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

const int maxn=2e5+10;
int n,fa[20][maxn],st[20][maxn],ans[maxn];
bool vis[maxn];
vector<int> g[maxn],stk;

void dfs1(int pos){
	st[0][pos]=pos;
	for(int i=1;i<20;++i){
		fa[i][pos]=fa[i-1][fa[i-1][pos]];
		st[i][pos]=max(st[i-1][pos],st[i-1][fa[i-1][pos]]);
	}
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos]){
			fa[0][g[pos][i]]=pos;
			dfs1(g[pos][i]);
		}
}
void dfs2(int pos){
	ans[pos]+=ans[fa[0][pos]];
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos])
			dfs2(g[pos][i]);
}
inline int rmq(int x,int y){
	if(x>y)
		return 0;
	int k=log(y-x+1)/log(2);
	return max(st[k][stk[y]],st[k][stk[x-1+(1<<k)]]);
}
void dfs(int pos){
	stk.push_back(pos);
	if(pos!=1){
		int l=0,r=stk.size()-1;
		while(l<r){
			int mid=l+r>>1;
			if(rmq(0,mid-1)>rmq(mid+1,stk.size()-1))
				r=mid;
			else
				l=mid+1;
		}
		++ans[stk[l]];
	}
	for(int i=0;i<g[pos].size();++i)
		if(g[pos][i]!=fa[0][pos])
			dfs(g[pos][i]);
	stk.pop_back();
}

