akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
sc = [input() for _ in range(m)]
ans = -1

for i in range(0,10**n):
    i = str(i)
    ok = 0
    
    if len(i) != n:
        continue
    
    for j in sc:
        s,c = j.split()
        
        if i[int(s)-1] == c:
            ok += 1
        
    if ok == m:
        ans = int(i)
        break
        
print(ans)

Measured memory_bytes: 9104
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

a1=(a+9)//10*10
b1=(b+9)//10*10
c1=(c+9)//10*10
d1=(d+9)//10*10
e1=(e+9)//10*10

tmax=0
if tmax<a1-a:
	tmax=a1-a
if tmax<b1-b:
	tmax=b1-b
if tmax<c1-c:
	tmax=c1-c
if tmax<d1-d:
	tmax=d1-d
if tmax<e1-e:
	tmax=e1-e

print(a1+b1+c1+d1+e1-tmax)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()

	cnt := map[int]int{}

	factorize := func(n int) {
		for i := 2; i*i <= n; i++ {
			for n%i == 0 {
				cnt[i]++
				n /= i
			}
		}

		if n!= 1 {
			cnt[n]++
		}
	}

	for i := 2; i <= n; i++ {
		factorize(i)
	}

	num := map[int]int{}
	for _, e := range cnt {
		if e+1 >= 75 {
			num[75]++
		}
		if e+1 >= 25 {
			num[25]++
		}
		if e+1 >= 15 {
			num[15]++
		}
		if e+1 >= 5 {
			num[5]++
		}
		if e+1 >= 3 {
			num[3]++
		}
	}

	debug(num)

	fmt.Fprintln(wr, num[75]+num[25]*(num[3]-1)+num[15]*(num[5]-1)+num[5]*(num[5]-1)*(num[3]-2)/2)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){

    int N;
    int i;
    scanf("%d",&N);

    int P[N];

    for(i = 0; i < N; i++){
        scanf("%d", &P[i]);
    }

    int ans = 0;
    int min = 10000000;

    for(i = 0; i < N; i++){
        if(P[i] < min){
            ans++;
            min = P[i];
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 896
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = []
    for _ in range(n):
        b,c = LI()
        a.append([b+c,b,c])
    d = sorted(a,reverse=True)
    r = 0
    for i in range(n):
        if i % 2 == 0:
            r += d[i][1]
        else:
            r -= d[i][2]

    return r



print(main())




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

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++)s[i] -= '0';
	int a = s[0] * 10 + s[1], b = s[2] * 10 + s[3];	
	bool x = true, y = true;
	if (a > 12 || a <= 0)x = false;
	if (b > 12 || b <= 0)y = false;
	if (x && y)puts("AMBIGUOUS");
	else if (x && (!y))puts("MMYY");
	else if ((!x) && y)puts("YYMM");
	else puts("NA"); 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
#define y1 qwert
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int n,m,k,x1,y1,x2,y2,dir,tot,cur,nx,ny,res;
string g[1000100];
vector<vector<pair<int,int> > >dis[4];
priority_queue<pair<pair<int,int>,pair<pair<int,int>,int> > > q;
pair<int,int> INF=make_pair(1e9,1e9),NOX;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++){cin>>g[i];g[i]="?"+g[i];}
	for(int i=0;i<4;i++){
		dis[i].resize(n+1,vector<pair<int,int> >(m+1,INF));
		dis[i][x1][y1]={0,0};
		q.push(make_pair(make_pair(0,0),make_pair(make_pair(x1,y1),i)));
	}
	while(q.size()){
		x1=q.top().second.first.first;y1=q.top().second.first.second;
		dir=q.top().second.second;
		NOX=q.top().first;
		q.pop();
		NOX.first*=-1,NOX.second*=-1;
		if(NOX>dis[dir][x1][y1]) continue;
		tot=dis[dir][x1][y1].first;
		cur=dis[dir][x1][y1].second;
		if(cur==k) goto nxt;
		nx=x1+dx[dir],ny=y1+dy[dir];
		NOX=dis[dir][x1][y1];
		NOX.second++;
		if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&g[nx][ny]=='.'){
			if(dis[dir][nx][ny]>NOX){
				dis[dir][nx][ny]=NOX;
				NOX.first*=-1,NOX.second*=-1;
				q.push(make_pair(NOX,make_pair(make_pair(nx,ny),dir)));
			}
		}
		nxt:;
		for(int i=0;i<4;i++){
			nx=x1+dx[i],ny=y1+dy[i];
			NOX=dis[dir][x1][y1];
			NOX.first++;NOX.second=1;
			if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&g[nx][ny]=='.'){
				if(dis[i][nx][ny]>NOX){
					dis[i][nx][ny]=NOX;
					NOX.first*=-1,NOX.second*=-1;
					q.push(make_pair(NOX,make_pair(make_pair(nx,ny),i)));
				}
			}
		}
	}
	res=min(dis[0][x2][y2].first,dis[1][x2][y2].first);
	res=min(res,dis[2][x2][y2].first);
	res=min(res,dis[3][x2][y2].first);
	res++;
	if(res>=1e9) res=-1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 113636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

