akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=2e5+51,MOD=1e9+7;
ll cnt,num,ftot,res=1;
ll fact[MAXN],finv[MAXN],factor[MAXN],exponent[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline ll qpow(ll base,ll exponent)
{
	ll res=1;
	while(exponent)
	{
		if(exponent&1)
		{
			res=(li)res*base%MOD;
		}
		base=(li)base*base%MOD,exponent>>=1;
	}
	return res;
}
inline void setup(ll cnt)
{
	fact[0]=fact[1]=finv[0]=1;
	for(register int i=2;i<=cnt;i++)
	{
		fact[i]=(li)fact[i-1]*i%MOD;
	}
	finv[cnt]=qpow(fact[cnt],MOD-2);
	for(register int i=cnt-1;i;i--)
	{
		finv[i]=(li)finv[i+1]*(i+1)%MOD;
	}
}
inline void getFact(ll num)
{
	for(register int i=2;i<=sqrt(num);i++)
	{
		if(num%i==0)
		{
			factor[++ftot]=i;
			while(num%i==0)
			{
				num/=i,exponent[ftot]++;
			}
		}
	}
	if(num!=1)
	{
		factor[++ftot]=num,exponent[ftot]=1;
	}
}
int main()
{
	cnt=read(),getFact(num=read()),setup(200000);
	for(register int i=1;i<=ftot;i++)
	{
		res=(li)res*fact[cnt+exponent[i]-1]%MOD;
		res=(li)res*finv[cnt-1]%MOD*finv[exponent[i]]%MOD;
	}
	printf("%d\n",res);
}

Measured memory_bytes: 1792
s = input()

x = 0
np = []
for i in reversed(range(len(s))):
    if s[i] == 'p':
        x += 1
    np.append(x)
np = list(reversed(np))

y = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'g':
        if y > np[i]:
            ans += 1
            y -= 1
        else:
            y += 1
    else:
        y -= 1
# print(np)
print(ans)


Measured memory_bytes: 6376
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;


int main(){
    ll n;cin>>n;
    vector<ll> v(5);
    for(int i=0;i<5;i++)cin>>v[i];
    for(int i=0;i<5;i++)v[i]=(n-1)/v[i]+1;
    cout<<*max_element(v.begin(),v.end())+4;
}

Measured memory_bytes: 256
N = int(input())
numbers = [int(i) for i in input().split()]
 
def build_stairs(N, numbers):
    for i in range(1, N): # 後ろから計算する
        stair1 = numbers[-i]
        stair2 = numbers[-(i + 1)]
        diff_stair = stair1 - stair2
        if diff_stair >= 0:
            pass
        elif diff_stair <= -2:
            return False
        elif diff_stair == -1:
            numbers[-(i + 1)] -= 1
    return True

if build_stairs(N, numbers):
    print('Yes')
else :
    print('No')

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; ++i)
#define pb push_back
#define mp make_pair
#define frab(i, a, b) for (int i = a; i < b; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll MAX = 1e12;
const ll INF = 1e17;
const ld EPS = 1e-9;
const int M = 1e2 + 12;
const int N = 3e5 + 10;

vector <int> g[N];
int par[N];

void dfs(int v, int p) {
    par[v] = p;
    for (auto t: g[v])
        if (t != p)
            dfs(t, v);
}

int color[N];

void dfs2(int v, int p) {
    color[v] = 1;
    for (auto t: g[v])
        if (t != p && color[t] != 2)
            dfs2(t, v);
}

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("mines.in", "r", stdin);
    //freopen("mines.out", "w", stdout);
    int n;
    cin >> n;
    fr(i, n - 1) {
        int v, u;
        cin >> v >> u;
        g[--v].pb(--u);
        g[u].pb(v);
    }

    fill(par, par + n, -1);
    dfs(0, -1);
    //fr(i, n)
    //    cout << par[i] << " ";cout << endl;

    vector <int> v;
    int cur = par[n - 1];
    while (cur != 0) {
        v.pb(cur);
        cur = par[cur];
    }
    reverse(v.begin(), v.end());

    color[0] = 1;
    color[n - 1] = 2;
    int m = v.size();
    fr(i, m)
        if (i <= (m - 1) / 2)
            color[v[i]] = 1;
        else
            color[v[i]] = 2;

    dfs2(0, -1);

    int cnt1 = 0;
    fr(i, n)
        if (color[i] == 1)
            cnt1++;
    if (cnt1 > n - cnt1)
        cout << "Fennec";
    else
        cout << "Snuke";
}


Measured memory_bytes: 16632
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  int n,t,i,ans,dif;
   long long  int ar[340005];
   cin>>n>>t;
   for(i=0;i<n;i++)
    cin>>ar[i];
   ans=0;
   for(i=1;i<n;i++)
   {
       dif=ar[i]-ar[i-1];
       if(dif<t)
       {
           ans=ans+dif;
       }
       else
       {
           ans=ans+t;
       }
   }
   ans=ans+t;
   cout<<ans<<endl;

}


Measured memory_bytes: 2304
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

