akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split();
        var h = int.Parse(input[0]);
        var w = int.Parse(input[1]);
        var matrix = new int[h, w];

        for (var i = 0; i < h; i++)
        {
            var temp = Array.ConvertAll(ReadLine().Split(), int.Parse);
            for (var j = 0; j < w; j++)
            { matrix[i, j] = temp[j]; }

        }

        var pickUp = false;
        var traceList = new List<string>();

        for (var i = 0; i < h; i++)
        {
            //奇数段
            if (i % 2 == 0)
            {
                for (var j = 0; j < w; j++)
                {
                    if (matrix[i, j] % 2 == 1)
                    { pickUp = !pickUp; }


                    if (pickUp)
                    {
                        var s = new string[4];

                        if (j + 1 < w)
                        {
                            s[0] = Convert.ToString(i + 1 + " ");
                            s[1] = Convert.ToString(j + 1 + " ");
                            s[2] = Convert.ToString(i + 1 + " ");
                            s[3] = Convert.ToString(j + 2);
                            traceList.Add(s[0] + s[1] + s[2] + s[3]);
                        }
                        else if (i + 1 < h)
                        {
                            s[0] = Convert.ToString(i + 1 + " ");
                            s[1] = Convert.ToString(j + 1 + " ");
                            s[2] = Convert.ToString(i + 2 + " ");
                            s[3] = Convert.ToString(j + 1);
                            traceList.Add(s[0] + s[1] + s[2] + s[3]);
                        }
                    }
                }
            }
            //偶数段
            else
            {
                for (var j = w - 1; j >= 0; j--)
                {
                    if (matrix[i, j] % 2 == 1)
                    { pickUp = !pickUp; }

                    if (pickUp)
                    {
                        var s = new string[4];

                        if (j > 0)
                        {
                            s[0] = Convert.ToString(i + 1 + " ");
                            s[1] = Convert.ToString(j + 1 + " ");
                            s[2] = Convert.ToString(i + 1 + " ");
                            s[3] = Convert.ToString(j);
                            traceList.Add(s[0] + s[1] + s[2] + s[3]);
                        }
                        else if (i + 1 < h)
                        {
                            s[0] = Convert.ToString(i + 1 + " ");
                            s[1] = Convert.ToString(j + 1 + " ");
                            s[2] = Convert.ToString(i + 2 + " ");
                            s[3] = Convert.ToString(j + 1);
                            traceList.Add(s[0] + s[1] + s[2] + s[3]);
                        }
                    }
                }
            }
        }

        WriteLine(traceList.Count);
        foreach (string s in traceList)
        { WriteLine(s); }
    }
}


Measured memory_bytes: 30748
#include <bits/stdc++.h>
#define int long long
using namespace std;


template<int mod>
struct ModInt{
	int x;

	ModInt() : x(0){}
	ModInt(long long y) : x(y>=0 ? y%mod : (mod-(-y)%mod)){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}

