akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x = input()
temp = x.count("1")
mod1 = [1]
for i in range(n-1):
    mod1.append(mod1[-1] * 2 % (temp + 1))
mod1.reverse()
num1 = 0
for i in range(n):
    if x[i] == "1":
        num1 += mod1[i]
        num1 %= (temp + 1)
if temp == 1 or temp == 2:
    mod2 = [0] * n
else:
    mod2 = [1]
    for i in range(n-1):
        mod2.append(mod2[-1] * 2 % (temp - 1))
    mod2.reverse()
    num2 = 0
    for i in range(n):
        if x[i] == "1":
            num2 += mod2[i]
            num2 %= (temp - 1)
x2 = int(x, 2)
for i in range(n):
    if x[i] == "1":
        if temp == 1:
            print(0)
            continue
        elif temp == 2:
            print(1)
            continue
        else:
            num = num2 - mod2[i]
            num %= (temp - 1)
    else:
        num = num1 + mod1[i]
        num %= (temp + 1)
    count = 1
    while num:
        num %= bin(num).count("1")
        count += 1
    print(count)

Measured memory_bytes: 25332
using System;

class Program
{
  static void Main(string[] args)
  {
    var cmps = Console.ReadLine().Split(' ');
    int left = int.Parse(cmps[0]);
    int right = int.Parse(cmps[1]);
    if (left == right) {
      Console.WriteLine(left + right);
    } else {
      Console.WriteLine(Math.Max(left, right) * 2 - 1);
    }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d, n;
  cin >> d >> n;
  if(d==0) if(n!=100)cout<<n<<endl;else cout<<101<<endl;
  if(d==1) if(n!=100)cout<<n*100<<endl;else cout<<10100<<endl;
  if(d==2) if(n!=100)cout<<n*10000<<endl;else cout<<1010000<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

  char n;
  int i,m;
  int s[26]={};

  for(;;){
    m=scanf("%c",&n);
    
    if(m==EOF){
      break;
    }

  
    for(i=0;i<=25;i++){
      if(n=='a'+i){
	s[i]++;
      }
      if(n=='A'+i){
	  s[i]++;
      }
    }
   
  }
      for(i=0;i<=25;i++){
	printf("%c : %d\n",'a'+i,s[i]);
      }

      return 0;

    }

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

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

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  cin >> n;

  vector<pair<int, int>> a(n);
  rep (i, 0, n) {
    int tmp;
    cin >> tmp;
    a[i].first = tmp;
    a[i].second = i + 1;
  }

  sort(a.begin(), a.end());

  rep (i, 0, n)
    cout << a[i].second << " ";

  cout << "\n";



	return 0;
}


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

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	int f,count=0;
	do{
		f=0;
		for(int i=0; i<n; i++){
			if(a[i]%2==0){
				a[i]=a[i]/2;
			}else{
				f=1;
				break;
			}
		}
		if(f==0){
			count++;
		}
	}while(f==0);
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << "\n";
    return 0;
}

Measured memory_bytes: 256
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, groupby
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
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 998244353

N = INT()
print((N-1)//2)


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

long long int solver(long long int k,long long int w[],long long int dp[][101],long long int v[],long long int n)
{
    if(k<=0||n<=0){return 0;}
    if(dp[k][n]!=-1){return dp[k][n];}
    if(k>=w[n-1])
    dp[k][n]=max(solver(k-w[n-1],w,dp,v,n-1)+v[n-1],solver(k,w,dp,v,n-1));
    else
    dp[k][n]=solver(k,w,dp,v,n-1);
    return dp[k][n];
}

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   long long int n,k;
   cin>>n>>k;
   long long int w[n+1],v[n+1],dp[k+1][101]={-1};
   for(long long int x=0;x<n;x++){cin>>w[x]>>v[x];}
   for(int x=0;x<k+1;x++)
   {
       for(int y=0;y<101;y++)
       {
           dp[x][y]=-1;
       }
   }
   cout<<solver(k,w,dp,v,n)<<endl;
}








