akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; cin >> n;
    set<char> st;
    REP(i,n){char c; cin >> c; st.insert(c);}
    if(st.size()==3) out("Three");
    else out("Four");

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
r = [0 for i in range(n+1)]
t = [0 for i in range(n+1)]
for ai in a:
    r[ai] += 1
def c2(n):
    return n * (n-1) // 2
t = list(map(lambda i:c2(i-1), r))
r = list(map(c2, r))
s = sum(r)
for i in range(n):
    l = a[i]
    print(s - r[l] + t[l])

Measured memory_bytes: 26140
S = input()

flag = 0
N = len(S)

s1 = int((N-1)/2)
s2 = int((N+3)/2)


if S[0:s1] == S[s1+1:]:
  flag = 1
else:
  flag = 0    

if S[s2-1:] == S[:s2-2]:
  flag = 1
else:
  flag = 0
  
if flag == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int main(){
	string sa,sb;
	ull la,lb,lc;
	cin>>sa;
	cin>>sb;
	la=sa.size();
	lb=sb.size();
	if(la>lb)
		cout<<"GREATER";
	else if(la<lb)
		cout<<"LESS";
	else{
		if(sa>sb)
			cout<<"GREATER";
		else if(sa<sb)
			cout<<"LESS";
		else if(sa==sb)
			cout<<"EQUAL";
	}
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] P = new int[n];
        int c = 0;
        Arrays.setAll(P	, i -> sc.nextInt());
        for(int i = 1; i < n-1; i++) {
            if(Math.min(P[i-1], P[i+1]) < P[i] &&  P[i] < Math.max(P[i-1], P[i+1])) c++;
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 27860
n = int(input())
As = list(map(int, input().split()))
q = int(input())
Ds = [0] * (10 ** 5 + 1)
Es = [i for i in range(10 ** 5 + 1)]
for a in As:
  Ds[a] += 1
ans = sum(As)
for i in range(q):
  b, c = map(int, input().split())
  ans += Ds[b] * (c-b)
  Ds[c] += Ds[b]
  Ds[b] = 0
  print(ans)

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

    int ma=0;
    int mi = 100001;
    for(int i=0;i<M;i++){
        cin>>L[i]>>R[i];
       ma = max(ma,L[i]);
        mi = min(mi,R[i]);
    }
    if(ma<=mi){
        cout<<mi-ma+1<<endl;
    }else
    {
        cout<< 0 <<endl;
    }
}

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

int main() {
  int A,B,C;
    
    cin >> A >> B >> C ;
  
  if ( (A==5 && B==5 && C==7) ||  
      (A==5 && B==7 && C==5) ||
      (A==7 && B==5 && C==5))
  {
    cout << "YES" << endl;
  }
    else
  {
    cout << "NO" << endl;
  }
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



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

	int n;
	cin >>n;
	VI t(n), x(n), y(n);
	rep(i,n) cin >>t[i] >>x[i] >>y[i];
	
	int cx=0, cy=0, ct=0;
	rep(i,n){
		ll wl = abs(x[i]-cx) + abs(y[i]-cy);
		ll wt = t[i] - ct;
	
		if(wl > wt || wl%2 != wt%2){
			puts("No"); return 0;
		}
		ct = t[i];
		cx=x[i]; cy=y[i];
	}
	puts("Yes");
	return 0;
	
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,s;
  cin>>k>>s;
  int cnt=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int d=s-i-j;
      if(0<=d&&d<=k)cnt++;
    }
  }
  cout<<cnt<<endl;
  return(0);
}


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

using namespace std;

struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(it,v) for(auto &it:v)

