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

int main(){
    int N;
    cin>>N;
    int k;
    cin>>k;
    int arr[N];

    for (int i = 0; i < N; ++i){
        cin >> arr[i];
    }

    vector<int> dp(N, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < N; ++i){
        for (int j = 1; j <= k; ++j){
            if(i + j <= N){
                dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i + j] - arr[i]));
            }
        }
    }
    cout << dp[N - 1]<<endl;
    return 0;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define sz(a) (int)((a).size())
#define fuck() cout<<"--------"<<endl
#define see(x) cout<<#x<<" = "<<x<<endl
#define see2(x,y) cout<<#x<<" = "<<x<<"::"<<#y<<" = "<<y<<endl 
const int mod=1000000007;
typedef pair<int,int> pii;
const int inf=1e17;
const int N=1e5+5;
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    string s;
    cin>>s;
    if(s[2]==s[3] and s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a,b,c,d; 
int main()
{
   cin>>a>>b>>c>>d;
   while(1)
   {
   	   c-=b;
   	  
   	   if(a<=0) {
   	   	cout<<"No"<<endl;return 0;
		  }
      a-=d;
		if(c<=0){
   	   	cout<<"Yes"<<endl;return 0;
		  }
   }


return 0;
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> m;
int n;
vector<int> a;

bool dfs(int as, int i, int tar) {
    // cout << as << " " << i << " " << tar << endl;
    if (i == n) {
        if (as == tar) {
            return true;
        } else {
            return false;
        }
    }
    // a[i]を足すバージョン
    return dfs(as+a[i], i+1, tar) || dfs(as, i+1, tar);
}

int main() {
    cout << fixed << setprecision(10);
    
    cin >> n;
    // vector<int> a(n);
    a.resize(n);
    rep(i, n) cin >> a[i];
    int q; cin >> q;
    m.resize(q);
    rep(i, q) {
        cin >> m[i];
    }

    rep(i, q) {
        if (dfs(0, 0, m[i])) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}


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

int main()
{
  char s[200001];
  int h1, h2, m1, m2, k;
  scanf("%s", s);
  int max = strlen(s);
  for (int i = 0; i < max; i++){
    if(s[i] == '?') s[i] = 'D';
  }
  printf("%s\n", s);
  return 0;
}

Measured memory_bytes: 1856
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  vector<ll> A;
  rep(i,N){
    ll a;
    cin >> a;
    A.push_back(a);
  }

  ll ret = 0;
  ret += A[0]-1;
  ll mn = 1;
  REP(i,1,N){
    if(mn >= A[i]) continue;
    if(A[i]==(mn+1)){
      mn++;
    }else{
      ll cnt = (A[i]-1)/(mn+1);
      ret += cnt;
    }
  }
  
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 1400
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pop_front(a) a.erase(a.begin())
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	forever
	{

		vector<int>taro, hanako;
		cin >> n;
		if (n == 0) { break; }
		loop(i, n) {
			int u;
			cin >> u;
			taro.push_back(u);
		}
		Sort(taro);
		for (int i = 1; i <= 2 * n; i++) {
			bool flag = false;
			for (int j = 0; j < taro.size(); j++) {
				if (taro[j] == i) { flag = true; }
			}
			if (!flag) { hanako.push_back(i); }
		}
		int now_card = 0;//今のカード
		bool turn=true;//true taro, false hanako
		forever
		{
			if (taro.size() == 0 || hanako.size() == 0) {
				cout << hanako.size() << endl << taro.size() << endl;
				break;
			}
			if (turn) {
				for (int i = 0; i < taro.size(); i++) {
					if (taro[i] > now_card) {
						now_card = taro[i];
						taro.erase(taro.begin() + i);
						break;
					}
					if (i == taro.size() - 1) {
						now_card = 0;
					}
				}
			}
			else {
				for (int i = 0; i < hanako.size(); i++) {
					if (hanako[i] > now_card) {
						now_card = hanako[i];
						hanako.erase(hanako.begin() + i);
						break;
					}
					if (i == hanako.size() - 1) {
						now_card = 0;
					}
				}

			}


			turn = !turn;
		}

	}
	return 0;
}


Measured memory_bytes: 3100
N, M = map(int, input().split())
A = [{i for i in range(0, 10)} for _ in range(N)]
if N > 1:
    A[0].discard(0)
T = True
for _ in range(M):
    s, c = map(int, input().split())
    A[s-1] = A[s-1] & set([c])
    if len(A[s-1]) == 0:
        T = False
if T:
    X = ''
    for i in range(N):
        X += str(min(A[i]))
    print(X)
else:
    print(-1)

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

int main(void)
{
	int a, b, k;
	cin >> a >> b >> k;
	
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			if (a % 2 == 1) {
				a--;
			}
			int t = a/2;
			a -= t;
			b += t;
		}
		else {
			if (b % 2 == 1) {
				b--;
			}
			int t = b/ 2;
			b -= t;
			a += t;
		}
	}
	cout << a << " " << b << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  string S,ans="NO",T="KIHBR"; cin>>S;
  ll j=0,count=0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='A'){
      count++;
      if(count>1) break;
    }
    else if(S[i]==T[0]){
      if(S[i+1]!=T[1]) break;
      if(S[i+2]!=T[2]) break;
      i+=2, j+=3, count=0;
    }
    else if(S[i]==T[j]){
      j++, count=0;
    }
    else break;
    if(i==S.size()-1 && j==5) ans="YES";    
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		char[] s=ir.next().toCharArray();
		s[5]=s[13]=' ';
		out.println(new String(s));
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

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

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

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int n,k;
string s;
vector <int> arr;
int res;

