akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[(1LL<<13)];

int main(){
    // cout << fixed << setprecision(5);

    lli n,m;
    cin>>n>>m;
    REP(i,0,(1LL<<13))dp[i]=INF;
    dp[0]=0;
    REP(i,0,m){
        lli a,b;
        cin>>a>>b;
        lli bit = 0;
        REP(j,0,b){
            lli c;
            cin>>c;
            c--;
            bit |= (1LL<<c);
        }
        REP(j,0,(1LL<<12))dp[j|bit] = min(dp[j]+a,dp[j|bit]);
    }

    if(dp[(1LL<<n)-1]==INF)cout<<-1<<endl;
    else cout<<dp[(1LL<<n)-1]<<endl;

    return 0;
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    int n,x;
    cin>>n>>x;

    if(x<n*2 || x>n*4){
        cout<<"No"<<endl;
        return;
    }  

    if(x%2==0){
        cout<<"Yes"<<endl;
        return;
    }else{
        cout<<"No"<<endl;
    }
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

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

int main(void)
{
	int N,i;
	scanf("%d",&N);
	long long int a[N],x,y,sum=0,sum1;
	
	for(i=0;i<N;i++)
	  {
	   scanf("%lld",&a[i]);
	   sum+=a[i];
      }
	
	x=a[0];
	sum1=llabs(sum-2*a[0]);
	for(i=1;i<N-1;i++)
	{
		x+=a[i];
		if(sum1>llabs(sum-2*x))
		  sum1=llabs(sum-2*x);
	}
	printf("%lld",sum1);
	
	return 0;	
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int n;
    string str;
    cin >> n;
    cin.ignore();
    while(n--) {
        getline(cin, str);
        int num;
        while(num = str.find("Hoshino"), num != -1) {
            str[num + 6] = 'a';
        }
        cout << str << endl;
    }
    return 0;
}

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

using ll=long long;

int main() {
  vector<int> a(10);
  rep(i,0,4) {
    int N; cin >>N;
    a[N]++;
  }
  if (a[1]==1 and a[9]==1 and a[7]==1 and a[4]==1) {
    cout <<"YES" <<endl;
  } else {
    cout <<"NO" <<endl;
  }
  return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

long long in(){
	long long n;
	scanf("%lld",&n);
	return n;
}
/*
	za atu + iroiro
*/

int st[50][3];
int en[50][3];

vector<int> u[3];

int sim[120][120][120];

int main(){
	int N,K;
	cin >> N >> K;
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> st[i][j];
			u[j].push_back(st[i][j]);
		}
		for(int j = 0 ; j < 3 ; j++){
			cin >> en[i][j];
			u[j].push_back(en[i][j]);
		}
	}
	for(int i = 0 ; i < 3 ; i++){
		sort(u[i].begin(),u[i].end());
		u[i].erase( unique(u[i].begin(),u[i].end()) , u[i].end() );
	}
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < 3 ; j++){
			st[i][j] = lower_bound( u[j].begin() , u[j].end() , st[i][j] ) - u[j].begin();
		}
		for(int j = 0 ; j < 3 ; j++){
			en[i][j] = lower_bound( u[j].begin() , u[j].end() , en[i][j] ) - u[j].begin();
		}
		for(int x = st[i][0] ; x < en[i][0] ; x++)
			for(int y = st[i][1] ; y < en[i][1] ; y++)
				for(int z = st[i][2] ; z < en[i][2] ; z++)
					sim[x][y][z]++;
	}
	long long ans = 0;
	for(int x = 0 ; x < u[0].size()-1 ; x++)
		for(int y = 0 ; y < u[1].size()-1 ; y++)
			for(int z = 0 ; z < u[2].size()-1 ; z++)
				if( sim[x][y][z] >= K ){
					long long dx = (u[0][x+1]-u[0][x]);
					long long dy = (u[1][y+1]-u[1][y]);
					long long dz = (u[2][z+1]-u[2][z]);
					long long vol = dx * dy * dz;
					ans += vol;
				}
	cout << ans << endl;
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ans.resize(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 23552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int max_n = 200010;
const ll mod = 998244353;
vector<ll> fac(max_n);
vector<ll> ifac(max_n);
vector<ll> m_mod(max_n);

ll N,M,K;
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % mod;
        x = x * x % mod;
        n = n>>1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < b || b < 0) return 0;
    ll tmp = ifac[b] * ifac[a-b] % mod;
    return tmp * fac[a] % mod;
}



