akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

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

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

int main(){
    string n;
    cin >> n;
    bool flag = 0;
    for(int i = 0; i < 3; i++){
        if(n[i] == n[i+1]) flag = 1;
    }
    if(flag) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int a,b;
  char c;
  
  scanf("%d %s %d",&a,&c,&b);
  
  if( c =='+'){
  printf("%d\n",a+b);
  } else {
  printf("%d\n",a-b);
  }
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{	
	int x,y,z;
	scanf("%d %d", &x, &y);
	if(x<y){
		printf("1");
	}
	else if(x>=y){
		z=(x-1)/y+1;
		printf("%d", z);
	} 
	return 0;
}

Measured memory_bytes: 3188
/**
 *    author:  [itmo] enot.1.10
 *    created: 03.04.2017 20:33:55       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

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

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 222;


int a[N];



int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    ll n;
    scanf("%lld", &n);
    /*if (n <= 100)
    {
        printf("%lld\n", 2 * n);
        forn(i, n) printf("%d %d%c", i + 1, i + 1, " \n"[i + 1 == n]);
        return 0;
    } */
    int last = 0;
    vi res;

    vi path;
    while (n > 0)
    {
        if (n & 1)
        {
            path.pb(2);
            n >>= 1;
        }
        else
        {
            path.pb(1);
            n -= 1;
        }
    }

    reverse(all(path));
    for (int x : path)
    {
        if (x == 1)
        {
            res.insert(res.begin(), ++last);
        }
        else
        {
            res.push_back(++last);
        }
    }

    printf("%d\n", 2 * last);
    forn(i, last) printf("%d ", i + 1);
    forn(i, last) printf("%d%c", res[i], " \n"[i + 1 == last]);
        
            
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 256
#18
import sys
c = [list(map(int,input().split())) for i in range(3)]

if not(c[0][0] - c[0][1] == c[1][0] - c[1][1] == c[2][0] - c[2][1]):
    print("No")
    sys.exit()
if not(c[0][0] - c[0][2] == c[1][0] - c[1][2] == c[2][0] - c[2][2]):
    print("No")
    sys.exit()
if not(c[0][1] - c[0][2] == c[1][1] - c[1][2] == c[2][1] - c[2][2]):
    print("No")
    sys.exit()
if not(c[0][0] - c[1][0] == c[0][1] - c[1][1] == c[0][2] - c[1][2]):
    print("No")
    sys.exit()
if not(c[0][0] - c[2][0] == c[0][1] - c[2][1] == c[0][2] - c[2][2]):
    print("No")
    sys.exit()
if not(c[1][0] - c[2][0] == c[1][1] - c[2][1] == c[1][2] - c[2][2]):
    print("No")
    sys.exit()
print("Yes")
    



Measured memory_bytes: 9292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
int main()
{
    scanf("%lld%lld",&n,&k);
    if(k&1)
    {
        n/=k;
        printf("%lld\n",n*n*n);
    }
    else
    {
        ll s=n/k;
        n=n/k+(n%k>=k/2);
        printf("%lld\n",n*n*n+s*s*s);
    }
}


Measured memory_bytes: 256
class B {
    static func solve() {
        let XY = readLine()!.split(separator: " ").map { Int($0)! }
        let X = XY[0]
        let Y = XY[1]
        for i in 0...X {
            if i * 2 + (X - i) * 4 == Y {
                print("Yes")
                return
            }
        }

        print("No")
    }
}

B.solve()


Measured memory_bytes: 8316
#include <iostream>
#include <string>

using namespace std;

int n;
int p[25];
int ans = 0;

bool maxfind(int a, int b, int c) {
	if (b > a && b < c||b>c&&b<a) return true;
	else return false;
}

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

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int numlane, numdata, i, swap;
	scanf("%d", &numlane);
	scanf("%d", &numdata);
	int lane[numlane], data[2];
	for (i = 0; i < numlane; i++) {
		lane[i] = i + 1;
	}
	for (i = 0; i < numdata; i++) {
		scanf("%d,%d", &data[0], &data[1]);
		swap = lane[data[0] - 1];
		lane[data[0] - 1] = lane[data[1] - 1];
		lane[data[1]-1] = swap;
	}
	for (i = 0; i < numlane; i++) {
		printf("%d\n", lane[i]);
	}
	return 0;
}

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

using namespace std;
using ll = long long;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

const int N = 1e6 + 100;

int n;
int m;
int arr[N];
int scnt[N];
int ssum[N];

int sc(int x) {
	x = min(x, N - 1);
	return scnt[max(x, 0LL)];
}
int ss(int x) {
	x = min(x, N - 1);
	return ssum[max(x, 0LL)];
}

