akhauriyash/Code-Regression huggingface dataset:
function main (s) {
    s=s.split(/[" ","\n"]/);
	for(var i=0;i<4;i++)s[i]=parseInt(s[i]);
	var t=Math.max(s[0],s[1],s[2]);
	var res=s[0]+s[1]+s[2]-t;
	for(var i=1;i<=s[3];i++)t*=2;
	res+=t;
	console.log(res);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			String s=sc.nextLine();
			int num=0;
			for(int i=0; i<4; i++) {
				if(s.charAt(i)=='+') {
					num++;
				}
				else {
					num--;
				}
			}
			System.out.println(num);
			
			
		}
	}
}



Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
#include<math.h>

 
int main(){
   long long int a,aa,b,bb,r,tmp;
   scanf("%lld %lld", &a,&b);
   bb = b;
   aa = a;
   if(a<b){
    tmp = a;
    a = b;
    b = tmp;
   }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  	tmp = aa*bb;
    printf("%lld", tmp/b);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, a = 26, k = 1;
  cin >> N;
  while(N > a) {
    N -= a;
    a *= 26;
    k++;
  }
  N--;
  for(int i = 0;i < k;i++) {
    a /= 26;
    int b = N / a;
    cout << (char)('a' + b);
    N %= a;
  }
  cout << endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N, R;
  cin >> N >> R;
  if (N >= 10)
    cout << R << endl;
  else
    cout << R + 100 * (10 - N);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // cout << fixed << setprecision(12);

  solve();

  return 0;
}


Measured memory_bytes: 256
n,x = map(int,input().split())

li = list(map(int,input().split()))

zahyo = 0
i = 0
while(zahyo <= x):
    
    zahyo = zahyo + li[i]
    
    if zahyo <= x:
        i = i+1
    if i == n:
        break

print(i+1)

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

class BiCoef
{
	public:
	int64_t size;
	int64_t Mod;
	vector<int64_t> fac;
	vector<int64_t> inv;
	vector<int64_t> finv;

	BiCoef(){};
	void init(int64_t tsize,int64_t tMod)
	{
		size=tsize;
		Mod=tMod;
		fac.resize(size+10);
		inv.resize(size+10);
		finv.resize(size+10);
		fac[0]=fac[1]=1;
		inv[0]=inv[1]=1;
		finv[0]=finv[1]=1;
		for(int64_t i=2;i<=size;i++)
		{
			fac[i]=i*fac[i-1]%Mod;
			inv[i]=Mod-(Mod/i)*inv[Mod%i]%Mod;
			finv[i]=inv[i]*finv[i-1]%Mod;
		}
	}

	int64_t comb(int64_t n,int64_t r)
	{
		if(n<r || n<0 || r<0)return (int64_t)0;
		return fac[n]*(finv[r]*finv[n-r]%Mod)%Mod;
	}

	int64_t perm(int64_t n,int64_t r)
	{
		return fac[r]*comb(n,r)%Mod;
	}

	int64_t rcomb(int64_t n,int64_t r)
	{
		if(n==0 && r==0)return (int64_t)1;
		return comb(n+r-1,r);	
	}
};

const lint mod=1e9+7;
BiCoef bc;

lint N,K;
vector<vector<lint>> edges;
lint ans;

void dfs(lint d,lint cur,lint prev)
{
	lint c=0;
	for(auto& i:edges[cur])
	{
		if(i==prev)continue;
		c++;
		dfs(d+1,i,cur);
	}

	if(d==0)ans=ans*bc.perm(K-1,c)%mod;
	else ans=ans*bc.perm(K-2,c)%mod;
	return;
}

