akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, A, B, C = getNM()
que = [input() for i in range(N)]
que.append(que[-1])
res = []
for i in range(N):
    q = que[i]

    if q == 'AB':
        if A > B:
            A -= 1
            B += 1
            res.append('B')
        elif A < B:
            A += 1
            B -= 1
            res.append('A')
        else:
            if que[i + 1] == 'AB':
                A -= 1
                B += 1
                res.append('B')
            elif que[i + 1] == 'AC':
                A += 1
                B -= 1
                res.append('A')
            elif que[i + 1] == 'BC':
                A -= 1
                B += 1
                res.append('B')
    elif q == 'AC':
        if A > C:
            A -= 1
            C += 1
            res.append('C')
        elif A < C:
            A += 1
            C -= 1
            res.append('A')
        else:
            if que[i + 1] == 'AC':
                A -= 1
                C += 1
                res.append('C')
            elif que[i + 1] == 'AB':
                A += 1
                C -= 1
                res.append('A')
            elif que[i + 1] == 'BC':
                A -= 1
                C += 1
                res.append('C')
    else:
        if B > C:
            B -= 1
            C += 1
            res.append('C')
        elif B < C:
            B += 1
            C -= 1
            res.append('B')
        else:
            if que[i + 1] == 'BC':
                B -= 1
                C += 1
                res.append('C')
            elif que[i + 1] == 'AB':
                B += 1
                C -= 1
                res.append('B')
            elif que[i + 1] == 'AC':
                B -= 1
                C += 1
                res.append('C')
    if A < 0 or B < 0 or C < 0:
        print('No')
        exit()
print('Yes')
for i in res:
    print(i)

