akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

using ll = long long;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	ll A = a * b;
	ll B = c * d;
	cout << (A >= B ? A : B) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	ll n;
	ll a, b,c;
	ll ansx, ansy,ansh;
	bool judge = false;
	cin >> n;
	vector<ll>x,y,h,x0,y0,h0;
	repp(i, 0, n) {
		cin >> a >> b >> c;
		if (c != 0) {
			x.push_back(a);
			y.push_back(b);
			h.push_back(c);
		}
		else {
			x0.push_back(a);
			y0.push_back(b);
			h0.push_back(c);
		}
	}
	repp(i, 0, 101) {
		repp(j, 0, 101) {
			ll H = h[0] + abs(x[0] - i) + abs(y[0] - j);
			repp(k, 0, h.size()) {
				if (H != h[k] + abs(x[k] - i) + abs(y[k] - j))break;
				if (k == h.size()-1) {
					ansx = i; ansy = j; ansh = H;
					judge = true;
					if (h0.size()) {
						repp(l, 0,h0.size()) {
							if (ansh - abs(x0[l] - ansx) - abs(y0[l] - ansy) > 0)judge = false;
						}
					}
					if (judge) {
						cout << ansx << " " << ansy << " " << ansh << endl;
						return 0;
					}
				}
			}
		}
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int n;
    cin >> n;
    vi p(n);
    int sum = 0;
    rep(i,n){
        cin >> p[i];
        sum += p[i];
    }
    int mx = maxel(p);
    sum -= mx;
    sum += (mx/2);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  int N,K,r=0;
  const int lz=0;
  cin>>N>>K;
  if(N==1){
    cout<<1;
    return 0;
  }
  if(!K){
    cout<<N*N;
    return 0;
  }
  for(int b=1;b<=N;++b)r+=max((b-K)*(N/b),lz)+max(N-(N/b)*b+1-K,lz);
  cout<<r;
  return 0;
}

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


int main() {
	int n;
	int a;
	int b;
	string s;
	cin >> n >> a >> b >> s;

	int passedNum = 0;
	int oversNum = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'a') {
			if (passedNum < a+b) {
				cout << "Yes";
				++passedNum;
			} else {
				cout << "No";
			}
		} else if (s[i] == 'b') {
			if (passedNum < a+b && oversNum < b) {
				cout << "Yes";
				++passedNum;
			} else {
				cout << "No";
			}
			++oversNum;
		} else {
			cout << "No";
		}

		if (i < s.length()-1) {
			cout << "\n";
		}
	}

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int base_num = P[0];
    int res = 1;
    for (int i=1; i<N; i++) {
        if (P[i] < base_num) {
            res += 1;
            base_num = P[i];
        } else {
            ;
        }
    }

    cout << res << endl;

    return 0;
}

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

int main() {

	int N, K;
	cin >> N >> K;

	vector<int> a;

	for(int i = 0;i<N;i++) {
		int h;
		cin >> h;
		a.push_back(h);
	}

	int dp[N];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2;i<N;i++) {
        int min = dp[i-1]+ abs(a[i]-a[i-1]);
        for(int j = 2; j<=K;j++)
            if(i >= j)
                if(min > dp[i-j]+ abs(a[i]-a[i-j]))
                    min = dp[i-j] + abs(a[i]-a[i-j]);
        dp[i] = min;
	}
	// for(int i = 0;i<N;i++)
	// 	cout << dp[i] << endl;
	cout << dp[N-1] ;
}

Measured memory_bytes: 1144
import java.util.*;

public class Main {
	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		// 林檎 1個は、砕くことで林檎の欠片 3個になります。
       // また、林檎の欠片 2個を鍋で煮込むことで、アップルパイが 1個作れます。
		System.out.print((a * 3 + p) / 2);
	}

	
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
const int MAX = 1e6+8;
const int sz = 1e5+5;
void f_io(){
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
}

int32_t main(){
    //f_io();
    int t = 1;
    //cin>>t;
    while(t--){
        string temp1,temp2; cin>>temp1>>temp2;
        int a,b; cin>>a>>b;
        string temp3; cin>>temp3;
        if(temp3 == temp1) a--;
        else b--;
        cout<<a<<" "<<b;

    }
}

Measured memory_bytes: 256
N = int(input())
s = []
for _ in range(N):
    s.append(''.join(sorted(input().lower())))

