akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define lowbit(x) ((x)&-(x))
#define debug(x) cout << #x " = " << x << endl;
namespace IO{
	const int L = 1 << 15;
	char ibuf[L|1],*iS=ibuf,*iT=ibuf;
	char obuf[L|1],*oS=obuf,*oT=obuf+L;
	char c,st[66];int tp=0,f;
	inline char gc(){
		if(iS==iT) iT=(iS=ibuf)+fread(ibuf,sizeof(char),L,stdin);
		return (*iS++);
	}
	inline void flush() {
		fwrite(obuf,sizeof(char),oS-obuf,stdout);
		oS = obuf;
	}
	inline void pc(char c){*oS++=c;if(oS==oT) flush();}
	#define gc getchar
	#define pc putchar
	inline ll read(){
		ll x=0;f=1,c=gc();
		for(;!isdigit(c);c=gc())if(c=='-')f=-1;
		for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c&15);
		return x*f;
	}
	void write(ll x){
		if(!x) pc('0');if(x<0) pc('-'),x=-x;
		while(x) st[++tp]=x%10+'0',x/=10;
		while(tp) pc(st[tp--]);
	}
	void wri(ll x){write(x);pc(' ');}
	void writeln(ll x){write(x);pc('\n');}
	struct IOflusher{~IOflusher(){flush();}}_ioflusher_;
}
using IO::read;
using IO::writeln;
using IO::wri;
inline void gg(string s){cout << s << endl;exit(0);}
inline void gg(ll x){writeln(x);exit(0);}
const int maxn = 1e7+233;
const int mod = 998244353;
string s[62];
int step,len;
int ask(string s){
	cout << "? " << s << endl;
	int x;
	cin >> x;
	return x;
}
string solve(int l,int r){
	if(l==r) return s[l];
	int m=(l+r)>>1;
	string L=solve(l,m),R=solve(m+1,r);
	if(L.empty()) return R;
	if(R.empty()) return L;
	string ret;
	int i=0,j=0;
	for(;i<L.size()||j<R.size();)
		if(i<L.size() && (j==R.size() || 
			ask(ret+L[i]+string(R.begin()+j,R.end()))==len-ret.size()-1-(R.size()-j)))
				ret = ret + L[i++];
		else	ret = ret + R[j++];
	return ret;
}
int main(){
	int p = 0;
	for(char c='a';c<='z';++c) s[p++] = string(128-ask(string(128,c)),c);
	for(char c='A';c<='Z';++c) s[p++] = string(128-ask(string(128,c)),c);
	for(char c='0';c<='9';++c) s[p++] = string(128-ask(string(128,c)),c);
	for(auto u:s) len+=u.size();
	auto zz=solve(0,61);
	cout << "! " << zz << endl;
	return 0;
}


Measured memory_bytes: 3720
import copy

N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
B = copy.deepcopy(A)

if max(A) > 1:
	print("-1")
