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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,tot,cnt;
int v[205],nxt[205],h[105],dep[105],f[105],du[105],a[105],maxd[105];
vector<pii> edge;

void addedge(int x,int y){
	v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
	v[++tot]=x; nxt[tot]=h[y]; h[y]=tot;
}

void getdep(int u,int fa){
	for(int p=h[u];p;p=nxt[p]){
		if(v[p]==fa) continue;
		dep[v[p]]=dep[u]+1,f[v[p]]=u;
		getdep(v[p],u);
	}
}

void getdia(){
	memset(h,0,sizeof(h)); tot=0;
	for(auto e:edge) addedge(e.fi,e.se);
	dep[1]=1,f[1]=0; getdep(1,-1);
	int maxa=0,rt1=0,rt2=0;
	for(int i=1;i<=n;i++) if(chkmax(maxa,dep[i])) rt1=i;
	dep[rt1]=1,f[rt1]=0; getdep(rt1,-1);
	maxa=cnt=0;
	for(int i=1;i<=n;i++) if(chkmax(maxa,dep[i])) rt2=i;
	a[++cnt]=rt2;
	while(rt2!=rt1) rt2=f[rt2],a[++cnt]=rt2;
}

ull calc1(){
	dep[a[cnt/2]]=dep[a[cnt/2+1]]=1;
	f[a[cnt/2]]=a[cnt/2+1],f[a[cnt/2+1]]=a[cnt/2];
	getdep(a[cnt/2],a[cnt/2+1]);
	getdep(a[cnt/2+1],a[cnt/2]);
	memset(du,0,sizeof(du));
	memset(maxd,0,sizeof(maxd));
	for(auto e:edge) du[e.fi]++,du[e.se]++;
	for(int i=1;i<=n;i++) chkmax(maxd[dep[i]],du[i]-1);
	ull ans=2;
	for(int i=1;i<=n;i++) ans*=maxd[i]?maxd[i]:1;
	return ans;
}

ull calc2(){
	dep[a[(cnt+1)/2]]=1,f[a[(cnt+1)/2]]=0;
	getdep(a[(cnt+1)/2],-1);
	memset(du,0,sizeof(du));
	memset(maxd,0,sizeof(maxd));
	for(auto e:edge) du[e.fi]++,du[e.se]++;
	du[a[(cnt+1)/2]]++;
	for(int i=1;i<=n;i++) chkmax(maxd[dep[i]],du[i]-1);
	ull ans=1;
	for(int i=1;i<=n;i++) ans*=maxd[i]?maxd[i]:1;
	return ans;
}