def resolve():
    N, M = LI()
    AB = [LI_() for _ in range(M)]
    ans = [N*(N-1)//2]
    uf = UnionFind(N)
    for A, B in reversed(AB):
        A_size = uf.size(A)
        B_size = uf.size(B)
        connected_island_num = 0
        if not uf.same(A, B):
            connected_island_num = A_size*B_size
        ans.append(ans[-1]-connected_island_num)
        uf.unite(A, B)
    # 崩落数0の分を除去
    ans.pop()
        
    for i in reversed(ans):
        print(i)


if __name__ == '__main__':
    resolve()

Measured memory_bytes: 27176
/*
I am A NOOB.
You CANNOT LEARN Anything from My CODE.
So Just Go please.
Happy Coding.
*/
#include<bits/stdc++.h>
#define PI            	acos(-1)
#define pb 			  	push_back
#define pf 			  	push_front
#define mx(v) 		  	*max_element(v.begin(),v.end())
#define mn(v) 		  	*min_element(v.begin(),v.end())
#define sum(v)		  	accumulate(v.begin(),v.end(),0)
#define uni(v)		  	v.erase(unique(v.begin(),v.end()),v.end());
#define scan(n)		  	scanf("%d",&n);
#define arInput0(ar,n)	for(int i=0;i<n;i++)scan(ar[i]);
#define arInput1(ar,n)	for(int i=1;i<=n;i++)scan(ar[i]);
#define arOut0(ar,n)  	for(int i=0;i<n;i++){printf("%lld ",ar[i]);}
#define arOut1(ar,n)  	for(int i=1;i<=n;i++){printf("%lld ",ar[i]);}
#define srt(x) 	      	sort(x.begin(),x.end());
#define INF 		  	(1e18)
#define mem(x,val) 	  	memset(x,val,sizeof(x))
#define io  		  	{freopen("in.txt","r", stdin);freopen("out.txt","w", stdout);}
#define X 			  	first
#define Y 			  	second
#define PII			  	pair<int,int>
typedef long long int 	lli;
using namespace std;

int main() {
	//io;
	int x, y; cin >> x >> y;
	if (y % 2 != 0) {cout << "No" << endl; return 0;}
	y /= 2;
	int lol = y - x;
	int hol = x - lol;
	if (hol < 0 || lol < 0)cout << "No" << endl;
	else cout << "Yes" << endl;




}


















Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			double mbi = 0;
			String mStr = "";
			double h;
			double w;
			double t;
			for(int i = 0;i < n;i++){
				String str = scan.next();
				h = scan.nextDouble() / 100;
				w = scan.nextDouble();
				t = (22.0 - w / h / h);
				t = (t < 0)?-t:t;
				if(mStr.equals("") || mbi > t){
					mStr = str;
					mbi = t;
				}
			}
			System.out.println(mStr);
		}
	}
}

Measured memory_bytes: 37880
import sys
from collections import defaultdict
#n=int(input())
n,a,b,c,d=map(int,input().split())
#a=[int(i) for i in input().split()]
s='_'+input()

ans=['Yes','No']

#print(s,n,a,b,c,d)

def CanGo(x,y):
    cnt=0
    root=s[x:y]
    for c in root:
        if c=='#':
            cnt+=1
        elif c=='.':
            if cnt>2:
                return False
            cnt=0
    return True


def CanPass(x,y):  #(b,d)
    root=s[x-1:y+2]
    '''
    q=s[x-1:x+2]
    print(root,q)
    print(root,len(root)-3+1)
    for i in range(len(root)-3+1):
        if q=='...':
            return True
        q=q[1:3]+s[x+3+i]
    '''
    if root.find('...')!=-1:
        return True
    return False
        


if c<d:
    if CanGo(b,d) and CanGo(a,c):
        ai=0
    else:
        ai=1
elif c>d:
    if CanGo(b,d) and CanGo(a,c) and CanPass(b,d):
        ai=0
    else:
        ai=1
    
    

print(ans[ai])


Measured memory_bytes: 3892
using System;
using System.Linq;

namespace AtCoderTutorial
{
    public class AtCoder175
    {
        public static void Main(string[] args)
        {
            int[] inputs = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
            int N = inputs[0];
            int X = inputs[1];
            int T = inputs[2];
            
            int totalTime = 0;
            int total = 0;

            while(true){
                totalTime += T;
                total += X;
                if(total >= N){
                    break;
                }
            }

            Console.WriteLine(totalTime);
        }
    }
}

Measured memory_bytes: 28244
n = int(input())
s = input()
e_counts = [0] * (n + 1)
w_counts = [0] * (n + 1)
e_counts[0] = 0
w_counts[0] = 0
ans = float("inf")
for i in range(n):
  if s[i] == "E":
    e_counts[i + 1] = e_counts[i] + 1
    w_counts[i + 1] = w_counts[i]
  else:
    e_counts[i + 1] = e_counts[i]
    w_counts[i + 1] = w_counts[i] + 1
for i in range(n):
  ans = min(ans,e_counts[n] - e_counts[i + 1] + w_counts[i])
print(ans)

Measured memory_bytes: 19560
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y,s;
    map<ll,ll>mp;
    cin>>s;
    mp[s] = 1 ;
    i = s ;
    j = 1 ;
    while(mp[i]<=1)
    {
    	if(i%2)
    	{
    		mp[3*i+1]++;
    		i = 3*i+1 ;
		}
		else
		{
			mp[i/2]++;
			i=i/2 ;
		}
		j++;
	}
	cout<<j ;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from math import sqrt

