akhauriyash/Code-Regression huggingface dataset:
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

const static ul NMAX = 100000;
const static ul SEGNMAX = (1 << 17);
const static ul AiMAX = 1000000000;

static ul N;
static ul Ai[NMAX];

template <class T>
T gcd(T a, T b) {
  while (b) {
    T t = a % b;
    a = b;
    b = t;
  }
  return a;
}

/* (identity element, operation) */
template <class T>
using Monoid = pair<T, function<T(T, T)>>;

template <class T, ul K>
class SegmentTree {
  const Monoid<T> monoid;
  const ul N = (1 << K);
  T tree[2 * (1 << K) - 1];

  ui parent(ui i) {
    if (i == 0) {
      return 0;
    }
    return (i - 1) / 2;
  }

  ui child1(ui i) {
    return i * 2 + 1;
  }

  ui child2(ui i) {
    return i * 2 + 2;
  }

  bool is_leaf(ui i) {
    return (N - 1 <= i);
  }

  void propagate_from_leaf(ui i) {
    ui cur = N - 1 + i;
    while (cur != 0) {
      cur = parent(cur);
      auto x1 = tree[child1(cur)];
      auto x2 = tree[child2(cur)];
      tree[cur] = monoid.second(x1, x2);
    }
  }

  T query_impl(ui a, ui b, ui k, ui l, ui r) {
    if (r <= a || b <= l) {
      return 0;
    } else if (a <= l && r <= b) {
      return tree[k];
    } else {
      auto ta = query_impl(a, b, child1(k), l, (l + r) / 2);
      auto tb = query_impl(a, b, child2(k), (l + r) / 2, r);
      return monoid.second(ta, tb);
    }
  }
public:
  /* Initialize Segment Tree with Monoid `_monoid` */
  SegmentTree(const Monoid<T>& _monoid) : monoid(_monoid) {
    FOR0(i, N) {
      tree[i] = monoid.first;
    }
  }

  void update(ui i, T x) {
    tree[N - 1 + i] = x;
    propagate_from_leaf(i);
  }

  // [a, b)
  T query(ui a, ui b) {
    return query_impl(a, b, 0, 0, N);
  }
};

void solve(void) {
  Monoid<ul> monoid = make_pair(0ULL, gcd<ul>);
  SegmentTree<ul, 17> tree(monoid);
  FOR0(i, N) {
    tree.update(i, Ai[i]);
  }
  ul res = 0;
  FOR0(i, N) {
    ul t = 0;
    if (0 != i) {
      t = tree.query(0, i);
    }
    if (i + 1 != N) {
      t = gcd(t, tree.query(i + 1, N));
    }
    // cout << t << endl;
    // cout << segtree_query(0, i) << ", " << segtree_query(i + 1, N) << endl;
    if (res < t) {
      res = t;
    }
  }
  cout << res << endl;
}

int main(void) {
  cin >> N;
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 2816
money_num, money_sum = gets.chomp.split(' ').map(&:to_i)
itiman_ans = -1
gosen_ans = -1
sen_ans = -1
for itiman in 0..money_num do
  for gosen in 0..(money_num - itiman) do
    sen = money_num - itiman - gosen
    total = itiman*10000 + gosen*5000 + sen*1000
    if total == money_sum then
      itiman_ans, gosen_ans, sen_ans = [itiman, gosen, sen]
    end
  end
end
puts "#{itiman_ans} #{gosen_ans} #{sen_ans}"

Measured memory_bytes: 1788
// D - Ki
#include <bits/stdc++.h>

using namespace std;

void dfs(const vector<vector<int> > &g, int u, int parent, vector<long long> &v, long long x)
{
	v[u] += x;
	for (int i = 0; i < g[u].size(); i++)
		if (g[u][i] != parent)
			dfs(g, g[u][i], u, v, v[u]);
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<vector<int> > g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vector<long long> v(n);

	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		v[p - 1] += x;
	}

	dfs(g, 0, -1, v, 0);

	for (int i = 0; i < n; i++) cout << (i ? " " : "") << v[i];
	cout << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    rep(i,n){
        int a;
        cin >> a;
        m[a]++;
    }
    int t = 0;
    for(auto x: m) t += x.second -1;
    if(t % 2) cout << n - t - 1 << endl;
    else cout << n - t << endl;
    return 0;
}

Measured memory_bytes: 4992
H, W = map(int, input().split())
S = [input() for i in range(H)]

h = []
v = []
for i in range(H):
    a = 0
    h.append([])
    v.append([])
    for j in range(W):
        if S[i][j] == '#':
            a = 0
        else:
            a += 1
        h[i].append(a)
    for j in range(W - 1, -1, -1):
        if S[i][j] == '#':
            a = 0
        else:
            if a == 0:
                a = h[i][j]
            h[i][j] = a

