akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);

	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int dis = (h2-h1)*60 + (m2-m1);
	cout<<dis-k<<endl;
	return 0;
}


Measured memory_bytes: 3656
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()
offset = 10**10

def main():
    """
    ナップサックで重さを飛び飛びにしてdpを軽くしなくても、
    そもそも重さが４パターンだから全探索で解けたのか。。。。。。
    """
    N, W = map(int, input().split())
    item = [[] for _ in range(4)]
    length = [1, 0, 0, 0]
    w0, v0 = map(int, input().split())
    item[0].append(v0)
    for _ in range(N - 1):
        w, v = map(int, input().split())
        item[w - w0].append(v)
        length[w - w0] += 1
    for i in range(4): item[i].sort(reverse=True)

    # 重さの累積和
    S = []
    for i in range(4):
        S.append([0] + list(accumulate(item[i])))

    ans = 0
    for a in range(length[0] + 1):
        for b in range(length[1] + 1):
            for c in range(length[2] + 1):
                for d in range(length[3] + 1):
                    weight = a * w0 + b * (w0 + 1) + c * (w0 + 2) + d * (w0 + 3)
                    if weight > W: continue
                    ans = max(ans, S[0][a] + S[1][b] + S[2][c] + S[3][d])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73008
import bisect
import math

N = int(input())
L = list(map(int, input().split()))
L.sort()
res = 0
for i in range(N):
    for j in range(i+1, N):
        k = bisect.bisect_left(L, L[i]+L[j])
        # print(j, k)
        res += max(0, k-j-1)
print(res)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int A, B, C; cin >> A >> B >> C;
  if(A + B + C >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PII;
int n;
int in[51],a[51];
int res;
int op;
int main()
{	
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>in[i];
		a[in[i]]=i;
	}
	for(int i=1;i<=n;i++){
		if(in[i]!=i) res++;
	}
	res--;
	if(res>1){
		cout<<"NO"<<endl;
	}
	else cout<<"YES"<<endl;
	return 0;
}

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