void enter()
{
    cin >> n >> k >> s;
}

void setup_arr()
{
    int i = 0, dem = 1;
    if (n == 1) arr.push_back(1);
    else
    {
        while (i < n)
        {
            if (i >= 1)
            {
                if (s[i] != s[i-1])
                    {
                        arr.push_back(dem);
                        dem = 1;
                    }
                else dem++;
                if (i == n - 1) arr.push_back(dem);
            }
        i++;
        }
    }

    //for (int i = 0 ; i < arr.size() ; i++) cout << arr[i] << " ";
    //cout << endl;
}

void case_1()
{
    if (s[0] == '1')
    {

        int temp_sum = 0;
        if (2*k > arr.size() - 1)
        {
            for (int i = 0; i <= arr.size() - 1; i ++)
                temp_sum += arr[i];
            res = temp_sum;
        }
        else
        {
            for (int i = 0; i <= 2*k; i ++)
            temp_sum += arr[i];

            //cout << temp_sum << endl;
            res = max(res,temp_sum);

            int j = 0;
            for (int i = 2*k + 1; i < arr.size() ; i ++)
            {
                if (i % 2 != 0)
                {
                    temp_sum -= (arr[j] + arr[j+1]);
                    j += 2;
                }
                temp_sum += arr[i];
                res = max(res,temp_sum);
            }
        }

    }

}

void case_0()
{
    if (s[0] == '0')
    {

        int temp_sum = 0;
        if (2*k - 1 > arr.size() - 1)
        {
            for (int i = 0; i <= arr.size() - 1; i ++)
            temp_sum += arr[i];
            res = temp_sum;
        }
        else
        {
            for (int i = 0; i <= 2*k - 1; i ++)
            temp_sum += arr[i];

            //cout << temp_sum << endl;
            res = max(res,temp_sum);

            if (2*k == arr.size() - 1)
            {
                temp_sum += arr[2*k];
                temp_sum -= arr[0];
                res = max(res,temp_sum);
            }
            else
            if (2*k + 1 == arr.size() - 1)
            {
                temp_sum += arr[2*k] + arr[2*k + 1];
                temp_sum -= arr[0];
                res = max(res,temp_sum);
            }
            else
            if (2*k + 1 < arr.size() - 1)
            {
                temp_sum += arr[2*k] + arr[2*k + 1];
                temp_sum -= arr[0];
                res = max(res,temp_sum);

                int j = 1;

                for (int i = 2*k + 2; i < arr.size() ; i ++)
                {
                    if (i % 2 == 0)
                    {

                        temp_sum -= (arr[j] + arr[j+1]);
                        j += 2;

                    }
                    temp_sum += arr[i];
                    res = max(res,temp_sum);
                }
            }
        }

    }
}

