akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

string str[] = {
    "dream"
    , "erase"
    , "dreamer"
    , "eraser"
};

string S;
int idx;

bool mycmp(int n){
    int L = str[n].length();
    bool ret = true;
    for(int i = 0; i < L; i++){
        if(S[idx+1-L+i] != str[n][i]) ret = false;
        //printf("%c, %c\n", S[idx+1-L+i], str[n][i]);
    }
    if(ret)
        idx -= L;
    return ret;
}

int main(){
    cin >> S;
    int N = S.length();
    idx = N-1;
    bool ans = true;
    while(idx > 0){
        if(S[idx] == 'r') {
            if(!mycmp(2)){
                if(!mycmp(3)){
                    ans = false;
                    break;
                }
            }
        }
        else if(S[idx] == 'e'){
            if(!mycmp(1)){
                ans = false;
                break;
            }
        }
        else if(S[idx] == 'm'){
            if(!mycmp(0)){
                ans = false;
                break;
            }
        }
        else{
            ans = false;
            break;
        }
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	ll n;
	cin >> n;

	ll x;
	cin >> x;
	--x;
	for (ll i = 1; i < n; i++) {
		ll y;
		cin >> y;
		if (x > y) {
			cout << "No" << endl;
			return 0;
		}
		if (x <= y - 1)
			x = y - 1;
		else
			x = y;
	}

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


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

int main()
{
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int N = S.length();
    int a[N];
    a[0] = int(S[0] - '0');
    int k = 10;
    rep(i,N-1){
      a[i+1] = (a[i] + int(S[i + 1] - '0') * k) % 2019;
      k = (k*10)%2019;
    }
    int ans = 0;
    int w[2019]={};
    rep(i,N){
      w[a[i]]++;
    }
    rep(i,2019){
      ans+=(w[i]*(w[i]-1))/2;
    }
    rep(i,N) if(a[i] == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4540
#include <stdio.h>

int main(void)
{
  int a,b;

	scanf("%d",&a);
	scanf("%d",&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 1932
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
  string S, T;
  int A, B;
  string U;
  cin >> S >> T >> A >> B >> U;
  if(S==U) cout << A-1 << " " << B << endl;
  else cout << A << " " << B-1 << endl;
}

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

int main() {
	int n;
	cin >> n;
	int a, b;
	cin >> a >>b;
	vector<int>rank(3,0);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x <= a)rank.at(0)++;
		else if (x <= b)rank.at(1)++;
		else rank.at(2)++;
	}
	sort(rank.begin(), rank.end());
	cout << rank.at(0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int N = 100 + 2;
const int W = 1e5 + 5;

int n, w, weight[N], value[N];
int64_t dp[N][W];

int main()
{
//    freopen("input.inp", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> w;
    for (int i = 1; i <= n; ++i)
        cin >> weight[i] >> value[i];
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= w; ++j)
        {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + weight[i + 1] <= w)
                dp[i + 1][j + weight[i + 1]] = max(dp[i + 1][j + weight[i + 1]], dp[i][j] + value[i + 1]);
        }
    int64_t ans = 0;
    for (int i = 0; i <= w; ++i)
        ans = max(ans, dp[n][i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 78464
#include <bits/stdc++.h>
using namespace std;
main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  bool tak = A > 0;
  bool aoki = C > 0;
  
  while (tak && aoki) {
    C -= B;
    if (C <= 0) {
    cout << "Yes" <<endl;
    break;
    }
    
    A -= D;
    if (A <= 0) {
    cout << "No" << endl;
    break;
    }
  }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int N=1000100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
char a[N],b[N];
int n,ans,sm,s[N],c;
int main(){
	int i,k;
	n=read();
	scanf("%s",a+1);
	scanf("%s",b+1);
	for(i=k=n;i;i--){
		sm+=s[i+c];
		if(k>i||b[i]!=a[k]){
			for(k--;k&&a[k]!=b[i];)k--;
			if(!k)goto fuck;
			if(k!=i)c++,sm++,s[i+c-1]=0,s[k-1+c]--;
		}ans=max(ans,sm);
	}printf("%d\n",ans);
	return 0;fuck:puts("-1");
}

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

using namespace std;

int main() {
  int n, nw, nx;
  cin >> n >> nw;
  
  int ct, mx = 0;
  for(int i = 0; i < n - 1; i++) {
    cin >> nx;
    if (nx <= nw) {
      ct++;
    } else {
      mx = max(mx, ct);
      ct = 0;
    }
    nw = nx;
  }
  
  mx = max(mx, ct);
  cout << mx << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl a(n);
    vl sum(n,0);
    rep(i,n){
        cin >> a[i];
        if(i==0) sum[i] = a[i];
        else sum[i] = a[i] + sum[i-1];
    }
    ll minus = 0;
    ll plus = 0;
    ll s = 0;
    rep(i,n){
        bool p = i % 2 == 1;
        bool q = sum[i] + s > 0;
        if(p!=q){
            if(sum[i] + s == 0){
                minus++;
                if(p) s++;
                else s--;
            }else{
                minus += abs(sum[i] + s) + 1;
                if(p) s += abs(sum[i] + s) + 1;
                else s -= abs(sum[i] + s) + 1;
            }
        }else{
            if(sum[i] + s == 0){
                minus++;
                if(p) s++;
                else s--;
            }
        }
    }
    s = 0;
    rep(i,n){
        bool p = i % 2 == 0;
        bool q = sum[i] + s > 0;
        if(p!=q){
            if(sum[i] + s == 0){
                plus++;
                if(p) s++;
                else s--;
            }else{
                plus += abs(sum[i] + s) + 1;
                if(p) s += abs(sum[i] + s) + 1;
                else s -= abs(sum[i] + s) + 1;
            }
        }else{
            if(sum[i] + s == 0){
                plus++;
                if(p) s++;
                else s--;
            }
        }
    }
    //cout << minus << plus << endl;
    cout << min(minus, plus) << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int64_t i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

using namespace std;

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

	int d, t, s; cin >> d >> t >> s;
	
	cout << (d<=t*s ? "Yes" : "No")   << endl;
	return 0;
}




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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

map<pair<int,int>, ll> memo;
ll combination(int n, int k){
  if(n-k<k) k=n-k;
  if(k==0) return 1;
  if(k==1) return n;
  ll& a=memo[make_pair(n-1,k)];
  if(a==0) a=combination(n-1,k);
  ll& b=memo[make_pair(n-1,k-1)];
  if(b==0) b=combination(n-1,k-1);
  return a+b;
}

int n,a,b;
ll v[51];
int main(){
  cin>>n>>a>>b;
  rep(i,n) cin>>v[i];
  sort(v,v+n,greater<ll>());
  long double avgMax=0;
  ll comb=0;
  for(int j=a;j<=b;j++){
    ll sm=0;
    rep(i,j) sm+=v[i];
    long double avg = static_cast<long double>(sm)/j;
    if(avg<avgMax) continue;
    if(avg>avgMax){
      avgMax=avg;
      comb=0;
    }
    int cnt=0,used=0;
    rep(i,n)
      if(v[i]==v[j-1]){
	cnt++;
	if(i<j)
	  used++;
      }
    comb+=combination(cnt,used);
  }
  cout<<fixed<<avgMax<<endl;
  cout<<comb<<endl;
}


Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al=lin()
	sl = [0]*n
	st=0
	for i in range(n):
		st += al[i]
		sl[i] = st
		
	full=sl[-1]
	min_v=mod*mod
	for v in sl[:-1]:
		t = abs(full - v*2)
		min_v=min(min_v, t)
	print(min_v)
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 101168
a,b,k = [int(i) for i in input().split()]
if a + k - 1 <= b:
    for i in range(a,a+k):
        print(i)
    if b-a+1>=2*k:
        for i in range(b-k+1,b+1):
            print(i)
    else:
        for i in range(a+k,b+1):
            print(i)
else:
    for i in range(a,b+1):
        print(i)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
		#include <bitset>
		using namespace std;
		#define ll long long 
		#define ld long double
		#define MOD 1000000007
		#define mod9 1000000009
		#define mod 1000003
		#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
		#define mp make_pair
		#define pb push_back
		#define ct ll t;cin>>t;while(t--)
		#define bi begin()
		#define ei end()
		#define fi first 
		#define se second   	
		bool isPrime(ll n) 
		{ 
			// Corner case 
			if (n <= 1) 
				return false; 
			
			// Check from 2 to n-1 
			for (ll i = 2; i*i <= n; i++) 
				if (n % i == 0) 
					return false; 
			
			return true; 
		}
		long long binpow(long long a, long long b) {
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = (res%mod) * (a%mod);
				a = (a%mod) * (a%mod);
				b >>= 1;
			}
			return res%mod;
		}

		bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
		{
			return (a.se<b.se);
		}
		ll lcm(ll a,ll b)
		{
			return(a*b)/__gcd(a,b);
		}
		// vector<ll>s;
		void SieveOfEratosthenes() 
		{  
			ll n=10005;
			bool prime[1000005]; 
			memset(prime, true, sizeof(prime)); 
			// s[0]=1;
			// s[1]=1;
			for (int p=2; p*p<=n; p++) 
			{ 
				
				if (prime[p] == true) 
				{   
					for (int i=p*p; i<=n; i += p) {
						prime[i] = false; 
						// s[i]=1;
						}
				} 
			} 
			for(ll i=2;i<10005;i++)
			{
				if(prime[i])
				{
					// s.pb(i);
				}
			}
		} 
		void eea(ll a, ll b, ll & x, ll & y) {
		if (a == 0) {
			x = 0;
			y = 1;
			return ;
		}
		ll x1, y1;
		eea(b % a, a, x1, y1);
		x = y1 - (b / a) * x1;
		y = x1;
		return ;
	}
	ll modinverse(ll a,ll m)
	{
		ll x, y;
		eea(a, m, x, y);
		if (__gcd(a,m) != 1) {
		return -1;
		}
	else {
		x = (x % m + m) % m;
		cout << x << endl;
		return x;
	}
	}
		ll fact[1000007]={0};
		ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
		y=y>>1;x=(1ll*x*x)%MOD;} return res;}
		void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
		ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
		ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
			
				
		int main()
		{
			fast
			ll n;
			cin>>n;
			ll a[n+1],b;
			memset(a,0,sizeof(a));
			for(ll i=0;i<n-1;i++)
			{
				cin>>b;
				a[b]++;
			}
			for(ll i=1;i<=n;i++)
			{
				cout<<a[i]<<"\n";
			}
			}

 

Measured memory_bytes: 5252
#include<iostream>
#include<vector>
#include<numeric>

using namespace std;

int main() {

	int r, c;
	vector<vector<int> > vt;

	vector<int> tmpv;

	int data;

	cin >> r >> c;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> data;
			tmpv.push_back(data);
		}
		vt.push_back(tmpv);
		tmpv.clear();
	}
	data = 0;

	vector<int> csum;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			data += vt[i][j];
		}
		csum.push_back(data);
		data = 0;
	}

	vector<int> rsum;

	for (int i = 0; i < c; i++) {
		for (int j = 0; j < r; j++) {
			data += vt[j][i];
		}
		rsum.push_back(data);
		data = 0;
	}


	/*for (int i = 0; i < c; i++) {
		cout << rsum[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < r; i++) {
		cout << csum[i] << " ";
	}*/

	int sum = accumulate(csum.begin(), csum.end(), 0) ;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cout << vt[i][j] << " " ;

		}
		cout << csum[i] << endl;
	}
	for (int i = 0; i < c; i++) {
		cout << rsum[i] << " ";
	}
	
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;using std::swap;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::vector<int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}