int getcnt(int x) {
	int s = 0;
	for (int i = 0; i < n; ++i) {
		s += sc(x - arr[i]);
	}
	return s;
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		++scnt[arr[i]];
		ssum[arr[i]] += arr[i];
	}
	for (int i = N - 2; i >= 0; --i) {
		scnt[i] += scnt[i + 1];
		ssum[i] += ssum[i + 1];
	}
	int lef = 0;
	int rig = N - 2;
	while (rig - lef > 1) {
		int mid = (lef + rig) / 2;
		if (getcnt(mid) >= m) {
			lef = mid;
		} else {
			rig = mid;
		}
	}
	int x = lef;
	int answer = 0;
	for (int i = 0; i < n; ++i) {
		answer += sc(x - arr[i]) * arr[i] + ss(x - arr[i]);
	}
	int delta = getcnt(x) - m;
	assert(delta >= 0);
	answer -= delta * x;
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 18688
//Next Prime

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int X;cin >> X;
    bool flag = true;
    while(flag){
        if(X!=2){
            if(X%2==1){
                rep(i,2,X){
                    if(X%i==0){
                        X++;
                        flag = true;
                        break;
                    }
                    flag = false;
                }
            }else X++;
        }else flag =false;
    }
    cout << X << endl;
    return 0;
}

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

const ll MAX_S = 2510;

struct Edge {
    ll to, a, b;
    Edge(ll to, ll a, ll b): to(to), a(a), b(b) {}
};

struct Data {
    ll v, s, x;  // いまいる頂点v, 所持金s, 進んだ距離x
    Data(ll v, ll s, ll x): v(v), s(s), x(x) {}
    bool operator<(const Data& hoge) const {
        return x > hoge.x;
    }
};

int main() {
    ll n, m, s;
    cin >> n >> m >> s;
    chmin(s, MAX_S);
    
    vector<vector<Edge>> G(n);
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;  v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }

    vl c(n), d(n);
    rep(i, n) {
        cin >> c[i] >> d[i];
    }
    
    vvl dp(n, vl(MAX_S+10, INF));  // dp[v][s] : 頂点vに所持金sでいるための距離の最小値
    priority_queue<Data> Q;
    auto push = [&](ll v, ll s, ll x) {
        if(s < 0) {
            return;
        }
        if(dp[v][s] <= x) {
            return;
        }
        dp[v][s] = x;
        Q.emplace(v, s, x);
    };
    
    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    const ll sv = 0;
    push(sv, s, 0);
    while(!Q.empty()) {
        Data hoge = Q.top();  Q.pop();
        ll v = hoge.v, s = hoge.s, x = hoge.x;
        if(dp[v][s] != x) {
            continue;
        }
        ll ns = min(s + c[v], MAX_S);
        push(v, ns, x + d[v]);
        for(Edge e : G[v]) {
            push(e.to, s - e.a, x + e.b);
        }
    }

    exrep(i, 1, n-1) {
        ll ans = INF;
        rep(j, MAX_S+10) {
            chmin(ans, dp[i][j]);
        }
        out(ans);
    }

    re0;
}

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




int main()
{
	int n,m,count=0;
	int T[521],P[521],X[521];
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> T[i];
		count += T[i];
	}
	cin >> m;
	for(int j = 1; j <= m; j++)
	{
		cin >> P[j] >> X[j]; 
	}
	for(int k = 1; k <= m; k++)
	{
		int ans = X[k]-T[P[k]];
		cout << count+ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

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

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	ll a;
	double b;
	cin >> a >> b;

	ll ib = b * 100 + 0.5;

	a = a * ib;
	a = a / 100;
	
	cout << a << endl;
}
	

Measured memory_bytes: 3676
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

