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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 1e5+50;
const int M = 1e6;
const ll oo = 1e18;
const int mod = 1e9+7;

ll dp[N];
ll w[110],v[110];

int main(){
	int n,W;
	cin>>n>>W;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	int ans = 0;
	for(int j=1;j<N;j++)dp[j] = 1e18;
	for(int i=1;i<=n;i++){
		for(int j=N-1;j>=0;j--){
			if(v[i] > j)continue;
			dp[j] = min(dp[j],dp[j-v[i]] + w[i]);
			if(dp[j] <= W)ans = max(ans,j);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long a[100001],b[100001],c[100001];
int main(){
	long long n,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		cin>>b[i];
	}
	for(i=0;i<n;i++){
		cin>>c[i];
	}
	sort(a,a+n);
	sort(c,c+n);
	long long ans=0;
	for(i=0;i<n;i++){
		long long j=lower_bound(a,a+n,b[i])-a;
		long long k=upper_bound(c,c+n,b[i])-c;
		ans+=j*(n-k);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2688
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    auto S = sread();
    long ans = long.max;
    bool[char] d;
    foreach (c; S)
        d[c] = true;
    if (d.keys.length == 1)
    {
        writeln(0);
        return;
    }
    foreach (c; d.keys)
    {
        ans = ans.min(solve(S, c));
    }
    writeln(ans);
}

long solve(string S, char c)
{
    bool flag = true;
    string newS = "";
    foreach (i; 0 .. S.length - 1)
    {
        if (S[i] == c || S[i + 1] == c)
            newS ~= c;
        else
        {
            newS ~= S[i];
            flag = false;
        }
    }
    if (flag)
    {
        return 1;
    }
    else
    {
        return 1 + solve(newS, c);
    }
}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
 
#define INF 1000000000;
 
int N;
int64_t A[100000];
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++)    cin >> A[i];
 
    int64_t ansA = 0;
    int maxIndex;
    for(int i=0;i<N;i++){
        if( ansA < A[i] ){
            ansA = A[i];
            maxIndex = i;
        }
    }
 
    int64_t mini = INF;
    int64_t ansB;
    for(int i=0;i<N;i++){
        if( i != maxIndex && abs( ansA / 2 - abs( ansA - A[i] ) ) < mini ){
            mini = abs( ansA / 2 - abs( ansA - A[i] ) );
            ansB = A[i];
        }
    }
 
    cout << ansA << " " << ansB << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int n;
    cin>>n;
    ll a[5]={};
    rep(i,n){
        string s;
        cin>>s;
        if(s[0]=='M')   a[0]++;
        if(s[0]=='A')   a[1]++;
        if(s[0]=='R')   a[2]++;
        if(s[0]=='C')   a[3]++;
        if(s[0]=='H')   a[4]++;
    }
    ll ans=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans+=(a[i]*a[j]*a[k]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2019
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 2019;
int modPow(long long a, long long n) {
    if(n==0) return 1;
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  long long t = modPow(a, n / 2);
  return (t * t) % MOD;
}
int main(){
    string s;
    cin>>s;
    vector<int>sum(SZ(s)+1);
    map<int,int>m;
    for(int i=SZ(s);i>=1;i--){
        sum[i-1]=(sum[i]+(s[i-1]-'0')*modPow(10,SZ(s)-i))%MOD;
        m[sum[i-1]]++;
    }
    m[0]++;
    ll ans=0;
    for(auto p:m){
        ans+=p.second*(p.second-1)/2;
    }
    OUT(ans);
    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    vec_int x(N),y(N);
    rep(i,N)cin>>x.at(i)>>y.at(i);

    int max = -pow(10,9)*2;
    int min = pow(10,9)*2;
    int max2 = -pow(10,9)*2;
    int min2 = pow(10,9)*2;

    for(int i=0;i<N;i++){
        int sum  = x.at(i) + y.at(i);
        int diff= y.at(i) - x.at(i);
        if(sum<min)min=sum;
        if(sum>max) max=sum;

        if(diff<min2)min2=diff;
        if(diff>max2) max2=diff;


    }
    int answer = max-min;
    if (answer<max2-min2)answer=max2-min2;

    cout<<answer<<endl;



    return 0;
}

Measured memory_bytes: 6380
#include <cstdio>
#include <utility>
#include <cstdlib>
#include <cmath>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

unsigned long powm(int b, int n, int m) {
	if (n == 0)
		return 1;
	else if (n == 1)
		return b % m;
	unsigned long t = powm(b, n / 2, m);
	return t * t % m * (n % 2 ? b : 1) % m;
}


bool fermat(int n) {
	for (int i = 0; i < log(n) * 3; i++) {
		int r = rand();
		if (r % n && powm(r, n - 1, n) != 1)
			return false;
	}
	return true;
}

bool is_prime(int n) {
	return fermat(n);
}

int main() {
	for (int n; scan(n);) {
		for (int i = n - 1;; i--)
			if(is_prime(i)) {
				out(i, ' ');
				break;
			}
		for (int i = n + 1;; i++)
			if(is_prime(i)) {
				out(i, '\n');
				break;
			}
	}
}


Measured memory_bytes: 2756
unittest
{
	assert( [ "4 9 2 3" ].parse.expand.solve == 2 );
	assert( [ "10 40 6 8" ].parse.expand.solve == 23 );
	assert( [ "314159265358979323 846264338327950288 419716939 937510582" ].parse.expand.solve == 532105071133627368 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abcd = input.front.split.to!( long[] );
	return tuple( abcd[ 0 ], abcd[ 1 ], abcd[ 2 ], abcd[ 3 ] );
}

auto solve( long a, long b, long c, long d )
{
	// 1 以上 a 未満で c と d で割り切れるものの個数を計算
	auto ac = ( a - 1 ) / c;
	auto ad = ( a - 1 ) / d;
	auto acd = ac + ad - ( ( a - 1 ) / lcm( c, d ) );
	
	// 1 以上 b 以下で c と d で割り切れるものの個数を計算
	auto bc = b / c;
	auto bd = b / d;
	auto bcd = bc + bd - ( b / lcm( c, d ) );
	
	// a 以上 b 以下で c と d で割り切れないものの個数を計算
	return ( b + 1 - a ) - ( bcd - acd );
}

// 最小公倍数
auto lcm( long x, long y )
{
	import std.numeric : gcd;
	return x * y / x.gcd( y );
}


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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll a, b;
  cin >> a >> b;

  if(a== b) {
    cout << a*2 << endl;
  } else {
    cout << max(a, b)*2-1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf =1 << 30;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int h, w; cin >> h >> w;
    vector<string> field(h);
    for(auto& e : field) cin >> e;

    int sx, sy;
    rep(y, h){
        rep(x, w){
            char c = field[y][x];
            if(c == '%'){
                sx = x, sy = y;
            }
        }
    }

    using Elem = tuple<int, int>;
    queue<Elem> q;
    q.push(Elem(sx, sy));
    vector<vi> min_dist(h, vi(w, inf));
    min_dist[sy][sx] = 0;
    int pd = inf, sd = inf;
    while(q.size()){
        Elem cur = q.front(); q.pop();
        int x, y; tie(x, y) = cur;

        if(field[y][x] == '$'){
            chmin(sd, min_dist[y][x]);
        }
        if(field[y][x] == '@'){
            chmin(pd, min_dist[y][x]);
        }

        rep(i, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 or w <= nx or ny < 0 or h <= ny or field[ny][nx] == '#') continue;

            if(chmin(min_dist[ny][nx], min_dist[y][x] + 1)){
                q.push(Elem(nx, ny));
            }
        }
    }

    cout << (pd < sd ? "Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

struct a {
	int num;
	bool goal, now;
};

a t[18];
int N, A[18][2], res, v[18];
bool b[18];


int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i][1];
	}
	for (int i = 0; i < N; i++) {
		cin >> A[i][0];
	}
	res = 0xE869120;
	for (int i = 0; i < (1 << N); i++) {
		int c = 0;
		for (int j = 0; j < N; j++) {
			c += (i >> j) & 1;
			t[j].goal = (i >> j) & 1;
			t[j].now = 1;
			v[j] = t[j].num = A[j][(i >> j) & 1];
			b[j] = false;
		}
		if ((c & 1) != (N & 1))continue;
		sort(v, v + N);
		int cnt = 0;
		bool f = false;
		for (int j = 0; j < N; j++) {
			for (int k = j; k <= N; k++) {
				if (k == N) {
					f = true;
					break;
				}
				if (t[k].num == v[j] && (((k - j) & 1) ^ t[k].now^t[k].goal^1)) {
					for (int l = k - 1; l >= j; l--) {
						t[l + 1].num = t[l].num;
						t[l + 1].goal = t[l].goal;
						t[l + 1].now = (t[l].now ^ 1);
						cnt++;
					}
					break;
				}
			}
			if (f)break;
		}
		if (f)continue;
		res = min(cnt, res);
	}
	if (res == 0xE869120)res = -1;
	cout << res << endl;
}

Measured memory_bytes: 256
argN,argM = list(map(int,input().split()))

aryL = [0] * argM
aryR = [0] * argM

for i in range(argM):
  argL,argR = list(map(int,input().split()))
  aryL[i] = argL
  aryR[i] = argR

maxL = max(aryL)
minR = min(aryR)
print(str(max(minR - maxL + 1,0)))

Measured memory_bytes: 11008
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s[]={"Sunny", "Cloudy", "Rainy"};
        String ip=in.nextLine();
        if(s[0].contains(ip)){
            System.out.println(s[1]);
        }
        else if(s[1].contains(ip)){
            System.out.println(s[2]);
        }else{
            System.out.println(s[0]);
        }
    }
}