Measured memory_bytes: 96536
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,p,m=0,k,h,w,sum=0,sum_a=0,sum_b=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u,v;
    bool ok=true;
    cin >> n;
    VS a(n);
    rep(i,n){
        cin >> s;
        a[i] = s;
        rep(j,s.size()-1){
            if(s[j]=='A' && s[j+1]=='B'){
                ans++;
            }
        }
    }

    rep(i,n){
        if(a[i][0] == 'B' && a[i][a[i].size()-1] == 'A'){
            sum++;
        }
        else if(a[i][0] == 'B'){
            sum_b++;
        }
        else if(a[i][a[i].size()-1] == 'A'){
            sum_a++;
        }
    }
    while(ok){
        if(sum_a > 0){
            sum_a--;
            while(sum > 0){
                sum--;
                ans++;
            }
            if(sum_b > 0){
                sum_b--;
                ans++;
            }
        }
        else if (sum > 0){
            sum--;
            while(sum > 0){
                sum--;
                ans++;
            }
            if(sum_b > 0){
                sum_b--;
                ans++;
            }
        }
        if(sum_a == 0){
            ok = false;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#ifdef _WIN32
#define DEBUG	1
#endif

#define _CRT_SECURE_NO_WARNINGS
#define MATH_PI 3.14159265358979323846264338327950288419716939
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

#ifdef DEBUG
#include "include.h"
#else
inline void wait(){}
inline void dout(const char *arg, ...){}
#endif

//template<typename T>inline void swap(T a, T b){T t = a; a = b; b = t;}

#define CLIP(ptr, min, max) {if((min)<=(max)){if(ptr<(min)){ptr=(min);}if(ptr>(max)){ptr=(max);}}}
#define max(a, b) a > b ? a : b;
#define min(a, b) a > b ? b : a;
#define Sin(deg) sin((deg)*MATH_PI/180)
#define Cos(deg) cos((deg)*MATH_PI/180)
#define Tan(deg) tan((deg)*MATH_PI/180)
#define Rad(deg) ((deg)*MATH_PI/180)
#define ff(param, num) for(int param=0 ; param<num ; ++param)
#define fi(num) for(int i=0 ; i<num ; ++i)
#define fj(num) for(int j=0 ; j<num ; ++j)
#define fk(num) for(int k=0 ; k<num ; ++k)
#define fl(num) for(int l=0 ; l<num ; ++l)
#define fn(num) for(int n=0 ; n<num ; ++n)
#define ffr(param, num) for(int param=num-1 ; param>=0 ; --param)
#define fir(num) for(int i=num-1 ; i>=0 ; --i)
#define fjr(num) for(int j=num-1 ; j>=0 ; --j)
#define fkr(num) for(int k=num-1 ; k>=0 ; --k)
#define flr(num) for(int l=num-1 ; l>=0 ; --l)
#define fnr(num) for(int n=num-1 ; n>=0 ; --n)
#define gi(p) Scanf("%d", p)
#define gi2(p1, p2) Scanf2("%d %d", p1, p2)
#define gi3(p1, p2, p3) Scanf3("%d %d %d", p1, p2, p3)
#define gi4(p1, p2, p3, p4) Scanf4("%d %d %d %d", p1, p2, p3, p4)
#define gll(p) Scanf("%lld", p)
#define gll2(p1, p2) Scanf2("%lld %lld", p1, p2)
#define gll3(p1, p2, p3) Scanf3("%lld %lld %lld", p1, p2, p3)
#define gll4(p1, p2, p3, p4) Scanf4("%lld %lld %lld %lld", p1, p2, p3, p4)
#define gf(p) Scanf("%f", p)
#define gf2(p1, p2) Scanf2("%f %f", p1, p2)
#define gf3(p1, p2, p3) Scanf3("%f %f %f", p1, p2, p3)
#define gf4(p1, p2, p3, p4) Scanf4("%f %f %f %f", p1, p2, p3, p4)
#ifdef DEBUG
#define gc(buf) fscanf(local_in.fp, "%s", buf)
#define Scanf(expr, p) fscanf(local_in.fp, expr, &p)
#define Scanf2(expr, p1, p2) fscanf(local_in.fp, expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) fscanf(local_in.fp, expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) fscanf(local_in.fp, expr, &p1, &p2, &p3, &p4)
#else
#define gc(buf) Scanf("%s", buf)
#define Scanf(expr, p) scanf(expr, &p)
#define Scanf2(expr, p1, p2) scanf(expr, &p1, &p2)
#define Scanf3(expr, p1, p2, p3) scanf(expr, &p1, &p2, &p3)
#define Scanf4(expr, p1, p2, p3, p4) scanf(expr, &p1, &p2, &p3, &p4)
#endif
#define ans(p) cout << p << endl;
signed main() {

	int ii, jj, kk, ll;
	int N;
	int ret = 0;
	int flag = 0;
	char cbuf[8192];

	gi(N);
	int life[100000];
	fn(N){
		gi(life[n]);
	}

	int *p[2];
	fn(N-1){
		while(true){
			if(life[n] % life[n+1] == 0 || life[n+1] % life[n] == 0){
				life[n+1] = min(life[n], life[n+1]);
				break;
			}
			if(life[n] > life[n+1]){
				life[n] %= life[n+1];
			}else{
				life[n+1] %= life[n];
			}
		}
	}

	ret = life[N-1];
	ans(ret);

	wait();

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

    vector<string> v;
    for(int i = 0; i < s.size(); ++i){
        string cur;
        for(int j = i; j < s.size() && j < i + 10; ++j){
            cur.push_back(s[j]);
            v.push_back(cur); } }

    int k;
    cin >> k;

    sort(begin(v), end(v));
    unique(begin(v), end(v));

    cout << v[k - 1] << endl;
    return 0; }


Measured memory_bytes: 3064
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        double x1,y1,x2,y2;
        double d;
        x1 = scanner.nextDouble();
        y1 = scanner.nextDouble();
        x2 = scanner.nextDouble();
        y2 = scanner.nextDouble();

        x1 -= x2;
        y1 -= y2;

        d = Math.sqrt(x1*x1+y1*y1);
        System.out.println(d);
    }
}



Measured memory_bytes: 27988
import numpy as np

H, W = map(int, input().split())
A = np.array([list(input()) for _ in range(H)])

row = [False] * H
column = [False] * W

for h in range(H):
    for w in range(W):
        if A[h, w] == "#":
            break
        if w == W-1:
            row[h] = True

for w in range(W):
    for h in range(H):
        if A[h, w] == "#":
            break
        if h == H-1:
            column[w] = True

for r, is_deleted in reversed(list(enumerate(row))):
    if is_deleted:
        A = np.delete(A, r, 0)

for c, is_deleted in reversed(list(enumerate(column))):
    if is_deleted:
        A = np.delete(A, c, 1)

