akhauriyash/Code-Regression huggingface dataset:
from sys import exit, stderr, stdin, setrecursionlimit
input = stdin.readline
setrecursionlimit(10**7)
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return




MOD = 10**9+7
NUM = 10**5 + 2

fact = [1] * (NUM + 1)
fact_inv = [1] * (NUM + 1)

for i in range(1, NUM+1):
    fact[i] = (fact[i-1]*i) % MOD
# フェルマーの少定理から(a**MOD-1)が1 => (a**MOD-2)がaの逆元
fact_inv[NUM] = pow(fact[NUM], MOD-2, MOD)

# 階乗の逆元は、逆元の階乗なので、(n-1)!の逆元を求めたいなら(n!の逆元)*nでOK
for i in range(NUM, 2, -1):
    fact_inv[i-1] = (fact_inv[i]*i) % MOD

def perm(n,k):
    if n<k or k<0:
        return 0
    else:
        return (fact[n]*fact_inv[n-k])% MOD



def main():
    N, K = map(int,input().split())

    adjl = [[] for _ in range(N)]
    for _ in range(N-1):
        a ,b = map(int,input().split())
        a ,b = a-1, b-1
        adjl[a].append(b)
        adjl[b].append(a)
    deg = [len(n) for n in adjl]

    def count(n, parent = None):
        # ルートなら親を含めたその子の塗り方
        if parent is None:
            c = perm(K,deg[n]+1)
        # それ以外なら自分と親が決まってるので子の塗り方
        else:
            c = perm(K-2,deg[n]-1)
        for neigh in adjl[n]:
            if neigh == parent:
                continue
            c *= count(neigh,n)
            c %= MOD
        return c
    print(count(0))





if __name__ == "__main__":
    main()


Measured memory_bytes: 115564
using System;

namespace arc063_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char now = s[0];
            int x = 0;
            for (int i = 1; i < s.Length; i++)
            {
                if (now != s[i])
                {
                    x++;
                }
                now = s[i];
            }
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 3032
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
s = [list(input()) for c in range(H)]
a = [[1 for c in range(W)] for d in range(H)]
b = [[0 for c in range(W)] for d in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j]=="#":
            if i-1 >= 0:
                if s[i-1][j] == "#":
                    a[i][j]=0
            if j-1 >= 0:
                if s[i][j-1] == "#":
                    a[i][j]=0
            if j+1 < W:
                if s[i][j+1] == "#":
                    a[i][j]=0
            if i+1 < H:
                if s[i+1][j] == "#":
                    a[i][j]=0
        else:
            a[i][j]=0
        if a[i][j] == 1:
            print("No")
            sys.exit(0)

print("Yes")

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

#define endl "\n"
#define int int64_t
#define ll long long

void solve()
{
std::map<int, int> mp;
for(int i=0;i<3;i++){
	int x;
	cin>>x;
	mp[x]++;
}

if(mp[5]==2&&mp[7]==1){
	cout<<"YES"<<endl;
}
else{
	cout<<"NO"<<endl;
}


}