int main(){
    int N,sum=0;
    cin>>N;
    vector<int> L(2*N);
    range(it,L)cin>>it;
    sort(L.begin(),L.end());
    for(int i=0;i<N;i++)sum+=L[2*i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    a, b, n = nm()

    x = min(b - 1, n)
    ans = math.floor(a * x / b)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9736
#include <bits/stdc++.h>
#define int long long

using namespace std;
using ll = long long;

const int N = (int)1e6 + 5;

int p[N], sz[N], cnt[N], ct[N];

int get_root(int v) {
  if (p[v] == v) {
    return v;
  }
  return p[v] = get_root(p[v]);
}

void union_set(int a, int b) {
  int ra = get_root(a);
  int rb = get_root(b);
  if (ra == rb) return;
  if (sz[ra] < sz[rb]) swap(ra, rb);
  p[rb] = ra;
  sz[ra] += sz[rb];
}

main() {
  ios :: sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    sz[i] = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    union_set(a, b);
    ++cnt[a];
    ++cnt[b];   
  }
  for (int i = 1; i <= k; ++i) {
    int a, b;
    cin >> a >> b;
    int ra = get_root(a);
    int rb = get_root(b);
    if (ra == rb) {
      ++ct[a];
      ++ct[b];
    }    
  }
  for (int i = 1; i <= n; ++i) {
    int ri = get_root(i);
    cout << sz[ri] - (cnt[i] + ct[i]) - 1 << ' ';
  }
  return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1], C = l[2];

            Console.WriteLine(A + B >= C ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let [| a; b |] = reada int
    let s = Array.init b (fun _ -> string a) |> fun x -> String.Join("", x)
    let t = Array.init a (fun _ -> string b) |> fun x -> String.Join("", x)
    min s t |> puts
    ()

main()
writer.Close()


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

for i in range(len(s)):
    if s[i] == 'C'or s[i] == 'G' or s[i] == 'T':
        s[i] = 'A'

s = ''.join(s)
n = s.count('A')

for i in range(n+1)[::-1]:
    if 'A' * i in s:
        print(i)
        break
else:
    print(0)

Measured memory_bytes: 9132
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long a = long.Parse(input[1]);
            long b = long.Parse(input[2]);
 
            long MOD = 1000000000 + 7;
 
            
            
            //まずは総和を計算
            //繰り返し二乗法を使う方法
            long ans = modpow(2,n,MOD);
            
 
            if(n/2 < a)
                 a = n - a;
            
            if(n/2 < b)
                 b = n - b;
 
            long a_sum = 1;
            long b_sum = 1;
            long a_sum_u = 1;
            long b_sum_u = 1;

            //分子の方をかける
            for(long i = 0;i < a;i++)
            {
                    a_sum *= n - i;
                    a_sum %= MOD;
            }
 
            //分母の方を割る
            for(long i = 0;i < a;i++)
            {
               a_sum_u *= i + 1;
               a_sum_u %= MOD;
            }

            //nCaを求める
            a_sum = a_sum * modpow(a_sum_u,MOD-2,MOD);
            a_sum %= MOD;
 
            //分子の方をかける
            for(long i = 0;i < b;i++)
            {
                    b_sum *= n - i;
                    b_sum %= MOD;
            }
 
            //分母の方を割る
            for(long i = 0;i < b;i++)
            {
                b_sum_u *= i + 1;
                b_sum_u %= MOD;
            }

            //nCbを求める
            b_sum = b_sum * modpow(b_sum_u,MOD-2,MOD);
            b_sum %= MOD;


            //最初の数からa,bのケースを引く
            ans -= a_sum;
            ans -= b_sum;
            ans -= 1;
            //最後に割る
            ans %= MOD;

            //負のときは絶対値を戻す
            if(ans < 0)
               ans = MOD - Math.Abs(ans);

            //出力
            Console.WriteLine(ans);
 
        }

        //繰り返し二乗法で求める
        static long modpow(long a, long n,long MOD)
        {
            if(n == 0)
                return 1;
            if(n % 2 == 0)
            {
                long temp = modpow(a, n/2, MOD);
                return temp*temp % MOD;
            }
            
            return a * modpow(a,n-1,MOD) % MOD;
        }
    }

Measured memory_bytes: 11092
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans

while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    print(get_num(n, x))

Measured memory_bytes: 6364
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

S = S[::-1]
T = T[::-1]

res = list()