int main(){
	migmig;
	int a,b;
	cin>>a>>b;
	if(a<=9 and b<=9){
		cout<<a*b;
	}else cout<<-1;
	return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Read, Write, BufWriter};
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    let n = get();
    let k: usize = get();
    let a: Vec<i64> = (0 .. n).map(|_| get()).collect();
    let mut mi = 1 << 60;
    for i in 0 .. n - k + 1 {
        let hi = max(a[i + k - 1], 0);
        let lo = min(a[i], 0);
        mi = min(mi, hi - 2 * lo);
        mi = min(mi, 2 * hi - lo);
    }
    puts!("{}\n", mi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int w = scan.nextInt();//縦線の数
        int n = scan.nextInt();//横線の本数
        int[] amida = new int[w];
        int copy = 0;
        for(int i=0;i<amida.length;i++){
            amida[i] = i+1;
        }
        while(n-->0){
            String str = scan.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            copy = amida[a];
            amida[a] = amida[b];
            amida[b] = copy;
        }
        for(int s: amida){
            System.out.println(s);
        }
    }

}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(100005, 0);
	int maxi = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
		maxi = max(maxi, b[i]);
		for (int j = a[i]; j <= b[i]; ++j) c[j]++;
	}

	int ans = 0;
	for (int i = maxi; i > 0; --i) {
		if (i - 1 <= c[i]) {
			ans = i - 1;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	int x, y, res = 0;
	int g1[7] = {1, 3, 5, 7, 8, 10, 12}, g2[4] = {4, 6, 9, 11};

	cin >> x >> y;

	REP(i, 7) if(x == g1[i] || y == g1[i]) res++;
	if(res == 2){
		cout << "Yes" << endl;
		return 0;
	}

	res = 0;

	REP(i, 4) if(x == g2[i] || y == g2[i]) res++;
	if(res == 2){
		cout << "Yes" << endl;
		return 0;
	}

	if(x == 2 && y == 2){
		cout << "Yes" << endl;
		return 0;
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  unordered_map<int, int> uo;
  REP(i, N) {
    cin >> A[i];
    uo[A[i]]++;
  }
  int num = 0;
  for (auto s : uo) {
    num += s.second - 1;
  }
  if (num % 2 == 1) num++;
  cout << N - num << endl;
}

Measured memory_bytes: 7692
/*
  AOJ #1616 
  title:Taro's shopping
  @kankichi57301
 */
int n,m;
#include <stdio.h>
#include <stdlib.h>
#define max(x,y) (((x)>(y))?(x):(y))
int n,m;
int a[1001];

int comp( const void * a , const void * b ) {

  if( *( int * )a > *( int * )b ) {
    return 1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return -1;
}

int solve()
{
  int l,h,ret;
  
  if(a[0]+a[1]>m)
    return(0);
  for(l=ret=0,h=n-1;l<n-1;l++)
  {
    //printf(":%d %d\n",a[l],a[h]);
    for(;h>l;h--)
   
	if(a[h]+a[l]<=m)
	{
	  ret=max(ret,a[h]+a[l]);
	  break;
	}
  }
  return(ret);
}

int main()
{
  int i,ret;

  while(1)
    {
      scanf("%d %d",&n,&m);
      if(n==0 && m==0)
	break;
      for(i=0;i<n;i++)
	scanf("%d",&a[i]);
      qsort(a,n,sizeof(int),comp);
      
      ret=solve();
      if(ret==0)
	printf("NONE\n",ret);  
      else
	printf("%d\n",ret);
    }
  return(0);
}



Measured memory_bytes: 1992
import numpy as np
n,k = map(int,input().split())
ary = list(map(int,input().split()))
ary = np.array(ary)
dp = np.zeros(n,dtype=int)
for i in range(1,n):
    a = max(0,i-k)
    dp[i] = min(dp[a:i]+np.abs(ary[i]-ary[a:i]))
print(dp[n-1])

Measured memory_bytes: 22832
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int[] A = nextIntArray(N);
		Arrays.sort(A);
		int min = A[0],max = A[N-1];
		long sum = 0;
		int zero_i = Integer.MAX_VALUE;//0以上である最初のindex
		for(int i=0;i<N;i++) {
			if(zero_i == Integer.MAX_VALUE&&0<=A[i])zero_i=i;
			sum+=Math.abs(A[i]);
		}

		if(N == 2) {
			out.println(max-min);
			out.println(max+" "+min);
			return;
		}

		long res = 0;
		if(min<=0 && 0<=max) {//正数, 0, 負数のいずれか２つ以上存在
			res = sum;
		}else if(0 < min){//正数のみ
			res = sum - min - min;
		}else if(max < 0) {//負数のみ
			res = sum + max + max;
		}

		out.println(res);
		StringBuilder buf = new StringBuilder();

		sum = 0;
		if(min<=0 && 0<=max) {//正数, 0, 負数のいずれか２つ以上存在
			if(A[1]>=0) {
				sum = A[0]-A[N-1];
				buf.append(A[0] + " " +A[N-1]+System.getProperty("line.separator"));
			}else {
				sum = A[N-1]-A[0];
				buf.append(A[N-1] + " " +A[0]+System.getProperty("line.separator"));
			}
		}else if(0 < min){//正数のみ
			sum = A[0]-A[N-1];
			buf.append(A[0] + " " +A[N-1]+System.getProperty("line.separator"));
		}else if(0 > max) {//負数のみ
			sum = A[N-1]-A[0];
			buf.append(A[N-1] + " " +A[0]+System.getProperty("line.separator"));
		}
		for(int i=1;i<N-1&&i<zero_i;i++) {
			if(A[i+1]>=0) {
				if(i==N-2) {
					buf.append(sum+" "+A[i]+System.getProperty("line.separator"));
					sum = sum-A[i];
					continue;
				}
				buf.append(A[i]+" "+sum+System.getProperty("line.separator"));
				sum = A[i]-sum;
			}else if(A[i+1]<0) {
				buf.append(sum+" "+A[i]+System.getProperty("line.separator"));
				sum = sum-A[i];
			}
		}
		if(zero_i == 0)zero_i = 1;
		for(int i=zero_i;i<N-1;i++) {

			if(i == N-2) {
				buf.append(A[i]+" "+sum+System.getProperty("line.separator"));
				sum = A[i]-sum;
			}
			else {

				buf.append(sum + " " +A[i]+System.getProperty("line.separator"));
				sum = sum-A[i];
			}

		}

		out.println(buf);
	}
	private static int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}

	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}

}

