akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int l[50];
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l, l+n);
    reverse(l, l+n);
    int sum = 0;
    for(int i=0; i<k; i++){
        sum += l[i];
    }
    cout << sum << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> T fl(T x, T y) { return x / y; }
template<typename T> T ce(T x, T y) { return (x + y - 1) / y; }

LL n, a[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	LL mi = 2, ma = 2;
	bool f = true;
	dec(i, n) {
		if(ce(mi, a[i]) * a[i] > ma) { f = false; break; }
		mi = ce(mi, a[i]) * a[i];
		ma = fl(ma, a[i]) * a[i] + a[i] - 1;
	}
	
	if(f) {
		cout << mi << " " << ma << endl;
	} else {
		cout << -1 << endl;
	}
	
	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	vector<vector<int> > vi;
	for(int i=0;i<26;i++)
	{
		vector<int> temp;
		vi.push_back(temp);
	}
	for(int i=0;i<s.size();i++)
		vi[s[i]-'a'].push_back(i);

	
	for(int i=0;i<26;i++)
		sort(vi[i].begin(),vi[i].end());
		
	int tot=0,curr=0;
	bool poss = true;
	for(int i=0;i<t.size();i++)
	{
		char c = t[i]-'a';
		if(i==0)
		{
			if(vi[c].size()==0)
			{
				poss=false;
				break;
			}
			curr = vi[c][0];
		}
		else
		{
			if(vi[c].size()==0)
			{
				poss=false;
				break;
			}
			int ind = lower_bound(vi[c].begin(),vi[c].end(),curr+1) - vi[c].begin();
			if(ind==vi[c].size())
			{
				tot++;
				curr = vi[c][0];
			}
			else
				curr = vi[c][ind];
		}
		
	}
	
	if(!poss)
		cout<<-1;
	else
	{
		long long ans = (tot*s.size()) + curr + 1;
		cout<<ans; 
	}
	
	
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll N = 100100;
ll Mod;

void DFS1(ll i = 1,ll p = 0);
void DFS2(ll i = 1,ll p = 0);

ll mul(ll x,ll y){
    return x*y % Mod;
}
void mul_self(ll& x,ll y){
    x = mul(x,y);
}

vector <ll> Adj[N];
vector <ll> Pref[N];
vector <ll> Suff[N];

ll Dp1[N];
ll Dp2[N];

int main()
{
    for(ll i=0;i<N;i++) Dp1[i] = Dp2[i] = 1;

    ll n;   cin>>n>>Mod;

    for(ll i=1;i<n;i++)
    {
        ll x,y; scanf("%lld%lld",&x,&y);

        Adj[x].push_back(y);
        Adj[y].push_back(x);
    }

    DFS1();
    DFS2();

    for(ll i=1;i<=n;i++)    printf("%lld\n",mul(Dp1[i],Dp2[i]));
}

void DFS1(ll i,ll p)
{
    for(auto j:Adj[i])
        if(j!=p)
            DFS1(j,i) , mul_self(Dp1[i],Dp1[j]+1);

    ll W = Adj[i].size();

    Pref[i].resize(W);
    Suff[i].resize(W);

    for(ll k=0;k<W;k++)
    {
        ll j = Adj[i][k];
        Pref[i][k] = ( j != p ? Dp1[j] + 1 : 1 );
        if(k-1>=0)  mul_self(Pref[i][k],Pref[i][k-1]);
    }

    for(ll k=W-1;k>=0;--k)
    {
        ll j = Adj[i][k];
        Suff[i][k] = ( j != p ? Dp1[j] + 1 : 1 );
        if(k+1<W)   mul_self(Suff[i][k],Suff[i][k+1]);
    }
}

void DFS2(ll i,ll p)
{
    ll k = -1;
    ll W = Adj[i].size();

    for(auto j:Adj[i])
        if(k++,j!=p)
        {
            ll L = k > 0 ? Pref[i][k-1] : 1 ;
            ll R = k+1 < W ? Suff[i][k+1] : 1 ;

            Dp2[j] = 1 + mul( Dp2[i] , mul(L,R) );

            DFS2(j,i);
        }
}


Measured memory_bytes: 24832
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    static BigDecimal[] cache = new BigDecimal[10];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        int length = str.length();
        BigDecimal result = new BigDecimal(0);
        for (int i = 1; i <= length; i++) {
            for (int from = 0; from + i <= length; from++) {
                int left = from == 0 ? 1 : from;
                int right = length - (from + i);
                right = right == 0 ? 1 : right;
                BigDecimal bigDecimal = new BigDecimal(str.substring(from, from + i));
                result = result.add(bigDecimal.multiply(c(left)).multiply(c(right)));
            }
        }
        System.out.println(result);

    }

    static BigDecimal c(int count) {
        if (cache[count] != null) {
            return cache[count];
        }
        if (count == 0 || count == 1) {
            return new BigDecimal(1);
        }
        int n = count - 1;
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int r = 1;
            for (int j = 0; j < i; j++) {
                r = r * (n - j);
            }
            for (int j = 0; j < i; j++) {
                r = r / (i - j);
            }
            result += r;
        }
        cache[count] = new BigDecimal(result + 1);

        return cache[count];
    }

}


