akhauriyash/Code-Regression huggingface dataset:
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  for(var i = 0, len = input.length; i < len; i++){
    var c = input[i].trim().split(',').sort(function(a,b){return b-a;}).map(Number);
    var result = "null";
    if((c[0] == c[1] && c[1] == c[2] && c[2] == c[3]) ||
       (c[1] == c[2] && c[2] == c[3] && c[3] == c[4])
       ){
      result = "four card";
    }else if(c[0] == c[1] && c[1] == c[2] && c[3] == c[4]
             || c[0] == c[1] && c[2] == c[3] && c[3] == c[4]){
      result = "full house";
    }else if(c[0] == c[1] + 1 && c[1] == c[2] + 1 && c[2] == c[3] + 1
             && ((c[0] == 13 && c[4] == 1) || (c[3] == c[4] + 1))){
      result = "straight";
    }else if((c[0] == c[1] && c[1] == c[2])
             || (c[1] == c[2] && c[2] == c[3])
             || (c[2] == c[3] && c[3] == c[4])
             ){
      result = "three card";
    }else if((c[0] == c[1] && (c[2] == c[3] || c[3] == c[4])) || (c[1] == c[2] && c[3] == c[4])){
      result = "two pair";
    }else if(c[0] == c[1] || c[1] == c[2] || c[2] == c[3] || c[3] == c[4]){
      result = "one pair";
    }
    console.log(result);
  }
}

Measured memory_bytes: 7640
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val A = nextIntList()
    val M = A.groupBy { it }.mapValues { it.value.size }
    val d1 = M.count { it.value % 2 == 1 }
    val d2 = M.size - d1
    val ans = M.size - d2 % 2
    println(ans)
}

Measured memory_bytes: 57884
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
edge=[[] for i in range(n)]
Chk=[False]*n
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1]+=[b-1]
  edge[b-1]+=[a-1]
Ans=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  Ans[p-1]+=x
Stack=[0]
Chk[0]=True
while Stack:
  c=Stack.pop(-1)
  ad=Ans[c]
  for ob in edge[c]:
    if Chk[ob]:
      continue
    else:
      Ans[ob]+=ad
      Stack+=[ob]
      Chk[ob]=True
print(*Ans)



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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr int INF = 1e9;
constexpr long double eps = 1e-8;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> g(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> v(Q), d(Q), c(Q);
    for(int i = Q - 1; i >= 0; --i) {
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }

    vector<pii> res(N, make_pair(0, -1));
    for(int i = 0; i < Q; ++i) {
        if(res[v[i]].second >= d[i]) {
            continue;
        }
        queue<pii> que;
        que.push(make_pair(v[i], d[i]));
        if(res[v[i]].first == 0) {
            res[v[i]].first = c[i];
        }
        res[v[i]].second = d[i];
        while(!que.empty()) {
            auto p = que.front();
            que.pop();
            if(res[p.first].second > p.second) {
                continue;
            }
            for(auto& to : g[p.first]) {
                if(res[to].second >= p.second - 1) {
                    continue;
                }
                if(res[to].first == 0) {
                    res[to].first = c[i];
                }
                res[to].second = p.second - 1;
                if(p.second - 1 > 0) {
                    que.push(make_pair(to, p.second - 1));
                }
            }
        }
    }
    for(auto& p : res) {
        cout << p.first << endl;
    }
}


Measured memory_bytes: 8912
import java.util.*;

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

        int N = sc.nextInt();

        int preT = 0;
        int preX = 0;
        int preY = 0;


        for(int i = 0; i < N; i++){
            int currentT = sc.nextInt();
            int currentX = sc.nextInt();
            int currentY = sc.nextInt();

            int diff = currentT - preT;
            int distance = Math.abs(currentX - preX) + Math.abs(currentY - preY);

            if((diff < distance) || ((distance - diff) % 2 != 0)){
                System.out.println("No");
                return;
            }
            preT = currentT;
            preX = currentX;
            preY = currentY;

        }

        System.out.println("Yes");
    }
}

Measured memory_bytes: 87272
S=gets.chomp
T=gets.chomp
r=T.size
(S.size-T.size+1).times{|i|
    c=0
    T.size.times{|j|
        if S[i+j]!=T[j]
            c+=1
        end
    }
    if c<r
        r=c
    end
}
puts r


Measured memory_bytes: 14372
Sa = input()
Sb = input()
Sc = input()
turn = 0
i = 0
j = 0
k = 0
while True:
    if turn%3 == 0:
        if i > len(Sa)-1:
            print("A")
            break
        elif Sa[i] == "a":
            turn = 0
        elif Sa[i] == "b":
            turn = 1
        elif Sa[i] == "c":
            turn = 2
        i += 1
    elif turn%3 == 1:
        if j > len(Sb)-1:
            print("B")
            break
        elif Sb[j] == "a":
            turn = 0
        elif Sb[j] == "b":
            turn = 1
        elif Sb[j] == "c":
            turn = 2
        j += 1
    elif turn %3 == 2:
        if k > len(Sc)-1:
            print("C")
            break
        elif Sc[k] == "a":
            turn = 0
        elif Sc[k] == "b":
            turn = 1
        elif Sc[k] == "c":
            turn = 2
        k += 1




