akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N = 5e4 + 5;

int n,m,q,mod,s,t,r,u[N],v[N],c[N],g,fa[N * 6] , id[N][2][3] , icnt;
bool can[2][1000100];

int get(int x) {
	return fa[x]==x?x:fa[x]=get(fa[x]);
}

void link(int x,int y) {
	x=get(x);
	y=get(y);
	if (x==y) return;
	fa[x]=y;
}

int main() {
	scanf("%d%d%d%d",&n,&m,&q,&mod);
	fo(i,1,m) {
		scanf("%d%d%d",&u[i],&v[i],&c[i]);
		g=__gcd(g,abs(c[i]-c[1]));
	}
	if (!g) g=mod;
	mod=__gcd(mod,3*g);
	int z=c[1]%g;

	for (int i = 1; i <= n; i++)
		for (int j = 0; j < 2; j++)
			for (int k = 0; k < 3; k++)
				id[i][j][k] = ++icnt;

	fo(i,1,icnt) fa[i]=i;
	fo(i,1,m) {
		int w=(c[i]-z)/g;
		fo(p,0,1)
		fo(q,0,2) {
			link(id[u[i]][p][q],id[v[i]][1^p][(2*q+w)%3]);
			link(id[v[i]][p][q],id[u[i]][1^p][(2*q+w)%3]);
		}
	}
	
	int mul = z;
	for (int i = 0;i <= (mod << 1);i++){
		can[i & 1][mul] = 1;
		mul = 2 * mul % mod;
	}
	
	for(; q; q--) {
		scanf("%d%d%d",&s,&t,&r);
		int ret=0;
		fo(p,0,1) fo(q,0,2) if (get(id[t][0][0])==get(id[s][p][q])) {
			ret|=can[p][(r+z+(3-q)*g)%mod];
			
			if (ret) break;
		}
		puts(ret?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define N 8
int a[N], b[2 * N - 1], c[2 * N - 1], x[N];
int n;
int xp[N], yp[N];

void found() {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (x[i] == j) cout << "Q";
			else           cout << ".";
		}
		cout << endl;
	}
}

void try_(int i) {
	for (int j = 0; j < N; j++) {
		if (a[j] && b[i+j] && c[i-j+N-1]) {
			x[i] = j;
			if (i < N -1) {
				a[j] = b[i+j] = c[i-j+N-1] = 0;
				try_(i + 1);
				a[j] = b[i+j] = c[i-j+N-1] = 1;
			}
			else {
				bool flag = true;
				for (int k = 0; k < n; k++)
					if (x[xp[k]] != yp[k])
						flag = false;
				if (flag)
					found();
			}

		}
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> xp[i] >> yp[i];

	fill_n(a, N, 1);
	fill_n(b, 2 * N - 1, 1);
	fill_n(c, 2 * N - 1, 1);
	try_(0);
	return 0;
}

Measured memory_bytes: 1156
zikan = 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
li = [a,b,c,d,e]
li2 = []

for x in li:
    if x % 10 != 0:
        li2.append(abs((x % 10) - 10))
    else:
        li2.append(0)
f = li[li2.index(max(li2))]
li.remove(f)
for y in li:
    if y % 10 == 0:
        zikan += y
    else:
        zikan += 10 * (y // 10 + 1)
zikan += f
print(zikan)

Measured memory_bytes: 3064
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

using namespace std;

struct Node {
    int key;
    Node *left, *right, *parent;
};
Node *root, *NIL;

void insert(int k) {
    if(root == NIL) {
        root = (Node *)malloc(sizeof(Node));
        root->key = k;
        root->left = root->right = NIL;
    }else {
        Node *z = (Node *)malloc(sizeof(Node));
        z->key = k;
        z->left = z->right = NIL;

        Node *x = root;
        while(true) {
            if(k < x->key) {
                if(x->left == NIL) {
                    x->left = z;
                    z->parent = x;
                    break;
                }
                else x = x->left;
            }else {
                if(x->right == NIL) {
                    x->right = z;
                    z->parent = x;
                    break;
                }
                else x = x->right;
            }
        }
    }
}

Node *find(Node *node, int k) {
    Node *x = node;
    while(x != NIL && k != x->key) {
        if(k < x->key) x = x->left;
        else x = x->right;
    }

    return x;
}

Node *treeSuccessor(Node *x) {
    if(x->right != NIL) {
        x = x->right;
        while(x->left != NIL) x = x->left;
        return x;
    }
    /*else {
        Node *y = x->parent;
        while(y!=NIL && x==y->right) {
            x = y;
            y = y->parent;
        }
        return y;
    }
    */

}

void deleteNode(Node *node) {
    Node *target, *child;
    if(node->left == NIL || node->right == NIL) target = node;
    else target = treeSuccessor(node);

    if(target->left != NIL)
        child = target->left;
    else
        child = target->right;
    if(child != NIL) child->parent = target->parent;

    if(target->parent == NIL) root = child;
    else {
        if(target == target->parent->left)
            target->parent->left = child;
        else
            target->parent->right = child;
    }

    if(target != node) node->key = target->key;
    free(target);
}

void inorder(Node *node) {
    if(node == NIL) return;
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
}

void preorder(Node *node) {
    if(node == NIL) return;
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
}

int main()
{
    int n, x;
    char str[19];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%s", str);
        if(str[0] == 'i') { //insert
            scanf("%d", &x);
            insert(x);
        }else if(str[0] == 'p') { //print
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(str[0] == 'f') { //find
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }else if(str[0] == 'd') { //delete
            scanf("%d", &x);
            deleteNode(find(root,x));
        }

    }

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n, k; cin >> n >> k;
    if ((n + 1) / 2 >= k) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w; scanf("%d%d", &h, &w);
  string s;
  int rx, ry;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    cin >> s;
    if (s == "snuke") {
      ry = i;
      rx = j;
    }
  }
  cout << char('A' + rx) << ry + 1 << endl;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define M 1046527
char H[M][14];

int getChar(char c){
  if(c == 'A') return 1;
  if(c == 'C') return 2;
  if(c == 'G') return 3;
  if(c == 'T') return 4;
}

long long getKey(char *s){
  long long sum = 0, p = 1;
  for(long long i=0;i<strlen(s);i++){
    sum += p*getChar(s[i]);
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key % M;
}

int h2(int key){
  return 1 + (key % (M -1));
}

int h(int key, int i){
  return (h1(key) + i * h2(key)) % M;
}

int find(char *s){
  long long i, j, key;
  key = getKey(s);
  for(i=0;;i++){
    j = h(key, i);
    if(strcmp(H[j], s) == 0) return 1;
    else if(strlen(H[j]) == 0) return 0;
  }
  return 0;
}

int insert(char *s){
  long long key, i, j;
  key = getKey(s);
  for(i=0;;i++){
    j = h(key, i);
    if(strcmp(H[j], s) == 0) return 1;
    else if(strlen(H[j]) == 0){
      strcpy(H[j], s);
      return 0;
    }
  }
  return 0;
}

int main(){
  int n;
  cin >> n;
  string com;
  char dna[14];
  for(int i=0;i<M;i++) H[i][0] = '\0';
  for(int i=0;i<n;i++){
    cin >> com >> dna;
    if(com[0] == 'i'){
      insert(dna);
    }
    else{
      if(find(dna)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}



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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine());

        var sum = 0;
        for (int a = 0; a < k; ++a)
        for (int b = 0; b < k; ++b)
        for (int c = 0; c < k; ++c)
        {
            sum += FindGcd(FindGcd(a + 1, b + 1), c + 1);
        }

        Console.WriteLine(sum);
    }

    public static int FindGcd(int x, int y, int k = 0) => x < 1 ? y : FindGcd(y % x, x, k + 1);
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll mod = 1e9+7;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow != 0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

ll lt[1234][1234], rt[1234][1234], upper[1234][1234], lower[1234][1234];

int dist(int x1, int y1, int x2, int y2){
    return abs(x1-x2)+abs(y1-y2);
}

int pre[123456];

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    string s1, t;
    cin >> s1 >> t;
    int cond = 0;
    vector <int> vec1;
    for(int i = 0; i < s1.size()-t.size()+1; i++){
        int cond1 = 0;
        for(int j = 0; j < t.size(); j++){
            if(s1[j+i] != t[j] && s1[j+i] != '?') break;
            if(j == t.size()-1) cond1 = 1;
        }
        if(cond1){
           vec1.push_back(i);
           cond = 1;
        }
    }
    //int ind = vec1.back();
    string s;
    if(!cond){
       cout << "UNRESTORABLE"; return 0;
    }
    vector <string> vec;
    for(int i = 0; i < vec1.size(); i++){
        string s;
        s = s1;
        int ind = vec1[i];
        for(int j = 0; j < t.size(); j++){
            s[ind+j] = t[j];
        }
        for(int i = 0; i < s.size(); i++) if(s[i] == '?') s[i] = 'a';
        vec.push_back(s);
    }
    sort(vec.begin(), vec.end());
    cout << vec[0];
}


Measured memory_bytes: 256
A, B, AB, X, Y = map(int, input().split())

A_p = A * X
B_p = B * Y
justAB = A_p + B_p

min_x_y = min(X, Y)
AB_p = int((min_x_y / 0.5 * AB))

dif = 0
dif_p = 0
if X > Y:
    dif = X - Y
    dif_p = dif * A
else:
    dif = Y - X
    dif_p = dif * B


max_x_y = max(X,Y)
AB_max_p = int(max_x_y / 0.5 * AB)

print(min(justAB, AB_p + dif_p, AB_max_p))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define inf 1<<29
using namespace std;

class State{
public:
  int a,time,cost;
  State(int a,int b,int c):a(a),time(b),cost(c){}
  bool operator<(State s)const{
    return s.cost<cost;
  }
};

int n,m,h,k,a,b,c,r,s,t,p,l,d,lim;
int R[101][101],C[101][101],H[101][101],D[(1<<8)+1];

void init(){
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      R[i][j]=inf;
      C[i][j]=inf;
      H[i][j]=inf;
    }
  }
  for(int i=0;i<(1<<8)+1;i++)D[i]=inf;
}

int Dijkstra(int bits){
  int dp[101][25],ans=inf;
  for(int i=0;i<101;i++){
    for(int j=0;j<25;j++)dp[i][j]=inf;
  }
  dp[s][0]=0;
  priority_queue<State> pq;
  pq.push(State(s,0,0));

  while(!pq.empty()){
    State u=pq.top();
    pq.pop();

    if(dp[u.a][u.time]<u.cost)continue;
    if(u.a==t){
      ans=min(ans,u.cost);
      continue;
    }

    for(int i=0;i<n;i++){
      if(H[u.a][i]==inf)continue;
      int time=u.time+H[u.a][i],cost=u.cost+C[u.a][i];
      if(((bits>>R[u.a][i])%2)&1)cost=u.cost;

      if(lim<time)continue;
      if(cost<dp[i][time]){
	dp[i][time]=cost;
	pq.push(State(i,time,cost));
      }
    }
  }
  return ans;
}

int main()
{

  while(1){
    cin>>n>>m>>lim>>k;
    if(n+m+lim+k==0)break;

    init();

    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>h>>r;
      a--;b--;r--;
      C[a][b]=c;C[b][a]=c;
      H[a][b]=h;H[b][a]=h;
      R[a][b]=r;R[b][a]=r;
    }
    cin>>s>>t>>p;
    s--;t--;
    for(int i=0;i<p;i++){
      cin>>l>>d;
      int sum=0;
      for(int j=0;j<l;j++){
	cin>>a;
	sum+=1<<(a-1);
      }
      D[sum]=d;
    }
  
    D[0]=0;
    for(int i=0;i<(1<<8);i++){
      if(D[i]==inf)continue;
      for(int j=i+1;j<(1<<8);j++){
	D[(i|j)]=min(D[(i|j)],D[i]+D[j]);
      }
    }
    int ans=inf;
    for(int i=0;i<(1<<8);i++){
      if(D[i]==inf)continue;
      ans=min(ans,Dijkstra(i)+D[i]);
    }
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) 
{
    string S; cin >> S;

    int pattern1 = 0 /* 0101... */ , pattern2 = 0 /* 1010... */ ;
    char cmp = '0';
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != cmp) {
            pattern1++;
        } else {
            pattern2++;
        }

        cmp = ((cmp == '0') ? '1' : '0');
    }

    cout << min(pattern1, pattern2) << endl;
    return 0;
}

