akhauriyash/Code-Regression huggingface dataset:
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();
        int cnt = 0;
        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                int a = s - y - x;
                if (a >= 0 && a <= k) {
                    cnt++;
                }
            }
        }
        System.out.println(cnt);

    }
}

Measured memory_bytes: 22868
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s;
  cin >> s;
  bool ca = true;
  if(s[2]!=s[3]) ca = false;
  if(s[4]!=s[5]) ca = false;
  if(ca) cout <<"Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Gmax(x,y) (x<(y)&&(x=(y)))
using namespace std;
int n;set<int> p,q;
struct Il {int x,y;I bool operator < (Con Il& o) Con {return x<o.x;}}s[N+5];
class FastIO
{
	private:
		#define FS 100000
		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
		#define tn (x<<3)+(x<<1)
		#define D isdigit(c=tc())
		char c,*A,*B,FI[FS];
	public:
		I FastIO() {A=B=FI;}
		Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
}F;
int main()
{
	RI i,j,t,ans=0;for(F.read(n),i=1;i<=n;++i) F.read(s[i].x),F.read(s[i].y);
	for(sort(s+1,s+n+1),i=1;i<=n;++i) q.insert(s[i].y);
	for(i=1;i<=n;++i) q.erase(s[i].y),p.insert(s[i].y),t=0,
		Gmax(t,max(*--p.end()-s[i].x+1,0)+max(min(*p.begin(),*q.begin())-s[n].x+1,0)),
		Gmax(t,max(*p.begin()-s[i].x+1,0)+max(*q.begin()-s[n].x+1,0)),Gmax(ans,t);
	return printf("%d",ans),0;
}

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

int main() {
  int ans = 500000,i,N,A;cin >> N;
  for(i = 0; i < N; i++){
    cin >> A;
    int count = 0;
    while(A%2 == 0){
      A /= 2;count++;
    }
    if(ans > count) ans = count;
  }
  cout << ans;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    left = 0
    ans = float("inf")
    for a in A:
        left += a
        ans = min(ans, abs(left * 2 - total))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 89424
#include <bits/stdc++.h>
using namespace std;
int c,p;
bool dfs(int i,int j,int k){//iはこれまでに買った個数、jは今見ている品物、kは金額の合計の下2桁
    if(i==c)return k==p;
    
    for(int l=j;l<=5;l++){
        if(dfs(i+1,l,k+l))return true;
    }
    return false;
}
int main(void){
    // Your code here!
    cin>>c;
    if(c>=2000){
        cout<<"1"<<endl;
        return 0;
    }
    p = c%100;
    c/=100;
    bool res = dfs(0,0,0);
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) a.begin(), a.end()
#define mp make_pair

int n;
ll m;
vi a;
vll pref;

pair<ll, ll> count(int low, int high) {
    ll cnt = 0, sum = 0;
    rep(i, 0, n) {
        ll lb = low - a[i];
        ll ub = high - a[i];
        auto limit = a.end();
        // first greater or equal; it1 included
        auto it1 = lower_bound(a.begin(), limit, lb);
        if (it1 == limit) {
            continue;
        }
        // first greater; it2 excluded
        auto it2 = upper_bound(a.begin(), limit, ub);
        if (it1 >= it2) {
            continue;
        }
        cnt += it2 - it1;
        int from = it1 - a.begin();
        int to = it2 - a.begin();
        sum += pref[to] - pref[from] + (ll)(it2 - it1) * a[i];
    }
#ifdef LOCAL
    cout << "low:" << low << " high:" << high << " cnt:" << cnt << " sum:" << sum << el;
#endif
    return mp(cnt, sum);
}

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

    cin >> n >> m;
    a = vi(n);
    loop(a) {
        cin >> x;
    }
    sort(all(a));
    pref = vll{0};
#ifdef LOCAL
    cout << "a sorted: ";
#endif
    loop(a) {
#ifdef LOCAL
        cout << x << ' ';
#endif
        pref.push_back(pref.back() + x);
    }
#ifdef LOCAL
    cout << el;
#endif

    int low = 2e5, high = 2;
    ll ans = 0;
    while (low >= high) {
        int mid = (low + high) / 2;
        auto res = count(mid, low);
        ll cnt = res.first;
        ll sum = res.second;
        if (cnt < m) {
            m -= cnt;
            ans += sum;
            low = mid - 1;
        } else {
            auto res1 = count(mid + 1, low);
            ll cnt1 = res1.first;
            ll sum1 = res1.second;
            if (cnt1 < m) {
                ans += sum1 + (m - cnt1) * mid;
                break;
            } else {
                high = mid + 1;
            }
        }
    }
    cout << ans << el;
}