int main(){
	cin>>n;
	for(int i=1,u,v;i<n;++i){
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1);
	dfs(1);
	dfs2(1);
	for(int i=2;i<=n;++i)
		cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 61304
/*
  AOJ 2516.
  Title:next permutation
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define mydiff(x,y) (((x)>(y))?((x)-(y)):((y)-(x)))
int n,m;

int compare(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int next_perm(int a[],int n)
{
  int i,j,p,min_,min_p,wk;

  if(a[n-2]<a[n-1])
    {
	wk=a[n-1];
	a[n-1]=a[n-2];
	a[n-2]=wk;
	return(-1);
    }


  for(i=n-1;i>=1;i--)
    if(a[i]>a[i-1])
      {
	p=a[i-1];
	min_=INT_MAX;
	for(j=i;j<n;j++)
	  if(a[j] > p && min_ > a[j])
	    {
	      min_=a[j];
	      min_p=j;
	    }
	wk=a[min_p];
	a[min_p]=a[i-1];
	a[i-1]=wk;
	qsort(&a[i],n-i,sizeof(int),compare);
        return(-1);
      }
 
  return(0);
}


void amida(int x[],int r[],int n,int m)
{
  int i,wk;
  for(i=1;i<=n;i++)
    r[i]=i;
  for(i=0;i<m;i++)
    {
      wk=r[x[i]];
      r[x[i]]=r[x[i]+1];
      r[x[i]+1]=wk;
    }
}

int height(int x[],int m)
{
  int i,j,ret,y[8],max_,max_max;

  y[0]=1;max_max=1;
  for(i=1;i<m;i++)
    {
      max_=0;
      for(j=i-1;j>=0;j--)
	if(mydiff(x[i],x[j])<2)
	    {
	      if(y[j]>max_)
		max_=y[j];
	    }
      y[i]=max_+1;
      if(y[i]>max_max)
	max_max=y[i];
    }
  return(max_max);
}

dump(int x[],int n)
{
  int i;

  for(i=0;i<n;i++)
    printf("%d|",x[i]);
  printf("\n");
}

dump2(int x[],int n)
{
  int i;

  for(i=1;i<=n;i++)
    printf("%d|",x[i]);
  printf("\n");
}

main()
{
  int i,j,x[9],r[9],r1[9],min_,h;
  

  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)
    {
      scanf("%d",&x[i]);
    }
  if(m>1)
    {
      min_=height(x,m);
      amida(x,r,n,m);
#ifdef DEBUG
      dump(x,m);
      dump2(r,n);
#endif
      qsort(x,m,sizeof(int),compare);  
      
      do
	{
	  amida(x,r1,n,m);
#ifdef DEBUG
	  dump(x,m);
	  dump2(r1,n);
#endif
	  
	  if(memcmp(r+1,r1+1,n*sizeof(int)))
	    continue;
	  
	  
	  h=height(x,m);
#ifdef DEBUG
	  printf(":h=%d\n",h);
#endif
	  if(h<min_)
	    min_=h;
	END:;	
	}  while(next_perm(x,m));
    }
  else
    min_=1;
  printf("%d\n",min_);

  return(0);
  
}

Measured memory_bytes: 616
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, K, C = map(int, input().split())
    S = input()

    """
    そもそもK日働くことができるのかは、左から順に働きづめにしてやれば貪欲法で判定できる。
    （必ず働かないといけない日）＝（その日を×にするとK日働けなくなる日）
    なので、O(N^2)でなら愚直な判定が可能。
    これをO(N)に高速化するために、必ず働かないといけないか判定したい日に対してその左右に働ける日が
    何個あるかを求める。
    →そうすると判定したい日を１日ずらしたときに尺取り法のようなことが可能！
    ただし左側の最終日と右側の初日が(C+2)日以下の場合は１日減らさないといけない。
    """

    # 左から貪欲に働く日を数える
    L = []
    work = 0
    diff = C + 1
    for i in range(N):
        if diff > C and S[i] == "o":
            work += 1
            L.append((work, 0))
            diff = 0
        else:
            L.append((work, diff))
        diff += 1
    #print("L={}".format(L))

    # 右から貪欲に働く日を数える
    R = []
    work = 0
    diff = C + 1
    for i in range(1, N + 1):
        if diff > C and S[-i] == "o":
            work += 1
            R.append((work, 0))
            diff = 0
        else:
            R.append((work, diff))
        diff += 1
    R.reverse()
    #print("R={}".format(R))

    # 求積パート
    ans = []

    if N == 1 and S[0] == "o":
        ans.append(1)
    elif N >= 2:
        for i in range(N):
            if S[i] == "x":
                continue
            else:
                if i == 0:
                    total_work = R[1][0]
                elif i == N - 1:
                    total_work = L[N - 2][0]
                else:
                    total_work = L[i - 1][0] + R[i + 1][0]
                    if L[i - 1][1] + R[i + 1][1] + 1 < C:
                        total_work -= 1
                #print("i={}, total_work={}".format(i+1, total_work))
                if total_work < K:
                    ans.append(i + 1)
    for d in ans:
        print(d)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 69496
from collections import Counter

N =int(input())
A_n =list(map(int,input().split()))
Q =int(input())
B_n ,C_n=[],[]
for i in range(Q):
    B,C =map(int,input().split())
    B_n.append(B)
    C_n.append(C)

dic =Counter(A_n)

sum0 =sum(A_n)
for i in range(Q):
    count = dic[B_n[i]]
    sum0 += (C_n[i]-B_n[i])*count
    dic[B_n[i]] = 0
    dic[C_n[i]] += count
    print(sum0)
    

Measured memory_bytes: 30068
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];

vector<int> v;
int L[200009], R[200009];
int C[510][510], X[510][510];
int main(void) {
    ll N, K; cin >> N >> K;
    if(K%2!=0){
        ll cnt=0;
        for(ll i=1; i<=N; ++i){
            if(i%K==0) cnt++;
        }
        cout << cnt*cnt*cnt << endl;
    }else{
        ll mid = K/2;
        ll c=0, t=0;
        for(ll i=1; i<=N; ++i){
            if(i%K==0) c++;
            if(i%K==mid) t++;
        }
        cout << c*c*c+t*t*t << endl;
    }
    return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
using namespace std;
int n, a, b, c, d, maxn;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		maxn = 1000000;
		cin >> a >> b >> c >> d;
		for (int j = 0; j < 7; j++) {
			for (int k = 0; k < 7; k++) {
				if (c <= j && d <= k) {
					if (j >= 5 && k >= 2) {
						maxn = min(maxn, (a*j + b*k) * 4 / 5);
					}
					maxn = min(maxn, (a*j + b*k));
				}
			}
		}
		cout << maxn << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
using namespace std;


int main(){
    
    string s;
    cin >> s;
    int array[150] = {0};
    int cnt=0;
    
    for (int i = 0; i < s.length(); i++)
    {
        array[s[i]] ++;
    }
    
    for (int i = 0; i < 150; i++)
    {
        if(array[i] == 2){
            cnt++;
        }
    }
    if(cnt==2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main()
{
	int n;
	cin >> n;
	int s[100];
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = n - 1; i >= 0; i--) {
		if (i == n - 1) cout << s[i];
		else cout << " " << s[i];
	}
	cout << endl;
	return 0;
}



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

int main() {
  char c;
  cin >> c;
  
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
      cout << "vowel" << endl;
    else
      cout << "consonant" << endl;

}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int A = (N + 1) / 2;
  int B = A - 1;
  int l = 1, r = A;
  while (M > 0 and l < r) {
    cout << l << " " << r << endl;
    M--;
    l++;
    r--;
  }
  l = A + 1, r = A + B;
  while (M > 0 and l < r) {
    cout << l << " " << r << endl;
    M--;
    l++;
    r--;
  }

  return 0;
}
/* vim:set fdm=marker: */


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

int main()
{
char s[101];
char ans[5];
char sentou[2], saigo[2];
int N;
char num[3];
int len;

scanf("%s",s);
len = strlen(s);
N= len-2;
sprintf(num, "%d", N);

sprintf(num, "%d", N);

sentou[0] = s[0];
sentou[1] ='\0';

saigo[0] = s[len-1];
saigo[1] ='\0';

strcpy(ans,sentou);
strcat(ans, num);

strcat(ans, saigo);

printf("%s" ,ans);


return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define hell 1000000007
#define int long long int

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector <int> a(n);
    int x=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x=x^a[i];
    }
    for(int i=0;i<n;i++){
        cout<<(x^a[i])<<" ";
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4784
#!/usr/bin/env python
# coding: utf-8

# In[27]:


x1,y1,x2,y2 = map(int, input().split())


# In[28]:


import numpy as np


# In[29]:


rot = np.array([[0, -1], [1, 0]])
vec0 = np.array([x1, y1])
vec1 = np.array([x2-x1, y2-y1])
vec2 = np.dot(rot, vec1)
vec3 = np.dot(rot, vec2)
ans = list(map(str, list(vec0 + vec1 + vec2) + list(vec0 + vec1 + vec2 + vec3)))
print(" ".join(ans))


# In[ ]:






Measured memory_bytes: 20036
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = ReadLine();
			Console.WriteLine((s[2].Equals(s[3]))&&(s[4].Equals(s[5])) ? "Yes" : "No");
		}
		public static int nCm(int n, int m)
		{
			if (n == 0) return 0;
			if (m == 0) return 1;
			return n * nCm(n-1, m-1) / m;
		}

		public static string ReadLine()
		{
			return Console.ReadLine();
		}

		public static int ReadLineInt()
		{
			return int.Parse(ReadLine());
		}

		public static string[] ReadLineStringSplit(char s=' ')
		{
			return ReadLine().Split(s).ToArray();
		}

		public static int[] ReadLineIntSplit(char s=' ')
		{
			return ReadLine().Split(s).Select(x => int.Parse(x)).ToArray();
		}

		public static long[] ReadLineLongSplit(char s = ' ')
		{
			return ReadLine().Split(s).Select(x => long.Parse(x)).ToArray();
		}
	}
}

