akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<ll> l, r;
  for(ll i = 0; i < n && l.size() < k; i++){
    if(s[i] == 'x') continue;
    if(l.empty()){
      l.emplace_back(i);
    }else if(l.back()+c < i){
      l.emplace_back(i);
    }
  }
  for(ll i = n-1; 0 <= i && r.size() < k; i--){
    if(s[i] == 'x') continue;
    if(r.empty()){
      r.emplace_back(i);
    }else if(r.back()-c > i){
      r.emplace_back(i);
    }
  }
  reverse(ALL(r));
  vector<ll> ans;
  REP(i, k){
    if(l[i] == r[i]) cout << l[i]+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 5108
H, W, A, B = map(int, input().split())

ans = []

for _ in range(H - B):
    a = ['0'] * (W - A)
    a.extend(['1'] * A)
    ans.append(a)
for _ in range(B):
    a = ['1'] * (W - A)
    a.extend(['0'] * A)
    ans.append(a)

for a in ans:
    print(*a, sep='')


Measured memory_bytes: 14324
#include<map>
#include<list>
#include<queue>
#include<iostream>
#include<unordered_set>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>

#define ull unsigned long long
#define ll long long
#define mp make_pair
#define imei(...)   "[ "<< #__VA_ARGS__ <<" = "<< __VA_ARGS__ <<" ] "

using namespace std;

void solve(int l, long long n) {
    vector<long long> tbl(1, 1);
    vector<char> cs;

    for (int i =0 ;i < 26; i++)
        cs.push_back(i+'a');

    for (int i = 0; i < l; i++)
        tbl.push_back(tbl.back()*26);

    while(l > 0) {
        int idx = (n - 1)/tbl[l-1];
        cout << cs[idx];
        n -= idx * tbl[l-1];
        l--;
    }
}

int main(int argc, char *argv[])
{
    long long n;
    cin >> n;

    long long count = 0;
    long long val = 1;
    int len = 1;

    for (;;) {
        val *= 26;
        if (count + val >= n)
            break;
        count += val;
        len++;
    }

    solve(len, n-count);

    return 0;
}


Measured memory_bytes: 3572
# -*- coding:utf-8 -*-
import sys


class Card(object):
    def __init__(self, card):
        self._suit = card[0]
        self._value = int(card[1])

    def __eq__(self, other):
        if other is None:
            return False
        return self.__dict__ == other.__dict__

    def __lt__(self, other):
        if other is None:
            return False
        return self._value < other._value

    def __le__(self, other):
        if other is None:
            return False
        return self._value <= other._value

    def __gt__(self, other):
        if other is None:
            return False
        return self._value > other._value

    def __ge__(self, other):
        if other is None:
            return False
        return self._value >= other._value

    def getValue(self):
        return self._value

    def __str__(self):
        return self._suit + " " + str(self._value)


def merge(lst, left, mid, right):
    L = lst[left: mid]
    R = lst[mid: right]
    l_len = len(L)
    r_len = len(R)
    i = 0
    j = 0
    for k in range(left, right):
        if l_len <= i:
            lst[k] = R[j]
            j += 1
        elif r_len <= j:
            lst[k] = L[i]
            i += 1
        elif L[i] <= R[j]:
            lst[k] = L[i]
            i += 1
        else:
            lst[k] = R[j]
            j += 1


def mergeSort(lst, left, right):
    if left + 1 < right:
        mid = (left + right) >> 1
        mergeSort(lst, left, mid)
        mergeSort(lst, mid, right)
        merge(lst, left, mid, right)


def partition(lst, p, r):
    x = lst[r]
    i = p - 1
    for j in range(p, r):
        if lst[j] <= x:
            i += 1
            tmp = lst[i]
            lst[i] = lst[j]
            lst[j] = tmp
    i += 1
    tmp = lst[i]
    lst[i] = lst[r]
    lst[r] = tmp
    return i


def quicksort(lst, p, r):
    if p < r:
        q = partition(lst, p, r)
        quicksort(lst, p, q-1)
        quicksort(lst, q + 1, r)


if __name__ == "__main__":
    n = int(input())
    data = [val.split() for val in sys.stdin.readlines()]
    cards = [Card(card) for card in data]
    conf = cards[:]
    quicksort(cards, 0, n - 1)
    mergeSort(conf, 0, n)
    if cards == conf:
        print("Stable")
    else:
        print("Not stable")
    print("\n".join([str(card) for card in cards]))

Measured memory_bytes: 60236
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const ll mod = 1000000007LL;
ll dp[100100][2];
vector<int> G[100100];
vector<int> visit(100100,0);
void dfs(int u, int p){
  // if(visit[u]) return;
  // visit[u] = 1;
  dp[u][0] = 1;
  dp[u][1] = 1;
  for(auto v: G[u]){
    if(v == p) continue;
    dfs(v,u);
    dp[u][0] = dp[u][0]*(dp[v][0]+dp[v][1])%mod;
    dp[u][1] = dp[u][1]*dp[v][0]%mod;
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1){
    int x,y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0,-1);
  cout<<(dp[0][0]+dp[0][1])%mod<<endl;
  return 0;
}

Measured memory_bytes: 17572
def f(n):
    return (n - 1) * n // 2


S = input()
arr = []
i = 0
while len(S) > i:
    s = i
    while i + 1 < len(S) and S[i] == S[i + 1]:
        i += 1
    arr.append(i - s + 1)
    i += 1

ans = 0
if S[0] == '>':
    ans += f(arr[0] + 1)
    arr = arr[1:]

if S[-1] == '<':
    ans += f(arr[-1] + 1)
    arr = arr[:-1]

for i in range(0, len(arr), 2):
    ans += max(arr[i], arr[i + 1]) + f(arr[i]) + f(arr[i + 1])

print(ans)

Measured memory_bytes: 59812
from collections import deque
 
S = deque(input())
Q = int(input())
 
Q_list = [list(map(str, input().split())) for i in range(Q)]
 
rev = False
 
for i in range(Q):
  if int(Q_list[i][0]) == 1:
    rev = not rev
  
  else:
    F = Q_list[i][1]
    C = Q_list[i][2]
    
    if rev ^ (int(F) == 1): # 排他的論理和片方真片方ぎの時真になる
      S.appendleft(C)
    else:
      S.append(C)
      
if rev:
  S.reverse()
  
print(''.join(S))

Measured memory_bytes: 44788
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = np.array(lr(), np.int32)
P_min = np.minimum.accumulate(P)

answer = np.count_nonzero(P_min >= P)
print(answer)


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

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

	ll r;  cin >> r;

	cout << 3 * r * r << '\n';

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;


class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		String s=sc.next();
		if(s.length()==7 && s.equals("keyence")){
			pl("YES");
		}
		else {
			for(int i=0; i<=7; i++) {
				String ss="";
				for(int j=0; j<s.length(); j++) {
					if(j>=i && j<i+(s.length()-7)) {
						continue;
					}
					else {
						ss=ss+s.charAt(j);
					}
				}
				//pl(ss);
				if(ss.equals("keyence")) {
					pl("YES");
					System.exit(0);
				}
			}
			pl("NO");
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 23124
loop = int(input())
num_list = list(map(int, input().split()))
ans = 0
min_value = 20000000
for n in num_list:
  flg = True
  if min_value < n:
    flg = False
  else:
    min_value = n
  if flg:
    ans += 1
print(ans)

Measured memory_bytes: 24744
import sys
input=lambda: sys.stdin.readline().rstrip()
x,y,a,b,c=map(int,input().split())
P=sorted([int(i) for i in input().split()],reverse=True)
Q=sorted([int(i) for i in input().split()],reverse=True)
R=sorted([int(i) for i in input().split()],reverse=True)
import heapq
P,Q=P[:x],Q[:y]
heapq.heapify(P)
heapq.heapify(Q)
for r in R:
  p=heapq.heappop(P)
  q=heapq.heappop(Q)
  if r<=p and r<=q:
    heapq.heappush(P,p)
    heapq.heappush(Q,q)
    break
  else:
    if p<=q:
      heapq.heappush(P,r)
      heapq.heappush(Q,q)
    else:
      heapq.heappush(P,p)
      heapq.heappush(Q,r)
print(sum(P)+sum(Q))
  

Measured memory_bytes: 110892
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = 100000000+7;
const ll MAX_N = 1000;

ll n,x,memo;
char a;
string s;
int main(){
  cin>>n;
  memo=0;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a=='I'){
      x++;
      memo=max(x,memo);
    }
    else x--;
  }

  cout<<memo<<endl;


}