Measured memory_bytes: 512
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


A, B, C = MI()
print('Yes' if A <= C <= B else 'No')

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

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

int main()
{
    int n;
    cin >> n;
    cout << (n + 999) / 1000 * 1000 - n << endl;
    return 0;
}

Measured memory_bytes: 3604
a,b = map(int,input().split())
lineA = [input() for i in range(a)]
lineB = [input() for i in range(b)]
count = 0
for i in range(b):
    if lineB[i] in lineA[i]:
        count += 1
if count == b:
    print("Yes")
else:
    print("No")


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

fn main() {
    let n = get!(i32);
    println!("{}", (n+1) * n / 2);
}

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

int main() {
  int n;
  cin>> n;
  vector<int> mao(n);
  for (int i=0; i<n; i++)
    cin>> mao.at(i);
  
  int z=0;
  int a=0;
  for (int i=0; i<n-1; i++) {
    if (mao.at(i)-1 > mao.at(i+1)) {
      z++;
      break;
    }
    else if (mao.at(i)-1 == mao.at(i+1) && a==0) {
      a++;
    }
    else if (mao.at(i)-1 == mao.at(i+1) && a!=0) {
      z++;
      break;
    }
    else if (mao.at(i) < mao.at(i+1)) {
      a=0;
    }
  }
  if (z==0)
    cout<< "Yes" <<endl;
  else
    cout<< "No" <<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const ll MAX1 = 2e5+7,
	     MOD = 1e9+7;

ll n, flag, x;

int main(){
	fast_io;
	cin >> n;
	flag = 1;
	for (int i = 0; i < n; ++i){
		cin >> x;
		if (flag == x)	++flag;
	}
	if (flag == 1)	cout << -1;
	else	cout << n-flag+1;
    return 0;
}
/*                     now or never                         */


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

//ABC114B
int main(void) {
  long long n, k, i, cou=0, tmp, min=1000;
  scanf("%lld", &n);
  for(i=0; i<10; i++){
    tmp=abs(753-n%1000);
    min=min>tmp ? tmp : min;
    n/=10;
  }
  printf("%lld", min);
}

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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int a, b;
        cin >> a >> b;
        cout << 6 - a - b << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define INF 1e18
//#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    int M[2];
    rep(i, 2) M[i] = s[i + 5] - '0';
    int m = 10 * M[0] + M[1];
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	vector<ll> x;
	ll n,k;
	cin >> n >> k;
	for(ll i = 0;i < n;i++) {
		ll xx;
		cin >> xx;
		x.push_back(xx);
	}
	sort(x.begin(),x.end());
	ll res = 0x7fffffff;
	for(ll i = 0;i <= n-k;i++) {
		ll n[2] = {min(x[i],x[i+k-1]),max(x[i],x[i+k-1])};
		ll dist;
		if(n[0] * n[1] < 0) {
			dist = min(abs(n[0]),abs(n[1])) * 2 + max(abs(n[0]),abs(n[1]));
		}
		else {
			dist = max(abs(n[1]),abs(n[0]));
		}
		res = min(res,dist);
	}
	cout << res;
}