int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
    cin>>N>>M>>K;
	//cout << fixed << setprecision(15);
    fac[0] = 1;
    ifac[0] = 1;
    m_mod[0] = 1;
    REP(i,N){
        fac[i+1] = fac[i] * (i+1) % mod; // fac[i] = n! % mod;
        ifac[i+1] = ifac[i] * mpow(i+1,mod-2) % mod; // ifac[i] = (i!) * pow(i, mod-2) % mod;
        m_mod[i+1] = m_mod[i] * (M-1) % mod;
    }

    ll ans = 0;
    for(ll i=0;i <= K; i++){
        ll now = 1;
        now = now* comb(N-1, i) % mod;
        now = now * M % mod;
        now = now * m_mod[N-i-1] % mod;
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
    
}

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

using namespace std;

int main() {

  int N=1;
  int mm = 0;
  while(true){
    cin >> N;
    if(!N)return 0;
    mm++;
    vector<vector<int> > stage;
    for (int i = 0; i < 400; i++) {
      vector<int> tmp_stage;
      for (int j = 0; j < 400; j++) {
        tmp_stage.push_back(-1);
      }
      stage.push_back(tmp_stage);
    }
    stage[200][200] = 0;
    int max_x = 200,min_x = 200;
    int max_y = 200,min_y = 200;
    for (int i = 1; i < N; i++) {
      int n, d;
      cin >> n >> d;
      for (int j = 0; j < 400; j++) {
        for (int k = 0; k < 400; k++) {
          int x = j, y = k;
          if (stage[j][k] == n) {
            switch (d) {
            case 0: {
              x--;
            } break;
            case 1: {
              y++;
            } break;
            case 2: {
              x++;
            } break;
            case 3: {
              y--;
            } break;
            }
            stage[x][y] = i;
            if(x > max_x)max_x = x;
            if(x < min_x)min_x = x;
            if(y > max_y)max_y = y;
            if(y < min_y)min_y = y;
          }
        }
      }
    }
    cout << max_x - min_x + 1  << " " << max_y - min_y + 1  <<endl;
  }
}

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


int main() {
  int H, W;

  cin >> H >> W;

  string S[60];

  S[0] = ".";
  for(int i=1;i<W+2;i++){
    S[0] += ".";
  }
  
  for(int i=1;i<H+1;i++){
    cin >> S[i];
    S[i] = "." + S[i] + ".";
  }

  for(int i=1;i<H+1;i++){
    for(int j=1;j<W+1;j++){
      if(S[i][j]=='.'){
        int count = 0;
        if(S[i-1][j-1]=='#') count++;
        if(S[i-1][j]=='#') count++;
        if(S[i-1][j+1]=='#') count++;
        if(S[i][j-1]=='#') count++;
        if(S[i][j+1]=='#') count++;
        if(S[i+1][j-1]=='#') count++;
        if(S[i+1][j]=='#') count++;
        if(S[i+1][j+1]=='#') count++;

        cout << count;
      }else{
        cout << "#";
      }
    }
    cout << endl;
  }


  
}


Measured memory_bytes: 256
#abc97 b
x=int(input())

beki=[1]

def gene_beki():
    for b in range(2,36):
        for p in range(2,10):
            num=b**p
            if num>x:
                continue
            else:
                beki.append(num)
gene_beki()
print(max(beki))

Measured memory_bytes: 2940
n,x = map(int,input().split())
l = [int(x) for x in input().split()]

save = 1
for i in range(1,n+2):
    if(i==1):
        d = 0
        continue
    d = d + l[i-2]
    if(d > x):
        break
    save = i
    
print(save)

Measured memory_bytes: 9072
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a, b;

int main() {
	scanf("%d %d", &a, &b);
	int ans = a;
	if(b < a) ans--;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);
int n;
int left(int i,vector<bool> &mk)
{
    for(int j=i-1;j>=0;j--)
    {
        if(mk[j]==0)
            return j;
    }
}
int right(int i,vector<bool> &mk)
{
    for(int j=i+1;j<n;j++)
    {
        if(mk[j]==0)
            return j;
    }
}

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
    int ans;
    for(int i=1;i<=5;i++)
    {
        int a;
        cin >> a;
        if(a==0)
            ans = i;
    }
    cout << ans;

	return 0;
}