Measured memory_bytes: 256
N=int(input())
p_list=[int(i) for i in input().split()]
p_sort=sorted(p_list)
swap_index=[]
for i,x,y in zip(range(len(p_list)),p_list,p_sort):
    if x!=y:
        swap_index.append(i)
if len(swap_index)==0:
    print("YES")
elif len(swap_index)!=2:
    print("NO")
else:
    i,j=swap_index
    tmp=p_list[i]
    p_list[i]=p_list[j]
    p_list[j]=tmp
    if p_list==p_sort:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#define maxn 105
#define Inf 1e9
int x[maxn],y[maxn];
int mdist(int a,int b){
	return fabs(x[a]-x[b])+fabs(y[a]-y[b]);
}
using namespace std;
int main()
{
   int n,m;
   int mind;
   scanf("%d%d",&n,&m);
   for(int i=1;i<=m+n;i++)
   {
   	cin>>x[i]>>y[i];
   }
   for(int k=1;k<=n;k++){
   			mind=Inf;
	for(int j=n+1;j<=m+n;j++)
	{
		mind=min(mind,mdist(k,j));
	}
	for(int j=n+1;j<=m+n;j++)
		if(mdist(k,j)==mind) {
			cout<<j-n<<endl;
			break;
		}
}
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int adj[5][5];
int indeg[5];
int main(){

    int m=3;
    while(m--){
        int u,v;
        scanf("%d %d",&u,&v);
        indeg[u]++;
        indeg[v]++;
    }
    int cnt=0;
    bool f=1;
    for(int i=1;i<=4;++i){
        if(indeg[i]&1)cnt++;
        if(!indeg[i])f=0;
    }
        puts((cnt==2&&f)?"YES":"NO");

}



Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())

