akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int now=0,N;

int main(){
    cin>>N;
    int A[N];
    rep(i,N){
        cin>>A[i];
        A[i]--;
    }
    stack<int> sta;
    string ans="";
    bool isok = true;
    rep(i,N){
        if(now<=A[i]){
            while(now<=A[i]){
                ans += "(";
                sta.push(now);
                now++;
            }
        }
        else if(sta.top() != A[i]){
            isok = false;
            break;
        }
        ans+=")";
        sta.pop();
    }
    if(isok)out(ans);
    else out(":(");
    
}



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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int x,y,a,b;
  cin>> x >> y;
  a=(2*y-x)/3;
  b=(2*x-y)/3;
  if(a*3 != 2*y-x || b*3 != 2*x-y){
    cout<<0<<endl;
    return 0;
  }

  COMinit();
  //cout<<a<<" "<<b<<endl;

    cout << COM(a+b, a) << endl;
}





Measured memory_bytes: 27036
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	a = parseMap(split(chomp(readline()),""))
	k = readline() |> parseInt
	n = length(a)
	dp = zeros(Int,n,k+1,2)
	dp[1,2,1] = a[1]-1
	dp[1,2,2] = 1
	dp[1,1,1] = 1
	for i in 2:n
		for j in 1:k+1
			dp[i,j,1] += dp[i-1,j,1]
			if a[i] == 0
				dp[i,j,2] = dp[i-1,j,2]
			else
				dp[i,j,1] += dp[i-1,j,2]
			end
			if j>1
				dp[i,j,1] += dp[i-1,j-1,1]*9+dp[i-1,j-1,2]*(max(a[i]-1,0))
				if a[i]>0
					dp[i,j,2] = dp[i-1,j-1,2]
				end
			end
		end
	end
	println(dp[n,k+1,1]+dp[n,k+1,2])
end

main()

Measured memory_bytes: 167672
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif

int rahul;
cin>>rahul;

cout<<pow(2, int(log(rahul)/log(2)))<<endl;

return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define maxs 2020202
#define ll long long
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int check(int t){

    int ans=0;
    while(t){
        ans++;
        t/=10;
    }
    return ans;
}