void process()
{
    setup_arr();
    case_1();
    case_0();
}

void print_res()
{

    cout << res;

}

int main()
{

    enter();
    process();
    print_res();
    return 0;

}


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

/*
int64_t ryuka(int n) {
    if (n == 0) return 2;
    if (n == 1) return 1;
    return (int64_t) ryuka(n-1) + ryuka(n-2);
}
*/

int64_t ryuka(int n) {
    int count = 0;
    int64_t ryu1 = 2, ryu2 = 1;
    while (count != n) {
        if (count%2 == 0) ryu1 = ryu1 + ryu2;
        else ryu2 = ryu1 + ryu2;
        count++;
    }
    if (count%2 == 0) return ryu1;
    else return ryu2;
}

int main() {
    int n;
    cin >> n;
    ct(ryuka(n));
}

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

signed main()
{
  int A[3];

  Rep(i, 3) cin >> A[i];

  sort(A, A + 3);

  int cnt = 1;
  cnt += A[0] != A[1];
  cnt += A[1] != A[2];

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np
from bisect import bisect_left

D = int(input())
C = np.array(list(map(int, input().split())))
S = np.array([list(map(int, input().split())) for d in range(D)])

L = np.empty(26, int)
L[:] = -1

X = [[-1] for _ in range(26)]
T = []

score = 0
for d in range(D):
    t = int(input())-1
    T.append(t)
    L[t] = d
    score += S[d, t] - np.dot(C, d-L)
    X[t].append(d)

for x in X:
    x.append(D)
    
M = int(input())
for _ in range(M):
    d, q = map(int, input().split())
    d-=1
    q-=1

    t = T[d]
    T[d] = q
    
    i = bisect_left(X[t], d)
    d_prev = X[t][i-1]
    d_next = X[t][i+1]
    
    dd = d-d_prev-1
    score += C[t]*(dd+1)*dd//2
    dd = d_next-d-1
    score += C[t]*(dd+1)*dd//2
    dd = d_next-d_prev-1
    score -= C[t]*(dd+1)*dd//2

    X[t].pop(i)
    
    i = bisect_left(X[q], d)
    d_prev = X[q][i-1]
    d_next = X[q][i]
    
    dd = d-d_prev-1
    score -= C[q]*(dd+1)*dd//2
    dd = d_next-d-1
    score -= C[q]*(dd+1)*dd//2
    dd = d_next-d_prev-1
    score += C[q]*(dd+1)*dd//2

    X[q].insert(i, d)

    score += S[d,q] - S[d,t]

    print(score)


Measured memory_bytes: 27440
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	while (true) {
		int h = sc.nextInt();
		int w = sc.nextInt();             
		if (h == 0 && w == 0) return;            
		for (int i = 0; i < h; i++) {                 
		for (int j = 0; j < w; j++) {                     
		System.out.print(((i + j) % 2 == 0)? '#' : '.'); 
		}                 
		System.out.println();             
		}             
		System.out.println(); 
		}
        }
}

Measured memory_bytes: 29040
import sys

input = sys.stdin.readline

def main():
    ans = 0
    A, B = map(int, input().split())
    for i in range(A, B+1):
        s = str(i)
        if s == s[::-1]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

const ll MOD { 1000000007 };
const double PI = acos(-1.0);

#define stdfor(i, a, b) for(int i = (a); i < (b); ++i)
#define invfor(i, n, b) for(int i = (n); i--; )
#define foreach(a, b) for(auto& a : b)
#define cforeach(a, b) for(const auto& a : b)
#define sz(a) ((int)(a.size()))
#define fill(a,v) memset(a, v, sizeof a)
#define all(a) a.begin(), a.end()
#define in(a,b) ((b).find(a) != (b).end())
#define entre(l, i, r) (l<i&&i<r)
#define pb push_back
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int A, B;

    cin >> A >> B;

    cout << (!(B%A) ? A+B : B-A) << endl;
 
    return 0;
}

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

int n, r;

