akhauriyash/Code-Regression huggingface dataset:
class Combination:                                      # 計算量は O(n_max + log(mod))
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):                     # 階乗(= n_max !)の逆元を生成
            f = f * i % mod                             # 動的計画法による階乗の高速計算
            fac.append(f)                               # fac は階乗のリスト
        f = pow(f, mod-2, mod)                          # 階乗から階乗の逆元を計算。フェルマーの小定理より、　a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
                                                        # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):                   # 上記の階乗の逆元から階乗の逆元のリストを生成（＝ facinv ）
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()


    def __call__(self, n, r):  # self.C と同じ
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def P(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[n-r] % self.mod

##############################################################################################
import sys
input = sys.stdin.readline

mod=10**9+7
N, K = map(int, input().split())
comb = Combination(K)
edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edges[a].append(b)
    edges[b].append(a)

res = K
res *= comb.P(K-1,len(edges[0]))
res %= mod
next_set = edges[0]
visited = set([0]+edges[0])
while next_set:
    p = next_set.pop()
    cnt = 0
    for q in edges[p]:
        if q in visited:
            continue
        cnt += 1
        visited.add(q)
        next_set.append(q)
    res *= comb.P(K-2,cnt)
    res %= mod
print(res%mod)

Measured memory_bytes: 112404
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s[n];
    string ans="";
    vector<int> str(26,0);
    vector<int> str2(26,0);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    for(int i=0;i<s[0].length();i++){
        str[s[0][i]-'a']++;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<s[i].length();j++){
            str2[s[i][j]-'a']++;
        }
        for(int j=0;j<26;j++){
            str[j]=min(str[j],str2[j]);
        }
        for(int j=0;j<26;j++){
            str2[j]=0;
        }
    }
    for(int i=0;i<26;i++){
        if(str[i]>0){
        for(int j=0;j<str[i];j++){
            ans+='a'+i;
        }
        }
    }
    cout << ans << endl;
}

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

int main(){
  int K,X;
  cin>>K>>X;
  for(int i=-(K-1);i<=K-1;++i){
    if(i<K-1){
    cout<<X+i<<" ";
    }
    else{
    cout<<X+i<<endl;
    }
  }
}

Measured memory_bytes: 256
N, M = gets.split.map{|i|i.to_i}
H = gets.split.map{|i|i.to_i}
T = Array.new(N){true}
M.times{
    a, b = gets.split.map{|i|i.to_i - 1}
    if H[a] <= H[b]
        T[a] = false
    end
    if H[b] <= H[a]
        T[b] = false
    end
}
puts T.count(true)


