akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef struct Node
{
    int key;
    struct Node *parent;
    struct Node *left;
    struct Node *right;
} Node;

class BinSearchTree
{
private:
    Node *root;

    Node *allocNode()
    {
        Node *node = (Node *)malloc(sizeof(Node));
        return node;
    };

    void setNode(Node *node, int key, Node *parent, Node *left, Node *right)
    {
        node->key = key;
        node->parent = parent;
        node->left = left;
        node->right = right;
    };

    Node *addNode(Node *node, int key)
    {
        if (node == NULL)
        {
            node = allocNode();
            setNode(node, key, NULL, NULL, NULL);
        }
        else if (key == node->key)
        {
            ;
        }
        else if (key < node->key)
        {
            node->left = addNode(node->left, key);
            node->left->parent = node;
        }
        else
        {
            node->right = addNode(node->right, key);
            node->right->parent = node;
        }

        return node;
    };

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

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

    bool findNode(int key, Node *node)
    {
        if (node == NULL)
            return false;
        if (key == node->key)
            return true;
        if (key < node->key)
            return findNode(key, node->left);
        return findNode(key, node->right);
    }

public:
    BinSearchTree()
    {
        root = NULL;
    };

    void insert(int key)
    {
        root = addNode(root, key);
    };

    void printPreorder()
    {
        preorder(root);
    };

    void printInorder()
    {
        inorder(root);
    };

    bool find(int key)
    {
        if (findNode(key, root))
        {
            cout << "yes" << endl;
            return true;
        }

        cout << "no" << endl;
        return false;
    }
};

int main()
{
    int n;
    BinSearchTree tree;
    cin >> n;
    string s;
    while (n--)
    {
        cin >> s;
        if (s == "insert")
        {
            int a;
            cin >> a;
            tree.insert(a);
        }
        else if (s == "find")
        {
            int a;
            cin >> a;
            tree.find(a);
        }
        else if (s == "print")
        {
            tree.printInorder();
            cout << endl;
            tree.printPreorder();
            cout << endl;
        }
    }
}


