akhauriyash/Code-Regression huggingface dataset:
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

// sum[p] = xs[0..p] の中から値の大きい(小さい)順の N 個の総和
long[] calcBestN(int[] xs, bool function(long, long) cmp) {
    assert(xs.length % 3 == 0);

    auto sum = new long[xs.length];
    auto q = new BinaryHeap!(Array!long, cmp);
    long s = 0;
    int N = cast(int)xs.length / 3;
    for (int i = 0; i < xs.length; i++) {
        q.insert(xs[i]);
        s += xs[i];
        if (q.length > N) {
            s -= q.front;
            q.removeFront();
        }
        sum[i] = s;
    }
    return sum;
}

long calc(int[] xs) {
    auto lsum = calcBestN(xs, (a, b) => a > b);

    auto ys = xs.dup;
    ys.reverse();
    auto rsum = calcBestN(ys, (a, b) => a < b);
    rsum.reverse();

    long ans = long.min;
    int N = cast(int)xs.length / 3;
    for (int i = N-1; i < 2 * N; i++) {
        // i までが左側に属する。i+1 以降は右側
        long diff = lsum[i] - rsum[i + 1];
        ans = max(ans, diff);
    }
    return ans;
}

void main() {
    readint;
    auto xs = readints;
    auto ans = calc(xs);
    writeln(ans);
}


Measured memory_bytes: 20404
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int main()
{
    fastIO
    
    int n, m;
    cin >> n >> m;
    
    vi height(n + 1);
    vector < vi > arr(n + 1);
    
    for(int i = 1; i <= n; ++i)
        cin >> height[i];
    
    for(int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        
        arr[u].pb(v);
        arr[v].pb(u);
    }
    
    vi good(n + 1, 1);
    
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j < arr[i].size(); ++j)
        {
            int v = arr[i][j];
            if(height[v] >= height[i])
            {
                good[i] = 0;
                break;
            }
        }
    }
    
    int total = 0;
    for(int i = 1; i <= n; ++i)
        if(good[i])
            ++total;
            
    cout << total;

    return 0;
}



Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1e9

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;