l = {}
for n in range(N):
    if s[n] in l:
        l[s[n]] += 1
    else :
        l[s[n]] = 1

print(sum(l[k] * (l[k]-1) // 2 for k in l))

Measured memory_bytes: 19400
def print_class(weight)
  if weight <= 48.00
    puts 'light fly'
  elsif weight <= 51.00
    puts 'fly'
  elsif weight <= 54.00
    puts 'bantam'
  elsif weight <= 57.00
    puts 'feather'
  elsif weight <= 60.00
    puts 'light'
  elsif weight <= 64.00
    puts 'light welter'
  elsif weight <= 69.00
    puts 'welter'
  elsif weight <= 75.00
    puts 'light middle'
  elsif weight <= 81.00
    puts 'middle'
  elsif weight <= 91.00
    puts 'light heavy'
  else
    puts 'heavy'
  end
end

readlines.map(&:to_f).each do |weight|
  print_class(weight)
end

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

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	int i = 100;
	int j = 100;
	while(C >0){
		C = C - B;
		i--;
	}
	while(A > 0){
		A = A - D;
		j--;
	}
	if(j <= i){
		cout << "Yes" << endl;
		}else{
		cout << "No" << endl;
		}
		return 0;
}


Measured memory_bytes: 3584
import random
class Dice:
    def __init__(self, top, dside, rside, lside, uside, bottom):
        self.top = top
        self.dside = dside
        self.rside = rside
        self.lside = lside
        self.uside = uside
        self.bottom = bottom
    def north(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.dside, 
            self.bottom, self.uside, self.top)
    def east(self):
        (self.top, self.lside, self.bottom, self.rside) = (self.lside,
            self.bottom, self.rside, self.top)
    def south(self):
        (self.top, self.dside, self.bottom, self.uside) = (self.uside, 
            self.top, self.dside, self.bottom)

num1 = list(map(int, input().split()))
num2 = list(map(int, input().split()))
dice1 = Dice(num1[0], num1[1], num1[2], num1[3], num1[4], num1[5])
dice2 = Dice(num2[0], num2[1], num2[2], num2[3], num2[4], num2[5])
if len(set(num1))<4:
    while(dice1.top!=dice2.top or dice1.rside!=dice2.rside
          or dice1.dside!=dice2.dside):
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
else:
    while dice1.top!=dice2.top or dice1.rside!=dice2.rside:
        mode = random.randint(0, 2)
        if mode==0: 
            dice2.north()
        elif mode==1: 
            dice2.east()
        else: 
            dice2.south()
if dice1.bottom==dice2.bottom and dice1.lside==dice2.lside:
    if dice1.dside==dice2.dside: 
        print("Yes")
    else: 
        print("No")
else:
    print("No")



Measured memory_bytes: 8188
def main():
    x = int(input())
    a = 0
    while True:
        b = a**5 - x
        if b < 0:
            b = abs(b-0)**(1/5)
            b = b * (-1)
        else:
            b = b**(1/5)
        b = int(b)

        if a**5 - b**5 == x:
            print(a,b)
            return 0
        else:
            a+=1
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 62336
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
    IO;
    ll k;
    cin>>k;
    if(k%2==0||k%5==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    ll sum=0,len=1,p=1;
    while(true)
    {
        sum=(sum+7*p)%k;
        if(sum==0) 
        {
            cout<<len<<endl;
            break;
        }
        len++;
        p=p*10%k;
    }
return 0;
}

Measured memory_bytes: 3588
from math import gcd


def factorization(n):
    global Ans, flag
    if n == 1:
        return
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            Ans[i] += 1
            if Ans[i] == 2:
                flag = True


    if temp != 1:
        Ans[temp] += 1
        if Ans[temp] == 2:
            flag = True

    return


N = int(input())
A = list(map(int, input().split()))
a = A[0]
flag = False
for b in A[1:]:
    a = gcd(a, b)

if a != 1:
    print('not coprime')
    exit()
ma = max(A) + 1
Ans = [0] * (ma)

Ans[0] = 1
for a in A:
    factorization(a)
    if flag:
        print('setwise coprime')
        exit()
print('pairwise coprime')

Measured memory_bytes: 205272
#include<bits/stdc++.h>
#include<math.h>
const double PI = acos(-1);
using namespace std;
int main()
{
  long int n;
  cin>>n;
  int flag=0;
  for(int i=1;i<10;i++)
  {
      for(int j=1;j<10;j++)
      {
          if(i*j==n){
          flag=1;
    
              break;
          }
      }
  }
  
  if(flag==1)
  cout<<"Yes";
  else 
  cout<<"No";
  

    
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>dp(3);
    for(int i=0;i<n;i++){
        vector<int>c(3);
        vector<int>new_dp(3,0);
        for(int j=0;j<3;j++){
            cin>>c[j];
        }
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k){
                    new_dp[k]=max(new_dp[k],dp[j]+c[k]);
                }
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]})<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    IOS;
    int N; cin >> N;
    vector<int> X,Y;
    rep(i,N){
        int a; cin >> a;
        X.push_back(a);
        Y.push_back(a);
    }
    sort(X.begin(),X.end());
    int A=X[N/2],B=X[N/2-1];
    rep(i,N){
        if(upper_bound(X.begin(),X.end(),Y[i])-X.begin()>N/2)
        cout << B << endl;
        else 
        cout << A << endl;
    }

    return 0;
}


