akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
#define pb push_back

using namespace std;
typedef long long ll;
bool used[100005], FL = false;
int col[100005];
vector <pair <int, int> > g[100005], obr[100005];
queue <int> q;
set <int> opa;
int rasst[100005];

void finds(int v)
{
    col[v] = 1;
    for (int i = 0; i < (int) g[v].size(); i++)
    {
        int u = g[v][i].x;
        if (col[u] == 0) finds(u);
        else if (col[u] == 1) FL = true;
    }
    col[v] = 2;
    return;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int l, r, d;
        cin >> l >> r >> d;
        g[r].pb(mp(l, d));
        obr[l].pb(mp(r, d));
    }

    for (int i = 1; i <= n; i++)
        if (col[i] == 0) finds(i);

    if (FL) cout << "No", exit(0);

    for (int i = 1; i <= n; i++)
        if ((int) g[i].size() == 0) opa.insert(i);

    while (!opa.empty())
    {
        int v = *opa.begin();
        opa.erase(v);
        used[v] = true;
        q.push(v);
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (int i = 0; i < (int) g[u].size(); i++)
            {
                int z = g[u][i].x, c = g[u][i].y;
                if (!used[z])
                {
                    used[z] = true;
                    rasst[z] = rasst[u] - c;
                    q.push(z);
                }
                else
                {
                    if (rasst[z] != rasst[u] - c) cout << "No", exit(0);
                }
                if (opa.find(z) != opa.end()) opa.erase(z);
            }
            for (int i = 0; i < (int) obr[u].size(); i++)
            {
                int z = obr[u][i].x, c = obr[u][i].y;
                if (!used[z])
                {
                    used[z] = true;
                    rasst[z] = rasst[u] + c;
                    q.push(z);
                }
                else
                {
                    if (rasst[z] != rasst[u] + c) cout << "No", exit(0);
                }
                if (opa.find(z) != opa.end()) opa.erase(z);
            }
        }
    }
    cout << "Yes";
    return 0;
}