Measured memory_bytes: 1400
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    StringBuffer sb = new StringBuffer(S);
    StringBuffer head = new StringBuffer();
    StringBuffer tail = new StringBuffer();
    int Q = Integer.parseInt(sc.next());
    int T, F;
    String C;
    boolean rev = false;
    for(int i=0; i<Q; i++){
      T = Integer.parseInt(sc.next());
      if(T==1){
        if(rev)rev=false;
        else rev=true;
      } else if(T==2){
        F = Integer.parseInt(sc.next());
        C = sc.next();
        if(F==1){
          if(rev) tail.append(C);
          else head.append(C);
        } else if(F==2){
          if(rev) head.append(C);
          else tail.append(C);
        }
      }
    }
    if(rev){
      tail.reverse();
      sb.reverse();
      System.out.println(tail.append(sb).append(head));
    } else {
      head.reverse();
      System.out.println(head.append(sb).append(tail));
    }
  }
}

Measured memory_bytes: 90592
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll h,w,b[10][10]={};
  char a[10][10]={};
  cin >> h >> w;
  b[0][0]=1;
  rep(i,h)rep(j,w)cin >> a[i][j];
  rep(i,h){
    rep(j,w){
      if(a[i+1][j]=='#'&&a[i][j+1]!='#'&&b[i][j]==1)b[i+1][j]=1;
      if(a[i][j+1]=='#'&&a[i+1][j]!='#'&&b[i][j]==1)b[i][j+1]=1;
    }
  }
  rep(i,h){
    rep(j,w){
      if(a[i][j]=='#'&&b[i][j]==0){
        printf("Impossible");
        return 0;
      }
    }
  }
  if(b[h-1][w-1]==1)printf("Possible");
  else printf("Impossible");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9;