Measured memory_bytes: 5488
#C - Same Integers
ABC = list(map(int,input().split()))
ABC = sorted(ABC,reverse = True)
A = ABC[0]#max
B = ABC[1]
C = ABC[2]#min
count = 0
while A != B:
    C += 1
    B += 1
    count += 1
while (B - C)%2 == 1:
    A += 1
    B += 1
    count += 1
while A!=C:
    C += 2
    count += 1
print(count)

Measured memory_bytes: 9052
/**
 *    Author  : Ador
 *    Created : 24.07.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
        //freopen("input.txt", "r", stdin) ;
        //freopen("output.txt", "w", stdout) ;
    int n , d , flag = 0 , i ; cin >> n ;
    for(i = 1 ; i <= 9 ; ++i)
    {
        if(!(n % i)) d = n / i ;
        if(d < 10) {flag = 1 ; break ; }
    }
    if(flag) cout << "Yes\n" ;
    else cout << "No\n" ;
    return 0 ;
}


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

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool flag = true;
        int count = 0;
        while(flag) {
            flag = false;
            for (int i = n-1; i > 0; i --) {
                if (a[i]<a[i-1]) {
                    int tmp = a[i];
                    a[i] = a[i-1];
                    a[i-1] = tmp;
                    count ++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < n; i ++) {
            if (i == n-1) Console.WriteLine(a[i]);
            else Console.Write(a[i]+" ");
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 18308
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------

struct mint {
	ll x;
	mint(ll x=0):x(x%mod){}

	bool operator==(const mint a)const{return x==a.x;}
	bool operator!=(const mint a)const{return x!=a.x;}
	bool operator>=(const mint a){return (x >= a.x)? 1: 0;}
	bool operator<(const mint a){return !(*this>=a);}
	bool operator>(const mint a){return (x > a.x)? 1:0;}
	bool operator<=(const mint a){return !(*this>a);}
	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;  //2 square
		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;
	}
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    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];
  }
} comb(2000005);

mint f(int n, int k) {
  if (n < 0) return 0;
  // nPk = nCk * k!
  mint res = comb(n,k);
  res *= comb.fact[k];
  return res;
}

int n;
string s;

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n >> s;
    mint ans(0);
    int sz = n + s.size();
    ans += mint(26).pow(sz);

    FOR(i,0,s.size()-1) {
        ans -= comb(sz,i)*(mint(25).pow(sz-i));
    }

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


Measured memory_bytes: 35472
from math import floor


def solve():
    A, B = map(int, input().split())
    for i in range(1, 10000):
        if A == floor(i * 0.08) and B == floor(i * 0.1):
            print(i)
            exit()
    print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#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()
using ll = long long;
using ull = unsigned long long;


int main(void)
{
    IOS
    int n; cin >> n;
    vector<int> a(n,0);
    FOR(i,0,n) cin >> a[i];

    vector<int> ans(n);
    ll sum = accumulate(ALL(a),0LL);
    ll tmp = 0;
    for(int i = 1;i < n-1;i=i+2) {
        tmp += a[i];
    } 
    ans[0] = sum - 2 * tmp;
    FOR(i,1,n) {
        ans[i] = a[i-1] * 2 - ans[i-1];
    }

    REP(i,n) cout << ans[i] << " ";
    cout << endl;



    return 0;
}


Measured memory_bytes: 2176
// abc115_a
// #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
	int D;
	cin >> D;
	switch (D)
	{
	case 22:
		cout << "Christmas Eve Eve Eve" << endl;
		break;
	case 23:
		cout << "Christmas Eve Eve" << endl;
		break;
	case 24:
		cout << "Christmas Eve" << endl;
		break;
	case 25:
		cout << "Christmas" << endl;
		break;
	default:
		break;
	}

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> x[n],y[n];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            int s,t;
            cin>>s>>t;
            x[i].push_back(s-1);
            y[i].push_back(t);
        }
    }
    int ans=0;
    for(int i=0;i<1<<n;i++){
        bool flag=true;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                int a=x[j].size();
                for(int k=0;k<a;k++){
                    if(y[j][k]&&((i>>x[j][k])&1)==0){
                        flag=false;
                        break;
                    }
                    if(!y[j][k]&&(i>>x[j][k])&1){
                        flag=false;
                        break;
                    }
                }
            }
        }
        if(flag){
            int cnt=0;
            for(int j=0;j<n;j++){
                if((i>>j)&1)cnt++;
            }
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = min(b, d)-max(a, c);
	co(max(ans, 0LL));

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        m: usize,
        mut k: i64,
        mut a: [i64; n],
        mut b: [i64; m],
    }

    let mut s1 = vec![0; n + 1];
    for i in 0..n {
        s1[i + 1] = s1[i] + a[i];
    }

    let mut res = 0;
    let mut s2 = 0;
    let mut j = 0;
    for i in (0..=n).rev() {
        if s1[i] > k {
            continue;
        }
        while j < m && s2 + b[j] + s1[i] <= k {
            s2 += b[j];
            j += 1;
        }
        res = std::cmp::max(res, i + j);
    }

    println!("{}", res);
}


Measured memory_bytes: 10832
H, W = map(int, input().split())
if H == 1 or W == 1:
  total = 1
else:
  Rodd = (W + 2 - 1) // 2
  Reven = W - Rodd
  odd = (H + 2 - 1) // 2
  even = H - odd
  total = Rodd * odd + Reven * even

print(total)  

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


int solve(int n,int m){
    vector<vector<pair<int,int>>> vec(n);
    for(int i=0;i<m;i++){
        int s,t,c;
        cin>>s>>t>>c;
        s--,t--;
        vec[s].push_back({-c,t});
        vec[t].push_back({-c,s});
    }

    vector<int> used(n,0);
    priority_queue<pair<int,int>> que;
    auto insert=[&](int v){
        for(auto &e:vec[v]) que.push(e);
    };
    used[0]=true;
    insert(0);
    vector<int> costs;
    while(!que.empty()){
        auto tmp=que.top(); que.pop();
        int c=-tmp.first;
        int v=tmp.second;
        if(used[v]) continue;
        used[v]=true;
        costs.push_back(c);
        insert(v);
    }
    sort(costs.begin(),costs.end());
    return costs[(n-1)/2];
}
int main(){
    int n,m;
    while(cin>>n>>m,n){
        cout<<solve(n,m)<<endl;
    }
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 string s,t;
 int i,n;
 t="";
 cin >> s;
 n=s.length();
 if(n%2)
 {
  cout << "No";
  return 0;
 }
 for(i=0;i<(n/2);i++)
 t.append("hi");
 if(t==s)
 cout << "Yes";
 else
 cout << "No";
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define ld long double
#define mod 998244353ll
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)#define case_g "Case #"<<ti<<": "
#define Debug(x) cout << x << "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
int main() {
    ll num;
    cin >> num;
    if(num % 1000) {
        cout << (1000 - num % 1000);
    }
    else {
        cout << 0;
    }
}


Measured memory_bytes: 3592
#include <stdio.h>
 
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
 
int main(){
  int H, i, A[10000];
 
  scanf("%d",&H);
  for(i=1; i<=H; i++){
    scanf("%d",&A[i]);
  }
  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i)>=1){
      printf("parent key = %d, ", A[parent(i)]);
    }
    if(left(i)<=H){
      printf("left key = %d, ", A[left(i)]);
    }
    if(right(i)<=H){
      printf("right key = %d, ", A[right(i)]);
    }
    printf("\n");
  }
   
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<long int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int num_odd_negative=0;
    int num_even_negative=0;
    for(int i=0;i<N;i++){
        if(A[i]<0){
            if(i%2==0){
            num_odd_negative+=1;
            }else{
                num_even_negative+=1;
            }
        }
    }
    long long int all_abs_sum=0;
    for(int i=0;i<N;i++){
        all_abs_sum+=std::abs(A[i]);
        A[i]=std::abs(A[i]);
    }

    if((num_even_negative+num_odd_negative)%2==0){
        cout<<all_abs_sum<<endl;
    }else{
        cout<<all_abs_sum-*std::min_element(A.begin(),A.end())*2<<endl;
    }
}

Measured memory_bytes: 1024
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;
const ll INF = 1e18;

bool cmp(ll a, ll b){return llabs(a) > llabs(b);}
bool cmp_in(ll a, ll b){return llabs(a) < llabs(b);}

ll n, k, c, res, hsh;
ll mn, mx, _mn, _mx;

int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    cin >> n >> k;
    vector<int> v(n);
    for(auto &i : v) cin >> i;
    for(auto i : v) c += (i == 0);
    if(n < k + c){cout << 0; exit(0);}

    sort(all(v), cmp);
    rep(i, 0, k) if(v[i] < 0)hsh++;
    res = 1;
    rep(i, 0, k)res = (res * llabs(v[i])) % MOD;
    if(hsh & 1){
        mn = _mn = INF;
        mx = _mx = -1;

        rep(i, 0, k) if(v[i] < 0) mn = min(mn, llabs(v[i]));
        rep(i, 0, k) if(v[i] >= 0) _mn = min(_mn, llabs(v[i]));
        rep(i, k, n) if(v[i] >= 0) mx = max(mx, llabs(v[i]));
        rep(i, k, n) if(v[i] < 0) _mx = max(_mx, llabs(v[i]));

        if(mx != -1 and _mn != INF and _mx != -1){
            if(mn * _mx > _mn * mx) res = ((res * _mx) % MOD) * power(_mn, MOD - 2);
            else res = ((res * mx) % MOD) * power(mn, MOD - 2);
        }else if(mx != -1){
            res = ((res * mx) % MOD) * power(mn, MOD - 2);
        }else if(_mx != -1 and _mn != INF){
            res = ((res * _mx) % MOD) * power(_mn, MOD - 2);
        }else{
            sort(all(v), cmp_in);
            res  = 1;
            rep(i, 0, k) res = (llabs(v[i]) * res) % MOD;
            res = (MOD-res) % MOD;
        }
    }
    cout << res % MOD;
}

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

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

ll dfs(ll prev, ll now, vector<vector<ll>>& adj, vector<ll>& dp, set<ll>& st) {
	if (dp[now] > 0) return dp[now];
	if (st.find(now) != st.end()) return -1;
	st.insert(now);
	ll ret = 0;
	for (auto i : adj[now]) {
		if (i == prev) continue;
		ll x = dfs(now, i, adj, dp, st);
		if (x == -1) return -1;
		ret = max(ret, x);
	}
	st.erase(now);
	return dp[now] = ret + 1;
}

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> a(n, vector<ll>(n - 1));
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - 1; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	auto idx = [&] (ll i, ll j) {
		if (i > j) swap(i, j);
		ll ret = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;
		return ret + j - i - 1;
	}; // {i, j} が対戦する試合の頂点番号

	ll m = n * (n - 1) / 2;
	vector<vector<ll>> adj(m);
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - 2; j++) {
			ll u = idx(i, a[i][j]), v = idx(i, a[i][j + 1]);
			adj[u].push_back(v);
		}
	}

	vector<ll> dp(m, 0);
	ll ans = 0;
	for (ll i = 0; i < m; i++) {
		set<ll> st;
		ll x = dfs(-1, i, adj, dp, st);
		if (x == -1) {
			cout << -1 << endl;
			return 0;
		} else ans = max(ans, x);
	}

	cout << ans << endl;
}

Measured memory_bytes: 42436
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int input_num = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		
		//単語の入力とカウント
		for(int i=0;i<input_num;i++){
			String str = sc.next();
			if(map.get(str) == null){
				map.put(str, 1);
			}else{
				map.put(str, map.get(str) + 1);
			}
		}
		
		int max = 0;
		//最大値の取得
		for (int val : map.values()) {
			if(val > max) max = val;
		}
		
		//System.out.println(max);
		
		//最大値に等しいkeyを格納するリストの定義
		List<String> list = new ArrayList<String>();
		
		//最大値に等しいvalueを持つkeyの取得
		for (String key : map.keySet()) {
			if(map.get(key) == max) list.add(key);
		}
		
		//辞書順にソート
		Collections.sort(list);
		
		//出力
		for(int i=0;i<list.size();i++){
			System.out.println(list.get(i));
		}
		
		/*
		for(Map.Entry<String, Integer> entry : map.entrySet()){
		    System.out.println(entry.getKey() + ":" + entry.getValue());
		}*/
		
		
	}
}
		
		


