akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll sieve(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vi a(n);
  REP(i,n) {
    int x;
    cin >> x;
    x--;
    a[i]=x;
  }
  vb check(n,false);
  vi cnt(n,-1);
  int now=0,c=0;
  while(1) {
    if(!check[now]) {
      check[now]=true;
      cnt[now]=c;
      c++;
      if(c==k) {
        cout << a[now]+1 << endl;
        break;
      }
      now=a[now];
    } else {
      int interval=c-cnt[now];
      int b=(k-c)%interval;
      auto iter=find(ALL(cnt),cnt[now]+b);
      cout << iter-cnt.begin()+1 << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 4812
#include<stdio.h>
#include<string.h>
#include<time.h>
int x,y,dx[8]={0,1,1,1,0,-1,-1,-1},dy[8]={1,1,0,-1,-1,-1,0,1},co[191],sps,final;
char dic[191][1000][191],sp[1000][191];
void ans(char map[20][10],int nx,int ny,int dir){
	int fx,fy,len,po,qw,sw,ck;
	char dam[191]={};
	fx=nx;
	fy=ny;
	len=0;
	while(1){
		dam[len]=map[nx][ny];
		len++;
		if(len>=final){
			if(co[len]==0){
				strcpy(dic[len][co[len]],dam);
				co[len]++;
			}
			else{
				sw=ck=0;
				for(po=0;po<sps;po++){
					if(strcmp(sp[po],dam)==0){
						ck++;
						break;
					}
				}
				if(ck==0){
					for(po=0;po<co[len];po++){
						if(strcmp(dic[len][po],dam)==0){
							if(final<strlen(dam)){
								strcpy(sp[0],dam);
								sps=1;
								final=strlen(dam);
							}
							else{
								strcpy(sp[sps],dam);
								sps++;
							}
							sw++;
							break;
						}
					}
				}
				if(sw==0&&ck==0){
					strcpy(dic[len][co[len]],dam);
					co[len]++;
				}
			}
		}
		nx=(nx+dx[dir]+x)%x;
		ny=(ny+dy[dir]+y)%y;
		if(nx==fx&&ny==fy){
			break;
		}
	}
	return;
}
int main(void){
	int i,j,k,maxl,t0,t1,tsum=0;
	char dn[20][10],nu;
	while(1){
		t0=clock();
		scanf("%d %d",&y,&x);
		if(x==0&&y==0){
			break;
		}
		for(k=0;k<191;k++){
			if(co[k]==0){
				continue;
			}
			co[k]=0;
			for(i=0;i<1000;i++){
				if(dic[k][i][0]==0){
					continue;
				}
				for(j=0;j<191;j++){
					if(dic[k][i][j]==0){
						break;
					}
					dic[k][i][j]=0;
				}
			}
		}
		for(i=0;i<1000;i++){
			if(sp[i][0]==0){
				continue;
			}
			for(j=0;j<191;j++){
				sp[i][j]=0;
			}
		}
		for(i=0;i<20;i++){
			if(dn[i][0]==0){
				break;
			}
			for(j=0;j<10;j++){
				dn[i][j]=0;
			}
		}
		i=j=0;
		while(1){
			scanf("%c",&nu);
			if(nu!='\n'){
				dn[i][j]=nu;
				i++;
				if(i==x){
					i=0;
					j++;
				}
				if(j==y){
					break;
				}
			}
		}
		sps=0;
		final=2;
		for(i=0;i<x;i++){
			for(j=0;j<y;j++){
				for(k=0;k<8;k++){
					ans(dn,i,j,k);
				}
			}
		}
		maxl=final;
		final=0;
		for(i=1;i<sps;i++){
			if(strcmp(sp[final],sp[i])>0){
				final=i;
			}
		}
		if(strlen(sp[final])==0){
			printf("0\n");
		}
		else{
			for(i=0;i<maxl;i++){
				printf("%c",sp[final][i]);
			}
			printf("\n");
		}
		t1=clock();
		//printf("time %d\n",t1-t0);
		tsum+=t1-t0;
	}
	//printf("Sum %d\n",tsum);
	return 0;
}

Measured memory_bytes: 35488
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 h, w;
    cin >> h >> w;
    vector<vector<char> > v(h+2, vector<char> (w+2, '#'));
    for (int i = 1; i <= h; ++i) {
        string s;
        cin >> s;
        for (int j = 1; j <= w; ++j) {
            v[i][j] = s[j-1];
        }
    }
    for (auto &&vv : v) {
        for (auto &&c : vv) {
            cout << c;
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

def factor(x):
    res = defaultdict(int)
    for i in range(2, int(x ** 0.5) + 1):
        while x % i == 0:
            res[i] += 1
            x //= i
    if x > 1:
        res[x] += 1
    return res


n, p = map(int, input().split())
ans = 1
for k, v in factor(p).items():
    ans *= k ** (v // n)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int X, Y;
    cin >> X >> Y;
    if(Y%2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if(Y/2-X < 0) {
        cout << "No" << endl;
        return 0;
    }
    if(2*X-Y/2 < 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ENABLE_ASSERT
#include <cassert>
#else
#undef assert
#define assert static_cast<void>(0)
#endif

using namespace std;
using namespace std::literals;

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

    string ss;
    ss.reserve(n);

    while (s.length() > 1) {
        n = s.length();
        ss.push_back(s[0]);
        for (int i = 1; i < n; i++) {
            if (s[i] == ss.back())
                continue;
            ss.push_back(s[i]);
        }
        if (ss.length() == s.length())
            break;

        swap(s, ss);
        ss.clear();
    }

    cout << s.length();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	int AB,BC,CA;
	cin >> AB >> BC >> CA;
	int mx = max({AB,BC,CA});
	if(AB == mx){
		cout << BC*CA /2  << endl;
	} else if(BC == mx){
		cout << CA*AB /2  << endl;
	} else{
		cout << AB*BC /2  << endl;
	}
}


Measured memory_bytes: 256
from collections import deque

k = int(input())

tbl = []
queue = deque()

for i in range(1, 10):
    queue.append(i)

while queue:
    if len(tbl) >= k:
        break
    x = queue.popleft()
    tbl.append(x)
    if x % 10 == 0:
        queue.append(x * 10)
        queue.append(x * 10 + 1)
    elif x % 10 == 9:
        queue.append(x * 10 + 8)
        queue.append(x * 10 + 9)
    else:
        queue.append(x * 10 + x % 10 - 1)
        queue.append(x * 10 + x % 10)
        queue.append(x * 10 + x % 10 + 1)

print(tbl[k - 1])


Measured memory_bytes: 16040
n, m = map(int,input().split())

g = {}
for i in range(m):
    s,t = map(int,input().split())
    val = g.get(s,[])
    val.append(t)
    g[s] = val
    val = g.get(t,[])
    val.append(s)
    g[t] = val

color = 1
done = [-1] + [-1] * n

def dfs(g, s):
    done[s] = color
    stack = [s]
    while stack != []:
        t = stack.pop()
        
        for c in g.get(t,[]):
            if done[c] == -1:
                done[c] = color
                stack.append(c)

q = int(input())

for v in range(n):
    if done[v] == -1:
        dfs(g,v)
        color += 1

for j in range(q):
    s,t = map(int,input().split())
    if done[s] == done[t]:
        print('yes')
    else: print('no')

Measured memory_bytes: 32764
import java.util.*

data class Dice(val value: List<Int>) {
    var top = 1
    var south = 2
    var east = 3
    var west = 4
    var north = 5
    var bottom = 6

    fun rolls(ds: String) {
        for (d in ds) {
            roll(d)
        }
    }

    fun roll(d: Char) {
        if (d == 'S') {
            val w = top
            top = north
            north = bottom
            bottom = south
            south = w
        } else if (d == 'N') {
            val w = top
            top = south
            south = bottom
            bottom = north
            north = w
        } else if (d == 'E') {
            val w = top
            top = west
            west = bottom
            bottom = east
            east = w
        } else if (d == 'W') {
            val w = top
            top = east
            east = bottom
            bottom = west
            west = w
        }
    }

    fun top() = this.value.get(top - 1)
    fun east() = this.value.get(east - 1)

    fun setTopAndSouth(n: Int, m: Int) {
        val t = value.indexOf(n) + 1
        val s = value.indexOf(m) + 1

        top = t;
        bottom = 7 - t
        south = s
        north = 7 - s
        if ((top == 1 && south == 2)
            || (top == 2 && south == 6)
            || (top == 6 && south == 5)
            || (top == 5 && south == 1)
        ) {
            east = 3
            west = 4
        } else if ((top == 1 && south == 3)
            || (top == 3 && south == 6)
            || (top == 6 && south == 4)
            || (top == 4 && south == 1)
        ) {
            east = 5
            west = 2
        } else if ((top == 1 && south == 4)
            || (top == 4 && south == 6)
            || (top == 6 && south == 3)
            || (top == 3 && south == 1)
        ) {
            east = 2
            west = 5
        } else if ((top == 1 && south == 5)
            || (top == 5 && south == 6)
            || (top == 6 && south == 2)
            || (top == 2 && south == 1)
        ) {
            east = 4
            west = 3
        } else if ((top == 2 && south == 3)
            || (top == 3 && south == 5)
            || (top == 5 && south == 4)
            || (top == 4 && south == 2)
        ) {
            east = 1
            west = 6
        } else if ((top == 2 && south == 4)
            || (top == 4 && south == 5)
            || (top == 5 && south == 3)
            || (top == 3 && south == 2)
        ) {
            east = 6
            west = 1
        }
    }
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val dice = Dice(
        listOf(
            scanner.nextInt(),
            scanner.nextInt(),
            scanner.nextInt(),
            scanner.nextInt(),
            scanner.nextInt(),
            scanner.nextInt()
        )
    )
    val q = scanner.nextInt()
    val answers = mutableListOf<Int>()
    (1..q).forEach {
        dice.setTopAndSouth(scanner.nextInt(), scanner.nextInt())
        answers.add(dice.east())
    }
    answers.forEach {
        println(it)
    }
}



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



int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 0;
  ll height = 0;
  ll mod = 1000000007;
  for(int i=1; i<n; ++i) {
    height = (height+a[i-1])%mod;
    sum += height * a[i];
    sum %= mod;
  }
    
  cout << sum << endl;
  
  return 0;
}

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

int main(){
  int n;
  string s;
  int maxi = 0;
  int x = 0;

  cin >> n >> s;

  for(int i=0;i < n;i++){

    if(s[i] == 'I')
      {
       	x++;
	maxi = max(maxi,x);

      }
    if(s[i] == 'D')
      {
       	x--;
	maxi = max(maxi,x);
      }
  }
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 384
N,D,A = gets.split.map(&:to_i)
E = N.times.map{ gets.split.map(&:to_i) }
E << [10 ** 18, 1]
E.sort_by!(&:first)
S = Array.new(N + 1, 0)

ans = N.times.inject(0) do |sa, i|
  S[i] += S[i - 1] if i > 0
  x0 = E[i][0]
  h = E[i][1]

  if S[i] >= h
    sa
  else
    a = (h - S[i] + A - 1) / A
    j = E.bsearch_index do |e|
      x = e[0]
      x > x0 + 2 * D
    end
    S[i] += a * A
    S[j] -= a * A
    sa + a
  end
end
puts ans


Measured memory_bytes: 22520
#include<stdio.h>
int a, b, c, x, y, z, i, j;
int ans;
int main(){
	scanf("%d%d%d%d", &a, &b, &c, &x);
	x /= 50;
	y = x-c;
	for(i=0; i<=a; i++){
		for(j=0; j<=b; j++){
			z = i*10 + j*2;
			if(y<=z && z<=x){ans++;}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
struct p
{
int v;
int index;
};
struct p inv[200000];
struct p cv[200000];
bool ch[200000]={false};
int n;
bool cmp(p x,p y)
{return x.v>y.v;}
int f(int nindex)
{
for(int i=0;i<n;i++)
if(inv[i].index==nindex)
return i;
return -1;
}
int main()
{
int i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>inv[i].v;
inv[i].index=i;
cv[i].v=inv[i].v;
cv[i].index=inv[i].index;
}
sort(cv,cv+n+1,cmp);
for(i=0;i<n/2;i++)
ch[cv[i].index]=true;
int m=n/2-1;
for(i=0;i<n;i++)
{
if(ch[i])cout<<cv[m+1].v;
else cout<<cv[m].v;
if(i<(n-1))cout<<endl;
}
return 0;
}




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

int main(){
  int x, y, z, k; cin >> x >> y >> z >> k;
  vector<int64_t> a(x), b(y), c(z);
  for (int i = 0; i < x; i++) cin >> a.at(i);
  for (int i = 0; i < y; i++) cin >> b.at(i);
  for (int i = 0; i < z; i++) cin >> c.at(i);
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  vector<int64_t> v;
  priority_queue<pair<int64_t, vector<int>>> q;
  set<vector<int>> s;
  vector<int> vec = {0, 0, 0};
  q.push(make_pair(a.at(0)+b.at(0)+c.at(0), vec));
  s.insert(vec);
  while (v.size() < k){
    auto p = q.top(); q.pop();
    v.push_back(p.first);
    vector<int> w = p.second;
    if (w.at(0) + 1 < x ){
      w.at(0)++;
      if (!s.count(w)) {q.push(make_pair(a.at(w.at(0))+b.at(w.at(1))+c.at(w.at(2)), w)); s.insert(w);}
      w.at(0)--;
    }
    if (w.at(1) + 1 < y){
      w.at(1)++;
      if (!s.count(w)) {q.push(make_pair(a.at(w.at(0))+b.at(w.at(1))+c.at(w.at(2)), w)); s.insert(w);}
      w.at(1)--;
    }
    if (w.at(2) + 1 < z){
      w.at(2)++;
      if (!s.count(w)) {q.push(make_pair(a.at(w.at(0))+b.at(w.at(1))+c.at(w.at(2)), w)); s.insert(w);}
    }
  }
  for (int64_t i : v) cout << i << endl;
  return 0;
} 

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
    int a;
    cin>>a;
    for(int i=1;i<=9;i++){
        if(a%i==0 and a/i<=9){cout<<"Yes";return 0;}
    }
cout<<"No";
}


Measured memory_bytes: 256
A = list(map(int,input().split()))
#[A1,A2,A3] = list(map(int,input().split()))
# print(A)

from itertools import permutations
Ls = list(permutations(A))

ans=100000000
for L in Ls:
    # print('L:',L)
    cost=0
    for i in range(1,3):
        cost+=abs(L[i]-L[i-1])
        # print('i,c:', i,cost)
    # print('cost:', cost)
    ans = min(ans,cost)

print(ans)


Measured memory_bytes: 62028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{

    char s[103];
    cin>>s;
    int ret = 0;
    int l = strlen(s);
    for(int i = 0;i < l;i ++)
    {
        if(s[l-1-i] != s[i])
        {
            ret ++;
        }
    }
    cout<<ret/2<<endl;
    return 0;
}


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

        String S = sc.next();

        String res;
        if(S.charAt(S.length()-1)=='s'){
            res = "es";
        }else{
            res="s";
        }

        res = S + res;
        System.out.println(res);
        }
    }

Measured memory_bytes: 39292
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
      	long B = sc.nextLong();
      	long C = sc.nextLong();
      	long max = Math.max(Math.max(A,B),Math.max(B,C));
      	long count = 0;
		long Ab = A%2;
      	long Bb = B%2;
      	long Cb = C%2;
      	boolean all=false;
      	if(Ab==Bb&&Bb==Cb){
        	all=true;
        }
      	if(all){
        	for(;A<max;A+=2){
            	count++;
            }
          	for(;B<max;B+=2){
            	count++;
            }
          	for(;C<max;C+=2){
            	count++;
            }
          	System.out.println(count);
        }else{
          if(Ab!=Bb&&Ab!=Cb){
          	B++;
            C++;
            count++;
          }
          if(Ab!=Bb&&Bb!=Cb){
          	A++;
            C++;
            count++;
          }          
          if(Cb!=Bb&&Ab!=Cb){
          	B++;
            A++;
            count++;
          }      
                  	for(;A<max;A+=2){
            	count++;
            }
          	for(;B<max;B+=2){
            	count++;
            }
          	for(;C<max;C+=2){
            	count++;
            }
          	System.out.println(count);
        }
      
 		sc.close();
	}
}


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

int main(){
  int a,b;
  cin>>a>>b;
  int c=a*b;
    for(int i=1;i<c;i=1)
      c-=2;
   if(c==0)
     cout<<"Even"<<endl;
  else
    cout<<"Odd"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
const int MX = 100005;
int n, x[MX], nx[MX][20], l, q, a, b, ans, k;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d", x+i);
	scanf("%d%d", &l, &q);
	rep(i,n){
		while(a < n && x[a] - x[i] <= l) a++;
		a--;
		nx[i][0] = a;
	}
	rep(j,19) rep(i,n) nx[i][j+1] = nx[nx[i][j]][j];
	rep(i,q){
		scanf("%d%d", &a, &b);
		a--; b--; ans = 0;
		if(a > b) swap(a,b);
		while(a < b){
			for(k = 0; nx[a][k] < b; k++);
			if(k) k--;
			ans += 1 << k;
			a = nx[a][k];
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 9088
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();
		
		Set<Integer> A = new HashSet<Integer>(Arrays.asList(1, 3, 5, 7, 8, 10, 12));
		Set<Integer> B = new HashSet<Integer>(Arrays.asList(4, 6, 9, 11));
		Set<Integer> C = new HashSet<Integer>(Arrays.asList(2));
		
		if(A.contains(x) && A.contains(y)
			|| B.contains(x) && B.contains(y)
			|| C.contains(x) && C.contains(y)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int mn = 1e9;
string s, t;

bool f(int p, int q) {
	int i;
	for (i = 0; i < q; i++) if (t[i] != p) return 1;
	return 0;
}

int main()
{
	int i, j, k;
	cin >> s;
	for (i = 'a'; i <= 'z'; i++) {
		t = s;
		for (j = 0; f(i, s.size() - j); j++) {
			for (k = 0; k < s.size() - j - 1; k++) {
				if (t[k] == i || t[k + 1] == i)
					t[k] = i;
			}
		}
		mn = min(mn, j);
	}
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ef(i,u) for(int i=b[u];i;i=nxt[i])
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,b,a) for(int i=b;i>=a;--i)
#define gcd(a,b) __gcd(a,b)
#define MEM(a,x) memset(a,x,sizeof(a))
#define VI vector<int>
#define PII pair<int,int>
#define ull unsigned long long
#define ll long long
#define fi first
#define se second
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n,k;
int main(){
    cin>>n>>k;
    ll ans=0;
    rep(i,k,n+1){
        ll a=1ll*i*(i-1);
        ll b=1ll*n*i;
        ans+=b-a+1;ans%=mod;
    }
    cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<string.h>
#include<iostream>
#include <fstream>
using namespace std;

#define N	100000
int	A[N + 1] = { 0 };
int	L[N + 1] = { 0 };
int search(int p[], int left, int right, int value)
{
	while (right - left >= 2){
		int s = (left + right) / 2;
		if (p[s] < value){
			left = s;
		}
		else {
			right = s;
		}
	}
	if (p[left] >= value)
		return	left;
	return right;
}

int main(){
	std::istream & c_in = cin;
	int	n;
	c_in >> n;
	for (int i = 0; i < n; i++){
		c_in >> A[i];
	}
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i){
		if (L[length - 1] < A[i]){
			L[length++] = A[i];
		}
		else{
			int j = search(L, 0, length - 1, A[i]);
			L[j] = A[i];
		}
	}
	if (n == 0)
		length = 0;
	printf("%d\n", length);
	return 0;
}

Measured memory_bytes: 1924
n = int(input())
depths = [0] * n
parents = [-1] * n
nodes = [0] * n
children = [0] * n
childs = []
parts = ['leaf'] * n
numall = []

for i in range(n):
    numall.append(list(map(int, input().split())))
    
numall.sort()
for i in range(n):
    nums = numall[i]
    nodes[i] = int(nums[0])
    children[i] = int(nums[1])
    child = [int(s) for s in nums[2:]]
    childs.append(child)
    if child != []:
        parts[i] = 'internal node'
        for j in child:
            parents[j] = i

root = 0
for i in range(n):
    if parents[i] == -1:
        parts[i] = 'root'
        root = i
        break

li = [root]
i = 0
while len(li) < n:
    for j in childs[li[i]]:
        li.append(j)
        depths[j] = depths[li[i]] + 1
    i += 1
      
answer = []
for i in range(n):
    answer.append([nodes[i], parents[i], depths[i], parts[i], childs[i]])
  
answer.sort()
for ans in answer:
    print(('node ' + str(ans[0]) + ': parent = ' + str(ans[1]) + ', depth = ' + str(ans[2]) + ', ' + ans[3] + ', '), end='')
    print(ans[4])



Measured memory_bytes: 49636
#include<stdio.h>
#include<stdlib.h>
int comp(int *a,int *b){
  return *b-*a;
}
int main(){
  int n,k,ans=0;
  int l[55]={};
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  qsort(l,n,sizeof(int),comp);
  for(int i=0;i<k;i++){
    ans+=l[i];
  }
  printf("%d",ans);
  return 0;
}

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

int main(){
  int n,r;
  cin >> n >> r;
  if(10 <= n){
  	cout << r << endl;
  }else{
  	cout << r+100*(10-n) << endl;
  }
  return 0;
}

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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

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

    if (r < 1200) {
        cout << "ABC";
    } else if (r < 2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
s = list(input())

sc = -1
sf = -1

for i in range(len(s)):
    if s[i] == "C":
        sc = i
    elif s[i] == "F":
        sf = i

if (sc == -1) or (sf == -1):
    print("No")
elif sc < sf:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	int a,b,c,d,e,k;

	cin >> a >> b >> c >> d >> e >> k;
	
	if(e-a > k) cout << ":(" << endl;
	else cout << "Yay!" << endl;
	
	
	return 0;
}
		

Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
output = "War"
mx = max(X)
my = min(Y)

for i in range(x + 1, y + 1):
    if mx < i <= my:
        output = "No War"

print(output)


Measured memory_bytes: 3060
import heapq as hq
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]

edges = [[] for _ in range(10)]
for i in range(10):
    for j in range(10):
        edges[j].append((c[i][j],i))

dis = [10**10] * 10
dis[1] = 0
q = []
hq.heappush(q, (0,1))

while q:
    dis1,p = hq.heappop(q)
    for dis2,p2 in edges[p]:
        if dis[p2] > dis[p] + dis2:
            dis[p2] = dis[p] + dis2
            hq.heappush(q, (dis[p2], p2))

ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += dis[a[i][j]]

print(ans)


Measured memory_bytes: 3444
def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n + 1
s = int(input())
ans = [s]
cnt = 0
while True:
    ans.append(f(s))
    if f(s) == 4:
        cnt += 1
        if cnt == 2:
            break
    s = f(s)

for i in range(len(ans)-1):
    for j in range(i+1, len(ans)):
        if ans[i] == ans[j]:
            print(j+1)
            break
    else:
        continue
    break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e5 + 5;

int n;
int a[N], b[N], c[N];
int dp[N][5];

int f(int idx, int now) {
    if(idx == n) return 0;
    int &sol = dp[idx][now];
    if(sol != -1) return sol;
    if(now == 0) {
        sol = max(f(idx + 1, 1) + a[idx + 1], 
              max(f(idx + 1, 2) + b[idx + 1], 
                  f(idx + 1, 3) + c[idx + 1]));
    } else if(now == 1) {
        sol = max(f(idx + 1, 2) + b[idx + 1],
                  f(idx + 1, 3) + c[idx + 1]);
    } else if(now == 2) {
        sol = max(f(idx + 1, 1) + a[idx + 1],
                  f(idx + 1, 3) + c[idx + 1]);
    } else {
        sol = max(f(idx + 1, 1) + a[idx + 1],
                  f(idx + 1, 2) + b[idx + 1]);
    }
    return sol;
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << f(0, 0) << "\n";
}

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

Measured memory_bytes: 12976
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;

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

int main() {
    int n, m;
    cin >> n >> m;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] /= 2LL;
    }
    int b = __builtin_ctzll(a[0]);
    rep(i, n-1) {
        if(b != __builtin_ctz(a[i+1])) {
            cout << 0 << endl;
            return 0;
        }
    }


    ll x = 1LL;
    rep(i, n) {
        x = lcm(a[i], x);
        if(x > (ll)1e11+10LL) {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = m/x;
    ans = (ans + 1)/2;

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
const int N = 3e5 + 5;
int k , n;
int ans[N];
int len;
void solve(){
	for(int i = 1 ; i <= n ; ++i){
		ans[i] = k + 1 >> 1;
	}
	len = n;
	for(int i = 0 ; i < (n >> 1) ; ++i){
		if(ans[len] > 1){
			--ans[len];
			while(len < n){
				ans[++len] = k;
			}
		}
		else{
			--len;
		}
	}
}
int main(){
	scanf("%d %d" , &k , &n);
	if(!(k & 1)){
		ans[1] = k >> 1;
		for(int i = 2 ; i <= n ; ++i){
			ans[i] = k;
		}
		len = n;
	}
	else{
		solve();
	}
	for(int i = 1 ; i <= len ; ++i){
		printf("%d%c" , ans[i] , " \n"[i == len]);
	}
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int x, n;
    cin >> x >> n;
    map<int, bool> mp;
    rep(i, 0, n)
    {
        int p;
        cin >> p;
        mp[p] = true;
    }
    int res;
    for (int i=x, j=x; ;i++, j--)
    {
        if (mp[j] == false)
        {
            res = j;
            break;
        }
        if (mp[i] == false)
        {
            res = i;
            break;
        }
    }
    cout << res;
    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	long long t;
	cin >> t;
	vector<pair<long long,long long>> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i].first >> a[i].second;
	}
	
	sort(a.begin(),a.end(),
		[&](pair<long long,long long> &p0,pair<long long,long long> &p1){
			if(p0.first==0 && p1.first==0){
				return p0.second<p1.second;
			}
			return p1.first*(p0.second+1)<p0.first*(p1.second+1);
		}
	);
	
	for(int i=0;i<n;i++){
		//cout << a[i] << "\n";
	}
	
	int sz=0;
	for(int i=0;i<n;i++){
		if(a[i].first==0) break;
		sz++;
	}
	
	//0 .. sz-1 : a>0
	vector<vector<long long>> dp(sz+1,vector<long long>(52,1LL<<56));
	dp[0][0]=0;
	for(int i=0;i<sz;i++){
		for(int j=0;j<50;j++){
			//dp[i][j]
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		}
		for(int j=0;j<50;j++){
			if((1LL<<56)/a[i].first<(1+dp[i][j])) continue;
			long long v=dp[i][j]+1+a[i].first*(1+dp[i][j])+a[i].second;
			if(v>(1LL<<56)) continue;
			dp[i+1][j+1]=min(dp[i+1][j+1],v);
		}
		//cout << dp[i+1] << "\n";
	}
	vector<long long> b;
	b.push_back(0);
	long long sum=0;
	for(int i=sz;i<n;i++){
		sum+=a[i].second+1;
		b.push_back(sum);
	}
	
	int res=0;
	for(int i=0;i<50;i++){
		//dp[sz][i]
		long long v=dp[sz][i];
		long long rem=t-v;
		if(rem<0) continue;
		int ind=(int)(upper_bound(b.begin(),b.end(),rem)-b.begin());
		ind--;
		res=max(res,i+ind);
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 92416
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr

using namespace std;

int main() {
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        // Header
        for (int i=0; i<W; i++) cout << '#';
				cout << endl;
        
        for (int i=0; i<H-2; i++) {
            // Left
            cout << '#';
            for (int j=0; j<W-2; j++) cout << '.';
            // Right
            cout << '#' << endl;
        }
        
        // Footer
        for (int i=0; i<W; i++) cout << '#';
				cout << endl;
        cout << endl;
    }
    return 0;		 
}


Measured memory_bytes: 3100
// ABC043_B

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    
    string ans;
    for(int i = 0; i < s.size(); i++) {
        switch(s[i]) {
            case '0' :
                ans.push_back('0');
                break;
            case '1' :
                ans.push_back('1');
                break;
            case 'B' :
                if(ans.empty() != true) {
                    ans.pop_back();
                }
                break;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:from __builtin__ import xrange as range;from future_builtins import ascii, filter, hex, map, oct, zip 

BUFSIZE = 8192;
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3: 
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n");ii = lambda: int(input());ll = lambda: list(map(int , input().split()));vv = lambda: map(int , input().split());pr = print
pl = lambda l: pr(" ".join(list(map(str,l))))
import math
def fun(n):
    tot = n * (n+1)
    tot//=2
    return tot

n = ii()
print(fun(n) - 3*fun(n//3) -5*fun(n//5) + 15*fun(n//15))


Measured memory_bytes: 85588
#include <bits/stdc++.h>
using namespace std;
int main() {
  int L, R, d;
  cin >> L >> R >> d;
  int ans = R / d;
  if(L > 1) {
    ans -= (L - 1) / d;
  }
  cout << ans << endl;
  return 0;
}

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

const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
// トポロジカルソートされるグラフ
vector<int> to[maxV];
int id[maxN][maxN];

int toId(int i, int j) {
    if (i > j) swap(i, j);
    return id[i][j];
}

bool visited[maxV]; // 関数外の変数については, ポインタはnull数値はゼロ値になるらしい.
bool calced[maxV];
int day[maxV];
int dfs(int v) {
    if (visited[v]) {
        if (!calced[v]) return -1;
        return day[v];
    }
    visited[v] = true;
    day[v] = 1;
    for (int e : to[v]) {
        int dayBefore = dfs(e); // 前回の回の日程を取得している.
        if (dayBefore == -1) {
            return -1;
        }
        // vに来るまでにやつ必要があった試合の日付よりも後の日付に設定する
        day[v] = max(day[v], dayBefore + 1);
    }
    calced[v] = true;
    return day[v];
}


signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // A_{i, j + 1} は A_{i, j}が終わらないとできない -> Aが終わった後にBをしなければならない
    // とき A -> Bとしたグラフを作り, そのグラフについてトポロジカルソートみたいなことをやる.
    // トポロジカルソートすると同時に, day(B) = day(A) + 1みたいな感じにしておく
    int N;
    cin >> N;

    // 対戦相手の情報をとりあえず入れておくやつ
    vector<vector<int>> ops(N, vector<int>(N - 1));
    for (int i = 0; i < N; i ++) {
        for (int j = 0; j < N - 1; j++) {
            cin >> ops[i][j];
            ops[i][j]--;
        }
    }
    // 次はidを振る
    int V = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i >= j) continue;
            id[i][j] = V++;
        }
    }
    // そして試合番号のグラフを作る
    // 次のやつをグラフに入れるだけでいい.
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 2; j++) {
            // 一つ後の試合番号 ひとつ前の試合番号
            to[toId(i, ops[i][j + 1])].push_back(toId(i, ops[i][j]));
        }
    }
    // 次はトポロジカルソートっぽいことをして, 何日目かを得る.
    int last = 0;
    for (int v = 0; v < V; v++) {
        int day = dfs(v);
        if (day == -1) {
            cout << -1 << endl;
            return 0;
        }
        last = max(last ,day);
    }
    cout << last << endl;

    return 0;
}

Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

string S;
ll K;

char solve() {
  for (char c:S) {
    if (c=='1') {
      if (K==1) return c;
      K--;
      continue;
    }

    return c;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  cin>>S>>K;
  cout<<solve()<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<ll> val(n);
	for(int i=0;i<n;i++)
		cin>>val[i];
	sort(val.begin(), val.end());
	if(n == 2) cout<<val[1];
	else if(n == 3) cout<<val[1] + val[2];
	else{
		ll ans = val[n-1];	
		int idx = n-2, t = 0;
		for(int i=0; i<n-2;i++){
			ans += val[idx];
			t++;
			if(t == 2){
				idx--; t = 0;
			}
		}
		cout<<ans;
	}
}

Measured memory_bytes: 4756
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    tmp=A[x-1]+B[y-1]-c
    ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 18608
package main

import (
	"fmt"
	"log"
	"strconv"
)

var logFlag = true

func main() {
	var N int
	fmt.Scanf("%d", &N)

	total := 0
	for i:= 1; i <= N ; i++ {
		if len(strconv.Itoa(i)) % 2 == 1 {
			total += 1
		}
	}

	fmt.Printf("%d", total)
}


func Log(format string, string ...interface{}) {
	if logFlag {
		log.Printf(format, string)
	}
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int dx[]={0,1};
int dy[] ={1,0};
int main() {
  int n;
  cin >> n;
  int f[2][n],ans[2][n];
  rep(i,2)rep(j,n){
    cin >> f[i][j]; 
    ans[i][j] = 0;
  }
  queue<P> q;
  q.push(P(0,0));
  ans[0][0] = f[0][0];
  while(!q.empty()){
    P p = q.front();q.pop();
    
    rep(i,2){
      if(p.fi+dx[i]>=2 || p.se+dy[i]>=n)continue;
      ans[p.fi+dx[i]][p.se+dy[i]] = max(ans[p.fi+dx[i]][p.se+dy[i]],ans[p.fi][p.se]+f[p.fi+dx[i]][p.se+dy[i]]);
      q.push(P(p.fi+dx[i],p.se+dy[i]));
    }
  }
  int mx = 0;
  rep(i,2)rep(j,n){
    maxs(mx,ans[i][j]); 
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, P;
    string S;
    cin >> N >> P >> S;
    if(P == 2 || P == 5){
        ll ans = 0;
        rep(i, N){
            int x = S[i]-'0';
            if(x%P == 0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }
    //a[i]:=10^iをPで割った余り
    int a[N];
    a[0] = 1;
    rep2(i, 1, N-1){
        a[i] = (a[i-1]*10)%P;
    }
    map<int, ll> mp;
    int now = 0;
    rep(i, N){
        int x = S[i]-'0';
        now += a[N-1-i]*x;
        now %= P;
        mp[now]++;
    }
    ll ans = 0;
    for(auto &e: mp){
        ans += e.second*(e.second-1)/2;
    }
    ans += mp[0];
    cout << ans << endl;
}

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

int main() {

	string n;
	cin >> n;
	
	char x = n.at(0);
	char y = n.at(1);
	char w = n.at(2);
	char z = n.at(3);	

  if (x != y && x != w && x != z) {

		cout << "No" << endl;
  }
  else if (y != w && y != z && y != x) {

    cout << "No" << endl;
  }
  else if (z != w && z != y && z != x) {

    cout << "No" << endl;
  }
  else if (((x == y && w == z) && w != x) || ((x == z && y == w) && y != x) || ((y == z && x == w) && x != y)){

        cout << "Yes" << endl;
  }
  else {

  	cout << "No" << endl;
  }

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

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

const int MOD = 1000000007;



int main() {
    string s; cin >> s;
    ll cnt = 0,ans = 0;
    for(int i = 0;i < s.length();i++){
        if(s[i] == 'B'){
            cnt++;
        }else{
            ans += cnt;
        }
    }
    cout << ans;
}



Measured memory_bytes: 640
#include<stdio.h>
int main()
{
  char S[12],T[12],U[12];
  int A,B;
  scanf("%s %s",&S,&T);
  scanf("%d %d",&A,&B);
  scanf("%s",&U);
  
  if(!strcmp(S,U)){A-=1;}else{B-=1;}
  printf("%d %d",A,B);
}

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

bool isOk(string s) {
    if(s.size() % 2 == 1) return false;
    rep(i, s.size()/2) {
        if(s.at(i) != s.at(i + s.size()/2)) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    for(int i = 1; i < s.size(); i++) {
        string t = s.substr(0, s.size() - i);
        if(isOk(t)) {
            cout << t.size() << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 2e5+50;
const int inf = 1e9;

int a[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
        a[i] -= i + 1;
    }
    sort(a, a + n);
    ll ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ans += abs(a[i] - a[n/2]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    S_list = []

    s_hash = dict()

    for i in range(N):
        S_list.append(input())

    for s in S_list:
        if s not in s_hash:
            s_hash[s] = 1
        else:
            s_hash[s] += 1
    max_p = 0
    max_p_name = []
    for k, v in s_hash.items():
        if max_p < v:
            max_p_name = []
            max_p = v
        if max_p == v:
            max_p_name.append(k)
    
    for p in sorted(max_p_name):
        print(p)

Measured memory_bytes: 39888
buffer = []
while True:
    x,y = map(int, input().split())
    if x==0 and y==0:
        break
    buffer.append([x,y])
for n in range(len(buffer)):
    for r in range(buffer[n][0]):
        for c in range(buffer[n][1]):
            if (r + c)%2 == 0:
                print('#', end = '')
            else:
                print('.', end = '')
        print('')
    print('')


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

int main(){
 string s;
  cin>>s;
  int n0=count(s.begin(),s.end(),'0');
  int n1=count(s.begin(),s.end(),'1');
  cout<<min(n0,n1)*2;
}

Measured memory_bytes: 512