akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int main(){
	ll N;
	cin>>N;
	for(ll i=1;i<=3500;i++){
		for(ll j=1;j<=3500;j++){
			if(4*i*j-N*i-N*j<=0){
				continue;
			}
            if((N*i*j)%(4*i*j-N*i-N*j)==0){
              cout<<i<<" "<<j<<" "<<(N*i*j)/(4*i*j-N*i-N*j)<<endl;
              return 0;
            }
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  string s; cin >> s;
  int a,b,c;
  a=b=c=0;
  rep(i,s.size()){
    switch (s.at(i)) {
      case 'a' : a++; break;
      case 'b' : b++; break;
      case 'c' : c++; break;
    }
  }

  bool ok = true;
  if(abs(a-b)>1) ok = false;
  if(abs(b-c)>1) ok = false;
  if(abs(c-a)>1) ok = false;

  if(ok) puts("YES");
  else puts("NO");


}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

struct product {
  int v, w;
};

int main() {
  int n, w;
  cin >> n >> w;
  vector<product> p(n + 1);
  FOR(i, 1, n + 1) cin >> p[i].v >> p[i].w;

  int dp[n + 1][w + 1];
  rep(i, n + 1) {
    rep(j, w + 1) {
      dp[i][j] = 0;
    }
  }

  FOR(i, 1, n + 1) {
    rep(j, w + 1) {
      if (j >= p[i].w) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p[i].w] + p[i].v);
      else dp[i][j] = dp[i - 1][j];
    }
  }

  cout << dp[n][w] << endl;

  
  return 0;
}


Measured memory_bytes: 6976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  
  if(N == 1){
    cout << "Hello World" << endl;
  }
  
  if(N == 2){
    int A,B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}


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

int main() {
	int A,B,C,D;
	cin>>A>>B>>C>>D;
	int turn=0;
	while(1)
	{
	    if(turn==0)
	    {
	        C = C-B;
	        if(C<=0)
	        {
	            cout<<"Yes"<<endl;
	            break;
	        }
	    }
	    else
	    {
	        A = A-D;
	        if(A<=0)
	        {
	            cout<<"No"<<endl;
	            break;
	        }
	    }
	    turn=(turn+1)%2;
	}
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl cout<<endl
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
ll n,m,a,b,c,k,x,y,z,ans=0,total=0;
ll arr[2000]={0};
string s;
bool check(ll x){
	int temp=x%10;
	while(x>0){
		if(temp!=x%10)return false;
		x/=10;
	}
	return true;
}
int main(void){   
	cin>>n;
	for(ll i=n;i<=999;i++){
		if(check(i)){
			pf("%d\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Array

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

calc :: [Int] -> Array Int Int -> Int -> Int -> Int
calc [] as' i k = k
calc (a : as) as' i k
  | a < i = calc as as' (i + 1) k
  | a > i && as' ! a == i = calc as as' (i + 1) (k + 1)
  | otherwise = calc as as' (i + 1) k

main = do
  n <- getInt
  as <- getIntList
  let as' = listArray (1, length as) as
  print $ calc as as' 1 0


Measured memory_bytes: 17088
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl f;  // f[v] : vを親とする部分木の塗り方の数
vl g;  // g[v] : vを親とする部分木をvを白で塗った時の塗り方の数

void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
        f[v] *= g[u];  
        g[v] *= f[u];
        f[v] %= mod;   
        g[v] %= mod;
    }
    f[v] += g[v];
    f[v] %= mod;
}

int main() {
    ll n;
    cin >> n;    

    G.resize(n);
    rep(i, n-1) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        G[x].pb(y);
        G[y].pb(x);
    }

    f.assign(n, 1);
    g.assign(n, 1);
    dfs(0);

    out(f[0]);
    re0;
}

Measured memory_bytes: 14208
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N % 2 == 1) {
      System.out.println((double)((N - 1)/2 + 1)/N);
    } else {
      System.out.println(0.5);
    }
  }
}

Measured memory_bytes: 20948
N = int(input())
A = [0] * 2
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))