Measured memory_bytes: 10580
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
 
int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return 1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}
 
int main(){
  int a,b,m,sum,tmp,tmpa=100001,tmpb=100001;
  scanf("%d%d%d",&a,&b,&m);
  int A[a],B[b];
  int str[m+1];
  for(int i=0;i<a;i++){
    scanf("%d",&A[i]);
    if(A[i]<tmpa){
      tmpa=A[i];
    }
  }
  for(int i=0;i<b;i++){
    scanf("%d",&B[i]);
    if(B[i]<tmpb){
      tmpb=B[i];
    }
  }
  int x[m],y[m],C[m];
  for(int i=0;i<m;i++){
    scanf("%d%d%d",&x[i],&y[i],&C[i]);
  }
  
  for(int i=0;i<m;i++){
    sum = A[x[i]-1]+B[y[i]-1]-C[i];  
    str[i]=sum;
  }
  
  str[m]=tmpa+tmpb;
  
  qsort(str, sizeof(str) / sizeof(int), sizeof(int), cmpnum);

  printf("%d",str[0]);
  
  return 0;
}

Measured memory_bytes: 2940
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))

dd = {}
tt ={}
for i in t:
    if i in tt:
        tt[i] += 1
    else:
        tt[i] = 1
        dd[i] = 0
for i in d:
    if i in dd:
        dd[i] += 1
    else:
        dd[i] =1


ans = 'YES'
for i in tt:
    if tt[i] > dd[i]:
        ans = 'NO'
print(ans)

Measured memory_bytes: 55776
d=int(input())
c = list(map(int,input().split()))

s=[None]*d
for i in range(d):
    s[i] = list(map(int,input().split()))

def maxarg(l):
    nl=len(l)
    ma=-10**20
    idx=-1
    for i in range(nl):
        if l[i]>ma:
            ma=l[i]
            idx=i
    return (idx,ma)

for ss in s:
    print(maxarg(ss)[0]+1)

Measured memory_bytes: 68180
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


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

using namespace std;

typedef long long lint;

lint gcd(lint x, lint y){ return __gcd(x, y); }
lint lcm(lint x, lint y){ return x / gcd(x, y) * y; }

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<lint, lint> > ss;
		lint l = 1;
		for (int i = 0; i < n; i++){
			lint d, v;
			cin >> d >> v;
			lint g = gcd(d, v);
			l = lcm(l, d / g);
			ss.push_back(make_pair(d, v));
		}
		lint g = l * ss[0].second / ss[0].first;
		for (int i = 1; i < n; i++){
			g = gcd(l * ss[i].second / ss[i].first, g);
		}
		for (int i = 0; i < n; i++){
			cout << l * ss[i].second / ss[i].first / g << endl;
		}
	}
	return (0);
}

