akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

const int N = 305;
int board[N][N];
int dist[N*N];
pair<int,int> location[N*N];

signed main() {
  int h,w,d;
  cin >> h >> w >> d;

  rep(i,h) rep(j,w) {
    int val; cin >> val;
    board[i][j] = val;
    location[val] = {i, j};
  }

  for (int cur = 1; cur <= h * w; cur++) {
    if(cur - d <= 0) continue;
    if(dist[cur] != 0) continue;
    int from =  cur - d;
    int distance = abs(location[cur].first - location[from].first)
            + abs(location[cur].second - location[from].second);
    dist[cur] = dist[from] + distance;
  }

  int q;
  cin >> q;
  while(q--) {
    int l, r;
    cin >> l >> r;

    int ans = dist[r] - dist[l];
    cout << ans << '\n';
  }


}

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ '0');
	return sum * fg;
}

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

const int MAXN = (int) 2e5;

// Template-Libs

// END

int n;

char S[MAXN + 5];

inline void input()
{
	scanf("%s", S + 1), n = strlen(S + 1);
}

inline void solve()
{
	int cntB = 0;
	LL ans = 0;
	for(int i = 1; i <= n; ++i)
		if(S[i] == 'B') ++cntB;
		else ans += cntB;
	printf("%lld\n", ans);
}