int main(){

    scanf("%d", &n);
    for(int i = n; i>=1; i--){
        std::string out_string;
        std::stringstream ss;
        ss << i;
        out_string = ss.str();
        if(out_string.size()%2==1)r++;
    }
    printf("%d\n", r);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N - i; ++j) {
            int rem = Y - 10000 * i - 5000 * j;
            if (rem < 0) continue;
            if (rem / 1000 == N - i - j) {
                cout << i << " " << j << " " << rem / 1000 << endl;
                return;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "2" ].solve == 14 );
	assert( [ "10" ].solve == 1110 );
}



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

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

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	return n + n ^^ 2 + n ^^ 3;
}


Measured memory_bytes: 2760
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


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

  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= n; ++j){
      if(i + j > n) break;
      if(10000 * i + 5000 * j + 1000 * (n - i - j) == y){
        cout << i << " " << j << " " << n - i - j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 100005
using namespace std;
int n,num,fa[MN],sz[MN],head[MN];
struct edge{int to,next;}g[MN<<1];
void dfs(int u,int f){
	fa[u]=f;sz[u]=1;
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=f)dfs(g[i].to,u),sz[u]+=sz[g[i].to];
}
void ins(int u,int v){g[++num].next=head[u];head[u]=num;g[num].to=v;}
int main(){
	scanf("%d",&n);int x,y;
	for(int i=1;i<n;i++)scanf("%d%d",&x,&y),ins(x,y),ins(y,x);dfs(1,1);
	int tmp=n,cnt=0,cnt2=0;while(tmp!=1)tmp=fa[tmp],cnt++;cnt--;tmp=n;
	while(cnt2<cnt/2)tmp=fa[tmp],cnt2++;
	printf("%s\n",sz[tmp]<sz[1]-sz[tmp]?"Fennec":"Snuke");
}

Measured memory_bytes: 7552
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	map<char,bool> ball;
	ball['A']=true;
	ball['B']=false;
	ball['C']=false;

	string s;
	while(cin>>s){
		swap(ball[s[0]],ball[s[2]]);
	}

	for(auto it=ball.begin();it!=ball.end();it++){
		if(it->second)  cout<<it->first<<endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
#define int long long

class Mod{
public:
    vector<int>fac;
    vector<int>finv;
    vector<int>inv;
    int MOD;

    Mod(int MAX=1e6,int mod=1e9+7){
        MOD = mod;
        fac.resize(MAX+2);
        finv.resize(MAX+2);
        inv.resize(MAX+2);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; 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;
        }
    }

    int com(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    int add(int a, int b){
        return (a + b)%MOD;
    }
    
    int mul(int a,int b){
        return (a*b)%MOD;
    }
    
    int modinv(int a) {
        int b = MOD, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        return u;
    }
    
    int div(int a, int b){
        return (a*modinv(b)%MOD);
    }
};

signed main(void){
    Mod M;
    int n,k; cin >> n >> k;
    for(int i=1;i<=k;i++){
        cout << M.mul(M.com(n-k+1,i),M.com(k-1,i-1)) << endl;
    }
    return 0;
}

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

using namespace std;

int n, m, x, y, state[100000], dp[100000], ans;
vector<int> g[100000], top;

void dfs(int a)
{
  if(state[a]==2)
    return;
  state[a] = 1;
  for(int i = 0; i<g[a].size(); i++)
    dfs(g[a][i]);
  state[a] = 2;
  top.push_back(a);
}

int main()
{
  cin >> n >> m;
  for(int i = 0; i<m; i++)
  {
    cin >> x >> y;
    g[x-1].push_back(y-1);
  }
  for(int i = 0; i<n; i++)
    if(!state[i])
      dfs(i);
  for(int i = n-1; i>=0; i--)
    for(int j = 0; j<g[top[i]].size(); j++)
      dp[g[top[i]][j]] = max(dp[g[top[i]][j]],dp[top[i]]+1);
  for(int i = 0; i<n; i++)
    ans = max(ans,dp[i]);
  cout << ans << endl;
}


Measured memory_bytes: 8440
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    if n %2== 0:
        print(a[0]+sum(a[1:n//2])*2)
    else:
        print(a[0]+sum(a[1:n//2])*2+a[n//2])



if __name__ == '__main__':
    main()

Measured memory_bytes: 31400
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n,ans[100004];
vector <pii> g[100004];
void dfs(int x,int now){
	ans[x]=now%2;
	for (int i=0;i<g[x].size();i++) if (ans[g[x][i].first]==-1) dfs(g[x][i].first,(now+g[x][i].second)%2);
}
int main(){
	memset (ans,-1,sizeof(ans));
	cin>>n;
	for (int i=0;i<n-1;i++){
		int x,y,z;
		cin>>x>>y>>z;
		g[x].push_back(make_pair(y,z));
		g[y].push_back(make_pair(x,z));  
	}
	dfs(1,0);
	for (int i=1;i<=n;i++) cout<<ans[i]<<"\n";
}

Measured memory_bytes: 8448
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    long N =sc.nextLong();
    long ans =0;
    for(long i=1;i<=N;i++){
      if(!(i%3==0||i%5==0)){
        ans=ans+i;
      }
    }
    System.out.println(ans);
  }
    


  
}


Measured memory_bytes: 35800
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	char c;
	cin >> c;
	cout << char(int(c) + 1) << endl;
}                                

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define llMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n;

int main(){
  cin >> n;
  vector<int>h(n+1);
  for(int i = 0; i<n; i++)cin >> h[i];

  int dp[n];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);

  for(int i = 2; i<n; i++){
    int tmp1 = dp[i-1] + abs(h[i] - h[i-1]);
    int tmp2 = dp[i-2] + abs(h[i] - h[i-2]);
    dp[i] = min(tmp1, tmp2);
    // cout << i <<" "<<dp[i] << endl;
  }
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#define MAX_N 100010
typedef long long ll;
using namespace std;

int N;
int a[MAX_N];
int d[MAX_N];
ll sum;

int main () {
    scanf("%d", &N);
    for (int i = 1;i <= N; ++i) {
	scanf("%d", a + i);
	d[i] = abs(a[i] - a[i - 1]);
	sum += d[i];
    }
    d[N + 1] = abs(a[N]);
    sum += d[N + 1];
    for (int i = 1;i <= N; ++i) {
	printf("%d\n", sum - d[i] - d[i + 1] + abs(a[i + 1] - a[i - 1]));
    }
    return 0;
}


Measured memory_bytes: 2048
let pn = 1000000007

let pow x n =
  let rec doit x n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (x * x) (n / 2) acc
    else doit (x * x) (n / 2) (acc * x) in
  doit x n 1

let fold_left f init s n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (f acc s.[i]) in
  doit 0 init

let () =
  let p = read_line () in
  let t = read_line () in
  let n = String.length p in
  let m = String.length t in
  let h = Array.make (n + 1) 0 in
  let hash x c = x * pn + Char.code c in
  String.iteri (fun i c -> h.(i+1) <- hash h.(i) c) p;
  let ht = fold_left hash 0 t m in
  let x = pow pn m in
  for i = m to n do
    if h.(i) - h.(i-m)*x = ht then Printf.printf "%d\n" (i - m);
  done

Measured memory_bytes: 14272
x, k, d = map(int, input().split())

count = abs(x)/d
if count.is_integer():
    count = int(count)
else:
    count = int(count)+1
    
if x >= 0:
    if count >= k:
        print(abs(x-k*d))
    else:
        if (k-count)%2 == 0:
            print(abs(x-d*count))
        else:
            print(x-d*count+d)
else:
    if count >= k:
        print(abs(x+k*d))
    else:
        if (k-count)%2 == 0:
            print(abs(x+d*count))
        else:
            print(-x-d*count+d)


Measured memory_bytes: 9192
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####

from collections import defaultdict as ddic

def solve(N, A, Q, queries):
    count = ddic(int)
    for x in A:
        count[x] += 1
    S = sum(A)
    for b, c in queries:
        ct = count[b]
        count[b] = 0
        count[c] += ct
        S += (c-b) * ct
        print S
        

N = rri()
A=rrm()
Q= rri()
queries = [rrm() for _ in xrange(Q)]
solve(N, A, Q, queries)


Measured memory_bytes: 101012
import sys
import numpy as np

A = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(A):
    s = str(input())
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    elif s == 'RE':
        RE += 1

print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)


Measured memory_bytes: 27136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

int main(void) {
    ll n;
    cin>>n;
    vl p(n);
    rep(i,n){
        ll a;
        cin>>a;
        p[a-1] = i;
    }
    ll left = inf;
    ll ans = 0;
    rep(i,n){
        if(left > p[i]){
            ans++;
            left = p[i];
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4760
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    string S,T;
    cin>>N>>S>>T;

    string a;

    for(int i=0;i<N;++i){
        a.push_back(S[i]);
        a.push_back(T[i]);
    }
    
    cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	s[3]='8';
	cout<<s;
	
	return 0;
}

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp  make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2500 + 5;
const int mod = 1e9 + 7;
int n , a , b;
ll Pow(ll a , ll b){
    if(b == 0)return 1;
    ll r = Pow(a,b/2);
    if(b&1)return (ll)r * r % mod * a%mod;
    return r * r%mod;
}
int nck(int n , int k){
    if(k < 0 || k > n)return 0;
    int res = 1;
    for(int i = 1 ; i <= k ; ++i){
        res = res * Pow(i,mod-2)%mod*(n-k+i)%mod;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin >> n >> a >> b;
//    cout << nck(2,1) << endl;
    cout << (Pow(2,n) - 1 - nck(n,a)-nck(n,b)+(ll)mod*mod)%mod;
}



Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

bool solve() {
    string S;
    cin >> S;
    for(int i = 0; i <= 2; i++) if(S[i] == S[i + 1]) return false;
    return true;
}

int main() {
    cout << (solve() ? "Good" : "Bad") << endl;
    return 0;
}


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

int main() {
    long long N,A,B; cin>>N>>A>>B;
    vector<int> X(N);
    rep(i,N) cin>>X[i];
    long long ans=0;
    for (int i=0;i<N-1;++i) {
        ans+=min((X[i+1]-X[i])*A, B);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  ll a,b,ans=0; cin >>a >>b;
  if(a%2==1){ans^=a; a++;}
  if(b%2==0){ans^=b; b--;}
  if((b-a+1)%4) ans^=1;
  cout <<ans;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
using Graph = vector<vector<int> >;

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            prev[nv] = v;
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) cout << prev[v] + 1 << endl;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

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

    int n;
    cin>>n;
    int a=0,w=0,t=0,r=0;
    string s;
    for(int i=0;i<n;i++) {
        cin>>s;
        if(s[0]=='A') {
            a++;
        }
        else if(s[0]=='W')
            w++;
        else if(s[0]=='R')
            r++;
        else
            t++;
    }   
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<w<<"\n";
    cout<<"TLE x "<<t<<"\n";
    cout<<"RE x "<<r<<"\n";

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 110;
ll arr[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    ll ans = mod;
    cin >> n;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
    }
    for(int k = -MAX_N; k <= MAX_N; k ++) {
        ll curr = 0;
        for(int i = 0; i < n; i ++) {
            curr += (k - arr[i]) * (k - arr[i]);
        }
        chkmin(ans, curr);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC152A
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int N = int.Parse(word[0]);
            int M = int.Parse(word[1]);
            if (N==M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

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

    string S;
    cin >> S;

    int len = S.length();

    int l, r;
    if (len % 2) r = l = len / 2 + 1;
    else l = len / 2, r = len / 2 + 1;

    int cnt = 0;
    char bk = S[l - 1];
    while (bk == S[l - 1] && S[l - 1] == S[r - 1])
    {
        l--;
        r++;
        cnt++;
        if (l < 0 || len < r) break;
    }

    cout << len / 2 + cnt << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    """
    根を固定させたバージョンをまず考える．
    木dpをしたいのでノードに通り数を持たせる．
    通り数が同じでも部分木のサイズが異なると，親要素の通り数は変わる（1-2-3-4で2が親のときを想起）ので
    通り数と部分木のサイズは持つ必要あり．
    子要素が2つの時を考える，
    左がa通り+b個
    右がc通り+d個
    a+cを並び替えてa側でb通り，c側でd通りなので
    (a+c)Ca *b*d
    ということは，各子要素の通り数をai，サイズをbiとして，
    Πai * (Σbi)!/(Π(bi!))
    シグマの部分だけ後回し（調整）
    
    あとは全方位化
    """
    N=I()

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]
    
    for i in range(2, 2*N+10):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
    
    adj=[[]for _ in range(N)]
    for i in range(N-1):
        a,b=MI()
        a-=1
        b-=1
        adj[a].append(b)
        adj[b].append(a)
        
    import queue
    
    P=[-1]*N#親リスト
    Q=queue.Queue()#BFSに使う
    R=[]#BFSでトポソしたものを入れる
    
    Q.put(0)#1回目では0を根とする
    
    #トポソ########################
    while not Q.empty():
        v=Q.get()
        R.append(v)
        for nv in adj[v]:
            if nv!=P[v]:
                P[nv]=v
                adj[nv].remove(v)#親につながる辺を消しておく
                Q.put(nv)
    
    #1が上りで，2が下り
    size1=[1]*N
    size2=[0]*N
    dp1=[1]*N
    dp2=[1]*N
    
    #先にサイズは求めておく
    for v in R[1:][::-1]:
        size1[P[v]]+=size1[v]
        
    for v in range(N):
        size2[v]=N-size1[v]
    
    for v in R[1:][::-1]:#根以外を後ろから
        dp1[v]=(dp1[v]*fact[size1[v]-1])%mod
        p=P[v]
        dp1[p]=(dp1[p]*dp1[v]*factinv[size1[v]])%mod
        
    #根だけ
    dp1[R[0]]=(dp1[R[0]]*fact[size1[R[0]]-1])%mod

        
    #累積和ではなく逆元で．ここではしっかり根から決まっていく
    for v in R[1:]:
        p=P[v]
        
        #下り部分，根側
        temp=dp2[p]
        
        # 親要素のdp1から自分のdp1を引くことで，親周りの自分以外の寄与を求めた
        temp2=(dp1[p]*pow(dp1[v],mod-2,mod))%mod
        temp=(temp*temp2)%mod
        
        
        temp=(temp*factinv[size1[p]-1]*fact[size1[v]])%mod#親のところは親要素の分を加味して1引く
        temp=(temp*factinv[size2[p]]*fact[size2[v]-1])%mod#逆側から見たときは，vがpの親に見える
        dp2[v]=temp
        
    for i in range(N):
        #上側と下側の塗り方を考慮して（これは結局，一番最初のa+bCaに近い）
        ans=(dp1[i]*dp2[i]*fact[N-1]*factinv[size1[i]-1]*factinv[size2[i]])%mod
        print(ans)
        
        
        
        
    
    
        
  
        

main()


Measured memory_bytes: 168856
import java.util.*
//val allNeightBours = mutableMapOf<Pair<Int, Int>,Boolean>()
val map = mutableListOf<String>()
var H = 0
var W = 0
var s = Pair(0,0)
var t = Pair(0,0)
fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)

    H = reader.nextInt()
    W = reader.nextInt()
    s = Pair(reader.nextInt() - 1, reader.nextInt() - 1)
    t = Pair(reader.nextInt() - 1, reader.nextInt() - 1)

    var allNeightBours = Array(H){
        val elms = IntArray(W)
            elms.fill(0)
        elms
    }

    repeat(H){
        map.add(reader.next())
    }
    val neighboursQueue = ArrayDeque<Pair<Int, Int>>()

    neighboursQueue.push(s)
    allNeightBours[s.first][s.second] = 1
    var swapNum = 0
    var findTarget = false

    var checkedNeighbous = mutableListOf<Pair<Int, Int>>()
    while(neighboursQueue.size > 0 && findTarget.not()){
        val checkPoint = neighboursQueue.pop()
        checkedNeighbous.add(checkPoint)
        listOf(Pair(1, 0), Pair(-1, 0), Pair(0, 1), Pair(0, -1)).forEach nearloop@{
            var newPoint = Pair(checkPoint.first + it.first, checkPoint.second + it.second)
            if ((newPoint.first >= 0 && newPoint.first < H && newPoint.second >= 0 && newPoint.second < W) &&
                allNeightBours[newPoint.first][newPoint.second] == 0 &&
                map[newPoint.first][newPoint.second] == '.'
            ) {
                if(newPoint == t){
                    findTarget = true
                    return@nearloop
                }
                else {
                    neighboursQueue.add(newPoint)
                    allNeightBours[newPoint.first][newPoint.second] = 1
                }
            }
        }
        if(findTarget){
            break
        }
        if(neighboursQueue.size == 0){
            swapNum+= 1
            checkedNeighbous.forEach farloop@{neighbour ->
                repeat(5){countH->
                    repeat(5){ countW->
                        val tempH = neighbour.first - 2 + countH
                        val tempW = neighbour.second - 2 + countW

                        if((tempH < 0 || tempH >= H || tempW < 0 || tempW >= W) ||
                            allNeightBours[tempH][tempW] == 1 ||
                            map[tempH][tempW] != '.'){

                        }
                        else {
                            if(tempH == t.first && tempW == t.second){
                                findTarget = true
                                return@farloop
                            }
                            else {
                                val item = Pair(tempH, tempW)
                                neighboursQueue.add(item)
                                allNeightBours[item.first][item.second] = 1
                            }
                        }
                    }
                }
            }
            checkedNeighbous.clear()
        }
    }
    println(if(findTarget)swapNum else -1)
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

struct mint {
  ll x;
  friend ostream& operator<<(ostream& os, const mint& m) {
    os << m.x;
    return os;
  }
  mint(ll x=0): x((x%mod+mod)%mod) {}
  mint& operator-=(const mint a) {
    if((x-=a.x) < 0) x+=mod;
    return *this;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint& operator+=(const mint a) {
    if((x+=a.x) >= mod) x-=mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x*=a.x) %= mod;
    return *this;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll ex) const {
    if (!ex) return 1;
    if (ex&1) return (*this)*pow(ex-1);
    mint root = pow(ex>>1);
    return root * root;
  }
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    (*this) *= a.inv();
    return *this;
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct Sieve {
  vector<int> table;
  Sieve(int n=2): table(n+1) {
    table[0] = table[1] = -1;
    // table[x]==xとなるidxが素数となるように設定してるので継続条件が異なる
    // for(int i=2; i*i<=n; i++) {
    for(ll i=2; i<=n; i++) {
      if(!table[i]) table[i] = i;
      for(ll j=i*i; j<=n; j+=i) { // llじゃないとi=46342のときi*iでoverflow
        if(!table[j]) table[j] = i;
      }
    }
  }
  friend ostream& operator<<(ostream& os, const Sieve& sieve) {
    for(int i=0; i< sieve.table.size(); i++) {
      os << sieve.table[i] << " ";
    } os << endl;
    return os;
  }
  map<ll,ll> factor(ll x) {
    map<ll,ll> m;
    if (table[x] == -1) return m;
    while(table[x]!=x) {
      m[table[x]]++;
      x /= table[x];
    }
    m[table[x]]++;
    return m;
  }
};

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> as;
  Sieve sieve((int)1e6);

  map<ll,ll> lcm;

  REP(i, n) {
    ll a;
    cin >> a;
    as.push_back(a);
    map<ll,ll> factor = sieve.factor(a);
    for(auto f: factor) {
      lcm[f.first] = max(lcm[f.first], f.second);
    }
  }

  mint c = 1;
  for(auto f: lcm) {
    REP(i, f.second) {
      c *= f.first;
    }
  }

  mint ans = 0;
  for(auto a: as) {
    mint b = c/a;
    ans += b;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4864
#include <iostream>

using namespace std;

int main(){
  int X, N=100004;
  cin >> X;
  int A[N];
  for (int i = 0; i < N; i++){
    A[i] = 1;
  }
  A[0] = A[1] = 0;
  for (int i = 2; i * i < N; i++){
    if (A[i]==1){
      for (int j = i * i; j < N; j+=i){
        A[j] = 0;
      }
    }
  }
  
  for (int i = X; i < N; i++){
    if(A[i]==1){
      printf("%d\n", i);
      break;
    }
  }
}


Measured memory_bytes: 4108
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N; cin >> N;
    vector<int> H(N), diff(N-1), rst(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    int mrst = 0;
    for (int j = 1; j < N; ++j) {
        diff[j-1] = H[j] - H[j-1];
        if (diff[j-1] <= 0) {
            rst[j] += rst[j-1] + 1;
            mrst = max(rst[j], mrst);
        } else {
            rst[j] = 0;
        }
    }
    cout << mrst << endl;
}

Measured memory_bytes: 1408