using namespace std;

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

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

	int dpa[n], dpb[n], dpc[n];
	
	dpa[0]=a[0];
	dpb[0]=b[0];
	dpc[0]=c[0];

	for(int i=1;i<n;i++){
		dpa[i]=max(dpb[i-1], dpc[i-1]) + a[i];
		dpb[i]=max(dpa[i-1], dpc[i-1]) + b[i];
		dpc[i]=max(dpa[i-1], dpb[i-1]) + c[i];
	}

	int ans = max(dpa[n-1], dpb[n-1]);
	ans = (ans>dpc[n-1])?ans:dpc[n-1];
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
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 n = read int
    let bs = reada int
    let mp = Dictionary<int, int>()
    for b in bs do
        if mp.ContainsKey(b) then mp.[b] <- mp.[b] + 1 else mp.Add(b, 1)

    let mutable even, odd = 0, 0
    mp
    |> Seq.iter (fun kv ->
        let v = kv.Value
        if v % 2 = 0 then even <- even + 1 else odd <- odd + 1)
    let ans =
        if even % 2 = 0 then even + odd else (even - 1) + odd
    puts ans
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 22240
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=1e6+5;
int fac[N],ifac[N],n,m,l,r;
void init(int n=1e6){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(R int n,R int m){return m<0||m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline int put(R int n,R int m){return C(n+m-1,m-1);}
inline int min(R int x,R int y){return x<y?x:y;}
int calc(R int d){
	R int ret=0;
	fp(i,1,d/m){
		R int s=d-i*m,res=0,tmp;
		fp(j,0,min(s/i,n-m))tmp=mul(C(n-m,j),put(s-j*i,n+1)),upd(res,j&1?P-tmp:tmp);
		if((i+1)*m<=d){
			s=d-(i+1)*m;
			fp(j,0,min(s/i,n-m))tmp=mul(C(n-m,j),put(s-j*i,n+1)),upd(res,j&1?tmp:P-tmp);
		}
		upd(ret,res);
	}
	ret=mul(ret,C(n,m));
	return dec(put(d,n+1),ret);
}
int main(){
	init();
	scanf("%d%d%d%d",&n,&m,&l,&r);
	printf("%d\n",dec(calc(r),calc(l-1)));
	return 0;
}

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

int main(){
  int n,m;
  cin >>n>>m;
  int a=0,b=n;

  for (int i=0;i<m;i++){
    int l,r;
    cin >>l>>r;
    if(a<=l){
      a=l;
    }
    if(b>=r){
      b=r;
    }
  }
  if(b>=a){
  	cout<<b-a+1 <<endl;
  }
  else{
    cout <<0<<endl;
  }
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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;
}

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

/*
int num = 200010;
vector<ll> fact(num), ifact(num);
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i < num; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
}
for (int i = 0; i < num; i++) {
    ifact[i] = modpow(ifact[i], mod-2);
    ifact[i] %= mod;
}
*/

using Edge = pair<int, ll>;
using Graph = vector<vector<Edge>>;

void dfs(const Graph &G, int v, int p, ll sum, vector<ll> &dist) {
    dist[v] = sum;
    for (auto e : G[v]) {
        if (e.first == p) continue;
        dfs(G, e.first, v, sum + e.second, dist);
    }
}

int main() {
    int N; cin >> N;
    Graph G(N);
    vector<ll> dist(N, 0);
    rep(i, N-1) {
        int a, b; ll c; cin >> a >> b >> c;
        a--; b--;
        G[a].pb({b, c});
        G[b].pb({a, c});
    }
    int Q, K; cin >> Q >> K;
    K--;
    dfs(G, K, -1, 0, dist);
    rep(i, Q) {
        int x, y; cin >> x >> y;
        x--; y--;
        cout << dist[x] + dist[y] << endl;
    }

    return 0;
}

Measured memory_bytes: 17408
import sys
sys.setrecursionlimit(10**7)
n,q=map(int,input().split())
edge=[[] for _ in range(n)]
for i in range(n-1):
    x,y=map(int,input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
def dfs(c,p):
    for i in edge[c]:
        if i==p:
            continue
        ans[i]+=ans[c]
        dfs(i,c)
dfs(0,-1)
print(*ans)

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

int main(void){
  int A, B, C, X, Y;
  cin >> A>> B>> C>> X>> Y;

  int ans = INT_MAX;
  ans = min(ans, A*X + B*Y);
  int res = ans;

  for(int i = 0; i < max(X, Y)*2+2; i++){
    int sum = ans;
    int c = i+1;
    int c1 = c, c2 = c;
    if(c > X) c1 = X;
    if(c > Y) c2 = Y;
    sum -= (A*c1 + B*c2);
    sum += 2*c*C;
    res = min(res, sum);
  }
  cout << res << endl;
}


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


int main() {

	long long a,b,ab,na,nb;
	cin >> a >> b >> ab >> na >> nb;
	if((a+b)>2*ab){
        long long mon = 0;
        long long buy = min(na,nb);
        mon+=2*buy*ab;
        na-=buy;
        nb-=buy;
        mon+=1*min(a,2*ab)*na;
        mon+=1*min(b,2*ab)*nb;
        cout << mon << endl;
	}
	else{
        cout << 1*a*na+1*b*nb << endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;

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

int dig(int a) {
	int res = 0;
	while (a) {
		res += a % 10;
		a /= 10;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int mn = 1000;
	for (int i = 1; 2 * i <= n; ++i) {
		mn = min(mn, dig(i) + dig(n - i));
	}	
	cout << mn << endl;
}


Measured memory_bytes: 256
import math

N = int(input())
K = int(input())
l = len(str(N))

dp = [[[0 for _ in range(2)] for _ in range(4)] for _ in range(102)]
dp[0][0][0] = 1

for i in range(l):
    for j in range(4):
        for k in range(2):
            for d in range(10):
                nd = int(str(N)[i])
                ni = i + 1
                nj = j
                nk = k
                if d > 0:
                    nj += 1
                if nj > K:
                    continue
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk = 1
                dp[ni][nj][nk] += dp[i][j][k]

print(dp[l][K][0] + dp[l][K][1])



Measured memory_bytes: 3064
S=input()
T=input()
dic={}
ans='Yes'
for i,x in enumerate(S):
    if dic.get(x,'')=='':
        dic[x]=T[i]
    elif dic[x]!=T[i]:
        ans='No'
        break
dic2={}
for i,x in enumerate(T):
    if ans=='No':
        break
    if dic2.get(x,'')=='':
        dic2[x]=S[i]
    elif dic2[x]!=S[i]:
        ans='No'
        break
print(ans)

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  double r;
  cin >> r;
  double ans = 2.0 *  3.14 * r;
  cout << ans << endl;
}


Measured memory_bytes: 3796
def gcd(a, b):
    """a, bの最大公約数(greatest common divisor:GCD)を求める"""
    if b == 0:
        return a
    return gcd(b, a%b)


a, b = map(int,input().split())
gcd_ab = gcd(a, b)
if gcd_ab == b:
    print(-1)
else:
    if a % b == 0:
        print(a*gcd_ab)
    else:
        print(a)

Measured memory_bytes: 38256
N, K = map(int, input().split())
H = list(map(int, input().split()))
 
# N<=Kの場合、全てのモンスターを必殺技で倒して終了
# N>Kの場合、N体のモンスターのうち、体力が高い順に、K体を必殺技で倒す
# 残ったモンスターは、攻撃によって倒す
# 攻撃の回数を求める（必殺技は数えない）ことに注意する

H = sorted(H, reverse=True)
ans = 0
if N > K: ans = sum(H[K:])
  
print(ans)

Measured memory_bytes: 31496
n,l,t=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=[]
cnt=0
for i in range(n):
  tmp=arr[i][0]
  if arr[i][1]==1:
    tmp+=t
    tmp%=l
    cnt+=(arr[i][0]+t)//l
  else:
    tmp-=t
    tmp%=l
    cnt+=(arr[i][0]-t)//l
  ans.append(tmp)
ans=sorted(ans)
cnt%=n
tmp=[0]*n
for i in range(n):
  tmp[i]=ans[(cnt+i)%n]
ans=tmp
for pos in ans:
  print(pos)

Measured memory_bytes: 29476
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()))

r = ni()
if r < 1200:
    print('ABC')
elif r < 2800:
    print('ARC')
else:
    print('AGC')

Measured memory_bytes: 3696
#include <stdio.h>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	int A[n];

	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
	printf("%d\n",A[0]);
}



Measured memory_bytes: 2680
#include<bits/stdc++.h>
#define MAXN 200000
using namespace std;
int N,K;
vector<int>num(MAXN,0);
int main(){
    cin >> N;
    cin >> K;
    for(int i = 0;i < N;i++){
        int n;
        cin >> n;
        num[n-1]++;
    }
    sort(num.begin(),num.end());
    int ans = 0;
    for(int i = MAXN-1-K;i >= 0;i--){
        ans+=num[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {// ここにプログラムを追記
    string x;
    cin >> x;
    if (x == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == N - 1){
      cout << "Three" << endl;
    }
  }
}



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



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

int main() {
    long long A, B, C;
    cin >> A >> B >> C;
    string ans;
    if ((A == B && B != C) || (A == C && B != C) || (B == C && B != A)) {
        ans = "Yes";
    } else {
        ans = "No";
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n) {
  std::vector<int64_t> sieved(n + 1, 0);
  int64_t ret = 1;
  for (int64_t p = 2; p <= n; p++) {
    for (int64_t pp = p; pp <= n; pp += p) {
      sieved[pp]++;
    }
    ret += (sieved[p] + 1) * p;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  auto const res = solve(n);
  std::cout << res << std::endl;
  return 0;
}


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

signed main(){
  ll n, K; cin >> n >> K;
  vector<ll> a(n);
  for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
  vector<vector<ll> > dp(50, vector<ll> (2, -1));
  dp[40][0] = 0;
  for(int d = 45; d >= 0; d--){
   ll num = 0, mask = 1LL << d;
   for(int j = 0; j < n; j++) if(a[j] & mask) num++;
   if(dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num));
   if(dp[d + 1][0] != -1){
     if(K & mask){
       dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num);
       dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * (n - num));
     }
     else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num);
   }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    vector<bool> a(31,false);
    for(int i = 0;i < 28;++i) {
        int t;
        cin>>t;
        a[t]=true;
    }
    for(int i = 1;i <= 30;++i) {
        if(a[i])continue;
        cout<<i<<endl;
    }
    return 0;
}



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

int main(){
	int n, m; cin >> n >> m;
	vector<int> v[n];
	for(int i = 0; i < m; ++i){
		int a, b; cin >> a >> b;
		v[--a].push_back(--b);
		v[b].push_back(a);
	}
	int q; cin >> q;
	int color[q + 1] = {};
	int dp[n][11];
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 11; ++j) dp[i][j] = q;
	}
	for(int i = 0; i < q; ++i){
		int v, d, c; cin >> v >> d >> c;
		color[q - 1 - i] = c;
		dp[--v][d] = q - 1 - i;
	}
	for(int j = 10; j >= 1; --j){
		for(int i = 0; i < n; ++i){
			dp[i][j - 1] = min(dp[i][j - 1], dp[i][j]);
			for(int next : v[i]) dp[next][j - 1] = min(dp[next][j - 1], dp[i][j]);
		}
	}
	for(int i = 0; i < n; ++i) cout << color[dp[i][0]] << endl;
	return 0;
}

Measured memory_bytes: 11128
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 20:59:19 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
A, B, N = map(int,input().split())
#A = list(map(int,input().split()))
#graph = [[] for _ in range(N+1)]
#for _ in range(N-1):
#    a, b = map(lambda x : int(x)-1, input().split())
#    graph[a].append(b)
#    graph[b].append(a)

x = min(B-1, N)
ans = int(A*x/B) - A * int(x/B)

print(ans)



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

int main() {
    int n, b, f, r, v;

    int a[4][3][10];
    for (int b = 0; b < 4; b++) {
        for (int f = 0; f < 3; f++) {
            for (int r = 0; r < 10; r++) {
                a[b][f][r] = 0;
            }
        }
    }

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b >> f >> r >> v;
        a[b-1][f-1][r-1] += v;
    }
    for (int b = 0; b < 4; b++) {
        for (int f = 0; f < 3; f++) {
            for (int r = 0; r < 10; r++) {
                cout << " ";
                cout << a[b][f][r];
            }
            cout << endl;
        }
        if (b != 3) {
            cout << "####################" << endl;
        }
    }
}


