akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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; }
const int INF = INT_MAX;
const int MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<pair<long, long>> p;
    for (long i = 1; i*i <= N; i++) {
        if (N % i == 0) {
            p.push_back(make_pair(i, N/i));
        }
    }
    ll ans = __LONG_LONG_MAX__;
    rep(i, p.size()) {
        ll d = (p[i].first - 1) + (p[i].second - 1);
        chmin(ans, d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;

int first,last;
char s[12];

struct mission
{
    char S[11];
    int time;
}A[100015];

struct
{
    void enqueue(mission x,int n)
    {

        A[last]=x;
        ++last;
        if(last==n+1)
            last=0;
    }

    mission dequeue(int n)
    {
       mission x=A[first];
       ++first;
       if(first==n+1)
        first=0;
       return x;
    }

}Myqueue;

int main()
{
    mission nt;
    int n,m,k,usedtime=0,ntime;
    first=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%s%d",A[i].S,&A[i].time);
    }
    last=n;

    while(first!=last)
    {
        nt=Myqueue.dequeue(n);
        if(nt.time>m)
        {
           usedtime+=m;
           nt.time=nt.time-m;
           Myqueue.enqueue(nt,n);
        }
        else if(nt.time<=m && nt.time>0)
         {
             usedtime+=nt.time;
             nt.time=0;
            printf("%s %d\n",nt.S,usedtime);
        }
    }
    return 0;
}

Measured memory_bytes: 3924
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (-par[x] < -par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
};
void solve() {
    int N;
    cin >> N;
    vector<long long> x(N);
    vector<long long> y(N);
    using pint = pair<int, int>;
    using Edge = pair<long long, pint>;
    vector<Edge> edges;
    vector<long long>ids(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j){
        return x[i] < x[j];
    });
    //x軸方向でソートして隣接している部分のみ
    for (int i = 0; i + 1 < x.size(); i++) {
        long long u = ids[i];
        long long v = ids[i + 1];
        edges.push_back(Edge(x[v] - x[u], pint(u, v)));
    }
    //y軸でソートして隣接している部分のみ
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return y[i] < y[j];
    });
    for (int i = 0; i + 1 < x.size(); i++) {
        long long u = ids[i];
        long long v = ids[i + 1];
        edges.push_back(Edge(y[v] - y[u], pint(u, v)));
    }
    //Kruskal
    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    long long res = 0;
    for (auto e : edges) {
        long long u = e.second.first;
        long long v = e.second.second;
        long long cost = e.first;
        if(uf.issame(u, v)) {
            continue;
        }
        uf.merge(u, v);
        res += cost;
    }
    cout << res << endl;
    return;
}

int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 8560
#include <stdio.h>
typedef long long int ll;
ll arr1[10000];
ll arr2[10000];
ll diff[10000];
ll N;
ll a = 0, b = 0;
int main() {
	scanf("%lld", &N);
	for (ll i = 0; i < N; ++i) {
		scanf("%lld", &arr1[i]);
	}
	for (int i = 0; i < N; ++i) {
		scanf("%lld", &arr2[i]);
		diff[i] = arr1[i] - arr2[i];
		if (diff[i] < 0) a+=(diff[i]*-1)/2;
		else b += diff[i];
	}
	if (a < b) printf("No");
	else printf("Yes");

}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main(void) {
    int a, b;
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    cout << (a <= 8 && b <= 8? "Yay!" : ":(") << "\n";
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    string t = s;
    reverse(s.begin(),s.end());
    int ans = 0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MaxN = 100000 + 5;

int N;
int A[MaxN][3];
int Dp[MaxN][3];

inline int max(int x, int y) { return x > y ? x : y; }

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j < 3; ++j)
      scanf("%d", &A[i][j]);
}

void solve() {
  for (int i = 1; i <= N; ++i)
    for (int j = 0; j < 3; ++j)
      for (int k = 0; k < 3; ++k)
        if (k != j)
          Dp[i][j] = max(Dp[i][j], Dp[i - 1][k] + A[i][j]);
  printf("%d\n", max(max(Dp[N][0], Dp[N][1]), Dp[N][2]));
}

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 100000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
vector<int> G[N + 5];