namespace ndifix{
template<class T> void sort(T &v){std::sort(v.begin(),v.end());}
template<class T> void rsort(T &v){std::sort(v.rbegin(),v.rend());}
std::vector<std::vector<long long>> combination_memo(2001,std::vector<long long>(2001,0));
long long combination(int n, int r){
  if(r==1)return n;
  if(r==0)return 1;
  if(n<r)return 0;
  //if(combination_memo.size()<n)combination_memo.resize(n+1);
  //if(combination_memo[n].size()<r)combination_memo[n].resize(r+1);
  if(r > n-r)return combination(n,n-r);
  if(combination_memo[n][r]>0)return combination_memo[n][r];
  combination_memo[n][r]=combination(n-1,r)+combination(n-1,r-1);
  combination_memo[n][r]=combination_memo[n][r]%mod;
  return combination_memo[n][r];
}//combination_memo is needed
}


int main(){
  int n,k;cin>>n>>k;
  LL ans1, ans2;

  for(int i=1;i<=k;i++){
    ans1=ndifix::combination(k-1,i-1);
    ans2=ndifix::combination(n-k+1,i);
    
    cout<<(ans1*ans2)%mod<<endl;
  }

  
  return 0;
}


Measured memory_bytes: 31744
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextInt();
        long b = scanner.nextInt();
        long k = (a + b) / 2;
        if (k * 2 == a + b) System.out.println(k);
        else System.out.println("IMPOSSIBLE");
    }
}


Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