int main()
{
	input();
	solve();

	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <complex>
#include <cmath>
#include <vector>

using namespace std;

typedef complex<double> xy_t;

double cross_product(xy_t a, xy_t b) {
	return (conj(a) * b).imag();
}

int main() {
	double x, y;
	double s = 0;
	vector<xy_t> vertex;
	while (scanf("%lf,%lf", &x, &y) != EOF) {
		vertex.push_back(xy_t(x, y));
	}
	for (int i = 1; i < vertex.size() - 1; i++) {
		s += cross_product(vertex[i] - vertex[0], vertex[i + 1] - vertex[0]) / 2;
	}
	printf("%.6f", s);
}

Measured memory_bytes: 1092
#include <stdio.h>
main()
{ 
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==1 && b==2)
	printf("3");
	else if(a==1 && b==3)
	printf("2");
	
	else if(a==2 && b==3)
	printf("1"); 
	if(a==2 && b==1)
	printf("3");
	else if(a==3 && b==1)
	printf("2");
	
	else if(a==3 && b==2)
	printf("1"); 
	
	}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
    int n,i,p[51],q[51],m[51];
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&p[i]);
    }
    int c=0;
    for(i=1; i<=n; i++)
    {
        if(p[i]!=i)
        {
            q[c]=p[i];
            m[c]=i;
            c++;
        }
    }
    if(c==0)
        printf("YES\n");
    else if(c==1)
        printf("NO\n");
    else if(c>2)
        printf("NO\n");
    else if(c==2)
    {
        p[m[0]]=q[1];
        p[m[1]]=q[0];
        int flag=0;
        for(i=1; i<=n; i++)
        {
            if(p[i]!=i)
            {
                flag=1;
                break;
            }
        }
        if(flag==1) printf("NO\n");
        else printf("YES\n");
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
    int n;

    cin >> n;
    vector<int> v(n);
    rep(i, n) { cin >> v[i]; }
    sort(v.begin(), v.end());

    int ans = INT_MAX, tmp = 0;
    int l = v[0];
    int r = v[v.size() - 1];
#ifdef local
    dbg(l);
    dbg(r);
#endif
    for (int i = l; i != r + 1; ++i)
    {tmp=0;
        for (auto x : v) { tmp += pow((x - i), 2); }
#ifdef local
	dbg(i);
	dbg(tmp);
	dbg(ans);
#endif
	ans=min(ans,tmp);
    }

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

/*author  https://qiita.com/drken/items/0c88a37eec520f82b788*/
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a[3];

int main(){
	for(int i = 0; i < 3; i++){
		cin >> a[i];
	}
	
	if(abs(a[0]-a[1]) < abs(a[0] - a[2])) cout << "A" << endl;
	else cout << "B" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int>B=A;
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  int Max=B.at(0);
  int Max1=B.at(1);
  for(int i=0;i<N-1;i++){
  if(A.at(i)!=Max)
    cout<<Max<<" ";
    else
      cout<<Max1<<" ";
  
  }if(A.at(N-1)!=Max)
      cout<<Max<<endl;
  else
    cout<<Max1<<endl;

return 0;
}

Measured memory_bytes: 3200
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main()
{
  string s, t;

  cin >> s;
  cin >> t;

  int n = s.length();
  bool flag;

  for (int k = 0; k < n; k++)
  {
    flag = true;
    for (int i = 0; i < n; i++)
    {
      if (s[i] != t[(i+k) % n])
      {
        flag = false;
        break;
      }
    }
    if (flag) { printf("Yes\n"); break; }
  }

  if (!flag) printf("No\n");

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main(void){
    // Your code here
    int H ,W;
    
    cin >> H >> W;
    int cnt=0;
    vector<int> v1={1,-1,0,0,1,1,-1,-1};
    vector<int> v2={0,0,1,-1,1,-1,1,-1}; 
    vector<string> vec(H);
    
    for(int i=0;i<H;i++){
        cin >> vec[i];
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cnt =0;
            if(vec[i][j]== '.'){
                
                for(int k=0;k<8;k++){
                int x=i+v1[k];
                int y=j+v2[k];
                
                if(x<0||H<=x) continue;
                if(y<0||W<=y) continue;
                
                if(vec[x][y]=='#') cnt++;
                
                }
                cout << cnt;
                if(j==W-1){
                    cout << endl;
                }
            }else{
                cout<<"#";
                if(j==W-1){
                    cout << endl;
                }
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys


def f(n):
    re = 1
    for i in range(1,n + 1):
	re *= i
    return re


def solve():
    while True:
	n = int(raw_input())
	if n ==	0:
            break
        else:
            rr = f(n)
            ss = str(rr)
            rss = ss[::-1]
#            print rss                                                          
            c =	0
	    for k in rss:
                if k == "0":
                    c += 1
		else:
                    break
	    print c
if __name__ == "__main__":
    solve()

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;




void one_case() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n), good(n, 1);
    for (auto& el : h) {
        cin >> el;
    }
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        good[a] &= h[a] > h[b];
        good[b] &= h[b] > h[a];
    }

    cout <<  accumulate(good.begin(), good.end(), 0) << "\n";
}

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

    int t = 1;
//    cin >> t;
    while (t--) {
       one_case();
    }

    return 0;
}


Measured memory_bytes: 4056
#include <iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==b)
  {
  cout<<"Draw\n";}
  else if((a<b&&a!=1)||b==1)
  {
    cout<<"Bob\n";
  }
  else 
  {
    cout<<"Alice\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<char,ll> M;

int main(){
    ll A,B,C,T;cin>>A>>B>>C;
    if(A+B+1>=C){
        T=B+C;
    }
    else{
        T=2*B+1+A;
    }
    cout << T << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn = 55;
vector<int> g[maxn];
int n, m;
int main() {
 //   freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i =0; i < m; i++){
        int f,t;
        cin >> f >> t;
        g[f].push_back(t);
        g[t].push_back(f);
    }
    for(int i = 1;i <= n; i++)
        cout << g[i].size()<<endl;
    return 0;
}



Measured memory_bytes: 256
<>;@D=(1)x2e6;$s=.5;($x^=$_)?$P[$x]+=($D[$x]+=$P[$x]*($%-$c[$x]))%=$=:($%++,($s*=2)%=$==1e9+7),$c[$x]=$%for split$",<>;$s+=$_ for@P;print$x?$D[$x]:$s%$=

Measured memory_bytes: 189184
n=int(input())
s=[input() for _ in range(2)]
mod=1000000007
dp=[0]*n
if s[0][0]==s[1][0]:
    dp[0]=3
else:
    dp[0]=6
for i in range(1,n):
    if s[0][i]==s[1][i]:
        if s[0][i-1]==s[1][i-1]:
            dp[i]=dp[i-1]*2%mod
        else:
            dp[i]=dp[i-1]
    else:
        if s[0][i-1]==s[1][i-1]:
            dp[i]=dp[i-1]*2%mod
        else:
            if s[0][i]==s[0][i-1]:
                dp[i]=dp[i-1]
            else:
                dp[i]=dp[i-1]*3%mod
print(dp[-1])


Measured memory_bytes: 38384
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F first
#define S second
#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define db double
#define pb push_back
#define mp make_pair
#define el "\n"
#define vll vector <ll>
#define vl vector <long int>
#define vi vector <int>
#define all(v) (v.begin(), v.end()) 
#define rall(v) (v.rbegin(), v.rend()) 
const ll mod = 1e9+7;

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
     #endif
    /***************-Code starts from here-***************/
    ll x;
    cin>>x;
    cout<<x+(x*x)+(x*x*x);
    return 0; 
} 

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1],s=0,i,f;
	for(i=1;i<=n;i++)
	cin>>a[i];
	do{
		f=0;
		for(i=1;i<=n;i++)
		{
			if(a[i]%2==1)
			{
				f=1;
				break;
			}
			else
			a[i]=a[i]/2;
		}
		if(f==0)
		s++;
	}while(f==0);
	cout<<s;
	return 0;
}

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

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


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct RollingHash {
    static const ull mod1 = (1ULL << 61) - 1, mod2 = (1ULL << 31) - 1;
    static const ull base1 = 12343, base2 = 9973;
    static const ull p1 = mod1 * 3, p2 = mod2 * 2;

    int N;
    vector<ull> hash1, hash2, power1, power2;

    RollingHash(vector<int> &S) {
        N = S.size() - 1;
        hash1.assign(N + 1, 0);
        hash2.assign(N + 1, 0);
        power1.assign(N + 1, 1);
        power2.assign(N + 1, 1);
        for (int i = 0; i < N; ++i) {
            hash1[i + 1] = calcmod1(mul1(hash1[i], base1) + (S[i] ^ S[i + 1]));
            hash2[i + 1] = calcmod2(mul2(hash2[i], base2) + (S[i] ^ S[i + 1]));
            power1[i + 1] = calcmod1(mul1(power1[i], base1));
            power2[i + 1] = calcmod2(mul2(power2[i], base2));
        }
    }

    inline ull mul1(ull a, ull b) {
        ull au = a >> 31, ad = a & mod2;
        ull bu = b >> 31, bd = b & mod2;
        ull c = au * bd + ad * bu;
        ull cu = c >> 30, cd = c & (mod2 >> 1);
        return 2 * au * bu + ad * bd + cu + (cd << 31);
    }

    inline ull mul2(ull a, ull b) {
        ull c = a * b;
        ull cu = c >> 31, cd = c & mod2;
        return cu + cd;
    }

    inline ull calcmod1(ull a) {
        ull au = a >> 61, ad = a & mod1;
        ull res = au + ad;
        if (res >= mod1)
            res -= mod1;
        return res;
    }

    inline ull calcmod2(ull a) {
        while (a >= mod2)
            a -= mod2;
        return a;
    }

    inline pair<ull, ull> get(int l, int r) {
        ull res1 = calcmod1(hash1[r] + p1 - mul1(hash1[l], power1[r - l]));
        ull res2 = calcmod2(hash2[r] + p2 - mul2(hash2[l], power2[r - l]));
        return {res1, res2};
    }

    inline void solve(vector<int> &S, vector<int> &T) {
        int Tlen = T.size() - 1;
        if (Tlen > N)
            return;

        pair<ull, ull> t_hash = {0,0};

        for (int i = 0; i < Tlen; ++i) {
            t_hash.first = calcmod1(mul1(t_hash.first, base1) + (T[i] ^ T[i + 1]));
            t_hash.second = calcmod2(mul2(t_hash.second, base2) + (T[i] ^ T[i + 1]));
        }

        for (int i = 0; i + Tlen <= N; ++i) {
            int tmp = S[i] ^ T[0];
            pair<ull, ull> s_hash = get(i, i + Tlen);
            if (s_hash == t_hash)
                cout << i << " " << tmp << '\n';
        }
    }
};

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

    int N;
    cin >> N;
    vector<int> a(2 * N), b(N);
    for (int i = 0; i < N; ++i)
        cin >> a[i], a[i + N] = a[i];
    for (int i = 0; i < N; ++i)
        cin >> b[i];
    a.pop_back();

    RollingHash rhs(a);
    rhs.solve(a, b);

    return 0;
}


