akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    FOR(i,1, n){
        cin >> arr[i];
    }
    int cnt = 0;
    FOR(i, 1, n){
        if(i != arr[i]) cnt++;
    }
    if(cnt == 2 || cnt == 0){
        cout << "YES";
    }
    else {
        cout << "NO";
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

struct edge{int to; ll cost; };
int V;
vector<edge> G[100000];
ll d[100000];

void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d,d+V,10000000000000);
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v]<p.first) continue;
		for(int i=0;i<G[v].size();i++){
			edge e = G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to] = d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	cin >> V;
	for(int i=0;i<V-1;i++){
		int s,t;
		cin >> s >> t;
		s--; t--;
		ll l; cin >> l;
		l = l%2;
		edge e1; e1.to = t; e1.cost = l;
		edge e2; e2.to = s; e2.cost = l;
		G[s].push_back(e1);
		G[t].push_back(e2);
	}
	dijkstra(0);

	for(int i=0;i<V;i++){
		if(d[i]%2==0){
			cout << "0" << endl;
		}else{
			cout << "1" << endl;
		}	
	}

	return 0;
}

Measured memory_bytes: 8704
#include <cstdio>
#include <map>
#define F(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
int n,a;
map<int,int>m;
int main(){
	scanf("%d",&n);
	F(i,1,n){
		scanf("%d",&a);
		++m[a];
		++m[a-1];
		++m[a+1];
	}
	int maxn=0;
	for(map<int,int>::iterator it=m.begin();it!=m.end();++it)maxn=max(maxn,it->second);
	printf("%d\n",maxn);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll n;
    ll a[5];
    cin>>n>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    ll min=a[0];
    for(int i=0;i<5;i++){
        if(a[i]<min) min=a[i];
    }
    cout<<4+(n+min-1)/min<<endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
     ll N;
    
    cin >>N;
    ll n = sqrt(N)+1;
    ll max=1;
    rep2(i,n){
        if((N%i) == 0){
            max = i;
        }
    }
    ll ans = max + N/max -2;
    cout << ans << endl;
    
    
    return 0;
    

}

Measured memory_bytes: 3564
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

// index が条件を満たすかどうか
bool isOK(vl &a, ll index, ll key) {
	ll cnt = 0;
	rep(i, a.size()) {
		cnt += ceil((double)a[i] / index)-1;
	}
	return cnt <= key;
}