Measured memory_bytes: 3064
//abc099_b.cpp
//Sun Jun 10 20:59:33 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	ll total = 0;
	ll prevtotal = 0;
	ll ans = 0;

	for (int i=1;i<=999;i++){
		total = total + i;
		if (total-prevtotal == b-a){
			ans = total - b;
			break;
		}
		prevtotal = total;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); 
        int b = sc.nextInt(); 
        if (a < b) { 
            System.out.println("a < b");
            } else if(a > b) {
            System.out.println("a > b");
            } else if(a == b) {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26144
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    int x=in();
    int y=x/100;
    x%=100;
    y*=5;
    cout<<(x<=y);
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigInteger;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	for(int i=0;i<n;++i){
		BigInteger a=sc.nextBigInteger(),b=sc.nextBigInteger();
		System.out.println((a.add(b).toString().length()>80)?"overflow":a.add(b));
	}
  }
}

Measured memory_bytes: 18468
#include <iostream>
#include <cmath>
using namespace std;
int main(void){

    int a,n,m;
    cin >> a >> n >> m;

    int c=0;    
    int i=1;
    while(pow(i,n)<=m){
        int x = pow(i,n);
        int div=1;
        int y=0;
        while(x/div!=0){
            y += (x%(div*10))/div;
            div = div*10;
        }
        if(x==pow(y+a,n)) c++;
        i++;
    }
    
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int d = a, e = b, f = c;
    int tempA = a, tempB = b, tempC = c;
    int ans = 0;
    while(tempA % 2 == 0 && tempB % 2 == 0 && tempC % 2 == 0){
        tempA = (b / 2) + (c / 2);
        tempB = (a / 2) + (c / 2);
        tempC = (a / 2) + (b / 2);
        ans++;
        a = tempA;
        b = tempB;
        c = tempC;
        if(tempA % 2  || tempB % 2  || tempC % 2 ){
            break;
        }
        if(tempA == d && tempB == e && tempC == f){
            ans = -1;
            break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3640
import bisect
s = list(input())
t = list(input())
dic = {}
for i, j in enumerate(s):
    if j in dic:
        dic[j].append(i)
    else:
        dic[j] = [i]
loop = 0
if set(t) <= set(s):
    for i in range(len(t)):
        if i==0:
            idx = dic[t[0]][0]
        else:
            lis = dic[t[i]]
            idx2 = bisect.bisect_right(lis, idx)
            if idx2 == len(lis):
                loop += 1
                idx = lis[0]
            else:
                idx = lis[idx2]
    print(loop*len(s) + idx + 1)
else:
    print(-1)

Measured memory_bytes: 8928
N=gets.to_i
A=gets.chomp.split.map(&:to_i)
B=gets.chomp.split.map(&:to_i)

if A.inject(:+) < B.inject(:+)
  puts -1
  exit
end


fusoku = 0
k = []
cc = 0
0.upto(N-1) do |i|
  if A[i] < B[i]
    fusoku += B[i] - A[i]
    cc += 1
  elsif A[i] > B[i]
    k << A[i] - B[i]
  end
end

if cc == 0
  puts 0
  exit
end

k.sort!
k.reverse!

flag = false
cnt = 0
k.each do |v|
  fusoku -= v
  cnt += 1
  if fusoku <= 0
    flag = true
    break
  end
end

puts flag ? cc + cnt : -1

Measured memory_bytes: 18064
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll N;
  cin >> N;
  ll n=N;
  int ans=0;
  for(ll i=2;i*i<N;i++){
    if(N%i!=0) continue;
    int j=0;
    while(n%i==0){
      j++; n/=i;
    }
    int k=1;
    while(k<=j){
      ans++; j-=k; k++;
    }
  }

  if(n!=1) ans++;

  cout << ans << endl;


  return 0;
}


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

struct SegmentTree{
    vector<ll> node;
    ll cou;
    ll size;
    SegmentTree(int n=1, int first_value = 0){
        cou = 0;
        while( n > (int)pow(2,cou) ) cou++;
        cou++;
        node.resize((int)pow(2,cou),first_value);
        size = (int)pow(2,cou);
    }
    void update(int index, ll value ){
        update_node(convert(index),value);
    }
    void update_node(int node_index, ll value ){
        // 本人と親を更新
        
        // 処理次第
        node[node_index] = value;
        
        if( node_index == 0 ) return;
        
        ll c1,c2;
        c1 = child1(parent(node_index));
        c2 = c1+1;
        // 処理次第。最小値の場合は、左右の子の小さい方を値とする   
        ll val = min( node[c1], node[c2] );
        update_node(parent(node_index),val);
    }
    // [a,b)に対して答える
    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l){
            return INF; // 区間が被らない場合は INF を返す
        }
        if (a <= l && r <= b){
            return node[k]; // ノード k の担当範囲がクエリ区間 [a, b) に完全に含まれる
        }else {
            // 一部だけ範囲が被る場合は左右の子に委託する
            ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
            ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
            return min(c1, c2); // 左右の子の値の min を取る
        }
    }

    int parent(int node_index){
        return (node_index-1)/2;
    }
    int convert(int origin){
        return origin    +(int)(pow(2,cou-1)-1);
    }
    int rconvert(int node_index){
        return node_index-(int)(pow(2,cou-1)-1);
    }
    int child1( int node_index){
        return node_index*2+1;
    }
};