for i in range(len(S)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                #print(T[k-i])
                ans += T[k-i]
            elif S[k] != "?":
                #print("B")
                ans += S[k]
            else:
                #print("C")
                ans += "a"
        ans = ans[::-1]
        res.append(ans)

if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")
#print(S)
#print(T)

Measured memory_bytes: 9104
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			sum = sum + a;
		}
		
		if (n < sum) {
			System.out.println("-1");
		} else {
			System.out.println(n - sum);
		}
	}
}

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

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		String S  = keyboard.next();
		String ans = "YES";
		
		for(int i = 0; i < S.length();) {
			if(S.length() - i >= 5) {
			//ここまでの判定に使った文字の残りが単語の文字数を充足する場合	に処理	
				if(S.substring(i,i+5).equals("dream")){
					if(S.length()-(i+5) >= 3 && S.substring(i+5,i+8).equals("era")) {
						i += 5;
						continue;
					}else if(S.length()-(i+5) >= 2 && S.substring(i+5,i+7).equals("er")) {
						i += 7;
						continue;
					}else {
						i += 5;
						continue;
						}
				}else if(S.substring(i,i+5).equals("erase")){
					if(S.length()-(i+5) >= 1 && S.substring(i+5,i+6).equals("r")) {
						i += 6;
						continue;
					}else {
						i += 5;
						continue;
						}
				//文字列が単語を成さなかった場合
				}else {
					ans = "NO";
					break;
				}
			//文字の残りが単語の文字数を充足しない場合				
			}else{
				ans = "NO";
				break;
			}
		}

		System.out.println(ans);
		keyboard.close();	
	}
}


Measured memory_bytes: 29236
import heapq

n, m = map(int, input().split())
a = []

for i in input().split():
  heapq.heappush(a, -int(i))

for j in range(m):
  highest = heapq.heappop(a)
  heapq.heappush(a, -(-highest // 2))

print(-sum(a))



Measured memory_bytes: 82352
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>
#define FOR(i,a,b) for(int (i)=(a);(i)<int(b);(i)++)
using namespace std;

const int MAX_V = 1000; // ????????°????????§???
const int MAX_E = 2000; // ????????°????????§???
const int INF = INT_MAX;

struct E{
  int to, cost;
  E(int t, int c) : to(t), cost(c){};
};

typedef pair<int,int> pii;

int v; // ????????°
vector<E> g[MAX_V]; // ??£??\?????????
int d[MAX_V]; // ??????s????????????????????¢

bool bellmanford(int s)
{
  fill(d,d+v,INF);
  d[s] = 0;

  // ??????s??????????????¨???k+1???????????????????????????????????¢???
  FOR(k,0,v){
    // ??????1?????????????????¨???
    FOR(j,0,v){
      int from = j;
      // ??????????§??????¨????????¨???????????????????????????????????????
      FOR(i,0,g[from].size()){
        int to = g[from][i].to;
        int cost = g[from][i].cost;

        if(d[from] != INF && d[to] > d[from] + cost){ // ???????????¢??¨??????????????´???
          d[to] = d[from] + cost;

          /* ????????????????????¨??????????????°?????????????????????????????????????????????
             ???????????£??????v???????????????????????¢????????????????????????????????°????????????????????¨ */
          if(k == v - 1) return false;
        }
      }
    }
  }

  return true;
}

int main()
{
  int gv, ge, gr; // gv???????????°???ge???????????°???gr????§????
  cin >> gv >> ge >> gr;
  v = gv;
  FOR(i,0,ge){
    int gs, gt, gd;
    cin >> gs >> gt >> gd; // ge??????????§???????gt??????????????????gd???????????????
    g[gs].push_back(E(gt,gd));
  }

  if(bellmanford(gr)) // ???????????????????????´???
    FOR(i,0,v){
      if(d[i] != INF)
        cout << d[i] << endl;
      else // ??????i?????????????????´???
        cout << "INF" << endl;
    }
  else
    cout << "NEGATIVE CYCLE" << endl;
}

Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x: a) cin >> x;

  int ans = 1000000007;
  for (int i = 1; i <= 100; i++) {
    int cost = 0;
    for (int j = 0; j < n; j++) {
      cost += (i - a[j]) * (i - a[j]);
    }
    if (cost < ans) {
      ans = cost;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
typedef vector<int> Vi;
typedef vector<P> Vp;
int const MOD = 1000000007;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n,ans=0; cin>>n; n--; int a[n];
    for (int i = 0; i < n; i++)cin>>a[i];
    for (int i = n-1; i >= 0; i--){
        if(i==n-1)ans+=a[i];
        else ans+=min(a[i+1],a[i]);
    }
    cout<<ans+a[0]<<'\n';
}

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

int main(){
  int N, n;
  int N_sum=0;
  
  cin >> N;
  n = N;
  
  for (int i=0;i<9;i++){
    N_sum += n%10;
    n /= 10;
  }
  
  if (N%N_sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3568
import java.io.*;
import java.util.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        long N = Long.parseLong(st.nextToken());
        int[] primeFactors = new int[10000000];
        long n = N;
        for (long i=2; i*i<=n+2; i++){
            while(N%i==0){
                primeFactors[(int)i]++;
                N/=i;
            }
        }
        int ans=0;

        for (long i=2; i*i<=n+2; i++){
            int cur=primeFactors[(int)i];
            for (int k=1; k<=cur; k++){
                cur-=k;
                ans++;
            }

        }
        if (N!=1)
            ans++;
        System.out.println(ans);



    }



}


Measured memory_bytes: 71796
a = input()

if a[0]=="A":
  if a[2:-1].count("C")==1:
    s = a[2:-1].replace("C","") + a[-1]
    if a[1].islower() and s.islower():
      print("AC")
    else:
      print("WA")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
from collections import Counter
def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            siz[a]+=siz[b]
        else:
            par[a]=b
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
            
def size(a):
    return siz[find(a)]

def same(a,b):
    return find(a)==find(b)

N,K,L=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]

for i in range(K):
    p,q=map(lambda x:int(x)-1,input().split())
    union(p,q)
    
road=[find(i) for i in range(N)]
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]
for i in range(L):
    r,s=map(lambda x:int(x)-1,input().split())
    union(r,s)