def main():
    a, b = sys.stdin.readline().split()
    n = int(a + b)
    sqrtn = int(sqrt(n))
    i = 1
    for i in range(1, sqrtn + 1):
        if i * i == n:
            print('Yes')
            break
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;


int dp[100005][3];

int main(){
    int n; cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
    rep(i,n) cin >> a[i] >> b[i] >> c[i];
    for(int i = 1; i <= n; i++){
        dp[i][0] = max(dp[i-1][1]+a[i-1],dp[i-1][2]+a[i-1]);
        dp[i][1] = max(dp[i-1][0]+b[i-1],dp[i-1][2]+b[i-1]);
        dp[i][2] = max(dp[i-1][0]+c[i-1],dp[i-1][1]+c[i-1]);
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]) << endl;
}

Measured memory_bytes: 2560
import scala.io.StdIn._

import Math._
object Main extends App {
  val Seq(xp1, yp1, xp2, yp2) = readLine.split(' ').map(_.toDouble).toList
  val vx1 = xp2 - xp1
  val vy1 = yp2 - yp1


  val q = readLine.toInt
  for (i <- 0 until q) {
    val Seq(x, y) = readLine.split(' ').map(_.toDouble).toList
    val vx2 = x - xp1
    val vy2 = y - yp1

    val c = (vx1 * vx2 + vy1 * vy2) / (vx1 * vx1 + vy1 * vy1)

    println("%.10f %.10f".format(c * vx1 + xp1, c * vy1 + yp1))
  }
}



Measured memory_bytes: 55964
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1LL<<61)

using namespace std;

typedef unsigned long long ull;

int main(void){
	
	int n;
	cin >> n;
	
	vector<ull> cost(n);
	for(int i=0;i<n;i++){
		cin >> cost[i];
		if(i>0)cost[i]+=cost[i-1];
	}
	
	static ull dp[4001][4001],k[4001][4001];
	fill(dp[0],dp[4001],INF);
	
	for(int i=0;i<n;i++){
		dp[i][i]=0;
		k[i][i]=i;
	}
	
	for(int w=1;w<=n;w++){
		for(int i=0,j=i+w;j<n;i++,j++){
			for(int r=k[i][j-1];r<=k[i+1][j];r++){
				ull c=dp[i][r]+dp[r+1][j]+cost[j]-((i>0)?cost[i-1]:0);
				if(dp[i][j]>c)dp[i][j]=c,k[i][j]=r;
			}
		}
	}
	cout << dp[0][n-1] << endl;
	
	return 0;
}

Measured memory_bytes: 251112
#include <bits/stdc++.h>
using namespace std;

int main(void){
  int X, A, B;
  cin >> X >> A >> B;
  int N; cin >> N;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "nobiro"){
      X = max(0, X + A);
    }else if(S == "tidime"){
      X = max(0, X + B);
    }else if(S == "karero"){
      X = 0;
    }else{
      assert(false);
    }
  }
  cout << X << endl;
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[2]==s[3] && s[4]==s[5]) cout << "Yes\n";
    else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,d,a[200010],ans=0,dpl[200010],dpr[200010];

int main()
{
	cin>>n>>d;
	rep(i,n) scanf("%I64d",&a[i]),ans+=a[i];
	if(n==1)
	{
		puts("0");
		rt0;
	}
	ans+=(n-1)*d;
	dpl[0]=a[0];
	for(int i=1;i<n;i++) dpl[i]=min(a[i],dpl[i-1]+d);
	dpr[n-1]=a[n-1];
	for(int i=n-2;i>=0;i--) dpr[i]=min(a[i],dpr[i+1]+d);
	for(int i=1;i<n-1;i++) ans+=min(dpl[i],dpr[i]);//cout<<min(dpl[i],dpr[i])<<' ';
	//cout<<endl;
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	int N,x;
	vector<int> A;
	int satisfied=0;
	cin >> N >> x;
	for(int i=0;i<N;i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(),A.end());
	for(const auto& a : A){
		x -= a;
		if(x>=0){
			satisfied++;
		}else{
			break;
		}
	}
	if(x>0){
		satisfied--;
	}
	cout << satisfied << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
    public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(br.readLine());
        String[]input = br.readLine().split(" " , num);
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i<num; i++) {
            sb.append(input[num-1-i] + " ");
        }
        System.out.println(sb.toString().substring(0 , sb.toString().length()-1));
    }
}


Measured memory_bytes: 24372
from collections import deque

n = int(input())
a = list(map(int, input().split()))

a.sort()

if a[0] >= 0:
    m = sum(a[1:]) - a[0]
    print(m)
    p = a.pop(0)
    while len(a) > 1:
        b = a.pop(0)
        print(*[p, b])
        p -= b
    b = a.pop()
    print(*[b, p])
elif a[-1] <= 0:
    m = -sum(a[:-1])+a[-1]
    print(m)
    p = a.pop(-1)
    while len(a) > 0:
        b = a.pop(0)
        print(*[p, b])
        p -= b
else:
    mi = list(filter(lambda x: x < 0, a))
    pl = list(filter(lambda x: x >= 0, a))
    m = -sum(mi) + sum(pl)
    print(m)
    lp = pl.pop(0)
    mi = deque(mi)
    while len(pl) > 0:
        b = pl.pop()
        c = mi.pop()
        print(*[c, b])
        c -= b
        mi.append(c)
    while len(mi) > 0:
        b = mi.pop()
        print(*[lp, b])
        lp -= b