int main(){
	n=readint();
	for(int i=1;i<n;i++) edge.push_back(mp(readint(),readint()));
	getdia();
	if(cnt%2==0) cout<<cnt/2<<' '<<calc1()<<endl;
	else{
		ull ans=calc2();
		for(auto e:edge){
			dep[e.fi]=dep[e.se]=1;
			f[e.fi]=e.se,f[e.se]=e.fi;
			getdep(e.fi,e.se);
			getdep(e.se,e.fi);
			bool fl=1;
			for(int i=1;i<=n;i++) if(dep[i]>(cnt+1)/2) fl=0;
			if(!fl) continue;
			memset(du,0,sizeof(du));
			memset(maxd,0,sizeof(maxd));
			for(auto e:edge) du[e.fi]++,du[e.se]++;
			for(int i=1;i<=n;i++) chkmax(maxd[dep[i]],du[i]-1);
			ull res=2;
			for(int i=1;i<=n;i++) res*=maxd[i]?maxd[i]:1;
			chkmin(ans,res);
		}
		cout<<(cnt+1)/2<<' '<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
int n,i,taro=0,hanako=0;
char card1[101],card2[101];
scanf("%d",&n);
for(i=0;i<n;i++){
 scanf("%s %s",card1,card2);
 if(strcmp(card1,card2)==0) taro+=1,hanako+=1;
 else if(strcmp(card1,card2)>0) taro+=3;
 else if(strcmp(card1,card2)<0) hanako+=3;
}
printf("%d %d\n",taro,hanako);
return 0; }


Measured memory_bytes: 2144
S,f=__import__('collections').deque(input()),0
for _ in range(int(input())):
	T=input()
	if T<'2':f=1-f
	else:(S.appendleft if (T[2]<'2')^f else S.append)(T[4])
if f:S.reverse()
print(*S,sep='')

Measured memory_bytes: 12272
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int MaxN = 1e5;

int main()
{
	int q;
	long long a,b,ans,jh,sum,vis,biu;
	while(~scanf("%d",&q))
	{
		while(q--)
		{
			ans = 0;
			scanf("%lld %lld",&a,&b);
			if(a > b)
			{
				jh = a;
				a = b;
				b = jh;
			}
			sum = a * b;
			jh = sqrt(sum);
			ans = jh * 2 - 1;
			if(a < jh) ans--;
			if(sum == jh * jh) ans--;
			else if(a == jh) ans--;
			if(jh * (jh + 1) < sum&&b != jh + 1) ans++;
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int n, k;
	map<int, int>mp;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		if (mp.find(num) == mp.end()) {
			mp.insert(make_pair(num, 1));
		}
		else {
			mp[num]++;
		}
	}

	if (mp.size() <= k) {
		cout << 0 << endl;
	}
	else {
		vector<pair<int,int>>list;

		for (auto itr = mp.begin(); itr != mp.end(); itr++) {
			list.push_back(make_pair((*itr).second, (*itr).first));
		}

		int sum = 0, ima = list.size();
		sort(list.begin(), list.end());
		int i = 0;

		while (ima>k)
		{
			sum += list[i].first;
			ima--;
			i++;
		}

		cout << sum << endl;

	}








	return 0;
}

Measured memory_bytes: 17264
from collections import deque

def search(tx, ty, kx, ky, mp):
  direct = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, -1, 0, 1), (0, 1, 0, -1))
  dic = {}
  dic[(tx, ty, kx, ky)] = 0
  que = deque()
  que.append((0, (tx, ty, kx, ky)))
  while que:
    dist, p = que.popleft()
    tx, ty, kx, ky = p
    for dtx, dty, dkx, dky in direct:
      if mp[ty + dty][tx + dtx] == 0:
        ntx, nty = tx + dtx, ty + dty
      else:
        ntx, nty = tx, ty
      if mp[ky + dky][kx + dkx] == 0:
        nkx, nky = kx + dkx, ky + dky
      else:
        nkx, nky = kx, ky
      if (ntx, nty, nkx, nky) not in dic:
        if (ntx, nty) == (nkx, nky):
          if dist + 1 >= 100:
            print("NA")
          else:
            print(dist + 1)
          return
        dic[(ntx, nty, nkx, nky)] = True
        que.append((dist + 1, (ntx, nty, nkx, nky)))
  else:
    print("NA")

def main():
  while True:
    w, h = map(int, input().split())
    if w == 0:
      break
    tx, ty = map(int, input().split())
    kx, ky = map(int, input().split())
    mp = [[1] + list(map(int, input().split())) + [1] for _ in range(h)]
    mp.insert(0, [1] * (w + 2))
    mp.append([1] * (w + 2))
  
    search(tx, ty, kx, ky, mp)

main()


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

int main() {
 string s;
  cin >> s;
  int n=s.size();
  bool ok=true;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
     if(s[i]==s[j])ok=false;
    }
  }
  
  if(ok)cout << "yes" << endl;
  else  cout << "no" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 2000000009
#define MOD 1000000007
#define MAXN 200005
#define MAXM 200005
#define MAXV 1000000009
ll n, a[MAXN], ans = INF;
ll s[MAXN];
int main()
{
    cin >> n;
    REP(i, 0, n){
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    REP(i, 1, n){
        ans = ans < abs(s[i] - (s[n] - s[i])) ? ans : abs(s[i] - (s[n] - s[i]));
    }
    cout << ans << endl;



    return 0;
}
/*
*/





Measured memory_bytes: 3328
#include<bits/stdc++.h> 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vv = vector<vector<int>>;
using P = pair<int,int>;

int main(){
  string s;
  cin >> s;
  string fr;
  ull q;
  cin >> q;
  for(ull i=0;i<q;i++){
    int t;
    cin >> t;
    if( t == 1 ){
      swap(s,fr);
      continue;
    }
    int f;
    char c;
    cin >> f >> c;
    if( f == 1 ){
      fr.push_back(c);
    }else{
      s.push_back(c);
    }
  }
  reverse(fr.begin(),fr.end());
  cout << fr + s << endl;
    
      
  return 0;
}


Measured memory_bytes: 1248
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    private static final int maxNumber = 1_000_000;

    public static void main(String[] args) throws Exception {
        int[] primeNumberCount = calcPrimeNumberCount();

        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        int num;
        String str;
        while((str = r.readLine()) != null) {
            num = Integer.parseInt(str);
            System.out.println(primeNumberCount[num]);
        }
    }

    private static int[] calcPrimeNumberCount() {
        boolean[] isPrime = new boolean[maxNumber];
        Arrays.fill(isPrime, true);
        isPrime[0] = false;
        isPrime[1] = false;

        int sqrtMaxNum = (int) Math.floor(Math.sqrt(maxNumber));
        for (int i = 2; i < sqrtMaxNum; i++) {
            for (int j = i*i; j < maxNumber; j += i) {
                if (!isPrime[j]) { continue; }
                isPrime[j] = false;
            }
        }

        int count = 0;
        int[] primeCount = new int[maxNumber];
        for (int i = 0; i < maxNumber; i++) {
            if (isPrime[i]) {
                count ++;
            }
            primeCount[i] = count;
        }

        return primeCount;
    }
}

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

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef VVI matrix;