class Solver {

    private final int H;
    private final int W;
    private final int[] A;

    Solver(Scanner in) {
        H = in.nextInt();
        W = in.nextInt();
        int N = in.nextInt();
        A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = in.nextInt();
        }
    }

    void solve() {
        String[] arr = new String[H * W];
        for (int i = 0, idx = 0; i < A.length; i++) {
            Arrays.fill(arr, idx, idx += A[i], String.valueOf(i + 1));
        }
        System.out.println(
                IntStream.iterate(0, i -> i + 1).limit(H)
                        .mapToObj(i -> i % 2 == 0 ? IntStream.iterate(W * i, j -> j + 1) : IntStream.iterate(W * i + W - 1, j -> j - 1))
                        .map(s -> s.limit(W))
                        .map(s -> s.mapToObj(j -> arr[j])
                                .collect(Collectors.joining(" "))
                        )
                        .collect(Collectors.joining("\n"))
        );
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 35244
#84c
import math

N = int(input())

#iの番号を合わせるのに、最初に不要だけど、値を入れておく。
C_list=[0]
S_list=[0]
F_list=[0]

for i in range(1,N):
    C,S,F = map(int, input().split())
    C_list.append(C)
    S_list.append(S)
    F_list.append(F)
    
#発車する時間は F*n + S

#指定した時間に到着したとき、次の駅への着時間を求める関数を拡張したら
#発駅と現在時刻からN駅への到着時間を求める再帰関数ができた。
def get_next_station_arrival_time(now_station_number,now_time):
    #終了条件
    if now_station_number == N:
        return now_time
    
    #継続時
    C = C_list[now_station_number]
    S = S_list[now_station_number]
    F = F_list[now_station_number]
    
    #次の発車時刻を求める … Fn+S >= now_time で最小となるnは?
    #ただし、始発前なら始発まで待機して出発
    if now_time <= S:
        return get_next_station_arrival_time(now_station_number + 1, S + C)
    else:
        n = math.ceil((now_time - S)/F) #←ここでミス。切り下げではなく上げる。
        return get_next_station_arrival_time(now_station_number + 1, F*n + S + C)
    

for i in range(1,N+1):
     print(get_next_station_arrival_time(i,0))
        
#切り下げと切り上げ、どちらを使うかをちゃんと確認しよう!

Measured memory_bytes: 3956
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    int n, m;

    while (cin >> n >> m && n) {
        vector<pair<int, P> > p(m);
        REP(i,m) {
            int t, s, d;
            scanf("%d %d %d", &t, &s, &d);
            p[i].first = t;
            p[i].second.first = s-1;
            p[i].second.second = d-1;
        }
        sort(p.begin(), p.end());

        VI d(n);
        d[0] = 1;
        REP(i,m){
            int s = p[i].second.first, t = p[i].second.second;
            if (d[s]) d[t] = 1;
        }

        int ans = 0;
        REP(i,n) ans += d[i];

        cout << ans << endl;
    }

    return 0;
}

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

