akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long lli;

class UnionFind {
private:
  int n;
  int *par, *rank, *num;

public:
  UnionFind(int _n) : n(_n) {
    par = new int[n];
    rank = new int[n];
    num = new int[n];
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
      num[i] = 1;
    }
  }

  ~UnionFind() {
    delete [] par;
    delete [] rank;
    delete [] num;
  }

  int find(int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
  }

  int getNum(int x) {
    return num[find(x)];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(rank[x] < rank[y]) {
      par[x] = y;
      num[y] += num[x];
    } else {
      par[y] = x;
      num[x] += num[y];
      if(rank[x] == rank[y]) ++rank[x];
    }
  }
};

int main() {
  int N;
  while(cin >> N) {
    vector<pair<int, pair<int,int> > > v;
    for(int i = 0; i < N-1; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      v.push_back(make_pair(c, make_pair(a,b)));
    }
    sort(v.begin(), v.end());
    UnionFind uf(N);
    lli res = 0;
    for(int i = 0; i < v.size(); ++i) {
      int a = v[i].second.first;
      int b = v[i].second.second;
      int c = v[i].first;
      res += (lli)uf.getNum(a) * (lli)uf.getNum(b) * (lli)c;
      uf.unite(a,b);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 5704
def main():
    a, b, x = map(int, input().split())

    result = 0
    if a % x == 0:
        result = (b // x) - (a // x) + 1
    else:
        result = (b // x) - (a // x)

    print(result)

if __name__ == "__main__":
    main()

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

const ll INF = 1LL << 60;

ll N;
vector<ll> g[100100];

ll K = 0;
map<P, ll> mp; // 辺の色を保持

// 探索する頂点、親の色
void dfs(int cur, int par_color, int par = -1) {
    int color = 1;
    for (int i = 0; i < g[cur].size(); i++) {
        int next = g[cur][i]; 

        if (par == next) continue;

        if (par_color == color) color++;

        if (cur > next) {
            mp[P(next, cur)] = color;
        } else {
            mp[P(cur, next)] = color;
        }
        color++;
        // cout << "cur " << cur << " " << "next " << next << " color " << color << endl; 
        dfs(next, color - 1, cur);
    }
}

int main() {
    cin >> N;

    vector<P> v;
    rep(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);

        if (a > b) swap(b, a);
        v.push_back(P(a, b));
    }

    rep(i, N) {
        K = max(K, (ll)g[i].size());
    }
    cout << K << endl;

    dfs(0, 0);

    rep(i, v.size()) {
        // cout << v[i].first << " " << v[i].second << endl;
        cout << mp[v[i]] << endl;
    }
}

Measured memory_bytes: 18620
x, y = map(int, input().split())
B = 0
if x == -y:
    print(1)
elif x <= y:
    if x < 0 and y > 0:
        B = 1
    print(B + abs(abs(y)-abs(x)))
elif y < x:
    if x >= 0 and y <= 0:
        print(1 + abs(x+y))
    else:
        print(2 + abs(y-x))
"""
y = -x : print(1)

x <= y : print(y-x)
(ex: x=3, y=10)
(ex: x=-3, y=-1)
(ex: x=-3, y=1)

(ex: x=-3, y=50) : 

y < x : 2 + |y-x|
(ex: x=20, y=10)
(ex: x=20, y=-100)
(ex: x=-20, y=-100)

"""

Measured memory_bytes: 3064
n = int(input())
arr = list(map(int, input().split()))
mod = 10**9 + 7

# 愚直
# res = 0
# for i in range(n-1):
#     for j in range(i+1, n):
#         res += arr[i] * arr[j]
#         res %= mod

# print(res)

s = sum(arr)
res = 0
for a in arr:
    s -= a
    res += a * s
    res %= mod

print(res)


Measured memory_bytes: 31440
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define all(c) (c).begin(),(c).end()
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; q > i; i++)
using namespace std; 
int waru_kiriage(int a, int b){//切り上げ割り算をする
  return (a % b == 0 ? a / b : a / b + 1);
}
int abss(int a){//absと一緒
    return (a < 0 ? a * -1 : a);
}
int bai(int k){//引数の数だけ10倍する
  int ans = 1;
  for(int i = 0;k>i;i++){
    ans *= 10;
  }
  return ans;
}
int int_length(int k){//引数の桁数を調べる
  int ans = 0;
  for(int i = 1; k > i; i=i*10)ans++;
  return ans;
}
/*
確認ポイント
to_string() はC++11以降の実装;
length(),size()に括弧をつけ忘れてないか;
*/

int main() { 
    int n;
    bool ok = true;
    cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    rep(i,n - 1){
      if(s[i].at(s[i].size() - 1) != s[i + 1].at(0)){
        ok = false;
        break;
      }
      rep(j,i){
        if(s[i] == s[j]){
          ok = false;
        }
      }
      if(!ok){
        break;
      }
    }
    rep(i,n - 1){
      if(s[i] == s[n-1]){
        ok = false;
      }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0; 
} 

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

bool IsPalindrome(const std::string &str) {
  const size_t half_size = str.size() / 2;
  const size_t size = str.size();
  for (int i = 0; i < half_size; ++i) {
    if (str.at(i) != str.at(str.size() - (i + 1))) {
      return false;
    }
  }
  return true;
}

int main(int, char **) {
  std::string S;
  std::cin >> S;
  const size_t N = S.size();
  const size_t substr_size = (N - 1) / 2;
  const std::string first{S.substr(0, substr_size)};
  const std::string second{S.substr(((N + 3) / 2) - 1, substr_size)};
  if (IsPalindrome(first) && IsPalindrome(second) && IsPalindrome(S)) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
//#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    vector<P> v;
    char c;
    int a,b;
    while(cin>>a>>c>>b && a){
        v.pb(MP(b,a));
    }
    sort(v.rbegin(),v.rend());
    
    int n;
    while(cin>>n){
        int count=1;
        for(int i=0;i<v.size();i++){
            if(v[i].se==n){
                cout<<count<<endl;
                goto AWAY;
            }
            while(v[i].fi==v[i+1].fi){
                i++;
                if(v[i].se==n){
                    cout<<count<<endl;
                    goto AWAY;
                }
            }
            count++;
        }
        AWAY:;
    }
    
    return 0;
}



Measured memory_bytes: 3056
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;

  std::vector<long long> A(N);
  for (int i = 0; i < N; ++i)
    std::cin >> A[i];

  // Main

  long long val = 0;
  for (int i = 0; i < N; ++i) {
    if (i % 2 == 0)
      val += A[i];
    else
      val -= A[i];
  }
  // std::cout << val << std::endl;

  for (int i = 0; i < N; ++i) {
    std::cout << val << " ";
    val = -1 * (val - A[i]) + A[i];
  }

  // Output

  return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

const int mod = 1e9 + 7;
const int N = 500500;
const int M = 10000;
const int inf = 2e9;
int n, a[N], cnt, ans;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    fo(i, n) cin >> a[i];
    fo(i, n) if(a[i] == a[i-1]) {
            cnt++;
        } else {
            ans += cnt / 2;
            cnt = 1;
        }
    ans += cnt/2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){return null;}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない 異常時:文字列「error」を返す（できる？）
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return "error";}}
function Main() {
  var list = myconv(next(),6);
  var count = {
    "a":0,
    "b":0,
    "c":0
  };
  for(var i = 0; i < list.length; i++){
    count[list[i]]++;
  }
  if(Math.abs(count["a"] - count["b"]) <= 1
     && Math.abs(count["c"] - count["b"]) <= 1
    && Math.abs(count["a"] - count["c"]) <= 1){
     myout("YES");
  }else{
    myout("NO");
  }
}

Measured memory_bytes: 8268
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000+5;
const int p=1e9+7;
typedef long long ll;
#define lowbit(x) (x&-x)
ll c[maxn<<1];
ll a[maxn],n,k;
void modify(int x,int d)
{
	for(x;x<=3000;x+=lowbit(x))c[x]+=d;
}

ll getsum(int x)
{ll sum=0;for(x;x;x-=lowbit(x))sum+=c[x];return sum;}

int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	ll ans=0;
	for(int i=n;i>=1;i--)
	{
		ans=(ans+getsum(a[i])*k)%p;
		modify(a[i]+1,1);
	}
	ll tmp=(k-1)*k/2%p;
	for(int i=1;i<=n;i++)
	{
		ans=(ans+getsum(a[i])*tmp)%p;
	}
	cout<<ans;
	return 0;
} 

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++) {
        cout << (char)('A' + (s.at(i) - 'A' + n) % 26);
    }
    cout << endl;
}

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

