akhauriyash/Code-Regression huggingface dataset:
#include<set>  
#include<map>  
#include<stack>  
#include<cstdio>  
#include<queue>  
#include<cmath>  
#include<vector>  
#include<climits>  
#include<cstring> 
#include<iostream> 
#include<algorithm> 
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
LL read(){ 
    LL f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 3000000
struct edge{
	int v,w;
	edge(){}
	edge(int V,int W){v=V,w=W;}
};
int n,m;
struct node{
	int u,k;
	node(){}	
	node(int U,int K){u=U,k=K;}
	friend bool operator < (node a,node b){return a.u==b.u?a.k<b.k:a.u<b.u;}
};
struct node1{
	int u,v,k;
	node1(){}	
	node1(int U,int V,int K){u=U,v=V,k=K;}
};
vector<node> Make_zx;
vector<node1> Make_xx;
vector<edge> G[MAXN+5];
int dis[MAXN+5];
bool vis[MAXN+5];
queue<int>Q;
int SPFA(int S,int T){
	memset(vis,0,sizeof(vis));
	memset(dis,0x3f,sizeof(dis));
	dis[S]=0,vis[S]=1,Q.push(S);
	while(!Q.empty()){
		int u=Q.front(),v,w,siz=G[u].size();
		Q.pop();
		vis[u]=0;
		for(int i=0;i<siz;i++){
			v=G[u][i].v,w=G[u][i].w;
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				if(!vis[v]){
					vis[v]=1;
					Q.push(v);
				}
			}
		}
	}
	return dis[T]==INF?-1:dis[T]/2;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		int p=read()-1,q=read()-1,c=read()-1;
		Make_zx.push_back(node(p,c));
		Make_zx.push_back(node(q,c));
		Make_xx.push_back(node1(p,q,c));
		Make_xx.push_back(node1(q,p,c));
	}
	sort(Make_zx.begin(),Make_zx.end());
	for(int i=0;i<int(Make_zx.size());i++){
		G[n+i].push_back(edge(Make_zx[i].u,1));
		G[Make_zx[i].u].push_back(edge(n+i,1));
	}
	for(int i=0;i<int(Make_xx.size());i++){
		int l1=lower_bound(Make_zx.begin(),Make_zx.end(),node(Make_xx[i].u,Make_xx[i].k))-Make_zx.begin(),
		l2=lower_bound(Make_zx.begin(),Make_zx.end(),node(Make_xx[i].v,Make_xx[i].k))-Make_zx.begin();
		G[l1+n].push_back(edge(l2+n,0));
	}
	printf("%d\n",SPFA(0,n-1));
    return 0;
}

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

int N;
int h[100005];
int dp[100005];

void solve() {
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; ++i) {
		dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i)
		cin >> h[i];
	solve();
	cout << dp[N - 1];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long int fun(long long int x,long long int y)
{
    long long int n=x,m=y,z;
    while(y!=0)
    {
        z=x%y;
        x=y;
        y=z;
    }
    return m*n/x;
}
int main()
{
    long long int a[100005],b[100005];
    char c[100005],d[100005];
    long long int n,m,sumn,summ;
    while(scanf("%lld%lld",&n,&m)==2)
    {
        a[0]=1,b[0]=1;
        int flag=1;
        scanf("%s",c);
        scanf("%s",d);
        long long int s=fun(n,m);
        for(int i=1; i<=n-1; i++)
        {
            a[i]=(i*(s/n))+1;
        }
        for(int i=1; i<=m-1; i++)
        {
            b[i]=(i*(s/m))+1;
        }
        for(int i=0,j=0;j<m&&i<n;)
        {
            if(a[i]==b[j])
            {
                if(c[i]!=d[j])
                {
                    flag=0;
                }
                i++,j++;
            }
            else if(a[i]>b[j])
            {
                j++;
            }
            else
            {
                i++;
            }
        }
        if(flag)
            printf("%lld\n",s);
        else
            printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int N, M;
    cin >> N >> M;
    vector<int> v(M, 0);
    REP(i, N){
        int K;
        cin >> K;
        int tmp;
        REP(j, K) {
            cin >> tmp;
            tmp--;
            v[tmp]++;
            }
    }
    int ans = 0;
    REP(i, M) if(v[i] == N) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EditDistanceAizu solver = new EditDistanceAizu();
        solver.solve(1, in, out);
        out.close();
    }

    static class EditDistanceAizu {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[] a = in.next().toCharArray();
            char[] b = in.next().toCharArray();
            int n = a.length;
            int m = b.length;

            int[][] dp = new int[n + 1][m + 1];

            for (int i = 0; i < n + 1; i++) {
                dp[i][0] = i;
            }

            for (int j = 0; j < m + 1; j++) {
                dp[0][j] = j;
            }

            for (int i = 1; i < n + 1; i++) {
                for (int j = 1; j < m + 1; j++) {
                    if (a[i - 1] == b[j - 1]) {
                        dp[i][j] = Math.min(Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1), dp[i - 1][j - 1]);
                    } else {
                        dp[i][j] = Math.min(Math.min(dp[i - 1][j] + 1, dp[i][j - 1] + 1), dp[i - 1][j - 1] + 1);
                    }
                }
            }

            out.println(dp[n][m]);
        }

    }
}




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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