int dfs(int u, int f) {
    int cnt = 0;
    for(const int& v : G[u]) if(v != f) {
        cnt += (!dfs(v, u));
    }
    if(cnt >= 2) {
        puts("First");
        exit(0);
    }
    return cnt;
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif 

    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        static int u, v;
        scanf("%d%d", &u, &v);
        G[u].pb(v); G[v].pb(u);
    }
    if(!dfs(1, 0)) {
        puts("First");
    } else puts("Second");

    return 0;
}


Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

	int n;
	cin >> n;

	int ans = 0;
	for (int i = 0; i < n; i++){
		int a;
		cin >> a;
		ans += a - 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int max1 = 0;
		int max2 = 0;
		int max3 = 0;
		int tmp;
		
		for(int i = 0;i<10;i++){
			tmp = scan.nextInt();
			
			if(tmp>max1){
				max3=max2;
				max2=max1;
				max1=tmp;
			}else if(tmp>max2){
				max3=max2;
				max2=tmp;
			}else if(tmp>max3){
				max3=tmp;
			}
		}
		
		System.out.println(max1);
		System.out.println(max2);
		System.out.println(max3);
	    
	}
}

Measured memory_bytes: 26360
//ARC072F
#include<cstdio>
#include<vector>
#include<deque>
#include<algorithm>
#include<utility>
using namespace std;
int main(void){
	int N,L;
	double tep,ryo,c,d,dam=0;//dam=熱量
	deque<pair<double,double>> water;//温度,水量
	scanf("%d %d",&N,&L);
	N--;
	scanf("%lf %lf",&tep,&ryo);
	water.push_front(make_pair(tep,ryo));
	dam=tep*ryo;
	printf("%f\n",dam/L);
	for(;N>0;N--){
		double hai=0;
		scanf("%lf %lf",&tep,&ryo);
		dam+=tep*ryo;
		water.push_front(make_pair(tep,ryo));
		//水を排出する
		while(hai<ryo){
			c=water.back().first;
			d=water.back().second;
			hai+=d;
			dam-=c*d;
			water.pop_back();
		}
		dam+=c*(hai-ryo);
		water.push_back(make_pair(c,hai-ryo));
		//水を混ぜる
		while(water.size()>1&&water[0].first<=water[1].first){
			d=water[0].second+water[1].second;
			c=(water[0].first*water[0].second+water[1].first*water[1].second)/d;
			water.pop_front();water.pop_front();
			water.push_front(make_pair(c,d));
		}
		printf("%f\n",dam/(double)L);
	}
	return 0;
}

Measured memory_bytes: 16788
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int LowerBound(int[] xs, int value) {
        int lo = 0;
        int hi = xs.Length - 1;
        int lower = xs.Length;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (value <= xs[m]) {
                lower = Math.Min(lower, m);
                hi = m - 1;
            }
            else {
                lo = m + 1;
            }
        }
        return lower;
    }

    static int Len(int[] xs) {
        int n = xs.Length;
        var dp = new int[n + 1];
        for (int i = 0; i < dp.Length; i++)
            dp[i] = int.MaxValue;

        foreach (int x in xs) {
            int p = Array.BinarySearch(dp, x);
            if (p < 0) {
                dp[~p] = x;
            }
        }
        return LowerBound(dp, int.MaxValue);
    }

    static void Main() {
        int n = ReadInt();
        var xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = ReadInt();
        }

        var ans = Len(xs);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 10668
h, w = gets.split.map(&:to_i)
n = gets.to_i
as = gets.split.map(&:to_i)
table = Array.new(h, Array.new(w))
visited = Array.new(h, Array.new(w))
visited = {}

if w == 1
  dir = 'down'
else
  dir = 'right'
end
idx = 0
i = 0
j = 0
visited[0] = {}
visited[0][0] = 0

as[idx] -= 1
while (idx != n-1) || as[idx] != 0
  visited[i] ||= {}
  visited[i+1] ||= {}

  idx += 1 if as[idx] == 0
  as[idx] -= 1

  if dir == 'right'
    if j == w - 1
      i += 1
      dir = 'down'
      visited[i][j] = idx
    else
      j += 1
      visited[i][j] = idx
    end
  elsif dir == 'left'
    if j == 0
      i += 1
      dir = 'down'
      visited[i][j] = idx
    else
      j -= 1
      visited[i][j] = idx
    end
  elsif dir == 'down'
    if j == 0 && 0 == w - 1
      i += 1
      dir = 'down'
      visited[i][j] = idx
    elsif j == 0
      j += 1
      dir = 'right'
      visited[i][j] = idx
    else
      j -= 1
      dir = 'left'
      visited[i][j] = idx
    end
  end