int main()
{
	bc.init(100000,mod);

	cin >> N >> K;
	edges.resize(N);	
	for(int i=0;i<N-1;i++)
	{
		lint a,b;
		cin >> a >> b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	ans=K;
	dfs(0,0,-1);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 13952
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        for (long i = 1; i <= N; i++) {
            ans += (i + (N-N%i))*(N/i)/2;
            // System.err.println((i + (N-N%i))*(N/i)/2);
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 35516
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		Uf uf=new Uf(s[0]+1);
		for(int i = 0;i<s[1];i++) {
			var e=sc.Ia;
			uf.Union(e[0],e[1]);
		}
		Console.WriteLine("{0}",s[0]-(s[0]+1-uf.all)-1);
	}
}
public class Uf{
	private int[] arr,hi;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		all=n;
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){(a,b)=(b,a);}
			arr[a]+=arr[b];
			hi[a]=Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
		}
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Size(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 46980
import numpy as np
from numba import njit
from numba.types import i8
ni8 = np.int64
MOD = 998244353


@njit((i8[:,::-1], i8[:], i8, i8), cache=True)
def solve(lr, dp, n, k):
    acc_dp = np.ones_like(dp)
    for i in range(1, n):
        val = 0
        for j in range(k):
            a = i - lr[j, 0]
            if a < 0:
                continue
            b = i - lr[j, 1] - 1
            val += acc_dp[a] - (acc_dp[b] if b >= 0 else 0)
        dp[i] = val % MOD
        acc_dp[i] = (acc_dp[i - 1] + dp[i]) % MOD
    return dp[n - 1]


def main():
    f = open(0)
    n, k = [int(x) for x in f.readline().split()]
    lr = np.fromstring(f.read(), ni8, sep=' ').reshape((-1, 2))
    dp = np.zeros(n, ni8)
    dp[0] = 1
    ans = solve(lr, dp, n, k)
    print(ans)

main()

Measured memory_bytes: 109752
#include <bits/stdc++.h>
using namespace std;
typedef priority_queue <int> pi;
typedef priority_queue <int, vector<int>, greater<int>> pg;
typedef unsigned long long int ulli;

int main() {
    string S;
    cin >> S;
    int ans = 700;
    for(int i = 0; i < S.length(); ++i) {
        if(S[i] == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ans = 10000

for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < ans:
           ans = abs(a - (t - h[i] * 0.006))
           b = i
print(b + 1)


Measured memory_bytes: 3060
#include<stdio.h>
const int MAX_V=1000000;
int prime[MAX_V+1];
int sum[MAX_V+2];
int main(){
  int i,k,n;
  for(i=2;i<=MAX_V;i++){
    prime[i]=1;
  }
  for(i=2;i*i<=MAX_V;i++){
    if(prime[i]){
      for(k=2*i;k<=MAX_V;k+=i){
        prime[k]=0;
      }
    }
  }
  for(i=0;i<MAX_V+1;i++){
    sum[i+1]+=sum[i]+prime[i];
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",sum[n+1]);
  }
  return 0;
}

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

constexpr int MOD = 998244353;

vector<vector<int>> dp(512, vector<int>(512, 0));
vector<vector<int>> memo0(512, vector<int>(512, 0));
vector<vector<int>> memo1(512, vector<int>(512, 0));

int main() {
    int N, X; cin >> N >> X;
    for (int i = 0; i <= X; i++) {
        dp[i][i] = 1;
    }
    for (int k = 0; k < 512; k++) {
            for (int j = 0; j <= X; j++) {
                if (j == 0) memo0[j][k] = dp[j][k];
                else memo0[j][k] = memo0[j-1][k] + dp[j][k];
                memo0[j][k] %= MOD;
            }
        }
    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= X; j++) {
            for (int k = 0; k < 512; k++) {
                dp[j][k] = memo0[j][k^j];
            }
        }
        for (int k = 0; k < 512; k++) {
            for (int j = 0; j <= X; j++) {
                if (j == 0) memo1[j][k] = dp[j][k];
                else memo1[j][k] = memo1[j-1][k] + dp[j][k];
                memo1[j][k] %= MOD;
            }
        }
        memo0 = memo1;
    }
    ll ans = 0;
    for (int i = 0; i <= X; i++) {
        ans += dp[i][X];
        ans %= MOD;
    }
    cout << ans % MOD << endl;
}



Measured memory_bytes: 5904
#include <stdio.h>
#define MAX 100000

int partition(int,int);

int A[MAX],n;

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i>=0 && i!=q){
      printf("%d",A[i]);
      if(i!=n-1){
        printf(" ");
      }
    }
    if(i==q){
      printf("[");
      printf("%d",A[i]);
      printf("] ");
    }
  }
  printf("\n");
  return 0;
}

int partition(int p,int r){
  int i,j,k,t;
  k=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=k){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}