Measured memory_bytes: 20692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
	string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
    s[i] = (s[i]-'A'+n)%26+'A';
    }
    cout << s << endl;
    return 0;
  } 

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


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e16;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
	int s, w;
	cin >> s >> w;
	cout << (w >= s ? "unsafe" : "safe");
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	//srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	vector<char> S;
	for (int i = 0; i < N; i++) {
		char buff;
		cin >> buff;
		S.push_back(buff);
	}
	int qual = 0;
	int forqual = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'c') {
			cout << "No" << endl;
		}
		else if (S[i] == 'a') {
			if (qual < A + B) {
				cout << "Yes" << endl;
				qual++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (S[i] == 'b') {
			if (qual < A + B && forqual < B) {
				cout << "Yes" << endl;
				qual++;
				forqual++;
			}
			else {
				cout << "No" << endl;
			}
		}
	}
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > (sum - 1) / (4 * m))
            c++;
    }
    if (c >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
ans = 0
d = {}
for i in range(1,n+1):
    t = str(i)
    key = t[0]+t[-1]
    if "0" not in key:
        d[key] = d.get(key,0) + 1

for k in d:
    k2 = k[1]+k[0]
    ans += d[k]*d.get(k2,0)

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  string a;
  int flag = 0,co=-1;
  cin >> a;
  if(a.at(0)!='A') flag = 1;
  for(int i = 1;i<a.size();i++){
    if(a.at(i)=='C') {
      if(co!=-1)flag = 1;
      if(i<2||i==a.size()-1)flag=1;
      co = i;
    }
    else if(a.at(i)<'a') flag = 1;
  }
  if(co==-1)flag = 1;
  if(flag) cout << "WA";
  else cout << "AC";
}


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