const int MOD=1e9+7;
const int MAXN=1e6+7;

int ans=0;
int n,m,k,q;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>a>>b;
    if(a>b)swap(a,b);
    int x=a*10;
    FOR(i,0,10000){
        if(((x+i)*8)/100==a&&(x+i)/10==b){
            cout<<x+i<<"\n";
            return 0;
        }
    }
    cout<<"-1\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=200;
int a[N];
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	int n;cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	int res=0;
	for(int i=0;i<n;++i)
		for(int j=i+1;j<n;++j)
			for(int k=j+1;k<n;++k)
				if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]&&a[i]+a[j]>a[k])
					++res;
	cout<<res<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
const int maxn=300009;
int Max[maxn<<2];
void upd(int rt,int l,int r,int p,int v){
  if(l==r){
    Max[rt]+=v;
    return;
  }
  int mid=(l+r)>>1;
  if(p<=mid)upd(rt<<1,l,mid,p,v);
  else upd(rt<<1|1,mid+1,r,p,v);
  Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
}
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int h,w,m;cin>>h>>w>>m;
  vector<vector<int>> v(h+1);
  for(int i=1;i<=m;++i){
    int a,b;cin>>a>>b;
    upd(1,1,w,b,1);
    v[a].push_back(b);
  }
  int res=Max[1];
  for(int i=1;i<=h;++i)if(SZ(v[i])){
    for(int j:v[i])upd(1,1,w,j,-1);
    res=max(res,SZ(v[i])+Max[1]);
    for(int j:v[i])upd(1,1,w,j,1);
  }
  cout<<res<<'\n';
  
  return 0;
}
//2020.08.22 20:34:41


Measured memory_bytes: 23792
def dis(d, x, y):
    if d >= (x**2 + y**2)**0.5:
        return 1
    return 0