Measured memory_bytes: 87756
#include <iostream>
using namespace std;
int num[10001];
int N;

int main(void){
    cin >> N;
    
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int f = i*i + j*j + k*k + i*j + j*k + k*i;
                if(f > N){
                    break;
                }
                else {
                    num[f]++;
                }
            }
        }
    }
    
    for(int i=1;i<=N;i++)cout << num[i] << endl;
    
}


Measured memory_bytes: 3048
#!/usr/bin/env python3
#ABC85 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,h = LI()
maxa = 0
ab = []
for _ in range(n):
    a,b = LI()
    maxa = max(maxa,a)
    ab.append([a,b])
x = sorted(ab,key = lambda x:x[1],reverse = True)
cnt = 0
for i in range(n):
    a,b = x[i]
    if maxa <= b:
        h -= b
        cnt += 1
    if h <= 0:
        print(cnt)
        quit()
cnt += math.ceil(h / maxa)
print(cnt)


Measured memory_bytes: 59868
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = []

X.sort()
for i in range(1, M):
    Y.append(X[i] - X[i-1])

Y.sort()
if N >= M:
    print(0)
else:
    print(sum(Y[:M-N]))

Measured memory_bytes: 13968
s = int(input())
x = []
x.append(s)
m = 1
z = 0
if s % 2 == 0:
    y = s // 2
