akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline ll read(){
	ll s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
#define f1 first
#define f2 second
#define mp make_pair
const int N=1e5+5;
int n,sz[N],f[N];ll Sum;
vector<int> G[N];
pair<ll,int> p[N];
void DFS(int x,ll d){Sum+=d;for(auto y:G[x])DFS(y,d+1);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)sz[i]=1,p[i]=mp(read(),i);
	sort(p+1,p+n+1);
	for(int i=n;i>1;i--){
		int x=p[i].f2;
		ll v=p[i].f1+2*sz[x]-n;
		int j=lower_bound(p+1,p+i,mp(v,0))-p;
		if(j>n)return puts("-1"),0;
		G[f[x]=p[j].f2].push_back(x),sz[f[x]]+=sz[x];
	}DFS(p[1].f2,0);
	if(Sum^p[1].f1)return puts("-1"),0;
	for(int i=1;i<=n;i++)if(f[i])printf("%d %d\n",f[i],i);
	return 0;
}


Measured memory_bytes: 12948
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
const ll MOD = 1e9+7; ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0}; vi d4y = {0, 1, 0, -1};
//---------------------------------------

int main(){
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int max1=0;
    int max2=0;
    vector<int> b(n);
    rep(i,n) b[i]=a[i];
    sort(all(b));
    max1=b[n-1];
    max2=b[n-2];
    rep(i,n){
        if(a[i]==max1) cout<<max2<<endl;
        else cout<<max1<<endl;
    }
}

Measured memory_bytes: 3200
#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++)
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  while(1){
 int h, m,cnt=0; cin>>h>>m;
  if(h==0&&m==0) break;
  rep(i,h){
    if(i%2==0){
   rep(k,m){
    if(k%2==0)cout<<'#';
     else cout<<'.';
       if(k==m-1) cout<<endl;     
   }
    }
 if(i%2==1){
   rep(k,m){
    if(k%2==1)cout<<'#';
     else cout<<'.';
       if(k==m-1) cout<<endl;     
   }
    }
    
  }
  cout<<endl;  
  }
}


Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int x;
  cin >> x;
  if (x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> A(2, vector<int>(N, 0));
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}

	int sum = A[0][0];
	for (int j = 0; j < N; j++) sum += A[1][j];

	int max = sum;
	for (int j = 1; j < N; j++) {
		sum += A[0][j] - A[1][j - 1];
		max = max < sum ? sum : max;
	}
	cout << max;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let i : i32 = read();
    let ans = 48 - i;
    println!("{}",ans);
}

Measured memory_bytes: 4352
S = str(input())
L = S[2:-1]
M = S.replace("A","").replace("C","")
if S.find("A") == 0:
    if L.count("C") == 1:
        if M.lower() == M:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		Console.WriteLine("{0}",(s[0]+1)>>1);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 3e6;

long long power(long long a, long long b = mod - 2) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int f[N + 1];
	f[0] = 1;
	FOR (i, 1, N) f[i] = f[i - 1] * i % mod;
	
	int r1, r2, c1, c2, ans = 0;
	cin >> r1 >> c1 >> r2 >> c2;
	c1--;
	
    FOR (i, r1, r2) ans = (ans + f[c2 + i + 1]*power(f[c2])%mod*power(f[i + 1])%mod - f[c1 + i + 1]*power(f[c1])%mod*power(f[i + 1])%mod) % mod;
    cout << (ans + mod) % mod;
}

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