int main() {
 int N, M;
  cin >> N >> M;
  vector<vector<int>> S(M, vector<int>(2));
  for (int i = 0; i<M; i++){
     for (int j = 0; j<2; j++){
       cin >> S.at(i).at(j);
     }
  }//行列完成
   for (int k = 0; k<N; k++){
      int counter = 0;
   for (int i = 0; i<M; i++){
     for (int j = 0; j<2; j++){
       if(S.at(i).at(j)==k+1){
         counter += 1;
       }
     }
   }
     cout << counter << endl;
   }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
max(A)
min(A)
CHE = list(range(min(A), max(A)+1))
#print(CHE)

RES = 0
PP = []

for n in CHE:
    for i in A:
        i = int(i)
        RES += (i-n)**2
    PP.append(RES)
    RES = 0
#print(min(PP))
print(min(PP))

Measured memory_bytes: 3064
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

ans = 0
for i in range(N):
    if A[i] >= B[i]:
        ans += B[i]
    else:
        if A[i + 1] >= (B[i] - A[i]):
            A[i + 1] -= (B[i] - A[i])
            ans += B[i]
        else:
            ans += A[i] + A[i + 1]
            A[i + 1] = 0

print(ans)




Measured memory_bytes: 19156
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a * 500 + b * 100 + c * 50 == X:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

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

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char anko = 'A' - 'a';
  cout << char(a[0] + anko) << char(b[0] + anko) << char(c[0] + anko) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n,m;
int main () {
n=read();
m=read();
if(n>m)swap(n,m);
if(n==1){
   if(m==1)puts("1");
   else printf("%d\n",m-2);
}
else printf("%lld\n",1ll*(n-2)*(m-2));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<math.h>

int judge(int x,int y){
    if((x+y)%2==0){
        return 0;
    }
    else{
        return 1;
    }
}

int main(){
    char d[2]={'#','.'};
    while(true){
        int a,b;
        cin>>a>>b;
        if(a==0 & b==0)break;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                int key=judge(i,j);
                cout<<d[key];
            }
        cout<<endl;
        }
    cout<<endl;
    }
return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
    long long N;
    cin >> N;
    pair<long long, long long> task[N];
    for(int i=0; i<N; i++){
        cin >> task[i].second >> task[i].first;
    }
    sort(task,task+N);
    long long used = 0;
    for(int i=0; i<N; i++){
        used += task[i].second;
        if(used > task[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

vector<int> tov(int N) {
    vector<int> ret;
    for (int i = 0; i < 4; ++i) {
        ret.push_back(N % 10);
        N /= 10;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

int main() {
    vector<vector<int>> table(10, vector<int>(10));
    for (auto &v : table) {
        for (auto &e : v) {
            cin >> e;
        }
    }

    auto calc_check = [&](vector<int> v) {
        int pre = 0;
        for (int i = 0; i < 4; ++i) {
            pre = table[pre][v[i]];
        }
        return pre;
    };

    auto check = [&](vector<int> v) {
        int pre = 0;
        for (int i = 0; i < 5; ++i) {
            pre = table[pre][v[i]];
        }
        return pre == 0;
    };

    int ans = 0;
    for (int id = 0; id < 10000; ++id) {
        vector<int> v = tov(id);
        v.push_back(calc_check(v));

        bool bad = false;
        for (int i = 0; i < 5; ++i) {
            int pre = v[i];
            for (int d = 0; d < 10; ++d) {
                v[i] = d;
                if (d != pre && check(v)) bad = true;
            }
            v[i] = pre;
        }

        for (int i = 0; i < 4; ++i) {
            if (v[i] == v[i + 1]) continue;
            swap(v[i], v[i + 1]);
            if (check(v)) bad = true;
            swap(v[i], v[i + 1]);
        }

        if (bad) ++ans;
    }

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



Measured memory_bytes: 3164
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN + 1];
int head, tail, n;

void enqueue(P x){
	Q[tail] = x;
	if (tail + 1 == LEN){
		tail = 0;
	}else{
		tail++;
	}
}

P dequeue(){
	P x = Q[head];
	if (head + 1 == LEN){
		head = 0;
	}else{
		head++;
	}
	return x;
}


int main(){
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	for (i = 1; i <= n; i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1;
	tail=i;
	u.t = 0;
	while (head!=tail){
		if (Q[head].t > q){ 
			Q[head].t -= q; 
			u.t += q;
			enqueue(dequeue());
		}
		else if (Q[head].t <= q){
			u.t += Q[head].t;
			strcpy(u.name, Q[head].name);
			dequeue();
			printf("%s %d\n",u.name,u.t);
		}
	}

	return 0;
}

Measured memory_bytes: 10764
#include<cstdlib>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = (int)1e5 + 10;

int a,b;

int gcd(int x,int y){
    return x==0 ? y : gcd(y%x,x);
}

void work(){
    scanf("%d%d",&a,&b);
    printf("%d\n",gcd(a,b));
}

int main(){
    work();
    return 0;
}



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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
	int n;
	int now,tim;
	int c[499],s[499],f[499];
	cin>>n;
	REP(i,n-1){
		cin>>c[i]>>s[i]>>f[i];
	}
	REP(i,n){
		now=i;tim=0;
		//cerr<<i<<"Sta:\n";
		while(now!=n-1){
			tim=(tim+f[now]-1)/f[now];
			tim*=f[now];
			if(tim<s[now])tim=s[now];
			tim+=c[now];
			now++;
			//cerr<<now<<"Sta. now!\n"<<tim<<"now!\n";
		}
		cout<<tim<<"\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll n, m;

struct edge
{
  pair<ll, ll> to;
  ll cost;
  edge() {}
  edge(pair<ll, ll> to, ll cost) : to(to), cost(cost){};
};
ll dijkstra(pair<ll, ll> s, map<pair<ll, ll>, vector<edge>> &g)
{
  priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> q;
  map<pair<ll, ll>,ll> dist;
  dist[s] = 1;
  q.push({0, s});

  while (!q.empty())
  {
    pair<ll, pair<ll, ll>> p = q.top();
    q.pop();
    pair<ll, ll> v = p.second;
    if (dist[v] < p.first)
      continue;
    rep(i, g[v].size())
    {
      edge e = g[v][i];
      if(dist[e.to]==0)dist[e.to]=INF;
      if (dist[e.to] > dist[v] + e.cost)
      {
        dist[e.to] = dist[v] + e.cost;
        q.push({dist[e.to], e.to});
      }
    }
  }
  pair<ll, ll> pp={n-1,-1};
  return dist[pp];
}
int main()
{
cin >> n >> m;
map<pair<ll, ll>, vector<edge>> g;
set<ll> s[n];
rep(i, m)
{
  ll a, b, c;
  cin >> a >> b >> c;
  pair<ll, ll> p = {b - 1, c};
  g[{a - 1, c}].emplace_back(p, 0);
  p = {a - 1, c};
  g[{b - 1, c}].emplace_back(p, 0);
  s[a-1].insert(c);
  s[b-1].insert(c);
}
rep(i,n){
  for(auto c:s[i]){
    pair<ll, ll> p = {i , c};
    g[{i , -1}].emplace_back(p, 1);
    p = {i , -1};
    g[{i , c}].emplace_back(p, 0);
  }
}
pair<ll, ll> pp={0,-1};
cout << dijkstra(pp,g)-1 << endl;
return 0;
}

Measured memory_bytes: 147376
#define _USE_MATH_DEFINES

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	double a, b, c;

	double S, L, h;

	cin >> a >> b >> c;

	S = 0.5*a*b*sin(c*M_PI/180);

	L = a + b + sqrt((a*a) + (b*b) - (2 * a*b*cos(c*M_PI / 180)));

	h = b*sin(c*M_PI/180);

	printf("%lf\n%lf\n%lf\n", S, L, h);

	return 0;
}

Measured memory_bytes: 3404
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[5],flag=0,n;
  
  for(int i=0;i<5;i++)
  {
      cin>>n;
      if(n==0)
        flag=i;
  }
  cout<<flag+1;
  
 return 0; 
}

Measured memory_bytes: 3620
//API???????????????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
	final static int Code = 5;
	
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		char[] A, B;
		//??\?????¨??¨??????char???????????£??\
		A = br.readLine().toCharArray();
		B = br.readLine().toCharArray();

		//A??????????????????????????????
		if(A.length < B.length) return;

		int t = 0;
		int p = 0;
		int BN = search(Code, B.length);

		for(int i = 0; i < B.length; i++){
			t = t * Code + A[i];
			p = p * Code + B[i];
		}

		System.out.print(Print(t ,p, A, B, BN));

		return;
	}

	public static int search(int x, int n){
		if(n == 0) return 1;
		int ret = search(x * x, n / 2);
		//??????????????????AND?????????
		if((n & 1) == 1) ret *= x;
		return ret;
	}

	public static String Print(int t, int p, char[] A, char[] B, int BN){
		StringBuilder sb = new StringBuilder();

		//t??¨p?????????????????????????????¨???
		if(t == p) sb.append("0\r\n");
		for(int i = 1; i < A.length - B.length + 1; i++){
			t = t * Code + A[i + B.length - 1] - A[i - 1] * BN;
			if(t == p) sb.append(i + "\r\n");
		}

		return sb.toString();
	}
}

Measured memory_bytes: 86288
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(ll x, ll y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) {
        return root(x) == root(y);
    }
    ll root(ll x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(ll x) {
        return -data[root(x)];
    }
};

ll gcd(ll a, ll b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

ll lcm(ll a, ll b)
{
    ll temp = gcd(a, b);
    
    return temp ? (a / temp * b) : 0;
}

int main()
{
    string s;
    cin >> s;
    int n = (int)s.length();
    int start = ((n % 2) == 1) ? n/2+1 : n/2;
    ll c = 0;
    for(int i = 0;i < start;i++)
    {
        if(s[i] == 'p')
        {
            c--;
        }
    }
    for(int i = start;i < n;i++)
    {
        if(s[i] == 'g')
        {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main (int argc, char **argv){
	char c[5]={"0"};
	scanf("%s",c);
	for(int i=1;i<4;i++){
		if(c[0]==c[i]){
			if(c[0]==c[i+1]){
			   
				puts("No");
				return 0;
			}
			switch(i){
			case 1 :if(c[2]==c[3]) {puts("Yes");return 0;}
			case 2 :if(c[1]==c[3]) {puts("Yes");return 0;}
			case 3 :if(c[2]==c[1]) {puts("Yes");return 0;}
			}
			
		}
	}
	puts("No");
	return 0;
}



Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

string s;
bool used[30];

int main() {
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	REP(i, s.size()) {
		used[s[i] - 'a'] = true;
	}
	REP(i, 26) {
		if (used[i] == false) {
			cout << s << (char)(i + 'a') << endl;
			return 0;
		}
	}
	for (int i = 25; i >= 0; i--) {
		if (i == 25) {
			used[s[i] - 'a'] = false;
		}
		else {
			REP(j, 26) {
				if (used[j] == false && s[i] - 'a' < j) {
					REP(k, i)cout << s[k];
					cout << (char)(j + 'a') << endl;
					return 0;
				}
				if (j == 25) {
					used[s[i] - 'a'] = false;
				}
			}
		}
	}
}

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

char ans[110][110];
int A,B;

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

    printf("100 100\n");
    for(int i = 0; i < 50; i++)
    {
        for(int j = 0; j < 100; j++)ans[i][j] = '.';
        for(int j = 0; j < 100; j++)ans[i + 50][j] = '#';
    }

    A--;
    B--;
    int y = 1,x = 1;
    for(int i = 0; i < B; i++)
    {
        ans[y][x] = '#';
        x += 2;
        y += (x / 100) * 2;
        x %= 100;
    }
    y = 1,x = 1;
    for(int i = 0; i < A; i++)
    {
        ans[y + 50][x] = '.';
        x += 2;
        y += (x / 100) * 2;
        x %= 100;
    }
    for(int i = 0; i < 100; i++)
    {
        for(int j = 0; j < 100; j++)
        {
            printf("%c",ans[i][j]);
        }printf("\n");
    }printf("\n");
    return 0;
}


Measured memory_bytes: 256
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)-1>i:
  lis+=[gcd(lis[i],lis[i+1])]
  i+=2
print(lis[-1])

Measured memory_bytes: 14224
/*********************************
Date: Fri Mar  9 13:29:05 CST 2018
Author: ycl
*********************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <sstream>
using namespace std;
#define CL(a) memset(a,0,sizeof(a))
#define Cl(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define INF 0x7fffffff
#define LL long long
const int MOD = 1e9 + 7;
const int maxn = 1e5 + 100;
LL pos[maxn];
int vs[maxn];
int deg[maxn];
struct Node
{
	int r,d;
	Node(int r=0,int d=0):r(r),d(d)
	{
		
	}
};
vector<Node> G[maxn],G2[maxn];
int ans=1;
void dfs(int );
void dfs2(int u)
{
	for (int i=0;i<G2[u].size();++i){
		int v = G2[u][i].r;
		if (!vs[v]){
			vs[v]=1;
			pos[v] = pos[u]-G2[u][i].d;
			dfs(v);
		}
		else{
			if (pos[v] != pos[u]-G2[u][i].d)
				ans=0;
		}
	}
}
void dfs(int v)
{
	for (int i=0;i<G[v].size();++i){
		int u =G[v][i].r;
		if (!vs[u]){
			vs[u]=1;
			pos[u]=pos[v]+G[v][i].d;
			dfs(u);
		}
		else{
			if (pos[u] != pos[v]+G[v][i].d)
				ans=0;
		}
	}
	dfs2(v);
}
int main()
{
	int n,m,l,r,d;
	scanf("%d%d",&n,&m);
	for (int i=0;i<m;++i){
		scanf("%d%d%d",&l,&r,&d);
		G[l].push_back(Node(r,d));
		G2[r].push_back(Node(l,d));
		++deg[r];
	}
	int cnt=0;
	for (int i=1;i<=n;++i){
		if (!vs[i]){
			vs[i]=1;
			pos[i]=0;
			dfs(i);
		}
		if (!ans) break;
	}
	if (ans)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}


Measured memory_bytes: 17280
import java.util.Scanner;

public class Main 
{
	static int n,m;
	static int[] a, b;
	static int[] par; //parent of an element
	static int[] rank; //rank of an element
	static long[] size;
	static long score = 0;
	
	static void union(int a, int b)
	{
		//when union-ing 2 different elements, the root of one of the two elements
		//becomes the parent of the other element's root.
		int ra = root(a);
		int rb = root(b);
		if(ra == rb)return;
		
//		System.out.println("size was " + size[ra] + " " + size[rb]);
		long lost1 = ((size[ra]*size[ra])-(size[ra]))/2;
		long lost2 = ((size[rb]*size[rb])-(size[rb]))/2;
//		System.out.println("lost " + lost1 + " " + lost2);
		score += -lost1 -lost2;
		size[ra] = size[ra]+size[rb];
		size[rb] = size[ra];
		score += (((size[ra]*size[ra])-(size[ra]))/2);
//		System.out.println("size now " + size[ra]);
		
		if(rank[ra] >= rank[rb])
		{ //a's root is higher ranked means it should be the parent
			par[rb] = ra;
			if(rank[ra] == rank[rb])rank[rb]++; //if they're same rank,
			//ra's height is now increased due to having rb as a child, so ra's rank is increased
		}
		else par[ra] = rb;
	}
	
	static int root(int i) //alternate name: root()
	{ 
		//unless this is the root (parent == self), walk up the parents and find the root
		//then set that root as the direct parent of this node (path compression)
		if(par[i] != i)
			par[i] = root(par[i]); //path compression
		return par[i];
	}
	
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		par = new int[n];
		rank = new int[n];
		size = new long[n];
		
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			size[i]=1;
		}
		
		for(int i = m-1; i >= 0; i--)
		{
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
//			union(a[i],b[i]);
//			System.out.println("pairs now: " + score);
		}
		
//		if(true)
		long ln = n;
		long init = (ln*(ln-1))/2;
		long[] note = new long[m];
		for(int i = 0; i < m; i++)
		{
//			System.out.println("Consider " + i + ": " + a[i] + " " + b[i]);
//			System.out.println("debug " + (init-score));
			note[i] = init-score;
			union(a[i],b[i]);
		}
//		System.out.println("debug " + (init-score));
		
		for(int i = m-1; i >= 0; i--)
		{
			System.out.println(note[i]);
		}
	}

}


Measured memory_bytes: 95920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 8;

int checkV(int n, int h[N]){
    int ans = 0;
    for(int i = 1, cnt = 0; cnt < N; i *= 10, cnt++) ans += (h[(N - cnt - 1 + n) % N] * i);
    //debug
    //REP(i, N) cout <<h[(i + n) % N] <<" "; cout <<endl;
    //cout <<ans <<endl;
    return ans;
}

int main(){
    string inp;
    while(getline(cin, inp)){
        int h[N] = {4, 1, 4, 1, 2, 1, 2, 1};
        stringstream ss(inp);
        vector<int> c(N); REP(i, N) ss >>c[i];
        vector<int> ansv(N);

        int v = 1; REP(i, N) v += c[i];
        int ans = INF;
        REP(i, N){
            int sum = 0;
            REP(j, N) sum += max(0, c[j] - h[(i + j) % N]);
            if(sum < ans || (ans == sum && checkV(i, h) < v)){
                REP(k, N) ansv[k] = h[(k + i) % N];
                //debug
                //REP(k, N) cout <<ansv[k] <<" "; cout <<endl;
                v = checkV(i, h);
                ans = sum;
            }
        }
        cout <<ansv[0];
        FOR(i, 1, N) cout <<" " <<ansv[i];
        cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    d = abs(b-a);
    e = abs(c-a);
    if(d<e){
        printf("A\n");
    }
    else{
        printf("B\n");
    }
    return 0;
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18



int main(){ 

	int n, p;

	while (1) {
			cin >> n >> p;

			if (n == 0 && p == 0)break;

			vector<int>hand(n, 0);

			int turn = 0;
			int wan = p;

			while (true) {
				if (wan > 0) {
					wan--;
					hand[turn]++;

					if (hand[turn] == p) {
						break;
					}
				}
				else {
					wan += hand[turn];
					hand[turn] = 0;
				}

				turn = (turn + 1) % n;
			}

			cout << turn << endl;
		}

	return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
set<string> S;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 19216
import numpy as np

N = int(input())
Vlist = np.array(list(map(int, input().split())))
Clist = np.array(list(map(int, input().split())))
diff_list = []

sum = 0
for i in range(0, N):
    diff = Vlist[i] - Clist[i]
    if diff > 0:
        sum = sum + diff

print(sum)

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
using P = pair<int, int>;

signed main(){

  int n, m; cin >> n >> m;
  vector<P> v(m);
  for(int i = 0; i < m; i++){
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(),v.end(),[&](P x, P y){
    if(x.second == y.second) return x.first < y.first;
    return x.second < y.second;
  });

  int ans = 0, right = -1;
  for(int i = 0; i < m; i++){
    if(right <= v[i].first){
      right = v[i].second;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
"use strict";
main(
  require("fs")
    .readFileSync("/dev/stdin", "UTF-8")
    .trim()
    .split("\n")
);

function main(input) {
  input = input[0].split(" ").map(Number);

  if (input[0] >= 10) {
    console.log(input[1]);
  } else {
    console.log(input[1] + 100 * (10 - input[0]));
  }
}


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N;
  cin>>N;
  cout << (N+1)/2 << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0; u < n; u++) color[u] = WHITE;
    tt = 0;

    for(u = 0; u < n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u = 0;u < n; u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
}

int main(){
    int u,v,k,i,j;

    scanf("%d",&n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++) M[i][j] = 0;
    }

    for(i = 0; i < n; i++){
        scanf("%d%d",&u,&k);
        u--;
        for(j = 0; j < k; j++){
            scanf("%d",&v);
            v--;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


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

typedef long long int lli;

const long long int m = 1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;

    lli a,x;
    cin >> x;
    lli s = 0;
    lli sp = 0;
    s = (s%m + x%m)%m;

    for(int i = 2;i<=n;i++)
    {
        cin >> x;
        sp = (sp%m + ((s%m*x%m)%m)%m)%m;
        s = (s%m + x%m)%m;
    }
    cout << sp << endl;
}


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

int main(int argc, char const *argv[])
{
    int n, m, k; cin >> n >> m >> k;
    long long int a, b, c[200010], d[200010];
    c[0] = 0;
    rep(i,n) {
        cin >> a;
        c[i+1] = c[i] + a;
    }
    d[0] = 0;
    rep(i,m) {
        cin >> b;
        d[i+1] = d[i] + b;
    }
    int ans = 0;
    int j = m;
    rep(i,n+1) {
        if (k < c[i]) break;
        while (k < c[i] + d[j]) {
            j--;
        }
        ans = max(ans, i+j);
        //cout << ans << " " << i << " " << j << endl;
    }    
    cout << ans << endl;


    return 0;
}


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

using namespace std;

int main(){
	string s[2], cond;
	int n[2];
	int r[2];

	for (int i = 0 ; i < 2; i++)	cin >> s[i];
	for (int i = 0 ; i < 2; i++)	cin >> n[i];

	cin >> cond;

	for (int i = 0 ; i < 2; i++){
		if (s[i] == cond)
			r[i] = n[i] - 1;
		else
			r[i] = n[i];
	}
	
	cout << r[0] << ' ' << r[1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int dp[5011][5011];

bool cmp(const ii &a, const ii &b)
{
	if(a.fi+a.se!=b.fi+b.se) return a.fi+a.se<b.fi+b.se;
	else return a.fi<b.fi;
}

vector<ii> vec;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		int h,w ; cin>>h>>w;
		vec.pb(mp(h,w));
	}
	sort(vec.begin(),vec.end(),cmp);
	dp[0][0] = 0;
	dp[0][1] = vec[0].se;
	for(int i=2;i<=n;i++) dp[0][i]=int(2e9)+55;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>0&&vec[i].fi>=dp[i-1][j-1])
			{
				dp[i][j]=min(dp[i][j],dp[i-1][j-1]+vec[i].se);
			}
			//cerr<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
		}
	}
	for(int i=n;i>=0;i--)
	{
		if(dp[n-1][i]<int(2e9)+55)
		{
			cout<<i<<'\n'; return 0;
		}
	}
}	


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, a[200000], b[200000], c[200000];

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	
	bool ans = false;
	inc(i, m) {
		if(a[i] == 0) { c[b[i]] = 1; }
		
	}
	inc(i, m) {
		if(c[a[i]] == 1 && b[i] == n - 1) { ans = true; }
	}
	
	cout << (ans ? "" : "IM") << "POSSIBLE" << endl;
	
	return 0;
}


Measured memory_bytes: 2560
n,x,y=map(int,input().split())
x-=1
y-=1

shortest=[0 for i in range(n-1)]

for i in range(n-1):
    for j in range(i+1,n):
        distance=min((j-i,abs(i-x)+1+abs(j-y)))
        shortest[distance-1]+=1

for i in shortest:
    print(i)
        

    
    
    


Measured memory_bytes: 3444
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Sep  1 21:29:49 2019
//
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if b == 1 {
		fmt.Println(0)
		return
	}

	ans := 1
	b -= a
	for b > 0 {
		b -= a - 1
		ans++
	}
	fmt.Println(ans)
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int off = 1;
ll tur[600005];
int h[200005];

void update(int node, ll val) {
	if (!node) return ;
	if (node >= off) {
		tur[node] = val;
	} else {
		tur[node] = max(tur[node*2], tur[node*2+1]);
	}
	update(node/2, val);
}

ll query(int x, int y, int l, int r, int node) {
	if (l>=x and r<=y) return tur[node];
	if (r<x or l>y) return 0;
	return max(query(x, y, l, (l+r)/2, node*2), query(x, y, (l+r)/2+1, r, node*2+1));
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<n ; i++) {
		scanf("%d", h+i);
	}
	ll sol = 0;
	while (off <= n) off*=2;
	for (int i=0 ; i<n ; i++) {
		int x;
		scanf("%d", &x);
		ll maxx = query(0, h[i], 0, off-1, 1);
		sol = max(sol, maxx + x);
		if (tur[off+h[i]] < maxx + x) {
			update(off+h[i], maxx + x);
		}
	}
	printf("%lld\n", sol);
	return 0;
}

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

int main() {
	int data[3], i , j, n;

	for (i = 0; i < 3; i++) {
		cin >> data[i];
	}

		for (i = 0; i < 2; i++) {
			for (j = 0; j < 2; j++) {
				if (data[j] > data[j + 1]) {
					n = data[j];
					data[j] = data[j+1];
					data[j + 1] = n;
				}
			}
		}
	cout << data[0] << " " << data[1] << " " << data[2] << endl;
}

Measured memory_bytes: 3088
// C - Back and Forth
#include <bits/stdc++.h>
using namespace std;

int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;

	int dx = tx-sx;
	int dy = ty-sy;
	string s = "";
	for(int i=1; i<=dy; i++) s += "U";
	for(int i=1; i<=dx; i++) s += "R";
	for(int i=1; i<=dy; i++) s += "D";
	for(int i=1; i<=dx; i++) s += "L";
	dx++; dy++;
	s += "L";
	for(int i=1; i<=dy; i++) s += "U";
	for(int i=1; i<=dx; i++) s += "R";
	s += "DR";
	for(int i=1; i<=dy; i++) s += "D";
	for(int i=1; i<=dx; i++) s += "L";
	s += "U";

	cout<< s <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a > k)
        cout << ":(";
    else
        cout << "Yay!";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<string> word(N);
	rep (i, N){
		string s; cin >> s;
		word[i] = s;
	} // end rep
	map<string,int> cnt; cnt.clear();
	rep (i, N){
		++cnt[word[i]];
	} // end rep

	bool ok = true;
	map<string,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int c = (*it).second;
		if (c != 1) ok = false;
	} // end for

	if (ok){
		for (int i = 1; i < N; ++i){
			if (word[i-1][(int)word[i-1].length() - 1] != word[i][0]){
				ok = false;
				break;
			} // end if
		} // end for
	} // end if

	cout << (ok ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 256