akhauriyash/Code-Regression huggingface dataset:
//#include <iostream>
//#include <vector>
//#include <algorithm>
//#include <string>
//#include <utility>
#include <bits/stdc++.h>

using namespace std;

long long solve(long long a, long long b) {
    if(a == 0) return b;
    if(b == 0) return a;
    
    if(a<b) swap(a,b);
    long long r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(void){

    int n;
    cin >> n;
    
    vector<long long> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    vector<long long> memo_l_gcd(n);
    vector<long long> memo_r_gcd(n);
    for(int i=0; i<n; i++) {
        memo_l_gcd[i] = -1;
        memo_r_gcd[i] = -1;
    }
    
    if(n==2) {
        cout << max(a[0], a[1]) << endl;
        return 0;
    }

    long long max = 0;

    long long l_gcd = 0;
    for(int j=0; j<n; j++) {
        if(j==0) memo_l_gcd[j] = solve(l_gcd, a[j]);
        else memo_l_gcd[j] = solve(memo_l_gcd[j-1], a[j]);
    }
    
    long long r_gcd = 0;
    for(int j=n-1; j>=0; j--) {
        if(j==n-1) memo_r_gcd[j] = solve(r_gcd, a[j]);
        else memo_r_gcd[j] = solve(memo_r_gcd[j+1], a[j]);
    }


    for(int i=0; i<n; i++) {
        long long gcd = 0;
        if(i == 0) gcd = solve(0, memo_r_gcd[i+1]);
        else if(i == n-1) gcd = solve(memo_l_gcd[i-1], 0);
        else gcd = solve(memo_l_gcd[i-1], memo_r_gcd[i+1]);
//        cout << gcd << endl;
        if(gcd > max) max = gcd;
    }
    
    cout << max << endl;
    
    return 0;
    
}


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

typedef long long ll;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define _for(i,a,b) for(int i = (a); i < (b); i++) 
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

const int kMod = 1e9 + 7;
const int kMaxN = 1e6 + 5;

void taskA() {
    string s; cin >> s;
    int n = s.size();
    cout << (s[2]==s[3] && s[4]==s[5] ? "Yes\n" : "No\n");
    return;
}
void taskB() {
    int n; cin >> n;
    int ans = 0;
    ans += (n/500)*1000; n%=500;
    ans += (n/5)*5;
    cout << ans;
    return;
}
void taskC() {
    int n,k; cin >> k >> n;
    vector<int> a(n);
    _for(i,0,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    int ma = 0;
    _for(i,1,n) {
        ans += (a[i]-a[i-1]); 
        ma = max(ma, a[i]-a[i-1]);
    }
    ans += (k-a[n-1]+a[0]);
    ma = max(ma, k-a[n-1]+a[0]);
    cout << ans-ma;
    return;
} 
void taskD() {
    int n,x,y; cin >> n >> x >> y;
    vector<int> cnt(n, 0);
    _rep(i,1,n) _rep(j,i,n) {
        int dis = j-i;
        int d1 = abs(i-x)+abs(j-y)+1;
        int d2 = abs(i-y)+abs(j-x)+1;
        d1 = min(d1, d2);
        dis = min(dis, d1);
        cnt[dis]++;
    }
    _for(i,1,n) {
        cout << cnt[i] << "\n"; 
    }
    return;
}
void taskE() {
    int x,y,a1,b1,c1; cin >> x >> y >> a1 >> b1 >> c1;
    vector<int> a(a1), b(b1), c(c1+x+y);
    _for(i,0,a1) cin >> a[i];
    _for(i,0,b1) cin >> b[i];
    _for(i,0,c1) cin >> c[i];
    sort(all(a)); sort(all(b)); 
    reverse(all(a)); reverse(all(b)); 
    
    _for(i,0,x) c.push_back(a[i]);
    _for(i,0,y) c.push_back(b[i]);

    sort(all(c));reverse(all(c));
    ll ans = 0;
    _for(i,0,x+y) ans += c[i];
    cout << ans << "\n";
    return;
}
int main(){
    //ios::sync_with_stdio(false), cin.tie(nullptr);
    //taskA();
    //taskB();
    //taskC();
    //taskD();
    taskE();
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    while (true) {
        int n, r, a[50];

        cin >> n >> r;
        if ( n == 0 && r == 0) { break; }

        for (int i = 0; i < n; i++) {
            a[i] = n-i;
        }

        while (r--) {
            int p, c;
            cin >> p >> c;
            rotate(a, a+p-1, a+p+c-1);
        }

        cout << a[0] << endl;
    }

    return 0;
}


Measured memory_bytes: 3020
#include <iostream>

using namespace std;

int main(){
  string str;
  cin >> str;
  int res = 0;

  for (int i=1; i<str.size()/2; i++){
    int len = str.size() - i*2;
    bool flag = true;
    for (int j=0; j<len/2; j++){
      if (str[j] != str[len/2+j]){
        flag = false;
        break;
      }
    }
    if (flag){
      res = len;
      break;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

A, B, C, D = map(int, input().split())

alice = np.zeros(max(B, D))
bob = np.zeros(max(B, D))

alice[A:B] = 1
bob[C:D] = 1

# print(alice)
# print(bob)
print(np.sum(alice + bob == 2))

Measured memory_bytes: 12508
def main():
    n, max_t = map(int, input().split())
    max_val = 10 ** 9 + 7
    answer = max_val
    for _ in range(n):
        c, t = map(int, input().split())
        if t <= max_t:
            answer = min(answer, c)
    print(answer if answer != max_val else "TLE")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
n=int(input())
a=[]
from collections import deque as dq
for i in range(n):
	aaa=list(map(int,input().split()))
	aa=aaa[2:]
	a.append(aa)
dis=[-1]*n
dis[0]=0
queue=dq([0])
while queue:
	p=queue.popleft()
	for i in range(len(a[p])):
		if dis[a[p][i]-1]==-1:
			queue.append(a[p][i]-1)
			dis[a[p][i]-1]=dis[p]+1
for i in range(n):
	print(i+1,dis[i])
		



Measured memory_bytes: 6032
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println("a " + ((a > b) ? ">" : (a == b) ? "==" : "<") + " b");
	}
}

Measured memory_bytes: 17300
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include <stack>
#include<set>
#include<algorithm>
#include<stdio.h>

using namespace std;
int main() {

	
	set<string>s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string str;
		cin >> str;
		s.insert(str);
	}
	cout << s.size();

		return 0;
}
	




Measured memory_bytes: 19252
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  if(n % 2 != 0){
    cout << 0 << endl;
    return 0;
  }

  ll t = 10;
  ll ans = 0;

  while(true){
    if(t > n) break;
    ans += n / t;
    t *= 5;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    enum State {
        Down,
        Up,
        Same,
    }
    let mut s = State::Same;
    let mut cnt = 1;
    for i in 1..n {
        let b = a[i - 1];
        let c = a[i];
        if b == c {
            continue;
        }
        if b > c {
            s = match s {
                State::Up => {
                    cnt += 1;
                    State::Same
                }
                _ => State::Down,
            };
        } else if b < c {
            s = match s {
                State::Down => {
                    cnt += 1;
                    State::Same
                }
                _ => State::Up,
            }
        }
    }
    println!("{}", cnt);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}

Measured memory_bytes: 12668
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int h,w;

void solve(){
  int sqDiag=h*h+w*w;
  int next=1<<27;
  int resultH,resultW;
  for(int a=2;a<150;a++){
    for(int b=a-1;b>0;b--){
      int tmp=a*a+b*b;
      if(tmp<sqDiag)break;
      if(sqDiag==tmp&&b<=h)break;
      if(next>=tmp){
	next=tmp;
	resultH=b;
	resultW=a;
      }
    }
  }
  cout<<resultH<<" "<<resultW<<endl;
}

int main(){ _;
  while(cin>>h>>w,(h|w)!=0){
    solve();
  }
}

Measured memory_bytes: 1188
'use strict';
(function(stdin) {

    var inputs = stdin.toString().trim().split(' ');

    var a = Number(inputs[0]);
    var b = Number(inputs[1]);
    var c = Number(inputs[2]);
    if (a < b && b < c) {
        console.log('Yes');

    } else {
        console.log('No');
    }

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<string,int> P;
int main(){
   int N;
   cin>>N;
   vector<string> S(N);
   vector<int> T(N),ans(N);
   vector<P> Q,judge; 
   for(int i=0;i<N;i++){
       cin>>S.at(i)>>T.at(i);
        Q.push_back(P(S.at(i),T.at(i)));
        judge.push_back(P(S.at(i),T.at(i)));
   }
   sort(S.begin(),S.end());
   sort(Q.begin(),Q.end());
   string check1;
   int  check2;
   int k=0;
   bool flag=true;
   for(int i=0;flag;i++){
       flag=false;
       for(int j=N-1;j>=i+1;j--){
       if(Q.at(j).first==Q.at(j-1).first&&Q.at(j).second>Q.at(j-1).second){
          swap(Q.at(j),Q.at(j-1));
          flag=true;
       }
       }
   }
for(int i=0;i<N;i++){
    check1=judge.at(i).first;
    check2=judge.at(i).second;
    for(int j=0;j<N;j++){
        if(check1==Q.at(j).first&&check2==Q.at(j).second){
            ans.at(j)=i+1;
            k++;
        }
    }
}
for(int i=0;i<N;i++){
    cout<<ans.at(i)<<endl;
}
}

Measured memory_bytes: 256
#C
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))

for i in range(N):
    A[i]=math.log10(A[i])
max=0
for i in range(K):
    max+=A[i]
for i in range(K,N):
    if max<max-A[i-K]+A[i]:
        print("Yes")
        max=max-A[i-K]+A[i]
    else:
        print("No")

Measured memory_bytes: 105000
#include <iostream>

using namespace std;

int main()
{
    int x[3];
    int sum = 0;
    for(int i =0 ;i<3 ;i++){
        cin >> x[i];
        sum+=x[i];
}
    if(sum > 22 || sum == 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    double n; cin >> n;
    double t,a, h; cin >> t >> a;
    int ans=0;
    double mindif=1e9;
    rep(i,n){
        cin >> h;
        double dif = abs(a-(t-h*0.006));
        if(mindif > dif) {
            mindif=dif;
            ans = i;
        }
    }
    cout << ans+1 << endl;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k < u->key){
   return treeSearch(u->left,k);
  }
  else {
    return treeSearch(u->right,k);
  }

}

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

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left==NIL || z->right==NIL){
    y=z;
  }
  else{
    y= treeSuccessor(z);
  }
  
  if(y->left!=NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  
  if(x!=NIL){
    x->parent=y->parent;
  }
  
  if(y->parent==NIL){
    root=x;
  }
  else if(y==y->parent->left){
    y->parent->left=x;
  }
  else {
    y->parent->right=x;
  }
  
  if(y!=z){
    z->key=y->key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left=z;
  }
  else y->right=z;

}

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

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

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
N, K = map(int, input().split())
num = [0] * K
for i in range(1, N+1):
    num[i % K] += 1
ans = 0
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K != 0:
        continue
    ans += num[a] * num[b] * num[c]
print(ans)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<int,int> p;

int N, M; 
vector<vector<int>> A(310, vector<int>(310));

p max_participant(set<int> sports){
    vector<int> cnt(M,0); // 各競技の参加人数
    rep(i,N) rep(j,M){
        if(sports.find(A[i][j]) != sports.end()){
            cnt[A[i][j]]++; break;
        }
    }

    int max_id = max_element(cnt.begin(), cnt.end()) - cnt.begin();
    int max_p = cnt[max_id];
    return p(max_id, max_p);
}

int solve(set<int> sports){
    if(sports.empty()) return 1e8;

    p now = max_participant(sports);
    int max_id_now = now.first, max_p_now = now.second;
    //cout << max_id_now << " " << max_p_now << endl;

    sports.erase(max_id_now);
    p next = max_participant(sports);
    int max_id_next = next.first, max_p_next = next.second;

    return min(max_p_now, solve(sports));
}

int main(){
    cin >> N >> M;
    
    rep(i,N)rep(j,M){
        cin >> A[i][j]; A[i][j]--;
    }

    set<int> sports; // 開催する競技の集合
    rep(i,M) sports.insert(i);

    int ans = solve(sports);
    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int X = N;

    int sum = 0;
    while (N != 0) {
        sum += N % 10;
        N /= 10;
    }

    if (X % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}

		int s[1000];
		double total = 0;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			total += s[i];
		}

		double m = total / n;

		double a_2 = 0;
		for (int i = 0; i < n; i++) {
			a_2 += (s[i] - m)*(s[i] - m) / n;
		}

		double a = sqrt(a_2);
		printf("%.4f\n", a);
	}

	return 0;
}

