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

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,b) for(int i=0;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define N 10005
#define input(v) for(int i=0;i<n;i++) cin>>v[i];
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
int mod=1e9+7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x;}
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

//variables
int n;


int32_t main() {
    faster;

    int x,y,z;
    cin>>x>>y>>z;

    cout<<z<<" "<<x<<" "<<y;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

template<typename T> struct UF {
    vector<int> par;
    vector<T> sz;

    UF(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    rep(k, n) {
        llong lower_limit = a + k * c - (n - k - 1) * d, upper_limit = a + k * d - (n - k - 1) * c;
        if (lower_limit <= b && b <= upper_limit) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    int count0=0, count1=0; 
    for(int i=0; i<str.size(); i++) {
        if(i%2) {
            if(str[i]=='1') count0++;
            else count1++;
        } else {
            if(str[i]=='0') count0++;
            else count1++;
        }
    }
    
    if(count1>count0) cout << count0 << endl;
    else cout << count1 << endl;

    return 0;
    
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
LL x[123], y[123];
int flag[123];
int maxf[123];
int minf[123];
long double ans[123];

const long double PI = acos(-1);

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
	}
	vector<pair<double, pair<int, int>>>vec;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j)continue;
			LL dx = x[i] - x[j];
			LL dy = y[i] - y[j];
			auto angle = atan2(dy, dx);
			angle += PI;
			angle += (PI / 2);
			if (angle >= PI * 2) {
				angle -= PI * 2;
			}
			vec.push_back({ angle,{i,j} });
		}
	}
	sort(vec.begin(), vec.end());
	fill(maxf, maxf + 123, -123456);
	fill(minf, minf + 123, 123456);
	for (auto elm : vec) {
		int in = elm.second.first;
		int out = elm.second.second;
		flag[in]++;
		flag[out]--;
		maxf[in] = max(maxf[in], flag[in]);
		maxf[out] = max(maxf[out], flag[out]);
		minf[in] = min(minf[in], flag[in]);
		minf[out] = min(minf[out], flag[out]);
	}
	int i = 0;
	int M = vec.size();
	for (auto elm : vec) {
		int in = elm.second.first;
		int out = elm.second.second;
		flag[in]++;
		flag[out]--;
		for (int x = 0; x < N;++x) {
			if (flag[x] == maxf[x]) {
				if (i + 1 == M) {
					ans[x] += vec[(i + 1) % M].first - vec[i].first + 2 * PI;
				}
				else {
					ans[x] += vec[(i + 1) % M].first - vec[i].first;
				}
			}
		}
		i++;
	}
	cout.precision(15);
	for (int x = 0; x < N; ++x) {
		ans[x] /= (2 * PI);
		if (N - 1 != maxf[x] - minf[x]) {
			ans[x] = 0;
		}
		cout << ans[x] << endl;
	}
	return 0;
}


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

n = list(input())
kouho1 = n[0] * len(n)
kouho2 = str(int(n[0]) + 1) * len(n)

m = "".join(n)

if int(kouho1) >= int(m):
    print(kouho1)
else:
    print(kouho2)


Measured memory_bytes: 2940
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = min(a) + min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    total = min(total, a[x-1] + b[y-1] - c)
print(total)


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  ll A, B, C;
  cin >> A >> B >> C;
  ll res = 2e18;
  res = min(res, (A % 2) ? B * C : 0LL);
  res = min(res, (B % 2) ? C * A : 0LL);
  res = min(res, (C % 2) ? A * B : 0LL);
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
def solution(a,b,c,d):
  return(max(a,max(b,max(c,d)))-min(a,min(b,min(c,d))))
n=int(input())
a=list(map(int,input().split()))
tot=sum(a)
pointer1=1
p=a[0]
q=a[1]
pointer2=0
s=tot-p-q
r=0
pointer2=2
while r+a[pointer2]<s-a[pointer2]:
  r+=a[pointer2]
  s-=a[pointer2]
  pointer2+=1
ans=solution(p,q,r,s)
ans=min(ans,solution(p,q,r+a[pointer2],s-a[pointer2]))
for i in range(2,n-1):
  q+=a[i]
  r-=a[i]
  while p+a[pointer1]<q-a[pointer1]:
    p+=a[pointer1]
    q-=a[pointer1]
    pointer1+=1
  while r+a[pointer2]<s-a[pointer2]:
    r+=a[pointer2]
    s-=a[pointer2]
    pointer2+=1
  ans=min(ans,solution(p,q,r,s))
  ans=min(ans,solution(p+a[pointer1],q-a[pointer1],r,s))
  ans=min(ans,solution(p+a[pointer1],q-a[pointer1],r+a[pointer2],s-a[pointer2]))
  ans=min(ans,solution(p,q,r+a[pointer2],s-a[pointer2]))