Measured memory_bytes: 22420
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a,b,c[100010]={0},visited[100010]={0};
  vector<pair<int,int> > tree[100010];
  queue<pair<int,int> > que;
  m=0;
  cin >> n;
  rep(i,n-1){
    cin >> a >> b;
    a--;b--;
    tree[a].push_back(make_pair(b,i));
    tree[b].push_back(make_pair(a,i));
    c[i]=-1;
  }
  rep(i,n){
    m = max(m,(ll)tree[i].size());
  }
  
  que.push(make_pair(0,-1));
  visited[0]=1;
  while(!que.empty()){
    auto p = que.front();
    que.pop();
    int color=1;
    if(color==p.second) color=2;
    for(auto q : tree[p.first]){
      if(visited[q.first]==1) continue;
      visited[q.first]=1;
      que.push(make_pair(q.first,color));
      
      c[q.second] = color;
      color++;
      if(color==p.second) color++;
    }
  }
  
  cout << m << endl;
  rep(i,n-1){
    cout << c[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 10412
[Fixnum, Bignum].each do |klass|
	klass.class_eval do
		alias :orig_plus :+
		alias :orig_mul :*
		alias :orig_sub :-
		remove_method :*, :/, :%, :+, :-, :&
	end
end	

e0 = gets.chomp
results = []

redef = -> op, orig {
	Integer.class_eval { define_method(op){|x| send(orig, x)} }
}

[0, 1, 2].repeated_permutation(3) do |priority|
	next if ! priority.include?(0) 
	next if priority.sort.uniq == [0, 2]

	e = e0.tr("+*-", "abc")	
	ops = [[?*, ?/, ?%], [?+, ?-], [?&]]

	op = ops[priority[0]].pop
	e.gsub!(?a, op)
	redef[op, :orig_plus]

	op = ops[priority[1]].pop
	e.gsub!(?b, op)
	redef[op, :orig_mul]

	op = ops[priority[2]].pop
	e.gsub!(?c, op)
	redef[op, :orig_sub]

	results << eval(e)
end

p results.max

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

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


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

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

int main() {
 int a,b,k; cin>>a>>b>>k;
  int p=gcd(a,b);
  
  int count=0;
  for(int i=p;i>=1;i--){
    if(p%i==0){count++;
               if(count==k){cout<<i<<endl;
                        break;}
              }
  }
  
  

}

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

#define MOD 2019

long long power( long long x, int n )
{
	long long res = 1;
	while( n > 0 ) {
		if( n % 2 ) res = res * x % MOD;
		x = x * x % MOD;
		n /= 2;
	}
	return res;
}

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

	int N = S.size();
	vector<long long> T( N + 1 );
	for( int i = N - 1; i >= 0; i-- ) {
		T[N - i] = T[N - i - 1] + (S[i] - '0') * power( 10, N - i - 1 );
		T[N - i] %= MOD;
	}
	vector<long long> cnt( MOD );
	for( int i = 0; i < N + 1; i++ ) {
		cnt[ T[i] ]++;
	}
	long long ans = 0;
	for( int i = 0; i < MOD; i++ ) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < s.length(); i++) {
			sb = sb.append("x");
		}
		System.out.println(sb.toString());
	}
}

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

#define ll long long 

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

    ll n;
    cin >> n;
    vector<int> v(n, 0);
    for(int x = 1; x < 101; x++) {
      for(int y = 1; y < 101; y++) {
        for(int z = 1; z < 101; z++) {
          ll m = x*x + y*y + z*z + x*z + z*y + x*y;
          if(m <= n)
            v[m-1]++;
        }
      }
    }
    for(int i = 0; i < n; i++)
      cout << v[i] << '\n';
}


Measured memory_bytes: 3540
arr = list(map(int,input().split("/")))
if arr[0] <= 2019:
    if arr[1] <= 4:
        if arr[2] <= 30:
            print("Heisei")
        else:
            print('TBD')
    else:
        print('TBD')
else:
    print('TBD')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n)    for(int i=0; i<(n); i++)
#define fst first
#define pb push_back
#define mp make_pair
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;
typedef unsigned long ul;
typedef long long ll;
//#define int unsigned int
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

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

  int n;
  cin >> n;