Measured memory_bytes: 14736
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,t,a,b,n,c,d,y,temp,m,r,sum,count,k,l,ans;
    t=1;
    // cin>>t;
    while(t--)
    {
        cin>>n;
        ans=0;
        long arr[n],brr[n];
        for(i=0;i<n;i++)
        cin>>arr[i],brr[i]=0;;
        for(i=0;i<n;i++)
        {
            ans=0;
            while(arr[i]%2==0)
            {
                ans++;
                arr[i]/=2;
            }
            brr[i]=ans;
        }
        sort(brr,brr+n);
        cout<<brr[0];
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();

	int c500 = x/500;
	int c5 = (x%500)/5;

	System.out.print(c500*1000 + c5*5);
    }
}


Measured memory_bytes: 22740
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
typedef pair<int,pii> P;
priority_queue<P,vector<P>,greater<P> > ma;
int amida[10010];
int n,m,a;
int h,p,q;
int main(){
	while(cin>>n>>m>>a,n||m||a){
		for(int i =1;i <=n;i++){
			amida[i] = i;
		}
		for(int i =0;i < m;i++){
			cin>>h>>p>>q;
			ma.push(P(h,pii(p,q)));
		}
		while(!ma.empty()){
			int x =ma.top().second.first;
			int y =ma.top().second.second;
			ma.pop();
			swap(amida[x],amida[y]);
		}
		cout <<amida[a]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>

using namespace std;

typedef long long ll;

int n;
ll a[101010];
ll s[101010];

void rip() {
	cout << "-1\n";
	exit(0);
}

int main() {
	cin >> n;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = n; i >= 0; i--) s[i] = s[i+1]+a[i];
	ll c = 1;
	ll u = 0;
	for (int i = 0; i <= n; i++) {
		u += c;
		if (a[i] > c) rip();
		c -= a[i];
		if (i == n) break;
		if (c == 0 || c > s[i+1]) rip;
		c = min(2*c,s[i+1]);
	}
	if (c != 0) rip();
	cout << u << "\n";
}


Measured memory_bytes: 5188
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int H, W, K;
int dp[50][50][4][1<<12]; // 00: s, 01: n, 10: e, 11: w
char map[51][51];

bool twice(int prev_d){
    int x = 0, y = 0;
    for(int i=0;i<6;i++,prev_d>>=2){
        int d = prev_d & 0x3;
        x += dx[d];
        y += dy[d];
        if(x == 0 && y == 0){return true;}
    }
    return false;
}

int rec(int x, int y, int k, int prev_d){
    if(x == W-1 && y == H-1){return 0;}
    if(map[y+1][x] == '#' && map[y][x+1] == '#' && k == 0){return -INF;}
    if(dp[y][x][k][prev_d] != -1){return dp[y][x][k][prev_d];}

    int res = -INF, gifts = 0;

    if(isdigit(map[y][x]) && !twice(prev_d)){
        gifts = map[y][x] - '0';
    }

    REP(i, 4){
        int nx = x + dx[i], ny = y + dy[i];
        if(0 <= nx && nx < W && 0 <= ny && ny < H && k-i%2 >= 0 && map[ny][nx] != '#'){
            res = std::max(res, gifts + rec(nx, ny, k - i % 2, (prev_d << 2 | i) & 0xfff));
        }
    }

    return dp[y][x][k][prev_d] = res;
}

int main(){
    std::cin >> H >> W >> K;

    REP(i, H){
        REP(j, W){
            std::cin >> map[i][j];
        }
    }

    REP(i, H){
        map[i][W] = '#';
    }

    REP(j, W){
        map[H][j] = '#';
    }

    REP(i, H){
        REP(j, W){
            REP(k, K+1){
                REP(l, 1<<12){
                    dp[i][j][k][l] = -1;
                }
            }
        }
    }

    std::cout << rec(0, 0, K, 0) << std::endl;
}

Measured memory_bytes: 161172
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

#define REP(i,s,e) for(int i=int(s);i<int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)

#define EPS 1e-6

using namespace std;

int main(){

	int n;
	cin >> n;

	int d=100000;
	rep(i,n){

    d=1.05*d;

	if(d%1000!=0)
	d=d+1000-d%1000;

	}

	cout << d << endl;


	return 0;
}

Measured memory_bytes: 1160
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    if(a+b==15)cout<<'+';
    else if(a*b==15)cout<<'*';
    else cout<<'x';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt;
	cin>>n;
	if(n%2==1)
		for(int i=1;i<=n/2;i++)
		{
			cnt++;
		} 
	else 
		for(int i=1;i<n/2;i++)
		{
			cnt++;
		} 
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
s = gets.chomp
sum = 0
num = 0

if s[0] == 'A'
  i = 2
  while i < s.size - 1
    if s[i] == 'C'
      sum += 1
      num = i
    end
    i += 1
  end
  
  if sum == 1
    puts s.count("A-Z") == 2 ? "AC" : "WA"
    exit(0)
  end
end
puts "WA"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,maxi = 0,p,dmin = 1e9+8;
	cin >> N;
	vector<int> a(N);
	for(int i=0;i<N;i++){
		cin >> a[i];
		maxi = max(maxi,a[i]);
	}
	for(int i=0;i<N;i++){
		int d = maxi - 2*a[i];
		if(d<0){
			d = -d;
		}
		if(dmin >= d){
			dmin = d;
			p = a[i];
		}
	}
	cout << maxi << " " << p << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    rep(i, s.size()) {
        if (a + b) {
            if (s[i] == 'a') {
                cout << "Yes" << endl;
                a--; continue;
            }
            if (s[i] == 'b' && b) {
                cout << "Yes" << endl;
                b--; continue;
            }
        }
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
import collections
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))
        self.rank = [1]*n
        self.size = [1]*n
        

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)

        if px == py:
            return
        else:
            if self.rank[px] < self.rank[py]:
                self.parents[px] = py
                self.size[py] += self.size[px]
            else:
                self.parents[py] = px
                self.size[px] += self.size[py]
                #ランクの更新
                if self.rank[px] == self.rank[py]:
                    self.rank[px] += 1