for i in range(W):
    a = 0
    for j in range(H):
        if S[j][i] == '#':
            a = 0
        else:
            a += 1
        v[j].append(a)
    for j in range(H - 1, -1, -1):
        if S[j][i] == '#':
            a = 0
        else:
            if a == 0:
                a = v[j][i]
            v[j][i] = a

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, h[i][j] + v[i][j])
print(ans - 1)


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

using namespace std;
int main(){
    string S;
    long Q;
    cin>>S;
    cin>>Q;
    
    bool swap=false;
    string forward="",back="";
    for(int i=0;i<Q;i++){
        int T;
        cin>>T;
        if(T==1){
            if(swap) swap=false;
            else swap=true;
        }
        else{
            int F;
            cin>>F;
            char C;
            cin>>C;
            if((F==1&&!swap) || (F==2&&swap)) forward+=C;
            else back+=C;
        }
    }
    if(!swap) {
        reverse(forward.begin(),forward.end());
        cout <<forward+S+back<<endl;
    }
    else{
        reverse(S.begin(),S.end());
        reverse(back.begin(),back.end());
        cout<<back+S+forward<<endl;
    }
    
    return 0;
}



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

const long long MOD = 1000000007;

struct fenwick_tree {
    typedef int T;
    T n;
    vector<T> bit;

    // 各要素の初期値は 0
    fenwick_tree(T num) : bit(num+1, 0) { n = num; }

    // a_i += w
    void add(T i, T w) {
        for (T x = i; x <= n; x += x & -x) {
            bit[x] += w;
        }
    }
    // [1, i] の和を計算.
    T sum(T i) {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
    // [left+1, right] の和を計算.
    T sum(T left, T right) {
        return sum(right) - sum(left);
    }
};

void solve(long long N, long long K, std::vector<long long> A){
    fenwick_tree f_tree(5000);
    long long res = 0;
    for (int j = 0; j < N; j++) {
        res += j - f_tree.sum(A[j]);
        res %= MOD;
        f_tree.add(A[j], 1);
    }
    res *= K;
    res %= MOD;
    long long tmp = (K * (K-1) / 2)%MOD;
    for (int j = 0; j < N; j++) {
        res += tmp * (N - f_tree.sum(A[j]));
        res %= MOD;
    }
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 256
s = input().split()
n=int(s[0])
m=int(s[1])
acc=0
penalty={}
ans={}
pen=0
for i in range(n+1):
    penalty[str(i)]=0
    ans[str(i)]=0
for i in range(m):
    s = input().split()
    if s[1]=='AC':
        ans[s[0]]=1
    if ans[s[0]]==0 and s[1]=='WA':
        penalty[s[0]]+=1
for p in penalty:
    if ans[p]==1:
        pen+=penalty[p]
print(list(ans.values()).count(1),pen)

Measured memory_bytes: 28436
using System;
using System.Collections.Generic;
using System.Linq;

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var i=cin();
			int count=0;
			while(i>>count!=0)count++;
			print(1<<(count-1));
		}
	}
}

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

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

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

