akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        init(n);
        for (int i = 0; i < n - 1; i++) {
            addEdge(i + 1, nextInt() - 1);
        }
        dfs(0, -1);
        out.println(d[0]);
    }

    void init(int n) {
        this.n = n;
        this.m = (n - 1) * 2;
        last = 0;
        head = new int[n];
        nx = new int[m];
        dst = new int[m];
        d = new int[n];
        temp = new int[n];
        Arrays.fill(head, -1);
    }


    void addEdge(int x, int y) {
        nx[last] = head[x];
        dst[last] = y;
        head[x] = last;
        last++;
        nx[last] = head[y];
        dst[last] = x;
        head[y] = last;
        last++;
    }

    private void dfs(int x, int p) {
        int j = head[x];
        while (j >= 0) {
            int y = dst[j];
            if (y != p) {
                dfs(y, x);
            }
            j = nx[j];
        }
        int n = 0;
        j = head[x];
        while (j >= 0) {
            int y = dst[j];
            if (y != p) {
                temp[n++] = d[y];
            }
            j = nx[j];
        }
        Arrays.sort(temp, 0, n);
        for (int i = 0; i < n; i++) {
            d[x] = Math.max(d[x], temp[n - 1 - i] + i + 1);
        }
    }

    int n, m;
    int[] head;
    int[] nx;
    int[] dst;
    int[] d;
    int[] temp;
    int last;


    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

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

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 43492
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
int main(){
    int n;
    cin >> n;
    
    int h[n];
    for(int i(0); i<n; i++){
        cin >> h[i];
    }
    
    int ans(0);
    for(int i(0); i<n-ans-1; i++){
        int j(0);
        while(h[i+j] >= h[i+j+1]){
            //printf("%d, h[%d] >= h[%d]\n",j,i+j,i+j+1);
            j++;
            if(i+j+1 > n-1) break;
        }
        if(j > ans) ans = j;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0)
    {
        cout << b / x + 1 << endl;
    }
    else
    {
        cout << b / x - (a - 1) / x << endl;
    }
}

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

int main()
{
    int H,W;
    while(1)
    {
         scanf("%d %d",&H,&W);
         if(H == 0 && W == 0)
              exit(0);
         for(int i=0;i<H;i++)
         {
              for(int j=0;j<W;j++)
              {
                if(i%2==0){
                   if(j%2==0){
                   printf("#");
                   }else {
                   printf(".");
                   }
                }else {
                    if(j%2==1){
                   printf("#");
                   }else {
                   printf(".");
                   }
                }
              }
              printf("\n");
         }
         printf("\n");
    }
    return 0;
}


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