end

h.times do |i|
  tmp = visited[i].dup
  tmp = visited[i-1].dup if tmp.nil?
  tmp2 = []
  w.times do |j|
    tmp2 << tmp[j] + 1
  end
  puts tmp2.join(' ')
end


Measured memory_bytes: 15516
#!/usr/bin/env python3
import sys


def solve(N: int, D: int):
    watch_range = 2 * D + 1

    people = 0
    while people * watch_range < N:
        people += 1

    print(people)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	
    int input;
	long long int count = 0;
	scanf("%d", &input);
	
    for (int i = 1; i <= input; i++){
		if (i % 3 == 0 && i % 5 == 0){
		}
        else if (i % 3 == 0){	
		}
        else if (i % 5 == 0){
		}
        else {count += i;}
	}
	printf("%lld\n", count);
	
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, c;
	cin >> n >> c;
	int grid[500][500];
	int color[30][30];
	int cnt[3][30] = {};
	
	for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) cin >> color[i][j];
	for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		cin >> grid[i][j];
		cnt[(i + j) % 3][grid[i][j] - 1]++;
	}
	
	
	int ans = 987654321;
	for (int x = 0; x < c; ++x) {
		for (int y = 0; y < c; ++y) {
			if (x == y) continue;
			for (int z = 0; z < c; ++z) {
				if (z == x || z == y) continue;
				int t = 0;
				for (int i = 0; i < c; ++i) {
					t += color[i][x] * cnt[0][i];
					t += color[i][y] * cnt[1][i];
					t += color[i][z] * cnt[2][i];
				}
				ans = min(t, ans);
			}
		}
	}
	cout << ans;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    map<int,int> m;
    int l = 0;
    rep(i,n) {
        cin >> a[i];
        m[a[i]]++;
        l = max(a[i],l);
    }
    bool can = true;
    if(l % 2){
        for(int i = 1; i < (l+1)/2; i++){
            if(m[i] > 0) can = false;
        }
        if(m[(l+1)/2] > 2) can = false;
        for(int i = (l+1)/2; i <= l; i++){
            if(m[i] < 2) can = false;
        }
    } else {
        for(int i = 1; i < l/2; i++){
            if(m[i] > 0) can = false;
        }
        if(m[l/2] != 1) can = false;
        for(int i = l/2 + 1; i <= l; i++){
            if(m[i] < 2) can = false;
        }
    }
    cout << (can? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d;
        if(a>b){
        d = a;
        a = b;
        b = d;
        }
        if(b>c){
        d = b;
        b = c;
        c = d;
        if(a>b){
            d = a;
            a = b;
            b = d;
            }
        }
        System.out.printf("%d %d %d\n",a,b,c);
    }
}