int32_t main()
{

	// int test;
	// cin >> test;
	// while (test--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<cmath>
#include<vector>
#include<string>

using namespace std;
#define ML 1000

inline int comp_char(char a,char b) { if(a==b) return 1;else return 0;}


int longest_cmmsubseq(string &xcomp,string &ycomp,vector<vector<int>> &memo){
  int ysize=ycomp.size();
  int xsize=xcomp.size();
  int max=0;
  for(int i=0;i<xsize;i++){
    if(ycomp.at(0)==xcomp.at(i)){
      while(i<xsize){ memo.at(i).at(0)=1; i++;}
      continue;
    }
    else memo.at(i).at(0)=0;
  }
  for(int j=0;j<ysize;j++){
    if(ycomp.at(j)==xcomp.at(0)){
      while(j<ysize){ memo.at(0).at(j)=1; j++;}
      continue;
    }
    else memo.at(0).at(j)=0;
  }

  for(int j=1;j<ysize;j++){
    for(int i=1;i<xsize;i++){
      max=memo.at(i-1).at(j-1)+comp_char(xcomp.at(i),ycomp.at(j));
      if(max<memo.at(i-1).at(j)) max=memo.at(i-1).at(j);
      if(max<memo.at(i).at(j-1)) max=memo.at(i).at(j-1);
      memo.at(i).at(j)=max;
      max=0;
    }
  }
  return memo.at(xsize-1).at(ysize-1);
}

int main(void){

  int size;
  cin>>size;

  vector<vector<int>> memo(ML,vector<int>(ML));
  string xcomp,ycomp;
  for(int i=0;i<size;i++){
    cin>>xcomp>>ycomp;
    cout<<longest_cmmsubseq(xcomp,ycomp,memo)<<endl;
  }
}



Measured memory_bytes: 6844
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  
  int N, ans = 0;
  
  cin>>N;
  
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if( a % 2 == 1 ) ans = 1;
  }
  
  if( ans ) cout<<"first"<<endl;
  else cout<<"second"<<endl;
  
  return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> flower(n);
  for (int i = 0; i < n; i++) cin >> flower[i];
  
  int ans = 0;
  int max = *max_element(flower.begin(), flower.end());
  
  while (max > 0) {
    for (int i = 0; i < n; ) {
      if (flower[i] > 0) {
        int last = i + 1; // for "i=(n-1)", as it won't do the for loop below.
        for (int j = i + 1; j < n; j++) {
          if (flower[j] != 0) last = j + 1;
          else break;
        }
        for (int j = i; j < last; j++) flower[j]--;
        ans++;
        i = last;
      }
      i++;
    }
    max = *max_element(flower.begin(), flower.end());
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int,input().split())

A=[[10**12 for i in range(N+1)]for j in range(N+1)]
B=[[10**12 for i in range(N+1)]for j in range(N+1)]
for i in range(M):
    a,b,c=map(int,input().split())
    if c<=L:
        A[a][b]=c
        A[b][a]=c
        B[a][b]=1
        B[b][a]=1

#print(A)


A= floyd_warshall(A,directed = False)
#print(A)
for i in range(N+1):
    for j in range(N+1):
        if A[i][j]<=L:
            B[i][j]=1
"""for c in range(1,N+1):
    for a in range(1,N+1):
        for b in range(1,N+1):
            A[a][b]=min(A[a][b],A[a][c]+A[c][b])
            if A[a][b]<=L:
                B[a][b]=1"""
#print(B)

B= floyd_warshall(B,directed = False)
"""for c in range(1,N+1):
    for a in range(1,N+1):
        for b in range(1,N+1):
            B[a][b]=min(B[a][b],B[a][c]+B[c][b])"""

#print(B)
Q=int(input())
for i in range(Q):
    s,t=map(int,input().split())
    if B[s][t]==10**12:
        print(-1)
    else:
        print(int(B[s][t]-1))

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

int main() {
	int i, N;
	int ans = 0;
	bool *p;
	cin >> N;
	p = new bool[N];
	for (i = 0; i < N; i++) {
		int t;
		cin >> t;
		p[i] = t == i + 1;
	}
	for (i = 0; i < N; i++) 
		if (p[i]) {
			if (p[i + 1]) i++;
			ans++;
		}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 1; i <= n; i++) {
            map.put(i, new ArrayList<>());
        }
        for (int i = 0; i < n - 1; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            List<Integer> alist = map.get(a[i]);
            alist.add(b[i]);
            map.put(a[i], alist);
            List<Integer> blist = map.get(b[i]);
            blist.add(a[i]);
            map.put(b[i], blist);
        }

        Deque<int[]> queue = new ArrayDeque<>();
        queue.add(new int[] { 1, 0 });
        boolean[] visited = new boolean[n + 1];
        visited[1] = true;
        Map<Integer, Map<Integer, Integer>> ans = new HashMap<>();
        int max = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                int[] q = queue.poll();
                int src = q[0];
                int prev = q[1];
                int color = 1;
                List<Integer> dests = map.get(src);
                for (int j = 0; j < dests.size(); j++) {
                    int dest = dests.get(j);
                    if (visited[dest]) {
                        continue;
                    }
                    visited[dest] = true;
                    if (color == prev) {
                        color++;
                    }
                    Map<Integer, Integer> destmap = ans.getOrDefault(src, new HashMap<>());
                    destmap.put(dest, color);
                    ans.put(src, destmap);
                    max = Math.max(max, color);
                    queue.add(new int[] { dest, color });
                    color++;
                }
            }
        }
        System.out.println(max);
        for (int i = 0; i < n - 1; i++) {
            System.out.println(ans.get(a[i]).get(b[i]));
        }
    }

}