int main(void){
    ll n,q;
    std::cin >> n>>q;
    SegmentTree seg(n,(int)(pow(2,31)-1));

    for (int i = 0; i < q; i++) {
        int c,x,y;
        std::cin >> c>>x>>y;
        if(c==0){
            seg.update(x,y);
        }else{
            std::cout << seg.query(x,y+1,0,0,seg.size/2) << std::endl;
        }
    }
}



Measured memory_bytes: 5116
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

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

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

int main() {
    ll n;
    ll ans = 0;

    vector<int> d;

    cin >> n;

    for (int i = 0; i < n; i++) {
         int temp;
         cin >> temp;
         d.push_back (temp);
    }

    for (int i = 0; i < n-1; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect

a,b,q=nii()
s=[-10**18]+[int(input()) for i in range(a)]+[10**18]
t=[-10**18]+[int(input()) for i in range(b)]+[10**18]

for i in range(q):
  x=int(input())
  s_inx=bisect(s,x)
  t_inx=bisect(t,x)

  s_l=s[s_inx-1]
  s_r=s[s_inx]

  t_l=t[t_inx-1]
  t_r=t[t_inx]

  ans=10**18
  for i in [s_l,s_r]:
    for j in [t_l,t_r]:
      ans=min(ans,abs(i-x)+abs(j-i))

  for i in [t_l,t_r]:
    for j in [s_l,s_r]:
      ans=min(ans,abs(i-x)+abs(j-i))

  print(ans)

Measured memory_bytes: 17556
#include <stdio.h>

char s[200000];//文字列//

int main(void) {

	int alice;
	int bob;

	scanf("%d", &alice);
	scanf("%d", &bob);

	if (alice == bob) {
		printf("Draw\n");
	}
	else {
		if (alice == 1) {
			printf("Alice\n");
		}
		else if (bob == 1) {
			printf("Bob\n");
		}
		else if (alice > bob) {
			printf("Alice\n");
		}
		else {
			printf("Bob\n");
		}
	}


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
ll INF=1e18+5;

int main(){
    string S, T;
    cin >> S >> T;
    ll ans = INF;
    rep(i,0,S.size()-T.size()+1){
        ll tmp = 0;
        rep(j,0,T.size()){
            if(S[i+j] == T[j]) tmp++;
        }
        ans = min(ans, (ll)(T.size()) - tmp );
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
     
     
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  ll A, B, C;

  cin >> A >> B >> C;

#ifdef DEBUG
  cout << "A=" << A << " B=" << B << " C=" << C << endl;
#endif

  cout << B + min(A + B + 1, C) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

const Int MAX = 4040;
Int dp[MAX+1][MAX+1];;
string s,t;

Int nx0[MAX+1],nx1[MAX+1];
Int ny0[MAX+1],ny1[MAX+1];

Int dfs(Int x,Int y){
  if(x==MAX&&y==MAX) return 0;
  Int &res=dp[x][y];
  if(~res) return res;
  res=MAX;;
  //cout<<x<<" "<<y<<":"<<endl;
  //cout<<nx0[x]<<" "<<ny0[y]<<endl;
  //cout<<nx1[x]<<" "<<ny1[y]<<endl;
  
  chmin(res,dfs(nx0[x],ny0[y])+1);
  chmin(res,dfs(nx1[x],ny1[y])+1);
  return res;
}
void dfs2(Int x,Int y){
  if(x==MAX&&y==MAX) return;
  Int &res=dp[x][y];
  assert(~res);
  if(res==dfs(nx0[x],ny0[y])+1){
    cout<<"0";
    dfs2(nx0[x],ny0[y]);
  }else{
    cout<<"1";
    dfs2(nx1[x],ny1[y]);
  }
}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>s>>t;

  s="$"+s;
  t="$"+t;

  memset(dp,-1,sizeof(dp));

  for(Int i=0;i<=MAX;i++)
    nx0[i]=nx1[i]=ny0[i]=ny1[i]=MAX;
  
  {
    Int n=s.size(),t0=MAX,t1=MAX;
    for(Int i=n-1;i>=0;i--){
      nx0[i]=t0;
      nx1[i]=t1;
      if(s[i]=='0') t0=i;
      if(s[i]=='1') t1=i;
    }
  }

  {
    Int n=t.size(),t0=MAX,t1=MAX;
    for(Int i=n-1;i>=0;i--){
      ny0[i]=t0;
      ny1[i]=t1;
      if(t[i]=='0') t0=i;
      if(t[i]=='1') t1=i;
    }
  }

  dfs(0,0);

  //cout<<dfs(0,0)<<endl;

  
  dfs2(0,0);

  cout<<endl;
  return 0;
}



Measured memory_bytes: 130952
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
const int MAX = INT_MAX;
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}



int main() {

    ll N = lin();
    ll M = lin();
    
    if (N>=3 && M>= 3){
        cout << N*M - 2*N -2*M + 4 << endl;
        return 0;
    }
    
    if (N == 1 && M == 1){
        cout << 1 << endl;
        return 0;
    }
    
    if (N == 1 && M >=2){
        cout << M -2 << endl;
        return 0;
    }
    
    if (M == 1 && N >=2){
        cout << N-2 << endl;
        return 0;
    }
    
    
    cout << 0 << endl;  // 2*2以上でかつ、3 *3以下なら常に偶数枚と隣接

    
    
    
    return 0;
}




                          




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

const long long INF = 1e18;
const long long state[4][2] = { { 1, 1 }, { 1, -1 }, { -1, -1 }, { -1, 1 } };
 
int main() {
    int n;
    std::cin >> n;
 
    std::vector<long long> x(n), y(n);
	for (int i = 0; i < n; i++)
	    std::cin >> x[i] >> y[i];
 
    long long dbst = 0, dmax, dmin;
	for (int r = 0; r < 4; r++) {
        dmax = -INF;
        dmin = INF;
		for (int i = 0; i < n; i++) {
			long long dcur = x[i] * state[r][0] + y[i] * state[r][1];
            dmin = std::min(dmin, dcur);
            dmax = std::max(dmax, dcur);
		}
        dbst = std::max(dbst, dmax - dmin);
	}

    std::cout << dbst;
}

Measured memory_bytes: 6424
#include<stdio.h>
#define NIL -1
#define MAX 500000
int root = NIL;
int key[MAX];
int left[MAX];
int right[MAX];
//int T[MAX];
int p[MAX];
void insert(int z) {
	int y = NIL;
	int x = root;
	while (x != NIL) {
		y = x;
		if (key[z] < key[x])x = left[x];
		else x = right[x];
	}
	p[z] = y;
	if (y == NIL) {
		root = z;
	}
	else if (key[z] < key[y]) {
		left[y] = z;
	}else right[y] = z;

}
void pre(int t) {
	if (t == NIL) {
		return;
	}
	printf(" %d", key[t]);
	pre(left[t]);
	pre(right[t]);
}

void ino(int t) {
	if (t == NIL) {
		return;
	}
	ino(left[t]);
	printf(" %d", key[t]);
	ino(right[t]);
}

void print() {
	ino(root);
	printf("\n");
	pre(root);
	printf("\n");
}

int find(int t) {
	int i = 0;
	int y = NIL;
	int x = root;
	while (x != NIL) {
		if (key[x] == t) {
			return 1;
		}
		y = x;
		if (t < key[x]) {
			x = left[x];
		}else x = right[x];
	}
	return 0;
}

int main() {

	int i, nu, x;
	int y = 0;
	char AP[10];
	scanf("%d", &nu);
	for (i = 0; i < MAX; i++) {
		key[i] = NIL;
		left[i] = NIL;
		right[i] = NIL;
		//   T[MAX]=NIL;
		p[i] = NIL;
	}
	for (i = 0; i < nu; i++) {
		scanf("%s", AP);
		if (AP[0] == 'i') {
			scanf("%d", &x);
			key[y] = x;
			insert(y);
			y++;
		}
		else if (AP[0] == 'p') {
			print();
		}else if (AP[0] == 'f') {
			scanf("%d", &x);
			if (find(x) == 1) {
				printf("yes\n");
			}else printf("no\n");
		}
	}

	return 0;
}


Measured memory_bytes: 9668
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c; cin >> c;
    cout << (char)(c + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int isPrime(int x){
  int i;
  
  if(x<2) return 0;
  else if(x==2) return 1;
  if(x%2==0) return 0;
  for(i=3;i*i<=x;i+=2){
    if(x%i==0) return 0;
  }
  return 1;
}


int main(){
  int n,i,A;
  int cnt=0;

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &A);
    if(isPrime(A)==1)cnt++;
  }
  printf("%d\n", cnt);

  return 0;
}



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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, K; cin >> N >> K;
    ll H[N]; rep(i, N) cin >> H[i];
    sort(H, H+N, greater<ll>());
    //K回必殺技を使える
    ll ans = 0;
    for(int i = K; i < N; i++){
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int i=0, j, k=0, n;
    scanf("%d", &n);
    int A[n], B[n], C[2000001];
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    for(i = 0; i < 2000001; i++) C[i] = 0;

    for(i = 0; i < n; i++) C[A[i]]++;
    i = 0;
    k = 0;
    while(i < n) {
    for(j = 0; j < C[k]; j++) {
        B[i] = k;
        i++;
    }
    k++;
    }

    for(i = 0; i < n - 1; i++) printf("%d ", B[i]);
    printf("%d\n", B[n-1]);
    return 0;
}




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

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

  if(a <= 2*b){
    cout << 0 << endl;
    return 0;
  }else{
    cout << a-2*b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

ll Gcd(ll x, ll y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return Gcd(y, x%y);
}
ll lcm(ll a, ll b) {
	ll g = Gcd(a, b);
	return a / g * b;
}
int main() {
	ll A, B; cin >>  A >> B;
	cout << lcm(A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a+b==c) {
			System.out.println("Yes");
			
		} else if(a+c==b) {
			System.out.println("Yes");
			
		} else if(b+c==a) {
			System.out.println("Yes");
			
		} else {
			System.out.println("No");
		}
			
			 
  	}
}

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

int main(){
    string s,t;
    cin >> s >> t;
    /**/
    vector<int> c1[26],c2[26];
    bool moji[26] = {0};
    for(int i = 0;i < s.size();i++){
        int x = s.at(i) - 'a';
        int y = t.at(i) - 'a';
            c1[x].push_back(i);
            c2[y].push_back(i);
        
        moji[x] = 1;
        moji[y] = 1;
    }
    /**/
    /**/

    int ans[26] = {0};

    for(int i = 0;i < 26;i++){
        if((c1[i].empty())||(ans[i] == -1)) ans[i] = -1;
        else{
            for(int j = 0;j < 26;j++){
                if(c1[i] == c2[j]){
                    ans[i] = -1;
                    ans[j] = -1;
                    break;
                }
            }
        }
    }


    bool a = 1;

    for(int i = 0;i < 26;i++){
       if(ans[i] != -1){
           a = 0;
           break;
       }
    }

    if(a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }



    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int rgb[8][3] = {
	{0, 0, 0},
	{0, 0, 255},
	{0, 255, 0},
	{0, 255, 255},
	{255, 0, 0},
	{255, 0, 255},
	{255, 255, 0},
	{255, 255, 255}
};

string name[8] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

int sqr(int x) { return x * x; }

void search(string str) {
	string input = str.substr(1, 2) + " " + str.substr(3, 2) + " " + str.substr(5, 2);
	
	int col[3];
	sscanf(input.c_str(), "%x %x %x", &col[0], &col[1], &col[2]);
	
	int min_dst = 1L << 30, ans = -1;
	
	for_(i,0,8) {
		int dst = 0;
		
		for_(j,0,3) {
			dst += sqr(rgb[i][j] - col[j]);
		}
		
		if (min_dst > dst) {
			min_dst = dst;
			ans = i;
		}
	}
	
	cout << name[ans] << endl;
}

int main() {
	string str;
	while (cin >> str, str != "0") search(str);
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
    int N, M;

    // Define Blue Cards
    cin >> N;
    vector<string> s(N);
    for(int i=0; i<N; i++){
        cin >> s.at(i);
    }

    // Define Red Cards
    cin >> M;
    vector<string> t(M);
    for(int i=0; i<M; i++){
        cin >> t.at(i);
    }

    int result=0;

    for(int i=0; i<N; i++){
        int blue=0;
        int red=0;

        for(int j=0; j<N; j++){
            if(s.at(i) == s.at(j)){
                blue++;
            }
        }
        for(int j=0; j<M; j++){
            if(s.at(i) == t.at(j)){
                red++;
            }
        }
        if(result < blue - red){
            result = blue - red;
        }
    }
    cout << result << endl;
} 

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

int main()
{
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	for(auto&& i : b)
	{
		cin >> i;
	}
	int ans = 0;
	while(n--)
	{
		int score = c;
		for(int i = 0; i < m; i++)
		{
			int a;
			cin >> a;
			score += a * b[i];
		}
		ans += score > 0;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long n, a, b, c, d, e, f;
int main() {
	cin >> n;
	for (a = 1; a <= 3500; a ++)
		for (b = 1; b <= 3500; b ++) {
			long long x = n * a * b;
			c = 4 * a * b - b * n - a * n;
			if (c <= 0) continue;
			if (x > c && x % c == 0) {
				c = x / c;
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
		}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[11111];
main()
{
    while(cin>>n,n)
    {
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        long ans=0,sum=0;
        for(int i=0;i<n;i++)
        {
            ans+=sum;
            sum+=a[i];
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3164
N,M,*A = `dd`.split.map &:to_i
Mod = 10**9 + 7
dp = Array.new(N+1,0)
dp[0] = 1
Broken = Hash[A.map{ |a| [a,1] }]
(0...N).each{ |i|
  if !Broken[i+1]
    dp[i+1] = (dp[i+1] + dp[i]) % Mod
  end
  if i+2 <= N && !Broken[i+2]
    dp[i+2] = (dp[i+2] + dp[i]) % Mod
  end
}

p dp[-1]


Measured memory_bytes: 21256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
typedef pair<int,int> P ;
int main() {
  
  int N  ;
  cin >> N  ;
  vector<P> A(N) ;
  for ( int i = 0 ; i < N ; i++ ){
    cin >> A[i].first ;
    A[i].second = i+1;
  }
  sort(A.begin(),A.end());
  rep(i,N){
  cout << A[i].second <<endl;
  }
}


Measured memory_bytes: 1536
#include <stdio.h>
int main()
{
  int n, i, x, a;
  scanf("%d",&n);

  for(i=1;i<=n;i++){
    x=i;
    if(x%3==0){
      printf(" %d",i);
      continue;
    }
    if(x%10==3){
      printf(" %d",i);
      continue;
    }
    x/=10;
    if(x%10==3){
      printf(" %d",i);
      continue;
    }
    x/=10;
    if(x%10==3){
      printf(" %d",i);
      continue;
    }
    x/=10;
    if(x%10==3){
      printf(" %d",i);
      continue;
    }  
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define lint long long
#define db long double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
typedef pair<int,int> pii;
typedef set<int>::iterator sit;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
const int N=100010;vector<int> v[N];
int main()
{
	int n=inn(),k=0,cnt=0;
	if(n==1) return !printf("Yes\n2\n1 1\n1 1\n");
	rep(i,1,n) if((lint)i*(i-1)/2==n) { k=i;break; }
	if(!k) return !printf("No\n");
	rep(i,1,k) rep(j,i+1,k) cnt++,v[i].pb(cnt),v[j].pb(cnt);
	printf("Yes\n%d\n",k);
	rep(i,1,k)
	{
		printf("%d ",(int)v[i].size());
		Rep(j,v[i]) printf("%d ",v[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll cnt=0,res=-INF_LL,N,F[100][5][2],P[100][11];
  cin >> N;
  REP(i,N)REP(j,5)REP(k,2)cin >> F[i][j][k];
  REP(i,N)REP(j,11)cin >> P[i][j];
  
  for(int j=1;j< (1 << 10) ;j++){
    int arr[101]={0};
    REP(i,101)arr[i] = 0;
    for(int k=0;k<10;k++){
      if((j >> k) & 1){
        for(int d=0;d<N;d++)
          if(F[d][k/2][k%2] == 1)
            arr[d]++;
      }
    }
    cnt = 0;
    REP(i,N)cnt += P[i][arr[i]];
    
    res = max(cnt,res);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	static int a, b;
	static long s[][];

	public static int half(int at, long x) {
		int l = 0, r = a + 1;
		if (at == 1)
			r = b + 1;
		int mid;
		while (l + 1 < r) {
			mid = (r + l) / 2;
			if (s[at][mid] >= x)
				r = mid;
			else
				l = mid;
		}
		return r;
	}

	public static long solve(long x) {
		long ans = 0;
		int sa, sb, ta, tb;
		long min = (long) Math.pow(10, 18);
		sb = half(0, x);
		sa = sb - 1;
		tb = half(1, x);
		ta = tb - 1;
		//System.out.println(sb + " " + tb + "?");
		for (int i = sa; i <= sb; ++i) {
			for (int j = ta; j <= tb; ++j) {
				ans = Math.abs(s[0][i] - x) + Math.abs(s[1][j] - s[0][i]);
				//System.out.println(ans + " ?");
				min = Math.min(ans, min);
				ans = Math.abs(s[1][j] - x) + Math.abs(s[0][i] - s[1][j]);
				min = Math.min(ans, min);
			}
		}
		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		int q = sc.nextInt();
		s = new long[2][Math.max(a, b) + 2];
		for (int i = 1; i <= a; ++i)
			s[0][i] = sc.nextLong();
		s[0][a + 1] = (long) Math.pow(10, 18);
		s[0][0] = -1 * s[0][a + 1];
		for (int i = 1; i <= b; ++i)
			s[1][i] = sc.nextLong();
		s[1][b + 1] = (long) Math.pow(10, 18);
		s[1][0] = -1 * s[1][b + 1];
		long x;
		for (int i = 0; i < q; ++i) {
			x = sc.nextLong();
			//System.out.println(x + "??");
			System.out.println(solve(x));
		}
		sc.close();
	}

}


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

using namespace std;

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

    int X, Y;
    cin >> X >> Y;
    int p[206]{300'000, 200'000, 100'000};
    int res = p[X - 1] + p[Y - 1] + (X == 1 && Y == 1 ? 400'000 : 0);
    cout << res << "\n";

    return 0;
}

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

vector<int> a[1000];
int hei[1000] , vis[1000] , mx=0 , ans=0;

void bfs( int root ){
	
	memset(vis,0,sizeof vis);
	memset(hei,0,sizeof hei);

	queue<int> q;
	q.push(root);
	vis[root] = 1;
	hei[root] = 0;
 
	while(q.size()){
		int f = q.front();
		q.pop();
 
		for(auto i : a[f]){
			if( !vis[i] ){
				q.push(i);
				vis[i] = 1;
				hei[i] = hei[f] + 1;
				ans = max( ans , hei[i] );
				if(hei[i] > hei[mx])
					mx = i;
			}
		}
	}
}

void add ( int u , int v ){
	a[u].push_back(v);
	a[v].push_back(u);
}

int main(){

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	int h,w;
	cin>>h>>w;

	char g[h][w];
	int root = -1;

	for(int i=0 ; i<h ; ++i)
		for(int j=0 ; j<w ; ++j){
			cin>>g[i][j];
			if(g[i][j] == '.')
				root = i*w + j;
		}


	for(int i=0 ; i<h-1 ; ++i)
		for(int j=0 ; j<w ; ++j)
			if( g[i][j] == '.' && g[i+1][j] == '.' )
				add( i*w + j , (i+1)*w + j );


	for(int i=0 ; i<h ; ++i)
		for(int j=0 ; j<w-1 ; ++j)
			if( g[i][j] == '.' && g[i][j+1] == '.' )
				add( i*w + j , i*w + j+1 );


	if(root == -1){
		cout<<0;
	}
	else{

		for(int i=0 ; i<h ; ++i)
			for(int j=0 ; j<w ; ++j)
				if( g[i][j] == '.' )
					bfs( i*w + j );
	}

	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1111];
int main()
{
	int n,k,total=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++)
		total+=a[i];
	cout<<total;	
	return 0; 
 } 

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

struct uft{
    vector<ll> par;
    uft(ll n) {
        par.resize(n);
        rep(i,n)par[i]=i;
    }

    ll find(ll a){
        if(par[a]==a){
            return a;
        }else {
            return find(par[a]);
        }
    }

    void unite(ll a,ll b){
        par[find(a)]=find(b);
    }

    bool same(ll a,ll b){
        return find(a) == find(b);
    }
};

struct edge{
    ll s,t,w;
};

bool sortw(edge a,edge b) {
    return a.w < b.w;
}

int main() {
    ll v,e;
    cin>>v>>e;
    vector<edge> edges;
    rep(i,e){
        ll s,t,w;
        cin>>s>>t>>w;
        edges.push_back(edge{s,t,w});
    }
    sort(edges.begin(),edges.end(),sortw);
    ll sum=0;
    uft uni(v);
    rep(i,e){
        if(!uni.same(edges[i].s,edges[i].t)) {
            uni.unite(edges[i].s,edges[i].t);
            sum+=edges[i].w;
        }
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 6004
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(void)
{
	long long i, no, X, Y;
	scanf("%lld %lld", &X, &Y);

	no = 1000000000000000000 / X;

	if ( X==Y ||
		(X>Y && !(X%Y)) ){printf("-1"); return 0;}
	
	for(i=2;i<=no;i++){	
		if ((X * i) % Y){ 
			printf("\n%lld",X*i); return 0;
		}
	}
	printf("\n-1");
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int x,y,m,ans = INF;
vector<int> v,vv;

signed main() {
    cin >> x >> y >> m;
    rep(i,x) {
        int a;
        cin >> a;
        v.pb(a);
    }
    rep(i,y) {
        int b;
        cin >> b;
        vv.pb(b);
    }
    rep(i,m) {
        int a,b,c;
        cin >> a >> b >> c;
        --a, --b;
        ans = min(ans, v[a] + vv[b]-c);
    }
    sort(all(v));
    sort(all(vv));
    ans = min(ans, v[0] + vv[0]);
    cout << ans << endl;
}


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

using namespace std;
using ll = long long int;

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

    vector<ll> val(2019 + 10, 0);
    ll tenfactor = 1;
    ll cur = 0;

    val[cur]++;

    for (int i = 0; i < s.size(); i++)
    {
        cur = (cur + (s[s.size() - i - 1] - '0') * tenfactor) % 2019;
        tenfactor = (tenfactor * 10) % 2019;
        val[cur]++;
    }

    ll res = 0;
    for (int p = 0; p < 2019; p++)
    {
        res += val[p] * (val[p] - 1) / 2;
    }

    cout << res << endl;
}

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

int main(){
    
    int N;
    cin>>N;
    int ans=0;
    vector<int> test(N+1);
    for(int i=0;i<N;i++){
        cin>>test.at(i);
    }

    for(int a=0;a<N;a++){
     for(int b=0;b<N;b++){
      for(int c=0;c<N;c++){
    
if(a<b&&b<c&&a!=b&&b!=c&&c!=a&&test.at(a)!=test.at(b)&&test.at(a)!=test.at(c)&&test.at(c)!=test.at(b)&&test.at(a)<test.at(c)+test.at(b)&&test.at(b)<test.at(c)+test.at(a)&&test.at(c)<test.at(a)+test.at(b)){
ans=ans+1;
}

    }
    }
    }
    
     
    cout<<ans<<endl;
   
   
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define REP(i,a,b,c) for(int i=a;i<=b;i+=c)
const int N = 1e5+5;
const int maxVal=1e4+5;
int a[N];
int dp[N];
using namespace std;
signed main(){
	int n;cin>>n;
	REP(i,0,n-1,1)cin>>a[i];
	REP(i,0,N-1,1) dp[i]=maxVal;
	dp[n-2]=abs(a[n-1]-a[n-2]);
	dp[n-3]=abs(a[n-1]-a[n-3]);
	int i=n-4;
	while(i>=0){
		dp[i]=min(dp[i+1]+abs(a[i+1]-a[i]),dp[i+2]+abs(a[i+2]-a[i]));
		i--;
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 4356
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll lcm(ll a, ll b)
{
   return a / gcd(a, b) * b;
}

int main()
{
    int h,w;
    cin >> h >> w;
    char a[h][w];
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }

    vector<bool> gyou(h,false);

    rep(i,h){
        rep(j,w){
            if(a[i][j] != '.') gyou[i] = true;
        }
    }

    vector<bool> retu(w,false);

    rep(i,w){
        rep(j,h){
            if(a[j][i] != '.') retu[i] = true;
        }
    }

    rep(i,h){
        rep(j,w){
            if(gyou[i] && retu[j]) cout << a[i][j];
            if(gyou[i] && j == w-1) cout << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let s: Vec<i64> = s
        .trim()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as i64)
        .collect();
    let mut dp: Vec<i64> = [0, 1].to_vec();
    for &c in s.iter() {
        let tmp1 = std::cmp::min(dp[0] + c, dp[1] + 10 - c);
        let tmp2 = std::cmp::min(dp[0] + c + 1, dp[1] + 10 - (c + 1));
        dp[0] = tmp1;
        dp[1] = tmp2;
    }
    println!("{}", dp[0]);
}

Measured memory_bytes: 14588
s=sorted
n,k,*a=map(int,open(i:=0).read().split())
l=s([-a,i:=i+1]for a in a)
_,r=zip(*l)
exec('*_,b=r\nfor t in s(l):\n if t[1]-b:t[t[0]>-2<exit(print(-1))]+=1;r+=t[1],\n'*k)
print(len(r),*r)

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

int main(){
    long long ans=0,sum=0;
    int n;
    long long A=0,B=0;
    cin >> n;
    
    int a[n];

    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    

    for (int i = 0; i < n-1; i++){
        
        if(a[i]==a[i+1]){
            A=a[i];
            
            i+=2;

            for (int j = i; j < n-1; j++){
                
                if(a[j]==a[j+1]){
                    B=a[j];
                    break;
                }
            }

            break;
        }
    }
    
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << A*B << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int a,b,k;
  cin >> a >> b >> k;
  vec t;
  RFOR(i, 1, min(a,b) + 1){
    if(a % i == 0 && b % i == 0){
      t.push_back(i);
    }
  }

  cout << t[k - 1] << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import deque

h,w = map(int,input().split())
m = [input() for _ in range(h)]
vm  = [[-1] * w for _ in range(h) ]

q = deque()

for i in range(h):
    for j in range(w):
        if m[i][j] == '#':
            q.append((i,j))
            vm[i][j]=0

while q:
    y,x = q.popleft()
    d = vm[y][x]

    for i,j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
        yi , xj = y + i , x + j
        if yi >= 0 and xj >= 0 and yi < h and xj < w and vm[yi][xj] == -1 :
            vm[yi][xj] = d +  1
            q.append([yi,xj])
            

print(d)


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

int main(){
  
  int a;
  double b;
  cin >> a;
  
  b = (a+1)/2;
  
  if( a%2 == 0 ){
    
    cout << "0.5000000000" << endl;
    
  }
  
  else{
    
    cout << b/a << endl;
    
  }
  
}


Measured memory_bytes: 3756
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    lp(i,0,n)
        cin>>a[i],c[i]=i+1;
    lp(i,0,n)
        cin>>b[i];
    int cnt=1,x=0,y=0;
    do{
        if(c==a)
            x=cnt;
        if(c==b)
            y=cnt;
        cnt++;
    }while(next_permutation(all(c)));
    cout<<abs(x-y);
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,m;
    cin>>n>>m;
    int ans;
    if(n*2<m){
        ans=m-n*2;
        cout<<n+ans/4<<endl;
    }
    else{
        cout<<m/2<<endl;
    }
}


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

int N, M;
vector<int> H;
vector<int> ma;

int main(){
    cin >> N >> M;
    H.resize(N);
    ma.resize(N);

    for (int i = 0; i < N; i++){
        cin >> H[i];
        ma[i] = 0;
    }
    for (int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        ma[a - 1] = max(ma[a - 1], H[b - 1]);
        ma[b - 1] = max(ma[b - 1], H[a - 1]);
    }

    int count = 0;
    for (int i = 0; i < N; i++){
        count += H[i] > ma[i];
    }
    cout << count << endl;
}

Measured memory_bytes: 3988