akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;

int main(){
    string N;
    cin >> N;
    char a=N[0],b='.';
    int a_cnt=1,b_cnt=0;
    for(int i=1;i<4;i++){
        if(a!=N[i]&&b=='.'){
            b=N[i];
            b_cnt++;
        }
        else{
            if(b==N[i]){
                b_cnt++;
            }
            else if(a==N[i]){
                a_cnt++;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if(a_cnt==2&&b_cnt==2){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


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

using namespace std;

const int MAX_N = 1010, MAX_E = 2e5 + 200;

int n, m, mp[MAX_N][MAX_N], etot, ui[MAX_E], vi[MAX_E], p[MAX_N], q[MAX_N];
bool accessible[MAX_N][MAX_N], vis[MAX_N], enabled[MAX_N][MAX_N];
vector<int> G[MAX_N];

void mark(int u, int root)
{
    vis[u] = true, accessible[root][u] = true;
    for (int v : G[u])
        if (!vis[v])
            mark(v, root);
}

void markPos(int u)
{
    vis[u] = true;
    for (int v : G[u])
        if (!vis[v])
            p[v] = mp[u][v], markPos(v);
}

void markNeg(int u)
{
    vis[u] = true;
    int siz = G[u].size() - 1;
    for (int i = siz; i >= 0; i--)
    {
        int v = G[u][i];
        if (!vis[v])
            q[v] = mp[u][v], markNeg(v);
    }
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1, u, v; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        ui[++etot] = u, vi[etot] = v;
        mp[u][v] = etot, G[u].push_back(v);
    }
    for (int i = 1; i <= n; i++)
        mark(i, i), memset(vis, false, sizeof(vis));
    for (int i = 1; i <= n; i++)
    {
        markPos(i), memset(vis, false, sizeof(vis));
        markNeg(i), memset(vis, false, sizeof(vis));
        for (int v : G[i])
            if (p[v] != mp[i][v] || q[v] != mp[i][v])
                enabled[i][v] = true;
        memset(p, 0, sizeof(p)), memset(q, 0, sizeof(q));
    }
    for (int i = 1; i <= m; i++)
        puts((accessible[vi[i]][ui[i]] ^ enabled[ui[i]][vi[i]]) ? "diff" : "same");
    return 0;
}

Measured memory_bytes: 10240
#include <iostream>
#include <cmath>

using namespace std;

int n;
int a[110];
double av,num;
int ans;

int main(int argc, const char * argv[]) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        av += a[i];
    }
    av = av / (double)n;
    num = floor(av);
    if (av - num > 0.5) {
        num = num + 1;
    }
    for (int i = 0; i < n; i++) {
        ans = ans + (a[i] - num) * (a[i] - num);
    }
    cout << ans << endl;
    return 0;
}


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

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

	int K;
	string S;
	cin >> K;
	cin >> S;
	// cout << K << " " << S;

	if (S.size() <= K)
	{
		cout << S;
		return 0;
	}
	for (int i = 0; i < K; i++)
	{
		cout << S[i];
	}
	cout << "...";

	return 0;
}

Measured memory_bytes: 3624
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker,"/stack:200000000")
#include <bits/stdc++.h>
using namespace std;

#define PI 2*acos(0.0)
#define print(x) return cout<<x<<endl,0
#define watch(x) cerr<<#x<<"-> "<<x<<endl
#define CLEAR(x,val) memset(x,val,sizeof(x))
// #define int long long

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;