else:
    y = 3 * s + 1
m += 1
x.append(y)
while z == 0:
    n = y
    if  n % 2 == 0:
        y = n // 2
    else:
        y = 3 * n + 1
    if y in x:
        z += 1
        m += 1
        print(m)
    else:
        m += 1
        x.append(y)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define debug(x) cout << (x) << "\n";
#define mp make_pair
#define pb push_back

void solve() {
	int s, w;
	cin >> s >> w;
	if (w >= s) cout << "unsafe";
	else cout << "safe";
	cout << "\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	} 
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	s := scanInts(n)

	ma := 0
	for i := 1; i < n; i++ {
		sum := 0
		for k := 0;; k++ {
			if n-1-k*i < 0 || (k+1)*(n-1-k*i)-(n-1) < 0{
				break
			}

			if k*i == n-1-k*i || (k-1)*i == n-1-k*i {
				break
			}

			sum += s[k*i]+s[n-1-k*i]
			ma = max(ma, sum)
			// debug(i,k,sum)
		}
	}

	fmt.Fprintln(wr, ma)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'R') cnt++;
  }

  if (cnt > n-cnt) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import math
eight,ten = map(int,input().split())
dummy = 10*ten
flag = "ng"
for i in range(dummy,dummy+10):
  if math.floor(i*0.08) == eight:
    flag = "ok"
    ans = i
    break