for row in A:
    print("".join(row))


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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    int m[10][10];
    int x;
    for(int i = 1; i <= 3; i++)
    {
        for(int j = 1; j <= 3; j++)
        {
            cin >> m[i][j];
        }
    }
    int n;
    cin >> n;
    for(int k = 1; k <= n; k++)
    {
        cin >> x;
        for(int i = 1; i <= 3; i++)
        {
            for(int j = 1; j <= 3; j++)
            {
                if(m[i][j] == x)
                {
                    m[i][j] = 0;
                }
            }
        }
    }
    if(m[1][1]==0&&m[1][2]==0&&m[1][3]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[2][1]==0&&m[2][2]==0&&m[2][3]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[3][1]==0&&m[3][2]==0&&m[3][3]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[1][1]==0&&m[2][1]==0&&m[3][1]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[1][2]==0&&m[2][2]==0&&m[3][2]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[1][3]==0&&m[2][3]==0&&m[3][3]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[1][1]==0&&m[2][2]==0&&m[3][3]==0)
    {
        cout << "Yes" << endl;
    }
    else if(m[1][3]==0&&m[2][2]==0&&m[3][1]==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[101],sum,n;
	while(cin>>n,n){
	sum=0;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)if(i!=0&&i!=n-1)sum+=a[i];
	cout<<sum/(n-2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define INF int(1e9)
#define MOD int(1e9)
#define repi(i,j,n) for (int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

struct edge {
  int v, cost;
  edge() {}
  edge(int v, int cost) : v(v), cost(cost) {}
};

vector<edge> g[100005];
long long d[100005], dk[100005];
int V, E, k;

inline void bfs(int s) {
    queue<pair<long long, long long> > que;
    bool used[100005] = {false};
    used[s] = true;
    d[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();

        int v = p.second;
        int size_ = g[v].size();

        for (int i = 0; i < size_; ++i) {
            if (!used[g[v][i].v]) {
                used[g[v][i].v] = true;
                d[g[v][i].v] = p.first + g[v][i].cost;
                //cout << d[g[v][i].v] << endl;
                if (g[v][i].v == k) return;
                que.push(make_pair(p.first + g[v][i].cost, g[v][i].v));
            }
        }
    }
}

inline void bfsk(int s) {
    queue<pair<long long, long long> > que;
    bool used[100005] = {false};
    used[s] = true;
    dk[s] = 0;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();

        int v = p.second;
        int size_ = g[v].size();

        for (int i = 0; i < size_; ++i) {
            if (!used[g[v][i].v]) {
                used[g[v][i].v] = true;
                dk[g[v][i].v] = p.first + g[v][i].cost;
                //cout << dk[g[v][i].v] << endl;
                que.push(make_pair(p.first + g[v][i].cost, g[v][i].v));
            }
        }
    }
}

int main(void) {
    init();
    cin >> V;
    E = V - 1;
    int a, b, c;

    rep(i,V-1) {
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back(edge(b, c));
        g[b].push_back(edge(a, c));
    }

    int q, x, y;
    cin >> q >> k;
    k--;
    bfsk(k);
    for (int i = 0; i < q; ++i) {
        cin >> x >> y;
        x--; y--;
        cout << dk[x] + dk[y] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 9076
h,w=gets.split.map(&:to_i)
l=[]
f=false
ee=0
c=0
h.times do |i|
  a=gets.split.map(&:to_i)
  e=0
  w.times do |j|
    if j<w-1
      if (a[j]+e).odd?
        l << "#{i+1} #{j+1} #{i+1} #{j+2}"
        c+=1
        e=1
      else
        e=0
      end
    else
      if i<h-1
        if (a[w-1]+e+ee).odd?
          l << "#{i+1} #{j+1} #{i+2} #{j+1}"
          c+=1
          ee=1
        else
          ee=0
        end
      end
    end
  end
end
puts c
puts l


Measured memory_bytes: 24868
s_a = list(input())
s_b = list(input())
s_c = list(input())

def a(cnt,p,q,r):
    if cnt == "a":
        if len(p) == 0 : return "A"
        else :
            cnt = str(p[0])
            p.pop(0)
            return a(cnt,p,q,r)
    elif cnt == "b":
        if len(q) == 0 : return "B"
        else :
            cnt = str(q[0])
            q.pop(0)
            return a(cnt,p,q,r)
    elif cnt == "c" :
        if len(r) == 0 : return "C"
        else:
            cnt = str(r[0])
            r.pop(0)
            return a(cnt,p,q,r)

cnt = a("a",s_a,s_b,s_c)
print(cnt)

Measured memory_bytes: 3188
#include<stdio.h>

int main() {
    char s[11] = {'\0'}, *p;
    int ans = 0, count = 0;
    
    scanf("%s", s);
    p = s;
    while(*p != '\0') {
        if(*p == 'A' || *p == 'C' || *p == 'G' || *p == 'T') {
            count++;
        } else {
            count = 0;
        }
        if(count > ans) ans = count;
        p++;
    }
    printf("%d\n", ans);
    
    return 0;
}


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


int make_reverse(int number){
  int reverse = 0;
  while (number > 0){
    reverse = reverse * 10 + number % 10;
    number /= 10;
  }
  return reverse;
  }

int main() {
  int A, B, reverse_num;
  cin >> A >> B;
  int count_num = 0;
  for (int k=A; k<=B; k++){
    reverse_num = make_reverse(k);
    if (k == reverse_num){
      count_num += 1;
  }
  }
  cout << count_num << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll N,M;
  cin >> N >> M;
  ll ans;
  ans = min(N,M/2);
  ll ad = M-2*N;
  if(ad>0) ans += ad/4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int main()
{
    double x,y,a,b,w,h,l,m,p=0;
    int r=0;
     cin>>w>>h>>a>>b;
    l=(w*h)/2.0;
    if(w/2==a&&h/2==b){
        r=1;
    }
    printf("%.6lf %d\n",l,r);
}

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

int main(){
    int N,K,X,Y;
    cin>>N>>K>>X>>Y;
    int cost=0;
    int i;
    for( i=1;i<=K&&i<=N;i++){
        cost+=X;
    }
    for( i=K+1;i<=N;i++)
        cost+=Y;
    cout<<cost<<"\n";    
    return 0;
}



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

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

    int N, X, Y, cnt[2003];

    cin >> N >> X >> Y;

    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j <= N; j++) {
            int d = abs(i - j); //goes straight

            d = min(d, abs(i - X) + 1 + abs(Y - j)); //goes to X then Y then j
            d = min(d, abs(i - Y) + 1 + abs(X - j)); //goes to Y then X then j

            cnt[d] += 1;
        }
    }

    for (int i = 1; i < N; i++)
        cout << cnt[i] << endl;
}


Measured memory_bytes: 256
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    else:
        for i in range(a):
            for k in range(b):
                if i==0 or i==a-1 or k==0 or k==b-1:
                    print("#",end="")
                else:
                    print(".",end="")
            print()
        print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k; cin >> k;
    ll a,b; cin >> a>>b;
    bool r = false;
    for(int i = a;i<=b;i++){
        if(i%k==0)r =true;
    }
    r ? cout << "OK" << endl : cout << "NG" << endl;
}