Measured memory_bytes: 11092
package main

import (
	"fmt"
	"os"
)

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	var n int64
	var cities [5]int64
	fmt.Fscan(fp, &n, &cities[0], &cities[1], &cities[2], &cities[3], &cities[4])
	m := minint(cities)
	if n%m > 0 {
		fmt.Println(n/m + int64(5))
	} else {
		fmt.Println(n/m + int64(4))
	}

}

func minint(list [5]int64) int64 {
	min := list[0]
	for i := int64(1); i < 5; i++ {
		if min > list[i] {
			min = list[i]
		}
	}

	return min
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        String strInput = input.nextLine();
        int hour = Integer.parseInt(strInput)/3600;
        int min = (Integer.parseInt(strInput)%3600)/60;
        int sec = (Integer.parseInt(strInput)%3600)%60;
        System.out.println(hour + ":" + min + ":" + sec);
    }
}


Measured memory_bytes: 26256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>x(n);
	int ans = 0;
	rep(i, n) {
		cin >> x[i];
		if (x[i] * 2 < k)ans += x[i];
		else ans += k - x[i];
	}
	ans *= 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MAX = 1000000000000000000;
int main(){
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll n = 1, s = 0;
  for(ll i = k; i > 0; i >>= 1){
    if((i & 1) == 1){
      s += n;
    }
    n = n * 2;
  }
  s /= 3;
  ll ab = a - b;
  if(k % 2 == 0){
    cout << a - b << endl;
  }else{
    cout << b - a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int w,h,n;
  cin >> w >> h >> n;
  
  int x,y,a;
  int xmin=0,ymin=0,xmax=w,ymax=h;
  
  for(int i=0;i<n;i++){
    cin >> x >> y >>a;
    if(a==1)xmin=max(xmin,x);
    if(a==2)xmax=min(xmax,x);
    if(a==3)ymin=max(ymin,y);
    if(a==4)ymax=min(ymax,y);
  }
  
  int yoko = xmax - xmin;
  int tate = ymax - ymin;
  
  if(yoko<=0||tate<=0)cout << 0 << endl;
  else cout << yoko*tate << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
 
int main() {
    int a;
    cin>>a;
    vector<int>b(a);
    for(int i=0;i<a;i++){
        cin>>b.at(i);
    }
    reverse(b.begin(), b.end());
    cout<<b.at(0);
        for(int i=1;i<a;i++){
        cout<<" "<<b.at(i);
    }
  cout<<endl;
}


Measured memory_bytes: 3096
#include<stdio.h>
 
int main(){
 unsigned int K=0, S=0;
unsigned int count = 0;
 scanf("%d%d", &K, &S);
 for(unsigned int X = 0; X <= K; X++)
 for(unsigned int Y = 0; Y <= K; Y++)
 if(S - X - Y <= K) count ++;
 printf("%d\n", count);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  if(N <= 999){
    cout << "ABC" << endl;
  }else{
    cout << "ABD" << endl;
  }
}


Measured memory_bytes: 256
class Dice
  def initialize
    @face = 1
    @north = 5
    @south = 2
    @west = 4
    @east = 3
  end
  def move_north
  @north,@face,@south = @face,@south,7-@face
  @face
  end
  def move_south
  @south,@face,@north = @face,@north,7-@face
  @face
  end
  def move_west
  @west,@face,@east = @face,@east,7-@face
  @face
  end
  def move_east
  @east,@face,@west = @face,@west,7-@face
  @face
  end
  def move_right
  @north,@west,@south,@east = @west,@south,@east,@north
  @face
  end
  def move_left
  @west,@south,@east,@north = @north,@west,@south,@east
  @face
  end
end

until (n = gets.chomp.to_i) == 0 ? true:false
  dice = Dice.new
  count = 1
  n.times do
    count += case order = gets.chomp
               when "North"
                  dice.move_north
               when "South"
                  dice.move_south
               when "East"
                  dice.move_east
               when "West"
                  dice.move_west
               when "Left"
                  dice.move_left
               when"Right"
                  dice.move_right
              end
  end
  p count
end

Measured memory_bytes: 6108
#include <stdio.h>

int main(void)
{
	int num[10], i, j, max, dum;
	
	for (i = 0; i < 5; i++)scanf("%d", &num[i]);
	
	for (i = 0; i < 4; i++){
		max = i;
		for (j = i + 1; j < 5; j++){
			if (num[max] < num[j])max = j;
		}
		dum = num[i];
		num[i] = num[max];
		num[max] = dum;
	}
	
	for (i = 0; i < 5; i++){
		printf("%d", num[i]);
		if (i != 4)printf(" ");
		else puts("");
	}
	
	return (0);
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  vector<char> S(s.size()),T(t.size());
  for (int i = 0; i < s.size(); i++) S[i] = s[i];
  for (int i = 0; i < t.size(); i++) T[i] = t[i];
  sort(S.begin(),S.end());
  sort(T.begin(),T.end());
  reverse(T.begin(),T.end());
  s = "";
  t = "";
  for (int i = 0; i < S.size(); i++) s += S[i];
  for (int i = 0; i < T.size(); i++) t += T[i];
  cout << (s < t ? "Yes" : "No");
}

Measured memory_bytes: 256
def f(x):
    k = int(x)
    return c[k], k

c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

N, M = list(map(int, input().split()))
A = list(map(f, input().split()))
A = sorted(A, key=lambda x: x[0] * 10 - x[1])

b = []
dic = {}
n = 0
for d in A:
    if n != d[0]:
        b.append(d[0])
        n = d[0]
        dic[n] = d[1]

ans = [0] * b[0]
n = b[0]
count = 0
while True:
    max_ = 0
    for d in b:
        if n - d == 0:
            if dic[d] > max_:
                max_ = dic[d]
        elif n - d > 0 and ans[n - d] > 0:
            t = ans[n - d] * 10 + dic[d]
            max_ = max(max_, t)

    if n == N:
        print(max_)
        break;
    if max_ > 0 and (N - n) % b[0] == 0:
        if count < 2:
            count += 1
        else:
            print(''.join(sorted(list(str(max_) + str(dic[b[0]])*((N - n)//b[0])), reverse=True)))
            break
    ans.append(max_)
    n += 1

Measured memory_bytes: 3188
INF = float('inf')

N,M,RR = map(int,input().split(" "))
R = list(map(lambda x:int(x)-1,input().split(" ")))
G = [[] for i in range(N)]
sq = [[(x==y)-1 for x in range(RR)] for y in range(RR)]
for i in range(M):
    a,b,c = map(int,input().split(" "))
    a -= 1
    b -= 1
    G[a].append((b,c))
    G[b].append((a,c))

for i in range(RR):
    E = [INF]*N
    F = [1]*N
    E[R[i]] = 0
    F[R[i]] = 0
    q = R[i]
    c = 1
    while c != N:
        for a,b in G[q]:
            if F[a]:
                E[a] = min(E[a],E[q] + b)
        a = [x for x in range(N) if F[x]]
        q = min(a,key=lambda x:E[x])
        F[q] = 0
        c += 1
    for j in range(RR):
        sq[i][j] = E[R[j]]

q = [[[],0,0]]
s = []
while len(q):
    a,b,c = q.pop()
    if b == RR:
        s.append(c)
        continue
    for i in range(RR):
        if i in a:
            continue
        d = c
        d += b and sq[a[-1]][i]
        q.append([a+[i],b+1,d])

print(min(s))


Measured memory_bytes: 8336
import bisect

def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
n = I()
a_li = sorted(LI())
b_li = sorted(LI())
c_li= sorted(LI())
ans = 0
for i in range(n):
  B = b_li[i]
  k = n - bisect.bisect_right(c_li,B)
  l = bisect.bisect_left(a_li,B)
  ans += k*l
print(ans)


Measured memory_bytes: 28900
#include <stdio.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int map[ 4 ][ 3 ][ 10 ] = { };
  int n;
  int i, j, k;

  scanf ( "%d", &n );
  while ( n-- )
  {
    int b, f, r, v;

    scanf ( "%d%d%d%d", &b, &f, &r, &v );
    map[ b - 1 ][ f - 1 ][ r - 1 ] += v;
  }

  for ( i = 0; i < 4; ++i )
  {
    if ( i ) puts ( "####################" );
    for ( j = 0; j < 3; ++j )
    {
      for ( k = 0; k < 10; ++k )
      {
        printf ( " %d", map[ i ][ j ][ k ] );
      }
      puts ( "" );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail)
{
  cout << head;
  if (sizeof...(tail) != 0)
    cout << " ";
  print(forward<Tail>(tail)...);
}

int main()
{
  int n;
  cin >> n;
  print(n ^ 1);
  return 0;
}

Measured memory_bytes: 3556
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define ll long long
#define pb push_back
#define pf push_front			
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pi 3.14159265358
#define xmod 1000000007
using namespace std;

int h,w,h2,w2;
int main(){
	scanf("%d%d%d%d",&h,&w,&h2,&w2);
	printf("%d\n",(h-h2)*(w-w2));
	return 0;
}

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

using namespace std;

string S;

int main(void)
{
	cin >> S;
	int ans = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == '1') ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll a=0,b=0;
    cin>>a>>b;
    cout<<(a+b-3)/(a-1);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int N, K;
	cin >> N >> K;
	LL ans = 0;
	if(!K)ans-=N;
	for(int i=K+1;i<=N;++i){
		ans += N/i*(i-K);
		ans += max(N%i-K+1, 0);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
n, x, y = map(int, input().split())
g = [[] for _ in range(n)]
g[0].append(1)
g[-1].append(n - 2)
g[x - 1].append(y - 1)
g[y - 1].append(x - 1)
for i in range(1, n - 1):
    g[i].append(i - 1)
    g[i].append(i + 1)
ans = [0] * n
for i in range(n):
    q = deque([i])
    d = [-1] * n
    d[i] = 0
    while q:
        p = q.popleft()
        for node in g[p]:
            if d[node] == -1:
                q.append(node)
                d[node] = d[p] + 1
                ans[d[node]] += 1
for k in range(1, n):
    print(ans[k] // 2)


Measured memory_bytes: 47804
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

if max(t) != max(a):
    print(0)
    exit()


def f(li, rev):
    if rev:
        li = li[::-1]

    cnts = [0] * n
    cands = [0] * n
    mx = 0
    cnt = 0
    for i, e in enumerate(li):
        if e > mx:
            cnts[i] = 1
            cands[i] = e
            cnt = e
            mx = e
        else:
            cnts[i] = cnt

    if rev:
        cnts = cnts[::-1]
        cands = cands[::-1]

    return cnts, cands


t_cnt, t_cand = f(t, False)
a_cnt, a_cand = f(a, True)

for e1, e2 in zip(a, t_cand):
    if e2 > e1:
        print(0)
        exit()

ans = 1
for e1, e2 in zip(t_cnt, a_cnt):
    ans *= min(e1, e2)
    ans %= mod

print(ans)


Measured memory_bytes: 19136
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>

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

const char WHITE = '.';

int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> map(h);
    for(int i = 0; i < h; ++i){
        cin >> map.at(i);
    }

    ll numw = 0;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            numw += map.at(i).at(j) == WHITE;
        }
    }

    vector<vector<ll>> d(h, vector<ll>(w, -1));
    queue<P> q;
    d.at(0).at(0) = 0;
    q.push(make_pair(0, 0));
    while(!q.empty()){
        P p = q.front();
        q.pop();
        if(p == P(h - 1, w - 1)){ break; }

        if(p.first > 0 && map.at(p.first - 1).at(p.second) == WHITE &&
           d.at(p.first - 1).at(p.second) == -1){
            d.at(p.first - 1).at(p.second) = 1 + d.at(p.first).at(p.second);
            q.push(P(p.first - 1, p.second));
        }
        if(p.first < h - 1 && map.at(p.first + 1).at(p.second) == WHITE &&
           d.at(p.first + 1).at(p.second) == -1){
            d.at(p.first + 1).at(p.second) = 1 + d.at(p.first).at(p.second);
            q.push(P(p.first + 1, p.second));
        }
        if(p.second > 0 && map.at(p.first).at(p.second - 1) == WHITE &&
           d.at(p.first).at(p.second - 1) == -1){
            d.at(p.first).at(p.second - 1) = 1 + d.at(p.first).at(p.second);
            q.push(P(p.first, p.second - 1));
        }
        if(p.second < w - 1 && map.at(p.first).at(p.second + 1) == WHITE &&
           d.at(p.first).at(p.second + 1) == -1){
            d.at(p.first).at(p.second + 1) = 1 + d.at(p.first).at(p.second);
            q.push(P(p.first, p.second + 1));
        }
    }

    if(d.at(h - 1).at(w - 1) == -1){
        cout << -1 << endl;
    }else{
        cout << numw - (d.at(h - 1).at(w - 1) + 1) << endl;
    }

    return 0;
}


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

int main(){
    ll n; cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll l = a[0], r = a[n-1], i = 1, j = n-2;
    while(i <= j){
        if(l < r){l+= a[i]; i++;}
        else if(l == r) {
            if(i != j) {l += a[i]; r += a[j]; i++; j--;}
            else {l += a[i]; i++;}
        }
        else {r += a[j]; j--;}
    }
    cout << abs(l-r) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

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

  int n;
  ll a, b;
  cin >> n >> a >> b;
  vector<ll> x(n);
  for (int i = 0; i < n; i++)
    cin >> x[i];

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += min((x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3968
#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=998244353;

/*
vector<vector<int>>で表現するバージョン
各要素は、mod=10^9+nとかで計算する
*/
typedef vector<int>vec;
typedef vector<vec>mat;


mat mul(const mat &A,const mat &B){
    mat C(A.size(),vec(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int j=0;j<B[0].size();j++){
            for(int k=0;k<A[0].size();k++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat mat_pow(mat A,int m){
    mat B(A.size(),vec(A.size()));
    for(int i=0;i<A.size();i++)B[i][i]=1;
    while(m){
        if(m&1)B=mul(B,A);
        A=mul(A,A);
        m>>=1;
    }
    return B;
}

int F(int n){
    mat A(2,vint(2));
    A[0][0]=1;A[0][1]=1;
    A[1][0]=1;A[1][1]=0;
    mat X(2,vint(1));
    X[0][0]=0;
    X[1][0]=1;
    X=mul(mat_pow(A,n),X);
    return X[0][0];
}

int mpow(int n,int m){
    int ret=1;
    n%=mod;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int L=222222;
int fact[L],inv[L];

int C(int n,int k){
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}

int T(int n,int k){
    int ans=F(n+k+1);

    int c=1;
    for(int i=n+k;i>n;i--){
        ans=(ans-c+mod)%mod;
        c=c*mpow(i,mod-2)%mod;
        c=c*mpow(n+k-i+1,mod-2)%mod;
        c=c*((2*i-n-k)%mod)%mod;
        c=c*((2*i-n-k-1)%mod)%mod;
    }
    return ans;
}

signed main(){
    fact[0]=1;
    for(int i=1;i<L;i++)fact[i]=fact[i-1]*i%mod;
    inv[L-1]=mpow(fact[L-1],mod-2);
    for(int i=L-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;

    int N,M;
    cin>>N>>M;
    int ans=0;
    N--;M--;

    int n=N+M;
    int k=N;
    cout<<T(n,k)<<endl;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);
	vector<ll> cumSum(n);
	rep(i,n) cin>>a[i];
	cumSum[0] = a[0];
	for(int i = 1; i < n; i++){
		cumSum[i] = cumSum[i-1] + a[i];
	}
	ll evenAns = 0;
	ll oddAns = 0;
	ll offset = 0;
	ll ans = 0;
	// 0番目が正になる場合
	for(int i = 0; i < n; i++){
		if( i % 2 == 0 ){
			if( cumSum[i] + offset > 0){
				// do nothing
			}else if( cumSum[i] + offset <= 0){
				int x = 1 - offset - cumSum[i];
				evenAns += abs(x);
				offset = offset + x;
			}
		}else{
			if( cumSum[i] + offset < 0){
				// do nothing
			}else if( cumSum[i] + offset >= 0){
				int x = -1 - offset - cumSum[i];
				evenAns += abs(x);
				offset = offset + x;
			}
		}
		//cout<<cumSum[i] + offset<<" ";
	}
	//cout<<endl;

	// 0番目が負になる場合
	offset = 0;
	for(int i = 0; i < n; i++){
		//偶数番目が負
		if( i % 2 == 0 ){
			if( cumSum[i] + offset < 0){
				// do nothing
			}else if( cumSum[i] + offset >= 0){
				int x = -1 - offset - cumSum[i];
				oddAns += abs(x);
				offset = offset + x;
			}
		}else{
			if( cumSum[i] + offset > 0){
				// do nothing
			}else if( cumSum[i] + offset <= 0){
				int x = 1 - offset - cumSum[i];
				oddAns += abs(x);
				offset = offset + x;
			}
		}
	}
	cout<<min(evenAns,oddAns)<<endl;
	return 0;
}


Measured memory_bytes: 4456
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define debug(x) cerr << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef DEBUG
  freopen("in", "r", stdin);
#endif

  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k - 1] << '\n';

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    if (b == 'T') cout << 'A' << endl;
    if (b == 'C') cout << 'G' << endl;
    if (b == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N,K;
    cin>>N>>K;
    
    int num;
    if(N%2==0)num=N/2;
    else num=(N+1)/2;
    
    if(K<=num)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}


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

int main()
{
  int S, K;
  char testchar[120];
  char str1[120] = "";
  char str2[5] = "...";

  scanf("%d", &S);
  scanf("%s", testchar);
  K = strlen(testchar);

  if (S >= K){
    printf("%s", testchar);
  }else{
    
    strncpy(str1, testchar,S);
    strcat(str1, str2);
    printf("%s", str1);
  }
  return 0;
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=3005;
int main(){
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	int i,j,dp[N][N],n,m;
	string ans="",a,b;
	fflush(stdin); cin>>a; n=a.size();
	fflush(stdin); cin>>b; m=b.size();
	for(i=0;i<n;++i){
		if(a[i]==b[0]){
			for(j=i;j<n;++j) dp[j][0]=1;
			break;
		}
		else dp[i][0]=0;
	}
	for(i=0;i<m;++i){
		if(b[i]==a[0]){
			for(j=i;j<m;++j) dp[0][j]=1;
			break;
		}
		else dp[0][i]=0;
	}
	for(i=1;i<n;++i){
		for(j=1;j<m;++j){
			if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
//	for(i=0;i<n;++i){
//		for(j=0;j<m;++j) cout<<dp[i][j]<<" ";
//		cout<<endl;
//	}
	i=n-1; j=m-1;
	while((i>=0)&&(j>=0)){
		if(a[i]==b[j]){
			ans+=a[i];
			--i; --j;
			continue;
		}
		if(dp[i-1][j]>dp[i][j-1]) --i;
		else --j;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
}

Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>


using namespace std;

int main(){
int N; cin >> N;
  vector<pair<string,pair<int,int>>> S(N);
  for(int i = 0; i < N; i++){
    string a; int b; cin >> a >> b;
   S[i].first = a; S[i].second.first = -b; S[i].second.second = i + 1;}
  
  sort(S.begin(),S.end());
  
  for(int i = 0; i < N; i++){
    cout << S[i].second.second << endl;
  }
  
  return 0;}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long ans = 0;
		for(int i = k + 1; i < n + 1; i++) {
			ans += n / i * (i - k);
			if(n % i >= k)
				ans += n % i - k + 1;
		}
		if(k == 0)
			ans -= n;
		System.out.println(ans);
	}

}


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

using namespace std;

int H, W;
int cost[60][60];
char s[60][60];

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

int bfs() {
  queue<pair<int, int>> q;  // (y, x)
  q.push(make_pair(0, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cost[i][j] = 1e9;
    }
  }
  cost[0][0] = 0;
  s[0][0] = '#';
  int blank = 0;
  while (!q.empty()) {
    auto o = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int fx = o.second + dx[i], fy = o.first + dy[i];
      if (fx < 0 || fx >= W || fy < 0 || fy >= H) {
        continue;
      }
      if (s[fy][fx] != '.') {
        continue;
      }
      s[fy][fx] = '#';
      blank++;
      cost[fy][fx] = cost[o.first][o.second] + 1;
      q.push(make_pair(fy, fx));
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '.') {
        blank++;
      }
    }
  }
  if (cost[H - 1][W - 1] == 1e9) {
    return -1;
  }
  return blank - cost[H - 1][W - 1];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
    }
  }
  cout << bfs() << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C, D, E int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	fmt.Scan(&D)
	fmt.Scan(&E)
	ans := 0
	lis := []int{A, B, C, D, E}
	diff := 0
	for i := 0; i < 5; i++ {
		ans += ((lis[i] + 9) / 10) * 10
		tmp_diff := ((lis[i]+9)/10)*10 - lis[i]
		// fmt.Println(tmp_diff)
		if tmp_diff > diff {
			diff = tmp_diff
		}
	}
	fmt.Println(ans - diff)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    // k回操作を行う。なお、全てが最大値(=n)となった場合には途中で抜ける
    rep(cnt, k){
        vi sum(n, 0);
        rep(i, n){
            ll left = max(0LL, i-a[i]);
            ll right = min(n-1, i+a[i]);
            sum[left]++;
            if(right != n-1) sum[right+1]--;
        }
        ll cnt_n = 0;
        rep(i, n){
            a[i] = sum[i];
            if(i < n-1) sum[i+1] += sum[i];
            if(a[i] == n) cnt_n++;
        }
        if(cnt_n == n) break;
    }
    rep(i, n) cout << a[i] << (i == n-1 ? endl : " ");
}

Measured memory_bytes: 6360
/// @file a1.cpp
#include <cstdio>

void f() {}

/// @brief Creates a string from the input.
int main() {
    char s[4];

    scanf("%c%*c%*c%*c", s+0);
    scanf("%*c%c%*c%*c", s+1);
    scanf("%*c%*c%c%*c", s+2);
    s[3] = '\0';
    printf("%s\n", s);
    f();
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define base 950527
#define base2 1777771
using namespace std;
typedef unsigned long long ll;
typedef pair <int,int> P;
ll A[1001][1001];
char a[1001][1001],b[1001][1001];

int main(){
  int W,H,w,h;
  cin>>H>>W;
  for(int i=0;i<H;i++)scanf("%s",a[i]);
  cin>>h>>w;
  for(int i=0;i<h;i++)scanf("%s",b[i]);

  ll target=0;
  for(int i=0;i<h;i++){
    ll key=0;
    for(int j=0;j<w;j++){
      key=key*base+b[i][j];
    }
    target=target*base2+key;
  }
  
  for(int i=0;i<H;i++){
    ll k=0,l=1;
    for(int j=0;j<W;j++){
      k=k*base+a[i][j];
      if(j-w>=0) k-= l*a[i][j-w];
      else l*=base;
      A[i][j]=k;
    }
  }

  vector <P> ans;
  for(int j=w-1;j<W;j++){
    ll k=0,l=1;
    for(int i=0;i<H;i++){
      k=k*base2+A[i][j];
      if(i-h>=0) k-=l*A[i-h][j];
      else l*=base2;
      if(target==k) ans.push_back(P(i-h+1,j-w+1)); 
    }
  }

  sort(ans.begin(),ans.end());
  for(int i=0;i<(int)ans.size();i++)printf("%d %d\n",ans[i].first,ans[i].second);
  
  return 0;
}

Measured memory_bytes: 16552
import java.io.*;
import java.util.*;
 
public class Main{
	
 
	public void solve(){
		while(true){
			int H = nextInt();
			int W = nextInt();
			if(H == 0) break;
			
			int l = H * H + W * W;
			
			int h = H + 1;
			
			while(true){
				int ww = l - h * h;
				if(ww < 1){
					l += 1;
					h = 1;
				}else{
					int w = sqrt(ww);
					if(w > 0 && h < w){
						out.println(h + " " + w);
						break;
					}else{
						h += 1;
					}
				}
			}
			
		}
	}
	public int sqrt(int v){
		for(int i = 1; i * i <= v; i++){
			if(i * i == v) return i;
		}
		return -1;
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 24484
D,G = map(int,input().split(' '))
l = [list(map(int,input().split())) for i in range(D)]

ans = 10**8
for i in range(2**D):
    score = 0
    tmp = 0
    n_list = []
    for j in range(D):
        if (i >> j & 1):
            k = l[j]
            score += (j+1)*100*k[0]+k[1]
            tmp += k[0]
        else:
            n_list.append([j+1]+l[j])
    e_flag = False
    for ii in n_list[::-1]:#[1or2or..,times,bonus]
        for jj in range(ii[1]-1):
            if score<G:
                score += ii[0]*100
                tmp += 1
            else:
                e_flag = True
                break
        if e_flag:
            break
    if score<G:
        continue
    ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
//#include <limits>
//#include <type_traits>
//#include <boost/integer/common_factor_rt.hpp>
using namespace std;

int main(){

  long N,K,a,b,s,ans;
  int i,j,k,d;
  string A[200000];
  bool can;
  can=true;
  //using T = int32_t;
  ans=1;
  cin>>N;
  for(i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A,A+N);
  for(i=0;i<N-1;i++){
    if(A[i]!=A[i+1]){
      ans+=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7916
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long signed int ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
string S;
vector<int> number;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>S;
	REP(i, S.length()) {
		number.push_back(S[i]-'0');
	}
	int sum = 0;
	for (int bit = 0; bit < (1 << S.length()-1); ++bit) {
		sum = number[0];
		for (int i = 0; i<3; ++i) {
			if (bit & (1 << i)) {
				sum += number[i+1];
			}
			else {
				sum -= number[i+1];
			}
		}
		if (sum == 7) {
			cout << number[0];
			for (int i = 0; i<3; ++i) {
				if (bit & (1 << i)) {
					cout << '+';
				}
				else {
					cout << '-';
				}
				cout << number[i + 1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,c=0,n=0,q=0,s[10000],t[500];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&t[j]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(s[j]==t[i]){
	c++;
	break;
      }
      else continue;
    }
  }
 
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 640
#B問題

import math

distance = 0
ans = 0
n, d = map(int, input().split())
x = [input().split() for l in range(n)]

#リストの中にリストがある時→A[i][j]のように表現
for i in range(n):
    distance = math.sqrt(pow(int(x[i][0]),2)+pow(int(x[i][1]),2))
    if distance <= d:
        ans += 1
print(ans)

Measured memory_bytes: 67628
public class Hello{
    public static void Main(){
        string[] s=new string[4];
        int word_a=0,word_b=0;
        string b=" ";
         string word=System.Console.ReadLine();
        for(int i=0;i<4;i++){
            s[i]=word.Substring(i,1);
            
            if(s[0]==s[i]){
                word_a++;
            }
            else if(word_b==0)
            {
                b=s[i];
                word_b++;
            }
            else if(b==s[i])
            word_b++;
        }
                if(word_a==2 && word_b==2)
            System.Console.WriteLine("Yes");
            else
            System.Console.WriteLine("No");
        
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 510000
#define S 233
int n;
int ai[N], ar[N];
char ch[N], cr[N];
int pr[N];
void solve(char ch[], int a[])
{
    int u = 0;
    a[1] = 1;
    for (int i = 2; i <= n; ++ i)
    {
        while (u && ch[u + 1] != ch[i]) u = pr[u];
        if (ch[u + 1] == ch[i]) u ++;
        pr[i] = u;
        if (u && i % (i - u) == 0); else a[i] = 1;
    }
}
int main()
{
    scanf("%s", ch + 1); n = strlen(ch + 1);
    int bo = 1;
    for (int i = 2; i <= n; ++ i)
        if (ch[i] != ch[1]) bo = 0;
    if (bo) {cout << n << "\n" << 1; return 0;}
    for (int i = 1; i <= n; ++ i) cr[i] = ch[n - i + 1];
    solve(ch, ai);
    if (ai[n]) {cout << 1 << "\n" << 1; return 0;}
    solve(cr, ar);
    for (int i = 1, j = n; i < j; ++ i, -- j) swap(ar[i], ar[j]);
    int cnt = 0;
    for (int i = 1; i < n; ++ i)
        if (ai[i] && ar[i + 1])
            cnt ++;
    cout << 2 << "\n" << cnt;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main(){
	int a, b;
	cin >> a >> b;
	rep(i,1001) {
		int s = i * 0.08, t = i * 0.1;
		if (s == a && b == t) {
			cout << i << endl;
			return 0;
 		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256