print(ans)

Measured memory_bytes: 102664
#include <bits/stdc++.h>
#define itn int
#define rep(i, n) for (int i = 0; i < n; i++)
#define irep(i,n) for(int i = n-1; i>=0; i--)
#define repeach(itr, k) for(auto itr : k)
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    vector<int> ans(n);
    vector<int> ans1(n);
    rep(i,n){
        cin >> w[i];
        i==0?ans[i]=w[i]:ans[i]=ans[i-1]+w[i];
    }
    irep(i,n){
        i==n-1?ans1[i]=w[i]:ans1[i]=ans1[i+1]+w[i];
    }
    int min_a=114514;
    for(int i=0;i!=n-1;i++){
        min_a=min(min_a,abs(ans[i]-ans1[i+1]));
    }
    cout << min_a << endl;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc075/tasks/abc075_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

char dp[60][60];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    REP(i, h) REP(j, w) cin >> dp[i + 1][j + 1];
    REP(i, h) REP(j, w) {
        if (dp[i + 1][j + 1] == '.') {
            int cnt = 0;
            REP(k, 3) REP(l, 3) {
                if (dp[i + k][j + l] == '#')
                    cnt++;
            }
            dp[i + 1][j + 1] = '0' + cnt;
        }
    }

    REP(i, h) {
        REP(j, w) { cout << dp[i + 1][j + 1]; }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
from itertools import combinations

n,m,x = map(int, input().split())
c = [0] * n
a = []
for i in range(n):
	v = [int(i) for i in input().split()]
	c[i] = v[0]
	a.append(v[1:])
	
rng = list(range(n))

ans = 10000000000

for i in range(1, n+1):
	for cb in list(combinations(rng,i)):
		r = [0]*m
		cout = 0
		for j in cb:
			cout+=c[j]
			for k in range(m):
				r[k]+=a[j][k]
		if min(r)>=x:
			ans = min(ans, cout)
		
print(ans if ans !=10000000000 else -1)


Measured memory_bytes: 9392
def biserch(ok,ng):
    while abs(ok-ng) > 1:
        mid = (ok+ng) // 2
        if judge(mid):
            ok = mid
        else:
            ng = mid
    return ok

def judge(x):
    if x * (x + 1) // 2 >= N:
        return True
    else:
        return False

N = int(input())
K = biserch(10 ** 7, 0)
d = K * (K + 1) // 2 - N
for i in range(1, K + 1):
    if i == d:
        continue
    print(i)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//int k;
//string s;
signed main(){
	acc_io;
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double C,Ta,Tb;
	Ta=30*(60*h+m);
	Tb=60*6*m;
	if(Tb>Ta) C=Tb-Ta;
	else C=Ta-Tb;
	if(C>180*60) C=360*60-C;
	C=C*PI/(60*180);
//	DBG("C",C,0,0);

	double ans;
	ans=sqrt(a*a+b*b-2*a*b*cos(C));
	cout << fixed << setprecision(20) << ans << endl;	
//	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4308
#n,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
#BC = gets.chomp.to_i.times.map { gets.split.map(&:to_i) }
#bc=q.times.map{gets.split.map(&:to_i)}
n,m,k=gets.split(' ').map(&:to_i)
a=gets.split(' ').map(&:to_i)
b=gets.split(' ').map(&:to_i)
a[n]=10**11
b[m]=10**11
acount=0
bcount=0
ans=0
#time=0
#puts a[n-1]
#puts a[n]
=begin
while a[acount]<=k || b[bcount]<=k
  ans+=1
  if a[acount]<=b[bcount]
    k-=a[acount]
    acount+=1
  else
    k-=b[bcount]
    bcount+=1
  end
end
puts ans
=end
best=0
ak=k
while a[acount]<=ak
  ans+=1
  ak-=a[acount]
  acount+=1
end
#puts ak
while b[bcount]<=ak
  ans+=1
  ak-=b[bcount]
  bcount+=1
  #puts ak
end
best=ans
astart=acount
for i in 0..astart-1
  atarget=astart-i-1
  #puts atarget
  ans-=1
  ak+=a[atarget]
  #puts bcount
  #puts ak
  while b[bcount]<=ak
    ans+=1
    ak-=b[bcount]
    bcount+=1
  end
  if ans>best
    best=ans
  end
end
puts best

Measured memory_bytes: 41720
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int length = n.length();
		if(!isPalindrome(n, 0, length-1)) {
			System.out.println("No");
			return;
		}
		if(!isPalindrome(n.substring(0, ((length-1)/2)), 0, (length-1)/2-1)) {
			System.out.println("No");
			return;
		}
		if(!isPalindrome(n.substring((length+3)/2-1, length), 0, (length-1)/2-1)) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");
		return;
		
	}
	static boolean isPalindrome(String s, int start, int end) {
		int length = 0;
		while(start<end) {
			if(s.charAt(start)!=s.charAt(end)) {
				return false;
			}
			start++;
			end--;
			length++;
		}
		return true;
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int n = 0,w = 0,s = 0,e = 0;
    for(auto c:S){
        if(c == 'N')n=1;
        if(c == 'W')w=1;
        if(c == 'S')s=1;
        if(c == 'E')e=1;
    }
    if((n ^ s) | (w ^ e))cout << "No" << endl;
    else    cout << "Yes" << endl;
}

Measured memory_bytes: 256
/* ex4_3
    fmuacshai */

#include<stdio.h>
#include<math.h>
int snow(int w_height,int e_height);

int main (void){
    int west,east;
    scanf("%d",&west);
    scanf("%d",&east);
    printf("%d\n",snow(west,east));
    return 0;
}

int snow(int w_height,int e_height){
    int snow_height,dif,sum;
    dif=e_height-w_height;
    dif-=1;
    sum=0;
    while(dif>0){
        sum+=dif;
        dif-=1;
    }
    snow_height=sum-w_height;
    return(snow_height);
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;


int main() {
    //cin.tie(0), ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    int res = 0;
    for (auto ch : s) {
        res += ch - '0';
    }

    --s[0];
    int ans = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (i == 0) {
            ans += s[i] - '0';
        } else {
            ans += 9;
        }
    }
    cout << max(ans, res) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

vector<ll> g[110000];
vector<P> s;
vector<ll> ans(210000);
int main(){
    ll n, m;
    cin >> n >> m;
    s.resize(m);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << "Yes" << endl;
    queue<P> q;
    ll d[210000] = {};
    bool used[210000] = {};
    q.push(P(0, 0));
    used[0] = true;
    while (!q.empty()) {
        P now = q.front();
        q.pop();
        ll a = now.first, b = now.second;
        ans[a] = b;
        REP(i, g[a].size()) {
            ll x = g[a][i];
            if (used[x]) continue;
            //if(s[x][y] == '#') continue;
            used[x] = true;
            d[x] = d[a] + 1;
            q.push(P(x, a));
        }
    }
    FOR(i, 1, n)
        cout << ans[i] + 1 << endl;
}



Measured memory_bytes: 18168
#include<bits/stdc++.h>
using namespace std;
const int N=100100,mod=1000000007;
typedef long long ll;
int a[N],d[N],n,vis[N],ans=1,cnt[N],b[N];
void gofail(){cout<<0<<'\n';exit(0);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i],d[a[i]]++;//,b[a[i]]=i;
	for(int i=1;i<=n;++i){
		if(d[i]>2)gofail();
		if(d[i]<2||vis[i])continue;
		vis[i]=1;b[a[i]]=i;
		for(int j=a[i];j!=i;j=a[j]){
			if(vis[j])gofail();
			vis[j]=1;b[a[j]]=j;
		}
	}
	for(int i=1;i<=n;++i)
		if(!d[i]){
			int cha=0,cir=1,j=i;
			for(;!vis[j];j=a[j])vis[j]=1,++cha;
			for(j=b[j];d[j]<2;j=b[j])++cir;
			if(cha<cir)ans=ans*2%mod;
			else if(cha>cir)gofail();
		}
	for(int i=1;i<=n;++i)
		if(!vis[i]){
			int L=1;vis[i]=1;
			for(int j=a[i];j!=i;j=a[j])vis[j]=1,++L;
			cnt[L]++;
		}
	for(int i=1;i<=n;++i)if(cnt[i]){
		int t=2;if(i==1||(i%2==0))t=1;
		int u=1,v=t;
		for(int j=2;j<=cnt[i];++j){
			int w=((ll)u*(j-1)%mod*i+(ll)v*t)%mod;
			u=v;v=w;
		}
		ans=(ll)ans*v%mod;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1920
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()

	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = ri()
	}

	h = append([]int{-1}, h...)
	ok := true
	for i := 1; i < len(h); i++ {
		switch {
		case h[i-1] > h[i]:
			ok = false
			break
		case h[i-1] < h[i]:
			h[i]--
		}
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 2304
import java.util.Scanner;

class Main{
  public static void main(String[] arg){
  	int a, b, c, cnt=0;
  	Scanner in = new Scanner(System.in);
  	a = in.nextInt();
  	b = in.nextInt();
  	c = in.nextInt();
  	for(int i=a; i<=b; i++){
  		if(c/i > 0 && c%i == 0){
  			cnt++;
  		}
  	}
  	System.out.println(cnt);
	}
}

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

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/

ll gd(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

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




int main(void){
    const ll M = 1000000007;
    ll n;
    ll ans;
    string s;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)cin >> a[i];
    sort(a,a+n);
    ll bob = 0;
    ll alice = 0;
    ll cnt = 1;
    for(ll i = n-1; i >= 0; i--){
        if(cnt % 2 == 1)alice += a[i];
        else bob += a[i];
        cnt++;
    }
    ans = alice - bob;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cassert>

using namespace std;

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

    vector<set<int>> G(n);
    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b;
        G[a - 1].insert(b - 1);
        G[b - 1].insert(a - 1);
    }
   
    vector<int> vis(n);
    
    deque<int> q;
    for (int i = 0; i < n; ++i) {
        if (G[i].size() <= 1) {
            q.push_back(i);
            vis[i] = true;
        }
    }

    auto remove_edge = [&G](int a, int b) {
        G[a].erase(b);
        G[b].erase(a);
    };

    while (!q.empty()) {
        int node = q.front();
        q.pop_front();
       
        if (vis[node] == 2) continue;
        if (G[node].empty()) {
            cout << "First" << endl;
            return 0;
        }


        int parent = *G[node].begin();
        vis[parent] = 2;

        remove_edge(node, parent);
        
        while (G[parent].size()) {
            int vec = *G[parent].begin();
            remove_edge(parent, vec);
            
            if (G[vec].size() <= 1 && vis[vec] == 0) {
                q.push_back(vec);
            }
        }
    }

    cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 12672
#include <stdio.h>
#include <string.h>

typedef int DICE[6];

int cmp_dice(DICE a, DICE b)
{
  DICE c;
  memcpy(c, b, sizeof(int)*6);
  for (int i=0; i<4; i++) {
    c[0] = b[1];
    c[4] = b[0];
    c[5] = b[4];
    c[1] = b[5];
    memcpy(b, c, sizeof(int)*6);
    for (int j=0; j<4; j++) {
      c[1] = b[3];
      c[2] = b[1];
      c[4] = b[2];
      c[3] = b[4];
      memcpy(b, c, sizeof(int)*6);
      for (int k=0; k<4; k++) {
	c[0] = b[1];
	c[4] = b[0];
	c[5] = b[4];
	c[1] = b[5];
	memcpy(b, c, sizeof(int)*6);
	if (memcmp(a, b, sizeof(int)*6)==0) return 1;
      }
    }
  }
  return 0;
}

int main()
{
  int n;
  fscanf(stdin, "%d", &n);
  DICE dd[n];

  for (int i=0; i<n; i++)
    for (int j=0; j<6; j++)
      fscanf(stdin, "%d", &dd[i][j]);

  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      if (cmp_dice(dd[i], dd[j])) {
	puts("No");
	return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {

	int a, b, c;

	scanf("%d %d %d", &a, &b, &c);

	if( (a == b) && (b != c)) {
		printf("Yes\n");
		return 0;
	}
	if( (b == c) && (a != c)){
		printf("Yes\n");
		return 0;
	}
	if( (c == a) && (b != a) ){
		printf("Yes\n");
		return 0;
	}

	printf("No\n");

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
    char input[1000],w[10];
    int count=0;
    scanf("%s",w);
    while(1){
        scanf("%s",input);
        if(!strcmp(input,"END_OF_TEXT")){
            break;
        }
        for(int i=0; input[i] != '\0'; i++){
            input[i] = tolower(input[i]);
        }
        if(!strcmp(w,input)){
            count++;
        }
    }
    printf("%d\n",count);
}


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

int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0) cout << 1 << endl;
  if (b == 0) cout << 2 << endl;
  if (c == 0) cout << 3 << endl;
  if (d == 0) cout << 4 << endl;
  if (e == 0) cout << 5 << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vp a,b,c;

int main(){
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int x=0,mx=0;
		for(auto c:s){
			if(c=='(') x++;
			else x--;
			mx=min(mx,x);
		}
		sum+=x;
		if(x>0) a.push_back({x,mx});
		else if(x==0) b.push_back({x,mx});
		else c.push_back({x,mx});
	}
	sort(a.begin(),a.end(),[](P p,P q){
		return p.second>q.second;
	});
	sort(c.begin(),c.end(),[](P p,P q){
		return p.first-p.second>q.first-q.second;
	});
	sum=0;
	bool B=1;
	for(auto p:a){
		if(sum+p.second<0) B=0;
		sum+=p.first;
	}
	for(auto p:b){
		if(sum+p.second<0) B=0;
		sum+=p.first;
	}
	for(auto p:c){
		if(sum+p.second<0) B=0;
		sum+=p.first;
	}
	cout<<(B&&!sum?"Yes":"No")<<endl;
}

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

int main() {
  int N;
  cin >> N;
  
 
 
  if((N/10)%111 == 0 || (N%1000) % 111 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	VI a(4); rep(i,4) cin>>a[i]; sort(ALL(a));
	if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

west_nums_from_west = [0]
east_nums_from_east = []
east_nums_from_east[N-1] = 0

for i in 1...N
  west_nums_from_west[i] = west_nums_from_west[i-1]
  if S[i-1]=='W'
    west_nums_from_west[i] += 1
  end
end

(N-2).downto(0) do |i|
  east_nums_from_east[i] = east_nums_from_east[i+1]
  if S[i+1]=='E'
    east_nums_from_east[i] += 1
  end
end

puts (0...N).map {|i|
  west_nums_from_west[i] + east_nums_from_east[i]
}.min


Measured memory_bytes: 10380
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String[] lines = sc.nextLine().split(" ");
			int num1 = Integer.parseInt(lines[0]);
			int num2 = Integer.parseInt(lines[2]);
			int ans = 0;
			if(lines[1].equals("+")) {
				ans = num1 + num2;
			} else if(lines[1].equals("-")) {
				ans = num1 - num2;
			} else if(lines[1].equals("*")) {
				ans = num1 * num2;
			} else if(lines[1].equals("/")) {
				ans = num1 / num2;
			} else {
				break;
			}
			System.out.println(ans);
		}

	}
}

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

int main() {
    string s, t;
    cin >> s >> t;
    ll ans = s.size();
    rep(i,s.size()-t.size()+1) {
        string tmp = s.substr(i,t.size());
        ll cnt = 0;
        rep(j,t.size()) if (tmp[j] != t[j]) cnt++;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
var
	N,k:int64;
	i,u,v,es:Longint;
	VV,nxt,beg:Array[1..400000]of Longint;
	ans:Array[1..200000]of int64;
	cnt,c:Array[1..200000]of Longint;
function dfs(u,p:Longint):Longint;
var
	ret,sto,pre,id,t:Longint;
	k:int64;
begin
	ret:=1;
	sto:=cnt[c[u]];
	pre:=sto;
	id:=beg[u];
	while id<>0 do begin
		if VV[id]<>p then begin
			t:=dfs(VV[id],u);
			inc(ret,t);
			k:=t-(cnt[c[u]]-sto);
			sto:=cnt[c[u]];
			dec(ans[c[u]],k*(k+1)div 2);
		end;
		id:=nxt[id];
	end;
	cnt[c[u]]:=pre+ret;
	dfs:=ret;
end;
begin
	read(N);
	for i:=1 to N do read(c[i]);
	for i:=2 to N do begin
		read(u,v);
		inc(es);
		VV[es]:=v;
		nxt[es]:=beg[u];
		beg[u]:=es;
		inc(es);
		VV[es]:=u;
		nxt[es]:=beg[v];
		beg[v]:=es;
	end;
	dfs(1,0);
	for i:=1 to N do begin
		inc(ans[i],N*(N+1)div 2);
		k:=N-cnt[i];
		dec(ans[i],k*(k+1)div 2);
		writeln(ans[i]);
	end;
end.


Measured memory_bytes: 24392
N,M,K=map(int,input().split())
c=[0 for i in range(N*M)]
c[1]=1
c[0]=1
mod=10**9+7
for i in range(1,N*M-1):
  c[i+1]=(i+1)*c[i]%mod
def comb(a,b):
  return c[a]*pow(c[b],mod-2,mod)*pow(c[a-b],mod-2,mod)%mod
ans=0
for i in range(N):
  ans+=i*(N-i)*pow(M,2)
  ans%=mod
for i in range(M):
  ans+=i*(M-i)*pow(N,2)%mod
  ans%=mod
ans*=comb(N*M-2,K-2)

ans%=mod
print(ans)

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

int main() {
        int n, k;
        string s;
        cin >> n >> k;
        cin >> s;
        k--;

        if (s[k] >= 'A' && s[k] <= 'Z') {
                s[k] = s[k] += 'a' - 'A';
        }
        cout << s << endl;
        return 0;
}


Measured memory_bytes: 3624
main = do
    l <- getLine
    let (a:b:[]) = map read $ words l :: [Int]
    putStrLn $ a `compare'` b

compare' :: Int -> Int -> String
compare' a b
    | ordering == LT = "a < b"
    | ordering == EQ = "a == b"
    | ordering == GT = "a > b"
    where ordering = a `compare` b


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 9;

int _;

//========================================================================
struct node
{
    int num,val;
}x[maxn],y[maxn];
int cmp(node a,node b)
{
    return a.val>b.val;
}
// map<map<int,int>,int>mp;
map<int,map<int,int> >mp;
vector<int>vx,vy;
//========================================================================
int main()
{
    int h,w,k,v,u;
    scanf("%d%d",&h,&w);
    scanf("%d",&k);
    for(int i=1;i<=k;i++)
    {
        scanf("%d%d",&u,&v);
        x[u].val++;
        y[v].val++;
        x[u].num=u;
        y[v].num=v;
        mp[u][v]++;
    }
    node maxx,maxy;
    maxx.val=0;
    maxx.num=0;
    maxy.val=0;
    maxy.num=0;
    for(int i=1;i<=h;i++) 
    {
        if(x[i].val>maxx.val)
        {
            maxx.val=x[i].val;
            maxx.num=x[i].num;
        }
    }
    for(int i=1;i<=w;i++) 
    {
        if(y[i].val>maxy.val)
        {
            maxy.val=y[i].val;
            maxy.num=y[i].num;
        }
    }
    for(int i=1;i<=h;i++) 
    {
        if(x[i].val==maxx.val)
        {
            vx.push_back(i);
        }
    }
    for(int i=1;i<=w;i++) 
    {
        if(y[i].val==maxy.val)
        {
            vy.push_back(i);
        }
    }
    int lenx=vx.size();
    int leny=vy.size();
    int flag=0;
    for(int i=0;i<lenx;i++)
    {
        for(int j=0;j<leny;j++)
        {
            if(mp[vx[i]][vy[j]]==0) 
            {
                flag=1;
                break;
            }
        }
    }
    int ans=maxx.val+maxy.val;
    if(!flag) ans--;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 66552
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  long long int ans = max(0, A[0] - x);
  A[0] = min(x, A[0]);
  for(int i = 1; i < N; ++i){
    if(A[i] + A[i-1] > x){
      ans += A[i] + A[i-1] - x;
      A[i] = max(0, x - A[i-1]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int N; cin>>N;
    vector<int> h(N,0);
    for(int i = 0; i < N; i++) cin>>h[i];
    vector<int> dp(N, 0);
    dp[1] = dp[0] + abs(h[0]-h[1]);
    for(int i = 2; i < N; i++){
	dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1024
import sys

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])

def main():
    N,Q = LI()
    node=[[] for _ in range(N)]
    flag = [True for _ in range(N)]
    for _ in range(N-1):
        a,b = LI()
        node[a-1].append(b-1)
        node[b-1].append(a-1)

    counter = [0] * N
    for _ in range(Q):
        p,x = LI()
        counter[p-1] += x

    que = [[0,0]]
    while que:
        a,c = que.pop()
        flag[a]=False
        counter[a]+=c
        for b in node[a]:
            if flag[b]:
                que.append([b,counter[a]])

    r = [counter[i] for i in range(N)]

    return(" ".join(map(str,r)))

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 134264
def main():
    n = int(input())
    d_lst = list(map(int, input().split()))
    sum_d_lst = sum(d_lst)
    ans = 0

    for i in range(n):
        ans += d_lst[i] * (sum_d_lst - d_lst[i])

    print(ans // 2)


if __name__ == "__main__":
    main()


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

typedef long long ll;
#define pb push_back

// int gcd(int a, int b) {   if (b == 0) return a; return gcd(b, a % b);  }
// int lcm(int a,int b){return a/gcd(a,b)*b;}

int main(){
    int n,d,count=0,x,y;
    cin>>n>>d;
    while(n--){
        cin>>x>>y;
        long double dis = pow((pow(x,2)+pow(y,2)),0.5);
        if(dis<=d) ++count;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 4256
/**
 *      AGC 26 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-10 23:51:07
**/

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int count = 0;

    for (int i = 0; i < N - 1; ++i) {
        if (a[i] == a[i + 1]){
            ++count; a[i + 1] = 0;
        }        
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int H,W;
    int i,j;

    while(1){
        scanf("%d %d",&H,&W);

        if(H == 0 && W == 0){
            break;
        }else{

            for(i = 0; i < H; i++){
                for(j = 0; j < W; j++){
                    if(i == 0 || i == H - 1 
                            || j == 0 || j == W  - 1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }                           //end H
                printf("\n");
            } 
            printf("\n");                   //end W

        }                                   //end if


    }                                       //end while

    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;
//isPrime
//modpow modinv
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
      a = a * a % mod;
      n >>= 1;
    }
        return res;
}

long long modinv(long long a,long long mod){
  return modpow(a,mod-2,mod);
}

long long int modfact(long long int n,long long int mod){
  if(n){
    return n*modfact(n-1,mod)%mod;
    }else{
      return 1;
    }
}
int main() {
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  cout << modfact(n,MOD) << endl;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = ReadLongs();
            var N = inputs[0];
            var K = inputs[1];
            var S = ReadText();

            var startHappiness = 0L;
            for (int i = 0; i < N; i++)
            {
                switch (S[i])
                {
                    case 'L':
                        if (i != 0 && S[i - 1] == 'L')
                        {
                            startHappiness++;
                        }
                        break;
                    case 'R':
                        if (i != N - 1 && S[i + 1] == 'R')
                        {
                            startHappiness++;
                        }
                        break;
                }
            }

            return Math.Min(N - 1, startHappiness + 2 * K);
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using namespace std;

int main(){
    vector<int> S(3);
    for(int i=0;i<3;i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end(),greater<int>());
    cout << S.at(0) * 10 + S.at(1) + S.at(2) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a,b,c,temp,i,j;
    
    scanf("%d",&i);
    for(j=0;j<i;j++){
        scanf("%d %d %d",&a,&b,&c);
        
        if(a>b){
            temp=a;a=b;b=temp;
        }if(b>c){
            temp=b;b=c;c=temp;
        }if(a>b){
            temp=a;a=b;b=temp;
        }
        
        if(a*a+b*b==c*c){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return(0);
}


Measured memory_bytes: 2040
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B, C, X; cin >> A >> B >> C >> X;

	int ans = 0;
	REP(i,A+1){
		REP(j,B+1){
			REP(k,C+1){
				if(500*i+100*j+50*k == X) ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    if(k*2-1<=n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}

struct edge{int v,next;}vs[N];
int st[N],ee,n,m,A[N],B[N],vis[N];
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline bool check(int x)
{
	for(int i=st[x];i;i=vs[i].next)
		if(!vis[vs[i].v]) return 0;
	return 1;
}
int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++)
	{
		int u=read(), v=read();
		addedge(u,v); addedge(v,u);
	}
	int S=1,T=vs[st[1]].v;
	vis[S]=1; vis[T]=1;
	while(1)
	{
		if(check(S)) break;
		for(int i=st[S];i;i=vs[i].next)
		{
			if(vis[vs[i].v]) continue;
			A[++A[0]]=S; S=vs[i].v; vis[S]=1;
			break;
		}
	}
	while(1)
	{
		if(check(T)) break;
		for(int i=st[T];i;i=vs[i].next)
		{
			if(vis[vs[i].v]) continue;
			B[++B[0]]=T; T=vs[i].v; vis[T]=1;
			break;
		}
	}
	printf("%d\n",A[0]+B[0]+2);
	printf("%d ",S); for(int i=A[0];i>=1;i--) printf("%d ",A[i]);
	for(int i=1;i<=B[0];i++) printf("%d ",B[i]); printf("%d\n",T);
	return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int MAXN=110,MAXM=1e5+10,MOD=1000000000+7;
int read()
{
	int a=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		a=a*10+ch-'0';
		ch=getchar();
	}
	return a*f;
}
void file(string s){freopen((s+".in").c_str(),"r",stdin),freopen((s+".out").c_str(),"w",stdout);}
int n,k;
int f[MAXN][MAXM],s[MAXN][MAXM];
signed main()
{
//	file("");
	n=read(),k=read();
	for(int i=1;i<=k;++i){
//		s[i][0]=1;
		s[0][i]=1;
	}
	s[0][0]=1;
	for(int i=1;i<=n;++i){
		f[i][0]=s[i][0]=1;
		int a=read();
//		cout<<i<<endl;
		for(int j=1;j<=k;++j){
			if(j>a){
				f[i][j]=(s[i-1][j]-s[i-1][j-a-1]+MOD)%MOD;
			}else{
				f[i][j]=s[i-1][j]%MOD;
			}
			s[i][j]=(s[i][j-1]+f[i][j])%MOD;
//			cout<<i<<' '<<j<<' '<<f[i][j]<<' '<<s[i][j]<<endl;
		}
//		cout<<i<<' '<<s[i][k]<<endl;
	}
	cout<<f[n][k]%MOD<<endl;
	return 0;
}


Measured memory_bytes: 160000
def Libra(a , b , c , d):

    ans = ""

    if a + b == c + d:
        ans = "Balanced"
    elif a + b > c + d:
        ans = "Left"
    else:
        ans = "Right"
    
    return ans

def main():
    a , b , c , d = map(int , input().split())
    print(Libra(a , b , c , d))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, ll> psl;
typedef pair<pii, int> tri;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<tri> viii;
 
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<string, int> msi;
typedef map<string, vi> msv;
typedef unordered_map<int, int> umap;
typedef unordered_map<ll, ll> umapl;
typedef priority_queue<int> pq;

#define fi(i,a,b) for(auto i=a;i<b;i++)
#define fd(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ss second
#define ff first
#define sz(a) a.size()
#define cini(a) int a; cin >> a;
#define cinii(a, b) int a, b; cin >> a >> b;
#define ciniii(a, b, c) int a, b, c; cin >> a >> b >> c;
#define cinl(a) ll a; cin >> a;
#define cinll(a, b) ll a, b; cin >> a >> b;
#define cinlll(a, b, c) ll a, b, c; cin >> a >> b >> c;
#define cinc(c) char c; cin >> c;
#define cins(s) string s; cin >> s;
#define cinss(s1, s2) string s1, s2; cin >> s1 >> s2;
#define cinvi(v, n) vi v(n, 0); fi(i, 0, n) cin >> v[i];
#define cinvl(v, n) vl v(n, 0); fi(i, 0, n) cin >> v[i];
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define flush fflush(stdout)

#define print(v) for (auto it = v.begin(); it != v.end(); ++it) cout << *it << ' '; cout << endl;
#define print2(v) for (auto it = v.begin(); it != v.end(); ++it) cout << *it << endl;
#define printmap(m) for (auto it = m.begin(); it != m.end(); ++it) cout << it->first<<' '<<it->second << endl; cout << endl;
#define disparr(arr,n) for(ll i=0;i<(n);++i)   cout<<arr[i]<<' ';  cout<<endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

#define LC(i) 2*(i)+1
#define RC(i) 2*(i)+2
#define MID(i,j) ((i)+(j))/2
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))

#define nn "\n"
#define sp << " " <<
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const int MOD = 1000000007;
const ll INF = 1e18;
const ld PI=3.141592653589793238462643383279502884197169399375105820974944;

int main()
{
	fastio; //Remove for interactive problems

	cinll(n, d);
	ll ans = 0;
	while(n--)
	{
		cinll(x, y);
		// cout << "Here: " << x sp y << endl;
		double temp = sqrt( (double)(x*x) + (double)(y*y));
		// cout << temp << endl;
		if(temp <= d)
			ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  int k = s.size();
  outl(ctos(s[0]) + to_string(k - 2)  + ctos(s[k - 1]));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int n;
string str;
Int cnt[412];
int main(){
  cin >> n >> str;
  int r = 0;
  for(int i = 0;i < n;i++){
    cnt[str[i]]++;
  }
  Int res = 1;
  for(int i = 'a';i <= 'z';i++){
    res = (res * (cnt[i] + 1)) % MOD;
  }
  res--;
  if(res < 0)res += MOD;
  cout << res << endl;
  
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for(int i=0; i<N; i++){
        cin >> P[i];
    }
    for(int i=0; i<N; i++){
        cin >> Q[i];
    }

    map<vector<int>, int> order_num;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        A[i] = i+1;
    }

    int i = 1;
    do{
        order_num[A]=i;
        i++;
    }while(next_permutation(A.begin(), A.end()));

    cout << abs(order_num[P]-order_num[Q]) << endl;

    return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

typedef struct team{

    int id;
    int belongs;
    int AC;
    int penalty;

}TEAM;

bool comp(const TEAM& a,const TEAM& b){

    if(a.AC == b.AC && a.penalty == b.penalty){/*AC数もペナルティも同じ場合はID順*/
        return a.id > b.id;
    }else if(a.AC == b.AC){
        return a.penalty > b.penalty;
    }else{
        return a.AC < b.AC;
    }
}




int main(){

    int n;
    while(cin >> n){

        int I,U,A,P;
        vector<TEAM> arr(n);

        int total_accept_team = 0;/*通過したチーム*/
        vector<int> ac_team_of_each_team(1001,0);


        REP(i,n){
            cin >> arr[i].id >> arr[i].belongs >> arr[i].AC >> arr[i].penalty;
        }

        /*昇順ソート*/
        sort(arr.begin(),arr.end(),comp);
        /*降順に直す*/
        reverse(arr.begin(),arr.end());

        REP(i,n){

            if(total_accept_team < 10){

                if(ac_team_of_each_team[arr[i].belongs] < 3){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }

            }else if(total_accept_team >= 10 && total_accept_team < 20){

                if(ac_team_of_each_team[arr[i].belongs] < 2){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }
            }else if(total_accept_team >= 20 && total_accept_team < 26){

                if(ac_team_of_each_team[arr[i].belongs] == 0){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }

            }
        }
    }
    return 0;
}




Measured memory_bytes: 3148