if flag == "ok":
  print(ans)
else:
  print(-1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
		static String s1="AC";
		static String s2="WA";
		static String s3="TLE";
		static String s4="RE";
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int c1=0,c2=0,c3=0,c4=0;
		for	(int i=0;i<n;i++)
		{
			
			String s=scan.next();
			if(s.contains(s1)) c1++;
			else if(s.contains(s2)) c2++;
			else if (s.contains(s3)) c3++;
			else if(s.contains(s4)) c4++;
		}
		System.out.println(s1+" "+"x"+" "+c1);
		System.out.println(s2+" "+"x"+" "+c2);
		System.out.println(s3+" "+"x"+" "+c3);
		System.out.println(s4+" "+"x"+" "+c4);
		

	}

}


Measured memory_bytes: 48820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    string d,p,q;
    rep(i,n){char c;cin>>c;p.push_back(c);}
    rep(i,n){char c;cin>>c;q.push_back(c);}
    for(char i = '1';i<'1'+n;i++)d.push_back(i);
    ll acnt,bcnt,cnt=1;
    do{
        if(d==p)acnt=cnt;
        if(d==q)bcnt=cnt;
        cnt++;
    }while(next_permutation(d.begin(),d.end()));
    co(abs(acnt-bcnt));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int MAX_N = 101010;
int prime[MAX_N];//i番目の素数
bool is_prime[MAX_N + 1];//is_prime[i]がtrueならiは素数