else:
	for i in range(N // 2, 0, -1):
		total = 0
		for j in range(2 * i, N + 1, i):
			total += B[j]
		if total % 2 != A[i]:
			B[i] = 1
		else:
			B[i] = 0
			
	print(sum(B))
	for i in range(len(B)):
		if B[i] == 1:
			print(i, end = " ")

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

ll x = 1e9 + 7; 

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3604
n, m = map(int, input().split())
A = list(map(int, input().split()))

d = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

INF  =10**18
dp = [-INF]*(n+1)
dp[n] = 0
for i in reversed(range(1, n+1)):
    for a in A:
        j = i-d[a]
        if j >= 0:
            dp[j] = max(dp[j], dp[i]*10+a)
print(dp[0])

Measured memory_bytes: 84276
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define INF 1000000000000000000
#define minimize(a, b) a = min(a, b)

int main() {
    int n, k;
    cin >> n >> k;
    vector<long> h(n+1);
    h[0] = 0;
    for (int i=1; i<=n; i++) cin >> h[i];
    h.push_back(0);
    long dp[n+2][k+1];
    fill(dp[0], dp[n+2], INF);
    dp[0][0] = 0;
    for (int i=0; i<=n; i++) {
        for (int j=0; j<=k; j++) {
            for (int l=0; i+l+1<=n+1 && j+l<=k; l++) { 
                minimize(dp[i+l+1][j+l], dp[i][j] + max(h[i+l+1] - h[i], 0l));
            }
            //cerr << dp[i][j] << ' ';
        }
        //cerr << '\n';
    }
    long ans = INF;
    for (auto &dpi:dp[n+1]) {
        ans = min(ans, dpi);
        // cerr << dpi << ' ';
    }
    // cerr << '\n';
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 896
n = gets.to_i
x = gets.split.map(&:to_i)

min = 9999999
(1..100).each do |i|
  	sum = 0
	x.each do |num|
  		sum += (num - i) * (num - i)
	end
  	if min > sum
      min = sum
    end
end
puts min

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

typedef long long ll;
typedef unsigned long long ull;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,S;
ll X[100010],P[100010];

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

  cin>>N>>S;
  rep(i,N)cin>>X[i]>>P[i];

  ll l=0,r=N-1;
  vector<int> perm;
  while(X[l]<S&&S<X[r]){
    if(P[l]>=P[r]){
      P[l]+=P[r]; P[r]=0;
      perm.push_back(r); r--;
    }else{
      P[r]+=P[l]; P[l]=0;
      perm.push_back(l); l++;
    }
  }
  if(S<X[l]){
    while(l!=r)perm.push_back(r--);
    perm.push_back(r);
  }else if(X[r]<S){
    while(l!=r)perm.push_back(l++);
    perm.push_back(l);
  }
  reverse(all(perm));

  ll res=abs(S-X[perm[0]]);
  rep(i,N-1)res+=abs(X[perm[i+1]]-X[perm[i]]);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 2428
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] o = saori.nextHayami().split("");
		String[] e = saori.nextHayami().split("");
		int num = Math.max(o.length, e.length);
		for(int i = 0;i < num;i++){
			if(i < o.length){
				System.out.print(o[i]);
			}
			if(i < e.length){
				System.out.print(e[i]);
			}
		}
		System.out.println("");
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21844
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

long long fact[1000100];
void calcfact() {
    long long i;
    fact[0] = 1;
    fact[1] = 1;
    for (i = 2; i < 1000100; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
    }
}
long long power(long long a, long long b) {
    long long x = 1, y = a;
    while (b > 0) {
        if (b % 2) {
            x = (x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x % MOD;
}
long long inv(long long x) {
    return power(x, MOD - 2);
}
long long nCr(long long n, long long r) {
    return (fact[n] * (inv(fact[r])*inv(fact[n - r]) % MOD)) % MOD;
}

int main(){
    calcfact();
    ll n, m;
    cin >> n >> m;
    ll copym = m;
    map<int, int>f;
    if (copym % 2 == 0) {
        while (1) {
            if (m % 2 == 0) {
                f[2]++;
                m /= 2;
            }
            else break;
        }
    }
    for (int i = 3; i <= m; i+=2) {
        while (1) {
            if (m%i == 0) {
                f[i]++;
                m /= i;
            }
            else break;
        }
        if (m == 1)break;
    }
    ll ans = 1;
    for (auto i = f.begin(); i != f.end(); ++i) {
        ans *= nCr(i->second+n-1,i->second);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
  int n,k;
  cin >> n >> k;
  int a = 1;
  for (int i = 0; i < n; i++) {
    if (a*2-a < k) a *= 2;
    else a += k;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


int main(){
	int n, T;
    int c, t;
    int minc = 100000;
    cin >> n >> T;
    for(int i=0;i<n;i++){
        cin >> c >> t;
        if(t <= T){
            if(minc > c) minc = c;
        }
    }
    if(minc == 100000) cout << "TLE" << endl;
    else cout << minc << endl;
	
	
	return 0;
}


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

int n;

int calc(vector<int> a){
    int ans = 0;
    for(int i=1;i<n-1;i++){
        if(a[i-1] < a[i] && a[i] < a[i+1]){
            ans++;
            if(i+1 == n-1) break;
            if(a[i+1] < a[i+2]){
                swap(a[i],a[i+1]);
            }
            else if(a[i] < a[i+2]){
                swap(a[i],a[i+1]);
            }
            else swap(a[i+1],a[i+2]);
        }
        if(a[i-1] > a[i] && a[i] > a[i+1]){
            ans++;
            if(i+1 == n-1) break;
            if(a[i+1] >a[i+2]) {
                swap(a[i],a[i+1]);
            }
            else if(a[i] > a[i+2]){
                swap(a[i],a[i+1]);
            }
            else swap(a[i+1],a[i+2]);
        }
    }
    return ans;
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i] = a[i];
    }
    int ans = 0;
    ans = calc(a);
    swap(b[0],b[1]);
    ans = min(ans,1+calc(b));

    cout << ans << endl;
    
}


Measured memory_bytes: 4180
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new AOJ1144().doIt();
	}
	
	class AOJ1144{
		int w,h;
		int[][] map;
		int[] sx = {0,1,0,-1};
		int[] sy = {-1,0,1,0};
		Point2D nextPoint(int x,int y,int muki){
			Point2D result = new Point2D.Double(-1,-1);
			int ax = x+sx[muki],ay = y+sy[muki];
			if(ax<0||ax>=w||ay<0||ay>=h)return result;
			if(map[ay][ax]==1)return result;
			for(;x>=0&&x<w&&y>=0&&y<h;){
				if(map[y][x]==3||map[y][x]==1){
					result = new Point2D.Double(x, y);break;
				}
				x+=sx[muki];y+=sy[muki];
			}
			return result;
		}
		
		int dfs(int x,int y,int cost){
//			System.out.println(x+" "+y+" "+cost);
			int result = Integer.MAX_VALUE;
			if(cost>10)return Integer.MAX_VALUE;
			if(map[y][x]==3)return cost;
			for(int i=0;i<4;i++){
				Point2D np = nextPoint(x, y, i);
//				System.out.println(nx+" "+ny);
//				System.out.println(np);
				if(np.getX()<0&&np.getY()<0)continue;
				int nx = (int)np.getX(),ny = (int)np.getY();
				if(map[ny][nx]==1){
					map[ny][nx] = 0;
					result = Math.min(result, dfs(nx-sx[i], ny-sy[i], cost+1));
					map[ny][nx] = 1;
				}else{
					result = Math.min(result, dfs(nx, ny, cost+1));
				}
			}
			return result;
		}
		
		void solve(){
			Point2D start = new Point2D.Double();
			for(int i=0;i<h;i++)for(int s=0;s<w;s++)if(map[i][s]==2){
				start = new Point2D.Double(s,i);break;
			}
			int result = dfs((int)start.getX(), (int)start.getY(), 0);
			System.out.println(result==Integer.MAX_VALUE? "-1":result);
		}
		
		void doIt(){
			while(in.hasNext()){
				w = in.nextInt();
				h = in.nextInt();
				if(w+h==0)break;
				map = new int[h][w];
				for(int i=0;i<h;i++)for(int s=0;s<w;s++)map[i][s] = in.nextInt();
				solve();
			}
		}
	}
	
}

Measured memory_bytes: 92668
#include<iostream>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,0)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
		}
		else
		{
			parent[b]=a;
			if(rank[a]==rank[b])rank[a]++;
		}
		return true;
	}
};
int N,M;
main()
{
	cin>>N>>M;
	UF uf(N);
	int ans=N;
	for(int i=0;i<M;i++)
	{
		int x,y,z;cin>>x>>y>>z;
		if(uf.unite(x-1,y-1))ans--;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
use proconio::{input, fastout};

use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        ss: [String;n]
    }
    let mut m: HashMap<&str,usize> =
        [
            ("AC", 0),
            ("WA", 0),
            ("TLE", 0),
            ("RE", 0),
        ].iter().cloned().collect();
    for s in &ss {
        m.entry(s).and_modify(|e| *e += 1);
    }
    println!("AC x {}",  m["AC"]);
    println!("WA x {}",  m["WA"]);
    println!("TLE x {}", m["TLE"]);
    println!("RE x {}",  m["RE"]);
}