Measured memory_bytes: 26208
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

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

    int n, m;
    cin >> n >> m;
    if(n == m){
        COUT("Yes");
    }else{
        COUT("No");
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int n;

void solve() {
  if (n > 999) {
    cout << "ABD" << endl;
  } else {
    cout << "ABC" << endl;
  }
}

int main() {
  cin >> n;
  solve();
  return 0;
}


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

using namespace std;

int Edges[100];

int main() {
	int len;

	memset(Edges, 0, sizeof(Edges));
	for (int i = 0; i < 12; ++i) {
		cin >> len;
		++Edges[len - 1];
	}

	for (int i = 0; i < 100; ++i) {
		if (Edges[i] == 0) {
			continue;
		}
		if (Edges[i] % 2 != 0) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;

	return 0;
}



Measured memory_bytes: 3092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        abc: [i32; 3],
    }
    let mut abc = abc;
    let mut ans = 0;
    abc.sort();
    if abc[0] % 2 != abc[1] %2 && abc[0] % 2 != abc[2] % 2 {
        abc[1] += 1;
        abc[2] += 1;
        ans += 1;
    } else if abc[1] % 2 != abc[0] %2 && abc[1] % 2 != abc[2] % 2 {
        abc[0] += 1;
        abc[2] += 1;
        ans += 1;
    } else {
        abc[0] += 1;
        abc[1] += 1;
        ans += 1;
    }
    ans += abc[2] - (abc[0] + abc[1]) / 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


//(0,0)??????(n,n)????????????????????¢
void matrix_right_rotation(vector<vector<int>> &data, int n){
    vector<vector<int>> tmp = data;
    rep(i,n){
        rep(j,n){
            data[i][j] = tmp[n-j-1][i];
        }
    }
}
int main(){
    int n,m;
    while(cin>>n>>m&&(n||m)){
        vector<vector<int>> v(n,vector<int>(n));
        vector<vector<vector<int>>> p(4,vector<vector<int>>(m,vector<int>(m)));
        rep(i,n)rep(j,n)cin>>v[i][j];
        rep(i,m)rep(j,m)cin>>p[0][i][j];
        for(int k=1;k<4;k++){
            rep(i,m)rep(j,m)p[k][i][j] = p[k-1][i][j];
            matrix_right_rotation(p[k],m);
        }
        
        int y=INF,x=INF;
        rep(i,n-m+1){
            rep(j,n-m+1){
                rep(k,4){
                    bool f = true;
                    for(int ii=i;ii<i+m;ii++){
                        for(int jj=j;jj<j+m;jj++){
                            if(p[k][ii-i][jj-j]==-1)continue;
                            if(p[k][ii-i][jj-j]!=v[ii][jj])f = false;
                        }
                    }
                    if(f){
                        for(int ii=i;ii<i+m;ii++){
                            for(int jj=j;jj<j+m;jj++){
                                if(p[k][ii-i][jj-j]!=-1){
                                    if(ii<y || ii==y&&jj<x)y = ii, x = jj;
                                }
                            }
                        }
                    }
                }
            }
        }
        if(y==INF)cout<<"NA"<<endl;
        else cout<<x+1<<" "<<y+1<<endl;
    }
}

Measured memory_bytes: 3252
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
int n=read(),i=read();
write(n-i+1);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,x=mii()
arr=limii()
cnt=0

if arr[0]>x:
    cnt+=arr[0]-x
    arr[0]=x

for i in range(n-1):
    if arr[i]+arr[i+1]>x:
        cnt+=arr[i+1]+arr[i]-x
        arr[i+1]=x-arr[i]
print(cnt)

Measured memory_bytes: 88940
import fractions
A,B,C,D = map(int, input().split())

lcm = (C * D) // fractions.gcd(C, D)
print(B-A+1 - (B//C - (A-1)//C) - (B//D - (A-1)//D) + (B//lcm - (A-1)//lcm))


Measured memory_bytes: 5432
#include<iostream>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ll long long
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0'){
		s=(s<<1)+(s<<3)+(ch^48);
		ch=getchar();
	}
	return s*w;
}
int main()
{
	int n=read();
	cout<<n+n*n+n*n*n<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/


bool isPal(string s){
  int i=0,j=s.length()-1;
  while(i<j){
    if(s[i]==s[j]){
      i++,j--;
    }
    else
    {
      return false;
    }
    
  }
  return true;
}


signed main(){
  fast;
  //usefile;
  //test
  {
    string s;
    cin>>s;
    bool ok=1;
    ok&=isPal(s);
    int n=s.length();
    string s1=s.substr(0,n/2);
    ok&=isPal(s1);
    string s2=s.substr(n/2+1,n-(n/2+1));
    ok&=isPal(s2);
    // cout<<s1<<endl<<s2<<endl;
    if(ok)
      cout<<"Yes";
    else
    {
      cout<<"No";
    }
    
  }
  //time("");
  return 0;
}

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

int s2i(char a[7]){
    int i,k=0;
    for(i=0;a[i]!='\0';i++){
        k = k*10+(a[i]-'0');
    }
    return k;
}

int main(void){
    int a[128],b,c;
    int top=2,n;
    char str[7];
    scanf("%d",&a[0]);
    scanf("%d",&a[1]);
    while(scanf("%s",str)!=EOF){
        if(strcmp(str,"+")==0){
            b = a[top-1];
            c = a[top-2];
            a[top-2] = b+c;
            top--;
        }else if(strcmp(str,"-")==0){
            b = a[top-2];
            c = a[top-1];
            a[top-2] = b-c;
            top--;
        }else if(strcmp(str,"*")==0){
            b = a[top-1];
            c = a[top-2];
            a[top-2] = b*c;
            top--;
        }else{
            a[top] = s2i(str);
            top++;
        }
    }
    printf("%d\n",a[0]);
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

ll N, M;
vvll g;
ll dp1[110000], dp2[110000], ans[110000];

void dfs1(ll x, ll p = -1) {
    ll prod = 1;
    for(auto e : g[x]) {
        if(e == p) continue;
        dfs1(e, x);
        prod *= dp1[e];
        prod %= M;
    }
    dp1[x] = prod + 1;
    dp1[x] %= M;
}

void dfs2(ll x, ll p = -1) {
    if(p == -1) dp2[x] = 1;

    ll m = g[x].size();
    vll lprod(m, 1), rprod(m, 1);
    rep(i, m) {
        ll to = g[x][i];
        if(i-1 >= 0) lprod[i] = lprod[i-1];
        if(to == p) continue;
        (lprod[i] *= dp1[to]) %= M;
    }

    for(ll i = m-1; i >= 0; i--) {
        ll to = g[x][i];
        if(i+1 <= m-1) rprod[i] = rprod[i+1];
        if(to == p) continue;
        (rprod[i] *= dp1[to]) %= M;
    }

    rep(i, m) {
        ll to = g[x][i];
        if(to == p) continue;

        ll prod = dp2[x];
        if(i-1 >= 0) (prod *= lprod[i-1]) %= M;
        if(i+1 <= m-1) (prod *= rprod[i+1]) %= M;
        dp2[to] = (prod + 1) % M;
        dfs2(to, x);
    }
}

void dfs3(ll x, ll p = -1) {
    ans[x] = dp2[x];
    for(auto to : g[x]) {
        if(to == p) continue;
        ans[x] *= dp1[to];
        ans[x] %= M;
        dfs3(to, x);
    }
}

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

    cin >> N >> M;
    g.resize(N);
    rep(i, N-1) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs1(0);
    dfs2(0);
    dfs3(0);
    rep(i, N) cout << ans[i] << endl;
}


Measured memory_bytes: 19328
N,K = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
 
b = Array.new(N+1, 0)
a.map { |i| b[i-1] += 1 }
b.delete(0)

c = b.size

if c <= K
  puts 0
else
  puts b.sort.shift(c-K).inject(:+)
end


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

int main(){
	int a,b;
	
	cin >> a >> b;
	
	if(a<b) cout << "a < b\n";
	else if(a>b) cout << "a > b\n";
	else if(a==b) cout << "a == b\n"; 
	
	return 0;
}

Measured memory_bytes: 1124
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

static const int INFTY = (1 << 21);

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char> > a(H, vector<char>(W));
  vector<vector<int> > d(H, vector<int>(W, INFTY));
  queue<pair<int, int> > q;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        q.push(make_pair(i, j));
        d[i][j] = 0;
      }
    }
  }

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

  while (!q.empty()) {
    pair<int, int> u = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      if (u.first + dx[i] < 0 || u.first + dx[i] >= H || u.second + dy[i] < 0 || u.second + dy[i] >= W) continue;
      if (d[u.first + dx[i]][u.second + dy[i]] != INFTY) continue;
      d[u.first + dx[i]][u.second + dy[i]] = d[u.first][u.second] + 1;
      q.push(make_pair(u.first + dx[i], u.second + dy[i]));
    }
  }

  int ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (d[i][j] > ans) {
        ans = d[i][j];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int n;
	cin >> n;
	vector<lli> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	lli sum=0;
	bool even=true;
	lli absmin=1e18;
	for(int i=0; i<n; i++){
		sum += abs(a[i]);
		absmin = min(absmin, abs(a[i]));
		if(a[i] < 0){
			even = !even;
		}
	}
	if(even){
		cout << sum << endl;
	}else{
		cout << sum -2*absmin << endl;
	}
    return 0;
}

Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextLong()
  val m = sc.nextLong()
  val ab = (1..n).map { Pair(sc.nextLong(), sc.nextLong()) }

  val map = mutableMapOf<Long, Long>()
  for (abi in ab) {
    val a = abi.first
    val b = abi.second
    val tmp = map.getOrElse(a) { 0 }
    map.put(a, b + tmp)
  }

  val keys = map.keys.sorted()
  var count = 0L
  var ans = 0L
  for (key in keys) {
    val value = map.getOrElse(key) { 0 }
    if (count + value >= m) {
      val tmp = count + value - m
      val cost = key * (value - tmp)
      ans += cost
      break
    }
    count += value
    ans += value * key
  }

  println(ans)
}