	ModInt operator-() const{return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{return ModInt (*this)+=p;}
	ModInt operator-(const ModInt &p) const{return ModInt (*this)-=p;}
	ModInt operator*(const ModInt &p) const{return ModInt (*this)*=p;}
	ModInt operator/(const ModInt &p) const{return ModInt (*this)/=p;}
	bool operator==(const ModInt &p) const{return x==p.x;}
	bool operator!=(const ModInt &p) const{return x!=p.x;}
	friend ostream &operator<<(ostream &os, const ModInt &p){return os<<p.x;}
	friend istream &operator>>(istream &is,ModInt &a){
		int t;
		is>>t;
		a=ModInt<mod>(t);
		return (is);
	}

	ModInt inverse() const{
		int a=x, b=mod, u=1, v=0, t;
		while(b>0){
			t=a/b;
			a-=t*b;
			swap(a,b);
			u-=t*v;
			swap(u,v);
		}
		return ModInt(u);
	}
	
	ModInt pow(int e) const{
		long long a=1,p=x;
		while(e>0){
			if(e%2==0){p=(p*p)%mod; e/=2;}
			else {a=(a*p)%mod; e--;}
		}
		return ModInt(a);
	}
};

using modint=ModInt<1000000007>;

signed main(){
    int N,K; cin>>N>>K;
    modint ans=0;
    for(int j=K;j<=N+1;j++){
        ans+=(j*N-j*j+j+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>  
#define endl "\n"
using namespace std;
	typedef long long ll;
	const int maxn=100005;
	const int inf=0x3f3f3f3f;
	int a[maxn]; 
	int dp[maxn];
	int n,k;
	int main(){
		cin>>n>>k;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		memset(dp,0x3f,sizeof(dp));
		dp[1]=0;
		for(int i=2;i<=n;i++)
			for(int j=1;j<=k;j++){
				if(i-j<0)
					break;
				dp[i]=min(dp[i],dp[i-j]+(abs(a[i]-a[i-j])));
			}
				
		cout<<dp[n]<<endl;
	}

Measured memory_bytes: 4388
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    ll x;
    cin >> x;
    cout << (x / 500 * 1000 + (x % 500) / 5 * 5) << endl;
    return 0;
}

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

// Problem https://atcoder.jp/contests/abc061/tasks/abc061_b

vector<int> solver(int point,int bridge,vector<vector<int> > linkB){
    vector<int> result(point,0);
    for(int j=0;j<bridge;j++){
        for(int k=0;k<2;k++){
            int positionID;
            positionID = linkB.at(j).at(k)-1;
            result.at(positionID)=result.at(positionID)+1;
        }
    }
    return result;
}

int main(void){
    int N,M;
    cin >> N >> M ;
    vector< vector<int> > ab (M, vector<int>(2) );
    vector<int> answer(N);
    for(int j=0;j<M;j++){
        cin >> ab.at(j).at(0) >> ab.at(j).at(1);
    }
    answer = solver(N,M,ab);
    for(int j=0;j<N;j++){
        cout << answer.at(j) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)


//C++で提出



// string s="AAA";    s.size() =3    (sのサイズ) ...1
// vector <int> a;    配列a(サイズは0) ...2
// a.push_back(10);   配列のサイズが一つ増えて一番後ろに10を代入 ...2
// A.pop_back();   最後の要素が消去される
// sort(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)より前までを小さい順に並び替えてa[0]から代入していく...3
// reverse(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)までを逆の順にしてa[0]から代入していく
// s.substr(3,2)   配列s[3]から2個の文字を抜き出した文字列 (s[3]とs[4]) ...4
// strcmp(s1,s2)  文字列が等しければ0を出力　s1>s2なら1 s1<s2なら-1を出力　C言語用なので配列は、s1[100]にする...5




/*
const int MAX = 100;
int main() {
	int N, M;
	string s, t;
	map<string, int> m;
	m["apple"] = 10;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> t;
		m[t]--;
	}
	
	int max=0;

	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max < (i->second)) max = i->second;
	}

	if (max < 0) cout << "0";
	else cout << max;

	return 0;
}

*/

int main() {

	
	string s,t;
	cin >> s>>t;
	
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";






}

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

using namespace std;
typedef long long ll;

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

int main()
{
  int X, A;

  cin >> X >> A;
  if(X<A)
    cout << 0 << endl;
  else
    cout << 10 << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  rep(i, B + 1)
  {
    if (i * A % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

int main() {
    ll n,m;
    std::cin >> n>>m;
    vector<vector<ll>> edges(n);
    for (int i = 0; i < m; i++) {
        ll a,b;
        std::cin >>a>>b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    typedef pair<ll, ll> P;
    vector<ll> d(n,1e16);
    vector<ll> f(n,-1);
    d[0]=0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, 0));
    while (!que.empty()) {
     P p = que.top();
     que.pop();
     int v = p.second;
     if (d[v] < p.first) continue;
    	for (int i=0; i<edges[v].size(); ++i) {
        	auto e = edges[v][i];
         if (d[e] > d[v] + 1) {
             d[e] = d[v] + 1;
             f[e] = v;
             que.push(P(d[e], e));
         }
     }
    }
    for (int i = 0; i < n; i++) {
        if(d[i]==1e16){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    for (int i = 1; i < n; i++) {
        std::cout << f[i]+1 << std::endl;
    }
}


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

iii PD[3001][3001];

int main(){
	string a, b;
	cin >> a >> b;
	FOR(i, 0, sz(a)){
		FOR(j, 0, sz(b)){
			iii ans = mp(0, mp(i-1, j));
			if(a[i] == b[j]){
				if(i > 0 && j > 0){
					ans = mp(1 + PD[i-1][j-1].st, mp(i-1, j-1));
				} else {
					ans = mp(1, mp(i-1, j-1));
				}
			}
			if(i > 0){
				if(ans.st < PD[i-1][j].st){
					ans = mp(PD[i-1][j].st, mp(i-1,j));
				}
			}
			if(j > 0){
				if(ans.st < PD[i][j-1].st){
					ans = mp(PD[i][j-1].st, mp(i,j-1));
				}
			}
			PD[i][j] = ans;
		}
	}
	int i = sz(a)-1, j = sz(b)-1;
	string ans;
	while(i >= 0 && j >= 0){
		iii curr = PD[i][j];
		if(curr.nd.st == i-1 && curr.nd.nd == j-1){
			ans.pb(a[i]);
			j--; i--;
		} else {
			i = curr.nd.st;
			j = curr.nd.nd;
		}

	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {

	int N, vet[1123];	

	scanf("%d", &N);

	for (int i = 0;i < N;i++) {
		scanf("%d", vet + i);
	}
	int res=0;
	for (int i = 0;i < N;i++) {
		for (int j = i+1;j < N;j++) {
			res += vet[i]*vet[j];
		}
	}

	printf("%d\n", res);
	return 0;	
}

Measured memory_bytes: 256
import sys
n = int(sys.stdin.readline()[:-1])
S = [int(x) for x in (sys.stdin.readline()[:-1].split())]
q = int(sys.stdin.readline()[:-1])
T = [int(x) for x in (sys.stdin.readline()[:-1].split())]

count = 0
for t in T:
    l = 0
    h = n - 1
    while l <= h:
        half = (h + l) // 2
        if S[half] == t:
            count += 1
            break
        elif S[half] < t:
            l = half + 1
        else:
            h = half - 1

print(count)


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

int main()
{
    string N;
    cin >> N;
    long long cnt = 0;
    for (int i=0; i<N.size(); i++) cnt += (N[i] - '0');
    string ans;
    if (cnt%9==0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include <iostream>
 using namespace std;
#include <math.h>

int main() {

	int buf=0;
	int i=1;

	while(cin >> buf){
		if(buf==0){
			break;
		}

		cout << "Case " << i << ": " << buf <<endl;
		i++;
	}

  return 0;
}




Measured memory_bytes: 3068
class Node():
    def __init__(self):
        self.edge = []
        self.level = None
        self.par = None
        self.cap = 10**18

class Edge():
    def __init__(self, to, cap, rev=None):
        self.to = to
        self.cap = cap
        self.rev = rev

from collections import deque

class BipartiteMatching():
    def __init__(self, n, m):
        self.n = n
        self.m = m
        self.inf = 10**18
        self.source = Node()
        self.sink = Node()
        self.lt = [Node() for _ in range(n)]
        self.rt = [Node() for _ in range(m)]
        for i in range(n):
            edge = Edge(self.lt[i], 1)
            rev = Edge(self.source, 0)
            edge.rev, rev.rev = rev, edge
            self.source.edge.append(edge)
            self.lt[i].edge.append(rev)
        for i in range(m):
            edge = Edge(self.sink, 1)
            rev = Edge(self.rt[i], 0)
            edge.rev, rev.rev = rev, edge
            self.rt[i].edge.append(edge)
            self.sink.edge.append(rev)

    def add(self, x, y):
        lt = self.lt[x]
        rt = self.rt[y]
        edge = Edge(rt, 1)
        rev = Edge(lt, 0)
        edge.rev, rev.rev = rev, edge
        lt.edge.append(edge)
        rt.edge.append(rev)

    def maximum_matching(self):
        flow = 0
        while True:
            queue = deque([self.source])
            self.source.level = 0
            self.sink.level = None
            for i in range(self.n):
                self.lt[i].level = None
            for i in range(self.m):
                self.rt[i].level = None
            while queue:
                node = queue.popleft()
                for edge in node.edge:
                    to = edge.to
                    if edge.cap and to.level is None:
                        to.level = node.level + 1
                        queue.append(to)
            if self.sink.level is None: break
            stack = [self.source]
            self.source.par = None
            self.sink.par = None
            for i in range(self.n):
                self.lt[i].par = None
            for i in range(self.m):
                self.rt[i].par = None
            while stack:
                node = stack.pop()
                if node is self.sink:
                    break
                for edge in node.edge:
                    to = edge.to
                    if edge.cap and node.level < to.level:
                        to.par = edge.rev
                        #to.cap = min(edge.cap, node.cap)
                        stack.append(to)
            node = self.sink
            delta = node.cap
            while node is not self.source:
                node.par.cap = 1
                node.par.rev.cap = 0
                node = node.par.to
            flow += 1
        return flow

import sys
input = sys.stdin.readline

N, M, E = map(int, input().split())
bm = BipartiteMatching(N, M)
for _ in range(E):
    x, y = map(int, input().split())
    bm.add(x, y)
print(bm.maximum_matching())


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

int main() {
  int N;
  cin >> N;
  if((N/1000==N%1000/100 && N/1000==N%100/10) || (N%1000/100==N%100/10 && N%100/10==N%10)){
    cout << "Yes" << endl;
    return 0;
  }
  
 
    cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;

ll solve(ll a, ll b){

    ll tscore = a * b;

    cerr << tscore << endl;

    ll ok = 0;
    ll ng = tscore + 1;

    while(abs(ok - ng) > 1){

        ll tmp = (ok + ng) / 2;
        ll tmpscore;

        if(tmp % 2 == 1){
            if(tmp / 2 + 1 < INT_MAX){
                tmpscore = (tmp / 2 + 1) * (tmp / 2 + 1);
            }else{
                tmpscore = LLONG_MAX;
            }
        }else{
            if(tmp / 2 + 1 < INT_MAX){
                tmpscore = (tmp / 2 + 1) * (tmp / 2);
            }else{
                tmpscore = LLONG_MAX;
            }
        }

        if(tmpscore < tscore){
            ok = tmp;
        }else{
            ng = tmp;
        }
    }

    if(a == b) ok++;
    //cerr << a << " " << b << " " << ok << endl;
    
    if(a <= ok && b <= ok){

        ll amaria = ok - b + 1;
        ll amarib = ok - a + 1;
        
        if(amaria == a && amarib == b){
            ok = max(ok - 1, (ll)0);
        }else if(amaria * amarib < tscore){
            ok = max(ok - 1, (ll)0);
        }else{
            ok = max(ok - 2, (ll)0);
        }

    }else{
        ok = max(ok - 1, (ll)0);
    }

    return ok;

}

int main(){

    int q;
    cin >> q;

    rep(i,q){
        ll a,b;
        cin >> a >> b;

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

    }

    return 0;
}

Measured memory_bytes: 256
money = int(input())
ft = 0
f  = 0
#print (money)
while money >= 500:
  money = money - 500
  ft = ft + 1
#print (money)
#print (ft)
while money >= 5:
  money = money - 5
  f = f + 1
#print (money)
#print(f)
happy = ft * 1000 + f * 5
print (happy)

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 3010;
const int MOD = 1000000007;

int n, k;
int yue[MAXN], f[MAXN];

int power(int x, int y)
{
	int ret = 1;
	while (y) {
		if (y & 1) ret = 1ll * ret * x % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return ret;
}

int main()
{
	in(n); in(k);

	int sqr = sqrt(n);

	FOR(i, 1, sqr) {
		if (n % i == 0) {
			yue[++yue[0]] = i;
			if (i != n / i) yue[++yue[0]] = n / i;
		}
	}

	std::sort(yue + 1, yue + yue[0] + 1);

	LL ans = 0;
	
	FOR(i, 1, yue[0]) {
		f[i] = power(k, (yue[i] + 1) / 2);
		FOR(j, 1, i - 1) if (yue[i] % yue[j] == 0) f[i] = (f[i] - f[j] + MOD) % MOD;
		if (yue[i] % 2 == 0) ans = (ans + 1ll * f[i] * power(2, MOD - 2) % MOD * yue[i]) % MOD;
		else ans = (ans + 1ll * f[i] * yue[i]) % MOD;
	}

	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**6)
n = int(input())
adjacent_list = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
dist = [0 for i in range(n+1)]
def bfs(node,pre_node):
    que = deque([(node, pre_node)])
    while que:
        node, pre_node = que.popleft()
        for i in adjacent_list[node]:
            if i != pre_node:
                dist[i] = dist[node] + 1
                que.append([i,node])
bfs(1,0)
index = dist.index(max(dist))
dist = [0 for i in range(n+1)]
bfs(index,0)
l = max(dist)
#一回の操作というのは,木の直径を1or2減らすことになる
if l % 3 == 1:
    print("Second")
else:
    print("First")

Measured memory_bytes: 120780
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	q := getNextInt(scanner)
	lst := list.New()
	lst.PushBack(0)
	e := lst.Front()
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		switch t {
		case 0:
			x := getNextInt(scanner)
			lst.InsertBefore(x, e)
			e = e.Prev()
		case 1:
			d := getNextInt(scanner)
			if d < 0 {
				for j := 0; j < -d; j++ {
					e = e.Prev()
				}
				continue
			}
			for j := 0; j < d; j++ {
				e = e.Next()
			}
		case 2:
			erased := e.Next()
			lst.Remove(e)
			e = erased
		}
	}
	e = lst.Front()
	for i := 0; i < lst.Len()-1; i++ {
		fmt.Fprintln(writer, e.Value)
		e = e.Next()
	}
}



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

int main(){
	int N;
  	cin >> N;
  	for(int i = 0; i < 8;i++){
    	if(400 + 200 * i <= N && N <= 599 + 200 * i){
          	cout << 8-i << endl;
          	break;
        }
    }
}


Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

int main(void){
   
   int n;
   cin>>n;
   string s;
   cin>>s;

  if(n%2==1){
    cout<<"No"<<endl;
    return 0;
  }
   for(int i=0;i<n/2;i++){
     if(s[i] != s[n/2+i]){
       cout<<"No"<<endl;
       return 0;
     }
   }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 10
#define INF 1e9
typedef pair<int,string> P;
 
int N,bit;
string s[MAX_N];
string dp[1<<MAX_N][MAX_N];
vector<P> G[MAX_N];
 
void init(){
    bit = 0;
    for(int i = 0 ; i < (1<<N) ; i++){
	for(int j = 0 ; j < N ; j++){
	    dp[i][j] = "#";
	}
    }
}
 
string cat(const string &a,const string &b){
    int l1 = a.size(),l2 = b.size();
    for(int i = min(l1,l2) ; i >= 0 ; i--){
	string suba = a.substr(l1-i,i);
	string subb = b.substr(0,i);
	if(suba == subb){
	    return a + b.substr(i);
	}
    }
}
 
void overlap(int a,int b){
    string s1 = s[a], s2 = s[b];
    if(s2.find(s1) != string::npos &&
       s1.find(s2) == string::npos){
	bit |= (1<<a);
    }
    if(s1.find(s2) != string::npos &&
       s2.find(s1) == string::npos){
	bit |= (1<<b);
    }
}
 
string solve(int S,int v){
    if(S == (1<<N)-1){
	return s[v];
    }
    if(dp[S][v] != "#"){
	return dp[S][v];
    }
    string res = "#";
    for(int i = 0 ; i < N ; i++){
	if((S >> i) & 1) continue;
	string next = cat(s[v],solve(S|(1<<i),i));
	if(res == "#"){
	    res = next;
	}else{
	    if(next.size() < res.size()){
		res = next;
	    }else if(next.size() == res.size() && next < res){
		res = next;
	    }
	}
    }
    return dp[S][v] = res;
}
 
int main(){
    while(cin >> N, N > 0){
	init();
	for(int i = 0 ; i < N ; i++){
	    cin >> s[i];
	}
	if(N == 1){
	    cout << s[0] << endl;
	    continue;
	}
	for(int i = 0 ; i < N ; i++){
	    for(int j = 0 ; j < N ; j++){
		if(i == j) continue;
		overlap(i,j);
	    }
	}
	string res = "#";
	for(int i = 0 ; i < N ; i++){
	    if((bit >> i) & 1) continue;
	    string r = solve(bit|(1<<i),i);
	    if(res == "#"){
		res = r;
	    }else{
		if(r.size() < res.size()){
		    res = r;
		}else if(r.size() == res.size() && r < res){
		    res = r;
		}
	    }
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

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

signed main(){

  int H, W; cin >> H >> W;
  vector<string> a(H);
  queue<pair<int, int>> q;
  vector<vector<bool>> visited(H, vector<bool>(W, false));
  vector<vector<int>> dp(H, vector<int>(W, 0));
  for(int i = 0; i < H; i++){
    cin >> a[i];
    for(int j = 0; j < W; j++){
      if(a[i][j] == '#'){
        q.push({i, j});
      }
    }
  }

  while(!q.empty()){
    auto p = q.front(); q.pop();
    int y = p.first, x = p.second;
    if(visited[y][x]) continue;
    visited[y][x] = true;
    for(int i = 0; i < 4; i++){
      int ny = y + dy[i];
      int nx = x + dx[i];
      if(ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
      if(dp[ny][nx] == 0 && a[ny][nx] != '#') dp[ny][nx] = dp[y][x] + 1;
      q.push({ny, nx});
    }
  }

  int ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}


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

const int S = 100010;
int N, C;
int s[S], t[S], c[S];
int imos[2 * S], sum[2 * S];

int main() {
    scanf("%d%d", &N, &C);
    for(int i=0; i<N; i++) {
        scanf("%d%d%d", &s[i], &t[i], &c[i]);
    }

    for(int k=1; k<=C; k++) {
        memset(imos, 0, sizeof(imos));
        for(int i=0; i<N; i++) {
            if(c[i] != k) continue;
            imos[2*s[i] - 1]++; imos[2*t[i]]--;
        }
        for(int i=1; i<2*S; i++) {
            imos[i] += imos[i-1];
            if(imos[i]) sum[i]++;
        }
    }

    printf("%d\n", *max_element(sum, sum + 2*S));
    return 0;
}

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

int main() {
    long long N, K, ave, max, ans;
    cin >> N;
    vector<int>A(N);
    long long sum = 0;
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
        sum ^= A[i];
    }
    for (long long i = 0; i < N; i++) {
        cout << (sum ^ A[i]);
        if (i < N-1) {
            cout << ' ';
        }
    }
    cout << endl;
 
    
}



Measured memory_bytes: 4048
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
//		String s = sc.next();
		int i = 0;
		if(A%2 != B%2) {
			System.out.println("IMPOSSIBLE");
			return;
		}
		while(true) {

			if(Math.abs(A-i)==Math.abs(B-i))break;

			i++;
		}

		System.out.println(i);


	}

}


Measured memory_bytes: 23252
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int a[S.size()];
    for(int i=0;i<S.size();i++){
        a[i]=S[i]-'0';
    }
    ll ans=0;
    for(int bit=0;bit<(1<<(S.size()-1));bit++){
        ll tmp=a[0];
        ll sum=0;
        for(int i=0;i<(S.size()-1);i++){
            if(bit&(1<<i)){
                sum+=tmp;
                tmp=0;
            }
            tmp=10*tmp+a[i+1];
        }
        sum+=tmp;
        ans+=sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<vector>
#include<cctype>
#include<cstdio>
using namespace std;
inline int readint(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-'){
		f=1;
		c=getchar();
	}
	while(isdigit(c)){
		x=x*10+c-'0';
		c=getchar();
	}
	return f?-x:x;
}
const int m=1e6+5;
int n,c[m];
typedef long long ll;
const ll mod=998244353,inv2=499122177;
int mf[m];
vector<int> p;
ll mu[m],f[m];
int main(){
	#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	n=readint();
	while(n--) c[readint()]++;
	for(int i=2;i<m;i++){
		if(!mf[i]) p.push_back(i);
		for(int j=0;j<(int)p.size()&&1ll*i*p[j]<m;j++){
			mf[i*p[j]]=p[j];
			if(i%p[j]==0) break;
		}
	}
	mu[1]=1;
	for(int i=2;i<m;i++)
		if(!mf[i]) mu[i]=mod-1;
		else{
			if(i/mf[i]%mf[i]==0) mu[i]=0;
			else mu[i]=mu[mf[i]]*mu[i/mf[i]]%mod;
		}
	for(int i=1;i<m;i++) for(int j=1;i*j<m;j++)
		f[i*j]=(f[i*j]+i*mu[i]%mod)%mod;
	ll ans=0;
	for(int i=1;i<m;i++){
		ll res=0;
		for(int j=1;i*j<m;j++) res=(res+1ll*j*c[i*j]%mod)%mod;
		ans=(ans+i*res%mod*res%mod*f[i]%mod)%mod;
	}
	for(int i=1;i<m;i++) ans=(ans+mod-1ll*i*c[i]%mod)%mod;
	ans=ans*inv2%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 24056
package main

import (
    "fmt"
    "math"
)

func main() {
    var n, t1, t2 int
    var x1, y1, x2, y2 float64
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t2, &x2, &y2)
        dt := t2 - t1
        dist := math.Abs(x2-x1) + math.Abs(y2-y1)
        if dt < int(dist) || int(dist)%2 != dt%2 {
            fmt.Println("No")
            return
        }
        x1, y1, t1 = x2, y2, t2
    }
    fmt.Println("Yes")
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    ll int n;
    cin>>n;
    ll int a[n];
    rep(i,n)cin>>a[i];
    ll int ans =0;
    ll int cou=1;
    rep(i,n){
        if(cou!=a[i])ans++;
        else cou++;
    } 
    if(cou!=1)cout<<ans<<endl;
    else cout<<-1<<endl;
}

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

const int MAX_V = 10010;
int n, m;
vector<int> G[MAX_V];
int color[MAX_V];

bool dfs(int v, int c){
    color[v] = c;
    bool res = true;
    rep(i, 0, G[v].size()){
        if(color[G[v][i]] == c) res &= false;
        if(color[G[v][i]] == 0) res &= dfs(G[v][i], -c);
    }
    return res;
}

int main(){
    while(cin >> n >> m, n){
        rep(i, 0, MAX_V){
            G[i].clear();
            color[i] = 0;
        }
        rep(i, 0, m){
            int a, b;
            cin >> a >> b;
            a--; b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        bool f = true;
        rep(i, 0, n){
            if(color[i] == 0){
                f &= dfs(i, 1);
            }
        }
        if(f){
            set<int> st;
            int cnt[2] = {};
            rep(i, 0, n){
                if(color[i] == -1) cnt[0]++;
                else cnt[1]++;
            }
            if(cnt[0] % 2 == 0 && cnt[0] > 0){
                st.insert(cnt[0] / 2);
            }
            if(cnt[1] % 2 == 0 && cnt[1] > 0){
                st.insert(cnt[1] / 2);
            }
            
            cout << st.size() << endl;
            for(auto it = st.begin(); it != st.end(); it++){
                cout << *it << endl;
            }
        }else{
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3556
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

class Program
{
    static void Main(string[] args)
    {
        WriteLine(Hoge());
    }

    static int Hoge()
    {
        var sp = ReadLine().Split();
        int all = Parse(sp[0]);
        int k = Parse(sp[1]);
        sp = ReadLine().Split();
        List<int> minus = new List<int>(all), plus = new List<int>(all);
        for(int i = 0; i < sp.Length; ++i)
        {
            var n = Parse(sp[i]);
            if (n < 0) minus.Add(n * -1);
            else if (0 == n) --k;
            else plus.Add(n);
        }
        if (k == 0) return 0;
        minus.Reverse();
        int maxPlus = Math.Min(k, plus.Count);
        int minPlus = Math.Max(k - minus.Count, 0);
        int result = int.MaxValue;
        for(int pCount = minPlus; pCount <= maxPlus; ++pCount)
        {
            int tmp;
            if (0 == pCount)
            {
                tmp = minus[k - 1];
            }
            else if (k == pCount)
            {
                tmp = plus[k - 1];
            }
            else
            {
                int p = plus[pCount - 1];
                int m = minus[k - pCount - 1];
                tmp = Math.Min(p * 2 + m, p + m * 2);
            }
            result = Math.Min(tmp, result);
        }
        return result;
    }


//    static string ReadLine()
//    {
//        return _inputs[_inIndex++];
//    }

//    static string[] _inputs = @"8 5
//-9 -7 -4 -3 1 2 3 4".Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

//    static int _inIndex = 0;
}


Measured memory_bytes: 20704
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, ccnt;
	cin >> n >> ccnt;
	int d[ccnt][ccnt];
	for( int i = 0; i < ccnt; ++i ){
		for( int j = 0; j < ccnt; ++j ){
			cin >> d[i][j];
		}
	}
	int c[n][n];
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n; ++j ){
			cin >> c[i][j];
			c[i][j] -= 1;
		}
	}
	vector<int> p(ccnt, 0); // (2, 1)
	vector<int> q(ccnt, 0); // (2, 2)
	vector<int> r(ccnt, 0); // (1, 1)
	for( int k = 0; k < ccnt; ++k ){
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				int put = d[c[i][j]][k];
				int schalt = (i+j)%3;
				if( schalt == 0 ){
					p[k] += put;
				} else if( schalt == 1 ){
					q[k] += put;
				} else {
					r[k] += put;
				}
			}
		}
	}

	/*
	for( int i = 0; i < ccnt; ++i ) cout << p[i] << " ";
	cout << endl;
	for( int i = 0; i < ccnt; ++i ) cout << q[i] << " ";
	cout << endl;
	for( int i = 0; i < ccnt; ++i ) cout << r[i] << " ";
	cout << endl;
	*/
	
	int ans = INF;
	for( int i = 0; i < ccnt; ++i ){
		for( int j = 0; j < ccnt; ++j ){
			for( int k = 0; k < ccnt; ++k ){
				if( i == j || j == k || k == i ) continue;
				ans = min(ans, p[i]+q[j]+r[k]);
			}
		}
	}

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

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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
int H, W;
char a[1010][1010];
mint dp[1010][1010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> H >> W;
	rep(i, H)rep(j, W)cin >> a[i][j];
	rep(i, H) {
		rep(j, W) {
			if (i == 0 && j == 0) {
				dp[i][j] = 1;
			}
			if (i > 0)dp[i][j] += dp[i - 1][j];
			if (j > 0)dp[i][j] += dp[i][j - 1];
			if (a[i][j] == '#')dp[i][j] = 0;
		}
	}
	cout << dp[H - 1][W - 1].x << endl;
	return 0;
}

Measured memory_bytes: 12616
# https://atcoder.jp/contests/abc171/tasks/abc171_c

import string

def getOrdOfAlphabet(s):
    return ord(s) - 64


def getAlphabetByNum(n):
    alphabets = string.ascii_lowercase
    return alphabets[n - 1]



N = int(input())

dog_name = ''

while N > 0:
    
    N -= 1
    mod = N % 26
    dog_name += getAlphabetByNum(mod + 1)
    N //= 26



print(dog_name[::-1])



Measured memory_bytes: 9956
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll gcd(ll m, ll n){
  ll temp;
  while(m % n != 0){
    temp = n;
    n =	m %n;
    m =	temp;
  }
  return n;
}

ll lcm(ll m, ll n){
  return m * n / gcd(m,n);
}
int main()
{
  ll A,B,C,D;
  cin >> A >>B >>C >> D;
  ll lcmNum = lcm(C,D);
  //  cout <<"lcm " << lcmNum << endl;                                                                                           
  ll countC= 0;
  ll countD = 0;
  ll countLcm = 0;
  countC = B/C - (A%C ==0?A/C:A/C+1) +1;
  countD = B/D - (A%D ==0?A/D:A/D+1) +1;
  countLcm = B/lcmNum - (A%lcmNum ==0?A/lcmNum:A/lcmNum+1) +1;
  // for(int i = A; i <= B;i++){                                                                                                 

  //   if(i % C == 0) countC+=1;                                                                                                 
  //   if(i % D == 0) countD+=1;                                                                                                 
  //   if(i % lcmNum == 0) countLcm+=1;                                                                                          
  // }                                                                                                                           

  cout << B- A+1 - (countC+countD - countLcm) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main{
public  static void main(String[] args){
	String[] x = new String[10];
	int[] mountain=new int[10];
	try{
	InputStreamReader is =new InputStreamReader(System.in);
	BufferedReader br = new BufferedReader(is);
     	for(int i=0;i<10;i++)
	    x[i]=br.readLine();
	}catch(IOException e){
	    System.out.println(e.getMessage());

	}
	for(int i=0;i<10;i++)
	    mountain[i]=Integer.parseInt(x[i]);
	for(int i=0;i<10;i++)
	    for(int j=1;j<10;j++)
		if(mountain[j]<mountain[j-1]){
		    int t=mountain[j];
		    mountain[j]=mountain[j-1];
		    mountain[j-1]=t;
		}

	for(int i=9;i>6;i--)
	    System.out.println(mountain[i]);
    }
}

Measured memory_bytes: 16996
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B = map(int, readline().split())
    A -= 2
    B -= 2
    if A % 13 > B % 13:
        print('Alice')
    elif A % 13 < B % 13:
        print('Bob')
    else:
        print('Draw')


if __name__ == '__main__':
    main()


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


int main() {

	int N;
	string S;
	int counter_R = 0;
	int counter_B = 0;
	string R = "R";
	string B = "B";

	cin >> N;
	cin >> S;

	for (int i = 0; i < N; i++) {
		if (S[i] == R[0]) counter_R++;
		if (S[i] == B[0]) counter_B++;
	}

	if (counter_R > counter_B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;

}


Measured memory_bytes: 256
import bisect as b

n = int(input().strip())
l = list(map(lambda x: int(x.strip()), input().split()))

l.sort()
ans = 0

for i in range(n - 2):
    for j in range((i + 1), (n - 1)):
        k = b.bisect_left(l, (l[i] + l[j]))
        ans += k - (j + 1)

print(ans)


Measured memory_bytes: 43228
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
    long long int A, B, C, sum = 0;
    cin >> A >> B >> C;
    if ((A + B) >= C) { sum += (B+C); }
    if ((A + B) < C) { sum += (A + 2 * B + 1); }
    cout << sum << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [usize; n]);
    let mut aa = a.clone();
    aa.sort();
    let a_max = aa[n - 1];

    for v in a {
        println!("{}", if a_max == v { aa[n - 2] } else { a_max });
    }
}


Measured memory_bytes: 7212
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long


class BCollatzProblem {
public:
    void solve(std::istream &in, std::ostream &out) {
      vector<bool> a(1e6 + 1, false);
      int s;
      in >> s;
      a[s] = true;
      int now = s;
      int i = 1;
      while (true) {
        i++;
        if (now % 2 == 0) {
          if (a[now / 2]) break;
          else {
            a[now / 2] = true;
            now = now / 2;
          }
        } else {
          if (a[3 * now + 1]) break;
          else {
            a[3 * now + 1] = true;
            now = 3 * now + 1;
          }
        }
      }
      out << i << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BCollatzProblem solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 384
import fractions


def main():
    A, B, C, D = map(int, input().split())
    lcm = (C * D) // fractions.gcd(C, D)
    bc = B // C
    ac = A // C
    if A % C == 0:
        ac -= 1
    bd = B // D
    ad = A // D
    if A % D == 0:
        ad -= 1
    blcm = B // lcm
    alcm = A // lcm
    if A % lcm == 0:
        alcm -= 1
    print(B - A + 1 - ((bc - ac) + (bd - ad) - (blcm - alcm)))


main()


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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<string> a;
  vector<string> b;
  for (int k = 0; k < n; k++)
  {
    string s;
    cin >> s;
    a.push_back(s);
  }
  for (int k = 0; k < m; k++)
  {
    string s;
    cin >> s;
    b.push_back(s);
  }

  bool ans = false;
  for (int i = 0; i <= n - m; i++)
  {
    for (int j = 0; j <= n - m; j++)
    {
      int count = 0;
      for (int k = 0; k < m; k++)
      {
        if (b.at(k) == a.at(i + k).substr(j, m))
        {
          count++;
        }
      }
      if (count == m)
      {
        ans = true;
        break;
      }
    }
    if (ans)
    {
      break;
    }
  }
  ans ? cout << "Yes" << endl : cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;
int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;

    for (size_t i = 1; i <= n; i++)
    {
        int dig = 0;
        int sum = 0;
        int num = i;
        while(num){
            dig = num%10;
            sum += dig;
            num /= 10;
        }
        if(a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

A = [int(i) for i in input().split()]


from_ = 1
way = []
way.append(1)
way_set = set([1])

for i in range(K):
    s = A[from_ - 1]
    if(s in way_set):
        way.append(s)
        break
    else:
        way.append(s)
        way_set.add(s)
        from_ = s

key_from = way.index(way[len(way) - 1])
key_to = len(way) - 1



if(K > key_from):
    ans_loop = (K - key_from) % (key_to - key_from)
    ans_num = key_from + ans_loop

    print(way[ans_num])
else:
    print(way[K])

Measured memory_bytes: 32280
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,a[N],b[N],sum[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int pd(int mid)
{
	int y=0;
	for(int i=1;i<=n;i++)
	{
		int x=mid/b[n-i+1];
		if(x<a[i])y+=a[i]-x;
	}
	return y<=m;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
	int l=0,r=a[n]*b[n];
	while(l<r)
	{
		int mid=(l+r)/2;
		if(pd(mid))r=mid;
		else l=mid+1;
	}
	cout<<r;
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n - 1);
  for (int i = 0; i < n - 1; ++i)
  {
    cin >> B[i];
  }
  int sum = 0;
  A[n - 1] = A[n - 2] = B[n - 2];
  sum = A[n - 1] + A[n - 2];
  for (int i = n - 3; i >= 0; --i)
  {
    A[i] = B[i];
    sum += A[i];
    if (B[i] < A[i + 1])
    {
      sum -= A[i + 1];
      A[i + 1] = B[i];
      sum += A[i + 1];
    }
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))

a = [0 for i in range(n)]

if n == 2:
    print(b[0] * 2)
    exit()
else:
    a[-1] = b[-1]
    a[0] = b[0]
    for i in range(1, n-1):
        a[i] = min(b[i-1:i+1])
    print(sum(a))
    exit()


Measured memory_bytes: 3060
from itertools import accumulate
N, K = map(int, input().split())
MOD = 10**9 + 7
cum = list(accumulate([0]+ list(range(N+1))))
print((sum(cum[N+1] - cum[N+1-k] - cum[k] + 1 for k in range(K,N+2)))%MOD)

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,s.size()) {
    int count = 0;
    for(int j = i; j < s.size(); j++) {
      if(s.at(j) == 'A'|| s.at(j) == 'C' || s.at(j) == 'G' || s.at(j) == 'T') count++;
      else break;
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x, a[101];
    cin >> n >> x;
    llong sum_a = 0;
    rep(i, n) {
        cin >> a[i];
        sum_a += a[i];
    }
    if (sum_a == x) {
        cout << n << endl;
        return 0;
    }
    sort(a, a + n);

    int k = 0, tmp = 0;
    for (int i = 0; i < n; ++i) {
        if (tmp + a[i] <= x) tmp += a[i], ++k;
    }
    
    if (k == n) cout << n - 1 << endl;
    else cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
N,K =map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)

#X学期の評点
for i in range(K+1,N+1):
    iscore = a[i]
    jscore = a[i-1-K+1]
    if iscore > jscore:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 31624