akhauriyash/Code-Regression huggingface dataset:
MAX = 5 * (10**5)
MOD = 10**9 + 7

_fact = [1,1] + [0] * MAX
_inv = [0,1] + [0] * MAX
_fact_inv = [1,1] + [0] * MAX
for k in range(2, MAX + 1):
    _fact[k] = _fact[k-1] * k % MOD
    _inv[k] = (-_inv[MOD % k] * (MOD // k)) % MOD
    _fact_inv[k] = _fact_inv[k-1] * _inv[k] % MOD

def P(m, n):
    return _fact[m] * _fact_inv[m-n] % MOD

def C(m, n):
    return _fact[m] * _fact_inv[m-n] * _fact_inv[n] % MOD

def solve(n, m):
    res = 0
    for k in range(n+1):
        sign = 1 - 2 * (k%2)
        cur = sign * C(n, k) * P(m, k) * (P(m-k, n-k) ** 2)
        res = (res + cur) % MOD
    return res

n, m = map(int, input().split())
print(solve(n, m))

Measured memory_bytes: 71960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final String in = br.readLine();
        final int x = Integer.parseInt(in.substring(0, in.indexOf(' ')));
        final int y = Integer.parseInt(in.substring(in.indexOf(' ')+1));
        System.out.println(gcd(x, y));
    }
    private static int gcd(int x, int y){
        while(true){
            x %= y;
            if(x==0)
                return y;
            y %= x;
            if(y==0)
                return x;
        }
    }
}

Measured memory_bytes: 24360
n, x = map(int, input().split())
#print("n:%d" %n)
#print("x:%d" %x)
l = list(map(int, input().split()))
sum = 0
b = 1;
for i in range(n):
	sum = sum + l[i]
	if(sum > x):
		print(b)
		break
	else:
		if(i == n-1):
			print(n+1)
			break
		else:
			b=b+1

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            int n = NextInt;
            var a = LongList;
            var array = Enumerable.Repeat(long.MaxValue >> 2, n + 1).ToArray();
            array[0] = 1;

            for (int i = 0; i < n && array[i] <= long.MaxValue >> 4; i++)
            {
                array[i + 1] = (array[i] - a[i]) * 2;
            }

            if (array.Any(x => x <= 0) || array.Zip(a, (x, y) => x < y).Any(b => b))
            {
                System.Console.WriteLine(-1);
                return;
            }

            array[n] = Math.Min(a[n], array[n]);
            for (int i = n - 1; i >= 0 ; i--)
            {
                array[i] = Math.Min(array[i], array[i + 1] + a[i]);
            }

            // System.Console.WriteLine(string.Join(" ", array));
            System.Console.WriteLine(array.Sum());
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 38340
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N;
    cin >> N;
    ll A[N];
    for(int i = 0; i < N; i++)  cin >> A[i];
    
    ll digit[70];
    for(int i = 0; i < 62; i++) digit[i] = 0;
    
    for(int i = 0; i < N; i++){
        int d = 0;
        while(A[i]){
            if(A[i]%2)  digit[d]++;
            d++;
            A[i] /= 2;
        }
    }
    
    ll ans = 0;
    ll pow2 = 1;
    for(int i = 0; i < 62; i++){
        ans += pow2 * ((digit[i] * (N - digit[i])) % mod) % mod;
        ans %= mod;
        pow2 *= 2;
        pow2 %= mod;
    }
    
    cout << ans << "\n";
    
    return 0;
}


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


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //#ifndef ONLINE_JUDGE
  //freopen("date.in", "r", stdin);
  //freopen("date.out", "w", stdout);
  //#endif //ONLINE_JUDGE

  int n;
  cin >> n;

  int c1 = n % 10;
  int c2 = n % 100 / 10;
  int c3 = n % 1000 / 100;
  int c4 = n / 1000;

  if((c1 == c2 and c2 == c3) || (c2 == c3 and c3 == c4))
    cout << "Yes";
  else
    cout << "No";

  return 0;
}