int func(int a){
    int sum = 0;
    while(a > 0){
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for(int i = 0; i <= N; i++){
        if(func(i) >= A && func(i) <= B){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
//#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fi first
#define se second
#define res resize
//CF408C
const llint mod=1000000007;
const double dbig=1e20;
inline int sa(int a,int b,int c){
	return max(a,max(b,c))-min(a,min(b,c));
}
int main(void){
	int N,ans,H,W,bmax,bmin;
	cin>>H>>W;
	if(H<W){swap(H,W);}
	if(H%3==0||W%3==0){cout<<0<<endl;return 0;}
	ans=W;
	ans=min(ans,sa(H*((W+1)/3),(H/2)*(W-(W+1)/3),(H-H/2)*(W-(W+1)/3)));
	swap(H,W);
	ans=min(ans,sa(H*((W+1)/3),(H/2)*(W-(W+1)/3),(H-H/2)*(W-(W+1)/3)));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
dl=[]
for i in range(h):
    if "#" not in l[i]:dl.append(i)
for i in dl[::-1]:
    del l[i]
l = [list(x) for x in zip(*l)]
dl=[]
for i in range(w):
    if "#" not in l[i]:dl.append(i)
for i in dl[::-1]:
    del l[i]
l = [list(x) for x in zip(*l)]
for i in l:print("".join(map(str,i)))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

bool isl(int w, int h, int iw, int ih){
  return (w*w + h*h < iw*iw + ih*ih) || (
    (w*w + h*h == iw*iw + ih*ih) &&
    (h > ih)
  );
}

signed main(){
  int w; int h;
  while(cin >> w >> h, !(w == 0 && h == 0)){
    int resw = 1000;
    int resh = 1000;
    for(int iw = 1; iw < 200; iw++){
      for(int ih = iw+1; ih < 200; ih++){
        if(isl(w, h, iw, ih)){
          if(!(iw == w && ih == h)){
            if(isl(iw, ih, resw, resh)){
              resw = iw;
              resh = ih;
            }
          }
        }
      }
    }
    cout << resw << " " << resh << endl;;
  }
}

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

int main() {
  string s;
  cin >> s;
  if(s.size() == 1) {
    cout << stoi(s) << endl;
    return 0;
  }
  int lim = s.size() - 1;
  long long int ans = 0LL;
  for(int i=0;i<pow(2, lim);i++) {
    bitset<9> plus(i);
    int start = 0;
    for(int i=0;i<9;i++) {
      if(plus[i]) {
        string ss = s.substr(start, i+1-start);
        ans += stoll(ss);
        start = i + 1;
      }
      if(i == 8) {
        string ss = s.substr(start, s.size() - start);
        ans += stoll(ss);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
LL a[202020], f[202020];
LL k;

bool cond(LL mid){
    LL num = 0;
    REP(i, n){
        if(a[i] * f[i] <= mid)continue;
        num += ((a[i] * f[i] - mid)/f[i]) + ((a[i] * f[i] - mid)%f[i] != 0);
    }
    //cout << mid << " " << num << " " << k << endl;
    return num <= k;
}

int main(){
    cin >> n >> k;
    REP(i, n)cin >> a[i];
    sort(a, a + n);
    REP(i, n)cin >> f[i];
    sort(f, f + n);
    reverse(f, f + n);
    LL l = -1, r = HINF<LL>();
    while(r - l > 1){
        LL mid = (l + r)/2;
        //cout << mid << endl;
        if(cond(mid))r = mid;
        else l = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;

int main() {
  string s;
  cin>>s;
  int n=s.size();

  int cntbc=0;
  int64_t ans=0;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='A'){ans+=cntbc;}
    else if(i-1>=0&&s.substr(i-1,2)=="BC"){cntbc++;i--;}
    else if(i-1>=0&&s.substr(i-1,2)!="BC"){cntbc=0;}
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3716
n, x = map(int, input().split())
a = list(map(int, input().split()))
res = 0
if a[0] > x:
    res += a[0] - x
    a[0] = x

zan = x - a[0]

for i in range(1, n):
    if a[i] > zan:
        res += a[i] - zan
        a[i] = zan
    zan = x - a[i]

print(res)


Measured memory_bytes: 14544
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	vector<int64> be(nn), vv(nn), cc(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> vv[ii];
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> cc[ii];
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		be[ii] = vv[ii] - cc[ii];
	}
	sort(be.begin(), be.end());
	reverse(be.begin(), be.end());
	for(int64 ii = 0;ii < nn;ii++)
	{
		if(be[ii] <= 0)
		{
			break;
		}
		ans += be[ii];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
for i in range(n):
    h[i] = abs(a - (t - h[i] * 0.006))
tmp = float("inf")
ans = float("inf")
for i in range(n):
    if tmp > h[i]:
        tmp = h[i]
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int c[5];
char s[20];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
    	scanf("%s",s);
    	if(s[0]=='A')c[0]++;
    	else if(s[0]=='W')c[1]++;
    	else if(s[0]=='T')c[2]++;
    	else if(s[0]=='R')c[3]++;
	}
	printf("AC x %d\n",c[0]);
	printf("WA x %d\n",c[1]);
	printf("TLE x %d\n",c[2]);
	printf("RE x %d\n",c[3]);
    return 0;
}

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

const int INF = 1e10;

bool done[2][2010];
int dp[2][2010];

int N, Z, W, a[2010];

int solve(bool isx, int p) {
  if (done[isx][p + 1]) {
    return dp[isx][p + 1];
  }

  int res;
  if (isx) {
    res = -INF;
    for (int i=p+1;i<N-1;i++) {
      res = max(res, solve(false, i)); 
    }
    res = max(res, abs(a[N-1] - (p >= 0 ? a[p] : W)));
  } else {
    res = INF;
    for (int i=p+1;i<N-1;i++) {
      res = min(res, solve(true, i));
    }
    res = min(res, abs(a[N-1] - (p >= 0 ? a[p] : Z)));
  }

  done[isx][p + 1] = true;
  return dp[isx][p + 1] = res;
}

int main() {
  cin >> N >> Z >> W;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  cout << solve(true, -1) << endl;
  
  return 0;
}


Measured memory_bytes: 384
import sys

input = sys.stdin.readline

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

class UnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n + 1)
    
    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
 
        return self.par[x]
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
 
ans = 0
for i in range(M):
    Path = AB[:i] + AB[i+1:]
    uf = UnionFind(N)
    for x, y in Path:
        uf.union(x, y)

    count = 0
    for j in range(1, N+1):
        if uf.par[j] == j:
            count += 1
            if count >= 2:
                ans += 1
                break
    
print(ans)

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

int main (){
	int a,b,x,y;
	scanf ("%d %d %d %d",&a,&b,&x,&y);
	int hasil1=a*b;
	int hasil2=x*y;
	if(hasil1>=hasil2){
		printf ("%d\n",hasil1);
	}
	else printf ("%d\n",hasil2);
	return 0;
}

Measured memory_bytes: 128
N = int(input())

A = [None] * N
B = [None] * N

for i in range(1, N+1):
    a, b = map(int, input().split())
    A[N-i] = a
    B[N-i] = b

cnt = 0
for i in range(N):
    A_add = A[i] + cnt
    r =  A_add % B[i]
    if r == 0:
        pass
    else:
        cnt += B[i] - r
print(cnt)


Measured memory_bytes: 10932
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<pair<char,int>> V;
    int i = 0;
    while (i < N) {
        int p = 0;
        while(S[i+p] == 'R') p++;
        V.push_back({'R',p});
        i += p, p = 0;
        while(S[i+p] == 'L') p++;
        V.push_back({'L',p});
        i += p, p = 0;
    }
    i = -1;
    vector<int> T(N,0);
    for (auto [k,v] : V) {
        switch (k) {
        case 'R':
            i += v;
            T[i]   = (v + 1) / 2;
            T[i+1] =  v / 2;
            break;
        case 'L':
            i++;
            T[i]   += (v + 1) / 2;
            T[i-1] +=  v / 2;
            i += v - 1;
            break;
        }
    }
    rep(i, N) {
        cout << T[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		char[] S = s.toCharArray();
		char[] T = t.toCharArray();
		int count = 0;

		for(int i = 0;i < s.length();i++) {
			if(S[i] != T[i]) {
				count += 1;
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 42060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

int dp[3010][3010];
int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
	//cout << dp[s.size()][t.size()];
	string ans;
	int i = s.size() - 1, j = t.size() - 1;
	while (i >= 0 && j >= 0) {
		if (s[i] == t[j]) {
			ans.push_back(s[i]);
			i--; j--;
		}
		else if (dp[i + 1][j + 1] == dp[i][j + 1]) {
			i--;
		}
		else {
			j--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
  #endif

  int R;
  cin >> R;
  cout << setprecision(20)<<  2*3.14159265358979323*R << endl;
  return 0;
}

Measured memory_bytes: 3800
X,K,D = map(int,input().split())

X = abs(X)

if X-K*D <= 0:
    d = X//D
    K -= d
    X -= D*d
    if K%2 == 0:
        print(X)
    else:
        print(abs(X-D))
else:
    print(X-K*D)


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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int>vec(N);
    
    for (int i = 0; i < N; i++) {
        cin>>vec.at(i);
    }
    
    sort(vec.begin(),vec.end());
    int ans = 0;
    for (int i = 0; i < N-1; i++){
        if(vec.at(i) != vec.at(i+1)){
             ans +=1;
        }
    }
    
    cout<<ans+1<<endl;
    
    return 0;
    }




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

int main() {


    int N;
    cin >> N;

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

    bool flag = true;
    for (int i = 0; i < N; i++) {
        if (sum - L[i] <= L[i]) {
            cout << "No" << endl;
            break;
        }
        if (i == N-1) {
            cout << "Yes" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	c.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.02 21:06:22
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int k;cin >> k;
    vector<bool> used(k,false);
    ll now = 0;
    int i = 0;
    while (true) {
        now *= 10;
        now += 7;
        now %= k;
        if (used[now]) {
            puts("-1");
            return 0;
        }
        else if (now == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        used[now] = true;
        i++;
    }
    return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

int power[1000];

int N;
int sum[5],cnt[5];

int table[205][1005];
int table2[205][205];
int C[500][500];
int F[500];

int calc(){
    memset(table,0,sizeof(table));
    rep(i1,cnt[1]+1){
        rep(i2,cnt[2]+1){
            rep(i3,cnt[3]+1){
                rep(i4,cnt[4]+1){
                    int t=C[cnt[1]][i1]*C[cnt[2]][i2]%mod*C[cnt[3]][i3]%mod*C[cnt[4]][i4]%mod;
                    table[i1+i2+i3+i4][i1+i2*2+i3*3+i4*4]=(table[i1+i2+i3+i4][i1+i2*2+i3*3+i4*4]+t)%mod;
                }
            }
        }
    }

    int ret=0;
    for(int z=0;z<=cnt[0];z++){
        for(int c=0;c<N-cnt[0];c++){
            for(int s=0;s<N*4;s++){
                int t=table[c][s]*C[cnt[0]][z]%mod;
                t=t*F[c+z]%mod;
                int lc=N-cnt[0]-1-c;
                int lz=cnt[0]-z;
                t=t*table2[lc][lz]%mod;
                ret=(ret+t*power[s+z])%mod;
            }
        }
    }

    return ret;
}

signed main(){
    power[0]=1;
    for(int i=1;i<1000;i++)power[i]=power[i-1]*10%mod;
    C[0][0]=1;
    for(int i=1;i<500;i++){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    }
    F[0]=1;
    for(int i=1;i<500;i++)F[i]=F[i-1]*i%mod;

    for(int i=0;i<=200;i++){
        for(int j=0;j<=200;j++){
            table2[i][j]=1;
            if(i){
                int s=i+j-1;
                for(int k=0;k<=s;k++){
                    int t=C[s][k]*F[k]%mod;
                    t=t*i%mod;
                    table2[i][j]=(table2[i][j]+t)%mod;
                }
            }
        }
    }

    cin>>N;
    rep(i,N){
        int a;
        cin>>a;
        if(a==0){
            cnt[0]++;
        }
        else{
            stringstream ss;
            ss<<a;
            int d=ss.str().size();
            sum[d]+=a;
            cnt[d]++;
        }
    }

    int ans=0;
    for(int i=1;i<5;i++){
        if(cnt[i]==0)continue;
        cnt[i]--;
        int tmp=calc();
        cnt[i]++;
        ans=(ans+tmp*sum[i])%mod;
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[101];
	scanf("%s",a);
	for(int i=0;i<strlen(a);++i)
	{
		if(a[i]=='C')
		{
			for(int j=i+1;j<strlen(a);++j)
			{
				if(a[j]=='F')
				{
					printf("Yes\n");
					return 0;
				}
			}
			
		}
	}
	printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  /*
  vector<ll> s(n,1);
  REP(i,k) { s[0] *= a[i]; }

  */

  /*
  REP(i,n-k+1) {
    if (i == 0) continue;
    s[i] = (s[i-1] / a[i-1]) * a[i+k-1];
    cout << a[i-1] << " " << a[i+k-1]<<endl;;
  }
  */

  REP(i,n-k) {
    Yes(a[i+k] > a[i]);
    // cout << a[i+k] << " " <<  a[i] << endl;;
    // cout << s[i] << " " << s[i+1] << endl;
    // cout << a[i+k-1] << " " << a[i] << endl;;
    // Yes(s[i+1] > s[i]);
  }

  return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

bool isnumber(char a) {
    if(a >= '0' && a <= '9') return true;
    return false;
}
vector<string> parse() {
    string tmp;
    cin >> tmp;
    vector<string> ret;
    ret.push_back("");
    int l = 0;
    for(int i = 0; i < tmp.size(); i++) {
        if(isnumber(tmp[l]) ^ isnumber(tmp[i])) {
            ret.push_back("");
            l = i;
        }
        ret.back().push_back(tmp[i]);
    }
    return ret;
}

bool comp(vector<string> &a, vector<string> &b, int index) {
    if(index == a.size()) return true;
    if(index == b.size()) return false;
    if(isnumber(a[index][0]) && !isnumber(b[index][0])) return true;
    if(!isnumber(a[index][0]) && isnumber(b[index][0])) return false;
    if(isnumber(a[index][0])) {
        if(a[index].size() != b[index].size()) {
            return a[index].size() < b[index].size();
        }
        if(a[index] != b[index]) return a[index] < b[index];
    } else {
        if(a[index] != b[index]) return a[index] < b[index];
    }
    return comp(a, b, index + 1);

}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> v0 = parse();
    while(n--) {
        vector<string> now = parse();
        if(now == v0) {
            cout << "+" << endl;
            continue;
        }
        if(comp(v0, now, 0)) cout << "+" << endl;
        else cout << "-" << endl;
    }
    return 0;
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")


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

	string s;
  cin >> s;
  cout << s[0] << (s.size()-2) << s.back() << endl;
	return 0;
}


Measured memory_bytes: 256
import collections 
n = int(input())
s = [input() for i in range(n)]
words = list(collections.Counter(s).most_common())
S = []
i = 0
maxcount = words[0][1]
for word in words:
    if word[1] != maxcount:
        break
    S.append(word[0])
S.sort()
for s_word in S:
    print(s_word)

Measured memory_bytes: 45120
a=input()
b=input()

flag=0
if a==b:
    flag=1
else:
    for i in range(len(a)):
        a=a[-1:]+a[:-1]
        if a==b:
            flag=1
            break

if flag==1:
    print('Yes')
elif flag==0:
    print('No')


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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
int a[mxN];

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

    char t;
    cin >> t;

    if (t == tolower(t))
        cout << "a";
    else
        cout << "A";

    return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

D = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for _ in range (D)]
M = 26
INF = 10**20

ans = [0]*D
lasts = [0]*(M+1)

for i in range(D):
    score = -INF
    contest = 0
    for m in range(1,M+1):
        cur = S[i][m-1]
        cur -= C[m-1]*(i+1-lasts[m])
        if cur>score:
            score = cur
            contest = m
    ans[i] = contest

for a in ans:
    print(a)

Measured memory_bytes: 68352
N=int(input())
l=[]
for i in range(N):
  l.append(list(input().split()))
  l[i][1]=int(l[i][1])
l1=sorted(l,key=lambda x:x[1],reverse=True)
l2=sorted(l1,key=lambda x:x[0])
for i in range(N):
  print(l.index(l2[i])+1)

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

long long n;
int c,i;
vector<int> v1,v2;
int main(){
	cin>>n;n++;
	while(n>1){
		if(n&1){
			v2.push_back(++c);
		}
		v1.push_back(++c);
		n/=2;
	}
	cout<<c*2<<endl;
	rep(i,c) cout<<i<<' ';
	for(i=0;i<v1.size();i++) cout<<v1[i]<<' ';
	while(!v2.empty()) {cout<<v2.back()<<' ';v2.pop_back();}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define N 20003

int n;
int a[N];
string S,X,Y;
map<pair<string,string>,LL>mp;
LL ans;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	cin>>S;
	X=S.substr(0,n);
	Y=S.substr(n,n);
	reverse(Y.begin(),Y.end());
	for (int i=0;i<1<<n;i++){
		int res=i;
		string s1="",s2="";
		for (int j=0;j<n;j++){
			if (res%2==0) s1+=X[j];
			  else s2+=X[j];
			res/=2;
		}
		mp[make_pair(s1,s2)]++;
	}
	for (int i=0;i<1<<n;i++){
		int res=i;
		string s1="",s2="";
		for (int j=0;j<n;j++){
			if (res%2==0) s1+=Y[j];
			  else s2+=Y[j];
			res/=2;
		}
		ans+=mp[make_pair(s1,s2)];
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 91904
X, Y = [int(arg) for arg in input().split(' ')]

def f(X, Y):
    for i in range(X + 1):
        for j in range(X + 1):
            kame = i
            tsuru = j
            if kame + tsuru == X and kame * 4 + tsuru * 2 == Y:
                return 'Yes'
    return 'No'

print(f(X, Y))

Measured memory_bytes: 9124
#include <iostream>

using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int k; cin >> k;
    char kc=s[k-1];
    for(auto c : s){
        if(c!=kc) c='*';
        cout << c;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
# Problem C - Prison

# input
N, M = map(int, input().split())

# initialization
max_left = 0
min_right = N

# update loop
for i in range(M):
    L, R = map(int, input().split())
    max_left = max(max_left, L)
    min_right = min(min_right, R)

# output
if max_left>min_right:
    print(0)
else:
    ans = min_right - max_left + 1
    print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();
    vi a(n); rep(i, n) a[i] = in[i] - '0';

    int l = n / 2, r = n / 2;
    if(n % 2 == 0) l--;
    int res = n / 2;
    int b = a[l];
    while(l >= 0 and r < n and a[l] == b and a[r] == b){
        res++;
        l--, r++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 848
#include<iostream>
#include<string>

using namespace std;

int hit(string r,string a){
  int cnt=0;
  for(int i=0;i<r.size();i++)
    if(r[i]==a[i])cnt++;

  return cnt;
}

int blow(string r,string a){
  int cnt=0;
  for(int i=0;i<a.size();i++)
    for(int j=0;j<r.size();j++)
      if(i!=j && a[i]==r[j])cnt++;

  return cnt;
}

int main(void){
  string r,a;

  while(cin >> r >> a){
    if(r=="0" && a=="0")break;
    
    cout << hit(r,a) <<" "<< blow(r,a) << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#define w 200001
p;main(){
    int n,m,j;
    long int k,a[w],A[w],b[w],B[w];
    
    
    scanf("%d%d%ld",&n,&m,&k);
    
   
    for(int i=0;i<n;i++){
        scanf("%ld",&a[i]);
        if(i==0){
            A[i]=0;
        }
        A[i+1]=A[i]+a[i];
        
    }
    
    
    for(int i=0;i<m;i++){
        scanf("%ld",&b[i]);
        if(i==0){
            B[i]=0;
        }
        B[i+1]=B[i]+b[i];
        
    }
    int mo=m;
    
    for(int i=0;i<=n;i++){
        if(A[i]>k)break;
        
        for(j=mo;j>=0;j--){
            if(A[i]+B[j]<=k){
                if(i+j>p)p=i+j;
                mo=j;
                break;
            }
        }
        
    }
    
    
    printf("%d",p);
}

Measured memory_bytes: 7976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S; ll K; cin >> K;
    res = 1;
    ll onecnt = 0;
    for(int i = 0; S.length();i++){
        if(S[i] == '1'){
            onecnt++;
        }else{
            res = S[i] - '0';
            break;
        }
    }
    if(onecnt >= K) return 1;
    else return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code)]
fn remove_whitespace(s: &str) -> String {
    s.chars().filter(|c| !c.is_whitespace()).collect()
}

#[allow(unused_imports)]
use std::io::{stdout, Write};
#[allow(unused_imports)]
use std::collections::HashMap;
fn gcd(mut x: u64, mut y: u64) -> u64 {
    let mut z = x;
    let mut gcd_num = x;
    while z != 0 {
        gcd_num = z;
        z = y % x;
        y = x;
        x = z;
    }
    gcd_num
}
#[allow(dead_code)]
fn tansaku_fn(iti: usize, n: usize, kyori: &mut Vec<i32>, map: &Vec<Vec<bool>>, ans: &mut Vec<usize>) {
    let mut tansaku1: Vec<usize> = Vec::new();
    for j in 0..n {
        if map[iti][j] == true {
            tansaku1.push(j);
        }
    }
    let mut tansaku2: Vec<usize> = Vec::new();
    for j in tansaku1 {
        if kyori[j] > kyori[iti] + 1 {
            kyori[j] = kyori[iti] + 1;
            ans[j] = iti;
            tansaku2.push(j);
        }
    }
    for iti1 in tansaku2{
        tansaku_fn(iti1, n, kyori, map, ans);
    }
}
fn main() {
    let _n = read::<i32>();
    let mut vect = read_vec::<i128>();
    let mut ans = 1i128;
    let ju = 10_i128.pow(18);
    vect.sort();
    for i in vect {
        ans = ans * i;
        if ans > ju {
            ans = -1;
            break;
        }
    }
    println!("{}", ans);

}

Measured memory_bytes: 6476
import java.math.*;
import java.util.*;
  
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int num = 0;
        for(int i = 0; i < N; ++i) {
            String s;
            s = scan.next();
            if(new BigInteger(s).isProbablePrime(5)) ++num;
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 54540
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());
    int r = min(a[1], a[0] - a[1]);
    int r_ind = 1;
    for (int i = 1; i < n; i++) {
        int r1 = min(a[i], a[0] - a[i]);
        if (r <= r1) {
            r = r1;
            r_ind = i;
        }
    }

    printf("%d %d\n", a[0], a[r_ind]);
    
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> ppair;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ppair> ab(N);
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a,b);
    }
    sort(ab.begin(),ab.end(),greater<ppair>());
    ll k=0;
    int ans;
    for(int i=0; i<N; i++){
        ppair now = ab.back();
        ab.pop_back();
        int tmp=now.second;
        //cout << tmp << endl;
        if(k+tmp<K){
            k+=tmp;
            continue;
        }
        for(int j=0; j<tmp; j++){
            ans = now.first;
            k++;
            if(k==K){
                break;
            }
        }
        if(k==K){
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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


void solve(long long N){
    cout << (N*(N-1)/2) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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




int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int ans=0;
    for(int i=0;i<s1.length();i++)
        if(s1[i]==s2[i])
        ans++;
    cout<<ans<<endl;
    return 0;
}
///*
//
//4 6 0
//0 1 2
//1 2 2
//1 3 1
//0 2 5
//1 3 3
//0 3 4
//
//
//
//*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define prl pair<ll,ll>
#define pri pair<int,int>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define db double
#define N 1000005
#define mod 1000000007
#define INF 2147483647
using namespace std;
mt19937 mrand(random_device{}());
uniform_int_distribution<ll> dist(0, 100000000);
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll qpow(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
int n;
int a[N], c[N]; //对应原数组和树状数组
inline int lowbit(int x) {
    return x & (-x);
}
void modify(int i, int k) {    //在i位置加上k
    while (i <= n) {
        c[i] += k;
        i += lowbit(i);
    }
}
int getsum(int i) {        //求A[1 - i]的和
    int res = 0;
    while (i > 0) {
        res += c[i];
        i -= lowbit(i);
    }
    return res;
}
int loc[N];
struct query {
    int l,r,id;
    bool operator <(query& b) { return r < b.r; }
}Q[N];
int ans[N];
int main() {
	IOS;
    int q;
    cin >> n>>q;
    rep(i, 1, n+1) {
        cin >> a[i];
    }
    rep(i, 0, q) {
        cin >> Q[i].l >> Q[i].r;
        Q[i].id = i+1;
    }
    sort(Q, Q + q);
    int cur = 0;
    rep(i, 1, n + 1) {
        if (loc[a[i]]) {
            modify(loc[a[i]], -1);
        }
        modify(i, 1);
        loc[a[i]] = i;
        while (cur < q && Q[cur].r == i) {
            ans[Q[cur].id] = getsum(i);
            if (Q[cur].l > 1)ans[Q[cur].id] -= getsum(Q[cur].l-1);
            cur++;
        }
        if (cur == q)break;
    }
    rep(i, 1, q + 1)cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 17412
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>

using namespace std;

int main(void){
    int N;
    vector <int> a;
    int sub;
    int ans = 0;
    map <int, int> number;
    int max_e;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> sub;
        a.push_back(sub);
        number[a[i]]++;
        max_e = max(max_e, a[i]);
    }
    
    for(int i = 0; i < N; i++){
        if(number[a[i]]){
            if(number[a[i]] > a[i]){
                ans += number[a[i]] - a[i];
                number[a[i]] = a[i];
            }
            else if (number[a[i]] < a[i]){
                ans += number[a[i]];
                number[a[i]] = 0;
            }
        }
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int N;
  cin >> N ;
  int sum = 0;
  int numb = 0;
  vector<int> vec(N);
  
  for(int i = 0 ; i < N ; i++ ){
    cin >> vec.at(i);
  }
  
  for(int i = 0 ; i < N+1 ; i++){
    numb = vec.at(numb) -1;
    sum ++;
    
    if(numb+1 == 2){
      cout << sum <<endl;
      break;
    }
    if(i == N){
      cout << -1 << endl;
      break;
    }
  }
}

Measured memory_bytes: 640
import numpy as np

S = input()
N = int(S)

A = np.zeros([N])
A_temp = np.zeros([N])

for i in range(0, N, 1):
    A[i] = int(input())

max = 0

index_max = np.argmax(A)
A_temp = np.copy(A)
A_temp[index_max] = 0
index_max_second = np.argmax(A_temp)

result = np.full(N, A[index_max])
result[index_max] = A[index_max_second]

for i in range(0, N, 1):
    print(int(result[i]))


Measured memory_bytes: 18872
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    map<string,int> map;
    int n,a,c;
    string b;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        if ( a==0 ) {
            cin >> b >> c;
            if ( map.find(b)!=map.end() ) {
                map.erase(b);
                map.emplace(b,c);
            } else {
                map.emplace(b,c);
            }
        } else if ( a==1 ) {
            cin >> b;
            if ( map.find(b)!=map.end() ) {
                cout << map.at(b) << endl;
            } else {
                cout << "0" << endl;
            }
        } else if ( a==2 ) {
            cin >> b;
            map.erase(b);
        }
    }
}



Measured memory_bytes: 27792
import fractions

n, a = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(t-a) for t in x]

if n == 1:
  print(x[0])
  exit()
  
d = x[0]
for t in x[1:n]:
  d = fractions.gcd(d,t)
print(d) 

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

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

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

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


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long 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;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    int ans = 0;
    int pre_a;
    cin >> pre_a;
    REP(i,N-1){
        int a;
        cin >> a;
        if(pre_a == a){
            pre_a = 0;
            ans++;
        } else {
            pre_a = a;
        }
    }

    pl(ans)

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int K = 0,N = 0;
  int a[200000];
  int *p;
  int max = 0,def = 0;
  p = a;
 
  scanf("%d %d\n",&K,&N );
  scanf("%d",p);
  for(int i = 1;i < N; i++ ){
    scanf(" %d",(p+i) );
    if((*(p + i) - *(p + i -1)) > max){
      max = *(p + i) - *(p + i -1);
    }
  }
  if(((*p - 0) + (K - *(p+N-1))) > max){
    max = (*p - 0) + (K - *(p+N-1));
  }
  def = K - max;
  printf("%d\n",def );
  return 0;
}

Measured memory_bytes: 896