akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    ll n;cin>>n;
    vel a(n);
    ll m =1000;
    ll kab =0;
    rep(i,n) {
        cin>>a[i];
    }
    rep(i,n) {
        if(i==n-1) {
                m+=kab*a[i];
                kab=0;
        }
        else {
            if(a[i]<a[i+1]) {
                ll kari = m/a[i];
                kab += kari;
                m -= kari*a[i];
            }
            else {
                m += kab*a[i];
                kab =0;
            }
        }
    }
    cout<<m<<endl;
}


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

using lint = int64_t;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
        cerr << fixed << setprecision(12);
    }
} iosetup;

struct Task {
    lint time, deadline;
    bool operator < (const Task that) const {
        return deadline < that.deadline;
    }
};

int main() {
    int n;
    cin >> n;
    vector<Task> tasks(n);
    for (int i = 0; i < n; i++) {
        cin >> tasks[i].time >> tasks[i].deadline;
    }
    sort(tasks.begin(), tasks.end());

    bool ans = true;
    lint now = 0;
    for (int i = 0; i < n; i++) {
        now += tasks[i].time;
        if (now > tasks[i].deadline) {
            ans = false;
            break;
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  for(int i=0;i<s.size();i++){
    s.at(i)+=n;
    if(s.at(i)>90){
      s.at(i)-=26;
    }
  }
  cout<<s<<endl;
}

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

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if ((c - a - b) * (c - a - b) > 4 * a * b && c - a - b > 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

typedef long long ll;
//sort(rt,rt+sizeof(rt)/sizeof(rt[0]),greater<>());
using namespace std;

#define rep(i,n) for(i=0;i<n;i++)



int main(){
    int i,n;
    cin>>n;
    ll dan[n];
    rep(i,n){
        cin>>dan[i];
    }
    if(n==1){
        cout<<"Yes";
        return 0;
    }
    for(i=n-1;i>0;i--){
        if(dan[i]>=dan[i-1]){
            ;
        }else if(dan[i]==dan[i-1]-1){
            dan[i-1]--;
        }else{
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int a = N;
    int digits = 0;
    while(a > 0){
        a /= 10;
        digits++;
    }
    ll ans = 0;
    for(int i = 1; i < digits; i++){
        if(i % 2 == 1){
            int x = 9;
            REP(j,i-1){
                x *= 10;
            }
            ans += x;
        }
    }
    if(digits % 2 == 1){
        int x = 1;
        REP(i,digits-1) x *= 10;
        ans += N - x + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(10);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int N;
int u[100005], v[100005], w[100005];

VVec<P> g(100005);
vector<int> ans(100005);

void dfs(int now, int p, int mask) {
	for (auto x: g[now]) {
		if (x.fi == p) continue;
		if (x.se % 2 == 0) {
			ans[x.fi] = mask;
			dfs(x.fi, now, mask);
		}
		else {
			ans[x.fi] = (mask == 1 ? 0 : 1);
			dfs(x.fi, now, ans[x.fi]);
		}
	}
}

int main() {
	cin >> N;
	rep (i, N - 1) {
		cin >> u[i] >> v[i] >> w[i];
		u[i]--;
		v[i]--;
		g[u[i]].eb(v[i], w[i]);
		g[v[i]].eb(u[i], w[i]);
	}

	dfs(0, -1, 0);

	rep (i, N) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 12056
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
M = int(readline())
DC = np.array(read().split(),np.int64)

D = DC[::2]; C = DC[1::2]

# 桁数が減って総和は不変 or 桁数が不変で総和が-9
# 手順によらない
# 「桁数 * 9 + 和」が9ずつの減少量

x = 9 * C.sum() + (D * C).sum()

y = x % 9
if y == 0:
    y = 9
y += 9
answer = (x - y) // 9
print(answer)

Measured memory_bytes: 29956
#include<bits/stdc++.h>
using namespace std;
 
#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back
#define fi first
#define se second
 
const int mod = 1e8;
const int maxn = 1e5 + 10;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);
const ll inf = 1e18;
 
int n,m;
priority_queue<int >q;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    rep(i,0,n) {
        int x;
        cin >> x;
        q.push(x);
    }
    while(m--){
        int u = q.top();
        q.pop();
        q.push(u / 2);
    }
    ll ans = 0;
    while(!q.empty()){
        ll u = q.top();
        q.pop();
        ans += u;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 892
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import qualified Data.IntSet as IS


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    _ <- readLn :: IO Int
    s <- C.getLine
    print $ length $ C.group s



Measured memory_bytes: 1148
def edit_distance(M):
  n = len(M)



  m = [[0 for i in range(n)] for j in range(n)]
   
  for long in range(2, n+1):

    for i in range(0, n-long+1):

      j = i + long - 1

      def a(i, k ,j):
        return m[i][k] + m[k+1][j] + M[i][0]*M[k][1]*M[j][1]
      m[i][j] = min(a(i, k, j) for k in range(i, j))
   
  return m[0][n-1]
 
n = input()
M = []
 
for i in range(n):
  M.append(map(int, raw_input().split()))
print edit_distance(M)

Measured memory_bytes: 6532
from collections import deque

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

connected = [set() for i in range(n+1)]

for i in range(m):
  a,b = map(int, input().split())
  connected[a].add(b)
  connected[b].add(a)
  
def bfs(x):
  queue = deque([x])
  d = [None] * (n+1)
  d[x] = 0
  while queue:
    v = queue.popleft()
    for i in connected[v]:
      if d[i] is None:
        d[i] = v
        queue.append(i)
  return d

print('Yes')
ans = bfs(1)[2:]

for i in ans:
  print(i)

Measured memory_bytes: 63380
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const double PI = acos(-1);

double rad(double x)
{	return x * PI / 180.0;	}

int main()
{
    int n;
	while(cin >> n && n)
	{
		double S = 0;
		double v;
		
		double d = 360;
		rep(i, n - 1)
		{
			cin >> v; d -= v;
			S += sin(rad(v));
		}
		
		S += sin(rad(d));
		
		d = 360;
		cin >> n;
		rep(i, n - 1)
		{
			cin >> v; d -= v;
			S -= sin(rad(v));
		}
		
		S -= sin(rad(d));
		
		cout << (abs(S) < EPS ? 0 : (0 < S ? 1 : 2)) << endl;
	}
}

Measured memory_bytes: 0
import java.util.*

fun main(args:Array<String>) {
    val sc = Scanner(System.`in`)

    val N:Int = sc.nextInt()
    val T:Int = sc.nextInt()

    var i:Int = 0
    var ans:Int = 0

    while (i<N) {
        var c = sc.nextInt()
        var t = sc.nextInt()

        if (t <= T) {
            if (ans == 0) {
                ans = c
            } else {
                ans = Math.min(ans, c)
            }
        }
        i += 1
    }
    if (ans == 0) {
        println("TLE")
    } else {
        println(ans)
    }
}


Measured memory_bytes: 31260
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<int,int>
#define iil pair<ll,ll>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define x0 zxcxzcsacasd
#define x1 ghfghujfgfg
#define y0 olkjhdnncvcv
#define y1 bhvgrewm345345435
#define debug(x) std::cerr<<#x<<": "<<(x)<<'\n'
#define all(x) x.begin(), x.end()
using namespace std;

int main(){
	int n;
	cin>>n;
	int ans = 0;
	for(int a = 1; a <= n ; a++){
		ans+=(n-1)/a;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
 
    /**
     * @param args
     * @throws IOException 
     * @throws NumberFormatException 
     */
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
         
        Tree tree = new Tree();
        for(int i = 0; i < n; i++){
            String[] tmpArray = br.readLine().split(" ");
            if(tmpArray[0].equals("insert")){
                Node node = new Node(Integer.parseInt(tmpArray[1]), null, null);
                tree.insert(node);
            }
            else if(tmpArray[0].equals("find")){
            	if(tree.find(Integer.parseInt(tmpArray[1]))){
            		System.out.println("yes");
            	}
            	else{
            		System.out.println("no");
            	}
            }
            else {
                inorder(tree.root);
                System.out.println();
                preorder(tree.root);
                System.out.println();
            }
        }
    }
 
    static void preorder(Node node){
        System.out.print(" "+node.key);
        if(node.left != null){
            preorder(node.left);
        }
        if(node.right != null){
            preorder(node.right);
        }
    }
     
    static void inorder(Node node){
        if(node.left != null){
            inorder(node.left);
        }
        System.out.print(" "+node.key);
        if(node.right != null){
            inorder(node.right);
        }
    }
     
}
 
class Tree {
    Node root = null;
     
    public Tree(){
         
    }
    public Tree(Node root){
        this.root = root;
    }
     
    public boolean find(int key){
    	Node node = root;
    	
    	while(node != null){
    		if(node.key == key){
    			return true;
    		}
    		
    		else if(node.key > key){
    			node = node.left;
    		}
    		else {
    			node = node.right;
    		}
    	}
    	
    	return false;
    }
    public void insert (Node node){
        Node y = null;
        Node x = this.root;
        while(x != null){
            y = x;
            if( node.key < x.key){
                x = x.left;
            }
            else{
                x = x.right;
            }
        }
        node.parent = y;
         
        if (y == null){
            this.root = node;
        }
        else if(node.key < y.key){
            y.left = node;
        }
        else {
            y.right = node;
        }
    }
}
 
class Node {
    int key;
    Node left = null;
    Node right = null;
    Node parent = null;
     
    public Node(int key, Node left, Node right){
        this.key = key;
        this.left = left;
        this.right = right;
    }
}

Measured memory_bytes: 137564
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

A,B,C,K = imn()

ans = A-B
if K % 2 == 1: ans *= -1
print(ans)

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

using i64 = int64_t;

string J(string s){
    char c = s.back();
    s.pop_back();
    return c + s;
}

string C(string s){
    char c = s[0];
    s = s.substr(1, s.size()-1);
    return s + c;
}

string E(string s){
    string left = s.substr(0, s.size()/2);
    string right = s.substr(s.size()/2 + s.size()%2, s.size()/2);
    string res = right;
    if(s.size() % 2)res += s[s.size()/2];
    res += left;
    return res;
}

string A(string s){
    reverse(s.begin(), s.end());
    return s;
}

string P(string s){
    string res;
    for(auto c: s){
        if(c >= '0' && c <= '9'){
            if(c == '0')c = '9';
            else c--;
        }
        res.push_back(c);
    }
    return res;
}

string M(string s){
    string res;
    for(auto c: s){
        if(c >= '0' && c <= '9'){
            if(c == '9')c = '0';
            else c++;
        }
        res.push_back(c);
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        string mes;
        cin >> mes;
        reverse(s.begin(), s.end());
        for(auto c: s){
            if(c == 'J'){
                mes = J(mes);
            }else if(c == 'C'){
                mes = C(mes);
            }else if(c == 'E'){
                mes = E(mes);
            }else if(c == 'A'){
                mes = A(mes);
            }else if(c == 'P'){
                mes = P(mes);
            }else{
                mes = M(mes);
            }
        }
        cout << mes << endl;
    }

    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int n;
vector<int> a;
int main() {
    cin >> n;
    a.resize(n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int ans = 1; int min = a[1];
    for (int i = 2; i <= n; i++) {
        if (a[i] < min) {
            ++ans;
            min = a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};


int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        uf.merge(a,b);
    }

    int ans=0;
    rep(i,n){
        ans=max(ans,uf.size(i));
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3972
#include <stdio.h>
int main(void) {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 1e6 + 10;
int A[maxn];
int B[maxn];
int main(void)
{
	int n; cin >> n;
	set<P> s;
	set<int> s2;
	for (int i = 1; i <= (1 << n); ++i) {
		scanf("%d", &A[i]);
		s.insert(P(A[i], i));
	}
	auto t = s.end();
	t--;
	A[1] = (*t).first;
	s.erase(t);
	// cout << A[1] << endl;
	for (int i = 0; i < n; ++i) {
		for (int j = 1; j <= (1 << i); ++j) {
			auto it = s.lower_bound(P(A[j], 0));
			// cout << s.size() << endl;
			// cout << (it == s.begin()) << endl;
			if (it == s.begin())
				return 0 * puts("No");
			it--;
			// cout<<
			A[j + (1 << i)] = (*it).first;
			// cout << A[j + (1 << i)] << endl;
			s.erase(it);
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    set<int> st;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size() == n){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 9600
n, m = map(int, input().split())
tasks = []
for i in range(m):
    a, b = map(int, input().split())
    tasks.append([a, b])
tasks = sorted(tasks, key=lambda x:x[1])
cnt = 1
r = tasks[0][1]
for task in tasks:
    if task[0] >= r:
        cnt +=1
        r = task[1]
print(cnt)


Measured memory_bytes: 22108
#include <iostream>

using namespace std;

long long int gcd(long long int m, long long int n) {
    while(n != 0) { 
        long long int r = m % n; 
        m = n; 
        n = r; 
    } 
    return m;
}

long long int lcm(long long int m, long long int n) {
    return m * n / gcd(m, n);
}

int main(){
    long long int lower, higher, a, b;
    cin >> lower;
    cin >> higher;
    cin >> a;
    cin >> b;

    long long int ans = higher - lower + 1;
    
    long long int lower_a, lower_b, higher_a, higher_b, lower_c, higher_c;
    long long int c = lcm(a, b);


    if(lower%a==0){
        lower_a = lower;
    }else{
        lower_a = a*(lower/a+1);
    }
    
    if(lower%b==0){
        lower_b = lower;
    }else{
        lower_b = b*(lower/b+1);
    }

    if(lower%c==0){
        lower_c = lower;
    }else{
        lower_c = c*(lower/c+1);
    }


    higher_a = a*(higher/a);
    higher_b = b*(higher/b);
    higher_c = c*(higher/c);

    
    long long int to_minus_a = 1;
    long long int to_minus_b = 1;
    long long int to_minus_c = 1;
    if(higher_a != lower_a){
        to_minus_a = (higher_a - lower_a)/a-1+2;
    }
    if(higher_b != lower_b){
        to_minus_b = (higher_b - lower_b)/b-1+2;
    }
    if(higher_c != lower_c){
        to_minus_c = (higher_c - lower_c)/c-1+2;
    }


    cout << ans-to_minus_a-to_minus_b+to_minus_c << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < k; i++) {
			list.add(sc.nextInt());
		}
		tag: for (int i = n;; i++) {
			int num = i;
			for (int j = 0; j < String.valueOf(i).length(); j++) {
				if (list.contains(num % 10)) {
					continue tag;
				}
				num /= 10;
			}
			System.out.println(i);
			break tag;
		}
		sc.close();
	}

}


Measured memory_bytes: 26964
/***********************
*  Date: 2018.11.28    *
*  Problem:            *
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,q,co[100010],most[100010];
vector <int> g[100010];
vector <pair<int,pii> > qs;
bool vis[100010];

int main()
{
	cin>>n>>m;
	memset(most,-1,sizeof(most));
	rep(i,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	cin>>q;
	rep(i,q)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		qs.pb({x,{y,z}});
	}
	for(int i=qs.size()-1;i>=0;i--)
	{
		//cout<<qs[i].fi<<' '<<qs[i].se.fi<<' '<<qs[i].se.se<<endl;
		memset(vis,0,sizeof(vis));
		int v=qs[i].fi,colo=qs[i].se.se,dist=qs[i].se.fi;
		queue <pii> q;
		q.push({v,0});
		while(!q.empty())
		{
			int pos=q.front().fi,dist1=q.front().se;
			//cout<<pos<<' '<<colo<<' '<<dist<<' '<<dist1<<endl;
			q.pop();
			if(vis[pos]) continue;
			if(most[pos]>=dist-dist1) continue;
			vis[pos]=true;
			most[pos]=dist-dist1;
			if(co[pos]==0) co[pos]=colo;
			if(dist1==dist) continue;
			rep(j,g[pos].size()) q.push({g[pos][j],dist1+1});
		}
	}
	repn(i,n) printf("%d\n",co[i]);
	rt0;
}

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

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

int main() {
  int n;
  cin >> n;
  queue<int> que;
  rep(i, n) {
    int p;
    cin >> p;
    if(i == 0) que.push(p);
    else {
      if(que.back() > p) que.push(p);
    }
  }
  cout << que.size() << endl;
}


Measured memory_bytes: 4244
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
 
//using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define NULL 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";
 
//#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;} 
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;} 
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const  ll mod= 1000000007  ; 
const long long inf = (ll)1e18+17;
const int inff = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};


void solve(){ 
    ll n;cin>>n;
    if(n%2==0){
        n=n/2-1;
        cout<<n<<endl;return;
    }
cout<<n/2<<endl;
}
 
int main()
{  
    clock_t tt;tt = clock(); 
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;   
    //printf("code took %f seconds to execute \n", time_taken); 
    return 0;
}
 
// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases


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

typedef long long ll;
typedef long double ld;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

	int k;
	cin >> k;
	cout << a[k-1];
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod=1e9+7;
ll inf=1e18;


int main(void){
	ll n,T,c,t,ans=inf;
	cin>>n>>T;
	rep(i,n){
		cin>>c>>t;
		if(t<=T){
			ans=min(ans,c);
		}
	}
	if(ans==inf){
		cout<<"TLE"<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  int num = 0;
  for (int i = A; i <= B; ++i){
    int tmp = i;
	if ( (tmp / 10000) == (tmp % 10) ){
      tmp %= 10000;
      tmp /= 10;
      if ( (tmp / 100) == (tmp % 10) ){
        num++;
      }
    }
  }
  cout << num << endl;
}

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

 int main (void) {
    int x;
    int a;
    
    //printf("1~3000までの整数を入力してください\n");
    rewind(stdin);
     a = scanf("%d",&x);
    
    if(x<1 || x>3000){
    printf("1~3000までの整数を入力してください");
    exit(0);
    }
      
    if(x<1200){
    printf("ABC\n");
    return 0;
    }else{
    printf("ARC\n");
    return 0;
    }
   }

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main()
{
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	if(s==u)
		a--;
	else
		b--;
	cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD NUM000007
#define EPS 0.0000001
#define NUM 30000
using namespace std;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 9 && col >= 0 && col <= 9)return true;
	else{
		return false;
	}
}

int diff_row[5] = {-1,0,0,0,1},diff_col[5] = {0,-1,0,1,0};

int main(){

	int N,table[10][10],work[10][10],calc_row,calc_col;
	bool tmp[10][10],ans[10][10],FLG;
	scanf("%d",&N);

	for(int loop = 0; loop < N; loop++){

		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++){
				scanf("%d",&table[i][k]);
			}
		}

		for(int i = 0; i < 1024; i++){

			for(int a = 0; a < 10; a++){
				for(int b = 0; b < 10; b++){
					work[a][b] = table[a][b];
				}
			}

			for(int k = 0; k < 10; k++){
				if(i & (1 << k)){
					tmp[0][k] = true;
				}else{
					tmp[0][k] = false;
				}
			}

			for(int a = 0; a < 10; a++){
				if(tmp[0][a]){
					for(int b = 0; b < 5; b++){
						calc_row = 0+diff_row[b];
						calc_col = a+diff_col[b];

						if(rangeCheck(calc_row,calc_col) == true){
							work[calc_row][calc_col] = 1 - work[calc_row][calc_col];
						}
					}
				}
			}

			for(int row = 1; row <= 9; row++){
				for(int col = 0; col <= 9; col++){
					if(work[row-1][col] == 1){
						tmp[row][col] = true;
					}else{
						tmp[row][col] = false;
					}
				}

				for(int a = 0; a <= 9; a++){
					if(tmp[row][a]){
						for(int b = 0; b < 5; b++){
							calc_row = row+diff_row[b];
							calc_col = a+diff_col[b];

							if(rangeCheck(calc_row,calc_col) == true){
								work[calc_row][calc_col] = 1 - work[calc_row][calc_col];
							}
						}
					}
				}

			}

			FLG = true;
			for(int a = 0; a <= 9; a++){
				if(work[9][a] == 1){
					FLG = false;
					break;
				}
			}
			if(FLG){
				for(int a = 0; a < 10; a++){
					for(int b = 0; b < 10; b++)ans[a][b] = tmp[a][b];
				}
				break;
			}

		}

		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 9; k++){
				if(ans[i][k]){
					printf("1 ");
				}else{
					printf("0 ");
				}
			}
			if(ans[i][9]){
				printf("1\n");
			}else{
				printf("0\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 2672
#include <stdio.h>
#define WARU 1000000007

int main(){
   long i,n,k,kk,m,u,ans;

   scanf("%ld %ld",&n,&kk);
   ans=0;
   for (k=kk;k<=n+1;k++) {
      m=k*(k-1)/2;
      u=(2*n-k+1)*k/2;
      ans=(ans+u-m+1)%WARU;
   }
   printf("%ld\n",ans);
   return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    while(true){
    ll h;cin >> h;
    if(h==0)break;
    vvl f(h,vl(5,0));
    per(i,h){
        rep(j,5)cin >> f[i][j];
    }
    ll ans=0;
    bool check=true;
    while(check){
        ll tmp=ans;
        vvl d(h,vl(5,0));
        rep(i,h){
            ll a=f[i][0];
            ll cnt=0;
            rep(j,5){
                if(a==f[i][j])cnt++;
                else{
                    if(cnt>=3){
                        rep(l,cnt){
                            f[i][j-l-1]=0;
                        }  
                        repl(k,i+1,h){
                            rep(l,cnt){
                                d[k][j-l-1]++;
                            }    
                        }
                        ans+=a*cnt;
                    }
                    a=f[i][j];
                    cnt=1;
                }
            }
            if(cnt>=3){
                rep(l,cnt){
                    f[i][4-l]=0;
                } 
                repl(k,i+1,h){
                    rep(l,cnt){
                        d[k][4-l]++;
                    }  
                }
                ans+=a*cnt;
            }
        }
        rep(i,h){
            rep(j,5){
                if(d[i][j]){
                    f[i-d[i][j]][j]=f[i][j];
                    f[i][j]=0;
                }
            }
        }
        /*rep(i,h){
            rep(j,5)cout << d[i][j] <<" ";
            cout <<endl;
        }*/
        if(tmp==ans)break;
    }
    /*rep(i,h){
        rep(j,5)cout << f[i][j] <<" ";
        cout <<endl;
    }*/
    cout <<ans <<endl;
    }
}



Measured memory_bytes: 3072
using System;
using System.Linq;

namespace ABC179
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }

        public static void c()
        {
            long n = long.Parse(Console.ReadLine());
            //double g = Math.Sqrt(n);
            long ans = 0;
            for(long i = 1; i < n; i++)
            {
                for (long j = 1; j * i < n; j++)
                {
                    if (0 < n - i * j && i * j < n)
                    {
                        ans++;
                       // Console.WriteLine(i * j);
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27536
program anything_goes_to_zero
  implicit none
  integer :: n, i, m, k
  integer(8) :: cnt = 0, rem1to0 = 0, rem0to1 = 0, rem
  character(200000) :: x
  read(*,*) n
  read(*,*) x
  do i = 1, n
    if (x(i:i) == '1') cnt = cnt + 1
  end do
  do i = 1, n
    k = ichar(x(i:i)) - 48
    if (cnt > 1) rem1to0 = mod(2 * rem1to0 + k, cnt - 1)
    rem0to1 = mod(2 * rem0to1 + k, cnt + 1)
  end do
  do i = 1, n
    if (x(i:i) == '1') then
      if (cnt < 2) then
        write(*,'(i0)') 0
        cycle
      end if
      rem = modulo(rem1to0 - pow(2_8, n - i, cnt - 1), cnt - 1)
    else
      rem = mod(rem0to1 + pow(2_8, n - i, cnt + 1), cnt + 1)
    end if
    m = 1
    do while (rem > 0)
      k = popcnt(rem)
      rem = mod(rem, k)
      m = m + 1
    end do
    write(*,'(i0)') m
  end do
contains
  pure elemental integer function pow(a, n, modu) result(res)
    integer(8), intent(in) :: a, modu
    integer, intent(in) :: n
    integer(8) :: b
    integer :: m
    res = 1
    b = a
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = mod(res * b, modu)
      b = mod(b * b, modu)
      m = rshift(m, 1)
    end do
  end
end program anything_goes_to_zero

Measured memory_bytes: 3280
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200002;
int n,i,k,f[N],l[N],r[N],a[N],d[N];
ll ans;
bool cmp(int x,int y){
	return a[x]>a[y];
}
int p(int x){
	return f[x]==x?x:f[x]=p(f[x]);
}
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",a+i);
		l[i]=r[i]=f[i]=d[i]=i;
	}
	sort(d+1,d+n+1,cmp);
	for(i=1;i<=n;i++){
		k=d[i];
		if(a[k-1]>a[k]){
			l[k]=l[p(k-1)];
			f[p(k-1)]=k;
		}
		if(a[k+1]>a[k]){
			r[k]=r[p(k+1)];
			f[p(k+1)]=k;
		}
		ans+=1ll*a[k]*(r[k]-k+1)*(k-l[k]+1);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 4096
#include <stdio.h>

int main(void){
	
	int S;
	int h,m,s;
	
	printf("");
	scanf("%d",&S);
	
	h=(S/3600);
	m=(S%3600)/60;
	s=(S%60);
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m,c,ans=0;
    cin>>n>>m>>c;
    ll b[1000],a[100][100];
    rep(i,m){
        cin>>b[i];
    }
    rep(i,n)rep(j,m){
        cin>>a[i][j];
    }
    rep(i,n){
        ll sum=c;
        rep(j,m){
            sum+=b[j]*a[i][j];
        }
        if(sum>0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  ll n; cin >> n;

  ll a = 1, b = 1;
  ll x, y;
  ll m;
  rep(i,n){
    cin >> x >> y;
    m = max((a + x -1) / x, (b + y - 1) / y);
    m = max(m, ll(1));
    //cout << m << endl;
    a = m * x; b = m * y;
  }
  cout << a + b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

ll N;
ll h[100010];
ll dp[100010];

int main()
{
    ll N;
    cin >> N;
    ll h[N];
    for (ll i = 0; i < N; i++)
        cin >> h[i];
    for (int i = 0; i < 100010; ++i)
        dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < N; ++i)
    {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
}

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

#define ll long long 

int main(){
	unsigned int n;
	cin>>n;
	int ans[3]={}, temp[3];
	for(unsigned int i = 0; i<n; i++){
		int a[3];
		cin>>a[0]>>a[1]>>a[2];
		temp[0] = temp[1] = temp[2] = INT_MIN;
		for(unsigned int j= 0; j<3; j++){
			for(unsigned int k = 0; k<3; k++){
				if(j!=k){
					temp[j] = max(ans[k] + a[j], temp[j]);
					}
				}
			
			}
			ans[0] = temp[0], ans[1] = temp[1], ans[2] = temp[2];
		
		}
		
	cout<<max({ans[0], ans[1], ans[2]})<<endl;
	return 0;
	}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>

#define C 300000
using namespace std;

int main() {
    int n, q;
    int c[300000], query[100000];
    bool has_c[C+1];
    scanf("%d%d", &n, &q);
    for (int i=0; i<n; i++) {
        scanf("%d", &c[i]);
    }
    for (int i=0; i<q; i++) {
        scanf("%d", &query[i]);
    }
    for (int i=0; i<=C; i++) {
        has_c[i] = false;
    }
    for (int i=0; i<n; i++) {
        has_c[c[i]] = true;
    }
    for (int i=0; i<q; i++) {
        int max_r = -1;
        for (int r=query[i]-1; r>=0; r--) {
            for (int k=0; true; k++) {
                int x = k*query[i]+r;
                if (x > C) {
                    break;
                }
                if (has_c[x]) {
                    max_r = max(r, max_r);
                    break;
                }
            }
            if (max_r >= 0) {
                break;
            }
        }
        printf("%d\n", max_r);
    }
    return 0;
}

Measured memory_bytes: 2880
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std; 

int main() {
    int n, m;
    cin >> n >> m;
    string s[n]; 
    for (int i = 0; i < n; i++) cin >> s[i];
    int a[n][m];
    for (int i = 0; i < n; i++) memset(a[i], 0, sizeof(a[i]));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] != '#') {
                int ans = 0;
                for (int dx = -1; dx <= 1; dx++) {
                    for (int dy = -1; dy <= 1; dy++) {
                        if (dx + i < n &&  dx + i >= 0 && dy + j >= 0 && dy + j < m && s[dx + i][dy + j] == '#') {
                            ++ans;
                        }
                    }
                }
                a[i][j] = ans;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '#') {
                cout << s[i][j];
                continue;
            }
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0; 
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author @MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        NoShortestPath solver = new NoShortestPath();
        solver.solve(1, in, out);
        out.close();
    }

    static class NoShortestPath {
        private static final int INF = (int) 1e8;

        public void solve(int testNumber, FastReader fs, PrintWriter pw) {
            int n = fs.nextInt();
            int m = fs.nextInt();
            int[][] f = new int[n][n];
            int[][] g = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (i != j)
                        f[i][j] = f[j][i] = INF;
                }
            }
            for (int i = 0; i < m; i++) {
                int a = fs.nextInt() - 1, b = fs.nextInt() - 1, c = fs.nextInt();
                g[a][b] = g[b][a] = f[a][b] = f[b][a] = c;
            }
            for (int k = 0; k < n; k++) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        f[i][j] = Math.min(f[i][j], f[i][k] + f[k][j]);
                    }
                }
            }

            int ans = 0;

            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    if (g[i][j] > f[i][j])
                        ++ans;
                }
            }
            pw.println(ans);
        }

    }

    static class FastReader {
        BufferedReader bf;
        StringTokenizer st;

        public FastReader(InputStream is) {
            bf = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        public String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    String line = bf.readLine();
                    if (line == null) return null;
                    st = new StringTokenizer(line);
                }
            } catch (Exception e) {
            }

            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 9784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    string S;
    cin >> S;
    int n = S.size();
    int maxi = 0;
    for (int i = n - 1; i > 0; i--)
    {
        if (i % 2 != 0)
        {
            continue;
        }
        string before, after;
        before = S.substr(0, i / 2);
        after = S.substr(i / 2, i / 2);
        if (before == after)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=5e5+4;

int main()
{
	int n;

	scn(n);

	set<string> st;

	rep(i,0,n)
	{
		string s;
		
		cin>>s; st.insert(s);
	}

	pri((int)st.size());

    return 0; 
}

Measured memory_bytes: 19388
N = int(input())
CHECK = "OK"
A_list = list(map(int, input().split()))
ans = 0
for i in A_list:
    if i == 0:
        ans = 0
        CHECK = "OK"
        break
    elif ans == 0:
        ans = i
        continue
    else:
        if ans * i > 10 ** 18:
            CHECK = "NG"
        else:
            ans *= i
if CHECK == "OK":
    print(ans)
else:
    print(-1)


Measured memory_bytes: 21480