Measured memory_bytes: 15872
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    s=input()
    len_s=len(s)
    sc=list(Counter(s).items())
    sc.sort(key=itemgetter(1),reverse=True)
    if sc[0][1]==1:
        print(len_s//2)
        sys.exit()
    ans=100
    for scc in sc:
        dp=[[False]*len_s for _ in range(len_s)]
        for i,ss in enumerate(s):
            if ss==scc[0]:
                dp[0][i]=True
        dp[1][-1]=True
        for sosa in range(len_s):
            if all(dp[sosa]):
                ans=min(ans,sosa)
                break
            for i in range(len_s-1,-1,-1):
                if dp[sosa][i]==True:
                    dp[sosa+1][i]=True
                    if i>0:dp[sosa+1][i-1]=True
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 41836
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n,w;
    cin>>n>>w;
    vector<vector<long long>> dp(n+1,vector<long long>(w+1,0));
    for(int i=1;i<=n;i++){
        long long w1,v;
        cin>>w1>>v;
        for(int j=1;j<=w;j++){
            if(j-w1>=0){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w1]+v);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<"\n";
    return(0);
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


signed main(){
  ll n, y;
  cin >> n >> y;
  for(ll i = 0; i <= n; i++){
    for(ll j = 0; j <= n-i; j++){
      ll k = n-(j+i);
      if(i*10000 + j*5000 + k*1000 == y){
        printf("%d %d %d\n",i,j,k);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 100010;
const int INF = INT_MAX/2;

char x;

int32_t main(){
	cin >> x;
	if (x >= 'A' and x <= 'Z') cout << "A";
	else cout << "a";
	
}









Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef vector<long long int> VI;

int main(void) {
    long long int n;
    cin >> n;
    VI a(n);
    long long int total = 0;
    for (long long int i = 0; i < n; i++) {
        cin >> a[i];
        total += a[i];
    }

    long long int div;
    long long int left = 0;
    long long int right = total;
    for (long long int i = 0; i < n - 1; i++) {
        left += a[i];
        right -= a[i];
        //cout << left << " " << right << endl;

        long long int temp = right - left;
        if (temp < 0) {
            temp *= (-1);
        }
        if (i == 0) {
            div = temp;
        } else {
            div = min(temp, div);
        }

    }
    cout << div << endl;
    return 0;
}




Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int a[100], i, n;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (i = n-1; i >= 0; i--){
		printf("%d", a[i]);
		if (i != 0){
			putchar(' ');
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2728
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int Mod=1000000007;
int H;
#define Maxn 1000010
#define V 6000010
struct Node{
	int son[2],sum;
}tree[V];
int root[Maxn],cnt=0;
int val[Maxn],inval[Maxn],P[Maxn];
int inv[Maxn],L[Maxn],R[Maxn],invval[Maxn];
int pig[Maxn];
void dfs(int u){
	L[u]=R[u]=u;
	if(u*2<(1<<H)){
		val[u*2]=1ll*val[u]*(u*2)%Mod;
		invval[u*2]=1ll*invval[u]*inv[u*2]%Mod;
		dfs(u*2);
		L[u]=L[u*2];
	}
	if(u*2+1<(1<<H)){
		val[u*2+1]=1ll*val[u]*(u*2+1)%Mod;
		invval[u*2+1]=1ll*invval[u]*inv[u*2+1]%Mod;
		dfs(u*2+1);
		R[u]=R[u*2+1];
	}
}
void Insert(int &k,int x,int num,int add,int at){
	k=++cnt;
	tree[k]=tree[x];
	tree[k].sum+=add;if(tree[k].sum>=Mod)tree[k].sum-=Mod;
	if(at==-1)return;
	if(num&(1<<at))Insert(tree[k].son[1],tree[x].son[1],num,add,at-1);
	else Insert(tree[k].son[0],tree[x].son[0],num,add,at-1);
}

int main(){
	invval[0]=1;
	val[1]=1;invval[1]=1;
	scanf("%d",&H);
	inv[0]=inv[1]=1;
	for(int i=2;i<(1<<H);++i)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	dfs(1);
	for(int i=1;i<=(1<<(H-1));++i){
		scanf("%d",&P[i]);
		pig[i]=1ll*val[i+(1<<(H-1))-1]*val[P[i]+(1<<(H-1))-1]%Mod;
		Insert(root[i],root[i-1],P[i]+(1<<(H-1))-1,pig[i],H-2);
	}
	int Ans=0;
	for(int i=1;i<=(1<<(H-1));++i){
		int x=i+(1<<(H-1))-1,y=P[i]+(1<<(H-1))-1;
		for(int ancx=(x>>1),pre=x;ancx;pre=ancx,ancx>>=1){
			int k1,k2;
			if(pre==ancx*2){
				int tmpl=L[pre+1]-(1<<(H-1)),tmpr=R[pre+1]-(1<<(H-1))+1;
			    k1=root[tmpl],k2=root[tmpr];
			}else{
				int tmpl=L[pre-1]-(1<<(H-1)),tmpr=R[pre-1]-(1<<(H-1))+1;
				k1=root[tmpl],k2=root[tmpr];
			}
			int ancy=1,dir,tmp,tok1,tok2;
			int z=1ll*invval[ancx]*invval[ancx>>1]%Mod;
			for(int k=1;k<H;++k){
				int invz=1ll*z*invval[ancy]%Mod*invval[ancy>>1]%Mod;
				tmp=ancy*2;
				if(L[tmp]<=y&&y<=R[tmp])dir=0;
				else dir=1;
				if(dir==0){
				    tok1=tree[k1].son[1];tok2=tree[k2].son[1];
					Ans=(Ans+1ll*(tree[tok2].sum-tree[tok1].sum+Mod)*pig[i]%Mod*invz)%Mod;
					k1=tree[k1].son[0];k2=tree[k2].son[0];ancy=ancy*2;
				}else{
					tok1=tree[k1].son[0];tok2=tree[k2].son[0];
					Ans=(Ans+1ll*(tree[tok2].sum-tree[tok1].sum+Mod)*pig[i]%Mod*invz)%Mod;
					k1=tree[k1].son[1];k2=tree[k2].son[1];ancy=ancy*2+1;
				}
			}
		}
	}
	if(Ans%2==0)Ans/=2;
	else Ans=(Ans+Mod)/2;
	printf("%d\n",Ans);
	return 0;
}

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

typedef complex<double> P;

// ティツィツアテ・ツョツケテ」ツ?凖」ツつ凝ィツェツ、テ・ツキツョテ篠オ
#define EPS (1e-10)
// 2テ」ツ?、テ」ツ?ョテ」ツつケテ」ツつォテ」ツδゥテ」ツδシテ」ツ?古ァツュツ嘉」ツ?療」ツ??」ツ?凝」ツ?ゥテ」ツ??」ツ??
#define EQ(a,b) (abs((a)-(b)) < EPS)

// テ・ツ、ツ姪ァツゥツ?(cross product) : aテδ傭 = |a||b|sinテ篠?
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

// 2テァツ崢エテァツキツ堙」ツ?ョテ・ツケツウティツ。ツ古・ツ按、テ・ツョツ?: a//b <=> cross(a, b) = 0
int is_parallel(P a1, P a2, P b1, P b2) {
  return EQ( cross(a1-a2, b1-b2), 0.0 );
}

int main(){
	int n;
	double x1,x2,x3,x4,y1,y2,y3,y4;

	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		P a(x1,y1), b(x2,y2), c(x3,y3), d(x4,y4);
		if( is_parallel(a,b,c,d) ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

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


int main() {
  int n;
  cin>>n;
  vector<long long>a(n+1);
  a.at(0)=2;
  a.at(1)=1;
  for(int i=0;i<n-1;i++){
    a.at(i+2)=a.at(i+1)+a.at(i);
  }
  cout<<a.at(n)<< endl;
}
  
  
  
  


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            int cy = 0, cx = 0,ct =0;
            for (int i = 0; i < N; i++)
            {
                string[] p = Console.ReadLine().Split(' ');
                int t = int.Parse(p[0]);
                int x = int.Parse(p[1]);
                int y = int.Parse(p[2]);

                var d = Math.Abs(cy - y) + Math.Abs(cx - x);
                if(t - ct - d >= 0 && (t - ct - d) % 2 == 0)
                {

                }
                else
                {
                    Console.WriteLine("No");
                    return;
                }

                cx = x;
                cy = y;
                ct = t;
            }
            Console.WriteLine("Yes");
        }
    }
}


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

int main() {
  string s;
  cin >> s;
  
  bool ok = true;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && s.at(i) == 'L') {ok = false;}
    if (i % 2 == 1 && s.at(i) == 'R') {ok = false;}
  }
  
  if (ok) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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;}


signed main(void) {
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u){
        cout << a-1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }

}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll         long long
#define max(a,b)    (a>b?a:b)
#define min(a,b)    (a<b?a:b)
#define endl        '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


signed main(){
    FAST
	ll int a,b,c,k,max_card=0;
    cin>>a>>b>>c>>k;
    if(a>=k) {
        a=k;
        k=0;
    }
    else{
        k=k-a;
    }
    if(b>=k){
         b=k;
         k=0;
         }
    else k=k-b;
    cout<<a*1+b*0+k*(-1)<<endl;


}

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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

main(){
  int a=in(),b=in();
  if (b%a==0) cout << a+b << endl;
  else cout << b-a << 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);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int n = 0;
		int m = 0;
		for(int x=0;b>x;x++){
			int v= (int)Math.pow(10, x);
			n=n+a*v;
		}
		for(int y=0;a>y;y++){
			int z=(int)Math.pow(10, y);
			m=m+b*z;
		}

		if(Integer.compare(n, m)==-1){
			System.out.println(m);
		}else{
			System.out.println(n);
		}
	}

}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}



int main(void)
{
  string w;
  cin >> w;
  map<char, int> mp;
  REP(i, w.size()) mp[w[i]] ++;
  bool ok = true;
  for(auto v:mp) {
    //    cout << v.first << v.second << endl;
    if(v.second % 2 == 1) ok = false;
  }
  cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b,&c);
	int x = c - (a-b);
	if (x >= 0)
		printf("%d\n",x);
	else
		printf("0\n");
	return(0);
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

template <class T = int>
T in() { T x; std::cin >> x; return x; }
#define output(e) std::cout << e << '\n'

#ifdef LOCAL
#define db std::cout << "L" << __LINE__
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif

//
// Implementation
//

int main() {
  int a = in();
  int b = in();
  int N = in();

  rep(i, N) {
    int s = in();
    int e = in();
    if (e > a && s < b) {
      output("1");
      return 0;
    }
  }
  output("0");
}



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

int main(void) {
    long long x;
    cin >> x;
    long long ans;
    
    if(x % 11 > 6) {
        ans = x / 11 * 2 + 2;
    }
    else if(x % 11 != 0) {
       ans = x / 11 * 2 + 1;
    }
    else    ans = x / 11 * 2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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 count = 0;
  for(int i = 0; i < N - 2; i++){
    for(int j = i + 1; j < N - 1; j++){
      for(int k = j + 1; k < N; k++){
        if(L.at(i) + L.at(j) > L.at(k)){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
const int INF = 1e9;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(a%b, b);
}
int main() {
    int n;
    cin >> n;
    ll a[n];
    ll ans = 0;
    REP(i, n) cin >> a[i];
    ll l[n], r[n];
    l[0] = a[0];
    r[n-1] = a[n-1];
    FOR(i, 1, n) {
        l[i] = gcd(l[i-1], a[i]);
    }
    RFOR(i, n-2, 0) {
        r[i] = gcd(r[i+1], a[i]);
    }
    REP(i, n) {
        ll t;
        if(i == 0) t = r[1];
        else if(i == n-1) t = l[n-2];
        else t = gcd(l[i-1], r[i+1]);
        ans = max(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int res = a * x + b * y;
  res = min(res, (c * 2) * max(x, y));
  res = min(res, min(x, y) * 2 * c + a * (x - min(x,y)) + b * (y - min(x, y)));
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] s = in.nextLine().split("");
		String[] t = in.nextLine().split("");
		
		Arrays.parallelSort(s);
		Arrays.parallelSort(t, Collections.reverseOrder());
		
		String newS = String.join("", s);
		String newT = String.join("", t);
		
		System.out.println(newS.compareTo(newT) < 0 ? "Yes" : "No");
		
		/*if (newS.equals(newT)) {
			System.out.println("No");
		} else {
			System.out.println(newS.compareTo(newT) <= 0 ? "Yes" : "No");
		}
		*/
	}

}

Measured memory_bytes: 35988
n=int(input())
a=list(map(int,input().split()))
k=sum(a)
if n==0:
    print(1 if a[0]==1 else -1)
    exit()
ans=1
e=1
for i in range(n):
    e-=a[i]
    k-=a[i]
    if e<0:
        print(-1)
        exit()
    elif e==0 and k>0:
        print(-1)
        exit()
    if 2*e<k:
        e*=2
    elif e<k:
        e=k
    #print("e",e)
    ans+=e
print(ans if e==k else -1)

Measured memory_bytes: 83372
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string str;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> str >> str;
	cout << 'A' << str[0] << "C\n";
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::Reverse;

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        w: usize,
        items: [(usize, usize); n],
    }

    let mut dp = vec![vec![0; w + 1]; n];
    for j in items[0].0..=w {
        dp[0][j] = items[0].1;
    }
    for i in 1..n {
        for j in 0..=w {
            if j < items[i].0 {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = dp[i - 1][j].max(dp[i - 1][j - items[i].0] + items[i].1);
            }
        }
    }
    println!("{}", dp[n - 1][w]);
}


Measured memory_bytes: 80288
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int N, n[3];
  cin >> N;
  for (int i; i < N; i++) {
    rep(i, 3) cin >> n[i];
    sort(n, n + 3);
    if (n[0] * n[0] + n[1] * n[1] - n[2] * n[2] == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3056
fun main(args: Array<String>) {
    abc149d()
}

fun abc149d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val points = readLine()!!.split(' ').map { it.toInt() }
    val t = readLine()!!.map {
        when (it) {
            'r' -> 2
            's' -> 0
            else -> 1
        }
    }.toIntArray()

    val dp = Array(n) { 0 to -1 }
    dp[0] = points[t[0]] to t[0]

    for (i in 1 until n) {
        val win = t[i]

        if (i + 1 <= k || dp[i - k].second != win) {
            dp[i] = dp[i - 1].first + points[win] to win
        } else {
            dp[i] = dp[i - 1].first to -1
        }
    }

    val answer = dp.last().first

    println(answer)
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

int main() {
	fastio();
	
	LL n;
	cin >> n;

	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e;
	}

	LL net_gcd = a[0];
	for (LL i = 1; i < n; ++i) {
		net_gcd = __gcd(net_gcd, a[i]);
	}

	if (net_gcd != 1) {
		cout << "not coprime\n";
		return 0;
	}
	vector<LL> primes (N, 0);
	for (LL i = 0; i < n; ++i) {
		LL x = a[i];

		for (LL j = 2; j*j <= x; ++j) {
			if (x % j == 0) {
				while (x % j == 0) x /= j;
				primes[j]++;
			}
		}
		if (x > 1) {
			primes[x]++;
		}
	}

	for (auto e : primes) {
		if (e > 1) {
			cout << "setwise coprime\n";
			return 0;
		}
	}
	cout << "pairwise coprime\n";

	return 0;

}

Measured memory_bytes: 18756
n, m = map(int, input().split())
s = []
for i in range(m):
    l = input().split()
    s.append(list(map(int, l[1::])))
p = list(map(int, input().split()))

ans = 0
for i in range(0,2**n):
	bi_str = format(i, '0'+str(n)+'b')
	#print(bi_str)
	flag = True
	for j in range(len(s)):
		#print(s[j])
		switch = 0
		for x in s[j]:
			if bi_str[x-1] == str(1):
				switch += 1
		#print(switch)
		#print(p[j])

		if switch%2 != p[j]:
			flag = False
	if flag:
		ans += 1

print(ans)



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

int main() {
  int N, 
      K,
      x = 0,
      sum = 0;
  
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (K - x > x) {
      sum += x * 2;
    } else {
      sum += (K - x) * 2;
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys
 
import numba as nb
import numpy as np
 
input = sys.stdin.readline
 
 
@nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
    dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
    dp[:, 0] = 0
    for i in range(N):
        np.minimum(w[i], dp[i][:v[i]], dp[i + 1][:v[i]])
        np.minimum(w[i] + dp[i][: - v[i]], dp[i][v[i]:], dp[i + 1][v[i]:])
    return np.where(dp[-1] <= W)[0][-1]
 
 
def main():
    N, W = map(int, input().split())
 
    w = np.empty(shape=N, dtype=np.int64)
    v = np.empty(shape=N, dtype=np.int64)
    for i in range(N):
        w[i], v[i] = map(int, input().split())
 
    ans = solve(N, W, w, v)
    print(ans)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 198100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl X(N);
    rep(i, N) cin >> X[i];

    ll ans = INF;

    rep(x,101){
        ll tmp = 0;
        rep(i,N){
            tmp += (X[i] - x) * (X[i] - x);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(string S) {
    vector<bool> isin(26, true);
    for (int i = 0; i < S.size(); i++) {
        isin[S[i] - 'a'] = false;
    }
    bool flag = false;
    for (int i = 0; i < 26; i++) {
        if (isin[i]) {
            std::cout << (char) ('a' + i) << std::endl;
            flag = true;
            break;
        }
    }
    if (not flag) {
        std::cout << "None" << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    string S;

    gettimeofday(&start,NULL);

    std::cin >> S;
    solve(S);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<iomanip>
#define M_PI 3.14159265358979323846
using namespace std;
struct point {
	double x, y;
};

void draw(int n, point lo, point hi) {
	if (n == 0) return;
	point a, b, c;
	double sixty = M_PI / 3.0;
	a.x = (2.0 * lo.x + hi.x) / 3.0;
	a.y = (2.0 * lo.y + hi.y) / 3.0;
	b.x = (2.0 * hi.x + lo.x) / 3.0;
	b.y = (2.0 * hi.y + lo.y) / 3.0;
	c.x = (b.x - a.x)*cos(sixty) - (b.y - a.y)*sin(sixty) + a.x;
	c.y = (b.x - a.x)*sin(sixty) + (b.y - a.y)*cos(sixty) + a.y;

	draw(n - 1, lo, a);
	cout << a.x << " " << a.y << endl;
	draw(n - 1, a, c);
	cout << c.x << " " << c.y << endl;
	draw(n - 1, c, b);
	cout << b.x << " " << b.y << endl;
	draw(n - 1, b, hi);

	
}

int main() {
	int n;
	cin >> n;
	cout << fixed << setprecision(8);
	point lo;
	point hi;
	lo.x = lo.y = hi.y = 0;
	hi.x = 100;
	cout << lo.x << " " << lo.y << endl;
	draw(n, lo, hi);
	cout << hi.x << " " << hi.y << endl;
	return 0;
}


Measured memory_bytes: 3304
#include <stdio.h>
int main(void){
    int n,i,x;
    scanf("%d",&n);
    
    for(i=1;i<=n;i++){
        x=i;
        if( x % 3 == 0 ){
            printf(" %d",i);
        }else{
            do{
                if( x % 10 == 3 ){
                    printf(" %d",i);
                    x=0;
                }
                x /= 10;
            }while( x );
        }
    }
    printf("\n");
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  int sum = 0;
  rep(i,n) {
    cin >> w[i];
    sum += w[i];
  }

  int ans = 10005;
  rep(i,n){
    if (i == 0) continue;
    int s1=0, s2;
    rep(j,i) s1 += w[j];
    s2 = sum - s1;
    ans = min(abs(s1-s2),ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int j = 0; j < N; j++){
      cin >> A[j];
    }
    string S;
    cin >> S;
    bool ok = true;
    for (int j = N - 1; j >= 0; j--){
      for (int k = N - 1; k > j; k--){
        A[j] = min(A[j], A[j] ^ A[k]);
      }
      if (S[j] == '1' && A[j] != 0){
        ok = false;
      }
    }
    if (ok){
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 3516
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <utility>
#include <iomanip>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>

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

using namespace std;


int main(){
    int A,B,C;
    cin>>A>>B>>C;
    
    int  a=B/A;
    
    if(a<C){
        cout<<a<<endl;
    }else{
        cout<<C<<endl;
    }

}

Measured memory_bytes: 3592
import sys

def main(lines):
  x1, y1, x2, y2 = map(int, lines[0].split())
  x3 = x2 + (y2 - y1) * -1
  y3 = y2 + (x2 - x1)
  x4 = x3 + (y3 - y2) * -1
  y4 = y3 + (x3 - x2)
  print(x3, y3, x4, y4)


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int k, n;
    cin >> k >> n;

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

    double min_len = k;
    rep(i,n) {
        if (i != 0) {
            if (abs(k + a[(n-1+i)%n] - a[i]) <= min_len) {
                min_len = abs(k + a[(n-1+i)%n] - a[i]);
            }
        }
        if (i == 0) {
            if (abs(a[n-1] - a[i]) <= min_len) {
                min_len = abs(a[n-1]-a[i]);
            }
        }
        // cout << (int)min_len << "koko" << endl;
    }
    cout << (int)min_len << endl;
}

Measured memory_bytes: 1024
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

struct Node {
  int key;
  struct Node *l, *r;
  Node(): l(NULL), r(NULL) {}
  Node(int _k): key(_k), l(NULL), r(NULL) {}
};

/* global variables */

/* subroutines */

void insert(Node *(&root), Node *z) {
  Node *y = NULL, *x = root;

  while (x != NULL) {
    y = x;
    if (z->key < x->key) x = x->l;
    else x = x->r;
  }

  if (y == NULL) root = z;
  else if (z->key < y->key) y->l = z;
  else y->r = z;
}

bool find(Node *root, int key) {
  Node *x = root;

  while (x != NULL) {
    if (key == x->key) return true;
    x = (key < x->key) ? x->l : x->r;
  }
  return false;
}

void inorder(Node *nd, vi &v) {
  if (nd != NULL) {
    inorder(nd->l, v);
    v.push_back(nd->key);
    inorder(nd->r, v);
  }
}

void preorder(Node *nd, vi &v) {
  if (nd != NULL) {
    v.push_back(nd->key);
    preorder(nd->l, v);
    preorder(nd->r, v);
  }
}

void print_vec(vi &v) {
  for (int i = 0; i < v.size(); i++) printf(" %d", v[i]);
  putchar('\n');
}

/* main */

int main() {
  Node *root = NULL;

  int m;
  cin >> m;

  while (m--) {
    string op;
    cin >> op;

    if (op[0] == 'i') {
      int key;
      cin >> key;
      insert(root, new Node(key));
    }
    else if (op[0] == 'f') {
      int key;
      cin >> key;
      cout << (find(root, key) ? "yes" : "no") << endl;
    }
    else {
      vi v;

      v.clear();
      inorder(root, v);
      print_vec(v);

      v.clear();
      preorder(root, v);
      print_vec(v);
    }
  }
  return 0;
}

Measured memory_bytes: 15644
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define dump(x) cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;

template<typename T>string join(vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream& operator<<(ostream& o, vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, vector<vector<T> >&vv)
{int l=vv.size();if(l){rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int N;
vi a, b;

int check(int cur, int pre){
    a[0] = pre; a[1] = cur;
    REP(i, 2, N+1) a[i] = a[i-2] ^ a[i-1] ^ b[i-1];
    a[N+1] = a[1]; a[0] = a[N];
    return !(a[0]^a[1]^b[1]^a[2] || a[N-1]^a[N]^b[N]^a[N+1]);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> N;
    string s;
    cin >> s;

    a = b = vi(N+2);
    rep(i, N) b[i+1] = (s[i] == 'o' ? 0 : 1);
    int found = 0;
    if(check(0,0)||check(1,0)||check(0,1)||check(1,1)) found = 1;
    if(!found){
        cout << -1;
    }else{
        REP(i, 1, N+1) cout << ((a[i]==0) ? "S" : "W");
    }
    cout << endl;
    return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;

  bool result = true;
  // odd
  for(int i=0; i < S.length(); i+=2){
    if(!(S[i] == 'R' || S[i] == 'U' || S[i] == 'D')){
      result = false;
    }
  }

  if(!result){
    cout << "No" << endl;
    return 0;
  }

  if(S.length() == 1){
    cout << "Yes" << endl;
    return 0;
  }

  // even
  for(int i=1; i < S.length(); i+=2){
    if(!(S[i] == 'L' || S[i] == 'U' || S[i] == 'D')){
      result = false;
    }
  }

  if(result){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int dp[1001][20001] = {};

int main() {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  int ma = 0;
  REP(i, n) {
    cin >> a[i] >> b[i];
    ma = max(ma, a[i]);
  }

  REP(i, n + 1) {
    FOR(j, 1, h + ma + 1) { dp[i][j] = 1e9; }
  }

  FOR(i, 1, n + 1) {
    FOR(j, 1, h + ma + 1) {
      dp[i][j] = dp[i - 1][j];
      if (j - a[i - 1] >= 0) {
        dp[i][j] = min(dp[i][j], dp[i][j - a[i - 1]] + b[i - 1]);
      }
      // cout << i << " " << j << " " << dp[i][j] << endl;
    }
  }
  int ans = 1e9;
  REP(i, n + 1) {
    FOR(j, h, h + ma + 1) { ans = min(ans, dp[i][j]); }
  }
  cout << ans << endl;
}


Measured memory_bytes: 77440
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int h, w, k;
   cin >> h >> w >> k;
   int ans = INF;
   vector<string> s(h);
   rep(i, 0, h) cin >> s[i];
   rep(div, 0, 1 << (h - 1)) {
      int g = 0;
      vector<int> id(h);
      rep(i, 0, h) {
         id[i] = g;
         if (div >> i & 1) g++;
      }
      g++;
      vector<vector<int>> c(g, vector<int>(w, 0));
      rep(i, 0, h) rep(j, 0, w) c[id[i]][j] += s[i][j] - '0';
      int num = g - 1;
      vector<int> now(g);
      auto add = [&](int j) {
         rep(i, 0, g) now[i] += c[i][j];
         rep(i, 0, g) if (now[i] > k) return false;
         return true;
      };
      rep(j, 0, w) {
         if (!add(j)) {
            num++;
            now = vector<int>(g);
            if (!add(j)) {
               num = INF;
               break;
            }
         }
      }
      ans = min(ans, num);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, b;
  cin >> a >> b;
  ll al = a.size(), bl = b.size();
  vector<vector<ll>> dp(al + 1, vector<ll>(bl + 1, INF));
  dp.at(0).at(0) = 0;
  for (ll i = 0; i < al; ++i) {
    for (ll j = 0; j < bl; ++j) {
      if (a.at(i) == b.at(j)) {
        dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i).at(j));
      }
      //削除・挿入
      dp.at(i + 1).at(j) = min(dp.at(i + 1).at(j), dp.at(i).at(j) + 1);
      dp.at(i).at(j + 1) = min(dp.at(i).at(j + 1), dp.at(i).at(j) + 1);
      //変更
      dp.at(i + 1).at(j + 1) = min(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1);

      dp.at(al).at(j + 1) = min(dp.at(al).at(j + 1), dp.at(al).at(j) + 1);
    }
    dp.at(i + 1).at(bl) = min(dp.at(i + 1).at(bl), dp.at(i).at(bl) + 1);
  }
  cout << dp.at(al).at(bl) << "\n";
  // for (ll i = 0; i <= al; ++i) {
  //   for (ll j = 0; j <= bl; ++j) {
  //     cout << dp.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
}



Measured memory_bytes: 10732
A, B = map(int, input().split())
lst = [['#' for j in range(100)] for i in range(50)] + [['.' for j in range(100)] for i in range(50)]
for i in range(A-1):
    a, b = divmod(i, 50)
    lst[a*2][b*2] = '.'
for i in range(B-1):
    a, b = divmod(i, 50)
    lst[-1-a*2][-1-b*2] = '#'
print(100, 100)
for j in lst:
    print(''.join(j))

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



int main()
{
    string s;
    cin >> s;
    int onecount = 0;
    int zerocount = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] == '0'){
            zerocount++;
        }
        else{
            onecount++;
        }
    }
    cout << 2 * min(zerocount, onecount) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

vector<int> fact(1, 1), fact_inv(2, 1);

int comb(int N, int k){
//	printf("comb(%lld, %lld)\n", N, k);
	if(k < 0 || N < k || N < 0){
		return 0;
	}
	else{
		return MOD(fact[N] * MOD(fact_inv[k] * fact_inv[N - k]));
	}
}

int calc(int N, int K){
//	printf("calc(%lld, %lld)\n", N, K);
	return MOD(comb(N + K, N) - comb(N + K, K - 1));
}

signed main(){
	int N, M, K, i;
	scanf("%lld%lld%lld", &N, &M, &K);
	int u = N + M + 2 * K;
	for(i = 1; i <= u; i++){
		fact.push_back(MOD(i * fact[i - 1]));
	}
	for(i = 2; i <= u; i++){
		fact_inv.push_back(MOD(-(p / i) * fact_inv[p % i]));
	}
	for(i = 1; i <= u; i++){
		fact_inv[i] = MOD(fact_inv[i] * fact_inv[i - 1]);
	}
	int ans = 0;
	for(i = 0; i <= K; i++){
//		printf("i = %lld\n", i);
		ans = MOD(ans + comb(N + M + 2 * K, N + 2 * i) * MOD(calc(N + i, i) * calc(M + K - i, K - i)));
//		printf("ans = %lld\n", ans);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 7564
import sys

s = 'abcdefghijklmnopqrstuvwxyz.?! '
d = {}
for y in range(1, 7):
    for t in range(1, 6):
        d[(str(y),str(t))] = s[0]
        s = s[1:]

for line in sys.stdin:
    line = line.rstrip()
    if len(line) == 0 or len(line) % 2 != 0:
        print 'NA'
        continue
    ans = ''
    for i in range(0, len(line), 2):
        if (line[i],line[i+1]) in d:
            ans += d[(line[i],line[i+1])]
        else:
            print 'NA'
            break
    else:
        print ans

Measured memory_bytes: 4236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x,ans=0;
int n,num[15];
void dfs(int pos,ll sum){
	if(pos==n+1) {
		ans+=sum;return;
	}
	ll tmp=0;
	for(int i=pos;i<=n;i++)tmp=tmp*10+num[i],dfs(i+1,sum+tmp);
}
int main(){
	cin>>x;
	while(x)num[++n]=x%10,x/=10;
	reverse(num+1,num+n+1);
	dfs(1,0);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define LL long long
#define mo 1000000007
#define M 1048580
#define N 21
using namespace std;
int f[N][M];
int n,m,l,a[N][N],cf[N],qs[M][N][2];
int main()
{
	cin>>n>>m>>l;
	memset(a,255,sizeof(a));
	cf[0]=1;
	fo(i,1,n) cf[i]=cf[i-1]*2;
	fo(i,1,l)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		a[x][y]=z;
	}
	n--;
	fo(c,0,cf[n]-1)
	{
		int w1=0,w2=0;
		fod(i,n,0)
		{
			qs[c][i][0]=w1,qs[c][i][1]=w2;
			if(i>0)
			{
				if(c&cf[i-1]) w2=i;
				else w1=i; 
			}
		}
	}
	f[0][0]=1;
	LL ans;
	fo(i,1,m)
	{
		fo(j,0,n-1)
		{
			fo(c,0,cf[n]-1)
			{
				if(!f[j][c]) continue;
				int p=qs[c][j][0];
				if(p&&p<=n)
				{
					fo(k,j+1,p-1) 
					{
						if(a[i][k]==0) 
						{
							f[j][c]=0;
							break;
						} 
					}
					if(a[i][p]!=1) 
					{
						(f[p][c]+=f[j][c]);
						if(f[p][c]>=mo) f[p][c]-=mo;
					}
					if(a[i][p]!=0) 
					{
						int q=qs[c][p][1];
						if(q&&q<=n) 
						{
							int v=(c|cf[p-1])-cf[q-1];
							(f[p][v]+=f[j][c]);
							if(f[p][v]>=mo) f[p][v]-=mo;
						}
						else 
						{
							int v=c|cf[p-1];
							(f[p][v]+=f[j][c]);
							if(f[p][v]>=mo) f[p][v]-=mo;
						}
					}
				}
				else 
				{
					fo(k,j+1,n) 
					{
						if(a[i][k]==0) 
						{
							f[j][c]=0;
							break;
						} 
					}
					(f[n][c]+=f[j][c]);
					if(f[n][c]>=mo) f[n][c]-=mo;
				}
				f[j][c]=0;
			}
		}
		if(i==m)
		{
			ans=0;
			fo(c,0,cf[n]-1) (ans+=f[n][c])%=mo;
		}
		else
		fo(c,0,cf[n]-1)
		{
			f[0][c]=f[n][c];
			f[n][c]=0;
		}
	}
	printf("%lld\n",ans);
}

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

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

    int h,w,k;
    cin >> h >> w >> k;

    vector<vector<char>> board(h,vector<char>(w));
    vector<int> num(h);
    vector<vector<int>> ans(h,vector<int>(w));

    rep(i,h){
        rep(j,w) {
            cin >> board[i][j];
            if(board[i][j] == '#') num[i]++;
        }
    }

    int cnt = 1;
    for(int i = 0; i < h; i++){
        if(i != 0 && num[i]) cnt = ans[i-1][w-1] + 1;
        bool first = false;
        for(int j = 0; j < w; j++) {
            if(num[i] == 0 && i != 0) {
                ans[i][j] = ans[i-1][j];
            } else if(num[i] == 0) {
                ans[i][j] = 0;
            } else {
                if(board[i][j] == '#' && first) cnt++;
                else if(board[i][j] == '#' && !first) first = true;
                ans[i][j] = cnt;
            }
        }
    }

    for(int i = h - 2; i >= 0; i--){
        for(int j = 0; j < w; j++){
            if(ans[i][j] == 0){
                ans[i][j] = ans[i+1][j];
            }
        }
    }

    for(int i = 1; i < h; i++){
        for(int j = 0; j < w; j++){
            if(ans[i][j] == 0) ans[i][j] = ans[i-1][j];
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include <stdio.h>

int main (){
	int W,H,x,y,r;
	scanf ("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)printf ("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 2144
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
using namespace std;
typedef pair<int,int> p;
typedef unsigned long long ll;

ll gcd(ll a,ll b){
	if(b==0)return a;
	else return gcd(b,a%b);
}

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

int main(){
	int n;
	cin>>n;
	ll t;
	ll ans=1;
	rep(i,n){
		cin>>t;
		ans=lcm(ans,t);
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#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;}

int main() {
    int k,q;
    cin >> k >> q;
    array<ll,5000> d;
    for (int i = 0;i < k;++i) cin >> d[i];
    while (q--) {
        ll n,x,m;
        cin >> n >> x >> m;
        n--;
        x %= m;
        ll sum = 0,z = 0,ans = n;
        for (int i = 0;i < k;++i) sum += d[i]%m;
        for (int i = 0;i < k;++i) if (d[i]%m == 0) z++;
        ll a = (n/(m*k))*sum%mod,b = (n/(m*k))*m%mod*z%mod;
        n %= m*k;
        (a += (x+(n/k)*sum)/m) %= mod;
        (b += (n/k)*z) %= mod;
        (ans -= a+b) %= mod;
        (ans += mod*2) %= mod;
        (x += sum*(n/k)) %= m;
        n %= k;
        for (int i = 0;i < n;++i) {
            if (x >= (x+d[i])%m) ans--;
            x = (x+d[i])%m;
        }
        cout << (ans+mod)%mod << "\n";
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string qw = "qwertasdfgzxcvb";
  
  string query;
  while(cin >> query && query != "#") {
    bool isL = qw.find(query[0]) != string::npos;
    int N = query.size();
    int ans = 0;
    for(int i=1; i<N; i++) {
      if((qw.find(query[i])!=string::npos) ^ isL) {
	ans ++;
	isL = !isL;
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n-1]-a[0]);
	}
}

Measured memory_bytes: 23380
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

INF = 10**9+7

if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    ans = 0
    for i in range(1,n):
        if a[i-1] > a[i]:
            ans += a[i-1] - a[i]
            a[i] += a[i-1] - a[i] 
    print(ans)


Measured memory_bytes: 94256
#backfront
N=int(input())
lists=[]
for _ in range(N):
    x=int(input())
    lists.append((_,x))
lists.sort(key=lambda x:x[1])
lists.append((-10000000000000000,"end"))

cnt=0
now=-1
maxi=0
for i in range(N+1):
    p=lists[i][0]
    if now<p:
        cnt+=1
        now=p
    elif now>p:
        maxi=max(maxi,cnt)
        cnt=1
        now=p
print(N-maxi)

Measured memory_bytes: 72920
#include<stdio.h>
int main ()
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF)
	{
		int m;
		m=(a+b)<(a+c)?(a+b):(a+c);
		m=m<(b+c)?m:(b+c);
		printf("%d\n",m);
	}
} 

Measured memory_bytes: 128