int main(){
	long long int a[3],m[3],xyz[3];
	long long int n[3];
	while(true){
		for(int i=0; i<3; ++i){
			cin >> a[i] >> m[i];
		}
		if(a[0]==0) break;
		for(int i=0; i<3; ++i){
			xyz[i]=1;
			n[i]=0;
			do{
				xyz[i]=(xyz[i]*a[i])%m[i];
				++n[i];
			}while(xyz[i]!=1);
		}
		long long int ans=LCM(LCM(n[0],n[1]),n[2]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int n;
ll J[100010],I[100010];
ll JO[100010],OI[100010];
int main(){
  cin>>n;string s;cin>>s;
  s='x'+s;
  ll cnt=0;
  J[0]=0,JO[0]=0;
  for(int i=1;i<=n;i++){
    J[i]=J[i-1]+(s[i]=='J');
    if(s[i]=='O')cnt+=J[i-1];
    JO[i]=cnt;
  }
  cnt=0;
  I[n+1]=0,OI[n+1]=0;
  for(int i=n;i>=1;i--){
    I[i]=I[i+1]+(s[i]=='I');
    if(s[i]=='O')cnt+=I[i+1];
    OI[i]=cnt;
  }
  cnt=0;
  for(int i=0;i<=n;i++){
    cnt=max(cnt,OI[i+1]);
    cnt=max(cnt,J[i]*I[i+1]);
    cnt=max(cnt,JO[i]);
  }
  for(int i=1;i<=n;i++){
    if(s[i]=='O')cnt+=J[i-1]*I[i+1];
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 6440
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll dp[101][2][101];

string ns;
int k;

ll rec(int i, bool less_than_n, int non_zero_cnt) {
  if(dp[i][less_than_n][non_zero_cnt]!=-1) {
    return dp[i][less_than_n][non_zero_cnt];
  }
  if(i==ns.size()) {
    if(non_zero_cnt==k) {
      return 1;
    } else {
      return 0;
    }
  }
  int hd = (int)(ns[i]-'0');
  ll ret = 0;
  // zero
  if(less_than_n) {
    ret += rec(i+1,true,non_zero_cnt);
  } else {
    if(0<hd)
      ret += rec(i+1,true,non_zero_cnt);
    else
      ret += rec(i+1,false,non_zero_cnt);
  }
  // nonzero
  if(less_than_n) {
    repeat(j,1,10) {
      ret += rec(i+1,true,non_zero_cnt+1);
    }
  } else {
    repeat(j,1,hd+1) {
      if(j<hd) {
	ret += rec(i+1,true,non_zero_cnt+1);
      } else {
	ret += rec(i+1,false,non_zero_cnt+1);
      }
    }
  }

  return dp[i][less_than_n][non_zero_cnt] = ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  memset(&dp,-1,sizeof(dp));
  cin>>ns>>k;
  cout << rec(0,false, 0) << endl;
  return 0;
}


Measured memory_bytes: 512
from collections import Counter
mod = 10**9+7
n = int(input())
A = list(map(int,input().split()))
dic = dict(Counter(A))
for k,v in dic.items():
    if n%2==0:
        if v!=2 or k==0:
            print(0)
            break
    else:
        if k!=0 and v!=2:
            print(0)
            break
        elif k==0 and v!=1:
            print(0)
            break
else:
    if n%2==0:
        print(2**len(dic)%mod)
    else:
        print(2**(len(dic)-1)%mod)

Measured memory_bytes: 16352
#include <stdio.h>

char isprime[100000];
int pr[100000];
int primenum;

void mpl(void) {
	int i,j;
	for(i=0;i<100000;i++)isprime[i]=1;
	isprime[0]=isprime[1]=0;
	primenum=0;
	for(i=2;i<100000;i++) {
		if(isprime[i]) {
			pr[primenum++]=i;
			for(j=i+i;j<100000;j+=i)isprime[j]=0;
		}
	}
}

int main(void) {
	int m,a,b;
	mpl();
	while(scanf("%d%d%d",&m,&a,&b)==3 && (m|a|b)!=0) {
		int i;
		int p=0,q=0;
		for(i=0;i<primenum;i++) {
			int l=i,r=primenum-1;
			while(l<=r) {
				int j=(l+r)/2;
				if((long long)pr[i]*pr[j]<=m &&
				(long long)a*pr[j]<=(long long)pr[i]*b) {
					l=j+1;
				} else {
					r=j-1;
				}
			}
			if(l>i && (long long)pr[i]*pr[l-1]<=m &&
			(long long)a*pr[l-1]<=(long long)pr[i]*b && pr[i]*pr[l-1]>p*q) {
				p=pr[i];
				q=pr[l-1];
			}
		}
		printf("%d %d\n",p,q);
	}
	return 0;
}

Measured memory_bytes: 736
import sys

n, w = map(int, sys.stdin.readline().split())
weight = []
value = []
sum_value = 0
for i in range(n):
    wi, vi = map(int, sys.stdin.readline().split())
    weight.append(wi)
    value.append(vi)
    sum_value += vi

#val = [0] * (sum_value + 1)
wght = [1<<64] * (sum_value + 1)
wght[0] = 0
for i in range(n):
    for j in range(sum_value - value[i], -1, -1):
        wght[j + value[i]] = min(wght[j + value[i]], wght[j] + weight[i])
            #val[j + value[i]] = max(val[j + value[i]], val[j] + value[i])
            #wght[j + value[i]] = wght[j] + weight[i]


max_val = 0

for i in range(sum_value, -1, -1):
    if wght[i] <= w:
        #max_val = max(max_val, val[i])
        max_val = max(max_val, i)

print(max_val)


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

using namespace std;
using ll = long long;


int main()
{
    ll n, m, d;
    cin >> n >> m >> d;
    long double unit = 0;
    unit += (n - d) * 2;
    if(d == 0)unit = n;
    unit /= n * n;
    cout << fixed <<setprecision(12) << unit * (m - 1) << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
int cmp(const void *a, const void *b){return *(int *)a - *(int *)b;}

int n, q, a[100100], b, c;
ll d[100100] = {}, sum = 0;
int main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", a+i);
        sum += a[i];
        d[a[i]]++;
    }
    scanf("%d", &q);
    while(q--){
        scanf("%d%d", &b, &c);
        ll tmp = d[b]; d[b] = 0;
        sum -= b * tmp;
        sum += c * tmp;
        d[c] += tmp;
        printf("%lld\n", sum);
    }
    return 0;
}

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

bool isLand[12][12];

bool deleteOneLand(int x, int y)
{
  if (!isLand[y][x]) return false;
  isLand[y][x] = false;
  if (x > 0) deleteOneLand(x - 1, y);
  if (y > 0) deleteOneLand(x, y - 1);
  if (x < 11) deleteOneLand(x + 1, y);
  if (y < 11) deleteOneLand(x, y + 1);
  return true;
}

int main()
{
  int x, y, ans;
  while (!cin.eof())
  {
    ans = 0;
    for (y = 0; y < 12; y++)
    {
      for (x = 0; x < 12; x++)
	isLand[y][x] = getchar() == '1';
      getchar();
    }
    for (y = 0; y < 12; y++)
      for (x = 0; x < 12; x++)
	if (deleteOneLand(x, y)) ans++;
    cout << ans << endl;
    if (getchar() != '\n') break;
  }
  return 0;
}

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

using namespace std;

int main() {
	int N;
	long long heights;
	long long max = -1;
	long long sum=0;

	scanf("%d", &N);
	for (int _ = 0; _ < N; _++) {
		scanf("%lld", &heights);
		if (heights >= max || max==-1) {
			max = heights;
			sum++;
		}
	}

	printf("%lld", sum);
}

Measured memory_bytes: 256
//
// Created by yuu on 2019-04-26.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>

using namespace std;


int main(void){
    int N,M;
    string A[60];
    string B[60];

    cin>>N>>M;

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

    for (int i = 0; i < M; ++i) {
        cin>>B[i];
    }
    bool flag=false;
    for(int i=0; i<=N-M; i++){
        for (int k = 0; k <= N-M; ++k) {
            if(A[i].substr(k,M) == B[0]){
                flag = true;
                for (int j = 0; j < M; ++j) {
                    if(A[i+j].substr(k,M) != B[j]){
                        flag = false;
                        break;
                    }
                }
            }
            if(flag){
                break;
            }
        }

        if(flag){
            break;
        }
    }



    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define N 120

int main(){
    long long x;
    cin >>x;
    for(int b = -N;b<N;b++){
        for(int a = -N;a<N;a++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                cout <<a << " " << b << endl;
                return 0;
            }
        }
    }
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d) {
        cout << "Yes" << endl;
    }
    else if(abs(a-b) <= d && abs(b-c) <= d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i],a[i]--;

    ll res=0;
    int cnt=0;
    ll sum=0;
    for(int i=0;i+1<n;i++){
        if(a[i]>a[i+1]){
            res+=m-(a[i]-a[i+1]);
            cnt++;
            sum+=m-a[i];
        }
        else res+=a[i+1]-a[i];
    }

    vector<vector<int>> vec(m);
    for(int i=0;i<n;i++) vec[a[i]].push_back(i);
    ll sub=0;
    for(int i=0;i<m;i++){
        sub=max(sub,sum-cnt);
        for(auto e:vec[i]){
            if(e==0){
                cnt++;
            }
            else{
                if(e==n-1) cnt--;
                if(a[e-1]<a[e]) sum-=a[e]-a[e-1];
                else sum-=m-(a[e-1]-a[e]);
            }
        }
        sum+=cnt;
    }
    res-=sub;
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}









int main() {
  int Q;
  cin>>Q;
  int l[Q];
  int r[Q];
  for(int i=0;i<Q;i++){
      cin>>l[i]>>r[i];
  }
  int sosu[100001];
  for(int i=0;i<100001;i++){
      sosu[i]=0;
  }
  for(int i=1;i<=100001;i++){
      
      if(IsPrime(i)&&IsPrime((i+1)/2)){
          sosu[i]=1;
      }
  }
  for(int i=1;i<=100001;i++){
      sosu[i]=sosu[i-1]+sosu[i];

  }
  for(int i=0;i<Q;i++){
      if(sosu[l[i]]-sosu[l[i]-1]==1){
          cout<<sosu[r[i]]-sosu[l[i]]+1<<endl;
          continue;
      }
      else{
      cout<<sosu[r[i]]-sosu[l[i]]<<endl;

      }
      
  }

  

  





  

  


  

    


  

  
  
  
  
}


  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    ll s;
    cin >> s;
    if (s == 1e18) {
        printf("%d %d %d %d %d %d", int(1e9), int(1e9), 0, 0, int(1e9), 0);
        exit(0);
    }
    ll p = s / 1e9;
    ll q = s % int(1e9);
    printf("%d %d %d %d %d %d", int(1e9), 0, q, p+1, 0, 1);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int n,m,k;
int main(){
	fast
	cin>>n>>m>>k;
	int sx,sy,ex,ey;
	cin>>sx>>sy>>ex>>ey;
	pii came[n][m];
	sx--;sy--;ex--;ey--;
	char a[n][m];
	FOR0(n){
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	int vis[n][m];
	mem(vis,-1);
	queue<pair<int,int> >q;
	vis[sx][sy]=0;
	q.push({sx,sy});
	mem(came,-1);
	came[sx][sy]={-1,-1};
	while(!q.empty()){
		pii f=q.front();
		q.pop();
		int x=f.ff,y=f.ss;
		for(int i=1;i<=k;i++){
			int yy=y+i;
			if(yy>=m) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int yy=y-i;
			if(yy<0) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x+i;
			if(xx>=n) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x-i;
			if(xx<0) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
	}
	cout<<vis[ex][ey];
}



Measured memory_bytes: 17204
#define _CRT_SECURE_NO_WARNINGS
////#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int n,ans=0;
	int a, b;

	for (; ~fscanf(stdin, "%d%d%d", &a, &b, &n); P(d, ans), ans = 0)
		while (n--)
			a %= b,
			a *= 10,
			ans += a / b;
	return 0;
}

Measured memory_bytes: 600
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int A,B,H;

signed main(){

    in(A,B,H);
    out((A+B)*H/2);

    return 0;
}


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

bitset<2000> dpl[2000],dpr[2000],g[2000];
string s;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>s;
		for(int j=0;j<i;j++){
			g[i][j]=s[j]-'0';
			g[j][i]=g[i][j]^1;
		}
	}
	for(int i=0;i<n;i++)
		dpl[i][i]=dpr[i][i]=true;
	for(int len=2;len<=n;len++){
		for(int l=0;l+len-1<n;l++){
			int r=l+len-1;
			if((g[l]&dpl[r]&dpr[l+1]).any())	dpl[r][l]=true;
			if((g[r]&dpl[r-1]&dpr[l]).any())	dpr[l][r]=true;
		}
	}
	cout<<(dpl[n-1]&dpr[0]).count()<<endl;
	
}



Measured memory_bytes: 1792
///a = 97  z = 122
///A = 65  Z = 90

#include <bits/stdtr1c++.h>
//#include <boost/algorithm/string.hpp>

using namespace std;

#define endl                "\n"
#define pb                  push_back
#define pii                 pair<int, int>
#define mp                  make_pair
#define x                   first
#define y                   second
#define all(v)			    ((v).begin()), ((v).end())
#define sz(v)			    ((int)((v).size()))
#define ll                  long long
#define rep(i,n)            for(int i=0 ; i<sz(n) ; i++)
#define lp(i, n)            for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define ms(arr, v)      memset(arr, v, sizeof arr)
typedef vector<vector<char>> vcc;
typedef vector<int> vi;
typedef deque<int> de;

int n;
int ctr, maxCtr;
multimap<string, int> words;
vector<string> vec;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif*/
    cin >> n;
    while(n--)
    {
        string str;
        cin >> str;
        words.insert(mp(str, 1));
    }
    maxCtr = -1;
    int i; string str = words.begin()->first;
    for(auto it : words)
    {
        if(it.first == str)
        {
            ctr++;
        }
        else
        {
            if(ctr > maxCtr)
            {
                vec.clear();
                vec.pb(str);
                maxCtr = ctr;
            }
            else if(ctr == maxCtr)
            {
                vec.pb(str);
            }
            ctr = 1;
            str = it.first;
        }
    }
    if(ctr > maxCtr)
    {
        vec.clear();
        vec.pb(str);
    }
    else if(ctr == maxCtr)
    {
        vec.pb(str);
    }
    for(auto s : vec) cout << s << endl;
    return 0;
}

Measured memory_bytes: 25584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int m = Integer.parseInt(scanner.next());
        System.out.println(cmb(n)+cmb(m));
    }
    
    public static int cmb(int a) {
        if (a < 1){
            return 0;
        }
        return a*(a-1)/2;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <list>
#include <cstring>

//#define USE_SET

int main(void) {
  int K;

  std::string str;

  std::string s_;
  std::cin >> s_;
  const char* s = s_.c_str();

  std::cin >> str;
  K = std::stoi(str);

  size_t lsize = 0;
  size_t len = s_.length();

#if defined(USE_SET)
  typedef struct s_set {
    int pos;
    int len;

    s_set(int i, int j) : pos(i), len(j) {
    }
  } set;
#endif

#if defined(USE_SET)
  std::list<set> wlist;
  wlist.push_back(set(0, 1));
#else
  std::list<std::string> wlist;
  wlist.push_back(s_.substr(0, 1));
#endif

  for (int a = 'a'; a <= 'z' && lsize < K; ++a) {        /* a to z   */
    for (int b = 'a'; b <= 'z' && lsize < K; ++b) {      /* a to z   */
      for (int i = 0; i < len; ++i) {                    /* 0 to len */
        if (s[i] == a && (i+1 >= len || s[i+1] == b)) {
          for (int j = 1; j <= len - i && j <= K; ++j) {           /* length 1 to len - i */
            for (auto itr = wlist.begin(); itr != wlist.end(); ++itr) {
#if defined(USE_SET)
              int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
#else
              int cmp = s_.compare(i, j, *itr);
#endif
              if (cmp == 0) {
                break;
              }
              if (cmp < 0) {
#if defined(USE_SET)
                wlist.insert(itr, set(i, j));
#else
                wlist.insert(itr, s_.substr(i, j));
#endif
                lsize++;
                break;
              }
#if defined(USE_SET)
              if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
                wlist.push_back(set(i, j));
#else
              if (cmp > 0 && itr->c_str() == wlist.rbegin()->c_str()) {
                wlist.push_back(s_.substr(i, j));
#endif
                lsize++;
                break;
              }
            }
          }
        }
      }
    }
  }

  size_t idx = 0;
  for (auto &str : wlist) {
    idx++;
    if (idx == K) {
#if defined(USE_SET)
      //std::cout << str.pos << "," << str.len << std::endl;
      std::cout << s_.substr(str.pos, str.len) << std::endl;
#else
      std::cout << str << std::endl;
#endif
    }
  }

  return 0;
}

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

#define REP(i,n) for(ll i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> p(M), pena(N, 0);
  vector<string> S(M);
  vector<bool> ACs(N, false);
  int AC = 0, Cpena = 0;
  REP(i, M){
    cin >> p[i] >> S[i];
    p[i]--;
    if(S[i] == "AC" && ACs[p[i]] == false){
      AC++;
      Cpena += pena[p[i]];
      ACs[p[i]] = true;
    }
    else{
      pena[p[i]]++;
    }
  }
  cout << AC << " " << Cpena << endl;
  return 0;
}