Measured memory_bytes: 1196
def lcm(a,b)
	a/gcd(a,b)*b
end
def gcd(a,b)
	if(a>b)
		return gcd(b,a)
	end
	if(b%a == 0)
		return a
	else
		return gcd(a,b%a)
	end
end
A,B,C,D=gets.chomp.split(' ').map{|n| n.to_i}
qac = A%C == 0 ? A/C : A/C+1
qbc = B%C == 0 ? B/C : B/C
qad = A%D == 0 ? A/D : A/D+1
qbd = B%D == 0 ? B/D : B/D
qacd = A%lcm(C,D) == 0 ? A/lcm(C,D) : A/lcm(C,D)+1
qbcd = B%lcm(C,D) == 0 ? B/lcm(C,D) : B/lcm(C,D)
# puts qac
# puts qbc
# puts qad
# puts qbd
# puts lcm(C,D)
# puts qacd
# puts qbcd
cnt = qbc - qac + 1
cnt += qbd - qad + 1
cnt -= qbcd - qacd + 1
# puts cnt
puts B-A+1-cnt


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=200000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

set<int> adj[N + 5];
int n,m;
int main()
{
  finp;
  cin>>n>>m;
  afor(i,1,m)
  {
    int u,v;
    cin>>u>>v;
    adj[u].insert(v);
    adj[v].insert(u);
  }

  afor(i,2,n-1)
  {
    if(adj[i].find(1)!=adj[i].end() && adj[i].find(n)!=adj[i].end())
    {
      cout<<"POSSIBLE";
      return 0;
    }
  }
  cout<<"IMPOSSIBLE";
  return 0;
  
return 0;
}

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