//n以下の素数の数を返す
int sieve(int n){
    int p=0;
    for(int i=0; i<=n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j= 2*i; j<= n; j+=i) is_prime[j] = false;
        }
    }
    return p;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sieve(101010);
    vector<int> cum(101010);
    for(int i=1;i<101000;i++){
        if(is_prime[i] && is_prime[(i+1)/2]) cum[i]++;
        cum[i+1] += cum[i];
    }
    int Q;
    cin >> Q;
    while(Q--){
        int l, r;
        cin >> l >> r;
        cout << cum[r] - cum[l-1] << endl;
    }
}

Measured memory_bytes: 1152
#include <stdio.h>
int main(void){
  char str[201];
  int i,j;
  scanf("%s",str);
  i=0;
  while(str[i]!='\0') i++;
  str[i-1]='\0';

  while(1){
    if(i%2==0){
      str[i-2]='\0';
    }
    i=0;
    while(str[i]!='\0') i++;

    for(j=0;j<i/2;j++){
      if(str[j]!=str[i/2+j]){
        break;
      }
    }
    if(j==i/2){
      printf("%d\n",i);
      break;
    }


    str[i-1]='\0';

    if(i==0){
      break;
    }

  }
  return 0;
}


Measured memory_bytes: 128
'use strict'