Measured memory_bytes: 256
from sys import stdin

def main():

    input = stdin.readline

    N = int(input())

    ans_sum = 0
    for i in range(1,N+1):
        if (i % 5 == 0) | (i % 3 == 0):
            pass
        else:
            ans_sum += i

    print(ans_sum)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9180
n = int(input())
aList = [int(x) for x in input().split(" ")]

minNum = 0

for x in range(0, len(aList)):
	minNum += 1 if aList[x] < 0 else 0
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)


even = minNum%2==0

if even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))


Measured memory_bytes: 14260
#include<iostream>
#include<string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
	int N;
	cin >> N;
	int i;
	vector<long long> minus;
	long long abs_min = 100000000;
	long long ans = 0;
	for (i = 0; i < N; i++) {
		long long a;
		cin >> a;
		abs_min = min(abs_min, abs(a));
		if (a < 0) {
			minus.push_back(a);
			ans -= a;
		}
		else {
			ans += a;
		}
	}
	sort(minus.begin(), minus.end());
	reverse(minus.begin(), minus.end());
	if (minus.size() % 2 == 0) {
		cout << ans;
	}
	else {
		cout << ans - abs_min * 2;
	}
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
using namespace std;
 
vector<int> findMin(const vector<int> &a) {
    stack<pair<int, int> > ST;
    vector<int> ans;
    ST.push(make_pair(-1, -1));
    for (int i = 0; i < (int)a.size(); ++i) {
        while (ST.top().first > a[i])
            ST.pop();
        ans.push_back(ST.top().second);
        ST.push(make_pair(a[i], i));
    }
    return ans;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    vector<int> ls = findMin(a);
    reverse(a.begin(), a.end());
    vector<int> rs = findMin(a);
    reverse(a.begin(), a.end());
    reverse(rs.begin(), rs.end());
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        ans += (long long)((n-1-rs[i]) - i) * (long long)(i - ls[i]) * a[i];
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm> 

using namespace std;

int triangles(int n, int l[]) {
  vector<int> edges;
  for(int i = 0; i<n;i++) {
    edges.push_back(l[i]);
  }
  sort(edges.begin(), edges.end());
  int ans = 0;
  for(int i = edges.size() - 1; i > 0; i--) {
    for(int j = i - 1; j >= 0; j--) {
      // precondition: a>=b>=c;
      int a = edges.at(i);
      int b = edges.at(j);
      vector<int>::iterator c_iter = upper_bound(edges.begin(), edges.end(), a - b);
      int index_c = c_iter - edges.begin();
      if(index_c >= j) {
	continue;
      }
      ans += j - index_c;
    }
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  int l[n];
  for(int i= 0;i<n;i++) {
    cin >> l[i];
  }
  cout << triangles(n, l);
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define getsize(x) ((long long)(x).size())
#define srt(x) sort((x).begin(), (x).end())
#define rsrt(x) sort((x).rbegin(), (x).rend())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
template<class T>void print(T x) { cout << '\n' << "== " << x << " ==" << '\n'; }
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>void precise(T x) { cout << setprecision(21) << x << '\n'; }
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long double doublepi = M_PI * 2.0;
const long double halfpi = M_PI / 2.0;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long MOD = 1e9 + 7;

int main()
{
    ll N, K;
    cin >> N >> K;
    vll nums(N+1);
    rep(i, 0, N+1) {
        nums[i] = i;
    }
    vll acc(N+2, 0);
    rep(i, 0, N+1) {
        acc[i+1] = (acc[i] + nums[i]) % MOD;
    }

    ll sm = 0;
    rep(i, K, N+2) {
        ll left = (acc[i] - acc[0]) % MOD;
        ll right = (acc[N+1] - acc[N+1-i]) % MOD;
        if (right < 0) right += MOD;
        ll ans = (right - left + 1) % MOD;
        if (ans < 0) ans += MOD;
        sm = (sm + ans) % MOD;
    }
    cout << sm << endl;
}



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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	if (s.size()<2) {
		cout << -1 << " " << -1 << "\n";
		return 0;
	}
	if (s.size()==2) {
		if (s[0]==s[1]) {
			cout << 1 << " " << 2 << "\n";
			return 0;
		} else {
			cout << -1 << " " << -1 << "\n";
			return 0;
		}
	}
	for (int i = 0; i < s.size()-3; i++) {
		if (s[i]==s[i+2]) {
			cout << i+1 << " " << i+2+1 << endl;
			return 0;
		}
		if (s[i]==s[i+1]) {
			cout << i+1 << " " << i+2+1 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << "\n";

}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

uintmax_t combination(unsigned int n, unsigned int r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

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

	ll  d, n, r ,l ,k, ans = 0, ret = M;
	bool flag = false, flag2 = false;
	string s, t;
	cin >> n;
	vP rec;
	ans += !(n % 2);
	REP(i, 1, n + 1) {
		REP(j, i + 1, n + 1) {
			if(i + j != n+ans) rec.pb(P(i, j));
		}
	}
	cout << rec.size() << endl;
	for (auto p : rec) {
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}


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

int main()
{
long long int x[53],n,i,p;
char c;

for(i=1;i<=52;i++)
{
x[i]=0;

}

cin>>n;




for(i=1;i<=n;i++)
{

cin>>c;

cin>>p;
if(c=='S')
    x[p]=1;
else if(c=='H')
    x[p+13]=1;
else if(c=='C')
    x[p+26]=1;
else if(c=='D')
    x[p+39]=1;


}

for(i=1;i<=13;i++)
{
   if(x[i]==0)
        cout<<"S"<<" "<<i<<endl;

}

for(i=14;i<=26;i++)
{
   if(x[i]==0)
        cout<<"H"<<" "<<i-13<<endl;

}

for(i=27;i<=39;i++)
{
   if(x[i]==0)
        cout<<"C"<<" "<<i-26<<endl;

}

for(i=40;i<=52;i++)
{
   if(x[i]==0)
        cout<<"D"<<" "<<i-39<<endl;

}


}









Measured memory_bytes: 3096
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
#define ALL_STR(a) (a).cbegin(), (a).cend()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}


int main(void){
  ll N, A, B, W, H, C, D, Q, X, Y;
  string S, T, A_S, B_S;
  cin >> A >> B;
  cin >> S;
  string S_A = S.substr(0, A), S_B = S.substr(A+1, B);
  //cout << S_A << endl;
  //cout << S_B << endl;
  
  if (!all_of(ALL_STR(S_A), ::isdigit)){
    cout <<"No" << endl;
    return 0;
  }
 
  if (S[A] != '-') {
    cout <<"No" << endl;
    return 0;
  }
  if (!all_of(ALL_STR(S_B), ::isdigit)){
     cout <<"No" << endl;
     return 0;
  }
  cout <<"Yes" << endl;
  return 0;
  

}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a = IR(2)
    n %= 500
    if a >= n:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152
#include <stdio.h>

#define DATA 3000

int main(void)
{
	int x[DATA], y[DATA];
	int i;

	for(i = 0;i < DATA;i++)
	{
		scanf("%d %d", &x[i], &y[i]);
		if((x[i] == 0) && (y[i] == 0))
			break;
	}
	for(i = 0;(x[i] != 0) || (y[i] != 0);i++)
	{
		if(x[i] < y[i])
			printf("%d %d\n", x[i], y[i]);
		else
			printf("%d %d\n", y[i], x[i]);
	}

	return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	FOR(i, 0, n) cin >> a[i];
	sort(ALL(a));
	cout << a[n / 2] - a[n / 2 - 1];
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 640
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(defparameter *hash-memo* (make-hash-table :test #'equal))

(defmacro dp (&body func)
  `(let* ((f (quote func))
          (num (gethash f *hash-memo*)))
     (if num
       num
       (setf (gethash f *hash-memo*) ,func))))

(let ((n (read)))
  (princ (if (= n (length (remove-duplicates (loop repeat n collect (read))))) "YES" "NO")))


Measured memory_bytes: 62524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;


ll sol(ll a){
    ll i;
    if(a==0) return 0;
    if(a==1) return 1;
    if(a==2) return 3;


    a++;
    ll c=0;
    for(i=0;i<45;i++){
        if((a>>i)&1) c++;
    }
    if(c==1) return 0;

    
    vector<ll> v(45);

    if(a%4==2||a%4==3) v[0]=1;

    for(i=1;i<45;i++){
        if((a>>i)&1 && a%2==1){
            v[i]=1;
        }
    }
    ll s=0;
    for(i=0;i<45;i++){
        if(v[i]==1) s+=(ll)pow(2,i);
    }
    return s;
}

int main(){
    ll i,j;
    ll a,s;
    cin>>a>>s;
    ll p=sol(a-1);
    ll q=sol(s);
    ll r=p^q;
    cout<<r<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<ll> a(n);rep(i,n){cin>>a[i];}
#define repins(a,n) vector<string> a(n);rep(i,n){cin>>a[i];}
#define repind(a,n) vector<double> a(n);rep(i,n){cin>>a[i];}
#define in(a) ll a;cin>>a;
#define ins(a) string a;cin>>a;
#define ind(a) double a;cin>>a;
template<class T>
inline void out(T a){cout<<a<<endl; }
inline void out(double a){ printf("%.10f\n", a);} 
#define all(x) (x).begin(),(x).end()
#define rep2(i,a,b) for(ll i=(a);i<(b);++i)
#define range(i,s,c) for(ll i=(s);i<(s+c);++i)
using vell = vector<ll>;
using ves = vector<string>;
using ved = vector<double>;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main()
{
	in(n);
	unordered_map<ll,ll> m;
	rep(i,n){
		in(a);
		if(m.count(a)>=1){
			out("NO");
			return 0;
		}else{
			m[a] = 0;
		}
	}
	out("YES");
}

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

int main()
{
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    bool flag = false;

    while (1) {
        if (a % k == 0) {
            flag = true;
            break;
        }
        else {
            a = a + 1;    
        }
        if (a > b) {
            flag = false;
            break;
        }
    }

    if (flag) 
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
      
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdio>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 200007;
const int M = 15005;
const int offset = 7500;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double eps = 1e-20;
int n,m;
int main()
{
    while (~scanf("%d",&n))
    {
        int ans=1;
        while ((ans<<1)<=n)
            ans<<=1;
        printf("%d\n", ans);
    }
    return 0;
}

/*


*/

Measured memory_bytes: 256
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
      
a = int(input())
print(num2alpha(a).lower())

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

int main() {
    string s;
    cin>>s;
    rep(i,s.length()){
        if(i%2!=0 && s[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
        if(i%2==0 && s[i]=='L'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main()
{
  int S[10000],num,num2,i,j,count=0,t,match[10];


  scanf("%d",&num);
  for(i=0;i<num;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&num2);
  for(i=0;i<num2;i++)
    {
      scanf("%d",&t);
      for(j=0;j<num;j++)
	{
	  if(S[j]==t)
	    {
	      count++;
	      break;
	    }
	}
      
    }
  printf("%d\n",count);
  
 
  return 0;
}














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

int main() {

  long long int w, h, x, y;
  cin >> w >> h >> x >> y;

  if ( x * 2 == w && y * 2 == h ) {
    cout << fixed << setprecision(2) << 0.50L * w * h << " " << 1 << endl;
  } else {
    cout << fixed << setprecision(2) << 0.50L * w * h << " " << 0 << endl;
  }

  return 0;

}


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

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    vector<pair<int,int> >v(m);
    for(int i=0;i<m;i++) scanf("%d %d",&v[i].second,&v[i].first);
    sort(v.begin(),v.end());
    int ans=0,prev=-1;
    for(int i=0;i<m;i++){
        if(v[i].second>prev){
            ans++;
            prev=v[i].first-1;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> v(N);
    vector<int> c(N);
    vector<int> s(N);
    int X = 0;
    if(N==1){
        cout<<0<<endl;
    }else{
    for(int i = 0;i<N;i++){
       cin >> v.at(i);
    }
    for(int i = 0;i<N;i++){
       cin >> c.at(i);
    }
     for (int i = 0; i < N; i++) {
         s.at(i) = v.at(i) - c.at(i);
  }
        sort(s.begin(), s.end());
        reverse(s.begin(), s.end());
        for(int i=0;i<N;i++){
            if(s.at(i)<0){
                s.at(i)=0;
            }
            X += s.at(i);
        }
        cout<<X<<endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
int h[N];
vector<int> g[N];
int main(void){
    IOS;
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; ++i){
        cin >> h[i];
    }
    for (int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i){
        bool flag = true;
        for (int j = 0; j < g[i].size(); ++j){
            int v = g[i][j];
            if (h[i] <= h[v]){
                flag = false; break;
            }
        }
        if (flag) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 9172
#include <stdio.h>

int main(int argc, const char * argv[])
{
    
    int month, day, i;
    int monthdata[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    while (1) {
     scanf("%d %d", &month, &day);
        if (month == 0 || day == 0) {
            break;
        } else {
            
            for (i = 1; i <= month; i++) {
                day += monthdata[i - 1];
            }
            
            switch (day % 7) {
                case 1:
                    printf("Thursday\n");
                    break;
                case 2:
                    printf("Friday\n");
                    break;
                case 3:
                    printf("Saturday\n");
                    break;
                case 4:
                    printf("Sunday\n");
                    break;
                case 5:
                    printf("Monday\n");
                    break;
                case 6:
                    printf("Tuesday\n");
                    break;
                default:
                    printf("Wednesday\n");
                    break;
            }
            
        }
    }
    
    return 0;
}

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

using namespace std;

int main(){
  int a,b,c,n, m, r, R[9], d[210][210],I=100000000;
  cin >> n >> m >> r;
  for(int i=0;i<r;i++){
    cin >> R[i];
  }
  for (int i = 1; i <= n; i++){
    for (int j = i + 1; j <= n; j++){
      d[i][j] = d[j][i] = I; //無限大
    }
  }
  for(int i = 0; i < m; i++){
    		cin >> a >> b >> c;
		if (d[a][b] > c)d[a][b] = d[b][a] = c;
  }
  
  for (int k = 1; k <= n; k++){
    for (int i = 1; i <= n; i++){
      for (int j = 1; j <= n; j++){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);  //ワーシャルフロイド
      }
    }
  }
  
  sort(R,R+r); //next_permutation使うため
  int re = I;
  do {
		int s = 0;
		for (int i = 0; i < r - 1; i++){
          s += d[R[i]][R[i + 1]];
        }
		re = min(re, s);
	} while (next_permutation(R, R + r)); //Rの組み合わせ全てに対して判断
  
  cout << re << endl;
  
  return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

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

	for (int i = 0; i < h; i++)
	{
		string s;
		cin >> s;

		cout << s << endl;
		cout << s << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=300005;
int n,q[maxn],t,ans=1<<30;
char s[maxn];
int main()
{
    cin>>n;
    scanf("%s",s+1);
    for(int i=1;i<=n;i++) q[i]=q[i-1]+(s[i]=='E');
    t=q[n];
    for(int i=1;i<=n;i++) ans=min(ans,(i-1-q[i-1])+(t-q[i]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.close();
		int b = a%1000;
		if (b==0) b = 1000;
		System.out.println(1000-b);
	}
}


Measured memory_bytes: 27044
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;

int main(void){

	char S[100] = {0};
	scanf( "%s", S );
	char T[100] = {0};
	scanf( "%s", T );
	char ans[2] = {0};

	char cmpS[100] = {0};

	int sLen = strlen(S);
	int i;

	for( i = 0; i < sLen ; i++ ){
		memset( cmpS, '\0', sizeof(cmpS));
		ans[0] = S[sLen-1];
		S[sLen-1] = '\0';
		strcat( cmpS, ans );
		strcat( cmpS, S );
		if( strcmp( T, cmpS) == 0 ){
			printf( "Yes");
			break;
		}
		memmove( S, cmpS, sizeof(S) );
	}
	if( i == sLen ){
		printf( "No" );
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int snk(int);
int main(void){
  int N,A,sum=1000;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&A);
    if(snk(A)<sum){
      sum=snk(A);
    }
  }
  if(sum!=1000){
    printf("%d\n",sum);
  }else{
    printf("0\n");
  }
  return 0;
}
int snk(int X){
  int j=0;
  while(1){
    if(X%2==0){
      X/=2;
      j++;
    }else{
      break;
    }
  }
  return j;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main{
    static Scanner scan=new Scanner(System.in);
    public static void main(String args[]){
        long n=scan.nextLong();
        long m=scan.nextLong();

        long x=n*2+m;
        if(n<m)System.out.println(x/4);
        else System.out.println(m/2);
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,count1=0,count2=0,c=0;
  string s,a;
  cin >> n;
  for(int i=0; i<n; i++){
	cin >> s;
	if(i==0) if(s == "Un") {
	  count1 = 100;
	  break;
	}
	if(s == "A") {
	  count1++;
	  a = s; c++;
	}
	if(s == "Un" && a == "A"){
	  count2++;
	  c--;
	  if(c<0) break;
	}
  }
  if(count1 == count2) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}
	




Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	cin >> n >> k;
	vector<ll> h(n);
	FOR(i,0,n)cin>>h[i];
	SORT(h);
	ll ans = INF;
	FOR(i,0,n-k+1){
		ans = min(ans,h[i+k-1]-h[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A==1)A=14;
		if(B==1)B=14;
		if(A==B)System.out.println("Draw");
		if(A>B)System.out.println("Alice");
		if(B>A)System.out.println("Bob");
	}
}

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

const int N = 100010;
vector<pair<int, int>> G[N]; // {vertex, cost}
vector<int> Color(N);

int n;

void dfs(int now, int pre){
    for(int i = 0; i < G[now].size(); i++){
        int to = G[now][i].first;
        if(to == pre) continue;

        int cost = G[now][i].second;
        if(cost == 0){
            Color[to] = Color[now];
        }else{
            Color[to] = Color[now] ^ 1;
        }
        dfs(to, now);
    }
}

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

    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, w % 2});
        G[v].push_back({u, w % 2});
    }

    dfs(0, -1);

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

    return 0;
}

Measured memory_bytes: 9216
/**
 *      purpose : NIKKEI Programming Contest 2019
 *      author  : kyomukyomupurin
 *      created : 
**/

// in, out
#include <iostream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias templates
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    string a, b, c; cin >> a >> b >> c;

    int cnt = 0;

    rep(i, n){
        if (a[i] == b[i] && b[i] == c[i]) continue;
        else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ++cnt;
        else cnt += 2;
    }
    print(cnt);
    
    return 0;
}

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

using ll = long long;
int h, w, k;
char s[12][10010];



int main () {
  scanf("%d %d %d", &h, &w, &k);
  for(int i = 0; i < h; i++) 
    scanf(" %s", s[i]);

  int ans = h * w;
  for(int mask = 0; mask < (1 << (h + 1)); mask+=2) {
    int cnt[12] = {0}, here = 0, ok = 1;
    for(int j = 0; j < w; j++) {
      int p = 0;
      int add[12] = {0};
      for(int i = 0; i < h; i++) {
        if(i && (mask >> i & 1)) p++;
        add[p] += s[i][j] - '0';
      }
      bool split = false;
      for(int i = 0; i <= p; i++) 
        if(cnt[i] + add[i] > k) 
          split = true;
      if(split) {
        here++;
        for(int i = 0; i <= p; i++) 
          cnt[i] = add[i];
      } else {
        for(int i = 0; i <= p; i++)
          cnt[i] += add[i];
      }
      for(int i = 0; i <= p; i++) 
        if(cnt[i] > k) {
          ok = 0;
          break;
        }
      if(!ok) break;
    }
    if(ok) ans = min(ans, here + __builtin_popcount(mask));
  } printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  out(c/a*b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
  int n,x,y;
  cin >> n >> x >> y;
  x--; y--;
  vector<int> xd(n);
  vector<int> yd(n);
  for(int i=0; i<x; i++){
    xd[i] = x-i;
    yd[i] = x-i+1;
  }
  for(int i=x; i<y; i++){
    xd[i] = min(i-x, y-i+1);
    yd[i] = min(i-x+1, y-i);
  }
  for(int i=y; i<n; i++){
    xd[i] = i-y+1;
    yd[i] = i-y;
  }
  vector<int> ans(n,0);
  rep(i,n){
    for(int j=i+1; j<n; j++){
      int dis = min({j-i, xd[i] + xd[j], yd[i] + yd[j]});
      ans[dis]++;
    }
  }
  rep(i,n-1) cout << ans[i+1] << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    int n=readI();
    int a[]=new int[100001];
    long sum=0;
    for(int i=0;i<n;i++){
      int k=readI();
      a[k]++;
      sum+=k;
    }
    int q=readI();
    for(int ii=0;ii<q;ii++){
      int b=readI(),c=readI();
      if(a[b]!=0){
        sum+=(c-b)*a[b];
        a[c]+=a[b];a[b]=0;
      }
      pl(sum+"");
    }
  }
  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static int readI(){
    return stoi(readS());
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
}


Measured memory_bytes: 57664
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")
    };
}

use std::collections::HashSet;

fn main() {
    input! {
        N: i32,
        XYH: [(i32, i32, i32); N],
    }
    for cx in 0..101 {
        for cy in 0..101 {
            let mut values = HashSet::new();
            let mut ok = true;
            for &(x, y, h) in &XYH {
                if h == 0 {
                    continue;
                }
                let rest = -(x - cx).abs() - (y - cy).abs();
                let H = h - rest;
                if H >= 1 {
                    values.insert(H);
                } else {
                    ok = false;
                }
            }
            if ok && values.len() == 1 {
                for value in &values {
                    for &(x, y, h) in &XYH {
                        if h == 0 {
                            let H = value - (x - cx).abs() - (y - cy).abs();
                            if !(H < 0 || H == 0) {
                                ok = false;
                            }
                        }
                    }
                    if ok {
                        println!("{} {} {}", cx, cy, value);
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
using namespace std;

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

		int x, ice[10] = {0};
		for(int i=0;i<n;i++){
			cin>>x;
			ice[x]++;
		}

		for(int i=0;i<10;i++){
			if(ice[i]==0){
				cout<<"-"<<endl;
			} else {
				for(int j=0;j<ice[i];j++) cout<<"*";
				cout<<endl;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 1152
#ABC054C
from itertools import permutations

n,m=map(int,raw_input().split())
r=set()
s=set()
for i in xrange(m):
 u,v=map(int,raw_input().split())
 u-=1
 v-=1
 r.add(u)
 r.add(v)
 s.add((u,v))
 s.add((v,u))

res=0
l=list(permutations(r))
for t in l:
 if t[0]!=0:
  continue
 if all((t[i],t[i+1]) in s for i in xrange(n-1)):
  res+=1
   
print res


Measured memory_bytes: 7924
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


int main()
{
	int n;
	cin >> n;
	if (n % 1000 == 0)cout << 0 << endl;
	else cout << 1000 - n % 1000 << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <map>
using namespace std;
map<int,int> m;

int main()
{
	int n,a;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		m[a]=i;
	}
	map<int,int>::iterator it;
	for(it=m.begin();it!=m.end();it++) cout<<it->second<<" ";
	return 0;
}

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

int main()
{
ll a , b , c ;
cin >> a >> b >> c ;
if(a+b+c>=22)ans="bust";
else ans="win";
cout << ans << endl;
return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,i,j,min=(ll)1e9,min2;
  cin>>n;
  vector<ll> a(n),l(n),r(n),b(n);
  for(i=0;i<n;i++){
	cin>>a[i];
  }
  l[0]=a[0];
  for(i=0;i<n;i++){
    if(i!=0){
     l[i]=gcd(l[i-1],a[i]);
    }
  }
  r[n-1]=a[n-1];
  for(i=n-2;i>=0;i--){
     r[i]=gcd(r[i+1],a[i]);
  }
  b[0]=r[1];
  b[n-1]=l[n-2];
  for(i=1;i<n-1;i++){
	b[i]=gcd(l[i-1],r[i+1]);
  }
  sort(b.begin(),b.end());
  cout<<b[n-1]<<endl;
}
  

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,k;
	cin >> n >> k;
	
	vector<ll> a(n) , rui(n+1) , prui(n+1);
	rui[0] = 0;
	rep(i,0,n){
		cin >> a[i];
		rui[i+1] = a[i] + rui[i];
		prui[i+1] = max(a[i],(ll)0) + prui[i];
	}

	
	ll ans = INF * -1;
	rep(i,0,n-k+1){
		ll w = rui[i+k] - rui[i];
		//cout << i << " " << prui[i] << " " << prui[n]-prui[i+k] << " " << w << endl;
		ll sum = prui[i] + ( prui[n] - prui[i+k] ) + max(w,(ll)0);
		ans = max( ans , sum );
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>	
#include <string>	
#include <vector>	
#include <queue>	
#include <deque>	
#include <stack>	
#include <set>	
#include <map>	
#include <unordered_map>	
#include <unordered_set>	
#include <cstring>	
#include <cmath>	
#include <cstdlib>	
#include <algorithm>	
#include <random>	
#include <iomanip>	
#include <functional>	
#include <cassert>	
 	
typedef long long ll;

using namespace std;	
 
const int K = 51;

int go[K][K];

int main() {	
  ios_base::sync_with_stdio(false); cin.tie(0);	
#ifdef LOCAL	
  freopen("input.txt", "r", stdin);	
#endif	
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector <int> b(n);
  for (int i = 0; i < n; ++i) cin >> b[i];
  auto can = [&] (ll mask) {
    for (int i = 0; i < K; ++i) {
      for (int j = 0; j < K; ++j) {
        go[i][j] = 0;
      }
    }
    for (int i = 0; i < K; ++i) {
      go[i][i] = 1;
      for (int j = 1; j < K; ++j) {
        if (!(mask & (1LL << j))) continue;
        for (int k = 0; k < K; ++k) {
          go[i][k] |= go[i % j][k];
        }
      }
    }
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      ok &= go[a[i]][b[i]];
    }
    return ok;
  };
  if (!can((1LL << 51) - 1)) {
    cout << "-1\n";
    return 0;
  }
  ll ans = 0;
  for (int i = 50; i >= 1; --i) {
    if (can(ans | ((1LL << i) - 1)));
    else ans |= (1LL << i);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256