ans = 0
for i in range(N):
    now = 0
    for j in range(N):
        if j < i:
            now += A[0][j]
        elif j > i:
            now += A[1][j]
        else:
            now += A[0][j] + A[1][j]
    ans = max(ans, now)
print(ans)

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

int main() {

    vector<int> X(4);
    vector<int> Y(4);

    REP(i, 4) {
        cin >> X[i];
    }

    int a,b,res,cnt;

    REP(i, 4) {
        Y[i] = X[3] / X[i];
    }

    vector<int> tes(3000*3000);

    for (int j = 0; j <= Y[0]; j++){
        if(X[3]< X[0]*j)break;
        for(int k = 0; k <= Y[1]; k++){
            if(X[3]< X[0]*j + X[1]*k  )break;
            tes[cnt] = X[0]*j + X[1]*k;
            cnt++;
        }
    }

    for(int m = 0; m < cnt; m++){
        b = X[3] - tes[m];
        //ここはあまりを求めるだけよい
        if(b % X[2] == 0)res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 35456
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    D=list(mi())

    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += D[i]*D[j]

    print(ans)




if __name__ == "__main__":
    main()

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;



int main() {

    ll K;
    cin >> K;
    vector<ll>  a;
    ll count = 0;
    REP1(i, 10){
        a.push_back(i);
    }
    if(K < 10){
        cout << K << endl;
        return 0;
    }
    while(1){
        vector<ll>old;
        swap(old, a);
        for(ll x: old){
            for(int i = -1; i <= 1; i++){
                int d = x % 10 + i;
                if(d < 0 || d > 9)continue;
                ll nx = x * 10 + d;
                a.push_back(nx);
                // cout << nx << endl;
                count++;

                if(count == (K-9) ){
                    cout << nx << endl;
                    return 0;
                }
            }
        }

    }




    return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

int main() {
    int n; cin >> n;            // 8
    vector<int> a(n); 
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;           // 7 1 6 2 3 4 5 0
    vector<int> idx(n);
    rep(i, n) idx[a[i]] = i;    // 7 1 3 4 5 6 2 0  (a[i]のidx)
    set<int> s;                 // ascending order
    ll ans = 0;
    // 大きい順でみていく
    for (int x=n-1; x >=0; --x) {
        int i = idx[x];
        ll c = 0;
        {   // calc c
            s.insert(i);
            vector<int> l(2, -1), r(2, n);  // x, w, y, z
            {   // calc l
                auto it = s.find(i);
                rep(j, 2) {
                    if (it == s.begin()) break;
                    --it;
                    l[j] = *it;
                }
            }
            {   // calc r
                auto it = s.find(i);
                rep(j, 2) {
                    ++it;
                    if (it == s.end()) break;
                    r[j] = *it;
                }
            }
            vector<int> ls(2);
            ls[0] = i-l[0]; ls[1] = l[0]-l[1];
            vector<int> rs(2);
            rs[0] = r[0]-i; rs[1] = r[1]-r[0];
            c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
        }
        ans += c*(x+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

const int N = 1e4 + 10;

int a[N];

int main() {
	int n;
	cin >> n;
	
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			for (int k = 1; k <= n; ++k) {
				int t = i * i + j * j + k * k + i * j + j * k + k * i;
				if (t <= n) a[t]++;
				else break;
			}
		}
	}
	
	for (int i = 1; i <= n; ++i) cout << a[i] << '\n';
	
	return 0;
}

Measured memory_bytes: 3552
class Mod13DPTable:
    MOD = 10**9 + 7
    def __init__(self, length):
        self.mod13 = [{j:0 for j in range(13)} for i in range(length)]
        self.MOD = 10**7 + 7
    def set_start(self, units_digit):
        if units_digit == '?':
            for i in range(10):
                self.mod13[0][i] = 1
        else:
            self.mod13[0][int(units_digit)] = 1
    def get_table(self, digit):
        return self.mod13[digit]
    def update(self, num, digit, multi):  # multi = 10**digit % 13
        for k, v in self.mod13[digit-1].items():
            remain = ((num * multi) + k) % 13
            self.mod13[digit][remain] = (self.mod13[digit][remain] + v) % Mod13DPTable.MOD
            
def main():
    MOD = 10**9 + 7
    S = input()
    mod13dp = Mod13DPTable(len(S))
    mod13dp.set_start(S[-1])
    multi = 10
    for i, m in enumerate(reversed(list(S[:-1]))):
        i += 1
        if m == '?':
            for j in range(10):
                mod13dp.update(j, i, multi)
        else:
            mod13dp.update(int(m), i, multi)
        multi = multi*10 % 13
    print(mod13dp.get_table(-1)[5])
main()

Measured memory_bytes: 134024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

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

int main() {
	int a, b;
	cin >> a >> b;
	
	if (a >= 10 || b >= 10) {
		cout << -1 << endl;
	} else {
		cout << a*b << endl;
	}	
}


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

using namespace std;

long long M = 1000000000 + 7;

long long factm(long long x) {
  long long result = 1;
  for (long long i = 1; i <= x; i++) {
    result = result * i % M;
  }
  return result;
}

long long powm(long long x, long long p) {
  if (p == 0) return 1;
  long long tmp = x * x % M;
  if (p % 2 == 0) {
    return powm(tmp, p/2);
  } else {
    return x * powm(tmp, (p-1)/2) % M; 
  }
}

long long invfactmc[2001] = {};

long long invfactm(long long x) {
  long long result = 1;
  if (invfactmc[x] != 0) return invfactmc[x];
  for (long long i = 1; i <= x; i++) {
    result = result * powm(i, M-2) % M;
  }
  return invfactmc[x] = result;
}

long long com(long long n, long long k) {
  if (n < k) return 0;
  if (k < 0) return 0;
  return (factm(n)*invfactm(k) % M) * invfactm(n-k) % M;
}


int main() {
  long long N, K;
  cin >> N >> K;
  for (long long i = 1; i <= K; i++) {
    long long result = com(N-K+1, i)*com(K-1, i-1) % M;
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(void){char buf1;int n,c[53]={0},i,buf2;scanf("%d",&n);for(i=0;i<n;++i){scanf("%c",&buf1);scanf("%c %d",&buf1,&buf2);++c[((buf1=='S')?0:((buf1=='H')?13:((buf1=='C')?26:39)))+buf2];}for(i=1;i<=52;++i){if(!c[i]){printf("%c %d\n",(((i-1)/13)==0)?'S':(((i-1)/13)==1)?'H':(((i-1)/13)==2)?'C':'D', ((i-1)%13)+1);}}return(0);}


Measured memory_bytes: 2760
#include <iostream>

using namespace std;

void solve()
{
	int a[4];
	int b[4];
	while(cin >> a[0] >> a[1] >> a[2] >> a[3])
	{
		cin >> b[0] >> b[1] >> b[2] >> b[3];
		int Hit = 0;
		int Blow = 0;
		for(int i = 0; i < 4; ++i)
		{
			for(int j = 0; j < 4; ++j)
			{
				if(a[i] == b[j])
				{
					if(i == j)
					{
						++Hit;
					}
					else
					{
						++Blow;
					}
				}
			}
		}
		cout << Hit << " " << Blow << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

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

  ll ans = 0;
  rep(i,n){
    ans += a[i]-1;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll a[2002];
ll dp[2002][2];//dp[i][j] := 山札からi枚取った場合j=0 先手 j=1後手の番

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,Z,W;
    cin >> n >> Z >> W;
    rep(i,n)cin >> a[i];

    for(int i=n-1;i>=0;i--){
        // 先手番
        dp[i][0] = -INF;
        ll Y = (i?a[i-1]:W);
        chmax(dp[i][0],abs(Y-a[n-1]));
        for(int j=i+1;j<n;j++)chmax(dp[i][0],dp[j][1]);

        dp[i][1] = INF;
        ll X = (i?a[i-1]:Z);
        chmin(dp[i][1],abs(X-a[n-1]));
        for(int j=i+1;j<n;j++)chmin(dp[i][1],dp[j][0]);
    }
    cout << dp[0][0] << endl;
}

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

using namespace std;

int main()
{
	for(int w,q;scanf("%d%d",&w,&q),w|q;){
		vector<int> wall(w,-1);
		for(int i=0;i<q;i++){
			char kind; scanf(" %c",&kind);
			if(kind=='s'){
				int id,width; scanf("%d%d",&id,&width);
				int pos=-1;
				for(int j=0;j<w;j++)
					if(count(wall.begin()+j,wall.begin()+j+width,-1)==width){
						fill(wall.begin()+j,wall.begin()+j+width,id);
						pos=j;
						break;
					}
				if(pos==-1)
					puts("impossible");
				else
					printf("%d\n",pos);
			}
			else{
				int id; scanf("%d",&id);
				replace(wall.begin(),wall.end(),id,-1);
			}
		}
		puts("END");
	}
	
	return 0;
}

Measured memory_bytes: 1044
package main

import (
	"bufio"
	"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) {
	n := getNextInt(scanner)
	eras := make([]int, n+1)
	for i := 2; i < n+1; i++ {
		if eras[i] != 0 {
			continue
		}
		for j := i; j < n+1; j += i {
			if eras[j] == 0 {
				eras[j] = i
			}
		}
	}
	var ans int = 1
	for i := 2; i < n; i++ {
		x := i
		m := map[int]int{}
		for x > 1 {
			m[eras[x]]++
			x /= eras[x]
		}
		y := 1
		for _, c := range m {
			y *= c + 1
		}
		ans += y
	}
	fmt.Fprintln(writer, ans)
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int k,n; scanf("%d%d",&k,&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int mx=*max_element(a.begin(),a.end());
	printf("%d\n",max(mx-1-(k-mx),0));

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int main(){
  char takahashi[4];
	int result = 0;
	cin >> takahashi[0] >> takahashi[1] >> takahashi[2] >> takahashi[3];
	for(int i=0;i<4;i++){
		if(takahashi[i]=='-') result--;
		else result++;
	}
	cout << result << endl;
  return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<bits/stdc++.h>
using namespace std; 
 
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n, d;
    cin>>n;
    int a[n], b[n];
    
    for(int i=0; i<n; i++)
    {
    	cin>>a[i];
    	b[i]=a[i];
	}
	sort(b, b+n);
	for(int i=0; i<n; i++)
	{
		if(a[i]==b[n-1])cout<<b[n-2]<<endl;
		else cout<<b[n-1]<<endl;
	}
    
    return 0;
}

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() { 
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    int dame[n] = {0};

    int a, b;
    for(int i = 0; i < m; ++i) {
        cin >> a >> b;
        a--, b--;
        uf.merge(a, b);
        dame[a]++, dame[b]++;
    }

    int c, d;
    for(int i = 0; i < k; ++i) {
        cin >> c >> d;
        c--, d--;
        if(uf.issame(c, d)) {
            dame[c]++, dame[d]++;
        }
    }

    for(int i = 0; i < n; ++i) {
        cout << uf.size(i) - dame[i] - 1 << " ";
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize(3)
#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>
#define MAXN 305
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,k,a[MAXN];
int dp[MAXN][2*MAXN*MAXN];
int dp2[MAXN][MAXN*MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
int main()
{
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++) 
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    dp[0][300*300]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=2*300*300;j++)
        {
            if(!dp[i][j]) continue;
            add(dp[i+1][j-a[i]],dp[i][j]);
            add(dp[i+1][j+a[i]],2LL*dp[i][j]%MOD);
        }
    }
    dp2[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=300*300;j++)
        {
            if(!dp2[i][j]) continue;
            add(dp2[i+1][j],dp2[i][j]);
            add(dp2[i+1][j+a[i]],dp2[i][j]);
        }
    }
    int ans=pow_mod(3,n);
    for(int j=0;j<=300*300;j++) dec(ans,3LL*dp[n][j]%MOD);
    if(sum%2==0) add(ans,3LL*dp2[n][sum/2]%MOD);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 327936
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
int dp[1001][6][7];
string s;
int k1;
 
int solve(int pos,int f,int num)
{
 
    
    if(pos==s.size())
    {
        
        if(num==k1)
            return 1;
        return 0;
    }
  
   int &res=dp[pos][f][num];
   if(res!=-1)
    return res;
    res=0;
    int fin;
    if(f==0)
    {
        fin=s[pos]-'0';
    }
    else
        fin=9;
   // cout<<fin<<endl;

    for(int x=0;x<=fin;++x)
    {
        int k=f;
        if(f==0 and x<fin)
            k=1;
        if(x==0)
        {
            res+=solve(pos+1,k,num);
        }
        else
        {
            res+=solve(pos+1,k,min(num+1,(ll)4));
        }
        
    }
 
    return res;
}


int32_t main()
{
    IOS
     
   
    

    cin>>s>>k1;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0,0);
    
 
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

string s;
int k;

int main() {
    cin >> s >> k;
    int n = s.size();
    vector<int> c(n);
    REP(i,n){
        c[i] = (int)(char)'z'-s[i]+1;
    }
    REP(i,n){
        if(c[i] <= k && c[i]!=26){
            k -= c[i];
            c[i] = 26;
        }
    }
    c[n-1] -= k;
    c[n-1] %= 26;
    if(c[n-1]<=0){
        c[n-1] += 26;
    }
    REP(i,n){
        cout << (char)(int)((int)(char)'z'-c[i]+1);
    }
    return 0;
}


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

#define ll long long

using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    bool ans = false;
    if(a == b + c || b == a + c || c == a + b){
        ans = true;
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}        


Measured memory_bytes: 256
#ABC044D
def fun(b,n):
    if b<2:return -1
    if n<b:return n
    return (n%b)+fun(b,n//b)
n=int(input())
s=int(input())
n_root=n**0.5

def main(n,n_root,s):
    if s==n:return n+1
    if s>n:return -1
    for b in range(2,1+int(n_root)):
        if fun(b,n)==s:
            return b
    for i in range(int(n_root),0,-1):
        b=1+(n-s)//i
        if fun(b,n)==s:
            if b>1:return b
    return -1
print(main(n,n_root,s))


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

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  
  int a = W-(x+r);
  int b = H-(y+r);
  int c = x-r;
  int d = y-r;
  
  if((a>=0) && (b>=0) && (c>=0) && (d>=0)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3116
#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int

#define pb push_back
#define m <i> map<int>
#define v <i> vector<int>

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

#define rep(i, n) for(int i=0; i<n; i++)

int main()
{
  IOS;
  int n, x, t;
  cin >> n >> x >> t;
  int q=0;
  for (int i=0; i<t; i++)
    {
      q++;
      n=n-x;
      if (n<=0)
	break;
    }
  cout << q*t << endl;
  return 0;
}


Measured memory_bytes: 3648
n = int(input())
t = [0]*(n+1)
x = [0]*(n+1)
y = [0]*(n+1)
for i in range(1, n+1):
    t[i], x[i], y[i] = map(int, input().split())

ok = True

for i in range(n):
    delta_t = t[i+1] - t[i]
    delta_x = x[i+1] - x[i]
    delta_y = y[i+1] - y[i]
    if delta_t < delta_x + delta_y:
        ok = False
    else:
        if abs(delta_x + delta_y - delta_t)%2 != 0:
            ok = False

if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11636
using System;
using System.Linq;

namespace AFerrisWheel
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = inputs[0];
            var b = inputs[1];

            var price = GetPrice(a, b);

            // 解答の出力
            Console.WriteLine(price);
        }

        // 観覧車の年齢別料金の取得
        static int GetPrice(int age, int basePrice)
        {
            if (age >= 13)
            {
                return basePrice;
            }
            else if (age >= 6)
            {
                return basePrice / 2;
            }
            else
            {
                return 0;
            }
        }
    }
}


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

int main () {
    string S;
    cin >> S;

    int N = S.size();
    for (int i=N; i>0; i--) {
        string str;
        str = S.substr(i-5, 5);

        reverse(str.begin(), str.end());
        if (str == "maerd" || str == "esare") { i -= 4; }
        else if (str == "resar" && S.substr(i-6, 1) == "e" && i-6>=0) { i -= 5; }
        else if (str == "remae" && S.substr(i-7, 2) == "dr" && i-7>=0) { i -= 6; }
        else {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

vector<vector <int>> graph;
vector<int> d_fennec, d_snuke;

// k -> start, p -> prev node, n -> goal node
// d -> distance, flag -> 0(fennec), 1(snuke)
void search_path(int k, int p, int n, int d, int flag)
{
    if(flag == 0){
        d_fennec[k] = d;
    }
    else if(flag == 1){
        d_snuke[k] = d;
    }
    
    for(auto itr=graph[k].begin(); itr != graph[k].end(); ++itr){
        if(*itr != p){
            search_path(*itr, k, n, d+1, flag);
        }
    }
    return;
}

int main()
{
    int n, a, b, get_fennec, get_snuke;
    get_fennec = 0;
    get_snuke = 0;
    vector<int> path_t;
    string answer;
    cin >> n;
    graph.resize(n+1);
    d_fennec.resize(n+1);
    d_snuke.resize(n+1);
    for(int i=0; i<n; ++i){
        if(i != n-1){
            cin >> a >> b;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
        d_fennec[i] = 100000;
        d_snuke[i] = 100000;
    }
    // search fennec -> snuke path
    search_path(1, 0, n, 0, 0);
    // search snuke -> fennec path
    search_path(n, 0, 1, 0, 1);
    // check distance
    for(int i=1; i<=n; ++i){
        if(d_fennec[i] <= d_snuke[i]){
            get_fennec++;
        }
        else {
            get_snuke++;
        }
        // cout << i << " @ df: " << d_fennec[i] << " * ds: " << d_snuke[i] << endl;
        // cout << "point (fennec, snuke) -> (" << get_fennec << ", " << get_snuke << ")" << endl;
    }
    if(get_fennec > get_snuke){
        answer = "Fennec";
    }
    else {
        answer = "Snuke";
    }
    cout << answer << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) (v.begin(), v.end())
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int f(ll a, ll b) {
    string x = to_string(a);
    string y = to_string(b);
    return max(x.size(), y.size());
}

int main() {
    ll n;
    cin >> n;

    int ans = 1e9;
    for (ll a = 1; a * a <= n; a++) {
        if (n % a == 0) {
            ll b = n / a;
            ans = min(ans, f(a, b));
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll i, N, a[200001], sum[200001]={0};
    cin >> N;
    for(i=1; i<=N; i++) {
        cin >> a[i];
        sum[i]=sum[i-1]+a[i];
    }
    ll l=1, r=1, tmp=0, ans=0;
    for(l=1; l<=N; l++) {
        
        while(r<=N && (tmp^a[r])==sum[r]-sum[l-1]) {
            tmp^=a[r];
            r++;
        }
        ans+=r-l;
        if(l==r) r++;
        else tmp^=a[l];
    }
    
    prin(ans)
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int X;
    cin >> X;
    int hap = 0;
    while (X >= 500)
    {
        hap = hap + 1000;
        X = X - 500;
    }
    while (X >= 5)
    {
        hap = hap + 5;
        X = X - 5;
    }
    cout << hap << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  
  int a,b,i;
  for(i=1;i<=10000;i++){
    scanf("%d%d",&a,&b);
    if(a==0&&b==0) break;
   
    if(a<b){
      printf("%d %d\n",a,b);
    }else if(a==b){
      printf("%d %d\n",a,b);
    }else printf("%d %d\n",b,a);
    
  }
  return 0;
}

Measured memory_bytes: 1028
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// NextPermutation generates the next permutation of the
// sortable collection x in lexical order.  It returns false
// if the permutations are exhausted.
//
// Knuth, Donald (2011), "Section 7.2.1.2: Generating All Permutations",
// The Art of Computer Programming, volume 4A.
// ※NextPermutationは辞書順で次を返す
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	x := make([]float64, N)
	y := make([]float64, N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		x[i], y[i] = float64(getInt()), float64(getInt())
		a[i] = i
	}

	ans := 0.0
	cnt := 0.0
	for {
		sum := 0.0
		px, py := x[a[0]], y[a[0]]
		for _, v := range a {
			dx := x[v] - px
			dy := y[v] - py
			sum += math.Sqrt(dx*dx + dy*dy)
			px, py = x[v], y[v]
		}
		cnt++
		ans += sum
		if !NextPermutation(sort.IntSlice(a)) {
			break
		}
	}

	out(ans / cnt)
}


Measured memory_bytes: 1920
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mp make_pair
 
using namespace std;
 
inline char nc(){
	/*
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
  	*/return getchar();
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline int read(char *s)
{
	char c=nc();int len=1;
	for(;!(c>='a' && c<='z');c=nc()) if (c==EOF) return 0;
	for(;(c>='a' && c<='z');s[len++]=c,c=nc());
	s[len++]='\0';
	return len;
}

inline void read(char &x){
  for (x=nc();!(x>='A' && x<='Z');x=nc());
}

int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {
	for (wt=0;x;ss[++wt]=x%10,x/=10);
	for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,m;
char s[110],t[110],p[210];

bool check(int x)
{
	for (int i=1;i<=n;i++)
		if (s[i]!=p[i]) return false;
	return true;
}

int main()
{
	n=read(s),n=strlen(s+1);
	m=read(t);int x=0;
	for (int i=n;i<=n+n;i++)
	{
		for (int j=1;j<=i-n;j++)
			p[j]=s[j];
		for (int j=1;j<=n;j++)
			p[(i-n)+j]=t[j];
		if (check(i)) {print(i),puts("");return 0;}
	}
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, fin;
  cin >> n;
  vector<ll> f(n);
  vector< vector<ll> > p(n, vector<ll>(11));
  for(int i = 0; i < n; ++i) for(int j = 0; j < 10; ++j)
  {
    cin >> fin;
    f[i] += (fin << j);
  }
  for(int i = 0; i < n; ++i) for(int j = 0; j < 11; ++j)
  {
    cin >> p[i][j];
  }
  ll ans = -1e9;
  for(int mask = 1; mask <= (1 << 10) - 1; ++mask)
  {
    ll ben = 0;
    for(int i = 0; i < n; ++i)
    {
      bitset<10> b(mask & f[i]);
      ben += p[i][b.count()];
    }
    ans = max(ans, ben);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3692
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
s = list(input())[:-1]
t = list(input())[:-1]
n = len(s)
fflag = 0
for i in range(n):
    if fflag == 1:
        break
    flag = 0
    for j in range(n):
        index = (i+j)%n
        if s[index] != t[j]:
            flag = 1
            break
    if flag == 0:
        print("Yes")
        fflag = 1
if fflag == 0:
    print("No")

Measured memory_bytes: 13828
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var N=arr.shift()-0;
   if(N==0)break;
   for(var I=0;I<N+1;I++){
      var n=arr.shift()-0;
      var ary=[];
      while(n--)ary.push(arr.shift().split(" ").map(Number));
      var r=[];
      for(var i=1;i<ary.length;i++){
         var a=ary[i-1];
         var b=ary[i];
         if(a[0]==b[0] && a[1]>b[1])r.push(["s",a[1]-b[1]]);
         else if(a[0]==b[0] && a[1]<b[1])r.push(["n",b[1]-a[1]]);
         else if(a[1]==b[1] && a[0]>b[0])r.push(["w",a[0]-b[0]]);
         else if(a[1]==b[1] && a[0]<b[0])r.push(["e",b[0]-a[0]]);
      }
      if(I==0){
         var f=r.join("").replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
      }else{
         var rA=r.join("");
         var rB=r.reverse().join("");
         var NrA=rA.replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
         var ErA=rA.replace(/n/g,"E").replace(/e/g,"S").replace(/s/g,"W").replace(/w/g,"N");
         var SrA=rA.replace(/n/g,"S").replace(/e/g,"W").replace(/s/g,"N").replace(/w/g,"E");
         var WrA=rA.replace(/n/g,"W").replace(/e/g,"N").replace(/s/g,"E").replace(/w/g,"S");
         var NrB=rB.replace(/n/g,"N").replace(/e/g,"E").replace(/s/g,"S").replace(/w/g,"W");
         var ErB=rB.replace(/n/g,"E").replace(/e/g,"S").replace(/s/g,"W").replace(/w/g,"N");
         var SrB=rB.replace(/n/g,"S").replace(/e/g,"W").replace(/s/g,"N").replace(/w/g,"E");
         var WrB=rB.replace(/n/g,"W").replace(/e/g,"N").replace(/s/g,"E").replace(/w/g,"S");
         if(f==ErA || f==SrA || f==WrA || f==NrA || f==ErB || f==SrB || f==WrB || f==NrB)console.log(I);
      }
   }
   console.log("+++++");
}

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

int func(int x, int r, int D){
	return r*x - D;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int Lmax=0, Rmin=INF;
	for (int i = 0; i < M; i++)
	{
		int l, r;
		cin >> l >> r;
		if(l>Lmax) Lmax = l;
		if(r<Rmin) Rmin = r;
	}
	int ans = (Rmin-Lmax>=0)?Rmin-Lmax+1:0;

	cout << ans << endl;
	
}

Measured memory_bytes: 384
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=1000000000000001;
const ld PI=acos(-1);
 
int main(){
    rapgame
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        lli sum=0;
        unordered_map <int,int> cnt;
        fr(i,n){ read(x); ++cnt[x]; sum+=x;}
        read(q);
        fr(i,q){
            read2(b,c);
            sum+=cnt[b]*(c-b);
            cnt[c]+=cnt[b];
            cnt[b]=0;
            cout << sum << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 7124
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int s,w;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> s >> w;
}

int solve(){ 
    cout << (s<=w ? "unsafe":"safe") << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
a_list = [int(elem) for elem in input().split()]

avg_a = sum(a_list) / N

min_dist = float('inf')
idx = -1
for i, a in enumerate(a_list):
    dist = abs(a - avg_a)
    if min_dist > dist:
        idx = i
        min_dist = dist
    elif min_dist == dist and i < idx:
        idx = i

print(idx)


Measured memory_bytes: 3060
#include <iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,d,r;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	cout<<d<<" "<<r<<" ";
	double f,u,k;
	u=a,k=b;
	 f=u/k;
	 printf("%.5lf\n",f);

return 0;
}


Measured memory_bytes: 3208
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner(s.lock());
    let n: usize = sc.read();
    if n % 2 != 0 {
        println!("No");
        return;
    }
    let s = sc.chars();

    if (0..(n / 2)).all(|i| s[i] == s[i + n / 2]) {
        println!("Yes");
    } else {
        println!("No");
    }
}

pub struct Scanner<R>(R);

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
n = gets.to_i
x = gets.split(" ").map(&:to_i)
sum = 0

(0..x.max).each do |i|
    x.each do |p|
        sum = sum + (p-i)**2
    end
    $min_sum ||= sum
    $min_sum = sum if $min_sum > sum
    sum = 0
end

puts $min_sum

Measured memory_bytes: 1788
import sys

def solve(a, b):
    if a == 0 or a==1 or a==2:
        if b==100:
            answer=100**a*b+(100**a)
        else:
            answer=100**a*b
    return answer

def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>

int main(void) {
  char ch;
  int i = 1;
  int count[26] = {0};

  while (i) {
   while ((ch = getchar()) != '\n') {
    ch = tolower(ch);

    if (ch == EOF) {
      i = 0;
      break;
    }
    
    if (ch >= 97 && ch <= 123)
      count[ch - 97]++;
  }
  }

   for (i = 0; i < 26; i++) {
     printf("%c : %d\n", i + 97, count[i]);
    }

  return 0;
}


Measured memory_bytes: 2128