akhauriyash/Code-Regression huggingface dataset:
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n, a, b = map(int, readline().rstrip().split())
    if (b - a) % 2 == 0:
        print((b - a) // 2)
        return
    print(min(a-1, n-b) + (b - a + 1)//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8968
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
using namespace std;
int main(void){
    string in;
    string left="qwertasdfgzxcvb";
    string right="yuiophjklnm";
    while(true){
        cin>>in;
        if(in=="#")break;
        bool sw=1;//leftなら1、rightなら0
        for(int i=0;i<right.length();i++){
            if(in[0]==right[i]){
                sw=0;
                break;
            }
        }
        int cnt=0;
        for(int s=1;s<in.length();s++){
            bool kensa=0;
            for(int i=0;i<left.length();i++){
                if(in[s]==left[i]){
                    if(sw==0){
                        cnt++;
                    }
                    kensa=1;
                    sw=1;
                    break;
                }
            }
            if(kensa==1){
                continue;
            }else{
                for(int i=0;i<right.length();i++){
                    if(in[s]==right[i]){
                        if(sw==1){
                            cnt++;
                        }
                        sw=0;
                        break;
                    }
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[111111];

int dfs(int v){
    if(G[v].size()==0)return 0;
    vint lis;
    for(auto u:G[v]){
        lis.pb(dfs(u));
    }

    sort(all(lis));
    reverse(all(lis));
    int ma=0;
    rep(i,lis.size())chmax(ma,lis[i]+1+i);
    return ma;
}

signed main(){
    cin>>N;
    for(int i=1;i<N;i++){
        int a;cin>>a;
        a--;
        G[a].pb(i);
    }

    cout<<dfs(0)<<endl;
    return 0;
}


Measured memory_bytes: 13824
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
int main() {
	ll D;
	cin >> D;
	vl C(26);
	for (i = 0; i < 26; i++) cin >> C[i];
	vll S(D, vl(26));
	for (i = 0; i < D; i++) {
		for (j = 0; j < 26; j++) {
			cin >> S[i][j];
		}
	}
	vl T(D);
	for (i = 0; i < D; i++) cin >> T[i];
	vl last(26,-1);
	for (i = 0; i < D; i++) {
		ans += S[i][T[i] - 1];
		last[T[i] - 1] = i;
		for (j = 0; j < 26; j++) {
			ans -= C[j]*(i - last[j]);
		}
		co(ans);
	}
}

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

#define MAX_V 15
#define INF (INT_MAX/MAX_V)

// copy from Takanori MAEHARA HomePage

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Weight chinesePostman( const Graph &g )
{
	Weight total = 0;
	vector<int> odds;
	REP(u, g.size()) {
		FOR(e, g[u]) total += e->weight;
		if (g[u].size() % 2) odds.push_back(u);
	}
	total /= 2;
	int n = odds.size(), N = 1 << n;
	Weight w[n][n]; // make odd vertices graph
	REP(u,n) {
		int s = odds[u]; // dijkstra's shortest path
		vector<Weight> dist(g.size(), INF); dist[s] = 0;
		vector<int> prev(g.size(), -2);
		priority_queue<Edge> Q;
		Q.push( Edge(-1, s, 0) );
		while (!Q.empty()) {
			Edge e = Q.top(); Q.pop();
			if (prev[e.dst] != -2) continue;
			prev[e.dst] = e.src;
			FOR(f,g[e.dst]) {
				if (dist[f->dst] > e.weight+f->weight) {
					dist[f->dst] = e.weight+f->weight;
					Q.push(Edge(f->src, f->dst, e.weight+f->weight));
				}
			}
		}
		REP(v,n) w[u][v] = dist[odds[v]];
	}

	Weight best[N]; // DP for general matching 
	REP(S,N) best[S] = INF;
	best[0] = 0;

	for (int S = 0; S < N; ++S)
		for (int i = 0; i < n; ++i) if (!(S&(1<<i)))
			for (int j = i+1; j < n; ++j) if (!(S&(1<<j)))
				best[S|(1<<i)|(1<<j)] = min(best[S|(1<<i)|(1<<j)], best[S]+w[i][j]);
	return total + best[N-1];
}

int V, E;

int main()
{
	cin >> V >> E;

	Graph G( V );

	for( int i = 0; i < E; i++ ) {
		int s, t, d;
		cin >> s >> t >> d;
		G[s].push_back( Edge( s, t, d ) );
		G[t].push_back( Edge( t, s, d ) );
	}

	cout << chinesePostman( G ) << endl;

	return 0;
}



Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str s;
int K;
int main(){
  cin>>s;
  cin>>K;
  int ss=s.size();
  int snum[100010]; 
  rep(i,ss){
    snum[i]='z'+1-s[i];
  }
  rep(i,ss){
    if(snum[i]<26&&snum[i]<=K){
      s[i]='a';
      K-=snum[i];
    }
  }
  if(K!=0){
    int k=K%26;
    s[ss-1]=s[ss-1]+k;
  }
  rep(i,ss) std::cout<<s[i];
  std::cout<<"\n";
  return 0;
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-12;

ll par[MAXN];
ll a[MAXN], ind[MAXN], mk[MAXN], sz[MAXN];

ll get_par(ll u){
	if(par[u] == u) return u;
	return par[u] = get_par(par[u]);
}

void merge(ll u, ll v, ll t = 0){
	u = get_par(u); v = get_par(v);
	if(u > v) swap(u, v);
	if(a[u] > a[v]) swap(a[u], a[v]);
	par[v] = u;
}

bool CMP(ll i, ll j){
	return a[i] < a[j];
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    fill(sz, sz + MAXN, 1);
	for(int i = 0; i < MAXN; i++) par[i] = i, ind[i] = i;
	ll n, m;
	cin >> n >> m;
	for(int i = 0;i < n; i++) cin >> a[i];
	ll cm = n - m;
	ll u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		merge(u, v);
	}
	ll ans = 0, po = 0;
	sort(ind, ind + n, CMP);
	sz[n] = 10000;
	if(cm == 1) return cout << 0, 0; 
	ll nd = cm - 2;
	
	for(int i = 0; i < n; i++){
		ll ii = ind[i];
		if(par[ii] == ii){
			ans += a[ii];
		} else if(nd > 0){
			nd --;
			ans += a[ii];
		}
	}
	if(nd > 0) cout << "Impossible\n";
	else cout << ans;
	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x >= r && y >= r && x+r <= W && y+r <= H) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    for(ll i = 0; i < s.size(); i ++)
    {
        if(s[i] == '1')
        {
            cnt ++;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int x,y,z;
int main()
{
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		z = y / 2 + x;
		cout<<z<<endl;
	}
}

Measured memory_bytes: 256
N,L=map(int,input().split())
tabenai = [(L+_-1) for _ in range(1,N+1)]
abs_tabenai = [abs(L+_-1) for _ in range(1,N+1)]
min_index = abs_tabenai.index(min(abs_tabenai))
ans = sum(tabenai)-tabenai[min_index]
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t A, B, C, K;
    cin >> A >> B >> C >> K;
    int64_t sum = 0;
    if (K > A) {
        K = K - A;
        sum = A;
        if (K > B) {
            K = K - B;
            while (K > 0) {
                sum -= 1;
                C = C - 1;
                K -= 1;
            }
        } else {
        }
    } else {
        sum = K;
    }

    cout << sum << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    int x = max(h, w);
    cout << (n + x - 1) / x << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

//table[i][w] ?????????i????????§???????????´??????w??\?????????????????????????????§???

int value[100],weight[100];
int table[101][10001];

int main(){
  int N,W;
  cin>>N>>W;
  for(int i=0;i<N;++i){
    cin>>value[i]>>weight[i];
  }
 
  for(int i=1;i<=N;++i){
    for(int w=0;w<=W;++w){
      if(w<weight[i-1]){
        table[i][w] = table[i-1][w];
      }else{
        table[i][w] = max(table[i-1][w],table[i-1][w-weight[i-1]]+value[i-1]);
      }
    }
  }
  cout<<table[N][W]<<endl;
  return 0;
}

Measured memory_bytes: 7020
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
    int n,flag=0;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                flag=1;
                break;
            }
        }
    }
    if(flag==1)
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
n,k = map(int, open(0).read().split())

left = right = 0
ans = 0
MOD = 10**9+7

for c,(i,j) in enumerate(zip(range(n+1), range(n,-1,-1))):
    left += i
    right += j
#     print(i,j, right, left,c)
    if c >= k-1:
        ans += (right-left+1)
        ans %= MOD

print(ans)

Measured memory_bytes: 65552
N = int(input())

list = [0] * 10000
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            v = i**2 + j**2 + k**2 +i*j + j*k + k*i
            if v <= 10000:
                list[v-1] += 1

for i in range(N):
    print(list[i])


Measured memory_bytes: 74312
#include <bits/stdc++.h>
#include <math.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll ans = 0;
    sort(a.begin(),a.end());

    if(n%2==0){
        for(int i=0;i<n;i++){
            if(i<n/2 - 1){
                ans -= 2*a.at(i);
            }else if(i==n/2 -1){
                ans -= a.at(i);
            }else if(i==n/2){
                ans += a.at(i);
            }else{
                ans += 2*a.at(i);
            }
        }
    }else{
        ll ans1=0,ans2=0;
        //pattern1 big/small (e.g. 3/4 n=7)
        for(int i=0;i<n;i++){
            if(i<n/2 - 1){
                ans1 -= 2*a.at(i);
            }else if(i<=n/2){
                ans1 -= a.at(i);
            }else{
                ans1 += 2*a.at(i);
            }
        }
        //pattern2 small/big (e.g. 4/3 n=7)
        for(int i=0;i<n;i++){
            if(i<n/2){
                ans2 -= 2*a.at(i);
            }else if(i<=n/2 + 1){
                ans2 += a.at(i);
            }else{
                ans2 += a.at(i)*2;
            }
        }
        ans = max(ans1,ans2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val counts = Array.fill(N + 1)(0L)
  val As = Array.fill(N)(in.nextInt)
  As.foreach(a => counts(a) += 1)
  val sum = counts.map(c => c * (c - 1) / 2).sum
  println(As.map(a => sum - counts(a) + 1).mkString("\n"))
}

Measured memory_bytes: 89676
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,m,p,q;
   cin>>n>>m;

   p=max(n,m);
   q=min(n,m);

   for(int i=0;i<p;i++)
      cout<<q;
   cout<<"\n";

   return 0;
}


Measured memory_bytes: 256
S = list(input())
S = list(map(lambda x: int(x),S))
ans = 0

for i in range(len(S) - 1,0,-1):
  
  if S[i] == 9:
    tmp = sum(S)
  else:
    S[i] = 9
    S[i - 1] -= 1
    tmp = sum(S)
  
  ans = max(tmp,ans)

if len(S) == 1:
  ans = S[0]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/


int calc(int y, int m, int d)
{
	int res = 0;
	
	for (int i=1; i<y; i++)
	{
		res += (i % 3 != 0) ? 195 : 200;
	}
	for (int i=1; i<m; i++)
	{
		if (y%3!=0 && i%2==0) res += 19;
		else res += 20;
	}
	
	return res + d - 1;
}


int main()
{
	int n, y, m, d;
	
	cin >> n;
	while (n--)
	{
		cin >> y >> m >> d;
		cout << 196470 - calc(y, m, d) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())


n=int(input())
ar=lis()
if 0 in ar:
    print(0)
    quit()
p=1
for i in range(n):
    p*=ar[i]
    if p>10**18:
        print(-1)
        quit()
print(p)

Measured memory_bytes: 83996
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	int pre = 0;
	long long ans = 0;
	for(int i=1,val;i<=n;i++) {
		cin >> val;
		int need = max(0,(pre+val)-k);
		ans += need;
		pre = val - need;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int>a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (a.at(a.at(i)-1) == i+1){
      count++;
    }
  }
  cout << count/2 << endl;
}



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

long long mod = 1000000007LL;


long long cnt[200004];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	
	long long ac = 0;
	long long p = 0;
	long long n, m;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int x; cin >> x;
		string s; cin >> s;
		if(s == "AC"){
			if(cnt[x] == -1) continue;
			ac++;
			p += cnt[x];
			cnt[x] = -1;
		}
		else{
			if(cnt[x] == -1) continue;
			cnt[x]++;
		}
		
	}
	cout << ac << " " << p << "\n";
}


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

ll solve() {
    ll N, a;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        if ( A[i] == 0 ) return 0;
    }
    ll mx = 1e18;
    ll m = 1, p = 1;
    for ( int i = 0; i < N; i++ ) {
        m *= A[i];
        if ( m < p || m > mx ) return -1;
        p = m;
    }
    return m;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

int mod = 1000000007;

long long mpow(int a, int b);

int main()
{
	int x, y;
	cin >> x >> y;
	
	if ((x + y) % 3 != 0) {
		cout << 0 << endl;

		return 0;
	}

	int m = (2 * y - x) / 3, n = (2 * x - y) / 3;
	if (m < 0 || n < 0) {
		cout << 0 << endl;

		return 0;
	}

	if (m > n) {
		int tmp = m;
		m = n;
		n = tmp;
	}

	long long t = 1;
	long long s = 1;
	for (int i = 0; i < m; i++) {
		t *= m + n - i;
		t %= mod;
		s *= i + 1;
		s %= mod;
	}

	cout << (t * mpow(s, mod - 2)) % mod << endl;

	return 0;
}

long long mpow(int a, int b)
{
	long long t = a;
	long long ans = 1;
	for (int i = 0; i < 31; i++) {
		if ((b & 1) == 1) {
			ans *= t;
			ans %= mod;
		}
		t *= t;
		t %= mod;
		b >>= 1;
	}

	return ans;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	std::vector<int> a;
	int current = 0;
	rep(i,n) {
		if(s[i]=='<') {
			if(current<0) {
				a.emplace_back(current);
				current = 0;
			}
			current++;
		} else {
			if(current>0) {
				a.emplace_back(current);
				current = 0;
			}
			current--;
		}
	}
	if(current!=0) a.emplace_back(current);

	int m = a.size();
	int sum = 0;
	rep(i,m-1) {
		if(a[i]>0 && a[i+1]<0) sum+=std::max(a[i],-a[i+1]);
	}
	if(a[m-1]>0) sum+=a[m-1];
	if(a[0]<0) sum+=-a[0];
	for(int i:a) {
		i = std::abs(i);
		sum+=i*(i-1)/2;
	}
	print(sum);


	return 0;
}


Measured memory_bytes: 3068
a1=input()
a2=a1.split(' ')
a3=[]
for i in range(2):
  a3.append(int(a2[i]))

b1=[] 
for i in range(a3[0]):
  b1.append(input())

b2=sorted(b1)

s=''
for i in range(a3[0]):
  s=s+b2[i]
  
print(s)

Measured memory_bytes: 3060
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))

cnt = 0
for a,b,c in combinations(L, 3):
    if a != b and b != c and c != a:
        if a+b>c and b+c>a and c+a>b:
            cnt += 1
print(cnt)

Measured memory_bytes: 9184
N = int(input())
dp = [i for i in range(N+1)]
 
for i in range(1, 7):
    for j in range(9**i, N+1):
        dp[j] = min(dp[j], dp[j-9**i]+1)
for i in range(1, 7):
    for j in range(6**i, N+1):
        dp[j] = min(dp[j], dp[j-6**i]+1)
print(dp[N])

Measured memory_bytes: 12872
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	ll s;
	cin >> s;
	ll x1 = 0;
	ll y1 = 0;
	ll x2 = 1e9;
	ll y2 = 1;
	ll y3 = dup(s, 1000000000);
	ll x3 = x2 * y3 - s;
	cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

Measured memory_bytes: 3560
package main

import "fmt"

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

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

	start := 0
	for i := 0; i < n; i++ {
		if start <= h[i]-1 {
			start = h[i] - 1
		} else if start <= h[i] {
			start = h[i]
		} else {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 5504
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

cnt = [0] * (2000 * 20)

for i in range(1, 2**n + 1):
    SUM = 0
    for j in range(n):
        if i>>j & 1:
            SUM += a[j]
    cnt[SUM] = 1

for _m in m:
    if cnt[_m] == 1:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5720
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut buffer = String::new();

    stdin.read_line(&mut buffer).unwrap();
    let n = buffer.trim().parse::<u128>().unwrap();

    buffer = String::new();
    stdin.read_line(&mut buffer).unwrap();
    let inputs = buffer
        .trim()
        .split(" ")
        .map(|x| x.trim().parse().unwrap())
        .collect::<Vec<u128>>();

    if inputs.iter().any(|x| *x == 0) {
        println!("0");
        return;
    }

    let mut result: u128 = 1;
    for x in inputs {
        result *= x;

        if result > 1000000000000000000 {
            println!("-1");
            return;
        }
    }

    println!("{}", result)
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e10;


void dfs1(int i ,vector<vector<int>>& G ,vector<int>& dist1) {
    for (int e:G[i]) {
        if (dist1[e] == -1) {
            dist1[e] = dist1[i] + 1;
            dfs1(e,G,dist1);
        }
    }
}

void dfs2(int i ,vector<vector<int>>& G ,vector<int>& dist2) {
    for (int e:G[i]) {
        if (dist2[e] == -1) {
            dist2[e] = dist2[i] + 1;
            dfs2(e,G,dist2);
        }
    }
}

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

    vector<vector<int>> G(n);

    for (int i = 0; i < n - 1; i ++ ) {
        int a, b;
        cin >> a >> b;
        a --; b --;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist1(n,-1);
    vector<int> dist2(n,-1);
    dist1[0] = 0;
    dist2[n - 1] = 0;
    dfs1(0,G,dist1);
    dfs2(n - 1,G,dist2);
    
    int f = 0;
    int s = 0;

    for (int i = 0; i < n; i ++) {
        if (dist1[i] <= dist2[i]) {
            f += 1;
        }
        else s += 1;
    }

    if (f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<int> v;

  int n;// = 200001:
  cin >> n;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    v.push_back(x);
  }

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

  for (int i=0; i<n-1;i++){
    if(v[i]==v[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1400
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	double x, h;
	
	while(1){
		scanf("%lf%lf", &x, &h);
		if(x==0 && h==0)
			break;
		printf("%f\n", pow(x,2) + 2*x*sqrt(pow(h,2)+pow(x/2,2)));
	}
	return 0;
}

Measured memory_bytes: 644
H, W = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(H)]
visited = [[True]*(W+2)] + [[True]+[False]*W+[True] for _ in range(H)] + [[True]*(W+2)]

dirs = [
  (1, 0),
  (0, 1),
  (-1, 0),
  (0, -1)
]
direction = 0
x, y = 1, 1
carry = 0
ans = []
while not visited[y][x]:
  visited[y][x] = True
  m[y-1][x-1] += carry
  if carry:
    ans[-1] += [y, x]

  carry = m[y-1][x-1] % 2
  if carry:
    ans.append([y, x])
    m[y-1][x-1] -= 1 # 別にいらない

  # 今の向きに進めないなら右に曲がる
  nx, ny = x + dirs[direction][0], y + dirs[direction][1]
  if visited[ny][nx]:
    direction = (direction + 1) % 4
  x += dirs[direction][0]
  y += dirs[direction][1]

if len(ans) > 0 and len(ans[-1]) < 4:
  y, x = ans.pop()
  m[y-1][x-1] += 1 # もどす

print(len(ans))
for a in ans:
  print(' '.join(list(map(str, a))))

Measured memory_bytes: 33760
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
bool used[100010];
vector<int> ans;
vector<int> to[100010], from[100010];
void dfs(int u){
    if(used[u])return;
    used[u] = true;
    for(auto &i: to[u])dfs(i);
    ans.push_back(u);
}
main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(N+M-1),B(N+M-1);
    vector<int> in(N);
    rep(i,0,N+M-1){
        cin >> A[i] >> B[i];
        A[i]--,B[i]--;
        in[B[i]]++;
        to[A[i]].push_back(B[i]);
        from[B[i]].push_back(A[i]);
    }
    int start;
    rep(i,0,N)if(in[i] == 0)start = i;
    dfs(start);
    reverse(ans.begin(), ans.end());
    vector<int> rev(N);
    rep(i,0,N)rev[ans[i]] = i;
    //rep(i,0,N)cout << ans[i] << " \n"[i == N-1];
    //rep(i,0,N)cout << rev[i] << " \n"[i == N-1];
    rep(i,0,N){
        if(rev[i] == 0){
            cout << 0 << endl;
            continue;
        }
        int maxi = -1, maxv;
        for(auto j:from[i]){
            if(rev[j] > maxi){
                maxi = rev[j];
                maxv = j;
            }
        }
        cout << maxv + 1<< endl;
    }
}

Measured memory_bytes: 18684
using System;

namespace _135C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[32]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
            Console.WriteLine(a[int.Parse(Console.ReadLine())-1]);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define INF 100005

string a;
long long ans;
int n;
string str;

void rec(int pos)
{
	if(pos==n-1)
	{
		str.push_back(a[pos]);
		stringstream ss(str);
		long long num;
		while(ss >> num)
		{
			ans=ans+num;
		}
		str.pop_back();
		return;
	}
	str.push_back(a[pos]);
	rec(pos+1);
	str.pop_back();
	str.push_back(a[pos]);
	str.push_back(' ');
	rec(pos+1);
	str.pop_back();
	str.pop_back();
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin >> a;
    n=a.size();
    rec(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

typedef long long ll;
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

void Main(){
    ll N, K, l, r;
    cin >> N >> K;
    vector<mint> dp1(N, 0);
    vector<mint> dp_sum(N, 0);
    vector<pll> lrs(K);
    rep(i, K){
        cin >> l >> r;
        // --l; -- r;
        lrs[i] = make_pair(l, r);
    }

    dp_sum[0] = 1;
    dp1[0] = 1;
    for(ll i=1;i<N;i++){
        dp_sum[i] += dp_sum[i-1];
        for(auto lr:lrs){
            l = lr.first;
            r = lr.second;
            mint add_v = 0;
            if(i>=l){
                add_v = dp_sum[i-l];
                // cout << "dp_sum[i-l]=" << dp_sum[i-l] << endl;
            }
            if(i>r){
                add_v -= dp_sum[i-r-1];
                // cout << "dp_sum[i-r-1]=" << dp_sum[i-r-1] << endl;
            }
            // cout << "i=" << i << " lr="<< lr << " add_v=" << add_v <<endl;
            dp1[i] += add_v;
            dp_sum[i] += add_v;
            // cout << "dp_sum[" << i <<"]=" << dp_sum[i] <<endl;
        }
    }

    cout << dp1[N-1] <<endl;


}

int main(){
    Main();
}

Measured memory_bytes: 5972
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <string>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  int n; cin >> n;
  vector<int> v(n);
  int maxxy = 0, minn = INT32_MAX;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    maxxy = max(maxxy, v[i]);
  }
  for (int i = 1; i <= maxxy; i++) {
    int count = 0;
    for (int j : v) count += (i - j)*(i - j);
    minn = min(minn, count);
  }
  cout << minn << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

//vector<unordered_set<int>> cache; // n -> y
vector<vector<int>> cache; // n -> y

void c(int n, int y, int m, int g, int s) {
    //cout << "n: " << n << ", y: " << y << endl;
    if (cache[n][y])
        return;

    if (y == 0) {
        if (n != 0) {
            return;
        }

        cout << m << " " << g << " " << s << endl;
        exit(0);
    } else if (n == 0) {
        return;
    }

    if (10 <= y) {
        c(n - 1, y - 10, m + 1, g, s);
        if (2 <= n)
            c(n - 2, y - 10, m, g + 2, s);
        if (10 <= n)
            c(n - 10, y - 10, m, g, s + 10);
    }

    if (5 <= y) {
        c(n - 1, y - 5, m, g + 1, s);
        if (5 <= n)
            c(n - 5, y - 5, m, g, s + 5);
    }

    if (1 <= y)
        c(n - 1, y - 1, m, g, s + 1);

    cache[n][y] = 1;
}

int main() {
    int n, y;
    cin >> n;
    cin >> y;

    cache.resize(2001);
    for (int i = 0; i < cache.size(); i++)
        cache[i].resize(20000);

    if (y <= n * 10000 && n * 1000 <= y)
        c(n, y / 1000, 0, 0, 0);
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 156800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define upper_index(v,a) (ll)distance(v.begin(), upper_bound((v).begin(),(v).end(),a))
#define lower_index(v,a) (ll)distance(v.begin(), lower_bound((v).begin(),(v).end(),a))
#define eachdo(e,array) for(const auto& e : array)
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chman(T &a, T b){if(a<b){a=b;return true;}return false;}
const ll INF=1LL<<63-1;
const ll MOD=1e9+7;

struct SegmentTree{
private:
    ll unit=0;
    ll op(ll a,ll b){return a+b;}
    ll n;
    vector<ll> node;

public:
    SegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1,unit);
        for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
    }

    void update(ll x,ll val){
        x+=n-1;
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=op(node[2*x+1],node[2*x+2]);
        }
    }

    ll query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if (r<0) r=n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a,b,2*k+1,l,(l+r)/2);
        ll vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};

struct LazySegmentTree{
private:
    ll n;
    vector<ll> node,lazy;
public:
    LazySegmentTree(vector<ll> v){
        ll sz=(ll)v.size();
        n=1;while(n<sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1);
        for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
        for(ll i=n-2;i>=0;i--) node[i]=node[2*i+1]+node[2*i+2];
    }

    void lazyEval(ll k,ll l,ll r){
        if(lazy[k]!=0){
            node[k]+=lazy[k];
            if(r-l>1){
                lazy[2*k+1]+=lazy[k]/2;
                lazy[2*k+2]+=lazy[k]/2;
            }
            lazy[k]=0;
        }
    }
    void update(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        lazyEval(k,l,r);
        if(b<=l || r<=a) return;
        if(a<=l && r<=b){
            lazy[k]+=(r-l)*x;
            lazyEval(k,l,r);
        }
        else{
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }

    ll query(ll a,ll b,ll k=0,ll l=0,ll r=-1){
        if(r<0) r=n;
        if(b<=l || r<=a) return 0; 

        lazyEval(k,l,r);
        if(a<=l && r<=b) return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }

    ll at(ll a){return query(a,a+1);}
};

int main(){
    ll N,M;cin>>N>>M;
    vector<pair<ll,ll>> a(N),b(N);rep(i,N)cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    // reverse(a.begin(),a.end());
    ll ans=0,bot=0;
    ll i=0;
    while(bot<M){
        ans+=a[i].first*a[i].second;
        bot+=a[i].second;
        ++i;
    }
    --i;
    while(bot!=M){
        bot--;
        ans-=a[i].first;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);

    if (a == b){
        printf("%c %s %c\n", 'a', "==", 'b');
    }
    else if (a < b){
        printf("%c %c %c\n", 'a', '<', 'b');
    }
    else {
        printf("%c %c %c\n", 'a', '>', 'b');
    }

    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 20160116
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
const int Maxn=100005;
const long long mod=1000000007;
long long fact[Maxn];
long long qp(long long x,long long p){
	if (p==0) return 1LL;
	if (p==1) return x;
	if (p%2==0LL){
		long long y=qp(x,p/2);
		return y*y%mod;
	}
	else{
		long long y=qp(x,p/2);
		return y*y%mod*x%mod;
	}
}
long long inv(long long x){
	return qp(x,mod-2);
}
long long c(long long n,long long k){
	if (k>n) return 0;
	if (k<0) return 0;
	if (k*2>n) k=n-k;
	long long x=fact[n];
	x=x*inv(fact[n-k]);
	x%=mod;
	x*=inv(fact[k]);
	x%=mod;
	return x; 
}
int a[Maxn];
int use[Maxn];
int main(){
	fact[0]=1;
	for (int i=1;i<Maxn;i++){
		fact[i]=fact[i-1]*i;
		fact[i]%=mod;
	}
	int n;
	scanf("%d",&n);
	int dist=0;
	memset(use,0,sizeof(use));
	for (int i=0;i<n+1;i++){
		scanf("%d",&a[i]);
		if (use[a[i]]!=0){
			dist=i-use[a[i]];
		}
		use[a[i]]=i+1;
	}
	dist=n-1-dist;
//	cout<<dist<<endl;
	for (int i=1;i<=n+1;i++){
		long long res=c(n+1,i);
		res-=c(dist,i-1);
		res%=mod;
		res+=mod;
		res%=mod; 
		if (res<0) throw 3;
		printf("%I64d\n",res);
	}
	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3092
#include <stdio.h>
#define N 10001

int linearSearch(int A[], int n, int key)
{
  int i;

  i = 0;
  A[n] = key;
  if(A[0] == key){
    return 1;
  }
  while(A[i] != key){
    i++;
  }
  if(i == n){
    return 0;    
  }
  return i;
}

int main(){

  int i, n, q, key, count=0;
  int A[N];
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);

  for(i=0; i<q; i++){
    scanf("%d", &key);
    if(linearSearch(A, n, key)){
	count++;
      }
  }

    printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;


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

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

    cout << (a-1)*(b-1);

   
}


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

int main() {
	string S, T; cin >> S >> T;
	vector<vector<int>> dp(S.size()+1, vector<int>(T.size()+1, 0));
	for(int i=0; i<S.size(); ++i){
	    for(int j=0; j<T.size(); ++j){
	        if(S[i]==T[j]) dp[i+1][j+1]=dp[i][j]+1;
	        else dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
	    }
	}
	string ans="";
	int a=S.size(), b=T.size();
	while(a>0 && b>0){
	    if(S[a-1]==T[b-1]){
	        ans += S[a-1];
	        --a;
	        --b;
	    }
	    else if(dp[a-1][b]==dp[a][b]) --a;
	    else --b;
	}
	for(int i=dp[S.size()][T.size()]; i>0; --i) cout << ans[i-1];
	cout << endl;
	return 0;
}


Measured memory_bytes: 35584
#include<stdio.h>
#include<string.h>
int d[20000]={0};

int main()
{
	int n,c,m,s,i,j,t;
	for(;scanf("%d",&n),n;memset(d,0,sizeof(d)))
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&c);
			for(j=t=0;j<4;t+=m*60+s,j++)
				scanf("%d%d",&m,&s);
			d[t]=c;
		}
		for(i=0;d[i]==0;i++);
		printf("%d\n",d[i++]);
		for(;d[i]==0;i++);
		printf("%d\n",d[i]);
		for(i=20000;d[i]==0;i--);
		for(i--;d[i]==0;i--);
		printf("%d\n",d[i]);
	}
	return 0;
}

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

int main(){
    ll c[3][3];
    rep(i, 0, 3){
        rep(j, 0, 3) cin >> c[i][j];
    }
    // tate
    bool f = true;
    ll d[3];
    rep(j, 0, 3){
            rep(i, 0, 3) d[i] = c[j%3][i] - c[(j+1)%3][i];
            if(d[0] != d[1] || d[1] != d[2] || d[2] != d[0]) f = false;
    }
    rep(j, 0, 3){
        rep(i, 0, 3) d[i] = c[i][j%3] - c[i][(j+1)%3];
        if(d[0] != d[1] || d[1] != d[2] || d[2] != d[0]) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

bool check(std::string s){
    if(s == "AKIHABARA") return true;
    
    if(s == "AKIHABAR") return true;
    if(s == "AKIHABRA") return true;
    if(s == "AKIHBARA") return true;
    if(s == "KIHABARA") return true;

    if(s == "AKIHABR") return true;
    if(s == "AKIHBAR") return true;
    if(s == "KIHABAR") return true;
    if(s == "AKIHBRA") return true;
    if(s == "KIHABRA") return true;
    if(s == "KIHBARA") return true;

    if(s == "KIHBRA") return true;
    if(s == "KIHBAR") return true;
    if(s == "KIHABR") return true;
    if(s == "AKIHBR") return true;

    if(s == "KIHBR") return true;

    return false;
}

int main(void){
    std::string s;
    std::cin >> s;

    bool flag = check(s);
    if(flag){
        std::cout << "YES" << std::endl;
        return 0;
    }
    else{
        std::cout << "NO" << std::endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string s;cin>>s;
    bool f=1;
    rep(i,s.size()){
        if(i%2==0&&s[i]=='L')f=0;
        if(i%2==1&&s[i]=='R')f=0;
        if(!f)break;
    }
    cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

cnt_W = [0]*N #西を向いている人の累積和を求める
if S[0] == 'W':
    cnt_W[0] = 1

for i in range(1, N):
    if S[i]=="W":
        cnt_W[i] += cnt_W[i-1] + 1
    else:
        cnt_W[i] = cnt_W[i-1]

most_E = cnt_W[-1] #全体で西を向いている人数
ans = []
for i in range(N):
    if i == 0:
        if S[i] == "W":
            ans.append(N-most_E)
        else:
            ans.append((N-most_E)-1)
    elif i == N-1:
        if S[i] == "W":
            ans.append(most_E-1)
        else:
            ans.append(most_E)
    else:
        ans.append(cnt_W[i-1] + (N-most_E) - (i+1-cnt_W[i]))

print(min(ans))


Measured memory_bytes: 32896
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main () {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 256