Measured memory_bytes: 115920
import sys
n,a,b = map(int,input().split())
if a == 0:
    print(0)
    sys.exit()

if b == 0:
    print(n)
    sys.exit()

if n%(a+b) <= a:
    print(n//(a+b)*a + n%(a+b))
else:
    print(n//(a+b)*a + a)


Measured memory_bytes: 8944
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		while(sc.hasNext()) {
			double x1 = Double.parseDouble(sc.next());
			double y1 = Double.parseDouble(sc.next());
			double x2 = Double.parseDouble(sc.next());
			double y2 = Double.parseDouble(sc.next());
			double x3 = Double.parseDouble(sc.next());
			double y3 = Double.parseDouble(sc.next());
			double x4 = Double.parseDouble(sc.next());
			double y4 = Double.parseDouble(sc.next());
			if(x1 <= x4 && x2 >= x3 && y1 <= y4 && y2 >= y3) {
				out.println("YES");
			}
			else {
				out.println("NO");
			}
		}
		out.flush();
	}
}
	
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 17024
import numpy as np

X = int(input())

def beki(num):
  for j in range(1, num+1):
    for k in range(2, 10):
      if j ** k == num:
        return True
  return False


for i in range(X, 0, -1):
  if beki(i):
    print(i)
    break

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    for(int i=0;i<S.size();i++){
        if(S.at(i)+N-65<26) S.at(i)+=N;
        else S.at(i)='A'+(S.at(i)+N-26-65);
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    int f = 0;
    rep(i, N) {
        int a;
        cin >> a;
        f += a - 1;
    }
    write(f);
}

Measured memory_bytes: 256
S = str(input())
S = list(S)

for i in range(4):
    S[i] = int(S[i])

mae = S[0] * 10 + S[1]
usiro = S[2] * 10 + S[3]

if mae <= 12 and usiro <= 12 and mae != 0 and usiro != 0:
    print("AMBIGUOUS")
elif mae <= 12 and mae != 0:
    print("MMYY")
