akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;

bool same_all(string str) {
	char c = str[0];
	for (int i = 1; i < str.length(); i++) {
		if (str[i] != c) {
			return false;
		}
	}
	return true;
}

bool check(std::vector<string> v, string str) {
	for (std::vector<string>::iterator itr = v.begin(); itr != v.end(); ++itr) {
		if (*itr == str) {
			return true;
		}
	}
	return false;
}

string rev_str(string str) {
	string res;
	for (int i = 0; i < str.length(); i++) {
		res += str[str.length()-i-1];
	}
	return res;
}

int main(void) {
	int n;
	cin >> n;
	string str;
	getline(cin, str);


	for (int i = 0; i < n; i++) {
		getline(cin, str);
		int len = str.length();
		int count = 0;
		std::vector<string> v;

		if (same_all(str)) {
			count = 1;
		} else {
			for (int j = 1; j < len; j++) {
				string str1,str2;
				str1 = str.substr(0, j);
				str2 = str.substr(j, len-1);
				string str3 = rev_str(str1);
				string str4 = rev_str(str2);

				if (!check(v, str1+str2)) {
					v.push_back(str1+str2);
					count++;
				}
				if (!check(v, str2+str1)) {
					v.push_back(str2+str1);
					count++;
				}
				if (!check(v, str1+str4)) {
					v.push_back(str1+str4);
					count++;
				}
				if (!check(v, str4+str1)) {
					v.push_back(str4+str1);
					count++;
				}
				if (!check(v, str2+str3)) {
					v.push_back(str2+str3);
					count++;
				}
				if (!check(v, str3+str2)) {
					v.push_back(str3+str2);
					count++;
				}
				if (!check(v, str3+str4)) {
					v.push_back(str3+str4);
					count++;
				}
				if (!check(v, str4+str3)) {
					v.push_back(str4+str3);
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;

  // 奇数が立ち、偶数が逆立ち
  vector <int> sum;

  // 計算の都合上、最初に0を入れる
  sum.push_back(0);

  char pre_updown = '0'; // 0:stand, 1:updown
  int continue_cnt = 0;

  for (int i = 0; i < N; i++) {
    char updown = S[i];
    if (updown != pre_updown) {
      sum.push_back(sum[sum.size()-1] + continue_cnt);

      pre_updown = updown;
      continue_cnt = 1;
    } else {
      continue_cnt += 1;
    }
  }

  // last
  sum.push_back(sum[sum.size()-1] + continue_cnt);

  // 計算の都合上、最後に+0を入れる
  sum.push_back(sum[sum.size()-1]+0);

  int ans = 0;

  for (int st = 0; st < sum.size(); st+=2) {
    int en = min(st+K+K, (int)sum.size()-1);
    ans = max(ans, sum[en]-sum[max(st-1,0)]);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int N,M,C;
	cin>>N>>M>>C;
	int A[N][M],B[M];
	for(int i=0;i<M;++i)cin>>B[i];
	for(int i=0;i<N;++i){
		for(int j=0;j<M;++j){
			cin>>A[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<N;++i){
		int tmp=0;
		for(int j=0;j<M;++j){
			tmp+=A[i][j]*B[j];
		}
		if(tmp+C>0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if (S.matches("A[a-z]+C[a-z]+")) {
            System.out.println("AC");
        } else {
            System.out.println("WA");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		
		int[] w = sc.nextIntArray(n);
		
		int[] s1 = new int[n+1];
		int[] s2 = new int[n+1];
		
		s1[0] = w[0];
		s2[0] = w[n-1];
		
		for(int i = 1; i < n; i++) {
			s1[i] = w[i]+s1[i-1];
		}
		
		for(int i = n-1; i >= 0; i--) {
			s2[i] = w[i]+s2[i+1];
		}
		
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i<  n-1; i++) {
			min = Math.min(Math.abs(s1[i] - s2[i+1]), min);
		}

		out.println(min);
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static int lcm(int a, int b) {
		return a / gcd(a, b) * b;
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		string s,t;
		cin>>s>>t;
		int ans=0;
		FOR(i,0,s.size())
		{
			if(s[i]!=t[i])
			ans++;
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n; cin >> n;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  int m; cin >> m;
  vector<string> t(m);
  REP(i, m) cin >> t[i];
  int mx = 0;
  REP(i, n) {
    int cnt = count(s.begin(), s.end(), s[i]) - count(t.begin(), t.end(), s[i]);
    mx = max(cnt, mx);
  }
  cout << mx << endl;
  return 0;
}

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

int main(void)
{   
    int k;
    string s;

    cin >> k >> s;

    if(s.length() <= k){
        cout << s << endl;
    }else{
        s = s.erase(k) + "...";
        cout << s << endl;
    }
}

Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<cstring>

namespace Cao
{
	typedef long long ll;
	const int N=52,MOD=1000000007;
	ll inv(int x){return x==1?1:(-(MOD/x)*inv(MOD%x)%MOD);}
	inline void inc(int a,int &b){b=(a+b)%MOD;}
	inline int abs(int x){return x<0?-x:x;}

	int fact[N],ifact[N];
	int *f[N],t0[N*N*2];

	int n;

	void dp()
	{
		f[1][0]=f[1][-1]=1;
		for(int i=1;i<n;i++)
			for(int j=-n;j<=n;j++)
			{
				int v=f[i][j];
				if(!v)continue;

				for(int a=0;i+a<=n;a++)
					for(int b=0;i+a+b<=n;b++)
					{
						if(abs(j)>abs(a+b) || a+b==0)continue;

						int k=j+a-b;

						if(k&1)continue;
						inc((ll)v*ifact[a]%MOD*ifact[b]%MOD,f[i+a+b][k/2]);
					}
			}
	}
	void solve()
	{
		for(int i=0;i<N;i++)f[i]=t0+(i-1)*N*2+N;
		fact[0]=1;
		for(int i=1;i<N;i++)fact[i]=(ll)fact[i-1]*i%MOD;
		ifact[N-1]=(inv(fact[N-1])+MOD)%MOD;
		for(int i=N-1;i;i--)ifact[i-1]=(ll)ifact[i]*i%MOD;

		scanf("%d",&n);
		dp();
		printf("%lld\n",(ll)f[n][0]*fact[n]%MOD);
	}
}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
double a, b, x;
cin >> a >> b;
x = (a + b) / 2;
int ans;
if (x == int(x)) ans = x;
else if (x > int(x)) ans = x + 1;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(void){
  int a;
  cin>>a;
  if(a==25){
    cout<<"Christmas"<<endl;
  }else if(a==24){
    cout<<"Christmas Eve"<<endl;
  }else if(a==23){
    cout<<"Christmas Eve Eve"<<endl;
  }else{
    cout<<"Christmas Eve Eve Eve"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

const ll MODULO = 1000000007;
// 負の数の剰余
ll mod_minus(ll x, ll modval) {
    if (x >= 0) {
        return x % modval;
    } else {
        ll mm = ((-x) % modval);
        if (mm == 0) {
            return 0;
        } else {
            return modval - mm;
        }
    }
}

ll mod_pow(ll x, ll n, ll modval) {
    if (n == 0) {
        return 1;
    }
    ll res = mod_pow(x * x % modval, n / 2, modval);
    if (n & 1) {
        res = res * x % modval;
    }
    return res;
}

ll pow(ll x, ll n) {
    return mod_pow(x, n, MODULO);
}
// 法が固定の場合 (競プロでよくある)
ll mod(ll x) {
    return mod_minus(x, MODULO);
}

vector<ll> makedivprimes(ll n) {
    // エラトステネスの篩
    vector<ll> divprimes(n + 1, -1);
    vector<bool> isprime(n + 1, true);
    isprime[0] = false;
    isprime[1] = false;
    for (ll i = 2; i <= n; i++) {
        if (isprime[i]) {
            divprimes[i] = i;
            for (ll j = 2 * i; j <= n; j += i) {
                divprimes[j] = i;  // その数をふるい落とした素数を記録
                isprime[j] = false;
            }
        }
    }
    return divprimes;
}

void fact(ll cur, ll i, vector<ll> &pfs, set<ll> &fac) {
    if (i == pfs.size()) {
        fac.insert(cur);
        return;
    }
    fact(cur * pfs[i], i + 1, pfs, fac);
    fact(cur, i + 1, pfs, fac);
}
set<ll> factors_fast(ll n, vector<ll> &divprimes) {
    // n < divprimes.size() であること.
    vector<ll> result;
    ll ni = n;
    while (ni >= 2) {
        ll p = divprimes[ni];
        result.push_back(p);
        ni = ni / p;
    }
    set<ll> fac;
    fact(1, 0, result, fac);
    return fac;
}

int main() {
    ll N, K;
    cin >> N >> K;
    auto divprimes = makedivprimes(100005);
    vector<set<ll>> facts(100003);
    for (ll i = 2; i <= 100002; i++) {
        facts[i] = factors_fast(i, divprimes);
    }
    facts[1].insert(1);

    // for (ll i = 2; i <= 16; i++) {
    //     for (auto j : facts[i]) {
    //         print(i, j, "fact");
    //     }
    // }

    ll total = 0;
    vector<ll> subs(100005, 0);
    for (ll i = K; i >= 1; i--) {
        ll val = K / i;
        ll cnt = pow(val, N);
        //print(i, cnt, subs[i]);
        ll add = (cnt - subs[i]);
        total = mod(total + add * i);
        for (auto f : facts[i]) {
            if (f != i) {
                subs[f] = mod(subs[f] + add);
            }
        }
    }
    print(total);
}


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

int main(void)
{
    int n,initialScore,question,i,player;
    scanf("%d %d %d",&n,&initialScore,&question);
    int *correct=(int*)malloc(sizeof(int)*(n+1));
    for(i=0;i<n+1;i++) correct[i]=0;
    for(i=0;i<question;i++)
    {
        scanf("%d",&player);
        correct[player]++;
    }
    for(i=1;i<n+1;i++)
    {
        if(correct[i]-question+initialScore>0) printf("Yes\n");
        else printf("No\n");
    }
    free(correct);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
      
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int k,x;
  cin>>k>>x;

  if(500*k>=x) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n;
    cin >> n;
    vector<ll>a(n);
    double ans =0;
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        if(a.at(i)==0){
            cout<<0<<endl;
            return 0;
        }
        ans+=log10(a.at(i));
    }
    if(ans>18){
        cout<<-1<<endl;
        return 0;
    }
    ll che = 1;
    ll d = 1e18;
    for(int i=0;i<n;i++){
        che*=a.at(i);
        if(che>d){
            cout << -1<<endl;
            return 0;
        }
    }
    cout << che << endl;
}
    



Measured memory_bytes: 4116
n = int(input())
numbers = map(int, input().split())

even_numbers = []
for i in numbers:
  if i % 2 == 0:
    even_numbers.append(i)

answers = []
for i in even_numbers:
  if i % 3 == 0 or i % 5 == 0:
    answers.append(i)

if even_numbers == answers:
  print('APPROVED')
else:
  print('DENIED')


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

signed main() {
	int n;
	cin >> n;
	if(n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int a[1000];
signed main(){
    int n,sum = 0;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }   
    sort(a,a+n,greater<int>());
    if(a[0] >= sum - a[0]) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
flag = False
i=0
j=0
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            a = 0
            while A[i+a][j:j+M]==B[a]:
                if a == M-1:
                    flag = True
                    break
                a += 1
            if flag:
                break
    if flag:
            break
                
if flag == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
import java.util.Scanner;
public class Main{
    int kazu;
     
    public void solve(){
        Scanner sc = new Scanner(System.in);
        kazu = sc.nextInt();
        System.out.println(kazu*kazu*kazu);
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17156
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
input=lambda :sys.stdin.buffer.readline().rstrip()
class ModInt(object):
    __MOD=10**9+7

    def __init__(self,x):
        self.__x=x%self.__MOD

    def __repr__(self):
        return str(self.__x)

    def __add__(self,other):
        return ModInt(self.__x+other.__x) if isinstance(other,ModInt) else ModInt(self.__x+other)

    def __sub__(self,other):
        return ModInt(self.__x-other.__x) if isinstance(other,ModInt) else ModInt(self.__x-other)

    def __mul__(self,other):
        return ModInt(self.__x*other.__x) if isinstance(other,ModInt) else ModInt(self.__x*other)

    def __truediv__(self,other):
        return ModInt(self.__x*pow(other.__x,self.__MOD-2,self.__MOD)) if isinstance(other, ModInt) else ModInt(self.__x*pow(other, self.__MOD-2,self.__MOD))

    def __pow__(self,other):
        return ModInt(pow(self.__x,other.__x,self.__MOD)) if isinstance(other,ModInt) else ModInt(pow(self.__x,other,self.__MOD))

    __radd__=__add__

    def __rsub__(self,other):
        return ModInt(other.__x-self.__x) if isinstance(other,ModInt) else ModInt(other-self.__x)

    __rmul__=__mul__

    def __rtruediv__(self,other):
        return ModInt(other.__x*pow(self.__x,self.__MOD-2,self.__MOD)) if isinstance(other,ModInt) else ModInt(other*pow(self.__x,self.__MOD-2,self.__MOD))

    def __rpow__(self,other):
        return ModInt(pow(other.__x,self.__x,self.__MOD)) if isinstance(other,ModInt) else ModInt(pow(other,self.__x,self.__MOD))
def resolve():
    from itertools import product
    L,R=map(int,input().split())
    D=61
    dp=[[[[ModInt(0)]*2 for _ in range(2)] for _ in range(2)] for _ in range(D+1)]
    dp[D][0][0][0]=ModInt(1)
    for d in range(D-1,-1,-1):
        lb=L>>d&1; rb=R>>d&1
        for i,j,m,x,y in product([0,1],repeat=5):
            ni,nj,nm=i,j,m
            if(x>y): continue
            # i:L<=X
            if(i==0 and lb>x): continue
            if(lb<x): ni=1
            # j:Y<=R
            if(j==0 and y>rb): continue
            if(y<rb): nj=1
            # m:MSB
            if(m==0 and x!=y): continue
            if(x==1 and y==1): nm=1
            dp[d][ni][nj][nm]+=dp[d+1][i][j][m];
    print(sum(dp[0][i][j][m] for i,j,m in product([0,1],repeat=3)))
resolve()

Measured memory_bytes: 40944
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)

n,m = [int(i) for i in input().split()]

#ko = [[] for _ in range(n)]
oya = [[] for _ in range(n)]
for _ in range(m):
    x,y = [int(i)-1 for i in input().split()]
#    ko[x].append(y)
    oya[y].append(x)

memo = [-1]*n

def longest(v): #nを終点とするlongest
    if memo[v] >= 0:
        return memo[v]
    else:
        c=0
        for j in oya[v]:
            c = max(c,longest(j)+1)
        memo[v] = c
        return c

for i in range(n):
    longest(i)

print(max(memo))    
#print(memo)


Measured memory_bytes: 103984
#include <iostream>

using namespace std;

int main(){
	int A,B;
  	cin >> A >> B;
  	if(A >= 13){
    	cout << B << endl;
    }else if(A < 13 && A >= 6){
      	cout << B/2 << endl;
    }else{
      cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){

	int H[N],W[N];
	int i,j,k,l;
	int f=0,g=0;
	
	for(i=0;i<N;i++){
	
		scanf("%d %d",&H[i],&W[i]);
	
		if((H[i]==0)&&(W[i]==0)){break;}
	
	}
	
	for(j=0;j<i;j++){
		for(k=0;k<H[j];k++){
			for(l=0;l<W[j];l++){
				if((f==0)&&(g==0)){printf("#"); f=1;continue;}
				if((f==1)&&(g==0)){printf("."); f=0;continue;}
				if((f==1)&&(g==1)){printf("#"); f=0;continue;}
				if((f==0)&&(g==1)){printf("."); f=1;continue;}
			}
			printf("\n");
			if(g==0){g=1; f=0;}else{g=0; f=0;}
		}
		printf("\n");	
		f=0;
		g=0;
	}
	
	return 0;
}

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

int main(){
    int n,x; cin >> n >> x;
    int sum = 0, count = 0;
    for (int i = 1; i <= n; i++){
        int m; cin >> m;
        sum += m;
        if (sum <= x) count++;
    }

    cout << count + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
a = inp

dp = na2(n+1,2,-1e20)
dp[0][0] = 0
(n).times do |i|
  dp[i+1][0] = [dp[i][0]+a[i],dp[i][1]-a[i]].max
  dp[i+1][1] = [dp[i][0]-a[i],dp[i][1]+a[i]].max
end
p dp[n][0]



Measured memory_bytes: 18964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = (1e+9) +7;
ll mod_inverse(ll a){
  ll x = 1, n = MOD - 2;
  while(n != 0){
    if(n%2 == 1){ 
      x = (x * a) % MOD;
      n -= 1;
    }else{
      a = (a * a) % MOD;
      n /= 2;
    }        
  }
  return x;
}

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> st(2001), invst(2001);
  int tkn = n-k-1;
  int tk = k-1;
  st[0] = 1; invst[0] = 1;
  st[1] = 1; invst[1] = 1;
  for(int i=2;i<=2000;i++){
    st[i] = (i*st[i-1]) % MOD;
    invst[i] = mod_inverse(st[i]);
  }
  if( k == n){
    for(int i=1;i<=k;i++){
      if(i == 1) cout << 1 << endl;
      else cout << 0 << endl;
    }
  }else {
    for(int i=1;i<=k;i++){
      ll ans = 0;
      // 青球をi個の塊に分割する組み合わせが何パターンあるか
      // k-1の2項係数
      ll blue = (((st[tk] * invst[i-1]) % MOD) * invst[tk-i+1]) %MOD;
      // i-1個の穴を埋め,その両端分余裕がある
      // 赤球はi-1 ~ i+1個の塊
      for(int j = max(i-1,1);j <= min(i+1, n-k); j++ ){
        ll red = (((st[tkn] * invst[j-1]) % MOD) * invst[tkn-j+1]) %MOD;
        if(j == i-1 || j == i+1) ans = (ans + red * blue) % MOD;
        if(j == i) ans = (ans + 2*((red * blue) % MOD)) % MOD;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 256
/*  union_find_tree_size.cpp
    素集合系を union-find tree で管理するライブラリ
    併合時の工夫：union by size

    verified: AtCoder ABC157 D - Friend Suggestions
        https://atcoder.jp/contests/abc157/tasks/abc157_d
*/

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

/* UnionFind：素集合系管理の構造体(union by size)
    isSame(x, y): x と y が同じ集合にいるか。 計算量はならし O(α(n))
    unite(x, y): x と y を同じ集合にする。計算量はならし O(α(n))
    treeSize(x): x を含む集合の要素数。
*/
struct UnionFind {
    vector<int> size, parents;
    UnionFind() {}
    UnionFind(int n) {  // make n trees.
        size.resize(n, 0);
        parents.resize(n, 0);
        for (int i = 0; i < n; i++) {
            makeTree(i);
        }
    }
    void makeTree(int x) {
        parents[x] = x;  // the parent of x is x
        size[x] = 1;
    }
    bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
    bool unite(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) return false;
        if (size[x] > size[y]) {
            parents[y] = x;
            size[x] += size[y];
        } else {
            parents[x] = y;
            size[y] += size[x];
        }
        return true;
    }
    int findRoot(int x) {
        if (x != parents[x]) {
            parents[x] = findRoot(parents[x]);
        }
        return parents[x];
    }
    int treeSize(int x) { return size[findRoot(x)]; }
};

using ll = long long;
int main() {
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);  // Union-Find Tree で考える
    vector<int> A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A.at(i) >> B.at(i);
        A[i]--, B[i]--;
    }

    ll now = N * (N - 1) / 2;
    vector<ll> ans(M);
    for (int i = M - 1; i >= 0; i--) {
        ans[i] = now;
        if (!uf.isSame(A[i], B[i])) {
            now -= (ll)uf.treeSize(A[i]) * (ll)uf.treeSize(B[i]);
            uf.unite(A[i], B[i]);
        }
    }

    for (int i = 0; i < M; i++) {
        cout << ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 3712
def main():
    mod = 1000000007
    n = int(input())
    cnt = [0] * (n + 2)
    cnt[0] = 3
    res = 1
    for x in input().split():
        v = int(x)
        res *= cnt[v] - cnt[v + 1]
        res %= mod
        cnt[v + 1] += 1
    print(res)

main()

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

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

    if (400 <= x && x <= 599) {
        cout << 8 << endl;
    }
    else if (600 <= x && x <= 799) {
        cout << 7 << endl;
    }
    else if (800 <= x && x <= 999) {
        cout << 6 << endl;
    }
    else if (1000 <= x && x <= 1199) {
        cout << 5 << endl;
    }
    else if (1200 <= x && x <= 1399) {
        cout << 4 << endl;
    }
    else if (1400 <= x && x <= 1599) {
        cout << 3 << endl;
    }
    else if (1600 <= x && x <= 1799) {
        cout << 2 << endl;
    }
    else if (1800 <= x && x <= 1999) {
        cout << 1 << endl;
    }

    return 0;
}

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


using namespace std;
using vi=vector<int>;

void max_u(int&m, int v)
{
	if(m<v) m=v;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n);

		for(int i=0;i<n;i++) scanf("%d", &a[i]);

		vi c(100000+2);
		int ans=0;
		for(int i=0;i<n;i++)
		{
			a[i]++;
			max_u(ans, c[a[i]-1]+=1);
			max_u(ans, c[a[i]  ]+=1);
			max_u(ans, c[a[i]+1]+=1);
		}
		printf("%d\n", ans);
	}

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int  main()
{
  int a,b,i,n;

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

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

      printf("%dx%d=%d\n",i,n,
i*n);
    }

  }

  return 0;
}

Measured memory_bytes: 924
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

int a, b;
string s;

int main() {
	cin >> a >> b >> s;
	if (s[a] != '-') { cout << "No" << endl; return 0; }
	
	int i;
	rep(i, a) if (!('0' <= s[i] && s[i] <= '9')) { cout << "No" << endl; return 0; }
	rep(i, b) if (!('0' <= s[a+1+i] && s[a+1+i] <= '9')) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
def calc_e(num):
    return (num + 1) / 2

def main():
    n, k = map(int, input().split())
    dices = list(map(int, input().split()))

    current = (sum(dices[:k]) + k) / 2
    e_max = (sum(dices[:k]) + k) / 2
    for i in range(n-k):
        current = current + calc_e(dices[i+k]) - calc_e(dices[i])
        e_max = max(e_max, current)

    print(e_max)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24804
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

#define F first
#define S second
#define X first
#define Y second
#define all(c) (c).begin(),(c).end()

using namespace std;

typedef pair<int,int>P;
typedef pair<P,P> P2;

int g[110][110];

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

void dfs(int x,int y,int c){
  g[y][x]=-1;
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0 || ny<0 || 110<=nx || 110<=y)continue;
    if(g[ny][nx]!=c)continue;
    dfs(nx,ny,c);
  }
}

int main(void){

  int n;
  while(cin >> n,n){
    vector<P2>v(n);
    vector<int>x,y;
    
    for(int i=0;i<n;i++){
      cin >> v[i].F.X >> v[i].F.Y >> v[i].S.X >> v[i].S.Y;
      x.push_back(v[i].F.X);
      x.push_back(v[i].S.X);
      y.push_back(v[i].F.Y);
      y.push_back(v[i].S.Y);
    }
    
    sort(all(x));
    sort(all(y));
    
    x.erase(unique(all(x)),x.end());
    y.erase(unique(all(y)),y.end());
    
    map<int,int>mpx,mpy;
    
    for(int i=0;i<x.size();i++)mpx[x[i]]=i+1;
    for(int i=0;i<y.size();i++)mpy[y[i]]=i+1;
    
    fill(g[0],g[110],0);
    
    for(int i=0;i<v.size();i++){
      for(int j=mpx[v[i].F.X];j<mpx[v[i].S.X];j++){
	for(int k=mpy[v[i].S.Y];k<mpy[v[i].F.Y];k++){
	  g[k][j]+=(i+1);
	}
      }
    }

    int cnt=0;
    for(int i=0;i<110;i++){
      for(int j=0;j<110;j++){
	if(g[i][j]>=0)dfs(j,i,g[i][j]),cnt++;
      }
    }
    
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1844
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=b;i++)
	{if((a*i)%b==c)
	{
		cout<<"YES"<<endl;
		return 0;
	}
	}
	cout<<"NO"<<endl;
	return 0;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    string s;
    cin >> s;
    ll x = 1;
    REP(i, a, max(c, d)) {
        if (s[i] == '#' && s[i+1] == '#') {
            x = 0;
            break;
        }
    }
    if (x == 0) {
        cout << "No\n";
        return 0;
    }
    if (c < d)
        cout << "Yes\n";
    else {
        ll p = 0;
        REP(i, b-1, d) {
            if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
                p = 1;
                break;
            }
        }
        if (p)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int c=0;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])c++;
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 3916
import sys


def check(k, flag=False):
    fixed = [-1] * n
    q = [(0, k, False, None)]
    has_non_bipartite_loop = False
    while q:
        v, m, is_odd, a = q.pop()
        # print(v, m, is_odd, q, fixed)
        if fixed[v] != -1:
            p, was_odd = fixed[v]
            if is_odd == was_odd:
                if m != p:
                    return 0
                continue
            else:
                if m == p:
                    has_non_bipartite_loop = True
                    continue
                if flag:
                    return 0
                d = m - p if is_odd else p - m
                if d < 0:
                    return 0
                if d % 2:
                    return 0
                return check(k + d // 2, True)
        else:
            fixed[v] = (m, is_odd)

        for u, s in links[v]:
            if s - m < 1:
                if not is_odd:
                    return 0
                return check(k + m - s + 1, False)
            if u == a:
                continue
            q.append((u, s - m, not is_odd, v))

    if has_non_bipartite_loop:
        return 1

    min_is_odd = float('inf')
    for m, is_odd in fixed:
        if is_odd:
            min_is_odd = min(min_is_odd, m)
    return min_is_odd


n, m = map(int, input().split())
links = [set() for _ in range(n)]
for line in sys.stdin.readlines():
    u, v, s = map(int, line.split())
    u -= 1
    v -= 1
    links[u].add((v, s))
    links[v].add((u, s))
print(check(1))


Measured memory_bytes: 111876
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#define ll long long

using namespace std;

int main(){
  ll A, B, K;
  cin >> K >> A >> B;

  if (B/K - (A-1)/K >= 1) {
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

  

Measured memory_bytes: 3548
#include <iostream>
#include <stdio.h>

int main(void){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a == b){
    printf("a == b\n");
  } else if(a < b){
    printf("a < b\n");
  } else {
    printf("a > b\n");
  }
  return 0;
}



Measured memory_bytes: 3144
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define MSI map<string,int>
#define VI vector<int>
#define VII vector<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b&&b == c)cout << 1 << endl;
	else if (a == b || a == c || b == c)cout << 2 << endl;
	else cout << 3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX

ll mpow(ll a, ll b){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

void solve(){
	ll n,ga,gb,c;
	cin >> n >> ga >> gb >> c;
	ll ans=0;
	ll glfact = mpow(ga+gb,MOD-2);
	ll a[n+1],b[n+1],fact[n+1];
	a[0]=1;b[0]=1,fact[0]=mpow(glfact,n);
	forsn(i,1,n+1){
		a[i]=(a[i-1]*ga)%MOD;
		b[i]=(b[i-1]*gb)%MOD;
		fact[i]=(fact[i-1]*glfact)%MOD;
	}
	ll ncx[n];
	ncx[0]=1;
	forsn(i,1,n){
		ncx[i]=((ncx[i-1]*(n-1+i))%MOD)*mpow(i,MOD-2);
		ncx[i]%=MOD;
	}
	// forn(i,n+1){
	// 	cout << a[i] << " ";
	// }
	// cout << ln;
	// forn(i,n+1){
	// 	cout << b[i] << " ";
	// }
	// cout << ln;
	// forn(i,n){
	// 	cout << ncx[i] << " ";
	// }
	// cout << ln;
	forn(i,n){
		ans += ((((n+i)*ncx[i] % MOD)*(a[n]*b[i] % MOD) % MOD) * fact[i])%MOD;
		ans %= MOD;
	}
	// cout << ans << ln;
	// (n+i)
	forn(i,n){
		ans += ((((n+i)*ncx[i] % MOD)*(b[n]*a[i] % MOD) % MOD) * fact[i])%MOD;
		ans %= MOD;
	}
	// cout << ans << ln;
	if(c!=0){
		ans *= 100;
		ans %= MOD;
		ans *= mpow(ga+gb,MOD-2);
		ans %= MOD;
	} 
		 
	cout << ans << ln;
}


int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin >> t;
    forn(i,t) solve();
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(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;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int T;
    T=1;
    //cin>>T;
    while(T--){
    	int n,m,i,j,k;
    	cin>>n>>m>>k;
    	int r[n+1]={0},c[m+1]={0};
    	set<pii>s;
    	for(i=1;i<=k;i++)
    	{
    		int x,y;
    		cin>>x>>y;
    		r[x]++;
    		c[y]++;
    		s.insert({x,y});
		}
		int mx=0,my=0;
		for(i=1;i<=n;i++)
		{
			mx=max(mx,r[i]);
		}
		for(i=1;i<=m;i++)
		{
			my=max(my,c[i]);
		}
		vector<int>v1,v2;
		for(i=1;i<=n;i++)
		{
			if(r[i]==mx)
			v1.pb(i);
		}
		for(i=1;i<=m;i++)
		{
			if(my==c[i])
			v2.pb(i);
		}
		for(i=0;i<v1.size();i++)
		{
			for(j=0;j<v2.size();j++)
			{
				if(s.find({v1[i],v2[j]})==s.end())
				{
					cout<<mx+my;
					return 0;
				}
			}
		}
		cout<<mx+my-1;
    

    }

}

Measured memory_bytes: 23820
n,k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

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

y = 0
for a1 in a:
    for a2 in a:
        if a1 > a2: y += 1

ans = (cnt * k + y * k * (k-1)//2)%MOD
print(ans)

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

typedef long long ll;

bool isPrime(){
  
}
 
int main(){
  bool IsPrime[100001];
  for(int i=0; i<100001; i++){
    IsPrime[i] = true;
  }
  IsPrime[0] = false;
  IsPrime[1] = false;
  for(int i=0; i<100001; i++){
    if(IsPrime[i]){
      for(int j=2; i*j<100001; j++){
        IsPrime[i*j] = false;
      }
    }
  }
  int q;
  cin >> q;
  int s[100001] = {};
  for(int i=1; i<100001; i++){
    s[i] = s[i-1];
    if(IsPrime[i]){
      if(IsPrime[(i+1)/2]) s[i] = s[i-1] + 1;
    }
  }
  for(int i=0; i<q; i++){
    int l, r;
    cin >> l >> r;
    cout << s[r]-s[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
import java.lang.Math

fun main(args: Array<String>) {
    val mod = 1000000007L

    val (n, a, b) = readInputLine().split(" ").map { it.toInt() }

    val inverse = LongArray(Math.min(n, 200000) + 1)
    val factorialInverse = LongArray(Math.min(n, 200000) + 1)
    inverse[0] = 1L
    inverse[1] = 1L
    factorialInverse[0] = 1L
    factorialInverse[1] = 1L
    for (i in 2 until Math.min(n, 200000) + 1) {
        inverse[i] = (mod - inverse[mod.toInt() % i] * (mod / i.toLong()) % mod)
        factorialInverse[i] = (factorialInverse[i - 1] * inverse[i] % mod)
    }

    // 2^n
    val pow = sortedMapOf(Pair(0, 1L), Pair(1, 2L))
    var powNum = 2
    while (powNum <= n) {
        pow[powNum] = (pow[powNum / 2]!! * pow[powNum / 2]!!) % mod
        powNum *= 2
    }
    pow[powNum] = (pow[powNum / 2]!! * pow[powNum / 2]!!) % mod

    var ans = 1L

    var nTmp = n
    powNum = 1

    while (nTmp != 0) {
        if (nTmp % 2 == 1) {
            ans *= pow[powNum]!!
            ans %= mod
        }
        powNum *= 2
        nTmp /= 2
    }

    ans = (ans + mod - 1L) % mod

    var subTmp = 1L

    for (i in (n - a) + 1..n) {
        subTmp *= i.toLong()
        subTmp %= mod
    }
    subTmp *= factorialInverse[a]
    subTmp %= mod

    ans = (ans + mod - subTmp) % mod

    subTmp = 1L

    for (i in (n - b) + 1..n) {
        subTmp *= i.toLong()
        subTmp %= mod
    }
    subTmp *= factorialInverse[b]
    subTmp %= mod

    ans = (ans + mod - subTmp) % mod

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;
#define ll long long

ll INF = 1e18;

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

    vector<pair<int,int>> v1(N);
    vector<pair<int,int>> v2(N);

    for(int i = 0; i< N;i++)
    {
        int a,b;
        cin>>a>>b;
        v1[i] = make_pair(a,b);
        v2[i] = make_pair(b,a);
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    if(N%2 == 1)
    {
        int ans = v2[N/2].first - v1[N/2].first + 1;
        cout<<ans<<endl;
    }
    else
    {
        int ans = v2[N/2].first + v2[(N-1)/2].first;
        ans -= (v1[N/2].first + v1[(N-1)/2].first);
        ans++; 
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;

int main()
{
    ll x, y;
    scanf("%lld %lld", &x, &y);
    for (ll i = 0ll; i <= 60ll; i++)
    {
        if (x * (1ll << i) > y)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

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;
}
ll n, m, v, p;
const int maxn = 1e5 + 5;
int a[maxn];

bool isok(int s) {
    ll sum = 0;
    for (int i = n - 1, j = 0; i >= 0; --i) {
        if (i == s) continue;
        if (j < p - 1 || i < s) {
            sum += m;
        }else {
            if (a[s] + m < a[i]) return false;
            sum += (a[s] + m - a[i]);
        }
        ++j;
    }
    if (sum >= m * (v - 1)) return true;
    return false;
}

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    sf(n, m, v, p);
    rep(i, 0, n - 1) {
        sf(a[i]);
    }
    sort(a, a + n);
    int l = 0, r = n - 1, mid, ans;
    while (l <= r) {
        mid = (l + r) / 2;
        if (isok(mid)) {
            r = mid - 1;
            ans = mid;
        }else {
            l = mid + 1;
            ans = l;
        }
    }
    out(n - ans);
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF (1e9+7)

using namespace std;

int main(){
  int n, m;
  while(cin >> n >> m and n + m){
    vector<int> nsroad(n+1);
    vector<int> weroad(m+1);
    nsroad[0] = 0;
    weroad[0] = 0;
    REP(i, n){
      int tmp; cin >> tmp;
      nsroad[i+1] = nsroad[i] + tmp;
    }
    REP(i, m){
      int tmp; cin >> tmp;
      weroad[i+1] = weroad[i] + tmp;
    }
    int res = 0;
    map<int, int> counts;
    REP(i, nsroad.size()) REP(j, i){
      int count = 0;
      int width = nsroad[i] - nsroad[j];
      if(counts.find(width) != counts.end()) { res += counts[width]; continue; }
      int fr = 0; int to = 0;
      while(fr < weroad.size()){
        if(to >= weroad.size()) break;
        if(weroad[to] - weroad[fr] == width){ count++; to++; }
        if(weroad[to] - weroad[fr] > width) fr++;
        if(weroad[to] - weroad[fr] < width) to++;
      }
      counts[width] = count;
      res += count;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 16408
MOD = 1000000007
n = int(input())
dp = [[0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
    c = input()
    for j in range(n):
        if c == "-":
            dp[i + 1][j] += dp[i][j]
            dp[i + 1][j] %= MOD
        if c == "U":
            dp[i + 1][j] += j * dp[i][j]
            dp[i + 1][j] %= MOD
            if n > j:
                dp[i + 1][j + 1] += dp[i][j]
                dp[i + 1][j + 1] %= MOD
        if c == "D":
            dp[i + 1][j] += j * dp[i][j]
            dp[i + 1][j] %= MOD
            if j > 0:
                dp[i + 1][j - 1] += j * j * dp[i][j]
                dp[i + 1][j - 1] %= MOD
print(dp[n][0])
                
        


Measured memory_bytes: 6168
#include <iostream>
using namespace std;
int main(){
  int k, s;
  int count = 0;
  cin >> k >> s;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      int z = s - x - y;
      if(0 <= z && z <= k){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
program main
	integer i
	character(100) S, T
	character last
	read(*, *) S, T	
	do i = 1, 110
		if(trim(S) == trim(T)) then
			write(*, *) 'Yes'
			exit
		else
			last = S(len_trim(S):len_trim(S))
			S = last // S(1:len_trim(S)-1)
		end if
		if(i == 110) then
			write(*, *) 'No'
		end if
	end do
end program main

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long n,k,m,t,j;
int main()
{
	scanf("%lld%lld", &n,&k);
	m=n%k;
	t=abs(m-k);
	//printf("%d", t);
	j=abs(t-k);
	printf("%lld", min(t,j));
}

Measured memory_bytes: 128