Measured memory_bytes: 1784
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
vector<int> son[100010];
int top,stk[500010];
bool u[500010];
int fa1[500010],ans[500010],val[500010],tp[500010],d[500010],n,hed[500010],nedge,fa2[500010],too[500010],nxt[500010];
void ae(int x,int y,int a,int b){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
	val[nedge]=a;
	tp[nedge]=b;
}
void add(int x,int y,int z,int tp){
	ae(x,y,z,tp),ae(y,x,z,-tp);
	++d[x],++d[y];
}
void dfs(int x){
	for (int i=hed[x];i;i=hed[x]){
		hed[x]=nxt[i];
		if (u[i] || u[i^1]) continue;
		u[i]=1;
		int y=too[i];
		dfs(y);
		ans[val[i]]=tp[i];
		//在第x个方程里是1，第y个方程里是-1 
	}
	stk[++top]=x;
}
int main(){
	scanf("%d",&n);
	FOR(i,1,n){
		getint(fa1[i]);
		if (fa1[i]==-1) fa1[i]=0;
		son[fa1[i]].pb(i);
	}
	FOR(i,1,n){
		getint(fa2[i]);
		if (fa2[i]==-1) fa2[i]=0;
	}
	nedge=1;
	FOR(i,1,n){
		add(fa1[i],i,i,-1);
	}
	FOR(i,1,n){
		add(fa2[i],i,i+n,1);
	}
	FOR(i,0,n)
		if (d[i]&1) return puts("IMPOSSIBLE"),0;
	dfs(0);
	puts("POSSIBLE");
	FOR(x,1,n){
		int t=ans[x];
		for (int i=0;i<son[x].size();++i){
			int y=son[x][i];
			t-=ans[y];
		}
		printf("%d ",t);
	}
	return 0;
}


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

bool isMax(long long a, long long b, long long c, long long d) {
    if (a >= b && a >= c && a >= d) {
        return true;
    }
    return false;
}

int main(void) {
    int n;
    vector<long long> a;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        long long tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(), a.end());
    long long front, rear, ans = 0;
    front = rear = a[0];
    int is = 1, ie = n - 1;
    for (int i = 0; i < n - 1; ++i) {
        long long ss, se, es, ee;
        ss = abs(front - a[is]);
        se = abs(front - a[ie]);
        es = abs(rear - a[is]);
        ee = abs(rear - a[ie]);
        if (isMax(ss, se, es, ee)) {
            ans += ss;
            front = a[is];
            ++is;
        } else if (isMax(se, ss, es, ee)) {
            ans += se;
            front = a[ie];
            --ie;
        } else if (isMax(es, ss, se, ee)) {
            ans += es;
            rear = a[is];
            ++is;
        } else {
            ans += ee;
            rear = a[ie];
            --ie;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1400
package main

import "fmt"

const NUM = 26
const A = int('A')

func main() {
	var n int
	fmt.Scanln(&n)
	n %= NUM
	var table [256]byte
	for i := A; i < A+NUM; i++ {
		table[i] = byte((i-A+n)%NUM + A)
	}
	var s string
	fmt.Scanln(&s)
	ans := make([]byte, len(s))
	for i := 0; i < len(s); i++ {
		ans[i] = table[s[i]]
	}
	fmt.Println(string(ans))
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int q,x,i,k,l[N],r[N],j,M=998244353;
long long dp[N*2],n,ans,s[N*2];
int main()
{
	scanf("%d %d",&n,&k);
	for(i=1;i<=k;++i)
		scanf("%d %d",&l[i],&r[i]);
	dp[n]=1;
	s[n]=1;
	for(i=n-1;i>=0;--i)
	{
		for(j=1;j<=k;++j)
			dp[i]=(dp[i]+s[i+l[j]]-s[i+r[j]+1])%M;
		s[i]=(dp[i]+s[i+1])%M;
	}
	cout<<(dp[1]%M+M)%M<<endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n+1);
 for(int i= 1;i<=n;i++){
   cin >> h[i];
 }

 vector<int> dp(n+1);
 for(int i=1; i<=n;i++) {
    dp [i] = 1001001;
}
dp[1] = 0;
for(int i=2; i<=n;i++){ 
   if(i >=3){
        dp[i] =  min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
   }else{
        dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
   }
}
cout  << dp[n] << endl;
return 0;
}

Measured memory_bytes: 1024
S = input()
T = input()
s = list(S)
t = list(T)
match = False
for rotation in range(len(s)):
    flag = 0
    for i in range(len(s)):
        if i+rotation > len(s)-1:
            count = i+rotation-len(s)
        else:
            count = i+rotation
        if s[count] == t[i]:
            pass
        else:
            flag = 1
    if flag == 0:
        match = True
if match == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,T;cin>>n>>T;
  ll cost=INF;
  rep(i,n){
    ll c,t;cin>>c>>t;
    if(t<=T)cost=min(cost,c);
  }
  if(cost==INF){
    cout<<"TLE"<<endl;
    return 0;
  }
  cout<<cost<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (B % A == 0) {
            System.out.println(A + B);
        } else {
            System.out.println(B - A);
        }
    }
}