n, d = map(int, input().split())
cnt = 0
for i in range(n):
    x, y = map(int, input().split())
    cnt += dis(d, x, y)
print(cnt)




Measured memory_bytes: 9636
#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 main() {
	int x, a, b;
	cin >> x >> a >> b;
	
	cout << (a >= b ? "delicious" : (b - a <= x ? "safe" : "dangerous")) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,Amari;
	cin >> N;
    Amari = N%10;
  if(N<=999){
    if(Amari == 3){
        cout << "bon" << endl;
    }
    else if(Amari == 0 || Amari == 1){
    	cout << "pon" << endl;
    }
    else if(Amari == 6 || Amari == 8){
    	cout << "pon" << endl;
    }
    else{
    	cout << "hon" << endl;
    }
  }
}

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

using namespace std;
using ll = long long int;

int main() {

	string s;
	cin >> s;

	ll Astock = 0;
	bool Bchance = false;
	ll cnt = 0;

	for (ll i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			if (Bchance) {
				Astock = 0;
			}
			Astock++;
			Bchance = false;
		}
		if (s[i] == 'B') {
			if (Bchance) {
				Astock = 0;
			}

			Bchance = true;
		}
		if (s[i] == 'C') {
			if (Bchance) {
				cnt += Astock;
			}
			else {
				Astock = 0;
			}

			Bchance = false;
		}

	}

	cout << cnt;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define lli long long int
#define llu long long unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,s,e) for(i=s; i<e; i++)
#define mod 1000000007
#define F first
#define S second
#define plli pair<lli,lli>
#define pqlli priority_queue<lli>
#define test(t) cin>>t; while(t--)
using namespace std;

lli power(lli a, lli b, lli M = mod)
{
	lli result = 1;
    for (;;)
    {
        if (b & 1)
            result = (result*a)%M;
        b >>= 1;
        if (!b)
            break;
        a = (a*a)%M;
    }
    return result;
}
map<lli,lli> dis;

void bfs(vector<vector<lli> > &g, lli start, lli n)
{
	queue<plli> q;
	q.push(mp(start, 0));
	int mark[n+1];
	memset(mark, 0, sizeof(mark));
	mark[start] = 1;
	while(!q.empty())
	{
		lli temp = q.front().first;
		lli c = q.front().second;
		q.pop();
		for(auto i : g[temp])
		if(mark[i] == 0)
		q.push(mp(i, c+1)), dis[c+1]++, mark[i] = 1;
	}
}

int main()
{
	IOS;
	lli n,x,y;
	cin>>n>>x>>y;

	for(lli i = 1; i<=n; i++)
	{
		for(lli j = i+1; j<=n; j++)
		{
			lli temp = j-i;
			temp = min(temp, abs(i-x) + abs(j-y) + 1);
			temp = min(temp, abs(i-y) + abs(j-x) + 1);
			dis[temp]++;
		}
	}
	for(lli i = 1; i<n; i++)
	cout<<dis[i]<<endl;
	
}


Measured memory_bytes: 384
import copy


def main():
    target = input()

    num_list = []

    def function(n):
        if n == 0:
            num_list.append([(target[0], )])
        else:
            ans = []
            for i in num_list[n-1]:
                m = list(copy.copy(i))
                m.pop()
                m.append(i[-1] + target[n])
                ans.append(m)
                m = list(copy.copy(i))
                m.append(target[n])
                ans.append(m)
            ans = tuple(ans)
            num_list.append(ans)
    for x in range(len(target)):
        function(x)
    # print(num_list[-1])
    answer = 0
    for x in num_list[-1]:
        for y in x:
            answer += int(y)
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9356
package main

import (
	"fmt"
)