int main() {
  int a, b, t;
  cin >> a >> b >> t;

  cout << b * (int) ((t + 0.5) / a) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int num[5];
	cin>>num[0]>>num[1]>>num[2]>>num[3]>>num[4];
	int a;
	for(int i=0;i<4;i++){
		for(int j=i+1;j<=4;j++){
			if(num[i]<num[j]){
				a = num[i];
				num[i] = num[j];
				num[j] = a;
			}
		}
	}
	for(int k=0;k<5;k++){
		if(k != 0) cout<<" ";
		cout<<num[k];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>

using namespace std;

void solve()
{
    int N;
    cin >> N;

    vector<int> p(N);

    for (int i = 0; i < N; ++i)
    {
        cin >> p[i];
    }

    vector<int> dp(N);

    dp[0] = 0;
    dp[1] = abs(p[0] - p[1]);

    for (int i = 2; i < N; ++i)
    {
        dp[i] = min(dp[i - 1] + abs(p[i] - p[i - 1]), dp[i - 2] + abs(p[i] - p[i - 2]));
    }

    cout << dp[N - 1] << "\n";
}

int main()
{
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

vector<int> edge[100010];
int dist1[100010], dist2[100010];

void dfs1(int v, int p) {
    for (int nv : edge[v]) {
        if (nv == p) continue;
        dist1[nv] = dist1[v] + 1;
        dfs1(nv, v);
    }
}

void dfs2(int v, int p) {
    for (int nv : edge[v]) {
        if (nv == p) continue;
        dist2[nv] = dist2[v] + 1;
        dfs2(nv, v);
    }
}

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    dfs1(u, -1);
    dfs2(v, -1);

    int ans = 0;
    rep(i, 0, n) {
        if (dist1[i] < dist2[i]) ans = max(ans, dist2[i]);
    }
    cout << ans - 1 << endl;
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++)
    cin>>L.at(i);
  sort(L.begin(),L.end());
  int max=L.at(N-1);
  int sum=0;
  for(int i=0;i<N-1;i++)
    sum+=L.at(i);
  if(max<sum)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4e5 + 5, mod = 1e9 + 7;

int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, k;
    cin >> n >> k;
    ll ans = n % k;
    if(ans == 0) return cout << 0, 0;
    ans = min(ans, abs(ans - k));
    cout << ans;


    return 0;
}


Measured memory_bytes: 256
import math

A, B = map(int, input().split())


def main():
    # 偶数 n と 奇数 n + 1 の ペア の数
    pair = math.floor((B - A) / 2)

    if A % 2 == 0:
        pair = math.ceil((B - A) / 2)

        if B % 2 == 1:
            print(pair % 2)
        else:
            print(pair % 2 ^ B)

    else:
        if B % 2 == 1:
            print(A ^ pair % 2)
        else:
            print(A ^ pair % 2 ^ B)

    return


main()


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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

int dp[2001]={0};

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
        
	int n,x,y;
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i<=x&&j>=y){
				dp[j-i-(y-x)+1]++;
			}
			else if(i>=x&&j<=y){
				dp[min(j-i,y-j+i-x+1)]++;
			}
			else if(i>=x){
				dp[min(j-i,i-x+1+j-y)]++;
			}
			else if(i<=x){
				dp[min(j-i,y-j+1+x-i)]++;
			}

		}
	}
	for(int i=1;i<=n-1;i++)
		cout<<dp[i]<<endl;


	return 0;
}

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

using namespace std;

int hardCode(string s)
{
    if(s == "SSS")
        return 0;
    else if(s == "SSR")
        return 1;
    else if(s == "SRS")
        return 1;
    else if(s == "SRR")
        return 2;
    else if(s == "RSS")
        return 1;
    else if(s == "RSR")
        return 1;
    else if(s == "RRS")
        return 2;
    else if(s == "RRR")
        return 3;
}

int main()
{
    string records;
    cin >> records;
    cout << hardCode(records);

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

LL labs( LL x );

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL n, m;
    cin >> n >> m;
    LL xsum = 0, ysum = 0;
    for( int i = 1; i <= n; ++i ) {
        LL x;
        cin >> x;
        xsum = ( xsum + ( ( i - 1 ) * x - ( n - i ) * x ) ) % MOD;

    }

    for( int i = 1; i <= m; ++i ) {
        LL y;
        cin >> y;
        ysum = ( ysum + ( ( i - 1 ) * y  - ( m - i ) * y ) ) % MOD;

    }

    cout << ( xsum * ysum ) % MOD << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a,b,c;
	scanf("%d%d%d",  &a,&b,&c);
	if (a >= b && a >= c) {
		printf("%d", 10 * a + b + c);
		return 0;
	}
	if (b >= a && b >= c) {
		printf("%d", 10 * b + a + c);
		return 0;
	}
	if (c >= a && c >= b) {
		printf("%d", 10 * c + a + b);
		return 0;
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N;
	cin >> N;
	ll H[N];
	for(int i=0;i<N;i++)cin >> H[i];
	bool ok = 1;
	ll m = 0;
	for(int i=0;i<N;i++){
		m = max(m,H[i]);
		if(m-1>H[i])ok = 0;
	}
	if(ok)cout <<"Yes"<<endl;
	else cout <<"No"<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int h, w, d;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt(); h = sc.nextInt(); d = sc.nextInt();
			if((h|w|d) == 0) break;
			
			boolean[][] v = new boolean[h][w];
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) v[i][j] = sc.nextInt() == 1;
			
			boolean[][][] A = new boolean[h][w][h*w];
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) {
				A[i][j][i*w+j] = true;
				for(int k=-d;k<=d;k++) {
					int x = j + k, y = i + d - abs(k);
					if(!out(x, y)) A[i][j][y*w+x] = true;
					y = i - d + abs(k);
					if(!out(x, y)) A[i][j][y*w+x] = true;
				}
			}