Measured memory_bytes: 56248
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
ll n, cou[4];
double p[305][305][305];
double ev[305][305][305];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++){
		ll a;
		cin >> a;++cou[a];
	}
	//~ p[a][b][c] is the probability that you will get to that state
	//~ ev[a][b][c] is the expected value of number of moves to get to get rid of all the 0s, before getting to state a, b, c
	//~ memset(p, 0, sizeof(p));
	//~ memset(ev, 0, sizeof(ev));
	p[cou[1]][cou[2]][cou[3]] = 1;
	
	for (ll c = n; c >= 0; c--){
		for (ll b = n; b >= 0; b--){
			for (ll a = n; a >= 0; a--){
				if (a == 0 && b == 0 && c == 0)continue;
				if (a+b+c > n)continue;
				double p_waste = (double) (n-(a+b+c))/(double)n;
				double ev_waste = p_waste/(1-p_waste);
				ev[a][b][c] += ev_waste*p[a][b][c];
				//1
				if (a != 0){
					double p_pick = (double)a/(a+b+c);
					p[a-1][b][c] += p[a][b][c] *p_pick;
					ev[a-1][b][c] += ev[a][b][c] *p_pick;
				}
				//2
				if (b!= 0){
					double p_pick = (double)b/(a+b+c);
					p[a+1][b-1][c] += p[a][b][c]*p_pick;
					ev[a+1][b-1][c] += ev[a][b][c]*p_pick;
				}
				//3
				if (c!= 0){
					double p_pick = (double)c/(a+b+c);
					p[a][b+1][c-1] += p[a][b][c]*p_pick;
					ev[a][b+1][c-1] += ev[a][b][c]*p_pick;
				}
			}
		}
	}
	double ans = ev[0][0][0] + cou[1]+2*cou[2]+3*cou[3];
	cout << setprecision(20) << ans;
}


Measured memory_bytes: 438528
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>
#ifndef ATCODER_DSU_HPP
#define ATCODER_DSU_HPP 1

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
    struct dsu {
    public:
        dsu() : _n(0) {}
        dsu(int n) : _n(n), parent_or_size(n, -1) {}

        int merge(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            int x = leader(a), y = leader(b);
            if (x == y) return x;
            if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
            parent_or_size[x] += parent_or_size[y];
            parent_or_size[y] = x;
            return x;
        }

        bool same(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            return leader(a) == leader(b);
        }

        int leader(int a) {
            assert(0 <= a && a < _n);
            if (parent_or_size[a] < 0) return a;
            return parent_or_size[a] = leader(parent_or_size[a]);
        }

        int size(int a) {
            assert(0 <= a && a < _n);
            return -parent_or_size[leader(a)];
        }

        std::vector<std::vector<int>> groups() {
            std::vector<int> leader_buf(_n), group_size(_n);
            for (int i = 0; i < _n; i++) {
                leader_buf[i] = leader(i);
                group_size[leader_buf[i]]++;
            }
            std::vector<std::vector<int>> result(_n);
            for (int i = 0; i < _n; i++) {
                result[i].reserve(group_size[i]);
            }
            for (int i = 0; i < _n; i++) {
                result[leader_buf[i]].push_back(i);
            }
            result.erase(
                    std::remove_if(result.begin(), result.end(),
                                   [&](const std::vector<int>& v) { return v.empty(); }),
                    result.end());
            return result;
        }

    private:
        int _n;
        // root node: -1 * component size
        // otherwise: parent
        std::vector<int> parent_or_size;
    };

}  // namespace atcoder

#endif  // ATCODER_DSU_HPP

//#include "../library/fenwicktree.hpp"
//#include "../library/modint.hpp"
//#include "../library/segtree.hpp"

using namespace std;
using namespace atcoder;

void ADisjointSetUnion(std::istream& in, std::ostream& out) {
    int n, q;
    in >> n >> q;
    dsu d(n);
    while (q--) {
        int t, u, v;
        in >> t >> u >> v;
        if (t) out << d.same(u, v) << '\n';
        else d.merge(u, v);
    }
}