Measured memory_bytes: 7792
#include<stdio.h>
#include<iostream>

using namespace std;

int main(void) {

	int h, w, n, k, row, col, a[10000], c[100][100],num;
	num = 0;

	cin >> h >> w >> n;

	for (k = 0; k < n; k++) {
		cin >> a[k];
	}

//	cout << h << ":" << w << ":" << n << "\n";

	for (row = 0; row < h; row++) {
		if (row % 2 == 0) {
			for (col = 0; col < w; col++) {
				c[row][col] = num;
				a[num]--;
				if (a[num] == 0)num++;

				cout << c[row][col] + 1 << " ";
			}
		}
		else {
			for (col = 0; col < w; col++) {
				c[row][col] = num;
				a[num]--;
				if (a[num] == 0)num++;

			}
			for (col = w - 1; col >= 0; col--) {
				cout << c[row][col] + 1 << " ";
			}
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w;
  while(cin >> h >> w){
    TSTART();
    REP(i,w+2){
      cout << "#";
    }
    cout << endl;

    REP(i,h){
      string sh;
      cin >> sh;
      cout << "#" << sh << "#" << endl; 
    }
    
    REP(i,w+2){
      cout << "#";
    }
    cout << endl;
    
    TSTOP();
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string S;
    cin>>S;
    int N=S.size();
    int count=0;
    for(int i=0;i<N;i++){
    if(S[i]==S[i+1]){
        count++;
        if(S[i+1]=='1'){
            S[i+1]='0';
        }
        else if(S[i+1]=='0'){
            S[i+1]='1';
        }   
    }
    }
    cout<<count<<endl;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vec H(N);
    bool ans = true;
    REP(i,N){
        cin>>H[i];
    }
    FOR(i,1,N){
        if(H[i]<H[i-1]){
            ans = false;
            break;
        }
        else if(H[i]>H[i-1]) H[i]--;
    }
    if(ans) Out("Yes");
    else Out("No");
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

struct edge {
   ll to, cost;
};

const ll INF = 1e18;
ll N, M, dist[1010];
vec<edge> G[3000];

bool bellman() {
   for (int i = 0; i < N; i++) {
      dist[i] = INF;
   }
   dist[0] = 0;
   for (int k = 0; k < N*8; k++) {
      for (int i = 0; i < N; i++) {
         for (edge e : G[i]) {
            if (dist[i] != INF && dist[e.to] > dist[i] + e.cost) {
               dist[e.to] = dist[i] + e.cost;
               if (e.to == N-1 && k >= 5*N) return true;
            }
         }
      }
   }
   return false;
}

int main() {
   cin >> N >> M;
   for (int i = 0; i < M; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      a--, b--;
      G[a].push_back(edge{b, -c});
   }

   if (bellman()) {
      puts("inf");
   } else {
      cout << -dist[N-1] << endl;
   }

   return 0;
}

Measured memory_bytes: 384
N = int(input())
mem = [[0]*10 for _ in range(10)]

for i in range(1,N+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    mem[a][b] += 1

ans = 0
for i in range(1,N+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    ans += mem[b][a]
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
// unbounded knapsack..
using namespace std;
using ll=long long ;
int main(){
        int n;
        cin>>n;
        vector<vector<double>>dp(n+1,vector<double>(n+1,0));
        vector<double>p(n);
        for(int i=0;i<n;i++) cin>>p[i];
        dp[0][0]=1.0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=i;j++){
                dp[i][j]=(1-p[i-1])*dp[i-1][j];
                if(j>0){
                    dp[i][j]+=p[i-1]*dp[i-1][j-1];
                }
            }
        }
    double ans=0;
    for(int x=0;x<=n;x++){
        if(x>n/2) ans=ans+dp[n][x];
    }
    cout << setprecision(9) << ans << endl;
    return 0;

}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n, p[20];

int main() {
	cin >> n;
	inc(i, n) { cin >> p[i]; }
	
	int ans = 0;
	inc(i, n) {
		if(i == 0 || i == n - 1) { continue; }
		if(inII(p[i], p[i - 1], p[i + 1]) || inII(p[i], p[i + 1], p[i - 1])) { ans++; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>


#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

int main()
{

  int n;
  cin >>n;
  vector<long> a;
  long total=0;
  rep(i,n)
  {
    int ai;
    cin >>ai;
    
    a.push_back(ai);
    total+=ai;
  }
  
  long now=0;
  long sa=0;
    rep(i,n)
    {
      now+=a[i];
      if(now==total-now)
      {
        cout <<0;
        return 0;
      }
      
      if(total-now<now)
      {
        long last =now-a[i];
        if(now-(total-now) < total-(last*2))
        {
          sa=now-(total-now);
        }
        else
        {
          sa=total-(last*2);
        }
        
                cout <<sa;
        return 0;
          
      }
      
    }
  
	return 0;
}





Measured memory_bytes: 2420
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (x, y) = get!(u64, u64);

    let mut a = x;
    let mut ans = 0;

    while y >= a {
        a *= 2;
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

int main () {
    int a = read(), b = read();
    int i, j;
    for (i = 1; i <= 100000; i++) {
        if (int(double(i) * 0.08) == a && int(double(i) * 0.1) == b) {cout << i << endl; return 0;}
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 256
#!ruby -narprime
A=$F.map &:to_i
d=A.tally
A[1]&&print(Prime.each(1e6).all?{|r|a=(r..10**6).step(r).sum{d[_1]||0}<2}?:pairwise:A.reduce(:gcd)<2?:setwise: :not,' coprime')

Measured memory_bytes: 133440
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	long long int a=0,b=0,c=0,d=0,n=0,ans=0,count=0,h,w ,up,down,end=0,idx,m,kuso;
	string s;
	vector<long long int> x;
	vector<long long int>::iterator position;
	bool q=false;
	cin >> h>>a;
	ans = h / a;
	if (h % a != 0)ans++;
	
		cout <<ans<< endl;
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

using namespace std;
struct Human
{
	int age;
	double weight;
	char name[256];
};




int main()
{
	//cin>>N;
	// for (int i = 0; i < N; ++i) cin >> A[i];
	//while(true){break; ++res;}
	//cout << res << endl;
	//sort(a, a+N, greater<int>()) 大きい順ソート sort(v.begin(), v.end()); // vector
	//set<int>values; values.insert() values.size()
	//map<string,int>salary; salary["John"] = 1400;
	// string num = to_string(counter);
	// swap(a,b);


	int a, b, d;
	int sum = 0;
	int count=0;
	int j = 0;
	int check = 0;
	int time;
	int w, h;
	int x, y, r;
	int N=1000;

	int gcdmemo = 1000000000;

	vector<string> lang;

	string s; // s.size() to_string char string %s



	// cin >> N;
	vector<int> A(N);
	vector<int> B(N);

	while (cin >> x>>y) {
		A[count] = x;
		B[count] = y;
		count++;
		if (x== 0) {
			break;
		}
	}

	for (int k = 0; k < count; k++)
	{
		for (int i = 0; i < A[k]; i++)
		{
			for (int j = 0; j < B[k]; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		if (k != count - 1)
		{
			cout << endl;
		}
	}



}


Measured memory_bytes: 3100
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		long [] in = new long [a];
        for(int i=0;i<a;i++){
                             in[i] = sc.nextLong();
        }
        Arrays.sort(in);
        int ans = 0;
        for(int i=0;i<a-2;i++){for(int j=i+1;j<a-1;j++){
          for(int k=j+1;k<a;k++){
          if(in[i]<in[j] && in[j]<in[k] && in[k]<in[i]+in[j]){ans++;}  
                                }                                                 
                                                       }       
                              }
		System.out.println(ans);
	}
}

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

int main() {
	double n,t,a;
	cin>>n>>t>>a;
	vector<pair<double,int>>v(n);
	map<int,int>mp;
	for(int i=0;i<n;i++)
	{
		double x;
		cin>>x;
		double temp=abs((t-x*0.006)-a);
		v[i]={temp,i+1};
		
	}
	sort(v.begin(),v.end());
   cout<<v[0].second;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep2(i, N, M) for (ll i = N; i < M; i++)
#define pb push_back



typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<pll, vector<pll>, greater<pll>> greater_pq;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}
template<class T>
T getbit( T i) {
	return 1LL<<i;
}

ll sum(ll M, ll  i) {
	if (M < 0) {
		cout << "";
	};
	if (!((M >> i) % 2 )) {
		return M + (1LL << i);
	}
	else if(!atbit(M,i+1)){
		return sum(M,i+2) - getbit(i) + getbit(i+1);
	}
	else {
		return M - getbit(i)-getbit(i+1);
	}
}

int main() {
	ll N;
	cin >> N ;
	auto x = bitset<64>(N);
	ll M=0;
	if (N > 0) {
		rep(i, 64) {
			if (i % 2 == 0 && ((N >> i) % 2) == 1) {
				M =sum(M, i);
			}
			if (i % 2 == 1 && ((N >> i) % 2) == 1) {
				M =sum(sum(M,i) ,i+1);
			}
		}
		
		auto flg = false;
		for (int i =60; i>-1; --i) {
			flg = flg || ((M >> i) % 2 == 1);
			if (flg) {
				cout << (M >> i) % 2;
			}
		}
	}
	else if(N<0) {
		N = -2*N;
		rep(i, 64) {
			if (i % 2 == 0 && ((N >> i) % 2) == 1) {
				M = sum(M, i);
			}
			if (i % 2 == 1 && ((N >> i) % 2) == 1) {
				M = sum(sum(M, i), i + 1);
			}
		}

		auto flg = false;
		for (int i = 60; i>0; --i) {
			flg = flg || ((M >> i) % 2 == 1);
			if (flg) {
				cout << (M >> i) % 2;
			}
		}
	}
	else cout << 0;

	return 0;
}



Measured memory_bytes: 764
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int m=sc.nextInt();
        int n=sc.nextInt();
        int[] nums=new int[n];
        for(int i=0;i<n;i++)nums[i]=sc.nextInt();
        int count1=0;
        int count2=0;
        int ans=0;
        if(m==2){
            for(int i=0;i<n;i++){
                if(i%2==0&&nums[i]==1||i%2==1&&nums[i]==2)count1++;
                else count2++;
            }
            System.out.println(Math.min(count1,count2));
        }else{
            for(int i=0;i<n-1;i++){
                if(nums[i]==nums[i+1]){
                    nums[i+1]=-1;
                    ans++;
                }
            }
            System.out.println(ans);
        }
    }
    
}


Measured memory_bytes: 69784
a, b, c, d = gets().split(' ').map(&:to_i)

def gcd(n, m)
	if n < m
		a = m
		b = n
	else
		a = n
		b = m
	end

	return (a % b == 0 ? b : gcd(b, a % b))
end

lcm = c * d / gcd(c, d)

sum = b - a + 1
sum -= Rational(b, c).floor - Rational(a, c).ceil + 1
sum -= Rational(b, d).floor - Rational(a, d).ceil + 1
sum += Rational(b, lcm).floor - Rational(a, lcm).ceil + 1

puts sum


Measured memory_bytes: 1916
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

long double angle(int a,int b)
{
	long double ma=(b)*6;
	long double ha=(a+(long double)(b/(long double)60))*30;

	long double Min=min(abs(ma-ha),360-abs(ma-ha));

	long double rad=(Min*PI)/(long double)180;

	return rad;
}

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;

	int a,b,c,d;

	cin>>a>>b>>c>>d;

	long double ang=angle(c,d);

	long double ans;

	d(ang);

	ans = (long double)((long double)(a*a+b*b)-(long double)(2*a*b*cosl(ang)));

	ans = sqrtl(ans);

	cout<<fixed<<setprecision(12)<<ans;
	

}

Measured memory_bytes: 4144
use std::io;

pub fn main(){
    let mut instr = String::new();
    io::stdin().read_line(&mut instr).expect("!");
    let instr = instr.trim().split(' ').map(|ref x|x.parse::<i32>().unwrap()).collect::<Vec<i32>>();
    let (N, M) = (instr[0], instr[1]);
    
    let mut paths = Vec::<(i32, i32)>::new();
    for _ in 0..M {
        let mut instr = String::new();
        io::stdin().read_line(&mut instr).expect("!");
        let instr = instr.trim().split(' ').map(|ref x|x.parse::<i32>().unwrap()).collect::<Vec<i32>>();
        
        let (l, r) = (instr[0], instr[1]);
        paths.push((l, r));
    }

    paths.sort_by_key(|ref k| k.1);

    let mut prev_r = -1;
    let mut result = 0;
    for (l, r) in paths{
        let r = r - 1;
        if prev_r < l {
            prev_r = r;
            result += 1;
        }
    }
    println!("{}", result);

}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool up_min(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool up_max(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_mdvector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_mdvector(int n, Ts ... ts){
        return vector<decltype(make_mdvector(ts...))>(n, make_mdvector(ts...));
    }

    inline ll bit(int x){
        return 1ll << x;
    }

    template<class T>
    istream& operator>>(istream& is, vector<T>& v){
        for (auto &&x : v) { is >> x; } return is;
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    ll N;
    void run();
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef XELMH
    string test_cases = "test_C.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


void solver::run(){
    ll K, Q;
    is >> N >> K >> Q;
    if(!is) return;
    vector<int> point(N, K);
    for (int i = 0; i < Q; ++i) {
        int A;
        is >> A;
        A--;
        point[A]++;
    } // end i
    for (auto &&pt : point) {
        os << ( pt - Q > 0? "Yes" : "No") << endl;
    } // end pt
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;
    vector<i64> a(N);
    rep(i,0,N) cin >> a[i];
    
    auto a1=a,a2=a;
    vector<pair<int,int>> ans1,ans2;
    bool f1=false,f2=false;
    if(*max_element(a.begin(),a.end())>0){
        f1=true;
        i64 ma=*max_element(a1.begin(),a1.end());
        int idx=max_element(a1.begin(),a1.end())-a1.begin();
        rep(i,0,N-1) while(f1 and a1[i]>a1[i+1]){
            a1[i+1]+=ma;
            ans1.push_back(make_pair(idx,i+1));
            if(ans1.size()>2*N){
                ans1.clear();
                ans1.shrink_to_fit();
                f1=false;
                break;
            }
            if(a1[i+1]>ma){
                ma=a1[i+1];
                idx=i+1;
            }
        }
    }
    if(*min_element(a.begin(),a.end())<0){
        f2=true;
        i64 mi=*min_element(a2.begin(),a2.end());
        int idx=min_element(a2.begin(),a2.end())-a2.begin();
        for(int i=N-1; i>0; --i) while(f2 and a2[i-1]>a2[i]){
            a2[i-1]+=mi;
            ans2.push_back(make_pair(idx,i-1));
            if(ans2.size()>2*N){
                ans2.clear();
                ans2.shrink_to_fit();
                f2=false;
                break;
            }
            if(a2[i-1]<mi){
                mi=a2[i-1];
                idx=i-1;
            }
        }
    }

    if(!f1 and !f2){
        cout << 0 << endl;
        return;
    }

    vector<pair<int,int>> ans;
    if(f1 and !f2) ans=ans1;
    if(!f1 and f2) ans=ans2;
    if(f1 and f2) ans=ans1.size()<ans2.size()?ans1:ans2;
    assert(ans.size()<=2*N);
    cout << ans.size() << endl;
    rep(i,0,ans.size()) cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

public class AtCoderB
{
    static void Main()
    {
        int n;
        int l;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            l = int.Parse(words[1]);
        }

        int[] apples = new int[n];
        int expect = 0;
        for (int i = 0; i < n; i++)
        {
            int apple = l + i;
            apples[i] = apple;
            expect += apple;
        }

        int answer = 0;
        for (int i = 0; i < n; i++)
        {
            int actual = expect - apples[i];
            if (Math.Abs(expect - actual) <= Math.Abs(expect - answer))
            {
                answer = actual;
            }
        }

        Console.WriteLine(answer);
    }
}

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

using namespace std;

typedef struct {
    string name;
    int time;
} Process;

const int LEN = 100005;
int top, tail;
Process P[LEN];

Process dequeue()
{
    Process p = P[top];
    top = (top + 1) % LEN;
    return p;
}

void enqueue(Process p)
{
    P[tail] = p;
    tail = (tail + 1) % LEN;
}

int main()
{
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++){
        Process p;
        cin >> p.name >> p.time;
        P[i] = p;
    }
    top = 0; tail = n;

    int total = 0;
    while(top != tail){
        Process p = dequeue();
        int m = min(q, p.time);
        total += m;
        p.time -= m;
        if(p.time > 0){
            enqueue(p);
        }else{
            cout << p.name << " " << total << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7032
import Control.Monad

main :: IO ()
main = do
  s <- getLine
  putStrLn $ if solve s then "AC" else "WA"

solve :: String -> Bool
solve s = foldr1 (&&) conds
  where
    n = length s
    conds = [
      head s == 'A',
      length (filter (== 'C') (drop 2 . take (n - 1) $ s)) == 1,
      length [x | x<- s, x `elem` ['a'..'z']] == n - 2]


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 2019

typedef long long ll;

ll modPow(ll a, int p) {// a^p (mod mod)
    if (p == 0) return 1;
    if (p%2 == 0) {
        int halfP = p/2;
        ll half = modPow(a, halfP);
        return half * half % (MOD);
    }
    else {
        ll ans = a * modPow(a, p - 1);
        return ans % (MOD);
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string S; cin >> S;
    ll res = 0;
    vector<vector<ll>> v_v(MOD);
    vector<ll> ruiseki;
    ruiseki.push_back(0);
    v_v[0].push_back(0);
    REP(i, S.size()) {
        //右から見る
        ll target = S[S.size() - (i+1)] - '0';
        ruiseki.push_back((ruiseki[i] + modPow(10,i)*target)%MOD);
        v_v[ruiseki[i+1]%MOD].push_back(i+1);
    }
    REP(i, MOD) {
        if(v_v[i].empty()) continue;
        for (int right = 0; right < v_v[i].size() - 1; right++) {
            for (int left = right + 1; left < v_v[i].size(); left++) {
                if (v_v[i][left] - v_v[i][right] >= 4) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 7752
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstring>/*The header <string> and
<string.h> does not contain the useful
function 'memset' and 'memcpy'.*/
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<(a<b?0:10)<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?

		Scanner sc = new Scanner(System.in);
		
		String str = sc.nextLine();
		char[] result = new char[str.length()];
		
		for(int i = 0; i < str.length(); i++) {
			for(int j = 0; j < 26; j++) {
				if(str.charAt(i) == DEFchar[j]) result[i] = ABCchar[j]; 
			}
		}
		
		String result_str = new String(result);
		
		System.out.println(result_str);
		
	}

	static final String ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	static final String DEF = "DEFGHIJKLMNOPQRSTUVWXYZABC";
	
	static final char ABCchar[] = ABC.toCharArray();
	static final char DEFchar[] = DEF.toCharArray();
}

Measured memory_bytes: 17976
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
// int dp[100005][4];
void solve();
signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t=1; 
    int tt = t;
    while (t--) {

        int n;
        cin>>n;
        int maxi;
        cin>> maxi;
        int weight[n],value[n];

        rep(i,0,n){
            cin>>weight[i]>>value[i];
        }
        int dp[n+1][maxi+1]={0};
        memset(dp,0,sizeof(dp));
        for(int i=0;i<=n;i++){
            for(int j=0;j<=maxi;j++){
                if(i==0||j==0){
                    dp[i][j]=0;
                }
                else if(j-weight[i-1]>=0){
                    dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]], dp[i-1][j]);
                }
                else{
                    dp[i][j]= dp[i-1][j];
                }
            }
        }

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

    }
    return 0;
}


Measured memory_bytes: 82524