//			for(boolean[][] a:A) for(boolean[] b: a)debug(b);
			boolean ng = false;
			for(int i=0;i<h && !ng;i++) for(int j=0;j<w && !ng;j++) {
				int px = -1, py = -1;
				for(int k=i*w+j;k<h*w;k++){
					int y = k/w, x = k%w;
					if(A[y][x][i*w+j]) {
						px = x; py = y; break;
					}
				}
				if(px>=0) swap(j, i, px, py, A, v);
				else continue;
				
				for(int k=0;k<h*w;k++)if(k != i*w+j) {
					int y = k/w, x = k%w;
					if(!A[y][x][i*w+j]) continue;
					for(int l=i*w+j;l<w*h;l++) A[y][x][l] = A[y][x][l]^A[i][j][l];
					v[y][x] = v[y][x]^v[i][j];
				}
			}
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) ng |= !A[i][j][i*w+j] && v[i][j];
//			debug(ng);
			System.out.println((!ng? 1: 0));
		}
	}
	
	void swap(int x1, int y1, int x2, int y2, boolean[][][] A, boolean[][] v) {
		boolean[] tmp = new boolean[w*h];
		System.arraycopy(A[y1][x1], 0, tmp, 0, w*h);
		System.arraycopy(A[y2][x2], 0, A[y1][x1], 0, w*h);
		System.arraycopy(tmp, 0, A[y2][x2], 0, w*h);
		boolean tmp2 = v[y1][x1]; v[y1][x1] = v[y2][x2]; v[y2][x2] = tmp2;
	}
	
	boolean out(int x, int y) {
		return x < 0 || y < 0 || x >= w || y >= h;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 61744
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string input;
  unordered_map<string, int> res;
  res["AC"] = res["WA"] = res["TLE"] = res["RE"] = 0;
  for (int i = 0; i < n; ++i) {
    cin >> input;
    res[input]++;
  }
  cout << "AC x " << res["AC"] << '\n';
  cout << "WA x " << res["WA"] << '\n';
  cout << "TLE x " << res["TLE"] << '\n';
  cout << "RE x " << res["RE"] << '\n';
  return 0;
}

Measured memory_bytes: 3612
A = int(input())
B = int(input())
if A == 1:
    if B == 2:
        print(3)
    else:
        print(2)
elif A == 2:
    if B == 1:
        print(3)
    else:
        print(1)
else:
    if B == 1:
        print(2)
    else:
        print(1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string S;
	cin>>S
		;
	int len = S.length();
	if (S[len-1] == 's'){
		S = S + "es";
	}
	else{
		S = S +"s";
	}
	cout<<S;
	return 0;
}


Measured memory_bytes: 3656
N=int(input())
XYU=[tuple(input().split()) for _ in range(N)]
U=[]
R=[]
D=[]
L=[]
for x,y,u in XYU:
 x,y = int(x),int(y)
 if u=="U":
  U.append((x,y))
 elif u=="D":
  D.append((x,y))
 elif u=="L":
  L.append((x,y))
 else:
  R.append((x,y))
r=10**9
def z(A):
 global r
 A.sort()
 n=p=-10**9
 for k,c,a in A:
  if k!=n:
   if a==1:
    n=k
    p=c
   continue
  if a==1:
   p=c
   continue
  if (c-p)*5<r:
   r=(c-p)*5
z([(x,y,1) for x,y in U]+[(x,y,-1) for x,y in D])
z([(y,x,1) for x,y in R]+[(y,x,-1) for x,y in L])
z([(x+y,x-y,1) for x,y in R]+[(x+y,x-y,-1) for x,y in U])
z([(x+y,x-y,1) for x,y in D]+[(x+y,x-y,-1) for x,y in L])
z([(x-y,x+y,1) for x,y in U]+[(x-y,x+y,-1) for x,y in L])
z([(x-y,x+y,1) for x,y in R]+[(x-y,x+y,-1) for x,y in D])
print("SAFE" if r>=10**9 else r)

Measured memory_bytes: 103116
main = do 
    [w, h, x, y] <- map (read :: String -> Int). words <$> getLine
    let s = w * h 
    let s2 = ( fromIntegral s ) / (2::Float)
    let b = ((2*x) == w) && ((2*y) == h)
    putStrLn $ (show s2) ++ " " ++ if b then "1" else "0"

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