Measured memory_bytes: 6528
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,x = get_nums_l()
nums = get_nums_l()

now = 0
ans = 1
for n in nums:
    now += n
    if now <= x:
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 38484
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

K, X = two_int()

print()
if K*500 >= X:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#pragma comment(linker, "/STACK:336777216")  

using namespace std;

const int MAXN = 100 + 10;

int H, W;
char A[MAXN][MAXN];
int cnt[1000];
int used[MAXN][MAXN];

bool chk()
{
	for (int i = 0; i < H; i ++)
		for (int j = 0; j < W; j ++)
			cnt[A[i][j]] ++;
	int ccc[5] = {0, 0, 0, 0, 0};
	for (int i = 0; i < H; i ++)
		for (int j = 0; j < W; j ++)
			if (! used[i][j])
			{
				int ii, jj;
				int cc = 0;
				ii = i; jj = j; cc += (used[ii][jj] == 0); used[ii][jj] = 1;
				ii = H - 1 - i; jj = j; cc += (used[ii][jj] == 0); used[ii][jj] = 1;
				ii = i; jj = W - 1 - j; cc += (used[ii][jj] == 0); used[ii][jj] = 1;
				ii = H - 1 - i; jj = W - 1 - j; cc += (used[ii][jj] == 0); used[ii][jj] = 1;
				ccc[cc] ++;
			}
	for (int i = 4; i >= 0; i --)
		while (ccc[i] --)
		{
			int ok = 0;
			for (char c = 'z'; c >= 'a'; c --)
				if (cnt[c] >= i)
				{
					cnt[c] -= i;
					ok = 1;
					break;
				}
			if (ok == 0)
				return 0;
		}
	return 1;
}

