akhauriyash/Code-Regression huggingface dataset:
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), M = scanner.nextInt();
        scanner.nextLine();
        int[][] q = new int[M][2];
        for (int i = 0; i < M; i++) {
            q[i] = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).map(x -> x - 1).toArray();
        }

        UFT uft = new UFT(N);
        long ans[] = new long[M];
        for (int i = 1; i < N; i++) {
            ans[M - 1] += i;
        }
        for (int i = M - 1; i >= 1; i--) {
            int f = q[i][0];
            int t = q[i][1];
            if (!uft.same(f, t)) {
                ans[i - 1] = Math.max(0, ans[i] - uft.cnt(f) * uft.cnt(t));
                uft.merge(f, t);
            } else {
                ans[i - 1] = ans[i];
            }
        }

        for (long a: ans) {
            System.out.println(a);
        }

    }

    static class UFT {
        int x;
        int[] par;
        int[] cnt;

        UFT(int x) {
            this.x = x;
            par = new int[x];
            cnt = new int[x];
            for (int i = 0; i < x; i++) {
                par[i] = i;
                cnt[i] = 1;
            }
        }

        int root(int x) {
            if (x == par[x]) {
                return x;
            }
            int root = root(par[x]);
            par[x] = root;
            return root;
        }

        void merge(int x, int y) {
            int xr = root(x);
            int yr = root(y);
            par[yr] = xr;
            cnt[xr] += cnt[yr];
        }

        boolean same(int x, int y) {
            return root(x) == root(y);
        }

        int cnt(int x) {
            return cnt[root(x)];
        }
    }

}


Measured memory_bytes: 164192
package main

import "fmt"

func main() {
	var b string
	fmt.Scan(&b)
	fmt.Println(helix(b))
}

func helix(b string) string {
	if b == "A" {
		return "T"
	}
	if b == "T" {
		return "A"
	}
	if b == "C" {
		return "G"
	}
	if b == "G" {
		return "C"
	}
	return ""
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans=0, n=0,m,count,sum=0,ch=0;
	llint s;
	bool check = false;
	vector<llint> a;
	vector<llint> r,b;
	char c,d,e;
	cin >> c>>d>>e;
	if (c == '7' || d == '7' || e == '7')cout << "Yes" << endl;
	else cout << "No" << endl;
	
	please AC;
}


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

long power(long x, long y, long mod){
  if(y==0)return 1;
  else if(y==1)return x;
  else if(y%2==0)return (power(x,y/2,mod)*power(x,y/2,mod))%mod;
  else return (((power(x,y/2,mod)*power(x,y/2,mod))%mod) *x)%mod;
}