//  int dp[4][4][4]={
//    {{4, 4, 3, 3}, {4, 4, 4, 3}, {4, 4, 4, 0}, {3, 3, 0, 3}},
//    {{4, 4, 3, 3}, {4, 4, 4, 4}, {4, 4, 4, 4}, {3, 4, 4, 4}},
//    {{4, 4, 3, 3}, {4, 4, 4, 4}, {4, 4, 4, 4}, {3, 4, 4, 4}},
//    {{4, 4, 0, 3}, {4, 4, 4, 4}, {4, 4, 4, 4}, {3, 4, 4, 4}}
//  };
  ll dp[4][4][4];
  FOR(i, 0, 4){
    FOR(j, 0, 4){
      FOR(k, 0, 4){
        dp[i][j][k] = 1;
      }
    }
  }
  dp[0][2][3] = 0; // ACG
  dp[0][3][2] = 0; // AGC
  dp[3][0][2] = 0; // GAC

  ll dp_[4][4][4];

  ll sum;

  REP(p, n-3){
    REP(i, 4){
      REP(j, 4){
        sum = 0;
        REP(l, 4){
          sum += dp[l][i][j] % MOD;
          sum %= MOD;
        }
        REP(k, 4){
          dp_[i][j][k] = sum;
        }
      }
    }

    dp_[0][2][3] = 0; // ACG
    dp_[0][3][2] = 0; // AGC
    dp_[3][0][2] = 0; // GAC
    dp_[1][3][2] = (dp_[1][3][2] - dp[0][1][3] + MOD) % MOD; // TGC = ?TGC - ATGC
    dp_[3][3][2] = (dp_[3][3][2] - dp[0][3][3] + MOD) % MOD; // GGC = ?GGC - AGGC
    dp_[3][1][2] = (dp_[3][1][2] - dp[0][3][1] + MOD) % MOD; // GTC = ?GTC - AGTC
    // CGC = ?CGC - ACGC(0)
    // GCC = ?GCC - AGCC(0)

    FOR(i, 0, 4){
      FOR(j, 0, 4){
        FOR(k, 0, 4){
          dp[i][j][k] = dp_[i][j][k];
        }
      }
    }
  }

  ll ans=0;
  FOR(i, 0, 4){
    FOR(j, 0, 4){
      FOR(k, 0, 4){
         ans += dp[i][j][k] % MOD;
         ans %= MOD;
      }
    }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


int a[100];

int main(){
  int N,M;
  cin >> N >> M;
  rep(i,N){
    int k;
    cin >> k;
    rep(j,k){
      int b;
      cin >> b;
      a[--b]++;
    }
  }
  int ans = 0;
  rep(i,M) if(a[i] == N) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
 int q,p,w[1000001],u[1000001],o;
 string a;
 int main()
 {
     cin>>a;
     for (int i=0;i<a.size();i++)
     {
         if (a[i]=='C') 
         {
             p++;
             u[p]=i+1;
         }
         else if (a[i]=='F')
         {
            q++;
             w[q]=i+1;
         }
     }
     if (q>=1 && p>=1)
     {
     for (int i=1;i<=p;i++)
     {
         for (int j=1;j<=q;j++)
         {
             if (u[i]<w[j])
             {
                 o=1;
             }
         }
     }
     if (o==1) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;  
     }
     else cout<<"No"<<endl;
     return 0;
 }

Measured memory_bytes: 2304
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if (a == 2) {
            System.out.printf("%d%n",a);
            return;
        }
        if (a % 2 == 0) a += 1;
        while (true) {
            if (isPrime(a)) {
                System.out.printf("%d%n",a);
                return;
            }
            a += 2;
        }
        
    }
    
    private static boolean isPrime(int a) {
        for (int b = 3; b * b <= a; b += 2) {
                if (a % b == 0) {
                    return false;
                }
            } 
        return true;
    }
}

Measured memory_bytes: 23892
#include<stdio.h>
#include<stdlib.h>

int main() {
	int m,i,j,k,sum=0;
	char d[100];
	int di[100];
	scanf("%d", &m);
	scanf("%s", &d);

	di[0] = (int)d[0]-48;
	di[1] = (int)d[1]-48;
	for (i = 1;i <= m;i++) {
		for (j = 2;j <= di[0];j++) {
			if (j == di[0]) {
				for (k = 2;k <= di[1];k++) {
					if (j*k == i) {
						sum++;
					}
				}
			} else {
				for (k = 2;k <= 9;k++) {
					if (j*k == i) {
						sum++;
					}
				}
			}
		}
	}
	printf("%d", sum);
	return 0;
}

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

#define INF 100000000
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int bole[N];
  int flag[N];
  for(int i = 0; i < N; i++){
    bole[i] = 1;
    flag[i] = 0;
  }
  flag[0] = 1;
  for(int i = 0; i < M; i++){
    int x,y;
    cin >> x >> y;
    x--;y--;
    if(bole[x] > 1 && flag[x]){
      bole[x] --;
      bole[y]++;
      flag[y] = 1;
    }else if(bole[x] == 1 && flag[x]){
      bole[x]--;
      bole[y]++;
      flag[y] = 1;
      flag[x] = 0;
    }else{
      bole[x]--;
      bole[y]++;
    }
  }
  int count = 0;
  for(int i = 0; i < N; i++){
    if(flag[i])count++;
  }
  cout << count << endl;
}



