akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<utility>
#include<map>
using namespace std;
int main(){
    int m;
    while(cin >> m, m){
        int a,b;
        cin >> a >> b;
        vector<int> tx(m-1),ty(m-1);
        for(int i = 0; i < m-1; i++){
            int p,q;
            cin >> p >> q;
            tx[i] = p-a;
            ty[i] = q-b;
        }
        int n;
        cin >> n;
        vector<int> x(n),y(n);
        map<pair<int,int>,int> ma;
        for(int i = 0; i < n; i++){
            cin >> x[i] >> y[i];
            ma[make_pair(x[i],y[i])]++;
        }
        for(int i = 0; i < n; i++){
            bool c = true;
            for(int j = 0; j < m-1 && c; j++){
                if(ma.count(make_pair(x[i]+tx[j],y[i]+ty[j])) == 0){
                    c = false;
                }
            }
            if(c){
                cout << x[i] - a << " " << y[i] - b << endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    map<char,int> memo;
    string s;
    while (cin >> s) {
        for (auto c : s) {
            if ('a' <= c && c <= 'z') {
                memo[c]++;
            }
            else if ('A' <= c&&c <= 'Z') {
                c = c - 'A' + 'a';
                memo[c]++;
            }
        }
    }

    rep(i,0,26){
        char c = i + 'a';
        cout << c << " : " << memo[c] << endl;
    }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define M 100000
using namespace std;
int main() {
  int N,answer=0,a;
  map<int,int> b;
  for (cin >> N; N; b[a]++, N--) {
    cin >> a;
  }
  for (int i = 0; i <= M; i++) {
    answer = max(answer,b[i]+b[i-1]+b[i+1]);
  }
  cout << answer;
}

Measured memory_bytes: 8260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 4e3 + 2;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; cin >> a[i++]);
    sort(a, a + n);
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        int low, high, mid, val;
        for (int j = i + 1; j < n; j++)
        {
            low = j + 1, high = n - 1, val = -1;
            while(low <= high)
            {
                mid = (low + high) / 2;
                if (a[i] < a[j] + a[mid] && a[j] < a[mid] + a[i] && a[mid] < a[i] + a[j])
                    low = mid + 1, val = mid;
                else
                    high = mid - 1;
            }
            if (~val) ans += (val - j);
        }
    }
    cout << ans;
    return 0;
}

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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=1;i<=n;i++){
        int c=0,k=i;
        while(k>0){
            k/=10;
            c++;
        }
        arr[i]=0;
        if(c&1){
            arr[i]=1;
        }
    }

    for(int i=2;i<=n;i++){
        arr[i]+=arr[i-1];
    }

    cout<<arr[n];

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define int long long
#define D double
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define maxn 200005
int n, m, a[maxn], ans, Mi = -1e18, Ma = 1e18, c1, c2, b[maxn], c[maxn], g, d[maxn], c3;
il int check(int x) {
	int tem = 0;
	if(x >= 0) {
		tem = g * (c1 + c2) + g * (g - 1) / 2 + c1 * c2;
		rep(i, 1, c1 - 1) tem += upper_bound(b + i + 1, b + c1 + 1, x / b[i]) - b - 1 - i;
		rep(i, 1, c2 - 1) tem += upper_bound(c + i + 1, c + c2 + 1, x / c[i]) - c - 1 - i;
	}
	else {
		x = -x;
		rep(i, 1, c1){
            int pos = lower_bound(c + 1, c + c2 + 1, (int)ceil((D)x / (D)b[i])) - c;
            if(b[i] * c[pos] < x) pos++;
            while(b[i] * c[pos - 1] >= x) -- pos;
            if(c2 >= pos) tem += c2 - pos + 1;
        } 
	}
	return tem >= m;
}
signed main() {
	n = read(), m = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) {
		if(a[i] < 0) b[++ c1] = -a[i];
		else if(a[i] > 0) c[++ c2] = a[i];
		else ++ g;
	}
	sort(b + 1, b + c1 + 1), sort(c + 1, c + c2 + 1);
	while(Mi < Ma){
        int Mid = (Mi + Ma) >> 1;
        if(check(Mid)) Ma = Mid;
        else Mi = Mid + 1;
    }
	cout << Ma;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; 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(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    string s;cin >> s;
    vector<vector<int>> e(n);
    vector<int> a(n),b(n);
    REP(i,m){
        int u,v;cin >> u >> v;
        u--,v--;
        e[u].push_back(v);
        e[v].push_back(u);
        if(s[v]=='A') a[u]++;
        else b[u]++;
        if(s[u]=='A') a[v]++;
        else b[v]++;
    }
    vector<bool> c(n,true);
    queue<int> q;
    REP(i,n){
        if(!a[i]||!b[i]){
            q.push(i);
            c[i]=false;
        }
    }
    while(!q.empty()){
        int p=q.front();
        q.pop();
        for(int x:e[p]){
            if(!c[x]) continue;
            if(s[p]=='A') a[x]--;
            else b[x]--;
            if(!a[x]||!b[x]){
                c[x]=false;
                q.push(x);
            }
        }
    }
    REP(i,n){
        if(c[i]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 15256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

int main()
{
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    string ans;
    rep(i,n)
    {
        ans+=s[i];
        ans+=t[i];
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

const int Mod = 1e9 + 7, MaxN = 100005;

int n, a[MaxN], vis[MaxN];
long long fact[MaxN], rfact[MaxN];

long long quickPow(long long a, int b)
{
    long long res = 1;
    for (; b; b >>= 1, a = a * a % Mod)
        if (b & 1)
            res = res * a % Mod;
    return res;
}

long long C(int n, int m)
{
    if (n < 0 || m < 0)
        return 0;
    if (n < m)
        return 0;
    return fact[n] * rfact[m] % Mod * rfact[n - m] % Mod;
}

int main()
{
    scanf("%d", &n);
    fact[0] = rfact[0] = 1LL;
    for (int i = 1; i < MaxN; i++)
        fact[i] = fact[i - 1] * i % Mod;
    for (int i = 1; i < MaxN; i++)
        rfact[i] = quickPow(fact[i], Mod - 2);
    int p[2];
    for (int i = 1; i <= n + 1; i++)
    {
        scanf("%d", a + i);
        if (vis[a[i]])
            p[0] = vis[a[i]], p[1] = i;
        vis[a[i]] = i;
    }
    int tot = p[0] + n - p[1];
    for (int i = 1; i <= n + 1; i++)
    {
        long long ans = C(n + 1, i), cur = C(tot, i - 1);
        ans = ((ans - cur) % Mod + Mod) % Mod;
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long long a,b,c;
  cin >> a >> b >> c;
  
  if(c-a-b>0){
  
  long long Ans = a*a + b*b + c*c -2*(a*b + b*c + c*a);
  
  if(0 < Ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  }else{
cout << "No" << endl;
  }
  
  
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;



int main(){
    int n;cin >> n;
    vector<P> x(n);
    vector<int> ans(n*n,0);
    for (int i = 0; i < n; i++) {
        int X;cin >> X;
        X--;
        x[i] = mp(X,i+1);
        ans[X] = i+1;
    }
    sort(ALL(x));
    vector<int> c(n,1);
    int l = 0,r = 0;
    for (int i = 0; i < n*n; i++) {
        if(ans[i]) continue;
        while(r < n && c[r] == x[r].second){
            r++;
        }
        while(l < n && c[l] == n){
            l++;
        }
        if(r == n){
            ans[i] = x[l].second;
            c[l]++;
        }
        else{
            ans[i] = x[r].second;
            c[r]++;
        }
    }
    vector<int> s(n,0);
    int k = 0;
    for (int i = 0; i < n*n; i++) {
        s[ans[i]-1]++;
        if(k < n && x[k].first == i){
            if(s[x[k].second-1] != x[k].second){
                puts("No");
                return 0;
            }
            k++;
        }
    }
    puts("Yes");
    for (int i = 0; i < n*n; i++) {
        cout << ans[i] << (i==n*n-1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int n,m;
	cin>>n>>m;
	m/=1000;
	for(int i=0;i<=2000;i++)
		for(int j=0;j<=2000;j++)
		{
			if(9*i+4*j==m-n&&i+j<=n)
			{
				printf("%d %d %d\n",i,j,n-i-j);
				return 0;
			}
		}
	puts("-1 -1 -1");
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{
	public static void main(String args[]) throws IOException
	{
		try{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=0;
		n=Integer.parseInt(br.readLine());
		if(n==1)
		{
			System.out.println("0");
		}
		else
		{
			System.out.println("1");
		}
		}
	catch(Exception e){}
}}

Measured memory_bytes: 32384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) x.begin(),x.end()
#define endl '\n'

#ifndef ONLINE_JUDGE
template<typename T>		
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

const int INF = 1e9+5;

void test_case(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n),dp(n,INF);
	for(int &x : a){
		cin>>x;
	}
	dp[0]=0;
	for(int i=1;i<n;i++){
		for(int j=i-1;j>=max(0LL,i-k);j--){
			dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
		}
	}
	cout<<dp[n-1];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int T=1;
    //cin>>T;
    for(int TT=1; TT<=T; TT++){
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


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

int fact(int n){
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}

int main(){
    int n;
    cin>>n;
    vector<pair<double,double>>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    double ans=0.0;
    sort(a.begin(),a.end());
    do{
        double hel=0.0;
        for(int i=0;i<n-1;i++){
            hel+=hypot(a[i].first-a[i+1].first,a[i].second-a[i+1].second);
        }
        // cout<<hel<<'\n';
        ans+=hel;
    }while(next_permutation(a.begin(),a.end()));
    ans=ans/(double)fact(n);
    printf("%.10lf",ans);
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int L[N];
    int sum = 0;
    int mx = 0;
    for (int i=0;i < N;i++) {
        cin >> L[i];
        if (L[i] > L[mx]) {
            mx = i;
        }
    }
    for (int i=0;i < N;i++){
        if (i != mx) {
            sum += L[i];
        }
    }
    if (sum > L[mx]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x,ans=1e9;
    cin>>a>>b>>x;
    for(int i=0;i<=20000;i++){
        int c=x-(i*1000);
        if(c<=0)ans=min(a*i,ans);
        else{
            if(c%500==0)ans=min(a*i+c/(500)*b,ans);
            else ans=min(a*i+(c/(500)+1)*b,ans);
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll D;
    cin >> D; //=365
    vec c(26);
    loop(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    loop(i, D)
    {
        loop(j, 26) cin >> s[i][j];
    }
    loop(i, D)
    {
        ll ran = (rand() % 26) + 1;
        putout(ran);
    }
    return 0;
}

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

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N, probs):
    "void()"
    m = [0.0] * (N + 1)
    m[0] = 1.0

    for i in range(N):
        n = [0.0] * (N + 1)
        for j in range(N):
            n[j + 1] += m[j] * probs[i]
        for j in range(N + 1):
            n[j] += m[j] * (1 - probs[i])
        m = n
    return sum(m[N // 2 + 1:])


def main():
    N = int(input())
    probs = list(map(float, input().split()))
    print(solve(N, probs))


T1 = """
3
0.30 0.60 0.80
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    0.612
    """


T3 = """
5
0.42 0.01 0.42 0.99 0.42
"""


def test_T3():
    """
    >>> as_input(T3)
    >>> main()
    0.3821815872
    """


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 74412
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

constexpr int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;
    vector<set<int>> days(K);
    int idx = 0;
    int cnt = 0;
    // left to right
    while (idx < N) {
        if (S[idx] == 'o') {
            days[cnt++].insert(idx);
            idx += C + 1;
        }
        else {
            ++idx;
        }
        if (cnt == K) {
            break;
        }
    }
    // right to left
    idx = N - 1;
    cnt = K;
    while (idx >= 0) {
        if (S[idx] == 'o') {
            days[--cnt].insert(idx);
            idx -= C + 1;
        }
        else {
            --idx;
        }
        if (cnt == 0) {
            break;
        }
    }
    vector<int> ans;
    rep(i, 0, K) {
        if ((int)days[i].size() == 1) {
            ans.push_back(*days[i].begin());
        }
    }
    sort(all(ans));
    rep(i, 0, ans.size()) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 22924
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
ll a[3005];
ll dp[3005][3005];
ll rec(ll l,ll r,ll eo){
	if(dp[l][r] != -1){
		return dp[l][r];
	}
	if(r == l){
		if(eo) return -a[l];
		else return a[l];
	}
	ll ans1 = rec(l + 1,r,1 - eo);
	ll ans2 = rec(l,r - 1,1 - eo);
	if(eo){
		ans2 = ans2 - a[r];
		ans1 = ans1 - a[l];
		dp[l][r] = min(ans1,ans2);
	}
	else{
		ans2 = ans2 + a[r];
		ans1 = ans1 + a[l];
		dp[l][r] = max(ans1,ans2);
	}
	return dp[l][r];	
}
int main(){
	cin >> n;
	for(ll i = 0;i < n;i++){
		cin >> a[i];
	}
	memset(dp,-1,sizeof(dp));
	cout << rec(0,n - 1,0) << "\n";
	return 0;
}

Measured memory_bytes: 70912
s_1, s_2, s_3, s_4 = input()
i = 0
if s_1 == '+':
  i += 1
elif s_1 == '-':
  i += -1
if s_2 == '+':
  i += 1
elif s_2 == '-':
  i += -1
if s_3 == '+':
  i += 1
elif s_3 == '-':
  i += -1
if s_4 == '+':
  i += 1
elif s_4 == '-':
  i += -1
print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

  int N;
  //
  cin >> N;
    vector<ll> vec(N);
  for(int i=0; i < N; i++) cin >> vec[i];
  //
  cout << accumulate(vec.begin(), vec.end(), 0) - N << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200005];
long long cnt[200005];

int main(){
    int n;
    cin>>n;
    for(int i=0; i<200004; ++i) cnt[i]=0;
    for(int i=0; i<n; ++i){
        cin>>a[i];
        cnt[a[i]]++;
    }
    long long sol=0;
    for(int i=0; i<200004; ++i)
        sol+=(cnt[i]*(cnt[i]-1))/2;
    for(int i=0; i<n; ++i){
        cout<<sol-cnt[a[i]]+1<<endl;
    }
    return 0;
}


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

/* editorial */

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

    int N;
    cin >> N;
    vector<long long> A(N);
    int minus_num = 0;
    bool exist_zero = false;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] < 0)
        {
            minus_num++;
        }
        if (A[i] == 0)
        {
            exist_zero = true;
        }
    }

    long long sum = 0LL;
    long long mn = 1e9 + 7;
    for (int i = 0; i < N; i++)
    {
        sum += abs(A[i]);
        mn = min(mn, abs(A[i]));
    }

    if (minus_num % 2 == 0 || exist_zero)
    {
        cout << sum << endl;
    }
    else
    {

        cout << sum - 2 * mn << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
	Scanner sc;

	void calc() {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		if (N%2 != 0) {
			System.out.println("No");
			return;
		}
		int h = S.length()/2;
		for (int i = 0; i < h; i++) {
			if (S.charAt(i) != S.charAt(i+h)) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 21844
//ABC155_C
#include<iostream>
#include<map>
#include<string>
using namespace std;

map<string, int> Data;

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

	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;

		Data[S] += 1;
	}

	int maxv = 0;

	for (const auto& x : Data) {
		int v = x.second;
		if (v > maxv) maxv = v;
	}

	for (auto it = Data.begin(); it != Data.end(); it++) {
		if (it->second == maxv) {
			cout << it->first << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 19284
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n,ans=0;
	string s="No";
	bool flag = false;

	cin >> s;

	string operate;

	vecbool isAdd(3, false);

	forll(i, 0, 2)
	{
		ll buf;
		isAdd[0] = (i % 2 == 0 ? true : false);
		forll(j, 0, 2)
		{
			isAdd[1] = (j % 2 == 0 ? true : false);
			forll(k, 0, 2)
			{
				isAdd[2] = (k % 2 == 0 ? true : false);

				buf = s[0] - '0';

				forll(l, 0, 3)
				{
					if (isAdd[l])
					{
						buf += (s[l + 1]- '0');
					}
					else
					{
						buf -= (s[l + 1]- '0');
					}

					if (buf == 7)
						break;
				}
				if (buf == 7)
					break;
			}
			if (buf == 7)
				break;
		}
		if (buf == 7)
			break;
	}

	forll(i, 0, 3)
	{
		if (isAdd[i])
			operate.push_back('+');
		else
			operate.push_back('-');
	}

	cout << s[0] << operate[0] << s[1] << operate[1] << s[2] << operate[2] << s[3] << "=7";

}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            cin = new CommonInput();

            int N, W, H, S, T;
            int x, y;
            int result, tmp;
            bool[,] map;

            while (true)
            {
                N = cin.GetNextToInt();

                if (N == 0)
                    break;

                W = cin.GetNextToInt();
                H = cin.GetNextToInt();

                map = new bool[W + 1, H + 1];

                result = 0;

                for (int i = 0; i < N; i++)
                {
                    x = cin.GetNextToInt();
                    y = cin.GetNextToInt();
                    map[x, y] = true;
                }

                S = cin.GetNextToInt();
                T = cin.GetNextToInt();

                for (int i = 1; i <= W - S + 1; i++)
                {
                    for (int j = 1; j <= H - T + 1; j++)
                    {
                        tmp = Search(map, S, T, i, j);

                        if (result < tmp)
                        {
                            result = tmp;
                        }
                    }
                }

                Console.WriteLine(result);
            }
        }

        private int Search(bool[,] map, int s, int t, int sx, int sy)
        {
            int result = 0;

            for (int i = 0; i < s; i++)
            {
                for (int j = 0; j < t; j++)
                {
                    if (map[sx + i, sy + j])
                        result++;
                }
            }

            return result;
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n, C;
  cin >> n >> C;
  vector<vector<ll>> d(C, vector<ll>(C));
  vector<vector<ll>> c(n, vector<ll>(n));
  for (int i = 0; i < C; i++){
    for (int j = 0; j < C; j++){
      cin >> d[i][j];
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  vector<vector<ll>> rem(3, vector<ll>(C, 0));
  for (int i = 0; i < 3; i++){
    for (int j = 0; j < C; j++){
      for (int x = 0; x < n; x++){
        for (int y = 0; y < n; y++){
          if ((x + y) % 3 == i && c[x][y] != j){
            rem[i][j] += d[c[x][y]][j];
          }
        }
      }
    }
  }

  ll res = INF;
  for (int i = 0; i < C; i++){
    for (int j = 0; j < C; j++){
      for (int k = 0; k < C; k++){
        if (i != j && j != k && i != k){
          res = min(res, rem[0][i] + rem[1][j] + rem[2][k]);
        }
      }
    }
  }


  cout << res << endl;

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 2176
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
s = input()
t = input()

for i in range(N, -1, -1):
	if s[-i:] == t[:i]:
		print(N+(N-i))
		break
else:
	print(2*N)


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

int mm1[100005];
int mm2[100004];


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mm1[i]=__gcd(mm1[i-1],a[i]);
    }
    for(int i=n;i>=1;i--)
    {
        mm2[i]=__gcd(mm2[i+1],a[i]);
    }
    int mx=mm1[n];
    for(int i=1;i<=n;i++)
    {
        mx=max(mx,__gcd(mm1[i-1],mm2[i+1]));
    }
    cout<<mx;

}

Measured memory_bytes: 6008
while True:
    H, W = map(int, input().split())
    if H == 0:
        break
   
    for i in range(H):
        S=''
        for j in range(W):
          if (i+j) %2 == 0:
            S += '#'
          else:
            S += '.'
        print(S)
      
    print()


Measured memory_bytes: 5612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> C(m);
	vector<int> T(n+1,INT_MAX);
	for (int i=0;i<m;i++){
		cin >> C[i] ;
	}
	
	T[0]=0;
	T[1]=1;
	for (int i=2;i<=n;i++){
		for(int j=0;j<m;j++){
			if(i-C[j]>=0 && T[i]>T[i-C[j]]+1){
				T[i]=T[i-C[j]]+1;
			}
		}
	}
	cout << T[n] << endl;
	return 0;
}

Measured memory_bytes: 1284
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] R = new int[n];
		for (int i = 0; i < n; i++) {
			R[i] = sc.nextInt();
		}
		int maxProfit = -2000000000;
		int minProfit = R[0];
		for (int i = 1; i < n; i++) {
			maxProfit = Math.max(maxProfit, R[i] - minProfit);
			minProfit = Math.min(minProfit, R[i]);
		}
		System.out.println(maxProfit);
		sc.close();
	}
}



Measured memory_bytes: 101652
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {
	
	int k; 
	cin >> k;
	vector<int> A(k);
	vector<int> B(k);
	vector<int> C(k - 1);

	rep(i, k) cin >> A.at(i);
	rep(i, k) cin >> B.at(i);
	rep(i, k - 1) cin >> C.at(i);

	int sum = 0;

	rep(i, k) {
		sum += B.at(A.at(i) - 1);

		if (i > 0 && A.at(i - 1) + 1 == A.at(i)) {
			sum += C.at(A.at(i - 1) - 1);
		}
	}

	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, int> amap;
  for(int i=0;i<S.size();++i) {
    amap[S[i]]++;
  }
  bool can = true;
  if(amap['N']>0 && amap['S']==0) can = false;
  if(amap['S']>0 && amap['N']==0) can = false;
  if(amap['W']>0 && amap['E']==0) can = false;
  if(amap['E']>0 && amap['W']==0) can = false;
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

using namespace std;

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

	vector<int> B(N);

	for (int i = 0; i < N; i++)
	{
		int count = 0;
		cin >> A;

		while (A % 2 == 0)
		{
			A /= 2;
			count++;
		}

		B[i] = count;
	}

	sort(B.begin(), B.end());

	cout << B[0] << endl;

	return 0;
}


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

int main(){
    int a,b,c;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op=='+'){
            cout << a+b <<endl;
        }else if(op=='-'){
            cout << a-b <<endl;
        }else if(op=='*'){
            cout << a*b <<endl;
        }else if(op=='/'){
            cout << a/b <<endl;
        }else break;
    }
    return 0;
}


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

#define endl '\n'
#define ll long long
#define int long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

#define db  long double;
#define pll pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	m, z, k, n;
	cin >> m >> n;
	ll a[n];
	scan(a, n);
	rep(i, 0, n, 1)	{
		m -= a[i];
	}

	if (m < 0)	m = -1;
	ce(m)
	// cout_p((44 * n) / 7.0, 6);
}


Measured memory_bytes: 3732
#include<cstdio>
int a[3][3],A[3],B[3];
int main(){
	for(int i=0; i<3; i++)
	for(int j=0; j<3; j++)
		scanf("%d",&a[i][j]);
	for(A[0]=-1000; A[0]<=1000; A[0]++){
		B[0] = a[0][0] - A[0];
		B[1] = a[0][1] - A[0];
		B[2] = a[0][2] - A[0];
		A[1] = a[1][0] - B[0];
		A[2] = a[2][0] - B[0];
		bool ff = true;
		for(int i=0; i<3; i++)
			for(int j=0; j<3; j++)
				if(a[i][j] != A[i] + B[j])
					ff = false;
		if(ff){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int current = 1;
        int sum = 0;
        while (true) {
            if (sum + current >= x) {
                System.out.println(current);
                break;
            }
            sum += current++;
        }
    }
}


Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s;
  cin >> s;
  int n = s.size() - 1;
  long long sum = 0;
  for(int i = 0; i < 1 << n; i++){
    string tmp = "";
    for(int j = 0; j < n + 1; j++){
      tmp += s[j];
      if(i >> j & 1){
        sum += stoll(tmp);
        tmp = "";
      }
    }
    sum += stoll(tmp);
  }
  cout << sum << endl;
  return 0;
}

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

int main()
{
	int a, b, d, r;
    double f;

    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / b;

    cout << d << " " << r << " " << fixed << setprecision(6) << f << endl;

}


Measured memory_bytes: 3276
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll MOD = 1e9 + 7;



unordered_map<ll, ll>mp;
ll gcd(ll a, ll b)
{
  if (a == 0)
    return b;

  return gcd(b % a, a);

}
bool solve1(ll arr[], ll n)
{
  for (ll i = 0; i < n; i++)
  {


    if (arr[i] == 1)
    {
      continue;
    }
    if (mp[arr[i]])
    {
      return 0;
    }
    else
    {
      mp[arr[i]]++;
    }
    for (ll k = 2; k * k <= arr[i]; k++)
    {
      if (arr[i] % k == 0)
      {
        if (mp[k])
        {
          return 0;
        }
        if (arr[i] / k == k)
        {
          mp[k]++;
        }
        else
        {
          mp[k]++;
          if (mp[arr[i] / k])
          {
            return 0;
          }
          mp[arr[i] / k]++;
        }
      }
    }
  }


  return 1;


}
bool solve2(ll arr[], ll n)
{
  ll res = arr[0];

  for (int i = 1; i < n; i++)
  {
    res = gcd(res, arr[i]);
    if (res == 1)
    {
      return 1;
    }
  }
  return 0;

}
int main()
{


  ll n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++)
  {
    cin >> arr[i];
  }
  if (solve1(arr, n))
  {
    cout << "pairwise coprime" << endl;
  }
  else if (solve2(arr, n))
  {
    cout << "setwise coprime" << endl;
  }
  else
  {
    cout << "not coprime" << endl;
  }

}







Measured memory_bytes: 11416
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    set<int> mod;
    for (int i = 1; i < n; ++i)
      mod.insert((i*i)%n);

    vector<int> ans(n, 0);
    for (set<int>::iterator it = mod.begin(); it != mod.end(); ++it) {
      for (set<int>::iterator jt = it; jt != mod.end(); ++jt) {
	if (*it == *jt)
	  continue;
	int diff = *it - *jt;
	if (diff < 0)
	  diff += n;
	if (diff > (n-1)/2)
	  diff = n - diff;
	++ans[diff];
      }
    }

    for (int i = 1; i <= (n-1)/2; ++i)
      cout << ans[i]*2 << endl;
  }
  return 0;
}

Measured memory_bytes: 1064
#include <iostream>
#include <vector>
using namespace std;
int mp[10000000][5];
//d<muki p<nagasa q<basyo
int d,p,q;
int ktflg = 0,th;
int kesuflg =0;

void deb() {
  /*for(int i=0;i<10;i++) {
    for(int j=0;j<5;j++)
      cout << mp[i][j] << " ";
    cout << endl;
  }
  cout << "----------------------------" <<endl; */

}


void tumeru() { 
  
  int c = 0;
  for(int i=0;i<th;i++) {
    int zero = 0;
    for(int j=0;j<5;j++) if(mp[i][j] == 0) zero++;
    
    if(zero == 5) continue;
    for(int j=0;j<5;j++) mp[c][j] = mp[i][j];
    c++;
  }

  for(int i=c;i<th;i++) 
    for(int j=0;j<5;j++) 
      mp[i][j] = 0;


}

void kesu() {
  kesuflg = 0;
     int h = 0;
  while(1) {
    int flg =0;
    for(int i=0;i<5;i++) {
      if(mp[h][i] !=0) break;
      if(i == 4) flg = 1;
    }
    if(flg == 1) break;
    h++;
  }
  th = h;

  h = 0;
  while(1) {
    int zero = 0;
    int count = 0;
    for(int i=0;i<5;i++) {
      if(mp[h][i] == 0) zero++;
      else count++;
    }

    if(zero == 5) break;
    if(count == 5)
      for(int i=0;i<5;i++)
	mp[h][i] = 0;
    h++;
    kesuflg = 1;
  }
  
  
}
       

void add(int c) {

  int h = 0;
  while(1) {
    int flg =0;
    for(int i=0;i<5;i++) {
      if(mp[h][i] !=0) break;
      if(i == 4) flg = 1;
    }
    if(flg == 1) break;
    h++;
  }
  
  if(d == 1) {
    while(1) {
      if(h <= 0)break;
      int flg = 0;
      for(int i=0;i<p;i++)
	if(mp[h-1][i+q-1] != 0) break;
	else if(i == p-1) h-- ,flg = 1;
      if(flg == 0) break;
    }
  
  
    for(int i=0;i<p;i++)
      mp[h][i+q-1] = c;
  }
  
  if(d == 2) {

    int t=1;
    while(1) {
      if(h-t >= 0 && mp[h-t][q-1] == 0){
	h--;
	continue;
      }
      break;
    }
    for(int i=0;i<p;i++)mp[h+i][q-1] = c;
  }

  deb();
}
  


int main() {

  int ques;
  while(1) {
  cin >> ques;
  if(ques == 0) break;
  for(int i=0;i<50000;i++)
    for(int j=0;j<5;j++)
      mp[i][j] = 0;
  
  int c = 1;
  for(int i=0;i<ques;i++) {
    cin >> d >> p >>q;
    //cout << d <<" " << p <<" "<<q<<endl;
    add(c);
    kesu();
    tumeru();
    c++;
  }



    
  int h=0;
  int ans = 0;
  while(1) {
    int zero = 0;
    for(int i=0;i<5;i++){
      if(mp[h][i] == 0) zero++;
      else ans++;
    }
    if(zero == 5) break;
    h++;
  }
  cout << ans << endl;

  }
    return 0;
  
}

Measured memory_bytes: 2140
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main(){

    input!{
        S: chars,
        T: chars,
        A: usize,
        B: usize,
        U: chars,
    }

    if S==U{
        println!("{} {}", A-1,B);
    } else if T==U{
        println!("{} {}",A,B-1);
    } else {
        println!("error");
    }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 14;

int sm[(1 << MAX_N)];
double dp[(1 << MAX_N)];
double pp[101];

int main()
{
    int n,m,p;
    scanf("%d%d%d",&n,&m,&p);
    pp[0] = 1;
    vp edge(m);
    rep(i,m){
        pp[i+1] = pp[i] * (p / 100.0);
        scanf("%d%d",&edge[i].fi,&edge[i].se);
    }
    rep(i,(1 << n)){
        int res = 0;
        rep(j,m){
            int u = edge[j].fi - 1,v = edge[j].se - 1;
            if((i >> u) & (i >> v) & 1){
                res++;
            }
        }
        sm[i] = res;
    }
    for(int S=1;S<(1 << n);S=(S+1)|1){
        double res = 0;
        for(int T=S;T>0;T=(T-1)&S){
            res += dp[T]*pp[sm[S]-sm[T]-sm[S^T]];
        }
        dp[S] = 1.0 - res;
    }
    printf("%.12lf\n",dp[(1 << n)-1]);
    return 0;
}

Measured memory_bytes: 3408
#include <stdio.h>
#define BIG 2000000000
#define white 0
#define black 1
 
int n,c[100][100];
 
int prim() {
    int i, d[100], p[100], color[100], sum, minconst, u;
    for (i = 0; i < n; ++i) {
        color[i] = white;
        d[i] = BIG;
    }
     
    d[0] = 0;
     
    while(1){
        minconst = BIG;
        for (i = 0; i < n; ++i){
            if (color[i] != black && d[i] < minconst){
                minconst = d[i];
                u = i;
            }
        }
         
        if (minconst == BIG) break;
         
        color[u] = black;
         
        for (i = 0; i < n; ++i) {
            if (color[i] != black && c[u][i] != BIG) {
                if (c[u][i] < d[i]){
                    d[i] = c[u][i];
                    p[i] = u;
                }
            }
        }
    }
     
    sum = 0;
    for (i = 1; i < n ; ++i) {
        sum += c[i][p[i]];
    }
    return sum;
}
 
int main() {
    int i, j;
    scanf("%d", &n);
     
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            scanf("%d", &c[i][j]);
            if (c[i][j] == -1) c[i][j] = BIG;
        }
    }
     
    printf("%d\n", prim());
    return 0;
}

Measured memory_bytes: 1808