akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = [list(input()) for _ in range(n)]

ans = dict()

a = ord('a')
for x in range(a, a + 26):
    c = chr(x)
    ans[c] = s[0].count(c)

for i in range(1, n):
    for c in ans.keys():
        ans[c] = min(ans[c], s[i].count(c))

res = ""
for x in range(a, a + 26):
    c = chr(x)
    res = res + c * ans[c]

print(res)


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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> V(N);
  for (int i = 0, x, l; cin >> x >> l; i++) {
    V.at(i) = {x - l, x + l};
  }
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  pair<int, int> now = V.at(0);
  int rem = 0;
  for (int i = 1; i < N; i++) {
    if (V.at(i).second <= now.first) now = V.at(i);
    else rem++;
  }
  cout << N - rem << "\n";
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	int xy[2];
	int a;
	int W, H, N;
	int i;
	int lowX, lowY;
	int highX, highY;
	int ans;

	scanf("%d %d %d", &W, &H, &N);
	lowX = lowY = 0;
	highX = W;
	highY = H;

	for (i = 0; i < N; i++) {
		scanf("%d %d %d", &xy[0], &xy[1], &a);
		if (a == 1) {
			if (xy[0] > lowX) {
				lowX = xy[0];
			}
		}
		else if (a == 2) {
			if (xy[0] < highX) {
				highX = xy[0];
			}
		}
		else if (a == 3) {
			if (xy[1] > lowY) {
				lowY = xy[1];
			}
		}
		else {
			if (xy[1] < highY) {
				highY = xy[1];
			}
		}
	}

	if (lowX >= highX || lowY >= highY) {
		ans = 0;
	}
	else {
		ans = (highX - lowX)*(highY - lowY);
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

int main() {
  ll N;
  cin >> N;
  string s[MAX];
  ll i, j;
  
  for(i=0; i<N; i++) {
    cin >> s[i];
    
    vector<char> v(10);
    for(j=0; j<10; j++)
      v[j]=s[i][j];
    sort(v.begin(), v.end());
    for(j=0; j<10; j++)
      s[i][j]=v[j];
    
  }
  
  sort(s, s+N);
  
  ll ans=0;
  for(i=0; i<N; i++) {
    ll t=1;
    while(i<N && s[i]==s[i+1]) {
      i++;
      t++;
    }
    ans+=t*(t-1)/2;
  }
  
  pt(ans);
  
}


Measured memory_bytes: 7296
from collections import deque


def main():
    n = int(input())
    trees = [[] for _ in range(n)]
    sibs = [-1 for _ in range(n)]
    for i in range(n):
        tree = list(map(int, input().split()))
        # trees[tree[0]] = tree[1:]
        if tree[1] != -1 and tree[2] != -1:
            trees[tree[0]] = tree[1:]
            sibs[tree[1]] = tree[2]
            sibs[tree[2]] = tree[1]
        elif tree[1] != -1:
            trees[tree[0]].append(tree[1])
            sibs[tree[1]] = -1
        elif tree[2] != -1:
            trees[tree[0]].append(tree[2])
            sibs[tree[2]] = -1
    

    # 根を探す
    candidates = set()
    have_parents = set()
    children = []
    for i in range(len(trees)):
        if len(trees[i]):
            candidates.add(i)
            children.extend(trees[i])
    children = set(children)
    have_parents = {c for c in candidates if c in children}

    if n == 1:
        root_node = 0
    else:
        root_node = list(candidates - have_parents)[0]

    depth = []
    q = deque()
    seen = [0]*n
    depth = [0]*n
    parents = [0]*n
    leaf_node = []
    heights = [0]*n

    q.append(root_node)
    seen[root_node] = 1
    parents[root_node] = -1

    # DFS
    while len(q):
        v = q.pop()
        d = depth[v] + 1
        for t in trees[v]:
            if seen[t]:
                continue
            seen[t] += 1
            parents[t] = v
            q.append(t)
            depth[t] = d
            if not len(trees[t]):
                leaf_node.append(t)

    for l in leaf_node:
        v = l
        height = 0
        while v != -1:
            heights[v] = max(heights[v], height)
            height += 1
            v = parents[v]

    for i in range(n):
        if not depth[i]:
            print(
                "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, root"
                .format(i, parents[i], sibs[i], len(trees[i]), depth[i], heights[i]))
        elif depth and len(trees[i]):
             print(
                "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, internal node"
                .format(i, parents[i], sibs[i], len(trees[i]), depth[i], heights[i]))
        else:
             print(
                "node {}: parent = {}, sibling = {}, degree = 0, depth = {}, height = {}, leaf"
                .format(i, parents[i], sibs[i], depth[i], heights[i]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 6028
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;

char table[10] = {'0','1','2','3','4','5','6','7','8','9'};
char map[52][52];

int main(int argc,char** argv) {
	string temp;
	for(int i = 0;i < 52;i++) for(int j = 0;j < 52;j++) map[i][j] = '.';
	int h,w;
	cin >> h >> w;
	for(int i = 1;i <= h;i++) {
		cin >> temp;
		for(int j = 1;j <= w;j++) {
			map[i][j] = temp[j-1];
		}
	}
	for(int i = 1;i <= h;i++) {
		for(int j = 1;j <= w;j++) {
			if(map[i][j] == '.') {
				int count = 0;
				for(int k = -1;k <= 1;k++) {
					for(int l = -1;l <= 1;l++) {
						if(map[i+k][j+l] == '#') count++;
					}
				}
				map[i][j] = table[count];
			}
		}
	}
	for(int i = 1;i <= h;i++) {
		for(int j = 1;j <= w;j++) {
			cout << map[i][j];
		}
		cout << endl;
	}
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int N, int x, vi& a) {
    assert(IN(N,2,2000));

    ll best = LLONG_MAX;
    vi cheapest(N, INT_MAX);
    for (ll shift=0, shift_time=0; shift<N; ++shift,shift_time+=x) {
        rep(i, N) {
            int f = (i - shift + N)%N;
            cheapest[i] = min(cheapest[i], a[f]);
        }
        ll total_time = shift_time + accumulate(ALL(cheapest), 0LL);
        best = min(best,  total_time);
#ifdef DEBUG
        cerr << shift << cheapest << "; best=" << best << endl;
#endif
    }

    return best;
}

int main() {
    int N, x; cin >> N >> x;
    read_cr();
    vi a(N);
    loadvec(a, N);
    cout << solve(N,x,a) << endl;
    return 0;
}


Measured memory_bytes: 256
//Coded by tzc_wk
/*
Êý¾Ý²»Çå¿Õ£¬±¬ÁãÁ½ÐÐÀá¡£
¶à²â²»¶ÁÍê£¬±¬ÁãÁ½ÐÐÀá¡£
±ß½ç²»ÌØÅÐ£¬±¬ÁãÁ½ÐÐÀá¡£
Ì°ÐÄ²»Ö¤Ã÷£¬±¬ÁãÁ½ÐÐÀá¡£
D P Ë³Ðò´í£¬±¬ÁãÁ½ÐÐÀá¡£
´óÐ¡ÉÙµÈºÅ£¬±¬ÁãÁ½ÐÐÀá¡£
±äÁ¿²»Í³Ò»£¬±¬ÁãÁ½ÐÐÀá¡£
Ô½½ç²»ÅÐ¶Ï£¬±¬ÁãÁ½ÐÐÀá¡£
µ÷ÊÔ²»×¢ÊÍ£¬±¬ÁãÁ½ÐÐÀá¡£
Òç³ö²» l l£¬±¬ÁãÁ½ÐÐÀá¡£
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
signed main(){
	int a=read(),b=read(),c=read();
	if(c<a+b)					return puts("No"),0;
	if(4*a*b<(c-a-b)*(c-a-b))	puts("Yes");
	else						puts("No");
	return 0;
}
//a+b+2sqrt(ab)<c

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
forward = []
backward = []
sumA = 0
for i in range(N):
    forward.append(A[i]+sumA)
    sumA += A[i]
sumA = 0
for j in range(N):
    backward.append(A[N-j-1]+sumA)
    sumA += A[N-j-1]
sa = []
for i in range(N-1):
    sa.append(abs(forward[i]-backward[N-i-2]))

print(min(sa))

Measured memory_bytes: 37648
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>

//not accepted

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

vector<ll>vv;
vector< pair<ll,ll> >ans;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll u=0;u<n;u++)
	{
		ll tmp;
		cin>>tmp;
		vv.eb(tmp);
	}
	sort(vv.begin(),vv.end());
	ll a=vv[0];
	ll b=vv[n-1];
	for(ll i=1;i<n-1;i++)
	{
		if(vv[i]<0)
		{
			ans.eb(b,vv[i]);
			b-=vv[i];
		}
		else
		{
			ans.eb(a,vv[i]);
			a-=vv[i];
		}
	}
	ans.eb(b,a);
	cout<<b-a<<endl;
	for(auto &x:ans)
	{
		cout<<x.fi<<" "<<x.se<<endl;
	}
    return 0;
}

Measured memory_bytes: 4336
//om namah shivaay
//faith over fear
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[100];
int main(){
    ll n;
    cin>>n;
    forn(i,n) cin>>a[i];
    ll money=1000;
    forn(i,n-1){
        ll stocks=money/a[i];
        money+=stocks*max((ll)0,a[i+1]-a[i]);
    }
    cout<<money;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n - 1; ++ i) {
        int a;
        cin >> a;
        mp[a] ++;
    }
    for (int i = 1; i <= n; ++ i) {
        cout << mp[i] << '\n';
    }
    
}

Measured memory_bytes: 12996
#include<stdio.h>
int main()
{
	int a,m=0,h=0,n=0;
	while(scanf("%d",&a)!=EOF)
	{
	    n=a%60;
	    h=a/3600;
	    m=(a-h*3600)/60;
		printf("%d:%d:%d\n",h,m,n);
	}
	return 0; 
}

Measured memory_bytes: 592
n = int(input())
A = [*map(int, input().split())]
# print(n)
# print(A)
all_xor = 0
for a in A: all_xor ^= a
# print(all_xor)
ans = []
for a in A: ans.append(all_xor ^ a)
print(*ans,sep=' ')


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


def solv(n, a, b):
    ans = 0
    for i in reversed(range(n)):
        kill = min(a[i+1], b[i])
        ans += kill
        a[i+1] -= kill
        b[i] -= kill

        kill = min(a[i], b[i])
        ans += kill
        a[i] -= kill
        b[i] -= kill

    return ans


if __name__ == '__main__':

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ans = solv(n, a, b)

    print(ans)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int MOD = 1000000007;
main(){
    int N,K,D[10];
    cin >> N >> K;
    for(int i = 0;i < K;i++){
        cin >> D[i];
    }
    for(int i = N;i <= 100000;i++){
        stringstream ss;
        ss << i;
        string s = ss.str();
        int flag = 0;
        for(int j = 0;j < K;j++){
            if(s.find(D[j]+'0') != -1)flag = 1;
        }
        if(flag)continue;
        cout << i << endl;
        return 0;
    }
}

Measured memory_bytes: 256
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
void main(){
	int n;
	while(read(n),n){
		int [][] infos;
		(n+1).times({
			auto info = new int[n+1];
			readArray(info);
			infos ~= info[1..1+info[0]].sort;
		});
		auto leaked = infos[n];
		infos = infos[0..$-1];
		int commiter = -2;
		foreach(int i,info;infos){
			bool Is = true;
			foreach(l;leaked){
				if (!(info.canFind(l))){ Is = false; break;}
			}
			if (Is){
				if(commiter == -2) commiter = i;	
				else {commiter = -2;break;}
			}
		}
		(commiter+1).writeln;
	}
}

Measured memory_bytes: 3188
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  vector<int> A(3);
  int K;
  cin>>A[0]>>A[1]>>A[2];
  cin>>K;
  
  sort(A.begin(),A.end());
  FOR(i,0,K){
    A[2]=A[2]*2;
  }
  cout<<A[0]+A[1]+A[2]<<endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,m;
    cin>>n>>m;

    Vec acflag(n+1);
    Vec wa(n+1);

    rep(i,m){
        ll p;
        string s;
        cin>>p>>s;
        if(s=="WA"){
            if(!acflag[p]){
                wa[p]++;
            }
        }else{
            acflag[p]=1;
        }
    }
    ll ac=0;
    ll wac=0;
    rep(i,n+1){
        if(acflag[i])ac++;
    }
    rep(i,n+1){
        if(acflag[i]){
            wac += wa[i];
        }
    }
    cout<<ac<<" "<<wac<<endl;
    return  0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  int cnt = 0;
  for (int h : H) if (h >= K) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    A_ = [0] + A +[0]
    ans = []
    p= 0
    for i in range(N+1):
        p += abs(A_[i+1] - A_[i])

    for i in range(1, N+1):
        print(p - (abs(A_[i]-A_[i-1]) + abs(A_[i+1]-A_[i])) + abs(A_[i+1]-A_[i-1]))


if  __name__=='__main__':
    main()

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[222][222][222];

void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

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

	ll n;cin >> n;
	dp[0][0][0] = 1;
	REP(i, n){
		char c;cin >> c;
		REP(j, 222){
			REP(k, 222){
				if(dp[i][j][k] == 0)continue;
				if(c == '-'){
					mod_add(dp[i+1][j][k], dp[i][j][k]);
				}
				else if(c == 'U'){
					if(j > 0) {
						mod_add(dp[i+1][j][k], dp[i][j][k] * j % MOD);
					}
					mod_add(dp[i+1][j+1][k+1], dp[i][j][k]);
				}
				else {
					if(j > 0 && k > 0){
						mod_add(dp[i+1][j-1][k-1], (dp[i][j][k] * j % MOD) * k % MOD);
					}
					if(k > 0){
						mod_add(dp[i+1][j][k], dp[i][j][k] * k % MOD);
					}
				}
			}
		}
	}

	cout << dp[n][0][0] << endl;

	return 0;
}



Measured memory_bytes: 22156
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = list(li())

x = [0]*n

total = sum(a) // 2
x[0] = total - sum(a[1:n:2])

for i in range(1, n):
    x[i] = a[i-1] - x[i-1]

for i in range(n):
    x[i] *= 2

print(*x)

Measured memory_bytes: 14196
n = int(input())
a = list(map(int, input().split()))
for j in range(n):
    a[j] = a[j] - (j + 1)
a.sort()
if n % 2 == 0:
    print(sum(a[int(n / 2):]) - sum(a[:int(n / 2)]))
else:
    print(sum(a[int((n + 1) / 2):]) - sum(a[:int((n - 1) / 2)]))

Measured memory_bytes: 26020
//D
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
int HO[] = {0, 1, 0, -1};
int VE[] = {-1, 0, 1, 0};

int main(){
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int H, W, sx, sy, ex, ey;
	cin >> H >> W;
	cin >> sx >> sy;
	cin >> ex >> ey;
	char a[H + 1][W + 1];
	int warp[H + 1][W + 1];
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> a[i][j];	
			warp[i][j] = 1e9;
		}
	}
	priority_queue<pair<int, pair<int, int> > > pq;
	pq.push(mp(0, mp(sx, sy)));
	warp[sx][sy] = 0;
	while (!pq.empty()) {
		int val = -pq.top().fi;
		int x = pq.top().se.fi;
		int y =  pq.top().se.se;
		pq.pop();
		if (warp[x][y] < val) continue;
		for (int i = 0; i < 4; i++) {
			int x2 = x + HO[i];
			int y2 = y + VE[i];
			if (x2 > 0 && x2 <= H && y2 > 0 && y2 <= W) {
				if (warp[x2][y2] > val && a[x2][y2] == '.') {
					warp[x2][y2] = val;
					pq.push(mp(-val, mp(x2, y2)));
				}
			}
		}
		for (int i = max(x - 2, 1); i <= min(x + 2, H); i++) {
			for (int j = max(y - 2, 1); j <= min(y + 2, W); j++) {
				if (warp[i][j] > val + 1 && a[i][j] == '.') {
					warp[i][j] = val + 1;
					pq.push(mp(-warp[i][j], mp(i, j)));
				}	
			}
		}
	}
	if (warp[ex][ey] == 1e9) warp[ex][ey] = -1;
	printf("%d\n", warp[ex][ey]);
}

Measured memory_bytes: 8604
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a<=b){
        a++;
    }
    cout << a-1;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i

road = Array.new(n+1){[]}
(n-1).times do
    a,b,c = gets.split.map(&:to_i)
    road[a] << [b,c]
    road[b] << [a,c]
end

q,k = gets.split.map(&:to_i)

cost = Array.new(n+1,10 ** 15)
cost[k] = 0
queue = [k]
while x = queue.shift do
    road[x].each do |g,c|
        if cost[g] > cost[x] + c
            cost[g] = cost[x] + c
            queue << g
        end
    end
end

q.times do
    x,y = gets.split.map(&:to_i)
    puts cost[x] + cost[y]
end

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int a, e, s, r;

int dist(string &a, string &b, int i){
    
    return 0;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, q;
    cin >> n >> q;
    vector<queue<int>> que(n);
    while(q--){
        int c, t;
        cin >> c >> t;
        if(c == 0){
            int x;
            cin >> x;
            que[t].push(x);
        }
        if(c == 1){
            if(!que[t].empty()) cout << que[t].front() << "\n";
        }
        if(c == 2) if(!que[t].empty()) que[t].pop();
    }
    return 0;
}


Measured memory_bytes: 4424
#include <iostream>
#include <utility>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int dist(pair<int, int>p1, pair<int, int>p2){
  return abs(p1.first-p2.first)+abs(p1.second-p2.second);
}

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>>xy(n);
  vector<int>h(n);
  for(int i=0; i<n; i++){
    cin >> xy[i].first >> xy[i].second >> h[i];
  }
  pair<int, int>pp;
  int pph;
  for(int i=0; i<n; i++){
    if(h[i]>0){
      pph = h[i];
      pp = xy[i];
      break;
    }
  }
  for(int cx=0; cx<=100; cx++)for(int cy=0; cy<=100; cy++){
    pair<int, int>pc = make_pair(cx, cy);
    int ch=pph+dist(pc, pp);
    bool trig=true;
    for(int i=0; i<n; i++){
      if(max(ch-dist(pc, xy[i]), 0)!=h[i]){
        trig=false;
        break;
      }
    }
    if(trig){
      cout << cx << ' ' <<  cy << ' ' << ch;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
mod =998244353

def main():
    #start coding here...
    #Three colors
    N=int(input())
    A=[int(input()) for i in range(N)]
    M=(sum(A)-1)//2
    S=sum(A)
    # 1<= R,G,B<= S, R+ G + B = S
    #ほうじょ原理
    Alls = pow(3,N,mod) 
    # R,G,B　のうち1つ以上が S より大のケース case2
    case2=0
    #dp[x][i] := 初めのｘこを塗り分けて、Rの値がiになるものの個数
    dp=[[0 for i in range(90001)] for j in range(N+1)]
    dp[0][0]=1
    for i in range(1,N+1):
        v=A[i-1]
        for j in range(90001):
            if j>=v:
                dp[i][j]= dp[i-1][j-v]+ 2*dp[i-1][j]
            else:
                dp[i][j]=2*dp[i-1][j]
            dp[i][j]%=mod   

    if S%2!=0:
        # R,G,B のうち1つだけがSより大きい
        for i in range(M+1,90001):
            case2+=3*dp[N][i]
            case2%=mod
    if S%2==0:
        #R,G,B のうち1つがSより大きい
        for i in range(M+1,90001):
            case2+=3*dp[N][i]
            case2%=mod
        #R,G,B のうち2つがS//2
        #sub_dp[x][v]:= 初めのxこを塗り分けて　Rの方をvにする方法
        sub_dp=[[0 for i in range(90001)] for j in range(N+1)]
        sub_dp[0][0]=1
        for i in range(1,N+1):
            v=A[i-1]
            for j in range(90001):
                if j>=v:
                    sub_dp[i][j]= sub_dp[i-1][j]+sub_dp[i-1][j-v]
                else:
                    sub_dp[i][j]=sub_dp[i-1][j]
                sub_dp[i][j]%=mod
        case2-=3*sub_dp[N][S//2]
        case2%=mod
    ans=Alls-case2
    print(ans%mod)
    return
        


if __name__ =="__main__":
    main()


Measured memory_bytes: 545996
/*
 * A.cpp
 *
 *  Created on: 2020/06/27
 *      Author: 17k1028
 */



#include <iostream>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


using namespace std;

int main(){
	int a;
	cin >> a;
	cout << a+a*a + a*a*a<< endl;
}


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

int main()
{
	int t,h,b,n[10];
	while(cin >> t)
	{
		memset(n,0,sizeof(n));

		n[t]=1; h=b=0;
		for(int i=1; i<4; i++)
		{
			cin >> t;
			n[t] = i+1;
		}

		for(int i=0; i<4; i++)
		{
			cin >> t;
			if(n[t]==i+1)    h++;
			else if(n[t]!=0) b++;
		}

		cout << h << " " << b << endl;
	}
}

Measured memory_bytes: 576
#include<iostream>
#include<vector>
#include<climits>
using namespace std;

// F : T x T -> T
// G : T x E -> T
// H : E x E -> E
template<typename T, typename E, typename F, typename G, typename H>
struct SegL{
private:
    vector<T> node;
    vector<E> lazy;
    int n;
    T defVal;
    E defOp;
    F f;    // merge elements(T)
    G g;    // update element(T) 
    H h;    // merge operators(E)

public:
    SegL(int siz, T defVal, E defOp, F f, G g, H h) : defVal(defVal), defOp(defOp), f(f), g(g), h(h){
        n = 1;
        while(n < siz)  n *= 2;
        node.resize(2*n-1, defVal);
        lazy.resize(2*n-1, defOp);
    }
    SegL(vector<T> v, T defVal, E defOp, F f, G g, H h) : defVal(defVal), defOp(defOp), f(f), g(g), h(h){
        n = 1;
        while(n < v.size())  n *= 2;
        node.resize(2*n-1, defVal);
        for(int i = 0; i < v.size(); i++)   node[n-1+i] = v[i];
        for(int i = n-2; i >= 0; i--)   node[i] = f(node[2*i+1], node[2*i+2]);
    }

    void eval(int k){
        if(lazy[k] == defOp)    return;
        if(k < n-1){
            lazy[2*k+1] = h(lazy[2*k+1], lazy[k]);
            lazy[2*k+2] = h(lazy[2*k+2], lazy[k]);
        }
        node[k] = g(node[k], lazy[k]);
        lazy[k] = defOp;
    }

    void update(int a, int b, E x, int k=0, int l=0, int r=-1){
        if(r < 0)   r = n;
        eval(k);
        if(b <= l || r <= a){
            return;
        }else if(a <= l && r <= b){
            lazy[k] = h(lazy[k], x);
            eval(k);
        }else{
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = f(node[2*k+1], node[2*k+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0)   r = n;
        eval(k);
        if(b <= l || r <= a)    return defVal;
        if(a <= l && r <= b)    return node[k];
        T lx = query(a, b, 2*k+1, l, (l+r)/2);
        T rx = query(a, b, 2*k+2, (l+r)/2, r);
        return f(lx, rx);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    auto f = [](int x, int y)->int{return min(x, y);};
    auto g = [](int x, int y)->int{return y==-1 ? x : y;};
    auto h = [](int x, int y)->int{return y==-1 ? x : y;};
    int defv = INT_MAX;
    int defop = -1;
    SegL<int, int, decltype(f), decltype(g), decltype(h)> seg(n, defv, defop, f, g, h);
    while(q--){
        int op;
        cin >> op;
        if(op == 0){
            int s, t, x;
            cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }else{
            int s, t;
            cin >> s >> t;
            cout << seg.query(s, t+1) << endl;
        }
        // for(int i = 0; i < n; i++){
        //     cout << seg.query(i, i+1) << " \n"[i==n-1];
        // }
    }
    return 0;
}


Measured memory_bytes: 4948
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int Q;
  cin>>Q;
  vector<int>l(Q),r(Q);
  for(int i=0;i<Q;i++){
    cin>>l[i]>>r[i];
  }
  vector<bool>prime(1e6,false);
  for(int i=2;i<1e5+5;i++){
    if(i%2==0){continue;}
    bool ok=true;
    for(int j=2;j*j<=i;j++){
      if(i%j==0){ok=false;}
      if(((i+1)/2%j==0)){ok=false;}
    }
    if(ok){prime[i]=true;}
  }

  vector<int>sum(1e6);
  int tot=0;
  for(int i=2;i<1e5+5;i++){
    if(prime[i]){tot++;}
    sum[i]=tot;
  }

  for(int i=0;i<Q;i++){
    cout<<sum[r[i]]-sum[l[i]-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 7944
#include<iostream>

using namespace std;

int main(void)
{
	int n,m,k;
	cin >> n >> m >> k;
	bool flag=false;
	for(int i=0;i<=m;i++)
		for(int j=0;j<=n;j++)
			if(n*i-(i-(m-i))*j==k)flag=true;
	cout << (flag ? "Yes":"No") << endl;
}

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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	if(n%2) return cout << "No",0;
	
	string s;
	cin >> s;
	for(int i=0 ; i<n/2 ;i++)
	{
		if(s[i] != s[i+n/2])    return cout << "No",0;
	}
	
	cout<< "Yes";
}


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

int main() {
  string S;
  int K;
  cin >> S >> K;
  
  vector<string> ans;

  rep(i, S.size()) {
    rep(j, K) {
      string tmp = S.substr(i, j + 1);
      ans.push_back(tmp);
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  cout << ans[K - 1]<< endl;
}


Measured memory_bytes: 1660
a, b = (int(i) for i in input().split())
def f0(x):
    xx = (x + 1) % 4
    if xx == 0:
        return 0
    elif xx == 1:
        return x
    elif xx == 2:
        return 1
    else:
        return x^1
a = f0(a-1)
b = f0(b)
print(a^b)

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

bool isPrime(ll x){
    if(x == 2) return true;
    if(x < 2 or x % 2 == 0) return false;
    
    for(ll i = 3; i <= sqrt(x); i+=2){
        if(x % i == 0) return false;
    }
    return true;
}

int main(){
    int n;
    int cnt = 0;
    cin >> n;
    
    rep(i,n){
        ll x;
        cin >> x;
        if(isPrime(x)) cnt++;
    }
    
    cout << cnt << endl;
}



Measured memory_bytes: 3076
def ncr(n, r, p): 
    
     
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,  
            p - 2, p)) % p 
S = int(input())
l,rem = divmod(S,3)
MOD = 10**9 + 7
ans = 0
for i in range(0,l+1):
  ans = (ans + ncr(S-2*i-1,S-3*i,MOD))%MOD
print(ans)


Measured memory_bytes: 9160
#include "bits/stdc++.h"
using namespace std;
int main() {
	vector<vector<int>>C(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> C.at(i).at(j);
		}
	}
	vector<int>A(3), B(3);
	for (int i = 0; i < 3; i++) {
		B.at(i) = C.at(0).at(i);
	}
	A.at(1) = C.at(1).at(0) - B.at(0);
	A.at(2) = C.at(2).at(0) - B.at(0);
	for (int i = 1; i < 3; i++) {
		for (int j = 1; j < 3; j++) {
			if (C.at(i).at(j) - B.at(j) != A.at(i)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

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

int main()
{
    int n, k, b;

    cin >> n;
    cin >> k;

    int u[n];
    double p = pow( 2, (double)n );
    bitset<28> s1(0);

    for( int i = 0; i < n; i++ )
        u[i] = i;

    for( int i = 0; i < k; i++ )
    {
        cin >> b;
        for( int j = 0; j < n; j++ )
        {
            if( u[j] == b )
                s1[j] = 1;
        }
    }

    for( int i = 0; i < (int)p; i++ )
    {
        bitset<28> t(i);

        bool judge = true;
        if( ( s1 | t ) != s1 )
            judge = false;

        if( judge == true )
        {
            cout << i << ":";
            for( int j = 0; j < 28; j++ )
            {
                if( t[j] == 1 )
                    cout << " " << u[j];
            }
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int ans, dp[128][4][4][4];
bool check(int a, int b, int c){
	return (a == 1 && b == 2 && c == 3);
}
int main(){
	int n;
	cin >> n;
	dp[0][0][0][0] = 1;
	for(int i = 0; i < n; i++)
		for(int a = 0; a < 4; a++)
			for(int b = 0; b < 4; b++)
				for(int c = 0; c < 4; c++)	
					for(int d = 0; d < 4; d++){
						if(check(b, c, d) || check(c, b, d) || check(b, d, c))
							continue;
						if(check(a, c, d) || check(a, b, d))
							continue;
						dp[i + 1][b][c][d] = (dp[i + 1][b][c][d] + dp[i][a][b][c]) % mod;
					}
	for(int a = 0; a < 4; a++)
		for(int b = 0; b < 4; b++)
			for(int c = 0; c < 4; c++){
				ans += dp[n][a][b][c];
				ans %= mod;
			}
	cout << ans;
}	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(int i=0;i<n;i++)
    cin>>h[i];
    sort(h,h+n);
    ll sum=0;
    for(int i=0;i<n-k;i++)
    sum+=h[i];
    cout<<sum;
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map(String::toInt)
    val a = mutableListOf<CharArray>()
    for (i in 1..h) {
        a.add(readLine()!!.toCharArray())
    }

    var result = "Possible"

    for (i in 0..(h - 2)) {
        for (j in 1..(w - 1)) {
            if (a[i][j] == '#' && a[i + 1][j] == '#' && a[i + 1][j - 1] == '#') result = "Impossible"
        }
    }

    for (i in 0..(h - 2)) {
        for (j in 0..(w - 2)) {
            if (a[i][j] == '#' && a[i + 1][j] == '#' && a[i][j + 1] == '#') result = "Impossible"
        }
    }

    println(result)
}


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

#define MAX 2002

int n;
int k;

vector<int> v[MAX];

bitset<MAX> bb[MAX];

vector<int> en[MAX];
inline void dfs(int b, int pr = -1, int d = 0,int id=0){
	if (d < 0){
		return;
	}
	if (d == 0){
		en[id].push_back(b);
	}
	bb[id].set(b, 1);
	for (int i = 0; i < v[b].size(); i++){
		if (v[b][i] != pr){
			dfs(v[b][i], b, d - 1, id);
		}
	}
}

int main(){
	cin >> n >> k;
	for (int i = 1; i < n; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for (int i = 0; i < n; i++){
		dfs(i, -1, k, i);
	}
	int ans = INT_MAX;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < en[i].size(); j++){
			int c = (bb[i] & bb[en[i][j]]).count();
			ans = min(ans, n - c);
		}
	}
	if (ans == INT_MAX)ans = 0;
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        cin >> n;
        if (n == 0) break;
        int taro[205] = {};
        int hanako[205] = {};
        int ans1 = 0, ans2 = 0;
        rep(i, n) {
            int m;
            cin >> m;
            taro[m] = 1;
        }
        rep2(i, 1, 2 * n + 1) {
            if (taro[i]) continue;
            hanako[i] = 1;
        }
        int now = 0;
        int i = 0;
        while(true) {
            if (i % 2 == 0) {
                bool check = false;
                int cnt = 0;
                rep2(j, 1, 2 * n + 1) {
                    if (taro[j]) cnt++;
                    if (!check && taro[j] && (now < j)) {
                        taro[j] = 0;
                        now = j;
                        check = true;
                        cnt--;
                    }
                }
                if (!check) now = 0;
                if (cnt == 0) {
                    rep2(j, 1, 2 * n + 1) {
                        if (hanako[j]) {
                            ans1++;
                        }
                    }
                    break;
                }
            }
            else {
                bool check = false;
                int cnt = 0;
                rep2(j, 1, 2 * n + 1) {
                    if (hanako[j]) cnt++;
                    if (!check && hanako[j] && (now < j)) {
                        hanako[j] = 0;
                        now = j;
                        check = true;
                        cnt--;
                    }
                }
                if (!check) now = 0;
                if (cnt == 0) {
                    rep2(j, 1, 2 * n + 1) {
                        if (taro[j]) ans2++;
                    }
                    break;
                }
            }
            i++;
        }
        cout << ans1 << endl;
        cout << ans2 << endl;
    }

}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main(){
  int k, n;
  cin>>k>>n;
  vector<long long> vec(n, 0);
  for(int i = 0; i < n; ++i){
    cin>>vec[i];
  }
  vector<int> d;
  for(int i = 0; i < n - 1; ++i){
    d.push_back(vec[(i + 1)] - vec[i]);
  }
  int t = vec[0] + k - vec[n - 1];
  d.push_back(t);
  sort(d.begin(), d.end());
  long long ans = 0;
  for(int i = 0; i < d.size() - 1; ++i)ans += d[i];
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 2936
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();
        if (k <= a) {
            a -= k;
        } else {
            if (b - k + a >= 0) {
                b -= k - a; 
            } else {
                b = 0;
            }
            a = 0;
        }
        System.out.println(a + " " + b);
        sc.close();
    }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

int n, m;
int scene[100][100];
int pic[4][50][50];
P res[4];

P check(int v){
	rep(i, n - m + 1)rep(j, n - m + 1){
		bool ok = true;
		P p = P(INF, INF);
		rep(k, m)rep(l, m){
			if(pic[v][k][l] >= 0 && scene[i+k][j+l] != pic[v][k][l]) ok = false; 
			else if(pic[v][k][l] >= 0 && p.first == INF) p = P(i+k+1, j+l+1);
		}
		if(ok) return p;
	}
	return P(INF, INF);
}

int main(){
	while(cin >> n >> m && (n || m)){
		rep(i, n) rep(j, n) cin >> scene[i][j];
		rep(i, m) rep(j, m){
			cin >> pic[0][i][j];
			pic[1][j][m-i-1] = pic[0][i][j];
			pic[2][m-i-1][m-j-1] = pic[0][i][j];
			pic[3][m-j-1][i] = pic[0][i][j];

		}
		fill(res, res + 4, P(INF, INF));

		rep(i,4){
			res[i] = check(i);
		}

		sort(res, res + 4);
		if(res[0].first == INF) cout << "NA" << endl;
		else cout << res[0].second << " " << res[0].first << endl;
	}
	return 0;
}

Measured memory_bytes: 956
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n;
  while(cin>>n,n){
    vector<int> to[26];
    vector<char> front;
    vector<char> back;
    string s;
    REP(i,n){
      cin>>s;
      front.push_back(s[0]);
      back.push_back(s[s.size()-1]);
      to[s[0]-'a'].push_back(s[s.size()-1]-'a');
    }
    sort(front.begin(),front.end());
    sort(back.begin(), back.end());
    bool used[26] = {};
    REP(i,26)if(to[i].size() > 0){
      used[i] = true;
      break;
    }
    REP(time,n){
      REP(i,26)if(used[i]){
        REP(j,to[i].size()){
          used[to[i][j]] = true;
        }
      }
    }
    bool ok = true;
    REP(i,26)if(!used[i] && to[i].size() > 0) ok = false;
    if(ok && front == back) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024