Measured memory_bytes: 3652
import sys
import math
import bisect
import heapq
from collections import Counter


def input():
    return sys.stdin.readline().rstrip()


def main():
    mod = 10 ** 9 + 7
    S = list(input())
    l = len(S)
    dp = [[0] * 13 for _ in range(l + 1)]

    dp[0][0] = 1
    for j in range(1, l + 1):
        if S[j - 1] == "?":
            for k in range(13):
                for q in range(10):
                    new_k = (k * 10 + q) %13
                    dp[j][new_k] += dp[j - 1][k]
                    dp[j][new_k] %= mod
        else:
            n = int(S[j - 1])
            for k in range(13):
                new_k = (k * 10 + n)%13
                dp[j][new_k] += dp[j - 1][k]
                dp[j][new_k] %= mod
    print(dp[l][5])

if __name__ == "__main__":
    main()


Measured memory_bytes: 98848
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define sz(s)  (int)s.size()
#define all(s)  s.begin(),s.end()
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

int ar[105],dp[N];
int main() {

    //IOS;
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n,k;
        cin>>n>>k;
        for(int i=1; i<=n; ++i) {
            cin>>ar[i];
        }
        for(int i=0; i<=k; ++i) {
            if(dp[i]==0) {
                for(int j=1; j<=n; ++j) {
                    if(i+ar[j]<=k)dp[i+ar[j]]=1;
                }
            }
        }
        if(dp[k]==1)cout<<"First";
        else
            cout<<"Second";
    }
    return 0;
}



Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n;
    cin >> n;
    ll s, t, pair = n + (n + 1) % 2;
    vector<P> p;
    REP(i, n){
        for(int j = i + 1; j < n; j++){
            s = i + 1, t = j + 1;
            if(s < t && s + t != pair && !(n % 2 && t == n)) p.push_back(P(s, t));
        }
    }
    if(n % 2){
        REP(i, n - 1) p.push_back(P(i + 1, n));
    }
    ll res = p.size();
    cout << res << endl;
    REP(i, res) cout << p[i].first << " " << p[i].second << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<cmath>
#include<bitset>
#include<cassert>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
int main()
{
    fast_io;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;

    if (n % 2 != 0)
        cout << (n / 2) + 1 << endl;
    else 
        cout << n / 2 << endl;

    return 0;
}

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

int l1 = 0;
int l2 = 0;

void getLs(vector<int> v) {
	sort(v.begin(), v.end(), greater<int>());
	l1 = v.at(0);
	l2 = v.at(1);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	getLs(a);
	for (int i = 0; i < n; i++) {
		int t = a.at(i);
		if (t == l1) {
			cout << l2 << endl;
		}
		else {
			cout << l1 << endl;
		}
	}
}