int main()
{
    long long n;
    ll ans,output=LONG_LONG_MAX;

    while(~scanf("%lld",&n)){
        for(int i=1;i<=sqrt(n);i++){
            if(n%i==0){
                int tmp = check(i),tp=check(n/i);
                ans =max(tmp,tp);
                output=min(ans,output);
            }
        }
        printf("%lld\n",output);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main(){
    int x,i = 0;
    while(true){
        std::cin >> x;
        if(x!=0){
            i += 1;
            std::cout << "Case " << i <<": " << x << std::endl;
        }else break;
    }
    return 0;
}


Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
int main(){
    char inp[3];
    int ans=0;
    cin >> inp;
    
    switch(inp[0]){
        case 'M':ans=6;break; 
        case 'W':ans=4;break;
        case 'F':ans=2; break;
        case 'S':
            if(inp[1]=='U') ans=7;
            else ans=1;
            break;
        case 'T':
            if(inp[1]=='U') ans=5;
            else ans=3;
            break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
n, m = (int(x) for x in input().split())
a, c  = [], []
for _ in range(n): a.append([int(x) for x in input().split()])
for _ in range(m): c.append([int(x) for x in input().split()])
ans = []
for i in range(n):
    l = [abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]) for j in range(m)]
    ans.append(l.index(min(l)) + 1)
for i in range(n): print(ans[i])

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define Max 1000

int main()
{
	int N;
	cin >> N;
	int A[Max];

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (int s = 0; s < N; s++)
	{
		cout << A[s];
		if (s < N-1)
			cout << ' ';
	}
	cout << endl;
	for (int i = 1; i < N; i++)
	{
		int tmp = A[i];
		int j = i - 1;
		for (j; j >= 0; j--)
		{
			if (tmp < A[j])
			{
				swap(A[j], A[j + 1]);
			}
			else
				break;
		}
		A[j + 1] = tmp;
		for (int s = 0; s < N; s++)
		{
			cout << A[s];
			if (s < N-1)
				cout << ' ';
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <string>


using namespace std;

int main() {

	int a;
	int num=1,ok=1;
	cin >> a;

	while(1) {
		if (a >= num) {
			ok = num;
			num = num * 2;
		}
		else {
			break;
		}
	}

	cout << ok;

}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	string Sd, T;
	cin >> Sd >> T;
	int st = 100;
	rep(i, Sd.size()-T.size()+1) {
		int fr = 0;
		for (int j = 0; j < T.size(); j++) {
			if (Sd.at(i+j)!='?'&&Sd.at(i+j)!=T.at(j)) {
				fr = 1;
				break;
			}
		}
		if (fr == 0) {
			st = i;
		}
	}
	if (st == 100) {
		cout << "UNRESTORABLE" << endl;
	}
	else {
		rep(i, Sd.size()) {
			if (i >=  st&&i<st+T.size()) {
				cout << T.at(i - st);
			}
			else if (Sd.at(i) == '?') {
				cout << "a";
			}
			else {
				cout << Sd.at(i);
			}
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
	int X;
	scanf("%d",&X);
	int ans=1,x;
	int i,j;
	for(i=1;i<1000;i++){
		for(j=2;j<10;j++){
			x = pow(i,j);
			if(x>X)break;
			if(ans<=x)ans=x;
		}
	}
	out: printf("%d",ans);
	
	return 0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    long long N, K;
    cin>>N>>K;
    vector<long> H(N);
    rep(i, N) cin>>H.at(i);
    sort(H.begin(),H.end(),greater<int>());
    rep(i, K){
        if(N<=i)
            continue;
         H.at(i) = 0;

    }
    long long sum = 0;
    rep(i, N) sum += H.at(i);
    cout << sum << endl;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    vi cup(N), mag(N);
    cup[0] = 1;
    int ball = 0;
    for (int i = 0; i <= Q; ++i) {
        for (int j = max(0, ball - 1); j < min(N, ball + 2); ++j) {
            mag[j] |= 1;
        }
        if (i == Q)break;
        int a, b;
        cin >> a >> b;
        --a, --b;
        if (cup[a] || cup[b]) {
            ball = cup[a] ? b : a;
        }
        swap(cup[a], cup[b]);
        swap(mag[a], mag[b]);
    }
    int ans = accumulate(all(mag), 0);
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<set>

using namespace std;

int main(){
  int n;
 cin >> n;
  int d[n];
  set<int> s;
  for(int i=0;i<n;i++) {cin>>d[i];
                        s.insert(d[i]);
                       }

 cout << s.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

const int maxn = 100000+7;
using namespace std;

int a[maxn],n,cnt;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==1)++cnt;
	}
	if(cnt%2==1 && n>1)printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


void solve_i(vpii&ans, int k, int hx, int hy, int x, int y)
{
	for(;;)
	{
		int d=abs(hx-x)+abs(hy-y);

		if(d==0) break;
		if(d%k)
		{
printf("d%%k=%d\n", d%k);
			ans.push_back(make_pair(-999999,-999999));
			return;
		}
		int sx=(hx-x)>0?1:-1;
		int sy=(hy-y)>0?1:-1;

		int vx=min(abs(hx-x), k)*sx;
		int vy=(k-abs(vx))*sy;

		x+=vx;
		y+=vy;
		ans.push_back(make_pair(x, y));
	}
}


void solve(vpii&ans, int k, int hx, int hy, int x, int y)
{
	int dx=abs(hx-x);
	int dy=abs(hy-y);
	int d=dx+dy;
	int sx=(hx-x)>0?1:-1;
	int sy=(hy-y)>0?1:-1;
	ll s=(d+k-1)/k;

	if(k%2==0 && d%2==1) return;
	if(s==1 && k!=d) s++;
	if((k*s)%2!=d%2) s++;
	int r=k*s-d;
	int vx, vy;

//printf("solve(k=%d hx=%d hy=%d x=%d y=%d r=%d s=%lld\n", k, hx, hy, x, y, r, s);

	if(r%k==0)
	{
		solve_i(ans, k, hx, hy, x, y);
		return;
	}

	if(dy>dx)
	{
		vx=-min(r/2, k)*sx;
		vy=(k-abs(vx))*sy;
	}
	else
	{
		vy=-min(r/2, k)*sy;
		vx=(k-abs(vy))*sx;
	}
	x+=vx;
	y+=vy;
	ans.push_back(make_pair(x, y));
	solve(ans, k, hx, hy, x, y);
	return;
}


int main(void)
{
	int k, x, y;

	while(scanf("%d%d%d", &k, &x, &y)==3)
	{
		vpii ans;

		solve(ans, k, x, y, 0, 0);

		if(ans.size()==0)
		{
			printf("%d\n", -1);
			continue;
		}

		printf("%d\n", ans.size());
		for(auto&ma:ans)
		{
			printf("%d %d\n", ma.first, ma.second);
		}
	}
	return 0;
}


Measured memory_bytes: 3952
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll N,K;
  cin >> N >> K;
  vector<pair<ll,ll> > xy;
  vector<ll> x,y;
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    xy.pb(mp(a,b));
    x.pb(a),y.pb(b);
  }
  
  sort(all(x));
  sort(all(y));


  ll ans = 5000000000000000000;
  //x:i<j
  //y:k<l
  rep(i,x.size())FOR(j,i+1,x.size())rep(k,y.size())FOR(l,k+1,y.size()){
    ll num = 0;
    rep(a,xy.size()){
      if(x[i]<=xy[a].first && xy[a].first<= x[j] && y[k]<=xy[a].second && xy[a].second<=y[l])num++;
    }

    if(num>=K){
      ans = min(ans,(x[j]-x[i])*(y[l]-y[k]));
    }
  }

  cout << ans << endl;;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

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

	int a, b;
	cin >> a >> b;

	if ((a & 1) && (b & 1)) cout << "Odd" << "\n";
	else cout << "Even" << "\n";

	return 0;
}

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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='1')s.at(i)='9';
    else s.at(i)='1';
  }
  cout<<s<<endl;
}

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

using namespace std;

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

struct UnionFind {
  vector<int> rank, par, W;
  
  UnionFind(int n)
  {
    rank.resize(n);
    par.resize(n);
    rep(i, n) rank[i] = 1, par[i] = i;
    W.resize(n);
  }

  pair<int, int> find(int x) {
    if(x == par[x]) { return make_pair(x, 0); }
    pair<int, int> ret = find(par[x]);
    par[x] = ret.first;
    W[x] += ret.second;
    return make_pair(par[x], W[x]);
  }
  
  void unite(int u, int v, int c) {
    pair<int, int> px = find(u), py = find(v);
    int x = px.first, y = py.first;
    if(x == y) return;
    if(rank[x] > rank[y]) {
      par[y] = x;
      W[y] = c+W[u]-W[v];
    }
    else {
      par[x] = y;
      W[x] = -(c+W[u]-W[v]);
      if(rank[x] == rank[y]) { rank[y] ++; }
    }
  }

  bool same(int u, int v) { return find(u).first == find(v).first; }
  
  // テゥツ?催」ツ?ソテ」ツ?ョテ・ツキツョテ」ツつ津ァツュツ氾」ツ?暗」ツつ?
  int diff(int u, int v) {
    return W[v]-W[u];
  }
  
};

int main() {

  for(int N, M; cin >> N >> M && (N|M);) {
    UnionFind uf(N*2);
    rep(i, M) {
      char op; cin >> op;
      int u, v; cin >> u >> v;
      if(op == '!') {
        int c; cin >> c;
        uf.unite(u, v, c);
      }
      else {
        if(uf.same(u, v)) {
          cout << uf.diff(u, v) << endl;
        }
        else {
          puts("UNKNOWN");
        }
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 3416
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(true){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl;
        for(int i=1;i<H-1;i++){
            cout<<'#';
            for(int j=1;j<W-1;j++){
                cout<<'.';
            }
            cout<<'#'<<endl;
        }
        for(int j=0;j<W;j++){
            cout<<'#';
        }
        cout<<endl<<endl;
    }
}
       


Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>

using namespace std;

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

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

int main(int argc, const char * argv[]) {

    // source code
    // char s[4];
    int A, B;
    cin >> A >> B;
    if (A >= 13) {
      cout << B <<endl;
    }else if (A >= 6 ){
      cout << B/2 <<endl;
    }else{
      cout << 0 <<endl;
    }


    return 0;
}


Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP
n,m=map(int,input().split())
X=((n-m)*100+1900*m)*(0.5**m)
j=0
for i in range(10**6):
    j+=X*i*((1-(0.5)**m)**(i-1))

print(Decimal(str(j)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,k;
  cin >> n >> k;
  vector<int32> a(n);
  REP(i,n)cin >> a[i];
  vector<int64> asum(n+1),apsum(n+1,0);
  REP(i,n)asum[i+1] = asum[i] + a[i];
  REP(i,n)apsum[i+1] = apsum[i] + max<int32>(0,a[i]);
  int64 ans = 0;
  FOR(i,k,n+1){
    chmax(ans, max<int64>(0,asum[i] - asum[i-k]) + apsum[i-k] + apsum[n] - apsum[i]);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 5544
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    string s, s1, s2, s3, s4;
    cin >> s;
    reverse(s.begin(), s.end());
    s1 = "maerd";
    s2 = "esare";
    s3 = "remaerd";
    s4 = "resare";
    int left = 0;
    while(1){
        if (s.size() == left){
            cout << "YES" << endl;
            break;
        }
        if (s.substr(left, s1.size()) == s1 \
        || s.substr(left, s2.size()) == s2){
            left += s1.size();
        }else if (s.substr(left, s3.size()) == s3){
            left += s3.size();
        }else if (s.substr(left, s4.size()) == s4){
            left += s4.size();
        }else {
            cout << "NO" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 512
//yashverma

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define Pi 3.141592653589793
#define MOD 1000000007
// For i/o
#define sd1(a) scanf("%d",&a)
#define sd2(a,b) scanf("%d %d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf scanf
#define pf printf
// For debugging
#define deb(a) printf("deb%d\n",a)

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

int main()
{
	ios::sync_with_stdio(false);
	int arr[1003][1003];
	int h,w;
	cin >> h >> w;
	int n;
	cin >> n;
	int c[1000006];
	rep(i,0,n)cin >> c[i];
	int indx = 0;
	for(int i=0; i < n; i++)
	{
		while(c[i]--)
		{
			int x = indx/w;
			if(x%2 == 0)
			{
				arr[indx/w][indx%w] = i+1;
			}
			else
			{
				arr[indx/w][w - indx%w - 1] = i + 1;
			}
			indx += 1;
		}
	}
	rep(i,0,h)
	{
		rep(j,0,w)cout << arr[i][j] << " ";
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
#include <map>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll N, K, temp;
    vector<ll> H;
    cin >> N >> K;
    REP(i,N){
        cin >> temp;
        H.push_back(temp);
    }
    if(N<=K){
        cout << 0 << endl;
        return 0;
    }
    sort(H.begin(), H.end());
    ll ans = 0;
    FOR(i, 0, N-(K+1)){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5368
<?php
list($n) = ints();
$a = ints();
$cnt = 0;
foreach (array_info($a) as $v)
    $cnt += intdiv($v[1], 2);
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function array_info(array $a): array
{
    $n = count($a);
    $cnt = 0;
    for ($i = 0; $i < $n; $i++) {
        $cnt++;
        if ($i === $n - 1 || $a[$i] !== $a[$i + 1]) {
            $_a[] = [$a[$i], $cnt];
            $cnt = 0;
        }
    }
    return $_a;
}


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

using namespace std;
const int maxn = 40;
const int base = 31337;

int n;
char niz[maxn];
map< pair<int, int>, int> s;

int main() {
	scanf("%d%s", &n, niz);
	for (int i = 0; i < (1 << n); i++) {
		int hasc = 0;
		for (int j = 0; j < n; j++) 
			if (i & (1 << j)) hasc *= base, hasc += niz[j];
		
		int hasp = 0;
		for (int j = n - 1; j >= 0; j--)
			if (!(i & (1 << j))) hasp *= base, hasp += niz[j];
		s[make_pair(hasc, hasp)]++;
	}
	
	long long sol = 0;
	for (int i = 0; i < (1 << n); i++) {
		int hasc = 0;
		for (int j = 0; j < n; j++) 
			if (i & (1 << j)) hasc *= base, hasc += niz[j + n];
		
		int hasp = 0;
		for (int j = n - 1; j >= 0; j--)
			if (!(i & (1 << j))) hasp *= base, hasp += niz[j + n];
		
		sol += s[make_pair(hasp, hasc)];
	}
	printf("%lld", sol);
	return 0;
}

Measured memory_bytes: 33024
s = input()

frommap = []
for d in range(10):
    frommap.append([0] * 13)
    for m in range(13):
        m2 = (m * 10 + d) % 13
        frommap[d][m2] = m

dp = [1] + [0] * 12
for c in s:
    if c == '?':
        dp = [sum(dp[f] for f in fromlist) % 1000000007 for fromlist in zip(*frommap)]
    else:
        dp = [dp[f] for f in frommap[int(c)]]

print(dp[5])

Measured memory_bytes: 44524
#include <stdio.h>
//#define scanf scanf_s
typedef long long int lli;

// ITP1_2_D
// 3つの整数a,b,cを読み込み、aからbの中にcの約数がいくつ含まれているかをカウント
int main()
{
	int iInputA, iInputB;
	char chInputOp;

	scanf("%d %c %d", &iInputA, &chInputOp, &iInputB);

	while (chInputOp != '?')
	{

		switch (chInputOp)
		{
		case '+':
			printf("%d\n", iInputA + iInputB);
			break;
		case '-':
			printf("%d\n", iInputA - iInputB);
			break;
		case '*':
			printf("%d\n", iInputA * iInputB);
			break;
		case '/':
			printf("%d\n", iInputA / iInputB);
			break;
		default:
			break;
		}

		scanf("%d %c %d", &iInputA, &chInputOp, &iInputB);
	}


	return 0;
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define MP make_pair
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double PI = acos(-1);
const double EPS = 1e-9;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

///////////////////////////////////////////////////////

int n;
int B[105];

int solve(){
	int ret = B[1] + B[n-1], val;
	REP(i,2,n-1){
		val = min(B[i-1],B[i]);
		ret += val;
	}
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	REP(i,1,n-1) cin >> B[i];
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
M = max(A)

count = [0 for _ in range(M + 1)]
for i in range(N):
    count[A[i]] += 1

S = 0
for i in range(M + 1):
    m = count[i]
    S += (m * (m - 1)) // 2

ans = [S for _ in range(N)]
for i in range(N):
    m = count[A[i]]
    ans[i] -= m - 1

for i in range(N):
    print(ans[i])

Measured memory_bytes: 32204
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if ((A == B && B != C) || (C == B && B != A) || (A == C && C != B)){
			System.out.println("Yes");
		} else System.out.println("No");
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21716
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
A = get_ints_minus_one

hash = Hash.new

stock = 0
cur = 0
num = 0

loop do
  break if num >= K

  if hash[cur].nil?
    hash[cur] = num
  else
    one_loop = num - hash[cur]
    zan = K - num
    stock = zan % one_loop
    break
  end
  cur = A[cur]
  num += 1
end

stock.times do |i|
  cur = A[cur]
end

puts cur+1


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

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

  long long ans = 1000000010;

  long long tmp;
  for (int p=1; p<=100; p++){
    tmp = 0;
    for (int j=0; j<N; j++) {
      tmp += pow(X[j]-p, 2);
    }
    ans = min(tmp, ans);
  }

  cout << ans << endl;

  return 0;
}


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

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

    set<char> acgt = {'A', 'C', 'G', 'T'};
    string s; cin >> s;
    int ans = 0, suc = 0;
    for (int i = 0; i < (int) s.size(); ++i) {
        if (acgt.count(s[i]) > 0) {
            suc++;
        } else {
            ans = max(ans, suc);
            suc = 0;
        }
        if (i == (int) s.size() - 1) {
            ans = max(ans, suc);
            suc = 0;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    int n,k;
    cin >> n >> k;
    if(k==1) cout << 0 << endl;
    else cout << n-k << endl;
}

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

using namespace std;

typedef long long ll;
const ll N = 1e5;

string s;


int main()
{
    while ( cin >> s )
    {
        if (s.size() == 2)
        {
            cout << s << endl;
        }
        else
        {
            reverse(s.begin(), s.end());
            cout << s << endl;
        }
    }

    return 0;
}


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

int A, B, C, D;

int main() {
	cin >> A >>B >>C>>D;
	
	if(ceil(C*1.0f/B+1) > ceil(A*1.0f/D+1)) {
		cout << "No" << endl;
	}else {
		cout << "Yes" << endl;
	}
		
	return 0;
}


Measured memory_bytes: 3628
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n, ans, i
    integer(int32), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    ans=a(1)
    do i = 2, n
        ans = gcd(ans,a(i))
    end do
    print'(i0)', ans

contains
recursive function gcd(x,y) result(ret)
    integer(int32):: x,y,ret

    if (mod(x,y) == 0) then
        ret = y
        return
    end if

    ret = gcd(y,mod(x,y))
end function
end program name

Measured memory_bytes: 1536
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		ll A,B;
		char op;

		cin >> A >> op >>B;

		if(op=='+'){
			cout << A+B;
		}else if(op=='-'){
			cout << A-B;
		}

		return 0;
    }

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

int main(){
  int M1,D1,M2,D2;
  cin >> M1 >> D1 >> M2 >> D2;
  
  if(D2-D1==1){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }

}

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

using namespace std;

const int MOD = 998244353;

long long pow10(long long p){
    long long res = 1;
    long long cur = 10;
    while(p){
        if(p%2) res = (res*cur)%MOD;
        cur = (cur*cur)%MOD;
        p /= 2;
    }
    return res;
}

vector<long long> makeGrundy(int N){
    int M; cin >> M;
    vector<vector<int>> g(N+1);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        if(a > b) swap(a, b);
        g[a].push_back(b);
    }
    vector<int> grundy(N+1);
    vector<long long> res(512, 0);
    grundy[N] = 0;
    res[0] = pow10(18*N);
    for(int i=N-1;i>=1;i--){
        vector<int> visit(512, 0);
        for(auto& t : g[i]){
             visit[grundy[t]] = 1;
        }
        for(int j=0;j<512;j++){
            if(!visit[j]){
                grundy[i] = j;
                res[j] = (res[j] + pow10(18*i)) % MOD;
                break;
            }
        }
    }
    return res;
}

int main(){
    int N; cin >> N;
    auto g1 = makeGrundy(N);
    auto g2 = makeGrundy(N);
    auto g3 = makeGrundy(N);
    long long res = 0;
    for(int i=0;i<512;i++){
        for(int j=0;j<512;j++){
            res = (res + g1[i] * g2[j] % MOD * g3[i^j] % MOD) % MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4816
#include<stdio.h>
int main(void)
{
	int d1, d2, d3;
	scanf("%d %d %d",&d1,&d2,&d3);

	if(d1==1&&d2==1&&d3==0){
		printf("Open\n");
	}
	if(d1==0&&d2==0&&d3==1){
		printf("Open\n");
	}
	if(d1==1&&d2==0&&d3==0){
		printf("Close\n");
	}
	if(d1==0&&d2==1&&d3==0){
		printf("Close\n");
	}
	if(d1==0&&d2==0&&d3==0){
		printf("Close\n");
	}
	return 0;
	
}

Measured memory_bytes: 1012
#include<stdio.h>
#define L 100000
int main(){
  int i,j,k=0;
  int N;
  long ans=0;
  scanf("%d",&N);
  int A[L+1];
  for(i=1;i<=L;i++)
    A[i]=0;
  
  for(i=0;i<N;i++){
    scanf("%d ",&j);
    if(j <= L )
      A[j]++;
    else
      k++;
  }
  for(i=1;i<=L;i++){
    if(A[i] >= i){
      ans += (A[i]-i);
    }
    else 
      ans += A[i];
  }
  ans+=k;
  printf("%ld\n",ans);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

string ans;
ll DP[3100][3100];
string S, T;

void dfs(int y, int x){
    if(y <= 0 || x <= 0) return;
    ll now = DP[y][x];
    ll up = DP[y-1][x];
    ll left = DP[y][x-1];
    ll ul = DP[y-1][x-1];
    if((now - 1) == ul){
        if(now == up)
            dfs(y-1, x);
        else if(now == left)
            dfs(y, x-1);
        else{
            ans += S[y-1];
            dfs(y-1, x-1);
        }
    }
    else
        dfs(y-1, x-1);
}

int main(){
    cin >> S >> T;

    int SL = S.size();
    int TL = T.size();

    REP(i,SL+1){
        REP(j,TL+1){
            DP[i][j] = 0;
        }
    }

    REPi(i,1,SL+1){
        REPi(j,1,TL+1){
            char x = S[i-1];
            char y = T[j-1];
            ll tmp = 0;
            if(x == y)
                chmax(tmp, DP[i-1][j-1] + 1);
            chmax(tmp, DP[i-1][j]);
            chmax(tmp, DP[i][j-1]);
            DP[i][j] = tmp;
        }
    }

    //REP(i,SL+1){
    //    REP(j,TL+1){
    //        printf("%lld ", DP[i][j]);
    //    }
    //    printf("\n");
    //}

    //ll ans = DP[SL][TL];

    dfs(SL, TL);
    reverse(ans.begin(), ans.end());

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


Measured memory_bytes: 73984
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    A, B, C, D = map(int, input().split())

    l = A + B
    r = C + D

    if l > r:
        print("Left")
    elif l < r:
        print("Right")
    else:
        print("Balanced")

if __name__ == "__main__": main()


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

#define fill(x,y) memset(x,y,sizeof(x))
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pb push_back
#define smp(x,y,z) mp(x,mp(y,z))
#define reads(x) scanf("%s",&x)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)

typedef long long ll;
typedef string s;
typedef pair<ll,ll> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vector<int> > matrix;

const ll oo = 1e16;
const int maxSize = 100100;
const int mod = 1e9+7;

const double EPS = (1e-9);

int dcmp(double x, double y){return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;}

int x,y,arr[100][100],seq[10100] ;

void rec(int i , int j , int n , bool fl){
    arr[i][j] = n+1 ;
    seq[n]--;
    if(seq[n]==0)n++;
    if(fl){
        if(j+1<x)rec(i,j+1,n,fl);
        else if(i+1<y) rec(i+1,x-1,n,!fl);
    }else{
        if(j-1>=0)rec(i,j-1,n,fl);
        else if(i+1<y) rec(i+1,0,n,!fl);
    }
}

int main(){
    int t ;
    cin >> y >> x >> t ;
    for(int i=0;i<t;i++){
        cin>>seq[i] ;
    }
    rec(0,0,0,1);
    for(int i=0 ;i<y;i++){
        for(int j=0;j<x;j++){
            cout << arr[i][j] << " " ;
        }
        cout << endl ;
    }
}


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

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> points(m);
  for(auto& p : points) {
    std::cin >> p;
  }
  std::sort(points.begin(), points.end());
  std::vector<int> differences(m - 1);
  for(int i = 0; i < m - 1; ++i) {
    differences[i] = points[i + 1] - points[i];
  }
  std::cout << std::endl;
  std::sort(differences.begin(), differences.end(), std::greater<int>());
  int sum = 0;
  for(int i = n - 1; i < m - 1; ++i) {
    sum += differences[i];
  }
  std::cout << sum << std::endl;
  return 0;
}

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

int main() {
	int h, w;
	std::cin >> h >> w;
	bool black[55][55] = {0};
	bool hantei = true;

	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			char a;
			std::cin >> a;
			if(a=='#')  black[i][j]=true;
		}
	}


	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (black[i][j]) {
				if (!black[i + 1][j] && !black[i - 1][j] && !black[i][j + 1] && !black[i][j - 1]) {
					hantei = false;
				}
			}
		}
	}

	if (hantei)std::cout << "Yes";
	else std::cout << "No";

}

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

template <typename T>
T gcd(T a, T b){ return b%a==0 ? a : gcd(b%a, a); }

template <typename T>
T lcm(T a, T b){ return (a/gcd(a, b))*b; }

int main()
{
    i64 a,b,c,d;
    cin >> a >> b >> c >> d;

    i64 cd = lcm(c, d);
    i64 c_cnt = b/c - (a-1)/c;
    i64 d_cnt = b/d - (a-1)/d;
    i64 cd_cnt = b/cd - (a-1)/cd;

    i64 ans = b-a+1 - c_cnt - d_cnt + cd_cnt;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l; cin >> n >> l;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) cout << v[i];
  cout << endl;
}

Measured memory_bytes: 256
from math import floor
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def num_divisors(n):
    i = 1
    result = 0
    while i * i <= n:
        if n % i == 0:
            result += 2 if n // i != i else 1
        i += 1
    return result


def solve(n):
    result = 0
    for k in range(1, n + 1):
        result += k/2 * floor(n/k) * floor(1+(n/k))

    return int(result)


if __name__ == "__main__":
    n = int_in()
    out(solve(n))

Measured memory_bytes: 64192
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <map>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll maxn = 1e6 + 5;

int n,Q;
char s[maxn];
set<int>ss[30];

int main(){
	cin>>n>>s+1>>Q;
	for(int i=0;i<26;i++) ss[i].insert(n+1);
	for(int i=1;i<=n;i++) ss[s[i]-'a'].insert(i);
	while(Q--){
		int t,i,l,r;
		char c;
		cin>>t;
		if(t==1){
			cin>>i>>c;
			if(s[i]!=c) ss[s[i]-'a'].erase(i);
			s[i]=c;
			ss[c-'a'].insert(i);
		}else{
			int ans=0;
			cin>>l>>r;
			for(int i=0;i<26;i++)
				if(*ss[i].lower_bound(l)<=r) ans++;
			cout<<ans<<'\n';
		}
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++) cin >> L[i];
  sort(L.begin(), L.end());
  
  int ans = 0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(L[k] < L[i]+L[j]) ans += 1;
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//内積
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//外積
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//直行？
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//平行？
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int main()
{
	int n, k; cin >> n >> k;
	vector<string> st;
	for (int i = 0; i < k; i++)
	{
		string s; cin >> s;
		st.push_back(s);
	}
	while (1)
	{
		stringstream ss;
		ss << n;
		bool ok = true;
		for (int i = 0; i < k; i++)
		{
			for (int j = 0; j < ss.str().size(); j++)
			{
				if (ss.str()[j] == st[i][0])ok = false;
			}
		}
		if (ok)break;
		n++;
	}
	cout << n << endl;

}

Measured memory_bytes: 256
from itertools import *
n=int(input())
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
sa1=list(accumulate(a1))
sa2=list(accumulate(a2))
ans=sa1[0]+sa2[n-1]
for i in range(1,n):
    ans=max(ans,sa1[i]+sa2[n-1]-sa2[i-1])
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	string s;
	cin >> s;
	
	REP(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
  n,m=map(int,input().split())
  x=list(map(int,input().split()))
  xmod=[y%m for y in x]
  from collections import Counter
  cx=Counter(x)
  cxmod=Counter(xmod)
  keys=cxmod.keys()
  ans1,ans2=0,0 # ams1:m倍になるペア、ans2:同数のペア。ans1からもとめる
  for k in keys:
    if k==0:
      ans1+=cxmod[k]//2
      cxmod[k]-=2*(cxmod[k]//2)
    else:
      if k==m-k:
        ans1+=cxmod[k]//2
        cxmod[k]-=2*(cxmod[k]//2)
      elif m-k in keys:
        tmp=min(cxmod[k],cxmod[m-k])
        ans1+=tmp
        cxmod[k]-=tmp
        cxmod[m-k]-=tmp
  for k in cx:
    v=cx[k]
    if v>=2 and cxmod[k%m]>=2:
      tmp=min(v//2,cxmod[k%m]//2)
      ans2+=tmp
      cxmod[k%m]-=tmp*2

  print(ans1+ans2)
if __name__=='__main__':
  main()



Measured memory_bytes: 32308
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 100
using namespace std;
typedef vector<int> V;
const V zero(51,0);
struct edge{
  int to,rev;
  V cap;
  edge();
  edge(int to,V cap,int rev):to(to),cap(cap),rev(rev){};
};

bool compare (const V &a,const V &b){
  for(int i=a.size()-1;i>=0;i--)if(a[i]!=b[i])return a[i]<b[i];
  return 0;
}
V min(V &a,V &b){return compare(a,b)? a:b;}

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°
//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,V cap){
  G[from].push_back(edge(to,cap,G[to].size()));
  G[to].push_back(edge(from,cap,G[from].size()-1));  
}

void add(V &a,V &b){for(int i=0;i<(int)a.size();i++)a[i]+=b[i];}
void sub(V &a,V &b){for(int i=0;i<(int)a.size();i++)a[i]-=b[i];}

//?¢?????????????DFS??§??¢???
V dfs(int v,int t,V f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap != zero){
      V d = dfs(e.to ,t , min(f,e.cap));
      if(d != zero){
	sub(e.cap,d);
	add(G[e.to][e.rev].cap,d);
	return d;
      }
    }
  }
  return zero;
}

//s??????t???????????§???????±???????
V max_flow(int s,int t){
  V flow=V(51,0);
  for(;;){
    memset(used,0,sizeof(used));
    V f = dfs(s, t, V(51,1e4));
    if(f == zero)return flow;
    add(flow,f);
  }
}


int StoI(string &a,int &i){
  int res=0;
  while(isdigit(a[i])) res=res*10+a[i++]-'0';
  return res;
}

string ItoS(int a){
  string res;
  while(a) res=char(a%10+'0')+res,a/=10;
  if(res.empty()) res="0";
  return res;
}

V StoV(string s){
  V res(51);
  if(s=="0") return zero;
  for(int i=0;i<s.size();i++){
    int a = max(1,StoI(s,i));
    int L = 0;
    if(s[i]=='x')i+=1+(s[i+1]=='^'),L=max(1,StoI(s,i));
    res[L] = a;
  }
  return res;
}

string VtoS(V a){
  string res;
  for(int i=a.size()-1;i>=0;i--){
    if(a[i]==0)continue;
    if(!res.empty()) res+='+';
    if(a[i]>1||i==0) res+=ItoS(a[i]);
    if(i)res+='x';
    if(i>1) res+='^'+ItoS(i);
  }
  if(res.empty()) res="0";
  return res;
}

int main(){
  while(1){
  int n,m;
  cin>>n>>m;
  if(!n&&!m) return 0;
  for(int i=0;i<MAX_V;i++) G[i].clear();
  for(int i=0,a,b;i<m;i++){
    string c;
    cin>>a>>b>>c;
    V vc = StoV(c);
    add_edge(a-1,b-1,vc);
  }

  V ans = max_flow(0,n-1);
  cout<<VtoS(ans)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vll A(N);
    cin >> A;
    int flag = 0;
    if(A[0] > A[1])flag = -1;
    else if(A[0] < A[1])flag = 1;
    else flag = 0;

    int ans = 1;
    for(int i=2; i<N; i++){
        if(A[i-1] > A[i]){
            if(flag == 1){
                flag = 0;
                ans++;
            }else if(flag == 0)flag = -1;
        }
        else if(A[i-1] < A[i]){
            if(flag == -1){
                flag = 0;
                ans++;
            }else if(flag == 0)flag = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4020
#include<iostream>
using namespace std;
typedef long long LL;
const int MAXN=105;
int a[MAXN];
int n,p;
int odd,even;

int main()
{
    while(cin>>n>>p)
    {
        odd=0;
        even=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]&1) odd++;
            else even++;
        }
        LL num;
        if(odd==0) num=0;
        else
        {
            num=((LL)1<<(odd-1))*((LL)1<<even);
        }
        if(p&1)
        {
            cout<<num<<endl;
        }else
        {
            cout<<((LL)1<<n)-num<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
total = K*K
for i in range(2,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      total += gcd(i,j,k)
print(total)

Measured memory_bytes: 69536
#include <cstdio>

using namespace std;

int hi, ke;

int main()
{
    int a,b,c,d,h1,h2,k1,k2;
    scanf( "%d %d\n%d %d\n%d %d %d %d\n", &h1, &h2, &k1, &k2, &a, &b, &c, &d );
    hi = h1 * a + ( h1 / 10 ) * c + h2 * b + ( h2 / 20 ) * d;
    ke = k1 * a + ( k1 / 10 ) * c + k2 * b + ( k2 / 20 ) * d;
    if( hi == ke )
    {
        printf( "even\n" );
    }
    else if ( hi < ke )
    {
        printf( "kenjiro\n");
    }
    else
    {
        printf( "hiroshi\n");
    }
    return 0;
}


Measured memory_bytes: 2556