N,M = map(int,input().split())
ufpc = UnionFindPathCompression(N)
AB = [list(map(int, input().split())) for _ in range(M)]
for a,b in AB:
    a,b = a-1,b-1
    ufpc.union(a,b)
    
for i in range(N):
    ufpc.find(i)

c = collections.Counter(ufpc.parents)
score_sorted = sorted(c.items(), key=lambda x:-x[1])
print(score_sorted[0][1])
    

Measured memory_bytes: 113264
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 3e5 + 5;
const ld PI = 4 * atan((ld)1);
int dp[MX],h[MX],pre[MX];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,K;
	cin>>n>>K;
	for(int i=0;i<n;i++)
		cin>>h[i];
	fill(dp,dp+n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int k=1;k<=K;k++)
		dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k]-h[i]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MOD 1000000007

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;

  vector<ll> v = {};
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);

  sort(v.begin(), v.end());
  if ((v[0] == v[1] && v[0] != v[2]) || (v[1] == v[2] && v[0] != v[1]))
  {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int N, T, L, B;
int lose[105];
int back[105];
int board[105];
double p[2][105], losep[2][105];
double memo[105][105];
double dfs(int t, int idx){
	if(idx == N) return 1.0;
	if(t <= 0) return 0;
	if(memo[t][idx] != -1.0) return memo[t][idx];
	double ans = 0;
	for(int i = 1; i <= 6; i++){
		int ni = idx + i;
		if(ni > N) ni = N - (ni - N);
		if(board[ni] == 1){
			ans += dfs(t - 2, ni) / 6.0;
		}else if(board[ni] == 2){
			ans += dfs(t - 1, 0) / 6.0;
		}else{
			ans += dfs(t - 1, ni) / 6.0;
		}
	}
	return memo[t][idx] = ans;
}

int main(){
	while(cin >> N >> T >> L >> B, N){
		for(int i = 0; i <= N; i++){
			board[i] = 0;
		}
		for(int i = 0; i < L; i++){
			cin >> lose[i];
			board[lose[i]] = 1;
		}
		for(int i = 0; i < B; i++){
			cin >> back[i];
			board[back[i]] = 2;
		}
		for(int i = 0; i <= T; i++){
			for(int j = 0; j <= N; j++){
				memo[i][j] = -1.0;
			}
		}
		
		printf("%.10f\n", dfs(T, 0));
	}
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //int t=100;while(t--){
    int x,n,ans;
    cin>>x>>n;
    int p[n+1];
    set<int>s;
    for(int i=0;i<n;i++){
        cin>>p[i];
       s.insert(p[i]);
    }
    if(n==0)
        ans=x;
    else
    {
        int t1=x,t2=x;
        while(1)
        {
            if(s.count(t2)==0)
            {
                ans=t2;
                break;
            }
            else if(s.count(t1)==0)
            {
                ans=t1;
                break;
            }
            t1++;
            t2--;

        }

    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3640
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N;
	cin >> N;
	vector<ll> A(N);
	vector<ll> B(N);
	rep(i, N) {
		cin >> A.at(i) >> B.at(i);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	if (N % 2 != 0) {
		cout << B.at(N / 2) - A.at(N / 2) +1<< endl;
	}

	else {
		cout << ((B.at((N - 1) / 2) + B.at(N / 2) - A.at((N - 1) / 2) - A.at(N / 2)) )+ 1 << endl;
	}
}


Measured memory_bytes: 6396
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N;
int hs[110];

int min(int start, int end) {
  int m = 1000;
  for (int i = start; i <= end; i++) {
    if (hs[i] < m) {
      m = hs[i];
    }
  }
  return m;
}

int solve(int start, int end) {
  if (end - start < 1) {
    int count = hs[start];
    hs[start] = 0;
    return count;
  }

  bool hasZero = false;
  int count = 0;
  for (int i = start; i <= end; i++) {
    if (hs[i] == 0) {
      hasZero = true;
      count = solve(start, i - 1) + solve(i + 1, end);
      break;
    }
  }

  if (!hasZero) {
    int m = min(start, end);
    for (int i = start; i <= end; i++) {
      hs[i] = hs[i] - m;
    }
    count += m;
    count += solve(start, end);
  }

  return count;
}

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> hs[i];
  }

  cout << solve(1, N) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())

AB = [0] * N

for i in range(N):
    AB[i] = tuple(map(int, input().split()))

AB.sort(key=lambda x: x[1])

time = 0
for i in AB:
    A, B = i
    time += A
    if time > B:
        print('No')
        sys.exit()

print('Yes')


Measured memory_bytes: 31888
#include<stdio.h>
long long int fac(int);
int main()
{
    int a;
    long long int f;
    scanf("%d",&a);
    f=fac(a);
    printf("%lld\n",f);
    return 0;
}

long long int fac(int a)
{
    if(a<=1)
        return 1;
    else
        return a*fac(a-1);
}

Measured memory_bytes: 592
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())