Measured memory_bytes: 83620
import sys
import numpy as np

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 2

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

N, K = s[0]
p = s[1]
p.sort()
print(sum(p[:K]))


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int n;
	string in[100];
	map<string, bool> m;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> in[i];
	}
	for(int i = 0; i < n; i++){
		if(i != 0){
			if(m[in[i]] || in[i][0] != in[i-1][(int)in[i-1].size()-1]){
				cout << "No" << endl;
				return 0;
			}
		}
		m[in[i]]++;
	}

	cout << "Yes" << 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)

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> pic(H);
  rep(i,H){
    cin >> pic.at(i);
  }
  rep(i,W+2){
    cout <<"#";
  }
  cout << endl;
  rep(i,H){
    cout << "#" << pic.at(i) << "#" << endl;
  }
  rep(i,W+2){
    cout <<"#";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    from collections import Counter
    n=int(input())
    a=list(map(int,input().split()))

    q = Counter(a)
    a_cn = sum(x * (x - 1) // 2 for x in q.values())

    ans = []
    for x in a:
        ans.append(a_cn - q[x] + 1)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 30008
#include <cstdio>
using namespace std;
int main(){
	int n,scan,i;
	int cnt_max;
	scan = scanf("%d", &n);
	int a[n];
	for (i = 0;i < n && scan; i ++){
		scan = scanf("%d",&a[i]);
	}
	int k;
	int b[9];
	for (i = 0;i < 9; i ++){
		b[i] = 0;
	}
	for (i = 0;i < n; i ++){
		k = a[i] / 400;
		if (k > 8) k = 8;
		b[k]++;
	}
	int cnt = 0;
	for (i = 0;i < 8;i ++){
		if (b[i] > 0) cnt++;
	}
	if(cnt == 0){
		cnt = 1;
		cnt_max = b[8];
	} else {
		cnt_max = b[8] + cnt;
	}
	printf("%d %d",cnt,cnt_max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(3 * N);
    rep(i,3 * N){
        cin >> A[i];
    }
    sort(all(A));
    ll ans = 0;
    for (ll i = 0; i < N; i++){
        ans += A[3 * N - 2 - i * 2];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5624
class Main{

	public static void main (String[] args) {

		Main main = new Main();

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int x = sc.nextInt();
		int kyu = 0;

		if (x<600) {
			kyu=8;
		} else if (x<800) {
			kyu=7;
		} else if (x<1000) {
			kyu=6;
		} else if (x<1200) {
			kyu=5;
		} else if (x<1400) {
			kyu=4;
		} else if (x<1600) {
			kyu=3;
		} else if (x<1800) {
			kyu=2;
		} else if (x<2000) {
			kyu=1;
		}

		System.out.println(kyu);

		sc.close();;

	}
}


Measured memory_bytes: 35668
//              |----------------------------|
//              | BISMILLAHIR RAHMANIR RAHIM |
//              |----------------------------|

//      /\      ||  //      /\      /______  ||     ||
//     //\\     || //      //\\    ||------  ||     ||
//    //__\\    ||/|      //__\\   ||______\ ||_____||
//   //----\\   ||\|     //----\\   \-----|| ||-----||
//  //      \\  || \\   //      \\  ______|| ||     ||
// //        \\ ||  \\ //        \\ ------|/ ||     ||



#include<bits/stdc++.h>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define   ll            long long int
#define   mxx           200005
#define   pb            push_back
#define   rep(i,n)      for(int i=0;i<n;i++)
#define   rep1(i,n)     for(int i=1;i<=n;i++)
#define   mod           1000000007


int main()
{
    ll t,n,a,b,c,d,i,j,k,l,m,cnt;

    cin>>n;
    if(n==0)
        cout<<"1"<<endl;
    else
        cout<<"0"<<endl;

    return 0;
}





Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
d, g = map(int, input().split())
pc = []
for i in range(d):
    p, c = map(int, input().split())
    pc.append([p, c // 100])
g = g // 100
ans = 1000
for i in range(2 ** d):
    rem = g
    cost = 0
    for j in reversed(range(d)):
        if ((i >> j) & 1):
            p, c = pc[j]
            rem -= c + p * (j + 1)
            cost += p
    for j in reversed(range(d)):
        if  not ((i >> j) & 1):
            p, c = pc[j]
            p -= 1
            if rem >= p * (j + 1):
                rem -= p * (j + 1)
                cost += p
            else:
                while rem > 0:
                    rem -= j +1
                    cost += 1
                break
    if rem <= 0:
        ans = min(cost, ans)
print(ans)


Measured memory_bytes: 41712
import java.util.Scanner;

/**
 * https://abc053.contest.atcoder.jp/tasks/abc053_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		sc.close();
		
		int s = str.indexOf('A');
		int e = str.lastIndexOf('Z');
		
		System.out.println(e-s+1);

	}

}


Measured memory_bytes: 26668
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n,k;
vector<int> num;
void dfs(int t,int ret,vector<int> use){
	if(t==k)	s.insert(ret);
	else{
		for(int i=0;i<n;i++){
			if(use[i])	continue;
			use[i]=1;
			if(num[i]<10)	dfs(t+1,ret*10+num[i],use);
			else 	dfs(t+1,ret*100+num[i],use);
			use[i]=0;
		}
	}
}
int main(){
	while(true){
		cin>>n>>k;
		if(n==0)	return 0;
		s.clear();
		num.clear();
		for(int i=0;i<n;i++){
			int a;	cin>>a;
			num.push_back(a);
		}
		dfs(0,0,vector<int>(n,0));
		cout<<s.size()<<endl;
	}
}

Measured memory_bytes: 1332
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, D;

int main() {
  std::cin >> N >> D;

  std::cout << (N+2*D)/(2*D+1) << endl;

  return 0;
}

Measured memory_bytes: 3624
#068-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n,m=IL()
nl=[[] for i in range(n)]
for i in range(m):
    a,b=IL()
    nl[a-1].append(b-1)
for i in nl[0]:
    if n-1 in nl[i]:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 33816
a1, a2, a3 = list(map(int, input().split()))

diff1 = abs(a1 - a2)
diff2 = abs(a2 - a3)
diff3 = abs(a3 - a1)

diffs = [diff1, diff2, diff3]

diffs = sorted(diffs)

print(sum(diffs[:2]))



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[500005],y[500005],z[500005];

ll t,i,j;
ll sum;
ll p,q;
ll n,m,a,b,c,d,e,h,w;
int main (){
	cin >> a >> b >> c;
	cout << (c / a) * b << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
pair<pii,int> edges[125252];

const int N = 1<<17;
ll seg[2*N];
ll lazy[2*N];
const ll INF = 1ll<<60;
void push(int k){
    if(lazy[k] == INF)return;
    CHMIN(seg[k], lazy[k]);
    if(k<N-1){
        CHMIN(lazy[2*k+1], lazy[k]);
        CHMIN(lazy[2*k+2], lazy[k]);
    }
    lazy[k] = INF;
}
void add(int l, int r, ll v, int a, int b, int k){
    push(k);
    if(r<=a || b<=l)return;
    if(l<=a && b<=r){
        CHMIN(lazy[k], v);
        push(k);
        return;
    }
    int m = (a+b)/2;
    add(l,r,v,a,m,2*k+1);
    add(l,r,v,m,b,2*k+2);
    seg[k] = min(seg[2*k+1], seg[2*k+2]);
}
ll query(int l, int r, int a, int b, int k){
    push(k);
    if(r<=a || b<=l)return 1ll<<60;
    if(l<=a && b<=r)return seg[k];
    int m = (a+b)/2;
    return min(query(l,r,a,m,2*k+1), query(l,r,m,b,2*k+2));
}

int main(){
    scanf("%d%d",&n,&m);
    REP(i,m){
        int l,r,c;
        scanf("%d%d%d",&l,&r,&c);
        --l;
        edges[i] = make_pair(pii(l,r),c);
    }
    sort(edges, edges+m);
    fill(seg, seg+2*N, INF);
    fill(lazy,lazy+2*N,INF);
    int x = N-1;
    seg[x] = 0;
    while(x>0){
        x=(x-1)/2;
        seg[x] = 0;
    }
    REP(i,m){
        int l = edges[i].first.first;
        int r = edges[i].first.second;
        ll c = edges[i].second;
        ll v = query(l,r,0,N,0);
        add(l,r,v+c,0,N,0);
        // printf("v=%lld, c=%lld\n",v,c);
    }
    ll ans = query(n-1,n,0,N,0);
    printf("%lld\n", ans>=(1ll<<50) ? -1ll : ans);
    return 0;
}


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

int main() {
  int A,B,C,D ;
  cin >> A >> B >> C >> D ;
  if ( (A+B) > (C+D) ) {
    cout << "Left" << endl;
  }
  else if ( (A+B) < (C+D) ) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define repp(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define popcnt __builtin_popcount
#define all(v) v.begin(),v.end()
#define _Pi 3.1415926535
#define _MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int main(){
    string s; cin >> s;
    int r = 0;
    rep(i,s.size()){
        if(s[i] == '0') ++r;
    }
    cout << min(r,(int)s.size()-r) * 2 << endl;
    
    return 0;
}


Measured memory_bytes: 512
def f(u, i, d, t, vis):
    if vis[u]:
        return
    vis[u] = True
    z = t[u]

    c = 1
    for v in z:
        if vis[v]:
            continue
        if c == i:
            c += 1
        d[u].update({v: c})
        f(v, c, d, t, vis)
        c += 1


def main():
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(100000)
    n = int(input())
    t = [[] for _ in range(n + 1)]
    m = []

    for _ in range(n - 1):
        i, j = map(int, input().split())
        t[i].append(j)
        t[j].append(i)
        m.append([i, j])
    d = defaultdict(dict)
    vis = [False for _ in range(n + 1)]
    f(1, len(t[1]) + 1, d, t, vis)

    ans = ''
    if t.count([]) == n:
        ans += str(n - 1) + '\n'
    else:
        ans += str(max(len(i) for i in t)) + '\n'

    for (u, v) in m:
        ans += str(d[u][v]) + '\n'

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 94428
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >>n>>k;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int kyori=0;
  for(int i=0;i<n;i++){
    kyori+=min(abs(a[i]),abs(k-a[i]))*2;
  }
  cout<<kyori<<endl;
  return 0;
}

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

const int bas = 2e3 + 1, mod = 1e9 + 7;
const int Maxn = 2e5 + 5, N = bas * 2 + 5;

int n, ans, a[Maxn], b[Maxn], f[N][N];
int fac[N * 2], inv[N * 2];

inline int add(int &x, int y) {
    x += y; if(x >= mod) x -= mod;
}
inline void sub(int &x, int y) {
    x -= y; if(x < 0) x += mod;
}
inline int mul(int x, int y) {
    return (LL) x * y % mod;
}
inline int Pow(int a, int b = mod - 2) {
    int res = 1;
    for(; b; b >>= 1, a = mul(a, a))
        if(b & 1) res = mul(res, a);
    return res;
}
inline int C(int n, int m) {
    if(n < m || n < 0 || m < 0) return 0;
    return mul(fac[n], mul(inv[m], inv[n - m]));
}
void init(int n = 8e3) {
    inv[0] = fac[0] = 1;
    for(int i = 1; i <= n; ++i)
        fac[i] = mul(fac[i - 1], i);
    inv[n] = Pow(fac[n]);
    for(int i = n - 1; i; --i)
        inv[i] = mul(inv[i + 1], i + 1);
}
int main() {
    init();
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", a + i, b + i);
        ++ f[bas - a[i]][bas - b[i]];
    }
    for(register int i = 1; i <= bas * 2; ++i)
        for(register int j = 1; j <= bas * 2; ++j) {
            add(f[i][j], f[i - 1][j]);
            add(f[i][j], f[i][j - 1]);
        }
    for(int i = 1; i <= n; ++i) {
        add(ans, f[bas + a[i]][bas + b[i]]);
        sub(ans, C(2 * (a[i] + b[i]), 2 * a[i]));
    }
    printf("%d\n", mul(ans, Pow(2)));
    return 0;
}

Measured memory_bytes: 64640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        String[] line = scanner.nextLine().split(" ", n);
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(line[i]);
        }
        Arrays.sort(arr);

        int alice = 0;
        int bob = 0;
        for (int i = 0; i < n; i++) {
            int num = arr[n - 1 - i];
            if (i % 2 == 0) {
                alice += num;
            } else {
                bob += num;
            }
        }
        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int MAXN = 1e5 + 1;
vector<ii> adj[MAXN];
int color[MAXN];

void dfs(int u, int p) {
	for (auto e : adj[u]) if (e.first != p) {
		if (e.second & 1)
			color[e.first] = 1 - color[u];
		else
			color[e.first] = color[u];
		dfs(e.first, u);
	}
}

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

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n-1; i++) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		adj[u].push_back({v, w});
		adj[v].push_back({u, w});
	}

	for (int u = 1; u <= n; u++) color[u] = -1;
	color[1] = 0;
	dfs(1, 0);
	for (int u = 1; u <= n; u++) printf("%d\n", color[u]);
}


Measured memory_bytes: 9216