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

#define null                ""
#define all(dat)            dat.begin(), dat.end()
#define over(msg)           cout << msg << endl, exit(0);
#define loop(i, to)         for (num i = 0; i < to; ++i)
#define cont(i, to)         for (num i = 1; i <= to; ++i)
#define foreach(i, dat)     for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long           num;

using namespace std;

struct sta {
    
    int from, com, d;
    
    sta() {}
    
    sta(int a, int b, int c) {
        
        this -> from = a;
        
        this -> com = b;
        
        this -> d = c;
        
    }
    
};

bool operator < (sta a, sta b) {

    return a.d > b.d;

}

const int inf = 0x3f3f3f;

int n, m, ans = inf;

vector<int> g[100005];

unordered_map<int, int> dis[100005];

unordered_map<int, vector<int>> com[100005];

int main() {
    
    ios_base::sync_with_stdio(0);
    
    cin >> n >> m;
    
    loop (i, m) {
        
        int p, q, c;
        
        cin >> p >> q >> c;
        
        --p;
        
        --q;
        
        com[p][c].push_back(q);
        
        com[q][c].push_back(p);
        
        g[p].push_back(c);
        
        g[q].push_back(c);
        
    }
    
    priority_queue<sta> q;
    
    dis[0][0] = 0;
    
    q.push(sta(0, 0, 0));
    
    while (!q.empty()) {
        
        sta u = q.top();
        
        q.pop();
        
        if (dis[u.from][u.com] != u.d)  continue;
        
        if (dis[u.from].find(0) == dis[u.from].end() || dis[u.from][0] > u.d) {
            
            dis[u.from][0] = u.d;
            
            q.push(sta(u.from, 0, u.d));
            
        }
        
        if (u.com == 0) {
            
            loop (i, g[u.from].size()) {
                
                int v = g[u.from][i];
                
                if (dis[u.from].find(v) == dis[u.from].end() || dis[u.from][v] > u.d + 1) {
                    
                    dis[u.from][v] = u.d + 1;
                    
                    q.push(sta(u.from, v, u.d + 1));
                    
                }
                
            }
            
            continue;
            
        }
        
        loop (i, com[u.from][u.com].size()) {
            
            int v = com[u.from][u.com][i];
            
            if (dis[v].find(u.com) == dis[v].end() || dis[v][u.com] > u.d) {
                
                dis[v][u.com] = u.d;
                
                q.push(sta(v, u.com, u.d));
                
            }
            
        }
        
    }
    
    foreach (it, dis[n - 1]) {
        
        ans = min(ans, it -> second);
        
    }
    
    if (ans == inf) {
        
        over(-1);
        
    }
    
    over(ans);
    
}


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

using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	int d=a*100+b*10+c;
	if(d%4==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    ll h;
    cin >> h;

    ll ans = 0;

    int cont = 0;
    while ( h > 0 ) {
        ans += (1LL << cont);
        cont++;
        h /= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
lis=[]
cnt=0
for i in range(n-1):
  if a[i+1]==a[i]:
    cnt+=1
  else:
    if cnt>=1:
      lis.append([a[i],cnt])
    cnt=0
if cnt>=1:
  lis.append([a[n-1],cnt])
lis.sort(reverse=True)
if len(lis)>=2:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(lis[0][0]*lis[1][0])
elif len(lis)==1:
  if lis[0][1]>=3:
    print(lis[0][0]**2)
  else:
    print(0)
else:
  print(0)

Measured memory_bytes: 14672
#include <algorithm>
#include <iostream>
#include <map>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
 /////////////////////////////////////////////////////
const int INF = 100000000;

int main(){
    int H,W;
    int c[10][10]; // 0 - indexed
	SCD(H); SCD(W);

    
    REP(i,10){
        REP(j,10){
            SCD(c[i][j]);
        }
    }
    
    
    REP(i,10){
        REP(j,10){
            REP(k,10){
                c[j][k] = min(c[j][k],c[j][i]+c[i][k]);
            }
        }
    }


    int ans = 0;
    FORq(i,1,H){
        FORq(j,1,W){
            int x;
			SCD(x);
           
            if (x >=0) ans += c[x][1];
        }
    }
    
   

    PRINTD(ans);
	return 0;
}




Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))
l=[]
for i in range(N):
  if i!=0 and i!=N-1:
    if A[i+1]-A[i]>=A[i]-A[i-1]:
      x=K-(A[i+1]-A[i])
    else:
      x=K-(A[i]-A[i-1])
  elif i==0:
      if (K-A[N-1])+A[0]>=A[1]-A[0]:
        x=A[N-1]-A[0]
      else:
        x=K+A[0]-A[1]
  else:
    if (K-A[N-1])+A[0]>=A[N-1]-A[N-2]:
      x=A[N-1]-A[0]
    else:
      x=K-(A[N-1]-A[N-2])
  l.append(x)
