akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#define MAX 101

using namespace std;

int main(){
  int N;
  cin >> N;
  int h[N+1];
  vector<int> threshold;
  int s_flag = 0;
  for(int i = 1;i <= N;i++){
    cin >> h[i];
    if(h[i]!=0) s_flag=1;
  }

  if(!s_flag){
    cout << 0 << endl;
    return 0;
  }

  int count = 0;
  int flag = 1;
  s_flag = 1;
  while(s_flag){
    flag=1;
    for(int i = 1;i <= N;i++){
      if(h[i]!=0){
        h[i]--;
        if(i==1 || flag){
          count++;
          flag=0;
        }
      }
      else{
        flag=1;
      }
    }
    s_flag=0;
    for(int i = 1;i <= N;i++){
      if(h[i]!=0) s_flag = 1;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;
#define MAXN 100000
int fa[MAXN+10];
int l[MAXN+10],r[MAXN+10];
LL sum[MAXN+10];
int find(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
void Union(int x,int y)
{
	int fx=find(x),fy=find(y);
	fa[fy]=fx;
	l[fx]=min(l[fx],l[fy]);
	r[fx]=max(r[fx],r[fy]);
	sum[fx]+=sum[fy];
}
void solve(long long N, long long L, vector<long long> a){
	queue<int> q;
	int cnt=0;
	for(int i=1; i<=N; ++i) {
		fa[i]=i;
		l[i]=r[i]=i;
		sum[i]=a[i-1];
	}
	for(int i=1; i<=N; ++i) {
		q.push(i);
	}
	stack<int> s;
	while(!q.empty()) {
		int now=q.front(); q.pop();
		int fnow=find(now),fl=find(l[fnow]-1),fr=find(r[fnow]+1);
		if (l[fnow]>1 && fnow!=fl && sum[fnow]+sum[fl]>=L) {
			s.push(l[fnow]-1);
			++cnt;
			Union(fl,fnow);
			q.push(fl);
		} else if (r[fnow]<N && fnow!=fr && sum[fnow]+sum[fr]>=L) {
			s.push(r[fnow]);
			++cnt;
			Union(fnow,fr);
			q.push(fnow);
		}
	}
	if (cnt<N-1) {
		puts("Impossible");
	} else {
		puts("Possible");
		while(!s.empty()) {
			cout<<s.top()<<'\n';
			s.pop();
		}
	}

}

int main(){
#ifdef WAAUTOMATON
	freopen("1_12.txt","r",stdin);
#endif
	long long L;
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	scanf("%lld",&L);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, L, a);
	return 0;
}



Measured memory_bytes: 5708
#include<iostream>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<climits>
#include<algorithm>
using namespace std;

typedef long long int ll;

int main() {
    int n;
    cin >> n;
    pair<int, int> arr[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i].first;
        cin >> arr[i].second;
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        if (arr[i].first != arr[i].second) {
            count = 0;
        } else {
            count++;
        }

        if (count == 3) {
            cout << "Yes" << endl;
            break;
        }
    }

    if (count != 3) {
        cout << "No" << endl;
    }
}


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

const int maxn=200007;
pair<int,int> seg[maxn],res[maxn];
int n,m,a[maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n;
    for (int i=0;i<n;++i) cin>>seg[i].first>>seg[i].second;
    int lm=0,rm=1e9;
    for (int i=0;i<n;++i){
        lm=max(lm,seg[i].first);
        rm=min(rm,seg[i].second);
    }
    for (int i=0;i<n;++i){
        res[i].first=max(0,seg[i].second-lm+1);
        res[i].second=max(0,rm-seg[i].first+1);
    }
    sort(res,res+n);
    int ans=0;
    a[0]=1e9;
//    for (int i=0;i<n;++i) cout<<res[i].first<<" "<<res[i].second<<endl;
    for (int i=1;i<=n;++i){
        a[i]=min(a[i-1],res[i-1].second);
    }
    for (int i=1;i<n;++i){
        ans=max(ans,a[i]+res[i].first);
    }
    int mxx=0;
    for (int i=0;i<n;++i){
        mxx=max(mxx,seg[i].second-seg[i].first+1);
    }
    cout<<max(ans,mxx+max(rm-lm+1,0))<<endl;
    return 0;
}


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

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

using namespace std;

int main(){
	int n; cin>>n;
	double ans=0;
	rep(_,n){
		double a;
		string s; cin>>a>>s;
		if(s=="JPY") ans+=a;
		else         ans+=a*380'000;
	}
	cout<<ans<<endl;

	return 0;
}


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

int n, k, s;
int main() {
	int i;
	cin >> n >> k >> s;
	for(i=0; i<k; i++) printf("%d ", s);
	for(; i<n; i++) printf("%d ", s<1e9 ? s+1 : 1);
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;

namespace AOJ.Volume2
{
    public class TicketSales
    {
        public static int Main()
        {
            var price = new Dictionary<string, int>()
            {
                {"1", 6000 },
                {"2", 4000 },
                {"3", 3000 },
                {"4", 2000 }
            };

            for(int i = 0; i < 4; i++)
            {
                var input = Console.ReadLine().Split(' ');
                Console.WriteLine(price[input[0]] * int.Parse(input[1]));
            }

            return 0;
        }
    }
}

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define MN 400000
#define mod 998244353
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char s[MN+5];
int n,ans,num,tot,res[MN+5];
int Solve(int x)
{
    int res=0;
    for(int i=1;i<=x;++i) res=(res*2+s[i]-'0')%mod;
    for(int i=1;i<=n;++i) 
    {
        int j=(i-1)%x+1,k=(s[j]-'0')^(1&((i-1)/x));
        if(k>s[i]-'0') return res;
        else if(k<s[i]-'0') return res+1;
    }
    return res+1;
}
int main()
{
    n=read();scanf("%s",s+1);
    for(int i=1;i<=n;++i) tot=(2LL*tot+s[i]-'0')%mod;
    tot=(tot+1)%mod;
    for(int i=1;i<=n;++i) if((n%i==0&&((n/i)&1))) res[i]=Solve(i);
    for(int i=1;i<=n;++i) if((n%i==0&&((n/i)&1))) for(int j=i<<1;j<=n;j+=i) res[j]=(res[j]-res[i]+mod)%mod;
    for(int i=1;i<=n;++i) if((n%i==0&&((n/i)&1))&&res[i])
    {
        ans=(ans+2LL*i*res[i])%mod;
        tot=(tot-res[i]+mod)%mod;
    }
    cout<<(ans+2LL*n*tot)%mod;
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
  int N;
  
  scanf("%d",&N);
  if(1 > N || N > 100) return 0;

  int A[N+1],i,j;
  int v;

  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0; i < N; i++){
    printf("%d",A[i]);
    if(i != N - 1)printf(" ");
    else printf("\n");
  }
  
  for(i = 1; i < N; i++){
    v = A[i];
    j = i - 1;
    
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    
    for(j = 0; j < N; j++){
      printf("%d",A[j]);
      
      if(j != N - 1){
	printf(" ");
      }
      else printf("\n");
    }
  }
  return 0;
}


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

int main() {
    int a;
    int b;
    int c;
    string calc;
    cin >> a >> b >> c;
    
    if(a < b && b < c){
        calc = "Yes";
    }else{
        calc = "No";
    }

    cout << calc << endl;
}


Measured memory_bytes: 3204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int D = in.Int();
            int N = 26;
            int[] c = in.Int(N);
            int[][] s = new int[D][N];
            for (int i = 0; i < D; i++) {
                s[i] = in.Int(N);
            }
            int[] t = new int[D];
            for (int i = 0; i < D; i++) {
                t[i] = in.Int() - 1;
            }

            int score = 0;
            int[] last = new int[N];
            for (int d = 0; d < D; d++) {
                score += s[d][t[d]];
                last[t[d]] = d + 1;
                for (int i = 0; i < N; i++) {
                    if (t[d] != i) {
                        score -= c[i] * ((d + 1) - last[i]);
                    }
                }
                out.println(score);
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 34372
#include <stdio.h>

int digit_number(int, int);

int main(){
	int a, b;
	
	while(scanf("%d %d", &a, &b) != EOF){
		printf("%d\n", digit_number(a+b, 1));
	}

	return 0;
}

int digit_number(int x, int flag){
	if(x/10 >= 1){
		flag++;
		return digit_number(x/10, flag);
	}else{
		return flag;
	}
}

Measured memory_bytes: 596
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int main() {
	int n, ret = 0;
	cin >> n;
	REP(i, n) {
		int k;
		cin >> k;
		while (!(k & 1)) {
			ret++;
			k >>= 1;
		}
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

int main() {
    int X;
    cin >> X;
    
    vector<int> prime;
    prime.push_back(2);
    int p_max=2;
    while(p_max<X) {
        int tmp_p=p_max+1;
        bool flag=true;
        while(flag) {
            bool ff=true;
            for(int i=0; i<prime.size(); i++) {
                if(tmp_p%prime[i]==0) {
                    tmp_p++;
                    ff=false;
                    break;
                }
            }
            if(ff) {
                p_max = tmp_p;
                prime.push_back(tmp_p);
                flag=false;
            }
        }
    }
    
    cout << p_max << endl;


    return 0;
    
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 998244353
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}

ll n,s,a[3001],dp[3001][6100][3];

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

    cin>>n>>s;
    rep(i,n) cin>>a[i];

    rep(i,n){
        dp[i][0][0]=1;
        for(int j=3000;j>=0;j--){
            //左端指定
            dp[i+1][j+a[i]][1]+=dp[i][j][0];    dp[i+1][j+a[i]][1]%=mod;
            dp[i+1][j][1]+=dp[i][j][0];         dp[i+1][j][1]%=mod;
            //区間伸ばし
            dp[i+1][j+a[i]][1]+=dp[i][j][1];    dp[i+1][j+a[i]][1]%=mod;
            dp[i+1][j][1]+=dp[i][j][1];         dp[i+1][j][1]%=mod;
            //区間閉じ
            dp[i+1][j+a[i]][2]+=dp[i][j][0];    dp[i+1][j+a[i]][2]%=mod;
            dp[i+1][j][2]+=dp[i][j][0];         dp[i+1][j][2]%=mod;
            dp[i+1][j+a[i]][2]+=dp[i][j][1];    dp[i+1][j+a[i]][2]%=mod;
            dp[i+1][j][2]+=dp[i][j][1];         dp[i+1][j][2]%=mod;
            dp[i+1][j][2]+=dp[i][j][2];         dp[i+1][j][2]%=mod;

            //modint導入しておけばよかったと反省しています
        }
    }
    cout<<dp[n][s][2]<<endl;
    return 0;
}


Measured memory_bytes: 428032
d = {i: 0 for i in range(1, 5)}
for i in range(3):
    a, b = map(int, input().split())
    d[a] += 1
    d[b] += 1

ans = 'YES'
for i in d.values():
    if i == 3:
        ans = 'NO'
        break

print(ans)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    while(true){
        c-=b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a-=d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3636
#include <stdio.h>
#pragma warning (disable:4996)

//prototype
int counter(int);

int main() {
	//input
	int N;
	(void)scanf("%d", &N);

	//output
	printf("%d", counter(N));
}

int counter(int N) {
	int count = 0;
	for (int a = 1; a < N; a++) {
		for (int b = 1; a * b < N; b++) {
			count++;
		}
	}
	return count;
}

Measured memory_bytes: 1712
n, m = map(int, input().split())
a = [input().split() for _ in range(m)]
A = []
B = []

for i in range(m):
    if a[i][0] == "1":
        A.append(a[i][1])
    if a[i][1] == str(n):
        B.append(a[i][0])
print("POSSIBLE" if set(A) & set(B) else "IMPOSSIBLE")


Measured memory_bytes: 68240
import sys
input = sys.stdin.readline

def main():
    MOD = 10 ** 9 + 7
    h, w = map(int, input().split())
    tizu = [input() for _ in range(h)]
    dp = [[0 for _ in range(w)] for _ in range(h)]
    dp[0][0] = 1
    for i in range(h):
        for j in range(w):
            if tizu[i][j] == "#":
                continue
            if i != 0:
                dp[i][j] += dp[i - 1][j]
            if j != 0:
                dp[i][j] += dp[i][j - 1]
            dp[i][j] %= MOD
    print(dp[-1][-1])
main()

Measured memory_bytes: 50388
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int h, w,memo[2005][2005];
char d[2005][2005];

int main()
{
    ciosup;
    cin >> h >> w;
    vector<int> vx[h], vy[w];
    REP(i,h){
        vx[i].eb(-1);
    }
    REP(i, w)
    {
        vy[i].eb(-1);
    }
    REP(i, h)
    {
        REP(j,w){
            cin >> d[i][j];
            if (d[i][j] == '#'){
                vx[i].eb(j);
                vy[j].eb(i);
            }
        }
    }
    REP(i, h)
    {
        vx[i].eb(w);
        sort(vx[i].begin(), vx[i].end());
    }
    REP(i, w)
    {
        vy[i].eb(h);
        sort(vy[i].begin(), vy[i].end());
    }
    ll ans = 0;
    REP(i,h){
        REP(j,w){
            if (d[i][j] == '.'){
                ll kazu = 0;
                auto ite1 = lower_bound(vx[i].begin(), vx[i].end(), j);
                kazu += (*ite1) - (*(ite1 - 1)) - 1;
                //cout << " efwa" << kazu << endl;
                auto ite2 = lower_bound(vy[j].begin(), vy[j].end(), i);
                kazu += (*ite2) - (*(ite2 - 1)) - 1;
                kazu -= 1;
                ans = max(ans, kazu);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 38656
import java.util.*;


import java.io.*;



public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		
		
		int dp[]=new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		int k=2;
		dp[0]=0;
		dp[1]=Math.abs(ar[1]-ar[0]);
		for(int i=2;i<n;i++) {
			for(int j=1;j<=k;j++) {
				dp[i]=Math.min(dp[i],dp[i-j]+Math.abs(ar[i]-ar[i-j]));
				
			}
			
		}
		System.out.println(dp[n-1]);

	}
}

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


int main(){
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll cnt = 0;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            if(N - (R * i) - (G * j) >= 0 && (N - (R * i) - (G * j)) % B == 0){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations

class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)
        
    def build(self,seq):
        data = seq
        size = self.size
        for i,x in enumerate(data):
            j = i+(i&(-i))
            if j < size:
                data[j] += data[i]
        self.data = data
        
    def __repr__(self):
        return self.data.__repr__()
        
    def get_sum(self,i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i
    
    def find_kth_element(self,k):
        data = self.data; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

def Inversion(seq):
    seq = [i + 1 for i in seq]
    # seqは、1,2,...,Nの順列 (0-indexだったので合わせた。)
    N = len(seq)
    bit = BinaryIndexedTree([0] * (N+1))
    inv = N*(N-1)//2
    for x in seq:
        inv -= bit.get_sum(x)
        bit.add(x,1)
    return inv

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 偶数/奇数の位置に来るindex達を生成する。Combinations(range(N), N//2)
# 偶数だけの列と奇数だけの列を作って、それぞれソート。(転倒数を計算したいので、valとともにindex番号も持っておく)
# 数字と位置の偶奇が異なる場合はB面、一致しているときはA面を使う。
# 上記の２つの数列を一つにまとめた時に広義単調増加になっているかを判定。
# 最小の移動回数が答え。存在しない場合は-1
# 最小の操作回数⇒転倒数

# combinations(n, n//2)が偶数の位置に来るindex。
ptn = list(combinations(range(N), N//2))

ans = - 1
for p in ptn:
  evnline = []
  oddline = []
  for i in range(N):
    if i in p:
      evnline.append((A[i] if (i + 1) % 2 == 0 else B[i], i))
    else:
      oddline.append((B[i] if (i + 1) % 2 == 0 else A[i], i))
  line = [0] * N
  evnline.sort()
  oddline.sort()
#   print("e, o", evnline, oddline)
  for itr, val in enumerate(evnline):
    line[itr * 2 + 1] = val
  for itr, val in enumerate(oddline):
    line[itr * 2] = val
  if all([j[0] >= i[0] for i, j in zip(line,line[1:])]):
    exchange_cnt = Inversion([i[1] for i in line])
    if ans == -1:
      ans = exchange_cnt
    else:
      ans = min(ans, exchange_cnt)

print(ans)


Measured memory_bytes: 59080
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

ok = N-1
ng = -1
mid = (ok+ng)//2
while ok - ng > 1:
    if mid >= N - P:
        ok = mid
        mid = (ok+ng)//2
        continue
    K = A[mid] + M
    if K < A[N - P]:
        ng = mid
        mid = (ok+ng)//2
        continue
    p = M * (V-P)
    flg = 0
    for i in range(mid):
        p -= M
        if p <= 0:
            flg = 1
            break
    if flg:
        ok = mid
        mid = (ok+ng)//2
        continue
    for i in range(mid+1, N - (P-1)):
        p -= K - A[i]
        if p <= 0:
            flg = 1
            break
    if flg:
        ok = mid
        mid = (ok+ng)//2
    else:
        ng = mid
        mid = (ok+ng)//2

print(N - ok)


Measured memory_bytes: 62576
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=100005;

int n,m,cnt,last[N],a[N],f[N],now,op[N],vis[N];
LL g[N];
struct data{int x,y,z;}b[N];
struct edge{int to,next,w;}e[N*2];

bool cmp(data a,data b)
{
	return a.z<b.z;
}

int find(int x)
{
	if (f[x]==x) return x;
	else return f[x]=find(f[x]);
}

void addedge(int u,int v,int w)
{
	e[++cnt].to=v;e[cnt].w=w;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].w=w;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x)
{
	for (int i=last[x];i;i=e[i].next)
		if (!op[i/2]&&e[i].w<=now) op[i/2]=1,dfs(e[i].to);
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=m;i++) scanf("%d%d%d",&b[i].x,&b[i].y,&b[i].z);
	std::sort(b+1,b+m+1,cmp);
	cnt=1;
	for (int i=1;i<=m;i++) addedge(b[i].x,b[i].y,b[i].z);
	for (int i=1;i<=n;i++) f[i]=i,g[i]=a[i];
	for (int i=1;i<=m;i++)
	{
		int x=find(b[i].x),y=find(b[i].y);
		if (x!=y) f[x]=y,g[y]+=g[x];
		if (g[y]>=b[i].z) vis[i]=1;
	}
	for (int i=m;i>=1;i--)
		if (!op[i]&&vis[i]) now=b[i].z,op[i]=1,dfs(b[i].x),dfs(b[i].y);
	int ans=0;
	for (int i=1;i<=m;i++) if (!op[i]) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
using namespace std;
string s1,s2;
int main()
{
    cin>>s1>>s2;
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    reverse(s2.begin(),s2.end());
    if(s1<s2)cout<<"Yes\n";
    else cout<<"No\n";
    return 0; 
}

Measured memory_bytes: 256
xy=input().split()
X=xy[2]
Y=xy[3]
n=input().split()
n.append(X)
n=[int(i) for i in n]
n=sorted(n)
m=input().split()
m.append(Y)
m=[int(i) for i in m]
m=sorted(m)
x=n[-1]
y=m[0]
if x>=y:
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    int n,k,h,o=0;
    cin>>n>>k;
    for(int z=1;z<=n;z++){
        cin>>h;
        if(k<=h){
            o++;
        }
    }
    cout<<o<<endl;;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    int num[5];
    int jd;
    
    int result=0;
    
    for(int i=0; i<5; i++)scanf("%d", &num[i]);
    scanf("%d", &jd);
    
    for(int i=0; i<5; i++)
    {
        for(int j=i+1; j<5; j++)
        {
            if(num[j]-num[i]>jd)
            {
                result=1;
                break;
            }
        }
    }
    
    if(result==0)printf("Yay!\n");
    else printf(":(\n");
    
    return 0;
}

Measured memory_bytes: 128
<?php
  
  $input = explode(' ',trim(fgets(STDIN))) ;
  
$c = 1 ;
if($input[1]==1){
echo 0 ;
  exit ;
}
for($i=0;$i<90;$i++){
$c +=$input[0]-1 ;
if($c >= $input[1]){
echo $i+1 ;
  exit ;
}
}

Measured memory_bytes: 3828
n=int(input())
if n==1:
  print('Yes')
  print('2')
  print('1 1')
  print('1 1')
  exit()
a=1
while ((a+1)*(a+2))//2<=n:
  if n==((a+1)*(a+2))//2:
    print('Yes')
    x=a+2
    print(x)
    break
  a+=1
else:
  print('No')
  exit()
b=[]
for i in range(1,n+1):
  b+=[i]
b=b+b

l=[[] for i in range(x)]
for i in range(x):
  if i==0:
    for j in range(x-1):
      l[i].append(b.pop())
    print(x-1,*l[i])
  else:
    for j in range(i):
      l[i].append(l[j].pop())
    for j in range(x-1-i):
      l[i].append(b.pop())
    print(x-1,*l[i])


Measured memory_bytes: 10892
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 20005;
int p[MAXN],n,a[MAXN],b[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",p+i);
	for(int i=1;i<=n;++i)a[i]=n*i;
	for(int i=1;i<=n;++i)b[i]=n*(n-i+1);
	int now=0;
	for(int i=1;i<=n;++i)
		a[p[i]]+=(now++);
	for(int i=1;i<=n;++i)printf("%d ",a[i]);
	puts("");
	for(int i=1;i<=n;++i)printf("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 896
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    const char White = '.';
    const char Black = '#';

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        SetArray(ary, (x, i) => x - 1);

        int c = 0;

        Action<int, int> swap = (ii, jj) => {
            var tmp = ary[ii];
            ary[ii] = ary[jj];
            ary[jj] = tmp;
            c++;
        };

        if (ary[0] == 0) swap(0, 1);
        if (ary[n-1] == n-1) swap(n-1, n-2);

        for(int i=1; i<n-1; i++) {
            if(ary[i] == i) {
                swap(i, i + 1);
            }
        }

        return c;
    }

    static void SetArray<T>(T[] array, Func<T, int, T> f) {
        for (int i = 0; i < array.Length; i++)
            array[i] = f(array[i], i);
    }
    static void FillArray<T>(T[] array, T value) {
        for (int i = 0; i < array.Length; i++)
            array[i] = value;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    while(n > 0) { n -= 1000; }
    cout << -n << '\n';
    return 0;
}



Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s,t;

bool check(int v){
	for(int i=0;i+v<n;i++){
		if(s[v+i]!=t[i])return false;
	}
	return true;
}

int main(void){
	scanf("%d",&n);
	cin >> s;
	cin >> t;
	for(int i=0;i<n;i++){
		if(check(i)){
			printf("%d\n",n+i);
			return 0;
		}
	}
	printf("%d\n",n*2);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	
	int t; cin >> t; bool encontrado=false;
	while (t-- && !encontrado){
		int a; cin >> a;
		if (a%2==0){
			if (a%3==0 || a%5==0){
			}
			else {
				encontrado=true;
			}
		}
	}
	
	if (!encontrado){
		cout << "APPROVED";
	}
	else {
		cout << "DENIED";
	}
	
	return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m = map(int, input().split())

# zikan
x1 = a * math.cos(math.radians(360 * (h * 60 + m) / 720))
y1 =  a * math.sin(math.radians(360 * (h * 60 + m) / 720))
# fun
x2 =  b * math.cos(math.radians(360 * m / 60))
y2 =  b * math.sin(math.radians(360 * m / 60))

print(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))


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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

void chmin(int &a, int b){
    a = min(a,b);
}

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    int ans = 0;
    vector<vector<int> > dp(h,vector<int>(w,INF));
    if(s[0][0] == '#' && s[h-1][w-1] == '#'){
        ans++;
    }
    dp[0][0] = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i>0) chmin(dp[i][j], dp[i-1][j] + (s[i][j]!=s[i-1][j]?1:0));
            if(j>0) chmin(dp[i][j], dp[i][j-1] + (s[i][j]!=s[i][j-1]?1:0));
        }
    }
    ans += (dp[h-1][w-1]+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID (l+r)/2
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int t, n;
vi a, b;
vector<vi> adj;
vi vis;

void dfs(int s){
	vis[s] = true;
	for(auto v : adj[s]) if(!vis[v]) dfs(v);
}

int main(){
	int m;
	cin>>n>>m;
	adj.assign(n+1, vi());
	vis.assign(n+1, false);
	FOR(i,m){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int cnt=0;
	FOR(i,n) if(!vis[i+1]) dfs(i+1), cnt++;
	cout<<cnt-1<<endl;
}


Measured memory_bytes: 9596
import java.util.Arrays;
import java.util.Scanner;

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

        int[] a = new int[5];
        int[] b = new int[5];
        
        int ans = 0;
        for (int i = 0; i < 5; i++) {
            a[i] = sc.nextInt();
            b[i] = 10 - a[i] % 10;
            b[i] = b[i] == 10 ? 0 : b[i];
            ans += a[i] + b[i];
        }

        Arrays.sort(b);
        ans -= b[4];
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 24148
N = int(input())
H = list(map(int, input().split()))

now = 0
count = 0
tmp = 0
for i in range(len(H) - 1):
    if H[i] >= H[i+1]:
        tmp += 1
    else:
        now = H[i+1]
        count = max(tmp, count)
        tmp = 0
if tmp != 0:
    count = max(tmp, count)
print(count)

Measured memory_bytes: 14224
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string s;
    int q,x,y;
    char z;
    cin>>s>>q;
    int flag=0;
    while(q--){
    	cin>>x;
    	if(x==1)
			flag++;
    	else{
       		cin>>y>>z;
        	if(flag%2==0){
            	if(y==1)	s.insert(s.begin(),z);
            	else s.insert(s.end(),z);
        	}else{
            	if(y==1)	s.insert(s.end(),z);
            	else	s.insert(s.begin(),z);
        	}
      	}
    }
    if(flag%2==1)
		reverse(s.begin(),s.end());
   cout<<s<<endl;
}

Measured memory_bytes: 900
//#fuccccc
#include <bits/stdc++.h>
#define TASK ""
#define inpf freopen(TASK".inp", "r", stdin)
#define outf freopen(TASK".out", "w", stdout)
#define ll long long
#define db double
#define F first
#define S second
#define maxn 1000005
#define MP make_pair
#define PB push_back
using namespace std ;
int n, m, tr[maxn];
vector<int> a[maxn] ;
void dfs(int u)
{
    tr[u] = 1;
    for(auto v: a[u])
    {
        if(!tr[v]) dfs(v) ;
    }
}
int main()
{
    cin >> n >> m ;
    for(int i = 1; i <= m; i++ )
    {
        int u, v;
        cin >> u >> v;
        a[u].PB(v) ;
        a[v].PB(u) ;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(tr[i] == 0) dfs(i), ans ++;
    }
    cout << ans - 1 ;
}


Measured memory_bytes: 31080
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 5e5 + 5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    
    ll n; cin >> n;
    vector<pair<ll, ll>> edges;
    for (ll i = 0; i < n - 1; i++) {
        ll u, v; cin >> u >> v;
        edges.emplace_back(u, v);
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += i * (n - i + 1);
    }

    for (auto p : edges) {
        ll u = p.X, v = p.Y;
        if (u > v) swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << endl;

    return 0;
}

/*

*/

Measured memory_bytes: 7436
#include <stdio.h>

int main(void)
{
	char r[5], a[5], hit, blow;
	int i, n;
	
	while (1){
		
		scanf("%s %s", r, a);
		
		hit = 0;
		blow = 0;
		
		if (r[0] == '0' && a[0] == '0'){
			break;
		}
		
		for (i = 0; i < 4; i++){
			if (r[i] == a[i]){
				hit++;
			}
		}
		for (i = 0; i < 4; i++){
			for (n = 0; n < 4; n++){
				if (r[i] == a[n]){
					blow++;
				}
			}
		}
		blow -= hit;
		
		printf("%d %d\n", hit, blow);
	}
	return (0);
}

Measured memory_bytes: 540
#include<stdio.h>

int main(){
    int n;
    int d;
    scanf("%d %d",&n,&d);

    int a;
    int num;
    a=(2*d+1);

    while(n>0){
        n=n-a;
        num++;
    }
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> arr(N);
  for(int i=0;i<N;++i) arr[i]=i;
  double x[N], y[N];
  for(int i=0;i<N;++i) cin>>x[i]>>y[i];
  double sum = 0;
  do {
    for(int i=0;i<N-1;++i) {
      sum += sqrt(pow(x[arr[i]]-x[arr[i+1]], 2)+pow(y[arr[i]]-y[arr[i+1]], 2));
    }
  }while(next_permutation(arr.begin(), arr.end()));
  int tmp = 1;
  for(int i=1;i<=N;++i) tmp *= i;
  cout<<setprecision(20)<<sum/tmp<<endl;
}



Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dev 1000000007
signed main(){
  int n,x=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    x*=i;
    if(x>dev)x%=dev;
  }
  cout<<x<<endl;
  return 0;
}  

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

ll N, M;

pair<ll, ll> A[1 << 20];
ll B[1 << 20];

pair<ll, ll> toptwo(pair<ll,ll> A,pair<ll,ll> B){
	ll fir = max(A.first, B.first);
	ll sec = max(min(A.first, B.first), max(A.second, B.second));
	return make_pair(fir, sec);
}	

int main(void){
    
    cin >> N;
    for(ll i = 0; i < 1 << N; ++i) cin >> A[i].first;
    
    for(int i = 0; i < N; ++i){
		for(int j = 0; j < (1 << N); ++j){
			if(j & (1 << i)) A[j] = toptwo(A[j], A[j ^ (1 << i)]);
		}
	}
    
    for(ll i = 0; i < (1 << N); ++i) B[i] = A[i].first + A[i].second;
    
    for(ll i = 0; i < (1 << N); ++i) B[i + 1] = max(B[i + 1], B[i]);
    
    for(ll i = 1; i < (1 << N); ++i) cout << B[i] << endl;
    
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 1e5+100;
ll n,a[SIZE];
ll ans[SIZE];

int main(){
    cin >> n;
    ll mem = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    
    }
    mem = a[0];
    for(int i = 1; i < n; i++){
        if(i%2 == 0){
            mem += a[i];
        }
        else{
            mem -= a[i];
        }
    }
    ans[0] = mem;
    cout << mem << ' ';
    for(int i = 1; i < n; i++){
        ans[i] = a[i-1]-ans[i-1]/2;
        ans[i] *= 2;
        cout << ans[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    string s;
    ll k;
	cin >> s >> k;
    vector<int> chrs;
    int num = 1;
    rep(i,s.size()) {
        if(i) {
            if(s[i-1]==s[i]) {
                num++;
            } else {
                chrs.push_back(num);
                num = 1;
            }
        }
    }
    chrs.push_back(num);
    ll cnt = 0; // sの最初と最後の文字種を除いたs内の操作回数
    rep(i,int(chrs.size())-2) cnt += chrs[i+1] / 2;

    ll ans = 0;
    if (chrs.size() == 1) {     // 全結合
        ans = (k * s.size()) / 2;
    } else if (s.front() == s.back()) { // 結合あり
        ans = cnt * k + chrs.front()/2 + chrs.back()/2 + ((chrs.front()+chrs.back())/2)*(k-1);
    } else {                    // 結合なし
        ans = (cnt + chrs.front()/2 + chrs.back()/2) * k;
    }

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


Measured memory_bytes: 256
var s:String;i:Longint;c:char;f:boolean;
begin
	readln(s);
	for c:='a' to 'z' do begin
		f:=false;
		for i:=1 to length(s) do begin
			f:=f or(s[i]=c);
		end;
		if not f then begin
			writeln(c);
			exit;
		end;
	end;
	writeln('None');
end.


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

int main(){
long long n;
long long ans=1;
cin>>n;
long long a[n];
for(long long i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
reverse(a,a+n);
for(long long i=0;i<n;i++){
if(a[n-1]==0){
    ans=0;
    break;
}
if(a[0]*a[1]>1000000000000000000){
    ans=-1;
    break;
}
if(a[i]>1000000000000000000){
    ans=-1;
    break;

}


if(1000000000000000000/ans<a[i]){
    ans=-1;
    break;
}
ans=a[i]*ans;
}



cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 4412
/**
 *    author:  lets
 *    created: 2020-06-07 20:52:19 JST
 **/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 1; i < 1e8; i++) {
    if (a * i % b == c) {
      cout << "YES" << '\n';
      return 0;
    }
  }
  cout << "NO" << '\n';
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final String s;	// 1≦|s|≦10
		try(Scanner scan = new Scanner(System.in)) {
			s = scan.next();
		}
		
		StringBuilder result = new StringBuilder();
		
		for (char c : s.toCharArray()) {
			switch (c) {
			case '0':
				result.append(c);
				break;
			case '1':
				result.append(c);
				break;
			case 'B':
				if (result.length() != 0) {
					result.deleteCharAt(result.length() - 1);
				}
				break;
			default:
				break;
			}
		}
		
		// 出力
		out.println(result.toString());
		out.close();
	}

}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N=0, tmp=0, c=0, maxh=0, h;
	cin >> N;
	REP(i, 0, N){
		cin >> h;
		maxh = max(c, maxh);
		if(h > tmp) c = 0;
		else ++c;
		
		tmp = h;
	}
	maxh = max(c, maxh);
	cout << maxh;

}


Measured memory_bytes: 256
// 2010/12/22 Tazoe

#include <iostream>
using namespace std;

void convert(int n)
{
	if(n==0)
		return;

	convert(n/8);

	switch(n%8){
		case 0:
			cout << 0;
			break;
		case 1:
			cout << 1;
			break;
		case 2:
			cout << 2;
			break;
		case 3:
			cout << 3;
			break;
		case 4:
			cout << 5;
			break;
		case 5:
			cout << 7;
			break;
		case 6:
			cout << 8;
			break;
		case 7:
			cout << 9;
			break;
	}
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		convert(n);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 864
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 303;
const int K = 1000000;
int cnt[N], b[N];
int nx(int x){
    int c = 1;
    if (x == 0) return 0;
    while(x % 10 == 0){
        x /= 10;
        c *= 10;
    }
    x /= 10;
    x -= 9;
    return x * c;
}
int gen(int x, int y, int ny, int s, int f = 0){
    if (s == 0) return (x == 0);
    int res = 0;
    if (abs(x) > 100 * y * ny) return 0;
    if (s == 1 && y == 0) return 10 * (x == 0);
    for (int i = 0; i <= 18; i++){
        res += (cnt[i] - f * b[i]) * gen(x - (i - 9) * (y * ny), y / 10 / 10, ny * 10, s - 1);
    }
    return res;
}
int solve(int x, int qq = 0){
    int l = 0;
    int z = x;
    while(x){
        x /= 10;
        l++;
    }
    int y = 0;
    int res = 0;
    int ny = 1;
    for (int i = 1; i <= 17; i++){
        res += gen(z, y, ny, (i + 1) / 2, 1 - qq);
        y = 10 * y + 9;
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    for (int i = 0; i < 10; i++){
        for (int j = 0; j < 10; j++){
            cnt[j - i + 9]++;
            if (i == 0) b[j - i + 9]++;
        }
    }
    int q = 1;
    int d;
    cin >> d;
    while(d % 10 == 0){
        d /= 10;
        if (q == 1)q *= 9; else
        q *= 10;
    }
    cout << q * solve(d, (q != 1));

}


Measured memory_bytes: 384
function main(input){
    input=input.split(' ');
    inputA=parseInt(input[0]);
    inputB=parseInt(input[1]);
    
    x = inputA * inputB;

    out = inputA % inputB;
    while(out!=0){
        inputA = inputB;
        inputB = out;
        out = inputA % inputB;
    }

    console.log(x/inputB);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372