int main(){
  string s;
  long k;
  cin >> k >> s;
  long mod = INF;
  long lens = int(s.size());
  long ans = 0;
  long comb = 1, tmp = lens;
  for(long i=0;i<=k;i++){
    ans += (((power(25,i,mod)*comb)%mod)*power(26,k-i,mod))%mod;
    ans %= mod;
    comb *= (tmp * power(i+1,mod-2,mod))%mod;
    comb %= mod;
    tmp++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5252
<?php

$n = trim(fgets(STDIN));

$min = $n+$n;
$s = [];
for($i=1; $i<=sqrt($n); $i++){
  
  if ($n%$i==0){
      $x= $i;
      $y = $n/$x;
      $m = $x+$y;
    
      if ($m < $min){
        $min = $m;
      }
  }
}
  
echo $m-2;

?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
const int N=32010;
const int mod=998244353;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct poly {
    vector<int> v;
    int &operator[](int x) {
        return v[x];
    }
    void set(int n) {
        v.resize(n+1);
    }
    int get() {
        return (int)v.size()-1;
    }
};
int qpow(int a,int b) {
    int ret=1;
    while(b) {
        if(b&1) ret=1ll*ret*a%mod;
        a=1ll*a*a%mod,b>>=1;
    }
    return ret;
}
int add(int a,int b) {
    return a+b>=mod?a+b-mod:a+b;
}
int sub(int a,int b) {
    return a-b<0?a-b+mod:a-b;
}
void inc(int &a,int b) {
    a=(a+b>=mod)?a+b-mod:a+b;
}
void dec(int &a,int b) {
    a=(a-b<0)?a-b+mod:a-b;
}
void NTT(poly &a,int n,int f,vector<int> &r) {
    for(int i=0;i<n;i++)
        if(i<r[i]) swap(a[i],a[r[i]]);
    for(int i=1;i<n;i<<=1) {
        int wn=qpow(3,(mod-1)/(i<<1));
        if(f==-1) wn=qpow(wn,mod-2);
        for(int p=i<<1,j=0;j<n;j+=p) {
            int w=1;
            for(int k=0;k<i;k++,w=1ll*w*wn%mod) {
                int x=a[j+k],y=1ll*w*a[j+k+i]%mod;
                a[j+k]=add(x,y),a[j+k+i]=sub(x,y);
            }
        }
    }
    if(f==-1) {
        int inv=qpow(n,mod-2);
        for(int i=0;i<n;i++) a[i]=1ll*a[i]*inv%mod;
    }
}
poly operator*(poly a,poly b) {
    int n=a.get(),m=b.get(),l=0;
    m+=n;for(n=1;n<=m;n<<=1) ++l;
    vector<int> r(n);
    for(int i=0;i<n;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
    a.set(n-1),b.set(n-1);
    NTT(a,n,1,r),NTT(b,n,1,r);
    for(int i=0;i<n;i++) a[i]=1ll*a[i]*b[i]%mod;
    NTT(a,n,-1,r);
    a.set(m);return a;
}
int n,m,fac[N],ifac[N];
poly f[N];
void init() {
    const int n=30000;
    fac[0]=1;for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    ifac[n]=qpow(fac[n],mod-2);
    for(int i=n-1;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int C(int n,int m) {
    if(n<0||m<0||n<m) return 0;
    return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main() {
    n=gi(),m=gi(),init();
    f[0].set(n),f[0][0]=1;
    for(int i=0;i<m;i++) {
        f[i+1].set(n);
        for(int j=0;j<=n;j++) inc(f[i+1][j],1ll*f[i][j]*add(C(j+1,2),1)%mod);
        poly A,B;A.set(n),B.set(n+2);
        for(int j=0;j<=n;j++) A[j]=1ll*f[i][j]*ifac[j]%mod;
        for(int j=3;j<=n+2;j++) B[j]=ifac[j];
        poly C=A*B;
        for(int j=0;j<=n;j++) inc(f[i+1][j],1ll*C[j+2]*fac[j+2]%mod);
    }
    int ans=0;
    for(int i=0;i<=n;i++) {
        inc(ans,1ll*C(n,i)*f[m][i]%mod);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int num = 0;
    char c;
    bool flag = false;
    while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
        if (c == '-') flag = true;
    else
        num = c - '0';
    while (isdigit(c = getchar()))
    num = num * 10 + c - '0';
    return (flag ? -1 : 1) * num;
}
int main()
{
	int a,b;
	char c;
	a=read();
	cin>>c;
	b=read();
	if(c=='+') cout<<a+b<<endl;
	else cout<<a-b<<endl;
	return 0;
}



Measured memory_bytes: 256
n = int(raw_input())

nums = [[[0 for x in range(10)] for x in range(3)] for x in range(4)]

for idx in range(n):

    b, f, r, v  = tuple([int(x) for x in raw_input().split(" ")])
    nums[b-1][f-1][r-1] += v

for i_b in range(4):
    if i_b != 0: print "#"*20
    for i_f in range(3):
        print " " + " ".join([str(x) for x in nums[i_b][i_f]])

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

using namespace std;

int main()
{
    long long int a,b,c,k,result;
    cin>>a>>b>>c>>k;
    result=min(k,a);
    if(k>a+b){
        result-=k-a-b;
    }
    cout<<result;
    return 0;
}


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

void shake(int D[], char c) {
		int tmp;
		switch (c) {
				case 'S':
						tmp = D[0];
						D[0] = D[4];
						D[4] = D[5];
						D[5] = D[1];
						D[1] = tmp;
						break;
				case 'E':
						tmp = D[0];
						D[0] = D[3];
						D[3] = D[5];
						D[5] = D[2];
						D[2] = tmp;
						break;
				case 'W':
						tmp = D[0];
						D[0] = D[2];
						D[2] = D[5];
						D[5] = D[3];
						D[3] = tmp;
						break;
				case 'N':
						tmp = D[0];
						D[0] = D[1];
						D[1] = D[5];
						D[5] = D[4];
						D[4] = tmp;
						break;
				case 'R':
						tmp = D[1];
						D[1] = D[3];
						D[3] = D[4];
						D[4] = D[2];
						D[2] = tmp;
						break;
				case 'L':
						tmp = D[1];
						D[1] = D[2];
						D[2] = D[4];
						D[4] = D[3];
						D[3] = tmp;
						break;
		}
}

void print(int D[], int n)
{
		int i;
		cout << "\n---" << n << "---\n";
		for (i=0; i<6; i++) cout << "D[" << i << "]:" << D[i] << "\n";
}

int main()
{
		int D1[6], D2[6], i, j;
		bool is=false;
		string op;
		for (i=0; i<6; i++) cin >> D1[i];
		for (i=0; i<6; i++) cin >> D2[i];

		op = "NNNNRNNNN";
		for (i=0; i<op.size(); i++) {
				if (D1[0]==D2[0]&&D1[5]==D2[5]) break;
				else shake(D2, op[i]);
		}
		op = "RRRR";
		for (i=0; i<op.size(); i++) {
				if (D1[0]==D2[0]&&D1[1]==D2[1]) {
						if (D1[2]==D2[2]&&D1[3]==D2[3]) {
								if (D1[4]==D2[4]&&D1[5]==D2[5]) {
										is = true;
										break;
								}
						}
				}
				shake(D2, op[i]);
		}

		if (is) cout << "Yes\n";
		else cout << "No\n";
}

Measured memory_bytes: 3172
n = int(input())
a = list(map(int, input().split()))
#b = []
#for ai in a:
#  b.append(str(ai))
#  b = list(reversed(b))
#print(' '.join(b))
if len(a) % 2 == 0:
  even = []
  odd = []
  for i, ai in enumerate(a):
    if (i + 1) % 2 == 0:
      even.append(str(ai))
    else:
      odd.append(str(ai))

  r = list(reversed(even))
  answer = r + odd
  print(' '.join(answer))
else:
  even = []
  odd = []
  for i, ai in enumerate(a):
    if (i + 1) % 2 == 0:
      even.append(str(ai))
    else:
      odd.append(str(ai))
  r = list(reversed(odd))
  answer = r + even
  print(' '.join(answer))

Measured memory_bytes: 34372
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N; double P[3030][3030];

int main()
{
	scanf ("%d",&N);
	P[0][0] = 1;
	for (int i=0;i<N;i++){
		double p; scanf ("%lf",&p);
		for (int j=0;j<=i;j++){
			P[i+1][j+1] += P[i][j] * p;
			P[i+1][j] += P[i][j] * (1 - p);
		}
	}

	double ans = 0;
	for (int i=N,j=0;i>j;i--,j++) ans += P[N][i];
	printf ("%.12lf\n",ans);

	return 0;
}

Measured memory_bytes: 70144
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll H,W;
    cin >> H >> W;
    vector <string> a(H);
    REP(i,H)
    {
        cin >> a[i];
    }

    vector <int> alpha(26,0);
    REP(i,H)
    {
        REP(j,W)
        {
            ++alpha[a[i][j] - 'a'];
        }
    }

    //例えば5, 1なら (2,2,1 or 5)の構成で勝てる
    //これが2,5になると、4,4,2でないと勝てない。(4,4,6でも勝てる)
    //これが3,5になると、4,4,2,{5 or(2,2,1)}でも勝てるようになる
    //これが4,4になると、4,4,2でないと勝てない。

    //H,Wから、4を何組、2を何組、1を何組必要か求める
    //alphaをアッパーでソートして、あてがう

    int hitu4,hitu2,hitu1;
    //4で必要な数 2*2 -> 1 4 * 4 -> 4
    hitu4 = (H/2) * (W/2);
    hitu2 = (H*W - hitu4*4) / 2;
    hitu1 = (H*W) % 2;

    sort(alpha.rbegin(),alpha.rend());

    string res;

    int cnt = hitu4 + hitu2 + hitu1;
    int tar = 0;
    while(cnt > 0)
    {
        for(int i = 0; i < 26; ++i)
        {
            if(alpha[i] == 0)continue;
            if(alpha[i] >= 4 && hitu4 > 0)
            {
                --hitu4;
                --cnt;
                alpha[i] -= 4;
            }
            else if(alpha[i] >= 2 && hitu2 > 0)
            {
                --hitu2;
                --cnt;
                alpha[i] -= 2;
            }
            else if(alpha[i] >= 1)
            {
                --hitu1;
                --cnt;
                alpha[i] -= 1;
            }
        }
    }

    if(hitu4 == 0 && hitu2 == 0 && hitu1 == 0)
    {
        res = "Yes";
    }
    else res = "No";

    

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int A = sc.nextInt();
    int B = sc.nextInt();

    if (A > 8 || B > 8) {
      System.out.println(":(");
    } else {
      System.out.println("Yay!");
    }
  }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  int s[n+10];
  int sum=0;
  rep(i,0,n){cin>>s[i];sum+=s[i];}
  sort(s,s+n);
  if(sum%10!=0){out(sum);return 0;}
  rep(i,0,n){
    if(s[i]%10!=0){out(sum-s[i]);return 0;}
  }
  out(0);

  return 0;
}


Measured memory_bytes: 256
//Buble sort
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i = 0; n > i; i++){
    cin>>a[i];
    b[i] = a[i];
  }
  sort(b.begin(),b.end());
  for(int i = 0; n > i; i++){
    a[i] = lower_bound(b.begin(),b.end(),a[i])-b.begin();
  }
  int ans = 0;
  for(int i = 0; n > i; i++){
    if(i%2 != a[i]%2){
      ans++;
    }
  }

  
  cout << ans/2 << endl;
}

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

const int MAXN = 3005;

string s, t;
int dp[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> s >> t;
    for (int i = 0; i <= s.length(); i++) {
        for (int j = 0; j <= t.length(); j++) {
            if (i == 0 || j == 0) dp[i][j] = 0;
            else if (s[i-1] == t[j-1]) dp[i][j] = 1+dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    vector<char> ans;
    int i = s.length(), j = t.length();
    while (i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            ans.push_back(s[i-1]);
            i--; j--;
        } else if (dp[i-1][j] > dp[i][j-1]) i--;
        else j--;
    }
    for (int i = ans.size()-1; i >= 0; i--) cout << ans[i];
    cout << "\n";
    return 0;
}


Measured memory_bytes: 38864
#include<stdio.h>
int d[201][201],l[8],u[8],n,m,r,a;
void df(int c,int p,int e){
  if(c==r){if(a>e)a=e;return;}
  for(int i=0;i<r;i++)if(u[i]){u[i]=0;if(p==-1)df(c+1,i,0);else df(c+1,i,e+d[l[p]][l[i]]);u[i]=1;}
}
int main(){
  int i,j,k,x,y,z;
  scanf("%d%d%d",&n,&m,&r);n++;
  for(i=0;i<r;i++){scanf("%d",&l[i]);u[i]=1;}
  for(i=1;i<n;i++)for(j=1;j<n;j++)d[i][j]=(i!=j)*(1<<29);
  for(i=0;i<m;i++){scanf("%d%d%d",&x,&y,&z);d[x][y]=d[y][x]=z;}
  for(k=1;k<n;k++)for(i=1;i<n;i++)for(j=1;j<n;j++)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
  a=1<<29;df(0,-1,0);
  printf("%d",a);
}


Measured memory_bytes: 1888
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int a[3]; rep(i, 3) cin >> a[i];
    sort(a, a + 3, greater<int>());
    int k; cin >> k;
    rep(i, k) a[0] *= 2;
    int ans = 0;
    rep(i, 3) ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &x[i])
	}

	ans := 1000000
	for p := 1; p <= 100; p++ {
		tmp := 0
		for i := 0; i < n; i++ {
			tmp += (x[i] - p) * (x[i] - p)
		}
		if ans > tmp {
			ans = tmp
		}
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
n,a,b = map(int, input().split())
if a > b:
    print(0)
elif a==b:
    print(1)
elif n == 1 and a!=b:
    print(0)
elif n == 1:
    print(1)
elif n == 2:
    print(1)
else:
    c1 = a * n + (b-a)
    c2 = b * n - (b-a)
    print(c2-c1 + 1)

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

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
    int N, A[2][101] = {}, a;
    cin >> N;
    REP(i, 2) REP(j, N) {
        cin >> a;
        A[i][j + 1] = A[i][j] + a;
    }
    int ans = 0;
    FOR(i, 1, N + 1)
        ans = max(ans, A[0][i] + A[1][N] - A[1][i - 1]);
    cout << ans << endl;
    return 0;
}

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

int main(){
	
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		int cnt=-1;
		for(int j=0;j<w;j++){
			char c;cin>>c;
			if(c=='c')cnt=0;
			else if(cnt>=0)cnt++;
			cout<<cnt;
			if(j==w-1)cout<<endl;
			else cout<<" ";
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 1160
def Warshall_Floyd(dist,n,restoration=False):
    next_point = [[j for j in range(n)] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if dist[j][k] > dist[j][i] + dist[i][k]:
                    next_point[j][k] = next_point[j][i]
                    dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
    if restoration:
        return dist,next_point
    else:
        return dist

n,m,l = map(int,input().split())
inf = 10**18
dist = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    dist[i][i] = 0

for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    if c <= l:
        dist[a][b] = c
        dist[b][a] = c

dist = Warshall_Floyd(dist,n)
route = [[inf for i in range(n)] for j in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            route[i][j] = 0
        elif dist[i][j] <= l:
            route[i][j] = 1

route = Warshall_Floyd(route,n)

q = int(input())


for i in range(q):
    s,t = map(int,input().split())
    s -= 1
    t -= 1
    print(route[s][t]-1 if route[s][t] < inf else -1)

Measured memory_bytes: 60632
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define modd 998244353
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
vector<lld> adj[300000][3];
ar<lld,3> siz;
lld grundy[300000][3];
map<lld,lld> sums[3];
lld fastpower(lld x, unsigned lld y, lld p)
{
    lld res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void dfs_grundy(lld node,lld grp){
    if (grundy[node][grp]!=-1)return ;
  //  grundy[node][grp]=0;
    vector<lld> mex;
    //nums[0][grp]++;
    for (auto it:adj[node][grp]){
        if (it<node) continue;
        dfs_grundy(it,grp);
        mex.pb(grundy[it][grp]);
    }
    if (mex.empty()) {grundy[node][grp]=0;sums[grp][0]+=fastpower(10,18*(node+1),modd);sums[grp][0]%=modd;return;}
    sort(all(mex));
    auto ip = unique(all(mex));
    mex.resize(distance(mex.begin(),ip));
    rep(i,0,mex.size()-1){
        if (i!=mex[i]){
            grundy[node][grp]=i;
        //    nums[0][grp]--;
      //      nums[i][grp]++;
            sums[grp][i]+=fastpower(10,18*(node+1),modd);sums[grp][i]%=modd;
            return ;
        }
    }
    grundy[node][grp]=mex.size();
    //nums[0][grp]--;
    //nums[mex.size()][grp]++;
    sums[grp][mex.size()]+=fastpower(10,18*(node+1),modd);sums[grp][mex.size()]%=modd;
}
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
//     ans=0;
     //cin>>TESTS;
     memset(grundy,-1,sizeof(grundy));
     while(TESTS--)
     {
         cin>>n;
         rep(j,0,2){
         cin>>siz[j];
         rep(i,0,siz[j]-1){
            cin>>a>>b;a--;b--;
            adj[a][j].pb(b);
            adj[b][j].pb(a);
         }
         }
         rep(j,0,2) rep(i,0,n-1) dfs_grundy(i,j);
         lld ans=0;
         rep(i,0,1000) rep(j,0,1000) {
            lld k=i^j;
            if(k<sums[2].size())ans+=(((sums[0][i]*sums[1][j])%modd)*sums[2][k])%modd;
            ans%=modd;
         }
         cout<<ans;
     }
    return 0;
}


Measured memory_bytes: 39296
#include <stdio.h>

int main(void) {
  int n,a[100],i,j,count,ans = 0;
  scanf("%d",&n);
  for (i = 0;i < n;i++) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < n - 1;i++) {
    if (a[i] == a[i + 1]) {
      count = 2;
      for (j = i + 2;j < n;j++) {
        if (a[i] == a[j]) {
          count++;
        } else {
          break;
        }
      }
      ans += count / 2;
      i = j - 1;
    }
  }
  printf("%d\n",ans);
}


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

int main(){
    int K = 26;
    int D;
    cin >> D;
    vector<ll> C(K);
    for (int i = 0; i < K; i++) cin >> C[i];
    vector<vector<ll>> s(D+1, vector<ll>(K, 0));
    for (int i = 1; i <= D; i++) {
        for (int j = 0; j < K; j++) {
            cin >> s[i][j];
        }
    }
    
    vector<int> ans(D+1, 0);
    
    vector<set<int>> day(K);
    for (int i = 0; i < K; i++) {
        day[i].insert(0);
        day[i].insert(D+1);
    }
    vector<int> cnt(K, 0);
    for (int i = 1; i <= D; i++) {
        int op = 0;
        int s_mx = 0;
        for (int j = 0; j < K; j++) {
            if (s_mx < s[i][j]) {
                s_mx = s[i][j];
                op = j;
            }
        }
        day[op].insert(i);
        ans[i] = op+1;
    }
    
    ll inf = 1e18;
    ll r = 123456789;
    ll mod = 1e9+7;
    int repmax = 300000;
    for (int rep = 0; rep < repmax; rep++) {
        r = r*r%mod;
        int a = r%D+1;
        
        int def = ans[a]-1;
        
        ll pt_max = -inf; 
        ll op = 0;
        day[def].erase(day[def].find(a));
        for (int i = 0; i < K; i++) {
            if (i == def && rep < repmax/2) continue;
            auto it = day[i].lower_bound(a);
            ll nxt = (*it);
            it--;
            ll pre = (*it);
            ll pt = ((nxt-pre)*(nxt-pre+1)/2 - ((a-pre)*(a-pre+1)/2+(nxt-a)*(nxt-a+1)/2)) * C[i] + s[a][i];
            if (pt > pt_max) {
                pt_max = pt;
                op = i;
            }
        }
        day[op].insert(a);
        ans[a] = op+1;
    }
    
    for (int i = 1; i <= D; i++) cout << ans[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3744
// B - Picture Frame

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int H, W;
	cin >> H >> W;

	vector<string> S;

	string s;
	for (int i=0; i<H; i++) {
		cin >> s;
		S.push_back("#" + s + "#");
	}

	for (int i=0; i<W+2; i++) {
		cout << "#";
	}
	cout << endl;

	for (int i=0; i<H; i++) {
		cout << S[i] << endl;
	}

	for (int i=0; i<W+2; i++) {
		cout << "#";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int s[n];
	int sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		sum += s[i];
	}
	sort(s, s + n);

	if(sum % 10 == 0) {
		bool sub = false;
		for (int i = 0; i < n; i++)
		{
			if(!sub && s[i] % 10 != 0) {
				sum -= s[i];
				sub = true;
			}
		}
	}

	if(sum % 10 != 0) cout << sum << endl;
	else cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 3596
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY
N,K=get_i
S=get_nsp.map(&:to_i)
num=[]
num.push(0) if S[0]==0
i=0
while i<N
    j=i
    j+=1 while j<N and S[i]==S[j]
    num.push(j-i)
    i=j
end
num.push(0) if S[-1]==0
n=num.size
accum_sum=array(n+1,0)
n.times do|i|
    accum_sum[i+1]=accum_sum[i]+num[i]
end
ans=0
#p accum_sum
0.step(n-1,2) do|l|
  r=min(l+2*K+1,n)
  ans=max(ans,accum_sum[r]-accum_sum[l])
end
puts ans

Measured memory_bytes: 21704
let () =
  let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m) in
  let xys = Array.init m (fun _ -> Scanf.scanf "%d %d\n" (fun x y -> x - 1, y - 1)) in
  let balls = Array.make n 1 in
  let possible = Array.init n (function 0 -> true | _ -> false) in
  Array.iter (fun (x, y) ->
    balls.(x) <- balls.(x) - 1;
    balls.(y) <- balls.(y) + 1;
    possible.(y) <- possible.(y) || possible.(x);
    possible.(x) <- possible.(x) && balls.(x) <> 0) xys;
  Printf.printf "%d\n" (List.length (List.filter (fun b -> b) (Array.to_list possible)))


Measured memory_bytes: 11648
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] map = new char[H][W];
    for (int i = 0; i < H; i++) map[i] = scanner.next().toCharArray();

    if (possible(H, W, map)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  private static boolean possible(int H, int W, char[][] map) {
    int[][] d = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (map[i][j] != '#') continue;
        boolean found = false;
        for (int[] dd : d) {
          int x = i + dd[0];
          int y = j + dd[1];
          if (x >= 0 && x < H && y >= 0 && y < W) {
            if (map[x][y] == '#') found = true;
          }
        }
        if (!found) return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 23892
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (W, H, x, y): (i64, i64, i64, i64) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };

    let ans = format!(
        "{} {}",
        (W * H) as f64 / 2.0,
        if 2 * x == W && 2 * y == H {
            1
        } else {
            0
        });

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define int long long
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

signed main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  int ans = 0;
  
  auto chans = [&](int n) {
    vector<int> v = A;
    rep(i, N) v[i] %= n;
    sort(v.begin(), v.end());
    vector<int> minus(N+1), plus(N+1);
    rep(i, N)
      minus[i+1] = minus[i]+v[i];
    for(int i=N; i>0; i--)
      plus[i-1] = plus[i]+(n-v[i-1])%n;
    rep(i, N+1) {
      if(!(abs(minus[i]-plus[i])%n)) {
        if(max(minus[i], plus[i]) <= K) {
          chmax(ans, n);
          break;
        }
      }
    }
  };
  
  for(int i=1; i*i<=sum; i++) {
    if(!(sum%i)) {
      chans(i);
      chans(sum/i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = list(raw_input())
t = 0
score = 0

for s in S:
    if s == 'g':
        if t > 0:
            t-=1
            score+=1
        else:
            t+=1
    else:
        if t > 0:
            t-=1
        else:
            t+=1
            score-=1
print score

Measured memory_bytes: 3460
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    cin >> n>>m;
    
    int A[n][m];
    int b[m][1];
    int result[n][1];
    
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            A[i][j]=0;
            b[j][0]=0;
            result[i][0]=0;
        }
    
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            int v;
            cin >> v;
            A[i][j]=v;
        }
    
    for(int j=0;j<m;j++){
        int v;
        cin >> v;
        b[j][0]=v;
    }
    
    
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            result[j][0]+=A[j][i]*b[i][0];
        }
    }
    
    for(int j=0;j<n;j++){
        cout << result[j][0] << endl;
    }
    
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int a, b;
  cin >> a >> b;

  vector<int> t;
  int h = 0;
  for (int i = 1; i <= 999; i++) {
    h += i;
    t.push_back(h);
  }

  int diff = b - a;
  int ans = 0;
  for (int i = 0; i < 998; i++) {
    if (t[i+1] - t[i] == diff) {
      ans = t[i] - a;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N;
    cin>>N;
    vector<long> p(N);
    for(int i=0;i<N;i++) cin>>p.at(i);
    
    long M=-1,ans=0;;
    for(int i=0;i<N;i++){
        ans+=p.at(i);
        M=max(p.at(i),M);
    }
    
    cout<<ans-M/2<<endl;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,x=0;
    cin>>n;
    multiset<int, greater<int> > ms;
    for(int i=0;i<(1<<n);++i)
    {
    	cin>>x;ms.insert(x);
    }
    /*for(auto i: ms)
    {
    	cout<<i<<" ";
    }
    cout<<endl;*/
    vector<int> v;
    v.pb(*ms.begin());
    ms.erase(ms.begin());
    for(int i=0;i<n;++i)
    {
    	vector<int> aux;
    	for(int j=0;j<(int)v.size();++j)
    	{
    		if(ms.upper_bound(v[j])==ms.end())
    		{
    			cout<<"No"<<endl;
    			return 0;
    		}
    		aux.pb(*(ms.upper_bound(v[j])));
    		ms.erase(ms.upper_bound(v[j]));
    	}
    	for(int j=0;j<(int)aux.size();++j)
    		v.pb(aux[j]);
    	sort(v.begin(),v.end());
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 13984
n,m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
res = "No"

if m == 1:
    for i in a:
        if b[0] in i:
            res = "Yes"
else:
    for k in range(n-m+1): # (0,1) ※aの長さを上限にbが縦に移動できる範囲
        if b[0] in a[k]: # もしa[0]かa[1]にb[0]が含まれるなら
            for l in range(n-m+1): # (0,1) ※aの長さを上限にbが横に移動できる範囲
                if b[0] == a[k][l:m+l]: # もし、b[0]がa[0/1][0:2]かa[0/1][1:3]と一致するなら
                    cnt = 0
                    for o in range(m-1): # (0,1) b[0]は一したのでそれ以外
                        if b[o+1] == a[k+o+1][l:m+l]: # b[1/2]がa[]
                            cnt += 1
                    if cnt == m-1:
                        res = "Yes"
        
print(res)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,a,b; cin >> n >> a >> b;
  cout << min(b, a*n) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int MAXN = 2e5+69;
int n,m;
struct vl{
	int x,y;
};
vector<vl> canh;
signed main(){	
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		if(x>y)swap(x,y);
		canh.push_back({x,y});
	}	
	int ans = 0;
	for(int i=n;i>=1;i--){
		ans+=i*(i+1)/2;
	//	cout<<ans<<endl;
	}
	for(int i=0;i<n-1;i++){
		ans-=(canh[i].x*(n-canh[i].y+1));
	}
	cout<<ans;
}

Measured memory_bytes: 7384
# ABC079b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())

memo = {}


def getLuca(nu):
    if (nu == 0):
        return 2
    if (nu == 1):
        return 1
    if (memo.get(nu) != None):
        return memo[nu]
    memo[nu] = getLuca(nu-1)+getLuca(nu-2)
    return memo[nu]


print(getLuca(n))

Measured memory_bytes: 3064
//#pragma GCC optimize(3)
#define _CRT_SECURE_NO_WARNINGS

#include<bits/stdc++.h>

typedef long long LL;
using namespace std;

#define MAXN 1005

struct point {
	char val = '#';
	int left;
	int right;
	int len;
};

point grid[MAXN][MAXN];

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int groups;
	//scanf("%d", &groups);
	groups = 1;
	//printf("%c", grid[0][0].val);
	for (int i = 0; i < groups; i++) {
		int h, w;
		queue<point> s;
		point temp, temp1;
		scanf("%d%d", &h, &w);
		int ans = 0;
		for (int j = 1; j <= h; j++) {
			getchar();
			for (int k = 1; k <= w; k++) {
				scanf("%c", &grid[j][k].val);
				grid[j][k].len = 0;
				grid[j][k].left = j;
				grid[j][k].right = k;
				if (grid[j][k].val == '#') s.push(grid[j][k]);
			}
		}
		while (!s.empty()) {
			temp = s.front();
			s.pop();
			//temp1 = grid[temp.left][temp.right-1];
			if (grid[temp.left][temp.right - 1].val != '#'){
				grid[temp.left][temp.right - 1].len = temp.len + 1;
				grid[temp.left][temp.right - 1].val = '#';
				ans = max(ans, grid[temp.left][temp.right - 1].len);
				s.push(grid[temp.left][temp.right - 1]);
			}
			//temp1 = grid[temp.left - 1][temp.right];
			if (grid[temp.left - 1][temp.right].val != '#'){
				grid[temp.left - 1][temp.right].len = temp.len + 1;
				grid[temp.left - 1][temp.right].val = '#';
				ans = max(ans, grid[temp.left - 1][temp.right].len);
				s.push(grid[temp.left - 1][temp.right]);
			}
			//temp1 = grid[temp.left][temp.right + 1];
			if (grid[temp.left][temp.right + 1].val != '#') {
				grid[temp.left][temp.right + 1].len = temp.len + 1;
				grid[temp.left][temp.right + 1].val = '#';
				ans = max(ans, grid[temp.left][temp.right + 1].len);
				s.push(grid[temp.left][temp.right + 1]);
			}
			//temp1 = grid[temp.left - 1][temp.right];
			if (grid[temp.left + 1][temp.right].val != '#'){
				grid[temp.left + 1][temp.right].len = temp.len + 1;
				grid[temp.left + 1][temp.right].val = '#';
				ans = max(ans, grid[temp.left + 1][temp.right].len);
				s.push(grid[temp.left + 1][temp.right]);
			}
		}
		printf("%d", ans);
	}
	return 0;
}

Measured memory_bytes: 32436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    vector<int> w(n);
    int x = 0, y = 0;
    rep(i,m){
        int p;
        string s;
        cin >>p >>s;
        --p;
        if(w[p]==-1) continue;

        if(s=="WA"){
            ++w[p];
        }
        else{
            ++x;
            y += w[p];
            w[p] = -1;
        }
    }

    cout << x << " " << y << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>

using namespace std;

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

const int N_MAX = 100;

int N;
int a[N_MAX];

void solve() {
  sort(a, a + N);
  int ai = a[0];
  int ax = a[N - 1];
  bool ans;
  if ((ax + 1) / 2 != ai) {
    ans = false;
  } else {
    ans = true;
    FOR(am, ai, ax) {
      int c = upper_bound(a, a + N, am) - lower_bound(a, a + N, am);
      if (am == ai && c != ax % 2 + 1) ans = false;
      if (am > ai && c <= 1) ans = false;
    }
  }
  puts(ans ? "Possible" : "Impossible");
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	cout<<fixed<<setprecision(20);
	double r; cin>>r;
	double ans = 2*3.14159265358979323846*r;
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k;
    cin>>k;
    ll a=0;
    rep(i,k){
        a=(a*10+7)%k;
        if(a==0){
            cout<<i+1;
            return 0;
        }
    }
    cout<<-1;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,D,X;
  cin>>N>>D>>X;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  D--;
  int ans=0;
  for(int i=0;i<N;i++){
    int now=0;
    while(now<=D){
      ans++;
      now+=A[i];
    }
  }
  cout<<ans+X<<endl;
  return 0;
}


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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private void solve(Scanner sc, PrintWriter out) {
        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < N; ++i) {
            p[i] = sc.nextInt() - 1;
        }

        int[] r = new int[N];
        for (int i = 0; i < N; ++i) {
            r[p[i]] = i + 1;
        }
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = N * (i + 1);
            b[i] = N * (N - i - 1) + r[i];
        }
//      for (int i = 0; i < N - 1; ++i) {
//          while (a[p[i]] + b[p[i]] >= a[p[i + 1]] + b[p[i + 1]]) {
//              for (int j = p[i + 1]; j < N; ++j) {
//                  ++a[j];
//              }
//              for (int j = p[i + 1]; j >= 0; --j) {
//                  ++b[j];
//              }
//          }
//      }
        for (int i = 0; i < N; ++i) {
            if (i > 0) {
                out.print(" ");
            }
            out.print(a[i]);
        }
        out.println();
        for (int i = 0; i < N; ++i) {
            if (i > 0) {
                out.print(" ");
            }
            out.print(b[i]);
        }
        out.println();
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

struct Island {
    int a, b;
};

const int mod = 1000000007;



int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<Island> ab(m);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        ab.at(i).a = a;
        ab.at(i).b = b;
    }

    sort(ab.begin(), ab.end(), [] (const Island &x, const Island &y) {return x.b < y.b;});

    int ans = 1;

    int a = ab.at(0).a;
    int b = ab.at(0).b;

    REP(i, m) {
        if (ab.at(i).a < b) continue;
        b = ab.at(i).b;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
// Don't Lose Hope, Nor Be Sad 

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

  #define lp(start,finish) for(int i=start; i<finish; i++)
  #define read freopen("input.txt","r",stdin);
  #define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

int main(){
	//read
	int a,pos=0;
	string s;
	cin >> s;
	cin >> a;
	while(pos<=s.size()-1){
		cout << s[pos];
		pos+=a;
	}
	cout << endl;
	return 0;
}

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

#define MAX 100001

int diffs[MAX];



int main()
{


    int T, N, K, splits, diff, prev, curr;
    int sum;

    std::scanf("%d", &T);

    for (int t = 0; t < T; t++) {

        std::scanf("%d %d", &N, &K);
        splits = K - 1;
        sum = 0;

        if (K >= N) {
            for (int i = 0; i < N; i++) {
                std::scanf("%d", &curr);
            }
            std::cout << 0 << std::endl;
        } else {

            //set first elem of array
            std::scanf("%d", &prev);

            for (int i = 0; i < N-1; i++) {
                std::scanf("%d", &curr);
                diff = curr - prev;
                sum += diff; diffs[i] = diff;
                prev = curr;
            }
            std::sort(diffs, diffs+N-1, std::greater<int>());

            for (int i = 0; i < splits; i++) {
                sum -= diffs[i];
            }
            std::cout << sum << std::endl;

        }
    }

    return 0;
}



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

#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

int main(){
  int a, b, c = 0;
  vector<int> q = { 1, 2, 3 };
  cin >> a >> b;
  q[--a] = 0;
  q[--b] = 0;
  REP(i, 3) {
    c += q[i];
  }
  cout << c << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

# リストxsの総乗
def inf_product(xs):
    limit = int(1e9) + 7
    p = 1
    for x in xs:
        p *= x
        p %= limit
    return p

def calp():
    '''
    import random
    limit = int(1e9)
    n = int(2e5)
    k = int(n*9/10)
    x = []
    for i in range(n):
        x.append(random.randint(-limit,limit))
    '''
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    
    # n=kであれば、全要素の総乗をpとして返す
    if n == k:
        return inf_product(x)
    # 要素0の個数がn-kより大きければ、pとして0を返す
    if x.count(0) > n-k:
        return 0

    #要素を負の配列x1 と 正の配列x2 0の配列x3に分ける
    x.append(0)
    x.sort()
    #print(x)
    m1 = x.index(0)
    m2 = x.count(0)
    x1 =x[:m1]
    x2 =x[m1+m2:]
    x3 =x[m1:m1+m2-1]
    #print(x1,x2,x3)

    # 正の要素がない場合、kが偶数の場合小さい順（絶対値の大きい順）に拾う
    # kが奇数で要素に0を含む場合は、0を返す
    # kが奇数で要素に0を含まない場合は、大きい順（絶対値の小さい順）に拾う
    if len(x2) == 0:
        if k%2 == 0:
            return inf_product(x1[:k])
        elif len(x3) != 0:
            return 0
        else:
            return inf_product(x1[-k:])

    # kが奇数の場合、正のリストの最大のものをまず1個選択する
    p = 1
    if k%2 ==1:
        p *= x2[-1]
        x2.pop(-1)
        k -= 1

    x1b,x2b = [],[]
    for i in range(0,2*int(len(x1)/2),2):
        x1b.append(x1[i]*x1[i+1])
    x2.sort(reverse=True)
    for i in range(0,2*int(len(x2)/2),2):
        x2b.append(x2[i]*x2[i+1])
    
    x1b.extend(x2b)
    x1b.sort(reverse=True)
    x1b.insert(0,p)
    #print(x1b,int(k/2)+1)
    temp = int(k/2)

    if len(x1b) > temp:
        return inf_product(x1b[:int(k/2)+1])
    else:
        if len(x3) != 0:
            return 0
        else:
            return(-1)

print(calp())


Measured memory_bytes: 33152