akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

long long calc(long long A, long long B, long long x){
  return (long long)(A*x)/B - A*(x/B);
}

int main(){
  long long A, B, N;
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%lld", &N);
  long long ans;
  if (N>=B-1){
    ans = calc(A, B, B-1);
  } else {
    ans = calc(A, B, N);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    uint_fast64_t i(0), ans(0);
    for(auto c : s){
        if(c == 'W')ans += i;
        else ++i;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    string s, t; cin >> s >> t;
    
    for(int i=0;i<s.size();i++){
        if (s != t) {
            char tmp;
            for (int i=s.size()-1;i>=0;i--){
                if (i == s.size()-1) {
                    tmp = s[s.size()-1];
                    continue;
                }

                s[i+1] = s[i];

                if (i == 0){
                    s[0] = tmp;
                }
            }
        } else {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN=2005,MOD=1e9+7;
int n,k,fac[MAXN*MAXN],inv[MAXN*MAXN],dp[MAXN];

ll quick_pow(ll a,ll b)
{
	ll ret=1;
	for(;b;b>>=1,a=a*a%MOD)
		if(b&1) ret=ret*a%MOD;
	return ret;
}
ll C(int a,int b)
{if(a<b) return 0;return 1ll*fac[a]*inv[a-b]%MOD*inv[b]%MOD;}

int main()
{
	scanf("%d%d",&n,&k);
	if(k==1) return puts("1"),0;
	fac[0]=dp[0]=1;
	for(int i=1;i<=n*k;i++) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[n*k]=quick_pow(fac[n*k],MOD-2);
	for(int i=n*k-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%MOD;
	
	for(int i=0;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			dp[j]=(dp[j-1]*C(i+(k-1)*j-1,k-2)%MOD+dp[j])%MOD;
	
	ll res=1ll*dp[n]*fac[n]%MOD;
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 31616
using System;

class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());

		string[] a = Console.ReadLine().Split(' ');

		int result = 0;
		for(int i = 0;i < N; i+=2)
        {
			if (int.Parse(a[i]) % 2 ==  1)
            {
				result++;
            }
        }

		Console.WriteLine(result);
	}

}

Measured memory_bytes: 27540
#include <iostream>
#include <stdio.h>
using namespace std;
#define MAX 100

int main()
{
  int is[MAX];
  int i, j,v,N;
  int count = 0;
  scanf("%d", &N);
      for (i = 0; i<N;i++)
	    scanf("%d", &is[i]);
        int a = 0;
  for(i = N-1;i>=a;a++)
  {
      int v;
      j = i-1;
      while(j>=a)
      {
          if (is[j]>is[j+1])
              {
                  v = is[j +1];
                  is[j+1] = is[j];
                  is[j] = v;
                  count++;
              }
          j--;
      }
  }
          for(int a = 0;a<N-1;a++)
              {printf("%d", is[a]);
              printf(" ");}
          printf("%d\n", is[N-1]);
          printf("%d\n", count);
  return 0;
} 


Measured memory_bytes: 3196
from math import factorial
mod = 10 ** 9 + 7
s = int(input())
n = s // 3

ans = 0
for i in range(1, n+1):
    a = s - 2 * i - 1 
    b = i - 1
    ans += factorial(a) // (factorial(b) * factorial(a - b))
    ans %= mod
print(ans)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const char M = '#';
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i,h) cin >> s[i];

    REP(i,h) REP(j,w) {
        if (s[i][j] == M) continue;
        int c = 0;
        FOR(y,i-1,i+2) FOR(x,j-1,j+2) {
            if (y < 0 || y >= h) continue;
            if (x < 0 || x >= w) continue;
            if (s[y][x] == M) c++;
        }
        s[i][j] = '0' + c;
    }

    REP(i,h) cout << s[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; } /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; } /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b)
{
	return *(char *)a - *(char *)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b)
{
	return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main(void)
{
	int n, k;
	scanf("%d %d", &n, &k);

	char s[n + 1];
	scanf("%s", s);

	int score = 0;
	rep(i, n - 1)
	{
		if (s[i] == s[i + 1])
			score++;
	}

	int ans = min(score + 2 * k, n - 1);
	printf("%d\n", ans);
	return 0;
}

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

int main() {
	int x, n;
	int diff[2];
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	vector<int> p(100);
	rep(i, n) {
		int pi;
		cin >> pi;
		p[pi]++;
	}
	int i;
	for (i = 0; i <= x; i++) {
		if (p[x - i] == 0) {
			cout << x - i << endl;
			return 0;
		}
		if (p[x + i] == 0) {
			cout << x + i << endl;
			return 0;
		}
	}
	for (int j = i; j <= 100; j++) {
		if (p[x + j] == 0) {
			cout << x + j << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-

n = int(input())

cnt = [[0]*10 for i in range(10)]
#print(cnt)

#先頭がi,末尾がjの数字のカウント: cnt[i][j]
for i in range(1, n+1):
    s = str(i)
    #print("---s: ", s)
    head = int(s[0])
    #print("head: ", head)
    tail = int(s[-1])
    #print("tail: ", tail)
    cnt[head][tail] += 1

#print(cnt)

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j]*cnt[j][i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n, m;
vector<int> v[8];
int ans = 0;

int main(){
  cin >> n >> m;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  vector<int> ord;
  rep(i, n-1) ord.push_back(i+1);
  do{
    int x = 0;
    for(int i = 0; i < n-1; i++){
      if(find(all(v[x]), ord[i]) != v[x].end()){
        x = ord[i];
      }else{
        break;
      }
      if(i == n-2) ans++;
    }
  }while(next_permutation(all(ord)));
  cout << ans <<endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s;cin>>s;
  vector<char> v;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B'){
      if(!v.empty())v.pop_back();
    }else{
      v.push_back(s[i]);
    }
  }
  for(int i=0;i<v.size();i++){
    cout<<v[i];
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            List<ClsInp> lstInp = new List<ClsInp>();
            for (int i = 0; i < iN; i++)
            {
                ClsInp oneUsr = new ClsInp();
                oneUsr.id = i;
                oneUsr.iA = int.Parse(System.Console.ReadLine().Trim());
                lstInp.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstInp.Sort(delegate (ClsInp mca1, ClsInp mca2) { return mca2.iA - mca1.iA; });    // iAの降順
            int iFisId = lstInp[0].id;
            int iSecId = lstInp[1].id;
            int iFisiA = lstInp[0].iA;
            int iSeciA = lstInp[1].iA;

            // 出力
            for (int i = 0; i < iN; i++)
            {
                if (i == iFisId)
                {
                    System.Console.WriteLine("{0}", iSeciA.ToString().Trim());
                }
                else
                {
                    System.Console.WriteLine("{0}", iFisiA.ToString().Trim());
                }
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 情報
        private class ClsInp
        {
            public int id { get; set; } = 0;
            public int iA { get; set; } = 0;
        }

}


Measured memory_bytes: 26940
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
 
//INSERT ABOVE HERE
signed main(){
  Int n,a,b,c;
  cin>>n>>a>>b>>c;
  vector<Int> l(n);
  for(Int i=0;i<n;i++) cin>>l[i];
  Int ans=1e9;
  function<void(Int, Int, Int, Int, Int)> dfs=
    [&](Int x,Int y,Int z,Int k,Int s){
      if(k==n){
        if(x!=0&&y!=0&&z!=0){
          Int t=s-30;
          t+=abs(x-a);
          t+=abs(y-b);
          t+=abs(z-c);
          chmin(ans,t);
        }
        return;
      }
      dfs(x,y,z,k+1,s);
      dfs(x+l[k],y,z,k+1,s+10);
      dfs(x,y+l[k],z,k+1,s+10);
      dfs(x,y,z+l[k],k+1,s+10);
    };
  dfs(0,0,0,0,0);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll, ll>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923
vi exist(1000005, 0);

vii dir = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

int main()
{
    ll tt = 1, n, m, k = 0, i, j, p, q;
    ll a, b, c, d, h, w, u, v, x, y, t = 0;
    ll ans = 0;

    ll l = 0, r = 0;
    bool poss = true;

    boost;
    string s; 

    time_t tic, toc;
    tic = clock();

    // cin >> tt;
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> h >> w >> k;
        ll x1, x2, y1, y2;
        
        cin >> x1 >> y1 >> x2 >> y2;
        x1--, x2--, y1--, y2--;

        vector<string> g(h);
        for(i = 0; i < h; i++){
            cin >> g[i];
        }

        vvi dist(h, vi(w, -1));
        dist[x1][y1] = 0;

        queue<pii> q;
        q.push({x1, y1});
        vvi done(h, vi(w, 0));
        while(!q.empty()){
            x = q.front().F;
            y = q.front().S;
            done[x][y] = 1;

            q.pop();

            loop(z, dir){
                for(l = 1; l <= k; l++){
                    int nx = x + z.F*l;
                    int ny = y + z.S*l;

                    if(nx < 0 or ny < 0 or nx >= h or ny >= w) break;
                    if(g[nx][ny] == '@') break;
                    if(done[nx][ny]) break;
                    if(dist[nx][ny] != -1) continue;

                    dist[nx][ny] = dist[x][y] + 1;
                    q.push({nx, ny}); 
                }
            }
        }

        cout << dist[x2][y2] << nl;
    }   
    // cerr << (clock() - tic*1.0) / CLOCKS_PER_SEC << nl;
    return 0;
}

Measured memory_bytes: 35476
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
 
//足したり引いたりすると勝手にmodをとってくれる
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
 
//コンビネーションのライブラリ
struct combination {
    //factのなかに階乗を求めている
    //ifactのなかに階乗逆元を求めている
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
 
int main(){
    int x, y;
    cin >> x >> y;
    
    //移動回数を求める
    //移動回数が３の倍数でないと不適である
    
    if ((x+y) % 3){
        cout << 0 << endl;
        return 0;
    }
    
    //到達目標は, x-n, y-n
    //(1,2) = (0, 1) + (1,1)
    //(2,1) = (1, 0) + (1,1)
    int n = (x+y) / 3;
    
    x -= n, y -= n;
    if (x < 0 || y < 0){
        cout << 0 << endl;
        return 0;
    }
    
    //長さ１の矢印を並べてゴールへ到達する経路数を求める
    //有名問題へ帰着させた
    //組み合わせの数を求める
    
    //combination の初期化を行う
    combination c(x+y);
    
    //答えは, x+y C xである
    mint ans = c(x+y, x);
    
    cout << ans.x << endl;
}

Measured memory_bytes: 10624
import scala.io.StdIn

object Main {

  def main(args: Array[String]) {
    val Array(a, b): Array[Int] = StdIn.readLine().split(" ").map(e => e.toInt)

    if (a <= 5) {
      println(0)
    } else if (a <= 12) {
      println(b / 2)
    } else {
      println(b)
    }

  }

}



Measured memory_bytes: 27340
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
map<PII, int> pti;
vector<PII> v[600010];
int dist[600010];
int tac;
priority_queue<PII> pq;
int main()
{
	scanf("%d%d",&n,&m);
	tac=n; 
	for (int i=0;i<m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--,y--,z--;
		if (!pti.count(MP(x,z)))
		{
			pti[MP(x,z)]=tac;
			v[tac].push_back(MP(x,0));
			v[x].push_back(MP(tac,1));
			tac++;
		}
		if (!pti.count(MP(y,z)))
		{
			pti[MP(y,z)]=tac;
			v[tac].push_back(MP(y,0));
			v[y].push_back(MP(tac,1));
			tac++;
		}
		int xi=pti[MP(x,z)],yi=pti[MP(y,z)];
		v[xi].push_back(MP(yi,0));
		v[yi].push_back(MP(xi,0));
	}
	for (map<PII, int>::iterator it=pti.begin();it!=pti.end();it++)
	{
		if (it==pti.begin()) continue;
		map<PII, int>::iterator jt=it; jt--;
		if (it->Fst.Fst==jt->Fst.Fst)
		{
			v[it->Snd].push_back(MP(jt->Snd,1));
			v[jt->Snd].push_back(MP(it->Snd,1));
		}
	}
	fill(dist,dist+tac,1e9);
	pq.push(MP(0,0));
	dist[0]=0;
	while (!pq.empty())
	{
		int y=-pq.top().Fst,x=pq.top().Snd;
		pq.pop();
		if (dist[x]!=y) continue;
		//cout <<x<<" "<<y<<" ##\n";
		if (x==n-1)
		{
			printf("%d",y);
			return 0;
		}
		for (int i=0;i<v[x].size();i++)
		{
			int xi=v[x][i].Fst,yi=v[x][i].Snd;
			if (dist[xi]<=y+yi) continue;
			if (!yi)
			{
				pq.push(MP(-y,xi));
				dist[xi]=y;
			}
			else
			{
				pq.push(MP(-(y+1),xi));
				dist[xi]=y+1;
			}
		}
	}
	printf("-1");
	return 0;
} 

Measured memory_bytes: 74484
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

#define INF 200000000

#include <cmath>
using namespace std;

int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

int main() {
    
    string s;
    cin >> s;
    
    char pre = s[0];

    for(auto i = 1; i< s.size();i++){
        if(pre == s[i]){
            cout << i-1 +1<< " " << i +1<< endl;
            return 0;
        }
        pre = s[i];
    }
    
    pre = s[1];
    char prepre = s[0];
    
    for(auto i = 2; i< s.size();i++){
        if(prepre == s[i]){
            cout << i-2 +1 << " " << i+1 << endl;
            return 0;
        }
        prepre = pre;
        pre = s[i];
    }
    
    
    
    cout << -1 << " " << -1 << endl;
    
    
    
    return 0;
    
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
class UnionFind {
  vector<int> p;
public:
  UnionFind (int n) : p(n, -1) {}
  int root(int x) {
    return p[x] < 0 ? x : p[x] = root(p[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};
double norm(double x, double y) { return sqrt(x*x+y*y); }
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<double> x(n),y(n);
  REP(i,n) cin >> x[i] >> y[i];
  vector<tuple<double,int,int>> e(m);
  REP(i,m) {
    int l,r;
    cin >> l >> r;
    --l; --r;
    double nlen = -norm(x[r]-x[l], y[r]-y[l]);
    e[i]=make_tuple(nlen,l,r);
  }
  SORT(e);
  UnionFind uf = UnionFind(n);
  double answer=0.0;
  REP(i,m) {
    double nlen;
    int l,r;
    tie(nlen, l, r) = e[i];
    if(!uf.unite(l,r)) answer-=nlen;
  }
  cout << fixed << answer << endl;
  return 0;
}

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

#define ll long long int
#define hell 998244353
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve(){
    ll n,W;
    cin>>n>>W;
    vi v(n),w(n);
    rep(i,0,n)
        cin>>w[i]>>v[i];
    ll dp[n+1][W+1];
    rep(i,0,n+1)
    {
        rep(j,0,W+1)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else if(w[i-1]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
        }
    }
    cout<<dp[n][W];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


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

const int MAX = 1e5;
const ll mod = 1e9 + 7;
ll white[MAX];
ll black[MAX];
bool vis[MAX];
vector<vector<int> > g(MAX);


void dfs(int u)
{
    vis[u] = true;
    white[u] = 1;
    black[u] = 1;

    for(unsigned int i=0; i<g[u].size(); i++){
        int v = g[u][i];
        if(vis[v] == false){
            dfs(v);
            white[u] = (white[u]%mod * (white[v]%mod + black[v]%mod)%mod)%mod;
            black[u] = (black[u]%mod * white[v]%mod)%mod;
        }
    }

    return;
}

int main()
{
    int n;
    cin >> n;
    for(int i=1; i<n; i++){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(0);
    cout << (white[0]%mod + black[0]%mod)%mod;
    return 0;
}


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

using namespace std;

struct edge
{
  int to, cost;
};

vector< edge > g[100000];
long long dist[100000];


void dfs1(int idx, int par)
{
  for(edge &e : g[idx]) {
    if(e.to == par) continue;
    dfs1(e.to, idx);
    dist[idx] = max(dist[idx], dist[e.to] + e.cost);
  }
}

int dfs2(int idx, int d_par, int par)
{
  vector< pair< int, int > > d_child;
  for(edge &e : g[idx]) {
    if(e.to == par) d_child.emplace_back(d_par + e.cost, e.to);
    else d_child.emplace_back(e.cost + dist[e.to], e.to);
  }
  sort(d_child.rbegin(), d_child.rend());
  int ret = d_child[0].first;
  for(edge &e : g[idx]) {
    if(e.to == par) continue;
    ret = max(ret, dfs2(e.to, d_child[d_child[0].second == e.to].first, idx));
  }
  return (ret);
}

int main()
{
  int N;
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int a, b, w;
    cin >> a >> b >> w;
    g[a].push_back((edge) {b, w});
    g[b].push_back((edge) {a, w});
  }

  if(N == 1) {
    cout << 0 << endl;
  } else if(N == 2) {
    cout << g[0][0].cost << endl;
  } else {
    int root = 0;
    for(int i = 0; i < N; i++) if(g[i].size() >= 2) root = i;
    dfs1(root, -1);
    cout << dfs2(root, 1333, 1333) << endl;
  }
}

Measured memory_bytes: 26556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		
		int[] ary = new int[5];
		int a = 0;
		
		for(int i=0;i<ary.length;i++) {
			ary[i] = scan.nextInt();
			
			if(ary[i] == 0) {
				a = i;
			}
		}
		
		System.out.println(a+1);
	}

}


Measured memory_bytes: 35696
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;
// 26
int main() {
    ll N;
    cin >> N;
    vector<char> name;
    while (N > 0) {
        ll c = N % 26L;
        if (c == 0) {
            c = 26;
            N -= 26;
        }
        name.push_back('a' + c - 1);
        N /= 26L;
    }
    reverse(name.begin(), name.end());
    for (char c : name) {
        cout << c;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3556
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA, datB, datC, datX, datY) = readLine.split(" ").map(_.toInt)
    // compare the cost for making each pizzas
    import math.min
    val cost2x2 = min((datA + datB), (datC * 2))
    val costA = min(datA, (datC * 2))
    val costB = min(datB, (datC * 2))
    val ans =
      if(datX > datY) datY * cost2x2 + (datX - datY) * costA
      else datX * cost2x2 + (datY - datX) * costB
    println(ans)
  }
}


Measured memory_bytes: 27324
# coding: utf-8
# 73
n = int(input())
def prime_factorize(n):
    a=[]
    while n%2 == 0:
        a.append(2)
        n //= 2
    f=3
    while f*f <= n:
        if n%f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(n,end='')
print(':',end=' ')
print(*prime_factorize(n))





Measured memory_bytes: 5600
#include<stdio.h>
int HammingNumbers(int n){
	int flag = 0;
	if (n == 1)return 1;
	while (n!=1) {
		if (n % 5 == 0) {
			n = n / 5;
		}
		else if (n % 3 == 0) {
			n = n / 3;
		}
		else if (n % 2 == 0) {
			n = n / 2;
		}
		else {
			return 0;
			break;
		}
	}
	return 1;
}

int main(void) {
	int count,m,n;
	int i;
	while (1) {
		scanf("%d",&m);
		if (m == 0) break;

		scanf("%d",&n);
		count = 0;
		for (i = m; i <= n; i++) {
			count += HammingNumbers(i);
		}
		printf("%d\n",count);
	}
	return 0;
}

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

def solver(d, v, a):
  a.append(v)
  if d == 10:
    return

  for i in range(-1, 2):
    add = (v % 10) + i;
    if add < 0 or 9 < add:
      continue
    solver(d + 1, v * 10 + add, a)

def main():
  k = int(input())

  a = []
  for i in range(1, 10):
    solver(1, i, a)
  a.sort();

  print(a[k - 1])

if __name__ == "__main__":
  main()


Measured memory_bytes: 19388
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	string s  = rstring;
	
	int ans;
	char last = ' ';
	foreach(c; s){
		if(last != c){
			ans += 1;
			last = c;
		}
	}
	ans.writeln;
	
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    ll x[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    ll ans=0;
    ll sum=0;
    for(int i=0;i<n-1;i++){
        sum+=modpow(i+1,MOD-2);
        sum%=MOD;
        ans+=sum*(x[i+1]-x[i]);
        ans%=MOD;
    }
    for(int i=1;i<n;i++){
        ans=(ans*i)%MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll pows(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>n;
ll mini=inf;
for(i=1;i<=sqrt(n);i++)
{
  if(n%i==0)
  {
  p=i-1;
  q=n/i-1;
  if(mini>p+q)
  {
    mini=p+q;
  }
  }
}
cout<<mini;
}


Measured memory_bytes: 256
n, m = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = [int(x) for x in range(n)]
        self.tree_size = [1 for _ in range(n)]

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

        if self.same(x_root, y_root):
            return

        if self.size(x_root) >= self.size(y_root):
            self.parent[y_root] = x_root
            self.tree_size[x_root] += self.tree_size[y_root]
        else:
            self.parent[x_root] = y_root
            self.tree_size[y_root] += self.tree_size[x_root]

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

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

    def same(self, x, y):
        if self.find(x) == self.find(y):
            return True
        else:
            return False


uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1, b-1)

# print([uf.size(i) for i in range(n)])
print(max([uf.size(i) for i in range(n)]))


Measured memory_bytes: 109444
fun main(args: Array<String>) {
  val (a1, a2, a3) = readInts()
  println(if (a1 + a2 + a3 >= 22) "bust" else "win")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 38176
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=9223372036854775806;
const int inf=2147483646;
int n,l,s=0,m=inf;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>n>>l;
	for (int i=0;i<n;i++){
		s+=l+i;
		if (abs(l+i)<abs(m))
			m=l+i;
	}
	cout<<s-m;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ll long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

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

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

    cout << N / 3 << endl;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;

    solve();
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		if(n<=99) {
			System.out.println(Math.min(9,n));
		}else if(n<=9999) {
			System.out.println(Math.min(909,n-99+9));
		}else{
			System.out.println(Math.min(90909,n-9999+909));
		}
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l,s=0,a[100];
    cin>>n>>l;
   for(int i=1;i<=n;i++){
    s+=l+i-1;
    a[i-1]=l+i-1;
   }
   if(l>0) cout<<s-l<<endl;
   //cout<<s<<endl;
  // for(int j=0;j<n;j++)cout<<a[j]<<" ";
   else{
        for(int j=0;j<n;j++){
    if(a[j]==0){cout<<s<<endl; break;}
    if(j==n-1){s=s-(a[n-1]);
    cout<<s<<endl;
    }
   }

   }//*/

}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <set>
#include <cassert>

using namespace std;

vector<int> primes;

vector<int> make_primes(int n) {
	vector<bool> is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;

	for (int i = 2; i * i <= n; i++) {
		if (is_prime[i]) {
			for (int j = i * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}

	vector<int> primes = {2};
	for (int i = 3; i <= n; i += 2) {
		if (is_prime[i]) {
			primes.emplace_back(i);
		}
	}

	return n < 2 ? vector<int>() : primes;
}


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

	primes = make_primes(55555);
	vector<int> ans;
	for (int i = 0; i < primes.size(); i++) {
		if (primes[i] % 5 == 1) {
			ans.emplace_back(primes[i]);
		}
		if (ans.size() == n) {
			break;
		}
	}

	for (int i = 0; i < n; i++) {
		if (i != 0) {
			cout << " ";
		}
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N,C;
	int s[Nmax+10]={},t[Nmax+10]={0},c[Nmax+10]={},tsc[Nmax+10]={},scheme[Nmax+10]={};
	//0.5対策で２倍サイズ
	cin >> N >> C;
	REP(i,N) cin >> s[i] >> t[i] >> c[i];
	REP(i,C){
		int scheme[Nmax+10]={};
		REP(j,Nmax+10) 
			if(c[j]==i+1){
				scheme[2*s[j]-1+1]++;
				scheme[2*t[j]+1]--;
			}
		REP(j,Nmax+9) scheme[j+1]+=scheme[j];
		REP(j,Nmax+10) if(scheme[j]>0) tsc[j]++;
	}
	int mac=0;
	REP(i,Nmax+10) mac = max(mac, tsc[i]);
	cout << mac << endl;
	return 0;
}

Measured memory_bytes: 4096
X,N=map(int,input().split())
if N>0:
    p=list(map(int,input().split()))
else:
    print(X)
    exit()
if X not in p:
    print(X)
    exit()
Y=X
Z=X
s=0
t=0
while s==0:
    Y+=1
    if Y not in p:
        break
while t==0:
    Z-=1
    if Z not in p:
        break
if abs(X-Y)<abs(X-Z):
    print(Y)
elif abs(X-Y)>abs(X-Z):
    print(Z)    
else:
    print(Z)
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 9212
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  CIN(n,k);
  VC1(n,a);
  ll ans = LINF;
  REP(i,n - k + 1){
    ll x = a[i];
    ll y = a[i+k - 1];
    if((x>0) == (y>0))
      ans = min(ans, min(ans, max(abs(x), abs(y))));
    else
      ans = min(ans, abs(x) + abs(y) + min(abs(x), abs(y)));
  }
  COUT(ans);

}

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

namespace Handstand
{
    class Program
    {
        static void Main(string[] args)
        {
            int large = (int)1e6;
            string[] a = Console.ReadLine().Split(' ');
            int N = Convert.ToInt32(a[0]);
            int K = Convert.ToInt32(a[1]);
            char[] S = Console.ReadLine().ToCharArray();
            int[] change = new int[large];
            change[0] = 0;
            int j = 1;

            for (int i=1;i<N;i++)
            {
                if(S[i]!=S[i-1])
                {
                    change[j] = i;
                    j++;
                }
            }
            int[] values = new int[j];

            for (;j<large;j++)
            {
                change[j] = N; 
            }

            for(int z=0;z<values.Length;z++)
            {
                if (S[change[z]] == '0')
                {
                    if (z == 0)
                    {
                        values[z] = change[2 * K];
                    }
                    else
                    {
                        values[z] = change[z + 2 * K] - change[z - 1];
                    }
                }
                else
                {
                    values[z] = change[z + 1 + 2 * K] - change[z];
                }
            }

            int ans = 0;
            for (int i = 0; i < values.Length; i++)
            {
                if (values[i] > ans) ans = values[i];
            }
            Console.WriteLine(ans);

            Console.ReadKey();
        }
    }
}


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

int main(){
  string s;
  cin >> s;
  bool ans=false;
  if(s[2]==s[3] && s[4]==s[5]) ans=true;
  cout << (ans?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int num, i, ans = 0;
	cin >> num;
	vector<int> d(num);
	for (i = 0; i < num; i++)
		scanf("%d", &d[i]);
	for (i = 1; i < num - 1; i++) {
		if (d[i - 1] < d[i] && d[i] < d[i + 1])
			ans++;
		else if (d[i - 1] > d[i] && d[i] > d[i + 1])
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append([b, a])
ab.sort()
time = 0
for b, a in ab:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")
    

Measured memory_bytes: 35600
/**
*    author:  velengel
*    created: 08.05.2020 18:50:09
*    to run & test the code, type below command.
*    cptest abc000_a
**/

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

int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(false);
   int k,a,b;
   cin>>k>>a>>b;
   for (int i = a;i<=b;++i){
      if(i%k==0){
         cout << "OK" << endl;
         return 0;
      }
   }
   cout << "NG" << endl;
   return 0;
}

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

using namespace std;

#define FOR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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


    string s;
    cin >> s; 

    int ss = s.length();
    int a = 0, b = 0;
    FOR(i, 0, ss){
        if(s[i] == '0')
            a++;
        else 
            b++;
    }

    cout << 2*min(a,b);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, ans = 1e18;
int a[N];

int32_t main()
{
	IOS;
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int cur = 0;
	for(int i = 1; i <= n; i++)
	{
		cur += a[i];
		sum -= a[i];
		ans = min(ans, abs(cur - sum));
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main(){
        int a, b, c, d, e, f;
        cin>>a>>b>>c>>d>>e>>f;
        int resw=0, ress=0;
        double res=0;
        vector <int> w, s;
        for(int i=0;100*i<=f;i++){
                for(int j=0;100*j<=f;j++){
                        int ww=100*a*i+100*b*j;
                        w.push_back(ww);
                }
        }
        for(int i=0;i<=f;i++){
                for(int j=0;j<=f;j++){
                        int ss=c*i+d*j;
                        s.push_back(ss);
                }
        }
        /*for(int i=0;i<(int)s.size();i++){
                cout<<s[i]<<endl;
        }*/
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        sort(w.begin(), w.end());
        w.erase(unique(w.begin(), w.end()), w.end());
        for(int i=0;i<(int)s.size();i++){
                for(int j=0;j<(int)w.size();j++){
                        if(s[i]+w[j]>f){
                                break;
                        }
                        else if(s[i]*100<=w[j]*e&&res<=(double)(s[i]*100)/(double)(w[j]+s[i])){
                                res=(double)(s[i]*100)/(double)(w[j]+s[i]);
                                resw=w[j];
                                ress=s[i];
                        }
                }
        }
        cout<<ress+resw<<" "<<ress<<endl;
        return 0;
}


Measured memory_bytes: 34540
N, M = map(int, input().split())
As = list(map(lambda a: int(a) >> 1, input().split()))

from fractions import gcd

l = As[0]
for a in As:
    l = l * a // gcd(l, a)
    if l > M:
        break

if l <= M:
    i = 2
    while l & (i - 1) == 0:
        i <<= 1
    i = (i >> 1) - 1

    fg = False
    if i > 0:
        for a in As:
            if a & i > 0:
                fg = True
                break

    if fg:
        print(0)
    else:
        print(M // l - M // (l * 2))
else:
    print(0)

Measured memory_bytes: 79968
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin >> n;
    cout << ((n+110) / 111) * 111 << "\n";
}

Measured memory_bytes: 256
import bisect
n = int(input())
a_ls = []
for i in range(n):
    a_ls.append(-int(input()))
L_ls = [a_ls[0]]
for a in a_ls[1:]:
    if L_ls[-1] <= a:
        L_ls.append(a)
    else:
        L_ls[bisect.bisect_right(L_ls, a)] = a
print(len(L_ls))

Measured memory_bytes: 56920
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
	int i,count=0;
	char input[10];
	char result[101]={'\0'};
	char o[2]={'o'};
	char x[2]={'x'};
	char d[2]={'d'};
	while(1){
		if(scanf("%s", input)==EOF){
			break;
		}
		else if(input[0]=='o'&&input[1]=='o'&&input[2]=='o'){
			strcat(result, o);
		}
		else if(input[3]=='o'&&input[4]=='o'&&input[5]=='o'){
			strcat(result, o);
		}
		else if(input[6]=='o'&&input[7]=='o'&&input[8]=='o'){
			strcat(result, o);
		}
		else if(input[0]=='o'&&input[4]=='o'&&input[8]=='o'){
			strcat(result, o);
		}
		else if(input[2]=='o'&&input[4]=='o'&&input[6]=='o'){
			strcat(result, o);
		}
		else if(input[0]=='o'&&input[3]=='o'&&input[6]=='o'){
			strcat(result, o);
		}
		else if(input[1]=='o'&&input[4]=='o'&&input[7]=='o'){
			strcat(result, o);
		}
		else if(input[2]=='o'&&input[5]=='o'&&input[8]=='o'){
			strcat(result, o);
		}
		else if(input[0]=='x'&&input[1]=='x'&&input[2]=='x'){
			strcat(result, x);
		}
		else if(input[3]=='x'&&input[4]=='x'&&input[5]=='x'){
			strcat(result, x);
		}
		else if(input[6]=='x'&&input[7]=='x'&&input[8]=='x'){
			strcat(result, x);
		}
		else if(input[0]=='x'&&input[4]=='x'&&input[8]=='x'){
			strcat(result, x);
		}
		else if(input[2]=='x'&&input[4]=='x'&&input[6]=='x'){
			strcat(result, x);
		}
		else if(input[0]=='x'&&input[3]=='x'&&input[6]=='x'){
			strcat(result, x);
		}
		else if(input[1]=='x'&&input[4]=='x'&&input[7]=='x'){
			strcat(result, x);
		}
		else if(input[2]=='x'&&input[5]=='x'&&input[8]=='x'){
			strcat(result, x);
		}
		else{
			strcat(result, d);
		}
		count++;
	}
	for(i=0; i<count; i++){
		printf("%c\n",result[i]);
	}
	return 0;
}

Measured memory_bytes: 544
#include<stdio.h>

int main()
{
	int i = 0;
	char s[4], tmp;
	scanf("%s", s);

	while (s[i] != '\0') {
		i++;
	}

	if (i == 3) {
		tmp = s[0];
		s[0] = s[2];
		s[2] = tmp;
		printf("%s\n", s);
	}
	else {
		printf("%s\n", s);
	}

	return 0;

}

Measured memory_bytes: 128