Measured memory_bytes: 22028
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
ll power(ll x,ll y)
{
	ll ss=1;
	if(y==0)
	return ss;
	ll h=(power(x,y/2))%bg;
	h=(h*h)%bg;
	ll gg=(x*h)%bg;
	if(y%2==1)
	 return gg;
	else
	 return h;
}
ll modinv(ll k)
{
	return (power(k,bg-2))%bg;
}
ll dp[500001];
int main()
{
    ll a[3],b,c;
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1] && a[2]>a[0])
	    cout<<"Yes";
	else if(a[1]==a[2] && a[0]<a[1])
	    cout<<"Yes";
	else
	    cout<<"No";		   	  	  	
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include <vector>
using namespace std;
int test[101];
int main() {
	long long n, a,ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; test[h] = a;
	}
	for (int h = 0; h < n; h++) {
		if (test[h] > test[h + 1]) {
			ans += test[h] - test[h + 1];
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int a[2],k,max,i,b=0;

   scanf("%d%d%d",&a[0],&a[1],&a[2]);
   scanf("%d",&k);

   max=a[0];
   for(i=1;i<3;i++){
     if(max<a[i]){
      max = a[i];
      b = i;
     }
   }

   for(i=1;i<=k;i++)
     max = max * 2;

   if(b==0)
     max = max + a[1] + a[2];
   else if(b==1)
     max = max + a[0] + a[2];
   else if(b==2)
     max = max + a[0] + a[1];

   printf("%d\n",max);
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 1E5 + 100;
typedef pair<int, int> P;
P a[N];

int main() {
    int n; cin >> n;
    FOR (i, 1, n + 1) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1, [](const P &a, const P &b) {
        return a.first + a.second > b.first + b.second;
    });
    LL ans = 0;
    FOR (i, 1, n + 1) {
        if (i % 2) ans += a[i].first;
        else ans -= a[i].second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,t;
int main() {
	cin>>n>>t;
	vector<pair <int,int>> p(n);
	
	for(int i=0;i<n;i++){
		cin>>p[i].first>>p[i].second;
	}
	sort(p.begin(),p.end());
	for(int i=0;i<n;i++){
		if(p[i].second<=t){
			cout<<p[i].first<<endl;
			return 0;
		}
	}
	cout<<"TLE"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int k,z,l;
  cin>>k>>z;
  l=k;
  while (k>1){
    cout<<z-(k-1)<<" ";
    k--;
  }
  cout<<z<<" ";
  while(l>1){
    z=z+1;
    cout<<z<<" ";
    l--;
  }
return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)


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


int main() {
    int n;
    cin >> n;
    if (n == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    else if (n == 4) {
        cout << "2 5 20 63" << endl;
        return 0;
    }
    else if (n == 5) {
        cout << "2 3 4 5 16" << endl;
        return 0;
    }

    vector<int> v;
    for (int i = 0; i < 30000 / 6; i++) {
        v.push_back(i * 6 + 2);
        v.push_back(i * 6 + 3);
        v.push_back(i * 6 + 4);
        v.push_back(i * 6 + 6);
    }

    vector<int> ans(n);
    long long s = 0;
    for (int i = 0; i < n; i++) {
        s += (long long)v.at(i);
        ans.at(i) = v.at(i);
    }

    if (s % 6 == 0) {
        for (auto x: ans) {
            cout << x << " ";
        }
        cout << endl;
    }
    else if (s % 6 == 2) {
        for (auto x: ans) {
            if (x == 2) cout << 30000 << " ";
            else cout << x << " ";
        }
        cout << endl;
    }
    else if (s % 6 == 3) {
        for (auto x: ans) {
            if (x == 3) cout << 30000 << " ";
            else cout << x << " ";
        }
        cout << endl;
    }
    else if (s % 6 == 5) {
        for (auto x: ans) {
            if (x == 3) cout << 29998 << " ";
            else cout << x << " ";
        }
        cout << endl;
    }
}

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

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	int sum = 0;
	int T[N]; for(int i=0;i<N;i++){ cin >> T[i]; sum += T[i]; }
	
	int M; cin >> M;
	pair<int,int> timeDrink[M]; for(int i=0;i<M;i++) cin >> timeDrink[i].first >> timeDrink[i].second;
	
	for(int i=0;i<M;i++){
		int time = sum - T[timeDrink[i].first-1];
		time += timeDrink[i].second;
		cout << time << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 384
// ARC083
// C - Sugar Water

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int A, B, C, D, E, F;

int main() {
    cin >> A >> B >> C >> D >> E >> F;

    int ans_w, ans_s;
    double max_p = 0.0;
    for (int a = 0; a <= F / (100 * A); a++) {
        for (int b = 0; b <= F / (100 * B); b++) {
            int w = 100 * (A * a + B * b);
            if (w == 0) {
                continue;
            }
            int s_max = min(F - w, w / 100 * E);
            for (int c = 0; c * C <= s_max; c++) {
                for (int d = 0; c * C + d * D <= s_max; d++) {
                    int s = c * C + d * D;
                    double p = 100.0 * s / (w + s);
                    if (p >= max_p) {
                        max_p = p;
                        ans_w = w;
                        ans_s = s;
                    }
                }
            }
        }
    }

    cout << (ans_w + ans_s) << " " << ans_s << endl;

    return 0;
}


Measured memory_bytes: 256
R=range;N,K=map(int,input().split());Q=R(N+1);d=[[0]*2**N for _ in Q];f=[[0]*2**N for _ in Q]
for i in Q:
 for j,c in enumerate(input()):d[i][j]=int(c)
for i in R(1,N+1):
 for j in R(1<<i):
  t=j>>i-1&1;r=0
  while r<i and j>>i-1-r&1==t:r+=1
  f[i][j]=r
for i in Q:
 for k in R(i+1,N+1):
  z=k-i;m=(1<<z)-1
  for j in R(1<<k):
   d[i][j>>z]+=d[k][j];r=f[z][j&m]
   if r!=z:d[k-r][j>>z<<z-r|j&(1<<z-r)-1]+=d[k][j]
 for j in R(1<<i):
  if d[i][j]>=K:I=i;J=j;break
print(''if I==J==0else bin(J)[2:].zfill(I))

Measured memory_bytes: 404872
#include<iostream>
#include<vector>
#include<algorithm>
#define INFTY 10000
#define PII pair<int,int>
#define MPII(a,b) make_pair(a,b)
using namespace std;
class NODE
{
public:
	vector<PII> v;
	int index = 0;
	bool Isdone = false;
};
class Tree
{
public:
	vector<int> V;
	int cost = 0;
};

int main()
{
	NODE* nodes;
	nodes = new NODE[101];
	Tree T;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			int t;
			cin >> t;
			if (t != -1)
			{
				PII p = MPII(t, j);
				nodes[i].v.push_back(p);
			}
		}
		sort(nodes[i].v.begin(), nodes[i].v.end());
	}
	T.V.push_back(1);
	nodes[1].Isdone = true;
	while (1)
	{
		if (T.V.size() == n)break;
		int mincost=INFTY;
		int addv=-1;
		int index;
		for (auto itr : T.V)
		{
			if (nodes[itr].v.size() <= nodes[itr].index)continue;
			while (1)
			{
				if (nodes[nodes[itr].v[nodes[itr].index].second].Isdone == false)break;
				nodes[itr].index++;
				if (nodes[itr].v.size() <= nodes[itr].index)break;
			}
			if (nodes[itr].v.size() <= nodes[itr].index)continue;
			if (mincost >= nodes[itr].v[nodes[itr].index].first)
			{
				mincost = nodes[itr].v[nodes[itr].index].first;
				addv = nodes[itr].v[nodes[itr].index].second;
				index = itr;
			}
		}
		
		nodes[index].index++;
		T.V.push_back(addv);
		nodes[addv].Isdone = true;
		T.cost += mincost;
	}
	cout << T.cost << endl;
	delete[] nodes;
	return 0;
}

Measured memory_bytes: 3216
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        fozubaoyou    pass System Test!
        quoted from "https://codeforces.com/contest/472/submission/7996840"
*/
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

vvi v(8);
ll ans=0;

void dfs(int pos, vector<bool> passed, int passnum, int n){
	passed[pos]=true;
	if(passnum==n){
		ans++;
	}
	for(int i=0;i<v[pos].size();i++){
		if(!passed[v[pos][i]])dfs(v[pos][i],passed,passnum+1,n);
	}
}

int main(void){
    
	int n,m;
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		v[a-1].push_back(b-1);
		v[b-1].push_back(a-1);
	}
	vector<bool> passed(n,false);
	passed[0]=true;
	dfs(0,passed,1,n);
	fin(ans);
	

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int day;
    int homework;
    int timeHomework[100001];


    //入力部分
    scanf("%d",&day);
    scanf("%d",&homework);

    for(int i=1;i<=homework;i++){
        scanf("%d",&timeHomework[i]);
    }

    //計算部分
    for(int i=1;i<=homework;i++){
        day -= timeHomework[i];
    }
    if(day < 0)day = -1;

    //出力部分
    printf("%d\n",day);
}

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

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

int main(){
  ll a, b;
  cin >> a >> b;
  ll result;
  if(b % a == 0) 
    result = a + b;
  else
    result = b - a;
    
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    int A, B, AB, X, Y;
    cin >> A >> B >> AB >> X >> Y;
    int m = 1 << 30;
    for (int c = 0; c <= 200000; c += 2) {
        if (X < c/2 && Y < c/2) {
            break;
        }
        int x = max(0, X - c/2);
        int y = max(0, Y - c/2);
        m = min(m, A * x + B * y + AB * c);
    }
    cout << m << endl;
    return 0;
}


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

int main(void){
  int i = 0;
  char ch[2];
  char str[64];

  gets(str);

  while (i < 5){
    ch[0] = str[2*i];
    if (atoi(ch) == 0){
      printf("%d", i+1);
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 1708
w, h, n = gets.split.map(&:to_i)
x, y = gets.split.map(&:to_i)

ans = 0
(n - 1).times do
    nx, ny = gets.split.map(&:to_i)
    v = [(nx - x).abs, (ny - y).abs]
    ans += v.inject(:+) - ((nx - x) * (ny - y) > 0 ? v.min : 0)
    x, y = nx, ny
end
puts ans

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m;
  cin >> n >> m;
  long long int cnt=0;
  if(n*2>m){
    cnt+=m/2;
  }else{
    cnt+=n;
    m-=n*2;
    cnt+=m/4;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
cntswap = 0

for i in range(0,N):
    minj = i
    for j in range(i,N):
        if A[minj] > A[j]:
            minj = j
    if i != minj:
        temp = A[i]
        A[i] = A[minj]
        A[minj] = temp
        cntswap += 1

for i in range(0, N-1):
    print(A[i], '', end='')
print(A[N-1])
print(cntswap)


Measured memory_bytes: 5624
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    k = int(input())
    nums = list(range(50))

    if k <= 50:
        for i in range(k):
            for j in range(50):
                if j == i:
                    nums[j] += 50
                else:
                    nums[j] -= 1
        print(50)
        print(*nums)
    else:
        q, r = divmod(k, 50)
        nums = [num + q for num in nums]
        for i in range(r):
            for j in range(50):
                if j == i:
                    nums[j] += 50
                else:
                    nums[j] -= 1
        print(50)
        print(*nums)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <string>

template <int MOD>
struct ModInt {
    using lint = long long;
    using mint = ModInt<MOD>;

    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // assignment
    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->val = x.val; }
        return *this;
    }

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt operator~() const {
        // non-recursive extended euclidean algorithm
        int s = val, t = MOD;
        mint sx = 1, sy = 0, tx = 0, ty = 1;
        while (s % t != 0) {
            int div = s / t;
            s = s - t * div;
            sx = sx - tx * div;
            sy = sy - ty * div;

            std::swap(s, t);
            std::swap(sx, tx);
            std::swap(sy, ty);
        }
        // t == 1 (since val and MOD is coprime)
        return mint(tx);
    }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= ~x; }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

int main() {
    int n, m;
    {
        std::string s;
        std::cin >> n >> s;
        m = s.length();
    }

    std::vector<mint> dp(n + 2, 0), ndp(n + 2);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        std::fill(ndp.begin(), ndp.end(), 0);
        for (int k = 0; k <= i; ++k) {
            ndp[k] += dp[k + 1];
            if (k > 0) {
                ndp[k] += dp[k - 1] * 2;
            } else {
                ndp[k] += dp[0];
            }
        }
        std::swap(dp, ndp);
    }

    std::cout << dp[m] / ipow(mint(2), m) << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

int n;
double x, x2, x3, x4, y, y2, y3, y4;

int main() {
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x, &y, &x2, &y2, &x3, &y3, &x4, &y4 );
		if ( fabs( ( x2 - x ) * ( y4 - y3 ) - ( x4 - x3 ) * ( y2 - y ) ) < EPS ) {
			printf( "YES\n" );
		}
		else {
			printf( "NO\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 1200
s=gets.chars.to_a
easyFlag=true
s.each_with_index do |foot_pos,index|
  count = index + 1
  if (count.even? && foot_pos=="R") || (count.odd? && foot_pos=="L")
      easyFlag = false
      break
  end
end
puts easyFlag ? :Yes : :No

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

int main(){
  int A, B, Q;cin>>A>>B>>Q;
  vll s, t, x;
  for (int i=0;i<A;++i){
    ll s_;cin>>s_;s.push_back(s_);
  }
  for (int i=0;i<B;++i){
    ll t_;cin>>t_;t.push_back(t_);
  }
  for (int i=0;i<Q;++i){
    ll x_;cin>>x_;x.push_back(x_);
  }

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  for (int i=0;i<Q;++i){
    ll ans=1000000000000;
    int j=lower_bound(s.begin(), s.end(), x[i])-s.begin();
    int k=lower_bound(t.begin(), t.end(),x[i])-t.begin();
  
    if(j<A&&k<B){
      ll sp=s[j];ll tp=t[k];
      ans=min(ans, max(sp,tp)-x[i]);
    }
    if(j<A&&k>0){
      ll sp=s[j]; ll tm=t[k-1];
      ans=min(ans, min(2*sp-tm-x[i], sp-2*tm+x[i]));
    }
    if (j>0&&k<B){
      ll sm=s[j-1];ll tp=t[k];
      ans=min(ans, min(2*tp-sm-x[i],tp-2*sm+x[i]));
    }
    if(j>0&&k>0){
      ll sm=s[j-1];ll tm=t[k-1];
      ans=min(ans, x[i]-min(sm,tm));
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int N;
	while( cin >> N && N){
		string s;
		map<char,int> flag;
		int f = 0;
		int cnt = 0;
		for(int i = 0 ; i < N ; i++){
			cin >> s;
			flag[s[0]] ^= 1;
			if( !f && flag['l'] && flag['r'] ){
				f = 1;
				cnt++;
			}
			if( !flag['l'] && !flag['r'] ){
				if(f){
					cnt++;
					f = 0;
				}
			}
		}
		cout << cnt << endl;
	}
}

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

#define TRUE 1
#define FALSE 0

int check(char *S, int len){
	if(len %2 != 0){
		return FALSE;
	}
	else{
		for(int i=0; i<len/2; i++){
			if(S[i] != S[len/2 + i]){
				return FALSE;
			}
		}
	}
	return TRUE;
}

int main(){

	char S[200];
	scanf("%s",S);
	int len = strlen(S) - 1;
	// printf("len = %d\n",len);
	while(len != 1){
		// printf("len = %d\n",len);
		if(check(S,len) == TRUE){
			printf("%d\n",len);
			return 0;
		}
		else if(check(S,len) == FALSE){
			len--;
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
s = gets.chomp.chars.map{|v|v.ord - ?a.ord}
n = s.size
t = gets.chomp.chars.map{|v|v.ord - ?a.ord}

dp = Array.new(n)
memo = Array.new(26,-1)
(n-1).downto(0) do |i|
  memo[s[i]] = i
  dp[i] = memo.dup
end

# tの文字でsに含まれないものがあれば解なし
if (t - s).size > 0
  puts -1
  exit
end

page = 0
i = 0 # sの位置
j = 0 # tの位置
while j < t.size
  if n <= i 
    i = 0
    page += 1
  end

  ni = dp[i][t[j]]
  if ni == -1
    page += 1
    i = 0
  else
    i = ni + 1
    j += 1
  end
end

ans = page * n + i
puts ans


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

int main(){
  long N, M;
  cin >> N >> M;
  if(N>M/2){
    cout << M/2 << endl;
    return 0;
  }
  M=M-2*N;
  cout << N+M/4 << endl;
  return 0;
}

Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()

typedef long long LL;
typedef long double LD;

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < a.second;
    }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{
    int N, ans;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> L(N+1, 0), R(N+1, 0), M(N, 0);
    for (int i = 0; i <= N-1; i++)
        L[i+1] = __gcd(L[i], A[i]);

    for (int i = N-1; i >= 0; i--)
        R[i] = __gcd(R[i+1], A[i]);

    for (int i = 0; i < N; i++)
        M[i] = __gcd(L[i], R[i+1]);

    sort(all(M));
    ans = M[N-1];

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



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n;

	while (cin >> n && n != 0) {
		P s[100010];
		int go, k = 1, ans = 0;

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

			if (i == 1) {
				s[k++] = P(i, go);
				continue;
			}

			if (s[k - 1].second != go) {
				if (i % 2) {//?\???°
					s[k++] = P(i, go);
				}
				else {
					if (k == 2)
						s[k - 1].second = go;
					else
						k--;
				}
			}
		}

		s[k] = P(n + 1, 0);
		for (int i = 1; i < k; ++i) {
			if (s[i].second == 0)
				ans += s[i + 1].first - s[i].first;
		}

		cout << ans << endl;
	}

	return 0;
}
/*
20
0
1
1
0
1
0
0
0
0
0
1
1
1
1
1
0
1
0
0
1
*/

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
inline vector<int> topo(vector<int> adj[], vector<int>& in){
    int v = in.size();
    queue<int> q;
    vector<int> res;
    vector<bool> vis(v);
    for(int i = 0 ; i < v ; i++)
        if(in[i] == 0)
        q.push(i), vis[i] = true;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        res.push_back(u);
        for(int i = 0 ; i < adj[u].size() ; i++){
            in[adj[u][i]]--;
            if(!vis[adj[u][i]] and in[adj[u][i]] == 0){
                q.push(adj[u][i]);
                vis[adj[u][i]] = true;
            }
        }
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int v, e;
    cin >> v >> e;
    vector<int> adj[v], in(v);
    for(int i = 0 ; i < e ; i++){
      int p, q;
      cin >> p >> q;
      adj[p-1].push_back(q-1);
      in[q-1]++;
    }
    vector<int> sorted = topo(adj, in);
    vector<int> dist(v);
    for(int i = 0 ; i < v ; i++){
        {
            for(auto u : adj[sorted[i]]){
                if(dist[u] < dist[sorted[i]]+1)
                    dist[u] = dist[sorted[i]]+1;
            }
        }
    }
    cout << *max_element(dist.begin(), dist.end()) << endl;
}


Measured memory_bytes: 10064
AB=input().split(" ")
A=int(AB[0])
B=int(AB[1])

if A==1:
    if B==1:
        print("Draw")
    else:
        print("Alice")
elif B==1:
    print("Bob")

else:
    if A>B:
        print("Alice")
    elif A<B:
        print("Bob")
    else:
        print("Draw")


Measured memory_bytes: 3064
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  combination c(n+k);
  mint ans = 0;
  for (int i = 0; i <= k; ++i) {
    mint now = mint(26).pow(k-i);
    now *= mint(25).pow(i);
    now *= c(i+n-1,n-1);
    ans += now;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35552
x1, y1, x2, y2 = map(int, input().split())

#x_diff = 2 3 6 6
#diff = abs(x1-x2) if x1!=x2 else abs(y1-y2)

def up(x_pre, y_pre, x_diff, y_diff):
  return x_pre-x_diff, y_pre+y_diff
def left(x_pre, y_pre, x_diff, y_diff):
  return x_pre-x_diff, y_pre-y_diff
def down(x_pre, y_pre, x_diff, y_diff):
  return x_pre+x_diff, y_pre-y_diff
def right(x_pre, y_pre, x_diff, y_diff):
  return x_pre+x_diff, y_pre+y_diff

x_diff_ = x2 - x1
y_diff_ = y2 - y1
#print(x_diff_, y_diff_)
rotate = []
if y_diff_ >= 0:
  if x_diff_ >= 0:
    #print(1)
    rotate = [up, left]
  else:
    #print(2)
    rotate = [left, down]
else:
  if x_diff_ >= 0:
    #print(3)
    rotate = [right, up]
  else:
    #print(4)
    rotate = [down, right]
  
x3, y3 = rotate[0](x2, y2, abs(y2-y1), abs(x2-x1))
#print(abs(y2-y1), abs(x2-x1))
x4, y4 = rotate[1](x3, y3, abs(y3-y2), abs(x3-x2))
#print(abs(y3-y2), abs(x3-x2))
print(x3, y3, x4, y4)
  


Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<M;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<int> arr(N);
  for(int i=0;i<N;++i) arr[i] = i;
  bool can;
  bool tmpcan;
  int ans = 0;
  do {
    if(arr[0]!=0) continue;
    can = true;
    for(int i=0;i<N-1;++i) {
      tmpcan = false;
      for(int j=0;j<edge[arr[i]].size();++j) {
        if(edge[arr[i]][j]==arr[i+1]) tmpcan = true;
      }
      if(!tmpcan) can = false;
    }
    if(can) {
      ans++;
    }
  }while(next_permutation(arr.begin(), arr.end()));
  cout<<ans<<endl;
}



Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>

using namespace std;

#define sz(a) int((a).size()) 
#define pb push_back 
#define mp make_pair
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 

typedef long long ll;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef pair<pi,pi > pi2;

typedef pair<ll,ll> pl;
typedef pair<pl,ll> pll;
typedef pair<pl,pl > pl2;

typedef vector<node> vn;

typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
typedef vector<pi2 > vpi2;

typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<pll> vpll;
typedef vector<pl2 > vpl2;

int main(){
	int n,m;
	cin>>n>>m;
	vl a;
	ll maxn=-(1L<<60);
	ll arr[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++)
			cin>>arr[i][j];
	}

	for(int i=0;i<8;i++){
		a.clear();
		for(int j=0;j<n;j++){
			ll sum=0;
			for(int k=0;k<3;k++){
				if(i&(1<<k)){
					sum+=arr[j][k];
				}
				else
					sum-=arr[j][k];
			}
			a.pb(sum);
		}
		sort(a.rbegin(),a.rend());
		ll temp=0;
		for(int i=0;i<m;i++)
			temp+=a[i];
		maxn=max(temp,maxn);
	}

	cout<<maxn;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

constexpr lint INF=1e18;

struct edge
{
	lint A,B,C;
};

int main()
{
	lint N,M,P;
	
	cin >> N >> M >> P;
	
	vector<edge> edges;
	for(int i=0;i<M;i++)
	{
		lint A,B,C;
		cin >> A >> B >> C;
		edges.push_back({A-1,B-1,-(C-P)});
	}

	lint dist[2510]{};
	for(int i=1;i<2510;i++)
		dist[i]=INF;
	
	lint ntime,n2time;
	for(lint i=0;i<2*N+10;i++)
	{
		for(auto&& e:edges)
		{
			if(dist[e.A]>=INF)continue;
			if(dist[e.A]+e.C<dist[e.B])
				dist[e.B]=dist[e.A]+e.C;
		}

		if(i==N-1)ntime=dist[N-1];
		if(i==2*N-1)n2time=dist[N-1];
	}

	if(ntime!=n2time) cout << -1;
	else cout << max(-dist[N-1],(lint)0);
	cout << endl;

	return 0;
}


Measured memory_bytes: 576
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S := ReadString()
	if S == "zyxwvutsrqponmlkjihgfedcba" {
		fmt.Println(-1)
		return
	}
	chars := []byte(S)
	m := make(map[byte]int)
	for _, c := range chars {
		m[c]++
	}

	if len(chars) <= 25 && isUnique(m) {
		for c := byte('a'); true; c++ {
			if m[c] == 0 {
				chars = append(chars, c)
				fmt.Println(string(chars))
				return
			}
		}
	}

	for i := len(chars) - 1; i >= 0; i-- {
		if i+1 <= len(chars)-1 && chars[i] < chars[i+1] && isUnique(m) {
			for c := chars[i] + 1; true; c++ {
				if m[c] == 0 {
					chars[i] = c
					fmt.Println(string(chars[:i+1]))
					return
				}
			}
		}
		m[chars[i]]--
	}
}

func isUnique(m map[byte]int) bool {
	for _, n := range m {
		if n > 1 {
			return false
		}
	}
	return true
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1848
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n;
  map<int, int> mo, me;

  cin >> n;
  for (int i = 0;i < n; ++i) {
    int a;
    cin >> a;
    if ((i+1)%2 == 0) {
      if (me.find(a) == me.end()) {
        me.insert(make_pair(a, 1));
      } else {
        me[a]++;
      }
    } else {
      if (mo.find(a) == mo.end()) {
        mo.insert(make_pair(a, 1));
      } else {
        mo[a]++;
      }
    }
  }

  int te = 0, se = 0, tie = -1, sie = -1;
  int to = 0, so = 0, tio = -1, sio = -1;
  for (auto p : me) {
    if (p.second > te) {
      se = te;
      te = p.second;
      sie = tie;
      tie = p.first;
    } else if (p.second > se) {
      se = p.second;
      sie = p.first;
    }
  }
  for (auto p : mo) {
    if (p.second > to) {
      so = to;
      to = p.second;
      sio = tio;
      tio = p.first;
    } else if (p.second > so) {
      so = p.second;
      sio = p.first;
    }
  }

  int result;
  if (tie == tio) {
    if (sie == -1 && sio == -1) {
      result = n-te;
    } else if (sie == -1) {
      result = n - te - so;
    } else if (sio == -1) {
      result = n - to - se;
    } else {
      result = te+so > to+se ? n-te-so : n-to-se;
    }
  } else {
    result = n-te-to;
  }

  cout << result << endl;
  return 0;
}


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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve(int &test) {
    int h, w, k;
    cin >> h >> w >> k;
    std::vector<string > c(h);
    for(int i = 0; i < h; i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < (1<<h); i++){
        for(int j = 0; j < (1<< w); j++){
            std::vector<string > tmp = c;
            for(int ii = 0; ii < h; ii++){
                if((i>>ii)&1){
                    for(int jj = 0; jj < w; jj++)
                        tmp[ii][jj] = '.';
                }
            }
            for(int ii = 0; ii < w; ii++){
                if((j>>ii)&1){
                    for(int jj = 0; jj < h; jj++)
                        tmp[jj][ii] = '.';
                }
            }
            int cur = 0;
            for(int ii = 0; ii < h; ii++){
                for(int jj = 0; jj < w; jj++)
                    if(tmp[ii][jj] == '#')cur++;
            }
            if(cur == k) ans++;
        }
    }
    cout << ans;
    cout << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;

    start = clock(); 

    cout << fixed << setprecision(2);
    
   
     
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    cerr << time(start);
    return 0;
}

Measured memory_bytes: 3840
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int n; cin >> n;
    if (n%1000 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - n%1000 << endl;
    return 0;
}

Measured memory_bytes: 3592
n, k = gets.split().map(&:to_i)
p = gets.split().map(&:to_i)
array = []
tmp = 0
ans = 0

p.each_with_index do |item, index|
  tmp += (item + 1)/2.0
  array[index] = tmp
end

ans = array[k-1]

(k..n-1).each do |i|
  ans = [ans, array[i] - array[i-k]].max
end

puts ans


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

int main() {
    int n;
    scanf("%d", &n);
    int approved = 1;    
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if (a % 2 == 0) {
            if  (a % 3 == 0 || a % 5 == 0)  {
            //
            } else {
                approved = 0;
                break;
            }
        }
    }
    printf("%s", approved ? "APPROVED" : "DENIED");
    return 0;
}

Measured memory_bytes: 128
#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>;
const int inf = 1001001001;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int cnt = 0;
    rep(i, h) rep(j, w) if(s[i][j]=='#') cnt++;
    queue<P> q;
    q.push(P{0, 0});
    vector<vector<int>> table(h, vector<int>(w, inf));
    table[0][0] = 1;
    while (!q.empty()) {
        P x = q.front(); q.pop();
        rep(i, 4) {
            int ch = x.first; int cw = x.second;
            int nh = ch+dh[i]; int nw = cw+dw[i];
            if(nh<0||nh>=h||nw<0||nw>=w) continue;
            if(s[nh][nw]=='#') continue;
            if(table[ch][cw]+1 >= table[nh][nw]) continue;
            q.push(P{nh, nw});
            table[nh][nw] = min(table[nh][nw], table[ch][cw]+1);
        }
    }
    if(table[h-1][w-1]==inf) cout << -1;
    else cout << h*w - cnt - table[h-1][w-1];
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> S;
    int N, L; cin >> N >> L;
    rep(i, N){
        string s; cin >> s;
        S.pb(s);
    }
    sort(all(S));
    rep(i, N) cout << S[i];
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define x first
#define y second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define szz(x) (int) (x).size()
#define FOR(i,a,b) for (int i = (a), _for = (b); i < _for; i++)
#define REP(i,n) FOR(i,0,(n))
#define _ << " " <<
const ll MOD = 1000000007ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline ll SUB(ll a, ll b) { return a-b >= 0ll ? a-b : a-b+MOD; }
inline ll ADD(ll a, ll b) { return a+b >= MOD ? a+b-MOD : a+b; }
inline ll MUL(ll a, ll b) { return a*b % MOD; }


constexpr int MAXX = 100000;
int dp[MAXX + 3];
int n, m;
vi graph[MAXX + 3];
vi rev[MAXX + 3];

int f(int node) {
  if (dp[node] != -1) return dp[node];
  int ret = 1;
  int sz = (int)rev[node].size();
  REP(i, sz) {
    ret = max(ret, 1 + f(rev[node][i]));
  }
  return dp[node] = ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(int) * (MAXX + 3));
  cin >> n >> m;
  REP(i,m) {
    int a, b;
    cin >> a >> b;
    graph[a].pb(b);
    rev[b].pb(a);
  }

  int ans = 0;
  FOR(i, 1, n + 1) {
    if (graph[i].empty()) {
      ans = max(ans, f(i));
    }
  }
  cout << (ans - 1) << endl;
}



Measured memory_bytes: 16256
//IN THE NAME OF 'ALLAH'//
#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n ;
    cin>> n ;
    string s ;
    cin>> s ;
    int len = s.size();
    if(  s.substr( 0 , len/2) == s.substr( len/2 , len ) )cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

int main(){
	int a;
	cin>>a;
	if(a<105){
		cout<<0<<endl;
	}
		else if(104<a&&a<135){
			cout<<1<<endl;
		}
			else if(134<a&&a<165){
				cout<<2<<endl;
			}
				else if(164<a&&a<189){
					cout<<3<<endl;
				}
					else if(188<a&&a<195){
						cout<<4<<endl;
					}
					else{
						cout<<5<<endl;
					}
	return 0;	
}


Measured memory_bytes: 256