int main(void){
  int N;cin>>N;
  bool jud = false;
  rep(k ,26){
    rep(t , 15){
      if(N == 4 * k + 7 *t)jud = true;
    }
  }
  cout<<(jud?"Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
    init();
    solve();
}

int N;
vector<bool> v;

void init()
{
	cin >> N;
	string s;
	cin >> s;
	rep(i, N) {
		v.PB(s[i] != 'o');
	}
}

void print(vector<bool>& res)
{
	for (auto x : res) {
		if (x) cout << 'W';
		else cout << 'S';
	}
	cout << endl;
}

bool ch(vector<bool>& res, int pos)
{
	int a = pos-1;
	int b = pos+1;
	if (pos == 0) {
		a = N-1;
	}
	if (pos == N-1) {
		b = 0;
	}
	return v[pos] != ((res[a] == res[b]) ^ res[pos]);
}

bool calc(vector<bool>& res)
{
	reps(i, 2, N) {
		res[i] = res[i-2] ^ v[i-1] ^ res[i-1];
	}
	rep(i, N) {
		if (!ch(res, i)) return false;
	}
	return true;
}


void solve()
{
	vector<bool> res(N);
	rep(i, 2) {
		rep(j, 2) {
			res[0] = i == 0;
			res[1] = j == 0;
			if (calc(res)) {
				print(res);
				return;
			}
		}
	}
	cout << -1 << endl;
}



Measured memory_bytes: 512
#include <cstdio>
using namespace std;
int main(){
	int r, g, b,scan;
	scan = scanf ("%d %d %d", &r, &g, &b);
	if ((100 * r + 10 * g + b) % 4 == 0) {
		puts("YES");
	} else {
		puts("NO");
	}
}

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

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

    int a;
    vector<long long> ans(n + 2, -1);
    for(int i = 0;i<m;i++){
        cin >> a;
        ans[a + 1] = 0;
    }
    ans[0] = 0;
    ans[1] = 1;

    int mod = 1000000007;
    for(int i = 2; i < n + 2; i++){
        if(ans[i] == -1){
            ans[i] = ans[i - 1] + ans [i - 2];
            ans[i] %= mod;
        }
    }

    cout << ans[n + 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
s = input()
key = 'keyence'
key_r = 'ecneyek'
j = 0
for i in key:
    if s[j] == i:
        j += 1
    else:
        break
k = 1
for i in key_r:
    if s[-k] == i:
        k += 1
    else:
        break

s = s[:j] + s[-k+1:]
if j + k > 7:
    s = key
if s == key:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];
bool flag[201010];
vector<vector<ll>>to;
ll res;

void dfs(ll x) {
	if (flag[x] == false) {
		res++;
		flag[x] = true;
		for (auto nx : to[x]) {
			if (flag[nx]==false) {
				dfs(nx);
			}
		}
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, m;
	cin >> n >> m;
	to.resize(n);
	rep(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ll ans = 0;
	rep(i, n) {
		res = 0;
		if (flag[i] == false) {
			dfs(i);
		}
		ans = max(res, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int A = scn.nextInt();
		int B = scn.nextInt();

		int min = Math.max(0, A + B - N);
		int max = Math.min(A,B);
		System.out.println(max + " " + min);
	}

}

Measured memory_bytes: 23636
#include <iostream>
using namespace std;
unsigned long long n;
int main()
{
    cin>>n;
    unsigned long long hap = 0;
    while(n>=500)
    {
        n -= 500;
        hap += 1000;
    }
    while (n>=5)
    {
        n -= 5;
        hap += 5;
    }
    cout<<hap<<endl;
}

Measured memory_bytes: 256
import copy

n = int(input())
x = [int(i) for i in input().split()]

x1 = copy.deepcopy(x)

x1.sort()

mae = x1[(n//2)-1]
ato = x1[(n//2)]

for i in range(len(x)):
    if x[i] > mae:
        print(mae)
    else:
        print(ato)
        


Measured memory_bytes: 26052
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        if(x==y){
            out.println(0);
            exit(0);
        }
        if(abs(x)==abs(y)){
            out.println(1);
            exit(0);
        }
        if(x==0){
            if(y<0)out.println(1-y);
            else out.println(y);
        }else if(y==0){
            if(x>0)out.println(1+x);
            else out.println(-x);
        }else if(x>0&&y>0){
            if(x>y)out.println(x-y+2);
            else out.println(y-x);
        }else if(x<0&&y>0){
            out.println(abs(x+y)+1);
        }else if(x<0&&y<0){
            if(x<y)out.println(y-x);
            else out.println(x-y+2);
        }else{
            out.println(abs(x+y)+1);
        }
    }
}

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

char s[105];
char t[105];
string k[10005];
int vis[105];
int sum=0,slen,tlen;

int check(int q)
{
    int tot=1;
    for(int i=q;i<=slen;i++)
    {
        if(s[i]==t[tot]||s[i]=='?') vis[i]=tot;
        else return false;
        tot++;
        if(tot==tlen+1) return true;
    }
}
int main()
{
    cin>>s+1;
    cin>>t+1;
    slen=strlen(s+1);
    tlen=strlen(t+1);
    if(tlen>slen) {cout<<"UNRESTORABLE"<<endl;return 0;}
    else {
        for(int i=1;i<=slen-tlen+1;i++)
        {
            memset(vis,0,sizeof(vis));
            if(check(i)){
                sum++;
                for(int j=1;j<=slen;j++){
                    if(s[j]=='?'&&vis[j]==0){
                        k[sum]+='a';
                    }
                    else if(vis[j]!=0){
                        k[sum]+=t[vis[j]];
                    }
                    else {
                        k[sum]+=s[j];
                    }
                }
            }
        }
        sort(k+1,k+sum+1);
        if(sum==0) cout<<"UNRESTORABLE"<<endl;
        else cout<<k[1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
	
int main() {
	int n;
	cin >> n;
	int a[n], b[n], c[n], d[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> d[i];
	}

	int blue_XtoY[205];
	int red_XtoY[205];

	memset(blue_XtoY, -1, sizeof(blue_XtoY));
	memset(red_XtoY, -1, sizeof(red_XtoY));

	for (int i = 0; i < n; i++) {
		blue_XtoY[c[i]] = d[i];
		red_XtoY[a[i]] = b[i];
	}
	
	int ans = 0;
	set<int> st;
	for (int right = 200; right >= 0; right--) {
		if (red_XtoY[right] != -1) {
			if (st.lower_bound(red_XtoY[right]) != st.end()) {
				ans++;
				st.erase(*st.lower_bound(red_XtoY[right]));
			}
		}
		if (blue_XtoY[right] != -1) {
			st.insert(blue_XtoY[right]);
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {

	int n;
	string A, B;
	int sizA, sizB, max=0;
	int c[1001][1001];
	
	cin >> n;
	
	for (int i = 0;i < n;++i) {
		cin >> A >> B;
		sizA = (int)(A.length());
		sizB = (int)(B.length());

		for (int a = 0;a <= sizA;++a) {
			for (int b = 0;b <= sizB;++b) {
				if (a == 0 || b == 0) {
					c[a][b] = 0;
				}else if(A[a-1]==B[b-1]){
					c[a][b] = c[a-1][b-1]+1;
				}else if(c[a][b-1]>c[a-1][b]){
				    c[a][b] = c[a][b-1];
				}else{
				    c[a][b] = c[a-1][b];
				}



				if (max < c[a][b]) {
					max = c[a][b];
				}
			}
		}
		cout << max << endl;
		max = 0;
	}
	return 0;
}


Measured memory_bytes: 7140
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        int N, M, r, q, temp, time1, answer;
        Record[] records;
        Question[] questions;
        boolean[] check;
        while((N = sc.nextInt()) != 0 | (M = sc.nextInt()) != 0){
            r = sc.nextInt();
            records = new Record[r];
            for(int i = 0; i < r; i++) records[i] = new Record(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
            q = sc.nextInt();
            questions = new Question[q];
            for(int i = 0; i < q; i++) questions[i] = new Question(sc.nextInt(), sc.nextInt(), sc.nextInt());

            for(Question Q : questions){
                check = new boolean[N];
                Arrays.fill(check, false);
                time1 = 0;
                temp = 0;
                answer = 0;
                for(; temp < r && records[temp].time <= Q.from_time; temp++){
                    if(records[temp].ST_ID == Q.ST_ID){
                        if(records[temp].log == 1) check[records[temp].PC_ID - 1] = true;
                        else check[records[temp].PC_ID - 1] = false;
                    }
                }
                if(totalCheck(check)) time1 = Q.from_time;
                for(; temp < r && records[temp].time <= Q.to_time; temp++){
                    if(records[temp].ST_ID == Q.ST_ID){
                        if(records[temp].log == 1) check[records[temp].PC_ID - 1] = true;
                        else check[records[temp].PC_ID - 1] = false;
                        if(totalCheck(check)){
                            if(time1 != 0) continue;
                            else time1 = records[temp].time;
                        }else{
                            answer += records[temp].time - time1;
                            time1 = 0;
                        }
                    }
                }
                if(totalCheck(check)) answer += Q.to_time - time1;
                System.out.println(answer);
            }
        }
    }

    static boolean totalCheck(boolean[] check){
        boolean total_check = false;
        for(boolean b : check) total_check |= b;
        return total_check;
    }


    static class Record{
        int time, PC_ID, ST_ID, log;

        Record(int time, int PC_ID, int ST_ID, int log){
            this.time = time;
            this.PC_ID = PC_ID;
            this.ST_ID = ST_ID;
            this.log = log;
        }
    }

    static class Question{
        int from_time, to_time, ST_ID;

        Question(int from_time, int to_time, int ST_ID){
            this.from_time = from_time;
            this.to_time = to_time;
            this.ST_ID = ST_ID;
        }
    }
}

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

int main(void){
    
    int N, M;
    int max_Point = 0;
    string s, t;
    map<string, int> card;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s;
        card[s]++;
    }
    cin >> M;
    for(int i = 0; i < M; i++){
        cin >> s;
        card[s]--;
    }
    
    for(auto p : card){
        auto value = p.second;
        max_Point = max(max_Point, value);
    }
    
    cout << max_Point << endl;
       
}




Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    n,m,k=list(map(int,input().strip().split()))

    uf = UnionFind(n)

    res=[[] for i in range(n)]
    frd=[[] for i in range(n)]
    blk=[[] for i in range(n)]

    for i in range(m):
        a,b=list(map(int,input().strip().split()))
        a-=1
        b-=1
        uf.Unite(a,b)
        frd[a].append(b)
        frd[b].append(a)
    
    for i in range(k):
        a,b=list(map(int,input().strip().split()))
        a-=1
        b-=1
        #blk[a].append(b)
        #blk[b].append(a)
        frd[a].append(b)
        frd[b].append(a)
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1
        for f in frd[i]:
            if uf.isSameGroup(f,i):
                ri-=1
        rescnt.append(str(ri))
        ##rescnt.append(str(n-uf.size(i)-len(blk[i])))
    
    print(" ".join(rescnt))

resolve()

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4 4 1
2 1
1 3
3 2
3 4
4 1"""
        output = """0 1 0 1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5"""
        output = """0 0 0 0 0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10 9 3
10 1
6 7
8 2
2 5
8 4
7 3
10 9
6 4
5 8
2 6
7 5
3 1"""
        output = """1 3 5 4 3 3 3 3 1 0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  int N;
  cin >> N;
  vector<ll> A(N, 0);
  vector<ll> B(N+1, 0);
  
  rep(i, N){
    cin>>A[i];
    B[A[i]]++;
  }

  ll ans = 0;
  rep(i, N){
    ll tmp = B[i+1];
    ans += (tmp * (tmp-1)) / 2;
  }
  rep(i, N){
    cout << ans - B[A[i]]+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 5760
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String ans = a.substring(0,1) + b.substring(0,1) +c.substring(0,1);

        System.out.println(ans.toUpperCase());
    }
}


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

int main(){
    char s[4];
    int n;

    scanf("%s",s);
    
    n=strlen(s);
    if(n==3){
        char tmp=s[0];
        s[0]=s[2];
        s[2]=tmp;
    }
    printf("%s",s);
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n; scanf("%d",&n);
   map<string,int> mp;
   vector<string> ss(n);
   ll res=0;
   rep(i,0,n){
      cin>>ss[i];
      int a; scanf("%d",&a);
      res+=a; mp[ss[i]]=a;
   }
   string s; cin>>s;
   rep(i,0,n){
      res-=mp[ss[i]];
      if(ss[i]==s)break;
   }
   printf("%lld\n",res);
   return 0;
}

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

ball = [1]*n
d={}
for i in range(1,n+1):
    d[i]=0
d[1]=1

for _ in range(m):
    x,y = map(int,input().split())

    ball[x-1]-=1
    if d[x]==1:
        if ball[x-1]==0:
            d[x]=0
        d[y]=1
    ball[y-1]+=1

cnt=0
for _ ,v in d.items():
    if v==1:
        cnt+=1


print(cnt)

Measured memory_bytes: 15852
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 100010
using namespace std;

ll n, ans;
char s[N];

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

int main(){
	n = read();
	REP(i, 1, n){
		cin >> s[i];
		if (s[i] != s[i - 1]) ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
#define pb push_back
#define ppb pop_back
#define nd second
#define st first
#define ll long long
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
int a,b,k;
int main()
{
  cin>>a>>b>>k;
  if(2*k>b-a+1)
    for(;a<=b;a++)
      cout<<a<<endl;
  else
  {
    for(int i=0;i<k;i++)
      cout<<a+i<<endl;
    for(--k;k>=0;k--)
      cout<<b-k<<endl;
  }
  return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && b == c) {
		cout << "No";
	}
	else if (a != b && a != c && b != c) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}

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

std::pair<int, int> a;

struct Order {
	int op, i, j, k;
};

std::vector<Order> ans;

void mul(int x, int p) {
	for (int i = 1; i <= p; ++i) {
		ans.push_back({0, x, x, x});
	}
}

void split(int x, int st) {
	ans.push_back({0, x, 3, 93});
	ans.push_back({0, 96, 97, 94});
	for (int i = 29; ~i; --i) {
		ans.push_back({0, 94, i + 3, 95});
		ans.push_back({1, 95, 93, 95});
		ans.push_back({0, 95, 96, st + i});
		mul(95, i);
		ans.push_back({0, 94, 95, 94});
	}
}

void land(int x, int y, int st) {
	ans.push_back({0, x, y, st});
	ans.push_back({1, 3, st, st});
}

int main() {
	ans.push_back({0, 0, 1, 3});
	ans.push_back({0, 3, 3, 3});
	ans.push_back({1, 0, 3, 3});
	for (int i = 1; i < 30; ++i) {
		ans.push_back({0, i + 2, i + 2, i + 3});
	}
	split(0, 33), split(1, 63);
	for (int i = 0; i < 30; ++i) {
		for (int j = 0; j < 30; ++j) {
			land(33 + i, 63 + j, 93);
			mul(93, i + j);
			ans.push_back({0, 2, 93, 2});
		}
	}
	printf("%d\n", (int)ans.size());
	for (auto v : ans) {
		printf("%c %d %d %d\n", v.op == 0 ? '+' : '<', v.i, v.j, v.k);
	}
}


Measured memory_bytes: 3644
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

def res(x):
    res_x = 0 if x % 10 == 0 else 10 - x % 10
    return res_x

def gauss(x):
    gx = x if x%10 == 0 else 10 * (x // 10 + 1)
    return gx

ds = [a, b, c, d, e]
ds_sort = sorted(ds, key=lambda x: res(x))
ans = sum([gauss(e) for e in ds_sort[:-1]]) + ds_sort[-1]

print(ans)

Measured memory_bytes: 3064
N, K = map(int, input().split())
costs = list(map(int, input().split()))
foods = list(map(int, input().split()))
foods.sort()
costs.sort(reverse=True)

def can_eat(x):
  count = 0
  for i in range(N):
    count += max(0, costs[i]-x//foods[i])
  return count <= K

l, r = -1, 10**12+1
while r-l > 1:
  mid = (l+r)//2
  if can_eat(mid):
    r = mid
  else:
    l = mid
print(r)

Measured memory_bytes: 113768
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())

xy = []
for _ in range(n):
    x,y = map(int,readline().split())
    if x>y: x,y = y,x
    xy.append((x,y))
xy.sort()


xx = []
yy = []
for x,y in xy:
    xx.append(x)
    yy.append(y)


ymaxr = yy[:]
for i in range(n-2,-1,-1):
    ymaxr[i] = max(ymaxr[i],ymaxr[i+1])

ymaxl= yy[:]
for i in range(1,n):
    ymaxl[i] = max(ymaxl[i],ymaxl[i-1])

ymin = yy[:]
for i in range(1,n):
    ymin[i] = min(ymin[i],ymin[i-1])

#print(yy)
#print(ymaxl)
#print(ymaxr)
#print(ymin)

#print(xx,yy)

ans = 1<<60
for i in range(n):
    mr = xx[0]

    Mr = xx[i]
    if i != n-1: Mr = max(Mr,ymaxr[i+1])
    
    mb = ymin[i]
    if i != n-1: mb = min(mb,xx[i+1])
    
    Mb = ymaxl[i]
    if i != n-1: Mb = max(Mb,xx[n-1])

    #print(i,mr,Mr,mb,Mb)
        
    ans = min(ans,(Mr-mr)*(Mb-mb))


print(ans)










Measured memory_bytes: 127012
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    int n, k;
    ll cur = 1;
    cin >> n >> k;
    while(n--) {
        if(k > cur) {
            cur *= 2;
        } else {
            cur += k;
        }
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from itertools import permutations
#グラフの作成   
def make_list(V,E):
 
    edges = []
    path=[[0]*E for i in range(V) ]   #ルート作成に必要になる
    
    for i in range(V):
        a=[int(x) for x in str(input()).split()]
        for j in range(len(a)):
            #print("j",j)
            path[i][j]=i
           # if j!= i and a[j]==0:
                #a[j]=2000
                #path[i][j]=-2000
	
        edges.append((a))    #  有効辺グラフ
	

   
     
    return edges ,path


#フロイド・ワーシャル
def warshall_floyd(glath):
	
	for k in range(len(glath)):
		for i in range(len(glath)):
			for j in range(len(glath[i])):
				if glath[i][j] > glath[i][k] + glath[k][j]:
                                   glath[i][j] = glath[i][k] + glath[k][j]
                                   glath[j][i] = glath[i][k] + glath[k][j]
				#glath[i][j]= min(int(glath[i][j]),int(glath[i][k])+int(glath[k][j]))
				
	return glath





N, M ,R= [int(x) for x in str(input()).split()]  #グラフの大きさ 

r=[int(x) for x in str(input()).split()]


graph=[[float("inf")]*N for i in range(N)]


for i in range(M):
	a,b,c=[int(x) for x in str(input()).split()]
	#if a in r and b in r:
	graph[a-1][b-1]=c
	graph[b-1][a-1]=c



#all_cost=warshall_floyd(select_graph)
all_cost=warshall_floyd(graph)


#print(all_cost)
#print(all_cost[r[0]-1-a][r[-1]-1-a])
#print(r[-1]-1-a)

max_count=float("inf")


for i in permutations(r):
        cost=0
        for j in range(len(i)-1):
                
                cost+= all_cost[i[j]-1][i[j+1]-1]
       
        max_count=min(max_count,cost)


#			max_count=min(max_count,all_cost[i-a-1][j-a-1]+all_cost[j-a-1][j-a-1])


print(max_count)    
  


Measured memory_bytes: 4660
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;

    double dist = sqrt( pow(A,2) + pow(B,2) - 2*A*B*cos( 2*M_PI* abs(H/12 + M/720 - M/60)) );

    cout << setprecision(9) << scientific << dist << endl;
}

Measured memory_bytes: 4192
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int n,table[7],tmp;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i < 7; i++)table[i] = 0;

		for(int i=0; i < n; i++){
			scanf("%d",&tmp);

			if(tmp < 10){
				table[0]++;
			}else if(tmp < 20){
				table[1]++;
			}else if(tmp < 30){
				table[2]++;
			}else if(tmp < 40){
				table[3]++;
			}else if(tmp < 50){
				table[4]++;
			}else if(tmp < 60){
				table[5]++;
			}else{
				table[6]++;
			}
		}

		for(int i=0; i < 7; i++)printf("%d\n",table[i]);

	}

    return 0;
}

Measured memory_bytes: 2732
def m():
    S = input()
    N = len(S)
    A = [0] * N
    cnt = 0
    for i in range(0, N):
        if S[i] == 'R':
            cnt +=1
        else:
            A[i] = cnt
            cnt = 0
    cnt = 0
    for i in range(N-1, -1, -1):
        if S[i] == 'L':
            cnt +=1
        else:
            A[i] = cnt
            cnt = 0
    left = 0
    while left < N-1:
        if A[left] == 0:
            left +=1
            continue
        l = A[left] // 2 + A[left+1] // 2 + (A[left+1] % 2)
        r = A[left] // 2 + A[left+1] // 2 + (A[left] % 2)
        A[left] = l
        A[left+1] = r
        left+=2
    for i in range(N):
        print(A[i], end=' ')
    return


m()

Measured memory_bytes: 77632
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    total = sum(A)
    threshold = -(-total // (4*M))
    if A[M-1] >= threshold:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include<iostream>
main(){int i,n,m[7][2]={4,3,3,4,0,4,6,5,3,6,2,0,6,6};for(std::string p;std::cin>>p,n=p!="#";std::cout<<(n?"No\n":"Yes\n"))for(i=0;i<p.size();)n=m[n][p[i++]-48];}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


void solve(int W,int H,int x,int y){
    double area = (double)W * H * 0.5;
    int plu = 0;
    if (x*2 == W && y*2 == H) plu = 1;
    printf("%.6f %d\n", area, plu);
}

int main() {
    int W,H,x,y; cin >> W>>H>>x>>y;
    solve(W,H,x,y);
    return 0;
}


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

using namespace std;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector<string> board(n);
  for (int i = 0; i < n; ++i) {
    cin >> board[i];
  }
  vector<vector<int>> sum(n, vector<int> (n + 1));
  
  auto recalc_sum = [&](int x) {
    for (int i = 0; i < n; ++i) {
      sum[x][i + 1] = sum[x][i] + (board[x][i] == '#' ? 0 : board[x][i] - '0');
    }
  };

  auto calc_sum = [&](int x, int l, int r) {
    return sum[x][r + 1] - sum[x][l];
  };

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

  vector<vector<int>> l(n, vector<int> (n, n)), r(n, vector<int> (n, -1));
  long long answer = 0;
  for (int x = n - 1; ~x; --x) {
    vector<vector<int>> tl(n, vector<int> (n, n)), tr(n, vector<int> (n, -1));
    for (int z = x; z < n; ++z) {
      if (z == x) {
        for (int y = n - 1; ~y; --y) {
          if (board[x][y] != '#') {
            tl[z][y] = y;
            tr[z][y] = max(y, y + 1 < n ? tr[z][y + 1] : -1);
            answer += (board[x][y] - '0') * calc_sum(z, tl[z][y] + 1, tr[z][y]);
          }
        }
      } else {
        for (int y = n - 1; ~y; --y) {
          if (board[x][y] != '#') {
            tl[z][y] = min(l[z][y], y + 1 < n ? tl[z][y + 1] : n);
            tr[z][y] = max(r[z][y], y + 1 < n ? tr[z][y + 1] : -1);
          }
        }
        vector<int> visit(n + 1);
        for (int y = 0; y < n; ++y) {
          if (tl[z][y] <= tr[z][y]) {
            ++visit[tl[z][y]];
            --visit[tr[z][y] + 1];
          }
        }
        for (int y = 0; y < n; ++y) {
          if (y) {
            visit[y] += visit[y - 1];
          }
          if (!visit[y]) {
            if (board[z][y] != '#') {
              board[z][y] = '#';
              recalc_sum(z);
            }
          }
        }
        for (int y = 0; y < n; ++y) {
          if (tl[z][y] <= tr[z][y]) {
            answer += (board[x][y] - '0') * calc_sum(z, tl[z][y], tr[z][y]);
          }
        }
      }
    }
    l = tl;
    r = tr;
  }

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 7536
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MAX 100001

struct Node {
	int p, l, r; //?????????????????¨???
};
struct Node T[MAX];
int D[MAX];

//??¨node?????±??????D???????´?
void rec(int u, int p) {
	D[u] = p;
	if (T[u].r != -1) {
		rec(T[u].r, p);
	}
	if (T[u].l != -1) {
		rec(T[u].l, p + 1);
	}
}

void print(int u) {
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].p == -1) { cout << "root, "; }
	else if (T[u].l == -1) { cout << "leaf, "; }
	else { cout << "internal node, "; }

	cout << "[";

	for (int i = 0, c = T[u].l; c != -1; i++, c = T[c].r) {
		if (i) { cout << ", "; }
		cout << c;
	}
	cout << "]" << endl;
}

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

	//?????????
	for (int i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = -1;
	}

	for (int i = 0; i < n; i++) {
		int id, k; cin >> id >> k;
		int l = 0;

		//?????????????????????
		for (int j = 0; j < k; j++) {
			int c; cin >> c;

			//?????????????¨????
			if (j == 0) { T[id].l = c; }
			//???(l)????????????(r)????¨????
			else { T[l].r = c; }

			//?????????????¨????
			T[c].p = id; 
			l = c;
		}
	}

	//??????????????????
	int r;
	for (int i = 0; i < n; i++) {
		if (T[i].p == -1) { r = i; }
	}

	rec(r, 0);

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

	return 0;
}

Measured memory_bytes: 5844
module Point = struct

  type t = { x : float; y : float }

  let make x y = { x; y }

  let sum a b = { x = a.x +. b.x; y = a.y +. b.y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let multi p k = { x = p.x *. k; y = p.y *. k }

  let norm p = p.x *. p.x +. p.y *. p.y

  let dot a b = a.x *. b.x +. a.y *. b.y

  let project p1 p2 p =
    let base = diff p2 p1 in
    dot (diff p p1) base /. norm base
    |> multi base
    |> sum p1

end

open Point

let () =
  let x1, y1, x2, y2 = Scanf.scanf "%f %f %f %f " (fun a b c d -> a,b,c,d) in
  let p1 = make x1 y1 in
  let p2 = make x2 y2 in
  let q = Scanf.scanf "%d " (fun i -> i) in
  for _ = 0 to q - 1 do
    let x, y = Scanf.scanf "%f %f " (fun x y -> x,y) in
    let p = make x y |> project p1 p2 in
    Printf.printf "%.10f %.10f\n" p.x p.y
  done

Measured memory_bytes: 3496
import sys
input=sys.stdin.readline
N=100000
primes = set(range(3, N+1, 2))
for i in range(3, int(N**0.5+1)):
  primes.difference_update(range(i*3, N+1, i*2))
primes=set(primes)
primes.add(2)
FG=[0]*(N+1)
for i in range(1,N+1,2):
  FG[i-1]=FG[i-2]
  if i in primes and (i+1)//2 in primes:
    FG[i]=FG[i-1]+1
  else:
    FG[i]=FG[i-1]
for q in range(int(input())):
  l,r=map(int,input().split())
  print(FG[r]-FG[l-1])

Measured memory_bytes: 8684
import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto K = to!ulong(tokens[1]);

	ulong[] trees;
	foreach (i; 0..N)
	{
		trees ~= to!ulong(my_readln());
	}
	trees.sort();
	ulong small = ulong.max;
	foreach (i; 0..N-(K-1))
	{
		auto diff = trees[i+K-1] - trees[i];
		if (diff < small) small = diff;
	}

	writeln(small);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}

Measured memory_bytes: 3964
count = 0
a = []
N,X = map(int,input().split())
for i in range(1, N+1):
  m = int(input())
  a.append(m)
a.sort()
for i in a:
  X = X - i
  count += 1
while True:
  if X >= a[0]:
    X = X - a[0]
    count += 1
  else:
    break
print(count)

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int N, A;
    cin >> N >> A;
    cout << ((N % 500) <= A ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  ll a,v,b,w,t; cin>>a>>v>>b>>w>>t;
  if (a>b) swap(a,b);
  b-=a; a-=a;
  if (t * (v-w) >= b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	int n, m;

	cin >> n >> m;
	cout << (n + m) * (n + m - 1) / 2 - (n * m) << "\n";
	
	return 0;
}

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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main() {
  int n;
  string S;
  cin >> n >> S;
  int ans = 0;
  vector<int> s(n);
  for(int i=0;i<n;i++){
    s.at(i) = ctoi(S.at(i));
  }
  for(int i=0;i<10;i++){
    int a=-1;
    for(int j=0;j<n;j++){
      if(s.at(j) == i){
        a = j;
        break;
      }
    }
    if(a < 0){continue;}
    for(int j=0;j<10;j++){
      int b = -1;
      for(int k=a+1;k<n;k++){
        if(s.at(k) == j){
          b = k;
          break;
        }
      }
      if(b < 0){continue;}
      for(int k=0;k<10;k++){
        for(int l=b+1;l<n;l++){
          if(s.at(l) == k){
            ans++;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num/=10;
        digit++;
    }
    return digit;
}

int main(){
    ll N;
    cin >> N;
    ll ans=N;
    int min=10;
    for(ll i=1; i<=sqrt(N); i++){
        if(N%i==0){
            if(GetDigit(max(N/i, i))<min){
                min=GetDigit(max(N/i,i));
            }
        }
    }
    cout << min;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  string s; cin >> s;
  if(s[0] == s[1] && s[1] == s[2]) cout << "Yes\n";
  else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
  return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)

#define ALL(x) (x).begin(),(x).end()

int henkan(int a) {
	if (a == 10000) {
		return 199;
	}
	else {
		return (a + 10000) / 100;
	}
}

LL mod = 1000000007;
int main() {

	int n;
	cin >> n;

	if (n <= 100) {
		vector<vector<int>> v(n, vector<int>(2));
		REP(i, n) {
			cin >> v[i][0] >> v[i][1];

		}
		int min = 1000000000;
		REP(i, n) {
			FOR(j, i+1, n) {
				int r = (v[i][0] - v[j][0])*(v[i][0] - v[j][0]) + (v[i][1] - v[j][1])*(v[i][1] - v[j][1]);
				if (r < min) { min = r; }
			}
		}
		cout << min << endl;
	}
	else {

		vector<vector<vector<vector<int>>>> v(200, vector<vector<vector<int>>>(200, vector<vector<int>>(0)));
		REP(i, n) {
			int a, b;
			cin >> a >> b;
			v[henkan(a)][henkan(b)].push_back({ a,b });
		}
		int min = 100000;
		REP(i, 199) {

			REP(j, 199) {
				vector<vector<int>> vv(0);

				vv.insert(vv.end(), v[i][j].begin(), v[i][j].end());
				vv.insert(vv.end(), v[i][j+1].begin(), v[i][j + 1].end());
				vv.insert(vv.end(), v[i + 1][j].begin(), v[i + 1][j].end());
				vv.insert(vv.end(), v[i + 1][j + 1].begin(), v[i + 1][j + 1].end());

				REP(ii, vv.size()) {
					FOR(jj, ii + 1, vv.size()) {
						int r = (vv[ii][0] - vv[jj][0])*(vv[ii][0] - vv[jj][0]) + (vv[ii][1] - vv[jj][1])*(vv[ii][1] - vv[jj][1]);
						if (r < min) { min = r; }
					}
				}
			}
		}
		cout << min << endl;
	}
}

Measured memory_bytes: 35936
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    lint N; cin >> N;
    map<lint, lint> m;
    vector<int> primes(101,1);
    primes[0] = primes[1] = 0;
    primes[2] = 1;
    for(int i=3; i<101; i+=2){
        if(primes[i]) continue;
        for(int j=1; i*j<101; j++){
            primes[i*j] = 0;
        }
    }
    vector<lint> ps;
    REP(i, 101) if(primes[i]) ps.push_back(i);
    REP(i, N){
        lint n = i+1;
        for(auto p: ps){
            while(n%p==0){
                m[p]++;
                n /= p;
            }
        }
    }
    lint l4=0, l2 = 0;
    lint l74=0, l24=0, l14=0;
    for(auto p: m){
        if(p.second>=74){
            l74++;
            l24++;
            l14++;
            l4++;
            l2++;
        } 
        else if(p.second>=24){
            l24++;
            l14++;
            l4++;
            l2++;
        } 
        else if(p.second>=14){
            l14++;
            l4++;
            l2++;
        } 
        else if(p.second>=4){
            l4++;
            l2++;
        }else if(p.second>=2) l2++;
    }
    if(l2<3 or l4<2){
        cout << 0 << endl;
        return 0;
    }
    lint res;
    res = l74;
    res += l24 * (l2-1);
    res += l14 * (l4-1);
    res += (l2-2) * l4 * (l4-1) / 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

// cl /EHsc xxx.cpp
int main(int argc, char *argv[])
{
	
	int n, m;
	cin >> n >> m;
	
	int ** A = new int *[n];
	for (int i = 0; i < n; i++)
		A[i] = new int[m];
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	
	int *B = new int[m];
	for (int i = 0; i < m; i++)
		cin >> B[i];
	
	
	for (int i = 0; i < n; i++)
	{
		int c = 0;
		for (int j = 0; j < m; j++)
		{
			c += (A[i][j] * B[j]);
		}
		cout << c << endl;
	}
	
	delete[] B;

	for (int i = 0; i < n; i++)
		delete[] A[i];
	delete[] A;

	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <string>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    string A[N], B[M];
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    bool found = false;
    for(int i = 0; !found && i < N - M + 1; i++) {
        int idxA = A[i].find(B[0]);
        found = idxA >= 0 && N == M;
        while(!found && idxA >= 0) {
            for(int j = 1; j < M; j++) {
                if(A[i+j].substr(idxA, M) != B[j]) break;
                found = j == M-1;
            }
            idxA = A[i].find(B[0], idxA+1);
        }
    }
    if(found) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	vector<int>a(3);
	int ans=0;
	rep(i,3)cin>>a.at(i);
	while(!(a.at(0)==a.at(1)&&a.at(1)==a.at(2))){
		sort(all(a));
		if(1<a.at(2)-a.at(0))a.at(0)+=2;
		else{
			a.at(0)++;a.at(1)++;
		}
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256