elif usiro <= 12 and usiro != 0:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main(){
  long long N,ans=pow(10,12)+1;
  cin>>N;
  int n=pow(N,0.5);
  for(int i=1;i<=n+1;i++){
    if(N%i==0){
      if(ans>N/i+i-2) ans=N/i+i-2;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ":" << x << "\n"
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

int main() {
    ll H;
    cin >> H;
    ll ans = 1LL;
    while (H > 0) {
        H /= 2;
        ans *= 2LL;
    }
    ans -= 1LL;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



int K, N;
vector<int> ans;
//---------------------------------------------------------------------------------------------------
int M;
void back() {
    ans[M]--;
    if (0 < ans[M]) {
        rep(i, M + 1, N) ans[i] = K;
        M = N - 1;
    } else M--;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> K >> N;

    if (K % 2 == 0) {
        ans.push_back(K / 2);
        rep(i, 0, N - 1) ans.push_back(K);
    } else {
        rep(i, 0, N) ans.push_back((K + 1) / 2);
        M = N - 1;
        rep(i, 0, N / 2) back();
    }

    rep(i, 0, N) {
        if (ans[i] == 0) break;
        if (i) printf(" ");
        printf("%d", ans[i]);
    } printf("\n");
}

Measured memory_bytes: 3568
def main():
    N = int(input())
    l = [int(x) for x in input().split()]
    Alice = 0
    Bob = 0
    l.sort()
    l.reverse()
    for i in range(len(l)):
        if i % 2 == 0:
            Alice += l[i]
        else:
            Bob += l[i]
    print(Alice-Bob)
main()

Measured memory_bytes: 9064
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int ans=0;
    for(int i=0; i<4; i++) {
        if(s[i]=='+') ans++;
        else if(s[i]=='-') ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, K, point = 1;
  cin >> N >> K;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(i >= K) {
      if(A.at(i) > A.at(i - K)) cout << "Yes" << endl;
      else cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    
    cin >> N;
    
    int V[N],C[N];


    for(int i=0;i<N;i++) cin >> V[i];
    
    for(int i=0;i<N;i++) cin >> C[i];

    int ans = 0;
    
    for(int i=0;i<N;i++){
    
        if(V[i]>=C[i]) ans+=(V[i]-C[i]);
    
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())

if a == 0 :
    ans = 0
elif b == 0 :
    ans = n
else :
    roop = a + b
    roop_count = int(n/roop)
    roop_amari = n % roop
    if roop_amari <= a :
        ans = roop_count * a + roop_amari
    elif roop_amari > a :
        ans = roop_count * a + a
        
print(ans)

Measured memory_bytes: 3064
N, M = map(int, input().split())
pairs = []
for _ in range(M):
    i, j = map(int, input().split())
    pairs.append([i, j])

pairs.sort(key=lambda x: x[1])  # 終端が早い順に並び替え

# 重複区間除去(greedy)
current = 0
bag = []
for pair in pairs:
    if pair[0] >= current:
        bag.append(pair)
        current = pair[1]

print(len(bag))

Measured memory_bytes: 62552
from collections import deque


def main():
    da = deque(input())
    db = deque(input())
    dc = deque(input())

    card = da.popleft()

    while True:
        if card == "a":
            if len(da) != 0:
                card = da.popleft()
            else:
                ans = "A"
                break
        elif card == "b":
            if len(db) != 0:
                card = db.popleft()
            else:
                ans = "B"
                break
        elif card == "c":
            if len(dc) != 0:
                card = dc.popleft()
            else:
                ans = "C"
                break
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9292
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, m;
vector<int> G[100010]; 
int d[100010];
bool f = true;

void dfs(int now, int pre, int c){
    if(d[now] == 0){
        d[now] = c;
    }else{
        if(d[now] != c){
            f = false;
        }
        return;
    }
    // cout << now << endl;
    rep(i, 0, G[now].size()){
        int next = G[now][i];
        dfs(next, now, c * (-1));    
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    rep(i, 0, m){
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    rep(i, 0, n) d[i] = 0;
    dfs(0, -1, 1);
    int all = n * (n - 1) / 2;
    if(f == false){
        cout << all - m << endl;
    }else{
        int odd = 0, even = 0;
        rep(i, 0, n){
            if(d[i] == -1) odd++;
            else even++;
        }
        cout << all - m - odd * (odd - 1) / 2 - even * (even - 1) / 2 << endl;
    }
}

Measured memory_bytes: 7936
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &a[i])
	}
	copy(b, a)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i := 0; i < n; i++ {
		if b[i] == a[0] {
			fmt.Fprintln(write, a[1])
		} else {
			fmt.Fprintln(write, a[0])
		}
	}
}


Measured memory_bytes: 7680
///////////////////////////////////////////////////
/* __                                       __   */
/*|  |--.-----.---.-.----.----.-----.-----.|  |_ */
/*|  _  |  -__|  _  |  __|  __|  -__|  _  ||   _|*/
/*|_____|_____|___._|____|____|_____|   __||____|*/
/*                                  |__|         */
///////////////////////////////////////////////////
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long lint; using namespace std;
#define rep(counter, limit) for (long long counter = 0; counter < limit; counter++)
#define INF 1000000000000
#define MOD 10000007
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){cin.tie(0);ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}setupios;
int main() {

  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.rbegin(),a.rend());
  int al=0,bo=0;
  rep(i,n){
    if(i%2==0){
      al+=a[i];
    }else{
      bo+=a[i];
    }
  }
  cout<<al-bo<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    cin>>t;
    p=0;
    q=0;
    k=0;
    while(t--)
    {
        cin>>n>>m;
        if(p==0 && q==0)
        {
            p=n;
            q=m;

        }
        else
        {
            DL x,y;
            x=(DL)n/(DL)p;
            y=(DL)m/(DL)q;
            if(x>=y)
            {
                l=q/m;
                if(q%m!=0)
                {
                    l++;
                }
                q=l*m;
                p=l*n;
            }
            else
            {
                l=p/n;
                if(p%n!=0)
                {
                    l++;
                }
                p=l*n;
                q=l*m;
            }
        }
//        cout<<p<<" "<<q<<endl;
    }
    cout<<p+q<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

const ll Kmax = 100000 + 10;

struct edge {
	ll edge0, edge1;
};

struct DQ_data {
	ll to, cost;
};

ll K;
deque<DQ_data> DQ;
vector<edge> nodes;
bool visited[Kmax];
ll BFS[Kmax];

int main() {
	rd(K);

	edge e0;
	nodes.push_back(e0);

	repi(i, 1, K) {
		edge e;
		e.edge0 = (i * 10) % K;
		e.edge1 = (i + 1) % K;
		nodes.push_back(e);
	}

	DQ_data dd_first;
	dd_first.to = 1, dd_first.cost = 1;
	DQ.push_front(dd_first);

	while (1) {
		DQ_data c_node = DQ.front();
		DQ.pop_front();

		if (visited[c_node.to]) {
			continue;
		}

		visited[c_node.to] = true;
		BFS[c_node.to] = c_node.cost;
		if (c_node.to == 0) break;

		DQ_data dd0;
		dd0.to = nodes[c_node.to].edge0;
		dd0.cost = c_node.cost;
		DQ.push_front(dd0);
		DQ_data dd1;
		dd1.to = nodes[c_node.to].edge1;
		dd1.cost = c_node.cost + 1;
		DQ.push_back(dd1);
	}

	wrln(BFS[0]);

	return 0;
}

Measured memory_bytes: 4336
#include<stdio.h>

int main(){

	int w, h, x, y, r;

	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	if (w>=x+r&&h>=y+r&&0<=x-r&&0<=y-r)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class BinaryIndexedTree {
    private:
        int N;
        std::vector<T> dat;
    public:
        BinaryIndexedTree(int n) : N(n), dat(n+1, static_cast<T>(0)) {}
        // a is 1-indexed
        void add(int a, const T v) {
            if (a == 0) return;
            while (a <= N) {
                dat[a] += v;
                a += (a & -a);
            }
        }
        // return sum of [1, a]
        // a is 1-indexed
        T sum(int a) const {
            T res = static_cast<T>(0);
            while (a > 0) {
                res += dat[a];
                a -= (a & -a);
            }
            return res;
        }
        // return sum of [a. b)
        // a and b are 1-indexed
        T sum(int a, int b) const {
            return sum(b-1) - sum(a-1);
        }
};

void solve() {
    int N, Q;
    cin >> N >> Q;
    vector<int> c(N);
    for (int i=0; i<N; ++i) cin >> c[i];
    vector<pair<int, int>> query(Q);
    for (int i=0; i<Q; ++i) cin >> query[i].first >> query[i].second;

    vector<vector<int>> pla(N+1);
    for (int i=0; i<N; ++i) pla[c[i]].push_back(i+1);
    for (auto &v : pla) v.push_back(0);

    vector<int> cur(N+1);
    BinaryIndexedTree<int> bit(N);
    for (int i=1; i<N+1; ++i) bit.add(pla[i][cur[i]], 1);

    vector<int> id(Q);
    for (int i=0; i<Q; ++i) id[i] = i;
    sort(id.begin(), id.end(), [&query](int i, int j){return query[i] < query[j];});

    vector<int> res(Q);
    int curid = 0;
    for (int i=0; i<N; ++i) {
        while (curid < Q && query[id[curid]].first == i+1) {
            res[id[curid]] = bit.sum(query[id[curid]].second);
            ++curid;
        }
        bit.add(pla[c[i]][cur[c[i]]], -1);
        bit.add(pla[c[i]][++cur[c[i]]], 1);
    }

    for (int x : res) cout << x << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 47024
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
l=["R"]*x+["U"]*y+["L"]*x+["D"]*y+["D"]+["R"]*(x+1)+["U"]*(y+1)+["L"]+["U"]+["L"]*(x+1)+["D"]*(y+1)+["R"]
print("".join(l))

Measured memory_bytes: 3288
/* 
	Author: ankrypt
*/

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

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 200005
#define PI 3.141592653589793
#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 trace5(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 go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], pref1[MAX_INT], pref2[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

ll check(ll ind, int X) {
	return (pref1[X] + pref2[ind] <= A);
}

ll bs(int X) {
	ll low = 0;
	ll high = M;
	while(low + 1 < high) {
		ll mid = low + (high - low) / 2;
		if(check(mid, X)) {
			low = mid;
		}
		else {
			high = mid;
		}
	}
	if(check(high, X)) {
		return high;
	}
	else {
		return low;
	}
}

int main() {
	go;
    cin >> N >> M >> A;
    fei(i, 1, N, 1) {
    	cin >> arr[i];
    }
    fei(i, 1, M, 1) {
    	cin >> arr1[i];
    }
    pref1[0] = 0;
    fei(i, 1, N, 1) {
    	pref1[i] = arr[i] + pref1[i - 1];
    }
    pref2[0] = 0;
    fei(i, 1, M, 1) {
    	pref2[i] = arr1[i] + pref2[i - 1];
    }
    ll finalAns = 0;
    fei(i, 0, N, 1) {
    	if(pref1[i] > A) {
    		continue;
    	}
    	ll ans = i;
    	ll ind = bs(i);
    	ans += ind;
    	finalAns = max(ans, finalAns);
    }
    cout << finalAns << "\n";
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

int gcd(int x, int y){
  int a = max(x, y);
  int b = min(x, y);
  if(b == 0){
    return a;
  }
  return gcd(b, a % b);
}

int N, A[100000], former[100005], latter[100005];

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  // former[i] = gcd(A[: i))
  former[1] = A[0];
  for(int i = 1; i <= N; i++){
    former[i + 1] = gcd(A[i], former[i]);
  }

  // latter[i] = gcd(A[i:])
  latter[N - 1] = A[N - 1];
  for(int i = N - 2; i >= 0; i--){
    latter[i] = gcd(latter[i + 1], A[i]);
  }

  int ans = max(latter[1], former[N - 1]);
  for(int i = 1; i < N - 1; i++){
    ans = max(ans, gcd(former[i], latter[i + 1]));
  }

  cout << ans << endl;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#define MIN_N 2
#define MAX_N 100
#define MAX_M 1000
#define MAX_X 100000

int main (void) {
	int i, n, x, *m, result, min = MAX_M;
	scanf("%d %d[^\n]", &n, &x);
	if (n < MIN_N || n > MAX_N || x > MAX_X) return -1;
	m = malloc(sizeof(int) * n);
	for (i = 0; i < n; i++) {
		scanf("%d", m + i);
		if (min > m[i]) min = m[i];
		x -= m[i];
	}
	if (x < 0) return -1; 
	result = n + x / min;
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

int main() {

    uint64_t n;
    std::cin >> n;
    uint32_t ac = 0;
    uint32_t wa = 0;
    uint32_t tle = 0;
    uint32_t re = 0;

    std::string s[n+1];

    for (int i = 0; i < n; ++i) {
        std::cin >> s[n];
        if(s[n] == "AC") ac++;
        else if(s[n] == "WA") wa++;
        else if(s[n] == "TLE") tle++;
        else re++;
    }

    std::cout << "AC x " << ac << "\n";
    std::cout << "WA x " << wa << "\n";
    std::cout << "TLE x " << tle << "\n";
    std::cout << "RE x " << re << "\n";

    return 0;
}


Measured memory_bytes: 6752
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return


ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

int main(){

    int n,m;
    cin >> n  >> m;
    int a[n];
    inrep(n,a);
    ll sum = 0;
    rep(i,0,n)sum += a[i];
    
    rsort(a,a+n,int);

    if((double)a[m-1] >= (double)sum/(4*m))Yes;
    else No;
    return  0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> x(n);
  int a, b;
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    x.at(a - 1)++;
    x.at(b - 1)++;
  }
  
  bool judge = true;
  for(int i = 0; i < n; i++){
    if(x.at(i) % 2 == 1) judge = false;
  }
  
  if(judge) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin>>n;
	cout<<((n-1)/111+1)*111<<endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    if N % 10 == 7:
        print('Yes')
        return
    d1 = N // 10
    if d1 % 10 == 7:
        print('Yes')
        return
    d2 = d1 // 10
    if d2 % 10 == 7:
        print('Yes')
        return
    print('No')
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 61772
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);

        int[][] flag = new int[4][13];
        for(int i = 0; i < n; i++) {
          line = sc.nextLine();
          String[] l = line.split(" ");

          int D = 0;
          if(l[0].equals("S")) {
            D = 0;
          } else if(l[0].equals("H")) {
            D = 1;
          } else if(l[0].equals("C")) {
            D = 2;
          } else if(l[0].equals("D")) {
            D = 3;
          }

          int N = Integer.parseInt(l[1]) - 1;

          flag[D][N] = 1;
        }

        for(int i = 0; i < 4; i++) {
          for(int j = 0; j < 13; j++) {

            String DD = "";
            if(flag[i][j] != 1) {

              if(i == 0) {
                DD = "S";
              } else if(i == 1) {
                DD = "H";
              } else if(i == 2) {
                DD = "C";
              } else if(i == 3) {
                DD = "D";
              }

              int J = j + 1;
              System.out.println(DD + " " + J);
            }
          }
        }
    }
}

Measured memory_bytes: 25880
nm_lst = list(map(int, input().split()))
city_lst = [list(map(int, (str(i)+' '+input()).split())) for i in range(nm_lst[1])]

city_lst = sorted(city_lst, key = lambda x: x[1]*(10**12) + x[2])

ans_lst = []
num_num = 0
for n, city in enumerate(city_lst):
    prefec_num = city[1]
    prefec_str = '0' * (6-len(str(prefec_num))) + str(prefec_num)
    if n == 0 or (prefec_num != city_lst[n-1][1]):
        num_num = 1
    else:
        num_num += 1
    num_str = '0' * (6-len(str(num_num))) + str(num_num)
    ans_lst.append([city[0], prefec_str, num_str])
    
ans_lst = sorted(ans_lst, key = lambda x:x[0])

for city in ans_lst:
    print(city[1]+city[2])

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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    for(auto &x: a) cin >> x;
    int sum = 0;
    for(auto x: a) sum += x;
    sort(a.begin(), a.end());
    const int pam = (sum+4*m-1)/(4*m);
    if(a[n-m] >= pam){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }


	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int S; cin >> S;
	int W; cin >> W;
	if (W >= S) {
		print("unsafe");
	} else {
		print("safe");
	}
}

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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

struct activity{
ll A,B,C;};

ll solve(ll n,vector<activity>v){
    ll dp[n+1][3];
dp[1][0]=v[1].A;
dp[1][1]=v[1].B;
dp[1][2]=v[1].C;
for(int i=2;i<=n;i++)
{
    dp[i][0]=v[i].A+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=v[i].B+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=v[i].C+max(dp[i-1][1],dp[i-1][0]);
}

return max(dp[n][0],max(dp[n][1],dp[n][2]));

}

int main()
{
    FIO;
    ll a,b,c,d,e,f=0,sum=0,ans,ck=0,m,n,k,p,q,r,t,add=0,x,y,z;

    string s;

    cin>>n;
    vector<activity>v(n+1);
    for(int i=1;i<=n;i++){cin>>v[i].A;cin>>v[i].B;cin>>v[i].C;}
    ans=solve(n,v);
    cout<<ans<<endl;



    return 0;
}



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


def solve(N: int, a: "List[int]"):
    a.sort(reverse=True)
    print(sum(a[0::2])-sum(a[1::2]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// AOJ 2480 Blame Game
// 2018.3.9 bal4u

#include <stdio.h>
#include <string.h>

#define MAX 1005
int  hi[MAX], to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, m, i, k;

	n = in(), m = in();
	for (i = 0; i < n; i++) {
		k = in(); while (k--) to[i][hi[i]++] = n+in()-1;
	}

	memset(match, -1, sizeof(match));
	k = 0; for (i = 0; i < n; i++) {
		memset(seen, 0, n+m);
		if (bpm(i)) k++;
	}
	puts(k == m? "Bob": "Alice");
	return 0;
}



Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

typedef pair<pair<string, int>, int> P;

int main()
{
    int N;
    cin >> N;
    vector<P> SP(N);

    for (int i = 0; i < N; i++)
    {
        cin >> SP[i].first.first;
        cin >> SP[i].first.second;
        SP[i].first.second *= -1;
        SP[i].second = i;
    }

    sort(SP.begin(), SP.end());

    for (int i = 0; i < N; ++i)
    {
        cout << SP[i].second + 1 << endl;
    }

    // cout << SP << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

S = []
T = []

n = int(input())

S = [int(n) for n in input().split()]

q = int(input())

T = [int(q) for q in input().split()]

def binarySearch(key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if S[mid] == key:
            return mid
        elif key < S[mid]:
            right = mid
        else: left = mid + 1
    return -1


cnt = 0

S.sort()
T.sort()
prev = -1

while len(T) > 0:
    key = T.pop()

    if key != prev and binarySearch(key) > 0:
        cnt += 1
    prev = key

print(cnt)


Measured memory_bytes: 17380
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

x,k,d=map(int,input().split())

if k%2==0:
    ans=abs(x)
else:
    ans=min(abs(x-d),abs(x+d))
if x>0:
    persuit=x%abs(d)
    moves=x//abs(d)
    if k<=moves:
        ans=min(ans,x-abs(d)*k)
    else:
        if (k-moves)%2==0:
            ans=min(ans,persuit)
        else:
            ans=min(ans,abs(persuit-abs(d)))
else:
    persuit=(-1)*(abs(x)%abs(d))
    moves=abs(x)//abs(d)
    if k<=moves:
        ans=min(ans,abs(x+abs(d)*k))
    else:
        if (k-moves)%2==0:
            ans=min(ans,abs(persuit))
        else:
            ans=min(ans,abs(persuit+abs(d)))
print(ans)

Measured memory_bytes: 9280
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int n,sizes[100005],rt,maxx=0x3f3f3f3f,vs=0,h[100005],cnt;
long long ans=0;
struct Edge
{
	int to,next,v;
}w[200005];
void add(int x,int y,int z)
{
	w[++cnt]=Edge{y,h[x],z};
	h[x]=cnt;
}
void dfs(int x,int fa,int v)
{
	sizes[x]=1;
	int s=0;
	for(int i=h[x];i;i=w[i].next)
	{
		int to=w[i].to;
		if(to==fa) continue;
		dfs(to,x,w[i].v);
		sizes[x]+=sizes[to];s=max(s,sizes[to]);
	}
	if(sizes[x]*2==n) vs=v;
	ans+=1ll*min(sizes[x],n-sizes[x])*v;
	s=max(s,n-sizes[x]);
	if(s<maxx) maxx=s,rt=x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z),add(y,x,z);
	}
	dfs(1,0,0);
	if(!vs)
	{
		vs=0x3f3f3f3f;
		for(int i=h[rt];i;i=w[i].next) vs=min(vs,w[i].v);
	}
	printf("%lld\n",ans*2-vs);
}

Measured memory_bytes: 13608
#include <iostream>
#define ll long long
using namespace std;
ll dp[3001][3001],ar[3001];
int main()
{
	ll n;cin>>n;
	for (int i=1;i<=n;i++) {cin>>ar[i];}
	for (int i=1;i<=n;i++) 
	{
		dp[i][i] = ar[i];
		if (!(n%2)) {dp[i][i] = -dp[i][i];}
	}
	for (int i=2;i<=n;i++)
	{
		for (int j=i;j<=n;j++)
		{
			if ((i+(int)(!(n%2)))%2) {dp[j-i+1][j] = max(dp[j-i+2][j]+ar[j-i+1],dp[j-i+1][j-1]+ar[j]);}
			else {dp[j-i+1][j] = min(dp[j-i+2][j]-ar[j-i+1],dp[j-i+1][j-1]-ar[j]);}
			//cout<<(i+(int)(!(n%2)))%2<<" "<<j-i+1<<" "<<j<<" "<<dp[j-i+1][j]<<"\n";
		}
	}
	cout<<dp[1][n]<<"\n";
	return 0;
}

Measured memory_bytes: 70016