Measured memory_bytes: 5604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int n = s.nextInt();
        int [] arr =new int[n];
        for(int i=0;i<n;i++){
            arr[i]=s.nextInt();
        }
        int t=arr[0];
        for(int i=1;i<n;i++){
            t^=arr[i];
        }
        for(int i=0;i<n;i++){
            System.out.print((arr[i]^t)+" ");
        }
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 59220
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define exists(s,x) (s).find(x)!=(s).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
#define fi first
#define se second
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}
inline ll modpow(ll x, ll y) {
    ll res = 1;
    while(y) {
        if(y&1) res = mul(res,x);
        y >>= 1;
        x = mul(x,x);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, K; cin >> N >> K;
    ll ans = 0;
    while(N != 0) {
        ans += 1;
        N /= K;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int x,y,z;cin>>x>>y>>z;
  int num=y+2*z,ans=0;
  while(1)
  {
  	if(num>x)break;
  	num+=y+z;
  	ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int W,H,x,y,r;

    scanf("%d %d %d %d %d %d",&W,&H,&x,&y,&r);

    int yoko1 = x + r;
    int yoko = x - r;
    int tate1 = y + r;
    int tate = y - r;

    if ( yoko1 > W || yoko < 0 || tate1 > H || tate < 0 ) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}


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



 int main() {
  long long int n,sum,ans;
  sum=0;
  vector<long long int> v;
  multiset<long long int> s;
  vector<long long int> cnt;
  vector<long long int> num;
  cin>>n;
  for(long long int i=0;i<n;i++){//0番目から数字を入れていく
    long long int tmp;
    cin>>tmp;
    v.push_back(tmp);
    s.insert(tmp);
  }
  for(long long int i=0;i<n;i++){
    long long int tmp;
    tmp=s.count(i+1);//1からnまでの数を数える
    num.push_back(tmp);
    if(tmp>0){ 
      tmp=tmp*(tmp-1)/2;//1個以上あったら通り数を計算する
    }
    cnt.push_back(tmp);//1~nの通り数をcntに収める
    sum+=tmp;
  }
  for(long long int i=0;i<n;i++){
    long long int tmp=num[v[i]-1];
    ans=sum;
    if(tmp>2){
      tmp-=1;
      ans-=tmp;     
    }else if(tmp==2){
      ans-=1;
    }
   cout<<ans<<endl;
  }
}



Measured memory_bytes: 18544
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define EPS 0.00000000001
#define INF 2000000000000000000
char s[MAX],t[MAX];
int main()
{
    int n,i;
    char c;
    for(i=0;;i++)
    {
        scanf("%c",&c);
        if('a'<=c&&c<='z')
        {
            s[i]=c;
        }
        else break;
    }
    n=i;
    int ans=0;
    for(i=0;i<n;i++)
    {
        scanf("%c",&t[i]);
        if(s[i]!=t[i]) ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 4212
unittest
{
	assert( [ "10 9 10 10" ].parse.expand.solve == "No" );
	assert( [ "46 4 40 5" ].parse.expand.solve == "Yes" );
}



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

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

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

auto solve( long a, long b, long c, long d )
{
	while( true )
	{
		c -= b;
		if( c <= 0 ) return "Yes";
		a -= d;
		if( a <= 0 ) return "No";
	}
}


Measured memory_bytes: 2780
#include<bits/stdc++.h>
using namespace std;
char a[40]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
int main ()
{
	char t;
	int sum,ans;
	for(int i=0;i<16;i++)
	{
		cin>>t;
		if(t!=a[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
int a;
int b;
scanf("%d %d",&a,&b);
if (a == 1 && b == 2 || a == 2 && b == 1)
{
  printf("3");
}
else if(a == 2 && b == 3 || a == 3 && b == 2)
{
printf("1");
}
else if(a == 3 && b == 1 || a== 1 && b == 3)
{
printf("2");
}
return(0);
}

Measured memory_bytes: 128
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();

    for (int c = M / N; c > 0; c--) {
      if (M % c != 0) continue;
      System.out.println(c);
      return;
    }
  }
}


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

int main() {
  int n, x, y;
  const int mod(1000000007);
  cin >> n;
  vector<vector<int>> trees(n);
  int sub[n];
  long fac[n], invfac[n], f[n], g[n], ans[n];
  
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    trees[x - 1].push_back(y - 1);
    trees[y - 1].push_back(x - 1);
  }
  
  auto mod_pow = [&](long a){
    long b(mod - 2), r(1);
    while (b) {
      if (b % 2) r = r * a % mod;
      a = a * a % mod;
      b /= 2;
    }
    return r;
  };
  
  for (int i = 0; i < n; ++i) {
    fac[i] = i ? fac[i - 1] * i % mod : 1;
    invfac[i] = mod_pow(fac[i]);
  }
  
  auto mod_add = [&](long a, long b){ return (a + b) % mod; };
  auto mod_mul = [&](long a, long b){ return a * b % mod; };
  auto mod_div = [&](long a, long b){ return a * mod_pow(b) % mod; };
  
  
  
  
  
  
  function<void(int, int)> root = [&](int i, int p) {
    f[i] = sub[i] = 1;
    for (const int& j: trees[i]) {
      if (j == p) continue;
      root(j, i);
      f[i] = mod_div(mod_mul(f[i], f[j]), fac[sub[j]]);
      sub[i] += sub[j];
    }
    f[i] = mod_mul(f[i], fac[sub[i] - 1]);
  };
  
  root(0, -1);
  
  function<void(int, int)> reroot = [&](int i, int p) {
    g[i] = 1;
    if (p != -1) {
      g[i] = mod_mul(mod_mul(fac[sub[i]], fac[n - sub[i] - 1]),
                     mod_mul(f[p], g[p]));
      g[i] = mod_div(g[i], mod_mul(f[i],
                           mod_mul(fac[sub[p] - 1], fac[n - sub[p]])));
    }
    for (const int& j: trees[i]) {
        if (j == p) continue;
        reroot(j, i);
    }
    ans[i] = mod_mul(f[i], mod_mul(g[i], fac[n - 1]));
    ans[i] = mod_div(ans[i], mod_mul(fac[sub[i] - 1], fac[n - sub[i]])); 
  };
  
  reroot(0, -1);
  
  for (int i = 0; i < n; ++i)
    cout << ans[i] << '\n';
  
  return 0;  
}

Measured memory_bytes: 22516
(function(stdin) {
  function makeArray(n) {
    var arr = [];
    for (var i = 0; i < n; i++) {
      arr.push(0);
    }
    return arr;
  }

  function inRoomData(room, data) {
    var line = makeArray(room[0][0].length * 2).join('').replace(/0/g, '#');
    data.map(function(v) {
      room[v[0] - 1][v[1] - 1][v[2] - 1] += v[3];
      return v;
    });
    return room.map(function(v) {
      return v.map(function(w) {
        return ' ' + w.join(' ');
      }).join('\n');
    }).join('\n' + line + '\n');
  }
  var inputs = stdin.toString().trim().split('\n');
  var manData = inputs.map(function(v) {
    return v.split(' ').map(Number);
  });
  var allRoom = makeArray(4).map(function() {
    return makeArray(3).map(function() {
      return makeArray(10);
    });
  });
  manData.shift();
  console.log(inRoomData(allRoom, manData));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 15824
/*
C:\Users\jolog\CLionProjects\progcpp
 */
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define endl '\n'
//#define int long long

signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int x, y, z; cin >> x>> y>>z;
        swap(x, y);
        swap(x, z);
        cout << x << ' ' << y << ' ' << z;
        return 0;
}

/*

*/

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
using namespace std;
typedef pair<int,int> PII;

int P[100]; //union_find

int root(int i){
    if(P[i] == i) return i;
    else return P[i] = root(P[i]);
}

bool same(int x, int y){
    return root(P[x]) == root(P[y]);
}

void unite(int x, int y){
    P[root(x)] = root(y);
}

int main(){
    int n;
    cin >> n;
    int g[n][n];
    vector<pair<int,PII>> V;
    REP(i,n){
        REP(j,n){
            cin >> g[i][j];
            if(i<j && g[i][j] >= 0) V.pb(mp(g[i][j],mp(i,j)));
        }
    }
    sort(all(V));
    REP(i,n){
        P[i] = i;
    }
    int wsum = 0, count = 0;
    REP(i,n*n){
        int x = V[i].snd.fst;
        int y = V[i].snd.snd;
        if(same(x,y)) continue;
        unite(x,y);
        wsum += V[i].fst;
        count++;
        if(count == n-1) break;
    }

    cout <<wsum<<endl;

    return 0;
}

Measured memory_bytes: 3128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int n, m;
    static int[] s, c;

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        n = sc.nextInt();
        m = sc.nextInt();
        s = new int[m];
        c = new int[m];

        for (int i = 0; i < m; i++) {
            s[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        for (int i = 0; i < 1000; i++) {
            if (isAns(i)) {
                System.out.println(i);
                System.exit(0);
            }
        }

        System.out.println(-1);
    }

    static boolean isAns(int a) {
        boolean isAns = true;
        switch (n) {
            case 1:
                if (a >= 10)
                    isAns = false;
                break;
            case 2:
                if (a < 10 || a >= 100)
                    isAns = false;
                break;
            case 3:
                if (a < 100)
                    isAns = false;
        }

        if (isAns) {
            int[] ans = new int[3];
            int tmp = a;
            for (int i = 0; i < 3; i++) {
                ans[i] = tmp % 10;
                tmp /= 10;
            }
            for (int i = 0; i < m; i++) {
                if (ans[n-s[i]] != c[i]) {
                    isAns = false;
                    break;
                }
            }
        }

        return isAns;
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 32796
package main

import "fmt"

type submit struct {
	number int
	result string
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	submits := make([]submit, m)
	for i, s := range submits {
		fmt.Scan(&s.number, &s.result)
		s.number--
		submits[i] = s
	}
	ac, wa := cal(submits, n)
	fmt.Println(ac, wa)
}

func cal(submits []submit, n int) (int, int) {
	accepts := make([]bool, n)
	warongs := make([]int, n)
	cntAC, cntWA := 0, 0

	for _, submit := range submits {
		if accepts[submit.number] != true {
			if submit.result == "AC" {
				accepts[submit.number] = true
				// cntAC++
				cntWA += warongs[submit.number]
			}
			if submit.result == "WA" {
				warongs[submit.number]++
			}
		}
	}

	for _, a := range accepts {
		if a {
			cntAC++
		}
	}
	// for _, w := range warongs {
	// 	cntWA += w
	// }

	return cntAC, cntWA
}


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

int main()
{
  int n;
  cin >> n;
  int prev_small;
  cin >> prev_small;
  int second;
  cin >> second;
  int res;
  res = second - prev_small;
  if (second < prev_small)
  {
    prev_small = second;
  }
  for (int i = 0; i < n - 2; ++i)
  {
    int tmp;
    cin >> tmp;
    if (prev_small > tmp)
    {
      prev_small = tmp;
    }
    else
    {
      int challenge = tmp - prev_small;
      if (res < 0)
      {
      }
      if (res < challenge)
      {
        res = challenge;
      }
    }
  }
  cout << res << endl;
}



Measured memory_bytes: 3120
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pii> v(n);
		rep(i,n){
			int id;
			cin>>id;
			int t=0;
			rep(j,4){
				int a,b;
				cin>>a>>b;
				t+=a*60+b;
			}
			v[i]=mkp(t,id);
		}
		sort(ALL(v));
		cout<<v[0].S<<endl;
		cout<<v[1].S<<endl;
		cout<<v[v.size()-2].S<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n, k;

vector<i64> e[MAXN];

i64 R = 1;

void dfs(i64 c, i64 p, i64 z, i64 l) {
    i64 t = max(0ll, k - min(l, 2ll) - z);
    R *= t;
    R %= mod;
    //cerr << c << " = " << t << endl;
    i64 j = 0;
    for (i64 i = 0; i < e[c].size(); i++) {
        i64 v = e[c][i];
        if (v == p) {
            continue;
        }
        dfs(v, c, j++, l + 1);
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;

    for (i64 i = 0; i < n - 1; i++) {
        i64 u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    dfs(1, 0, 0, 0);

    cout << R;

    return 0;
}


Measured memory_bytes: 11648
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion

string Alphabet[26] = { "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", };

int main() {
	int h, w; put h >> w;
	rep(i, h) {
		rep(j, w) {
			string s; put s;
			if (s == "snuke") {
				cout << Alphabet[j] << i + 1 << endl;
				goto END;
			}
		}
	}
END:
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	int x;
	cin >> a >> b >> c >> x;
	int count = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int l = 0; l <= c; l++) {
				if (i*500 + j*100 + l*50 == x)count++;
			}
		}
	}
	cout << count << endl;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int A;
  cin >> A;
  cout << A + A * A + A * A * A << "\n";
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        String givenNum = sc.next();
        givenNum = new StringBuilder(givenNum).reverse().toString();
        int x = 1, tot = 0;
        List<Integer> cnt = new ArrayList<>(2019);
        for (int i = 0; i < 2019; i++) {
            cnt.add(0);
        }
        long ans = 0;
        for (int i = 0; i < givenNum.length(); i++) {
            cnt.set(tot, cnt.get(tot) + 1);
            tot += (givenNum.charAt(i) - '0') * x;
            tot %= 2019;
            ans += cnt.get(tot);
            x = x * 10 % 2019;
        }
        System.out.println(ans);
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;

    if(a < b) {
        cout << "a < b" << endl;
    } else if(a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int wc = 0;
    for (int i = 0; i < n; i++) if (s[i] == 'W') wc++;
    int tr = 0;
    int ans = n - wc;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') tr++;
        else wc--;
        chmin(ans, max(i + 1 - tr, n - i - 1 - wc));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define moda 998244353
#define pi 3.14159265358979323846
#define io ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cout<<x<<"\n";
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const ll INF = 1e18*(-1);

int main()
{

	io

   ll n, w;
   cin>>n>>w;

   ll a[w + 1];

   a[0] = 0;

   for(ll i = 1 ; i <= w ; i++)
   		a[i] = INF;

   for(ll i = 0, x, y ; i < n ; i++)
   {
   		cin>>x>>y;

   		for(ll j = w ; j >= 0 ; j--)
   		{
   			if(j - x >= 0)
   			{
   				if(a[j - x] >= 0)
   					a[j] = max(a[j], a[j - x] + y);
   			}
   		}
   }

   ll mi = INF;

   for(ll i = 0 ; i <= w ; i++)
   		mi = max(a[i], mi);

   	cout<<mi<<"\n";

return 0;
}


Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define 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 (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  int ans = 0;
  rep(i,1,n+1){
    ans += (i + (n - n%i))*(n/i)/2;
  }
  cout << ans << endl;
}

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define eps 1e-9

const int MOD = 1e9+7;

typedef long long ll;
typedef pair<int,int> pii;

ll POWER[65];
ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
ll inv(ll x) {return power(x,MOD-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}
const int MAXN = 52;
ll dp[MAXN][2503][MAXN];
int ar[MAXN];
int n,a;
ll go(int idx, int sum, int now) {
	if(idx==n+1 and now*a==sum) return 1;
	else if(idx==n+1) return 0;
	if(dp[idx][sum][now]!=-1) return dp[idx][sum][now];
	ll ret=0;
	ret+=go(idx+1,sum,now);
	ret+=go(idx+1,sum+ar[idx],now+1);
	return dp[idx][sum][now]=ret;
}
int main() {
//	freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout);
	precompute();
	cin>>n>>a;
	for(int i=1;i<=n;i++) cin>>ar[i];
	memset(dp,-1,sizeof(dp));
	cout<<go(1,0,0)-1<<endl;
	return 0;
}


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

int main(){
	int N,K;
	cin >> N >> K;
	vector<int> A(N);
	for(auto &i:A)cin >> i;
	vector<long long> S(N+1,0);
	for(int i=0;i<N;i++)S[i+1]=(S[i]+(A[i]-1))%K;
	
	long long ans=0;
	map<long long,vector<int>> m;
	
	for(int i=0;i<N+1;i++){
		m[S[i]].push_back(i);
	}
	
	for(auto p:m){
		auto v=p.second;
		for(int i=0;i<v.size();i++){
			ans+=(int)(lower_bound(v.begin(),v.end(),v[i]+K)-lower_bound(v.begin(),v.end(),v[i]))-1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    string x;
    cin >>x;

    rep(i,x.length()){
        x[i]='x';
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<x<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	public static void main(String[] args) {
		try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str;
            while ((str = br.readLine()) != null) {
            	String[] num = str.split(" "); 
            	int guest = Integer.parseInt(num[0]);
            	int match = Integer.parseInt(num[1]);
            	int[] startTime = new int[guest];
            	int[] endTime = new int[guest];
            	int[] gapTime = new int [guest - 1];
            	
            	for (int i = 0; i < guest; i++) {
            		startTime[i] = Integer.parseInt(br.readLine());
            		endTime[i] = startTime[i] + 1;
            		if (i == 0) continue;
            		gapTime[i-1] = startTime[i] - endTime[i-1];
            	}
            	
            	Arrays.sort(gapTime);
            	
            	int tmp = guest - match;
            	int totalTime = guest;
            	for (int i = 0; i < tmp; i++) {
            		totalTime += gapTime[i];
            	}
            	System.out.println(totalTime);

            }
            } catch (Exception e) {
                System.out.println(e);
            }
	}

}



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

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    while(q--){
        int a, b;
        cin >> a >> b;
        if(n == 1 || a == 1){
            cout << a << "\n";
            continue;
        }
        while(a != b){
            if(b < a){
                swap(a, b);
            }
            if(b % n <= 1){
                b /= n;
            }else{
                b /= n;
                b++;
            }
        }
        cout << a << "\n";
    }
}

Measured memory_bytes: 1280
import sys
S=input()
N=len(S)
for i in range(N):
    for j in range(i,N+1):
        T=S[0:i]
        L=S[j:N+1]
        #print(T+L)
        if T+L=='keyence':
            print('YES')
            sys.exit()
print('NO')


Measured memory_bytes: 38768
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<cassert>
using namespace std;
#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0,-1,0,1};
static const int dy[4] = {1,0,-1,0};
static const char dir[4] = {'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{ int f[N2],space,MD; };

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle);
bool isSolved(void);
bool dfs(int,int);
string iterative_deepening(Puzzle);

int main() {

  for(int i=0;i<N2;i++) 
    for(int j=0;j<N2;j++) 
      MDT[i][j] = abs(i/N-j/N) + abs(i%N-j%N);
  
  Puzzle in;
  
  for(int i=0;i<N2;i++) {
    cin >> in.f[i];
    if(in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;
  
  return 0;

}

int getAllMD(Puzzle pz) {

  int sum = 0;
  for(int i=0;i<N2;i++) {
    if(pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i]-1];
  }
  return sum;
}

bool isSolved() {
  for(int i=0;i<N2;i++) if(state.f[i] != i+1) return false;
  return true;
}

bool dfs(int depth,int prev) {
  if(state.MD == 0) return true;
  if(depth+state.MD > limit) return false;

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for(int r=0;r<4;r++) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
    if(max(prev,r)-min(prev,r) == 2) continue;
    tmp = state;

    state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty],state.f[sx*N+sy]);
    state.space = tx*N+ty;
    if( dfs(depth+1,r) ) { path[depth] = r; return true; }
    state = tmp;
  }

  return false;

}

string iterative_deepening(Puzzle in) {
  in.MD = getAllMD(in);

  for(limit=in.MD;limit<=LIMIT;limit++) {
    state = in;
    if(dfs(0,-100)) {
      string ans = "";
      for(int i=0;i<limit;i++) ans += dir[path[i]];
      return ans;
    }
  }

  return "unsolvable";

}




Measured memory_bytes: 3232
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9

int main(){
    int n,m;
    while(cin>>n>>m&&n&&m){
        map<int,int> mn,mm;
        int a[2000],b[2000];
        rep(i,n) cin>>a[i];
        rep(i,m) cin>>b[i];
        
        rep(i,n){
            int t=0;
            for(int j=i;j<n;j++){
                t+=a[j];
                mn[t]++;
            }
        }
        rep(i,m){
            int t=0;
            for(int j=i;j<m;j++){
                t+=b[j];
                mm[t]++;
            }
        }
        int sum=0;
        for(auto &x:mn){
            sum+=x.second*mm[x.first];
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 32468