akhauriyash/Code-Regression huggingface dataset:
/**
 *   created: 03 June 2019  00:25:23
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#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;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vi v(n);
		int sum=0,maxi=0;
		rep(i,0,n){
			cin>>v[i];
			sum += v[i];
			maxi = max(maxi, v[i]);
		}
		sum -= maxi;
		if(maxi<sum)
			cout<<"Yes";
		else
			cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
import numpy as np

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

def calc(a):
    value = a[0]
    sign = value >= 0
    result = 0
    for i in a[1:]:
        value += i
        diff = 0
        if sign and value >= 0:
            diff = value + 1
        elif not sign and value < 0:
            diff = value - 1
        result += abs(diff)
        sign = not sign
        value -= diff
        if value == 0:
            diff += sign
            value += diff
            result += diff
    return result

if a[0] == 0:
    a[0] = 1
    r1 = calc(a[:])
    a[0] = -1
    r2 = calc(a[:])
    print(min(r1, r2) + 1)
else:
    r1 = calc(a[:])
    diff = -a[0] - a[0] // abs(a[0])
    a[0] += diff
    r2 = calc(a[:]) + abs(diff)
    print(min(r1, r2))


Measured memory_bytes: 23244
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    string  s;
    cin >> n >> s;
    int x = 0;
    int max_x = x;
    rep(i, s.size()) {
        if (s[i] == 'I') {
            x++;
        }
        if (s[i] == 'D') {
            x--;
        }
        max_x = max(max_x, x);
    }
    put(max_x)
    return 0;
}

Measured memory_bytes: 3548
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 200010;
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  string s,s1,s2;
  cin >> s;
  s1 = s.substr(n/2,n-1);
  s2 = s.substr(0,(n/2));
  if(s1 == s2 && n%2 == 0 )
  {
    cout << "Yes";
  }
  else
    cout << "No";
  return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define rep(n) for(ll i = 0 ; i<n ; i++) 
#define rep2(n) for(ll j=0 ; j<n ; ++j )
#define repd(n) for(ll i = n-1 ; i>=0 ; i--)
#define MOD 1000000007
#define pii pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define INF 1e18
#define sz(a) a.size() 
#define all(a) a.begin(),a.end()
#define M 998244353
#define limit 100000000


void solve() {
	ll n, p  ; cin >> n >> p ;
	string s ; cin >> s; 
	ll arr[p]={} ;

	if(p==2 || p==5) {
		ll c=0 ; 
		rep(n) if((s[i]-'0')%p==0) c += i+1 ;
		cout << c ; return ;
	}

	ll sm=0 ,cnt =0 , ten =10;
	for(ll i=n-1;i>=0;--i) {
		ll curr = (s[i]-'0')*ten;
		curr%=p;
		sm += curr;
		sm %= p;
		cnt += arr[sm] ;
		if(sm==0) ++cnt; 
		arr[sm%p]++ ;
		ten*=10; 
		ten%=p;
	}
	cout << cnt ;
}

int main() {


    fast;
	ll t=1;
	// cin>>t;
	rep(t) {
		solve() ;
	}
	return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
set<int> st;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int x;
	for(int i=1;i<=n;i++){
		cin>>x;
		st.insert(x);
	}
	return puts(st.size()==n?"YES":"NO"),0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
  int k, a, b;
  bool isok = false;
  cin >> k;
  cin >> a >> b;

  for (int i = a; i <= b; i++)
  {
    if (i % k == 0)
    {
      isok = true;
      break;
    }
  }

  if (isok)
  {
    cout << "OK";
  }
  else
  {
    cout << "NG";
  }

  return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>
#include <stdlib.h>

int N, *p, ans[100000], l = 0;

void swaps(int k){
	int i, tmp;
	for(i = k; i < N; i++){
		tmp = p[i];
		p[i] = p[i - k];
		p[i - k] = tmp;
	}
	ans[l] = k;
	l++;
}

void out(){
	int i;
	printf("p:");
	for(i = 0; i < N; i++){
		printf("%d ", p[i]);
	}
	printf("\n");
}

int main(){
	int i;
	scanf("%d", &N);
	p = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &p[i]);
//		p[i] = (N / 2 - i + N) % N;
	}
	for(i = N - 2; i >= 0; i--){
//		printf("i = %d\n", i);
		while(p[0] != i){
			swaps(1);
//			out();
		}
		while(p[1] != i + 1){
			swaps(1);
			swaps(N - 1);
//			out();
		}
	}
//	out();
	printf("%d\n", l);
	for(i = 0; i < l; i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

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

int main() {
  long long int N, X;
  cin >> N >> X;
  vector<long long int> A(N);
  long long int ans = 0;
  for (long long int i = 0; i < N; i++) cin >> A.at(i);
  for (long long int i = 1; i < N; i++) {
    if (A.at(i) + A.at(i - 1) > X) {
      ans += A.at(i) + A.at(i - 1) - X;
      if (A.at(i - 1) > X) {
        A.at(i - 1) = X;
        A.at(i) = 0;
      }
      else {
        A.at(i) = X - A.at(i - 1);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include <stdio.h>
#include <string.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == 5) 
    {
        if (b == 5 || c == 5) 
        {
            printf("YES");
        }
        else { printf("NO"); }
    }else
    if (b == 5)
    {
        if (c == 5)
        {
            printf("YES");
        }
        else { printf("NO"); }
    }
    else { printf("NO"); }
    return 0;
}



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

using namespace std;

map <string, int> s;

int main() {
  int n; cin >> n;
  vector <string> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  bool okay = 1;
  for(int i = 0; i < n; i++) {
    if(s.find(v[i]) != s.end()) {
      okay = 0;
      break;
    }
    s[v[i]]++;
  }
  for(int i = 0; i < n - 1; i++) {
    if(v[i].back() != v[i + 1][0]) {
      okay = 0;
      break;
    }
  }
  if(okay) {
    puts("Yes");
  } else {
    puts("No");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=107;
int a[N],x,n;
ll sum[N];
int main(){
	scanf("%d%d",&n,&x);
	for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(a[1]>x){
		puts("0");
		return 0;
	}
	for(int i = 1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
		if(sum[i]>=x){
			if(sum[i]==x){
				cout<<i<<endl;
				return 0;
			}
			cout<<i-1<<endl;
			return 0;
		}
	}
	cout<<n-1<<endl;
	return 0;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
from collections import deque


def bfs(u):
    queue = deque([u])
    ans = [0] * (n+1)
    ans[1] = 1
    while queue:
        v = queue.popleft()
#        print(v,d[v])
        for i in d[v]:
            if  ans[i] == 0:           
                ans[i] = v
                queue.append(i)
#        print(ans)
    return ans

n,m = iim()
d = {}
for i in range(m):
    a,b = iim()
    la = d.get(a,[])
    la.append(b)
    d[a] = la
    lb = d.get(b,[])
    lb.append(a)
    d[b] = lb
#print(d)
ans = bfs(1)

#print(ans)
if 0 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in ans[2:]:
        print(i)

Measured memory_bytes: 39088
/*
Author : Hocky Yudhiono
5/31/2020 7:10:12 PM

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef vector<int> vi;
typedef pair<LL,LL> PLL;
typedef pair<LL,int> PLI;
typedef pair<int,int> PII;
typedef pair<int,int> pii;
typedef vector<vector<LL>> VVL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

//If the time limit is strict, try not to use long double

//Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
// Do dir^1 to get reverse direction
const char dch[4] = {'R','L','D','U'};
// const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    //Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

#include <bitset>
const int MAX_PR = 5'000'000;
bitset<MAX_PR> isprime;
vi eratosthenesSieve(int lim) {
    isprime.set(); isprime[0] = isprime[1] = 0;
    for (int i = 4; i < lim; i += 2) isprime[i] = 0;
    for (int i = 3; i*i < lim; i += 2) if (isprime[i])
        for (int j = i*i; j < lim; j += i*2) isprime[j] = 0;
    vi pr;
    rep(i,2,lim) if (isprime[i]) pr.push_back(i);
    return pr;
}

int main(){
    LL n;
    vi prime = eratosthenesSieve(1'000'000);
    cin >> n; LL ans = 0;
    trav(curprime, prime){
        if(n%curprime == 0){
            LL cnt = 0;
            while(n%curprime == 0) cnt++, n /= curprime;
            LL kiri = 1;
            LL kanan = 100;
            // cout << cnt << endl;
            while(kiri < kanan){
                LL mid = (kiri+kanan+1)>>1;
                LL now = (mid*(mid+1))/2;
                if(now <= cnt) kiri = mid;
                else kanan = mid-1;
            }
            ans += kiri;
        }
    }
    if(n != 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4356
# -*- coding: utf-8 -*-

N = int(input())

# それぞれの文字が何回現れたかを格納する
dict = {}

ans = 0
for i in range(N):
    s = ''.join(sorted(input()))

    # すでに出現していればこれまでに出現した回数を答えに足す
    if s in dict:
        ans += dict[s]
        dict[s] += 1

    # 1回も出現していなければ追加する
    else:
        dict[s] = 1

print(ans)


Measured memory_bytes: 17852
#include <iostream>

using namespace std;

int getGcd(int a, int b)
{
  while (a && b) {
    if (a > b) a %= b;
    else if (b > a) b %= a;
    else if (a == b) return a;
  }

  if (a > b) return a;
  return b;
}

int main(void)
{
  int a, b;

  while (cin >> a >> b) {
    int gcd = getGcd(a, b);
    cout << gcd << ' ' << a * (b / gcd) << endl;
  }

  return 0;
}

Measured memory_bytes: 3000
s=input()
q=int(input())
for i in range(q):
    t=input().split(" ")
    if t[0]=="print":
        a,b=int(t[1]),int(t[2])
        print(s[a:b+1:])
    if t[0]=="reverse":
        a,b=int(t[1]),int(t[2])
        s=s[:a:]+s[a:b+1:][::-1]+s[b+1::]
    if t[0]=="replace":
        a,b=int(t[1]),int(t[2])
        x=t[3]
        s=s[:a:]+x+s[b+1::]



Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

ll comb(ll n, ll r) {
    ll ret = 1;
    for (ll i = 0; i < r; i++) ret = ret * (n - i);
    for (ll i = 1; i <= r; i++) ret /= i;
    return ret;
}

int main(){
    string s; cin >> s;
    ll k,d,sum = 0; cin >> k;
    queue<char> q;

    rep(i,s.length()){

        if(i == s.length()-1){
            sum = (k-sum)%26;
            d = (int)(s[i] - 'a');
            d = (sum+d)%26;

            q.push((char)('a' + d));

            break;
        }

        if(s[i] == 'a'){
            q.push('a');
            continue;
        }

        d = ('z' - s[i] + 1);
        if(sum+d <= k){
            sum += d;
            q.push('a');
        }else q.push(s[i]);


    }

    while(!q.empty()) {
        cout << q.front();
        q.pop();
    }
}

Measured memory_bytes: 3812
import collections

n = int(input())
array = list(map(int,input().split(" ")))

array1 = []
array2 = []

for i in range(int(n/2)):
    array1.append(array[i*2])
    array2.append(array[i*2+1])

a1 = collections.Counter(array1)
a2 = collections.Counter(array2)

a12 = sorted(a1.items(),key = lambda x: -x[1])
a22 = sorted(a2.items(),key = lambda x: -x[1])

if a12[0][0] != a22[0][0]:
    print(n- a12[0][1] - a22[0][1])
else:
    if len(a12) == 1:
        if len(a22) == 1:
            print(int(n/2))
        else:
            print(a22[0][1])
    elif len(a22) == 1:
        print(a12[0][1])
    else:
        print(n - max(a12[0][1] + a22[1][1],a12[1][1] + a22[0][1]))
            

Measured memory_bytes: 23776
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, M, R;
	int[] r, A, B, C;
	long[][] distMat;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		M = Integer.parseInt(tokens[1]);
		R = Integer.parseInt(tokens[2]);
		r = new int[R];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < R; ++i) {
			r[i] = Integer.parseInt(tokens[i]) - 1;
		}
		A = new int[M];
		B = new int[M];
		C = new int[M];
		for (int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			A[i] = Integer.parseInt(tokens[0]) - 1;
			B[i] = Integer.parseInt(tokens[1]) - 1;
			C[i] = Integer.parseInt(tokens[2]);
		}
		distMat = new long[N][N];
		for (int i = 0; i < N; ++i) {
			Arrays.fill(distMat[i], Long.MAX_VALUE / 4);
		}
		for (int i = 0; i < M; ++i) {
			distMat[A[i]][B[i]] = C[i];
			distMat[B[i]][A[i]] = C[i];
		}
	}

	void calcDistMat() {
		for (int k = 0; k < N; ++k) {
			for (int i = 0; i < N; ++i) {
				for (int j = i + 1; j < N; ++j) {
					distMat[i][j] = Math.min(distMat[i][j], distMat[i][k] + distMat[k][j]);
					distMat[j][i] = distMat[i][j];
				}
			}
		}
	}

	long calcDist(int current, Set<Integer> remain) {
		if (remain.size() == 1) {
			int next = remain.stream().findFirst().get();
			return distMat[current][next];
		} else {
			long min = Long.MAX_VALUE / 4;
			for (Integer next : remain) {
				int n = next;
				Set<Integer> nextRemain = new HashSet<>();
				nextRemain.addAll(remain);
				nextRemain.remove(n);
				min = Math.min(min, distMat[current][n] + calcDist(next, nextRemain));
			}
			return min;
		}
	}

	void calc() {
		calcDistMat();
		long min = Long.MAX_VALUE / 4;
		Set<Integer> nodes = new HashSet<>();
		for (int i = 0; i < R; ++i) {
			nodes.add(r[i]);
		}
		for (int i = 0; i < R; ++i) {
			Set<Integer> nextRemain = new HashSet<>();
			nextRemain.addAll(nodes);
			nextRemain.remove(r[i]);
			min = Math.min(min, calcDist(r[i], nextRemain));
		}
		System.out.println(min);
	}

	void showResult() {
	}
}

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

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < 4; i++) cout << s[i];
  cout << " ";
  for(int i = 4; i < s.size(); i++) cout << s[i];
  cout << endl;
 return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        //int t=Integer.parseInt(br.readLine());
        String str[]=br.readLine().split(" ");
        int n=Integer.parseInt(str[0]);
        int k=Integer.parseInt(str[1]);
        int arr[]=new int[n];
        str=br.readLine().split(" ");
        for(int i=0;i<n;i++)
        arr[i]=Integer.parseInt(str[i]);
        for(int i=k;i<n;i++)
        {
            if(arr[i]>arr[i-k])
            pw.println("Yes");
            else
            pw.println("No");
        }
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 62752
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import pprint
# for debug
pp = pprint.PrettyPrinter(width = 150)
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, a = II(), LI()
ruisekiwa = [0] * (n)
# 累積和の配列の最初の要素は、元のリストの最初の要素にする
ruisekiwa[0] = a[0]
for i in range(1, n):
    ruisekiwa[i] = ruisekiwa[i-1] + a[i]

ans1 = 0
ans2 = 0
diff = 0

# 偶数番目を正にする
for i in range(n):
    # 偶数番目なのに累積和が負
    # ruisekiwa[0] == -1 ならば1にするために2を加算する
    if i % 2 == 0 and ruisekiwa[i] + diff <= 0:
        ans1 += abs(1 - (ruisekiwa[i] + diff))
        diff += (1 - (ruisekiwa[i] + diff))
        # print(ans1, diff)
    # 奇数番目なのに累積和が正
    elif i % 2 == 1 and ruisekiwa[i] + diff >= 0:
        ans1 += abs(ruisekiwa[i] + diff - (-1))
        diff += ((-1) - (ruisekiwa[i] + diff))
        # print(ans1, diff)
        
diff = 0
# 偶数番目を負にする
for i in range(n):
    # 偶数番目なのに累積和が正
    if i % 2 == 0 and ruisekiwa[i] + diff >= 0:
        # -1にするためにどれだけ減算するか
        ans2 += abs(ruisekiwa[i] + diff - (-1))
        diff += ((-1) - (ruisekiwa[i] + diff))
        # print(ans2, diff)
    # 奇数番目なのに累積和が負
    elif i % 2 == 1 and ruisekiwa[i] + diff <= 0:
        ans2 += abs(1 - (ruisekiwa[i] + diff))
        diff += (1 - (ruisekiwa[i] + diff))
        # print(ans2, diff)
        
print(min(ans1, ans2))


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 2e18;


ll t[maxn*4], o[maxn*4];

void push(int v) {
    t[2*v]+=o[v];
    t[2*v+1]+=o[v];
    o[2*v]+=o[v];
    o[2*v+1]+=o[v];
    o[v]=0;
}

ll queryMin(int v, int tl, int tr, int l, int r) {
    if (l>tr||r<tl) return inf;
    if (l<=tl&&tr<=r) {
	return t[v];
    } else {
	push(v);
	int tm=(tl+tr)/2;
	return min(queryMin(2*v,tl,tm,l,r),queryMin(2*v+1,tm+1,tr,l,r));
    }
}

void rangeAdd(int v, int tl, int tr, int l, int r, ll dx) {
    if (l>r) return;
    if (l>tr||r<tl) return;
    if (l<=tl&&tr<=r) {
	t[v]+=dx;
	o[v]+=dx;
    } else {
	push(v);
	int tm=(tl+tr)/2;
	rangeAdd(2*v,tl,tm,l,r,dx);
	rangeAdd(2*v+1,tm+1,tr,l,r,dx);
	t[v]=min(t[2*v],t[2*v+1]);
    }
}


//0-indexed
void upd(int l, int r, ll dx) {
    if (l>r) return;
    rangeAdd(1,1,maxn,l+1,r+1,dx);
}

ll qry(int l, int r) {
    assert(l<=r);
    return queryMin(1,1,maxn,l+1,r+1);
}

void edit(int i, ll val) {
    upd(i,i,val-qry(i,i));
}


vector<pair<int,int>> intervals[maxn];


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

    int n, m; cin>>n>>m;
    ll tot=0;
    
    while (m--) {
	int l,r,a; cin>>l>>r>>a;
	tot += a;
	intervals[r].push_back({l,a});
    }


    upd(0,n+1,inf);
    edit(0,0);

    for (int i=1; i<=n+1; i++) {
	for (auto p: intervals[i-1]) {
	    upd(0,p.first-1,p.second);
	}
	ll dp = qry(0,i);
	edit(i,dp);
    }

    ll res = tot - qry(0,n+1);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 51584
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 4005;

int n;
string str;
int cnt[N][26];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n>>str;
    FOR(i,str.size()){
        cnt[i][str[i]-'A']++;
    }
    REV(i,n-1,0){
        FOR(j,26){
            cnt[i][j] += cnt[i+1][j];
        }
    }

    ll ans = 0;
    FOR(i,n){
        REP(j,i+1,n-1){
            if(str[i] == str[j])continue;
            int k = j + j-i;
            char ck = 'R';
            if(ck == str[i] || ck == str[j])ck = 'G';
            if(ck == str[i] || ck == str[j])ck = 'B';
            ans += cnt[j+1][ck-'A'];
            if(k < n && str[k] == ck)ans--;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int su = 0;
		for(int i = 0;;i++){	//???????????????
			su = Integer.parseInt(br.readLine());
			if(su == 0){		//su???0?????\?????????????????????
				break;
			}
			System.out.println("Case "+ (i + 1) +": "+su);
		}
	}
}

Measured memory_bytes: 31276
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int n,b,t,ans=INT_MIN;
int main(void){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t;
    if(i==0)b=t;
    else{
      ans=max(ans,t-b);
      if(t<=b)b=t;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

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

  vector<int> a(n);
  rep(i,n)cin >> a[i];

  ll c1 = 0, c2 = 0;
  ll s1 = 0, s2 = 0;
  for(int i = 0; i < n; i++) {
    s1 += a[i];
    if(i % 2 == 0 && s1 <= 0) {
      c1 += -s1 + 1;
      s1 = 1;
    } else if(i % 2 == 1 && s1 >= 0) {
      c1 += s1 + 1;
      s1 = -1;
    }

    s2 += a[i];
    if(i % 2 == 1 && s2 <= 0) {
      c2 += -s2 + 1;
      s2 = 1;
    } else if(i % 2 == 0 && s2 >= 0) {
      c2 += s2 + 1;
      s2 = -1;
    }
  }

  cout << min(c1, c2) << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int n,p; cin>>n;
	vector<tuple<string,int,int>> v;
	for(int i=1;i<=n;i++){cin>>s>>p; v.push_back(make_tuple(s,-p,i));}
	sort(v.begin(),v.end());
	for(auto& t:v) cout<<get<2>(t)<<endl;
}

Measured memory_bytes: 3548
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

#input
K = int(input())
S = str(input())

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 5 * pow(10, 6)
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

L = len(S)
answer = 0
for i in range(L, L+K+1):
    answer += pow(25, i-L, mod) * pow(26, L+K-i, mod) * cmb(i-1, L-1)
    answer %= mod
print(answer)

Measured memory_bytes: 169376
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;



void solve(){
	int n;
	cin>>n;
	int a[n];
	int mx=-1e9,sum=0;
	rep(i,n){
		cin>>a[i];
		mx=max(mx,a[i]);
		sum+=a[i];
	}
	cout<<sum-mx+mx/2;

}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

using namespace std;

int N, ans = 1e9, f[1000009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    f[i] = i % 10 + f[i / 10];
for (int i=1; i<N; i++)
{
    int curr = f[i] + f[N - i];
    if (curr < ans)
        ans = curr;
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
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;
}
int main()
{
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  rep(i, K){
    if(C <= B){
      C *= 2;
    }
    else if(B <= A){
      B *= 2;
    }
  }
  if(A < B && B < C){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;

using ll = long long;

int main(){
  string s; cin >> s;
  int ans=700;
  for(int i=0; i<3; i++){
    if(s[i]=='o') ans += 100;
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
  ll n, x, ans=1;
  cin >> n >> x;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  for(ll i=0,d=0; i<n; ++i) {
    d += l[i];
    if(d <= x)ans++;
    else break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

using MIte = multimap<ll, ll, greater<ll> >::iterator;

ll dp[3001][3001] = { 0 };

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

	// long long?
	string s,t;
	cin >> s >> t;

	for (int i = 0; i != s.length(); ++i) {
		for (int j = 0; j != t.length(); ++j) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
			}
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}

	int idx1 = s.length();
	int idx2 = t.length();
	string str = "";
	while (idx1 > 0 && idx2 > 0) {
		if (dp[idx1][idx2] == dp[idx1 - 1][idx2]) {
			idx1--;
		}
		else if (dp[idx1][idx2] == dp[idx1][idx2 - 1]) {
			idx2--;
		}
		else {
			str = s[idx1 - 1] + str;
			idx1--;
			idx2--;
		}
	}

	cout << str << endl;

	return 0;
}


Measured memory_bytes: 70656
a,b,c  = map (int, input().split())
if a > b:
    xc = a
    a = b
    b = xc
if b > c:
    xa = b
    b = c
    c = xa
if a > b:
    xc = a
    a = b
    b = xc
print ("{} {} {}".format(a,b,c))



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;
typedef pair<int, int> P;
int maze[100][100];
bool used[100][100];
int main()
{
	const int dir[][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
//	cut here before submit 
//	freopen ("testcase.block", "r", stdin );
	int w, h;

	while (cin >> w >> h && w && h ){
		memset (maze, 0, sizeof(maze ) );
		memset (used, false, sizeof (used ) );

		P start, goal;
		cin >> start.first >> start.second;
		start.first--; start.second--;
		cin >> goal.first >> goal.second;
		goal.first--; goal.second--;
		int n;
		cin >> n;
		for (int i = 0; i < n; ++i ){
			int color, dir;
			P block;
			cin >> color >> dir >> block.first >> block.second;
			block.first--; block.second--;
			if (dir == 0 ){
				for (int col = 0; col < 4; ++col ){
					maze[block.second][block.first+col] = color;
					maze[block.second+1][block.first+col] = color;
				} // end for
			}else{
				for (int row = 0; row < 4; ++row ){
					maze[block.second+row][block.first] = color;
					maze[block.second+row][block.first+1] = color;
				} // end for
			} // end if
		} // end for
		queue<P> que;
		que.push (P(start.first, start.second ) );
		int search_color = maze[start.second][start.first];
		bool found = false;

		while (!que.empty() ){
			P curr = que.front(); que.pop();
			int x = curr.first;
			int y = curr.second;
			if (x == goal.first && y == goal.second ){
				found = true;
				break;
			} // end if
			used[y][x] = true;
			for (int k = 0; k < 4; ++k ){
				int nx = x + dir[k][0];
				int ny = y + dir[k][1];
				if (nx < 0 || nx >= w || ny < 0 || ny >= h )
					continue;
				if ((maze[ny][nx] == search_color) && !used[ny][nx] ){
					P next; next.first = nx; next.second = ny;
					que.push (next );
				} // end if
			} // end for
		} // end while

		if (found )
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 6648
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
const ll mod = 998244353;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
struct seg {
	int s, e, m, v;
	seg *l, *r;
	seg (int _s, int _e ) {
		s = _s, e = _e, m = (s + e) >> 1, v = -1;
		if (s != e) {
			l = new seg(s, m);
			r = new seg(m + 1, e);
		}
	}
	void update(int pos, int value) {
		if (s == e) {
			v = value;
			return;
		} else if (pos > m) {
			r -> update(pos, value);
		} else {
			l -> update(pos, value);
		}
		v = max(l -> v, r -> v);	 
	}
	int query(int a, int b) {
		if (s == a && e == b) {
			return v;
		}
		if (a > m) {
			return r -> query(a, b);
		}
		if (b <= m) {
			return l -> query(a, b);
		}
		return max(l -> query(a, m), r -> query(m + 1, b));
	}
} *root;
int main() {
	INIT
	cin >> _;
	VI A(_);
	vector<pii> X(_);
	rep (i, 0, _) {
		cin >> X[i].x >> X[i].y;
	}
	sort(all(X));
	root = new seg(0, _ - 1);
	per(i, 0, _) {
		int pos = lower_bound(all(X), pii(X[i].x + X[i].y, 0)) - X.begin();
		if (pos == i + 1) {
			A[i] = i;
			root -> update(i, i);
		} else {
			A[i] = root -> query(i + 1, pos - 1);
			root -> update(i, A[i]);
		}
	}
	VI DP(_ + 1);
	DP[_] = 1;
	per (i, 0, _) {
		(DP[i] += DP[i + 1] + DP[A[i] + 1]) %= mod;
	}
	cout << DP[0];
	
	return 0;
}

Measured memory_bytes: 22144
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int main(){
    int N;
    cin >> N;
    int num[4];
    REPm(i,4){
        num[i] = N%10;
        N /= 10;
    }
    if(num[0] == num[1] && num[1] == num[2]) cout << "Yes" << endl;
    else if(num[3] == num[1] && num[1] == num[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int s[m], c[m];
    rep(i, m) scanf("%d%d", &s[i], &c[i]), --s[i];
    rep(i, 1000)if(to_string(i).size() == n){
        string t = to_string(i);
        bool flag = true;
        rep(j, m)if(t[s[j]]-'0' != c[j]){
            flag = false;
            break;
        }
        if(flag){
            printf("%d\n", i);
            return 0;
        }
    }
    puts("-1");
}

Measured memory_bytes: 256
#include <stdio.h>
int selectionSort(int A[],int N){
  int i,j,t,sw=0,minj;
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if (A[j]<A[minj])minj=j;
    }
    t=A[i];A[i]=A[minj];A[minj]=t;
    if(i!=minj) sw++;
  }
  return sw;
}
int main(){
  int A[100],N,i,sw;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  sw=selectionSort(A,N);
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);
  return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A >= 2*B) {
    cout << A - 2*B << endl;
  }
  
  else if (A < 2*B) {
    cout << 0 << endl;
  }
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    vector<pair<char, int>> ca(n * 2);
    for (auto &p: ca) cin >> p.first >> p.second, p.second--;
    vector<vector<int>> black(n, vector<int>(n + 1));
    vector<vector<int>> white(n, vector<int>(n + 1));
    {
        vector<bool> b(n), w(n);
        for (auto &p: ca) {
            char c = p.first;
            int i = p.second;
            vector<int> ge_b(n + 1), ge_w(n + 1);
            for (int j = n - 1; j >= 0; j--) {
                ge_b[j] = ge_b[j + 1] + b[j];
                ge_w[j] = ge_w[j + 1] + w[j];
            }
            for (int j = n; j >= 0; j--) {
                if (c == 'B') black[i][j] = ge_b[i + 1] + ge_w[j];
                if (c == 'W') white[i][j] = ge_b[j] + ge_w[i + 1];
            }
            (c == 'B' ? b[i] : w[i]) = true;
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) {
        if (i < n) chmin(dp[i + 1][j], dp[i][j] + black[i][j]);
        if (j < n) chmin(dp[i][j + 1], dp[i][j] + white[j][i]);
    }
    cout << dp[n][n] << endl;
    return 0;
}


Measured memory_bytes: 49408
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
void StringTransformation() {
	string s, t;

	cin >> s >> t;
	map<char, char> q;
	map<char, char> q2;
	for (size_t i = 0; i < s.size(); i++)
	{

		if (q.count(t[i]) ) {
			if (q[t[i]] != s[i]) {
				cout << "No" << "\n";
				return;
			}
		}
		q[t[i]] = s[i];
		if (q2.count(s[i])) {
			if (q2[s[i]] != t[i]) {
				cout << "No" << "\n";
				return;
			}
		}
		q2[s[i]] = t[i];
	}
	cout << "Yes" << "\n";
}
int main() {
	StringTransformation();
		return 0;
}

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

int main() {
	long long n;
	cin >> n;
	long long x[n],y[n];
	for(long long i=0;i<n;i++){
		cin >> x[i] >> y[i];
	}
	map<pair<long long ,long long>,long long> a;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			a[make_pair(x[i]-x[j],y[i]-y[j])]++;
			a[make_pair(x[j]-x[i],y[j]-y[i])]++;
		}
	}
	long long ans=0;
	for(auto i:a){
		ans=max(ans,i.second);
	}
	cout << n-ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //初期化
  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) sizes.push_back(1);
    return;
  }

  //頂点nの根
  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size(ll n) {
    return sizes[root(n)];
  }

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    sizes[root(a)] += size(b);
    parent[root(b)] = root(a);
    return;
  }
};

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

  vector<vll> ab(m, vll(2));
  for (ll i = 0; i < m; i++) cin >> ab[i][0] >> ab[i][1];

  ll cnt = 0;
  for (ll i = 0; i < m; i++) {
    union_find uf;
    uf.init(n);

    for (ll j = 0; j < m; j++) {
      if (j == i) continue;
      uf.unite(ab[j][0] - 1, ab[j][1] - 1);
    }

    if (!(uf.is_united(ab[i][0] - 1, ab[i][1] - 1))) cnt++;
  }
  cout << cnt << endl;
}

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

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<char> VB;

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

const double eps=1e-5;
const long long INF=(LL)(1e9)*(LL)(1e9);

template<class T>
void chmin(T& a, const T& b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T& b)
{
	if(a<b)
		a=b;
}

const LL pow(const LL p, const LL q)
{
	LL t=1;
	REP(i,q)
		t*=p;
	return t;
}



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

	string s;
	cin>>s;
	REP(i,s.size()-1)
	{
		if(s[i]=='A' && s[i+1]=='C')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	

	
}

Measured memory_bytes: 384
#include<stdio.h>
int flag[10000005],a[1000005];
int main()
{
    int n,i;
    scanf("%d",&n);
    a[1]=n;
    flag[a[1]]=1;
    for(i=2;;i++){
        if(a[i-1]%2==0){
            a[i]=a[i-1]/2;
        }
        else{
            a[i]=3*a[i-1]+1;
        }
        if(flag[a[i]]==1){
            printf("%d\n",i);
            break;
        }
        else{
            flag[a[i]]=1;
        }
    }
    return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
using namespace std;

long long int combination(long long int n, long long int r){
    if (n == r || r == 0)  return 1;
    else  return combination(n, r - 1) * (n - r + 1) / r;
}

int main(void){
    
    int a;
    cin>>a;

    string s;
    cin>>s;

    if (a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;

    
    return 0;

}

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

int n;
double dp[301][301][301];
array<int, 4> cnt{};

double go() {
    if (dp[cnt[1]][cnt[2]][cnt[3]] >= 0)
        return dp[cnt[1]][cnt[2]][cnt[3]];
    double E = double(n) / double(cnt[1] + cnt[2] + cnt[3]);
    for (int i = 1; i <= 3; i++) {
        if (cnt[i]) {
            double p = double(cnt[i]) / double(cnt[1] + cnt[2] + cnt[3]);
            cnt[i]--, cnt[i - 1]++;
            E += p * go();
            cnt[i]++, cnt[i - 1]--;
        }
    }
    return dp[cnt[1]][cnt[2]][cnt[3]] = E;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    fill_n(&dp[0][0][0], 301 * 301 * 301, -1.0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    dp[1][0][0] = double(n);
    cout << fixed << setprecision(10) << go() << '\n';
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll A, B;
    cin >> A >> B;

    ll res;
    if(A >= 13){
    	res = B;
    }else if(A >= 6){
    	res = B/2;
    }else{
    	res = 0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256