signed main()
{	
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	cin.tie(0), cout.tie(0);
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	cout<<n/2-(n%2==0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
LL mypow(LL x,LL y){
    x%=MOD;
    LL res=1%MOD;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}
void ADD(LL& x,LL v){
    x=(x+v)%MOD;
    if(x<0)x+=MOD;
}
LL dp[SIZE];
int main(){
    DRII(N,K);
    VI fac;
    for(int i=1;i*i<=N;i++){
        if(N%i==0)fac.PB(i),fac.PB(N/i);
    }
    sort(ALL(fac));
    fac.resize(unique(ALL(fac))-fac.begin());
    LL an=0;
    if(N%2==0){
        REP(i,SZ(fac)){
            LL me;
            if(N/fac[i]%2==0){
                me=mypow(K,fac[i]);
            }
            else
                continue;
            REP(j,i){
                if(fac[i]%fac[j]==0){
                    ADD(me,-dp[j]);
                }
            }
            dp[i]=me;
            ADD(an,me*fac[i]);
        }
    }
    else{
        REP(i,SZ(fac)){
            LL me;
            me=mypow(K,(fac[i]+1)/2);
            REP(j,i){
                if(fac[i]%fac[j]==0){
                    ADD(me,-dp[j]);
                }
            }
            dp[i]=me;
            ADD(an,me*fac[i]);
        }
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 256
time=input()
w_l=[]
ch=0
for i in range(time):
    j=raw_input()
    if j in w_l:
        print("No")
        ch=1
        break
    else:
        if w_l==[]:
            w_l.append(j)
        else:
            j_1=list(w_l[-1])
            j_2=list(j)
            if j_1[-1]!=j_2[0]:
                print("No")
                ch = 1
                break
            else:
                w_l.append(j)

if ch==0:
    print("Yes")

Measured memory_bytes: 2568
// 20151016
// ????£???????????????????????£?????£???????




#include<stdio.h>




int main() {
  int n;
  int count;
  int i, j, k, l;




  /* ??\??? */
  while (scanf("%d", &n) != EOF) {




    /** ??¶?´??????? **/
    if (n > 50 || n < 0) {
      return 0;
    }




    /* ??????????????????????¨? */
    count = 0;
    for (i = 0; i < 10; i ++) {
      for (j = 0; j < 10; j ++) {
	for (k = 0; k < 10; k ++) {
	  for (l = 0; l < 10; l ++) {
	    if (i + j + k + l == n) {
	      // debug
	      /* printf("%d %d %d %d\n", i, j, k, l); */
	      count ++;
	    }
	  }
	}
      }
    }




    /* ??¨??? */
    printf("%d\n", count);
  }




  /* ?????? */
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main() {
    int now = 0;
    int next = 0;
    vector<string> s(3);
 
    for (int i=0; i<3; i++) {
        cin >> s[i];
    }
 
    while (!s[now].empty()) {
        next = s[now][0] -'a';
        s[now].erase(s[now].begin());
        now = next;
    }
 
    if(now==0) {
        cout << 'A' << endl;
    } else if(now==1) {
        cout << 'B' << endl;
    } else if(now==2) {
        cout << 'C' << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a+b==15)
		printf("+\n");
	else if(a*b==15)
		printf("*\n");
	else
		printf("x\n");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
		if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}


string s = "CODEFESTIVAL2016";


int main() {
	string a;
	cin >> a;
	int ans = 0;
	for(int i = 0; i < a.length(); i ++) if(a[i] != s[i]) ans ++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N;
    int i,j,k;
    int X;
    int s;
    
    scanf("%d",&N);
    
    int m[N];
    
    //  値の格納
    for(i=0;i<N;i++){
        scanf("%d",&m[i]);
    }
    
    //  挿入ソート
    for(i=0;i<N;i++){
        s=m[i];
        for(j=0;j<i;j++){
            if(m[i]<m[j]){
                for(k=i;k>j;k--){
                    m[k]=m[k-1];
                }
                m[j]=s;
            }
        }
    }
    
    X=N;
    for(i=0;i<N-1;i++){
        if(m[i]==m[i+1]){
            X--;
        }
    }
    
    printf("%d",X);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long solve(long long a, long long b) {
    return b? solve(b, a % b) + 2 * b * (a / b) : -a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n, x;
    cin >> n >> x;
    cout << solve(x, n - x) + n << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using graph = vector<vector<int>>;

void dfs(int node, graph& g, vector<bool>& visited) {
  visited[node] = true;

  for (auto n : g[node])
    if (!visited[n])
      dfs(n, g, visited);
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> a(M), b(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }

  int count = 0;
  rep(i, M) {
    graph to(N);
    rep(j, M) {
      if (i == j)
        continue;
      to[a[j]].push_back(b[j]);
      to[b[j]].push_back(a[j]);
    }

    vector<bool> visited(N);
    dfs(0, to, visited);
    if (!all_of(visited.begin(), visited.end(), [](auto x) { return x; }))
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
#include<set>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
string s;
int main() {
	cin >> s;
	bool f = true;
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0 && s[i] == 'L') f = false;
		if (i % 2 == 1 && s[i] == 'R') f = false;
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;
using namespace std;
int w,h,n;
int s[105][105];
int cnt[10005];
int main()  
{  
	cin>>h>>w>>n;
	for(int i=1;i<=n;i++) cin>>cnt[i];
	int k=1;
	for(int i=1;i<=h;i++){
		if(i%2==1){
			for(int j=1;j<=w;j++){
				if(cnt[k]==0) k++;	
				cnt[k]--;
				s[i][j]=k;
			}
		}else{
			for(int j=w;j>0;j--){
				if(cnt[k]==0) k++;	
				cnt[k]--;
				s[i][j]=k;
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			printf("%d ",s[i][j]);
		}
		printf("\n");
	}
	return 0;  
}  


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int par[N];

void ut_init(){
	rep(i,N) par[i]=i;
}

int ut_root(int x){
	if(par[x]==x) return x;
	else return par[x]=ut_root(par[x]);
}

bool ut_issame(int x,int y){
	return ut_root(x)==ut_root(y);
}

void ut_merge(int x,int y){
	int rx=ut_root(x),ry=ut_root(y);
	if(rx==ry) return;
	par[rx]=ry;
}

int main() {
	int n,m;cin>>n>>m;
	int p[N];rep(i,n) cin>>p[i];
	ut_init();
	rep(i,m){
		int x,y;cin>>x>>y;x--;y--;
		ut_merge(x,y);
	}
	int ans=0;
	rep(i,n) if(ut_issame(p[i]-1,i)) ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}
void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}



Measured memory_bytes: 25144
#include<bits/stdc++.h>
#define r(n)for(i=0;i<n;i++)
int K,X,Y,W,i,x,y,n,a,b,c,F,E,s,A[1<<20],B[1<<20];
int p(int x,int y){if(s)std::swap(x,y);A[n]=F?-x:x,B[n++]=E?-y:y;}
main(){
    scanf("%d%d%d",&K,&X,&Y);
    if(X<0)F=1,X=-X;
    if(Y<0)E=1,Y=-Y;
    if(X>Y)s=1,std::swap(X,Y);
    if((W=X+Y)&~K&1)return puts("-1"),0;
    if(W<K&&W&1)p(X,-K+X),p(c,K-(c=(K+X-Y)/2)),p(-c,K-c);
    else{
        int U=W-W%K,V=-X+Y-K;
        if(W<K||K&1&&(W/K&1)==(W&1))U+=K;
        if(W%K!=0)p(X-(a=(U-V)/2),Y-(b=(U+V)/2)),X=a,Y=b;
        r(X/K)p(K,0);
        r(Y/K)p(0,K);
        if(X%K!=0)p(X%K,Y%K);
    }
    printf("%d ",n);
    r(n)printf("%d %d ",x=x+A[i],y=y+B[i]);
}

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

int main()
{
    std::string s;
    bool table[26]{};
    std::cin >> s;
    for (auto &e: s)
    {
        if (table[e - 'a'])
        {
            printf("no\n");
            return 0;
        }
        table[e - 'a'] = true;
    }
    printf("yes\n");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

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

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int digitsum(int i){
    int t = i;
    int ret = 0;
    while(t){
        ret += t%10;
        t /= 10;
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    long long dp[n+1];
    dp[0] = 2;
    dp[1] = 1;
    rep(i,2,n+1){
        dp[i] = dp[i-1] + dp[i-2];
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 256
#! /usr/bin/env python3

def main():
    L = [list(map(int, input().split())) for x in range(3)]
    b = L[0]
    a = [0, L[1][0] - b[0], L[2][0] - b[0]]
    for i in range(3):
        for j in range(3):
            if L[i][j] != a[i] + b[j]:
                print('No')
                return
    print('Yes')
    return
main()

Measured memory_bytes: 3060
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n")[0];
  const N = parseInt(input.split(' ')[0])
  const K = parseInt(input.split(' ')[1])

  console.log(N.toString(K).length)
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, p;
  //cin >> n >> p;
  string s;

  cin >> s;
  n = s.size();
  p=2019;
  if (10%p == 0) { // 2,5
    ll ans = 0;
    rep(r,n) {
      if ((s[r]-'0') % p == 0) {
        ans += r+1;
      }
    }
    cout << ans << endl;
    return 0;
  }
 
  vector<int> d(n+1);
  int ten = 1;
  for (int i = n-1; i >= 0; --i) {
    int a = (s[i]-'0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
  }
  vector<int> cnt(p);
  ll ans = 0;
  for (int i = n; i >= 0; --i) {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4392
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
	ll n, a, b, c;
	scanf("%lld%lld%lld%lld", &n, &a, &b, &c);
	vector<string> st(n);
	rep(i, n) cin >> st[i];
	string ans;
	rep(i, n) {
		string s = st[i];
		if (s == "AB") {
			if (a == 0 and b == 0) {
				printf("No\n");
				return 0;
			}
			if (a > b) {
				ans += 'B';
				a--, b++;
			} else if (a < b) {
				ans += 'A';
				a++, b--;
			} else {
				int ch = -1;
				for (int j = i + 1; j < n; j++) {
					if (st[j][0] == 'A') {
						ch = 0;
						break;
					} else if (st[j][0] == 'B' or st[j][1] == 'B') {
						ch = 1;
						break;
					}
				}
				if (ch == 0) {
					ans += 'A';
					a++, b--;
				} else {
					ans += 'B';
					a--, b++;
				}
			}
		} else if (s == "AC") {
			if (a == 0 and c == 0) {
				printf("No\n");
				return 0;
			}
			if (a > c) {
				ans += 'C';
				a--, c++;
			} else if (a < c) {
				ans += 'A';
				a++, c--;
			} else {
				int ch = -1;
				for (int j = i + 1; j < n; j++) {
					if (st[j][0] == 'A') {
						ch = 0;
						break;
					} else if (st[j][1] == 'C') {
						ch = 1;
						break;
					}
				}
				if (ch == 0) {
					ans += 'A';
					a++, c--;
				} else {
					ans += 'C';
					a--, c++;
				}
			}
		} else {
			if (b == 0 and c == 0) {
				printf("No\n");
				return 0;
			}
			if (b > c) {
				ans += 'C';
				b--, c++;
			} else if (b < c) {
				ans += 'B';
				b++, c--;
			} else {
				int ch = -1;
				for (int j = i + 1; j < n; j++) {
					if (st[j][0] == 'B' or st[j][1] == 'B') {
						ch = 0;
						break;
					} else if (st[j][1] == 'C') {
						ch = 1;
						break;
					}
				}
				if (ch == 0) {
					ans += 'B';
					b++, c--;
				} else {
					ans += 'C';
					b--, c++;
				}
			}
		}
	}
	printf("Yes\n");
	rep(i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 6760
#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 ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
int MAX_N = pow(10, 5);

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> h;
  rep(i, 0, n - 1) {
    int H;
    cin >> H;
    h.push_back(H);
  }

  int cost[MAX_N];
  cost[0] = 0;
  cost[1] = abs(h[1] - h[0]);
  rep(i, 2, n - 1) {
    cost[i] = pow(10, 9);
    rep(K, 1, k) {
      if (i >= K) {
        cost[i] = min(cost[i], cost[i - K] + abs(h[i] - h[i - K]));
      }
    }
  }
  cout << cost[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1144
#include<iostream>

int main(void){
  std::string S;
  int num_topping = 0;
  std::cin >> S;
  for(int i; i < 3; i++){
    if(S[i] == 'o'){
      num_topping++;
    }
  }
  std::cout << 700 + 100*num_topping << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double w,h,ans;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>w>>h;
    if(w==1 || h==1)
        cout<<1;
    else
        cout<<fixed<<setprecision(0)<<ceil((w*h)/2.0);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
maxDown = 0
count = 0
for x in range(N-1):
    if H[x] >= H[x + 1]:
        count += 1
    else:
        count = 0
    if maxDown < count:
        maxDown = count
print(maxDown)


Measured memory_bytes: 63856
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int n;
long long d[100][100];

void floyd() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			if (d[i][k] == INF)continue;
			for (int j = 0; j < n; j++) {
				if (d[k][j] == INF)continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	int e, u, v, c;
	cin >> n >> e;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = ((i == j) ? 0 : INF);
		}
	}
	for (int i = 0; i < e; i++) {
		cin >> u >> v >> c;
		d[u][v] = c;
	}

	floyd();

	bool negative = false;
	for (int i = 0; i < n; i++)if (d[i][i] < 0)negative = true;
	if (negative) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j)cout << " ";
				if (d[i][j] == INF)cout << "INF";
				else cout << d[i][j];
			}
			cout << endl;
		}
	}
}

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

int main (){
    string W;

    cin >> W;

    if(W == "Sunny"){
        cout << "Cloudy" << endl;
    }

    else if(W == "Cloudy"){
        cout << "Rainy" << endl;
    }

    else {
        cout << "Sunny" << endl;
    }
    


}

Measured memory_bytes: 256
import java.io.*;

public class Main
{
	static InputReader in;    
	static PrintWriter out;  
	
	
	/**
     * @param args
     * @throws IOException
     */
	
    public static void main(String[] args) throws IOException
    {
    	in = new InputReader(System.in);    
        out = new PrintWriter(System.out);
        
        String n=in.next();
        int count=0,sum=0;
        int l=n.length();
        
        for(int i=1;i<l;i++)
        {
        	if(n.charAt(i)!='9')
        	{
        		count=i;
        		break;
        	}
        }
        
        if(count==0)
        {
        	if(l==1)
        		out.println(n);
        	else
        	{
        		for(int i=0;i<l;i++)
        		{
        			sum+=(int)n.charAt(i)-48;
        		}
        		out.println(sum);
        	}
        }
        else
        {
        	sum=((int)n.charAt(0)-49)+(l-1)*9;
        	out.println(sum);
        }
        
        out.close();
    }

	static class InputReader {    
        BufferedReader br;    
    
        public InputReader(InputStream stream) {    
            br = new BufferedReader(new InputStreamReader(stream));    
        }    
    
        public int nextInt() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            boolean negative = false;    
            if (c == '-') {    
                negative = true;    
                c = br.read();    
            }    
            int x = 0;    
            while (c > 32) {    
                x = x * 10 + c - '0';    
                c = br.read();    
            }    
            return negative ? -x : x;    
        }    
    
        public long nextLong() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            boolean negative = false;    
            if (c == '-') {    
                negative = true;    
                c = br.read();    
            }    
            long x = 0;    
            while (c > 32) {    
                x = x * 10 + c - '0';    
                c = br.read();    
            }    
            return negative ? -x : x;    
        }    
    
        public String next() throws IOException {    
            int c = br.read();    
            while (c <= 32) {    
                c = br.read();    
            }    
            StringBuilder sb = new StringBuilder();    
            while (c > 32) {    
                sb.append((char) c);    
                c = br.read();    
            }    
            return sb.toString();    
        }    
    
        public double nextDouble() throws IOException {    
            return Double.parseDouble(next());    
        }    
    }
}

//static Scanner in = new Scanner(new BufferedInputStream(System.in));




Measured memory_bytes: 21204
#other's code
N,M=map(int,input().split())
 
ac = 0
wa = 0
aclist = {}
walist = {}

for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]

print(ac,wa,sep=" ")

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

#define PB emplace_back

using namespace std;

const int N = 22;

long long int dp[1<<N], mod = 1e9+7;

bool b[N][N];

int main () {
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++ ) {
        for(int j = 0 ; j < n ; j++ ) {
            cin >> b[i][j];
        }
    }
    dp[0] = 1;
    for(int i = 1 ; i < (1 << n) ; i++ ) {
        int cnt = __builtin_popcount(i);
        for(int j = 0 ; j < n ; j++ ) {
            if(i & (1 << j)) {
                if(b[j][cnt-1]) {
                    dp[i] += dp[i ^ (1 << j)];
                    dp[i] %= mod;
                }
            }
        }
    }
    cout << dp[(1 << n) - 1];
}


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

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

double const pi = acos(-1);

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "{" << a.first << "," << a.second << "}";return os;}

template<typename T> 
inline T inprod(complex<T> a,complex<T> b) {
    return a.real()*b.real()+a.imag()*b.imag();
}

template<typename T> 
inline T outprod(complex<T> a,complex<T> b) {
    return a.real()*b.imag()-a.imag()*b.real();
}

template<typename T>
vector<pair<complex<T>,int>> convex_hull(vector<pair<complex<T>,int>>& ps) {
    int n = ps.size();
    vector<pair<complex<T>,int>> qs(n*2);
    sort(ps.begin(),ps.end(),[](const pair<complex<T>,int>& a,const pair<complex<T>,int>& b){return (a.first.real() == b.first.real() ? (a.first.imag() < b.first.imag()) : (a.first.real() < b.first.real()));});
    int k = 0;
    for (int i = 0;i < n;++i) {
        while (k > 1 && outprod(qs[k-1].first-qs[k-2].first,ps[i].first-qs[k-1].first) <= 0) k--;
        qs[k++] = ps[i];
    }
    for (int i = n-2,t = k;i >= 0;--i) {
        while (k > t && outprod(qs[k-1].first-qs[k-2].first,ps[i].first-qs[k-1].first) <= 0) k--;
        qs[k++] = ps[i];
    }
    qs.resize(k-1);
    return qs;
}

int main() {
    int n;
    cin >> n;
    const complex<double> I(0,1);
    vector<pair<complex<double>,int>> a(n);
    for (int i = 0;i < n;++i) {
        double x,y;cin >> x >> y;
        a[i] = make_pair(x+y*I,i);
    }
    vector<pair<complex<double>,int>> b = convex_hull(a);
    int m = b.size();
    b.push_back(b[0]);
    b.push_back(b[1]);
    vector<double> ans(n,0.0);
    for (int i = 1;i < m+1;++i) {
        complex<double> x = b[i-1].first-b[i].first,y = b[i].first-b[i+1].first;
        x /= sqrt(norm(x));
        y /= sqrt(norm(y));
        ans[b[i].second] = acos(inprod(x,y))/2/pi;
    }
    cout << fixed << setprecision(9);
    for (int i = 0;i < n;++i) cout << ans[i] << "\n";
}

Measured memory_bytes: 512
from fractions import *

def lcm(a,b): 
    return int(abs(a * b) / gcd(a,b) if a and b else 0)

def getDivisors(a,b):
    divisors = []
    for i in range(2,min(a,b)+1):
        if a % i == 0 and b % i == 0:
            divisors.append(i)
    return divisors

N,M = map(int,input().split())
a = input()
b = input()

if a[0] != b[0]:
    print(-1)
elif gcd(N,M) == 1:
    print(lcm(N,M))
elif N != M:
    divisors = getDivisors(N,M)

    for i in divisors:
        k = N//i
        l = M//i
        while k < N and l < M:
            if a[k] != b[l]:
                print(-1)
                quit()
            k += N//i
            l += M//i
    print(lcm(N,M))
else:
    if a == b: print(N)
    else: print(-1)




Measured memory_bytes: 5432
s = input()
res = 0
for i in range(len(s)):
    for j in range(i + 1, len(s)+1):
        tmp = s[i:j]
        flag = True
        for k in range(len(tmp)):
            if not (tmp[k] == 'A' or tmp[k] == 'G' or tmp[k] == 'C' or tmp[k] == 'T'):
                flag = False
                break
        if flag:
            res = max(res, len(tmp))
print(res)

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

int main(){
  ll a,b;
  cin >> a >> b;
  if((a<10)&(a>0)&(b<10)&(b>0)){
    cout << a*b << endl;
  }
  else cout << -1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String sline = sc.next();
		int n = sline.length();
		int[] sl = new int[n];
		for (int i=0; i<n; i++){
			sl[i] = Integer.parseInt(String.valueOf(sline.charAt(i)));
		}
		int ans0 = 0;
		int ans1 = 0;
		// 010
		for(int i=0; i<n; i++){
			if(i%2==0 && sl[i]==0){
				continue;
			} else if (i%2==1 && sl[i]==1) {
				continue;
			} else {
				ans0++;
			}
		}
		// 10
		for(int i=0; i<n; i++){
			if(i%2==0 && sl[i]==1){
				continue;
			} else if (i%2==1 && sl[i]==0) {
				continue;
			} else {
				ans1++;
			}
		}
		System.out.println(Math.min(ans0, ans1));
		
	}

}


Measured memory_bytes: 31720
#include <iostream>
#include <utility>
using namespace std;
int main(void){
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(a>b){
        swap(a,b);
    }
        
    if(b>c){
        swap(b,c);
    }
            
    if(a>b){
        swap(a,b);
    }

    
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD=1000000007;

int main() {
  vector<int> a(5);
  rep(i,5) cin >> a[i];
  rep(i,5) {
    if(a[i]==0) cout << i+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int coE = count(s.begin(),s.end(),'E');
    vector<int> acuE(n,0),acuW(n,0);
    int ans = n;
    for(int i = 0; i < n; i++)
    {
        if (i==0) {
            if (s[0] == 'E') {
                acuE[0]++;
            }
            else
            {
                acuW[0]++;
            }
        }
        else
        {
            if (s[i]=='E') {
                acuE[i] = acuE[i-1]+1;
                acuW[i] = acuW[i-1];
            }
            else
            {
                acuE[i] = acuE[i-1];
                acuW[i] = acuW[i-1]+1;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        if (s[i] == 'W') {
            ans = min(ans, acuW[i]-1+coE-acuE[i]);
        }
        else
        {
            ans = min(ans, acuW[i]+coE-acuE[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    ll n;
    cin >> n;
    ll l = 0, r = n + 1;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        ll target = n - mid;
        ll possible = mid * (mid - 1) / 2;
        if (possible >= target)
            r = mid;
        else
            l = mid;
    }
    while (n > 0) {
        if (n - r >= 0) {
            cout << r << endl;
            n -= r;
        }
        r--;
    }
}

Measured memory_bytes: 256
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let mut s:Vec<char> = scan.next::<String>().chars().collect::<Vec<char>>();
    let t:Vec<char> = scan.next::<String>().chars().collect::<Vec<char>>();

    let mut found = false;

    let mut p:i64 = (s.len() - t.len()) as i64;

    while p >= 0 {
        if cmp(&s[(p as usize)..(p as usize)+t.len()],&t[0..]) {
            found = true;

            let mut p = p;

            for &c in &t {
                s[p as usize] = c;
                p += 1;
            }
        } else {
            if s[p as usize + t.len() - 1] == '?' {
                s[p as usize + t.len() - 1] = 'a';
            }
        }

        if found {
            p = p - 1;

            while p >= 0 {
                if s[p as usize] == '?' {
                    s[p as usize] = 'a';
                }
                p = p - 1;
            }
        }

        p -= 1;
    }

    if found {
        println!("{}", s.into_iter().collect::<String>());
    } else {
        println!("UNRESTORABLE");
    }
}
fn cmp(a:&[char],b:&[char]) -> bool {
    if a.len() != b.len() {
        false
    } else {
        for i in 0..a.len() {
            if a[i] != '?' && a[i] != b[i] {
                return false;
            }
        }

        true
    }
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int cost[21][21];
	int n,m;
	char com;
	cin>>n>>m;
	for(int i=0;i<21;i++){
		for(int j=0;j<21;j++){
			cost[i][j]=1<<27;
		}
	}
	for(int i=0;i<m;i++){
		int a,b,c,d;
		cin>>a>>com>>b>>com>>c>>com>>d;
		cost[a][b]=c;cost[b][a]=d;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
			}
		}
	}
	int x1,x2,y1,y2;
	cin>>x1>>com>>x2>>com>>y1>>com>>y2;
	cout<<y1-y2-cost[x1][x2]-cost[x2][x1]<<endl;
}

Measured memory_bytes: 1160
# C - 怪文書
def main():
    n = int(input())
    ans = list(input())

    
    for _ in range(n-1):
        s = list(input())
        temp = []
        for j in ans:
            if j in s:
                s.remove(j)
                temp.append(j)
        else:
            ans = temp
    else:
        ans.sort()
        print(''.join(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



int main(){
	

	string S;
	cin>>S;
	
	int k = 0;
	
	for(int i=0;i<S.size();i++){
		if(S[i]=='p')k--;
		else k++;
	}
	
	cout<<k/2<<endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int main(){
int a,b,c,k;
int i,j;
scanf("%d %d  %d",&a,&b,&c);
scanf("%d",&k);
j=a;//最大の数を探す
if(b>j) j=b;
if(c>j) j=c;
i=pow(2,k);
printf("%d",a+b+c+j*i-j);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;

ll gcd(ll m, ll n) {//最大公約数
    if (n == 0)return m;
    return gcd(n, m % n);
}//gcd

int main() {
  ll n,x;
  cin>>n>>x;
  vector<ll> y(n);
  rep(i,n){
    ll b;
    cin>>b;
    y[i]=abs(b-x);
  }
  ll ans=y[0];
  rep(i,n-1){
    ans=gcd(ans,y[i+1]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
n, t = map(int, input().split())
l = []
for _ in range(n):
    c, ti = map(int, input().split())
    l.append((c, ti))
least_cost = None
for j in l:
    if j[1] <= t and (least_cost == None or j[0] < least_cost):
        least_cost = j[0]
if least_cost == None:
    print('TLE')
else:
    print(least_cost)


Measured memory_bytes: 3060
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ok(a,b,d10,d1):
	if d10>a:
		if 10>b:
			re=1
		else:
			re=0
	if d10==a:
		if d1>=b:
			re=1
		else:
			re=0
	if d10<a:
		re=0
	return re



m,d=map(int,input().split())
count=0
if d<10:
	print(0)
	exit()
d10=int(str(d)[0])
d1=int(str(d)[1])
for i in range(1,m+1):
	# print(yakusu)
	yakusu=make_divisors(i)
	yakusu.sort()
	

	yakusu=yakusu[1:-1]
	# print(yakusu)
	# print(d10,d1)
	if len(yakusu)%2==1:
		a =yakusu[len(yakusu)//2]
		if ok(a,a,d10,d1):
			count+=1
		del yakusu[len(yakusu)//2]
	for j in range(0,len(yakusu)//2):
		if ok(yakusu[j],yakusu[-j-1],d10,d1):count+=1
		if ok(yakusu[-j-1],yakusu[j],d10,d1):count+=1
	# print(count)
print(count)
# print(ok(4,2,4,0))



Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <cstring>
#define MAX_N 102
#define MAX_W 10002
#define INF -1
using namespace std;

int dp[MAX_N][MAX_W];

//初期化
//this method initialize dynamic programming table as below.
//0 0 0 0 0 0 0 0 0 0 ...
//0 2 5 8 8 8
//0 2 5 8 10 13
//0
//.
//.
//.
void init() {
    for(int r = 0; r < MAX_N; r++) {
        memset(dp[r], INF, sizeof(dp[r]));
        dp[r][0] = 0;
    }
    memset(dp[0], 0, sizeof(dp[0]));
}

//DEBUGGER
//this method output dynamic programming table
void output(int n, int w) {
    for(int r = 0; r <= n; r++) {
        for(int c = 0; c <= w; c++) {
            cout << dp[r][c] << " ";
        }
        putchar('\n');
    }
}

int main(void) {
    init(); //initialize
    //input
    int n, w; cin >> n >> w;
    int value[n], weight[n];
    for(int r = 0; r < n; r++) cin >> value[r] >> weight[r];
    //Dynamic Programming
    /*
    for(int r = 1; r < n + 1; r++) {
        for(int c = 0; c < n; c++) {
            if(weight[r] != c) continue;
            //give Dynamic Programming
            for(int g = 0; g < n; g++) {//roop as long as given array of value and weight.
                int val = value[g], wei = weight[g]; //if gth baggage is selected,...
                
                dp[r][c] = max(dp[r][c], dp[r - 1][c]);
                if(c + wei > w) continue; //If next weight is out of table, we can not update.
                dp[r][c + wei] = max(dp[r][c + wei], dp[r - 1][c] + val);
            
            }
        }
    }
     */
    for(int r = 1; r < n + 1; r++) {
        for(int c = 0; c < w + 1; c++) {
            int val = value[r - 1], wei = weight[r - 1];
            //選ばない場合
            dp[r][c] = max(dp[r][c], dp[r - 1][c]);
            //選ぶ場合
            if(c + wei <= w) { //重量制限内で無ければならない
                dp[r][c + wei] = max(dp[r][c + wei], dp[r - 1][c] + val);
            }
        }
    }
    //output(n, w); //DEBUG
    int ans = -1;
    for(int r = 0; r < w + 1; r++) ans = max(ans, dp[n][r]);
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 5156
object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val (W,a,b)=readLine()!!.split(" ").map{it.toInt()}
    val (norm_a,norm_b)=if(a<b) Pair(a,b) else Pair(b,a)  
   println(if(norm_a<=norm_b && norm_b<=norm_a+W) 0 else norm_b-(norm_a+W))
  }
}

Measured memory_bytes: 28048
from collections import defaultdict

class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = [i for i in range(N)]
        self.rank = [1]*(N)

    def getroot(self, x):
        if self.parent[x] == x:
            return x
        else:
            root = self.getroot(self.parent[x])
            self.parent[x] = root
            return root

    def is_group(self, x,y):
        return self.getroot(x) == self.getroot(y)

    def union(self, x, y):
        rootx = self.getroot(x)
        rankx = self.rank[rootx]
        rooty = self.getroot(y)
        ranky = self.rank[rooty]
        if rankx > ranky:
            self.parent[rooty] = rootx
        else:
            self.parent[rootx] = rooty
            self.rank[rooty] = max(self.rank[rooty], self.rank[rootx]+1)

n, k, l = map(int, input().split())

loads = UnionFind(n)
rails = UnionFind(n)

for _ in range(k):
    x, y = map(int, input().split())
    loads.union(x-1, y-1)

for _ in range(l):
    x, y = map(int, input().split())
    rails.union(x-1, y-1)

pair = defaultdict(int)
for i in range(n):
    pair[(loads.getroot(i), rails.getroot(i))] += 1

ans = "" 
for i in range(n-1):
    ans += str(pair[(loads.getroot(i), rails.getroot(i))]) + " "
ans += str(pair[(loads.getroot(n-1), rails.getroot(n-1))])
print(ans)


Measured memory_bytes: 56068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,ans=1;
ll M=0;
ll MOD=998244353;
void Main(){
    cin>>n;
    vector<ll> d(n);
    For(i,0,n){
        cin>>d.at(i);
        M=max(d.at(i),M);
    }
    if(d.at(0)!=0){
        cout<<0<<endl;
        return;        
    }
    sort(ALL(d));
    vector<ll> dist(M+1,0);
    For(i,0,n) dist.at(d.at(i))++;
    if(dist.at(0)>1){
        cout<<0<<endl;
        return;
    }
    For(i,1,M+1){
        For(j,0,dist.at(i)) {
            ans*=dist.at(i-1);
            ans%=MOD;
        }
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 1792
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  s <- getLine
  print $ solve s

solve s = 7 - (fromJust $ elemIndex s table)
  where
    table = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
import Data.List

main = do
    n <- readLn
    let ps = takeWhile (<=n) primes
        fs = map (succ . (f n)) ps
    print $ foldl' (\a b -> (a * b) `mod` (10^9+7)) 1 fs

primes = 2 : 3 : [x | i <- [1..], j <- [-1, 1], let x = 6 * i + j, isPrime x]
    where isPrime n = null [i | i <- takeWhile (\x -> x * x <= n) primes, rem n i == 0]

f n p = sum . map (n `div`) . takeWhile (<= n) $ map (p^) [1..]

Measured memory_bytes: 636
import itertools

N, C = map(int, input().split())
MAX = 10 ** 5 + 1
table = [[0] * MAX for _ in range(C)]

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    table[c][s] += 1
    table[c][t] -= 1

for c in range(C):
    for x in range(MAX - 1):
        if table[c][x + 1] == 1:
            table[c][x + 1] = 0
            table[c][x] += 1

table_sum = [sum(table[c][i] for c in range(C)) for i in range(MAX)]
print(max(itertools.accumulate(table_sum)))


Measured memory_bytes: 27464
def sign(p):
    if p<0:
        return -1
    elif p>0:
        return 1
    else:
        return 0
N=int(input())
a=[int(i) for i in input().split()]
m=[0,0]
for sgn in [-1,1]:
    x=0
    S=0
    for i in range(N):
        S+=a[i]
        if sign(S)==sgn*(-1)**(i%2) or sign(S)==0:
            x+=abs(S)+1
            S=sgn*(-1)**((i+1)%2)
    m[(sgn+1)//2]=x
print(min(m))


Measured memory_bytes: 14468
# coding: utf-8
# Here your code !
n=int(input())
A=[int(i) for i in input().split()]
q=int(input())
m=[int(i) for i in input().split()]


from itertools import combinations
x=[]
for i in range(len(A)):
    t=(list(combinations(A,i)))
    x.append(t)
combi=set()
for i in x:
    for j in i:
        combi.add(sum(j))

for i in m:
    if i in combi:
        print("yes")
    else:
        print("no")

Measured memory_bytes: 150740