int32_t main(){
  int n;
  cin>>n;
  double p[n+1];
  p[0]=0.0;
  for(int i=1;i<=n;i++)cin>>p[i];
  double dp[n+1][n+1];
  memset(dp,0.0,sizeof dp);
  dp[0][0]=1.0;

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

          dp[i][j]=(dp[i-1][j]*(1.0-p[i])+dp[i-1][j-1]*p[i]);
        }

    }
  }
  double ans=0;
  for(int j=(n/2+1);j<=n;j++){
    ans+=dp[n][j];
  }
  cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> c(19,vector<int>(19,0));
  for(int i=0;i<n;i++){
    string x;
    cin>>x;
    int d=x.size();
    for(int j=0;j<x.size();j++)
      d=(x.at(j)=='.'?j:d);
    if(d==x.size())
      x.push_back('.');
    for(int j=d;j<d+10;j++)
      if(j==x.size())
        x.push_back('0');
    int64_t a=0;
    for(int j=0;j<x.size();j++){
      if(j==d)
        continue;
      a=a*10+(int)(x.at(j)-'0');
    }
    int a2=0;
    while(a%2==0){
      a2++;
      a/=2;
    }
    int a5=0;
    while(a%5==0){
      a5++;
      a/=5;
    }
    c.at(min(a2,18)).at(min(a5,18))++;
  }
  vector<vector<int>> s(19,vector<int>(19,0));
  for(int i=18;i>=0;i--){
    for(int j=18;j>=0;j--){
      s.at(i).at(j)+=c.at(i).at(j);
      if(i<18)
        s.at(i).at(j)+=s.at(i+1).at(j);
      if(j<18)
        s.at(i).at(j)+=s.at(i).at(j+1);
      if(i<18&&j<18)
        s.at(i).at(j)-=s.at(i+1).at(j+1);
    }
  }
  int64_t t=0;
  for(int i=0;i<=18;i++)
    for(int j=0;j<=18;j++)
      t+=(int64_t)c.at(i).at(j)*(s.at(18-i).at(18-j)-(i>=9&&j>=9?1:0));
  cout<<t/2<<endl;
}