Measured memory_bytes: 3088
import java.util.*

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)

    val sString = sc.next()
    val tString = sc.next()

    var sNum = sc.nextInt()
    var tNum = sc.nextInt()

    val uString = sc.next()

    if(sString == uString)sNum--
    if(tString == uString)tNum--

    println("$sNum $tNum")

    sc.close()
}

Measured memory_bytes: 31272
N, K = map(int, input().split())
mod = 10**9+7
kosu_table = [0]*(K+1)
i = K
while i > 0:
  kosu_table[i] = pow(K//i, N, mod)
  j = 2
  while i*j <= K:
    kosu_table[i] -= kosu_table[i*j]
    j += 1
  i -= 1
print(sum([i*kosu_table[i] for i in range(1, K+1)])%mod)


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110, M = 110;

int n, flag;
string s;
deque<char> S;

int main()
{
	cin >> s >> n;
	for (int i = 0; i < s.size(); i ++ ) S.push_back(s[i]);
	
	while (n -- )
	{
		int t, f;
		char c;
		cin >> t;
		
		if (t == 1) flag ^= 1;
		else
		{
			cin >> f >> c;
			if (f == 1)
			{
				if (flag) S.push_back(c);
				else S.push_front(c);
			}
			else
			{
				if (flag) S.push_front(c);
				else S.push_back(c);
			}
		}
	}
	
	vector<char> res;
	for (auto u : S) res.push_back(u);
	if (flag) reverse(res.begin(), res.end());
	
	for (auto u : res) cout << u;
	puts("");
	return 0;
}

Measured memory_bytes: 1404
#include<stdio.h>
int main(){
    
    long num,i,sum=0;
    long a[1000000];
    scanf("%ld",&num);
    
    for(i=0;i<=num;i++){
        if(i%3==0 || i%5==0 || i%15==0){
            a[i]=0;
        }else{
            a[i]=i;
        }
    }
    for(i=0;i<=num;i++){
        sum+=a[i];
    }
    printf("%ld",sum);
    
    return 0;
}

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

int main(){
  
  int N;
  cin >> N;
  
  vector<tuple<string,int,int>> pa(N);
  
  for(int i=0; i<N; i++){
    string s;
    int p,j=i+1;
    cin >> s >> p;
    pa.at(i) = make_tuple(s,-p,j);
  }
  
  sort(pa.begin(),pa.end());

  for(int i=0; i<N; i++){
    string s;
    int p,j;
    tie(s,p,j) = pa.at(i);
    cout << j << endl;
  }
  
}


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

bool sortbysec(const pair<long long,long long>&a,const pair<long long,long long> &b)
{
	return(a.second<b.second);
	//sort(s.begin(),s.end(),sortbysec);
	//s.push_back(make_pair(x,y));
}

int main()
{
	vector<pair<long long,long long>> ve;
	long long n;
	cin>>n;
	long long a[n+1],i,dp[n+1];
	for(i=0;i<n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		dp[i] = min(abs(a[i]-a[i-1]) + dp[i-1] , abs(a[i]-a[i-2]) + dp[i-2]);
	}	
	cout<<dp[n-1];
	return 0;
}

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

int main(){
  int N, M;
  scanf("%d %d", &N, &M);
  int k[M], s[10][10], i, j, p[M];
  for(i=0; i<M; i++){
    scanf("%d", &k[i]);
    for(j=0; j<k[i]; j++){
      scanf("%d", &s[i][j]);
    }
  }
  for(i=0; i<M; i++){
    scanf("%d", &p[i]);
  }

  int *sw = (int*)calloc(N, sizeof(int));
  int ans = 0, sn, on;
  for (i=0; i<(int)pow(2.0, (double)N); i++){
    on=0;
    for(j=0; j<M; j++){
      sn = 0;
      for(int l=0; l<k[j]; l++){
        if(sw[s[j][l]-1] == 1){
          sn++;
        }
      }
      if (sn%2 == p[j]){
        on++;
      }
    }
    sw[0]++;
    for(j=0; j<N; j++){
      if (sw[j] == 2) {
        sw[j+1]++;
        sw[j] = 0;
      }
    }
    if (on == M) ans++;
  }

  printf("%d", ans);
  
  return 0;
}

Measured memory_bytes: 128
x, y = map(int, input().split())
if x > 0:
    if y >= x:
        print(y - x)
    elif -x <= y and y <= 0:
        print(1 + x + y)
    elif 0 < y and y < x:
        print(x - y + 2)
    elif y < -x:
        print(-y - x + 1)
elif x == 0:
    if y >= 0:
        print(y)
    elif y < 0:
        print(-y + 1)
elif x < 0:
    if x <= y and y <= 0:
        print(y - x)
    elif 0 < y and y < -x:
        print(-y - x + 1)
    elif y >= -x:
        print(1 + x + y)
    elif y < x:
        print(x - y + 2)


Measured memory_bytes: 9212
# abc143_b.py
# https://atcoder.jp/contests/abc143/tasks/abc143_b

# B - TAKOYAKI FESTIVAL 2019 /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# たこ焼きフェスティバル (たこフェス) の季節がやってきました！
# 今年のたこフェスでは N個のたこ焼きがふるまわれる予定です。このうち i 個目のたこ焼きのおいしさは diです。
# ところで、おいしさが xと y であるたこ焼きを一緒に食べると、体力が x×y回復することが一般に知られています。
# たこフェスでふるまわれる N個のたこ焼きから、2 個を選ぶ方法は N×(N−1)2通り考えられます。
# そのそれぞれについて、一緒に食べたときの体力の回復量を求めて、その総和を出力してください。

# 制約
#     入力は全て整数である。
#     2≤N≤50
#     0≤di≤100

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# d1 d2 ... dN

# 出力
# たこフェスでふるまわれる N個のたこやきから、2個を選んで一緒に食べたときの体力の回復量の総和を出力せよ。

# 入力例 1
# 3
# 3 1 2

# 出力例 1
# 11

# 以下の 3通りの食べ方が考えられます。
#     1, 2個目のたこ焼きを選んで一緒に食べる。このとき、体力の回復量は 3である。
#     2, 3個目のたこ焼きを選んで一緒に食べる。このとき、体力の回復量は 2である。
#     1, 3個目のたこ焼きを選んで一緒に食べる。このとき、体力の回復量は 6である。

# 体力の回復量の総和は 11です。

# 入力例 2
# 7
# 5 0 7 8 3 3 2

# 出力例 2
# 312


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = 0
    for i in range(N-1):
        for j in range(i+1, N):
            log(f'i=[{i}], j=[{j}]')
            result += values[i] * values[j]
            # log(f'result=[{result}]')

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '3 1 2']
        lines_export = [11]
    if pattern == 2:
        lines_input = ['7', '5 0 7 8 3 3 2']
        lines_export = [312]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