int m, n, a, b;

struct P {
	int x, y, z;
	P() {}
	P(int x, int y, int z) : x(x), y(y), z(z) {}
	bool operator< (const P& l) const {
		if (x != l.x) return x < l.x;
		if (y != l.y) return y > l.y;
		return z > l.z;
	}
};

int r() {
	const int C = ~(1 << 31), M = (1 << 16) - 1;
	a = 36969 * (a & M) + (a >> 16);
	b = 18000 * (b & M) + (b >> 16);
	return (C & ((a << 16) + b)) % 1000000;
}

bool C(map<int, P>& polyline, const P& p) {
	map<int, P>::iterator it = polyline.lower_bound(p.y);
	if (it == polyline.begin()) return true;
	it--;
	return it->second.z >= p.z;
}

void insert_polyline(vector<map<int, P> >& polyline, const P& p) {
	int l = -1, r = sz(polyline);
	while (r - l != 1) {
		int md = (l + r) / 2;
		bool ok = C(polyline[md], p);
		if (ok) r = md;
		else l = md;
	}
	if (sz(polyline) == r) polyline.emplace_back();
	if (polyline[r].find(p.y) != polyline[r].end() && polyline[r][p.y].z <= p.z) return;
	polyline[r][p.y] = p;
	map<int, P>::iterator it = polyline[r].find(p.y);
	++it;
	while (it != polyline[r].end()) {
		if (it->second.z < p.z) break;
		polyline[r].erase(it++);
	}
}

int main() {
	int cnt = 0;
	while (cin >> m >> n >> a >> b, m || n || a || b) {
		cnt++;
		vector<P> v;
		FOR(i, m) {
			int x, y, z; cin >> x >> y >> z;
			v.emplace_back(x, y, z);
		}
		FOR(i, n) {
			int x = r();
			int y = r();
			int z = r();
			v.emplace_back(x, y, z);
		}
		sort(v.begin(), v.end());

		vector<map<int, P> > polyline;
		FOR(i, sz(v)) {
			insert_polyline(polyline, v[i]);
		}

		cout << sz(polyline) << "\n";
	}

	return 0;
}

Measured memory_bytes: 13860
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define INF            1e9
#define REP(i,n)       for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n)  for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPR(i,n)      for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(lint i=(n);i>0;--i)
#define REPRI(i,ini,n) for(lint i=(ini)-1,i##_len=(n);i>=i##_len;--i)
#define REPC(i,obj)    for(auto i:obj)
#define R_UP(a,b)      (((a)+(b)-1)/(b))
#define ALL(obj)       (obj).begin(),(obj).end()
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
int ans = 0;
void merge_sort(vector<int>&s, int left, int right)
{
	static int workspace[500000];
	if (left == right)return;
	int medium = (left + right) / 2;
	merge_sort(s, left, medium);
	merge_sort(s, medium + 1, right);
	for (int i = left; i <= medium; ++i)workspace[i] = s[i];
	for (int i = medium + 1, j = right; i <= right; ++i, --j)workspace[j] = s[i];
	for (int i = left, j = right, k = left; k <= right; ++k, ++ans)s[k] = workspace[i] <= workspace[j] ? workspace[i++] : workspace[j--];
}
signed main()
{
	int n = in();
	vector<int>s(n);
	REP(i, n)scanf("%d", &s[i]);
	merge_sort(s, 0, n - 1);
	REP(i, n)
	{
		if (i != 0)cout << ' ';
		cout << s[i];
	}
	cout << endl;
	cout << ans << endl;
}


Measured memory_bytes: 6740
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
Ain = A.index(1)
if N == K:
    print("1")
# else:
#     if Ain % K-1 == 0 and (len(A)-Ain-1)//(K-1) == 0:
#         print(Ain // (K - 1) + (len(A) - Ain - 1) // (K - 1) + 2)
#     else:
#         print(Ain//(K-1) + (len(A)-Ain-1)//(K-1) +1)

else:
#    print(Ain // (K - 1))
#    print((len(A)-(K - 1)* (Ain // (K - 1)) - 1))
    print(math.ceil(Ain / (K - 1)) + math.ceil((len(A)-(K - 1)* (math.ceil(Ain / (K - 1))) - 1) / (K-1)))