ll binary_search(vl &a, ll key) {
	ll ng = 0;
	ll ok = 1000000001;

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (isOK(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(void) {
	ll n, k;
	cin >> n >> k;
	vl a(n);
	rep(i, n) cin >> a[i];
	cout << binary_search(a, k) << endl;
	return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n,k;
  cin>>n>>k;
  map<int, int> mp;
  int x;
  rep(i,n) {
    cin>>x;
    mp[x]++;
  }
  vector<int> b;
  for(auto m: mp) {
    b.push_back(m.second);
  }
  sort(b.begin(), b.end());
  int ans = 0;
  if((int)b.size() - k > 0) {
    rep(i, b.size() - k) {
      ans += b[i];
    }
  }
  cout << ans << endl;


  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int N;
long long a[500], acc[500], dp[500][500];
long long getAcc(int l, int r) {
    if(l == 0) {
        return acc[r - 1];
    } else {
        return acc[r - 1] - acc[l - 1];
    }
}
long long rec(int l, int r) {
    if(dp[l][r] != -1) {
        return dp[l][r];
    }

    // 1
    if(l == r - 1) {
        return 0;
    }

    long long res = llINF;

    for(int mid = l + 1; mid < r; mid++) {
        res = min(res, rec(l, mid) + rec(mid, r) + getAcc(l, r));
    }

    return dp[l][r] = res;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        acc[i] = a[i];
    }
    REP(i, N - 1) { acc[i + 1] += acc[i]; }
    fill(dp[0], dp[500], -1);
    cout << rec(0, N) << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


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

}



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

  int main() {
    long long A,B,K;
    cin >>K;
      cin >> A >> B;
    long long ans =0;
    for(long long i = A; i <= B; i++){
      if(i % K == 0){
        ans ++;
      }
    }
      if(ans != 0){
        cout << "OK" << endl;
      }
        else{
          cout << "NG" << endl;
        }
      
      

  }
  

Measured memory_bytes: 3660
N = int(input())
S = input()
ans = 0
for i in range(N-1):
    c = 0
    for j in range(26):
        if chr(j+97) in S[:i+1] and chr(j+97) in S[i+1:]:
            c += 1
    if c > ans:
        ans = c
print(ans)


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

ll h, w;

ll solve() {
	ll res = 1ll<<62;
	
	for (ll i = 1; i < h; i++) {
		ll s[3];
		s[0] = i * w;
		s[1] = (h - i) * (w / 2);
		s[2] = (h - i) * ((w + 1) / 2);
		
		sort(s, s + 3);
		chmin(res, s[2] - s[0]);
	}
	
	for (ll i = 1; i < h - 1; i++) {
		ll s[3];
		s[0] = i * w;
		s[1] = (h - i) / 2 * w;
		s[2] = (h - i + 1) / 2 * w;
		
		sort(s, s + 3);
		chmin(res, s[2] - s[0]);
	}
	
	return res;
}

int main() {
	cin >> h >> w;
	
	ll ans = 1ll<<60;
	
	chmin(ans, solve());
	swap(h, w);
	chmin(ans, solve());
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C,D,E,K;
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>D;
	cin>>E;
	cin>>K;
	if (abs(A-B)>K || abs(A-C)>K || abs(A-D)>K ||abs(A-E)>K){
		cout<<":("<<endl;
		return 0;
	}
	if (abs(B-A)>K || abs(B-C)>K || abs(B-D)>K ||abs(B-E)>K){
		cout<<":("<<endl;
		return 0;
	}
	if (abs(C-A)>K || abs(C-B)>K || abs(C-D)>K ||abs(C-E)>K){
		cout<<":("<<endl;
		return 0;
	}
	if (abs(D-A)>K || abs(D-B)>K || abs(D-C)>K ||abs(D-E)>K){
		cout<<":("<<endl;
		return 0;
	}
	if (abs(E-A)>K || abs(E-B)>K || abs(E-C)>K ||abs(E-D)>K){
		cout<<":("<<endl;
		return 0;
	}
	cout<<"Yay!"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 100;
static const int INF = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];

void dijkstra() {
    int color[n], d[n], p[n];
    for (int i = 0; i < n; i++) {
        color[i] = WHITE;
        d[i] = INF;
    }
    int s = 0;
    d[s] = 0;

    while(true) {
        int v = -1;
        int minv = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && minv > d[i]) {
                v = i;
                minv = d[i];
            }
        }
        if (v == -1) break;
        color[v] = BLACK;
        for (int u = 0; u < n; u++) {
            if (color[u] != BLACK && M[v][u] != INF){
                if (d[u] > d[v] + M[v][u]){
                    d[u] = d[v] + M[v][u];
                    color[u] = GRAY;
                }
            }
        }

    }
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

}

int main() {
    int u, k;
    cin >> n;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            M[i][j] = INF;
        }
    }
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            int v, c;
            cin >> v >> c;
            M[u][v] = (c == 0) ? INF : c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 3080
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		long ans = 1;
		int MOD = 1000000007;
		int N = sc.nextInt();
		int[] count = new int[N];
		for(int i = 0; i < N; i++){
			int A = sc.nextInt();
			count[A]++;
		}
		
		if(N % 2 == 0){
			for(int i = 1; i <= N - 1; i += 2)
				if(count[i] != 2){
					System.out.println(0);
					return;
				}else ans = (ans * 2) % MOD;
			System.out.println(ans);
		}else{
			if(count[0] != 1){
				System.out.println(0);
				return;
			}
			for(int i = 2; i <= N - 1; i += 2)
				if(count[i] != 2){
					System.out.println(0);
					return;
				}else ans = (ans * 2) % MOD;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 50660
open Printf
open Scanf

let solve n d =
  let lxy = List.init n @@ fun _ -> scanf "%d %d " @@ fun x y -> (x, y) in
  let f ct (x, y) = if d * d >= x * x + y * y then ct + 1 else ct in
  List.fold_left f 0 lxy

let () =
  scanf "%d %d " solve |> printf "%d\n"


Measured memory_bytes: 20584
n,m,k=map(int,input().split())
fact,factinv,mod=[1]*n,[1]*n,998244353
for i in range(2,n):
  fact[i]=fact[i-1]*i%mod
factinv[n-1]=pow(fact[n-1],mod-2,mod)
for i in range(n-2,0,-1):
  factinv[i]=factinv[i+1]*(i+1)%mod
ncr=lambda n,r:fact[n]*factinv[r]%mod*factinv[n-r]%mod
ans=pow(m,n,mod)
for i in range(k+1,n):
  ans+=mod-m*pow(m-1,n-i-1,mod)*ncr(n-1,i)%mod
print(ans%mod)

Measured memory_bytes: 24536
import fractions

def factor(x):
  t = x
  p = [1]
  for i in range(2, -int(-x**0.5//1)+1):
    if x % i == 0:
      p += [i]
      while x % i == 0:
        x /= i
  if len(p) == 1 and t != 1:
    p += [t]
  return p

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


A, B = list(map(int, input().split()))
d = fractions.gcd(A, B)
#p = factor(d)
p = factorization(d)
#print(p)
print(len(p) + (0 if p[0][0] == 1 else 1))


Measured memory_bytes: 5212
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
C = Counter(A)
res = 0

for k, v in C.items():
    if v < k:
        res += v
    elif v > k:
        res += (v - k)
print(res)


Measured memory_bytes: 18676
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		String s = sc.next();
		
		System.out.println(!s.substring(0, a).contains("-") && s.charAt(a) == ('-') && !s.substring(a+1).contains("-") ? "Yes" : "No");
	}
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int ans = 0, size = S.size();
    for (int i = 0; i < size/2; ++i) {
        if (S[i] != S[size-i-1]) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
a,b,c,d = gets.chomp.split(" ").map(&:to_i)

c_count = b / c - a / c
c_count += 1 if a % c == 0

d_count = b / d - a / d
d_count += 1 if a % d == 0

cd = c.lcm(d)
cd_count = b / cd - a / cd
cd_count += 1 if a % cd == 0

puts b - a + 1 - c_count - d_count + cd_count


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

using namespace std;

#define int long long
#define ll long long
#define mst(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(ll i=a; i<b; i++)
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

ll n;
ll a[401];
ll pref[401];
ll cache[401][401];

ll dp(ll l, ll r){
    if(l==r) return 0;
    ll &ans=cache[l][r];
    if(ans!=-1) return ans;
    ans=inf;
    for(ll i=l; i<=r; i++){
        ans=min(ans,dp(l,i)+dp(i+1,r)+pref[r]-pref[l-1]);
    }
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,1,n+1){
        cin >> a[i];
        pref[i]=pref[i-1]+a[i];
    }
    mst(cache,-1);
    ll res=dp(1,n);
    cout << res;
    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <bits/stdc++.h>
#include <iostream>

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

using namespace std;

int main()
{
  int h,w,n,tmp;
  scanf("%d", &h);
  scanf("%d", &w);
  scanf("%d", &n);

  if(h>w)
    tmp=h;
  else
    tmp=w;

  int ans;
  ans = n/tmp;

  if(n%tmp!=0)
    ans+=1;

  cout << ans << endl; 


  return 0;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline

MAX = 2e9

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]
    L.append(MAX)
    R = A[mid:right]
    R.append(MAX)
    merged = []
    index_L = 0
    index_R = 0
    comp_cnt = 0
    for _ in range(n1+n2):
        cand_L = L[index_L]
        cand_R = R[index_R]
        comp_cnt += 1
        if (cand_L < cand_R):
            merged.append(cand_L)
            index_L += 1
        else:
            merged.append(cand_R)
            index_R += 1
    A[left:right] = merged
    return comp_cnt
        
def merge_sort(A, left, right):
    comp_cnt = 0
    if (left + 1 < right):
        # Devide
        mid = (left + right) // 2
        # Solve
        _, cnt = merge_sort(A, left, mid)
        comp_cnt += cnt
        _, cnt = merge_sort(A, mid, right)
        comp_cnt += cnt
        # Conquer
        comp_cnt += merge(A, left, mid, right)
    return A, comp_cnt

def main():
    N = int(input())
    S = list(map(int, input().split()))
    left = 0
    right = len(S)
    merged, cnt = merge_sort(S, left, right)
    print(" ".join([str(x) for x in merged]))
    print(cnt)

if __name__ == "__main__":
    main()


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

using ll=long long;



void solve(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    int sum=0;
    sum=H*w+h*W;
    sum-=h*w;
    cout<<H*W-sum<<endl;
}

signed main(){
    //while(1)
    solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, c;
  int p, sum = 0;
  
  scanf("%d%d", &n, &c);

  for(int i=0;i<c;i++){
    scanf("%d", &p);
    sum += p;
  }

  printf("%d\n", sum/(n+1) + !!(sum%(n+1)));
  
  return 0;
}



Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
	int N;
	cin >> N;
	vector<int> A( N );
	for( auto &x : A ) {
		cin >> x;
	}
	map<int,int> search;
	for (auto &x : A) {
		search[ x ]++;
		search[ x + 1 ]++;
		search[ x - 1 ]++;
	}
	int result{};
	for(auto x : search) {
		result = max(result, x.second);
	}
	cout << result << endl;

	return 0;
}


Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
 
using namespace std;
 
int main()
{
	int N = 0;
	cin >> N;
	vector<long long> T(N, 0);
 
	for (int i = 0; i < N; ++i) {
		cin >> T[i];
	}
	// sort(T.rbegin(), T.rend());
 
	// 端から最小公倍数を求めてゆく。
	long long res = T[0];
 
	for (int i = 0; i < N; ++i) {
		long long cur0 = T[i];
		if ((res % cur0) != 0) {
			if (res < cur0) {
				swap(cur0, res);
			}
			long long addUnit = res;
			while ((res % cur0) != 0) {
				res += addUnit;
			}
		}
	}
 
	cout << res << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

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

  sort(a,a+n);

  ll ans=a[0];
  ll h=a[n-1]/2;
  ll m=abs(h-a[0]);
  if(a[n-1]&1){
    m=min(m,abs(h+1-a[0]));
    for(ll i=0;i<n-1;i++){
      if(abs(h-a[i])<m || abs(h+1-a[i])<m){
        m=min(abs(h-a[i]),abs(h+1-a[i]));
        ans=a[i];
      }
    }
  }
  else{
    for(ll i=0;i<n-1;i++){
      if(abs(h-a[i])<m){
        m=abs(h-a[i]);
        ans=a[i];
      }
    }
  }

  cout << a[n-1] << " " << ans << endl;

}

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

int64_t n; 

// 4*4
char moji4[4][4] = {
    { 'a' , 'b', 'c', 'c' },
    { 'a' , 'b', 'd', 'd' },
    { 'e' , 'e', 'f', 'g' },
    { 'h' , 'h', 'f', 'g' },
};
// 5*5
char moji5[5][5] = {
    { '.', '.', 'a', 'b', 'c' },
    { '.', '.', 'a', 'b', 'c' },
    { 'd', 'd', 'e', 'f', 'f' },
    { 'g', 'g', 'e', '.', 'h' },
    { 'i', 'i', 'j', 'j', 'h' },
};
// 6*6
char moji6[6][6] = {
    { '.', '.', '.', 'a', 'b', 'c' },
    { '.', '.', '.', 'a', 'b', 'c' },
    { 'd', '.', 'e', 'e', '.', 'f' },
    { 'd', 'g', 'g', '.', '.', 'f' },
    { 'h', 'h', 'i', '.', 'j', 'j' },
    { 'k', 'k', 'i', 'l', 'l', '.' },
};
// 7*7
char moji7[7][7] = {
    { 'a', 'a', 'b', 'b', 'c', 'c', '.', },
    { 'd', 'd', 'e', 'e', 'f', '.', '.', },
    { '.', '.', 'g', 'g', 'f', 'h', 'h', },
    { '.', '.', '.', '.', 'i', 'j', 'k', },
    { '.', '.', '.', '.', 'i', 'j', 'k', },
    { 'l', 'm', '.', '.', '.', '.', 'n', },
    { 'l', 'm', '.', '.', '.', '.', 'n', },
};
int main() {

    // 入力
    cin >> n;

    if(n==2){
        cout << -1;
        return 0;
    }else if(n==3){
        cout << 'a' << 'a' << '.' << "\n";
        cout << '.' << '.' << 'a' << "\n";
        cout << '.' << '.' << 'a' << "\n";
        return 0;

    }

    char waku[n][n];
    
    int data = n/4;
    int mod = n%4;

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

        if(num<data-1||mod==0){
            for(int j=0; j<n; j++){
                if(j>=num*4&&j<=num*4+3){
                    waku[i][j]=moji4[i%4][j%4];
                }else{
                    waku[i][j]='.';
                }
            }   
        }else{
            if(mod+4==5){
                for(int j=0; j<n; j++){
                    if(j>=(data-1)*4&&j<=(data-1)*4+4){
                        waku[i][j]=moji5[i-(data-1)*4][j-(data-1)*4];
                    }else{
                        waku[i][j]='.';
                    }
                }   
            }else if(mod+4==6){
                for(int j=0; j<n; j++){
                    if(j>=(data-1)*4&&j<=(data-1)*4+5){
                        waku[i][j]=moji6[i-(data-1)*4][j-(data-1)*4];
                    }else{
                        waku[i][j]='.';
                    }
                }   
            }else if(mod+4==7){
                for(int j=0; j<n; j++){
                    if(j>=(data-1)*4&&j<=(data-1)*4+6){
                        waku[i][j]=moji7[i-(data-1)*4][j-(data-1)*4];
                    }else{
                        waku[i][j]='.';
                    }
                }   
            }
        } 
    }


    for(int i=0; i<n; i++){
        
        for(int j=0; j<n; j++){
            cout << waku[i][j];
        }  
        cout << "\n";
    }
    return 0;
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	lli ans = 0;
	lli pos = -1;
	vector<set<lli>> vec((size_t)('a' - 'A'));
	for (int i = 0; i < s.size(); i++) {
		vec[s[i] - 'a'].insert(i);
	}
	for (int i = 0; i < t.size(); i++) {
		if (vec[t[i] - 'a'].empty()) {
			cout << -1 << endl;
			return 0;
		}
		auto lb = vec[t[i] - 'a'].lower_bound(pos + 1);
		if (lb != vec[t[i] - 'a'].end()) {
			pos = (*lb);
		}
		else {
			pos = *(vec[t[i] - 'a'].begin());
			ans++;
		}

	}
	cout << ans*s.size() + pos + 1 << endl;
	return 0;
}


Measured memory_bytes: 5120
<?php
$n = (int)trim(fgets(STDIN));
$sqrt_n = (int)pow($n, 0.5);
for($i = $sqrt_n; $i > 0; $i--) {
    if ($n % $i == 0) {
        $answer = (int)log(max($i, $n / $i), 10) + 1;
        print "$answer\n";
        break;
    }
}
?>


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

int main() {


int A , B , C = 0 ;	// A:毎日もらえるコイン数 , B:7日連続ログインでもらえるコイン数 , C:手に入れたい総コイン数


int days = 0 ; 
int week_day_count = 0 ; // 週の何日目かのカウント。月曜日:1 , 火曜日:2 , …　土曜日:6 , 日曜日:7

cin >> A >> B >> C ;


	while( C > 0 ){
	
	days = days + 1 ;			// 「経過日数」を1追加
	week_day_count = week_day_count + 1 ;	// 週の何日目かのカウントを1追加

	C = C - A ;				// 毎日のログインボーナスの処理

		if( 7 == week_day_count ) 	//「日曜日になったとき」の処理。if( week_day_count == 7 )としなかったのはミス防止
		{ C = C - B ; 
		  week_day_count = 0 ;		// 週の何日目かのカウントを0にする。
		}else{				// C++ではelse{}は省略可
		}

		if( C <= 0 ) 			// Cが0未満になったときループを抜ける
		{
		break;
		}else{				// C++ではelse{}は省略可
		}
    

	}

cout << days << endl;

}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pll> v(N);
    ll x, h;
    for (int i = 0; i < N; i++) {
        cin >> x >> h;
        v[i] = pll(x, h);
    }
    v.push_back(pll(LINF, 0LL));
    sort(v.begin(), v.end());

    vector<ll> sum(N+1);
    ll times = 0;
    for (int i = 0; i < N; i++) {
        x = v[i].first, h = v[i].second;
        h -= sum[i];
        if (h <= 0LL) {
            sum[i+1] += sum[i];
            continue;
        }
        ll mul = ceil((double) h / A);
        times += mul;
        ll bom = A * mul;
        sum[i] += bom;
        int ind = lower_bound(v.begin(), v.end(),
                    make_pair(x + 2*D + 1, numeric_limits<ll>::min())) - v.begin();
        sum[ind] -= bom;
        sum[i+1] += sum[i];
    }

    cout << times << '\n';
}