li=[(road[i],find(i)) for i in range(N)]
c=Counter(li)
for i in range(N):
    print(c[li[i]],end=' ')
print()

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REP2(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
typedef long long ll;

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

    int maxl = 1;
    int minr = 100000;
    rep(i, m){
        int l, r; cin >> l >> r;
        maxl = max(maxl, l);
        minr = min(minr, r);
    }
    int ans = 0;
    if(maxl <= minr){
        ans = minr - maxl + 1;
        OP(ans);
    }else{
        OP(ans);
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N; 
vector<double> X, Y;
double g(double x, double y){
  double ret = 0;
  REP(i, N){
    chmax(ret, sqrt((X[i]-x)*(X[i]-x)+(Y[i]-y)*(Y[i]-y)));
  }
  return ret;
}

double f(double x){
  double l1 = -1001;
  double l2 = 1001;
  REP(i, 100){
    double m1 = (l1*2+l2*1)/3;
    double m2 = (l1*1+l2*2)/3;

    if(g(x, m1) > g(x, m2)) l1 = m1;
    else l2 = m2;
  }
  return g(x, l1);
}

signed main() {
  cin >> N;

  X.resize(N); Y.resize(N);
  REP(i, N) cin >> X[i] >> Y[i];

  double r1 = -1001;
  double r2 = 1001;
  REP(i, 100){
    double m1 = (r1*2+r2*1)/3;
    double m2 = (r1*1+r2*2)/3;

    if(f(m1) > f(m2)) r1 = m1;
    else r2 = m2;
  }

  cout << f(r1) << "\n";

  return 0;
}

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

using namespace std;


int main() {

  int h,w,d;
  int n;
  int r;

  double min_r;


  while(cin >> h >> w >> d) {

    if(h==0 && w==0 && d==0) break;

    cin >> n;

    if(sqrt(h*h+w*w)>sqrt(w*w+d*d)) {

      if(sqrt(w*w+d*d)>sqrt(d*d+h*h)) min_r=sqrt(d*d+h*h)/2.0;

      else min_r=sqrt(w*w+d*d)/2.0;

    }

    else {
	
      if(sqrt(h*h+w*w)>sqrt(d*d+h*h)) min_r=sqrt(d*d+h*h)/2.0;

      else min_r=sqrt(h*h+w*w)/2.0;
      
    }

    //cout << min_r << endl;

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

      cin >> r;

      if(min_r<(double)r) cout << "OK" << endl;

      else cout << "NA" << endl;

    }

  }

  return 0;

}

      

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

const int mxn = 405;
ll dp[mxn][mxn];
ll INF = 1e18 + 100;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	auto sum = [&](int L, int R) {
		ll s = 0;
		for (int i = L; i <= R; i++) {
			s += a[i];
		}
		return s;
	};

	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R) {
				dp[L][R] = 0;
			} else {
				dp[L][R] = INF;
				ll s = sum(L, R);
				for (int i = L; i <= R - 1; i++) {
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
				}
			}
		}
	}

	cout << dp[0][n - 1] << endl;
}

int main() {
    FAST_INPUT;

    solve();
    return 0;
}


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