Measured memory_bytes: 1204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BSs solver = new BSs();
        solver.solve(1, in, out);
        out.close();
    }

    static class BSs {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            String s = in.string();
            for (int i = 1; i < s.length(); i++) {
                String r = s.substring(0, s.length() - i - 1);
                if (r.length() % 2 == 0) {
                    String a = r.substring(0, r.length() / 2);
                    String b = r.substring(r.length() / 2);
                    if (a.equals(b)) {
                        out.println(r.length());
                        return;
                    }
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main(){
  int a;
  int b;
  cin >> a >> b;

  int ab = a* b;
  if (ab % 2 == 0){
    cout << "Even" << "\n";
  }
  else{
    cout << "Odd" << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,n) for(int _tmp=n,i=a;i<=_tmp;++i)
#define dep(i,a,n) for(int _tmp=n,i=a;i>=_tmp;--i)
#define re(i,a,n) for(int _tmp=n,i=a;i<_tmp;++i)
#define fec(i,a) for(__typeof a.begin() i=a.begin();i!=a.end();++i)
#define For(i,u) for(int i=H[u];i;i=nxt[i])
#define si(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
using namespace std;
template<class T> inline void read(T&x){char c;bool fu=0;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x*=-1;}
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z) {read(x,y);read(z);}
typedef long long ll;
typedef pair<int,int> pii;
const int N=111111;
//head
int a,b,c;
int main() {
	read(a,b,c);
	int d=a+b+c;
	if(d&1)puts("No");
	else if(a==d/2||b==d/2||c==d/2)puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;


struct point
{
    double x,y;
    point(double x,double y):x(x),y(y){}
};

double dis(point x,point y)
{
    double x1=x.x;double x2=y.x;
    double y1=x.y;
    double y2=y.y;
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
//    freopen("in.txt","r",stdin);

    double x1,y1,x2,y2;
    while(cin>>x1>>y1>>x2>>y2)
    {
        printf("%.8lf\n",dis(point(x1,y1),point(x2,y2)));
    }
}



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

const int MAX = 100;
int main() {
	int N, d;
	cin >> N;
	bool check[MAX]; // check[i]は直径i+1の餅が存在するか否かを示す
	for (int i = 0;i < MAX;i ++) check[i] = false; // 初期化
	
	for (int i = 0;i < N;i ++) {
		cin >> d;
		check[d - 1] = true;
	}
	int ret = 0; // 作れる最大の段数
	for (int i = 0;i < MAX;i ++) if (check[i]) ret ++;
	cout << ret;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、dをソートすることで、i<jの時d_i<=d_jであるものとする
この時、d_i==d_jとなるd_jの餅全てを取り除けば、i<jの時d_i<d_jであるから、
これはj==Nから順に全ての鏡餅を置くことができる
1<=d_i<=100を利用してバケットソートすれば速いし効率的だね
つまり、異なる直径の餅の数が何個あるか分かればいいだけなので、ある直径の餅が存在するか否かを
全ての直径に対して持っておけば良い訳だ
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int n;
int m;

vector<P> rot(vector<P> va){
	for(int i = 1; i < va.size(); i++){
		va[i].first -= va[0].first;
		va[i].second -= va[0].second;
	}
	va[0] = P(0, 0);
	if(va[0].first == va[1].first){
		int par = (va[1].second > va[0].second ? 1 : -1);
		for(int i = 0; i < va.size(); i++){
			va[i].first *= par;
			va[i].second *= par;
		}
		return va;
	}
	int par = (va[1].first > va[0].first ? -1 : 1);
	int par2 = (va[1].first > va[0].first ? 1 : -1);
	for(int i = 0; i < va.size(); i++){
		int buf = va[i].first;
		va[i].first = par * va[i].second;
		va[i].second = par2 * buf;
	}
	return va;
}

bool same(vector<P> va, vector<P> vb){
	if(va.size() != vb.size()) return false;
	for(int i = 0; i < va.size(); i++){
		if(va[i].first != vb[i].first || va[i].second != vb[i].second) return false;
	}
	return true;
}

int main(){
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		scanf("%d", &m);
		vector<P> va(m), va2(m);
		for(int i = 0; i < m; i++){
			scanf("%d %d", &va[i].first, &va[i].second);
			va2[m - i - 1].first = va[i].first;
			va2[m - i - 1].second = va[i].second;
		}
		va = rot(va);
		va2 = rot(va2);
		for(int i = 0; i < n; i++){
			scanf("%d", &m);
			vector<P> vb(m);
			for(int j = 0; j < m; j++) scanf("%d %d", &vb[j].first, &vb[j].second);
			vb = rot(vb);
			if(same(va, vb) || same(va2, vb)) printf("%d\n", i + 1);
		}
		printf("+++++\n");
	}
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main(){
    fast;
    
    ll n,x,y;
    cin>>n>>x>>y;
    
    vector<ll> v[n+1];
    
    v[1].push_back(2);
    v[n].push_back(n-1);
    for(ll i=2;i<n;i++){
        v[i].push_back(i-1);
        v[i].push_back(i+1);
    }
    
    v[x].push_back(y);
    v[y].push_back(x);
    
    ll ans[n+1] = {0};
    
    for(ll i=1;i<=n;i++){
        queue<ll> q;
        ll vis[n+1] = {0}, level[n+1] = {0};
        q.push(i);
        vis[i] = 1;
        
        while(!q.empty()){
            ll val = q.front();
            q.pop();
            ans[level[val]]++;
            for(ll u: v[val]){
                if(!vis[u]){
                    q.push(u);
                    vis[u] = 1;
                    level[u] = level[val] + 1;
                }
            }
        }
    }
    
    for(ll i=1;i<n;i++)
        cout<<ans[i]/2<<endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main(){
	vector<int> s, t;
	int n, n2;
	cin >> n;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	cin >> n2;
	for(int i = 0; i < n2; i++){
		int tmp;
		cin >> tmp;
		t.push_back(tmp);
	}
	int ans = 0;
	for(int i = 0; i < n2; i++){
		for(int j = 0; j < n; j++){
			if(t[i] == s[j]){
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3228
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;

  if(A >= 13){
    cout << B << endl;
  }else if(A >= 6 && A <= 12){
    cout << int(B/2) << endl;
  }else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
input = sys.stdin.readline

def solve():
    N = int(input())
    Sss = [input().rstrip() for _ in range(N)]

    cnt = Counter(Sss)
    #print('cnt:', cnt)

    maxNum = max(cnt.values())
    #print('maxNum:', maxNum)

    anss = []
    for key, value in cnt.items():
        if value == maxNum:
            anss.append(key)
    #print('anss:', anss)

    anss.sort()

    print('\n'.join(anss))


solve()


Measured memory_bytes: 35944
#include<stdio.h>
int main()
{
    int N,i,M,j,Pi,Xi,sum,a;
    int T[102];
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&T[i]);
    }
    scanf("%d",&M);
    for(j=1;j<=M;j++)
    {
        sum=0;
        scanf("%d %d",&Pi,&Xi);
        a=T[Pi-1];
        T[Pi-1]=Xi;
        for(i=0;i<N;i++)
        {
            sum=sum+T[i];
        }
        printf("%d\n",sum);
        T[Pi-1]=a;
    }
    return 0;
}


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

int main() {

    int n,k;
    cin >> n >> k;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    for (int i = k; i < n; i++) {
        if (a[i] > a[i-k]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

using namespace std;

#define ll long long

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	int n;
	cin>>n;
	int arr[n],dp[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	cout<<dp[n-1];

}

Measured memory_bytes: 4396
#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;
   long double b;
   cin>>a>>b;
   ll ans=a*b;
   cout<<ans<<endl;
}

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

int main(){
  int N, a[110];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int ans=0;
  for(int i = 0; i < N; i++){
    for(int j = N-1; j > i-1; j--){
      if(a[j] < a[j-1] ){
	int tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	ans++;
      }
    }
  }
  for(int i = 0; i < N;i++){
    if(i < N-1) cout << a[i] << " ";
    else cout << a[i] << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <utility>

#define MAX_H (1000000000)
#define MAX_W (1000000000)
#define MAX_N (100000)
#define ROW_PER (1024)
#define DIVIDE_ROUNDUP(n, k) (((n) + (k) - 1) / (k))

int main(int argc, char *argv[]) {
  long H, W, N, a[MAX_N], b[MAX_N], ans[10] = {};
  std::vector<std::vector<std::pair<long, long>>> table_h;
  long size_table;
  // read input
  scanf("%ld %ld %ld", &H, &W, &N);
  for (int n = 0; n < N; n++)
    scanf("%ld %ld", &a[n], &b[n]);
  for (int n = 0; n < N; n++) {
    a[n]--; b[n]--;
  }
  // create table_h
  size_table = DIVIDE_ROUNDUP(H, ROW_PER);
  for (int i = 0; i < size_table; i++)
    table_h.push_back(std::vector<std::pair<long, long>>());
  for (int n = 0; n < N; n++)
    table_h[a[n] / ROW_PER].push_back(std::pair<long, long>(a[n], b[n]));
  for (int i = 0; i < size_table; i++)
    std::sort(table_h[i].begin(), table_h[i].end());
  // count number of neighbours
  for (int n = 0; n < N; n++) {
    int a_n = a[n], b_n = b[n];
    // printf("n = %d, a_n = %d, b_n = %d\n", n, a_n, b_n);
    for (int di = -1; di <= 1; di++) {
      for (int dj = -1; dj <= 1; dj++) {
        int center_h = a_n + di, center_w = b_n + dj;
        if (center_h - 1 >= 0 && center_h + 1 < H &&
            center_w - 1 >= 0 && center_w + 1 < W) {
          // printf("center_h = %d, center_w = %d\n", center_h, center_w);
          int num_in_cell = 0;
          for (int i = center_h - 1; i <= center_h + 1; i++)
            for (int j = center_w - 1; j <= center_w + 1; j++)
              if (std::binary_search(table_h[i / ROW_PER].begin(),
                                     table_h[i / ROW_PER].end(),
                                     std::pair<long, long>(i, j)))
                num_in_cell++;
          ans[num_in_cell]++;
          // printf("num_in_cell = %d\n", num_in_cell);
        }
      }
    }
  }
  // remove duplicates and calculate 0
  ans[0] = (W - 2) * (H - 2);
  for (int k = 1; k < 10; k++) {
    ans[k] /= k;
    ans[0] -= ans[k];
  }
  // print answer
  for (int k = 0; k < 10; k++)
    printf("%ld\n", ans[k]);
  
  return 0;
}


Measured memory_bytes: 29156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

char s[N],t[N];
int sv[N],tv[N];

int main(){
	int n,m,a,b,c,d,q;
	scanf("%s",s);
	n=strlen(s);
	scanf("%s",t);
	m=strlen(t);
	REP(i,n){
		if (s[i]=='A')
			sv[i]=1;
		else sv[i]=2;
		if (i) sv[i]+=sv[i-1];
	}
	REP(i,m){
		if (t[i]=='A')
			tv[i]=1;
		else tv[i]=2;
		if (i) tv[i]+=tv[i-1];
	}
	scanf("%d",&q);
	REP(i,q){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		a--,b--,c--,d--;
		int x=sv[b];
		if (a) x-=sv[a-1];
		x%=3;
		int y=tv[d];
		if (c) y-=tv[c-1];
		y%=3;
		if (x==y) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<deque>
using namespace std;

int main(){
    string s;
    cin >> s;
    vector<char> x,y;
    for(char c : s) y.push_back(c);

    int q;
    cin >> q;

    int ti,fi;
    char ci;
    for(int i=0;i<q;i++){
        cin >> ti;
        if(ti==1){
            swap(x,y);
        }else{
            cin >> fi >> ci;
            if(fi==1){
                x.push_back(ci);
            }else{
                y.push_back(ci);
            }
        }
    }

    reverse(x.begin(),x.end());
    string ans;
    for(char c : x) ans += c;
    for(char c : y) ans += c;

    cout << ans << endl;
}

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

int main(void)
{
  int num;
  int data[200100];
  cin >> num;
  for(int i = 0; i < num; i++)
  {
    cin >> data[i];
  }
  sort(data, data+num);
  for(int i = 0; i < num - 1; i++)
  {
    if(data[i] == data[i + 1])
    {
      cout << "NO" << endl;
      return (0);
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
i=0;
loop{
    n=gets.to_i;
    exit if n==0;
    puts""if i>0;
    i+=1;
    n.times.map{s,*a=gets.split;[s,a[0].to_i*3+a[2].to_i]}.sort_by{|a|-a[1]}.map{|s|puts s*?,};
}


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*c,max(b*d,max(a*d,b*c)));
	return 0;
}

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

int main(){
	int k;
	std::string s;
	std::cin >> k >> s;
	if(s.size() > k){
		std::string tmp("...");
		s.resize(k);
		s += tmp;
	}
	std::cout << s << std::endl;
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool win(const char *f, char m) {
    if (f[0] == m && f[1] == m && f[2] == m) return true;
    if (f[3] == m && f[4] == m && f[5] == m) return true;
    if (f[6] == m && f[7] == m && f[8] == m) return true;
    if (f[0] == m && f[3] == m && f[6] == m) return true;
    if (f[1] == m && f[4] == m && f[7] == m) return true;
    if (f[2] == m && f[5] == m && f[8] == m) return true;
    if (f[0] == m && f[4] == m && f[8] == m) return true;
    if (f[2] == m && f[4] == m && f[6] == m) return true;
    return false;
}

int main() {
    char f[16];
    while (scanf("%s", f) != EOF) {
        if (win(f, 'o')) puts("o");
        else if (win(f, 'x')) puts("x");
        else puts("d");
    }
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, ans = 1e9 + 5;
    cin >> n;

    rep(i, n)
    {
        int c;
        cin >> c;
        int sum = 0;
        while (c % 2 == 0)
        {
            c /= 2;
            sum++;
        }
        ans = min(sum, ans);
    }

    OP(ans);
    return 0;
}

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


struct Info{
	int normal,compress;
};


int N,M;
int POW[15];
int min_num[16384];
Info info[14];


void func(){

	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].normal,&info[i].compress);
	}

	min_num[0] = 0;
	for(int i = 1; i < POW[N]; i++)min_num[i] = BIG_NUM;

	int ROOM,count,index_table[N];
	int add,compress_size;

	for(int state = 0; state < POW[N]-1; state++){
		if(min_num[state] == BIG_NUM)continue;

		ROOM = M;
		count = 0;

		for(int loop = 0; loop < N; loop++){
			if(state & (1 << loop)){
				ROOM += (info[loop].normal-info[loop].compress);
			}else{
				index_table[count] = loop;
				count++;
			}
		}

		for(int i = 0; i < POW[count]; i++){
			compress_size = 0;
			add = 0;
			for(int loop = 0; loop < count; loop++){
				if(i & (1 << loop)){
					compress_size += info[index_table[loop]].compress;
					if(compress_size > ROOM)continue;
					add += POW[index_table[loop]];
				}

				min_num[state+add] = min(min_num[state+add],min_num[state]+1);
			}
		}
	}

	if(min_num[POW[N]-1] == BIG_NUM){
		printf("Impossible\n");
	}else{
		printf("%d\n",min_num[POW[N]-1]);
	}
}


int main(){

	for(int i = 0; i < 15; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int n=s.size();
    int dame=0;
    rep(i,n-1){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+1+1<<endl;
            dame++;
            break;
        }
    }
    if(dame==0){
        rep(i,n-2){
            if(s[i]==s[i+2]){
                cout<<i+1<<" "<<i+2+1<<endl;
                dame++;
                break;
            }
            
        }
        if(dame==0){
            cout<<-1<<" "<<-1<<endl;
        }
    }
    
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

typedef pair<int, int> P;

struct Edge {
    int to, cost;
};

int main() {
    int n;
    cin >> n;
    vector<Edge> G[n];
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            G[i].push_back(Edge {v, c});
        }
    }

    vector<int> d(n, 1000000000); d[0] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, 0));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            Edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

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


Measured memory_bytes: 7824
N, M = map(int, input().split())
B = []
for _ in range(M):
    a, b = map(int, input().split())
    B.append([b, a])
B.sort()
C = []
i = 0
while True:
    C.append(B[i])
    if i == M - 1:
        break
    j = 1
    while True:
        if B[i][0] > B[i + j][1]:
            j += 1
            if i + j == M:
                break
            continue
        else:
            break
    if i + j == M:
        break
    i = i + j
print(len(C))

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

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

    int n;
    cin >> n;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    vector<long long> B(n + 1, 0);
    for(int i = 0; i < n + 1; i++){
        if(i > 0){
            B[i] += A[i - 1] + B[i - 1];
        }
    }

    long long mini = 1e18;
    for(int i = 0; i < n - 1; i++){
        mini = min(mini, abs(B[n] - B[i + 1] - B[i + 1]));
    }

    cout << mini << endl; 

    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  double sum = 0;
  double reciprocal;
  for (int i = 0; i < n; i++) {
    reciprocal = 1.0/a[i];
    sum += reciprocal;
  }
  double answer = 1/sum;
  printf("%lf\n", answer);

  return 0;
}

Measured memory_bytes: 128
n = int(input())
cards = sorted(map(int, input().split()), reverse=True)
score_alice, score_bob = 0, 0

for i in range(n):
  if i % 2 == 0:
    score_alice += cards[i]
  else:
    score_bob += cards[i]

print(score_alice - score_bob)



Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;ll a[200010];
ll dp[200010][4][2];

void solve(){
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n+1){
    rep(j,4){
      rep(flag,2){
        dp[i][j][flag]=-INF;
      }
    }
  }
  dp[0][0][0]=0;
  rep(i,n){
    rep(j,3){
      dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][0]+a[i]);
      if(j<2)dp[i+1][j+1][0]=max(dp[i+1][j+1][0],dp[i][j][0]);
      dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]);
    }
  }
  // rep(i,n+1){
  //   rep(j,3){
  //     rep(flag,2){
  //       cout << i << " " << j << " " << flag << " " << dp[i][j][flag] << endl;
  //     }
  //   }
  // }
  if(n%2) cout << max(dp[n][1][0],dp[n][2][1]) << endl;
  else cout << max(dp[n][0][0],dp[n][1][1]) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;

  int count = 0 ;

  
  for(int i=1;i<n;i++){
    if(s[i]==s[i-1]){
      count++;
    }
  }

  cout<<n-count<<endl;
  
}

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

int main(){
  int n,k,j=0,ans=0,c;
  cin>>n>>k;
  vector<int> a(n,0),b(n+1,0);
  REP(i,n){
    cin >> a.at(i);
    b.at(a.at(i))++;
  }
  sort(b.begin(),b.end());
  while(!b.at(j)) j++;
  c=n+1-j-k;
  REP(i,c){
    ans+=b.at(j);
    j++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<=n;i++)
#define out(s) cout << s << endl

int main(){
    int n;cin >>n;
    vector<int>a(n+2);
    vector<int>b(n+1);
    
    rep(i,n+1){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    int x=0;
    ll ans=0;
    rep(i,n){
        x=min(a[i],b[i]);
        ans+=x;
        b[i]-=x;
        x=min(a[i+1],b[i]);
        ans+=x;
        a[i+1]-=x;
        
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool {return abs(i) < abs(j);});
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//出力するよ
void output(vector<int> s){
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i!=0) cout<<" ";
        cout<<s[i];//<<endl;
    }
    cout<<endl;
}

void insert(string s,set<string> se){
    se.insert(s);
}

string find(string s,set<string> se){
    if(se.count(s)) return "yes";
    else return "no";
}

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

    vector<string> ans;
    set<string> se;

    for(int i=0;i<n;i++){
        string op,st;
        cin>>op>>st;
        if(op=="insert") se.insert(st);
        else{
            if(se.count(st)==1){
                ans.push_back("yes");
            }else{
                ans.push_back("no");
            }
        }
    }

    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 55320
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

class hopcroft_karp{
public:
	vector<vector<int> > graph; //linked list
	vector<int> dist,match;
	vector<bool> used,vv;

	hopcroft_karp(int n,int m) : graph(n),match(m,-1),used(n) {}

	void add_edge(int u,int v){
		graph[u].push_back(v);
	}

	void bfs(){
		dist.assign(graph.size(),-1);
		queue<int> que;
		for(int i = 0; i < graph.size(); i++){
			if (!used[i]){
				que.push(i);
				dist[i] = 0;
			}
		}

		while(!que.empty()){
			int a = que.front();
			que.pop();
			for(int i = 0 ; i < graph[a].size(); i++){
				int b = graph[a][i];
				int c = match[b];
				if(c >= 0 && dist[c] == -1){
					dist[c] = dist[a]+1;
					que.push(c);
				}
			}
		}
	}

	bool dfs(int a){
		vv[a] = true;
		for(int i = 0; i < graph[a].size(); i++){
			int b = graph[a][i];
			int c = match[b];
			if(c < 0 || (!vv[c] && dist[c] == dist[a]+1&& dfs(c))){
				match[b] = a;
				used[a] = true;
				return true;
			}
		}
		return false;
	}

	int bipartite_matching(){
		int ret = 0;
		while(1){
			bfs();
			vv.assign(graph.size(),false);
			int flow = 0;
			for(int i = 0; i < graph.size(); i++){
				if(!used[i] && dfs(i)) flow++;
			}
			if(flow == 0) return ret;
			ret += flow;
		}
	}

	void output(){
		for(int i = 0; i < match.size(); i++){
			if (~match[i]){
				cout << match[i] << " " << i << endl;
			}
		}
	}

};

int main()
{
	int X,Y,E;
	cin >> X >> Y >> E;
	hopcroft_karp g(X,Y);
	for(int i = 0; i < E; i++){
		int a,b;
		cin >> a >> b;
		g.add_edge(a,b);
	}

	cout << g.bipartite_matching() << endl;

	return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int check[505][505]={0};
    int ans[505][505]={0};
    int l[200005],r[200005];
    int p[100005],q[100005];
    for(int i=1; i<=M; i++){
        cin >> l[i] >> r[i];
        check[l[i]][r[i]]+=1;
    }
    //ij間に区間が完全に含まれる本数
    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            ans[i][j]=ans[i][j-1];
            for(int k=0; k+i<=N; k++){
                ans[i][j]+=check[i+k][j];
            }
        }
    }
    //質問に答える
    for(int i=1; i<=Q; i++){
        cin >> p[i] >> q[i];
    }
    for(int i=1; i<=Q; i++){
        cout << ans[p[i]][q[i]] << endl;
    }
    return 0;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    int n,k;
    cin>>n>>k;
    bool snuke[n+1]={};
    rep(i,k){
        int d;
        cin>>d;
        rep(l,d){
            int a;
            cin>>a;
            snuke[a]=true;
        }
    }

    long long ans=0;

    rep2(i,n){
        if(!snuke[i])ans++;
    }
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

enum Op {
	kMinus,
	kPlus
};

bool is_7(const int*nums, Op* op) {
	int num = 0;

	num += nums[0];
	for (int i = 1; i < 4; i++) {
		if (op[i] == kMinus) {
			num -= nums[i];
		}
		else {
			num += nums[i];
		}
	}

	return (num == 7);
}

bool find_7(const int* nums, int pos, Op* op) {
	if (pos == 4) {
		return is_7(nums, op);
	}

	op[pos] = kMinus;
	bool ret = find_7(nums, pos + 1, op);
	if (ret) return ret;
	
	op[pos] = kPlus;
	ret = find_7(nums, pos + 1, op);
	return ret;
}

int main()
{
	string s; cin >> s;

	int nums[4];
	for (int i = 0; i < 4; i++) {
		nums[i] = s[i] - '0';
	}

	Op op[4] = {};
	bool ret = find_7(nums, 1, op);

	cout << nums[0];
	for (int i = 1; i < 4; i++) {
		cout << ((op[i] == kMinus) ? "-" : "+");
		cout << nums[i];
	}
	cout << "=7" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n - 1));
  REP(i, n) {
    REP(j, n - 1) {
      cin >> a[i][j];
      a[i][j]--;
    }
    reverse(a[i].begin(), a[i].end());
  }

  vector<P> q;

  auto check = [&](ll i) {
    if (a[i].size() == 0) return;
    ll j = a[i].back();
    if (a[j].size() == 0) return;
    if (a[j].back() == i) {
      P p(i, j);
      if (p.first > p.second) swap(p.first, p.second);
      q.push_back(p);
    }
  };

  REP(i, n) { check(i); }
  ll day = 0;
  while (q.size() > 0) {
    day++;
    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    vector<P> prevQ;
    swap(prevQ, q);
    for (P p : prevQ) {
      ll i = p.first, j = p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    for (P p : prevQ) {
      ll i = p.first, j = p.second;
      check(i);
      check(j);
    }
  }

  REP(i, n) {
    if (a[i].size() != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << day << endl;
  return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<cstdio>
#define M 100000
using namespace std;
  
int main(){
    int n;
    int m;
    int l;
    int dis;
    int pos = 0;
    int ans = 0;
    int x[M];
    scanf("%d %d",&n,&m);
    x[0] = 0;
    for (int i = 1; i < n; i++){
        scanf("%d", &dis);
        x[i] = x[i - 1] + dis;
    }
    while (m--){
        scanf("%d", &l);
        if(l > 0){
            ans += x[pos + l] - x[pos];
        }
        else{
            ans -= x[pos + l] - x[pos];
        }
        pos += l;
        ans %= M;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1580
h,w,k=map(int,input().split())
s=[list(map(int,input().replace("#",'1').replace(".",'0'))) for i in range(h)]
a=s
tmp=1
for i in range(h):
  if sum(s[i])>0:
    for j in range(w):
      if s[i][j] == 1 and sum(s[i][j+1:])>0:
        a[i][j]=tmp
        tmp+=1
      elif j==w-1:
        a[i][j]=tmp
        tmp+=1
      else:
        a[i][j]=tmp

flg=0
for i in range(h):
  if flg>0 and sum(s[i])==0:
    s[i]=s[i-1]
  else:
    flg=1
for i in reversed(range(h)):
  if sum(s[i])==0:
    s[i]=s[i+1]
for i in range(h):
  print(' '.join(list(map(str,a[i]))))

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps){
	auto c3 = [](const P &a, const P &b, const P &c){
		ld A = norm(b - c);
		ld B = norm(c - a);
		ld C = norm(a - b);
		ld S = abs(cross(b - a, c - a));
		P p = (A*(B+C-A)*a + B*(C+A-B)*b + C*(A+B-C)*c) / (4*S*S);
		ld r = abs(p - a);
		return make_pair(r, p);
	};

	auto c2 = [](const P &a, const P &b){
		P c = (a + b) / (ld)2;
		ld r = abs(a - c);
		return make_pair(r, c);
	};

	auto in_circle = [](const P &a, const C &c){
		return norm(a - c.pnt) <= c.rad*c.rad + eps;
	};

	int n = ps.size();
	random_shuffle(ps.begin(), ps.end());
	C c = c2(ps[0], ps[1]);
	for(int i = 2; i < n; ++i){
		if(!in_circle(ps[i], c)){
			c = c2(ps[0], ps[i]);
			for(int j = 1; j < i; ++j){
				if(!in_circle(ps[j], c)){
					c = c2(ps[j], ps[i]);
					for(int k = 0; k < j; ++k){
						if(!in_circle(ps[k], c)){
							c = c3(ps[i], ps[j], ps[k]);
						}
					}
				}
			}
		}
	}
	return c;
}

// http://www.spoj.com/problems/QCJ4/
// http://www.spoj.com/status/ns=18116289

// int main(){
//     srand(time(0));
//     int n;
//     cin >> n;
//     vector<P> ps(n);
//     for(int i = 0; i < n; ++i){
//         ld x,y;
//         cin >> x >> y;
//         ps[i] = P(x,y);
//     }

//     printf("%.2lf\n", (double)smallest_enclosing_disc(ps).rad*2);
// }


int n,m;
ld r[111], mb[111];

bool used[111];

bool chk(int s){
	vector<int> b;
	rep(i,n)if(!used[i]) b.emplace_back(r[i]);
	vector<ld> a;
	for(int i = s; i < m; ++i) a.emplace_back(mb[i]);
	sort(all(a));
	sort(all(b));
	int last = -1;
	rep(i,a.size()){
		bool found = false;
		for(int j = last+1; j < (int)b.size(); ++j){
			if(a[i] < b[j] + eps){
				found = true;
				last = j;
				break;
			}
		}
		if(!found)return false;
	}
	return true;
}

int main(){
	vector<int> ans;
	cin >> n;
	G g(n);
	rep(i,n){
		ld x,y;
		cin >> x >> y;
		g[i] = P(x,y);
	}
	printf("%.10lf\n",smallest_enclosing_disc(g).rad);

}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let n: usize = read();
    let a: Vec<f64> = (0..n).map(|_| read()).collect();
    let mut ans: f64 = 0.0;
    for i in a{
        ans += 1.0 / i;
    }
    ans = 1.0 / ans;
    println!("{}", ans);
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int a[100000];
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 0;i < n;i++)scanf("%d", &a[i]);
	sort(a, a+n, greater<>());
	int t1 = -1, t2 = -1;
	long long ans = 0;
	for(int i = 1;i < n;i++){
		if(a[i] == a[i-1] && t1 != -1){
			t2 = a[i];
			ans = (long long)t1*t2;
			break;
		}
		if(a[i] == a[i-1] && t1 == -1){
			t1 = a[i];i++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>

using namespace std;

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

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

    int M;
    cin >> M;

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

    // ソート
    sort(D, D + N);
    sort(T, T + M);

    int dIndex = 0;

    for(int i = 0; i < M; i++) {
        while(D[dIndex] < T[i]) {
            if(dIndex < N - 1) {
                dIndex++;
            } else {
                cout << "NO" << endl;
                return 0;
            }
        }
        if(D[dIndex] != T[i]) {
            cout << "NO" << endl;
            return 0;
        }
        dIndex++;
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792