Measured memory_bytes: 22100
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
//番号とx座標と滑りやすさ
vector<P1>s[155];
//滑りやすさ、x座標、y座標
P1 d[1505];
int n,m;
//石番号と残り数を状態にもつdijkstra用配列
int di[1505][76];
//beatmania iidx楽しい!!の部分文字列ではなくindexの部分文字列
int idx=0;
int main()
{
	while(1)
	{
	idx=0;
	scanf("%d %d",&n,&m);
	if(!n) return 0;
	
	for(int i=1;i<=n;i++)
	{
		int k;
		scanf("%d",&k);
		s[i].clear();
		for(int j=0;j<k;j++)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			
			s[i].pb(mp(idx,mp(a,b)));
			d[idx++]=mp(b,mp(a,i));
		}
	}
	for(int i=0;i<1505;i++)for(int j=0;j<76;j++) di[i][j]=1e9;
	priority_queue<P1,vector<P1>,greater<P1> >que;
	for(int i=0;i<s[1].size();i++)
	{
		P1 p=s[1][i];
		di[p.first][m]=0;
		que.push(mp(0,mp(p.first,m)));
	}
	for(int i=0;m>0 && i<s[2].size();i++)
	{
		P1 p=s[2][i];
		di[p.first][m-1]=0;
		que.push(mp(0,mp(p.first,m-1)));
	}
	while(!que.empty())
	{
		P1 p=que.top();
		que.pop();
		int idd=p.second.first;
		int slip1=d[idd].first;
		int x=d[idd].second.first;
		int y=d[idd].second.second;
		int zan=p.second.second;
		if(p.first!=di[idd][zan]) continue;
		
		for(int i=0;i<s[y+1].size();i++)
		{
			P1 pp=s[y+1][i];
			int slip2=pp.second.second;
			int x2=pp.second.first;
			if(di[pp.first][zan]>p.first+(slip1+slip2)*abs(x-x2))
			{
				di[pp.first][zan]=p.first+(slip1+slip2)*abs(x-x2);
				que.push(mp(di[pp.first][zan],mp(pp.first,zan)));
			}
		}
		
		for(int i=0;zan>0 && i<s[y+2].size();i++)
		{
			P1 pp=s[y+2][i];
			int slip2=pp.second.second;
			int x2=pp.second.first;
			if(di[pp.first][zan-1]>p.first+(slip1+slip2)*abs(x-x2))
			{
				di[pp.first][zan-1]=p.first+(slip1+slip2)*abs(x-x2);
				que.push(mp(di[pp.first][zan-1],mp(pp.first,zan-1)));
			}
		}
	}
	
	int ret=INF;
	for(int j=0;j<s[n].size();j++) for(int i=0;i<76;i++) ret=min(ret,di[s[n][j].first][i]);
	for(int j=0;j<s[n-1].size();j++) for(int i=1;i<76;i++) ret=min(ret,di[s[n-1][j].first][i]);
	
	printf("%d\n",ret);
	}
}

Measured memory_bytes: 3232
#include <cstdio>