int a,b,c,d[100000],ans;
int main(){
    cin>>a;
    for(int i = 1; i <= a; i++){
        cin>>d[i];
    }
    sort(d+1,d+a+1);
    for(int i = 1; i <= a; i++){
        int t = 0;
        for(int j = i + 1; j <= a; j++){
            while(d[t+1]<=d[i]+d[j]-1 && t+1<=a){
                t++;
            }
            ans+=t-j;
        }
    }
    cout<<ans;
}


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

	int main(void){
		int train[100];
		int count = 0;
		int n;
		while(cin >> n){
			if(n > 0){
				train[count] = n;
				count++;
			}else if(n == 0){
				count--;
				cout << train[count] << endl;
			}
		}
		return 0;

	}

Measured memory_bytes: 3096
#include <cstdio>

int main(){
	int n, m;
	static int dict[256];
	char k, v, x;
	while (scanf("%d\n", &n)){
		if (!n) return 0;
		for (int i = 0; i<256; i++) dict[i] = i;
		for (int i = 0; i<n; i++){
			scanf("%c %c\n", &k, &v);
			dict[(int)k] = (int)v;
		}
		scanf("%d\n", &m);
		for (int i = 0; i<m; i++){
			scanf("%c\n", &x);
			printf("%c", dict[(int)x]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1004
# coding: utf-8
# Your code here!

def is_prime(x):
    for i in range(2,x+1):
        if x < i * i:
            return True
        if x % i == 0:
            return False

x = int(input())
for i in range(x,2*x+1):
    if is_prime(i):
        print(i)
        break


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define pi acos(0.0)
#define ll long long
#define f first
#define s second
#define gap ' '
#define pb push_back
int main()
{
    int n,k;
    cin>>n>>k;
    if(((n-2)*(n-1))/2 < k)
    {
        cout<<-1;
        return 0;
    }
    pair<int,int> ara[100005];
    int m=0;
    for(int i=2;i<=n;i++)
    {

       ara[m].f=1;
       ara[m].s=i;
       m++;

    }
    vector<pair<int,int> >p;
    for(int i=2;i<=n;i++)
    {
       for(int j=i+1;j<=n;j++)
       {
          p.pb({i,j});
       }
    }
    for(int i=0;i<((n-2)*(n-1))/2-k;i++)
    {
        ara[m]=p[i];
        m++;

    }
    cout<<m<<endl;
    for(int i=0;i<m;i++)
    {
        cout<<ara[i].f<<gap<<ara[i].s<<endl;
    }


}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


int main(void){
    int n,a,b;
    cin >> n >> a >> b;
    int ans;
    if (n*a>b)
    {
        ans=b;
    }
    else
    {
        ans=a*n;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3636
class Integer

  # O(min(n-k,k) log m)
  # combination: nPk / k! (mod p), note: m must be a prime number
  def cmb(k, m=10**9+7)
    n = self
    k = n - k if k > n - k
    n.prm(k, m) * k.prm(k,m).modinv(m) % m
  end

  # mod must be a prime number
  # O(log m)
  def modinv(mod = 10**9+7)
    pow(mod-2, mod)
  end

  # O(log n)
  def pow(n , mod = nil )
    a = self.to_i
    res = 1
    while n > 0
      if (n & 1) != 0
        res *= a
        res %= mod if mod
      end
      a *= a
      a %= mod if mod
      n >>= 1
    end
    res
  end
end


class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    @perms = Hash.new{|h,k| h[k] = [1] }
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    r = n - r if r > n - r
    setup_table(r) if @n_max < r
    prm(n,r) * @factinv[r] % @mod
    # @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    prm(n,n)
  end

  def prm(n,k)
    if @perms[n][k].nil?
      perm = @perms[n]
      (n-perm.size+1).downto(n-k){|i| perm.push( perm[-1] * i % @mod )  }
    end
    return @perms[n][k]
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        # @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 10 ** 9 + 7

n,a,b = gets.split.map(&:to_i)

#何も選ばない1通りを除く
f = Facts.new
# ans = 2.pow(n, mod) - 1
# p f.cmb(n,a)
ans = 2.pow(n, mod) - 1 - f.cmb(n,a) - f.cmb(n,b)
ans %= mod
 
puts ans

Measured memory_bytes: 6672
// Fighting over Candies

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int pack[3];
	cin >> pack[0] >> pack[1] >> pack[2];

	sort(pack, pack+3);

	if (pack[0]+pack[1] == pack[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    [_, _, x, y] <- fmap (map read . words) getLine :: IO [Int]
    xs           <- fmap (map read . words) getLine :: IO [Int]
    ys           <- fmap (map read . words) getLine :: IO [Int]
    putStrLn $ if maximum (x : xs) < minimum (y : ys) then "No War" else "War"


Measured memory_bytes: 1020
program prob1
    implicit none
    integer::a,b,c,d,e,k
    read(*,*) a
    read(*,*) b
    read(*,*) c
    read(*,*) d
    read(*,*) e
    read(*,*) k

    if(e-a > k)then
        write(*,'(a)') ":("
    else
        write(*,'(a)') "Yay!"
    end if
    stop
end program

Measured memory_bytes: 2904
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        char x;
        cin>>x;
        cout<<++x;
    }
}

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

using namespace std;

bool table[105000];
vector<int> primes;

int main() {
  table[2] = true;
  for (int i = 3; i < 105000; i += 2)
    table[i] = true;
  for (int i = 3; i <= 324; i += 2)
    if (table[i])
      for (int j = 3 * i; j < 105000; j += 2 * i)
        table[j] = false;
  primes.push_back(2);
  for (int i = 3; i <= 105000; i += 2)
    if (table[i])
      primes.push_back(i);
  for (int i = 1; i < 10000; i++)
    primes[i] += primes[i-1];
  for (int n; scanf("%d", &n) == 1 && n;)
    printf("%d\n", primes[n-1]);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int n, k;
	int a[100000],i,b;
	scanf("%d %d", &n,&k);
	//a = (int*)malloc(sizeof(n));
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	b = (n - 1) / (k - 1);
	if (((n - 1) % (k - 1)) != 0)b++;
	printf("%d\n",b);
	//free(a);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>

int n;
std::string str[200];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) std::cin>>str[i];
	for (int i=1;i<n;i++)
		for (int j=i+1;j<=n;j++)
			if (str[i]==str[j]){
				puts("No");
				return 0;
			}
	for (int i=2;i<=n;i++)
		if (str[i-1][str[i-1].length()-1]!=str[i][0]){
			puts("No");
			return 0;
		}
	puts("Yes");
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
const int N = 105;
int n, w[N], mn, mx;
int main() {
	n = Get(), mn = n, mx = 0;
	for (int i = 1, x; i <= n; ++i) 
		++w[x = Get()], mn = std :: min(mn, x), mx = std :: max(mx, x);
	
	if (w[mx] < 2) {
		puts("Impossible");
		return 0;
	}
	
	if (mx & 1) 
		if (mn != (mx + 1) / 2 || w[mn] != 2) {
			puts("Impossible");
			return 0;
		}
	
	if (!(mx & 1))
		if (mn != mx / 2 || w[mn] != 1) {
			puts("Impossible");
			return 0;
		}
	
	for (int i = mn + 1; i < mx; ++i) 
		if (w[i] < 2) {
			puts("Impossible");
			return 0;
		}
	
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long dp[2000010] = {},sum[2000010] = {},mod = 1000000007;
int main(){
	long long i,n;
	cin >> n;
	for(i=2*n;i>=n+1;i--){
		dp[i] = 1;
		sum[i] = sum[i+1] + dp[i];
	}
	dp[n] = n; sum[n] = sum[n+1] + dp[n];
	for(i=n-1;i>=1;i--){
		(dp[i] += (sum[i+1] - sum[i+n+2]) - dp[i+2] + (n-1)*(n-1) + mod) %= mod;
		sum[i] = (sum[i+1] + dp[i])%mod;
	}
	cout << dp[1] << endl;
}

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

using namespace std;

int main(){
	
	int i, n, a, lim, aux, cont;
	scanf("%d%d", &n, &lim);
	aux = cont = 0;
	for (i = 0; i < n; ++i){
		if (aux <= lim){
			++cont;
		}
		scanf("%d", &a);
		aux += a;
	}
	if (aux <= lim){
		++cont;
	}
	printf("%d\n", cont);


	return 0;
}

Measured memory_bytes: 256
import itertools
import copy
h,w,k=map(int,input().split())
c = [list(input()) for _ in range(h)]
x = itertools.product(range(2) , repeat=h+w)
ans = [0] * (h+w)

tmp = []
for q in x:
  tmp = copy.deepcopy(c)
  for i in range(h):
    if q[i] == 1:
      tmp[i] = ["r"] * w
    else :
      tmp[i] = copy.deepcopy(c[i])

  for j in range(w):
    if q[h+j] == 1:
      for i in range(h):
        tmp[i][j] = "r"
  tans = 0
  for i in range(h):
    for j in range(w):
      tans += tmp[i][j].count("#")
  ans.append(tans)
cnt = 0

for a in ans:
  if a == k :
    cnt += 1
  
print(cnt)


Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 200010;
ll a[N];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, k;
	cin >> n >> k;

	for(int i = 0; i < n; i++) cin >> a[i];

	sort(a, a+n);
	ll ans = 0;

	for(int i = 0; i < n - k; i++) ans += a[i];

	cout << ans;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  const int MAXN = 1e6;
  vector<int> cnt(MAXN + 1);
  for (int p : a)
    ++cnt[p];
  int res = 0;
  for (int i = 0; i < n; i++) {
    bool ok = true;
    if (cnt[a[i]] > 1) 
      continue;
    for (int j = 1; j * j <= a[i]; j++) {
      if (a[i] % j == 0) {
        if ((j != a[i] && cnt[j]) || (j != 1 && cnt[a[i] / j])) {
          ok = false;
          break;
        }
      }
    }
    res += ok;
  } 
  cout << res << '\n';
  return 0;
}

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

int main(){
    int n; long long k;
    scanf("%d%lld", &n, &k);
    int tele[n+1];
    long long last[n+1];
    for (int i=1; i<=n; ++i) scanf("%d", &tele[i]);
    memset(last, -1, sizeof last);
    int curr = 1;
    while (k>0){
        if (last[curr] == -1){
            last[curr] = k;
            curr = tele[curr];
            --k;
        }
        else{
            int cycle = last[curr] - k;
            k = k%cycle;
            break;
        }
    }
    while (k>0){
        last[curr] = k;
        curr = tele[curr];
        --k;
    }
    printf("%d", curr);
    return 0;
}


Measured memory_bytes: 6212
x=[0]*5
k=0
for i in range(5):
	x[i]=int(input())
for i in range(5):
	if (10-(x[i]%10))>k and x[i]%10!=0:
		k=(10-(x[i]%10))
for i in range(5):
	x[i]=(-(-x[i]//10))*10
print(round(sum(x)-k))

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

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

	int h, m, s;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = S % 60;
	cout << h << ":" << m << ":" << s << endl;

    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    bool ans = false;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s == "Y") {
            ans = true;
            break;
        }
    }
    if(ans) cout << "Four" << endl;
    else cout << "Three" << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n, k, i, j;
    cin>>n>>k;
    vector<int> h(n);
    for(i=0;i<n;i++) {
        cin>>h[i];
    }
    vector<int> dp(n, -1);
    dp[0]=0;
    for(i=0;i<n;i++) {
        for(j=i+1;j<=i+k;j++) {
            if(j>=n) {
                break;
            }
            if(dp[j]==-1) {
                dp[j] = dp[i] + abs(h[j]-h[i]);
            }
            else {
                dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

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

const int MAX_V = 110;

vector<int> graph[MAX_V];
int id[MAX_V];      // id[i] := ??±???i???????????????
int deg[MAX_V];

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

    for (int loop = 0; loop < n; loop++) {
        // ?????????
        for (int i = 0; i < MAX_V; i++) {
            graph[i].clear();
            id[i] = -1;
            deg[i] = 0;
        }

        int cur, r, num = 0, depth = 0;
        stack<int> st;
        cin >> r;

        cur = num++;
        deg[cur] = r;
        id[depth] = cur;

        while (cin >> r, r) {
            // ?????¨????????????????????\?¶?????????????????????¨??????????????£???????????????????????´??????
            while (graph[cur].size() == deg[cur] && !st.empty()) {
                cur = st.top(); st.pop();
                depth--;
            }
            /*
            cout << "??\???: " << r << endl;
            cout << "?????¨: " << cur << endl;
            */

            if (r > 0) {
                // ?????¨?????????????????????????????????
                st.push(cur);

                // ?§????
                depth++;

                int nxt = num++;
                graph[cur].push_back(nxt);
                graph[nxt].push_back(cur);

                cur = nxt;
                deg[cur] = r;
                id[depth] = cur;

                // cout << "{" << cur + 1 << ", " << nxt + 1 << "}" << endl;
            } else {
                // r????????§???????????¨?????¨???
                graph[cur].push_back(id[depth + r]);
                graph[id[depth + r]].push_back(cur);

                // cout << "{" << cur + 1 << ", " << id[depth + r] << "}" << endl;
            }
        }

        // ??????
        for (int v = 0; v < num; v++) {
            cout << v + 1;
            
            sort(ALL(graph[v]));
            for (int e : graph[v]) {
                cout << " " << e + 1;
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3168
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;

    vector<int> a(N), b(N), c(N);
    for (size_t i = 0; i < N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    auto dp = make_v(0, N + 1, 3);
    for (size_t i = 0; i < N; ++i) {
        for (size_t tail = 0; tail < 3; ++tail) {
            if (tail != 0) chmax(dp[i + 1][tail], dp[i][0] + a[i]);
            if (tail != 1) chmax(dp[i + 1][tail], dp[i][1] + b[i]);
            if (tail != 2) chmax(dp[i + 1][tail], dp[i][2] + c[i]);
        }
    }

    cout << max({dp[N][0], dp[N][1], dp[N][2]}) << "\n";

    return 0;
}


Measured memory_bytes: 6912
# ABC139E - League
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(x: int, y: int) -> None:
    scheduled[x] = 1
    for i in range(cur[x], N - 1):
        z = A[x][i]  # scheduled i-th opponent of player x
        if z == y:
            cur[x] = i + 1
            scheduled[x] = 0
            days[x] += 1
            days[z] += 1
            days[x] = days[z] = max(days[x], days[z])
            return
        if scheduled[z]:  # the schedule contradicts
            print(-1)
            exit()
        dfs(z, x)


def main():
    global N, A, cur, days, scheduled
    N = int(input())
    A = [0] + list(list(map(int, input().split())) for _ in range(N))
    cur, days, scheduled = [0] * (N + 1), [0] * (N + 1), [0] * (N + 1)
    for i in range(1, N + 1):
        dfs(i, 0)
    ans = max(days)  # the last day of games
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 35124
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a*b/2<<endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n : isize,
        m : isize,
        a : [i64; m],
    }
    let mut avail = n as i64;
    for (_i, v) in a.iter().enumerate() {
        avail -= v;
    }
    avail = std::cmp::max(avail, -1);

    println!("{}", avail);
}


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

int main()
{
  int n = 0;
  int k = 0;
  long long base = 1e9+7;
  scanf("%d %d", &n, &k);
  if(k == 0){
    printf("1\n");
    return 0;
  }
  vector<int> a(n, 0);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  int good_cnt = 0;
  for(int i=0; i<n; i++){
    if(a[i] > 0){
      a[good_cnt] = a[i];
      good_cnt++;
    }
  }
  n = good_cnt;
  long long arr[n][k+1];
  memset(arr, 0, sizeof arr);
  for(int j=0; j<k+1; j++){
    if(j >= a[0]){
      arr[0][j] = a[0]+1;
    }else{
      arr[0][j] = j+1;
    }
  }
  for(int i=1; i<n; i++){
    for(int j=0; j<k+1; j++){
      if(j <= a[i]){
        arr[i][j] = arr[i-1][j];
      }else{
        arr[i][j] = (arr[i-1][j] - arr[i-1][j-a[i]-1] + base ) % base;
      }
    }
    for(int j=1; j<k+1; j++){
      arr[i][j] = (arr[i][j] + arr[i][j-1]) % base;
    }
  }
//  for(int i=0; i<n; i++){
//    for(int j=0; j<k+1; j++){
//      printf("%lld ", arr[i][j]);
//    }
//    printf("\n");
//  }
  printf("%lld\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base);
}


Measured memory_bytes: 81756
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayDeque<Integer> list = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ");
            if (line[0].equals("insert")) {
                list.addFirst(Integer.parseInt(line[1]));
            } else if (line[0].equals("delete")) {
                list.remove(Integer.valueOf(Integer.parseInt(line[1])));
            } else if (line[0].equals("deleteFirst")) {
                list.removeFirst();
            } else {
                list.removeLast();
            }
        }
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        while (list.size() > 0) {
            if (!first) {
                sb.append(" ");
            }
            first = false;
            sb.append(list.poll());
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 189096