class Solver {
public:
    static void solve(std::istream& in, std::ostream& out) {
        return ADisjointSetUnion(in, out);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    Solver::solve(in, out);
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll inf = 1LL<<60;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n){
        if(n % 2){
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
    ll N,K; cin >>N>>K;
    vector<ll> binary(64,0); //1が立っている個数を数える
    vector<ll> A(N);
    REP(i,N){
        ll a; cin >> a;
        A[i] = a;
        int itr = 0;
        while(a){
            if(a & 1)binary[itr]++;
            a >>= 1;
            itr++;
        }
    }
    int itrk = 1;
    ll k_ = 1;
    while(k_ < K){
        k_ *= 2;
        itrk++;
    }
    vector<vector<ll> > equal(2,vector<ll>(itrk+1,-inf)), smaller(2,vector<ll>(itrk+1,-inf));
    equal[0][itrk] = 0;
    ll ans = 0;
    for(int itr = 63; itr >= itrk; itr--){
        ans += binary[itr] * mpow(2,itr);
    }
    bool smallerflag = false;
    ll nowk = K;

    for(int itr = itrk - 1; itr >= 0; itr--){
        if(nowk & (1LL << itr)){
            equal[1][itr] = equal[(nowk >> (itr+1)) & 1][itr+1] + (N - binary[itr]) * mpow(2,itr);
        }
        else{
            equal[0][itr] = equal[(nowk >> (itr+1)) & 1][itr+1] + binary[itr] * mpow(2,itr);
        }
    }

    for(int itr = itrk - 1; itr >= 0; itr--){
        if(nowk & (1LL<<itr)){
            smaller[1][itr] = max({smaller[1][itr+1], smaller[0][itr+1], }) + (N - binary[itr]) * mpow(2,itr);
            smaller[0][itr] = max({smaller[1][itr+1], smaller[0][itr+1], equal[(nowk >> (itr+1)) & 1][itr+1]}) + binary[itr] * mpow(2,itr);
        }
        else{
            smaller[1][itr] = max(smaller[1][itr+1], smaller[0][itr+1]) + (N - binary[itr]) * mpow(2,itr);
            smaller[0][itr] = max(smaller[1][itr+1], smaller[0][itr+1]) + binary[itr] * mpow(2,itr);

        }
    }

    ans += max({smaller[1][0], smaller[0][0], equal[1][0], equal[0][0]});
    cout << ans << endl;

    
}



Measured memory_bytes: 3984
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int C(int n) {
	return n * (n - 1) / 2;
}

int main()
{
	int N, K;
	cin >> N >> K;
	vector<pair<int, int>> ans;
	if (K > C(N - 1)) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			ans.push_back({ i + 1,j + 1 });
		}
	}
	for (int i = 0; i < N - 1; i++) {
		ans.push_back({ i + 1 ,N });
	}
	cout << ans.size() - K << endl;
	for (int i = K; i < ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}


Measured memory_bytes: 384
from queue import Queue
import copy

h, w = map(int, input().split())

f = [["#"] * (w + 2)] + \
    [list("#" + input() + "#") for i in range(h)] + \
    [["#"] * (w + 2)]
dxy = [(0,1), (0,-1), (1,0), (-1,0)]

d = [[-1]*(w+2) for i in range(h+2)]
for iy in range(h+2):
    for ix in range(w+2):
        if f[iy][ix] == '#':
            d[iy][ix] = 1000

ans = 0
for sy in range(h+2):
    for sx in range(w+2):
        if f[sy][sx] == '#':
            continue
        dist = copy.deepcopy(d)
        cnt = 0
        cnt_max = 0
        q = Queue()
        q.put([sy, sx])
        dist[sy][sx] = 0
        while q.qsize():
            y, x = q.get()
            cnt = dist[y][x]
            