int main()
{
	int N,D;
	int X[12][12]={};
	int cnt = 0;

	cin>>N>>D;

	for(int i = 0; i<N;i++){
		for(int j=0;j<D;j++){
			cin>>X[i][j];
		}
	}

	for(int i = 0;i<N-1;i++)
	{
		
		for(int j =i+1;j<N;j++)
		{
			int check = 0;
			double checkint = 0;
			for(int k =0;k<D;k++)
			{
			
				check += abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k]);
			}
			
			checkint = sqrt(check);
			if(ceil(checkint)==floor(checkint))
			{
				
				cnt++;
			}
		}
	}

	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,f[100009],z;
long long usg(long long q, long long w){
	if(q==0) return w; else return usg(w%q,q);
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(c=1; c<=a; c++) cin>>f[c];
	z=abs(b-f[1]);
	for(c=2; c<=a; c++){
		z=usg(min(z,abs(b-f[c])),max(z,abs(b-f[c])));
	}
	cout<<z;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(int a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
inline int read()//不管是正负数，都可以 
{
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
const int N=100005;
struct point{
	int x,y,num;
}a[N],e[N<<1];
inline bool cmp1(point a,point b){
	return a.x<b.x;
}
inline bool cmp2(point a,point b){
	return a.y<b.y;
}
inline bool cmp3(point a,point b){
	return a.num<b.num;
}
long long ans;
int n,have,m,father[N];
inline int getfather(int x){
	return x==father[x]?x:father[x]=getfather(father[x]);
}
int main(){
	n=read(); 
	for(int i=1;i<=n;i++){a[i].x=read(); a[i].y=read(); father[i]=a[i].num=i;}
	sort(&a[1],&a[n+1],cmp1); 
	for(int i=1;i<n;i++){
		e[++m].x=a[i].num; e[m].y=a[i+1].num; e[m].num=min(a[i+1].x-a[i].x,abs(a[i+1].y-a[i].y));
	}
	sort(&a[1],&a[n+1],cmp2);
	for(int i=1;i<n;i++){
		e[++m].x=a[i].num; e[m].y=a[i+1].num; e[m].num=min(a[i+1].y-a[i].y,abs(a[i+1].x-a[i].x));
	}
	sort(&e[1],&e[m+1],cmp3);
	for(int i=1;have<n-1;i++){
		int t1=getfather(e[i].x),t2=getfather(e[i].y);
		if(t1!=t2){
			father[t1]=t2;
			have++; ans+=e[i].num;
		}
	}
	writeln(ans);
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int R[300000] = {}, C[300000] = {};
int Rcp[300000] = {}, Ccp[300000] = {};

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W, M; cin >> H >> W >> M;
    int R2[H], C2[W];
    pair<int, int> bomb[M];
    rep(i, M){
        int r, c; cin >> r >> c;
        R[r-1]++; C[c-1]++;
        bomb[i] = pair<int, int>(r-1, c-1);
    }
    rep(i, H) Rcp[i] = R[i];
    rep(i, W) Ccp[i] = C[i];
    sort(R, R+H); sort(C, C+W);
    set<int> mx_st_r, mx_st_c;
    rep(i, H) if(Rcp[i] == R[H-1]) mx_st_r.insert(i);
    rep(i, W) if(Ccp[i] == C[W-1]) mx_st_c.insert(i);
    ll num_mx_r = 0, num_mx_c = 0;
    for(int i = H-1; i >= 0; i--) if(R[i] == R[H-1]) num_mx_r++;
    for(int i = W-1; i >= 0; i--) if(C[i] == C[W-1]) num_mx_c++;
    ll res = 0;
    rep(i, M){
        if(mx_st_r.count(bomb[i].first) && mx_st_c.count(bomb[i].second)) res++;
    }

    if(res == num_mx_r*num_mx_c) cout << R[H-1]+C[W-1]-1 << endl;
    else cout << R[H-1]+C[W-1] << endl;
    return 0;
}

Measured memory_bytes: 38696
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
 
#ifdef _WIN32
    #define gx getchar
    #define px putchar
    #define ps putchar(' ')
    #define pn putchar('\n')
    #define DEBUG 1
#else
    #define gx getchar_unlocked
    #define px putchar_unlocked
    #define ps putchar_unlocked(' ')
    #define pn putchar_unlocked('\n')
    #define DEBUG 0
#endif
 
#define rep(i,j,k) for(ll i=0;i<j;i+=k)
//input
void scan(int &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' ) sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * sign;
}
void lscan(ll &n)
{
    int sign = 1;
    n = 0;
    char c = gx();
    while( c < '0' || c > '9' )
    {
        if( c == '-' )
        sign = -1;
        c = gx();
    }
    while( c >= '0' && c <= '9' ) n = (n<<3) + (n<<1) + c - '0', c = gx();  n = n * (ll)(sign);
}
int sscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
int wscan(char a[])
{
    char c = gx();
    while(c==' ' || c=='\n') c=gx();
    int i=0;
    while(c!='\n' && c!=' ')a[i++] = c,c=gx();
    a[i]=0;
    return i;
}
 
//output
void print(int n)
{
    if(n<0)
    {
        n=-n;
        px('-');
    }
    int i=10;
    char o[10];
    do{o[--i] = (n%10) + '0'; n/=10;}while(n);
    do{px(o[i]);}while(++i<10);
}
void lprint(ll n)
{
    if(n<0LL)
    {
        n=-n;
        px('-');
    }
    int i=21;
    char o[21];
    do{o[--i] = (n%10LL) + '0'; n/=10LL;}while(n);
    do{px(o[i]);}while(++i<21);
}
void sprint(const char a[])
{
    const char *p=a;
    while(*p)px(*p++);
}
 
 
ll po(ll a, ll b, ll m)
{
	ll x=1,y=a;
	while(b > 0)
	{
		if(b%2 == 1)
		{
			x=(x*y);
			if(x>m) x%=m;
		}
		y = (y*y);
		if(y>m) y%=m;
		b /= 2;
	}
	return x;
}
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
	ll n;
	cin>>n;
	long long int ans=1;
	long long int correct;
	ll flag=0;
	vector<ll> temp(n);
	for(int i=0;i<n;i++) {
		cin>>temp[i];
	}
	sort(temp.begin(),temp.end());
	long long int max = 1000000000000000000;
	for(ll i=0;i<n;i++) {
		correct = ans;
		if(temp[i]!=0)
		{
			long long int val = max/temp[i];
			if(correct>val)
			{
				flag=1;
				break;
			}
		}
		else
		{
			ans = 0;
			break;
		}
		ans = ans*temp[i];
	}
	if(flag==0)
		cout<<ans<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
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 int MOD = 1000000007;

int main() {
    ll a, b;
    cin >> a >> b;
    if (a == b) {
        cout << 0 << endl;
        return 0;
    }
    if ((a + b) % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderB
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();

        int answer = 0;
        for (int i = n; i <= 999; i++)
        {
            if (i.ToString().Distinct().Count() == 1)
            {
                answer = i;
                break;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		double x1=scan.nextDouble();
		double y1=scan.nextDouble();
		double x2=scan.nextDouble();
		double y2=scan.nextDouble();
		double x=Math.abs(x1-x2)*Math.abs(x1-x2);
		double y=Math.abs(y1-y2)*Math.abs(y1-y2);
		System.out.println(Math.sqrt(x+y));
	}
}


Measured memory_bytes: 28012
#include <iostream>


using namespace std;

int main()
{
	int n , m , sum = 0 , total;
	cin >> n >> m;
	int arr[100000];
	for (int i = 0; i < m; i++){
		cin >> arr[i];
		sum += arr[i];
	}
	total = n - sum;
	if (sum <= n){
		cout << total;
	}
	else if (sum > n){
		cout << -1;
	}
	
	return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n = 5;
    vi a(n); for(auto& e : a) cin >> e;

    int res = 0;
    int maxd = 0;
    for(auto& e : a){
        int cur = (e + 9) / 10 * 10;
        chmax(maxd, cur - e);
        res += cur;
    }
    res -= maxd;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var output = 0;
	for(var i = 1; i < N - 1; i++){
		if(list[i - 1] < list[i] && list[i] < list[i + 1]){
			output++;
		}else if(list[i - 1] > list[i] && list[i] > list[i + 1]){
			output++;
		}
	}
	myout(output);
}


Measured memory_bytes: 7628
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int G[101][101];
bool used[101];
int f[101],s[101];
int cnt=0;
void dfs(int now){
	cnt++;
	s[now]=cnt;
	used[now]=1;
	for(int i=1;i<=100;i++){
	if(G[now][i]&&used[i]==0)dfs(i);
	}
	cnt++;
	f[now]=cnt;
}

int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int u,k,v;
cin>>u>>k;
for(int j=0;j<k;j++){
cin>>v;
G[u][v]=1;
}
}
dfs(1);
while(true){
int f=1,next=0;

	for(int j=1;j<=n;j++){
		if(used[j]==0){
		f=0,next=j;
		break;
		}
	}

if(f)break;
else dfs(next);
}
for(int i=1;i<=n;i++){
	printf("%d %d %d\n",i,s[i],f[i]);
}
return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>

using namespace std;

int main()
{
    int k,a,b;
    scanf("%d",&k);
    scanf("%d %d",&a,&b);
    if(a%k)
    {
        if((a/k+1)*k<=b)
        {
            printf("OK\n");
        }
        else
        {
            printf("NG\n");
        }
        
    }
    else
    {
        printf("OK\n");
    }
    

    //system("pause");
    return 0;
}

Measured memory_bytes: 3764
S = input()

flag = True

# 偶数
for a in set(S[1::2]):
    if a == "R":
        flag = False
        break 
    
# 奇数
for b in set(S[::2]):
    if b == "L":
        flag = False
        break
        
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

const int MOD = (int) 1e9 + 7;
const int DIM = 4;

struct Matrix {
    int a[DIM][DIM];
    Matrix(): a{0} {}
    Matrix(int _a[DIM][DIM]) {
        memcpy(a, _a, sizeof a);
    }
    Matrix operator*(const Matrix& o) const {
        Matrix ret;
        for (int i = 0; i < DIM; ++i) {
            for (int j = 0; j < DIM; ++j) {
                for (int k = 0; k < DIM; ++k) {
                    ret.a[i][j] = (ret.a[i][j] +
                            (int64_t) a[i][k] * o.a[k][j]) % MOD;
                }
            }
        }
        return ret;
    }
};

Matrix identity() {
    Matrix ret;
    for (int i = 0; i < DIM; ++i) {
        ret.a[i][i] = 1;
    }
    return ret;
}

Matrix Pow(Matrix x, int y) {
    Matrix ret = identity();
    for (; y > 0; y /= 2) {
        if (y & 1) {
            ret = ret * x;
        }
        x = x * x;
    }
    return ret;
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    vector<int> A(m + 2);
    A[0] = 0;
    A[m + 1] = n;
    for (int i = 1; i <= m; ++i) {
        cin >> A[i];
    }
    int _m1[DIM][DIM] = {
        {2, 1, 1, 1},
        {1, 1, 0, 1},
        {1, 0, 1, 1},
        {1, 0, 0, 1},
    };
    int _m2[DIM][DIM] = {
        {1, 1, 1, 1},
        {0, 1, 0, 1},
        {0, 0, 1, 1},
        {0, 0, 0, 1},
    };
    int _m3[DIM][DIM] = {
        {1, 1, 1, 1},
        {1, 1, 0, 1},
        {1, 0, 1, 1},
        {1, 0, 0, 1},
    };
    Matrix m1 = _m1, m2 = _m2, m3 = _m3;
    Matrix x = identity();
    for (int i = 1; i <= m + 1; ++i) {
        int diff = A[i] - A[i - 1];
        x = x * Pow(m1, diff - 1);
        if (i == m + 1) {
            x = x * m3;
        } else {
            x = x * m2;
        }
    }

    int ans = x.a[0][0];
    ans %= MOD;

    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
	map<string , int> data;
	string mxlen,mst,str;

	while(cin >> str){
		data[str]++;
		if(data[str] > data[mst]){
			mst = str;
		}
		if(str.size() > mxlen.size()){
			mxlen = str;
		}
	}
	cout << mst << ' ' << mxlen << endl;
	return 0;
}

Measured memory_bytes: 1192
n, y = gets.split(" ").map(&:to_i)
0.upto(n) do |yen_10000|
  0.upto(n - yen_10000) do |yen_5000|
    yen_1000 =  n - yen_10000 - yen_5000 > 0 ? n - yen_10000 - yen_5000 : 0
    sum = yen_10000 * 10000 + yen_5000 * 5000 + yen_1000 * 1000
    # p "#{yen_10000} #{yen_5000} #{yen_1000}"
    if sum == y
      puts "#{yen_10000} #{yen_5000} #{yen_1000}"
      exit
    end
  end
end

puts "-1 -1 -1"

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    ll k;
    cin >> k;
    if (k % 2 == 0 or k % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll ten = 1;
    ll now = 0;
    for (int i = 1; i <= k; i++) {
        now += ten * 7 % k;
        now %= k;
        if (now == 0) {
            cout << i << endl;
            return 0;
        }
        ten = ten * 10 % k;
    }
}

Measured memory_bytes: 3652
#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>;
#define INF 2100000000
#define MOD 1000000007

bool dbgflag = false; //debug

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

  ll x;
  cin >> x;
  vector<ll> fives(241);
  for(ll i = -120; i <= 120; i++) {
    fives[i+120] = i * i * i * i * i;
  }

  for (int i = 0; i < 241; i++) {
    for (int j = 0; j < 241; j++) {
      if (x == fives[i] - fives[j]) {
        cout << i-120 << " " << j-120 << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3648
import java.math.BigInteger;
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        ArrayList<Long> enemy = new ArrayList<Long>(n);
        long count = 0;

        if(n <= k) {System.out.println(count); scan.close();}
        else{
            for(int i = 0;i < n;i++){
                enemy.add(scan.nextLong());
            }
            scan.close();
            Collections.sort(enemy);

            for(int j = 0; j < n-k;j++) count += enemy.get(j);
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 96568
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main()
{
	ll A,B,C,K;
	cin >> A >> B >> C >> K;
 	
 	ll ans = 0;

 	if(A>=K)
 		cout << K;
 	else if(A<K && K<=A+B)
 		cout << A;
 	else if(A+B<K)
 		cout << A - (K-A-B);

 	cin >> A;
	
	return 0;	
}


Measured memory_bytes: 3636
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc_set = set(sc)
sc_list = list(sc_set)

used = [False] * n
for ele in sc_set:
    idx = ele[0] - 1
    if used[idx]:
        print(-1)
        exit()
    used[idx] = True

num = [None] * n
for i in range(len(sc_list)):
    num[sc_list[i][0] - 1] = sc_list[i][1]

if m == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(10 ** (n - 1))
        exit()

if n == 1:
    print(num[0])
    exit()

for i in range(10 ** (n - 1), 10 ** n):
    i = str(i)
    test = []
    for j in range(n):
        if num[j] == None:
            test.append(1)
        elif num[j] != None and num[j] == int(i[j]):
            test.append(1)
        else:
            test.append(0)
    if all(test):
        print(i)
        exit()

print(-1)

Measured memory_bytes: 39280
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, L, q, a[N], R[N][20];

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   cin >> L >> q;
   for (int i = 1; i <= n; i ++) {
      int pos = n;
      int l = i, r = n;
      while (l <= r) {
         int mid = l + r >> 1;
         if (a[mid] - a[i] <= L) l = mid + 1, pos = mid;
         else r = mid - 1;
      }
      R[i][0] = pos; 
   }
   for (int i = n; i >= 1; i --) {
      for (int j = 1; j < 20; j ++) 
         R[i][j] = R[R[i][j - 1]][j - 1];
   }
   while (q --) {
      int l, r;
      cin >> l >> r;
      if (l > r) swap (l, r);
      int pos = l;
      int ans = 0;
      for (int i = 19; i >= 0; i --) {
         if (R[pos][i] < r) {
            pos = R[pos][i];
            ans += (1 << i);
         }
      }
      cout << ans + (pos != r) << endl;
   }
}               
 
signed main () {                                       
   //#ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 11692
#include<bits/stdc++.h>
using namespace std;
 
#define ll          int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        200005
#define mod         1000000007 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;
}

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

using namespace std;

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

int main()
{
    int N;

    while (cin >> N, N) {
        int y[202];
        int x[202];

        y[0] = x[0] = 0;
        for (int i = 1; i < N; i++) {
            int nx, ny, n, d;

            cin >> n >> d;
            x[i] = x[n] + dx[d];
            y[i] = y[n] + dy[d];
        }
        int min_x, min_y, max_x, max_y;

        min_x = min_y = max_x = max_y = 0;
        for (int i = 1; i < N; i++) {
            min_x = min(min_x, x[i]);
            min_y = min(min_y, y[i]);
            max_x = max(max_x, x[i]);
            max_y = max(max_y, y[i]);
        }
        
        cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a, b = input().split()

print(sorted([a*int(b), b*int(a)])[0])


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

using namespace std;

int main() {
    int n, p = 0;
    cin >> n;

    int a[n+1], b[n+1], c[n], pv = -1, cc = -1;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    for (int i = 1; i <= n-1; ++i) cin >> c[i];

    for (int i = 1; i <= n; ++i) {
        cc = a[i];
        p += b[cc];
        if (cc-1 == pv) {
            p += c[cc-1];
        }
        pv = cc;
    }

    cout << p << endl;

    return 0;
}


Measured memory_bytes: 256