Measured memory_bytes: 3596
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.0555**i-1)/1.0555)for i in range(19,0,-1)]+[1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53324
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s,c = readInts()
need = s*2
if need > c:
    ans = c//2
    c = 0
else:
    ans = s
    c -= ans*2
ans += c//4
print(ans)


Measured memory_bytes: 10344
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    a = list(map(int, rl().split()))
    b = list(map(int, rl().split()))
    
    d = sum(b) - sum(a)
    cnt = 0
    for i in range(N):
        if a[i] < b[i]:
            cnt += (b[i] - a[i] + 1) // 2
    if cnt <= d:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 4596
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

A,B,C = map(int,readline().rstrip().split())
if (A+B+C) <=21:
    print("win")
else:
    print("bust")

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int,int>;
using P = pair<ll,ll>;
const int inf = numeric_limits<int>::max()/3;

int w[400000][2];
int e[400000][2];

int main(void){
  int n;
  string s;
  cin >> n;
  cin >> s;
  w[0][0] = 0LL;
  e[0][0] = 0LL;
  w[n+1][1] = 0LL;
  e[n+1][1] = 0LL;
  for(int i = 1;i <= n;++i){
    w[i][0] = w[i-1][0];
    e[i][0] = e[i-1][0];
    if(s[i-1] == 'W')
      ++w[i][0];
    else
      ++e[i][0];
  }
  for(int i = n;i >= 1;--i){
    w[i][1] = w[i+1][1];
    e[i][1] = e[i+1][1];
    if(s[i-1] == 'W')
      ++w[i][1];
    else
      ++e[i][1];
  }
  int res =  inf;
  for(int i = 1;i <= n;++i){
    res = min(res,w[i-1][0]+e[i+1][1]);
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 6788
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define MOD 1000000007
#define INF (1<<29)
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;

int n, m, r;
int d[210][210];
int ra[9];
int a, b, c;
int ans;
bool used[9];

void dfs(int c, int las, int dist) {
    if (c == r + 1) {
        if (ans > dist) {
            ans = dist;
        }
        return;
    }
    for (int i = 1; i <= r; i++) {
        if (!used[i]) {
            used[i] = true;
            if (las == -1) {
                dfs(c + 1, i, 0);
            }
            else {
                dfs(c + 1, i, dist + d[ra[las]][ra[i]]);
            }
            used[i] = false;
        }
    }
}

int main() {
    cin >> n >> m >> r;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i != j) {
                d[i][j] = INF;
            }
            else {
                d[i][j] = 0;
            }
        }
    }
    for (int i = 1; i <= r; i++) {
        cin >> ra[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> a >> b >> c;
        if (d[a][b] > c) {
            d[a][b] = c;
            d[b][a] = c;
        }
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ans = INF;
    dfs(1, -1, 0);
    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    a, b = MAP()
    if a <= 2* b:
        print(0)
    else:
        print(a - 2 * b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5700
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	long long x;
	cin >> x;
	long long cur = 100;
	int res = 0;
	while(cur < x){
		++ res;
		cur += cur / 100;
	}
	cout << res;
	return 0;
}

/*
100 101 102 ... 199 200 202 204 206 ... 300 
*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3692
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

int n, m;
int s, g;

struct edge
{
    int to, d, c;

    edge() {}
    edge(int to, int d, int c) 
        : to(to), d(d), c(c) {}
};

vector<vector<edge> > E;

struct node
{
    double cost;
    int prev, v, speed;

    node() {}
    node(double cost, int prev, int v, int speed)
        : cost(cost), prev(prev), v(v), speed(speed) {}
    bool operator <(const node& t) const {
        return cost > t.cost;
    }
};

double mem[32][32][32];

void solve()
{
    rep(i,32)rep(j,32)rep(k,32)mem[i][j][k]=1e15;

    priority_queue<node> q;
    q.push(node(0.0, n, s, 0));
    while (!q.empty()) {
        double cost = q.top().cost;
        int prev = q.top().prev;
        int v = q.top().v;
        int speed = q.top().speed;
        q.pop();

        // cerr<<cost<<' '<<prev<<' '<<v<<' '<<speed<<endl;

        if (mem[prev][v][speed] <= cost)
            continue;
        if (v == g && speed == 1) {
            printf("%.8f\n", cost);
            return;
        }

        mem[prev][v][speed] = cost;

        rep(i, E[v].size()) {
            if (E[v][i].to == prev)
                continue;
            for (int ns = speed - 1; ns <= speed + 1; ++ns) {
                if (ns > 0 && ns <= E[v][i].c) {
                    q.push(node(cost + (double) E[v][i].d / ns, v, E[v][i].to, ns));
                }
            }
        }
    }
    cout << "unreachable" << endl;
}

int main()
{
    while (cin >> n >> m && n) {
        cin >> s >> g;
        --s, --g;
        E.clear();
        E.resize(n);
        rep(i, m) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            --x, --y;
            E[x].push_back(edge(y, d, c));
            E[y].push_back(edge(x, d, c));
        }

        solve();
    }

    return 0;
}

Measured memory_bytes: 21580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<31;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    reverse(all(b));
    int num = -1, ct = 0;
    int l = -1, r = -1;
    rep(i,n) {
        if (a[i] == b[i]) {
            num = a[i];
            ct++;
            if (l == -1) {
                l = i;
                r = i;
            } else r = i;
        }
    }
    int ct_change = 0;
    vector<bool> ok(n,false);
    rep(i,n) {
        if (b[i] != num && a[i] != num) {
            ct_change++;
            ok[i] = true;
        }
    }
    if (ct_change < ct) cout << "No" << endl;
    else if (l == -1) {
        cout << "Yes" << endl;
        rep(i,n) cout << b[i] << " ";
    }
    else {
        rep(i,n) {
            if (!ok[i]) continue;
            swap(b[i],b[l++]);
            if (l > r) break;
        }
        cout << "Yes" << endl;
        rep(i,n) cout << b[i] << " ";
    }
}

Measured memory_bytes: 4832
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
		A[i]--;
	}
	vector<int> B(N); rep(i, 0, N) {
		cin >> B[i];
	}
	vector<int> C(N - 1); rep(i, 0, N - 1) {
		cin >> C[i];
	}
	int ans = 0;
	rep(i, 0, N) {
		ans += B[A[i]];
		if (i < N - 1 && A[i] + 1 == A[i + 1]) {
			ans += C[A[i]];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

#include<bits/stdc++.h>
using namespace std;
#define ll long long int

#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll h,w;
char a[1000+1][1000+1];
ll dp[1001][1001];

ll path(ll i, ll j)
{
    //cout<<i<<" "<<j<<endl;
    if(j>=w || i>=h)
    {
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    else
    {
        if(i==h-1 && j==w-1)
        {
            return 1;
        }
        else
        {
            if(a[i][j]=='.')
            {
                return (dp[i][j] = (path(i,j+1)%(1000000000+7)+path(i+1,j)%(1000000000+7))%(1000000000+7));
            }
            else
            {
                return 0;
            }
        }
    }
}


int main()
{

    cin>>h>>w;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }

    ll ans = path(0,0);
    cout<<ans<<endl;
}



Measured memory_bytes: 9088
#include<iostream>
    
using namespace std;
      
int selectionSort(int A[], int N) {
  int sw = 0;
  int minj;
  for ( int i = 0; i < N - 1; i++){
    minj = i;
    for ( int j = i; j < N; j++){
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    swap(A[minj], A[i]);
    if ( i != minj ) sw++;
  }
  return sw;
}
      
int main() {
  int sw, N, A[100];
  cin >> N;
        
  for ( int i = 0; i < N; i++) cin >> A[i];
        
  sw = selectionSort(A, N);
      
  for ( int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
      
  return 0;
}


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

using namespace std;

int main(){
  int n;cin >> n;
  string s; cin >> s;
  int cnt = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == '#')cnt++;
  }
  int ans = cnt;
  for(int i = n - 1; i >= 0; --i){
    if(s[i] == '#')cnt--;
    else cnt++;
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 3e2 + 5, MOD = 1000000007;

int a[NAX];
ll dp[NAX][NAX][NAX];

class Solution
{
private:
    int n, k;
    ll solve(int idx, int rem, int prev)
    {
        if (rem < 0)
            return 1e18;
        if (idx > n)
            return 0;
        ll &ans = dp[idx][rem][prev];
        if (ans >= 0)
            return ans;
        ans = 1e18;
        ans = min(solve(idx + 1, rem - 1, prev), max(0, a[idx] - a[prev]) + solve(idx + 1, rem, idx));
        return ans;
    }

public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        cin >> n >> k;
        for (size_t i = 0; i < n; i++)
            cin >> a[i + 1];
        memset(dp, -1, sizeof dp);
        cout << solve(1, k, 0) << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 221952
#include<bits/stdc++.h>
using namespace std;
int a[10010];
int n,x,ans=0;
int main()
{
	scanf("%d %d",&n,&x);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	if(x>=a[i])
	{
		x-=a[i];
		ans++;
	}
	else break;
	if(ans==n&&x>0)ans--;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    a--;b--;
    cout<< ((b-1+a)/(a));
    //if(a>b) puts("1");

   // if(c*a<b) cout<<c+1;
   // else
   // cout<<c;
}


Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author bcools
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] scores = new int[n];
            int sum = 0;
            for (int i = 0; i < n; ++i) {
                scores[i] = in.nextInt();
                sum += scores[i];
            }
            if (sum % 10 != 0) {
                out.println(sum);
            } else {
                Arrays.sort(scores);
                int index = 0;
                while (index < scores.length && sum % 10 == 0) {
                    if (scores[index] % 10 == 0) {
                        index++;
                    } else {
                        sum -= scores[index];
                        index++;
                    }
                }
                out.println((sum % 10 == 0) ? 0 : sum);
            }
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)           fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n,m;
    cin>>n>>m;
    
    ll meow=n/m;
    ll one=abs(n-(meow*m));
    ll two=abs(n-((meow+1)*m));
    cout<<min(one,two)<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 256
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]


N = int(input())
i = 0
while 2 ** i <= N:
    i += 1

print(2**(i-1))


Measured memory_bytes: 9088
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private boolean[][] b;
 
    private void solve(Scanner sc, PrintWriter out) {
        int W = sc.nextInt();
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        int[] a = new int[N];
        for (int i = 0; i < N; ++i) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }
 
        b = new boolean[H][W];
 
        for (int i = 0; i < N; ++i) {
            switch (a[i]) {
            case 1:
                blackout(0, x[i] - 1, 0, H - 1);
                break;
            case 2:
                blackout(x[i], W - 1, 0, H - 1);
                break;
            case 3:
                blackout(0, W - 1, 0, y[i] - 1);
                break;
            case 4:
                blackout(0, W - 1, y[i], H - 1);
                break;
            }
        }
 
        int count = 0;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (!b[i][j]) {
                    ++count;
                }
            }
        }
        if (debug) {
            for (int i = b.length - 1; i >= 0; --i) {
                for (int j = 0; j < b[i].length; ++j) {
                    System.err.print(b[i][j] ? '#' : ' ');
                }
                System.err.println();
            }
        }
 
        out.println(count);
    }
    private void blackout(int x0, int x1, int y0, int y1) {
        for (int i = y0; i <= y1; ++i) {
            for (int j = x0; j <= x1; ++j) {
                b[i][j] = true;
            }
        }
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 21844
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [s,t] = nexts(2,1);
  return s === t.slice(0,s.length) ? "Yes" : "No";
}

Measured memory_bytes: 29640
import numpy 
 
def convolve(g, h):
  s=len(g)+len(h)+1
  n=1
  while n<s:
    n*=2
  gg=numpy.fft.fft(g+[0]*(n-len(g)))
  hh=numpy.fft.fft(h+[0]*(n-len(h)))
  ff=[gg[i]*hh[i] for i in range(n)]
  ff=numpy.fft.ifft(ff)
  ans=[int(ff[i].real+0.5) for i in range(n)]
  return ans

p=200003
n=int(input())
arr=list(map(int,input().split()))
g=2
order=[1]
while g!=1:
  order.append(g)
  g*=2
  g%=p
pos=[0]*p
for i in range(len(order)):
  pos[order[i]]=i
cnt1=[0]*p
cnt2=[0]*p
coef=[0]*p
for val in arr:
  if val!=0:
    cnt1[pos[val]]+=1
    cnt2[pos[val]]+=1
    coef[(val*val)%p]-=1
ans=convolve(cnt1,cnt2)
for i in range(len(ans)):
  if ans[i]!=0:
    prod=order[i%(p-1)]
    coef[prod]+=ans[i]
total=0
for i in range(p):
  total+=(coef[i]//2)*i
print(total)

Measured memory_bytes: 133328
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;
typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;

int ar[MV], memo[MV];
ll arr[MV];

void solve(int T)
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>ar[i];
	for(int i=n-1;i>0;i--)
	{
		if(ar[i] >= ar[i+1])
		memo[i] = 1 + memo[i+1];	
	}	
	int mx = 0;
	for(int i=1;i<=n;i++)
	mx = max(mx, memo[i]);
	cout<<mx<<"\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;
	while(T--)
	solve(T);
	return 0;
}

Measured memory_bytes: 1024
A,B,C=map(int,input().split())
x=A*7+B
y=C//(A*7+B)
z=x*y
w=C-z
if (A*7)<w<x:
    print((y+1)*7)
else:
    coin=0
    day=0
    while coin<w:
        coin+=A
        day+=1
    print(y*7+day)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef pair <int, pii> piii;
#define fr first
#define sc second
#define pb push_back
#define ppb pop_back()
#define ins insert
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) int(x.size())
#define mpr make_pair
const int N = 1e5 + 11;
int n, a[N];
ll sum, d[N];
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	ll m = (1ll * n * (n + 1)) / 2;
	for(int i = 1;i <= n; ++ i){
		cin >> a[i];
		sum += a[i];
	}
	a[0] = a[n];
	if(sum % m != 0){
		cout << "NO";
		return 0;
	}
	ll z = sum / m;
	sum = 0;
	for(int i = 0;i < n; ++ i){
		ll dif = a[i] - a[i + 1];
		dif += z;
		if(dif < 0){
			cout << "NO";
			return 0;
		}
		if(dif % n != 0){
			cout << "NO";
			return 0;
		}
		d[i] = dif / n;
		sum += d[i];
	}
	if(sum != z){
		cout << "NO";
		return 0;
	}
	sum = 0;
	d[n] = d[0];
	int cnt = 0;
	for(int i = n;i >= -n; -- i){
		int j = (i + n) % n;
		sum -= cnt;
		if(i > 0)cnt += d[j];
		sum += 1ll * d[j] * n;
		if(i <= 1 && a[j] != sum){
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

Measured memory_bytes: 1408
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

def dist(a, b):
    return min(abs(b-a), abs(X-a) + 1 + abs(b-Y))

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

for a in ANS[1:]:
    print(a)

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

int main() {
 string s;
  cin >> s;
  int a = 0,b = 0;
  for(auto i:s) {
  	if(i == 'A')
      a++;
    else 
      b++;
  }
  if(a!= 0 && b!=0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
// typedef pair<int,int>P;

int _;

//========================================================================
ll dp[3009][3009][10],mp[3009][3009];
//========================================================================
int main()
{
    int x,y,k,a,b;
    ll c;
    scanf("%d%d%d",&x,&y,&k);
    for(int i=1;i<=k;i++) 
    {
        scanf("%d%d%lld",&a,&b,&c);
        mp[a][b]=c;
    }
    for(int i=1;i<=x;i++)
    {
        for(int j=1;j<=y;j++)
        {
            if(j==1)
            {
                dp[i][j][3]=dp[i-1][1][3]+mp[i][j];
                dp[i][j][2]=dp[i-1][1][3]+mp[i][j];
                dp[i][j][1]=dp[i-1][1][3]+mp[i][j];
                dp[i][j][0]=dp[i-1][1][3];
                continue ;
            }
            dp[i][j][0]=max(dp[i][j-1][0],dp[i-1][j][3]);
            for(int t=1; t<=3; t++)
            {
                dp[i][j][t]=max(dp[i][j-1][t],dp[i][j-1][t-1]+mp[i][j]);
                dp[i][j][t]=max(dp[i][j][t],dp[i-1][j][3]+mp[i][j]);
            }
        }
    }
    printf("%lld\n",dp[x][y][3]);
    return 0;
}


Measured memory_bytes: 779436
N = int(input())
arr = list(map(int, input().split()))

for i in range(len(arr)):
    for j in range(i,0,-1):
        if(arr[j] < arr[j-1]):
            temp = arr[j]
            arr[j] = arr[j-1]
            arr[j-1] = temp
        else:
            continue
    print(' '.join(map(str,arr)))


Measured memory_bytes: 5592
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

p = list(map(int, input().split()))

tmp = -1
for i in range(-1, 110):
    if i not in p:
        tmp = i if abs(X - tmp) > abs(X - i) else tmp
    
print(tmp)


Measured memory_bytes: 9128
import java.util.Scanner;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

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

     

        Scanner scan = new Scanner(System.in);
        String str = scan.next();
        int n = scan.nextInt();



        int i = 0;
        while(i < n){
       
            String[] box = new String[4];

            int j = 0;
            while(true){
          
                String query1 = scan.next();

                box[j] = query1;
                if(box[0].equals("print") && box[2] != null){
      
                    break;
                }else if(box[0].equals("replace") && box[3] != null){
        
                    break;
                }else if(box[0].equals("reverse") && box[2] != null){
          
                    break;
                }
                j++;
            }
   

            int num1 = Integer.parseInt(box[1]);
            int num2 = Integer.parseInt(box[2]);

            switch(box[0]){
                case "print":
      
                    printA(str, num1, num2);
                    break;
                case "replace":
    
                    str = replace(str, num1, num2, box[3]);
                    break;
                case "reverse":
         
                    str = reverse(str, num1, num2);
           
                    break;
                default:

                    break;

            }

     
            i++;
        }


    }


    public static void printA(String x, int a, int z){
        System.out.println(x.substring(a,z+1));
    }

    public static String replace(String x, int a, int z, String st){
        String start = x.substring(0,a);
        String end = x.substring(z+1,x.length());
        return start + st + end;
    }

    public static String reverse(String x, int a, int z){
        String reverse = "";
    
        for(int i = z; i >= a; i--){
            reverse = reverse + x.substring(i,i+1);
        }
     
        return x.substring(0,a) + reverse + x.substring(z+1,x.length());
    }

  
}



Measured memory_bytes: 47284
#include <stdio.h>

int main(){
  long long int a,b,k;
  long long int bis=1,j;
  scanf("%lld %lld %lld",&k,&a,&b);
  if(b-a<2){
    bis+=k;
  }
  else{
    j=k-(a-1);
    if(j>0){
      bis = a;
        bis += (j/2)*(b-a);
        bis += j % 2;
    }
  }
    
  printf("%lld",bis);
}

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

using namespace std;

int n, a[4000];

int main() {
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    cout << sum - n << '\n';
    return 0;
}


Measured memory_bytes: 256
N=int(input())
red=[tuple(map(int,input().split())) for i in range(N)]
blue=[tuple(map(int,input().split())) for j in range(N)]
from collections import defaultdict
branch=defaultdict(set)
for i,r in enumerate(red):
    for j,b in enumerate(blue):
        if r[0]<b[0] and r[1]<b[1]:
            branch[r[0]]|={b[0]}
            branch[b[0]]|={r[0]}
match=[-1]*(2*N)
used=[False]*(2*N)
def dfs(v):
    global used
    global match
    used[v]=True
    for nex in (branch[v]):
        w=match[nex]
        if (w<0 or (not used[w] and dfs(w))):
            match[nex]=v
            match[v]=nex
            return True
    return False
    
def main():
    global used
    global match
    cnt=0
    for i in range(2*N):
        if match[i]<0:
            used=[False]*(2*N)
            if dfs(i):
                cnt+=1
    return cnt
print(main())

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n, n ){

    int ans = 0 ;
    for( int i = 1 ; i < n ; i++ ){
      int sum = 0;
      for( int j = i ; j < n ; j++ ){
	sum += j;
	if( sum == n ) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import sys
from pprint import pprint

n, y = map(int, sys.stdin.readline().strip().split(" "))
yens = [10000, 5000, 1000]

for i in range(n+1):
    for j in range(0, n-i+1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            sys.exit()

print(-1, -1, -1)

Measured memory_bytes: 40684
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.*;
import java.util.stream.Stream;

public class Main
{
    static List<Edge>[] lEdge;

    @SuppressWarnings("unchecked")
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int V = in.nextInt();
        int E = in.nextInt();

        used = new boolean[V];
        lEdge = Stream.generate(ArrayList::new).limit(V).toArray(ArrayList[]::new);
        for (int i = 0; i < E; i++)
        {
            addEdge(in.nextInt(), in.nextInt(), in.nextInt());
        }

        int res = 0;
        while (true)
        {
            Arrays.fill(used, false);
            int ret = dfs(0, V - 1, Integer.MAX_VALUE);
            if (ret == 0) break;
            res += ret;
        }
        System.out.println(res);
    }

    static void addEdge(int fr, int to, int cap)
    {
        lEdge[fr].add(new Edge(to, cap, lEdge[to].size()));
        lEdge[to].add(new Edge(fr, 0, lEdge[fr].size() - 1));
    }

    static class Edge
    {
        int to, cap, rev;

        public Edge(int to, int cap, int rev)
        {
            this.to = to;
            this.cap = cap;
            this.rev = rev;
        }
    }

    static boolean[] used;

    static int dfs(int fr, int to, int f)
    {
        if (fr == to) return f;
        used[fr] = true;

        for (int i = 0; i < lEdge[fr].size(); i++)
        {
            Edge e = lEdge[fr].get(i);
            if (!used[e.to] && e.cap > 0)
            {
                int dist = dfs(e.to, to, Math.min(f, e.cap));
                if (dist > 0)
                {
                    e.cap -= dist;
                    lEdge[e.to].get(e.rev).cap += dist;
                    return dist;
                }
            }
        }
        return 0;
    }

}



Measured memory_bytes: 39228
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		String array[][] = new String[num][3];
		for(int i = 0; i < num; i ++) {
			array[i][0] = sc.next();
			array[i][1] = sc.next();
			array[i][2] = String.valueOf(i + 1);
		}
		Arrays.sort(array, (a, b) -> Integer.compare(Integer.parseInt(b[1]), Integer.parseInt(a[1])));
		Arrays.sort(array, (a, b) -> a[0].compareTo(b[0]));
		for(int i = 0; i < num; i ++) {
			System.out.println(array[i][2]);
		}
	}
}


Measured memory_bytes: 27092
#include<stdio.h>
int main(void) {
	int n;
	double a[1000];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf", &a[i]);
	}
	double b = 0;
	for (int i = 0; i < n; i++) {
		b += 1 /a[i];
	}
	double s = 1 / b;
	printf("%lf",s);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
L = list(map(int,input().split()))


S = [0,L[0]]
for i in range(1,N):
  temp = S[i]+L[i]
  S.append(temp)
dic ={}
for i in range(len(S)):
  if S[i] not in dic:
    dic[S[i]] = 1
  else:
    dic[S[i]] += 1
ans = 0    
for t in dic.values():
  ans += t*(t-1)//2
print(ans)

Measured memory_bytes: 43868
#include <bits/stdc++.h>
#define rep(i,n) for (int i=1 ; i<=(n) ; ++i)
typedef long long ll;
using namespace std;
const ll MAX = 2500LL;
typedef pair <ll, ll> P;

int main(){
  int k,n;
  cin >> k >> n;
  vector<int> A(n+1,0);
  rep(i,n){
    int a;
    cin >> a;
    A[i] = a;
  }
  sort(A.begin(), A.end());
  int max_sub=0;
  rep(i,n-1){
    max_sub = max(max_sub, A[i+1]-A[i]);
  }
  max_sub = max(max_sub, k-A[n]+A[1]);
  cout << k-max_sub << endl;
  return 0;

}


Measured memory_bytes: 1024
mod = 10**9 + 7

def init(n):
    # 階乗とその逆元をグローバルに定義
    global factorial, inverse
    # 0-indexedでそれぞれ１で初期化
    factorial = [1]*(n+1)
    inverse = [1]*(n+1)

    fact = 1 
    for p in range(1,n+1):
        fact *= p
        fact %= mod
        factorial[p] = fact
    
    inv = pow(fact, mod-2, mod)
    inverse[n] = inv
    for p in range(2,n+1)[::-1]:
        inv *= p
        inv %= mod
        inverse[p-1] = inv

def comb(n,r):
    if n < r:
        return 0
    return factorial[n] * inverse[n-r] * inverse[r] % mod

N,K = map(int,input().split())

def cal(i):
    return comb(K-1,i-1) * comb(N-K+1,i) % mod

init(10**4)

for i in range(1,K+1):
    ans = cal(i)
    print(ans)

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



int main(){
	int n;cin>>n;
	int aa;
	vector<int> arr(n);
	for(int i=0;i<n;i++){
		cin>>aa;
		arr[i] = aa;
	}
	
	vector<int> dp(n+1);
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]- arr[i-2]));
	}
	
	cout<<dp[n-1];
	
	
	return 0;
}

Measured memory_bytes: 1024