int main()
{
  int x, ans = 0;
  cin >> x;

  if (x >= 500)
  {
    ans += int(x / 500) * 1000;
    x %= 500;
  }
  if (x >= 5)
  {
    ans += int(x / 5) * 5;
  }

  cout << ans << endl;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n && n;){
		vi left(n-1),right(n-1);
		rep(i,n-1){
			cin>>left[i]>>right[i];
			left[i]--,right[i]--;
		}
		
		vi ps(n,-1);
		rep(i,n-1){
			if(left[i]!=n-1) ps[left[i]]=i;
			if(right[i]!=n-1) ps[right[i]]=i;
		}
		
		vi depth(n);
		repi(i,1,n-1)
			depth[i]=1+depth[ps[i]];
		
		vi size(n,1);
		per(i,n-1)
			size[i]=1+size[left[i]]+size[right[i]];
		
		vl unsaved(n);
		per(i,n-1){
			int l=left[i],r=right[i];
			unsaved[i]=unsaved[l]+(size[l]+1)/2+unsaved[r]+(size[r]+1)/2;
		}
		
		vl saved(n);
		per(i,n-1){
			int l=left[i],r=right[i];
			ll a=unsaved[i];
			ll b=1+saved[l]+depth[i]+1+saved[r];
			ll c=unsaved[l]+(size[l]+1)/2+1+saved[r];
			ll d=unsaved[r]+(size[r]+1)/2+1+saved[l];
			saved[i]=min({a,b,c,d});
		}
		
		cout<<saved[0]<<endl;
	}
}

Measured memory_bytes: 18612
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = ceil(max(12.5 * a, 10.0 * b));
    if (ans >= min(12.5 * (a + 1), 10.0 * (b + 1)))
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    // system("pause");
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n,k; cin >> n >> k;
    if(n%k == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

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

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    int n,m,k;
    scanf("%lld", &n);
    scanf("%lld", &m);
    scanf("%lld", &k);
    int turn = 0;
    while(k--){
        if(turn % 2 == 0){
            if(n % 2 == 1){
                n--;
            }
            m += n/2;
            n -= n/2;
        }
        else{
            if(m % 2 == 1){
                m--;
            }
            n += m/2;
            m -= m/2;
        }
        turn++;
    }
    printf("%lld %lld",n,m);
    return 0;
}

Measured memory_bytes: 256
while True :
    n, p = map(int, input().split())
    if n == 0 and p == 0 :
        break
    
    kouho = list([0] * n)
    wan = p
    
    while True :
        end = False
        for i in range(n) :
            if wan > 0 :
                kouho[i] += 1
                wan -= 1
                if wan == 0 and kouho[i] == p :
                    print(i)
                    end = True
                    break
            else :
                wan += kouho[i]
                kouho[i] = 0
        if end == True :
            break