int n;
char wcz[1007];
int czy[1007];
long long wyn;
void check()
{
	czy[n]=1;
	long long aktu=0;
	for(int i=1;i<=n;i++)
	{
		aktu*=10;
		aktu+=wcz[i]-'0';
		if(czy[i])
		{
			wyn+=aktu;
			aktu=0;
		}
	}
}
void rek(int v)
{
	if(v==n)
	{
		check();
		return;
	}
	czy[v]=0;
	rek(v+1);
	czy[v]=1;
	rek(v+1);
}
int main()
{
	scanf("%s",wcz+1);
	while(wcz[n+1])
	n++;
	rek(1);
	printf("%lld",wyn);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e18
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
using namespace std;
ll binpow(ll x, ll y) {
    ll int res = 1;
    for(int i = 1; i <= y; i++) {
        res = (res * x) % mod;
    }
    return res;
} 
int main() 
{
    fastio; 
    ll T=1;
    //cin>>T; 
    while(T--)
    { 	
    ll n; 
	cin>>n;
    ll dp[n+1];
    for(ll i=0;i<=n;i++)dp[i]=0;
    dp[0] = 1;
    for(int sum=1;sum<=n;++sum){
        for(int num=3;num<=sum;++num){
            dp[sum] = dp[sum] + dp[sum-num];
            dp[sum] = dp[sum]%mod;
        }
    }
    cout<<dp[n];
	}
}
 

Measured memory_bytes: 3684
import java.io.*;

public class Main{
    public static void main(String[] args){
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	
    	try{
    		int keta;
	    	double num[] = new double[2];
    	   	String str[] = new String[200];

    		str[0] = br.readLine();
    		int i = 0;
    		while(str[i] != null){
    			i++;
    			str[i] = br.readLine();
	    	}
	    	br.close();

    		for (int j=0;j<i;j++){
	    		String str2[] = str[j].split(" ",0);
	    		num[0] = Double.parseDouble(str2[0]);
	    		num[1] = Double.parseDouble(str2[1]);

	    		keta = (int)Math.log10(num[0]+num[1]);
    			System.out.println(keta+1);

    			if(num[0]+num[1]==0){
    				break;
    			}
    		}
   		}catch(IOException e){
   			System.out.println("fail.");
 	  	}
	}
}


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

map <int, vector<int>> adj;
int n, m;
bool visited[100005];
int dp[100005];

void dfs(int n)
{
  visited[n] = true;
  for (auto neigh : adj[n])
  {
    if (!visited[neigh])
      dfs(neigh);
    dp[n] = max(dp[n], 1+dp[neigh]);
  }
}

int solve(int n, int m, int* x, int* y)
{
  for (int i = 0; i < m; i++)
  {
    adj[x[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i])
      dfs(i);
  int r = 0;
  for (int i = 1; i <= n; i++)
    r = max(r, dp[i]);
  return r;
} 

int main()
{
  cin >> n >> m;
  int x[m];
  int y[m];
  for (int i = 0; i < m; i++)
  {
    cin >> x[i] >> y[i];
  }
  fill(visited, visited + n, false);
  int r = solve(n, m, x, y);
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 17332
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll a,b;
    cin>>a>>b;
    if(a==1||b==1)cout<<1<<endl;
    else cout<<(a*b+1)/2<<endl;


    return 0;
}

Measured memory_bytes: 256
//Keep Working Hard
  // I__Like__Food  

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define tracel5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)

const int N = 55;

char str[N][N];
int h,w;

int ans(int x,int y)
{
	int dx[] = {-1,0,1};
	int dy []= {-1,0,1};

	int count = 0;

	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			int xx = x + dx[i];
			int yy = y + dy[j];

			if(x == xx and y == yy)continue;

			if(xx >= 1 and xx <= h and yy >= 1 and yy <= w)
			{
				if(str[xx][yy] == '#')count++;
			}

		}
	}

	return count;
}
int32_t main()
{


    IOS

    cin >> h >> w;

    for(int i = 1; i <= h; i++)
    {
    	for(int j = 1; j <= w; j++)
    	{
    		cin >> str[i][j];
    	}
    }

    for(int i = 1; i <= h; i++)
    {
    	for(int j = 1; j <= w; j++)
    	{
    		if(str[i][j] == '.')
    		{
    			str[i][j] = '0' + ans(i,j);
    		}
    		cout << str[i][j];
    	}
    	cout << endl;

    }
    



    return 0;
}




Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long InF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑



int main() {
	int a, b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
}

Measured memory_bytes: 256
N, M, C = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = []
for i in range(N):
    A.append([int(x) for x in input().split()])
result = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j] * B[j]
    if tmp + C > 0:
        result += 1
print(result)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n, d, x, a[100];
	cin >> n;
	cin >> d >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int count = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		count = floor((d - 1) / a[i]) + 1;
		ans += count;
	}
	cout << ans + x << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int m,f,r;

  while (1){
    
    scanf("%d %d %d",&m,&f,&r);
    
    if (m == -1 && f == -1 && r == -1){
      
      break;
      
    } else {

      if (m == -1 || f == -1){
      
      printf("F");
      
    } else if (80 <= m+f){
      
      printf("A");
      
    } else if (65 <= m+f){
      
      printf("B");
      
    } else if (50 <= m+f){
      
      printf("C");
      
    } else if (30 <= m+f && 50 <= r){
      
      printf("C");
      
    } else if (30 <= m+f){
      
      printf("D");

    } else if (m+f < 30){
      
      printf("F");
      
    }
    
    printf("\n");

    }
    
  }

  return 0;
  
}

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

a = list(map(int, input().split()))
b = list(map(int, input().split()))

t = 0
ans = 0

for i in range(m):
    t += b[i]

