akhauriyash/Code-Regression huggingface dataset:
def main():
    from collections import deque
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    [g[a-1].append(b-1) for a,b in ab]
    [g[b-1].append(a-1) for a,b in ab]
    visit=[False]*n
    visit[0]=True
    now_front=0
    now_back=0
    d=deque([1])
    while now_front+now_back>-2:
        if now_front!=-1:
            for i in g[now_front]:
                if visit[i]==False:
                    visit[i]=True
                    now_front=i
                    deque.appendleft(d,i+1)
                    break
            else:
                now_front=-1
        if now_back!=-1:
            for i in g[now_back]:
                if visit[i]==False:
                    visit[i]=True
                    now_back=i
                    deque.append(d,i+1)
                    break
            else:
                now_back=-1
    print(len(d))
    print(*d)
main()

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

int main(){
	int n,m;
	while(1){
		cin >> n;
		if(n == 0) break;
		int cou[11111]={0};
		for(int i=0;i<n;i++){
			cin >> m;
			cou[m]++;
		}
		for(int i=0;i<10;i++){
			if(cou[i] == 0) cout  << "-";
			for(int j=0;j<cou[i];j++){
				cout << "*";
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1204
#include<stdio.h>
  
#define MIN 0
#define MAX 86399
  
int main(void)
{
    int S, h, m, s;
  
    scanf("%d", &S);
  
    if(S < MIN || S > MAX)
    {
        return -1;
    }
  
    s = S % 60;
    m = S / 60 % 60;
    h = S / 60 / 60;
  
    printf("%d:%d:%d\n", h, m, s);
  
    return 0;
  
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double ar[n],x;
    double sum=0;
    for(int i=1;i<=n;i++){
        cin>>ar[i];
         sum=sum+(1/ar[i]);
        }
     x=1/sum;
    cout<<x<<endl;
        
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int N, L;
int a[100002];

int dp[100002];

int rec(int i)
{
    if (~dp[i]) return dp[i];

    int cost = -1;

    if (a[i] < a[i - 1]) chmax(cost, rec(i - 1));
    if (a[i] < a[i + 1]) chmax(cost, rec(i + 1));

    int res;

    if (cost == -1) {
        res = L - a[i];
    } else {
        res = cost + (L - a[i]);
    }

    return dp[i] = res;
}

signed main()
{
    cin >> N >> L;

    rep1(i, N) cin >> a[i];

    memset(dp, -1, sizeof(dp));

    int ma = 0;
    rep1(i, N) chmax(ma, rec(i));

    cout << ma << endl;
}

Measured memory_bytes: 4096
import java.util.Scanner;

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

		n = sc.nextInt();
		String s = sc.nextLine();
		for (int i = 0; i < n; i++) {
			char c[] = sc.nextLine().toCharArray();
			for (int j = 0; j < c.length; ) {
				if (j < c.length && c[j] == 'H') {
					j++;
					if (j < c.length && c[j] == 'o') {
						j++;
						if (j < c.length && c[j] == 's') {
							j++;
							if (j < c.length && c[j] == 'h') {
								j++;
								if (j < c.length && c[j] == 'i') {
									j++;
									if (j < c.length && c[j] == 'n') {
										j++;
										if (c[j] == 'o') {
											c[j] = 'a';
										}
									}
								}
							}
						}
					}
				} else {
					j++;
				}
			}
			System.out.print(c);
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-15
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll N,P,Q;
ll C[500100];
vector<ll> vec;
int main(){
	scanf("%lld %lld %lld",&N,&P,&Q);
	ll sum = 0;
	for(int i=0;i<N;i++){
		scanf("%lld",&C[i]);
		sum += C[i];
		vec.pb(P*i+C[i]);
	}
	sort(all(vec));
	for(int i=1;i<vec.size();i++)vec[i]+=vec[i-1];
	ll ans = sum;
	for(int i=1;i<=N;i++)chmax(ans,sum+i*P*Q+P*i*(i-1)-vec[i-1]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10932
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while ( true )
	{
		int n;cin>>n;
		if(n==0)
			break;
		vector<int> a(n);
		for ( int i=0; i<n; i++ )
			cin>>a[i];
		long long ans=-10000000000ll;
		for ( int i=0; i<n; i++ )
		{
			long long t=0;
			for ( int j=i; j<n; j++ )
				t += a[j],
				ans = max(t,ans);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

const long long MAX_V = 1010101;

long long V;
vector<long long> Graph[MAX_V];
long long dist[MAX_V];

void bfs(long long start) {
  queue<long long> que;
  // fill(dist, dist + V, INF);
  fill(dist + 1, dist + 1 + V, INF);

  dist[start] = 0;
  que.push(start);

  while (!que.empty()) {
    auto cur = que.front();
    que.pop();

    for (auto nv : Graph[cur]) {
      if (dist[nv] != INF) {
        continue;
      }

      dist[nv] = dist[cur] + 1;
      que.push(nv);
    }
  }
}

ll N, M;

int main() {
  cin >> N >> M;
  V = N;
  repe(i, 1, M) {
    ll a, b;
    cin >> a >> b;

    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  bfs(1);

  cout << "Yes" << endl;
  repe(i, 2, N) {
    for (auto e : Graph[i]) {
      if (dist[e] == dist[i] - 1) {
        cout << e << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 34332
N = int(input())
abc = [tuple(map(int, input().split())) for _ in range(N)]
  
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
  for j in range(3):
    dp[i+1][j] = max(dp[i][j-1], dp[i][j-2]) + abc[i][j]
    
print(max(dp[-1]))

Measured memory_bytes: 74712
H,W = map(int,input().split())
A = [["#" for _ in range(W+2)]]
for _ in range(H):
    row = list(input().strip())
    row.insert(0,"#")
    row.append("#")
    A.append(row)
A.append(["#" for _ in range(W+2)])
for i in range(H+2):
    print("".join(A[i]))

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

using namespace std;

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

    int a, b;

    cin >> a >> b;
    cout << "a " << (a == b ? "==" : (a < b ? "<" : ">")) << " b\n";

    return 0;
}

Measured memory_bytes: 3120
//Yattazo! Watashiha-Yosen-tsuukashita! It's 460points/600points! OHO!!!!!
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int x[21000][256],n,m,y[64000],z[64000],d,minx;
int main(){
	while(true){
		minx=2000000000;
		for(int i=0;i<21000;i++){for(int j=0;j<256;j++){x[i][j]=2000000000;}}
		cin>>n>>m;if(!n){break;}
		for(int i=0;i<m;i++){cin>>y[i];}
		for(int i=1;i<=n;i++){cin>>z[i];}
		x[0][128]=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<256;j++){
				if(x[i-1][j]<1000000000){
					for(int k=0;k<m;k++){
						d=y[k]+j;
						if(d<0){d=0;}
						if(d>255){d=255;}
						x[i][d]=min(x[i][d],x[i-1][j]+(int)pow(1.0*(z[i]-d),2));
					}
				}
			}
		}
		for(int i=0;i<256;i++){minx=min(minx,x[n][i]);}
		cout<<minx<<endl;
	}
}

Measured memory_bytes: 24108
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int count = 0;
  char S[3], T[3];
    cin >> S >> T;
	  
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i])
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int N, R;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		R = sc.nextInt();
		
		int K = (N>9)?R:R+100*(10-N);
		System.out.println(K);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,i,ans,x;
char s[101];
int main(){
  scanf("%d %s",&n,s);
  ans=0;
  x=0;
  for (i=0;i<n;i++){
    if (s[i]=='I'){
      x++;
      ans=max(ans,x);
    }
    else {
      x--;
    }
  }
  printf("%d\n",ans);
}

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

int main(){
	long long N;
	cin >> N;
	vector<long long> A(N+1);
	vector<long long> lim(N+1);
	long long ans=0,loop;
	for(loop=0;loop<=N;loop++){
		cin >> A[loop];
	}
	long long tmp=0;
	for(loop=N;loop>-1;loop--){
		tmp+=A[loop];
		lim[loop]=tmp;
	}
	long long ps=1;
	for(loop=0;loop<=N;loop++){
		if(loop<N&&ps-1<A[loop]){
			ans=-1;
			break;
		}else{
			ans+=ps;
			if(loop<N){
				ps=min((ps-A[loop])*2,lim[loop+1]);
			}else if(ps!=lim[loop]){
				ans=-1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include <iostream>

using namespace std;

int main()
{
    int h, w;
    
    while (cin >> h >> w) {
        if (h == 0 && w == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (i == 0 || j == 0 || i == h - 1 || j == w - 1) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()

template<typename T>
T lcs(T a, T b) {
    if (b.size() > a.size()) swap(a,b);
    int I = a.size();
    int J = b.size();
    vector<vector<int>> dp(I+1, vector<int>(J+1));
    rep1(i,I) rep1(j,J) {
        if (a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
        else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }

    int cost = dp[I][J];
    T result;
    rep(ii,I) rep(jj,J) {
        int i = I-ii, j = J-jj;
        if(dp[i-1][j-1] == cost-1 && a[i-1] == b[j-1]) {
            result += a[i-1];
            cost--;
            break;
        }
    }
    reverse(all(result));
    return result;
}


int main(void){
    string a,b;
    cin >> a >> b;
    cout << lcs(a,b) << endl;
    return 0;
}


Measured memory_bytes: 35712
n,k,q = map(int,input().split())
a = []
while True:
  try:
    a.append(int(input()))
  except:
    break

score = [k-q]*n

for i in range(q):
  score[a[i]-1] +=1

for i in score:
  if i>=1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 56024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

double pi=3.141592653589;

int main(){
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double ra=30*h+(30*(m/60)), rb=6*m;
	double r=max(ra,rb)-min(ra,rb);
	if(r>180)
		r=360-r;
	r=r*pi/180;
	double ans=sqrt(a*a+b*b-2*a*b*cos(r));
	cout << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long mod_pow(long long a,long long n)
{
    if(n==0)
        return 1;
    long long p=mod_pow(a,n/2);
    long long a1=(p*p)%mod;
    if(n%2)
        return a*a1;
    else return a1;
}

int main()
{
    long long n;
    cin>>n;
    cout<<(n*(n-1)/2);
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MaxN = 2e5;
using namespace std;
int pre[2 * MaxN + 5] , last[MaxN + 5] , other[2 * MaxN + 5];
int n;
int all = -1 , ok = 0;
void Build(int u , int v){
	pre[++all] = last[u];
	last[u] = all;
	other[all] = v;
}
void Init(){
	memset(last , -1 , sizeof(last));
	all = -1 , ok = 0;
	for(int i = 1;i <= n - 1;i++){
		int u , v;
		scanf("%d%d" , &u , &v);
		Build(u , v); Build(v , u);
	}
}
int dfs(int x , int fa){
	int ed = last[x];
	int cont = 0 ;
	while(ed != -1){
		int dr = other[ed];
		if(dr != fa) {
			if(dfs(dr , x)) cont++;
		}
		ed = pre[ed];
	}
	if(cont >= 2){
		ok = 1;
	}
	return !cont;
}
void Solve(){
	if(dfs(1 , 0) == 1 || ok) printf("First\n");
	else printf("Second\n");
}
int main()
{
	while(~scanf("%d" , &n)){
		Init();
		Solve();
	}
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(){
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);
    int soma = 1;

    for(int i = 0; i < n; ++i){
        if(soma+k < soma*2){
            soma = soma+k;
        }
        else{
            soma = soma*2;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
import math

def main(m):
    l = []
    k = 9
    get_index = 0
    for i in range(len(m)):
        t = m[i] % 10
        l.append(t)
        if t != 0 and t < k:
            get_index = i
            k = t

    wa = 0
    for i in range(len(m)):
        if i != get_index:
            wa += math.ceil(m[i] / 10) * 10
        else:
            wa += m[i]
    
    return '{}'.format(wa)

if __name__ == '__main__':
    try:
        m = []
        for i in range(5):
            m.append(int(input().strip()))
        print('{}'.format(main(m)))
    except EOFError:
        pass


Measured memory_bytes: 3064
#include<stdio.h>
#define N 100

int main()
{
  int M[N][N];
  int kazu,i,j,a,b,c;
  scanf("%d",&kazu);
  for(i=0;i<kazu;i++){
    for(j=0;j<kazu;j++)M[i][j]=0;
  }
  for(i=0;i<kazu;i++){
    scanf("%d%d",&a,&b);
    a--;
    for(j=0;j<b;j++){
      scanf("%d",&c);
      c--;
      M[a][c]=1;
    }
  }
  for(i=0;i<kazu;i++){
    for(j=0;j<kazu;j++){
      if(j)printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  ll x; cin >> x;
  ll retval = x/11*2;
  
  if (x%11>0 && x%11<=6) retval++;
  else if (x%11>6 && x%11<=10) retval += 2;
  cout << retval << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3608
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
mod = 10**9+7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if __name__ == "__main__":
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        sys.exit()
    n = (2*y-x)//3
    m = (2*x-y)//3
    ans = cmb(int(n+m),int(n),mod)
    print(ans)

Measured memory_bytes: 168020
import math

def dist(x,y):
    return math.sqrt(x*x + y*y)

def main():
    n, d = map(int, input().split())
    points = []
    for i in range(n):
        points.append(list(map(int, input().split())))

    cnt = 0
    for p in points:
        if dist(p[0], p[1]) <= d:
            cnt += 1

    print(cnt)



if __name__ == "__main__":
    main()

Measured memory_bytes: 102572
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

char getop(char s) {
    if (s == '0') return '1';
    else return '0';
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        string s = ins();
        string s1, s2;
        rep(i, s.size()) s1 += (i % 2 == 0 ? '0' : '1'); // 0101
        rep(i, s.size()) s2 += (i % 2 == 1 ? '0' : '1'); //1010
        ll diff1 = 0, diff2 = 0;
        rep(i, s.size()) {
            if (s[i] != s1[i]) diff1++;
            if (s[i] != s2[i]) diff2++;
        }
        cout << min(diff1, diff2) << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    // 白　赤　はだね
    // 白　赤　OK

    val n = readInteger()
    val cString = br.readLine()!!
    val rSums = IntArray(n + 1)
    val wSums = IntArray(n + 1)
    for (i in 0 until n) {
        rSums[i + 1] += rSums[i] + if (cString[i] == 'R') 1 else 0
        wSums[i + 1] += wSums[i] + if (cString[i] == 'W') 1 else 0
    }

    var ans = Int.MAX_VALUE
    for (pivot in 0..n) {
        val leftWCount = wSums[pivot]
        val rightRCount = rSums.last() - rSums[pivot]

        val swapCount = min(leftWCount, rightRCount)
        val changeCount = max(leftWCount, rightRCount) - swapCount
        ans = min(ans, swapCount + changeCount)
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }

  vector<int> place;
  vector<int> order(n+1,-1);
  int cycle = 1,remainder= 0,v=1;
  
  while(order[v] == -1){
    order[v] = place.size();
    place.push_back(v);
    v = a[v-1];
    }
    cycle = place.size() - order[v];
    remainder = order[v];
  

  if(k < remainder){
    cout << place[k] << endl;
  }
  else {
    k -= remainder;
    k %= cycle;
    cout << place[remainder+k] << endl;
  }
  
}


Measured memory_bytes: 5892
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N){
  cout << (1 + (N-1)) * (N-1) / 2 << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
}


Measured memory_bytes: 256
let [|n;a;b|] = stdin.ReadLine().Split() |> Array.map int64
if a=0L && b=0L then stdout.WriteLine 0
else
    let div = n / (a + b)
    let dif = n - div * (a + b)
    let lef = [a;dif] |> List.min
    a*div + lef |> stdout.WriteLine

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

int main(){
  long n,m,p[1001];
  while(cin>>n>>m,n||m){
    for(int i=1;i<=n;++i) cin>>p[i];
    p[0]=0;
    vector<long> s(0);
    for(int i=0;i<=n;++i){
      for(int j=0;j<=n;++j) s.push_back(p[i]+p[j]);
    }
    sort(s.begin(),s.end());
    s.erase(std::unique(s.begin(), s.end()), s.end());
    long a=0;
    for(vector<long>::iterator it=s.begin();*it<m/2;++it){
      a=max(a,*it+*(upper_bound(s.begin(),s.end(),m-*it)-1));
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 17176
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int retu[8][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};

int main(){
    int a, b;
    cin >> a >> b;
    string A(b, a + '0');
    string B(a, b + '0');
    cout << min(A, B) << endl;
}


Measured memory_bytes: 256
n = input()
l = list(n)
m = int(n)
if l[1:]==["9"]*(len(n)-1):
    print(int(n[0])+9*(len(n)-1))
else:
    if l[0]==1:
        print(9*(len(n)-1))
    else:
        print(9*(len(n)-1)+int(n[0])-1)

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

int main(){
    int N; cin >> N;
    long long a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    long long sum[N+1]={};
    for(int i=0;i<N;i++){
        sum[i+1]=sum[i]+a[i];
    }
    map<long long,long long> ma;
    long long ans=0;
    ma[0]++;
    for(int i=1;i<=N;i++){
        ans+=ma[sum[i]];
        ma[sum[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define N 2050

int n,m,st[N];
char s[N][N];
int a[N][N],dp[N][N],l[N][N],r[N][N];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=(s[i][j]=='#');

	for(int i=1;i<n;i++)
		for(int j=1;j<m;j++)
			a[i][j]=(a[i][j]^a[i+1][j+1]^a[i+1][j]^a[i][j+1]);
	n--; m--;

	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			dp[i][j]=(a[i][j] ? 0 : dp[i-1][j]+1);

	for(int i=1,top=0;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			for (;top && dp[i][st[top]]>dp[i][j];top--)
				r[i][st[top]]=j-st[top];
			st[++top]=j;
		}
		while(top) r[i][st[top]]=m-st[top]+1,top--;
	}

	for(int i=1,top=0;i<=n;i++) {
		for(int j=m;j;j--) {
			for (;top && dp[i][st[top]]>dp[i][j];top--)
				l[i][st[top]]=st[top]-j;
			st[++top]=j;
		}
		while(top) l[i][st[top]]=st[top],top--;
	}

	int ans=max(n+1,m+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans=max(ans,(l[i][j]+r[i][j])*(dp[i][j]+1));
	printf("%d\n",ans);
}


Measured memory_bytes: 69888
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
	ll n,k;
	cin >> n >> k;
  ll i = 1;
  ll tmp = 1;
  while(tmp <= n) {
    tmp *= k;
    if(tmp > n) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(n);
    repins(s, n);

    ll ac = 0;
    ll wa = 0;
    ll tle = 0;
    ll re = 0;

    for (auto ss : s) {
        if (ss == "AC") {
            ac++;
        } else if (ss == "WA") {
            wa++;
        } else if (ss == "TLE") {
            tle++;
        } else if (ss == "RE") {
            re++;
        }
    }
    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);
}

Measured memory_bytes: 6424
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int n,a[101],b[100],ans;
	while(cin>>n&&n){
		for(int i=0;i<n+1;i++)cin>>a[i];
		for(int i=0;i<n+1;i++){
			int j;
			for(j=0;j<n+1;j++){
				if(i==j)continue;
				b[j-(i<j)]=a[j];
			}
			int d=b[1]-b[0];
			for(j=1;j<n;j++){
				if(b[j]-b[j-1]!=d)break;
			}
			if(j==n){	
				ans=a[i];
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1144
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int m_dist(int x1, int y1, int x2, int y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    for (int i = 0; i < n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++){
        if (t[i] % 2 == 0 && (x[i]+y[i])%2 != 0){
            cout << "No" << endl;
            return 0;
        }
        if (t[i] % 2 != 0 && (x[i]+y[i])%2 == 0){
            cout << "No" << endl;
            return 0;
        }
    }

    if (m_dist(x[0], y[0], 0, 0) > t[0]){
        cout << "No" << endl;
        return  0;
    }

    for (int i = 1; i < n; i++){
        if (m_dist(x[i], y[i], x[i-1], y[i-1]) > t[i] - t[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}





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

int main(){
    int a, b, ans;
    cin >> a >> b;
    if(a > b){
        rep(i, a){
            ans += b * pow(10, a-i-1);
        }
    }else{
        rep(i, b){
            ans += a * pow(10, b-i-1);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n,m;

int main(){
    cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#include<vector>
using namespace std;
int main() {
	long int a, b,det;
	cin >> a >> b;
	det = abs(a + b);
		if (det % 2 == 1) {
			cout << "IMPOSSIBLE";
		}
		else {
			cout << det / 2;
		}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
const int N=1e5+5;
const int MOD=1e9+7;

int n;
vector<int> e[N];
LL dp[N][2];
int dfs(int u,int v,bool t)
{
	if(dp[u][t]) return dp[u][t];
	dp[u][t]=1;
	for(int i=0;i<e[u].size();i++)
	{
		if(e[u][i]==v) continue;
		if(t) dp[u][1]=dp[u][1]*dfs(e[u][i],u,0)%MOD;
		if(!t) dp[u][0]=dp[u][0]*(dfs(e[u][i],u,1)+dfs(e[u][i],u,0))%MOD;
	}
	return dp[u][t];
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	printf("%d\n",(dfs(1,0,0)+dfs(1,0,1))%MOD);
	
	return 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

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

    double dp[n+1][n+1]; // dp[i][j] = i枚目まで投げて表がj枚の確率

    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            if(i==0 && j==0){
                dp[i][j] = 1;
            }
            else{
                if(i >= j){
                    dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
                }
            }
        }
    }

    double ans = 0;
    for(int i=1; i<=n; i++){
        if(i > n/2) ans += dp[n][i];
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 70528
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++(i))
#define REP(i,n) FOR(i,0,n)

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

using namespace std;
typedef vector<vector<int>> VVI;

VVI mat;
vector<int> d,f,color;
int tt,n;

void dfs_visit(int i){
  int v;
  color[i] = 1;
  d[i]=++tt;
  REP(v,n){
    if(mat[i][v]==0) continue;
    if(color[v]==0){
      dfs_visit(v);
    }
  }
  color[i] = 2;
  f[i] = ++tt;
}
void dfs(int n){
  tt=0;

  int i;
  REP(i,n){
    if(color[i]==0) dfs_visit(i);
  }

  REP(i,n) cout << i+1 << " " << d[i] << " " << f[i] << endl;
}

int main(void){
  int q,k,i,l;
  cin >> n;
  mat=VVI(n, vector<int>(n));
  color=d=f=vector<int>(n);
  REP(i,n){
    cin >> l; l--;
    cin >> q;
    REP(j,q){
      cin >> k; k--;
      mat[l][k]=1;
    }
  }
  dfs(n);

  return 0;
}

Measured memory_bytes: 3112
#ifdef ConanYu
#include "E:\yuzining\code\local.hpp"
#else
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie();
  Main();
  return 0;
}
#endif

int v[2005];

void Main() {
  int n, x, y; cin >> n >> x >> y;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      int cur = min({j - i, abs(x - i) + 1 + abs(y - j), abs(i - y) + 1 + abs(j - x)});
      v[cur]++;
    }
  }
  for(int i = 1; i < n; i++) {
    cout << v[i] << "\n";
  }
}

Measured memory_bytes: 256
#include <stdio.h>

#define chmax(a,b) ((a)>(b) ? (a) : (b))

#define MaxNum 100100

int main()
{
  int N;
  
  scanf("%d",&N);
 
  int a[MaxNum][3];
  for(int i=0;i<N;i++)
    for(int j=0;j<3;j++)
      scanf("%d",&a[i][j]);
  
  int dp[MaxNum][3]={};

  for(int i=0;i<N;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++)
      {
        if(j==k) continue;
        
        dp[i+1][j]=chmax(dp[i+1][j],dp[i][k]+a[i][j]);
      }
  
  int ans=0;
  for(int i=0;i<3;i++)
    ans=chmax(dp[N][i],ans);
  printf("%d",ans);
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    for(int i = 0;i < b;i++){
      if(i*a %b == c){
        cout << "YES" << endl;
        return 0;
      }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
while True:
 ins=input().split()
 a = int(ins[0])
 b = int(ins[2])
 op = ins[1]
 if op=='+':
  print(a+b)
 elif op=='-':
  print(a-b)
 elif op=='*':
  print(a*b)
 elif op=='/':
  print(a//b)
 else:
  break 

Measured memory_bytes: 7696
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())

n, m = inpl()
a = inpl()
if n - sum(a) < 0:
    print("-1")
else:
    print(n-sum(a))

Measured memory_bytes: 11200
N = int(input())
S = [x for x in input()]
ans = 0

#SL,SR = S[:3],S[3:]

#print(S,SL,SR)

for i in range(1,N+1):
    SL,SR = S[:i],S[i:]
    count = 0
 #   print(SL,SR,count)
    while SL != [] and SR != []:
        if SL[0] in SR:
            count += 1
            a = SL[0]
            while a in SL and a in SR:
                SL.remove(a)
                SR.remove(a)
 #               print(SL,SR)
        elif SL[0] not in SR:
            a = SL[0]
            while a in SL:
                SL.remove(a)

#    print(count)

    if count >= ans:
        ans = count


print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  invar(string, S);
  invar(int, Q);
  
  //deque
  deque<int> d;
  rep(i, S.size()) d.push_back(S[i]);
  
  int dir = 0;  //0 -- 反転なし
  rep(i, Q) {
    invar(int, qtype);
    if(qtype == 1) {
      dir ^= 1;
    } else {
      invar(int, F);
      invar(char, C);
      if(dir == 0 && F == 1 || dir == 1 && F == 2) {
        //先頭
        d.push_front(C);
      } else {
        d.push_back(C);
      }
    }
  }
  
  //string
  string res;
  rep(i, d.size()) {
    res.push_back(d[i]);
  }
  
  if(dir) {
    reverse(all(res));
  }
  
  fin(res);
}

Measured memory_bytes: 2260
#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define ULL ull
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int, pii >
#define pll pair <ll,ll>
#define pb push_back
#define big 20160116
#define INF 2147483647
#define pq priority_queue
using namespace std;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
namespace Mymath{
	LL qp(LL x,LL p,LL mod){
		LL ans=1;
		while (p){
			if (p&1) ans=ans*x%mod;
			x=x*x%mod;
			p>>=1;
		}
		return ans;
	}
	LL inv(LL x,LL mod){
		return qp(x,mod-2,mod);
	}
	LL C(LL N,LL K,LL fact[],LL mod){
		return fact[N]*inv(fact[K],mod)%mod*inv(fact[N-K],mod)%mod;
	}
	template <typename Tp> Tp gcd(Tp A,Tp B){
		if (B==0) return A;
		return gcd(B,A%B);
	}
	template <typename Tp> Tp lcm(Tp A,Tp B){
		return A*B/gcd(A,B);
	}
};
namespace fwt{
	using namespace Mymath;
	void FWT(int a[],int n,LL mod)
	{
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=(x+y)%mod,a[i+j+d]=(x-y+mod)%mod;
	                //xor:a[i+j]=x+y,a[i+j+d]=x-y;
	                //and:a[i+j]=x+y;
	                //or:a[i+j+d]=x+y;
	            }
	}

	void UFWT(int a[],int n,LL mod)
	{
		LL rev=inv(2,mod);
	    for(int d=1;d<n;d<<=1)
	        for(int m=d<<1,i=0;i<n;i+=m)
	            for(int j=0;j<d;j++)
	            {
	                int x=a[i+j],y=a[i+j+d];
	                a[i+j]=1LL*(x+y)*rev%mod,a[i+j+d]=(1LL*(x-y)*rev%mod+mod)%mod;
	                //xor:a[i+j]=(x+y)/2,a[i+j+d]=(x-y)/2;
	                //and:a[i+j]=x-y;
	                //or:a[i+j+d]=y-x;
	            }
	}
	void solve(int a[],int b[],int n,LL mod)
	{
	    FWT(a,n,mod);
	    FWT(b,n,mod);
	    for(int i=0;i<n;i++) a[i]=1LL*a[i]*b[i]%mod;
	    UFWT(a,n,mod);
	}
};
void mian(){
	LL a,b,c,d;
	cin>>a>>b>>c>>d;
	if (b>d || a<b){
		printf("No\n");
		return;
	}
	LL tmp=a-c;
	tmp=(tmp+b-1)/b;
	tmp*=b;
	a-=tmp;
	if (a<0){
		printf("No\n");
		return;
	}
	LL delta=d-b;
	if (b<=c){
		printf("Yes\n");
		return;
	}
	LL xx=__gcd(b,delta);
	LL xxx=b+(a%xx)-xx;
	if (xxx<=c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}
int main(){
	int tc;
	cin>>tc;
	while (tc--){
		mian();
	}
	return 0;
}

Measured memory_bytes: 256
read n
read a
read b
read c
s=0
for i in `seq 0 $((n-1))`
do
    if [ ${a:i:1} = ${b:i:1} -a ${a:i:1} = ${c:i:1} ]
    then
        continue
    elif [ ${a:i:1} = ${b:i:1} -o ${b:i:1} = ${c:i:1} -o ${c:i:1} = ${a:i:1} ]
    then
        s=$((s+1))
    else
        s=$((s+2))
    fi
done
echo $s

Measured memory_bytes: 3832
# -*- coding: utf-8 -*-
"""
D - Coloring Edges on Tree
https://atcoder.jp/contests/abc146/tasks/abc146_d

"""
import sys


from collections import OrderedDict, deque

def main(args):
    N = int(input())
    G = [[] for _ in range(N+1)]
    res = OrderedDict()
    for _ in range(N-1):
        a, b = map(int, input().split())
        res[(a, b)] = -1
        G[a].append(b)
        G[b].append(a)

    k = max(len(g) for g in G)
    colors = [0 for _ in range(N+1)]
    q = deque([1])
    visited = set([1])
    while q:
        cn = q.popleft()
        color = 1
        for nn in G[cn]:
            if nn not in visited:
                if color == colors[cn]:
                    color += 1
                visited.add(nn)
                q.append(nn)
                c = color
                colors[nn] = color
                color += 1
                if (cn, nn) in res:
                    res[(cn, nn)] = c
                if (nn, cn) in res:
                    res[(nn, cn)] = c
    print(k)
    for v in res.values():
        print(v)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 63224
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 123
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
const int n=read(),m=read(),V=read(),mod=read();
int C[N][N],dp[2][N][N],pw[N][N*N];
void init(int n){
	C[0][0]=1;
	for(int i=1;i<=n;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j){
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	for(int i=0;i<=n;++i){
		pw[i][0]=1;
		for(int j=1;j<=n*n;++j){
			pw[i][j]=1LL*pw[i][j-1]*i%mod;
		}
	}
}
int main(){
	init(max(max(n,m),V));
	dp[0][0][0]=1;
	int u=0;
	for(int k=1;k<=V;++k){
		u^=1;
		memset(dp[u],0,sizeof(dp[u]));
		for(int i=0;i<=n;++i){
			for(int j=0;j<=m;++j){
				int now=dp[u^1][i][j];
				if(!now)continue;
				for(int a=0;i+a<=n;++a){
					dp[u][i+a][j]=(dp[u][i+a][j]+1LL*now*C[n-i][a]%mod*pw[k][a*(m-j)]%mod*pw[V-k+1][a*j])%mod;
				}
			}
		}
		u^=1;
		memset(dp[u],0,sizeof(dp[u]));
		for(int i=0;i<=n;++i){
			for(int j=0;j<=m;++j){
				int now=dp[u^1][i][j];
				if(!now)continue;
				for(int b=0;j+b<=m;++b){
					dp[u][i][j+b]=(dp[u][i][j+b]+1LL*now*C[m-j][b]%mod*pw[k][b*(n-i)]%mod*pw[V-k+1][b*i])%mod;
				}
			}
		}
		u^=1;
		memset(dp[u],0,sizeof(dp[u]));
		for(int i=0;i<=n;++i){
			for(int j=0;j<=m;++j){
				int now=dp[u^1][i][j];
				if(!now)continue;
				for(int a=0;i+a<=n;++a){
					dp[u][i+a][j]=(dp[u][i+a][j]+1LL*now*C[n-i][a]%mod*pw[k][a*(m-j)]%mod*pw[V-k][a*j]*(a&1?-1:1))%mod;
				}
			}
		}
		u^=1;
		memset(dp[u],0,sizeof(dp[u]));
		for(int i=0;i<=n;++i){
			for(int j=0;j<=m;++j){
				int now=dp[u^1][i][j];
				if(!now)continue;
				for(int b=0;j+b<=m;++b){
					dp[u][i][j+b]=(dp[u][i][j+b]+1LL*now*C[m-j][b]%mod*pw[k][b*(n-i)]%mod*pw[V-k][b*i]*(b&1?-1:1))%mod;
				}
			}
		}
	}
	printf("%d\n",(dp[u][n][m]+mod)%mod);
	return 0;
}



Measured memory_bytes: 8152
# -*- coding: utf-8 -*-
N,K,Q=map(int,input().split())
A=[K-Q]*N
for _ in range(Q):
    i=int(input())
    A[i-1]=A[i-1]+1
for j in range(len(A)):
    if A[j]>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 6576
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

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

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string a,s,c;
	std::cin >> a >> s >> c;
	std::cout << "A" << s[0] << "C\n";
}


Measured memory_bytes: 256