ans=0
for i in range(N):
    if i<K:
        if T[i]=='r':
            ans+=P
        elif T[i]=='s':
            ans+=R
        else:
            ans+=S
    else:
        if T[i]==T[i-K]:
            T[i]='0'
            continue
        elif T[i]=='r':
            ans+=P
        elif T[i]=='s':
            ans+=R
        else:
            ans+=S
print(ans)


Measured memory_bytes: 49520
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 配列入力の受け取り
arrA = list(map(int,input().split()))
stdarr = list(range(1,n+1))

checknum = 0
for i in range(n):
    if arrA[i] != stdarr[i]:
        checknum += 1
    else:
        continue

if checknum <=2 and checknum!=1:
    ans = "YES"
else:
    ans = "NO"

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



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

int main() {
    
    int N;
    long long K;
    int ans;
    
    vector< pair<int,int> > pairs;
    
    cin >> N;
    cin >> K;
    
    for ( int i = 0; i < N; i++ ) {
        int a,b;
        cin >> a;
        cin >> b;
        
        pairs.push_back( make_pair( a, b ) );
    } 
    
    sort( pairs.begin(), pairs.end() );
    
    long long sum = 0;
    
    for ( int i = 0; i < N; i++ ) {
        
        sum += pairs[i].second;
        
        if ( sum >= K ) {
            ans = pairs[i].first;
            break;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1400
from math import atan2,pi

N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
ptoi = {}
for i,p in enumerate(src):
    ptoi[p] = i

if N == 2:
    for i in range(2): print(0.5)
    exit()

#ref https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
def convex_hull(ps):
    ps.sort()
    def cross(o,a,b):
        return (a[0]-o[0]) * (b[1]-o[1]) - (a[1]-o[1]) * (b[0]-o[0])
    lower = []
    for p in ps:
        while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
            lower.pop()
        lower.append(p)
    upper = []
    for p in reversed(ps):
        while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
            upper.pop()
        upper.append(p)
    return lower[:-1] + upper[:-1]

outer = convex_hull(src)
outer += outer[:2]

ans = [0] * N
for (y1,x1),(y2,x2),(y3,x3) in zip(outer,outer[1:],outer[2:]):
    dy1,dx1 = y2-y1,x2-x1
    dy2,dx2 = y3-y2,x3-x2
    ang1 = atan2(dx1, dy1)
    ang2 = atan2(dx2, dy2)
    a = (ang2 - ang1) % (pi*2) / (pi*2)
    ans[ptoi[(y2,x2)]] = a

for a in ans:
    print(a)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, size(s) - 1) {
    if (s[i] != s[i + 1]) ++ans;
  }
  cout << ans << endl;
}
int main(void) { solve(); }

Measured memory_bytes: 3744
Q, H, S, D = map(int,input().split())
N = int(input())
C = min([8*Q, 4*H, 2*S, D])
if N % 2 == 1:
    print(((N-1)//2)*C+min([4*Q, 2*H, S]))
else:
    print((N//2)*C)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
LL A[305][305];
int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>A[i][j];
        }
    }
    LL ans=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<i+1; j++)
        {
            bool flag=true;
            for(int k=0; k<n; k++)
            {
                if(A[i][j]>A[i][k]+A[k][j])
                {
                    cout<<"-1"<<endl;
                    return 0;
                }
                else if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j])
                    flag=false;
            }
            if(flag)
            {
                ans+=A[i][j];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
/**
题目：
链接：
题意：
思路：
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<bitset>
using namespace std;
const int maxn = 5005;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int a[maxn];
int n , k;
int b[maxn];
bitset<maxn> dp;
int judge(int x)
{
    if(a[x]>=k) return 1;
    ///剔除当前数，剩余的数dp一发；存在性判断.
    dp.reset();
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        if(i==x) continue;
        dp|=(dp<<a[i]);
    }
    for(int i = k-1; i >= k-a[x]; i--){
        if(dp[i]){
            return 1;
        }
    }
    return 0;
}
int solve()
{

    sort(a,a+n);
    int lo = -1, hi = n;
    while(hi-lo>1){
        int m = (lo+hi)/2;
        if(judge(m)) hi = m;
        else lo = m;
    }
    return hi;
    /*
    int lo = 0, hi = n-1;
    int mas = 0;
    while(lo<=hi){
        int m = (lo+hi)/2;
        if(judge(m)) hi = m-1;
        else{
            lo = m+1;
            mas = max(mas,m);
        }
    }
    return mas+1;///下标是mas，所以要再加一；
    */
}
int main()
{
    while(scanf("%d%d",&n,&k)==2)
    {
        for(int i = 0; i < n; i++){
            scanf("%d",&a[i]);
        }
        printf("%d\n",solve());
    }
    return 0;
}


Measured memory_bytes: 256
c=[]
for i in range(3):
    c.append(list(map(int,input().split())))

x=c[0][0]+c[1][1]+c[2][2]
y=c[0][1]+c[1][2]+c[2][0]
z=c[1][0]+c[2][1]+c[0][2]
if x==y and y==z:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n, k;
  cin >> n >> k;
  int ans = 1;
  while(n>=pow(k,ans)){
    ans++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int in;
    cin >> in;
    vector<int> slist(13);
    vector<int> clist(13);
    vector<int> hlist(13);
    vector<int> dlist(13);
    for(int i = 0; i < in;i++) {
        char tmp_suit;
        int tmp_card;
        cin >> tmp_suit >> tmp_card;
        if(tmp_suit == 'S') slist[tmp_card] = tmp_card;
        if(tmp_suit == 'C') clist[tmp_card] = tmp_card;
        if(tmp_suit == 'H') hlist[tmp_card] = tmp_card;
        if(tmp_suit == 'D') dlist[tmp_card] = tmp_card;
    }

    for(int j = 0; j < 4; j++) {
        char tmp_suit;
        for(int i = 1; i <= 13; i++) {
            if(j == 0 && slist[i] == 0) cout << "S " << i << endl;
            if(j == 1 && hlist[i] == 0) cout << "H " << i << endl;
            if(j == 2 && clist[i] == 0) cout << "C " << i << endl;
            if(j == 3 && dlist[i] == 0) cout << "D " << i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll a[100000];
int main() {
  int n;
  ll b = 1LL;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0LL) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (1000000000000000000 / b < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    b *= a[i];
    if (b > 1000000000000000000) {
      cout << -1 << endl;
    }
  }
  cout << b << endl;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

vector<long long>pf;
void PrimeFactor(long long n){
    pf.push_back(1);
    for(long long i=2; i<=sqrt(n); i++){
        ll j=i;
        while(n % j == 0) {
            pf.push_back(j);
            n /= j;
            j*=i;
        }
        while(n%i==0)n/=i;
        if(n==1)break;
    }
    if(n!=1)pf.push_back(n);
}

int main(){
    ll n;
    cin>>n;
    PrimeFactor(n);
    cout<<pf.size()-1<<endl;

return 0;
}

Measured memory_bytes: 3676
import math

N=int(input())
ans=0
for i in range(1,N+1):
    for j in range(i,N+1):
        for k in range(j,N+1):
            if i==j and j==k:
                ans+=i
            elif i<j and j<k:
                ans+=6*math.gcd(i,math.gcd(j,k))
            else:
                ans+=3*math.gcd(i,math.gcd(j,k))
print(ans)


Measured memory_bytes: 9196
def main():
    h,w=map(int,input().split())
    L=80*(h+w)+1
    a=[list(map(int,input().split())) for i in range(h)]
    b=[list(map(int,input().split())) for i in range(h)]


    x=[[abs(a[i][j]-b[i][j]) for j in range(w)] for i in range(h)]
    

    L=12800
    
    state=[[0]*w for _ in range(h)]
    delta=x[0][0]
    state[0][0]=(2**L>>delta)|(2**L<<delta)

    for j in range(1,w):
        delta=x[0][j]
        state[0][j]=(state[0][j-1]>>delta)|(state[0][j-1]<<delta)

    for i in range(1,h):
        delta=x[i][0]
        state[i][0]=(state[i-1][0]>>delta)|(state[i-1][0]<<delta)

    for i in range(1,h):
        for j in range(1,w):
            delta=x[i][j]
            state[i][j]=(state[i][j-1]>>delta)|(state[i][j-1]<<delta)
            state[i][j]|=(state[i-1][j]>>delta)|(state[i-1][j]<<delta)

    
    ans = 10**9
    for i in range(L*2):
        if state[h-1][w-1] & 1:
            ans = min(ans,abs(i-L))
        state[h-1][w-1]>>=1
    print(ans)



if __name__ == '__main__':
    main()


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

typedef pair<int, int> pii;

const int MX = 100002;
int N, M;

struct BIT {
    int tree[4*MX];
    void init() {
        memset(tree, 0, sizeof(tree));
    }
    void upd(int idx, int val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] += val;
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = tree[2*n] + tree[2*n + 1];
    }
    int quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 0;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        int L = quer(a, b, l, m, 2*n);
        int R = quer(a, b, m + 1, r, 2*n + 1);
        return L + R;
    }
} bit, cnt;

vector<pii> seg[MX];

int main() {
    scanf("%d %d", &N, &M);

    cnt.init();

    for(int i = 0; i < N; i++) {
        int l, r; scanf("%d %d", &l, &r);
        seg[ r - l + 1 ].push_back(pii(l, r));
        cnt.upd(r - l + 1, 1, 0, MX - 1, 1);
    }

    for(int i = 1; i <= M; i++) {
        int ans = cnt.quer(i, MX - 1, 0, MX - 1, 1);
        int d = i;
        while(d <= M) {
            ans += bit.quer(0, d, 0, MX - 1, 1);
            d += i;
        }
        printf("%d\n", ans);
        for(int j = 0; j < seg[i].size(); j++) {
            bit.upd(seg[i][j].first, 1, 0, MX - 1, 1);
            bit.upd(seg[i][j].second + 1, -1, 0, MX - 1, 1);
        }
    }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
	int64 h, w;
	while (cin >> h >> w && h+w) {
		auto f = make_v<int64>(h, w);
		REP(i, h) REP(j, w) cin >> f[i][j];
		int64 res = 0;
		REP(lu_y, h) {
			REP(lu_x, w) {
				FOR(rd_y, lu_y+2, h) {
					FOR(rd_x, lu_x+2, w) {
						int64 mini = INF, maxi = 0, sum = 0;
						FOR(y, lu_y, rd_y+1) {
							FOR(x, lu_x, rd_x+1) {
								if (y == lu_y || y == rd_y || x == lu_x || x == rd_x)
									mini = min(mini, f[y][x]);
								else {
									maxi = max(maxi, f[y][x]);
									sum += f[y][x];
								}
							}
						}
						if (maxi < mini)
							res = max(res, (rd_x-lu_x-1)*(rd_y-lu_y-1)*mini-sum);
					}
				}
			}
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;//
template <typename T>
T sq (T x) {
  return x * x;
}
vector<int> buf;
int max_ans = 0;
void dfs(int i, const int size, int range_start, const int range_end,vector<int> A,int a[50][4] ,int Q, int max_limt){
  if (i == size) {
    for(int i = 0; i < size; ++i){
      A.at(i) = buf[i];
    }
    int ans = 0;
  rep(j,Q){
      int ai = a[j][0];
      int bi = a[j][1];
      int ci = a[j][2];
      // cout << "aaa" << A.at(ai-1) << A.at(bi-1) << ci <<endl;
      if(A.at(bi-1) - A.at(ai-1) == ci){//a.at(j).at(2)){
        ans += a[j][3];
    // cout << ans << endl;
      } 
    }
    if (ans > max_ans){
      max_ans =  ans;
    if(max_ans == max_limt)return ;
    }
  }
  else{
    for(int j = range_start; j <= range_end; ++j){
      buf[i] = j;
      range_start = j;
      dfs(i + 1, size, range_start, range_end,A,a,Q,max_limt);
    }
  }
}
signed main () {
  int N,M,Q;
  cin >> N >> M >> Q;

int  a[50][4];
  rep(i,Q){
    cin >> a[i][0]; 
    cin >> a[i][1]; 
    cin >> a[i][2]; 
    cin >> a[i][3]; 
  }
// cout << a[0][0] << endl;
  vector<int> A(N);
  int size = N;
  int range_start = 1;
  int range_end = M;
  buf.resize(size);
  int max_limt = 0;
  rep(i,Q){
   max_limt += a[i][3];
  }
  dfs(0,size,range_start,range_end,A,a,Q,max_limt);
  cout << max_ans << endl;

  return 0;
}



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    string S;
    cin >> S;
    puts(S == "ABC" ? "ARC" : "ABC");
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] a) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<int[]> dataList = new ArrayList<int[]>();
		String str;
		int j=0;
		while ((str = br.readLine()) != null) {
			if(str.length()==0)break;
			String[] strBuf = str.split(" ");
			dataList.add(new int[2]);
			try {
				((int[]) dataList.get(j))[0] = Integer.parseInt(strBuf[0]);
				((int[]) dataList.get(j))[1] = Integer.parseInt(strBuf[1]);
			} catch (NumberFormatException nfex) {
				break;
			}
			j++;
			str = null;
		}

		for (int i = 0; i < dataList.size(); i++) {
			int sum = ((int[]) dataList.get(i))[0]
					+ ((int[]) dataList.get(i))[1];
			System.out.println((int) (Math.log10(sum) + 1));
		}
		br.close();
	}

}

Measured memory_bytes: 24280
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

if sum(A)<sum(B):
    print(-1)
else:
    ans=0
    sco=0
    C=[]
    for i in range(N):
        if A[i]<B[i]:
            ans+=1
            sco+=B[i]-A[i]
        elif A[i]>B[i]:
            C.append(A[i]-B[i])
    if ans==0:
        print(0)
        exit()
    C.sort(reverse=True)
    
    for i in range(len(C)):
        ans+=1
        sco-=C[i]
        if sco<=0:
            break
    print(ans)

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

int main() {
  int long long n,cou=0;
  cin>>n;
  vector<int> A(n);
  std::priority_queue<int> ans;
  for(int i=0;i<n;i++){
    cin>>A.at(i);
  }
  for(int a=0;a<n;a++){
    cou=0;
    for(int b=a;b<n;b++){
      if(b+1==n||A.at(b)<A.at(b+1)){
        ans.push(cou);
        if(ans.top()==n-1||ans.top()>=n-a){
          cout<<ans.top();
          exit(0);
        }
        break;
      }
      cou++;
    }
  }
  cout<<ans.top();
}


Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <string>
using namespace std;

const int MAX = 310;
const int INF = 10000000;
int d[MAX][MAX];
int vx[] = { 1, 0, -1, 0 };
int vy[] = { 0, 1, 0, -1 };
struct data { int x, y; };



int main(void){

    string s;
    char c[4] = { 'Y', 'A', 'K', 'I' };
    cin >> s;
    bool flag = false;

    if (s.length() >= 4){
        flag = true;
        for (int i = 0; i < 4; i++){
            if (s[i] != c[i]){
                flag = false;
                break;
            }
        }
        
    }
    
    if (flag){
        cout << "Yes" << endl;

    }
    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    ll n;
    cin >> n;
    ll a, c0 = 0, c2 = 0, c4 = 0;
    REP(i, n) {
        cin >> a;
        if (a % 4 == 0) c4++;
        else if (a % 2 == 0) c2++;
        else c0++;
    }
    // oxoxox
    if (n % 2 == 0) {
        if (c4 < c0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    // oxoxo
    else {
        if (c4 < c0 - 1) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int s = max(a,c);
    int e = min(b,d);
    cout << max(0, e-s) << endl;
    return 0;
}

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

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

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

Measured memory_bytes: 764
#include <stdio.h>  
int main()
{
	int m, f, r, sum;
	
	while(1)
	{
		scanf(" %d %d %d", &m, &f, &r);
		 
		if(m == -1 && f == -1 && r == -1) return 0;   
			
		if(m == -1 || f == -1)
		{
			printf("F\n");    
		}
		else
		{
			sum = m + f;

			if(sum >= 80) 
			{
				printf("A\n");
			}
			
			if(sum < 80 && sum >= 65) 
			{
				printf("B\n");
			}
			
			if(sum < 65 && sum >= 50)
			{
				printf("C\n");
			}

			if(sum < 50 && sum >= 30)
			{
				if(r >= 50) 
				{  
					printf("C\n");      
				}
				else
				{
					printf("D\n");    
				}
			}
			
			if(sum < 30) 
			{
				printf("F\n");    
			}
		}
		
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
char p[300500];
int main()
{
  ll a,b,c,d,e,f,g=0;
  scanf("%s",p);
  a=strlen(p);
  for(b=a-1;b>=0;b--)
  {
      if(p[b]=='B')
   {

   g+=a-b-1;
    a--;
   }
  }
  cout<<g;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];

    for (int i = 0; i <= n - m; i++) {
        for (int j = 0; j <= n - m; j++) {
            bool flag = true;;
            for (int k = 0; k < m; k++) {
                for (int l = 0; l < m; l++) {
                    if (a[i + k][j + l] != b[k][l]) {
                        flag = false;
                    }
                }
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
import static java.lang.Math.*;

public class Main {

	static int[][] d;
	static final int INF = 1 << 24;

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		while(true){
			int n = si(),m = si(),s = si()-1,g1 = si()-1,g2 = si()-1;
			if(n==0) break;
			d = new int[n][n];
			for (int i = 0; i < n ; i++) for (int j = 0; j < n ; j++) d[i][j] = i==j ? 0 : INF;
			while(m-->0) d[si()-1][si()-1]=si();
			warshallFloyd(n);
			int mincost = INF;
			while(--n>=0) mincost = min(d[s][n]+d[n][g1]+d[n][g2],mincost);
			out.println(mincost);
		}
		out.flush();
	}

	static void warshallFloyd(int n){
		for (int i = 0; i < n ; i++)
			for (int j = 0; j < n ; j++)
				for (int j2 = 0; j2 < n; j2++)
					d[j][j2] = min(d[j][j2],d[j][i]+d[i][j2]);

	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 66004
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n % 2== 0) {
            System.out.println(n);
        } else {
            System.out.println(2*n);
        }

    }
}

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

using lint = long long;

lint gcd(lint a, lint b) {
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
lint lcm(lint a, lint b) {
    return a / gcd(a, b) * b;
}

int main() {
    lint m, n;
    cin >> m >> n;
    string s, t;
    cin >> s >> t;

    lint x = lcm(m, n);
    bool can = true;
    lint c = x / m, d = x / n;
    for (int i = 0; i < m / d; i++) {
        if (s[d * i] != t[c * i]) {
            can = false;
            break;
        }
    }

    if (can) {
        cout << x << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

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

string lcs(string &a, string &b){
    string ans = "";
    vector<vector<int>> dp(a.length() + 1, vector<int>(b.length() + 1, 0));
    vector<vector<char>> direction(a.length() + 1, vector<char>(b.length() + 1, '\\'));

    for(int i = 1;i <= a.length();i++){
        for(int j = 1;j <= b.length();j++){
            if(a[i-1] == b[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
                direction[i][j] = '\\';
            }else if(dp[i-1][j] >= dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
                direction[i][j] = '|';
            }else{
                dp[i][j] = dp[i][j-1];
                direction[i][j] = '-';
            }
        }
    }

    for(int i = a.length(), j = b.length();i >= 1 and j >= 1;){
        if(direction[i][j] == '\\'){
            ans += b[j-1];
            --j;
            --i;
        }else if(direction[i][j] == '-'){
            --j;
        }else{
            --i;
        }
    }

    reverse(ans.begin(), ans.end());
    
    return ans;
}

int main(){
    string a, b;
    getline(cin, a);
    getline(cin, b);

    cout << lcs(a, b) << endl;

    return 0;
}

Measured memory_bytes: 45184
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v;
    rep(i,n){
        ll a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }
    sort(v.begin(), v.end());
    ll ans = 0;
    rep(i,n){
        if(m <= v[i].second){
            ans += m * v[i].first;
            m = 0;
            break;
        }
        else{
            ans += v[i].first * v[i].second;
            m -= v[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder.Beginner067
{
    public class ABC067C_SplittingPile
    {
        public static void Main(string[] args)
        {
            
            int n = int.Parse(Console.ReadLine());
            decimal[] nums = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
            
            decimal bestDiff = decimal.MaxValue;
            decimal x = nums.Sum();
            decimal y = 0;

            for( int i = 0; i < n-1; i++ )
            {
                x -= nums[nums.Length - i - 1];
                y += nums[nums.Length - i - 1];

                bestDiff = Math.Min(bestDiff, Math.Abs(x - y));
            }
            
            Console.WriteLine(bestDiff);

        }
    }
}

Measured memory_bytes: 37752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringTokenizer st;
		int a, b, suma, sumb;
		a = b = suma = sumb = 0;

		br.readLine();
		while ((line = br.readLine()) != null) {
			st = new StringTokenizer(line);
			if (st.countTokens() > 1) {
				a = Integer.parseInt(st.nextToken());
				b = Integer.parseInt(st.nextToken());
				if (a > b) {
					suma += (a + b);
				} else if (a < b) {
					sumb += (a + b);
				} else {
					suma += a;
					sumb += b;
				}
			} else {
				System.out.println(suma + " " + sumb);
				suma = sumb = 0;
			}
		}
	}
}

Measured memory_bytes: 24860
import java.util.HashSet;
import java.util.Set;

public class Main {


  private static void solve() {
    Set<Integer> set = new HashSet<>();
    for (int i = 0; i < 4; i ++) {
      set.add(ni());
    }
    
    if (set.contains(1) && set.contains(9) && set.contains(7) && set.contains(4)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22672
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(true)
    {
        C -= B;
        if(C <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
        {
            A -= D;
            if(A <= 0)
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
}

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

vector<int> a_seq;

int main() {
    int N, a;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        a_seq.push_back(a);
    }
    sort(a_seq.begin(), a_seq.end());
    cout << a_seq[N - 1] - a_seq[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()
ans = 0
for i in range(1,n):
  for j in range(i):
    if j > bisect.bisect_right(L,L[i]-L[j]):
      ans += j-bisect.bisect_right(L,L[i]-L[j])
print(ans)

Measured memory_bytes: 43612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}



int main(){
    string l;cin>>l;
    ll ans=1;
    ll sum=0;
    ll ls=l.size();
    rep(i,0,ls-1){
        if(l[i]=='1'){
            sum=(sum+(ans*(hpow(3,ls-i-1)))%i_7)%i_7;
            ans*=2;
            ans=ans%i_7;
            //cout<<sum<<' '<<ans<<endl;
        }
    }
    //cout<<ans<<endl;
    cout<<(sum+ans)%i_7<<endl;
    
    return 0;
}



Measured memory_bytes: 512
n = int(input())
S = input()

d = [0] * n
nl = 0
nr = 0
for i in range(n):
    if S[i] == '(': nl += 1
    if S[i] == ')': nr += 1
    d[i] = nl - nr

d = [0] + d
x = -min(d)
# print(d)
# print(x)

print('('*x + S + ')'*(d[-1]+x))

Measured memory_bytes: 3064
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

pnt = [K] * N

for i in range(N):
    pnt[i] -= Q
    
for a in A:
    pnt[a-1] += 1
    
for p in pnt:
    if p <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 11776