Measured memory_bytes: 8448
#include <stdio.h>
#include <bits/stdc++.h>
int self_x = 10, self_y = 10;
void command(int data[][22], char direction, int move_length) {
  while (move_length > 0) {
    switch(direction) {
    case 'N':
      self_y--;
      break;
    case 'E':
      self_x++;
      break;
    case 'W':
      self_x--;
      break;
    case 'S':
      self_y++;
      break;
    }
    data[self_y][self_x] = 0;
    move_length--;
    // printf("self_x = %d   self_y = %d\n",self_x,self_y);
  }

}

int main(void) {
  int i,j;
  int gem_num; //
  int command_num;//
  
  while (1) {
    int data[22][22] = {{0}};
    int move_length[1000] = {0};
    int gem_x[1000] = {0}, gem_y[1000] = {0};//
    char direction[1000][4] = {{0}};
    self_x = 10, self_y = 10;

    scanf("%d", &gem_num);
    if (gem_num == 0) {
      break;
    }
    for (i = 0; i < gem_num; i++) {
      scanf("%d%d", &gem_x[i], &gem_y[i]);
      data[20-gem_y[i]][gem_x[i]] = 1;
    }
    scanf("%d", &command_num);
    //    printf("command_num = %d\n",command_num);
    for (i = 0; i < command_num; i++) {
      scanf("%s", direction[i]);
      scanf("%d", &move_length[i]);
      //      printf("ss");
    }

    for (i = 0; i < command_num; i++) {
      //1_comand activate
      //printf("debug1\n");
      command(data, direction[i][0], move_length[i]);
      //     printf("debug2\n");

    }
    int flag = 0;
    for (i = 0; i < 21; i++) {
      for (j = 0; j < 21; j++) {
        if (data[i][j] != 0) {
          flag = 1;
          break;
        }
      }
    }
    
    // for (i = 0; i < 21; i++) {
    //   for (j = 0; j < 21; j++) {
    //     printf("%d ",data[i][j]);
    //   }
    //   puts("");
      
    // }









    
    if (flag == 0) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
      
    
  }
  return 0;
}