Measured memory_bytes: 13812
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin>>s;
  int n=s.size()-1;
  string sa,sb;
  for (int i = n; 0<i; i--) {
    if(i%2==1) continue;
    s = s.substr(0,i-1);

    sa = s.substr(0,i/2 - 1);
    sb = s.substr(i/2);
    if (sa == sb) {
      cout<<i <<endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
S = input()
list = ['a','b','c']
if S[0] in list:
    list.remove(S[0])
    if S[1] in list:
        list.remove(S[1])
        if S[2] in list:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int x,k,d; cin>>x>>k>>d;
    x=abs(x);
    if(k<=x/d) {
        cout<<x-k*d<<endl;
        return 0;
    }
    if((k-(x/d))%2==0) cout<<x%d<<endl;
    else cout<<abs(x%d-d)<<endl;
    return 0;
}

Measured memory_bytes: 3660
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    map<int,int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    LL ans = 0;
    for (auto&& var : mp) {
        if (var.second % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;

int main(){
  long long n; cin>>n;
  string s;
  if(n==0){cout<<0<<endl; return 0;}
  while(n){
    if(n%2){
      s+='1';
      n--;
      n/=-2;
    }else{
      s+='0';
      n/=-2;
    }
  }
  reverse(s.begin(),s.end());
  cout<<s.c_str()<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { rep(i,v.size())os<<v[i]<<(i==v.size()-1?"\n":" "); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n) ans += (s[i] == 'g');
    ans -= (n+1)/2;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

#define long long long
#define fi first
#define se second
typedef pair<int,int> ii;

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	int h, w, n;
	int x, y;
	string s, t;
	cin >> h >> w >> n;
	cin >> x >> y;
	cin >> s >> t;

	int u = 1, d = h, l = 1, r = w;
	for(int i = n-1; i >= 0; i--)
	{
		// cout << s[i] << "\n" << t[i] << "\n";
		if(t[i] == 'D') u = max(1, u-1);
		if(t[i] == 'U') d = min(h, d+1);
		if(t[i] == 'R') l = max(1, l-1);
		if(t[i] == 'L') r = min(w, r+1);
		// printf("%d %d %d %d\n", u, d, l, r);
		
		if(s[i] == 'U') u = max(1, u+1);
		if(s[i] == 'D') d = min(h, d-1);
		if(s[i] == 'L') l = max(1, l+1);
		if(s[i] == 'R') r = min(w, r-1);
		// printf("%d %d %d %d\n", u, d, l, r);

		if(l > r || u > d)
		{
			printf("NO\n");
			return 0;
		}
	}
	// printf("%d %d %d %d\n", u, d, l, r);

	if(u <= x && x <= d && l <= y && y <= r) printf("YES\n");
	else printf("NO\n");
}










Measured memory_bytes: 776
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] points = new int[n][2];
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
      points[i] = new int[] { sc.nextInt(), sc.nextInt() };
      for (int j = 0; j < i; j++)
        sum += Math.sqrt(Math.pow(points[i][0] - points[j][0], 2) + Math.pow(points[i][1] - points[j][1], 2));
    }
    System.out.println(sum * 2 / n);
  }
}

Measured memory_bytes: 22864
#include <cstdio>
#include <cstdlib>
#include <cmath>

int c[16];
int n, m, i, j, k, x;

int main(void){
	for(; scanf("%d%d", &n, &m), n; printf("%d\n", x > m ? -1 : x)){
		for(i = 3; i--;)
			for(scanf("%d", &j); j--; c[n-k] = i)
				scanf("%d", &k);
		x = 0;
		for(i = n; i--; k += c[i])
			x += pow(3, i) * abs(k*2%4 - c[i]);
		x = fmin(x, pow(3, n) - 1 - x);
	}
	return 0;
}

Measured memory_bytes: 1072
import sys
line=[]
in_line=sys.stdin
for _in in in_line:line.append(_in)
#for i in range(89):line.append(input())
sets=(len(line)+1)//9
for i in range(sets):
    flag=0
    topindex=-1
    for j in range(i*9,i*9+9):
        a=line[j].count('1')
        if a!=0:t=line[j].index('1')
        else:t=-1
        if a==4:
            print('C')
            break
        elif flag==0 and a!=0:
            topindex=t
            if a==1:flag=1
            elif a==2:flag=2
        elif flag==1:
            if a==1:
                print('B')
                break
            elif a==2:
                if topindex==t:
                    print('F')
                    break
                else:
                    print('D')
                    break
        elif flag==2:
            if topindex==t:
                print('A')
                break
            elif topindex<t:
                print('E')
                break
            else:
                print('G')
                break

Measured memory_bytes: 7436
#include <iostream>

using namespace std;
int main(){
  int k,x;
  cin>>k>>x;
  for(int i=(k-1);i>=0;i--){
    cout<<x-i<<" ";}
    
  for(int i=1;i<=(k-1);i++){
    cout<<x+i<<" ";}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    int n, limit;
    cin >> n >> limit;
    vector<vector<int>> dp(110, vector<int>(20000));
    vector<int> value(n), weight(n);
    for (int i = 0; i < n; ++i) {
        cin >> value[i] >> weight[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= limit; ++j) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j + weight[i]] = max(dp[i + 1][j + weight[i]], dp[i][j] + value[i]);
        }
    }
    cout << dp[n][limit] << endl;
}



Measured memory_bytes: 11568
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int N, M, X, A;
	int ans1 = 0, ans2 = 0;

	cin >> N >> M >> X;
	rep(i, M) {
		cin >> A;
		if (A < X) ans1++;
		else ans2++;
	}
	cout << min(ans1, ans2) << endl;

	return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [a,n,m]=input.trim().split(" ").map(Number);