print(min(l))

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

int main(){
  int A, B;
  cin >> A >> B;

  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
    cout << "Possible" << endl;
  }
  else
  {
    cout << "Impossible" << endl;
  }
  
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
// C - Train Ticket

int main(){
    //int a,b,c,d;
    //cin >> a >> b >> c >> d;
    string s;
    cin >> s;
    vector<int> a(4);
    for(int i=0;i<4;i++)
        a.at(i)=s.at(i)-'0';

    for (int bit = 0; bit < (1<<3); ++bit)
     {
         /* bit で表される集合の処理を書く */
         int ans=a.at(0);
        for (int i = 0; i < 3; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                ans+=a.at(i+1);
               }
            else{
                ans-=a.at(i+1);
            }
        }
        if(ans==7){
            cout<<a.at(0);
            for (int i = 0; i < 3; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                cout<<"+";
               }
            else{
                cout<<"-";
            }
            cout <<a.at(i+1);
            }
            cout << "=7";
            break;
        }
     }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  for(int i=N-2; i>=0; i--){
    if(v[i+1] < 0){
      v[i] *= -1;
      v[i+1] *= -1;
    }
  }

  if(v[0] >= 0){
    ll sum = 0;
    rep(i,N){
      sum += v[i];
    }
    cout << sum << endl;
  }else{
    ll sum = 0;
    rep(i,N){
      sum += v[i];
    }
    ll ret = sum;
    rep(i,N-1){
      sum -= v[i];
      sum -= v[i+1];
      v[i] *= -1;
      v[i+1] *= -1;
      sum += v[i];
      sum += v[i+1];
      ret = max(ret, sum);
    }
    cout << ret << endl;
  }
  
  return 0;
}



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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;