Measured memory_bytes: 2108
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, K;
  while (cin >> N >> K) {
    int res = N % K == 0 ? 0 : 1;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int[] n=new int[4];
		for(int i=0;i<n.length;++i)n[i]=sc.nextInt();
		Arrays.sort(n);
		if(n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9) {
			pw.println("YES");
		}else {
			pw.println("NO");
		}
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , a , b;

int main()
{
    _FastIO;
    cin >> n >> a >> b;
    cout << min((n * a) , b) << endl;
    return 0;
}


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

using namespace std;
int arr[(int)1e5 + 4];

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

    vector<int> dp(n, (int)1e9 + 10);
    dp[0] = 0;

    for(int i = 0; i < n - 1; ++i) {
        dp[i + 1] = min(dp[i+1], dp[i] + abs(arr[i+1] - arr[i]));
        if(i+2 < n) {
            dp[i +  2] = min(dp[i+2], dp[i] + abs(arr[i+2] - arr[i]));
        }
    }
    cout << dp[n-1] ;

}

Measured memory_bytes: 1024
from math import *

def main():
    N, M = map(int, input().split())
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(M//j for j in divisor_set)
    print(int(max([i for i in divisor_set if special_value >= i])))
    return

main()

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

using namespace std;

int gcd( int a, int b ) {
  if ( !b )
    return a;
  return gcd(b, a%b);
}

int main(){
  int n, x;
  cin >> n >> x;
  vector< int > city( n );
  
  for ( int i = 0; i < n; i++ ){
    int tmp;
    cin >> tmp;
    city.at( i ) = abs( tmp - x );
  }
  if ( n == 1 ) {
    cout << city.at( 0 ) << endl;
    return 0;
  }
  sort( city.begin(), city.end() );
  
  int m = gcd( city.at( 0 ), city.at( 1 ) );
  for ( int i = 2; i < n - 1; i++ ){
    m = gcd( city.at( i ), m );
  }
  
  // for ( int i = 0; i < n; i++ )
  //   cout << city.at( i ) << endl;
  // cout << endl;
  cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
    char s[100010];
    scanf("%s", &s);
    char c;
    c = 'a';
    int i;
    int flag = 1;
    while(1){
        flag = 1;
        for(i = 0; s[i] != '\0'; i++){
            if(s[i] == c){
                flag = 0;
                break;
            }
        }
        if(flag == 1){
            printf("%c\n", c);
            break;
        }
        c++;
        if(c == 'z' + 1){
            printf("None\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

l = sum(a)

sumation = 0
for i in range(n):
    sumation += a[i]
    if sumation >= l/2:
        print(min(int((sumation - l/2) * 2), int((l/2 - sumation + a[i]) * 2)))
        break

Measured memory_bytes: 88272
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define loop(i,a,b) for (int i=(a);i<(b);i++)
#define mod 1000000007
#define pb push_back

vector<ll> factrial(ll n)
{
	ll fac=2;
	ll cnt=0;
	vector<ll> ans;
	while (n%fac==0)
	{
		cnt++;
		n/=fac;
	}
	if (cnt>=1) ans.pb(cnt);
	fac++;
	while (n>1)
	{
		cnt=0;
		while (n%fac==0)
		{
			cnt++;
			n/=fac;
		}
		if (cnt>=1) ans.pb(cnt);
		fac+=2;
	}
return ans;
}

ll power(ll a, ll r)
{
	ll ans=1;
	for (int i=0;r>>i>0;i++)
	{
		if ((r>>i)&1) ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}

ll modinv(ll a)
{
	return power(a,mod-2);
}
struct cmb
{
	int n;
	
public:
	vector<ll>factrial;
	cmb(ll N)
	{
		n=N;
		factrial.resize(n+1,1);
		for (int i=1;i<n+1;i++) factrial[i]=i*factrial[i-1]%mod;
	}
	ll combo(ll n,ll r)
	{
		if (r>n) return 0;
		return factrial[n]*modinv(factrial[n-r])%mod*modinv(factrial[r])%mod;
	}
};


int main()
{
	ll N,M;cin >> N >> M;
	vector<ll> factor;
	cmb cal(1000000);
	factor=factrial(M);
	ll ans=1,num;
	for (int i=0;i<factor.size();i++)
	{
		num=factor[i];
		ans=ans*cal.combo(N+num-1,N-1)%mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h> 
#include<algorithm> 
#include<vector> 
using namespace std; 
#define PI acos(-1)
//const double PI =  3.1415926;
int main() 
{ 
	int n;
	cin>>n;
	//cout<<2*n*PI<<"\n";
	printf("%.20lf\n",2*n*PI);
} 


Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <numeric>	// require accumulate
#include <climits>

using namespace std;

int main()
{
	string str = "";
	int n;

	while (1){
		getline (cin, str );
		stringstream ssn(str);
		ssn >> n;

		if (n == 0){
			break;
		} // end if

		vector <int> a(n + 1, 0 );
		vector <int> sum (n + 1, 0 );
		int i,j;

		for (i = 1; i <= n; ++i){
			getline (cin, str );
			stringstream ss(str);
			ss >> a[i];
		} // end for

		for (i = 1; i <= n; ++i){
			sum[i] = accumulate (a.begin(), a.begin() + i + 1, 0 );
		} // end for

		int maxn = INT_MIN;
		for (i = 1; i <= n; ++i){
			for (j = i; j <= n; ++j){
				 maxn = max (maxn , sum[j] - sum[i - 1] );
			} // end for
		} // end for

		cout << maxn << endl;			

	} // end while

	return 0;
}

Measured memory_bytes: 0
from collections import deque

def bfs(u):
    dist = [-1 for _ in range(n)]
    dist[u] = 0
    que = deque([])
    que.append(u)

    while que:
        v = que.popleft()
        for nv in G[v]:
            if dist[nv] != -1:
                continue
            dist[nv] = dist[v] + 1
            que.append(nv)
            D[nv] = v
    return dist


n, m = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    G[a].append(b)
    G[b].append(a)

D = [-1]*n
bfs(0)
print('Yes')
for d in D[1:]:
    print(d+1)

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

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	int cnt = 0;
	ll sum = 0;
	bool contain_zero = false;
	ll mn = 1001001001;
	rep(i, n) {
		sum += abs(a[i]);
		mn = min(mn, abs(a[i]));
		if(a[i] < 0) cnt++;
		if(a[i] == 0) contain_zero = true;
	}
	if(contain_zero) {
		ans = sum;
	} else {
		if(cnt%2 == 0) {
			ans = sum;
		} else {
			ans = sum - mn * 2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if ((10 * g + b) % 4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" <<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count	= sc.nextInt();
		int legs	= sc.nextInt();
		int hind	= legs-(count*2);
		System.out.println(hind>=0&&hind%2==0&&hind/2<=count?"Yes":"No");
	}
}

Measured memory_bytes: 35784
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int n;
bool vis[8];
pair<double, double> pos[8];
double dis(int x, int y)
{
	return sqrt((pos[x].fst - pos[y].fst) * (pos[x].fst - pos[y].fst) + (pos[x].scd - pos[y].scd) * (pos[x].scd - pos[y].scd)); 
}
double calc(int _ind, double _dis)
{
	double ans = 0;
	bool isend = true;
	for(int i = 0; i < n; ++i)
	{
		if(!vis[i])
		{
			isend = false;
			vis[i] = true;
			ans += calc(i, _dis + dis(_ind, i));
			vis[i] = false;
		}
	}
	if(isend)
	{
		return _dis;
	}
	else
	{
		return ans;		
	}
}
signed main()
{
	double ans = 0, num = 1;
	scanf("%d", &n);
	for(int i = 0, j, k; i < n; ++i)
	{
		scanf("%d%d", &j, &k);
		pos[i] = make_pair(j, k);
		num *= (i + 1);
	}
	for(int i = 0; i < n; ++i)
	{
		vis[i] = true;
		ans += calc(i, 0);
		vis[i] = false;
	}
	printf("%.10lf\n", ans / num);
}


Measured memory_bytes: 256
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()

count = 0
for i in range(N):
    for j in range(i+1, N):
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            count += k -j -1
print(count)

Measured memory_bytes: 45916
#include <iostream>
#include <vector>
#include <utility>
using namespace  std;

void fnInput(vector<int> &rvnNum)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvnNum.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
    cin >> rvnNum[i];
}

int fnPartition(vector<int> &rvnNum, int nFront, int nBack)
{
  int nMid = nFront;

  for (int i = nFront; i < nBack; i++)
    if (rvnNum[i] <= rvnNum[nBack])
      swap(rvnNum[nMid++], rvnNum[i]);

  swap(rvnNum[nMid], rvnNum[nBack]);
  return nMid;
}

void fnResult(const vector<int> &cnrvnNum, int nMid)
{
  for (int i = 0; i < cnrvnNum.size(); i++)
  {
    if (i)  cout << " ";
    if (i == nMid) cout << "[";
    cout << cnrvnNum[i];
    if (i == nMid) cout << "]";
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnNum;

  fnInput(vnNum);
  int nFront = 0;
  int nBack = vnNum.size() - 1;

  int nMid = fnPartition(vnNum, nFront, nBack);
  fnResult(vnNum, nMid);

  return 0;
}

Measured memory_bytes: 1520
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define SORT(A) sort(A.begin(), A.end())

int main() {
    ll a,b;
    cin >> a >> b;

    ll g = 1;
    for(ll i = min(a,b); i > 0; i--){
        if(a % i == 0 && b % i == 0){
            a /= i;
            b /= i;
            g = i;
            break;
        }
    }

    cout << a * b * g << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	void rect(){
		Scanner s = new Scanner(System.in);
		int h = s.nextInt();
		int w = s.nextInt();
		while(h!=0||w!=0){
			for(int i = 0;i<h;i++){
				for(int j = 0;j<w;j++){
					if((j+i)%2==0){
						System.out.print("#");
					}else{
						System.out.print(".");
					}
				}
				System.out.println("");
			}
			System.out.println("");
			h = s.nextInt();
			w = s.nextInt();
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.rect();
	}
}

Measured memory_bytes: 32716
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return (t * t) % mod;
    } else {
        return (modpow(m, n - 1) * m) % mod;
    }
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

struct LCA {
    vector<vector<int>> par;
    vector<int> d;
    int n;
    LCA(vector<vector<int>> graph, int root) {
        n = graph.size();
        par.resize(n, vector<int>(30));
        d.resize(n, 0);
        function<void(int, int, int)> dfs = [&](int c, int p, int depth) {
            d[c] = depth;
            par[c][0] = p;
            for (auto ch : graph[c]) {
                if (ch != p) dfs(ch, c, depth + 1);
            }
        };
        dfs(0, 0, 0);
        for (int j = 1; j < 30; j++) {
            REP(i, n) { par[i][j] = par[par[i][j - 1]][j - 1]; }
        }
    }
    int getdistance(int u, int v) { return (d[u] + d[v]) - 2 * (d[query(u, v)]); }
    int query(int u, int v) {
        if (d[u] > d[v]) {
            swap(u, v);
        }
        for (int i = 29; 0 <= i; i--) {
            if (d[u] <= d[par[v][i]]) {
                v = par[v][i];
            }
        }
        /* LCA */
        for (int i = 29; 0 <= i; i--) {
            if (par[v][i] != par[u][i]) {
                v = par[v][i];
                u = par[u][i];
            }
        }
        if (u == v) {
            return u;
        } else {
            return par[v][0];
        }
    }
};

struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
int n, m;
vector<vector<int>> graph;
void aoj(vector<int> bs) {
    REP(i, bs.size() - 1) { cout << bs[i] << " "; }
    cout << bs[bs.size() - 1] << endl;
}

signed main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (d % 2 == 1) {
        cout << b - a << endl;
    }
    if (d % 2 == 0) {
        cout << a - b << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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(b<a) { a=b; return 1; } return 0; }

int main(){
  int n,m; cin >> n >> m;
  vector<vi> to(n);
  rep(i,m){
    int a,b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  for(auto i : to[0]){
    for(auto j : to[i]){
      if(j == n-1){
        cout << "POSSIBLE\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE";
  cout << "\n";
  return 0;
}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

Int n, m;

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		if(i % 2 == 0){
			Int a = (n + 1) / 4 - i / 2;
			Int b = a + i + 1;
			cout << a << " " << b << endl;
		}else{
			Int a = (n - 1) / 4 - i / 2;
			Int b = a + i + 1;
			cout << n - a + 1 << " " << n - b + 1 << endl;
		}
	}
}


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

int main(){
  priority_queue<int> que;
  int n,m;
  cin >> n >> m;
  int x;
  for(int i=0; i<n; i++){
    cin >> x;
    que.push(x);
   }
  for(int i=0; i<m; i++){
    x = que.top();
    que.pop();
    que.push(x/2);
   }
  long long s=0;
  for(int i=0; i<n; i++){
    s += que.top();
    que.pop();
   }
  cout << s << endl;
}

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

//xはサイコロの目,K基準値,カウンター0を代入すると表をだす必要がある回数を返す関数
int alpha(int x,int K,int cnt)
{
  while (x < K)
  {
    x *= 2;
    cnt +=1;
  }
  return cnt;
}

int main()
{
  int N,K;
  cin >> N >> K;

  int bunshi = 0;
  int alpha_max = alpha(1,K,0);
  int bunbo = pow(2,alpha_max)*N;

  for(int i = 0;i < N;i++)
  {
    if (alpha(i+1,K,0) != 0)
      bunshi += pow(2,alpha_max-alpha(i+1,K,0));
    else
      bunshi += pow(2,alpha_max);
  }
  
  //cout << bunshi << endl;
  //cout << bunbo << endl;
  double answer = (double)bunshi/bunbo;
  cout << fixed << setprecision(15);
  cout << answer << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  int k = 1;
  int c = 0;
  rep(i,n) {
    if (v[i] != k) c++;
    else k++;
  }
  cout << ((c == n)? -1: c) << endl;
}

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

Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
using namespace std;
const int mod=1e9+7;
int arr[21][21];
ll dp[21][(ll)1<<21];
int n;
ll add_self(ll &p, ll q)
{
    p+=q;
    if(p>=mod) p-=mod;
}
ll DP(int pos, int bit)
{
    if(pos>=n) return 1;
    if(dp[pos][bit]!=-1) return dp[pos][bit];
    ll ans=0;
    for(int i=0; i<n; i++)
    {
        if(arr[pos][i] && !(bit&(1<<i)))
        {
            ll temp=DP(pos+1, (bit|(1<<i)));
            add_self(ans, temp);
        }
            //ans=(ans+DP(pos+1, (bit|(1<<i))))%mod;
    }
    return dp[pos][bit]=ans;
}
int main()
{
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            scanf("%d", &arr[i][j]);
    }
    ll ans=DP(0, 0);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 344448
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c - (a - b) < 0) cout << 0;
	else cout << c - (a - b);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
void fmin(int&a,int b){
	if(b<a)a=b;
}
int s[41][41],f[41][41][41][41];
char str[41];
int get(int i,int j,int k,int l){
	if(i>k||j>l)return 0;
	return s[k][l]-s[i-1][l]-s[k][j-1]+s[i-1][j-1];
}
int main(){
	int n,m,i,j,k,l,x,y,sx,sy,ans;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%s",str+1);
		for(j=1;j<=m;j++){
			if(str[j]=='P'){
				sx=i;
				sy=j;
			}
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(str[j]=='#');
		}
	}
	memset(f,63,sizeof(f));
	ans=f[0][0][0][0];
	f[1][1][n][m]=0;
	for(i=1;i<=sx;i++){
		for(j=1;j<=sy;j++){
			for(k=n;k>=sx;k--){
				for(l=m;l>=sy;l--){
					fmin(ans,f[i][j][k][l]+min(min(get(i,j,sx,sy),get(i,sy,sx,l)),min(get(sx,j,k,sy),get(sx,sy,k,l))));
					for(x=i;x<=k;x++){
						for(y=j;y<=l;y++){
							if(sx<=x&&sy<=y)fmin(f[i][j][x][y],f[i][j][k][l]+get(i,y+1,x,l)+get(x+1,j,k,y));
							if(sx<=x&&y<=sy)fmin(f[i][y][x][l],f[i][j][k][l]+get(i,j,x,y-1)+get(x+1,y,k,l));
							if(x<=sx&&y<=sy)fmin(f[x][y][k][l],f[i][j][k][l]+get(i,y,x-1,l)+get(x,j,k,y-1));
							if(x<=sx&&sy<=y)fmin(f[x][j][k][y],f[i][j][k][l]+get(i,j,x-1,y)+get(x,y+1,k,l));
						}
					}
				}
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <unistd.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 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<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(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 ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< 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 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  char b;
  cin >> b;
  if (b == 'A') {
    cout << 'T';
  }
  else if (b == 'T') {
    cout << 'A';
  }
  else if (b == 'C') {
    cout << 'G';
  }
  else {
    cout << 'C';
  }
  cout << endl;
    

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = Math.max(a+b,Math.max(a-b,a*b));
        System.out.println(ans);
	}
}

Measured memory_bytes: 21844
'''
Author : Shubhanshu Jain;
'''

import math
import random;
from collections import defaultdict 
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rms = lambda : map(str,input().split());
rls = lambda : list(rm())

def solve():
    x,n = rm();
    ls = rls();
    ar = [0]*101;
    for i in ls:
        ar[i]= 1;
    f = x;end = x;
    # ar[x]=1
    while(True):
        if f not in ls:
            print(f)
            break;
        if end not in ls:
            print(end);
            break;
        f-=1;
        end+=1;
            
        





def def_value(): 
	return "nan"
	
solve();



Measured memory_bytes: 9784
import java.util.Scanner;
public class Main{
	public static int string(String i) {
		int j=0;
		if(i.equals("A")) {
			j=10;
		}if(i.equals("B")) {
			j=11;
		}if(i.equals("C")) {
			j=12;
		}if(i.equals("D")) {
			j=13;
		}if(i.equals("E")) {
			j=14;
		}if(i.equals("F")) {
			j=15;
		}
		return j;
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a=scan.next();
		String b=scan.next();
		int c=string(a);
		int d=string(b);
		if(c==d) {
			System.out.println("=");
		}
		else {
			if(c>d) {
				System.out.println(">");
			}
			else {
				System.out.println("<");
			}
		}
	}
}

Measured memory_bytes: 21332
#include <iostream>

int main(void){
    /* input */
    int beginNum  = 0;
    int endNum    = 0;
    int targetNum = 0;
    std::cin >> beginNum >> endNum >> targetNum;
    
    /* check */
    int count     = 0;
    for(int divideNum = beginNum; divideNum <= endNum; ++divideNum)
    {
        if((targetNum % divideNum) == 0)
        {
            ++count;
        }
    }
    /* output */
    std::cout << count << std::endl;
    
    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

const int N = 1e6+10;
vl lp(N+1);

void calcLp(){ //lowest prime
    for(int i=2; i<=N; i++){
        if(!lp[i]){
            for(int j=i; j<=N; j+=i)
                if(!lp[j]) // comment this line to find Largest Prime factor
                    lp[j] = i;
        }
    }
}

ll cntDivs(int n){
    ll ans = 1;
    while(n>1){
        int p = lp[n];
        ll c = 0;
        while(n%p==0){
            n/=p; ++c;
        }
        ans*=(c+1);
    }
    return ans;
}

vi primeFacts(int n){
    vi out;
    while(n>1){
        int p = lp[n];
        while(n%p==0){
            n/=p;
            out.pb(p); // to get proper prime factorisation
        }
        // out.pb(p); // to get only single facts
    }
    return out;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    calcLp();
    ll n;
    while(cin>>n){
        ll ans = 0;
        for(int rem = 1; rem<n; ++rem){
            ans+=cntDivs(n-rem);  
        }
        cout<<ans<<"\n";
    }
    return 0;
}

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

int n, a, b, c, d;
string s;

int main()
{
    cin >> n >> a >> b >> c >> d;
    a--, b--, c--, d--;
    cin >> s;
    for (int i = min(a,b); i <= max(c,d); i++)
    {
        if (s[i] == '#' && s[i+1] == '#')
        {
            return cout << "No", 0;
        }
    }
    if (a > b)
    {
        swap(a,b);
        swap(c,d);
    }
    if (c < d)
        return cout << "Yes", 0;
    for (int i = max(a,b); i <= min(c,d); i++)
    {
        if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.')
            return cout << "Yes", 0;
    }
    cout << "No";
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
from functools import reduce
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def calc(A):
    N = len(A)
    if N == 1:
        return A[0]%2 == 0

    K = sum(1 for a in A if a % 2 == 0)
    if K & 1:
        return True
    if N-K != 1:
        return False
    if min(A) == 1:
        return False
    A = [a-a%2 for a in A]
    g = reduce(gcd, A)
    A = [a//g for a in A]
    return not calc(A)


N = int(readline())
A = list(map(int, readline().split()))
print('First' if calc(A) else 'Second')

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

//与えられた２つの整数 a、b について ax+by=gcd(a,b) の整数解 (x,y)
template< typename T >
T extgcd(T a, T b, T &x, T &y) {
    T d = a;
    if(b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; }
    else { x = 1; y = 0; }
    return d;
}

int main() {
    int a, b, x, y;
    cin >> a >> b;
    extgcd(a, b, x, y);
    cout << x << " " << y << endl;
}


Measured memory_bytes: 3120
import math

s_num=int(input())
s_list=list(map(int,input().split()))
q_num=int(input())
q_list=list(map(int,input().split()))


count = 0

for q in q_list:
    left = 0
    right = s_num
    while left < right:
        mid = math.floor((left + right) / 2)
        if s_list[mid] == q:
            count += 1
            break
        elif s_list[mid] < q:
            left = mid+1
        else:
            right = mid

print(count)


Measured memory_bytes: 16764
# def linear_search(seq1, seq2):
#     count = 0
#     for i in seq1:
#         for j in seq2:
#             if i == j:
#                 count += 1
#     return count


def binary_search(seq, seq1_len, key):
    left = 0
    right = seq1_len
    center = 0
    while left < right:
        center = (left + right) // 2
        if seq[center] == key:
            return True
        if key < seq[center]:
            right = center
        else:
            left = center + 1
    return False


def main():
    # num_seq1 = int(input())
    seq1_len = int(input())
    seq1 = list(map(int, input().split(" "))) + [0]  # 番兵
    # num_seq2 = int(input())
    input()
    seq2 = list(map(int, input().split(" ")))
    count = 0
    for key in seq2:
        if binary_search(seq1, seq1_len, key):
            count += 1

    print(count)


if __name__ == "__main__":
    main()



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

using namespace std;

constexpr static int MAXN = 500;
int n;
int x[MAXN];
int a[MAXN * MAXN];
int cnt[MAXN];

bool solve() {
    for (int k = 0; k < n * n; k++)
        a[k] = -1;

    vector <pair <int, int>> c;
    for (int i = 0; i < n; i++) {
        a[x[i] - 1] = i;
        c.push_back({x[i] - 1, i});
    }
    sort(c.begin(), c.end());

    vector <int> use;
    for (auto p : c) {
        int i = p.second;
        for (int j = 0; j < i; j++)
            use.push_back(i);
    }

    int idx = 0;
    for (int k = 0; k < n * n; k++) {
        if (a[k] != -1) {
            int i = a[k];
            if (cnt[i] < i)
                return false;
            for (int j = 0; j < n - i - 1; j++)
                use.push_back(i);
            continue;
        }

        if (idx == use.size())
            return false;

        a[k] = use[idx++];
        cnt[a[k]]++;
    }
    return true;
}

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

    if (solve()) {
        cout << "Yes" << endl;
        for (int k = 0; k < n * n; k++)
            cout << a[k] + 1 << " ";
        cout << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7+5;
typedef long long LL;
const LL mo=1e9+7;
LL fac[maxn],inv[maxn];
LL C(int n,int m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mo*inv[n-m]%mo;
}
LL pw(LL x,LL k,LL p=::mo){
	LL ans=1;
	for(;k;k>>=1){
		if(k&1)ans=ans*x%mo;
		x=x*x%mo;
	}
	return ans;
}
int main(){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<maxn;i++){
		fac[i]=fac[i-1]*i%mo;
	}
	for(int i=2;i<maxn;i++){
		inv[i]=(mo-mo/i)*inv[mo%i]%mo;
	}
	for(int i=2;i<maxn;i++){
		inv[i]=inv[i-1]*inv[i]%mo;
	}

	LL ans=0;


	int n,m,k;
	cin>>n>>m>>k;
	if(m>k)swap(m,k);


//	long long ans=0;
/*	for(int i=0;i<=m;i++)
		for(int j=0;j<=k;j++){
			ans+=C(n+i+j-1,n-1)*C(i+j,i)*pw(3,m+k-i-j);
		}
	cout<<ans<<endl;

	for(int i=0;i<=m+k;i++)
		for(int j=0;j<=k&&j<=m;j++){
			ans+=C(n+i-1,n-1)*C(i,j)*pw(3,m+k-i);
		}
	cout<<ansi<<endl;
	return 0;*/
	LL cur=1;
	for(int p=0;p<=m+k;p++){
		LL res=0;
		
		res=C(n+p-1,n-1)*pw(3,m+k-p)%mo;

		ans+=res*cur%mo;
		ans%=mo;

		cur=cur*2%mo;
		if(p>=m){
			cur-=C(p,m);
			cur+=mo;cur%=mo;
		}
		if(p>=k){
			cur-=C(p,p-k);
			cur+=mo;cur%=mo;
		}


	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 156544
// Copyright 2017 wu_qing
#include <cstdio>
int a, b, c, tot;
int main() {
    scanf("%d%d%d", &a, &b, &c);
    tot = a * 100 + b *10 + c;
    if (tot % 4 == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 128