typedef long long int lli;

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

    lli n;
    cin >> n;

    vector<lli> frequencies(100000);


    for(int i  = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            for(int k = 1; k <= n; k++)
            {
                lli t = i*i + j*j + k*k + i*j + j*k + k*i;
                if(t > n)
                {
                    break;
                }
                frequencies[t]++;
            }
        }

    }

    for(int i = 1; i <= n; i++)
    {
        cout << frequencies[i] << endl;
    }
}


Measured memory_bytes: 3884
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main(){
	map<char, int> m;
	m['I'] = 1;m['V'] = 5;m['X'] = 10;m['L'] = 50;
	m['C'] = 100;m['D'] = 500;m['M'] = 1000;
	string s;
	while(cin >> s){
		int i = 0, ans = 0;
		while(i < s.size()){
			char c = s[i];
			int t = 0;
			for(i;c == s[i] && i < s.size()-1;i++)t += m[c];
			if(m[c] < m[s[i]])ans -= t;
			else ans += t;
			if(i == s.size()-1)ans += m[s[i++]];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int N;
	sci(N);
	int arr[N];
	int ans = INT_MAX;
	for (int i = 0; i < N; ++i) sci(arr[i]);
	for (int i = 0; i < N; ++i) {
		int tot[2];
		tot[0] = tot[1] = 0;
		for (int j = 0; j <= i; ++j) {
			tot[0] += arr[j];
		}
		for (int j = i + 1; j < N; ++j) {
			tot[1] += arr[j];
		}
		ans = min(ans, abs(tot[0]-tot[1]));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
const pad = (s) => `000000${s}`.slice(-6)

const solve = (input) => {
  const [head, ...l] = input.split("\n")
  const mm = l.map((v, l) => {
    const [pref, year] = v.split(" ").map(Number)
    return {
      idx: l,
      pref,
      year
    }
  })
  let r = []
  let mm2 = mm.sort((a, b) => a.year - b.year)
  let prefIdx = []
  mm2.map(({ idx, pref, year }) => {
    if (prefIdx[pref] === undefined) {
      prefIdx[pref] = 1
    }
    r[idx] = `${pad(pref)}${pad(prefIdx[pref])}`
    prefIdx[pref]++
  })
  return r.join("\n")
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}


Measured memory_bytes: 81288
import sys
import itertools
import math
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

pattern = list(itertools.permutations(list(range(N))))

pall = 0
for pat in pattern:
    for i in range(N-1):
        currp = xy[pat[i]]
        nextp = xy[pat[i+1]]
        dist = math.sqrt(
            (currp[0] - nextp[0])**2
          + (currp[1] - nextp[1])**2
            )
        pall += dist

print(pall/(len(pattern)))
    


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


int main(){
    int n;
    cin >> n;
    vector<string> S(n);
    rep(i,n) cin >> S[i];
    sort(S.begin(),S.end());
    set<string> s(S.begin(),S.end());
    cout<<s.size()<<endl;
    return 0;

}

Measured memory_bytes: 25044
def LCS_iter(s1, s2):
	dp = [[-10000 for i in range(len(s2) + 1)] for i in range(len(s1) + 1)]
	ans = [['' for i in range(len(s2) + 1)] for i in range(len(s1) + 1)]
	for i in range(len(s2) + 1):
		dp[0][i] = 0
	for i in range(len(s1) + 1):
		dp[i][0] = 0
	i = 1
	j = 1
	while i <= len(s1):
		while j <= len(s2):
			if s1[i - 1] == s2[j - 1]:
				dp[i][j] = 1 + dp[i - 1][j - 1]
				ans[i][j] = 'cross'
			else:
				if dp[i - 1][j] > dp[i][j - 1]:
					dp[i][j] = dp[i - 1][j]
					ans[i][j] = 'up'
				else:
					dp[i][j] = dp[i][j - 1]
					ans[i][j] = 'left'
			j += 1
		i += 1
		j = 1
	i = len(s1)
	j = len(s2)
	s = ''
	while i >= 0 and j >= 0:
		if ans[i][j] == 'cross':
			s += s1[i - 1]
			i -= 1
			j -= 1
		elif ans[i][j] == 'up':
			i -= 1
		else:
			j -= 1
	return s[::-1]
 
 
s1 = input()
s2 = input()
 
print(LCS_iter(s1, s2))

Measured memory_bytes: 231984
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using ll = long long;
#define int ll
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template <typename T> void _dbarr(T* a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
template <typename T> void _dbarr(vector<T> a, size_t sz){ for(int i = 0; i < sz; i++) cerr << a[i] << " \n"[i == sz-1]; }
#define dbarr(x, n) {cerr << #x << ": "; _dbarr((x),(n));}
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 1e7+5;
int n;
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	//freopen("in.txt","r", stdin);
    cin >> n;
    vector<int> div(MM,1);
    for(int i = 2; i<= n; i++){
        for(int j = i; j <= n; j += i)
            div[j]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n;i++){
        ans += (i * div[i]);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 81344
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rnfor(i,a,b) for(ll (i) = (a) - 1; (i) >= (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main(){
    string s;
    cin >> s;
    rep0(i, s.size() - 1){
        if(s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }
    rep0(i, s.size() - 2){
        if(s[i] == s[i + 2]){
            cout << i + 1 << " " << i + 3 << endl;;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(void){
	double x[4],y[4];
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3];
		double z1=(double)(x[0]-x[1])/(y[0]-y[1]);
		double z2=(double)(x[2]-x[3])/(y[2]-y[3]);
		if(x[0]-x[1]==0 && x[2]-x[3]==0 || y[0]-y[1]==0 && y[2]-y[3]==0)printf("YES\n");
		else if(z1==z2)printf("YES\n");
		else printf("NO\n");
	}
    return 0;
}

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

int a[12][12];
int main() {
    string S;
    cin >> S;
    int N = S.size();
    
    rep(bit,1<<N-1){
      int res=S[0]-'0';
      rep(j,N-1){
        if(bit&1<<j)res-=S[j+1]-'0';
        else res+=S[j+1]-'0';
      }
      if(res==7){
        rep(j,N-1){
          cout<<S[j];
          if(bit&1<<j)cout<<"-";
          else cout<<"+";
        }
        cout<<S[3]<<"=7"<<endl;
        return 0;
      }
    }

}

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			var counts = new Dictionary<int, int>();
			for (int i = 0; i < n; i++) {
				int a = cin.Int();
				if (counts.ContainsKey(a) == false) {
					counts[a] = 1;
				} else {
					counts[a] += 1;
				}
			}

			if (counts.Count > 2) {
				Console.WriteLine("No");
				return;
			}

			if (counts.Count == 2) {
				var keys = counts.Keys.OrderBy(x => x).ToArray();
				int key1 = keys[0];
				int key2 = keys[1];
				if (key2 - key1 != 1) {
					Console.WriteLine("No");
					return;
				}

				if (counts[key1] <= key1 && (key2 - counts[key1]) <= counts[key2] / 2) {
					Console.WriteLine("Yes");
					return;
				} else {
					Console.WriteLine("No");
					return;
				}
			} else {
				int key = counts.Keys.First();
				if (key <= counts[key] / 2 || key == counts[key] - 1) {
					Console.WriteLine("Yes");
					return;
				} else {
					Console.WriteLine("No");
					return;
				}
			}
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

using namespace std;

int main() {
	vector<int> v(3);
	for (int i = 0; i < 3; ++i) cin >> v[i];
	sort( v.begin(), v.end() );
	for (int i = 0; i < 3; ++i) {
		if (i) cout << " ";
		cout << v[i];
	}
	cout << endl;
}

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

long long n, a, t = 0, m = 0;

int main() {
    cin >> n;
    
    for(long long i = 0; i < n; i++){
        cin >> a;
        
       if(t < a)
           t = a;
       else{
           m += t - a;
       }
    }
    
    cout << m << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<long long> S(N + 1, 0);
    int A;
    for (int i = 1; i <= N; i++) {
        cin >> A;
        S[i] = S[i - 1] + A;
    }

    long long ans = S[N];
    for (int i = 1; i <= N; i++) {
        long long left = S[i];
        long long right = S[N] - left;
        ans = min(ans, abs(left - right));
    }

    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")

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

const int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int dy[8] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1; 


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

  int n;
  cin >> n;
  vii a(2, vi(n));
  rep(i,2)rep(j,n) cin >> a[i][j];
  int ans = 0;
  rep(i,n){
    int tmp = 0;
    rep(j,n){
      if(i > j) tmp += a[0][j];
      if(i == j) tmp += a[0][j]+a[1][j];
      if(i < j) tmp += a[1][j];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}
	ll const mx=7;
	ll h,w,k;
	vector<vector<char>>ch(mx,vector<char>(mx));
	
	bool ok(ll a,ll b,vector<vector<char>>ch){
		ll count=0;
		for(ll i=0;i<h;i++){
			if(a&(1<<i)){
				for(int j=0;j<w;j++){
					ch[i][j]='R';
				}
			}
		}
		
		for(ll i=0;i<w;i++){
			if(b&(1<<i)){
				for(int j=0;j<h;j++){
					ch[j][i]='R';
				}
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(ch[i][j]=='#')
					count++;
				}
			}
		if(count==k)
			return 1;
		
		return 0;
		
		
	}

int main(){
	Speed_UP
	ll t;
	t=1;
	while(t--){
		cin>>h>>w>>k;
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin>>ch[i][j];
		ll ans=0;
		for(ll a=0;a<(1<<h);a++){
			for(ll b=0;b<(1<<w);b++){
				if(ok(a,b,ch))
					ans++;
			}
		}
		
		cout<<ans;
		
		
	}





}


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

const int K = 26;
int nxt[K][maxn];

int main()
{
    string s;
    string t;
    cin >> s >> t;
    int ns = s.length();
    int nt = t.length();
    for (int i = 0; i < 26; i++)
    {
        for (int j = 0; j < ns; j++)
        {
            nxt[i][j] = -1;
        }
    }
    for (int i = 0; i < 26; i++)
    {
        int start = 0;
        for (int j = 0; j < s.length(); j++)
        {
            if (s[j] - 'a' == i)
            {
                for (int k = start; k <= j; k++)
                {
                    nxt[i][k] = j;
                }
                start = j + 1;
            }
        }
    }
    long ans = 0;
    long c = 0;
    if (nxt[t[0] - 'a'][0] == -1)
    {
        cout << "-1" << endl;
        return 0;
    }
    else
    {
        ans = nxt[t[0] - 'a'][0] + 1;
        c = ans;
        if (c == ns)
        {
            c = 0;
        }
    }
    for (int i = 1; i < nt; i++)
    {
        int m = t[i] - 'a';
        if (nxt[m][0] == -1)
        {
            cout << "-1" << endl;
            return 0;
        }
        else if (nxt[m][c] >= 0)
        {
            ans += nxt[m][c] - (c - 1);
            c = nxt[m][c] + 1;
            if (c == ns)
            {
                c = 0;
            }
        }
        else
        {
            ans += ns - (c);
            ans += nxt[m][0] + 1;
            c = nxt[m][0] + 1;
            if (c == ns)
            {
                c = 0;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
    int n,k,q,i,t; cin >> n >> k >> q;
    vector<int> a(n,0);
    rep(i,q) cin >> t, a[t-1]++;
    rep(i,n) (k+a[i]-q > 0)? cout << "Yes" << endl:cout << "No" << endl;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N-i; j++) {
            if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y) {
                cout << i << " " << j << " " << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
int a[12][12];
const int INF = 1001001001;
int main(){	
	int n,m,x;
	cin >> n >> m >> x;
	vector<int> c(n);
	rep(i,n){
		cin >> c[i];
		rep(j,m) cin >> a[i][j];
	}
	int ans = INF;
	rep(s,1<<n){
		int cost=0;
		vector<int> d(m);
		rep(i,n){
			if(s>>i&1){
				cost += c[i];
				rep(j,m) d[j] += a[i][j];
			}
		}
		bool ok = true;
		rep(j,m) if(d[j] < x) ok = false;
		if(ok) ans = min(ans, cost);
	}
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
	return 0;

}




Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    string s;cin >>s;
    ll n;n=s.size();
    ll mid=n/2;
    if(n%2){
        char t=s[mid];
        ll lat=mid;
        ll ans=n/2+1;
        while(s[mid-1]==t&&s[lat+1]==t){
            mid--;lat++;
            ans++;
        }
        cout << ans <<endl;
    }
    else{
        mid--;
        char t=s[mid];
        ll lat=mid+1;
        ll ans=n/2;
        if(t!=s[lat])cout << ans <<endl,exit(0);
        else ans++;
        while(s[mid-1]==t&&s[lat+1]==t){
            mid--;lat++;
            ans++;
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 512
using System;

class Program
{
    static void Main(string[] args)
    {
        int h, w;

        while (true)
        {
            string[] num = Console.ReadLine().Split(' ');
            h = int.Parse(num[0]);
            w = int.Parse(num[1]);

            if (h == 0 && w == 0)
            {
                break;
            }

            for (int i = 1; i <= h; i++)
            {
                for (int j = 1; j <= w; j++)
                {
                    if (j == 1 || i == 1 || j == w || i == h)
                    {
                        Console.Write("#");
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }
                Console.WriteLine("");
            }
            Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll a, b; cin >> a >> b;

	ll res{INF};
	if (a <= b) res = min(res, b - a);
	if (-a <= b) res = min(res, b + a + 1);
	if (-a >= b) res = min(res, -a - b + 1);
	if (b <= a) res = min(res, 2 + a - b);
	std::cout << res << std::endl;
}

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

int main() {
    long long X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    long long n = min(K, X / D);
    K -= n;
    X -= n * D;
    if(K % 2 == 0) {
        cout << X;
    } else {
        cout << abs(D - X);
    }
}

Measured memory_bytes: 3608
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int main() {
	int n, y;
	cin >> n >> y;
	rep(i, n+1){
		rep(j, n-i+1){
			if((y-10000*i-5000*j) == 1000* (n - i -j)){
				cout << i << " " << j <<  " " <<n-i-j<< endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " <<  -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<stdlib.h>

using namespace std;


struct Node
{
	int key;
	Node *pre, *next;
};

Node *nil;

void init()
{
	nil = (Node*)malloc(sizeof(Node));
	nil->pre = nil;
	nil->next = nil;
}

void insert(int key)
{
	Node *x = (Node*)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->pre = x;
	nil->next = x;
	x->pre = nil;
}

Node *findlist(int key)
{
	Node *cur = nil->next;
	while (cur->key != key&&cur != nil)
	{
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *node)
{
	if (node == nil) return;
	node->next->pre = node->pre;
	node->pre->next = node->next;
	free(node);
}

void deletekey(int key)
{
	deleteNode(findlist(key));
}

void deletefirst()
{
	deleteNode(nil->next);
}

void deletelast()
{
	deleteNode(nil->pre);
}

void printNode()
{
	int sum = 0;
	while (nil->next != nil)
	{
		if (sum++ > 0)
			cout << ' ';
		cout << nil->next->key;
		deleteNode(nil->next);
	}
	cout << endl;
}

int main()
{
	int N, key;
	char A[100];
	cin >> N;
	init();
	for (int i = 0; i < N; i++)
	{
		scanf("%s", A);
		if (A[0] == 'i')
		{
			scanf("%d", &key);
			insert(key);
		}
		else if (A[0] == 'd')
		{
			if (A[6] == 'F')
			{
				deletefirst();
			}
			else if (A[6] == 'L')
			{
				deletelast();
			}
			else
			{
				scanf("%d", &key);
				deletekey(key);
			}
		}
	}
	printNode();
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    map<string, set<int>> color_density_set_map;
    for (size_t i = 0; i < N; i++) {
        string C;
        int D;
        cin >> C >> D;
        color_density_set_map[C].insert(D);
    }
    int M;
    cin >> M;
    int current_density = -1;
    for (size_t i = 0; i < M; i++) {
        string O;
        cin >> O;
        auto next_density_iterator = color_density_set_map[O].lower_bound(current_density + 1);
        if (next_density_iterator == color_density_set_map[O].end()) {
            cout << "No" << endl;
            return 0;
        }
        current_density = *next_density_iterator;
    }
    cout << "Yes" << endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

int main() {
  int n; cin >> n;
  long long a[n];
  long long ans1=0, ans2=0;
  long long sum;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sum = 0;
  for(int i = 0, s=1; i < n; ++i, s*=-1) {
    sum += a[i];
    if(sum * s <= 0) ans1 += abs(sum-s), sum=s;
  }
  sum = 0;
  for(int i = 0, s=-1; i < n; ++i, s*=-1) {
    sum += a[i];
    if(sum * s <= 0) ans2 += abs(sum-s), sum=s;
  }
  cout << min(ans1, ans2) << endl;

  return 0;
}


Measured memory_bytes: 1024