Measured memory_bytes: 1184
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
 
struct edge{int to,cost;};

signed main(){
	int n,m,d[1000];
	vector<edge> G[1000];
	cin >> n >> m;
	for(int i = 0;i < n;i++) d[i] = -INF;
	d[0] = 0;
	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c; a--;b--;
		G[a].pb({b,c});
	}
	bool flag = true;
	for(int i = 0;i < 2 * n;i++){
		for(int j = 0;j < n;j++){
			for(int k = 0;k < G[j].size();k++){
				edge e = G[j][k];
				if(d[j] != -INF && d[e.to] < d[j] + e.cost){
					d[e.to] = d[j] + e.cost;
					if(i >= n - 1 && e.to == n - 1) flag = false;
				}
			}
		}
	}
	if(!flag) cout << "inf" << endl;
	else cout << d[n - 1] << endl;
	return 0;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;

    int x , y , p;
    cin>>x>>y>>p;
    unordered_map<int , int>r;
    unordered_map<int , int>h;
    vector<pii>v;
    map<pii , int>mp;
    for(int i=0; i<p; i++) {
        pii p ;
        cin>>p.first>>p.second;
        r[p.F]++;
        h[p.S]++;
        mp[p]++;
    }
    int m , n;
    int fm=0 , fn=0;
    for(auto x:r) {
        if(x.S>fm) {
            fm = x.S;
            m = x.F;
        }
    }

    int cnt = fm ;

    for(int i=1; i <= (sint)3e5; i++)
    {
        if(h.count(i))
        {
            if(mp.count({m , i})) {
                cnt = max(cnt , fm-1+h[i]);
            }
            else cnt = max(cnt , fm + h[i]);
        }
    }
    for(auto x:h) {
        if(x.S>fn) {
            fn = x.S;
            n = x.F;
        }
    }

    int ont = fn ;

    for(int i=1; i <= (sint)3e5; i++)
    {
        if(r.count(i))
        {
            if(mp.count({i , n})) {
                ont = max(ont , fn-1+r[i]);
            }
            else ont = max(ont , fn + r[i]);
        }
    }
    cout<<max(cnt , ont)<<"\n";



}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