void Work()
{
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i ++)
		scanf("%s", A[i]);
	printf(chk() ? "Yes\n" : "No\n");
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int,input().split())
G = [[] for i in range(N+ 1)]
ANS = [0] * (N + 1)
for _ in range(N - 1):
    a , b = map(int,input().split())
    G[a].append(b)
for _ in range(Q):
    p, x =map(int,input().split())
    ANS[p] += x
from collections import deque
que=deque([])
que.append(1)
while que:
    node = que.pop()
    ans = ANS[node]
    for child in G[node]:
        ANS[child] += ans
        que.append(child)
for i in range(1, N + 1):
    print(ANS[i])


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

using namespace std;

const int NMAX = 111;
const int INF = 0x3f3f3f3f;

vector< vector < pair <int, int> > > g(NMAX, vector< pair<int, int> >()); // g[u][i] -> (pair{weight(u, v); v})
int dist[NMAX]; // init: dist[i] = INF
int parent[NMAX];
int edge[NMAX][NMAX];

void dijkstra(int source) {
  dist[source] = 0;
  parent[source] = -1;
  set<pair<int, int>> q;
  q.insert({dist[source], source});
  while (!q.empty()) {
    int u = q.begin()->second, du = q.begin()->first;
    q.erase(q.begin());
    if (dist[u] < du) continue;
    for (pair<int, int>& e : g[u]) {
      int v = e.second, w = e.first;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        parent[v] = u;
        q.insert({dist[v], v});
      }
    }
  }
}