            # print(sx, sy, x, y)
            cnt_max = max(cnt_max, cnt)
            for dy, dx in dxy:
                ny, nx = y + dy, x + dx
                if dist[ny][nx] == 1000:
                    continue
                if dist[ny][nx] == -1:
                    q.put([ny, nx])
                    dist[ny][nx] = cnt + 1
        # print(sx, sy, x, y, cnt)
        ans = max(ans, cnt_max)
print(ans)

Measured memory_bytes: 78144
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define MAX 5000000
#define LOG 100
#define KOK 333
using namespace std;

int n,a[N],res[N],tot,tot2,ans,pre[N],fac[N];

void Pre() {

	fac[0]=1;
	
	for(int i=1;i<=n;i++) {

		fac[i]=1ll*fac[i-1]*i%MOD;
	
		pre[i]=(pre[i-1]+a[i])%MOD;

	}

	res[n+1]=1;

	for(int i=n;i>=1;i--) {

		res[i]=1ll*res[i+1]*i%MOD;

	}

}

void solve2(int len) {

	tot2=(1ll*tot2+a[len]+a[n-len+1])%MOD;
	
	ans=(ans+1ll*tot2*fac[len]%MOD*res[len+2]%MOD)%MOD;

}

void solve1(int len) {

	if(len>n-2) return ;

	tot=(1ll*tot+pre[n-1]-pre[len]+MOD)%MOD;

	tot=(1ll*tot-(pre[n-1]-pre[n-len]+MOD)+MOD)%MOD;

	ans=(ans+1ll*tot*2%MOD*fac[len]%MOD*res[len+3]%MOD)%MOD;

}

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d",&n);

	for(int i=1;i<=n;i++) {

		scanf("%d",&a[i]);

	}
	
	Pre();

	for(int l=1;l<n;l++) {

		solve1(l);
		solve2(l);

	}

	ans=(1ll*ans+1ll*fac[n]*pre[n]%MOD)%MOD;

	printf("%d",ans);
}

Measured memory_bytes: 1792
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int a,b;
cin>>a>>b;
if(a>=13){
    cout<<b<<endl;
}else if(a>=6){
    cout<<b/2<<endl;
}else{
    cout<<0<<endl;
}
    

return 0;
}

Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void showVec(string name, std::vector<ll> x) {
  cerr << name << ": ";
  for (auto v : x) {
    cerr << v << " ";
  }
  cerr << endl;
}

void solve(ll N, std::vector<ll> a) {
  bool result = false;

  ll c0 = 0;
  ll c1 = 0;
  ll c4 = 0;
  rep(i, N) {
    if (a.at(i) % 4 == 0) {
      c4++;
    } else if (a.at(i) % 2 == 0) {
      c1++;
    } else {
      c0++;
    }
  }

  if (c1 == 0) {
    result = c4 + 1 >= c0;
  } else {
    result = c4 >= c0;
  }
  yesOrNo(result);
}

int main() {
  ll N;
  scanf("%lld", &N);
  std::vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 1152
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a = str(input())
b = str(input())
c = str(input())

print(a[0]+b[1]+c[2])


Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    int max = 0;
    int min = 1000;
    for (int i = 0; i < n; i++){
        if (a[i] <= min){
            min = a[i];
        }
        if (a[i] >= max){
            max = a[i];
        }
    }
    printf("%d\n", max - min);

    return 0;
}


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

int main() {
	long long a,b,c,d;
	d=0;
	cin >>a>>b>>c;
	d=4*a*b;
	if(c-a-b>0){
		if(d<(c-a-b)*(c-a-b)){
		cout <<"Yes";
	}
		else{
		cout <<"No";
	}
	}
	else{
		cout <<"No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    int t = min(10, D - i);
    vector<vector<int>> L(t, vector<int>(26, 0));
    for (int j = 0; j < t; j++){
      for (int k = 0; k < 26; k++){
        L[j][k] = c[k] * (i + j - last[k]);
      }
    }
    int mx = 0;
    int a = 0;
    for (int j = 0; j < 10000; j++){
      vector<int> next(t, 0);
      for (int k = 0; k < t; k++){
        next[k] = mt() % 26;
      }
      //calculate diff
      int diff = 0;
      for (int k = 0; k < t; k++){
        diff += s[i + k][next[k]];
        for (int l = k; l < t; l++){
          diff += L[l][next[k]] - (l - k) * c[next[k]];
          L[l][next[k]] = (l - k) * c[next[k]];
        }
      }
      if (diff > mx){
        mx = diff;
        a = next[0];
      }
    }
    cout << a + 1 << endl;
    last[a] = i;
  }
}

Measured memory_bytes: 3692
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] prices = new int[n];
        for(int i=0; i<n; i++){
            prices[i] = sc.nextInt();
        }

        Arrays.sort(prices);

        int max = 0;
        for(int i=0; i<k; i++) {
            max += prices[i];
        }
        System.out.print(max);
    }

}