Measured memory_bytes: 5592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool LR[200000];
void Calc(){
	int N = rei()*2;
	string S = res();
	LR[0] = (S[0] == 'B');
	for(int i=1;i<N;i++){
		LR[i] = (S[i] != S[i-1]) ^ (!LR[i-1]);
	}
	long ans = 1;
	int c = 0;
	for(int i=0;i<N;i++){
		if(LR[i]){
			c++;
		}
		else{
			ans *= c;
			ans %= mod;
			c--;
			if(c == -1){
				cout << 0 << endl;
				return;
			}
		}
	}
	if(c != 0){
		cout << 0 << endl;
		return;
	}
	for(int i=1;i<=N/2;i++){
		ans *= i;
		ans %= mod;
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 788
n = int(input())
x_list = []
y_list = []
for _ in range(n):
    x, y = map(int, input().split())
    x_list.append(x - y)
    y_list.append(x + y)
x_list.sort()
y_list.sort()
ans = max(x_list[-1] - x_list[0], y_list[-1] - y_list[0])
print(ans)

Measured memory_bytes: 25568
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	int T=1;	
	while(T--)
	{
	 	int n;
	 	cin>>n;
	 	int l[n];
	 	for(int i=0;i<n;i++)
	 		cin>>l[i];
	 	sort(l,l+n);
	 	int ans=0;
	 	for(int i=0;i<n;i++)
	 	{
	 		for(int j=i+1;j<n;j++)
	 		{
	 			for(int k=j+1;k<n;k++)
	 			{
	 				if(l[i]==l[j]||l[j]==l[k])	continue;
	 				//cout<<l[i]<<" "<<l[j]<<" "<<l[k]<<endl;
	 				if(l[i]+l[j]>l[k]&&l[k]+l[i]>l[j])	ans++;
	 			}
	 		}
	 	}
	 	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#coding: utf-8

pos = [[0,0],[0,0],[0,0],[0,0]]

pos[0][0],pos[0][1],pos[1][0],pos[1][1] = map(int,raw_input().split())

vect = [pos[1][0] - pos[0][0], pos[1][1] - pos[0][1]]

vect_2 = [-vect[1], vect[0]]

pos[2] = [pos[1][0] + vect_2[0], pos[1][1] + vect_2[1]]
pos[3] = [pos[0][0] + vect_2[0], pos[0][1] + vect_2[1]]

print str(pos[2][0]) + " " + str(pos[2][1]) + " " + str(pos[3][0]) + " " + str(pos[3][1])
 

Measured memory_bytes: 2696
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    string s;
    cin >> s;
    int n = s.size();
    vi cnt(3, 0);
    
    rep(i, n){
        cnt[s[i] - 'a']++;
    }
    
    sort(all(cnt));
    // for(auto x : cnt) cout << x << endl;
    
    if(cnt[2] - cnt[0] <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3748
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

bool is_prime(int);
void prime_factor(int n, vector<int> &cnt);

int main(){
	int n;
	cin >> n;
	int a = 2;
	long long ans = 1;
	vector<int> cnt(1001, 0);
	while(a <= n){
		prime_factor(a, cnt);
		a++;
	}
	for(int i = 0; i < 1001; i++){
		if(cnt.at(i) > 0){
			if(i != 1){
				ans *= cnt.at(i) + 1;
			}
		}
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

bool is_prime(int n){
	if(n == 1){
		return false;
	}
	if(n == 2){
		return true;
	}
	int divisor = 2;
	while(divisor < n){
		if(n % divisor == 0){
			return false;
		}
		divisor++;
	}
	return true;
}

void prime_factor(int n, vector<int> &cnt){
	while(!is_prime(n)){
		int divisor = 2;
		// cout << "divisor : " << divisor << endl;
		// cout << "n : " << n << endl;
		while(divisor <= n){
			if(is_prime(divisor) && n % divisor == 0){
				cnt.at(divisor)++;
				n /= divisor;
				break;
			}
			divisor++;
		}
	}
	cnt.at(n)++;
	return;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef long double ld;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = (int)1e5 + 10;
const int MOD = (int)1e9 + 7;
int cnt[100][100];
int fac[N];
int ff[N];

int powr(int n, int k){
  if(k == 0) return 1;
  int p = powr(n,k/2);
  p = (p * 1ll * p) % MOD;
  if(k % 2 == 1)
    p = (p * 1ll * n) % MOD;
  return p;
}

int ncr(int n, int k){
  int r = fac[n];
  r = (r * 1ll * powr(fac[k],MOD-2))%MOD;
  r = (r * 1ll * powr(fac[n-k],MOD-2))%MOD;
  return r;
}

int main(){
  fastIO;
  int n;
  cin >> n;
  fac[0]=1;
  for(int i = 1; i <= n; i ++ )
    fac[i]=(fac[i-1]*1ll*i)%MOD;
  for(int i = 0 ; i < n; i ++ ){
    ff[i]=ncr(n,i+1);
    ff[i]=(ff[i]*1ll*fac[i])%MOD;
    ff[i]=(ff[i]*1ll*fac[n-i-1])%MOD;
    if(i)
      ff[i]=(ff[i-1]+ff[i])%MOD;
  }
  int h;
  int ans = 0;
  int cur;
  for(int i = 1; i <= n; i ++ ){
    cin >> h;
    cur=ff[n-i];
    cur=(cur+ff[i-1])%MOD;
    cur=(cur-ff[0]+MOD)%MOD;
    ans=(ans+(cur*1ll*h)%MOD)%MOD;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> mochi(N);
  for (int n = 0; n < N; n++) {
    cin >> mochi.at(n);
  }
  
  sort(mochi.begin(), mochi.end());
  reverse(mochi.begin(), mochi.end());
  
  int count = 1;
  int under = mochi.at(0);
  for (int n = 1; n < N; n++) {
    if (under > mochi.at(n)) {
      under = mochi.at(n);
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
long long a[MAXN];
long long b[MAXN];
long long ans=0;
int main()
{
    int n;
    cin >>n;    
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=b[i-1]+a[i];
        ans+=a[i];
    }
    long long cmin=INT_MAX;
    for(int i=1;i<n;i++)
    {
        if(cmin>abs(2*b[i]-ans))
            cmin=abs(2*b[i]-ans);
    }
    cout<<cmin<<endl;
    return 0;
}

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



int main(){
  string s;
  cin >> s;
  bool judge = 1;
  int N = s.size();
  rep(i, N / 2){
    if (s[i] == s[N-i-1]) {
      string s1, s2;
      s1 = s.substr(0, (N-1) / 2);
      s2 = s.substr((N+3) / 2 - 1);
      rep(j, s1.size()){
        if (s1[j] == s1[s1.size()-j-1]) continue;
        else judge = 0;
      }
      
      rep(j, s2.size()){
        if (s2[j] == s2[s2.size()-j-1]) continue;
        else judge = 0;
      }
    }
    else judge = 0;
  }
  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = n.times.map{gets.to_i}
ans = 0
for i in 0..n-2
  ans += a[i]/2
  if a[i+1] > 1 && a[i]%2 == 1
    ans += 1
    a[i+1] -= 1
  end
end
puts ans+a[-1]/2

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(3*n);
    rep(i,3*n) cin >> a[i];
    sort(all(a), greater<ll>());
    ll ans = 0;
    for(int i = 1; i < 2*n; ++i) {
        if(i%2) ans+=a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5600
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc;
		String str="";
		String[] kuwasiku;
		int[] hako=new int[3];
		int afrom=0,ato=0;
		int tmp1=0,tmp2=0;

		for(int i=0; i<3; i++) {
			hako[i]=0;
		}
		hako[0]=1;

	sc=new Scanner(System.in);
		while(sc.hasNext()) {
			str=sc.next();
			kuwasiku=str.split(",");
			if(kuwasiku[0].equals("A")) {
				afrom=0;
			}
			else if(kuwasiku[0].equals("B")) {
				afrom=1;
			}
			else if(kuwasiku[0].equals("C")) {
				afrom=2;
			}

			if(kuwasiku[1].equals("A")) {
				ato=0;
			}
			else if(kuwasiku[1].equals("B")) {
				ato=1;
			}
			else if(kuwasiku[1].equals("C")) {
				ato=2;
			}

			tmp1=hako[afrom];
			tmp2=hako[ato];
			hako[afrom]=tmp2;
			hako[ato]=tmp1;
		}
		if(hako[0]==1) {
			System.out.println("A");
		}
		else if(hako[1]==1) {
			System.out.println("B");
		}
		else if(hako[2]==1) {
			System.out.println("C");
		}
	}
}


Measured memory_bytes: 26100
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    int n,k;
    cin>>n;
    cin>>k;
    int ans=1;
    for(int i=0;i<n;i++){
        ans=min(ans*2,ans+k);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
N = int(input())

dic = [[] for i in range(N)]
for i in range(N-1):
  inf = input().split()
  u = int(inf[0])
  v = int(inf[1])
  w = int(inf[2])
  dic[u-1] +=[(v-1, w)]
  dic[v-1] +=[(u-1, w)]

dist = [-1]*N
stack = []
stack.append(0)
dist[0] = 0

while stack:
  label = stack.pop(-1)
  for i, c in dic[label]:
    if dist[i] == -1:
      dist[i] = dist[label]+c
      stack += [i]

ls = [0]
print(0)
for i in range(1,N):
  if dist[i]%2==0:
    print(0)
  else:
    print(1)


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

int main(){
    ll n;
    cin >> n;
    ll cnt_4 = 0;
    ll cnt_2 = 0;
    ll r = n;
    rep(i,n){
        int a;
        cin >> a;
        if(a%4 == 0)cnt_4++;
        if(a%2 == 0)cnt_2++;
    }
    cnt_2 -= cnt_4;
    r -= (cnt_4 + cnt_2);
    if(cnt_2 < 1){
        if(r <= cnt_4 + 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        if(r <= cnt_4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
int h[1005];
double tem[1005];
int main()
{
	int n,t,a;
	scanf("%d%d%d",&n,&t,&a);
	double po=(double)a;
	int ans=-1;
	double dis=2147483646.0;
	for(register int i=1;i<=n;++i)
	{
		scanf("%d",&h[i]);
		tem[i]=t-h[i]*0.006;
		if(fabs(tem[i]-po)<dis)
		{
			dis=fabs(tem[i]-po);
			ans=i;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> a;
  tools::read(a, N);
  std::transform(a.begin(), a.end(), a.begin(), [](const i64& a_i) { return a_i - 1; });

  i64 answer = 0;
  for (i64 i = 0; i < N; ++i) {
    if (a[a[i]] == i) ++answer;
  }
  answer /= 2;

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100003;
struct Edge {
	int to, nxt;
	Edge() {}
	Edge(int to, int nxt):to(to), nxt(nxt) {}
}e[MAXN << 1];
int h[MAXN], p;
int w[MAXN], du[MAXN], fa[MAXN];
int n, rt;
bool fg = 1;

inline void add_edge(int a, int b) {
	e[++p] = Edge(b, h[a]); h[a] = p;
	e[++p] = Edge(a, h[b]); h[b] = p;
}

int dfs(int u) {
	int s = 0, mx = 0;
	bool son = 0;
	for(int i = h[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(v == fa[u]) continue;
		son = 1;
		fa[v] = u;
		int cur = dfs(v);
		s += cur;
		mx = max(mx, cur);
	}
	if(!son) return w[u];
	if(w[u] > s || w[u] < mx || 2 * w[u] < s) {
		fg = 0;
		return 0;
	}
	return 2 * w[u] - s;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", w + i);
	for(int i = 1, a, b; i < n; i++) {
		scanf("%d%d", &a, &b);
		add_edge(a, b);
		du[a]++; du[b]++;
	}
	if(n == 2) {
		if(w[1] == w[2]) puts("YES");
		else puts("NO");
		return 0;
	}
	int res = 0;
	for(int i = 1; i <= n; i++) if(du[i] > 1) {
		res = dfs(i);
		break;
	}
	if(res == 0 && fg == 1) puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 7296
package main

import (
	"fmt"
)

var n, x, y int
var ps [][]int
var cs []int

func main() {
	fmt.Scan(&n, &x, &y)
	x--
	y--
	ps = make([][]int, n)
	for i := 0; i < n-1; i++ {
		ps[i] = append(ps[i], i+1)
		ps[i+1] = append(ps[i+1], i)
	}
	ps[x] = append(ps[x], y)
	ps[y] = append(ps[y], x)

	cs = make([]int, n-1)

	for i := 0; i < n; i++ {
		nqs := make([]int, 0)
		nqs = append(nqs, i)
		cnt := 0
		cj := make([]bool, n)
		for len(nqs) > 0 {
			qs := make([]int, len(nqs))
			for l := range nqs {
				qs[l] = nqs[l]
			}
			nqs = make([]int, 0)
			for len(qs) > 0 {
				q := qs[0]
				qs = qs[1:]
				for _, j := range ps[q] {
					if cj[j] || i == j {
						continue
					}
					cj[j] = true
					cs[cnt]++
					//fmt.Println("i,j,cnt: ", i+1, j+1, cnt+1)
					nqs = append(nqs, j)
				}
			}
			cnt++
		}
	}
	for i := range cs {
		fmt.Println(cs[i] / 2)
	}
}


Measured memory_bytes: 7680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int m;

int a[100],b[100];

int c[100],d[100];

int main()
{
    cin >> n >> m;
    rep(i,1,n)
        cin >> a[i] >> b[i];
    rep(i,1,m)
        cin >> c[i] >> d[i];

    rep(i,1,n)
    {
        int x = a[i];
        int y = b[i];

        int dist = abs(x - c[1]) + abs(y - d[1]);
        int index = 1;

        rep(j,2,m)
        {
            int temp = abs(x - c[j]) + abs(y - d[j]);
            if(dist > temp)
            {
                dist = temp;
                index = j;
            }
        }

        cout << index << endl;
    }
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin >>n >> k;
  vector<int> dp(n);
  vector<int> h(n);
  for(int i = 0; i<n;i++){
    cin >> h[i];
  }
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  for(int i = 2; i<n;i++){
    int cos = INT_MAX;
    for(int j = 1; j<=k && j<=i;j++){
      cos = min(dp[i-j]+abs(h[i-j]-h[i]),cos);
    }
    dp[i] = cos;
  }
  cout << dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000001000
#define int long long
using namespace std;
signed main()
{
	int n;
	while (cin >> n, n)
	{
		//cout << "--------------------------------------------" << endl;
		//cout << n << endl;
		vector<int> vec(n + 1);
		string s;
		int seq = 0;
		bool none_flag = false;
		bool x = false;
		rep(i, n)
		{
			cin >> s;
			if (s == "x")
			{
				seq++;
				x = true;
				if ((i + 1) % 2 == 0)
					vec[i] = INF;
				else
					vec[i] = -INF;
			}
			else
			{
				seq = 0;
				vec[i] = atoi(s.c_str());
				if (i > 0 && (i + 1) % 2 == 0)
				{
					if (vec[i] <= vec[i - 1])
						none_flag = true;
				}
				if (i > 0 && (i + 1) % 2 == 1)
				{
					if (vec[i] >= vec[i - 1])
						none_flag = true;
				}
			}
			if (seq > 1)
				none_flag = true;
			//cout << s << " ";
		}
		//cout << endl;
		//cout << vec[0] << " " << vec[1] << endl;
		if (none_flag)
		{
			cout << "none" << endl;
			continue;
		}
		if (!x)
		{
			cout << "ambiguous" << endl;
			continue;
		}
		int sup = INF, inf = -INF;
		int max_tmp, min_tmp;
		rep(i, n)
		{
			if (vec[i] == INF || vec[i] == -INF)
			{
				if ((i + 1) % 2)
				{
					if (i == 0)
						max_tmp = vec[i + 1];
					else if (i == n - 1)
						max_tmp = vec[i - 1];
					else
						max_tmp = min(vec[i + 1], vec[i - 1]);
					sup = min(sup, max_tmp);
				}
				else
				{
					if (i == 0)
						min_tmp = vec[i + 1];
					else if (i == n - 1)
						min_tmp = vec[i - 1];
					else
						min_tmp = max(vec[i + 1], vec[i - 1]);
					inf = max(inf, min_tmp);
				}
			}
			//cout << inf << " " << sup << endl;
		}
		sup--;
		inf++;
		//cout << inf << " " << sup << endl;
		if (sup == inf)
			cout << sup << endl;
		else if (sup == -INF - 1 || inf == INF + 1)
			cout << "ambiguous" << endl;
		else if (inf < sup)
			cout << "ambiguous" << endl;
		else
			cout << "none" << endl;
	}
	return 0;
}



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


int main() {
    int a;
    string s;
    cin >> a >> s;
    if(a < 3200){
        cout << "red";
    }
    else
    {
        cout << s;
    }
    
    
    
    cout << endl;
}


Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> m;
    ll res = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        m[a[i]]++;
        res += a[i];
    }
    int q;
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        if(m.find(b) == m.end()){
            cout << res << "\n";
            continue;
        }
        ll mult = m[b];
        m[b] = 0;
        m[c] += mult;
        res -= (b * mult);
        res += (c * mult);
        // for(auto x : m){
        //     cout << x.first << " " << x.second << "\n";
        // }
        cout << res << "\n";
    }
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 7468
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int x;
	int i = 0;
	while (true) {
		cin >> x;
		++i;
		if (x==0)break;
		cout << "Case " << i <<": "<< x << endl;
	}
	return 0;
}


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

int main()
{
    char a, b;
    cin >> a >> b;
    if( a=='H' and b=='H')
        cout << 'H' << endl;
    else if (a == 'H' and b == 'D')
        cout << 'D' << endl;
    else if (a == 'D' and b == 'H')
        cout << 'D' << endl;
    else if (a == 'D' and b == 'D')
        cout << 'H' << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		scn.nextLine();
		char[] str = scn.nextLine().toCharArray();
		int ans = 0;
		for(int i = 0;i < N;i++) {
			if(str[i]=='R') {
				ans++;
			}
		}
		System.out.println(2*ans > N?"Yes":"No");
	}

}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n,c = 0;;
int main() {
    cin >> n;
    int a[n];
    rep(i,0,n){
        cin >> a[i];
    }
    rep(i,0,n){
        per(j,n,i+1){
            if(a[j] < a[j-1]){
                swap(a[j],a[j-1]);
                c++;    
            }
        }
    }

    rep(i,0,n){
        printf("%d",a[i]);
        if(i != n-1) printf(" ");
    }
    printf("\n");
    pout(c);
    return 0;
}


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

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

#define bin(x) (1<<(x))
#define b(x) (1<<(x)>>1)

inline void cmax(int&x, const int y) {x < y && (x = y);}

const int N = 17, M = 40100;
int f[N][M], g[M];
int mp[N][N];
int n, m;

int main() {
	read(n), read(m);
	int Ans = 0;
	for(int i=1,x,y,z;i<=m;++i) {
		read(x), read(y), read(z);
		Ans += z;
		mp[x][y] = mp[y][x] = z;
	}
	for(int s=0;s<bin(n);++s) {
		int&v = g[s];
		for(int i=1;i<=n;++i) if(s & b(i)) 
		for(int j=i+1;j<=n;++j) if(s & b(j)) v += mp[i][j];
	}
	for(int i=1;i<=n;++i)
	for(int j=0;j<bin(n);++j)
		f[i][j] = -1;
	
	f[1][1] = 0;
	for(int S=1;S<bin(n);++S)
	for(int i=1;i<=n;++i) if((S & b(i)) and ~f[i][S]) {
		for(int j=1;j<=n;++j) if((~S & b(j)) and mp[i][j]) cmax(f[j][S|b(j)], f[i][S] + mp[i][j]);
		for(int iS=(bin(n)-1)^S, s = iS; s; s = (s-1) & iS)
			cmax(f[i][S|s], f[i][S] + g[s|b(i)]);
	}
	printf("%d\n", Ans - f[n][bin(n)-1]);
	return 0;
}

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

const int N_max=100000;
vector<bool> ch(N_max,false);
vector<vector<pair<int,int>>> G(N_max);
vector<int64_t> x(N_max,0);
bool flag=true;

void bfs(int v){
  
  ch[v]=true;
  
  for(auto nv:G[v]){
    if(ch[nv.first]==true && x[nv.first]-x[v]!=nv.second){
      flag=false;
      break;
    }
    else if(ch[nv.first]==false){
      x[nv.first]=x[v]+nv.second;
      bfs(nv.first);
    }
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<M;++i){
    int L,R,D;
    cin>>L>>R>>D;
    --L,--R;
    G[L].push_back(make_pair(R,D));
    G[R].push_back(make_pair(L,-D));
  }
  
  for(int i=0;i<N;++i){
    if(!ch[i]) bfs(i);
    if(!flag) break;
  }

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 12416
#include <stdio.h>

int GetNum(int n, int a, int b) {
  int ans = 0;
  for (int i = 0; i <= n; i += a) {
    if ((n - i) % b == 0) { ans++; }
  }
  return ans;
}

int main() {
  int r, g, b, n;
  scanf("%d%d%d%d", &r, &g, &b, &n);
  int ans = 0;
  for (int num = 0; num <= n; num += r) {
    ans += GetNum(n - num, g, b);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NQ = ReadSplitInt();
            var N = NQ[0];
            var Q = NQ[1];
            var S = Read();

            var lr = new List<List<int>>();
            for (int i = 0; i < Q; i++)
            {
                lr.Add(ReadSplitInt());
            }

            var s = new int[N + 1];
            for (int i = 1; i < S.Length; i++)
            {
                var count = s[i];
                if (S[i-1] == 'A' && S[i] == 'C')
                {
                    count++;
                }
                s[i + 1] = count;
            }

            foreach (var i in lr)
            {
                var left = i[0];
                var right = i[1];
                Println(s[right] - s[left]);
            }
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 29292
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
 
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;

ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}



void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll k = min(a,c);
    a-=k;
    c-=k;
    b-=min(b,c);
    cout<<a<<' '<<b<<endl;
}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
        ll t;
    //cin>>t;
    //while(t--)
        solve();
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
char ch;
int a[200001],n,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		std::cin>>ch;
		a[i]=ch=='R' ? 1 : 0;
		sum=a[i] ? sum+1 : sum;
		a[i]+=a[i-1];
	}
	printf("%d",sum-a[sum]);
	return 0;
}

Measured memory_bytes: 4512
n, k = map(int, input().split())
A = list(map(int, input().split()))

ans = float('inf')
for L in range(n-k+1):
    R = L + k
    if A[L] < 0 and A[R-1] < 0:
        ans = min(ans, abs(A[L]))
    elif A[L] < 0 and 0 <= A[R-1]:
        ans = min(ans, min(abs(A[L]), abs(A[R-1]))*2 + max(abs(A[L]), abs(A[R-1])))
    else:
        ans = min(ans, abs(A[R-1]))
print(ans)

Measured memory_bytes: 14568
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static class State implements Comparable <State>{
		int dist, y, x, dir;
		State(int dist, int y, int x, int dir){
			this.dist=dist;
			this.y=y;
			this.x=x;
			this.dir=dir;
		}
		public int compareTo(State s) {
			return this.dist-s.dist;
		}
	}
	
	public static void main(String args[]){
		try(Scanner sc=new Scanner(System.in)){
			while(sc.hasNext()) {
				int w=sc.nextInt();
				int h=sc.nextInt();
				if(w==0) break;
				int inf=100000000;
				int[][] board=new int[h][w];
				int[] cost=new int[5];//命令に払うcost
				int[] dy= {0, 1, 0, -1};//進む方向
				int[] dx= {1, 0, -1, 0};
				
				for(int i=0; i<h; i++) {
					for(int j=0; j<w; j++) {
						board[i][j]=sc.nextInt();
					}
				}
				for(int i=0; i<4; i++) {
					cost[i]=sc.nextInt();
				}
				
				int[][][] d=new int[h][w][5];//座標と向き
				for(int i=0; i<h; i++) {
					for(int j=0; j<w; j++) {
						for(int k=0; k<4; k++) {
							d[i][j][k]=inf;
						}
					}
				}
				PriorityQueue<State> pq=new PriorityQueue<State>();
				pq.add(new State(0, 0, 0, 0));
				while(! pq.isEmpty()) {
					State p=pq.poll();
					if(p.y==h-1 && p.x==w-1) {
						System.out.println(p.dist);
						break;
					}
					if(d[p.y][p.x][p.dir]!=inf) {
						continue;
					}
					d[p.y][p.x][p.dir]=p.dist;
					//System.out.println("p.dir="+p.dir);
					for(int k=0; k<4; k++) {//向きを全方向やる
						int ndir=(p.dir+k)%4;
						int ny=p.y+dy[ndir], nx=p.x+dx[ndir];
						if(0<=ny && ny<h && 0<=nx && nx<w && d[ny][nx][ndir]==inf) {
							int ndist=p.dist+(board[p.y][p.x]==k ? 0:cost[k]);
							//System.out.println("ndist="+ndist+" ny="+ny+" nx="+nx+" ndir="+ndir);
							pq.add(new State(ndist, ny, nx, ndir));
						}
					}
					//System.out.println();
					
				}
				
				
			}
		}
	}
} 


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

int main()
{
	double x1,y1,x2,y2,x3,y3,x4,y4;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4){
		if(((x2-x1)*(x4-x3)+(y2-y1)*(y4-y3))/sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))*sqrt((x4-x3)*(x4-x3)+(y4-y3)*(y4-y3)) == 0)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef pair<ul, ul> P;



int main()
{
    
    int N;
    uint64_t X;
    cin >> N >> X;

    int count = N;

    uint64_t sum = 0;
    while(count>=0){

        if(X<=0){
            break;
        }

        else if(X==1){
            if(count==0){
                sum += 1;
                break;
            }else{
                sum += 0;
                break;
            }
        }else if(X>1 &&X<pow(2, count+1)-3+2){
            
            X -= 1;
        }
        else if (X == pow(2, count+1)-3+2)
        {
            sum += pow(2, count);
            break;
        }
        else if(X<pow(2,count+2)-3){
            sum += pow(2, count);
            X -= (pow(2, count+1)-3 + 2);
        }
        else
        {
            sum += pow(2, count+1) - 1;
            break;
        }
        count -= 1;
    }

    cout << sum << endl;
    

}


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

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ld n, m, d; cin >> n >> m >> d;
    if(d == 0){
        cout << fixed << std::setprecision(30) << ((m-1)* 1)/n << endl;
    }else{
        cout << fixed << std::setprecision(30) << ((m-1) * 2*(n-d))/(n*n) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	int A[nmax_def];
	int ans[nmax_def];
	cin >> N;
	rep(i, N) {
		cin >> A[i];
		ans[A[i] - 1] = i + 1;
	}
	rep(i, N) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

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

int main(void){
    int K; cin >> K;
    int retsu[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << retsu[K-1] << endl;
    return 0;
}

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

int main() {
    std::string w;
    std::cin >> w;
    bool cnt[26] = {false}; 

    for (size_t i = 0; i < w.size(); ++i) {
        const int c = w[i] - 'a';
        if (cnt[c]) {
            cnt[c] = false;
        } else {
            cnt[c] = true;
        }
    }

    for (int i = 0; i < 26; ++i) {
        if (cnt[i]) {
            std::cout << "No\n";
            return 0;
        }
    }

    std::cout << "Yes\n";

    return 0;
}


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

long long int gcd(long long int a, long long int b){
    int r= a%b;
    while(r>0){
        a=b;
        b=r;
        r=a%b;
    }
    return(b);
}
long long int lcm(long long int a, long long int b){
    return( a * b / gcd(a,b));
}

long long int f(long long int n, long long int c, long long int d){
    return (n - n/c - n/d + n/lcm(c,d));
}

int main(){
    long long int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << f(B,C,D) - f(A-1,C,D) << endl;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim  *///{
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
#define im(a, b) if (a>=b) a -= b; else if (a<0) a += b;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    *this << "\n[";
    for (auto &elem : x) *this << elem << ", ";
    return *this << "]";
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << "{" << x.first << ", " << x.second << "}";
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args ...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(string(#args)), args), dbg << endl
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int n, m, K, T, Q, cn;//}
const int inf = 1000000007, mxn = -1;

int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.precision(10);
    cin >> n >> m;
    K = 1;
    while (K<m) {
        Q++;
        K += (n-1);
    }
    cout << Q << '\n';
}

Measured memory_bytes: 256
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(lst):
    return reduce(lcm_base, lst, 1)

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

m = lcm_list(a) - 1
ans = 0
for i in range(N):
    ans += m % a[i]
print(ans)

Measured memory_bytes: 5344
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	s := readR()
	a := make([]rune, 0, len(s))

	for i := 0; i < len(s); i++ {
		if len(a) != 0 {
			if a[len(a)-1] == 'S' && s[i] == 'T' {
				a = a[:len(a)-1]
				continue
			}
		}
		a = append(a, s[i])
	}
	fmt.Println(len(a))

}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 3788