int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  rep(i, n) {
    cout << s.at(i) << t.at(i);
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

int A, B, C;

int main(){
    cin >> A >> B >> C;

    if(A*C < B) cout << C << "\n";
    else cout << (B/A) << "\n";

    return 0;
}

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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int n;
int a[25][25];

ll PD[25][1<<22];

ll pd(int i,  int w){
	if(i == n){
		return 1;
	}
	ll &ans = PD[i][w];
	if(ans != -1){
		return ans;
	}
	ans = 0;
	for(int j = 0; j < n;  j++){
		if(!(w & (1 << j)) && a[i][j]){
			ans += (pd(i+1, w|(1<<j)));
			ans = ans%MOD;
		}
	}
	return ans;
}

int main(){
	scanf("%d", &n);
	FOR(i, 0, n){
		FOR(j, 0, n){
			scanf("%d", &a[i][j]);
		}
	}
	memset(PD, -1, sizeof PD);
	printf("%lld\n", pd(0, 0));
	return 0;
}

Measured memory_bytes: 819456
/*
 ***
 Question Name:
 ***
 Question Link:
 
 ***
 Idea:
 */

#include <memory.h>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef unordered_set<int> ui;
typedef pair<LL,LL> pLL;

int main(){
    int N, ans = 1;
    cin>>N;
    while(ans*2<=N) ans*=2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
import itertools

n,m,q=map(int,input().split())
lis=[list(map(int,input().split())) for i in range(q)]
ans=0

l=[]
for v in itertools.combinations_with_replacement(list(range(1,m+1)), n):
    l.append(list(v))

for i in l:
    ans1=0
    for j in range(q):
        ans1+=lis[j][3]*((i[lis[j][1]-1]-i[lis[j][0]-1])==lis[j][2])
    ans=max(ans,ans1)
print(ans)

Measured memory_bytes: 84732
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < S.length() - 2; i++) {
        if (S.substr(i, 3) == "ABC") ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    string s;
    cin >> s;
    
    string s2 = s.substr(0, s.size()-8);
    cout << s2<< endl; 

   return 0;
}

Measured memory_bytes: 256
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
 
int main(){
	int n;
	cin >> n;
 
	if (n%2 != 0){
		cout << n/2+1 << endl;
	}
	else{
		cout << n/2 << endl;
	}
 
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int x;

    cin >> x;

    V<int> ans;
    int y, z;

    ans.pb(1);

    int i;

    repi(i, x, 2) {
        y = z = i;

        if (x < y * y) break;
        if (y * y == x) {
            Out(x);

            return 0;
        }

        while (y < x) y *= z;

        if (y == x) {
            Out(x);

            return 0;
        }

        y /= z;

        ans.pb(y);
    }

    sort(All(ans));

    Out(ans.back());

    return 0;
}


Measured memory_bytes: 256
/*input
30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void checker(vector<ll> a, int k) {
	cout << "Checker() \n";
	vector<ll> ret;
	int i, j, n = a.size();
	for(i=0; i<n; i++) {
		for(j=i+1; j<n; j++)
			ret.emplace_back(a[i] * a[j]);
	}
	sort(ret.begin(), ret.end());
	cout <<"Ret has " << ret.size() << " elements:" << endl;
	for(i=0; i<ret.size(); i++) {
		if(i+1 == k) cout <<"[";
		cout << ret[i];
		if(i+1 == k) cout <<"]";
		cout << " " ;
	}
	cout << endl << "----------------------------------------------------------" << endl;
}

void run() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> pos, neg;
	int i, j, zeros=0;
	for(i=0; i<n; i++) {
		cin >> a[i]; 
		if(a[i] > 0) pos.emplace_back(a[i]);
		if(a[i] < 0) neg.emplace_back(a[i]);
		if(a[i] == 0) zeros++;
	}
	// checker(a, k);
	ll tot_zeros = 0;
	ll start = n-1;
	while(zeros > 0) {
		tot_zeros += max(0ll, start);
		zeros--;
		start--;
	}
	// cout <<"tot_zeros: " << tot_zeros << endl;
	sort(pos.begin(), pos.end());
	sort(neg.begin(), neg.end());
	ll mid, h, l;
	h = 1e18+10, l = -1e18-10;
	// h = 100, l = -100;
	while(l <= h) {
		mid = l + (h - l) / 2;
		// cout << "mid: " << mid << " with range [l, r] = [" << l << ", " << h << "]" << endl;		
		ll count = 0;
		if(mid < 0) {
			for(i=0; i<neg.size(); i++) {
				int bigger = pos.end() - lower_bound(pos.begin(), pos.end(), ((mid + neg[i] + 1) / neg[i]));
				// cout << "For neg[i]= " << neg[i] << ", mid/neg[i]=" << (mid+neg[i] + 1) / (neg[i]) << ", bigger: " << bigger << endl;
				count += bigger;
			}
		}
		else {
			if(mid > 0) count += tot_zeros;
			count += neg.size()*pos.size();
			for(i=0; mid>0 && i<neg.size(); i++) {
				ll x = (mid + abs(neg[i]) - 1) / abs(neg[i]);
				int bigger = neg.end() - upper_bound(neg.begin()+i+1, neg.end(), -x);
				// cout << "For neg[i]= " << neg[i] << ", mid/neg[i]=" << -x << ", bigger: " << bigger << endl;
				count += bigger;
			}
			for(i=0; mid>0 && i<pos.size(); i++) {
				ll x = (mid + pos[i] - 1) / pos[i];
				int bigger = lower_bound(pos.begin()+i+1, pos.end(), x) - pos.begin()-i-1;
				// cout << "For pos[i]= " << pos[i] << ", mid/pos[i]=" << x << ", bigger: " << bigger << endl;
				count += bigger;
			}
		}
		// cout <<"Count after loop: " << count << endl;
		if(count < k) {
			l = mid + 1;
		}
		else {
			h = mid - 1;
		}
		// if(mid == (l + (h-l)/2))
		// 	break;
	}
	cout << (l + h) / 2 << endl;
}

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


Measured memory_bytes: 3956
N,K=map(int,raw_input().split())
A=map(int,raw_input().split())

import collections
D = collections.defaultdict(int)

for a in A:
    a2=format(a, 'b')
    for i,a20 in enumerate(a2[::-1]):
        if a20=="1":
            D[i]+=1


K2=format(K, 'b')
K2=K2.zfill(max(D)+1)


Ans=0
n=len(K2)

for i in range(n):
    if K2[i]=="0":
        Ans+=(2**(n-i-1))*D[n-i-1]
    else:
        if D[n-i-1]>N-D[n-i-1]:
            Ans+=(2**(n-i-1))*D[n-i-1]
            break
        else:
            Ans+=(2**(n-i-1))*(N-D[n-i-1])
    
if i<n-1:
    Ans+=sum((2**(n-j-1))*max(D[n-j-1],N-D[n-j-1]) for j in range(i+1,n))

print Ans

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

#define min(x,y) ((x)<(y)?(x):(y))

int qsort_lld(const void *a, const void *b) {
    if (*(long long *)a < *(long long *)b) {
        return 1;
    }
    return -1;
}

int main(int argc, char *argv[])
{
    int x, y, z, k;
    long long a[1000], b[1000], c[1000];
    int yz;
    long long *d;
    long long *e;
    int xyz;
    int i;
    int ans;

    scanf("%d %d %d %d", &x, &y, &z, &k);
    
    d = malloc(sizeof(long long) * y * z);
    e = malloc(sizeof(long long) * x * min(3000, y * z));

    for (i = 0; i < x; i++) {
        scanf("%lld", &a[i]);
    }
    for (i = 0; i < y; i++) {
        scanf("%lld", &b[i]);
    }
    for (i = 0; i < z; i++) {
        scanf("%lld", &c[i]);
    }

    // D = B + C (Dは最大1e6要素)
    yz = y * z;
    for (i = 0; i < yz; i++) {
        d[i] = b[i / z] + c[i % z];
    }

    // 降順ソートする
    qsort(a, x, sizeof(long long), qsort_lld);
    qsort(d, yz, sizeof(long long), qsort_lld);

    // E = A + D
    // ただし，Dのうち上から最大3000要素のみを使う
    // すると，Eは最大で3000000要素 (3e6)
    yz = min(yz, 3000);
    xyz = x * yz;
    for (i = 0; i < xyz; i++) {
        e[i] = a[i / yz] + d[i % yz];
    }
    
    // 降順ソート
    qsort(e, xyz, sizeof(long long), qsort_lld);

    for (i = 0; i < k; i++) {
        printf("%lld\n", e[i]);
    }

    free(d);
    free(e);

    return 0;
}


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

using namespace std;

void solve()
{
	int N, K;
	cin >> N >> K;
	vector<int> l(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	int ans = 0;
	for (int i = 0; i < K; ++i)
	{
		ans += l[l.size() - 1 - i];
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/
int n, m, q;
vector<int> a(0);
vector<int> b(0);
vector<int> c(0);
vector<int> d(0);
int ans = 0;

void dfs(vector<int> a_array) {
    if (a_array.size() == n) {
        int num = 0;
        rep(i, q) {
            if (a_array[b[i] - 1] - a_array[a[i] - 1] == c[i])
                num += d[i];
        }
        ans = max(num, ans);
    }
    else {
        int num = 1;
        if (a_array.size() != 0)
            num = a_array[a_array.size() - 1];
        for (int i = num; i <= m; i++) {
            a_array.emplace_back(i);
            dfs(a_array);
            a_array.erase(a_array.begin() + a_array.size() - 1);
        }
    }
}

int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        int ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        a.emplace_back(ai);
        b.emplace_back(bi);
        c.emplace_back(ci);
        d.emplace_back(di);
    }
    vector<int> a_array(0,0);
    dfs(a_array);
    cout << ans << endl;
    return 0;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

int main() {
    int N, M, X;
    int A[100];

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

    int l = 0;
    int r = 0;

    for (int i = 0; i < M; i++){
        if (A[i] < X) {
            l++;
        } else {
            r++;
        }
    }

    if (r > l){
        cout << l << endl;
    } else{
        cout << r << endl;
    }
    
    return 0;
}

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

int main(){
	long long n;
	cin>>n;
	long long s1=0,s2=0,ans=0;
	long long a[n+1],b[n+1],c[n+1];
	long long h=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		s1+=a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		s2+=b[i];
		if(b[i]>a[i]){
			h+=b[i]-a[i];
			ans++;
		}
		c[i]=a[i]-b[i];
	}
	if(s2>s1){
		cout<<-1<<endl;
		return 0;
	}
	sort(c+1,c+n+1);
	if(h<=0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=n;i>=1;i--){
		h-=c[i];
		//cout<<c[i]<<endl;
		if(h<=0){
			cout<<++ans<<endl;
			return 0;
		}
		++ans;
	}
}
//

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    vector<int> v;
    vector<bool> kt(6, true);
    int a, b, c, d, e, k;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);
    scanf("%d", &e);
    scanf("%d", &k);
    
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    
    for(int i = 0; i < 6; ++i)
    {
        for(int j = 0; j < 6; ++j)
        {
            if(kt[i] && abs(v[i] - v[j]) > k) 
            {
                printf(":(");
                return 0;
            }
            else if(kt[i] && abs(v[i] - v[j]) <= k) kt[i] = false;
        }
    }
    
    printf("Yay!");
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[111111];
bool ei[111111];

vint solve(vint a){
    int cur=0;

    vint ret;
    rep(i,a.size()){
        rep(j,a[i])ret.pb(cur+1+j);
        ret.pb(cur);
        cur+=1+a[i];
    }

    return ret;
}

signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    if(N==2){
        cout<<"1 2"<<endl;
        return 0;
    }

    rep(i,N){
        if(G[i].size()!=1)ei[i]=true;
    }


    vint lis;
    rep(i,N){
        if(!ei[i])continue;

        int d=0;
        for(auto u:G[i]){
            if(!ei[u])continue;
            d++;
        }

        /*
        if(d==0){
            vint ans;
            ans.pb(1);
            for(int j=3;j<N;j++)ans.pb(j);
            ans.pb(2);
            ans.pb(N);
            rep(j,N){
                if(j)cout<<" ";
                cout<<ans[j];
            }cout<<endl;
            return 0;
        }*/

        if(d>2){
            cout<<-1<<endl;
            return 0;
        }
        if(d<=1){
            lis.pb(i);
        }
    }


    int x,y;
    x=lis[0];
    y=lis.back();

    int pre=-1;
    vint vs;
    while(true){
        vs.pb(x);
        if(x==y)break;
        for(auto u:G[x]){
            if(u==pre)continue;
            if(!ei[u])continue;
            pre=x;
            x=u;
            break;
        }
    }

    vint hoge;
    hoge.pb(0);
    rep(i,vs.size()){
        int d=0;
        for(auto u:G[vs[i]])if(!ei[u])d++;
        if(i==0)d--;
        if(i+1==vs.size())d--;
        hoge.pb(d);
    }
    hoge.pb(0);

    vint ans=solve(hoge);
    reverse(all(hoge));
    chmin(ans,solve(hoge));

    rep(i,ans.size()){
        if(i)cout<<" ";
        cout<<ans[i]+1;
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 10980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  queue<string> que;
  que.emplace(s);
  bool yes = false;
  while (!que.empty()) {
    string p = que.front(); que.pop();
    if (p == "ABC") {
      yes = true;
      break;
    }
    if ((int)p.size() <= 3) continue;
    int pz = p.size(), used[3] = {};
    bool no_abc = true;
    for (int i = 0; i < pz; i++) {
      if (i + 3 <= pz && p.substr(i, 3) == "ABC") {
        no_abc = false;
        if (i + 3 == pz) break;
        i += 2;
      } else {
        used[p[i] - 'A']++;
      }
    }
    if (no_abc) continue;
    bool all_used = true;
    for (int $ = 0; $ < 3; $++) {
      all_used &= used[$];
    }
    if (all_used) continue;
    for (int $ = 0; $ < 3; $++) {
      if (used[$]) continue;
      string t;
      for (int i = 0; i < pz; i++) {
        if (i + 3 <= pz && p.substr(i, 3) == "ABC") {
          t += char($ + 'A');
          if (i + 3 == pz) break;
          i += 2;
        } else {
          t += p[i];
        }
      }
      que.emplace(t);
    }
  }
    cout << (yes ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n;
    long long i=0;
    long long sum=0;
    cin >> n;
    while(i<=n){
        if(i%3 != 0 && i%5 !=0) sum += i;
        i++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int k;
    cin >> k;
    if(k%2 == 1){
        cout << (k+1)*(k-1)/4 << endl;
    }
    else{
        cout << k*k/4 << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

n,x,t=map(int,input().split())
print(t*(-(-n//x)))

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

enum{ OPEN, CLOSE };
typedef struct{
    char id[20];
} ID;

int isID(char id[], ID* reg, int regSize){
    int i;

    for(i = 0; i < regSize; i++){
        if(strcmp(id, reg[i].id) == 0){
            return 1;
        }
    }
    return 0;
}

int main(void){
    int i;
    int n, m;
    int state = CLOSE;

    scanf("%d", &n);
    ID* u = (ID *)malloc(n * sizeof(ID));

    for(i = 0; i < n; i++){
        scanf("%s", u[i].id);
    }

    scanf("%d", &m);
    ID* t = (ID *)malloc(m * sizeof(ID));

    for(i = 0; i < m; i++){
        scanf("%s", t[i].id);
    }

    for(i = 0; i < m; i++){
        if(isID(t[i].id, u, n)){
            if(state == CLOSE){
                printf("Opened by %s\n", t[i].id);
                state = OPEN;
            }
            else{
                printf("Closed by %s\n", t[i].id);
                state = CLOSE;
            }
        }
        else{
            printf("Unknown %s\n", t[i].id);
        }
    }

    free(u);
    free(t);

    return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;
import java.util.Arrays;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) A[i] = sc.nextInt();
		Arrays.sort(A);
		boolean[] ng = new boolean[A[N - 1] + 1];
		int count = 0;
		for (int i = 0; i < N; i++) {
			if (!ng[A[i]]) {
				if (!(i + 1 < N && A[i + 1] == A[i])) count++;
				for (int j = A[i]; j <= A[N - 1]; j += A[i]) ng[j] = true;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 59996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

int main(){
    int n, k;
    std::cin >> n >> k;
    std::vector<int> p(n);
    for(int i = 0; i < n; i++){
        std::cin >> p[i];
    }

    std::sort(p.begin(), p.end());



    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += p[i];
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int a[200000], b[200000];

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

	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 0; i < n-1; i++)
		b[i] = a[i + 1] - a[i];

	b[n - 1] = (k - a[n - 1]) + a[0];

	sort(b, b + n);

	cout << k - b[n - 1];
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main(void) {
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long a=0,b=0,c=0,d=0,m=0,n=0,p=0,q=0;

cin >> a;

vector<long long> x(a,0);

for(int i=0;i<a;i++)
{
cin >> x.at(i);
if(x.at(i)>b)
{
b=x.at(i);
}
if(x.at(i)<b)
{
c+=b-x.at(i);
}
}

cout << c;

}

Measured memory_bytes: 4844
def add_each_number(num):
  s = str(num)
  array = list(map(int, s))
  return sum(array)
 
n = int(input())
first_stand = 0
second_stand = 0
first_height = 0
second_height = 0
total = 0
height_list = map(int, input().split())
for second_height in height_list:
  if( (first_stand + first_height) > second_height ):
    second_stand = (first_stand + first_height) - second_height
  else:
    second_stand = 0
  total += second_stand
  first_stand = second_stand
  first_height = second_height
print(total)
  
  
  
  
  


Measured memory_bytes: 94128
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();   
            var a = Reads();
            long ans = 0;
            a = a.OrderByDescending(x => x).ToArray();
            for (int i = 0; i < n; i+=2)
            {
                if (i + 1 == n) ans += a[i];
                else ans += a[i] - a[i+1];
            }

            Console.WriteLine(ans);



            Console.Out.Flush();
        }
    }
}




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

int main() {
	string _s, _t; cin >> _s >> _t;
	int sn = _s.size(), tn = _t.size();
	int s[sn] = {}, t[tn] = {};
	for(int i = 1; i <= sn; ++i) {
		s[i] = s[i - 1] + (_s[i - 1] == 'A' ? 1 : 2);
	}
	for(int i = 1; i <= tn; ++i) {
		t[i] = t[i - 1] + (_t[i - 1] == 'A' ? 1 : 2);
	}
	int q; cin >> q;
	while(q--) {
		int sl, sr; cin >> sl >> sr;
		int tl, tr; cin >> tl >> tr;
		int x = (s[sr] - s[sl - 1]) % 3;
		int y = (t[tr] - t[tl - 1]) % 3;
		if(x == y) {
			cout << "YES" << '\n';
		} else {
			cout << "NO" << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(ll arg_X,ll arg_Y){
		X = arg_X;
		Y = arg_Y;
	}
	ll X,Y;
};

int main(){

	ll W,H;
	scanf("%lld %lld",&W,&H);

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

	vector<Info> V;
	vector<ll> V_X,V_Y;
	ll tmp_X,tmp_Y;

	for(int i = 0; i < N; i++){
		scanf("%lld %lld",&tmp_X,&tmp_Y);
		V.push_back(Info(tmp_X,tmp_Y));
		V_X.push_back(tmp_X);
		V_Y.push_back(tmp_Y);
	}

	sort(V_X.begin(),V_X.end());
	sort(V_Y.begin(),V_Y.end());

	vector<ll> X_CAN,Y_CAN;

	X_CAN.push_back(V_X[(N-1)/2]);
	X_CAN.push_back(V_X[(N-1)/2+1]);

	Y_CAN.push_back(V_Y[(N-1)/2]);
	Y_CAN.push_back(V_Y[(N-1)/2+1]);

	ll ans = 9999999999999999;
	ll ans_X,ans_Y;

	for(int i = 0; i < X_CAN.size(); i++){
		tmp_X = X_CAN[i];
		for(int k = 0; k < Y_CAN.size(); k++){
			tmp_Y = Y_CAN[k];

			ll tmp_sum = 0;
			ll max_value = 0;

			for(int a = 0; a < N; a++){
				tmp_sum += abs(tmp_X-V[a].X)+abs(tmp_Y-V[a].Y);
				max_value = max(max_value,abs(tmp_X-V[a].X)+abs(tmp_Y-V[a].Y));
			}

			tmp_sum = 2*tmp_sum-max_value;

			if(tmp_sum < ans){
				ans = tmp_sum;
				ans_X = tmp_X;
				ans_Y = tmp_Y;
			}else if(tmp_sum == ans){
				if(ans_X != tmp_X){
					ans_X = min(ans_X,tmp_X);
				}else{
					ans_Y = min(ans_Y,tmp_Y);
				}
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 7420
//#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>

#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll f[110][11];
ll p[110][10];
ll day[10];
main(){
  ll n;
  cin>>n;
  rep(i,0,n){
    rep(j,0,10){
      cin>>f[i][j];
      if(f[i][j]==1)day[j]++;
    }
  }
  rep(i,0,n){
    rep(j,0,11){
      cin>>p[i][j];
    }
  }
  ll nans=-1e9;
  for(int mask = 1; mask < (1 << 10); mask++){
    ll ans=0;
     rep(i,0,n){
       ll tmp=0;
        rep(j,0,10){
          if(mask&(1<<j)&&f[i][j]==1)tmp++;
        }
        ans+=p[i][tmp];
     }
     nans=max(ans,nans);
  }
  cout<<nans;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


int main(){
	double t;
	P a,b,c,d;
	while(cin>>a.F>>a.S>>b.F>>b.S>>c.F>>c.S>>d.F>>d.S){
		bool f=false;
		if((d.F>=a.F)&&c.F<=b.F){
			if((d.S>=a.S)&&c.S<=b.S){
				f=true;
			}
		}
		if(f) cout<<"YES\n";
		else cout<<"NO\n";
		
	}
	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>

#define MAX_E (1000000)

int main(void)
{
    int e;
    int m;
    int x, y, z;
    
    while (1){
        scanf("%d", &e);
        if (e == 0){
            break;
        }
        
        m = MAX_E;
        
        for (z = 0; z * z * z <= e; z++){
            for (y = 0; y * y <= e; y++){
                if (z * z * z + y * y > e){
                    break;
                }
            
                x = e - z * z * z - y * y;
                if (m > x + y + z){
                    m = x + y + z;
                }
            }
        }
                        
        printf("%d\n", m);
    }
    
    return (0);
}

    
    

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  while (cin >> s) {
    int sz = s.size(), now = 0;
    while (now < sz) {
      if (s[now] == '@') {
        int t = s[++now] - '0';
        char ch = s[++now];
        for (int i = 0; i < t; i++) {
          cout << (char)ch;
        }
      } else {
        cout << s[now];
      }
      now++;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3120
n, x = map(int, input().split())
burger = [2 ** (i + 2) - 3 for i in range(n)]
burger2 = [2 ** (i + 1) - 1 for i in range(n)]
num = [0 for i in range(n)]
ans = 0
temp = n - 1
while x > 0:
    if x >= 1:
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        ans += 1
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        x -= 1
    else:
        continue
for i in range(n):
    ans += burger2[i] * num[i]
print(ans)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string n; cin >> n;
	if(n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes\n";
	else cout << "No\n";
}

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

int main() {
  int s;
  cin>>s;
  const int MOD = 1000000007;

  if(s<=2) {
    cout<<0<<endl;
    return 0;
  }
  else if(s<=5) {
    cout<<1<<endl;
    return 0;
  }


  int ans[s+1];
  for(int i=0; i<s+1; i++) ans[i]=0;
  ans[3]=1;
  ans[4]=1;
  ans[5]=1;

  for(int i=6; i<s+1; i++) {
    int tmp = 1;
    for(int j=3; j<=i-3; j++) {
      tmp += ans[j];
      tmp = tmp%MOD;
    }
    ans[i] = tmp;
  }

  cout<<ans[s]<<endl;


  return 0;
}

Measured memory_bytes: 3644
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import static java.lang.Character.toLowerCase;


public class Main {

    // input
    static int n;
    static int k;
    static String s;
    
    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        s = sc.next();
        sc.close();
    }
 
    /**
     * solver
     */
    static void solve(){ 
        String ans = "";
        for (int i=0;i<n;i++) {
            if (i + 1 == k){
                ans += Character.toLowerCase(s.charAt((i)));  
            } else {
                ans += s.charAt(i);
            }
        }
        System.out.println(ans);
    }

    public static void main(String args[]) {

        input();

        solve();
    }
}


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

int main() {
  int N,A,a;
  cin >> N >> A;
  
  a = N % 500;
  if(N <= 500){
    if(A >= N){
     cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (N >= 500){
   if(A >= a){
     cout << "Yes" << endl;
   }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("6");
            WillReturn.Add("5");
            WillReturn.Add("3");
            WillReturn.Add("1");
            WillReturn.Add("3");
            WillReturn.Add("4");
            WillReturn.Add("3");
            //3
            //?????????1?????¨????????£???
            //4?????¨???????£??????¨4-1=3??§?????§3???????????????????????¨?????§????????????
            //?????????5???????????¨5-1=4??¨??????????????????
            //?????????5?????????????????????????????§?¨±??????????????????
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3");
            WillReturn.Add("4");
            WillReturn.Add("3");
            WillReturn.Add("2");
            //-1
            //?????????????°???????????????±????????§?????????
            //??????????????§???J > I ??¨???????????¶?????????
            //?????£????£????????\????1????????????????????????????????§???
            //?????§?????????-1??¨???????????????
        }
        else if (InputPattern == "Input3") { //???????¨???????
            WillReturn.AddRange(Enumerable.Repeat("100000000", 200000));
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] R = InputList.Skip(1).Select(X => int.Parse(X)).ToArray();

        int MinValue = R[0]; //????°???????
        int MaxProfit = int.MinValue; //?????§??????

        for (int I = 1; I <= R.GetUpperBound(0); I++) {
            int CurrProfit = R[I] - MinValue;

            //?????§???????????´??°
            if (MaxProfit < CurrProfit)
                MaxProfit = CurrProfit;

            //????°????????????´??°
            if (MinValue > R[I])
                MinValue = R[I];
        }
        Console.WriteLine(MaxProfit);
    }
}

Measured memory_bytes: 23964
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


vector<pair<int,int>> soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}

int mod=998244353;

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

    int a[n],b[n];
    rep(i,0,n){
        cin>>a[i]>>b[i];
    }

    sort(a,a+n);
    sort(b,b+n);

    if(n%2){
        int amid=a[n/2];
        int bmid=b[n/2];
        cout<<bmid-amid+1<<endl;
    }else{
        int amid=(a[n/2 -1]+a[n/2]);
        int bmid=(b[n/2 -1]+b[n/2]);

        cout<<(bmid-amid)+1<<endl;
    }
    
}  

Measured memory_bytes: 6724
def estr(s):
    if len(s) % 2 == 1:
        return False
    else:
        for i in range(len(s) // 2):
            if s[i] != s[i + len(s) // 2]:
                return False
    return True

s = input()

for i in range(len(s)):
    s = s[:-1]
    if estr(s):
        break

print(len(s))


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToList();

            var even = 0;

            for(int i = 0; i < n; i++)
            {
                if(a[i] % 2 == 0)
                {
                    even++;
                }
            }

            var odd = n - even;

            if(odd % 2 != 0)
            {
                Console.WriteLine("NO");
                return;
            }

            odd /= 2;

            Console.WriteLine("YES");
        }
    }
}


Measured memory_bytes: 38680
#include<bits/stdc++.h>
using namespace std;
# define int long long
# define mo 1000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

signed main()
{
   gok
    int n;
    cin>>n;
    if(n%2==1)
        cout<<0;
    else
    {
        int an=0;
        int p=5;
        while(p<=n)
        {
            an += n/(2*p);
            p*=5;
        }
        cout<<an;
    }
    return 0;
}


Measured memory_bytes: 384
/**
 * Author: Behradm
 * Created: 10-05-2020 16:27:01
 * In the Name of God
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout.tie(0);
	cout.precision(6);
	string a, b;
	cin >> a >> b;
	for (int i = 0; i < sz(a); i++)
		if (a[i] != b[i]){
			cout << "No\n";
			return 0;
		}
	cout << "Yes\n";
	return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
string a,b;
int dp[3003][3003];
ii way[3003][3003];
void print(int i,int j){
    //debugs(i,j);
    if(i>=sz(a)||j>=sz(b))
        return ;
    if(a[i]==b[j])
        cout<<a[i];
    if(way[i][j].fi==way[i][j].se&&!way[i][j].se)
        return ;
    print(i+way[i][j].fi,j+way[i][j].se);
}
int solve(int i,int j){
    if(i==sz(a)||j==sz(b))
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    int ans=0;
    if(a[i]==b[j]){
        int temp=1+solve(i+1,j+1);
        if(temp>ans)
            ans=temp,way[i][j]={1,1};
    }
    else{
        int temp=solve(i+1,j);
        if(temp>ans)
            ans=temp,way[i][j]={1,0};
        temp=solve(i,j+1);
        if(temp>ans)
            ans=temp,way[i][j]={0,1};
    }
    return dp[i][j]=ans;
}
int main(){
    boost;
    memset(dp,-1,sizeof dp);
    cin>>a>>b;
    solve(0,0);
    print(0,0);
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 105344
#include<iostream>
#include<algorithm>
using namespace std;
#define FOR(i, a, n) for(int i=a; i<n; i++)
#define RFOR(i, a, n) for(int i=n-1; i>=a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 0, n)

int main()
{
	int n;
	while (cin >> n, n) {
		int dp[301][301] = {};
		int w[301];
		REP(i, n) cin >> w[i];

		FOR(k, 1, n) {
			for (int i = 0; i + k < n; i++) {
				if (abs(w[i] - w[i + k]) <= 1) {
					if (dp[i + 1][i + k - 1] == k - 1) {
						dp[i][i + k] = dp[i + 1][i + k - 1] + 2;
					}
				}
				for (int j = i; j < i + k; j++) {
					dp[i][i + k] = max(dp[i][i + k], dp[i][j] + dp[j + 1][i + k]);
				}
			}
		}

		cout << dp[0][n - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3400