var cnt=0;
var i=1;
while(true){
   var k = Math.pow(i,n);
   if(k>m)break;
   var ary=(k+"").split("").map(Number);
   var sum = ary.reduce((a,b) => a+b);
   if(Math.pow(a+sum,n)==k)cnt++;
   i++;
}
console.log(cnt);


Measured memory_bytes: 17464
#include <bits/stdc++.h>

using namespace std;

const int MX = 105;
const int MV = 205;
const int ME = 22222;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct GRAPH
{
	int fst[MV],nxt[ME],v[ME],w[ME],lnum;
	int dep[MV],q[MV];          //分层网络的深度，bfs 的队列

	void addeg(int nu,int nv,int nw)
	{
		nxt[++lnum] = fst[nu];
		fst[nu] = lnum;
		v[lnum] = nv;
		w[lnum] = nw;
	}

	int bfs(int frm,int to)     //生成分层网络
	{
		int h=0,t=1,x,y;
		memset(dep,0xff,sizeof(dep));
		q[++h]=frm;
		dep[frm]=0;
		while(h>=t)
		{
			x=q[t++];
			for(int i=fst[x];i!=-1;i=nxt[i])
			{
				y=v[i];
				if(dep[y]==-1&&w[i])
				{
					dep[y]=dep[x]+1;
					q[++h]=y;
				}
			}
		}
		return (dep[to]>=0);    //返回分层网络是否成功生成
	}

	int cur[MV];                //当前弧优化的记录数组
	int dinic(int x,int mn,int t)
	{
		if(x==t)return mn;
		int y,a,now=0;
		for(int &i=cur[x];i!=-1;i=nxt[i])   //"int &i="这一句是当前弧优化的核心
		{
			y=v[i];
			if(w[i]&&dep[y]==dep[x]+1)
			{
				a=dinic(y,min(mn-now,w[i]),t);
				now+=a;                     //整体流量优化，记录当前节点往下流的最大流量后再返回
				w[i]-=a,w[i^1]+=a;      //帮助 dinic 反悔
				if(mn==now)return now;
			}
		}
		return now;
	}

	int mxflow(int s, int t)
	{
		int tot=0;
		while(bfs(s,t))
		{
			memmove(cur,fst,sizeof(fst));
			tot+=dinic(s,MX,t);
		}
		return tot;
	}

	void init()
	{
		memset(fst, 0xff, sizeof(fst));
		lnum = -1;
	}
} G;

int n, m;
int A[MX][MX], B[MX][MX], C[MX][MX];
int targx[MX*MX], targy[MX*MX];
vector<int> have[MX][MX];

void input()
{
	read(n), read(m);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
		{
			read(A[i][j]);
			targx[A[i][j]] = (A[i][j]-1)/m+1;
			targy[A[i][j]] = (A[i][j]-1)%m+1;
			have[i][targx[A[i][j]]].push_back(A[i][j]);
		}
}

void work()
{
	for(int i=1; i<=m; i++)
	{
		G.init();
		for(int x=1; x<=n; x++)
			for(int y=1; y<=n; y++)
				if(have[x][y].size())
					G.addeg(x, n+y, 1), G.addeg(n+y, x, 0);
		for(int x=1; x<=n; x++)
		{
			G.addeg(n*2+1, x, 1);
			G.addeg(x, n*2+1, 0);
			G.addeg(n+x, n*2+2, 1);
			G.addeg(n*2+2, n+x, 0);
		}
		int f = G.mxflow(n*2+1, n*2+2);
		for(int x=1; x<=n; x++)
		{
			for(int e=G.fst[x]; ~e; e=G.nxt[e])
			{
				if(G.v[e]>n && G.v[e]<=n*2 && !G.w[e])
				{
					assert(have[x][G.v[e]-n].size());
					B[x][i] = have[x][G.v[e]-n].back();
					have[x][G.v[e]-n].pop_back();
				}
			}
		}
	}
	for(int i=1; i<=n; i++)
		for(int j=1; j<=m; j++)
			C[targx[B[i][j]]][j] = B[i][j];
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++) printf("%d ", B[i][j]);
		putchar('\n');
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++) printf("%d ", C[i][j]);
		putchar('\n');
	}
}

int main()
{
	input();
	work();
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
using namespace std;

int main() {

  double r, T , S ;

  cin >> r ;

  T = (double) 2 * 3.141592653589 * r;

  S = (double) 3.141592653589 * r * r;

  printf("%lf %lf\n", S , T);

  return 0;

}

Measured memory_bytes: 1236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(input.readLine());

        long sumOfSeconds = 0;
        long[] timeToSolveProblem = new long[N];

        String[] ts = input.readLine().split(" ");
        for (int i = 0; i < N; i++) {
            long t = Long.parseLong(ts[i]);
            sumOfSeconds += t;
            timeToSolveProblem[i] = t;
        }
        int M = Integer.parseInt(input.readLine());
        for (int i = 0; i < M; i++) {
            String[] line = input.readLine().split(" ");
            int problemNumber = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            long sum  = sumOfSeconds + x - timeToSolveProblem[problemNumber - 1];
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 21332