j = m

for i in range(n+1):
    while (j > 0 and t > k):
        j -= 1
        t -= b[j]
    if t > k:
        break
    ans = max(ans, i+j)
    if i == n:
        break
    t += a[i]

print(ans)


Measured memory_bytes: 40416
length_list = int(input())
num_list = list(map(int, input().split()))

count = 0

for i in range(length_list):
    minj = i
    for j in range(i,length_list):
        if num_list[j] < num_list[minj]:
            minj = j
    if i != minj:
        num_list[i],num_list[minj] = num_list[minj],num_list[i]
        count += 1
print(" ".join(map(str,num_list)))
print(count)



Measured memory_bytes: 5596
s=input().rstrip().split()

if int(s[0])==5 and int(s[1])==5 and int(s[2])==7:
	print("YES")
elif int(s[0])==7 and int(s[1])==5 and int(s[2])==5:
	print("YES")
elif int(s[0])==5 and int(s[1])==7 and int(s[2])==5:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,s=0;
  cin>>n>>m;
  int a[m];
  for(int i =0;i<m;i++)
  { cin>>a[i];s+=a[i];}
  if(s>n)cout<<-1<<endl;
  else{cout<<n-s;}
  
}
  


Measured memory_bytes: 3592
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){

	int n;
	ull T;
	ull ans = 0;
	ull st = 0;
	ull fos = 0;
	cin >> n >> T >> st;

	rep(i, 1, n) {
		ull s;
		cin >> s;
		ans += min(T,s-st);
		st = s;
	}

	cout << ans + T << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())