Measured memory_bytes: 2416
#include<iostream>
#include<cstdlib>
using namespace std;
#define INF (1<<20)

int main(){
	int a,b,d;
	while(cin>>a>>b>>d,a|b|d){
		int x,y,ansx=INF,ansy=INF;
		for(x=0;x<=50000;x++){
			if((d-a*x)%b==0){
				y=abs((d-a*x)/b);
				if(x+y<ansx+ansy || x+y==ansx+ansy && a*x+b*y<a*ansx+b*ansy){
					ansx=x;
					ansy=y;
				}
			}
			if((d+a*x)%b==0){
				y=(d+a*x)/b;
				if(x+y<ansx+ansy || x+y==ansx+ansy && a*x+b*y<a*ansx+b*ansy){
					ansx=x;
					ansy=y;
				}
			}
		}
		cout<<ansx<<' '<<ansy<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

int main(){
   std::string S;
   std::cin >> S;

   std::string alphabets = "abcdefghijklmnopqrstuvwxyz";

   if(S.size()==26){
      int index = -1;
      for(int i=S.size()-2; i>=0; --i){
	 if(S[i]<S[i+1]){
	    index = i;
	    break;
	 }
      }
      if(index>-1){
	 char ans;
	 for(char ch=S[index]; ch<='z'; ++ch){
	    bool flag = false;
	    for(int i=0; i<index+1; ++i){
	       if(S[i]==ch){
		  flag = true;
		  break;
	       }
	    }
	    if(!flag){
	       ans = ch;
	       break;
	    }
	 }
	 for(int i=0; i<index; ++i)
	    std::cout << S[i];
	 std::cout << ans << std::endl;
	 return 0;
      }else{
	 std::cout << -1 << std::endl;
	 return 0;
      }
   }else{
      int index = -1;
      for(int i=0; i<26; ++i){
	 bool flag = false;
	 for(int j=0; j<S.size(); ++j){
	    if(S[j]==alphabets[i]){
	       flag = true;
	       break;
	    }
	 }
	 if(!flag){
	    index = i;
	    break;
	 }
      }	
      std::cout << S << alphabets[index] << std::endl;
      return 0;
   }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
struct Edge {
	int s, d; Weight w;
	Edge() {};
	Edge(int s, int d, Weight w) : s(s), d(d), w(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (sizeOf(x) < sizeOf(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int sizeOf(int x) { return -parent[root(x)]; }
};

/*
最小全域木
Kruskal法
非連結グラフでは最小全域森
計算量: O(E log E)
引数: グラフ
戻り値: (総コスト, 辺集合)
*/
pair<Weight, Edges> kruskal(const Graph &g) {
	int n = g.size();
	UnionFind uf(n);
	Edges es;
	for (int i = 0; i < n; i++)
		for (auto &e : g[i])
			es.push_back(e);
	sort(es.begin(), es.end());
	Weight total = 0;
	Edges mst;
	for (auto &e : es)
		if (!uf.same(e.s, e.d)) {
			uf.unite(e.s, e.d);
			mst.push_back(e);
			total += e.w;
		}
	return make_pair(total, mst);
}

/*
最小全域木
Kruskal法
非連結グラフでは最小全域森
計算量: O(E log V) (E = V^2 より log E = 2 log V)
引数: グラフ（行列表現）
戻り値: (総コスト, 辺集合)
*/
pair<Weight, Edges> kruskal(const Matrix &m) {
	int n = m.size();
	Graph g(n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (m[i][j] != INF)
				addArc(g, i, j, m[i][j]);
	return kruskal(g);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	Matrix m(N, Array(N, INF));
	vector<int> s(M), d(M), c(M); rep(i, 0, M) {
		cin >> s[i] >> d[i] >> c[i];
		s[i]--, d[i]--;
		m[s[i]][d[i]] = c[i];
	}

	Weight tot;
	Edges mst;
	tie(tot, mst) = kruskal(m);
	dump(kruskal(m));

	Matrix tm = m;

	int num = 0;
	int cost = 0;
	for (auto e : mst) {
		tm[e.s][e.d] = INF;
		Weight tot2; Edges mst2;
		tie(tot2, mst2) = kruskal(tm);
		dump(kruskal(tm));
		if (tot2 > tot || mst2.size() < mst.size()) {
			num++;
			cost += e.w;
		}
		tm[e.s][e.d] = m[e.s][e.d];
	}

	cout << num << " " << cost << endl;

	return 0;
}


Measured memory_bytes: 7740
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = new long[N];
            var Bi = new long[N];
            for (var i = 0; i < N; ++i)
            {
                var ab = Sarray();
                Ai[i] = ab[0];
                Bi[i] = ab[1];
            }
            var cnt = 0L;
            for (var i = N - 1; 0 <= i; --i)
            {
                var now = cnt + Ai[i];
                if (now == 0)
                {
                    now += Bi[i];
                    continue;
                }
                if (now % Bi[i] == 0)
                {
                    continue;
                }
                cnt += Bi[i] - now % Bi[i];
            }
            WriteLine(cnt);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 18784
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  int n,ans=0;
  cin >> n;
  VI a(n);
  REP(i,0,n){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  VB div(a[n-1]+1,true);
  
  REP(i,0,n){
    if(i != n-1){
      if(a[i] == a[i+1]){
        div[a[i]] = false;
      }
    }
    for(int j=2*a[i]; j<=a[n-1]; j+=a[i]){
      if(div[j]){div[j] = false;}
    }
  }
  
  REP(i,0,n){
    if(div[a[i]]){ans++;}
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4236
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int gcd(int x,int y){
	if (x%y == 0) return y;
	return gcd(y,x%y);
}
int main ()
{
	int n;
	int a[3009];
	scanf("%d",&n);
	int s = 0;
	for (int i = 1;i <= n; i++)
	{
		scanf("%d",&a[i]);
		s += a[i];
	}
		printf("%d\n",s-n);
}

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

int n, m, q;
vector<vector<int>> g(501);

int main(){
    cin >>n >>m >> q;
    lp(i, 0, m){
        int a, b;
        cin >> a>>b;
        g[b].push_back(b-a);
    }

    for (int i = 1; i < 501; i++)
        sort(g[i].begin(), g[i].end());

    while(q--){
        int a, b;
        cin >>a >>b;
        ll ans = 0, cur = 0;
        for (int i = a; i <= b; i++){
            if(g[i].size()){
                ll h = upper_bound(g[i].begin(), g[i].end(), cur) - g[i].begin();
                ans += (h);
            }
            cur++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	int x,a,b;
	cin >> x >> a >> b;
	int c=(-1*a)+b;
	
	if(c<=0){
		cout << "delicious" << endl;
	}else if( 0<c && c<=x){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

w, h = getList()

root = []
for i in range(w):
    n = getN()
    root.append((n, 0))

for i in range(h):
    n = getN()
    root.append((n, 1))

root.sort()
w += 1
h += 1
ans = 0
for r in root:
    if r[1] == 0:
        ans += r[0] * h
        w -= 1
    else:
        ans += r[0] * w
        h -= 1

print(ans)


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

int main() {
  double a,b;
  cin >> a >> b;
  bool flag = true;
  for(double i=1; i<1251; i++){
    if (floor(i*0.08) == a && floor(i*0.10) == b){
      cout << i << endl;  
      flag = false;
      break;
    }
  }
  if (flag==true) cout << -1 << endl;
}


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

int x, y;

int main() {
    cin >> x >> y;
    
    int group[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    if (group[x] == group[y]) cout << "Yes" << endl;
    else cout << "No" << endl;    

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int m,d;
	cin>>m>>d;
	if(d<10) cout<<"0"<<endl;
	else{
		int cnt=0;
		for(int i=1;i<=m;i++){
			for(int j=20;j<=d;j++){
				int d1=j%10;
				int d2=j/10;
				if(d1>=2 && d2>=2 && d1*d2==i){
					cnt++;
				}
					
			}
		}
		cout<<cnt<<endl;	
	}	
	return 0;
}

Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  for($i=0;$i<3;$i++){
    if($n[$i]=="1"){
      echo "9";
    }else if($n[$i]=="9"){
      echo "1";
    }else{
      echo $n[$i];
    }
  }

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

int main(void) {
	char w[11];
	char m[101];
	int i, count = 0;
	scanf("%s", w);

	while (1) {
		scanf("%s", m);
		if (strcmp("END_OF_TEXT", m) == 0) break;
for (i = 0; i < 101; i++) {
			if ('A' <= m[i] && m[i] <= 'Z') {
				m[i] = m[i] + 32;
			}
		}
		if (strcmp(w, m) == 0) count++;
	}
	printf("%d\n", count);
	return 0;
}


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

using ll = long long;
const ll INF = 1LL << 60;
const ll MAX_A = 300005;

ll op(ll a, ll b) { return max(a, b); }
ll e() { return -INF; }

int main() {
    int N, K;  cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    segtree<ll, op, e> dp(MAX_A);  // seg(n) で初期化すると seg の値は e() で初期化される
    for (int i = 0; i < MAX_A; ++i) dp.set(i, 0);
    for (int i = 0; i < N; ++i) {
        // DUMPS(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        ll mx = dp.prod(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        dp.set(A[i], mx + 1);
    }
    ll ans = dp.all_prod();
    cout << ans << endl;
}


Measured memory_bytes: 16212
N, M = input().split()
M    = int(M)
N    = int(N)
tmp  = [[int(j) for j in input().split()] for i in range(M)]

S    = [tmp[i][0] for i in range(M)]
C    = [str(tmp[i][1]) for i in range(M)]


targ = -1

range_list = [i for i in range(10**(N-1), 10**N)]
if N == 1:
  range_list = [0] + range_list

for i in range_list:
  tmp = 0
  str_i = str(i)
  for j in range(M):
    if str_i[S[j]-1] == C[j]:
      tmp += 1
  if tmp == M:
    targ = i
    break

print(targ)

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

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<long long> A(N);

  long long abs_min = 2000000000;
  long long abs_sum = 0;
  int odd_count = 0;

  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    odd_count += (tmp < 0 ? 1 : 0);

    A[i] = tmp;

    tmp = abs(tmp);
    abs_sum += tmp;

    if (abs_min > tmp) {
      abs_min = tmp;
    }
  }

  cout << (odd_count % 2 == 0 ? abs_sum : abs_sum - 2 * abs_min) << "\n";
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll n;
    cin >> n;
    vecll p(n);
    for(auto& i : p) cin  >> i;
    
    ll ans = 0;
    for(ll i = 1; i < n - 1; i++){
        if((p.at(i) < p.at(i - 1) && p.at(i) > p.at(i + 1)) || (p.at(i) < p.at(i + 1) && p.at(i) > p.at(i - 1))) ans++; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S=input()
P=10**9+7
N=len(S)
dp=[[0 for j in range(4)]for i in range(N+1)]
for i in range(N+1)[::-1]:
    for j in range(4)[::-1]:
        if i==N and j==3:
            dp[i][j]=1
        elif i==N and j!=3:
            dp[i][j]=0
        elif i!=N and j==3:
            m=0
            if S[i]=="?":
                m=3
            else:
                m=1
            dp[i][j]=m*dp[i+1][j]
        else:
            m1=0
            if S[i]=="?":
                m1=3
            else:
                m1=1
            m2=0
            if S[i]=="?" or S[i]=="ABC"[j]:
                m2=1
            else:
                m2=0
            dp[i][j]=m1*dp[i+1][j]+m2*dp[i+1][j+1]
        dp[i][j]=(dp[i][j]%P)
print(dp[0][0])


Measured memory_bytes: 27588
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, D: "List[List[int]]"):
    E = [d0 == d1 for d0, d1 in D]
    return YES if any(all(e) for e in zip(E, E[1:], E[2:])) else NO


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    print(solve(N, D))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

class UnionFind {
public:
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ
    
    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
};

int main() {
    ll n, q;
    cin >> n >> q;

    UnionFind Uni(n);
    Uni.init(n);
    rep(i, q) {
        ll t, u, v;
        cin >> t >> u >> v;
        if(t == 0) {
            Uni.unite(u, v);
        }
        else if(t == 1) {
            if(Uni.same(u, v)) {
                out(1);
            }
            else {
                out(0);
            }
        }
    }
    
    re0;
}

Measured memory_bytes: 5976
#include<algorithm>
#include<vector>
#include<list>
#include<iostream>
#include<utility>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<iterator>
#include<map>
#include<limits>
#include<iomanip>
#include<ctime>
 
const int INF=2147483647;
 
using namespace std;

//long long minEqVal;


int main(){
   int n,t;
   cin>>n>>t;
   
   long long ans=t;
   
   vector<int> vi(n,0);
   for(int i=0; i<n; i++){
       cin>>vi[i];
   }
   for(int i=0; i<n-1; i++){
       ans+=min(vi[i+1]-vi[i],t);
   }
   cout<<ans;
   
  
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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


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

  int n;
	cin >> n;

	vector<vector<ll>> vec(10, vector<ll>(10,0));
	rep1(i, n) {
	  string s = to_string(i);
		vec[(int) (s.back() - '0')][(int) (s.front() - '0')]++;
	}

	ll ans = 0;
	rep(i, 10) rep(j, 10) {
	  ans += vec[i][j]*vec[j][i];
	}

	cout << ans << endl;

}


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

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

vector<pair<ll, ll> > prime_factorize(ll N) {
  vector<pair<ll, ll> > res;
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main() {
  ll a,b;
  cin >> a >> b;
  ll k = gcd(a,b);
  vector<pair<ll,ll>> ans = prime_factorize(k);
  cout << ans.size() + 1 << endl;
  return 0;
}


Measured memory_bytes: 3632
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
h = Counter()
for x in a:
    h[x] += 1
f = True
for k, v in h.most_common():
    if n % 2 == 1 and k == 0:
        if v != 1:
            f = False
            break
    elif v != 2:
        f = False
        break
MOD = 1000000007
def mpow(n, p, mod):
    r = 1
    while p > 0:
        if p & 1 == 1:
            r = r * n % mod
        n = n * n % mod
        p >>= 1
    return r
print(mpow(2, int(n / 2), MOD) if f else 0) 

Measured memory_bytes: 16096
#include <stdio.h>
#include <string.h>
int main(){
  int i;
  char s[100001];
  scanf("%s",s);
  for(i='a';i<='z';i++)if(strchr(s,i)==0)break;
  if(i>'z')puts("None");
  else printf("%c",i);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    if(N%10==2 ||N%10==4 || N%10== 5 ||N%10== 7 ||N%10==9){
        cout << "hon" << endl;
    }
    else if(N%10==0 || N%10==1 || N%10== 6 ||N%10== 8){
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  
  int max = -INF, min = INF;
  
  for (int i = 0; i < n; i++) {
    if (max < a.at(i)) {
      max = a.at(i);
    }
    if (min > a.at(i)) {
      min = a.at(i);
    }
  }
   
  cout << max - min << endl;
  
  return 0;
}

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

namespace Vol0_13
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack<int> iStack = new Stack<int>();
            string sInput = "";
            // ??\??????????????????
            do
            {
                sInput = Console.ReadLine();
                if (sInput != null)
                {
                    int iInput = int.Parse(sInput);
                    if (iInput == 0)
                    {
                        Console.WriteLine("{0}", iStack.Pop());
                    }
                    else
                    {
                        iStack.Push(iInput);
                    }
                }
            } while (sInput != null);
        }
    }
}

Measured memory_bytes: 10052
#include <string>
#include <cstdio>
#include <unordered_map>
#include <deque>
#include <algorithm>
using namespace std;
typedef string key;

char b1[99],b2[99];
void main2(int n){
	unordered_map<key,deque<pair<key,long long>>>m;
	for(;n;n--){
		int d;
		scanf(" 1 %s = 10^%d %s",b1,&d,b2);
		string s1=b1,s2=b2;
		m[s1].emplace_back(s2,d);
		m[s2].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		auto s=m.begin()->first;
		deque<pair<key,long long>>st={{s,0}};
		unordered_map<key,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.begin();st.pop_front();
			auto cur=p.first;long long d=p.second;
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
					memo[e.first]=d+e.second;
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return;
				}
			}
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}
int main(){int n;for(;~scanf("%d",&n)&&n;)main2(n);}

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

#define     ll      long long
#define     pb      push_back
#define     eps     1e-9
#define     pi      acos(-1)
#define     ff      first
#define     ss      second
#define     case    cout<<"Case "<<++cs<<": ";
#define     Fast_Read                    ios_base::sync_with_stdio(false); cin.tie(nullptr);  cout.tie(nullptr);
#define     Precision(x)                 cout.setf(ios::fixed); cout.precision(x);

using namespace std;
typedef long double ld;
#ifdef ARnAb
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<"  ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************
int cs=0;
int node,query;
vector<int> adj[1000005];
bool vis[1000005];
ll val[1000005];
void bfs(int sp)
{
    queue<int>q;
    q.push(sp);
    vis[sp]=1;
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=0;i<adj[x].size();i++)
        {
            if(vis[adj[x][i]]==0)
            {
                q.push(adj[x][i]);
                vis[adj[x][i]]=1;
                val[adj[x][i]]+=val[x];
            }
        }
    }
}
void solve()
{
    cin>>node>>query;
    for(int i=0;i<node-1;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    while(query--)
    {
        int x,y;
        cin>>x>>y;
        val[x]+=y;
    }
    bfs(1);
    for(int i=1;i<=node;i++)
    {
        cout<<val[i]<<" ";
    }
}
int main()
{
    //Fast_Read
    Precision(6)
    #ifdef ARnAb
        double start_time = clock();
        ///freopen ("output.txt","w",stdout);
        ///freopen ("input.txt","r",stdin);
    #endif
    int tc=1;
    //cin>>tc;
    while(tc--)
    solve();
    return 0;
}


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

const int MAX_N=50;
int n,k,l[MAX_N];

int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> l[i];
	}
	sort(l,l+n);
	int sum=0;
	for(int i=0;i<k;i++){
		sum += l[n-1-i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256