Measured memory_bytes: 1024
r, c = map(int, input().split())
sheet = []
sum_column = [0 for _ in range(c)]

for i in range(r):
    row = list(map(int, input().split()))
    sheet.append(row)
    sheet[i].append(sum(sheet[i]))
    
sheet.append([sum(col) for col in zip(*tuple(sheet))])


for row in sheet:
    print(" ".join(map(str, row)))


Measured memory_bytes: 5708
import sys

N = input()
a = []
c = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
l = list(N)
if N =='zyxwvutsrqponmlkjihgfedcba':
  print(-1)
elif len(N) != 26:
  for i in range(len(N)):
    c.remove(l[i])
  N = N[0: i+1] + c.pop(0)
  print(N)
else:
  for i in range(len(N)-1,0,-1):
    a.append(l[i])
    if ord(l[i]) > ord(l[i-1]):
      for j in range(len(a)):
        if l[i-1] < a[j]:
          print(N[0:i-1]+a[j])
          sys.exit()

Measured memory_bytes: 3064
#!/bin/bash

OK=1
read S
for I in $(seq 1 ${#S})
do
        if [[ $(( ${I} % 2 )) -eq 1 ]]; then
                if [[ '' == $( echo ${S} | cut -b ${I} | egrep '[RUD]' ) ]]; then
                        OK=0
                        break
                fi
        else
                if [[ '' == $( echo ${S} | cut -b ${I} | egrep '[LUD]' ) ]]; then
                        OK=0
                        break
                fi
        fi
done

if [[ $OK -eq 1 ]]; then
        echo "Yes"
else
        echo "No"
fi


Measured memory_bytes: 1052
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class Combination(object):

    def __init__(self, N, mod=MOD):
        fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N+1):
            fac[i] = fac[i-1]*i % mod
            inv[i] = -inv[mod % i]*(mod//i) % mod
            finv[i] = finv[i-1]*inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        fac = self.fac
        finv = self.finv
        mod = self.MOD
        return fac[n] * (finv[k]*finv[n-k] % mod) % mod


def main():
    K = int(input())
    S = input()

    A = len(S)-1
    cmb = Combination(K+A)
    ans = 0
    for k in range(K+1):
        b = 1
        b *= pow(26, k, MOD)
        b %= MOD
        b *= pow(25, K-k, MOD)
        b %= MOD
        b *= cmb(K-k+A, A)
        # print(cmb(K-k+A, A))
        b %= MOD
        ans += b
        ans %= MOD
    print(ans)
    return


if __name__ == '__main__':
    main()


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

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

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

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N, M, X; cin >> M >> M >> X;

    int l = 0, r = 0;
    REP( i, M ){
        int t;
        cin >> t;
        if( t < X ) l++;
        else r++;
    }

    cout << min( l, r ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#define MAX 100
using namespace std;
int main() {
  int n, result[MAX]={}, rank[MAX], count=1, r=1;
  set<int> p;
  
  cin >> n;
  for(int i=0; i<n*(n-1)/2; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(c > d) result[a]+=3;
    else if(c < d) result[b]+=3;
    else {
      result[a]+=1;
      result[b]+=1;
    }
  }
  
  for(int i=1; i<=n; i++) {
    p.insert(result[i]);
  }
  
  for(set<int>::reverse_iterator it=p.rbegin(); it!=p.rend(); it++) {
    for(int i=1; i<=n; i++) {
      if(*it == result[i]) {
	rank[i] = r;
	count++;
      }
    }
    r=count;
  }
  
  for(int i=1; i<=n; i++) {
    cout << rank[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int b=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            b=i*m+n*j-2*i*j;
            if(b==k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int>l(n);
	for(auto& v : l){
		cin >> v;
	}

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

	int out=0;
	for(int i = 1; i <= k; ++i){
		out += *(l.end() - i);
	}

	cout << out << endl;

	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n - 1);
  for(int i = 0; i < n; i++)
    cin >> a[i];
  for(int i = 0; i < n; i++)
    cin >> b[i];
  for(int i = 0; i < n - 1; i++)
    cin >> c[i];
  
  int satisfact = b[a[0] - 1];
  for(int i = 1; i < a.size(); i++){
  	satisfact += b[a[i] - 1];
    if(a[i - 1] + 1 == a[i])
      satisfact += c[a[i - 1] - 1];
  }
  
  cout << satisfact << '\n';
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split();
            var a = int.Parse(abc[0]);
            var b = int.Parse(abc[1]);
            var c = int.Parse(abc[2]);

            if (a == b && b == c)
                Console.WriteLine(1);
            else if (a == b || b == c || c == a)
                Console.WriteLine(2);
            else
                Console.WriteLine(3);
        }
    }
}

Measured memory_bytes: 13140
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[M];
		for(int i = 0;i < M;++i)
			A[i] = sc.nextInt();
		sc.close();
		
		int route0 = 0;
		int routeN = 0;
		Arrays.sort(A);
		for(int i = 0;i < M;++i) {
			if(A[i] < X)
				route0++;
			else
				routeN++;
		}
		if(route0 > routeN)
			System.out.println(routeN);
		else
			System.out.println(route0);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

bool isOK(ll num) {
    bitset<3> use;
    ll d = log(num) + 1;
    REP(i, d) {
        ll x = num % 10;
        if (x == 7) use[2] = true;
        else if (x == 5) use[1] = true;
        else if (x == 3) use[0] = true;
        num /= 10;
    }
    return use.all();
}

ll dfs(ll num, ll n) {
    if (num > n) {
        return 0;
    }
    ll ret = 0;
    if (isOK(num)) ret++;
    ret += dfs(num*10 + 7, n);
    ret += dfs(num*10 + 5, n);
    ret += dfs(num*10 + 3, n);
    return ret;
}

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

    ll n;
    cin >> n;

    P(dfs(0, n));

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a, b, c, d, e, f;
bool dp[4000];
signed main() {
	cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; i * c <= f; i++) {
		dp[i*c] = 1;
	}
	for (int i = 0; i + d <= f; i++) {
		dp[i + d] |= dp[i];
	}
	ld res = 0, u = min(a, b) * 100, v = 0;
	for (int i = 0; i * a * 100 <= f; i++) {
		for (int j = 0; (i * a + j * b) * 100 <= f; j++) {
			if (i + j == 0) continue;
			int k = (i * a + j * b) * 100;
			for (int z = 0; z <= k / 100 * e && k + z <= f; z++) {
				if (dp[z]) {
					if (res < z * 100. / (k + z)) {
						u = k, v = z;
						res = z * 100. / (k + z);
					}
				}
			}
		}
	}
	cout << u + v << " " << v << endl;
}

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

int main() {
 string S,T;
 cin >> S >>T;
 string x;
 x = T.substr(0,S.size());
 if (x == S && S.size()==T.size()-1){
   cout << "Yes" <<endl;
 }
 else {
   cout << "No" << endl;
 }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long int
#define cin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define ll long long int
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rf1(i,a,n) for(int i=a;i>n;i--)
#define cases() int q;cin>>q;while(q--)
#define ld long double
#define cout(a,n) for(i=0;i<n;i++)cout<<a[i]<<" ";
#define inf 1e9;
#define mod 1000000007;
#define PI 3.14159265358979323846264338327950L
using namespace std;

int main(){
    ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int a,b;
cin>>a>>b;
cout<<a*b;
 return 0;
 }


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    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++;
    out(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/

int main(){
    ll N;
    cin >> N;
    cout << (N * N - N) / 2 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;




int main(){
    	int n;
        cin>>n;
        int ans=-1;
    int a[2][100];
    int rui[100]={0};
    for(int i=0;i<2;++i){
        for(int j=0;j<n;++j){
            cin>>a[i][j];
            if(i==0){
                if(j!=0){
                    rui[j]=rui[j-1]+a[i][j];
                }
                else  rui[j]=a[i][j];


            }
        }
    }
    for(int i=0;i<n;++i){
        int sum=rui[i];
        for(int j=i;j<n;++j){
            sum+=a[1][j];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 256
//Checkpoints.cpp (B)
#include <iostream>
#include <string>
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int a[N],b[N],c[M],d[M];
  for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for(int i = 0; i < M; i++) cin >> c[i] >> d[i];

  int D,dmin,ans;
  for(int i = 0; i < N; i++){
    for(int j = M-1; j >= 0; j--){
      D = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(j == M-1) dmin = D;
      else dmin = min(dmin,D);
      if(dmin == D) ans = j + 1;
    }
    printf("%d\n",ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    VV<> a(n, V<>(d));
    rep(i, n) rep(j, d) cin >> a[i][j];
    int ans = 0;
    rep(i, n) rep(j, i) {
        int now = 0;
        rep(k, d) now += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
        rep(num, 1000) {
            if(num * num == now) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
n, *a = map(int, open(0).read().split())
a += 1,
m = 1000

def groupby():
  c, res = [], []
  for i in range(n + 1):
    if a[i-1] <= a[i]:
      pass
    else:
      res += [c[0], c[-1]],
      c = []
    c += a[i],
  return res

for i, j in groupby():
  m = m // i * j + m % i
print(m)

Measured memory_bytes: 9084
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<cctype>
#include<sstream>
#include<stack>
using namespace std;
typedef long long ll;
const int N=110;
struct P{
    int s,t,c;
    friend bool operator<(const P &p1,const P &p2 ){
        return p1.s>p2.s;
    }
};
struct T{
    int t,c;
    friend bool operator<(const T &p1,const T &p2 ){
        return p1.t<p2.t;
    }
};
int main()
{
    int n,c;
    while(~scanf("%d%d",&n,&c)){
        P p;
        priority_queue<P>q;
        priority_queue<T>q1;
        priority_queue<T>q2;
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&p.s,&p.t,&p.c);
            q.push(p);
        }
        T tt;
        while(!q.empty()){
            p=q.top();
            q.pop();
            if(!q1.empty()){
                bool flag=0;
                while(!q1.empty()&&!flag){
                    tt=q1.top();
                    q1.pop();
                    if(tt.c==p.c){
                        if(tt.t<=p.s) {flag=1;tt.t=p.t;tt.c=p.c;q1.push(tt);}
                        else q2.push(tt);
                    }
                    else {
                        if(tt.t<p.s) {flag=1;tt.t=p.t;tt.c=p.c;q1.push(tt);}
                        else q2.push(tt);
                    }
                }
                while(!q2.empty()){
                    q1.push(q2.top());
                    q2.pop();
                }

                if(!flag){
                    tt.c=p.c;
                    tt.t=p.t;
                    q1.push(tt);
                }

            }
            else {tt.t=p.t;tt.c=p.c;q1.push(tt);}

        }
        int ans=0;
        while(!q1.empty()){
            ans++;
            q1.pop();
        }
        printf("%d\n",ans);
    }


    return 0;
}


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

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

    int ans;


    for (int Y = X;; Y++) {
        bool ok = true;
        for (int i = 2; i < Y / 2; i++) {
            if (Y % i == 0) {
                ok = false;
                break;
            }
        }

        if (ok) {
            ans = Y;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] a = new int[h][w];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int n = 0;
		List<String> list = new ArrayList<>();
		for(int i = 0; i < h; i++) {
			if(i % 2 == 0) {
				for(int j = 0; j < w; j++) {
//					System.out.println(i + " " + j);
					if(a[i][j] % 2 == 1) {
						if(i == h - 1 && j == w - 1) break;
						n++;
						a[i][j]--;
						if(j == w - 1) {
							a[i + 1][j]++;
							list.add((i + 1) + " " + (j + 1) + " " + (i + 2) + " " + (j + 1));
						} else {
							a[i][j + 1]++;
							list.add((i + 1) + " " + (j + 1) + " " + (i + 1) + " " + (j + 2));
						}
					}
				}
			} else {
				for(int j = w - 1; j >= 0; j--) {
//					System.out.println(i + " " + j);
					if(a[i][j] % 2 == 1) {
						if(i == h - 1 && j == 0) break;
						n++;
						a[i][j]--;
						if(j == 0) {
							a[i + 1][j]++;
							list.add((i + 1) + " " + (j + 1) + " " + (i + 2) + " " + (j + 1));
						} else {
							a[i][j - 1]++;
							list.add((i + 1) + " " + (j + 1) + " " + (i + 1) + " " + j);
						}
					}
				}
			}
		}
		System.out.println(n);
		for(String key : list) {
			System.out.println(key);
		}
	}
}


Measured memory_bytes: 103208
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int a, b, c; cin >> a >> b >> c;
    if (a + b + c > 21) cout << "bust" << '\n';
    else cout << "win" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3512
#include<stdio.h>

char* _fact[21] = {
"1",
"1",
"2",
"6",
"24",
"120",
"720",
"5040",
"40320",
"362880",
"3628800",
"39916800",
"479001600",
"6227020800",
"87178291200",
"1307674368000",
"20922789888000",
"355687428096000",
"6402373705728000",
"121645100408832000",
"2432902008176640000",};

/*
int fact(int n){
  if (n==0){
    return 1;
  }else{
    return fact(n-1) * n;
  }
}
*/


int main(){

  int n;

  scanf("%d", &n);
  printf("%s\n",_fact[n]);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;cin>>N;
  vector<int> data(N,0);
  cout<<0<<endl;
  string s;
  cin>>s;
  if(s == "Vacant")
  {
    // cout<<0<<endl;
    return;
  }
  else if( s == "Male")
  {
    for (int i = 0; i < N; i++)
    {
      data[i] = i%2;
    }
  }
  else
  {
    for (int i = 0; i < N; i++)
    {
      data[i] = (int)(i%2 == 0);
    }
  }
  int L = 0, R = N;
  for (int i = 0; i < 19; i++)
  {
    int mid = (L+R)/2;
    cout<<mid<<endl;
    cin>>s;
    int p;
    if(s == "Male") p = 0;
    else if( s == "Female") p = 1;
    else
    {
      // cout<<mid<<endl;
      return;
    }
    if(data[mid] == p)
    {
      L = mid;
    }
    else
    {
      R = mid;
    }
  }
  abort();
  
  return;
}

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

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 1744
def main():
  n, m = map(int, input().split())
  works =[[] for _ in range(n + 1)]
  while True:
    s, t, e = map(int, input().split())
    if s == 0:
      break
    works[s - 1].append((t - 1, e))
  
  l = int(input())
  for _ in range(l):
    blst = tuple(map(int, input().split()))
    print(*[sum([blst[t] * e for t, e in works[i]]) for i in range(n)])
main()


Measured memory_bytes: 13512
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000LL
#define M 1000000007
typedef long long ll;
using namespace std;
const int N = 105001;

int dp[1010][1<<12];
int n , m , a[1010],b[1010];
vector<int> c[1010];
int calc(int idx , int msk){
    if(idx==m)return msk==(1<<n)-1?0:100000001;
    int&ret=dp[idx][msk];
    if(ret!=-1)return ret;
    ret = calc(idx+1,msk);
    for(int i = 0 ; i < b[idx] ; i++){
        msk=msk|(1<<c[idx][i]-1);
    }
    ret = min(ret,calc(idx+1,msk)+a[idx]);
    return ret;
}

signed main(){
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        scanf("%d%d",a+i,b+i);
        for(int j =0,t ; j<b[i] ; j++){
            scanf("%d",&t);
            c[i].push_back(t);
        }
    }
    setDP(dp);
    cout<< (calc(0,0)<=100000000?calc(0,0):-1);



    return 0;
}


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

int main(){
  long long int n,k;
  cin >> n >> k;
  vector<long long int> a(n);
  rep(i, n, 0) cin >> a[i];
  
  long long int ans = 0;
  rep(i, n, 0){
    rep(j, n, i+1){
      if(a[i] > a[j]) ans += k*(k+1)/2;
      ans %= MOD;
      if(a[i] < a[j]) ans += k*(k-1)/2;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
ll gcd(ll a, ll b){if(b == 0)return a;return gcd(b, a % b);} 
bool isvalid(ll x,ll y,ll n, ll m) { return (x>=0&&x<n&&y>=0&&y<m); }

ll prime[1000011];

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

    for(ll i = 2; i <= 1000000; i++){

        if(prime[i] == 0){

            for(ll j = i; j*i <= 1000000; j++){

                prime[i*j] = 1;
            }
        }
    }

    ll a,b;

    cin>>a>>b;

    ll p = gcd(a,b);
    ll ans = 1;

    for(int i = 2; i <= 1000000; i++){

        if(prime[i] == 0 && (p%i == 0)){

            ans++;
            while((p%i) == 0){

                p = p/i;
            }
        }
    }

    if(p!=1){

        ans++;
    }

    cout<<ans;
    

    return 0;
}


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

int main() {
  int n; cin >> n;
  set<string> st;
  for (int i = 0; i < n; i++) {
    string s, t; cin >> s >> t;
    if (s.at(0) == 'i') st.insert(t);
    else {
      cout << (st.count(t) ? "yes" : "no") << endl;
    }
  }
}


Measured memory_bytes: 32152
s = list(input())
t = list(input())
flag = False
for j in range(len(s) - len(t) + 1):
    for i in range(1,len(t) + 2):
        if len(t) + 1 == i:
            flag = True
            start = len(s) - len(t) - j
            s = s[:start] + t + s[start + len(t):]
            break
        if s[-i - j] != "?" and t[-i] != s[-i - j]:
            break
    if flag:
        break
if flag:
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"
    print("".join(s))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define p 1000000007
int main() {
int m,n;
cin>>m>>n;
char a[m][n];
for(int i=0;i<m;i++)
{
	for(int j=0;j<n;j++)
	{
		cin>>a[i][j];
	}
}
long long dp[m][n];
dp[0][0]=1;
for(int i=1;i<m;i++)
{
	if(a[i][0]=='#')dp[i][0]=0;
	else dp[i][0]=dp[i-1][0];
}
for(int i=1;i<n;i++)
{
	if(a[0][i]=='#')dp[0][i]=0;
	else dp[0][i]=dp[0][i-1];
}
for(int i=1;i<m;i++)
{
	for(int j=1;j<n;j++)
	{
		if(a[i][j]=='#')dp[i][j]=0;
		else dp[i][j]=((dp[i-1][j]%p)+(dp[i][j-1]%p))%p;
	}
}
cout<<dp[m-1][n-1];
	return 0;
}

Measured memory_bytes: 9088
[L,R] = list(map(int,input().split()))
output = 2020
flag = 0
for k in range(1,int(2*10**9/2019)+1):
    if (L<=k*2019)and(k*2019<=R):
        flag = 1
if flag ==1:
    print(0)
else:
    for d in range(R-L+1):
        A = L+d
        for e in range(d,R-L+1):
            B = L+e
            if d==e:
                continue
            else:
                amari = (A*B)%2019
                if amari < output:
                    output = amari
    print(output)

Measured memory_bytes: 3064
#import math

#input = raw_input
n = int(input())

As = list(map(int, input().split(" ")))
sA = sum(As)
#half_sA= sA // 2 if sA % 2 == 0 else (sA // 2) + 1
half_sA = sA // 2

cur_val = 0
for i, a in enumerate(As):
    cur_val += a
    if half_sA <= cur_val:
        over_i = i # made
        break

cur_val2 = cur_val
cur_val1 = cur_val - a

#print(cur_val1, half_sA, cur_val2)
diff1 = half_sA - cur_val1
diff2 = cur_val2 - half_sA

val_a = cur_val1
val_b = sA - val_a

val_c = cur_val2
val_d = sA - val_c

out = min( abs(val_b-val_a), abs(val_c-val_d) )

#if diff1 <= diff2:
#    #half_sA = int(math.floor(half_sA))
#    out = diff1
#else:
#    out = diff2
print(out)

Measured memory_bytes: 26220