int main(){
    while(1){
        char a;
        cin.get(a);
        if(a=='\n'){
            cout<<endl;
            break;
        }
        if(islower(a)) {
            cout<<(char)toupper(a);
        }else if(isupper(a)) {
            cout<<(char)tolower(a);
        }else {
            cout<<a;
        }
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, W;
    cin >> H >> W;
    int d[10][10];
    rep(i, 10) rep(j, 10){
        int c;
        cin >> c;
        d[i][j] = c;
        if(i == j) d[i][j] = 0;
    }
    rep(i, 10){
        rep(j, 10){
            rep(k, 10){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
    int ans = 0;
    rep(i, H){
        rep(j, W){
            int a;
            cin >> a;
            if(a == -1) continue;
            ans += d[a][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans=0;
    for(ll i=0;i<=min(3*a,n);i++){
        ll tmp=(a*i)/b-a*(i/b);
        ans=max(ans,tmp);
    }
    if(n>=b-1) ans=max(ans,(a*(b-1))/b-a*((b-1)/b));
    else ans=max(ans,(a*n)/b-a*(n/b));
    cout<<ans<<endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N; cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}

	LL ans = LINF;
	for (LL x = -100; x <= 100; x++) {
		LL ret = 0;
		FOR(i, 0, N) {
			ret += (x-a[i])*(x-a[i]);
		}
		ans = min(ans, ret);
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
x = n - k

div = 10 ** 9 + 7
for i in range(1, k+1):
    if (i-1 <= x):
        print((comb(x+1, i) * comb(k-1, i-1)) % div) 
    else:
        print('0')


Measured memory_bytes: 3316
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n;
char f[102][3];

bool input(){
  cin>>n;
  REP(i, n)cin>>f[i];
  return n;
}

void solve(){
  int t=0, s=0;
  int r=0, l=0;
  REP(i, n) {
    if(f[i][0] == 'l') {
      if(f[i][1] == 'u')l++;
      else l--;
    }else {
      if(f[i][1] == 'u')r++;
      else r--;
    }
    if(r==l && s!=r) {
      t++;
      s=r;
    }
  }
  cout<<t<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 3060
#include <stdio.h>
 
int main() {
  int W, H , x ,y ,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 
  if(x-r<0 || x+r>W || y-r<0 || y+r>H) {
    printf("No\n");
  } else {
    printf("Yes\n"); 
  }
 
 
  return 0;
}


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

class Vertex{
  int connection;
  int name;
  list<Vertex*> v_list;
  Vertex(int n):connection(0),name(n){}
  friend class Graph;
};

class Graph{
  vector<Vertex*> graph;
public:
  Graph(int size){
    graph.resize(size);
    for(int i=0;i<size;i++){
      graph[i]=new Vertex(i);
    }
  }

  ~Graph(){
    for(int i=0;i<(int)graph.size();i++){
      delete graph[i];
    }
  }

  void addEdge(int from,int to){
    graph[from]->v_list.push_back(graph[to]);
    graph[to]->connection++;
  }

  void topo(){
    Vertex *v;
    queue<Vertex*> q;
    vector<Vertex*> vec;

    for(int i=0;i<(int)graph.size();i++){
      if(graph[i]->connection==0) q.push(graph[i]);
    }

    while(!q.empty()){
      v=q.front();
      q.pop();
      vec.push_back(v);
      for(list<Vertex*>::iterator it=v->v_list.begin();it!=v->v_list.end();it++){
	Vertex* w=*it;
	if((--w->connection)==0){
	  q.push(w);
	}
      }
    }

    for(int i=0;i<(int)vec.size();i++){
      cout<<vec[i]->name<<endl;
    }

  }

};

int main(){
  int v=0;
  int e=0;
  cin>>v>>e;
  Graph graph(v);
  for(int i=0;i<e;i++){
    int from,to;
    cin>>from>>to;
    graph.addEdge(from,to);
  }
  graph.topo();
  return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

LL const mod = 1e9 + 7;
int const MAXN = 2e5 + 5;
struct Edges { int to, next; } e[MAXN * 2];
int head[MAXN], tot;
int n, size[MAXN];
LL Bin[MAXN], ans;

inline void addedge(int from, int to) {
  e[++tot] = (Edges){to, head[from]};
  head[from] = tot;
  e[++tot] = (Edges){from, head[to]};
  head[to] = tot;
}

inline LL qpow(LL a, LL k) {
  LL re = 1;
  for (; k; k >>= 1, a = a * a % mod)
    if (k & 1) re = re * a % mod;
  return re;
}

void Dfs(int now, int fa) {
  size[now] = 1;
  for (RI i = head[now]; i; i = e[i].next)
    if (e[i].to != fa) {
      Dfs(e[i].to, now);
      (ans -= Bin[size[e[i].to]] - 1) %= mod;
      size[now] += size[e[i].to];
    }
  (ans -= Bin[n - size[now]] - 1) %= mod;
  ans += Bin[n - 1] - 1;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  read(n);
  Bin[0] = 1;
  for (RI i = 1; i <= n; ++i)
    Bin[i] = Bin[i - 1] * 2 % mod;
  for (RI i = 1, x, y; i < n; ++i)
    read(x), read(y), addedge(x, y);
  Dfs(1, 0);
  printf("%lld\n", (ans + mod) % mod * qpow(qpow(2, n), mod - 2) % mod);
  
  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 14208
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/
ll a[1000000];
int main(){
	ll n,x;

    sld(n) sld(x)
    ll sum = 0;
    for(ll i = 0; i < n; i ++){
        sld(a[i])
        if(a[i] > x){
            sum += a[i]-x;
            a[i] = x;
        }
    }
    for(int i = 1; i < n; i ++){
        if(a[i]+a[i-1] >x){
            sum += (a[i]+a[i-1]-x);
        a[i] -=(a[i]+a[i-1]-x);
        }

    }
    pld(sum) pn

    return 0;

}



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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a % 2 == 1 && b % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	system("pause");
    return 0;
}


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

typedef struct data {
    char name_[11];
    int time_;
} data_t;

class Queue
{
    data_t *data_;
    int totalCapacity_;
    int top_;
    int curCapacity_;
public:
    Queue(int);
    data_t enqueue(data_t);
    data_t dequeue(void);
    int isEmpty(void) const;
    int isFull(void) const;
};

Queue::Queue(int dataSize)
{
    data_ = new data_t[dataSize];
    totalCapacity_ = dataSize;
    top_ = 0;
    curCapacity_ = 0;
}

data_t Queue::enqueue(data_t enqueueData)
{
    if (isFull()) return enqueueData;
    data_[(top_ + curCapacity_) % totalCapacity_] = enqueueData;
    curCapacity_++;
}

data_t Queue::dequeue(void)
{
    data_t ret = data_[top_];
    if (isEmpty()) return ret;
    top_ = (top_ + 1) % totalCapacity_;
    curCapacity_--;
    return ret;
}

int Queue::isEmpty(void) const
{
    if (curCapacity_ == 0) return 1;
    return 0;
}

int Queue::isFull(void) const
{
    if (curCapacity_ == totalCapacity_) return 1;
    return 0;
}

int main(void)
{
    int n, q, curTime = 0;
    cin >> n >> q;
    Queue queue(n);
    for (int i = 0; i < n; i++) {
        data_t tmp;
        scanf("%s%d%*c", tmp.name_, &tmp.time_);
        queue.enqueue(tmp);
    }
    while (!(queue.isEmpty())) {
        data_t tmp = queue.dequeue();
        if (tmp.time_ - q <= 0) {
            curTime += tmp.time_;
            cout << tmp.name_ << " " << curTime << endl;
        } else {
            tmp.time_ -= q;
            curTime += q;
            queue.enqueue(tmp);
        }
    }

    return 0;
}

Measured memory_bytes: 2032
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define LEN_MAX 100000
#define MAP_MAX 100
#define FACTORIAL_MAX (MAP_MAX + LEN_MAX)
#define DIVISOR 1000000007

static uint64_t factorial[FACTORIAL_MAX+1];
static uint64_t inv_factorial[FACTORIAL_MAX+1];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a==0) return (struct pair){0, 1};
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y - b/a*p.x, p.x};
}

void init_combi(int n) {
    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;
    int i;
    for(i = 2; i <= n; i++) {
        factorial[i] = (factorial[i-1] * i) % DIVISOR;
        struct pair p = gcdext(i, DIVISOR);
        // p.x maybe negative
        int inv = (p.x + DIVISOR) % DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1] * inv) % DIVISOR;
    }
    return;
}
uint64_t calc_combi(int num, int r) {
    uint64_t ans = 1;
    ans = (ans * factorial[num])%DIVISOR;
    ans = (ans * inv_factorial[num-r])%DIVISOR;
    ans = (ans * inv_factorial[r])%DIVISOR;
    return ans;
}

uint64_t calc_homo(int kinds, int num) {
    return calc_combi(kinds+num-1, num);
}

int main(void) {
    int len, orig;
    int i, j;
    get_int2(&len, &orig);
    int orig_2 = (int)sqrt(0.5 + orig);

    // find prime in orig
    int cur = 2;
    //static int prime[MAP_MAX];
    static int cnt[MAP_MAX];
    int midx = 0;
    while(1) {
        if(orig==1) { midx++; break; }
        if(cur > orig_2) {
            cnt[midx++] = 1;
            break;
        }
        if(orig%cur) {
            if(cnt[midx]) midx++;
            cur++;
            continue;
        }
        orig /= cur;
        //prime[midx] = cur;
        cnt[midx]++;
    }
#ifdef DEBUG
    for(i = 0; i < midx; i++) {
        printf("%d ", cnt[i]);
    }
    putchar('\n');
#endif
    init_combi(len+100);

    uint64_t ans = 1;
    for(i = 0; i < midx; i++) {
        ans = (ans * calc_homo(len, cnt[i])) % DIVISOR;
    }

    printf("%d\n", (int)ans);
    return 0;
}

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

int main() {

  int a, b, k;
  cin >> a >> b >> k;

  int x;
  if(a < b) x = a;
  else x = b;

  vector <int> v;
  for(int i = 1; i <= x; i++) {
    if(a%i == 0 && b%i == 0) {
      v.push_back(i);
    }
  }

  cout << v[v.size()-k] << endl;
}


Measured memory_bytes: 256
//UG02-50-19-004
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,z,n;
    scanf("%d%d%d",&x,&y,&z);
    n = (x+y+z);
    if(n>=22)
    {
        printf("bust");
    }
    else
    {

        printf("win");
    }

    return 0;
}


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

int aa[100010],bb[100010];

#define INF 1000000

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

    int a,b,m;
    cin>>a>>b>>m;

    int mina=INF,minb=INF;

    for(int i=0;i<a;i++)
    {
        cin>>aa[i];
        mina=min(mina,aa[i]);
    }
    for(int i=0;i<b;i++)
    {
        cin>>bb[i];
        minb=min(minb,bb[i]);
    }

    int ans=mina+minb;

    for(int i=0;i<m;i++)
    {
        int x,y,c;
        cin>>x>>y>>c;

        ans=min(ans,aa[x-1]+bb[y-1]-c);
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 4404
h,w,m=list(map(int, input("").split()))
bo=[]
hb=[0]*h
wb=[0]*w
for i in range(m):
    a,b=list(map(int, input("").split()))
    #各行列に爆弾いくつあるか
    hb[a-1]+=1
    wb[b-1]+=1
    #爆弾の座標
    bo.append([a,b])
#ソート
mwb=[]
mhb=[]
#爆弾数が最大の行と列番号をメモ
hmax=max(hb)
wmax=max(wb)
for i in range(h):
    if hb[i]==hmax:
        mhb.append(i+1)
for i in range(w):
    if wb[i]==wmax:
        mwb.append(i+1)
c=0
#最大の爆弾数の行と列に含まれる爆弾数=cの確認
for h,w in bo:
     #h in mhb and w in mwb
    if(hb[h-1] == hmax and wb[w-1] == wmax):
        c+=1
#行と列の最大爆弾数の和
out=hmax+wmax
#行と列の最大数の積がcと一致するなら必ず重複があるので－1
if c==len(mwb)*len(mhb):
    out-=1
print(out)

Measured memory_bytes: 82412
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

struct db {
	ll f;
	ll s;
};

bool cmp(db x, db y) {
	return x.s > y.s;
}



ll n;

ll v[MAX];

int main() {

	char s;

	rep(i, 3) {
		cin >> s;
		if (s == '1') { cout << 9; }
		else { cout << 1; }
	}

	

	system("PAUSE");
}

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

using namespace std;

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    int total = 0;
    for (int i = 1; i <= n; i++) {
        total += l + i - 1;
    }
    int ans = -1e9;
    for (int i = 1; i <= n; i++) {
        int now = total - i - l + 1;
        if (abs(now - total) < abs(ans - total)) {
            ans = now;
        }
    }
    cout << ans;
    return 0;
}


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

const int N = 222222;
int n;
int a[N], b[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if(n & 1) {
        for(int i = n; i >= 1; i -= 2) {
            cout << a[i] << " ";
        }
        for(int i = 2; i <= n - 1; i += 2) {
            cout << a[i] << " ";
        }
        cout << endl;
    } else {
        for(int i = n; i >= 2; i -= 2) {
            cout << a[i] << " ";
        }
        for(int i = 1; i <= n - 1; i += 2) {
            cout << a[i] << " " ;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <vector>

bool visit[100000];
std::vector<int> edge[100000];

void dfs(int index)
{
  visit[index] = true;
  for (auto i : edge[index])
  {
    if (visit[i]) continue;
    dfs(i);
  }
}

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i)
  {
    int a, b;
    scanf("%d%d%*d", &a, &b);
    --a, --b;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    if (visit[i]) continue;
    ++ans;
    dfs(i);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  int a, b;
  cin >> a >> b;
  if(a >9 || b >9) COUT(-1);
  else COUT(a*b);
  return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int K=3005;
int x[K][K];
int n,k;
int getsize(int x1,int y1,int x2,int y2){
    return x[x2][y2]-x[x2][y1]-x[x1][y2]+x[x1][y1];
}
int main()
{
    scanf("%d%d",&n,&k);
    int a,b;
    char c;
    for(int i=1;i<=n;i++){
        scanf("%d%d %c",&a,&b,&c);
        a%=2*k,b%=2*k;
        if(c=='W')
            b+=k;
        x[a%(2*k)+1][b%(2*k)+1]++;
    }
    for(int i=1;i<=2*k;i++)
        for(int j=1;j<=2*k;j++)
            x[i][j]=x[i][j]+(x[i-1][j]+x[i][j-1]-x[i-1][j-1]);
    int ans=0,sum;
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++){
            sum=getsize(0,0,i,j);
            sum+=getsize(i,j,k+i,k+j);
            sum+=getsize(k+i,k+j,2*k,2*k);
            sum+=getsize(k+i,0,2*k,j);
            sum+=getsize(0,k+j,i,2*k);
            sum=max(n-sum,sum);
            ans=max(ans,sum);
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 24704
#include <stdio.h>
#include <string.h>
#include <algorithm>

char arr[100010];

int main()
{
	int k, i;
	scanf("%s%d", arr, &k);
	
	for(i = 0; arr[i]; i++)
	{
		if(arr[i] != 'a' && 'z'-arr[i]+1 <= k)
		{
			k -= 'z'-arr[i]+1;
			arr[i] = 'a';
		}
	}

	k %= 26;
	arr[i-1] += k;
	if(arr[i-1] > 'z')
		arr[i-1] -= 26;
	
	printf("%s\n", arr);
	return 0;
}

Measured memory_bytes: 384
x=input()
x=x.split()
n,k=map(int,x)
x=input()
x=x.split()
p=[]
for i in range(len(x)):
  p.append(int(x[i]))  
s=0
for i in range(k):
  s+=(p[i]+1)/2  
maxim=s
for i in range(k,n):
  s=s+(p[i]+1)/2-(p[i-k]+1)/2
  if s>maxim:
    maxim=s  
print(maxim)    




Measured memory_bytes: 24548
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000009
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    cout << (n * (n - 1ll)) / 2ll + (m * (m - 1ll)) / 2ll << endl;
}

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

using namespace std;

int main(void){
	int i,n,k,a,b,p,q,r,ans=0,dp[110][3][3],ls[110];
	cin >> n >> k;
	fill(ls,ls+110,-1);
	fill(dp[0][0],dp[110][0],0);
	for(i=0; i<k; i++){
		cin >> a >> b;
		a--;
		b--;
		ls[a] = b;
	}

	for(p=0; p<3; p++){
		if((ls[0]==-1) || (ls[0]==p)){

			for(q=0; q<3; q++){
				if((ls[1]==-1) || (ls[1]==q)){
					dp[1][p][q] = 1;
				}
			}

		}
	}

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

		for(p=0; p<3; p++){
			if((ls[i-2]==-1) || (ls[i-2]==p)){

				for(q=0; q<3; q++){
					if((ls[i-1]==-1) || (ls[i-1]==q)){

						for(r=0; r<3; r++){
							if((ls[i]==-1) || (ls[i]==r)){
								dp[i][q][r] += (p==q && q == r)?0:dp[i-1][p][q];
								dp[i][q][r] %= 10000;
							}
						}

					}
				}

			}
		}

	}
	for(p=0; p<3; p++){
		for(q=0; q<3; q++){
			ans += dp[n-1][p][q];
			ans %= 10000;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3052
/*I wanna be the very best, like no one ever was...*/

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define ll long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int main() {
    io;
    // freopen("in","r",stdin); 
    // freopen("out","w",stdout);
    
    int n,sum;
    cin>>n>>sum;
    int cnt = 0;
    
    for(int i  = 0;i  <n+1 ;i++){
        for(int j = 0;j<n+1;j++){
            int k = sum-i-j;
                if(0<=k && k<=n) cnt++;

        }
    }
    cout<<cnt<<endl;

 
 
 
    
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int sum;
int main(){
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;++i){
    cin >> v[i];
    sum += v[i];
  }
  if(sum%10!=0) cout << sum << endl;
  else{
    sort(v.begin(), v.end());
    for(int i=0;i<n;++i){
      if(v[i]%10!=0){
        cout << sum - v[i] << endl;
        return 0;
      }
    }
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
for i in range(n):
    P[i] -= 1

# for ij in range(100):
    # print("-----")
    # from random import randint
    # n = 5
    # k = 1
    # PP = [[randint(-100,100),i] for i in range(n)]
    # PP.sort()
    # P = [PP[i][1] for i in range(n)]
    # C = [randint(-10,10) for i in range(n)]
    # P=[4, 1, 0, 2, 3]
    # C=[10, -4, -5, 0, 5]


V = [0] * n
ans = -float("inf")
an = 0
for i in range(n):
    if V[i] == 0:
        A = []
        V[i] = 1
        ii = P[i]
        V[ii] = 1
        A.append(C[ii])
        while ii != i:
            ii = P[ii]
            V[ii] = 1
            A.append(C[ii])
        # print(A)
        an = 0
        anb=0
        anb2=0
        kb=k
        kb2=k
        if sum(A) > 0:
            anb += sum(A) * (k//len(A))
            kb = k%len(A)
        if k >= len(A) and sum(A) > 0:
            anb2 += sum(A) * (k//len(A)-1)
            kb2 = k % len(A) + len(A)
        A += A
        S = [A[0]]
        # print(anb,anb2,kb,kb2)
        for i in range(1,len(A)):
            S.append(S[-1]+A[i])
        # print(S)
        anc = 0
        for i in range(len(S)):
            for j in range(i+1, min(i+kb2+1,len(S))):
                anc = max(anc,S[j]-S[i])

        for i in range(len(S)):
            for j in range(i+1, min(i+kb+1,len(S))):
                an = max(an,S[j]-S[i])

        ans = max(an+anb,anc+anb2,ans)
            
if ans == 0 and max(C) < 0:
    ans = max(C)
print(ans)
# aaa = -float("inf")
# for i in range(n):
#     ii = P[i]
#     aa = C[ii]
#     aaa = max(aaa,aa)
#     for j in range(k-1):
#         ii = P[ii]
#         aa += C[ii]
#         aaa = max(aaa,aa)

# if aaa != ans:
#     print(C,P)
#     print(aaa,ans)
#     break



Measured memory_bytes: 69612
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define ll long long
#define hh puts("")
using namespace std;
int n,m,ans;
vector<int> v[100005];
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-ff;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch^48);ch=getchar();}
    return ret*ff;
}
signed main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		v[read()].push_back(1);
		v[read()+1].push_back(-1);
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<(int)v[i].size();j++) sum+=v[i][j];
		if(sum==m) ans++;
	}
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n;
ll a[N];

int calc() {
	int ans = 0;
	while (1) {
		sort(a+1,a+1+n);
		if (a[n]<=n-1) break;
		++ans;
		a[n]-=n;
		REP(i,1,n-1) ++a[i];
	}
	return ans;
}

int main() {
	scanf("%d", &n);
	REP(i,1,n) scanf("%lld",a+i);
	ll ans = 0;
	while (1) {
		sort(a+1,a+1+n);
		if (a[1]>60) {
			ll t = a[1]-60;
			ans += t*n;
			REP(i,1,n) a[i]-=t;
		}
		if (a[n]<=2000) { 
			ans += calc();
			break;
		}
		ll ma = -1;
		int p = 0;
		REP(i,2,n) if (a[i]-a[i-1]>ma) ma = a[i]-a[i-1], p = i;
		if (ma<=200) throw;
		ll w = n-p+1, t = (a[p]-a[p-1])/(n+1);
		ans += t*w;
		REP(i,1,p-1) a[i] += t*w;
		REP(i,p,n) a[i] += t*(-n+w-1);
	}
	printf("%lld\n", ans);
}








Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	long long freq[N + 1], ans = 0;
	int A[N];
	fill_n(freq, N + 1, 0);
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	for (int i = 0; i < N; ++i) ++freq[A[i]];
	for (int i = 1; i <= N; ++i) ans += freq[i] * (freq[i] - 1) / 2;
	for (int i = 0; i < N; ++i) printf("%lld\n", ans - freq[A[i]] + 1);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int Id[n];
  rep(i, n) {
    int p;
    cin >> p;
    Id[p-1] = i;
  }

  set<ll> plus{Id[n-1], n, n+1};
  set<ll> minus{-Id[n-1], 1, 2};

  ll ans = 0;
  for (int i = n-2; i >= 0; --i) {
    ll idx = Id[i];
    ll ps, pt, ms, mt;
    ps = *plus.upper_bound(idx); pt = *plus.upper_bound(ps);
    ms = *minus.upper_bound(-idx); mt = *minus.upper_bound(ms);

    if (ps < n) ans += (i+1) * (pt-ps) * (idx+ms);
    if (ms < 1) ans += (i+1) * (mt-ms) * (ps-idx);

    plus.insert(idx); minus.insert(-idx);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9984
# -*- coding: utf-8 -*-

def findSet(x):
  if x == parent[x]:
    return x
  else:
    temp = parent[x]
    parent[x] = findSet(parent[x])
    weight[x] += weight[temp]
    return parent[x]
  
def link(x, y, z):
  a = findSet(x)
  b = findSet(y)
  if a != b:
    parent[b] = a
    weight[b] = weight[x] - weight[y] + z

n, q = list(map(int, input().split()))

data = (i for i in range(n))
parent = [i for i in range(n)]
weight = [0 for i in range(n)]

for i in range(q):
  Ltemp = list(map(int, input().split()))
  if len(Ltemp) == 4:
    x, y, z = Ltemp[1:]
    link(x, y, z)
  else:
    x, y = Ltemp[1:]
    if findSet(x) == findSet(y):
      print(weight[y] - weight[x])
    else:
      print('?')



Measured memory_bytes: 11360
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
//#define mp make_pair 
typedef long long ll;
#define int long long
#pragma GCC optimize("Ofast")

const int maxn = 2e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;
//const int N = 2e6+10;

ll pw(ll a, ll b)
{
    if(b == 0) return 1;
    ll x = pw(a,b/2); x = (x*x) % mod;
    if(b & 1) x = (x*a) % mod;
    return x;
}

int n;
int a[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n;
    map<int,int> cnt;
    for(int i = 1; i <= n; i++) 
    {
        cin>> a[i];    
        cnt[a[i]]++;
    }
    sort(a+1,a+n+1);

    int ans = 0;
    for(int i = n; i >= 1; i--)
    {
        int x = log2(a[i])+1;
        int y = (1ll<<x);
        cnt[a[i]]--;
        if(cnt[y-a[i]] >= 1 && cnt[a[i]] >= 0)
        {
           // cout<< i <<" "<< a[i] <<" "<< y-a[i] <<"\n";
            ans++;
            cnt[y-a[i]]--;
        }
        //cout<< i <<" ";
    }
    cout<< ans;
}


Measured memory_bytes: 26880