VI A;
bool all9()
{
	FOR(i, 0, SZ(A))
	{
		if (A[i] != 9) return false;
	}

	return true;
}

int sum()
{
	int ans = 0;
	FOR(i, 0, SZ(A)) ans+= A[i];
	return ans;
}

int solve(LL n)
{
	while (n)
	{
		A.PB(n % 10);
		n /= 10;
	}

	if (SZ(A) == 1)	return A[0];

	if (all9())	return SZ(A)* 9;

	int ans = A.back() - 1 + (SZ(A) - 1) * 9;
	return max(ans, sum());
}

int getSum(int a)
{
	int s = 0;
	while(a)
	{
		s += a % 10;
		a/=10;
	}

	return s;
}

int get(int a)
{
	int mx = 0;
	FOR(i, 1, a + 1)
	{
		mx = max(mx, getSum(i));
	}

	return mx;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
//	FOR(i, 1, 10001)
//	{
//		A.clear();
//		int ans = solve(i);
//		int bans = get(i);
//		if (ans != bans)
//		{
//			cout << i << endl;
//			cout << ans << " " << bans << endl;
//			return 0;
//		}
//
//	}
//
//	cout << "*" << endl;
	LL n;
	cin >> n;

	int ans = solve(n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
terms, graded_terms = input().split(" ")
grade_list = [i for i in input().split(" ")]
x1 = 0
x2 = int(graded_terms)
for i in range(int(terms)-int(graded_terms)):
    if int(grade_list[x2]) > int(grade_list[x1]):
        print("Yes")
    else:
        print("No")
    x1 += 1
    x2 += 1


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

int main() {
    int n, W;
    cin >> n >> W;
    vector<ll> price(n), weight(n);
    for(int i = 0; i < n; ++i)
        cin >> weight[i] >> price[i];
    vector<ll> dp(W + 1, 0);
    for(int i = 0; i < n; ++i)
        for(int wt = W; wt >= weight[i]; --wt) 
            dp[wt] = max(dp[wt], dp[wt - weight[i]] + price[i]);
    cout << dp[W];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <map>
using namespace std;

struct NODE{
	int x,bit;
	NODE(int x,int bit) : x(x) , bit(bit) {}
};

int n;
vector<int> dd[25];

int mask[25];

int sim(int bit){
	int nextbit = 0;
	for(int i = 0 ; i < n*n ; i++){
		int c = __builtin_popcount(bit&mask[i]);
		if( (bit >> i & 1) && (c == 2) ){
			nextbit |= (1<<i);
		}else if( c == 3 ){
			nextbit |= (1<<i);
		}
	} 
	return nextbit;
}

string view(int bit){
		string s;
	for(int i = 0 ; i < n * n ; i++) s += string(1,(bit>>i&1) + '0') + ((i+1)%n==0?"\n":""); 
	return s;
}
int main(){
	while(cin >> n && n){
		int bit = 0;
		int st = 0;
		int weight = 1;
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				char c;
				cin >> c;
				if( c == '#' ) bit += weight;
				weight *= 2;
				if( c == '@' ) st = n * i + j;
			}
		}
		
		
		
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < n ; j++){
				dd[i*n+j].clear();
				mask[i*n+j] = 0;
				for(int k = 0 ; k < 8 ; k++){
					int dx[] =  {0, 1,0,-1,1,1,-1,-1};
					int dy[] =  {-1,0,1,0,1,-1,1,-1};
					int y = i + dy[k];
					int x = j + dx[k];
					if( y >= n || x >= n || x < 0 || y < 0 ) continue;
					dd[i*n+j].push_back(n*y+x);
					mask[i*n+j] |= (1<<(n*y+x));
					//cout << i << "," << j << " : " << dd[i*n+j].back() << endl;
				}
				//dd[i*n+j].push_back(i*n+j);
			}
		}
		
		queue<NODE> Q;
		Q.push(NODE(st,bit));
		map<int,int> done[25];
		done[st][bit] = 0;
		while(Q.size()){
			NODE q = Q.front(); Q.pop();
			//cout << view(q.bit) << q.x << " " << (q.bit >> q.x & 1 ) << "[" << done[q.x][q.bit] << "]" << endl;
			
			if( q.bit == 0 ){
				cout << done[q.x][q.bit] << endl;
				goto exit;
			}
			
			for(int i = 0 ; i < dd[q.x].size() ; i++){
				if( !(q.bit >> (dd[q.x][i]) & 1) ){
					int tnext = sim(q.bit|(1<<dd[q.x][i])) &~ (1<<dd[q.x][i]);
					if( !done[dd[q.x][i]].count(tnext) ){
						done[dd[q.x][i]][tnext] = done[q.x][q.bit] + 1;
						Q.push(NODE(dd[q.x][i],tnext));
					}
				}
			}
		}
		cout << -1 << endl;
		exit:;
	}
}