char A[3][105];
int idx[3];
int main(){
    for (int i=0; i<3; ++i) {
        scanf("%s", &A[i][0]);
    }

    int turn = 0;
    while (1) {
        if (A[turn][idx[turn]] == '\0') {
            printf("%c", turn + 'A');
            break;
        }

        int nxtTurn = A[turn][idx[turn]] - 'a';
        idx[turn]++;
        turn = nxtTurn;
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 50005;
const int M = 100005;

int n, m, t, i, x[M], y[M], mapa[N], co[N];
bitset<N> b[N], bb;
string s;
bool cc[N];


void solve() {
	if (n == 2) {
		printf("-1\n");
		return;
	}
	for (i=0;i<n;i++) {
		mapa[i] = i;
		co[i] = 1;
	}
	for (i=m-1;i>=0;i--) {
		if (co[mapa[x[i]]] > 1) {
			s += 'v';
			co[mapa[x[i]]]--;
			mapa[x[i]] = mapa[y[i]];
			co[mapa[x[i]]]++;
		} else {
			s += '^';
			co[mapa[y[i]]]--;
			mapa[y[i]] = mapa[x[i]];
			co[mapa[y[i]]]++;
		}
	}
	reverse(s.begin(), s.end());
	printf("%s\n", s.c_str());
}

int main() {
scanf("%d %d %d", &n, &m, &t);
s="";
for (i=0;i<m;i++) {
	scanf("%d %d", &x[i], &y[i]);
	x[i]--;
	y[i]--;
}
if (t == 2) {
	solve();
	return 0;
}
for (i=0;i<n;i++) {
	b[i].set(i);
	bb.set(i);
}
for (i=m-1;i>=0;i--) b[x[i]] = b[y[i]] = b[x[i]] | b[y[i]];
for (i=0;i<n;i++) bb &= b[i];
for (i=0;i<n;i++) if (bb[i]) {
	cc[i] = 1;
	for(i=m-1;i>=0;i--) {
		if (cc[y[i]]) s += 'v'; else s += '^';
		cc[x[i]] = cc[y[i]] = cc[x[i]] | cc[y[i]];
	}
	reverse(s.begin(), s.end());
	printf("%s\n", s.c_str());
	return 0;
}
printf("-1\n");
return 0;
}





Measured memory_bytes: 306816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    int t,n,i,j,c=0;
    string s,ss;
    cin>>s>>ss;
    for(i=0,j=0;i<s.size(),j<ss.size()-1;i++,j++)
    {
        if(s[i]!=ss[j])
            c++;
    }
    if(c==0)
    cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3596
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n=0;
	string in;
	cin >> in;
	rep(i, 3) {
		if (in[i] == '1')n++;
	}
	cout << n << endl;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class57
    {
        static void Main()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            for(int i = 0; i < S.Length; i++)
            {
                string s = S.Last().ToString();
                S=S.Remove(S.Length - 1);
                S=S.Insert(0, s);
                if (S == T)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


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

int main(){
	double a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << setprecision(10);
	cout << sqrt((a-c)*(a-c)+(b-d)*(b-d)) << endl;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<P>x(n);
  rep(i,0,n){
    cin>>x[i].fi;
    x[i].fi--;
    x[i].se=i;
  }
  sort(ALL(x));
  vector<ll>ret(n*n,-1);
  ll pos=0;
  rep(i,0,n){
    rep(j,0,x[i].se){
      while(pos<n*n&&ret[pos]!=-1)pos++;
      if(pos>=x[i].fi){
        judge=false;
        break;
      }
      ret[pos]=x[i].se+1;
    }
    if(!judge)break;
    ret[x[i].fi]=x[i].se+1;
  }
  //debug(ret,n*n);
  pos=0;
  rep(i,0,n){
    rep(j,0,n-x[i].se-1){
      while(pos<n*n&&ret[pos]!=-1)pos++;
      if(pos<x[i].fi){
        judge=false;
        break;
      }
      ret[pos]=x[i].se+1;
    }
    if(!judge)break;
  }
  ans1(judge);
  if(judge)debug(ret,n*n);
  return 0;
}

Measured memory_bytes: 3200
#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字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    vector<ll> r(N);
    ll sum = 0;
    for(int i=0; i<N; ++i) { cin >> a[i]; sum += a[i]; }

    ll sub = 0;
    for(int i=1; i<=N-1; i+=2) sub += a[i];
    r[0] = sum-2*sub;

    for(int i=1; i<N; ++i) r[i] = 2*a[i-1]-r[i-1];
    
    for(int i=0; i<N; ++i){
        if(i) cout << " ";
        cout << r[i];
    }
    cout << endl;

}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>

typedef long long ll;
using namespace std;

int main(){
	int j,k,a;
  string s;
  cin >> s;
  a=s.length();
  for(int i=0;;i++){
  	if(s[i]=='A'){
  		j=i;
  		break;
  	}
  }
  for(int i=a-1;;i--){
  	if(s[i]=='Z'){
  		k=i;
  		break;
  	}
  }
  cout << k-j+1<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void)
{
    uint32_t A, B, C;
    cin >> A >> B >> C;


    uint32_t ans = 0;
    if(B >= C)
    {
        ans = 2 * C + (B - C);
    }
    else if(B < C)
    {
        ans = 2 * B;
        C -= B;
        if(A >= C)
        {
            ans += C;
        }
        else if(A < C)
        {
            ans += A + 1;
        }
    }


    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>

/*
constraints
- ALL values in input are integers.
- 1 <= A <= B <= 1000
- 1 <= K <= 1000
*/

int main (){
	// multiple of K
	int k, multiK;
	
	// carry distance A - B
	int a, b;
	
	// if he can achieve the objective print OK
	// if he can't achieve the objective print NG
	scanf ("%d", &k);
	scanf ("%d %d", &a, &b);
	
	for (int i = a; i <= b; i++){
		if (i % k == 0) {
			printf ("OK");
			return 0;
		}
		else {
			continue;
		}
	}
	printf ("NG");
	return 0;
	}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <limits.h>

using namespace std;

int main() {
  int32_t n;
  int32_t value;
  int32_t max = 0;
  int32_t min = INT_MAX;

  cin >> n;
  for (int32_t i = 0; i < n; ++i) {
    cin >> value;
    max = std::max(max, value);
    min = std::min(min, value);
  }
  cout << max - min;
}



Measured memory_bytes: 256
//ノードが持つ情報→子のノードの情報
//ノードが子を持たないときはからのvectorを保持する
#include<iostream>
#include<vector>
#include<string>

using namespace std;

class Node{
public:
  ///ノードの番号
  int num;
  //そのノードの親
  Node* p=nullptr;
  //そのノードの子
  vector<Node*> v;
  //そのノードの深さ(-1は未定義)
  //0で初期化
  int dep;
};


int number(Node a){
  return a.num;
}

int parent(Node a){
  if(a.p!=nullptr){
    return (a.p)->num;
  }else{
    return -1;
  }
}
//ここの深さを計算する部分が遅い
//同じところを何回も計算してるからか
int depth(Node a){
  int k=0;
  while(a.p!=nullptr){
    a=*(a.p);
    k+=1;
  }
  return k;
}
//topから順に下へ深さを加算して求める
//structにdepthも記録しておく
Node find_root(vector<Node> vn){
  int lv=(int)(vn.size());
  for(int i=0;i<lv;i++){
    if(vn[i].p==nullptr){return vn[i];}
  }
}

void depth2(Node n){
  int l=n.v.size();
  if(l!=0){
    for(int i=0;i<l;i++){
      (n.v[i])->dep=n.dep+1;
      depth2(*(n.v[i]));
    }
  }
}

string type(Node a){
  if(a.p==nullptr){
    return "root";
  }else if(a.v.size()==0){
    return "leaf";
  }else{
    return "internal node";
  }
}

string Node_list(Node a){
  string s="[";
  int si= (int)((a.v).size());
  for(int i=0;i<si;i++){
    if(i!=si-1){
      s=s+to_string((a.v[i])->num)+", ";
    }else{
      s+=to_string((a.v[i])->num);
    }
  }
  s+="]";
  return s;
}




int main(){
  int n;cin >> n;
  vector<Node> tree(n);
  for(int i=0;i<n;i++){
    int k,l,m;
    cin >> k >> l;
    int num=k;
    tree[num].num=num;
    for(int j=0;j<l;j++){
      cin >> m;
      //ここは参照を入れないと
      (tree[num].v).push_back(&(tree[m]));
      //&がアドレス演算子
      tree[m].p= &tree[num];
      tree[m].num=m;
    }
  }
  //深さを先に求める
  depth2(find_root(tree));
  for(int i=0;i<n;i++){
    Node tr=tree[i];
    cout << "node " << number(tr) << ": parent = " << parent(tr) << ", depth = " << tr.dep << ", " << type(tr) << ", " << Node_list(tr) << endl;
    /*
    for(int j=0;j<(int)(tr.v.size());j++){
      cout << tr.v[j].num;
    }
    cout<< endl;
    */
  }

}



Measured memory_bytes: 14656
N, M = gets.split(' ').map(&:to_i)

stores = []
N.times do
  a = gets.split(' ').map(&:to_i)
  stores.push(a)
end
stores.sort_by!{|store| store[0]}

drinks = 0
money = 0
while true
  store = stores.shift
  if store[1] + drinks < M
    drinks += store[1]
    money += store[0] * store[1]
  else
    money += store[0] * (M - drinks)
    break
  end
end

puts money

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

using ll = long long;

const int MAXN = 200;
int N;
ll X;
ll A[MAXN];

int main() {
	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		cin >> A[i+1];
	}
	sort(A + 1, A + N + 1);
	A[0] = 0;
	for (int i = 0; i < N; i++) {
		A[i+1] += A[i];
	}
	if (A[N] == X) {
		cout << N << '\n';
	} else {
		int res = 0;
		while (res < N-1 && A[res+1] <= X) {
			res++;
		}
		cout << res << '\n';
	}

	return 0;
}


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

using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="SAT"){
    cout<<1<<endl;
    return 0;
  }
  if(s=="MON"){
    cout<<6<<endl;
    return 0;
  }
  if(s=="TUE"){
    cout<<5<<endl;
    return 0;
  }
  if(s=="WED"){
    cout<<4<<endl;
    return 0;
  }
  if(s=="THU"){
    cout<<3<<endl;
    return 0;
  }
  if(s=="FRI"){
    cout<<2<<endl;
    return 0;
  }
  if(s=="SUN"){
    cout<<7<<endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    ll count[3] = {};
    for(int i = 0;i < n;i++)
    {
        if(s[i] == 'R')
        {
            count[0]++;
        }
        else if(s[i] == 'G')
        {
            count[1]++;
        }
        else
        {
            count[2]++;
        }
    }
    ll ans = count[0] * count[1] * count[2];
    for(int i = 1;i + 1 < n;i++)
    {
        for(int j = 1;i + j < n && i - j >= 0;j++)
        {
            if(s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j])
            {
                ans--;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

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

int main(){
	int a1,a2,a3,b1,b2,b3;
	int x[4][4];
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin>>x[i][j];
		}
	}
	a1=0;
	b1=x[1][1]-a1;
	b2=x[1][2]-a1;
	b3=x[1][3]-a1;
	a2=x[2][1]-b1;
	a3=x[3][1]-b1;
	if(a2+b2==x[2][2] && a2+b3==x[2][3] \
	&& a3+b2==x[3][2] && a3+b3==x[3][3]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
//ヘッダファイル
#include<stdio.h>

//マクロ定義
#define MAX 5000
#define FALSE 1
#define compile 1

//関数のプロトタイプ宣言
void func_init(int array[], int n);

main()
{
	int dead_end[MAX];
	int exit[MAX];
	func_init(dead_end, MAX);
	func_init(exit, MAX);
	int input = 0, i = 0, j = 0, k = 0, flag = 0;
	
	while(scanf("%d", &input) != EOF)
	{
		if(input != 0)
		{
			dead_end[i] = input; //現在のiを要素番号としてinputを入力
			i++;
		}
		else if(input == 0)
		{
			exit[j] = dead_end[--i];
			dead_end[i] = 0;
			j++;
		}
	}
	
	for(i = 0; exit[i] != 0; i++)
	{
		printf("%d\n", exit[i]);
	}
	return 0;
}
void func_init(int array[], int n)
{
	int i = 0;
	for(i = 0; i < n; i++)
	{
		array[i] = 0;
	}
}

Measured memory_bytes: 636
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>
#define MP make_pair
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 1e5 + 1;

int x[MAX_N], y[MAX_N];
bool is_checked[MAX_N];
vector<int> graph[MAX_N];

int main() {
    int N;
    cin >> N;
    vector<pair<P, int> > x_vec, y_vec;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        x_vec.push_back(MP(P(x[i], y[i]), i));
        y_vec.push_back(MP(P(y[i], x[i]), i));
    }
    sort(x_vec.begin(), x_vec.end());
    sort(y_vec.begin(), y_vec.end());
    for (int i = 0; i < x_vec.size() - 1; i++) {
        graph[x_vec[i].second].push_back(x_vec[i + 1].second);
        graph[x_vec[i + 1].second].push_back(x_vec[i].second);
    }
    for (int i = 0; i < y_vec.size() - 1; i++) {
        graph[y_vec[i].second].push_back(y_vec[i + 1].second);
        graph[y_vec[i + 1].second].push_back(y_vec[i].second);
    }
    priority_queue<P> PQ;
    int ans = 0;
    PQ.push(MP(0, 0));
    while (!PQ.empty()) {
        P now = PQ.top();
        PQ.pop();
        int cost = -now.first, node = now.second;
        if (is_checked[node]) continue;
        is_checked[node] = true;
        ans += cost;
        for (int i = 0; i < graph[node].size(); i++) {
            if (is_checked[graph[node][i]]) continue;
            int u = graph[node][i];
            PQ.push(MP(max(-abs(x[node] - x[u]), -abs(y[node] - y[u])), u));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10796
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;
  std::cin >> NN;

  ll a[NN];

  for (size_t i = 0; i < NN; i++) {
    std::cin >> a[i];
  }

  int flag = 0;

  for (size_t i = 0; i < NN; i++) {
    if (a[i] % 2 == 1) {
      flag = 1;
    }
  }

  if (flag == 1) {
    std::cout << "first" << '\n';
  }else{
    std::cout << "second" << '\n';
  }

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int get_area(int height, int width);
int get_length(int height, int width);

int main() {
    int height;
    int width;

    scanf("%d %d", &height, &width);
    printf("%d %d\n", get_area(height, width), get_length(height, width));
    return 0;
}

int get_area(int height, int width) {
    return height * width;
}

int get_length(int height, int width) {
    return height * 2 + width * 2;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef __int128 INT;
typedef vector<LL> V;
typedef vector<V> VV;

V kmp_table_build(string word){
    int n=word.size();
    V table(n+1,0);
    table[0]=-1;
    for(int i=2,j=0;i<=n;){
        if(word[i-1]==word[j])table[i++]=++j;
        else if(j>0)j=table[j];
        else table[i++]=0;
    }
    return table;
}

V f(string s,INT k){
    LL x=s.size();
    V ret(26,0);
    LL loop=k/x;
    for(auto &it:s)ret[it-'a']+=loop;
    k-=loop*x;
    REP(i,k)ret[s[i]-'a']++;
    return ret;
}
V g(string &s1,VV &c,vector<INT> &l,INT k,int id){
    if(k==0)return V(26,0);
    if(id<=1){
        V ret(26,0);
        REP(i,k)ret[s1[i]-'a']++;
        return ret;
    }
    if(l[id-1]<=k){
        V ret=c[id-1];
        V rest=g(s1,c,l,k-l[id-1],id-2);
        REP(i,26)ret[i]+=rest[i];
        return ret;
    }
    else return g(s1,c,l,k,id-1);
}

int main(){
    string s;LL l,r;
    cin>>s>>l>>r;
    LL n=s.size()/2;
    s=s.substr(0,n);
    V table=kmp_table_build(s);
    LL x=n-table[n];
    if(n%x==0){
        s=s.substr(0,x);
        auto a=f(s,r);
        auto b=f(s,l-1);
        REP(i,26)cout<<" "+(!i)<<a[i]-b[i];cout<<endl;
    }
    else{
        VV cnt(128,V(26,0));
        vector<INT> len(128);
        REP(i,n)cnt[0][s[i]-'a']++;
        len[0]=n;
        len[1]=n+x;
        cnt[1]=cnt[0];
        REP(i,x)cnt[1][s[i]-'a']++;
        int id=-1;
        FOR(i,2,128){
            len[i]=len[i-1]+len[i-2];
            //cout<<i<<":"<<(int)len[i]<<endl;
                        
            REP(j,26)cnt[i][j]+=cnt[i-1][j]+cnt[i-2][j];
            if(len[i]>r){
                id=i;
                break;
            }
        }
        s=s+s.substr(0,x);
        auto a=g(s,cnt,len,r,id);
        auto b=g(s,cnt,len,l-1,id);
        REP(i,26)cout<<" "+(!i)<<a[i]-b[i];cout<<endl;
    }
    return 0;
}


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

using namespace std;

int R, C;
int a[11][10010];
bool turn[11];

int ans;

int senbei()
{
  int ret = 0;
  for(int i = 0; i < C; i++){
    int cnt = 0;
    for(int j = 0; j < R; j++){
      if(turn[j] && a[j][i] == 0 || !turn[j] && a[j][i] == 1) cnt++;
    }
    ret += max(cnt, R - cnt);
  }
  return ret;
}

void solve(int r)
{
  if(r == R){
    ans = max(ans, senbei());
    return;
  }
  
  turn[r] = true;
  solve(r + 1);
  
  turn[r] = false;
  solve(r + 1);
}

int main()
{
  while(cin >> R >> C, R || C){
    for(int i = 0; i < R; i++){
      for(int j = 0; j < C; j++) cin >> a[i][j];
    }
  
    fill(turn, turn + 11, false);
    ans = -1;
    solve(0);

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

Measured memory_bytes: 1556
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000000000000000000;
 
int main()
{
 
    long long a,b;
    long long x=0,k1=0;
    cin>>a>>b;
    if(a%b==0)cout<<-1;
else cout<<a;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        a: usize,
        b: usize
    }
    if a > b {
        println!("0");
        return;
    }
    if n == 1 {
        if a == b {
            println!("1");
        } else {
            println!("0");
        }
        return;
    } else if n == 2 {
        println!("1");
        return;
    }
    println!("{}", (n - 2) * (b - a) + 1);
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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


int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string str;cin >> str;
	if(regex_match(str, std::regex(".*?keyence"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("k.*?eyence"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("ke.*?yence"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("key.*?ence"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("keye.*?nce"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("keyen.*?ce"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("keyenc.*?e"))){cout << "YES" << endl;return 0;}
	if(regex_match(str, std::regex("keyence.*?"))){cout << "YES" << endl;return 0;}
	cout << "NO" << endl;
	return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  
  vector<string> vec(N);
  
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int i=0; i<N; i++){
    cout << vec.at(i);
  }
  
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=1002;
LL S;

void read(LL &x){ scanf("%lld",&x); }

int main(){
	read(S);
	LL x=sqrt(S)+0.0001,y=S/x;
	if (x*y<S) x++;
	LL v=x*y-S;
	LL a=x-1,b=y-v;
	printf("%lld %lld %lld %lld %lld %lld\n",a,0,0,b,x,y);
	return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
    ll a,b,k;scanf("%lld %lld %lld",&a,&b,&k);
    if(a+b <= k){
        cout << 0 << " " << 0 << endl;
    }else{
        if(a <= k){
            k -= a;a = 0;
        }else{
            a -= k; k = 0;
        }
        if(b <= k){
            b = 0;
        }else{
            b -= k;
        }
        cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 256
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int n,k;cin>>n>>k;
	if(n%k==0){
		cout<<0;
	}
	else{
		int r=n%k;
		int a1=abs(r-k);
		int a2=abs(a1-k);
		int a3=abs(a2-k);
		int ans=min({r,a1,a2,a3});
		cout<<ans;
	}
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string a;
  cin >> a;
  int b = 0;
  for(int i = 0;i<3;i++){
    if(a.at(i)==a.at(i+1)) b = 1;
  }
  if(b)cout << "Bad";
  else cout << "Good";
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#define llint long long

using namespace std;

llint n;
llint a[200005];

int main(void)
{
	cin >> n;
	for(llint i = 1; i <= n; i++) cin >> a[i];
	for(llint i = 1; i <= n; i++) a[i] -= i;
	sort(a+1, a+n+1);
	
	llint x = a[(n+1)/2];
	llint ans = 0;
	for(llint i = 1; i <= n; i++) ans += abs(a[i] -x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
ABs = []
for _ in range(N):
    A,B = list(map(int, input().split()))
    ABs.append([A,B])

ABs.sort(key=lambda x: x[0])
ans = 0

A,B = ABs[0]
ans += A-1

for i in range(1,N):
    A,B = ABs[i]
    A_prev,B_prev = ABs[i-1]

    ans += A - A_prev - 1

ans += ABs[-1][1]
ans += N

print(ans)

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

int main()
{
    long long n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    long long alpha=1;
    for(long long i=1;i<s.size();i++)
    {
        if(s[i]!=s[i-1])
            alpha++;
    }
    cout<<min(n-1,n-alpha+2*k);
    return 0;
}


Measured memory_bytes: 512
n=int(input())
li=list(map(int,input().split()))
li.sort(reverse=True)
ans=0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if li[i]==li[j] or li[j]==li[k]:
        continue
      if li[i]<li[j]+li[k]:
        ans+=1
print(ans)

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

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long V, long long B, long long W, long long T){
  string ans = (abs(A-B) > T * (V-W)) ? NO : YES;
  cout << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long V;
    scanf("%lld",&V);
    long long B;
    scanf("%lld",&B);
    long long W;
    scanf("%lld",&W);
    long long T;
    scanf("%lld",&T);
    solve(A, V, B, W, T);
    return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
int main(void)
{
	int n,g[2],i[2],j[2],k[2],h;
	while(1){
		int gis=0,id[3]={0};
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(h=0;h<n;h++){
			scanf("%d%d%d%d%d%d%d%d",&g[0],&i[0],&j[0],&k[0],&g[1],&i[1],&j[1],&k[1]);
			gis=g[0]*g[1]+i[0]*i[1]*-1+j[0]*j[1]*-1+k[0]*k[1]*-1;
			id[0]=g[0]*i[1]+i[0]*g[1]+j[0]*k[1]+k[0]*j[1]*-1;
			id[1]=g[0]*j[1]+j[0]*g[1]+i[0]*k[1]*-1+k[0]*i[1];
			id[2]=g[0]*k[1]+k[0]*g[1]+i[0]*j[1]+j[0]*i[1]*-1;
			printf("%d %d %d %d\n",gis,id[0],id[1],id[2]);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>

/*
問題文
シカのAtCoDeerくんは二つの正整数 
a, b  を見つけました。 
a と  b  の積が偶数か奇数か判定してください。

制約
1 ≤ a, b ≤ 10000
a, b  は整数

入力
入力は以下の形式で標準入力から与えられる。
a b

出力
積が奇数なら Odd と、 偶数なら Even と出力せよ。

*/

int main()
{
    int a, b, p = 0;
    std::cin >> a >> b;
    p = a * b;

    if ( p % 2 == 0 ) {
        std::cout << "Even" << std::endl;
    } else {
        std::cout << "Odd" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    S = _S()
    youbi = ["MON","TUE","WED","THU","FRI","SAT","SUN"][::-1]
    print(youbi.index(S) if S!="SUN" else 7)

main()



Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    bool restore = false;
    for (int i = s.size() - t.size(); i >= 0; i--)
    {
        bool replace = true;
        for (int j = 0; j < t.size(); j++)
        {
            if (s[i + j] != '?' && s[i + j] != t[j])
            {
                replace = false;
                break;
            }
        }
        if (replace == true)
        {
            restore = true;
            for (int j = 0; j < t.size(); j++)
                s[i + j] = t[j];
            break;
        }
    }
    if (restore == true)
    {
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] == '?') cout << 'a';
            else cout << s[i];
        }
    }
    else cout << "UNRESTORABLE";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
long long int dp[110][100100];
long long int w,weight[110],value[110];
int main(void){
    int n;
    cin>>n>>w;
    for (int i=0;i<n;i++) {
        cin>>weight[i]>>value[i];
    }
    const long long INF=1LL<<60;
    for (int i=0;i<110;i++) {
        for (int j=0;j<100100;j++) {
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for (int i=0;i<n;i++) {
        for (int sum_v=0;sum_v<100100;sum_v++) {
            if (sum_v-value[i]>=0) {
                chmin(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i]);
            }
            chmin(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }
    long long int ans=0;
    for (int sum_v=0;sum_v<100100;sum_v++) {
        if (dp[n][sum_v]<=w) {
            ans=sum_v;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 89592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	ll S;
	cin >> S;
    ll x1 = 1e9;
    ll y1 = 1;
    ll y2 = (S +(x1-1)) / x1;
    ll x2 = x1 * y2 - S;

    vector<ll> ans;
    ans.push_back(x1); ans.push_back(y1);
    ans.push_back(x2); ans.push_back(y2);
    ans.push_back(0); ans.push_back(0); 

    rep(i, ans.size()) {
    	cout << ans[i] << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 100005
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,w,i,j;
    cin>>n>>w;
    ll val[n],wt[n],sumval=0;
    for(ll i=0;i<n;i++)
    {
    	cin>>wt[i]>>val[i];
     	sumval+=val[i];
    }
    ll dp[n+1][sumval+1];
    rep(i,0,n+1)
    {
      rep(j,0,sumval+1)
      {
        if(j==0)
          dp[i][j]=0;
        else
          dp[i][j]=INT_MAX;
      }
    }
    rep(i,1,n+1)
    {
        rep(j,1,sumval+1)
        {
            if(j-val[i-1]>=0)
            {
                dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;;
            }
            else
            {
                dp[i][j]=dp[i-1][j];
                //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;;
            }
        }
    }
  int res=0;
 // rep(j,0,n+1)
 // {
  rep(i,0,sumval+1)
  {
   // cout<<dp[j][i]<<" ";
    if(dp[n][i]<=w)
      res=i;
  }
   // cout<<endl;
  //}
  cout<<res<<endl;
}


Measured memory_bytes: 79232