function main(inp) {
  inp = inp.trim().split('\n')
  const name = inp[0].split(' ')
  const num = inp[1].split(' ')
  const poi = inp[2]
  num[name.indexOf(poi)]--
  console.log(num.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
// J4180449 三宅亮輔
// 問題名
// - Depth First Search
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_11_B
// 所要時間
// - 35分
// 学んだこと
//  どこで時間を更新するのかの理解に苦しんだ
//  番号が小さい順に巡ることをソートで実装しようとしたが必要ないと気づいて楽になった
//  再帰関数のスマートさに感動した

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;

vector<int> v[100];
bool visited[100];
int d[100];
int f[100];

int dfs(int i, int now) {
    visited[i] = true;
    now++;
    d[i] = now;
    for(int j = 0; j < v[i].size(); j++) {
        if(!visited[v[i][j]])
            now = dfs(v[i][j], now);
    }
    now++;
    f[i] = now;
    return now;
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            v[u].push_back(x);
        }
    }
    int now = 0;
    for(int i = 0; i < n; i++) {
        if(!visited[i])
            now = dfs(i, now);
    }

    for(int i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
string s;
map<string,int>mp;
int main(){
	int n,ans=0;cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		if(!mp[s])mp[s]=++ans;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 19276
<?php
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    $ans = $a + $b;
    if($ans < $a - $b){
        $ans = $a - $b;
    }
    if($ans < $a * $b){
        $ans = $a * $b;
    }
    echo $ans;
?>

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

#define int long long
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; }

signed main(){
	int a, b;
	cin >> a >> b;
	cout << a*b/__gcd(a, b) << endl;

	return 0;
}


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

int main(){
	int L;
	while(cin >> L && L){
		int last = 0 , f = 0;
		for(int i = 1 ; i <= 12 ; i++){
			int a,b;
			cin >> a >> b;
			int c = a-b;
			last += c;
			if( last < L ){
				f = i;
			}
		}
		if( last < L ){
			cout << "NA" << endl;
		}else{
			cout << f+1 << endl;
		}
	}
	
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){

  char s[201];
  char p[101];

  int i,a=0,j,m,n,b=0; 

  scanf("%s",s);

  for(i=0;i<=100;i++){
    if( s[i]=='\0'){
      m=i;
      break;
    }
  }


  scanf("%s",p);

  for(i=0;i<=100;i++){
    if( p[i]=='\0'){
      n=i;
      break;
    }
  }
  //printf("%d %d\n",n,m);

  for(j=m;j<=2*m-1;j++){
    s[j]=s[b];
    b++;
  }

  for(j=0;j<=2*m-1;j++){
    for(i=0;i<=n-1;i++){
      if(p[i]==s[i+j]){
	a++;
      }
      else{
	a=0;
	break;
      }
      if(a==n){
	break;
      }
    }
    if(a==n){
      break;
    }
  }
  //printf("%d\n",a);

  if(a==n){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 948
#include"bits/stdc++.h"
using namespace std;

#define MAX 400002

int n;


vector<int> v[MAX];

bool ng[MAX];



vector<int> path;
set<int> s;

vector<int> ans;

int dist[MAX];
int pr[MAX];

inline void bfs(int b) {
	memset(dist, -1, sizeof(dist));
	memset(pr, -1, sizeof(pr));
	dist[b] = 0;
	queue<int> q;
	q.push(b);
	while (!q.empty()) {
		b = q.front();
		q.pop();
		for (int go : v[b]) {
			if (dist[go] == -1 || dist[go] > dist[b] + 1) {
				dist[go] = dist[b] + 1;
				q.push(go);
				pr[go] = b;
			}
		}
	}
}

vector<int> ans2;

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int cn = 0;
	for (int i = 0; i < n; i++) {
		if (v[i].size()>1) {
			ng[i] = true;
			cn++;
		}
	}
	bfs(0);
	int mx = -1;
	int ich = -1;
	for (int j = 0; j < n; j++) {
		if (mx < dist[j]) {
			mx = dist[j];
			ich = j;
		}
	}
	bfs(ich);
	int p = -1;
	int ich2 = -1;
	for (int j = 0; j < n; j++) {
		auto d =dist[j];
		if (p < d) {
			p = d;
			ich2 = j;
		}
	}
	while (ich2 >= 0) {
		path.push_back(ich2);
		s.insert(ich2);
		ich2 = pr[ich2];
	}
	for (int i = 0; i < path.size(); i++) {
		if (ng[path[i]]) {
			cn--;
		}
	}
	if (cn != 0) {
		puts("-1");
		return 0;
	}
	{
		int cur = 1;
		for (int i = 0; i < path.size(); i++) {
			int deg = 0;
			int eb = cur;
			cur++;
			for (int j = 0; j < v[path[i]].size(); j++) {
				int go = v[path[i]][j];
				if (s.count(go) == 0) {
					deg++;
					ans.push_back(cur);
					cur++;
				}
			}
			ans.push_back(eb);
		}
		ans2 = ans;
		ans.clear();
	}
	reverse(path.begin(), path.end());
	{
		int cur = 1;
		for (int i = 0; i < path.size(); i++) {
			int deg = 0;
			int eb = cur;
			cur++;
			for (int j = 0; j < v[path[i]].size(); j++) {
				int go = v[path[i]][j];
				if (s.count(go) == 0) {
					deg++;
					ans.push_back(cur);
					cur++;
				}
			}
			ans.push_back(eb);
		}
	}
	ans = min(ans, ans2);
	for (int i = 0; i < ans.size(); i++) {
		if (i)printf(" ");
		printf("%d", ans[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 22772
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
int a[101];

int main() {
  INCANT;
  cin >> N;
  rep(i, N) cin >> a[i];

  sort(a, a+N, greater<int>());
  int res = 0;
  rep(i, N) {
    if (i%2==0) res+=a[i];
    else res-=a[i];
  }
  
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		bool exercise=true,right=false,left=false;
		string input;
		int cnt=0;
		for(int i=0;i<n;i++){
			cin>>input;
			if(input=="lu")left=true;
			else if(input=="ru")right=true;
			else if(input=="ld")left=false;
			else right=false;
			if(exercise==true&&right==true&&left==true){
				exercise=false;
				cnt++;
			}else if(exercise==false&&right==false&&left==false){
				exercise=true;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 1208
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  ou(max(max(a1,a2),a3)-min(min(a1,a2),a3));
}

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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

struct Event {
	ll x, h;
	bool monster;

	Event() {}
	Event(ll x, ll h, bool monster): x(x), h(h), monster(monster) {}

	bool operator<(const Event oth) const {
		if(x == oth.x) return oth.monster;
		return x > oth.x;
	}
};

int main() {

	int N,D,A;
	scanf("%d%d%d", &N, &D, &A);

	priority_queue<Event> ev;

	for(int i = 0; i < N; i++) {
		int x, h;
		scanf("%d%d", &x, &h);
		ev.push(Event(x,h,true));
	}

	ll bombs = 0;
	ll dmg = 0;

	while(!ev.empty()) {
		Event cur = ev.top();
		ev.pop();
		if(cur.monster) {
			cur.h -= dmg;
			if(cur.h > 0) {
				int add = (cur.h-1) / A + 1;
				bombs += add;
				dmg += add*A;
				ev.push(Event(cur.x + 2*D, add*A, false));
			}
		} else {
			dmg -= cur.h;
		}
	}

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

	return 0;
}


Measured memory_bytes: 8560