Measured memory_bytes: 38948
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int dp[100005],i,ara[100005],n;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>ara[i];
    dp[1]=0;
    for(i=2;i<=n;i++)
    {
        dp[i]=dp[i-1]+abs(ara[i]-ara[i-1]);
        if(i>2)
            dp[i]=min(dp[i],dp[i-2]+abs(ara[i]-ara[i-2]));
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#define N 100005
using namespace std;
typedef long long ll;
int h, w, n;
int a[N], b[N];
int dr[3] = {-2, -1, 0};
int dc[3] = {-2, -1, 0};
int main() {
  cin>>h>>w>>n;
  set<pair<int, int>> cdd;
  set<pair<int, int>> bs;
  bs.clear();
  cdd.clear();
  for (int i = 1; i <= n; ++i) {
    cin>>a[i]>>b[i];
    bs.insert(make_pair(a[i], b[i]));
    for (int x = 0; x < 3; ++x) {
      for (int y = 0; y < 3; ++y) {
        if (a[i] + dr[x] >= 1 && a[i] + dr[x] <= h && a[i]+dr[x]+2 >= 1 && a[i]+dr[x]+2 <= h && b[i] + dc[y] >= 1 && b[i] + dc[y] <= w && b[i]+dc[y]+2>=1 && b[i]+dc[y]+2 <= w) {
          cdd.insert(make_pair(a[i]+dr[x], b[i]+dc[y]));
        }
      }
    }
  }
  int res[10];
  memset(res, 0, sizeof(res));
  ll has = 0;
 // cout<<"==="<<endl;
  for (auto v : cdd) {
    int cnt=0;
    int ax = v.first;
    int bx = v.second;
  //  cout<<ax<<" "<<bx<<endl;
    for (int x = 0; x < 3; ++x) {
      for (int y = 0; y < 3; ++y) {
        if (bs.find(make_pair(ax+x, bx+y)) != bs.end()) {
          cnt++;
        }
      }
    }
    res[cnt]++;
    if (cnt) has++;
  }
  ll tot=(ll)max(h-2,0)*(ll)max(w-2,0);
  cout<<tot-has<<endl;
  for (int i = 1; i <= 9; ++i) {
    cout<<res[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 47872
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>


int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(10);
    
    int n; std::cin >> n;

    std::vector<std::pair<int, int>> l(n);
    for(int i=0; i<n; i++)
        std::cin >> l[i].first >> l[i].second;
    
    long double sum = 0.0;

    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            long double x = l[i].first  - l[j].first;
            long double y = l[i].second - l[j].second;

            sum += std::sqrt(x*x + y*y);
        }
    }

    std::cout << sum  * 2.0 / (long double)n << std::endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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 (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int extractDigit(ll a, int digit, int base = 10) {
  rep(i, digit) a /= base;
  return a % base;
}

int main() {
  init();

  int N, M;
  cin >> N >> M;
  vi s(M), c(M);
  rep(i, M) cin >> s[i] >> c[i];

  rep(i, N == 1 ? 0 : N == 2 ? 10 : 100, N == 1 ? 10 : N == 2 ? 100 : 1000) {
    bool ok = true;
    rep(j, M) {
      if (extractDigit(i, N - s[j]) != c[j]) ok = false;
    }
    if (ok) {
      out(i);
      return 0;
    }
  }
  out(-1);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b = map(int, input().split())
    s = str(input())

    check = set()
    for dum in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
        check.add(dum)

    s = list(s)
    flag = 1
    for i in range(len(s)):
        if i == a:
            if s[i] != "-":
                flag = -1
                break

        else:
            if s[i] not in check:
                flag = -1
                break

    if flag == 1:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;
constexpr ll MOD = 1e9 + 7;


int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) {
        for (int i = 0; i < b; i++) {
            cout << a;
        }
        cout << endl;
        return 0;
    }else{
        for (int i = 0; i < a; i++) {
            cout << b;
        }
        cout << endl;
        return 0;
    }

}


Measured memory_bytes: 256
# require 'set'
N,M = gets.chomp.split(" ").map(&:to_i)
mat = []
M.times do
    mat << gets.chomp.split(" ").map(&:to_i)
end
S,T = gets.chomp.split(" ").map(&:to_i)

@graph = Array.new(N+1){[]}

# p [N,M]
# p mat
# p [S,T]

mat.each do |arr|
    u = arr[0]
    v = arr[1]
    @graph[u] << v
end
# p @graph
# (1..N).each do |n|

# next1 = []
=begin
@graph_2 = Array.new(N+1){Set.new}
(1..N).each do |n|
    @graph[n].each do |s1|
        @graph[s1].each do |s2|
            @graph[s2].each do |s3|
                if n != s3
                    @graph_2[n] << s3
                end
            end
        end
    end
end
=end
# p @graph_2
# next1.each do |n|
#     p n
# end
@visited = Array.new(N+1).map{Array.new(3)}
@q = []
@dist = Array.new(N+1).map{Array.new(3)}

def bfs(v)
    @visited[v][0] = true
    @dist[S][0]=0
    @q.push [v,0]

    while(node = @q.shift) do
        tmp,s = node
        # break if tmp == T and @visited[n][dist_tmp % 3]
        # p [tmp,s]
        break if tmp == T and s == 0

        nodes = @graph[tmp]
        nodes.each do |n|
            dist_tmp = @dist[tmp][s]
            # p [tmp,dist_tmp]
            if not @visited[n][(s+1) % 3]
                @visited[n][(s+1) % 3] = true
                @q.push [n, (s+1) % 3]
                @dist[n][(s+1) % 3] = dist_tmp + 1
            end
        end
    end
end

bfs(S)
# p @dist
# p @dist
# p @visited
puts @dist[T][0] ? @dist[T][0] / 3 : -1


Measured memory_bytes: 29180
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int c=0;
  
  for (int i=0; i < N; i++){
    int a,b;
    cin >> a >> b;
 
    c +=b-a+1;
  }
  
  cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){

	char c [200];
	int length,i;
	int j,z;
	int ans1 = 0,ans2 = 0;

	scanf("%s",c);

	length = strlen(c);

	for(i = length -1; i >= 2; i--){
		if(i % 2)
			continue;

		j = i / 2;
		for(z = 0; z < j; z++){
			if(c[z] != c[z+j])
				break;
		}
		
		if(z == j){
			printf("%d",i);
			return 0;
		}

	}

	printf("%d",2);
	return 0;
}

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

pair<ll, ll> burger[51];

ll rec(int n, ll x) {
	if (x == 0) return 0;
	ll ret;
	if (x == burger[n].first) {
		ret = burger[n].second;
	} else if (x - 1 <= burger[n - 1].first) {
		ret = rec(n - 1, x - 1);
	} else {
		ret = burger[n - 1].second + 1 + rec(n - 1, x - (2 + burger[n - 1].first));
	}
	return ret;
}

int main() {
	burger[0] = make_pair(1LL, 1LL);
	for(int i=1;i<=50;i++) {
		burger[i].first = 2 * burger[i - 1].first + 3;
		burger[i].second = 2 * burger[i - 1].second + 1;
	}

	ll N, X;
	cin >> N >> X;
	cout << rec(N, X) << endl;

	return 0;
}


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

int main() {
    int N;
    long long A, B;
    cin >> N >> A >> B;

    int prev;
    cin >> prev;
    long long res = 0;
    for(int i=1; i<N; ++i) {
        int X;
        cin >> X;
        res += min(A * (X - prev), B);
        prev = X;
    }
    cout << res << endl;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

struct unionfind {
    vector<i32> p, s;

    unionfind(i32 n): p(n), s(n, 1) {
        iota(begin(p), end(p), 0);
    }

    i32 find(i32 n) {
        return p[n] == n ? n : p[n] = find(p[n]);
    }

    void unite(i32 n, i32 m) {
        n = find(n), m = find(m);
        if (n == m) return;
        if (s[n] < s[m]) swap(n, m);
        s[n] += s[m];
        p[m] = n; 
    }

    i32 size(i32 n) {
        return s[find(n)];
    }

    bool same(i32 n, i32 m) {
        return find(n) == find(m);
    }
};

int main() {
    i32 n, m, k;
    cin >> n >> m >> k;
    unionfind can(n);
    vector<i32> friends(n);
    for (i32 i = 0; i < m; i++) {
        i32 a, b;
        cin >> a >> b, a--, b--;
        can.unite(a, b);
        friends[a]++, friends[b]++;
    }
    vector<i32> block(n);
    for (i32 i = 0; i < k; i++) {
        i32 c, d;
        cin >> c >> d, c--, d--;
        if (can.same(c, d)) block[c]++, block[d]++;
    }
    for (i32 i = 0; i < n; i++) {
        cout << (i == 0 ? "" : " ") << can.size(i) - friends[i] - block[i] - 1;
    }
    cout << endl;
}


Measured memory_bytes: 3968
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = scanner.nextInt();
        }
        Arrays.sort(c);
        if (n % 2 == 1) {
            for (int i = 0; i < n; i++) {
                if (c[i] % 2 != 0) {
                    System.out.println(0);
                    return;
                } else {
                    if (i == 0 && c[i] != 0) {
                        System.out.println(0);
                        return;
                    } else if (i != 0 && c[i] != ((i - 1) / 2 + 1) * 2) {
                        System.out.println(0);
                        return;
                    }
                }
            }
            System.out.println(new BigDecimal(2).pow((n - 1) / 2).remainder(new BigDecimal(1000_000_007)));
        } else {
            for (int i = 0; i < n; i++) {
                if (c[i] % 2 != 1 || c[i] != i / 2 * 2 + 1) {
                    System.out.println(0);
                    return;
                }
            }
            System.out.println(new BigDecimal(2).pow(n / 2).remainder(new BigDecimal(1000_000_007)));
        }

    }
}

Measured memory_bytes: 32712