Measured memory_bytes: 18304
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define PI 3.1415926535897932384626433832795
using namespace std;

int main(){
    string s;
    cin>>s;
    int a[3];
    int sum=0;
    f(i,3){
        a[i]=s[i]-65;
        sum= sum+a[i];
    }
    if(sum==1 || sum==2){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    
    return 0;
}



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


void p(const std::string& s) {
	std::cout << s << "\n";
}

int main() {
	std::string ss,s,t;
	std::cin >> ss;

	ss = ss.substr(0, ss.size() - 1);

	if (ss.size() % 2 == 1) {
		ss = ss.substr(0, ss.size() - 1);
	}

	//p(ss);

	bool b = true;
	
	while (b) {

		size_t len = ss.size();

		s = ss.substr(0, len/2);
		t = ss.substr(len / 2, len / 2);
		if (s == t) {
			b = !b;
		}
		else {
			ss = ss.substr(0, len - 2);
		}
	}

	std::cout << ss.size()  << "\n";

	return 0;
}


Measured memory_bytes: 256
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  q=[i-X for i in p]
  qs=set(q)

  for i in range(N+1):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

Measured memory_bytes: 9196
import bisect


n,m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
bc = []
for i in range(m):
    bc.append([int(_) for _ in input().split()])
bc = sorted(bc, key=lambda x:x[1])
a = sorted(a)
t = 0
ans = 0
for _ in range(m):
    b,c = bc.pop()
    idx = bisect.bisect_left(a, c)
    if idx > t:
        ans += c * min(idx - t, b)
        t += min(idx - t, b)
    else:
        continue
for i in range(t, n):
    ans += a[i]
print(ans)

Measured memory_bytes: 85100
n=int(input())
al=list(map(int,input().split()))
al.sort(reverse=True)
cnt=0
h=0
w=0
t=set()
for a in al:
    if a in t:
        if h==0:
            h=a
        else:
            w=a
            break
        t.remove(a)
    else:
        t.add(a)
print(h*w)

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

int f(ll A, ll B) {
  return max(to_string(A).length(), to_string(B).length());
}

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

  int ans = 11;
  for(ll i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      ans = min(ans, f(i, N / i));
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int c = a * b;

	if (c % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}

	return 0;
}

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

char str[100];
int len,pnum;

LL calc(int s, int t)
{
    LL ret = 0;
    for(int i = s; i < t; ++i)
        ret = ret*10 + str[i]-'0';
    return ret;
}

int main()
{
    scanf("%s",str);
    len = strlen(str);
    pnum = len-1;
    int st = 1<<pnum;
    int pre = 0,now,nst;
    LL res = 0;
    for(int i = 0; i < st; ++i)
    {
        pre = 0;
        for(int j = 0; j <= 15; ++j)
        {
            if((1<<j)&i)
            {
                now = j;
                res += calc(pre,now+1);
                pre = now+1;
            }
        }
        res += calc(pre,len);
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
signed main(){
  int n,r=0;
  cin>>n;
  while(n){
    if(n>9&&n%10<9)n-=n%10+1;
    r+=n%10,n/=10;
  }
  cout<<r;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bits/stdc++.h>
#include <array>

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

using namespace std;

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    // m = 1000000007; 
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(int argc, const char * argv[]) {
    // source code
    long X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 >= 1 || ( X > Y * 2 || Y > X * 2)) {
        cout << 0;
        return 0;
    }
    int a = (X + Y) / 3;
    int b = (X + Y) * 2 / 3 - X;
    long ret = 1;
    vector<int> mod(b+1);
    rep(i, b+1) mod[i] = modinv(i, 1000000007);
    for (int i = 1; i <= b; i++) {
//        cout << a - i + 1 << " " << i << "\n";
        ret = (static_cast<long>((a - i + 1) * ret ) % (1000000007) * mod[i]) % 1000000007; 
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 1920
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.sizes = [1] * (n+1)
        self.root = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.root[x] = -1
            self.sizes[y] += self.sizes[x]
        else:
            self.par[y] = x
            self.root[y] = -1
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sizes[find(x)]
    

n, m = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(m)]

all_comb = n*(n-1)/2

a = UnionFind(n)

ans = [all_comb]
for pair in reversed(lst):
    if a.same_check(pair[0], pair[1]):
        ans.append(ans[-1])
        pass
    else:
        ans.append(ans[-1] - a.sizes[a.find(pair[0])]*a.sizes[a.find(pair[1])])
        a.union(pair[0], pair[1])
    
for i in reversed(ans[:-1]):
    print(int(i))

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
	if (A.size() == n + 1) {
		int now = 0;
		rep(i, q) {
			if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
		}
		ans = max(ans, now);
		return;
	}

	A.push_back(A.back());
	while (A.back() <= m) {
		dfs(A);
		A.back()++;
	}	

}

int main() {
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	dfs(vector<int>(1, 1));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3560
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main() {
    string s;
    string ss;
    cin >> s;
    for (auto c : s) {
        if (c != 'x') {
            ss.push_back(c);
        }
    }
    bool flag = true;
    for (int i = 0; i < ss.size() / 2; i++) {
        if (ss[i] != ss[ss.size() - 1 - i]) {
            flag = false;
            break;
        }
    }

    if (!flag) {
        cout << -1 << endl;
    }
    else {
        list<char> lst;
        for (auto c : s) {
            lst.push_back(c);
        }
        int cnt = 0;
        while (lst.size() > 1) {
            if (lst.front() == lst.back()) {
                lst.pop_front();
                lst.pop_back();
            }
            else {
                if (lst.front() == 'x') {
                    lst.push_back('x');
                    cnt += 1;
                }else if (lst.back() == 'x') {
                    lst.push_front('x');
                    cnt += 1;
                }
            }
        }
        cout << cnt << endl;
    }
    sysp;
}

Measured memory_bytes: 6956
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 2001000
using namespace std;
int trie1[maxn][26];
int S1[26*maxn];
int tot1=0;
int  in(char *s)
{
	int root,len;
    len=strlen(s);
    root=0;
    for(int i=0;i<len;i++)
    {
        int id=s[i]-'a';
        if(!trie1[root][id]) 
		{
            trie1[root][id]=++tot1;
			S1[tot1]=0;
		}			
        root=trie1[root][id];
		S1[root]++;
    }
	return S1[root]-1;
}
int main()
{
	int N;
	scanf("%d",&N);
	long long ans=0;
	while(N--)
	{
		char s[15];
		cin>>s;
		sort(s,s+10);
		ans+=in(s);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 53376
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int P;
int A[3030];
ll from[3030],to[3030],B[3030];
ll mo;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>P;
	mo=P;
	
	FOR(i,P) cin>>A[i];
	
	from[0]=1;
	FOR(i,P) {
		ZERO(to);
		FOR(j,3000) to[j+1]=from[j];
		FOR(j,3000) to[j]=(to[j]+P-i*from[j]%P)%P;
		swap(from,to);
	}
	
	
	for(i=0;i<P;i++) if(A[i]) {
		ll Q=1;
		for(j=0;j<P;j++) if(j!=i) Q=Q*(i-j)%mo;
		Q=modpow((Q%mo+mo)%mo);
		
		memmove(to,from,sizeof(from));
		for(j=3000;j>=1;j--) {
			(B[j-1]+=to[j]*Q)%=mo;
			to[j-1]=(to[j-1]+to[j]*i)%mo;
		}
		
	}
	FOR(i,P) cout<<B[i]%P<<" ";
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K;
  cin >> K;
  string S;
  cin >> S;
  if (S.size() <= K)
  {
    cout << S << endl;
  }
  else
  {
    string ans;
    for (int i = 0; i < K; i++)
    {
      ans += S[i];
    }
    ans += "...";
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
using namespace std;
double dp[100001][13]={0};
double rate[12]={1};
int main(){
  for(int i=1; i<12; i++) rate[i]=rate[i-1]*0.5;
  dp[1][1] = 1;
  for(int i=1; i<100000; i++){
    for(int j=0; j<13; j++){
      if(j == 0) dp[i+1][1]+=dp[i][j];
      else if(j<12){
	dp[i+1][0]+=dp[i][j]*(1-rate[j]);
	dp[i+1][j+1]+=dp[i][j]*rate[j];
      }
      else{
	dp[i+1][0]+=dp[i][j];
      }
    }
  }
  int n;
  while(cin >>n,n){
    double ans = 0;
    for(int i=0; i<=n; i++){
      for(int j=1; j<13; j++){
	ans+=dp[i][j];
      }
    }
    printf("%.8lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
#define ll 	long long
#define pb push_back
#define mp make_pair
using namespace std;

int main()
{

ll n,k;
cin>>n>>k;

ll a[n+9];

for(ll i=0;i<n;i++) cin>>a[i];

for(ll i=0;i<n-k;i++)
{
	if(a[i]<a[i+k])
	cout<<"Yes\n";
	else
	cout<<"No\n";
}

    return 0;
}


Measured memory_bytes: 5124
/*
author: shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    double t,x;
    cin>>t>>x;
    cout<<fixed<<setprecision(10)<<t/x<<endl;
    return 0;
}


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

int main() {
    long long N,Q;
    long long buf;
    long long inp1,inp2;
    long long sum=0;

    cin >> N;
    vector<long long> ans(N);
    vector<long long> num(100001);
    for(int i=0;i<N;i++){
        cin >> buf;
        num.at(buf)++;
        sum += buf;
    }
    cin >> Q;
    for(int i=0;i<Q;i++){
        cin >> inp1 >> inp2;
        sum = sum + (inp2 - inp1)*num.at(inp1);
        num.at(inp2) += num.at(inp1);
        num.at(inp1) = 0;
        //for(int i=0;i<5;i++){
        //   cout << num.at(i) << " ";
        //}
        cout << sum << endl;
    }
}

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

int main(){
  long long n,k;
  cin >> n;
  cin >> k;
  long long ans = 0;
  for(long long i=k;i<=n+1;i++){
    long long min = (i-1)*i/2;
    long long max = (n-i+1+n)*i/2;
    ans += max - min + 1;
    ans = ans%(long long)(pow(10,9)+7);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  ll arr[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
              1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << arr[N - 1] << endl;
  return 0;
}


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9460
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	char n[3];
	scanf("%s",n);
	if(n[0] == n[2])	printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;

struct Edge {
        int to, cost;
        Edge(int a, int b) {
                to = a;
                cost = b;
         }
};

int main() {
        int V, E, r;
        cin >> V >> E >> r;
        
        vector<Edge> Graph[100001];
        priority_queue<pii, vector<pii>, greater<pii> > q; 
        int dist[100001];
        
        int s,t,d;
        rep(i,0,E) {
                cin >> s >> t >> d;       
                Graph[s].push_back(Edge(t,d));
         }
         
         /*rep(i,0,V) {
                vector<Edge>::iterator it = Graph[i].begin();
                while(it != Graph[i].end()) {
                        cout << it->to << " ";
                        cout << it->cost << endl;
                        it++;
                  }
          }*/
                        
         
         fill(dist,dist+V,INF);
         dist[r] = 0;
         q.push(pii(0,r));
         
         while(!q.empty()) {
                pii p = q.top(); q.pop();
                int v = p.second;
                if(dist[v] < p.first) continue;
                for(int i=0; i < Graph[v].size(); i++) {
                        Edge e = Graph[v][i];
                        if(dist[e.to] > dist[v] + e.cost) {
                                dist[e.to] = dist[v] + e.cost;
                                q.push(pii(dist[e.to], e.to));
                          }
                  }
          }
          
          rep(i,0,V) {
                if(dist[i] == INF) cout << "INF" << endl;
                else cout << dist[i] << endl;
           }
          return 0;
}

Measured memory_bytes: 11284
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <limits.h>

using namespace std;

int main(void)
{
    long long N, K;
    cin >> N >> K;

    long long res = N % K;
    N = res;
    if(res == 0)
    {
        cout << "0" << endl;
        return 0;
    }

    while(res > abs(N - K))
    {
        N = abs(N - K);
        res = N;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
double dis(double x1, double x2, double y1, double y2){
    return sqrt((x1 - y1) * (x1 - y1) + (x2 - y2) * (x2 - y2));
}
int main(){
    double x1, x2, y1, y2, d;
    scanf("%lf%lf%lf%lf", &x1, &x2, &y1, &y2);
    d = dis(x1, x2, y1, y2);
    printf("%.6lf\n", d);
    return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>
char str[3];
int main(){
	int a;
	while(scanf("%d",&a),a){
		int ret=0;
		int p=0;int q=0;
		int last=0;
		for(int i=0;i<a;i++){
			scanf("%s",str);
			if(str[0]=='l'&&str[1]=='u')p++;
			if(str[0]=='l'&&str[1]=='d')p--;
			if(str[0]=='r'&&str[1]=='u')q++;
			if(str[0]=='r'&&str[1]=='d')q--;
			if((p+q)%2==0&&last!=p+q){
				ret++;
				last=p+q;
			}
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1016
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll MOD = 998244353;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if (s.size() % 2) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if ((i%2==0 && s[i]!='h') || (i%2==1 && s[i]!='i')) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main()
{
    int n=0;
    int o=100000;
    
    cin >> n;
    
    for (int i=0; n != i; i++) {
        o = o*1.05;
        o = (o+999)/1000;
        o *= 1000;
    }
    
    cout << o << endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define ll long long
using namespace std;
const int N=1e6+6;
int a[N]; ll s[N],b[N];
int main(){
	int n,k,m=0; scanf("%d%d",&n,&k);
	rep(i,1,n) scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
	rep(i,1,n) rep(j,i,n) b[++m]=s[j]-s[i-1];
    ll ans=0;
    per(j,60,0){
        int cnt=0;
        rep(i,1,m) if (b[i]>>j&1) ++cnt;
        if (cnt>=k){
            ans|=1LL<<j; int t=0;
            rep(i,1,m) if (b[i]>>j&1) b[++t]=b[i];
            m=t;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8448
import java.util.Scanner;

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val num: Int = Integer.parseInt(sc.nextLine())
  var totald: Double = 0.0
  for (i in 1..num) {
    var str: String = sc.next()
    var stc: String = sc.next()
    if (stc == "BTC") {
      totald += str.toDouble() * 380000
    }
    if (stc == "JPY") {
      totald += str.toInt()
    }
  }
  println("${totald}")
}

Measured memory_bytes: 31256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
ll I,O,T,J,L,S,Z,res;
int main(){
	cin>>I>>O>>T>>J>>L>>S>>Z;
	cmax(res,(I-(I&1))+O+(J-(J&1))+(L-(L&1)));
	if(I&&J&&L)--I,--J,--L,cmax(res,(I-(I&1))+O+(J-(J&1))+(L-(L&1))+3),++I,++J,++L;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 384
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	XOR = 0
	for i in range(N):
		XOR = XOR ^ A[i]


	ans = [None] * N
	for i in range(N):
		ans[i] = XOR ^ A[i]

	print(*ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 94076
#include <stdio.h>

int comp(int r);
int main(void){
  int r;
  scanf("%d", &r);
  if(r < 1 || r > 100){
    return 1;
  }
  printf("%d ",comp(r));
  return 0;
}

int comp(int r){
  return r*r;
}

Measured memory_bytes: 128
S = input()
S = S[::-1]
li = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(len(li)):
    li[i] = li[i][::-1]

i = 0
can = True
while i < len(S):
    can2 = False
    # print("i: {}, len(S): {}".format(i, len(S)))
    for j in range(4):
        d = li[j]
        # print("d:{}".format(d))
        # print("len(d): {}".format(len(d)))
        # print("S[i:i+len(d)]: {}".format(S[i:i+len(d)]))
        if S[i:(i+len(d))] == d:
            can2 = True
            i += len(d)
            # print("成功, i:{}".format(i))
            break
        # print("失敗")

    if can2 == False:
        # print("失敗, i:{}".format(i))
        can = False
        break

if can:
    print('YES')
else:
    print('NO')

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

using namespace std;
typedef pair<int,int> P;
const int MAX = 1000001;
const int INF = (1<<20);

vector<int> p;
P ans[MAX];

void init(){

  for(int i = 1; i < MAX; i++)
    ans[i].first = ans[i].second = INF;

}

void make(){
  int n = 0;
  while(1){
    int now = (n*(n+1)*(n+2))/6;
    if(now >= MAX) break;
    p.push_back(now);
    n++;
  }


  for(int i = 1; i < MAX; i++)
    for(int j = 1; j < p.size(); j++){
      if(i-p[j] >= 0){
	if(p[j]%2) ans[i].second = min(ans[i].second,ans[i-p[j]].second+1);
	ans[i].first = min(ans[i].first,ans[i-p[j]].first+1);
      }
    }
}

int main(){
  init();
  make();
  int in;
  while(cin >> in && in) cout << ans[in].first << " " << ans[in].second << endl;
  return 0;
}

Measured memory_bytes: 9028
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s;
    cin>>n>>m;
    rep(i,1,20000){
        if(i*8/100==n&&i/10==m){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
}


Measured memory_bytes: 256
/*
 * ARC098_E.cpp
 *
 *  Created on: May 26, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int bit[200000][20];
int judge[20];

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

	int N;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		REP(b, 20) {
			bit[i][b] = (a>>b)&1;
		}
	}

	lng ans = 0;
	int r = 0;
	REP(i, N) {
		bool flag = true;
		ans += r-i;
		for(;r < N; r++) {
			REP(b, 20) {
				if(judge[b]>0 && bit[r][b]>0) {
					flag = false;
					REP(b2, b) {
						if(bit[r][b2]) judge[b2] = 0;
					}
					break;
				}
				judge[b] += bit[r][b];
			}
			if(!flag) {
				REP(b, 20) {
					if(bit[i][b]) judge[b] = 0;
				}
				break;
			}
			++ans;
		}
	}

	cout << ans << endl;
}






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

using namespace std;

int main ()
{
    int n, m;
    cin >> n >> m;
    vector<bool> v(n, false);
    for (int i = 0; i < m; i++) {
        int a, l;
        cin >> a >> l;
        for (int k = 0; k < l; k++) {
            v[(a + k) % n] = true;
        }
    }

    int s = 0;
    while (s < n && v[s]) {
        s++;
    }


    int count = 0;
    vector<int> res(n + 1, 0);

    if (s < n) {
        for (int i = 0; i <= n; i++) {
            if (v[(i + s) % n]) {
                count++;
            } else {
                if (count > 0) {
                    res[count]++;
                }
                count = 0;
            }
        }
    } else {
        res[n]++;
    }


    for (int i = n; i; i--) {
        if (res[i]) cout << i << " " << res[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 1200
while True:
    H,W = map(int,raw_input().split())
    if H == 0 and W == 0:
        break
    for i in xrange(1,H+1):
        a = [".","#"] if i %2 == 0 else ["#","."]
        b = ""
        for j in xrange(0,W):
            b += a[j%2]
        print b
    print ""

Measured memory_bytes: 4212
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n;
  cin >> n;
  vi p(n);
  rep(i, n) cin >> p[i];

  ll ans = 0;
  for (int i = 1; i < n-1; i++) {
    vector<int> x;
    x.push_back(p[i-1]);
    x.push_back(p[i]);
    x.push_back(p[i+1]);

    sort(all(x));
    if (x[1] == p[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
package main

import "fmt"

func uniqValue(arr []int) []int {
	m := make(map[int]bool)
	var uniq []int

	for _, v := range arr {
		if !m[v] {
			m[v] = true
			uniq = append(uniq, v)
		}
	}
	return uniq
}

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)

	for i:= 0;  i < N; i++ {
		fmt.Scan(&arr[i])
	}

	result := uniqValue(arr)

	fmt.Println(len(result))
}

Measured memory_bytes: 640