template<class graph_type,class T> std::vector<T> spfa(const graph_type &graph,const int start){
    std::vector<T> dist(graph.size(),std::numeric_limits<T>::max());
    std::queue<int> queue;
    std::vector<bool> in_q(graph.size(),false);
    dist[start]=0;
    queue.push(start);
    in_q[start]=true;
    while(!queue.empty()){
        const int u=queue.front();
        queue.pop();
        in_q[u]=false;
        for(const auto &edge:graph[u]){
            const int v=edge.first;
            if(dist[v]>dist[u]+edge.second){
                dist[v]=dist[u]+edge.second;
                if(!in_q[v]){
                    queue.push(v);
                    in_q[v]=true;
                }
            }
        }
    }
    return dist;
}

void solve(){
    int v,e,r;
    cin >> v >> e >> r;
    vector<vector<pair<int,int>>> graph(v);
    rep(i,0,e){
        int s,t,d;
        cin >> s >> t >> d;
        graph[s].push_back(make_pair(t,d));
    }
    vector<int> dist=spfa<vector<vector<pair<int,int>>>,int>(graph,r);
    rep(i,0,v){
        if(dist[i]==std::numeric_limits<int>::max()) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 12444
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n,n){
		int wh,hi;
		cin>>wh>>hi;
		bool place[100][100]={};
		for(int i=0,x,y;i<n;i++){
			cin>>x>>y;
			place[y][x]=1;
		}
		int w,h,ans=0;
		cin>>w>>h;
		for(int i=1;i<=hi-h+1;i++){
			for(int j=1;j<=wh-w+1;j++){
				int co=0;
				for(int k=i;k<i+h;k++){
					for(int l=j;l<j+w;l++)if(place[k][l]==1)co++;
				}
				ans=max(co,ans);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1176
def validation(l1, l2):
  dif_t = abs(l2[0] - l1[0])
  dif_x = abs(l2[1] - l1[1])
  dif_y = l2[2] - l1[2]

  if dif_x + dif_y > dif_t:
    return False
  elif dif_t % 2 == 0:
    if (dif_x + dif_y) % 2 != 0:
      return False
    else:
      return True
  elif dif_t % 2 != 0:
    if (dif_x + dif_y) % 2 == 0:
      return False
    return True
  else:
    return True

n = int(input())
l1 = [0,0,0]
ans = "Yes"
for _ in range(n):
  l2 = list(map(int, input().split()))
  if  validation(l1, l2):
    l1 = l2
  else:
    ans = "No"

print(ans)

Measured memory_bytes: 47592
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n;
    cin>>n;
    vector<ll> P(4);
    vector<ll> T(4);
    cin>>P>>T;
    vector<ll> dp(n+1000,E);
    dp[0]=0;
    ll ans=E;
    for(int i=0;i<n;i++){
        for(int j=0;j<4;j++){
            dp[i+T[j]]=min(dp[i+T[j]],dp[i]+P[j]);
            //cout<<i<<" "<<j<<endl;
            if(i+T[j]>=n){ans=min(ans,dp[i]+P[j]);}
        }
    }
    //cout<<dp<<endl;
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 3112
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        string S, T;
        cin >> S >> T;
        if (S[0] == T[2] && S[1] == T[1] && S[2] == T[0])
        {
                cout << "YES" << endl;
        }
        else
        {
                cout << "NO" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

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

    int n, l = 1e9, r = -1e9;
    cin >> n;
    map<int, int> mp;
    REP(i, n){
        int a;
        cin >> a;
        mp[a]++;
        l = min(l, a);
        r = max(r, a);
    }

    int mini = 1e9;
    for(int i = l; i <= r; i++){
        int cost = 0;
        for(auto x : mp){
            cost += abs(x.first - i) * abs(x.first - i) * x.second;
        }
        mini = min(mini, cost);
    }
    cout << mini << endl; 

    return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())

n, ma, mb = na()
abcs = []
for i in range(n):
    abcs.append(list(na()))
I = 9999999999
dp = [[I]*420 for _ in range(420)]
dp[0][0] = 0
sa = 1
sb = 1
for abc in abcs:
    for i in range(sa-1, -1, -1):
        for j in range(sb-1, -1, -1):
            dp[i+abc[0]][j+abc[1]] = min(dp[i+abc[0]][j+abc[1]], dp[i][j] + abc[2])
    sa += abc[0]
    sb += abc[1]

x = ma
y = mb
ret = I
while x< 420 and y < 420:
    ret = min(ret, dp[x][y])
    x += ma
    y += mb

if ret == I:
 print(-1)
else:
 print(ret)

Measured memory_bytes: 4980
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#include<typeinfo>
#define R(i, n) for(int i = 0;i < n; i++)
#define R1(i, n) for(int i = 1; i <= n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SC(a) scanf("%c", &a)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("YES")
#define PN printf("NO")
#define Py printf("Yes")
#define Pn printf("No")
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;
const double PI = acos(-1);

int main() {
	int n;
	S(n);
	vector<int> a(n), b(n);
	R(i, n) {
		S(a[i]);
	}
	R(i, n) {
		S(b[i]);
	}
	vector<int> plus;
	R(i, n) {
		if (a[i] > b[i]) plus.push_back(a[i] - b[i]);
	}
	sort(plus.begin(), plus.end(), greater<>());
	queue<int> q;
	R(i, plus.size()) {
		q.push(plus[i]);
	}
	int ans = 0;
	bool first = true;
	R(i, n) {
		if (a[i] < b[i]) {
			if (first) {
				ans += 2;
				first = false;
			}
			else {
				ans++;
			}
			int diff = b[i] - a[i];
			bool flag = true;
			while (flag) {
				if (!q.empty()) {
					if (diff - q.front() > 0) {
						diff -= q.front();
						q.pop();
						ans++;
					}
					else {
						q.front() -= diff;
						flag = false;
					}
				}
				else {
					P(-1);
					return 0;
				}
			}
		}
	}
	P(ans);
}

Measured memory_bytes: 1408
/*
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2152
  ?¨???¶?£???????map<kukan, int>??§????????????????????????priprity_queue??§?????????
  ?????????
  D??????erase???????????????
  ??§??????????????????????????°???????????¬?????????????????????????????????????????????????¬????????´??????????????????¬?????????
  set?????´???????????°??????????????????????????????????????????????????????????????°???
  map?????´???????????°???key??????????????????key??????????????????????????????????????????????????°???
  R??????lower_bound?????¨??????????£?????????°??\??????????°????????????????????????????????????????????????????
  ??????????????¢?????????set???lower_bound????????????????????¬?????????
  map???lower_bound???????????¬???????????????key?????????????????¨?????? ->first ??¨??????
  ????????????????????¨?????? ->second ??¨?????????
*/

#include <iostream>
#include <queue>
#include <tuple>
#include <cassert>
#include <map>
using namespace std;

const int C = 1e9+7;
typedef tuple<int, int> kukan; // ?????????????????????????????????

bool debug = false;

int main() {
  int N;
  while(cin >> N && N) {
    map<kukan, int> X;
    X[make_tuple(-1, 0)] = -1;
    X[make_tuple(C+1, 0)] = -1;
    priority_queue<kukan, vector<kukan>, greater<kukan> > Q;
    Q.push(make_tuple(0, C));
    for (auto i=0; i<N; i++) {
      char com;
      cin >> com;
      if (com == 'W') {
        int l, S;
        cin >> l >> S;
        while (S > 0) {
          assert(!Q.empty());
          kukan I = Q.top();
          Q.pop();
          int pt = get<0>(I);
          int si = get<1>(I);
          if (S >= si) {
            X[I] = l;
            S -= si;
          } else {
            X[make_tuple(pt, S)] = l;
            Q.push(make_tuple(pt+S, si - S));
            S = 0;
          }
        }
      } else if (com == 'D') {
        int l;
        cin >> l;
        auto it = X.begin();
        while (it != X.end()) {
          if (it->second == l) {
            Q.push(it->first);
            it = X.erase(it);
          } else {
            it++;
          }
        }
      } else {
        assert(com == 'R');
        int P;
        cin >> P;
        auto U = X.lower_bound(make_tuple(P, C+3));
        U--;
        auto I = U->first;
        int pt = get<0>(I);
        int si = get<1>(I);
        int va = U->second;
        if (debug) {
          cerr << "sansho" << endl;
          cerr << pt << " " << si << " " << va << endl;
        }
        if (P < pt+si) {
          cout << va << endl;
        } else {
          cout << -1 << endl;
        }
      }
      if (debug) {
        auto it = X.begin();
        it++;
        cerr << "nakami" << endl;
        auto end = X.end();
        end--;
        while (it != end) {
          cerr << get<0>(it->first) << " "
               << get<1>(it->first) << " "
               << it->second << endl;
          it++;
        }
      }
    }
    cout << endl;    
  }
}

Measured memory_bytes: 1512
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll dp[3001][3001];
int main(void) {
	int x, n, ans, s = INF;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, 0, n)cin >> p[i];
	sort(all(p));
	rep(k, 0, 102) {
		if (binary_search(all(p), k))continue;
		if (s > abs(x - k))s = abs(x - k), ans = k;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
const int N  = 2e5 + 123;
int cnt[N];

main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(NULL);cout.tie(NULL);
	int n , m;
	cin >> n >> m;
	while(m--){
		int a , b;
		cin >> a >> b;
		cnt[a]++ , cnt[b]++;
	}
	for(int i = 1 ; i <= n ; i++)
		if(cnt[i] % 2)
			return printf("NO"),0;
	printf("YES");
}

Measured memory_bytes: 640
#include <iostream>

int main() {
  int n,m;
  std::cin >> n;
  std::cin >> m;
  for(int i=0; i<m; i++) {
    int a;
    std::cin >> a;
    n -= a;
  }
  if(n<0) {
    std::cout << -1 << std::endl;
  }else{
    std::cout << n << std::endl;
  }
}

Measured memory_bytes: 3588