vector<vector<int> > identity(int n) {
  vector<vector<int> > A(n,vector<int>(n,0));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),vector<int>(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k) {
	C[i][j] += A[i][k]*B[k][j];
	C[i][j] = min(1,C[i][j]);
      }
  return C;
}

matrix pow(const matrix& A,int e)
{
  return !e?identity(A.size()):
    (e%2?multi(A,pow(A,e-1)):pow(multi(A,A),e/2));
}

int n,m,steps[3];
vector<int> G[51];
int par[51];

int find(int x) {
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unite(int a,int b) {
  a = find(a), b = find(b);
  if( a != b ) par[a] = b;
}

vector<int> reachable_nodes(int step) {
  vector<int> ret(n,0);
  vector<vector<int> > mat(n,vector<int>(n,0));
  rep(i,n) rep(j,(int)G[i].size()) mat[i][G[i][j]] = 1;
  mat = pow(mat,step);
  rep(sp,n) if( find(n-1) == find(sp) ) rep(i,n) if( mat[sp][i] ) ret[i] = 1;
  return ret;
}

void compute() {
  rep(i,n) par[i] = i;
  bool update = true;
  int answer = 0;
  while( update ) {
    update = false;
    vector<int> nodes[3];
    rep(i,3) nodes[i] = reachable_nodes(steps[i]);
    rep(i,n) {
      if( nodes[0][i] && nodes[1][i] && nodes[2][i] ) {
	if( find(n-1) != find(i) )  {
	  update = true;
	  unite(n-1,i);
	}
      }
    }
    ++answer;
    if( find(0) == find(n-1) ) break;
  }
  if( find(0) == find(n-1) ) {
    cout << answer << endl;
  } else {
    puts("IMPOSSIBLE");
  }
}

int main() {
  cin >> n >> m;
  rep(i,3) cin >> steps[i];
  rep(i,m) {
    int u,v;
    cin >> u >> v;
    --u, --v;
    G[v].push_back(u);
  }
  compute();
  return 0;
}

Measured memory_bytes: 3260
from sys import stdin
N=int(input())
nodes=[None]*N
class node_tree():
    def __init__(self,node):
        self.node=node
        self.left=None
        self.right=None
        self.brother=None
        self.up=None

def ino(u):

    if u.left is not None:
        ino(u.left)
    print("",u.node,end="")
    if u.right is not None:
        ino(u.right)
def pre(u):
    print("",u.node,end="")
    if u.left is not None:
        pre(u.left)
    if u.right is not None:
        pre(u.right)
def search(u,key):
    if u.node <=key.node:
        if u.right is not None:
            search(u.right,key)
        else:u.right=key
    else:
        if u.left is not None:
            search(u.left,key)
        else:u.left=key
for i in range(N):
    command= list((stdin.readline().strip().split()))
    if len(command)!=1:
        key=int(command[1])
        if i==0:
            nodes[i]=node_tree(key)
        else:
            ins=node_tree(key)
            search(nodes[0],ins)
            nodes[i]=ins
    else:
        ino(nodes[0])
        print()
        pre(nodes[0])
        print()




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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 5e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--)
    {
        LL a,b,n; cin >> a >> b >> n;
        LL x = min(n,b-1);
        cout << (a*x)/b - a*(x/b) << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

int main() {
	int a, b, t, aa;
	int ans = 0;

	cin >> a >> b >> t;
	aa = a;

	while (a <= t +.5) {
		ans += b;
		a += aa;	
	}

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

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

int main(){
  string s;
  cin >> s;
  cout << s.at(0) << s.at(1) << s.at(2) << s.at(3) << s.at(4) << " " << s.at(6) << s.at(7) << s.at(8) << s.at(9) << s.at(10) << s.at(11) << s.at(12) << " " << s.at(14) << s.at(15) << s.at(16)<< s.at(17)  << s.at(18) << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <iomanip>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	double A,res = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		res += 1/A;
	}
	cout << setprecision(20) << fixed << 1/res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	int n;
	string s1, s2;
	cin >> n;
	cin >> s1 >> s2;
	
	ll ans = 1, p = 0;
	bool f = false;
	
	if (s1[0] == s1[1]) ans = 6, p = 2;
	else ans = 3, p = 1, f = true;
	
	while (p < n) {
		if (p + 1 < n && s1[p] == s1[p + 1]) {
			if (!f) ans = ans * 3 % MOD;
			else ans = ans * 2 % MOD;
			f = false;
			p += 2;
		}
		else {
			if (f) ans = ans * 2 % MOD;
			f = true;
			p++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    if(b%a == 0){
        printf("%d\n",a+b);
    }else{
        printf("%d\n",b-a);
    }
}

Measured memory_bytes: 256
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;

using namespace std;

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

const int MAXN = (int)3e5 + 5;

ll fromLeft[MAXN], fromRight[MAXN];
int arr[MAXN];
int n;

void solve() {
  scanf("%d", &n);
  
  for (int i = 1; i <= 3 * n; ++i) {
    scanf("%d", &arr[i]);
  }
  
  priority_queue<int> Q;
  ll bestSum = 0;
  
  for (int i = 1; i <= n; ++i) {
    Q.push(-arr[i]);
    bestSum += arr[i];
  }
  
  for (int i = n; i <= 2 * n; ++i) {
    fromLeft[i] = bestSum;
    bestSum += arr[i + 1];
    Q.push(-arr[i + 1]);
    bestSum -= -Q.top();
    Q.pop();
  }
  
  while (!Q.empty()) {
    Q.pop();
  }
  
  bestSum = 0;
  
  for (int i = 3 * n; i > 2 * n; --i) {
    Q.push(arr[i]);
    bestSum -= arr[i];
  }
  
  for (int i = 2 * n; i >= n; --i) {
    fromRight[i] = bestSum;
    bestSum -= arr[i];
    Q.push(arr[i]);
    bestSum -= -Q.top();
    Q.pop();
  }
  
  ll ans = (ll)-1e18;
  
  for (int i = n; i <= 2 * n; ++i) {
    ans = max(ans, fromLeft[i] + fromRight[i]);
  }
  
  printf("%lld\n", ans);
}

int main() {
  int tt = 1;
  
  while (tt--) {
    solve();
  }

  return 0;
}



Measured memory_bytes: 6616
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/times.h>  // 構造体tmsを使うために必要.
#include <time.h>
#include <unistd.h>
// #include <iostream>
// #include <gmpxx.h>

// コンパイル時に
// -lgmpxx -lgmp

// printf("%d\n", x); => std::cout << x << "\n";
// scanf("%d", &x); => std::cin >> x;
// int => mpz_class

// using namespace std;で std:: を省略できる

int main(int argc, char **argv) {
    int x;
    scanf("%d", &x);
    if (x == 1) {
        puts("0");
        return 0;
    }
    puts("1");
    return 0;
}


Measured memory_bytes: 3164
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from collections import defaultdict, Counter

def main():
    h, w = map(int, input().strip().split())
    mat = [0] * h
    d = {}
    for i in range(h):
        s = input().strip()
        for k, v in dict(Counter(s)).items():
            if k in d:
                d[k] += v
            else:
                d[k] = v
    num = [0] * 4
    for k, v in d.items():
        num[v % 4] += 1

    ans = "No"
    if h % 2 == 1 and w % 2 == 1:
        if num[1] + num[3] == 1 and num[2] <= h // 2 + w // 2:
            ans = "Yes"
    elif h % 2 == 1:
        if num[1] + num[3] == 0 and num[2] <= w // 2:
            ans = "Yes"
    elif w % 2 == 1:
        if num[1] + num[3] == 0 and num[2] <= h // 2:
            ans = "Yes"
    else:
        if num[1] + num[3] + num[2] == 0:
            ans = 'Yes'
    print(ans)
    # print(num)
if __name__ == '__main__':
    main()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define inf (1<<30)-1
#define INF (1LL<<62)-1
#define MOD 1000000007LL
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define PI acos(-1)
#define MEM(x,y) memset(x,y,sizeof (x))
#define debug cout<<"A"<<'\n'
#define REP(i,a,b) for (int i=(a); i<=(b); i++)
#define PER(i,a,b) for (int i=(a); i>=(b); i--)
#define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
#define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
#define print(x) cout<<x<<'\n'
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define UNIQUE(X) X.erase( unique( X.begin(), X.end() ), X.end() )


typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef pair<LL,LL>PLL;
typedef vector<int> VI;
typedef vector<LL> VL;


// Order Statistic Tree

/* Special functions:

        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
PII,
null_type,
less<PII>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <class T> inline T bigmod(T p,T e,T M)
{
    T ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

/*end of header*/

LL ask(LL n)
{
    printf("? %lld\n",n);
    fflush(stdout);
    string s;
    cin>>s;
    if(s[0]=='Y')return 1;
    else return 0;
}

int main()
{
    //freopen("input_file_name.in","r",stdin);
    //freopen("output_file_name.out","w",stdout);
    LL p=-1;
    REPL(i,1,12)
    {
        if(ask(bigmod(10LL,i,INF)))continue;
        p=i-1;
        break;
    }
    if(p==-1)
    {
        LL ans;
        REPL(i,0,10)
        if(ask(bigmod(10LL,i,MOD)+1)){ans=(bigmod(10LL,i,MOD));break;}
        printf("! %lld\n",ans);
        return 0;
    }
    LL best;
    if(p==0)
    {
        best=10;
    }
    else
    {
        LL lo=bigmod(10LL,p-1,INF),hi=bigmod(10LL,p,INF)-1,mid;
        while(hi>=lo)
        {
            LL mid=(hi+lo)/2;
            if(ask(mid))
            {
                best=mid;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        best*=100LL;
    }
    while(!ask(best))best+=10;
    best/=10;
    printf("! %lld\n",best);
    return 0;
}



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

int main() {
  ll A,B,V,W,T;
  cin >> A >> V >> B >> W >> T;
  ll div = A -B;
  if(div<0){
    div *= -1;
  }
  div -= T*(V-W);
  if(div <= 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;

#define F 						first
#define PB 						push_back
#define MP 						make_pair
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon					1e-9

constexpr ll int_pow(ll b, ll e) {
    return (e == 0) ? 1 : b * int_pow(b, e - 1);
}

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main()
{
	doublade();
	// w(t) {
		ll x, n;
		cin>>x>>n;
		set<ll> s;
		ll temp;
		rep(i, n) {
			cin>>temp;
			s.insert(temp);
		}
		ll ans, i=0;
		while(true) {
			if(s.count(x-i)==0) {
				ans = x-i;
				break;
			}else if(s.count(x+i)==0) {
				ans = x+i;
				break;
			}
			i++;
		}
		cout<<ans<<"\n";
	// }
	return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	while(cin >> n)
	{
		vector<ll> v(n);
		ll sum = 0;
		for(int i=0; i<n; i++)
		{
			cin >> v[i];
		}
		for(int i=0; i<n; i++)
		{
			sum += v[i]/2;
			if(v[i]&1 && i+1<n && v[i+1])
			{
				sum++;
				v[i+1]--;
			}
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int x, y;
    while (cin >> x >> y, x || y) {
        cout << min(x, y) << " " << max(x, y) << endl;
    }
}

Measured memory_bytes: 1156
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    //height
    int h = sc.nextInt();
    //width
    int w = sc.nextInt();
    
    for (int i = 0; i < h; i++){
      String s = sc.next();
      System.out.println(s + "\r\n" + s);
    }
  }
}

Measured memory_bytes: 22356
/*g++ main.cpp -o main.out*/
/*./main.out*/
/*std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);*/

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

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(n,a) memset(n,a,sizeof(n));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

int a[200005];
LL s[200005];

int main()
{
    int n;
    scanf("%d",&n);
    s[0]=0;
    rep(i,n)
    {
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    LL mn=200000000000001;
    rer(i,1,n-1)
    {
        mn=min(mn,abs(s[n]-s[i]-s[i]));
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 2560
def examC():
    X = I()
    cur = int(0)
    i = 1
    while (X>cur):
        cur += i
        i +=1
    print(i-1)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 3444
#include <algorithm>
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc()
{
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x=0; int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f; 
}
typedef long long ll;
int A;
int B;
int C;
int D;
int K;
int Q;
bool check(int Na)
{
	int Nb=Na==0?0:(Na-1)/K;
	return (B-Nb)<=(ll)(A-Na+1)*K;
}
int main()
{
	read(Q);
	for(int kase=1;kase<=Q;++kase)
	{
		read(A),read(B),read(C),read(D);
		K=(max(A,B)-1)/(min(A,B)+1)+1;
		int l=0,r=A,Na=-1;
		while(l<=r)
		{
			int mid=(l+r)>>1;
			if(check(mid)) Na=mid,l=mid+1;
			else r=mid-1;
		}
		int Nb=Na==0?0:(Na-1)/K;
		int t=(B-Nb)-(A-Na)*K;
		for(int i=C;i<=D;++i)
		{
			int x=i;
			if(x<=Na+Nb) putchar(x%(K+1)==0?'B':'A');
			else
			{
				x-=Na+Nb;
				if(x<=t) putchar('B');
				else
				{
					x-=t;
					putchar(x%(K+1)==1?'A':'B');
				}
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9;

int N, M, hs, cs;

void dfs(int n, set<int> &S, vector< vector<int> > &es){
  S.insert(n);
  for(int next : es[n]) if(S.find(next) == S.end()) dfs(next, S, es);
}

void bfs(vector< vector<int> > &es, queue<int> &open, vector<int> &closed){
  while(!open.empty()){
    int now = open.front(), cost = closed[now]; open.pop();
    for(int next : es[now]){
      if(closed[next] > cost + 1){
        closed[next] = cost + 1;
        open.push(next);
      }
    }
  }
}

int main() {
  int T; cin >>T;
  while(T--){
    cin >>N >>M >>hs >>cs;
    N++;
    vector< vector<int> > hes(N), ces(N);
    REP(i, M){
      int a, b; char c; cin >>a >>b >>c;
      if(c == 'N') { hes[a].push_back(b); hes[b].push_back(a); }
      else { ces[a].push_back(b); ces[b].push_back(a); }
    }

    set<int> X, Y;
    dfs(cs, X, ces); dfs(0, Y, ces);
    if(X == Y) { cout <<0 <<endl; continue; }

    vector<int> A, B, C, ac(N, INF), bc(N, INF), cc(N, INF);
    queue<int> aq, bq, cq;
    aq.push(hs); ac[hs] = 0;
    for(int n : X) { bq.push(n); bc[n] = 0; }
    for(int n : Y) { cq.push(n); cc[n] = 0; }
    bfs(hes, aq, ac);
    bfs(hes, bq, bc);
    bfs(hes, cq, cc);

    int ans = INF;
    REP(i, N) ans = min(ans, ac[i] + bc[i] + cc[i]);
    cout <<ans <<endl;
  }
  return 0;
}

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

void countingSort(vector<int> a, int max){
    vector<int> b(max);

    rep(i, a.size()){
        b.at(a.at(i))++;
    } 

    rep(i, max){
        while(b.at(i) != 0){
            if(i == max - 1 && b.at(i) == 1){
                cout << i << endl;
            }else{
                cout << i << " ";
            }
            b.at(i)--;
        }
    }
}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    int max = 0;
    rep(i, n){
        cin >> a.at(i);
        if(a.at(i) > max){
            max = a.at(i);
        }
    }
    max++;
    countingSort(a, max);
}


Measured memory_bytes: 18380
l, r = map(int, input().split())
ans = 10000000000
if r - l >= 2019:
    print(0)
    exit()
for i in range(l, min(r, l+2019)):
    for j in range(i+1, min(r,l+2019)+1):
        ans = min(ans, i*j%2019)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[1003][1003] = { {} };
	ll memox[1003] = {};
	ll memoy[1003] = {};
	ll x[1000006] = {};
	ll y[200005] = {};
	ll z[200005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	ans = 99999999999;
	cin >> a;
	cin >> b;
	vector<pair<int, int> > pairs(a);
	for (int i = 0; i < a; i++)
	{
		cin >> c;
		cin >> d;
		pairs[i] = make_pair(c, d);
	}
	sort(pairs.begin(), pairs.end());
	for (int i = 0; i < a; i++)
	{
		b -= pairs[i].second;
		if (b<=0)
		{
			cout << pairs[i].first << endl;
			break;
		}
	}


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  
  set<string> S;
  for( int i = 0; i < N; i++ ){
    string T;
    cin >> T;
    S.insert(T);
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 19260
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = [list(map(int,input().split())) for _ in range(N)]
    MOD = 10**9+7
    
    dp = [1] + [0 for _ in range(1<<N)]

    for i in range(N):
        use = [0 for _ in range((1<<N)+1)]
        for s in range(1<<N):
            if dp[s] == 0:
                continue
            for j in range(N):
                jb = 1<<j
                if not (s&jb) and a[i][j]:
                    use[s^jb] += dp[s]
        dp = use
    
    print(dp[(1<<N)-1]%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 146080
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 d,t,s;
  std::cin>>d>>t>>s;

  if(s*t>=d)std::cout<<"Yes\n";
  else std::cout<<"No\n";
  
  return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<int>v;
int main()
{
   int n;
   cin>>n;
   int a[n+1],b[n+1],c[n+1];
   for(int i=1;i<=n;i++)cin>>a[i];
   for(int i=1;i<=n;i++)cin>>b[i];
   for(int i=1;i<n;i++)cin>>c[i];
   int s=0,pv=-1;
   for(int i=1;i<=n;i++)
   {
       s+=b[a[i]];
       if(a[i]-1==pv)
        s+=c[pv];
       pv=a[i];
   }
   cout<<s;

}


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

int main(){
    int N, D; cin >> N >> D;
    vector<vector<int>> points(N, vector<int>(D));
    for(int i=0; i < N; i++){
        for(int j=0; j < D; j++){
            int x; cin >> x;
            points[i][j] = x;
        }
    }
    int ans = 0;
    for(int i=1; i < N; i++){
        for(int j=0; j < i; j++){
            int dis = 0;
            for(int k=0; k < D; k++){
                dis += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k]);
            }
            for(int x=1; x < (int)sqrt(dis) + 1; x++){
                if(x * x == dis){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int MOD = 365;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        // k: コンテストの種類数
        int k = 26;
        
        // n: 1日目～n日目にコンテストが開催される
        int n = sc.nextInt();
        
        // c[i]: タイプiのコンテストのマイナス係数
        int[] c = new int[k];
        for (int i = 0; i < k; i++) {
            c[i] = sc.nextInt();
        }
        
        // s[d][i]: タイプiをd日目に開催したときに増加する満足度
        int[][] s = new int[n+1][k];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        
        // t[i]: i日目に開かれるコンテストのタイプ
        int[] t = new int[n+1];
        // for (int i = 1; i <= n; i++) {
        //     t[i] = sc.nextInt() - 1;
        // }
        
        // last[i]: タイプiのコンテストが最近何日目に開かれたか
        int[] last = new int[k];
        
        // 満足度計算
        long score = 0;
        for (int i = 1; i <= n; i++) {
            long max = -1;
            int choice = -1;
            for (int contest = 0; contest < k; contest++) {
                // int contest = t[i];
                
                long tmp = 0;
                
                // UP
                tmp += s[i][contest];
                // last[contest] = i;
                
                // DOWN
                for (int j = 0; j < k; j++) {
                    tmp -= c[j] * (i-last[j]);
                }
                
                // System.out.println(score);
                
                if (contest == 0 || tmp > max) {
                    choice = contest;
                    max = tmp;
                }
                
                // System.out.println(contest + " " + choice + " " + tmp + " " + max);
            }
            
            score += max;
            last[choice] = i;
            t[i] = choice;
        }
        
        for (int i = 1; i <= n; i++) {
            System.out.println(t[i] + 1);
        }
    }
    
    static public class Test {
        Test() {
            System.out.println(MOD);
        }
        
    }
}


Measured memory_bytes: 47080
<?php
$n = intval(fgets(STDIN));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
if(array_sum($A) < array_sum($B)){
    echo "-1\n";
}else{
    $count = 0;
    $minus = 0;
    for($i = 0; $i < $n; $i++){
        if($A[$i] < $B[$i]){
            $minus += $B[$i] - $A[$i];
            $count++;
        }else{
            $plus[] = $A[$i] - $B[$i];
        }
    }
    sort($plus);
    while($minus > 0){
        $best = array_pop($plus);
        $minus -= $best;
        $count++;
    }
    echo $count;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  int N; cin >> N;
  int b[N]; rep(i,N) cin >> b[i];
  rep(i,N) {
    int num = b[i]-1;
    if (num>i) { cout << -1 << endl; return 0; }
    rep(j,num) swap(b[i-j-1],b[i-j]);
  }
  per(i,N) cout << b[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	while(cin>>n&&n){
		int a[5000]={},sum[5000]={},m=-1000000;
		for(int i=0;i<n;i++){
			cin>>a[i];
			sum[i+1]=sum[i]+a[i];
		}
		for(int i=0;i<n;i++){//start
			for(int j=i;j<n;j++){//end
				int tmp=sum[j+1]-sum[i];
				//if(tmp<=0){i=j;break;}
				//printf("%d-%d:%d\n",i,j,tmp);
				m=max(m,tmp);
			}
		}
		cout<<m<<endl;
	}
    return 0;
}

Measured memory_bytes: 1204
#include <map>
#include <cstdio>
using namespace std;
void solve(int T){
	map<pair<int,int>,int> m;
	char cmd[2];
	int n,k;
	for(;T--;){
		scanf("%s%d",cmd,&n);
		if(*cmd=='D'){
			for(auto it=m.begin();it!=m.end();){
				if(it->second==n){
					m.erase(it++);
				}else{
					++it;
				}
			}
		}else if(*cmd=='R'){
			auto it=m.lower_bound(make_pair(n,2000000000));
			if(it==m.begin()){
				puts("-1");
			}else{
				--it;
				printf("%d\n",it->first.first<=n&&n<=it->first.second ? it->second : -1);
			}
		}else if(*cmd=='W'){
			int cur=0;
			scanf("%d",&k);
			for(auto it=m.begin();it!=m.end();++it){
				int d=it->first.first-cur;
				if(d>k)d=k;
				if(d)m[make_pair(cur,cur+d-1)]=n;
				k-=d;
				if(k==0)break;
				cur=it->first.second+1;
			}
			if(k)m[make_pair(cur,cur+k-1)]=n;
		}
	}
}
int main(){for(int T;~scanf("%d",&T)&&T;puts(""))solve(T);}

Measured memory_bytes: 1240
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

//pは県、yは設立年、inはindex
struct city{int p,y,in;};


//県ごとに市を若いものから並べる。
bool comp1(const city& c1,const city& c2){
  if(c1.p<c2.p)return true;
  else if(c1.p>c2.p)return false;
  else {
    if(c1.y<c2.y)return true;
    else return false;
  }
}

bool comp2(const city& c1,const city& c2){
  if(c1.in<c2.in)return true;
  else return false;
}

int N,M;

vector<city> C;

int main(){
  cin>>N>>M;
  REP(i,M){
    int s,t;
    cin>>s>>t;
    city c;
    c.p=s;
    c.y=t;
    c.in=i+1;
    C.push_back(c);
  }
  sort(C.begin(),C.end(),comp1);

  int t=C[0].p,count=1;
  REP(i,C.size()){
    if(t!=C[i].p){
      count=1;
      t=C[i].p;
    }
    C[i].y=count++;
  }

  sort(C.begin(),C.end(),comp2);

  REP(i,C.size()){
    cout<<setfill('0')<<right<<setw(6)<<C[i].p;
    cout<<setfill('0')<<right<<setw(6)<<C[i].y<<endl;
  }

}


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

int main(){
    int H1,M1,H2,M2,K;
    cin>>H1>>M1>>H2>>M2>>K;
    int r;
    int minute=(H2*60+M2)-(H1*60+M1);
    r=minute-K;
    cout<<r<<endl;
}

Measured memory_bytes: 3624
import java.util.*;
import java.lang.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      	int num = sc.nextInt();
      	double[] ary = new double[num];
      	for(int i = 0; i < num; i++){
      		ary[i] = sc.nextDouble();
      	}
      	Arrays.sort(ary);
  		double result = ary[0];
      	for(int j = 1; j < num; j++){
          result = (result + ary[j])/2.0;
      	}
      	System.out.println(result);
  	}
}

Measured memory_bytes: 24272
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,a[1005],b[1005],c[1005],d[105][105],res;
int main()
{
    scanf("%d%d",&n,&m);
    memset(d,0x3f,sizeof d);
    for (int i=0;i<m;++i) {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];
    }
    for (int i=1;i<=n;++i)
        d[i][i]=0;
    for (int k=1;k<=n;++k)
        for (int i=1;i<=n;++i)
            for (int j=1;j<=n;++j)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    for (int i=0;i<m;++i) {
        bool f=true;
        for (int j=1;j<=n;++j)
            for (int k=1;k<=n;++k)
                if (d[j][a[i]]+d[b[i]][k]+c[i]==d[j][k])
                    f=false;
        res+=f;
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-7
long long mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
ll memo[3005][3005] , anss;
string s , t;
vector<char> v;
ll solve(int i , int j)
{
    if(i == s.size() || j == t.size())
        return 0;
    if(memo[i][j] != -1)
        return memo[i][j];
    ll ans = 0;
    if(s[i] == t[j])
        ans = solve(i + 1 , j + 1) + 1;
    else
    {
        ans = solve(i + 1 , j);
        ans = max(ans ,solve(i , j + 1));
    }
    memo[i][j] = ans;
    return memo[i][j];
}
void build(int i , int j)
{
    if(i == s.size() || j == t.size())
        return;
    if(s[i] == t[j])
    {
        v.push_back(s[i]);
        build(i + 1 , j + 1);
    }
    else if(memo[i][j] == solve(i + 1 , j))
        build(i + 1 , j);
    else
        build(i , j + 1);
}
int main()
{
    em3
    memset(memo , -1 , sizeof memo);
    cin >> s >> t;
    anss = solve(0 , 0);
    build(0 , 0);
    for(int i = 0 ; i < v.size() ; i++)
        cout << v[i];
    return 0;
}


Measured memory_bytes: 71040