P = 0
R = S.count('R')
G = S.count('G')
B = S.count('B')
P = R*G*B
for i in range(1,(N//2)+1):
    for j in range(N-2*i):
            if S[j]!=S[j+i] and S[j+i]!=S[j+2*i] and S[j]!=S[j+2*i]:
                P -= 1
print(P)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,tasu,kakeru,hiku;
  cin >> a >> b;
  tasu = a + b;
  kakeru = a * b;
  hiku = a -b;
  if(tasu >= kakeru&& tasu >= hiku){
  	cout << tasu << endl;
  }else if(hiku >=kakeru && hiku >= tasu){
    cout << hiku << endl;
  }else{
    cout << kakeru << endl;
  }
   
}

Measured memory_bytes: 256
#include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
    vector<int> vis,dp;
    void initialise(int n)
    {
    	vis.assign(n,0);
    	dp.assign(n,0);
    }
    int dfs(int i,vector<int> v[])
    {
    	int max=0;
    	vis[i]=1;
    	for(int j=0;j<(int)v[i].size();j++)
    	{
    		if(!vis[v[i][j]])
    		{
    			if(max<dfs(v[i][j],v))
    			{

				max=dp[v[i][j]];
			}
		}
		else
		if(max<dp[v[i][j]])
		{
			max=dp[v[i][j]];
		}
	}
	dp[i]=max+1;
	return dp[i];
}
int main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	vector<int> v[n];
	initialise(n);
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--,y--;
		v[x].push_back(y);
	}
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			dfs(i,v);
		}
	}
	int i=*max_element(dp.begin(),dp.end());
	cout<<i-1;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    map<int,vector<int>> mapM;
    rep(m,0,M){
        int a,b; cin>>a>>b;
        mapM[a].push_back(b);
        mapM[b].push_back(a);
    }

    vector<bool> arrived(N,false);
    arrived.at(0)=true;
    queue<int> Q;
    Q.push(1);

    vector<int> ans(N,-1);
    while(!Q.empty()){
        int room=Q.front();
        Q.pop();

        for(auto _r:mapM[room]){
            if(!arrived.at(_r-1)){
                arrived.at(_r-1)=true;
                Q.push(_r);
                ans.at(_r-1)=room;
            }
        }
    }

    string ansS="Yes";
    rep(n,1,N) if(ans.at(n)==-1){ ansS="No"; break;}

    cout<<ansS<<endl;
    if(ansS=="Yes") rep(n,1,N) cout<<ans.at(n)<<endl;
}

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

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int x[m];
	for (int i = 0; i < m; ++i)
	{
		cin>>x[i];
	}
	if (n>=m)
	{
		cout<<"0\n";
		return 0;
	}
	sort(x,x+m);
	int s=0,a[m-1];
	for (int i = 0; i < m-1; ++i)
	{
		a[i]=abs(x[i+1]-x[i]);
		s+=a[i];
	}
	sort(a,a+m-1);
	reverse(a,a+m-1);
	for (int i = 0; i < n-1; ++i)
	{
		s-=a[i];
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def lr(xx):
    ll=[-1]*(n+1)
    rr=[-1]*(n+1)
    for i,x in enumerate(xx):
        if ll[x]==-1:ll[x]=i
        if i==n-1 or x!=xx[i+1]:rr[x]=i+1
    return ll,rr

n=II()
aa=LI()
bb=LI()
all,arr=lr(aa)
bll,brr=lr(bb)
# print(all,arr)
ca=[0]*(n+1)
cb=[0]*(n+1)
for a in aa:ca[a]+=1
for b in bb:cb[b]+=1
for i in range(n+1):
    if ca[i]+cb[i]>n:
        print("No")
        exit()
ng=[0]*(n+1)
for al,ar,bl,br in zip(all,arr,bll,brr):
    if al==-1 or bl==-1:continue
    if bl<ar:
        mn=max(0,al-br+1)
        mx=ar-bl
        ng[mn]+=1
        ng[mx]-=1
    else:
        mn=max(0,al+n-br+1)
        mx=min(n,ar+n-bl)
        ng[mn]+=1
        ng[mx]-=1
# print(ng)
for i in range(n):ng[i+1]+=ng[i]
shift=-1
for i in range(n):
    if ng[i]==0:
        shift=i
        break
ans=bb[-shift:]+bb[:-shift]
print("Yes")
print(*ans)


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

int main() {
	int a,b,c,n1=0,n2=0;
	while(scanf("%d,%d,%d",&a,&b,&c)>0){
		if(a==b && a*a+b*b==c*c) continue;
		if(a*a+b*b==c*c) n1++;
		if(a==b) n2++;
	}cout<<n1<<endl<<n2<<endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  for (int i=0; i<N; i++) std::cin >> a[i];
  
  // Prepare DP table
  std::vector<int> dp(N, std::numeric_limits<int>::max());
  
  // For a[0:1]
  dp[0] = a[0];
  
  for (int i=1; i<N; i++) {
    // For a[0:i+1]
    *std::lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }
  
  int i;
  for (i=0; i<N; i++) {
    if (dp[i] > 1000000000) break;
  }
  std::cout << i << std::endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

int main() {
	ll n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r << endl;
		return 0;
	}
	ll add = 100 * (10 - n);
	cout << r + add << endl;
    return 0;
}


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

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ll long long
#define fr(i,n) for(i=0;i<n;i++)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    if(n>m)
        swap(n,m);
    if(n==1)
    {
        if(m==1)
            cout<<1<<endl;
        else
            cout<<m-2<<endl;
    }
    else if(n==2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<(n-2)*(m-2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

ll lcm(ll x, ll y) {
    return x / gcd(x,y) * y;
}

int main(void)
{
    IOS
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    cin >> v[0];
    int g = v[0];
    int mx = v[0];
    REP(i,N-1) {
        cin >> v[i+1];
        g = gcd(g,v[i+1]);
        mx = max(mx,v[i+1]);
    }
    // bool ans = false;
    // REP(i,N) {
    //     if (v[i] < K) continue;
    //     if ((K-v[i]) % g == 0) {
    //         ans = true;
    //         break;
    //     }
    // }

    if ((K <= mx && K % g == 0)) OUT("POSSIBLE")
    else OUT("IMPOSSIBLE")

    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
def main():
    H,W = map(int,input().split())
    c = [list(map(int,input().split())) for _ in range(10)]
    A = [list(map(int,input().split())) for _ in range(H)]

    def mp_table(c):
        for i in range(10):
            for j in range(10):
                for k in range(10):
                    c[j][k] = min(c[j][k],c[j][i]+c[i][k])
        return c

    c = mp_table(c)

    point = 0
    for i in range(H):
        for j in range(W):
            if A[i][j] != -1:
                point += c[A[i][j]][1]

    print(point)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    int x,y,z;
    cin>>a>>b>>c;
    x=a*10+b+c;
    y=b*10+a+c;
    z=c*10+a+b;
    cout<<max({x,y,z});
    return(0);
}



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

// 回文ならばtrueを返す関数
bool Get_is_palindrome(string s) {
	bool result = true;
	for (int i = 0; i < s.size() / 2; i++) {
		if (s[i] != s[s.size() - i - 1]) {
			result = false;
		}
	}
	return result;
}

int main() {

	string s; cin >> s;
	int n = s.size();
	string left = s.substr(0, (n - 1) / 2);
	string  right = s.substr((n + 1) / 2);
	string ans = "No";
	if (Get_is_palindrome(s) && Get_is_palindrome(left) && Get_is_palindrome(right)) {
		ans = "Yes";
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612