func main() {
	var s int
	fmt.Scan(&s)
	dp := make([]int, s+1)
	const mod = int(1e9 + 7)
	dp[0] = 1
	for i := 1; i < s+1; i++ {
		for j := 3; j <= i; j++ {
			if i-j >= 0 {
				dp[i] += dp[i-j]
				dp[i] %= mod
			}
		}
	}
	fmt.Println(dp[s])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1788
n=int(input())
c=str(input())
red=0
for i in range(n):
    if c[i]== 'R':
        red+=1
ans=0
if red == n:
    print(0)
else:
    for i in range(red,n):
        if c[i] == 'R':
            ans += 1
    print(ans)


Measured memory_bytes: 9412
import sys
N=int(input())
W=[]
for _ in range(N):
    W.append(input())
    

pre=W.pop(0)
ans=[]
ans.append(pre)
for word in W:
    if((word in ans)==True or pre[-1]!=word[0]):
        print('No')
        sys.exit()
    pre=word
    ans.append(word)
print('Yes')



Measured memory_bytes: 3060
import sys
from io import StringIO
import unittest
import os
from collections import deque

# 検索用タグ、累積和、木、クエリ処理、遅延評価

relations = []


# 実装を行う関数
def resolve():
    global relations

    n, q = map(int, input().split())

    # 木のつながりを整理する
    relations = [[] for i in range(n + 1)]
    for i in range(n - 1):
        a, b = map(int, input().split())
        relations[a].append(b)
        relations[b].append(a)

    # どの木がきたら、いくら値を加算するか、を保持する(同じ木を何度か加算することもある)
    # 最終的に、これと「木のつながり」を組み合わせて各枝の累積和を求める。
    counters = [0 for i in range(n + 1)]
    for i in range(q):
        p, x = map(int, input().split())
        counters[p] += x

    # queを作成
    que = deque()
    que.append([1, 1])  # 初期値：スタート地点

    # BFS開始
    while len(que) is not 0:

        a = que.pop()
        now = a[0]
        bef = a[1]

        if not now == bef == 1:
            counters[now] += counters[bef]

        # 再帰処理のためのループ
        for target in relations[now]:

            if target == bef:
                continue

            que.appendleft([target, now])

    print(*counters[1:])


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """4 3
1 2
2 3
2 4
2 10
1 100
3 1"""
        output = """100 110 111 110"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10"""
        output = """20 20 20 20 20 20"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 121160
using System;

namespace ITP1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine();
                var values = input.Split(' ');
                int H = int.Parse(values[0]);
                int W = int.Parse(values[1]);
                if (H == 0 && W == 0) break;

                for (int i = 1; i <= H; i++)
                {
                    for (int j = 1; j <= W; j++)
                    {
                        if ( (i>=2 && i<=H-1) && (j>=2 && j<=W-1) )
                        {
                            Console.Write(".");
                        }
                        else
                        {
                            Console.Write("#");
                        }

                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}

Measured memory_bytes: 5292
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=500005;
vector<pii> que[MAXN];
int n,a[MAXN],last[MAXN],bit[MAXN],ans[MAXN];

void update(int now,int val){
	for(int i=now;i<=n;i+=(i&(-i)))bit[i]+=val;
}

int query(int now){
	int ret=0;
	for(int i=now;i>0;i-=(i&(-i)))ret+=bit[i];
	return ret;
}

int main(){
	int q,l,r;
	cin >> n >> q;
	for(int i=1;i<=n;i++)cin >> a[i];
	for(int i=1;i<=q;i++){
		cin >> l >> r;
		que[r].push_back({l,i});
	}
	for(int i=1;i<=n;i++){
		if(last[a[i]]!=0)update(last[a[i]],-1);
		last[a[i]]=i;
		update(i,1);
		for(auto isi : que[i]){
			ans[isi.second]=query(i)-query(isi.first-1);
		}
	}
	for(int i=1;i<=q;i++)cout << ans[i] << '\n';
	return 0;
}

Measured memory_bytes: 33224
class _in{struct my_iterator{int it;const bool rev;explicit constexpr my_iterator(int it_, bool rev=false):it(it_),rev(rev){}constexpr int operator*(){return it;}constexpr bool operator!=(my_iterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const my_iterator i,n;public:explicit constexpr _in(int n):i(0),n(n){}explicit constexpr _in(int i,int n):i(i,n<i),n(n){}constexpr const my_iterator& begin(){return i;}constexpr const my_iterator& end(){return n;}};

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

using i64 = long long;
const int INF = 1e9;
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int T; cin >> T;
    for(int _ : _in(T)) {
        int n, d;
        cin >> n >> d;
        if(n % 2) {
            int ans = 127 * (n - 1) + d;
            cout << ans << '\n';
        }
        else {
            int ans = 127 * (n - 1) + (d ^ 127);
            cout << ans << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

ll gcd(ll A, ll B)
{
    if (A < B)
    {
        return gcd(B, A);
    }
    if (B == 0)
    {
        return A;
    }
    return gcd(B, A % B);
}

ll lcm(ll a, ll b)
{
    return (a * b) / gcd(a, b);
}

int f(int b)
{
    int res = 0;
    while (b % 2 == 0)
    {
        b /= 2;
        res++;
    }
    return res;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        a[i] /= 2;
    }

    int k = f(a[0]);
    rep(i, n)
    {
        if (k != f(a[i]))
        {
            cout << 0 << endl;
            return 0;
        }
        // a[i] = a[i] >> k;
    }
    // m = m >> k;
    ll t = 1;
    for (auto &x : a)
    {
        t = lcm(t, x);
        if (t > m)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = m / t;
    ans = (ans + 1) / 2;

    cout << ans << endl;

    return 0;
}

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

#define ll long long int

using namespace std;

ll a[200001];

int main(){

    ll n,k; cin >> n >> k;
    ll before=1,now=1;

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

    for(int i=k;i<n;i++){
        cin >> a[i];
        if(a[i] > a[i-k]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    
    return 0;
}

Measured memory_bytes: 5140
def main():
    import sys
    from collections import deque
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    pq = deque([])
    mq = deque([])
    for n in range(N):
        s = input().strip()
        mini = 0
        dst = 0
        for ss in [1 if ss == '(' else -1 for ss in s]:
            dst += ss
            mini = min(dst, mini)
        
        if dst >= 0:
            pq.append((mini, dst))
        elif dst < 0:
            mq.append((mini - dst, mini, dst))
    pq = sorted(pq, reverse=True)
    mq = sorted(mq)
    p = 0
    for mini, dst in pq:
        if p + mini < 0:
            print('No')
            exit()
        p += dst
    for minimini, mini, dst in mq:
        if p + mini < 0:
            print('No')
            exit()
        p += dst
    if p != 0:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 88708
function Main(input) {
	input = input.split("\n");
	const input1 = input[0].split(" ")
	const M = parseInt(input1[0])
	const D = parseInt(input1[1])
	const s = []
	for(i=1; i <= D; i++){
		d1 = i % 10;
		d10 = Math.floor(i / 10);
		if(d1 >= 2 && d10 >= 2){
			s.push(d1 * d10)
		}
	}
  	
	const res = s.filter(d => d <= M)
	console.log(res.length)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<stdio.h>

int selectionSort(int A[],int N);
void Show(int A[],int N);

int selectionSort(int A[],int N)
{
	int i,minj,sum=0,j;
	for(i=0;i<N;i++)
	{
		minj=i;
		for(j=i+1;j<N;j++)
			if(A[j]<A[minj])
				minj=j;
		int temp;
		if(minj!=i)
		{
			temp=A[i];
			A[i]=A[minj];
			A[minj]=temp;
			sum++;	
		}			
	}
	return sum;	
}

void Show(int A[],int N)
{
	int i;
	for(i=0;i<N;i++)
	{
		if(i>0)
		    printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

int main()
{
	int N,A[200],i,sum;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	sum=selectionSort(A,N);
	Show(A,N);
	printf("%d\n",sum);
	return 0;
} 


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

  int n,y;
  cin >> n >> y;

  for (int a=0; a<=n; ++a){
    for (int b=0; a+b<=n; ++b){
      if ((a*10000 + b*5000 + (n-a-b)*1000) == y){
        cout << a << " " << b << " " << n-a-b << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;


int main() {
    ll x,y;
    cin >> x >> y;
    ll ans = 0;
    ll val_x = -x;
    ll val_y = -y;
    if(x >= 0 && y > 0){
        if(x <= y){
            ans = y - x;
        }
        else{
            ans = x - y + 2;
        }
    }
    else if(x >= 0 && y == 0){
        ans = x + 1;
    }
    else if(x >= 0 && y < 0){
        
        if(x <= val_y){// 3 -5
            ans = val_y - x + 1;
        }
        else{ //5 -3
            ans = x - val_y + 1;
        }        
    }
    else if(x < 0 && y > 0){
        
        if(val_x <= y){// -3 5
            ans = y - val_x + 1;
        }
        else{// -5 3
            ans = val_x - y + 1;
        }           
    }
    else if(x < 0 && y == 0){
        ans = val_x - y;
    }
    else{
        if(val_x <= val_y){//-3 -5
            ans = val_y - val_x + 2;
        }
        else{//-5 -3
            ans = val_x - val_y;
        }           
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,x,y = li()

abonly = a*x + b*y

abandc = 0
if x > y:
    abandc = c*(2*y) + a*(x-y)
else:
    abandc = c*(2*x) + b*(y-x)

conly = c*(2*max(x,y))

print(min(abonly, abandc, conly))

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

#define ll long long
#define REP(i, n) for(int i = 0;i < (int)(n);i++)

int main() {
  int N;
  cin >> N;
  vector<ll> v(N);
  bool z = false;
  ll S = 1;
  REP(i, N) {
    cin >> v[i];
    if (v[i] == 0) {
      z = true;
      cout << 0 << endl;
      break;
    }
  }
  if (!z) {
    REP(i, N) {
      if (S > (1000000000000000000 / v[i])) {
        z = true;
        cout << -1 << endl;
        break;
      } else {
        S *= v[i];
      }
    }
    if (!z) cout << S << endl;
  }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int64_t x, i;
    cin >> x;
    int64_t temp = 100;
    for(i=1; ; i++){
        temp += (1.0/100)*temp;
        if(temp >= x)
            break;
    }
    cout << i << '\n';
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int a, b;
  cin >> a >> b;
  if (a == b) cout << a*2 << endl;
  else cout << max(a, b)*2-1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
}

void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}

int main() {
    string s,t;
    cin >> s >> t;
    ll S = s.size();
    ll T = t.size();
    vector<vector<ll>> memo(S);
    for (int i = 0; i < S; ++i) {
        memo[i] = vector<ll>(T);
    }
    for (int yi = 0; yi < S; ++yi) {
        for (int xi = 0; xi < T; ++xi) {
            memo[yi][xi] = -1;
        }
    }

    bool judge = false;
    for (int yi = 0; yi < S; ++yi) {
        if(s[yi] == t[0] || judge){
            memo[yi][0] = 1;
            judge = true;
        }else{
            memo[yi][0] = 0;
        }
    }
    judge = false;
    for (int xi = 1; xi < T; ++xi) {
        if(s[0] == t[xi] || judge){
            memo[0][xi] = 1;
            judge = true;
        }else{
            memo[0][xi] = 0;
        }
    }
    for (int yi = 1; yi < S; ++yi) {
        for (int xi = 1; xi < T; ++xi) {
            if(s[yi] == t[xi]){
                memo[yi][xi] = memo[yi-1][xi-1] + 1;
            }else{
                memo[yi][xi] = max(memo[yi-1][xi],memo[yi][xi-1]);
            }
        }
    }
    ll x,y;
    y = S-1;
    x = T-1;
    stack<char> stack;
    if(memo[S-1][T-1] == 0){
        cout << "" << endl;
        return 0;
    }
    while((y >= 0 && x >= 0) && memo[y][x] > 0){
        if( y != 0 && memo[y][x] == memo[y - 1][x]){
            y--;
            continue;
        }
        if(x != 0 && memo[y][x] == memo[y][x - 1]){
            x--;
            continue;
        }
        stack.push(s[y]);
        y--;
        x--;
    }
    //OutputVec2d(memo);
    while(!stack.empty()){
        cout << stack.top();
        stack.pop();
    }
    cout << endl;

}


Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define INF 10000000
#define MAX 10000
using namespace std;

// ====== Implement of Heap ======
int heap[2000000]={INF};
int eoh=1;

void minHeapify(int* A, int i){
  int h = eoh-1;
  int l = 2*i;
  int r = 2*i+1;
  int smallest;
  if ( l <= h && A[l] < A[i] )
    smallest = l;
  else
    smallest = i;

  if ( r<= h && A[r] < A[smallest])
    smallest = r;

  if (smallest != i){
    swap(A[i], A[smallest]);
    minHeapify(A, smallest);
  }
}

void insert(int v, int p=-1){
  if (p == -1){
    p = eoh++;
    heap[p] = v;
    insert(v, p);
    return;
  }
  if (p == 1)
    return;
  int parent = heap[p/2];
  if (parent < v)
    return;
  swap(heap[p/2], heap[p]);
  insert(v, p/2);
}

int del(void){
  if (eoh == 1)
    return -1;
  int res = heap[1];
  heap[1] = heap[eoh-1];
  eoh--;
  minHeapify(heap, 1);
  return res;
}
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

// ====== Implement of List Structure ======
struct Node {
    int to, cost;
    struct Node * next;
};

typedef struct Node * NodePointer;

NodePointer NIL;

NodePointer makeNode(int to, int cost){
    NodePointer newNode = (NodePointer)malloc(sizeof(struct Node));
    newNode->to = to;
    newNode->cost = cost;
    newNode->next = NIL;
    return newNode;
}

NodePointer insert(NodePointer head, int to, int cost){
    NodePointer ite, newNode;
    for (ite=head;ite->next!=NIL;ite=ite->next);
    newNode = makeNode(to, cost);
    ite->next = newNode;
    return newNode;
}


// decl vals
int dist[MAX];

void dijkstraAlgorithm(NodePointer vertex[], int n){
  auto compare = [=](int i, int j){return dist[i] >= dist[j];};
  priority_queue<int, vector<int>,  decltype(compare)> searchQueue {compare}; 

  // Initialize of distance, previous and Push all of vectex to queue 
  dist[0] = 0;
  for (int i=0;i<n;i++){
    if (i!=0) dist[i] = INF;
    searchQueue.push(i);
  }

  while(!searchQueue.empty()){
    int current = searchQueue.top();
    NodePointer ite;
    searchQueue.pop();
    for (ite=vertex[current]->next;ite!=NIL;ite=ite->next){
      int alt = dist[current]+ite->cost;
      if ( dist[ite->to] > alt ){
        dist[ite->to] = alt;
        searchQueue.push(ite->to);
      }
    }
  }
}

int main(){
  NodePointer vertex[MAX];
  int i, n;
  cin >> n;
  NIL = makeNode(0, 0);
  for(i=0;i<n;++i) vertex[i] = makeNode(-1,INF);
  
  for (int i=0;i<n;++i){
    int id, k;
    scanf("%d%d", &id, &k);
    for (int j=0;j<k;++j){
      int node, cost;
      scanf("%d%d", &node, &cost);
      insert(vertex[id], node, cost);
    }
  }

  dijkstraAlgorithm(vertex, n);

  for (int i=0;i<n;++i){
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 18980