Measured memory_bytes: 2140
# coding: utf-8
# Here your code !
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        posi = []
        now = [10,10]
        for i in range(n):
            l = map(int,raw_input().split())
            posi.append(l)
        n = int(raw_input())
        for i in range(n):
            l = raw_input().split()
            if str(l[0]) == 'E':
                for i in range(int(l[1])):
                    now = [now[0] + 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'W':
                for i in range(int(l[1])):
                    now = [now[0] - 1, now[1]]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'N':
                for i in range(int(l[1])):
                    now = [now[0], now[1] + 1]
                    if now in posi:
                        posi.remove(now)
            elif str(l[0]) == 'S':
                for i in range(int(l[1])):
                    now = [now[0], now[1] - 1]
                    if now in posi:
                        posi.remove(now)
        if posi:
            print 'No'
        else:
            print 'Yes'

Measured memory_bytes: 6300
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BIG 2000000007

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;


#define N_MAX 50
#define M_MAX 200000

ull n, m;
ull a[N_MAX];
ull b[N_MAX];

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a < *(ull*)b) {
		return -1;
	} else if (*(ull*)a > *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

ull divide(ull a, ull b){
	ull x = MOD - 2;
	ull ans = 1;
	while (x) {
		if (x & 1) ans = (ans * b) % MOD;
		b = (b * b) % MOD;
		x /= 2;
	}
	return (a * ans) % MOD;
}

int digits(ull x){
	int i = 1;
	while (x >= 10) {
		x /= 10;
		i++;
	}
	return i;
}

int nibutan(ull x, int begin, int end){
	while (begin + 1 < end) {
		int med = (begin + end) / 2;
		if (b[med] < x) {
			begin = med;
		} else {
			end = med;
		}
	}
	if (b[begin] < x) {
		return begin;
	} else {
		return begin - 1;
	}
}

int solve(){
	int i, j;
	ull x, y;

	n = 50;

	x = (n - 1) + m / n;
	y = m % n;

	for (i = 0; i < n; i++) {
		if (i < y) {
			a[i] = x + (n - y + 1);
		} else {
			a[i] = x - y;
		}
	}

	printf("%llu\n", n);
	for (i = 0; i < n; i++) {
		printf("%llu%c", a[i], ((i + 1 == n) ? '\n' : ' '));
	}

	return 0;
}

int main(void){
	ull i;

	scanf("%llu", &m);

	solve();

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <math.h>

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vstr vector<string>

using namespace std;

int main()
{
	ll n;
	cin >> n;
	ll ans = n % 1000;
	ans = 1000 - ans;
	ans %= 1000;
	cout << ans << endl;

}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
string s;
signed main(){
	cin>>s;
	int x=stoi(s.substr(0,2));
	int y=stoi(s.substr(2,2));
	if(1<=x&&x<=12){
		if(1<=y&&y<=12){
			puts("AMBIGUOUS");
		}
		else{
			puts("MMYY");
		}
	}
	else{
		if(1<=y&&y<=12){
			puts("YYMM");
		}
		else{
			puts("NA");
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(all(a));
    ll ans=0;
    for(int i=0;i<n;i++){
        if(x>=a[i]){
            x-=a[i];
            ans++;
        }
        else if(i==n-1&&x>0){
            ans++;
        }
    }
    if(x>0){
        ans--;
    }
    if(ans<0){
        ans=0;
    }
    cout<<ans<<endl;
    
}



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

int main()
{
    int n;
    cin >> n;
    int a[n] = {};
    map<int, int> m;
    vector<int> v;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        m[t]++;
        if(m[t]>=2){
            v.push_back(t);
            m[t] -= 2;
        }
    }
    
    if(v.size() < 2){
        cout << 0 << endl;
    }else{
        sort(v.rbegin(), v.rend());
        long long ans = v[0];
        ans *= (long long)v[1];
        cout << ans << endl;
    }
    return 0;
}


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

int partition(int a[],int p,int r){
	int x = a[r];
	int i = p-1;
	for(int j = p;j<r;j++){
		if (a[j]<=x){
			i+=1;
			int tmp;
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
	int tmp;
	tmp = a[r];
	a[r] = a[i+1];
	a[i+1] = tmp;
	return i+1;
}

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int pos = partition(a,0,n-1);
	for(int i=0;i<n;i++){
		if(i>0) cout<<" ";
		if(i==pos){
			cout<<"["<<a[i]<<"]";
			continue;
		}
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1548
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

int m,a,r,c,h;
vector<int> x(10);

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	rep(i,n){
		cin >> s;
		x[0] += (s[0] == 'M');
		x[1] += (s[0] == 'A');
		x[2] += (s[0] == 'R');
		x[3] += (s[0] == 'C');
		x[4] += (s[0] == 'H');
	}
	int sum = 0;
	rep(i,5-2){
		for(int j = i + 1;j < 5;++j){
			for(int k = j + 1;k < 5;++k){
				sum += x[i] * x[j] * x[k];
			}
		}
	}
	cout << sum << '\n';
	return 0;
}


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

static const int Q = 1000;

int main(){
  int M[Q][Q],n,u,k,v;

  cin >> n;

  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}

  



Measured memory_bytes: 3392
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;  
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;

int n, njudge, neach, ntake;
int a[MAXN];

ll asum[MAXN + 1];

bool can(int idx) {
	if (idx < ntake) return true;
	int have = a[idx] + njudge;
	int need = a[ntake - 1];
	if (have < need) return false;
	int nsafe = ntake - 1 + (n - idx);
	//printf("idx=%d neach=%d nsafe=%d\n", idx, neach, nsafe);
	if (neach <= nsafe) return true;
	int nrem = neach - nsafe;
	int cnt = idx - (ntake - 1);
	ll sum = asum[idx] - asum[ntake - 1];
	ll lim = (ll)cnt * have;
	ll extra = lim - sum;
	//printf("nrem=%d njudge=%d extra=%lld\n", nrem, njudge, extra);
	return (ll)nrem * njudge <= extra;
}

int solve() {
	sort(a, a + n); reverse(a, a + n);
	//printf("a:"); REP(i, n) printf(" %d", a[i]); puts("");
	asum[0] = 0; REP(i, n) asum[i + 1] = asum[i] + a[i];
	int ret = 0;
	for (int l = 0, r = l; l < n; l = r) {
		int cur = a[l];
		while (r < n && a[r] == cur) ++r;
		int cnt = r - l;
		if (can(l)) ret += cnt;
	}
	return ret;
}

void run() {
	scanf("%d%d%d%d", &n, &njudge, &neach, &ntake);
	REP(i, n) scanf("%d", &a[i]);
	printf("%d\n", solve());
}

int main() {
	run();
	return 0;
}


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

#define int long long

signed main(){
    int n;
    cin >>n;
    int a[n+1];
    int b[n+1];
    for(int i=1;i<=n;i++){
        cin >> a[i];
        b[i]=0;
    }
    for(int i=1;i<=n;i++){
        b[a[i]]++ ;
    }
    int max=0;
    for(int i=1;i<=n;i++){
        max += b[i]*(b[i]-1)/2;
    }
    for(int i=1;i<=n;i++){
        cout << max - (b[a[i]] - 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    a = pow((x3-x2) ** 2 + (y3-y2) ** 2, 0.5)
    b = pow((x3-x1) ** 2 + (y3-y1) ** 2, 0.5)
    c = pow((x1-x2) ** 2 + (y1-y2) ** 2, 0.5)
    cosA = (b**2 + c**2 - a**2) / (2*b*c)
    sinA = pow(1 - cosA**2, 0.5)
    R = a / sinA / 2
    a, b, c = x1-x2, y1-y2, -(x1**2 + y1**2) + (x2**2 + y2**2)
    d, e, f = x2-x3, y2-y3, -(x2**2 + y2**2) + (x3**2 + y3**2)
    l = (c*e - b*f) / (e*a - b*d)
    m = (c*d - a*f) / (b*d - a*e)
    l, m = l*-0.5, m*-0.5
    print("{:.3f} {:.3f} {:.3f}".format(l, m, R))



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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

int mult(int a, int b){
    return ((a%2019)*(b%2019))%2019;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int l, r;
    cin >> l >> r;
    int m = 2019;
    int sol=mult(l,r);
    int range = (r-l)%2019;
    if(r-l>2018)
        sol=0;
    for(int i=0; i<range; i++){
        for(int j=range; j>=0; j--){
            if(l+i != r-j)
                sol = min(sol, mult(l+i,r-j));
        }
    }
    cout << sol;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ").map{|x|x.to_i}
heikin = 0
n.times do |i|
  heikin += a[i]
end
heikin /= n
ans = Array.new(3)
for i in -1..1 do
  ans[i + 1] = 0
  n.times do |j|
    ans[i + 1] += (heikin - (a[j] + i))**2
  end
end
p ans.min


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;


int main(){

  int W,H,N;
  bool p[100][100]={false};
  cin >> W >> H >> N;
  int x,y,a,w1=0,h1=0,w2=W,h2=H;
  for(int i=0;i<N;i++) {
      cin >> x >> y >> a;
      if(a == 1){
          for(int j=0;j<H;j++) for(int k=0;k<x;k++) p[j][k]=true;
      }
      if(a == 2){
          for(int j=0;j<H;j++) for(int k=x;k<W;k++) p[j][k]=true;
      }
      if(a == 3) {
          for(int j=H-y;j<H;j++) for(int k=0;k<W;k++) p[j][k]=true;
      }
      if(a == 4) {
          for(int j=0;j<H-y;j++) for(int k=0;k<W;k++) p[j][k]=true;
      }
  }
  int ans = 0;
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(!p[i][j]) ans++;

  cout << ans <<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();
      int re = 0;
      for(int i = 1;i <= n;i++){
        int sum = 0;
        int x = i;
        while(x != 0){
        	sum += x%10;
            x = x/10;
        }
        if(a <= sum&&sum <= b)re += i;
        sum = 0;
      }
      System.out.println(re);
    }
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;


bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  return match;
}

double tx[110],ty[110],tv[110];
double bx[110],by[110];
int N,M;

int chk(double t){
	Graph g(N+M);
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < M ; j++){
			double d = (tx[i]-bx[j])*(tx[i]-bx[j])+(ty[i]-by[j])*(ty[i]-by[j]);
			d = sqrt(d);
			d /= tv[i];
			if(d < t ){
				g[i].push_back(Edge(i,j+N,1));
				g[j+N].push_back(Edge(j+N,i,1));
			}
		}
	}
	Edges edgs;
	return bipartiteMatching(g,N,edgs) == M;
}
int main(){
	while(	cin >> N >> M && N ){
		assert(N>=M);
		for(int i = 0 ; i < N ; i++) cin >> tx[i] >> ty[i] >> tv[i];
		for(int i = 0 ; i < M ; i++) cin >> bx[i] >> by[i];
		double l = 0, r = 1e9;
		
		for(int i = 0 ; i < 128 ; i++){
			double m = (l+r) / 2;
			
			if( chk(m) ) r = m;
			else l = m;
		}
		printf("%.10lf\n",l);
	}
	
	
	
}

Measured memory_bytes: 1564
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int num;
  cin >> num;
  string str_first,str_second;
  cin >> str_first >> str_second;
  string result = "";
  
  for (int i = 0; i  < num; i++){
  	result = result + str_first[i] + str_second[i];
  }
  
  cout << result << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define REP(i, N) for (long long i = 0; i < (N); ++i)
#define REP1(i, N) for (long long i = 1; i <= (N); ++i)
#define RREP(i, N) for (long long i = (N) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

#define MAXPRN (100000) 
#define ANSRAN (1000000007)
//#define ANSRAN (10000)
ll m,n;
int pr[MAXPRN];
int pw[MAXPRN];

ll multi(ll a,ll b){
	return ((a%ANSRAN)*(b%ANSRAN))%ANSRAN;
}

ll facti(ll a){
	ll res=1;
	REP1(i,a) res=multi(res,i);
	return res;
	
}

ll powi(ll a,ll b){
	ll res=1;
	ll curNum=a;
	while(b>0){
		if(b&1) res=multi(res,curNum);
		curNum=multi(curNum,curNum);
		b>>=1;
	}
	return res;
}

ll combi(ll q,ll r)
{
	if(q<=r) return 1;

		ll res=facti(q);
		ll mul=powi(multi(facti(q-r),facti(r)),ANSRAN-2);
		return multi(res,mul);
}

void getPr(){
	REP(i,MAXPRN) pr[i]=1;
	pr[0]=pr[1]=0;
	REP(i,MAXPRN){
		if(i<2 || pr[i]==0) continue;
		for(int j=2*i;j<MAXPRN;j+=i)
			pr[j]=0;
	}
}

int main(){
	getPr();
	memset(pw,0,sizeof(pw));
	cin>>n>>m;
	ll res=-1;
	if(m==1){
		cout<<1<<endl;
		return 0;
	}
		REP(i,MAXPRN){
			if(!pr[i]) continue;
			while(!(m%i)) {
				pw[i]++;
				m/=i;
			}
		}
		
		REP(i,MAXPRN){
			if(pw[i]>0){
				if(res==-1) res=1;
				res=multi(combi(pw[i]+n-1,n-1),res);
			}
		}
		if(m>1){
			res=multi(res,combi(1+n-1,n-1));
		}
		
		
		if(res==-1)cout<<n<<endl;
		else cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		boolean left_init = false;
		int cur = 0;
		
		while(true){
			String in = sc.next();
			
			
			if("=".equals(in)){
				System.out.println(cur);
				break;
			}else if("+".equals(in)){
				int next = sc.nextInt();
				
				cur += next;
			}else if("-".equals(in)){
				int next = sc.nextInt();
				
				cur -= next;
			}else if("*".equals(in)){
				int next = sc.nextInt();
				
				cur *= next;
			}else if("/".equals(in)){
				int next = sc.nextInt();
				
				cur /= next;
			}else{
				int input = Integer.parseInt(in);
				if(!left_init){
					cur = input;
					left_init = true;
				}
			}
		}
	}

}

Measured memory_bytes: 19484
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    unsigned A, B, X;
    cin >> A >> B >> X;

    if( A <= X)
    {
        if(A + B-1 >= X)
        {
            cout << "YES" << endl;
        } else
        {
            cout << "NO" << endl;
        }
    } else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i = 0; i < M; i++)
    cin >> X[i];
  sort(X.begin(), X.end());
  vector<int> diff;
  for (int i = 0; i < M - 1; i++)
    diff.push_back(abs(X[i + 1] - X[i]));
  sort(diff.begin(), diff.end());
  int res = 0;
  for (int i = 0; i < M - N; i++)
    res += diff[i];
  cout << res << '\n';
  return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  string c;
  cin >> c;
  vector<int> sum(N + 1, 0);
  for (int i = 0; i < N; i++) {
    sum[i + 1] = sum[i] + (c[i] == 'W');
  }
  int ans = 100000000;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, max(sum[i], N - sum[N] - (i - sum[i])));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4452
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main (void)
{
    long a, b, c, k;
    long ans = 0;

    scanf("%ld %ld %ld %ld", &a, &b, &c, &k);

    if (k - a > 0) {
        ans += a;
        k -= a;
    } else {
        ans += k;
        printf("%ld", ans);
        return 0;
    }

    if (k - b > 0) {
        k -= b;
    } else {
        printf("%ld", ans);
        return 0;
    }

    if (k - c > 0) {
        ans -= c;
        k -= c;
    } else {
        ans -= k;
        printf("%ld", ans);
        return 0;
    }

    printf("%ld", ans);
    return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    unsigned long long ans,N,K,a;
    scanf("%lld%lld",&N,&K);

    a = N/K;

    if( K % 2 == 1 ){
        ans = a*a*a;
    }else{
        if( N % K >= K / 2 ){
            ans = a*a*a + (a+1)*(a+1)*(a+1);
        }else{
            ans = a*a*a * 2;
        }
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 128
h,w=map(int,input().split())
s=[]
for i in range(h):
    s_i=input()
    s.append(s_i)
ans="Yes"
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            if i-1>=0 and s[i-1][j]=="#":
                continue
            elif i+1<h and s[i+1][j]=="#":
                continue
            elif j-1>=0 and s[i][j-1]=="#":
                continue
            elif j+1<w and s[i][j+1]=="#":
                continue
            else:
                ans="No"
        if ans=="No":
            break
    if ans=="No":
        break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

int main(){
	int n;read(n);
	vector<pii> ans;
	if(n%2==0){
		rep(i,1,n)rep(j,i+1,n)
			if(i+j!=n+1)ans.pb(mp(i,j));
	}
	else{
		rep(i,1,n)rep(j,i+1,n)
			if(i+j!=n)ans.pb(mp(i,j));
	}
	printf("%d\n",(int)ans.size());
	REP(i,ans.size())
		printf("%d %d\n",ans[i].fi,ans[i].se);
	return 0;
}

Measured memory_bytes: 384
s = input()
t = input()
TABLE = {a: "" for a in map(chr, range(97, 123))}

for x, y in zip(s, t):
    if TABLE[x] == "":
        if y not in TABLE.values():
            TABLE[x] = y

    if TABLE[x] != y:
        print("No")
        break
else:
    print("Yes")


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

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

int main(){
    char c;
    int ans = 700;
    rep(i,3){
        cin >> c;
        if(c == 'o') ans += 100;
    }
    
    cout <<ans <<endl;

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[110];
int cnt[110];
int ma;
bool bl = true;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
		ma = max(ma, a[i]);
	}
	for (int i = ma; i >= 1; i--) {
		if (ma / 2 < i&&cnt[i] < 2)bl = false;
		if (ma % 2 && i == ma / 2 + 1 && cnt[i] != 2)bl = false;
		if (ma % 2 && i <= ma / 2 && cnt[i])bl = false;
		if (!(ma % 2) && i == ma / 2 && cnt[i] != 1)bl = false;
		if (!(ma % 2) && i < ma / 2 && cnt[i])bl = false;
	}
	if (bl)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N)
  {
    cin >> A[i];
    A[i]--;
  }

  vector<int> B(N);
  rep(i, N)
  {
    cin >> B[i];
  }

  vector<int> C(N - 1);
  rep(i, N - 1)
  {
    cin >> C[i];
  }

  int sum = 0;
  int before = -1;
  rep(i, N)
  {
    sum += B[A[i]];
    if (before + 1 == A[i])
    {
      sum += C[before];
    }
    before = A[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 

const int N=105;
const int M=1e3+5;
int f[M],t[M],w[M];
int dis[N][N];
int32_t main()
{
	int n,m; scanf("%d%d",&n,&m);
	memset(dis,63,sizeof dis);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&f[i],&t[i],&w[i]);
		dis[f[i]][t[i]]= dis[t[i]][f[i]] =w[i];
	}
	for(int i=1;i<=n;i++) dis[i][i]=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[j][k]);
	int ans=0;
	for(int i=0;i<m;i++){
		bool s=0;
		int x = f[i];
		int y = t[i];
		int W = w[i];
		for(int u=1;u<=n;u++)
			for(int v=1;v<=n;v++){
				int k = min(dis[x][u]+dis[v][y]+W,dis[x][v]+dis[u][y]+W);
				if(k<=dis[u][v]) s=1;
			}
		if(!s) ans++;
	}
	return cout<<ans<<endl,0;
}


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

int main(){
  int a,d,ans,sum;
cin>>a;
  vector<int>b(a),c(100001);
    for(int i=0;i<a;i++){
 cin>>b[i];
      c[b[i]]++;
  }
ans=0;

  for(int i=1;i<100000;i++){
     sum=c[i-1]+c[i]+c[i+1]; 
 ans=max(sum,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
w,h,n = map(int, input().split())
t=h
u=0
r=w
l=0

for i in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        u=max(u,y)
    elif a==4:
        t=min(t,y)

if l>=r or u>=t:
    print(0)
else:
    print((r-l)*(t-u))

Measured memory_bytes: 3064
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T>
constexpr bool in(T min, T max, T t)
{
    return t >= min && t <= max;
}

template <class T>
constexpr bool nin(T min, T max, T t)
{
    return !in(min, max, t);
}

template <class T>
void ninDebug(T min, T max, T t)
{
    using namespace std;
    if (nin(min, max, t))
    {
        cout << "ERROR" << endl;
    }
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int n, d;
    cin >> n >> d;

    auto range = d * 2 + 1;

    cout << n / range + (n % range == 0 ? 0 : 1) << endl;

    return 0;
}

Measured memory_bytes: 256