Measured memory_bytes: 82452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) {
        cin >> a[i];
    }

    if (n == 1) {
        if (a[0]) {
            cout << 1 << endl;
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
        return 0;
    }

    bool flag[n + 1] = {};
    ll x = (n + 1) / 2;
    if (n % 2 == 0) x++;
    for (ll i = n; i >= x; i--) {
        if (a[i - 1] == 1) flag[i] = true;
    }

    for (ll i = x - 1; i >= 1; i --) {
        ll sum = 0;
        for (ll j = i; j <= n; j += i) {
            sum += (ll)flag[j];
        }
        if (sum % 2 != a[i - 1]) flag[i] = true;
    }
    ll m = 0;
    rep(i, 1, n + 1) {
        if (flag[i]) m++;
    }

    cout << m << endl;
    rep(i, 1, n + 1) {
        if (flag[i]) cout << i << " ";
    }
    cout << endl;

    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a >= 13)
    {
        ans = b;
    }
    else if (a >= 6)
    {
        ans = b / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
  ll n,d,a;
  cin >> n >> d >> a;
  vp p(n);
  rep(i,0,n) cin >> p[i].fi >> p[i].se;
  sort(all(p));
  d*=2;
  
  queue<P> q;
  ll from=0,ans=0;
  rep(i,0,n){
   ll x=p[i].fi;
   ll h=p[i].se; 
   while(q.size()&&q.front().fi<x){
    from-=q.front().se;
    q.pop(); 
   }
   h-=from;
   if(h>0){
     ll num=(h+a-1)/a;
     ans+=num;
     from+=num*a;
     q.push(P(x+d,num*a));
   }

  }
  cout << ans << endl;
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 7940
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();

        if (k >= s.length()) {
            System.out.println(s);    
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}


Measured memory_bytes: 38664
#include<stdio.h>
#include<string.h>
int main(void){
    int f = 0, i,o, j, l, z, q, k[6], s[100][6], n[6], n2[6];
    char c;
    scanf("%d",&q);
    for (z = 0; z < q; z++){
        for (i = 0; i < 6; i++){
            scanf("%d", &s[z][i]);
            n[i] = i;
        }
    }
    for (i = 0; i < q; i++){
        for (z = 0; z < q; z++){
            if (i != z){
                for (j = 0; j < 5000; j++){
                    if (j % 6 < 3 && j % 5 == 4){
                        n2[0] = n[1]; 
                        n2[1] = n[5]; 
                        n2[3] = n[3]; 
                        n2[4] = n[0]; 
                        n2[2] = n[2]; 
                        n2[5] = n[4];
                    }
                    else {
                        n2[0] = n[3]; 
                        n2[1] = n[1]; 
                        n2[3] = n[5]; 
                        n2[4] = n[4]; 
                        n2[2] = n[0]; 
                        n2[5] = n[2];
                    }
                    for (o = 0; o < 6; o++){
                        n[o] = n2[o];
                    }
                    for (l = 0; l < 6; l++){
                        if (s[i][l] != s[z][n[l]])break;
 
                    }
                    if (l == 6){ 
                        f = 1; 
                        break;
                    }
 
                }
            }
            if (f == 1)break;
        }
        if (f == 1)break;
    }
        if (f == 1)printf("No\n");
        else printf("Yes\n");
    return 0;
}


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


void solve() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 3920
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W, K = LI()
    s = [SS() for _ in range(H)]

    ans = [[0] * W for _ in range(H)]

    # 行ごとにいちごで区切って塗り分け
    cnt = 1
    for i in range(H):
        is_first = True
        if s[i].count("#") >= 1:
            for j in range(W):
                if s[i][j] == '#':
                    if is_first:
                        is_first = False
                    else:
                        cnt += 1
                ans[i][j] = cnt
            cnt += 1

    # いちごなし行の場合、前の行の値をコピー
    first_strawberry_row = -1
    for i in range(H):
        if s[i].count("#") >= 1:
            first_strawberry_row = i
            break

    for i in range(first_strawberry_row, H):
        if s[i].count("#") == 0:
            for j in range(W):
                ans[i][j] = ans[i-1][j]

    # 前にコピー元がない場合、後ろの行からコピー
    for i in range(first_strawberry_row):
        r = first_strawberry_row - 1 - i
        if s[r].count("#") == 0:
            for j in range(W):
                ans[r][j] = ans[r+1][j]

    for i in ans:
        print(*i)

if __name__ == '__main__':
    resolve()


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

void swap(int *a,int *b){
  int c;
  c=*a;
  *a=*b;
  *b=c;
}

int main(void){
  int x,y,z;

  if(scanf("%d %d %d",&x,&y,&z) != 3){
    printf("****SCANF ERROR****\n");
    exit(1);
  }
  swap(&x,&y);
  swap(&x,&z);
  printf("%d %d %d",x,y,z);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;

typedef long long ll;
ll n, c, a[N], s[2];
int main()
{
	ll i;
//	freopen ("input.txt", "r", stdin);
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	sort(a, a + n);
	for (i = n - 1; i >= 1; i--) {
		if (a[i] == a[i - 1]) {
			s[c++] = a[i];
			i--;
		}
		if (c >= 2) break;
	}
	if (c == 2) {
		cout << s[0] * s[1];
	} else {
		cout << 0;
	}
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = str(input())
rr,gg = [],[]
for i in range(0,len(s)):
    if s[i] == "R":
        rr.append(i)
    elif s[i] == "G":
        gg.append(i)

bb = len(s) -len(rr) -len(gg)
ans = len(rr) * len(gg) * bb
for i in range(0,len(rr)):
    for j in range(0,len(gg)):
        che = 0
        a = rr[i] + gg[j]
        if a % 2 == 0:
            if s[a//2] == "B":
                che += -1
        b = min(rr[i],gg[j]) - abs(rr[i]-gg[j])
        if b >= 0:
            if s[b] == "B":
                che += -1
        c = a - b
        if c < n:
            if s[c] == "B":
                che += -1
        ans += che

print(ans)


Measured memory_bytes: 9304
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	n := scanInt()
	m := make(map[string]bool)
	for i := 0; i < n; i++ {
		s := scanString()
		m[s] = true
	}
	fmt.Println(len(m))
}


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

    if b - a + 1 > 2 * k:    
        for i in range(a, a+k):
            print(i)
        
        for i in range(b-k+1, b+1):
            print(i)
    else:
        for i in range(a, b+1):
            print(i)

if __name__ == '__main__':
    main()


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s,s1,s2;cin>>s>>s1>>s2;
  char c1 = toupper(s[0]);
  char c2 = toupper(s1[0]);
  char c3 = toupper(s2[0]);
  cout<<c1<<c2<<c3<<endl;;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,k,m,n,r,g,b;
long long ans;
int main()
{
	scanf("%d%d%d%d",&r,&g,&b,&n);
	for(int i=0;i<=n/r;i++)
	{
		for(int j=0;j<=(n-r*i)/g;j++)
		{
			if(((n-i*r-j*g)%b==0)) ans++;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#define N 40010
using namespace std;

int p[N];

int d[N], a[N], b[N], n;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &p[i]);
		d[p[i]] = d[p[i - 1]] + 1;
	}
		
	for (int i = n; i; --i) d[i] -= d[i - 1];
	
	for (int i = 1; i <= n; ++i) {
		a[i] = max(1, d[i] + 1);
		b[i] = d[i] - a[i];
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}
	
	for (int i = 1; i <= n; ++i) {
		printf("%d ", a[i] - a[1] + 1);
	}
	puts("");
	
	for (int i = 1; i <= n; ++i) {
		printf("%d ", b[i] - b[n] + 1);
	}
}

Measured memory_bytes: 896
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(ans, N - odd_1[1] - even_2[1])
ans = min(ans, N - odd_2[1] - even_1[1])
print(ans)


Measured memory_bytes: 24300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

int n;
int a[100'001];
int val[100'001];

int tree[200'002];

const int base = 100'001;

void upd(int x){
	x += base;
	while(x < 200'002){
		++tree[x];
		x += (x&(-x));
	}
}

int sum(int x){
	x += base;
	int ret=0;
	while(x) ret+=tree[x], x&=(x-1);
	return ret;
}

ll count(int x){
	memset(tree, 0, sizeof(tree));
	int ps = 0;
	ll ans = 0;
	upd(0);
	rep(i, n){
		int t = (a[i] <= x ? 1 : -1);
		ps += t;
		ans += sum(ps-1);
		upd(ps);
	}
	return ans;
}

int main()
{
	read(n);
	rep(i,n) read(a[i]), val[i]=a[i];
	sort(val, val+n);
	int l=-1, r=n-1;
	ll gn = n*1ll*(n+1)/2;
	while(l+1<r){
		int mid=(l+r)/2;
		if(count(val[mid]) < gn/2+1) l=mid;
		else r=mid;
	}
	printf("%d\n", val[r]);
	return 0;
}


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

const int mod=1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int cnt=0,cnt2=0;
    rep(i,n){
        for(int j=i+1; j<n; ++j){
            if(a[i]>a[j])cnt++;
        }
    }
    rep(i,n){
        rep(j,n){
            if(a[i]>a[j])cnt2++;
        }
    }
    ll ans=cnt*k;
    ans%=mod;
    ans+=cnt2*((k*(k-1)/2)%mod);
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
def is_prime(num):
    root = math.ceil(math.sqrt(num))
    for i in range(2, root):
        if num % i == 0:
            return False
    return True

N = int(input())
while True:
    if is_prime(N):
        print(N)
        exit(0)
    N += 1

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 01:17:00 2020

@author: liang
"""

S = input()
K = int(input())

#count = 0
for i in range(len(S)):
    if S[i] != '1':
        break
#print("i",i)

if K < i + 1:
    print(1)
    #print("A")
else:
    print(S[i])
    #print("B")

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

int main() {
  int k;
  while(cin >> k && k) {
    int sum=0;
    for(int i=0; i<k*(k-1)/2; i++) {
      int x;
      cin >> x;
      sum+=x;
    }
    cout << sum/(k-1) << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
from itertools import combinations as cmb
n = int(input())
L = list(map(int, input().split()))
#print(L)
counter = 0
for l1, l2, l3 in cmb(L, 3):
    #print(l1, l2, l3)
    if l1 + l2 > l3 and l2 + l3 > l1 and l3 + l1 > l2 and l1 != l2 and l2 != l3 and l3 != l1:
        counter += 1
print(counter)

Measured memory_bytes: 67844
n = int(input())
a = [input() for i in range(n)]

count = 0
dic = {}

for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

for i in dic.values():
    if i%2 == 1:
        count += 1

print(count)

Measured memory_bytes: 19468
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
intLine()=map(int,split(input()))
function inE(e)
    u,v=intLine()
    push!(e[u],v)
end
function main()
    n,m=intLine()
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m;inE(e);end
    s,t=intLine()
    f=ones(Int,(n,3))*-3
    f[s,1]=0
    q=Array{Int,1}[[s,1]]
    while !isempty(q)
        v,m=shift!(q)
        u=m>2?1:m+1
        for w=e[v]
            if f[w,u]<0
                f[w,u]=f[v,m]+1
                push!(q,[w,u])
            end
        end
    end
    show(f[t,1]÷3)
end
main()

Measured memory_bytes: 167320
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(void)
{
    int n, m;
    int h[100000];
    int a[100000];
    int b[100000];

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }

    bool memo[100000];
    for (int i = 0; i < n; i++) {
        memo[i] = true;
    }

    for (int i = 0; i < m; i++) {
        if(h[a[i] - 1] >= h[b[i] - 1]) {
            memo[b[i] - 1] = false;
        }
        if (h[a[i] - 1] <= h[b[i] - 1]) {
            memo[a[i] - 1] = false;
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
        if (memo[i] == true) {
            count++;
        }
    }

    cout << count;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    string s;
    cin >> s;

    cout << (s.size() % 2 == 0 ^ s[0] == s[s.size() - 1] ? "Second" : "First") << endl;

    return 0;
}


Measured memory_bytes: 512
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == t[i]) ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.length();i++){
    	if(s[i]=='7'){
    		cout<<"Yes";
			return 0; 
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <math.h>
int main(void){
    
    char a[52],b[51],c[102];
    int i,j=0;
    
    scanf("%s%s",a,b);
    
    for(i=0;i<strlen(a);i++){
        c[j]=a[i];
        j++;
        c[j]=b[i];
        j++;
    }
    c[j]='\0';
    
    printf("%s",c);
    
}

Measured memory_bytes: 1732
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

LL n;
int cur=0;
string solve(LL n)
{
	if(n==1)return "";
	string ret;
	if(n%2==1)
	{
		ret=solve(n-1);
		cur++;
		ret=char(cur)+ret;
	}
	else
	{
		ret=solve(n/2);
		cur++;
		ret=ret+char(cur);
	}
	return ret;
}
int main()
{
	get1(n);
	string s=solve(n+1);
	printf("%d\n",(int)s.size()+100);
	for(int i=0;i<(int)s.size();i++)printf("%d ",s[i]);
	for(int i=1;i<=100;i++)printf("%d ",i);
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let k: usize = read();
    let (a, b): (usize, usize) = (read::<usize>(), read::<usize>());
    for i in a..b + 1 {
        if i % k == 0 {
            println!("{}", "OK");
            exit(0);
        }
    }
    println!("{}", "NG");
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2136
/***************************************** START OF TEMPLATE *********************************************/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define  SPEED           ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT      mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)      for(ll i = (a); i >= n; i--)
#define  fo(i,n)         for(ll i = 0; i < n; i++)
#define  newl            cout<<"\n";
#define  f               first
#define  s               second
#define  pb              push_back
#define  mp              make_pair
#define  sym(s)          s="#"+s+"#";
#define  sqr(v)          v*v;
#define  all(x)          (x).begin(),(x).end()
#define  alll(x,n)       x+1, x+n+1
#define  uniq(a)         a.resize(unique(a.begin(), a.end()) - a.begin());
#define  mset(x,val)     memset(x,val,sizeof(x))
#define  mset1d(a,n,v)   foo(i,0,n+5)a[i]=v;
#define  mset2d(a,n,m,v) foo(i,0,n+5)foo(j,0,m+5)a[i][j]=v;
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}    

template <typename T> 
using  ordered_set =  tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
using  ll          =  long long;
using  ull         =  unsigned long long;
using  ld          =  long double;
using  pll         =  pair<ll,ll>;
using  vll         =  vector<ll>;
using  vpll        =  vector<pll>;

const ld   PI    =  3.14159265358979323846; 
const ll   MOD   =  1e+9+7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5+8;

vll adj[N]; ll vis[N];
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, a[N];

/***************************************** FUNCTION IMPLEMENTATIONS **************************************/


/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc){
    cin>>n;
    n>=30?cout<<"Yes":cout<<"No";
}

int main(){
    SPEED;

    //cin>>test_cases;
    foo(i,1,test_cases){
        MAIN(i);
    }
}

Measured memory_bytes: 8340
#include<stdio.h>

#define H 250

int main(){
  int A[H], n;

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

  for(int i = 1; i <= n; i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(i != 1 && 2*i <= n) printf("parent key = %d, ",A[i/2]);
    if(i != 1 && 2*i+1 > n && 2*i > n) printf("parent key = %d, \n",A[i/2]);
    if(2*i <= n && 2*i+1 <= n) printf("left key = %d, ",A[2*i]);
    if(2*i <= n && 2*i+1 > n) printf("left key = %d, \n",A[2*i]);
    if(2*i+1 <= n) printf("right key = %d, \n",A[2*i+1]);
  }
  
  return 0;
}



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

char F[102][102];

void DFS(int Y, int X, char T)
{
  if(F[Y][X]!=T)
    return;

  F[Y][X] = '.';

  DFS(Y-1, X, T);
  DFS(Y+1, X, T);
  DFS(Y, X-1, T);
  DFS(Y, X+1, T);
}

int main()
{
  int H, W;
  cin >> H >> W;

  if(H == 0 && W == 0)
    return 0;

  for(int y=1; y<=H; y++)
    for(int x=1; x<=W; x++)
      cin >> F[y][x];

  int cnt = 0;
  for(int y=1; y<=H; y++)
    for(int x=1; x<=W; x++)
      if(F[y][x]!='.'){
        cnt++;
        DFS(y, x, F[y][x]);
      }

  cout << cnt << endl;
  main();
}



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

#define int long long

using namespace std;

int dp[100010][110];
int a[110][2];

int32_t main()
{
    int n,w;
    cin >> n >> w;

    for(int i=1;i<=n;i++)
        cin >> a[i][0] >> a[i][1];

    int ans = 0;

    for(int i=1;i<=100000;i++)
    {
        for(int j=0;j<=n;j++)
            dp[i][j] = 2000000000;
    }

    for(int i=1;i<=100000;i++)
    {
        for(int j=1;j<=n;j++)
        {
            dp[i][j] = dp[i][j-1];

            if(a[j][1] <= i)
                dp[i][j] = min(dp[i][j],dp[i-a[j][1]][j-1] + a[j][0]);
            
            if(dp[i][j] <= w)
                ans = max(i,ans);
        }
    }

    // for(int i=1;i<=10;i++)
    // {
    //     for(int j=1;j<=n;j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    cout << ans << endl;
}

Measured memory_bytes: 86272
s = input()
if 'N' in s and 'W' in s and 'S' in s and 'E' in s:
    print('Yes')
elif ('N' in s and 'S' in s) and ('W' not in s and 'E' not in s):
    print('Yes')
elif ('N' not in s and 'S' not in s) and ('W' in s and 'E' in s):
    print('Yes')
else:
    print('No')

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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
const long long maxx = 1000000000000000000LL;
int main(){
  prep();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > rl[n+1];
  for (int i=0; i<m; i++){
      int l, r, v;
      cin >> l >> r >> v;
      rl[r].push_back({l, v});
  }

  set<int> have;
  have.insert(1);
  long long vals[n+1];
  bool got[n+1] = {false};
  got[1] = true;
  vals[1] = 0;
 
  for (int i=2; i<=n; i++){
      long long curval = maxx;
      for (int j=0; j<rl[i].size(); j++){
          int l = rl[i][j].first;
          int val = rl[i][j].second;
          set<int>::iterator it = have.lower_bound(l);
          if (it == have.end()){
              continue;
          }
          long long sumplus = vals[*it]+val;
          if (sumplus >= curval){
              continue;
          }
          curval = sumplus;
          set<int>::iterator it2 = have.end();
          it2--;
          while (have.size() > 0 && vals[*it2] > sumplus){
              have.erase(it2);
              it2 = have.end();
              it2--;
          }
      }
      
      if (curval != maxx){
          have.insert(i);
          got[i] = true;
          vals[i] = curval;
      }
  }
  if (!got[n]){
      cout << -1;
  }else{
      cout << vals[n];
  }
  return 0; 
}

Measured memory_bytes: 11008
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner(System.in);
        int N = sc.nextInt();
        int i = sc.nextInt();
        System.out.println(N - i + 1);
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;
    boolean hasNext;

    public FastScanner(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
        hasNext = true;
    }

    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                hasNext = false;
                return "##";
            }
        }
        return st.nextToken();
    }

    String next = null;
    public boolean hasNext(){
        next = nextToken();
        return hasNext;
    }

    public int nextInt() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Integer.parseInt(more);
    }

    public long nextLong() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Long.parseLong(more);
    }

    public double nextDouble() {
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return Double.parseDouble(more);
    }

    public String nextString(){
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return more;
    }

    public char nextChar(){
        if (next == null){
            hasNext();
        }
        String more = next;
        next = null;
        return more.charAt(0);
    }
}

Measured memory_bytes: 21076
#include <cstdio>
#include <cmath>

int cnt;
int m;
int G[100];

void insertionSort(int* A, int n, int g){
  for(int i = g; i < n; i++){
    int v = A[i];
    int j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}
void shellSort(int* A, int n){
  cnt = 0;
  m = 1;
  while(pow(2, m) < n){
    m++;
    if(m == 100){
      break;
    }
  }
  G[m-1] = 1;
  for(int i = m - 2; i >= 0; i--){
    G[i] = G[i+1] * 2;
  }
  for(int i = 0; i < m; i++){
    insertionSort(A, n, G[i]);
  }
}

int main(){
  int n;
  int A[1000000];
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  shellSort(A, n);
  printf("%d\n", m);
  for(int i = 0; i < m; i++){
    printf("%d", G[i]);
    if(i+1 == m) { printf("\n"); }
    else { printf(" "); }
  }
  printf("%d\n", cnt);
  for(int i = 0; i < n; i++){
    printf("%d\n", A[i]);
  }
}

Measured memory_bytes: 4960
#include<bits/stdc++.h>
using namespace std;
int main()
{
   char s[100][100];
    int i,j,k,l,r,c;
    cin>>r>>c;
   for(i=0;i<r;i++){
    for(j=0;j<c;j++){
        cin>>s[i][j];
    }
   }
     for(i=0;i<c+2;i++){cout<<"#";}
       cout<<endl;
    for(i=0;i<r;i++){
      for(j=0;j<c+2;j++){
        if(j==0||j==c+1){cout<<"#";}
          else{
            cout<<s[i][j-1];
        }
    }
        cout<<endl;
     }
    for(k=0;k<c+2;k++){cout<<"#";}
    cout<<endl;





}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
LL a[1002]={},sum[1002]={};
LL bitsum[64]={};
int main(){
  LL N,K;cin>>N>>K;
  for(int i=1;i<=N;i++)cin>>a[i];
  for(int i=1;i<=N;i++)sum[i]=sum[i-1]+a[i];
  
  int t=64;
  LL ans=0;
  while(1){
    for(int b=63;b>=0;b--)bitsum[b]=0;
    for(int i=1;i<=N;i++)for(int j=i;j<=N;j++){
      LL u=sum[j]-sum[i-1];
      if(ans!=0&&(u&ans)!=ans)continue;
      for(int b=0;u>0&&b<t;b++){
        bitsum[b]+=u&1;u>>=1;
      }
    }
    t=-1;
    for(int b=63;b>=0;b--)
      if(bitsum[b]>=K){t=b;break;}
    if(t==-1)break;
    ans+=(LL)1<<t;
  }
  cout<<ans<<endl;
}

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

int main(){
    char s;
    cin >> s;
    if(s == 'a' || s == 'e' || s == 'i' || s == 'o' || s == 'u'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

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

int N;
long long a[100010][3];
long long dp[100010][3];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;

    return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, M; cin >> N >> M;
    vvi s(M);
    vi p(M);
    REP(i, M)
    {
        int k; cin >> k;
        s[i].resize(k);
        REP(j, k) cin >> s[i][j];
    }
    REP(i, M) cin >> p[i];

    int ans = 0;
    for(int i = 0; i < 1 << N; i++)
    {
        bool all = true;
        REP(j, M)
        {
            int count = 0;
            REP(k, s[j].size())
            {
                if(1 << (s[j][k]-1) & i) count++;
            }
            if(count % 2 != p[j]) all = false;
        }
        if(all) ans++;
        else continue;
    }
    cout << ans << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int n, x, g;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x;
  FOR(i, 0, n){
    int y;
    cin >> y;
    g = gcd(g, abs(y-x));
  }
  cout << int(g) << endl;
  return 0;
}

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

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;
int c[100][2], res[101], table[17];
int main(){
  rep(i, 100){
    if(i%5==1) c[i][0] = 5;
    else c[i][0] = 2;
    c[i][1] = 17 * (i%2) + 3 * (i%3) + 19;
  }
  rep(i, 17) table[i] = 0;
  int p = 0;
  rep(k, 1000){
    rep(i, 17) if(table[i] > 0) table[i]--;

    while(p <= k / 5){
      int tmp = p;
      if(c[p][0] == 2){
	rep(i, 16){
	  if(table[i]==0&&table[i+1]==0){
	    table[i] = table[i+1] = c[p][1];
	    res[p] = k- p * 5;
	    p++;
	    break;
	  }
	}
      }else if(c[p][0] == 5){
	rep(i, 13){
	  if(table[i]==0&&table[i+1]==0&&table[i+2]==0&&table[i+3]==0&&table[i+4]==0){
	    table[i]=table[i+1]=table[i+2]=table[i+3]=table[i+4]=c[p][1];
	    res[p] = k - p  *5;
	    p++;
	    break;
	  }
	}
      }
      if(tmp == p) break;
    }
  }
  
  int n;
  while(~scanf("%d", &n))
    printf("%d\n", res[n]);

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
  ll a,b,count=0; cin >> a >> b;
  ll c = __gcd(a,b);

  
  for(ll i=2; i*i<=c; i++){
    if(c%i == 0){
      count++;
      while(c%i==0){
        c=c/i;
      }
    }if(c==1){
      break;
    }
  }
      if(c>1){
        count++;
      
      }
    cout << count + 1 << endl;
}

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

int d[110];
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < 200; i++) {
        d[i*a % b] = 1;
    }
    cout << (d[c] == 1 ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
def partition(arr, p, r)
  x = arr[r]
  i = p - 1
  for j in p...r
    if arr[j] <= x
      i += 1
      arr[i], arr[j] = arr[j], arr[i]
    end
  end
  arr[i + 1], arr[r] = arr[r], arr[i + 1]
  return i + 1
end

n = gets.to_i
arr = gets.split.map(&:to_i)
index = partition(arr, 0, n - 1)
for i in 0...index
  print arr[i].to_s + ' '
end
print '[' + arr[index].to_s + ']'
for i in index+1...n
  print ' ' + arr[i].to_s
end
print "\n"


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

string s1,s2,ans;
int n,m;
bool f;

int main(){
	cin>>s1>>s2;
	n=(int)s1.size();
	m=(int)s2.size();
	ans="~";
	for(int i=0;i<=n-m;i++){
		f=true;
		for(int j=0;j<m;j++)
			if(s1[i+j]!='?'&&s1[i+j]!=s2[j]){
				f=false;
				break;
			}
		if(f){
			string t="";
			for(int j=0;j<i;j++) {
				if(s1[j]=='?') t+='a';
				else t+=s1[j];
			}
			for(int j=0;j<m;j++) t+=s2[j];
			for(int j=i+m;j<n;j++) {
				if(s1[j]=='?') t+='a';
				else t+=s1[j];
			}
			ans=min(ans,t);
		}
	}
	if(ans=="~") puts("UNRESTORABLE");
	else cout<<ans<<endl;
	return 0;
}
//Dubious Document

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


using namespace std;


int main() {
	vector<long long int>X( 1001 );
	long long int N;
	cin >> N;
	for( size_t i = 1; i <= N; i++ ) {
		int k = i;
		for( size_t j = 2; j <= N; j++ ) {
			while( k%j == 0 ) {
				k /= j;
				X[j]++;
			}
		}
	}
	long long int ans = 1;
	for( size_t i = 0; i < 1001; i++ ) {
		ans *= X[i] + 1;
		ans %= (long long int)1e9 + 7;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {

    int g, h, m, s;

    scanf("%d", &g);

    h = g / 3600;
    m = (g - h * 3600)/ 60;
    s = g - h * 3600 - m * 60;

    printf("%d:%d:%d\n",h, m, s);

    return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int N;
    cin >> N;
    for(int i=0; i<3; i++){
        if(N%10==7) {
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<iostream>
#include<map>
#include<stack>
#include<set>
using namespace std;
int a[100000+5];
int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return
		gcd(b, a%b);
}

int main() {
	int N,K,flag = 0,max1 = 0;
	scanf("%d%d",&N,&K);
	int temp;
	for (int i = 0;i < N;++i) {
		scanf("%d",&a[i]);
		max1 = max(max1,a[i]);
		if(i>0)a[i]=gcd(a[i],a[i-1]);
	}
	if(K>max1||K%a[N-1]!=0)printf("IMPOSSIBLE");
	else printf("POSSIBLE");
}

Measured memory_bytes: 640
# input
a, b, c, x, y = map(int, input().split())

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

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll n, m;
vector<vector<ll>> G(100100);

ll dp[100100];
ll rec(ll v) {
    if (dp[v] != -1) return dp[v];

    ll res = 0;
    for (auto nv : G[v]) {
        chmax(res, rec(nv) + 1);
    }
    return dp[v] = res;
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
    }

    rep(v, n) dp[v] = -1;

    ll res = 0;
    rep(v, n) chmax(res, rec(v));
    cout << res << endl;
}

Measured memory_bytes: 8576