int N, M, ans = 0;

int main() {
  cin >> N >> M;
  for (int i = 0; i < NMAX; i++) {
    for (int j = 0; j < NMAX; j++) {
      edge[i][j] = INF;
    }
  }
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back({c, b});
    g[b].push_back({c, a});
    edge[a][b] = edge[b][a] = 0;
  }
  for (int i = 1; i <= N; i++) {
    memset(dist, INF, sizeof(dist));
    memset(parent, -1, sizeof(parent));
    dijkstra(i);
    for (int j = 1; j <= N; j++) {
      if (i == j) continue;
      int u = j;
      while (parent[u] != -1) {
        edge[parent[u]][u]++;
        edge[u][parent[u]]++;
        u = parent[u];
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (edge[i][j] == 0) {
        ans++;
      }
    }
  }
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 384
def kaibun(s):
    ns=len(s)
    f=True
    for i in range(ns//2):
        if s[i]!=s[ns-i-1]:
            f = False
    return f

s=input()
n=len(s)
if kaibun(s) and kaibun(s[:(n-1)//2]) and kaibun(s[(n+1)//2:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k){
		cout<<k<<endl;
	}
	else if(a+b>=k){
		cout<<a<<endl;
	}
	else{
		cout<<a-(k-a-b)<<endl;
	}
	return 0;
}

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

int main() {
	int n; cin >> n;
	map<int,int> d;
	for(int i=0;i<n;++i){
		int a; cin >> a;
		d[a]++;
	}
	
	int m; cin >> m;
	for(int i=0;i<m;++i){
		int t; cin >> t;
		if(d[t] > 0){
			d[t]--;
		}else{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	
	return 0;
}

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

#define int long long

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

  int N;
  cin >> N;

  string A, B, C;
  cin >> A >> B >> C;

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    set<char> all;
    all.insert(A[i]);
    all.insert(B[i]);
    all.insert(C[i]);
    if ( all.size() == 3 ) ans += 2;
    if ( all.size() == 2 ) ans += 1;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int early[200005], late[200005];
char s[200005];
int the_i;
int main()
{
	int n, k, c;
	scanf("%d %d %d", &n, &k, &c);
	scanf("%s", s);
	int size = strlen(s);
	the_i = 1;
	for(int i = 0; i < size;)
	{
		if(s[i] == 'o')
		{
			early[i] = the_i++;
			i += c + 1;
		}
		else
			i++;
		if(the_i > k)
			break;
	}
	the_i = k;
	for(int i = size - 1; i >= 0;)
	{
		if(s[i] == 'o')
		{
			late[i] = the_i--;
			i -= c + 1;
		}
		else
			i--;
		if(the_i < 1)
			break;
	}	
	for(int i = 0; i < size; i++)
	{
		if(early[i] && early[i] == late[i])
			printf("%d\n", i + 1);
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N, M;
  cin >> N >> M;
  
  map<int64_t, int64_t> hight;
  for (int64_t i = 0; i < N; i++) {
    int64_t x;
    cin >> x;
    hight[i+1] = x;
  }
  
  map<int64_t, int64_t> check = hight;
  
  map<int64_t, vector<int64_t>> way;
  
  for (int j = 0; j < M; j++) {
    int64_t a, b;
    cin >> a >> b;
    
    way[a].push_back(b);
    way[b].push_back(a);
  }
  
  for (auto p : way) {
    auto key = p.first;
    auto value = p.second;
    int64_t links = value.size();
    
    for (int64_t k = 0; k < links; k++) {
      if ( hight.at(key) <= hight.at(value.at(k)) ) {
        check.erase(key);
      }
    }
    
  }
  
  cout << check.size() << endl;
  
}

Measured memory_bytes: 26392
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = [int(input()) for _ in range(N)]

B = sorted(A)

for i in range(N):
    print(B[-1] if A[i] != B[-1] else B[-2])

Measured memory_bytes: 14088
n = int(input())

l = list(map(int,input().split()))

for i in range(n)[::-1]:
    if i == n-1:
        continue
    if l[i]>l[i+1]+1:
        print("No")
        exit(0)
    elif l[i]<=l[i+1]:
        continue
    else:
        l[i]-=1
print("Yes")


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

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	if(abs(a-b)%2 == 0){
		cout << "Alice\n";
	}
	else{
		cout <<"Borys\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<pair<int,int>>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i).first;
    A.at(i).second=i+1;
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    cout<<A.at(i).second<<" ";
  }
}
    

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans=0,n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    ans+=(s=="E869120");
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3228
let () =
  let n, s, t = Scanf.scanf "%d\n%s %s\n" @@ fun a b c -> a, b, c in
  let ans = Array.make (n*2) 'x' in
  for i = 0 to n-1 do
    ans.(2*i) <- s.[i]; ans.(2*i+1) <- t.[i];
  done;
  print_endline (Array.fold_left (fun s a -> s ^ Char.escaped a) "" ans)

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



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

int main(void) {
    int h,w;
    char s[52][52]={"."};
    bool result=true;

    cin >> h >> w;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> s[i][j];
            //scanf("%c", s[i][j]);
        }
    }

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(s[i][j] == '#'){
                if(s[i-1][j]=='#' || s[i][j-1]=='#' || s[i][j+1]=='#' || s[i+1][j]=='#'){
                    continue;
                }else{
                    result = false;
                    break;
                }
            }
        }
        if(result == false) break;
    }

    if(result == true) cout << "Yes"; else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int i,j,a[300],b[300],c[300],len;
	string str1,str2;
	cin>>str1>>str2;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(b));
	if(str2[0]=='0'&&str2[2]=='0'&&str2[3]=='0')
	cout<<"0"<<endl;
	else{
		a[0]=str1.length();
		for(i=1;i<=a[0];i++)
		a[i]=str1[a[0]-i]-'0';
		
		if(str2[0]!='0'&&str2[2]=='0'&&str2[3]!='0'){
			b[1]=str2[3]-'0';
			b[2]=str2[2]-'0';
			b[3]=str2[0]-'0';
			b[0]=3;
		}
		else{
			b[0]=0;j=1;
			for(i=1;i<=2;i++){
				
				if(str2[4-i]-'0'!=0){
					b[j]=str2[4-i]-'0';
					b[0]++;
					j++;
				}
			}
			if(str2[0]!='0'){
				b[j]=str2[0]-'0';
				b[0]++;
			}
		}
		for(i=1;i<=a[0];i++){
			for(j=1;j<=b[0];j++){
				c[i+j-1]=c[i+j-1]+a[i]*b[j];
				c[i+j]=c[i+j]+c[i+j-1]/10;
				c[i+j-1]=c[i+j-1]%10;
			}
		}
		len=a[0]+b[0]+1;
		while((c[len]==0)&&len>1)
		len--;
		if(len<=2)
		cout<<"0"<<endl;
		else{
			if(b[0]==2&&str2[0]-'0'!=0){
			for(i=len;i>=2;i--)
			cout<<c[i];
			cout<<endl;
		}
		else if(b[0]==2&&str2[0]-'0'==0){
			for(i=len;i>=3;i--)
			cout<<c[i];
			cout<<endl;
		}
		else if(b[0]==3){
			for(i=len;i>=3;i--)
			cout<<c[i];
			cout<<endl;
		}
		else if(b[0]==1&&str2[3]-'0'!=0){
			for(i=len;i>=3;i--)
			cout<<c[i];
			cout<<endl;
		}
		else if(b[0]==1&&str2[2]-'0'!=0){
			for(i=len;i>=2;i--)
			cout<<c[i];
			cout<<endl;
		}else if(b[0]==1&&str2[0]-'0'!=0){
			for(i=len;i>=1;i--)
			cout<<c[i];
			cout<<endl;
		}
		}
		
	}

}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int f[100010],h[100010];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	   cin>>h[i];
	f[1]=0;
	f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
		f[i]=f[i-1]+abs(h[i]-h[i-1]);
		for(int j=1;j<=k;j++){
			if(i-j>=1)
			   f[i]=min(f[i],f[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
//ITP1-9-B: Shuffle
//2019.05.20

#include <stdio.h>
#include <string.h>

int main(void){
  char deck[201];
  char deck_copy[201];
  int num;
  int i, m, h;
  int sum;

  while (1) {
    scanf("%s\n", deck);
    strcpy(deck_copy, deck);
    if (strcmp(deck, "-") == 0) break;
    num = strlen(deck);
    scanf("%d\n", &m);
    
    sum = 0;
    for (i = 0; i < m; i++) {
      scanf("%d\n", &h);
      sum = sum + h;
    }

    h = sum % num;
    
    int j = 0;
    for (i = 0; i < num; i++) {
      if (i < num-h) {
        deck[i] = deck[i+h];
      }else{
        deck[i] = deck_copy[j];
        j++;
      }
    }
    deck[num] = '\0';
    printf("%s\n", deck);
  }
  return 0;
}



Measured memory_bytes: 2036