akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            sum += s[i];
        }
        if (sum % 10 != 0) {
            System.out.println(sum);
            return;
        }
        Arrays.sort(s);
        for (int i = 0; i < n; i++) {
            if (s[i] % 10 != 0) {
                System.out.println(sum - s[i]);
                return;
            }
        }
        System.out.println(0);
    }

}


Measured memory_bytes: 24916
N,M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
count = 0
for i in range(1<<N):
    for m in range(M):
        switch=0
        for j in range(N):
            if (i>>j)&1 and j+1 in s[m]:
                switch += 1
        if switch%2!= p[m]:
            break
    else:
        count += 1
print(count)

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <climits>
using namespace std;

struct Edge {
    int dst;
    int weight;
    bool operator<(const Edge& a) const {
        return weight < a.weight;
    }
};

int start[100010];
int dist[100010];
vector<Edge> edges[100010];
int used[100010];

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

    if (M == 0) {
        cout << "Yes" << endl;
        return 0;
    }

    for (int i=0; i<M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        edges[l].push_back( Edge{r,d} );
        edges[r].push_back( Edge{l,-d} );
        // 始点を探し出す
        start[r] = 2; // 始点の可能性なし
        start[l] = start[l] == 2 ? 2 : 1; // 始点の可能性あり
    }

    // 始点を探す
    vector<int> sv;
    for (int i=1; i<=N; i++) {
        if (start[i] == 1) {
            sv.push_back(i);
        }
    }
    if (sv.size() == 0) {
        cout << "No" << endl;
        return 0;
    }

    for (int i=0; i<=N; i++) {
        dist[i] = INT_MAX;
        used[i] = -1;
    }
    // 適当に始点からはじめる
    for (int k=0; k<sv.size(); k++) {
        if (used[sv[k]] != -1) continue;
        queue<int> q;
        q.push( sv[k] );
        dist[sv[k]] = 0;

       while (!q.empty()) {
            int src = q.front();
            q.pop();

            if (used[src] != -1) continue;
            used[src] = k; // stage番号にする
            int curr_cost = dist[src];
            for (int i=0; i<edges[src].size(); i++) {
                Edge e = edges[src][i];
                if (dist[e.dst] == INT_MAX || dist[e.dst] == curr_cost + e.weight) {
                    dist[e.dst] = curr_cost + e.weight;
                    if (used[e.dst] == -1) {
                        q.push(e.dst);
                    }
                } else if (dist[e.dst] != INT_MAX && dist[e.dst] != curr_cost + e.weight) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
 
        // マイナスの距離になってないか確認する
        int max_minus = 0;
        for (int i=1; i<=N; i++) {
            if (used[i] == k) {
                max_minus = min(max_minus, dist[i]);
            }
        }
        // 相対位置をずらす, このときに10^9を超えてないか確認
        for (int i=1; i<=N; i++) {
            if (dist[i] != INT_MAX && used[i] == k) {
                dist[i] += -1 * max_minus;
                if (dist[i] > 1000000000) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>
#include <string>
#include <queue>
#include <iomanip>
using namespace std;

#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)


int main()
{
  long long int x; cin >> x;
  int out = 0;
  out += 1000 * (x/500); 
  x -= 500*(x/500);
  out += 5 * (x/5);
  cout << out << endl;


  return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int c = 1; c <= n; c += 2) {
		int num_of_divisors = 0;
		for (int x = 1; x <= c; ++x) {
			if (c % x == 0) ++num_of_divisors;
		}
		if (num_of_divisors == 8) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
string d[N];
int n;
char ans[N];
void dfs(int i,int a,int b,int c){
  if(i>n && a>=0 &&b>=0&&c>=0){
    cout<<"Yes\n";
    for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
    exit(0);
  }
  if(d[i]=="AB"){
    if(b>=1){
      ans[i]='A';
      dfs(i+1,a+1,b-1,c);
    }
    if(a>=1){
      ans[i]='B';
      dfs(i+1,a-1,b+1,c);
    }
  }else if(d[i]=="AC"){
    if(c>=1){
      ans[i]='A';
      dfs(i+1,a+1,b,c-1);
    }
    if(a>=1){
      ans[i]='C';
      dfs(i+1,a-1,b,c+1);
    }
  }else{
    if(c>=1){
      ans[i]='B';
      dfs(i+1,a,b+1,c-1);
    }
    if(b>=1){
      ans[i]='C';
      dfs(i+1,a,b-1,c+1);
    }
  }
}
int a,b,c;

int main() {
  ios::sync_with_stdio(false);
  cin>>n>>a>>b>>c;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  dfs(1,a,b,c);
  cout<<"No\n";
  return 0;
}

Measured memory_bytes: 17828
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll a[200017];
set< ll > s1,s2;
void solve(){
	ll n,i,x,tot,y;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x;
		a[x]=i;
	}
	tot=0;
	s1.insert(0);
	s1.insert(n+1);
	s2.insert(0);
	s2.insert(0-n-1);
	for(i=1;i<=n;i++){
		s1.insert(a[i]);
		s2.insert(0-a[i]);
		x=*s1.upper_bound(a[i])-a[i];
		y=a[i]+*s2.upper_bound(0-a[i]);
//		cout<<x<<" "<<y<<endl;
		tot+=(x*y*i);		 
	}
	cout<<tot;
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 23936
#include <iostream>
using namespace std;
int main(void){
	int n;
	cin >>n;
	int t[n];
	long sum=0;
	for(int i=0; i<n; i++){
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	while(m--){
		int p, x;
		cin >> p >> x;
		cout << sum + x - t[p-1] << "\n";
	}
}

Measured memory_bytes: 3528
local n=io.read("n")

local p={}
for i=2,math.sqrt(n) do
    if n%i==0 then
        local counter=0
        while n%i==0 do
            n=n//i
            counter=counter+1
        end
        table.insert(p, counter)
    end
end
if n>1 then
    table.insert(p,1)
end

local counter=0
for i=1,#p do
    local j=1
    while j<=p[i] do
        p[i]=p[i]-j
        j=j+1
        counter=counter+1
    end
end
print(counter)

Measured memory_bytes: 2720
s = input()

ma = 0
for i in range(len(s)):
    for j in range(1,len(s)-i+1):
        tmp = s[i:i+j]
        # print(i,j,tmp)
        is_good = True
        for c in tmp:
            if c not in "AGCT":
                is_good = False
                break
        if is_good:
            if (len(tmp)) > ma :
                ma = len(tmp)

print(ma)

        

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

int l[2000][2000] = {}, r[2000][2000] = {};
int u[2000][2000] = {}, d[2000][2000] = {};

int main(){
    int h, w;
    cin >> h >> w;
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] != '.')    continue;
            u[i][j] = (i==0 ? 0 : u[i-1][j]) + 1;
        }
    }
    for(int i = h-1; i >= 0; i--){
        for(int j = 0; j < w; j++){
            if(mat[i][j] != '.')    continue;
            d[i][j] = (i==h-1 ? 0 : d[i+1][j]) + 1;
        }
    }

    for(int j = 0; j < w; j++){
        for(int i = 0; i < h; i++){
            if(mat[i][j] != '.')    continue;
            l[i][j] = (j==0 ? 0 : l[i][j-1]) + 1;
        }
    }
    for(int j = w-1; j >= 0; j--){
        for(int i = 0; i < h; i++){
            if(mat[i][j] != '.')    continue;
            r[i][j] = (j==w-1 ? 0 : r[i][j+1]) + 1;
        }
    }

    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '#')    continue;
            ans = max(ans, l[i][j]+r[i][j]+d[i][j]+u[i][j]-3);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66688
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        d: usize,
        g: usize,
        scores: [(usize, usize); d],
    }

    let mut ans = {
        let mut ans = 0;
        for &(p,_) in scores.iter() {
            ans += p;
        }
        ans
    };

    for b in 0..2u32.pow(d as u32)-1 {
        let mut score = 0;
        let mut max = 0;
        let mut kosu = 0;

        for i in 0..d {
            if (b >> i) & 1 == 1 {
                let (p,c) = scores[i];
                score += 100*(i+1)*p + c;
                kosu += p;
            } else {
                max = i;
            }
        }
        
        let (p,_) = scores[max];
        for _ in 0..p {
            if score >= g {
                break;
            } else {
                score += 100*(max+1);
                kosu += 1;
            }
        }

        if (score >= g) & (ans > kosu) {
            ans = kosu;
        }
    }

    println!("{}",ans);
}


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vector<int>v;
    int t,in,i,mn;
    cin>>t;
    while(t--)
    {
        cin>>in;
        v.push_back(in);
    }
    mn=(*max_element(v.begin(),v.end()))+10;
    int cnt=0;
    for(i=0;i<v.size();i++)
    {
        if(mn>=v[i])
        {
            cnt++;
            mn=v[i];
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>


typedef long long int ll;

ll mod=1e9+7;

int main(){

    int N,K;
    scanf("%d%d",&N,&K);

    if (K==N+1){
        puts("1");
        return 0;
    }

    ll ans=1;
    ll high=N,low=0;
    for(int i=0;i<(N+1-K);i++){
        ll diff=(high+(mod-low))%mod;
        ans=(ans+(diff+1)%mod)%mod;
        high=(high+(N-i-1))%mod;
        low=(low+i+1)%mod;
    }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M; cin >> N >> M;
  map<long long, long long> P;
  for (int i=0; i<N; i++) {
    long long a; cin >> a;
    P[a] += 1;
  }
  for (int i=0; i<M; i++) {
    long long b, c; cin >> b >> c;
    P[c] += b;
  }
  long long rem=N, ans=0;
  for(auto itr = P.rbegin(); itr != P.rend(); itr++){
    long long b, c, idx;
    b=itr->second; c=itr->first;
    ans += c*min(rem,b);
    rem-=b;
    if(rem<=0) break;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 12800
use std::io;
use std::cmp;


fn main() {
    let n = read_one::<usize>();
    let a = read_one::<String>().chars().collect::<Vec<char>>();
    let b = read_one::<String>().chars().collect::<Vec<char>>();
    let c = read_one::<String>().chars().collect::<Vec<char>>();

    let mut cnt = 0;
    for i in 0..n {
        let mut diff_a = 0;
        let mut diff_b = 0;
        let mut diff_c = 0;

        if a[i] != b[i] { diff_a += 1; diff_b += 1; }
        if b[i] != c[i] { diff_b += 1; diff_c += 1; }
        if c[i] != a[i] { diff_c += 1; diff_a += 1; }
        cnt += cmp::min(diff_a, cmp::min(diff_b, diff_c));
    }

    println!("{}", cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
def main():
    n=int(input())
    a = list(map(int,input().split()))
    l1=[0 for _ in range(n+1)]
    l2=[0 for _ in range(n+1)]

    for i in range(n):
        l1[i+1]=a[i]-l1[i]
    l1[0]=l1[n]
    l2[1]=a[0]-l1[0]
    l2[0]=l2[n]
    for i in range(1,n):
        l2[i+1]=a[i]-l2[i]
    ans=[]
    for i in range(n):
        ans.append( str(l1[i]+l2[i]) )
    print(' '.join(ans))


if __name__ == "__main__":
    main()

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

int main(void) {
    while (true) {
        int a,b;
        char op;
        cin>>a>>op>>b;
        if (op == '+') cout << a + b << endl;
        if (op == '-') cout << a - b << endl;
        if (op == '*') cout << a * b << endl;
        if (op == '/') cout << a / b << endl;
        if (op == '?') break;
    }
    return 0;
}


Measured memory_bytes: 3092
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

sx, sy, tx, ty = inpl()
res = ""

res += "U"*(ty-sy) + "R"*(tx-sx) + "D"*(ty-sy) + "L"*(tx-sx)
res += "L" + "U"*(ty-sy+1) + "R"*(tx-sx+1) + "D"
res += "R" + "D"*(ty-sy+1) + "L"*(tx-sx+1) + "U"

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
ll t=0;
rep(i,n){
  t^=a[i];
}
vector<ll> sum;
sum.push_back(0);
rep(i, n)
{
  sum.push_back(a[i] ^ sum[i]);
}
if(t!=0){
  vector<vector<ll>> dp(n+1, vector<ll>(2,0) );
  dp[0][0]=1;
  rep(i,n){
    dp[i+1][0]+=dp[i][0];
    dp[i+1][1]+=dp[i][1];
    if(sum[i+1]==0)dp[i+1][0]+=dp[i][1];
    if(sum[i+1]==t)dp[i+1][1]+=dp[i][0];
    dp[i+1][0]%=mo;
    dp[i+1][1]%=mo;
  }
  ans=dp[n-1][0];
}
else{
  ll tt=0,num=0;
  rep(i,n){
    tt^=a[i];
    if(tt==0)num++;
  }
  ans=mypow(2,num-1);
  vector<ll> z;
  z.push_back(1);
  rep(i,n){
    if(sum[i+1]==0)z.push_back(z.back()+1);
    else z.push_back(z.back());
  }
  map<ll,ll> pre;
  map<ll,pair<ll,ll>> m;
  rep(i,n){
    if(sum[i+1]==0)continue;
    if(m[sum[i+1]].first==0&&m[sum[i+1]].second==0)m[sum[i+1]]={1,i};
    else {
      pre[sum[i+1]]+=m[sum[i+1]].first;
      m[sum[i+1]].first+=(z[i]-z[m[sum[i+1]].second])*pre[sum[i+1]];
      m[sum[i+1]].first%=mo;
      m[sum[i+1]].second=i;
    }
  }
  for (auto i = m.begin(); i != m.end(); ++i) {
    ans+=i->second.first;
    ans%=mo;
  }
  for (auto i = pre.begin(); i != pre.end(); ++i) {
    ans+=i->second;
    ans%=mo;
  }
}
cout << ans%mo << endl;
return 0;
}

Measured memory_bytes: 35436
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    string S;
    cin>>S;
    int N = S.size();
    int64_t a=0;
    for(int i=0;i<N;i++){
        a*=10; a+=S[i]-'0';
    }
    //n!?????????
    vector<int> V;
    for(int i=0;i<10;i++) V.push_back(i);
    int64_t ans=a, diff=0;
    int64_t pN=1; for(int i=0;i<N;i++) pN*=10;
    do{
        int64_t b=0;
        for(int i=0;i<N;i++){
            b*=10; b+=V[i];
        }
        int64_t ndiff = min(abs(a-b),pN-abs(a-b));
        if(ndiff>diff||(ndiff==diff&&b<ans)){
            ans=b; diff=ndiff;
        }
    }while(next_permutation(V.begin(),V.end()));
    if(ans<pN/10) cout<<'0';
    cout<<ans<<endl;
}

Measured memory_bytes: 3200
local unpack = table.unpack or unpack
local INF = math.floor(10^10)
local N, M, P = io.read("*n", "*n", "*n")
if string.find(_VERSION, "5.1") and N * M < 10^6 then
    -- for b06
    local f = io.open("in.txt", "w")
    f:write(table.concat({N, M, P}, " "))
    f:write("\n")
    for i=1,M do
        local a, b, c = io.read("*n", "*n", "*n")
        f:write(table.concat({a,b,c}, " "))
        f:write("\n")
    end
    f:close()
    os.execute("cat in.txt | lua Main.lua")
    return
end
local edges = {}
for i=1,M do
    local a, b, c = io.read("*n", "*n", "*n")
    edges[i] = {a, b, -1 * (c - P)}
end
-- Bellman-Ford
local function bf()
    -- distance from 1
    local d = {}
    for i=1,N do
        d[i] = INF
    end
    d[1] = 0
    for i=1,N-1 do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                local new_d = d[a] + w
                if new_d < d[b] then
                    d[b] = new_d
                end
            end
        end
    end
    for i=1,N do
        for j=1,M do
            local a, b, w = unpack(edges[j])
            if d[a] ~= INF then
                if d[a] + w < d[b] or d[a] == -INF then
                    d[b] = -INF
                end
            end
        end
    end
    return d
end

local d = bf()
local negloop = d[N] == -INF
if negloop then
    print(-1)
else
    print(math.max(0,-d[N]))
end

Measured memory_bytes: 1556
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P


int main(){
	int n,a,b;
	scanf("%d %d %d", &n, &a, &b);

	printf("%d\n", min(n*a,b));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[101];

int32_t main(){
	fastio();
	int s = 0;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		s += x;
		cnt[i] = x;
	}
	int ans = mod;
	for(int i = 1; i < n; i++){
		cnt[i] += cnt[i - 1];
		ans = min(ans,abs(s - 2 * cnt[i]));
	}
	cout << ans;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>

using namespace std;

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long a, b; cin >> a >> b;
    cout << a * b / gcd(a, b);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	int n, w; cin >> n >> w;
	vector<ll> a(n,0), v(n);
	int cnt[4] = {};
	vector<vector<ll>> s(4);
	rep(i, 0, n) {
		cin >> a[i] >> v[i];
		cnt[a[i] - a[0]]++;
		s[a[i]-a[0]].push_back(v[i]);
	}
	rep(i, 0, 4) sort(s[i].begin(), s[i].end(),greater<ll>());
	ll ans = 0;
	rep(i, 0, cnt[0] + 1)rep(j, 0, cnt[1] + 1)rep(k, 0, cnt[2] + 1)rep(l, 0, cnt[3] + 1) {
		ll weight = i * a[0] + j * (a[0] + 1) + k * (a[0] + 2) + l * (a[0] + 3);
		if (w < weight) continue;
		ll sum = 0;
		rep(a, 0, i) sum += s[0][a];
		rep(b, 0, j) sum += s[1][b];
		rep(c, 0, k) sum += s[2][c];
		rep(d, 0, l) sum += s[3][d];
		ans = max(ans, sum);
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 384
def main():
    x1, y1, x2, y2 = map(int, input().split())
    vx = x2 - x1
    vy = y2 - y1

    print(x2 - vy, y2 + vx, x1 - vy, y1 + vx)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61912
import java.util.*;
public class Main
{
public static void main(String[] args)
{
 
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
ar[i]=sc.nextInt();
TreeMap<Integer,Integer> t=new TreeMap<Integer,Integer>();
for(int j=0;j<n;j++)
{
    t.put(ar[j],j);
}
int gh[]=new int[n];int kf=0;
for(Map.Entry<Integer,Integer> e:t.entrySet())
{
    gh[kf++]=e.getValue();
}
int nas=0;
for(int yy=0;yy<n;yy++)
{
    if(gh[yy]%2!=0)
    {
        if(yy%2==0)nas++;
    }
    if(gh[yy]%2==0)
    {
        if(yy%2!=0)nas++;
    }
}
System.out.println(nas/2);}}

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

int main(void){
  int r,g,b,n; cin>>r>>g>>b>>n;
  long count =0;
  for(int i=0; i<=n/r; ++i){
    for(int j=0; j<=(n-r*i)/g; ++j){
      if( (n-r*i-g*j)%b == 0 ) count++;
    }
  }
  cout<< count <<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

cnt = [0] * (n+1)
for v in a:
    cnt[v] += 1

tmp = 0
for c in cnt:
    tmp += c * (c-1) // 2
for v in a:
    print(tmp - cnt[v] + 1)

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

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

    auto sales = 0LL;
    for (auto i = 0, price = 1; i < N; i++)
    {
        int x; cin >> x;

        if (i == 0)
        {
            sales += x-1;
            price = 2;
        }
        else
        {
            if (x == price) price++;
            else if (x > price) sales += x/price - (x%price == 0);
        }
    }

    cout << sales << endl;
}



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

int main(){
  vector<int> N(3);
  for(int i = 0; i < 3; ++i){
    cin >> N[i];
  }
  sort(N.begin(), N.end());
  cout << N[2] * 10 + N[1] + N[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
/* Data Structure */
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define debug cerr << "======= GOT_HERE ======\n"
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef map<int,int> mii;
typedef map<long long,long long> mll;
typedef set<int> si;
typedef set<long long> sll;

long long n,k;

int main()
{
	cin>>n;
	vector<int> v;
	double sum = 0;
	for(int i=0;i<n;++i)
	{
		int a;
		cin>>a;
		v.emplace_back(a);
		sum+=a;
	}
	sum/=n;
	double diff = 10000;
	int index = -1;
	for(int i=0;i<n;++i)
	{
		if(abs(sum-v[i])<diff)
		{
			index = i;
			diff = abs(sum-v[i]);
		}
	}
	cout << index << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (true) {
			double a = scanner.nextDouble();
			if (a == -1) {
				break;
			}
			double x = a / 2;
			while (Math.abs(x * x * x - a) >= 0.00001 * a) {
				x -= (x * x * x - a) / (3 * x * x);
			}
			System.out.println(x);
		}

	}
}

Measured memory_bytes: 20036
<?php

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $N, $TT);
$t = explode(" ", trim(fgets(STDIN)));

for ($i = 0; $i < $N - 1; $i++) {
    if ($t[$i + 1] - $t[$i] < $TT) {
        $ans += $t[$i + 1] - $t[$i];
    } else {
        $ans += $TT;
    }
}
$ans += $TT;

echo $ans . PHP_EOL;


Measured memory_bytes: 23028
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

signed main(){
  string s; cin>>s;
  if(s[0]==s[1]){
    cout<<1<<" "<<2<<en;
    RE;
  }
  for(int i=2; i<s.size(); i++){
    if(s[i-1]==s[i]){
      cout<<i-1<<" "<<i+1<<en;
      RE;
    }else if(s[i-2]==s[i]){
      cout<<i-1<<" "<<i+1<<en;
      RE;
    }
  }
  cout<<-1<<" "<<-1<<en;
}



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

int main() {

  string A, B;
  cin >> A >> B;

  if (A.size() < B.size()) {
    string a = "";
    for (int i = 0; i < B.size() - A.size(); i++) {
      a += "0";
    }
    a += A;
    A = a;
  } else if (A.size() != B.size()) {
    string b = "";
    for (int i = 0; i < A.size() - B.size(); i++) {
      b += "0";
    }
    b += B;
    B = b;
  }

  if (B < A) {
    cout << "GREATER" << endl;
  } else if (A == B) {
    cout << "EQUAL" << endl;
  } else {
    cout << "LESS" << endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include<vector>
#include <sstream>
#include <stdio.h>
#include <valarray>
#include <iomanip>
using namespace std;
vector<int> Data;

int main(void)
{
	int n, m;
	cin >> n >> m;
	Data.resize(n);

	int Sum = 0;

	for (auto& Target : Data)
	{
		cin >> Target;
		Sum += Target;
	}

	float Border = (float)Sum / (4 * m);

	int OkData = 0;
	for (auto& Target : Data)
	{
		if (Target >= Border)
		{
			OkData++;
			if (OkData >= m)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}


	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <functional>
#include <bitset>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using string_view = boost::string_ref;

#include <boost/function_output_iterator.hpp>


using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    F f;
    bool operator() (const T& t1, const T& t2)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};
 
template<size_t N, class T>
auto make_less_n(const T&)
{
    using t = typename T::value_type;
    using less = std::less<typename tuple_element<N, t>::type>;
    return compare_n<t, N, less>();
}


static const vector<int64_t> nL = [](){
    vector<int64_t> v = {1};
    while(v.size() <= 50)
    {
        v.push_back(2 * v.back() + 3);
    }
    return v;
}();

static const vector<int64_t> nP = [](){
    vector<int64_t> v = {1};
    while(v.size() <= 50)
    {
        v.push_back(2 * v.back() + 1);
    }
    return v;
}();

int64_t f(int64_t n, int64_t x)
{
    if(x <= n)
        return 0;
    
    if(n == 0)
        return 1;
    
    if(x >= nL[n] - n)
        return nP[n];

    return f(n-1, x-1) + f(0, (x-1)-nL[n-1]) + f(n-1, (x-1-nL[n-1])-1);
}

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int64_t n, x;
    cin >> n >> x;
    
    cout << f(n, x) << '\n';
    
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void fast() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
// #define endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

void solve() {
    string s;
    cin >> s;
    string t;
    cin >> t;
    bool n = 1;
    for(int x=0; x< s.length(); x++){
		if(s[x] != t[x]){
			n = 0;
		}
	}
	if(n == 1 && t.length()-s.length() == 1){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}

signed main() {
    
    fast();
    int t = 1;
    while (t--) {
        solve();
    }
    
    
}


Measured memory_bytes: 3652
package main

import (
	"fmt"
	"strconv"
)

var N int

func main() {
	fmt.Scan(&N)
	fmt.Println(dfs(0))
}
func dfs(s int) int {
	var r int
	if s > N {
		return 0
	}
	f3, f5, f7 := false, false, false
	for _, v := range strconv.Itoa(s) {
		switch string(v) {
		case "3":
			f3 = true
		case "5":
			f5 = true
		case "7":
			f7 = true
		}
	}
	if f3 && f5 && f7 {
		r++
	}

	for _, c := range []int{3, 5, 7} {
		r += dfs(s*10 + c)
	}
	return r
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e17;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = INF;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			string a = to_string(i); string b = to_string(n / i);
			chmin(ans, (int)max(a.size(), b.size()));
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int f[17];
int g[17];

vector <int> calc(int n, int a, int b) {
    int x = a ^ b, c = __builtin_popcount(x), i, j, k;
    vector <int> v;
    
    if (c == 1) {
        v.push_back(0);
        
        for (i = 0; i < n; i++) {
            for (j = 0; j < (1 << i); j++) {
                v[(1 << i) - j - 1] <<= 1;
                v.push_back(v[(1 << i) - j - 1] | 1);
            }
        }
    } else {
        vector <int> w, z;
        
        w = calc(n - 1, 0, 1);
        z = calc(n - 1, 1, (1 << (c - 1)) - 1);
        
        for (i = 0; i < w.size(); i++) v.push_back(w[i]);
        for (i = 0; i < z.size(); i++) v.push_back(z[i] | (1 << (n - 1)));
    }
    
    for (i = 0; i < n; i++) {
        f[i] = (v.back() >> i) & 1;
        g[i] = (x >> i) & 1;
    }
    
    for (i = 0; i < n; i++) {
        if (f[i] == g[i]) continue;
        
        for (j = i + 1; j < n; j++) {
            if (f[i] == g[j] && f[j] == g[i]) break;
        }
        
        for (k = 0; k < v.size(); k++) {
            int p = (v[k] >> i) & 1;
            int q = (v[k] >> j) & 1;
            
            if (p + q == 1) v[k] ^= ((1 << i) | (1 << j));
        }
        
        swap(f[i], f[j]);
    }
    
    for (i = 0; i < v.size(); i++) v[i] ^= a;
    
    return v;
}

int main() {
    int n, a, b, i;
    vector <int> v;
    
    scanf("%d %d %d", &n, &a, &b);
    
    if (__builtin_popcount(a ^ b) % 2 == 0) {
        puts("NO");
        
        return 0;
    }
    
    v = calc(n, a, b);
    
    puts("YES");
    for (i = 0; i < v.size(); i++) {
        if (i > 0) putchar(' ');
        printf("%d", v[i]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 1776
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,K;cin>>N>>K;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  int ans=0;
  
  for(int i=0;i<N;i++){
    if(vec[i]>=(double)K/2){
      ans+=(K-vec[i])*2;
    }
    else{
      ans+=2*vec[i];
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 1000000010

int main(){
    int n,k;
    cin >> n >> k;
    vint H(n);
    rep(i,n) cin >> H[i];
    vint ans(n);
    ans[0] = 0;
    for(int i = 1;i<n;i++){
        int temp = INF;
        if(i < k){
            for(int j = 0;j<i;j++){
                temp = min(temp,ans[j] + abs(H[i] - H[j]));
            }
            ans[i] = temp;
        }
        else{
            for(int j = i-k;j<i;j++){
                temp = min(temp,ans[j] + abs(H[i] - H[j]));
            }
            ans[i] = temp;
        }
    }
  //rep(i,n) cout << ans[i] << endl;
    cout << ans[n-1] << endl;
}

Measured memory_bytes: 1024
using System;

namespace abc157_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] A = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                string[] AStr = Console.ReadLine().Split(" ");
                A[i, 0] = int.Parse(AStr[0]);
                A[i, 1] = int.Parse(AStr[1]);
                A[i, 2] = int.Parse(AStr[2]);
            }

            int NCount = int.Parse(Console.ReadLine());
            bool[,] AAns = new bool[3, 3];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    AAns[i, j] = false;
                }
            }

            for (int i = 0; i < NCount; i++)
            {
                int bN = int.Parse(Console.ReadLine());
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (A[j, k] == bN)
                        {
                            AAns[j, k] = true;
                        }
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (AAns[i, 0] == true && AAns[i, 1] == true && AAns[i, 2] == true)
                {
                    Console.WriteLine("Yes");
                    return;
                }

                if (AAns[0, i] == true && AAns[1, i] == true && AAns[2, i] == true)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            if (AAns[0, 0] == true && AAns[1, 1] == true && AAns[2, 2] == true)
            {
                Console.WriteLine("Yes");
                return;
            }

            if (AAns[0, 2] == true && AAns[1, 1] == true && AAns[2, 0] == true)
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
            return;
        }
    }
}


Measured memory_bytes: 27480
#include<bits/stdc++.h>
#define f(x) (x)*(x)
using namespace std;
int n;
int a[1001];
int cnt;
int ans;
int tt=0x7fffffff;
int main()
{
    cin>>n;
    int mi=tt,ma=-tt;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        cnt+=a[i];
        if(a[i]<mi)mi=a[i];
        if(a[i]>ma)ma=a[i];
    }
    int t=cnt/n;
    for(int k=mi;k<=ma;k++)
    {
        ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=f(a[i]-k);
        }
        if(ans<tt)tt=ans;
    }
    cout<<tt<<endl;
    return 0;
}

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

int main() {
  string S; cin >> S;
  ll K; cin >> K;
  ll c = 0;
  while (S[c] == '1') ++c;
  int ans = (c < K) * c;
  cout << S[ans] << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	int k = read.to!int;
	
	if(n % 2 == k % 2) ((n + k) / 2).writeln;
	else "IMPOSSIBLE".writeln;
}


Measured memory_bytes: 256
//============================================================================
// Name        : f
// Date        : Wed Feb 20 10:59:11 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define fora(e, c) for (auto &e : c)
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define ford(i, a, b) for (int i = a; i > b; --i)
#define output(v) cout << (v) << '\n'
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define pvi(x, v) if(v) pvar(x); fora(a, x) cout << a << " "; cout << "\n"
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"

#ifndef __has_trace
#define trace(...)
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template <class T>
void amax(T& a, T b) {
    a = max(a, b);
}

void solve() {
    string ss, tt;
    cin >> ss >> tt;

    int a = sz(ss), b = sz(tt);
    using pip = pair<int, pii>;
    vector<vector<pip>> dp(a + 1, vector<pip>(b + 1, {0, {0, 0}}));
    fori (i, 0, a) {
        fori (j, 0, b) {
            amax(dp[i+1][j+1], {dp[i][j].first + (ss[i] == tt[j] ? 1 : 0), {i, j}});
            amax(dp[i+1][j], {dp[i][j].first, {i, j}});
            amax(dp[i][j+1], {dp[i][j].first, {i, j}});
        }
    }

    pip mx = {0, {0, 0}};
    fori (i, 0, a + 1) {
        fori (j, 0, b + 1) {
            amax(mx, {dp[i][j].first, {i, j}});
        }
    }

    pii cur = mx.second;
    string ret;
    while (mx.first && !(cur.first == 0 || cur.second == 0)) {
        int i = cur.first, j = cur.second;
        pii pre = dp[i][j].second;
        if (pre == pii(i - 1, j - 1)) {
            if (ss[i - 1] == tt[j - 1]) {
                ret = ss[i - 1] + ret;
            }
        }
        cur = pre;
    }
    output(ret);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 108032
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

void A_500_Yen_Coins(void) {

	int K, X;
	cin >> K >> X;
	cout << ((500 * K >= X) ? "Yes" : "No") << flush;
	return;
}

int main(void) {

	A_500_Yen_Coins();
	return 0;
}


Measured memory_bytes: 256
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())
for i in range(10**5):
    if is_prime(x+i):
        print(x+i)
        break



Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    int x, n; cin >> x >> n;
    vi p(n); rep(i, n) cin >> p[i];

    rep(i, x + 1) {
        for (int s: {-1, 1}) {
            int ans = x + s * i;
            if (count(all(p), ans) == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3612
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 1
ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += c[i] * c[j] * c[k]
            # print('i:{}, j:{}, k:{}, ci:{}, cj:{}, ck:{}, ci*cj*ck:{}'
            #       .format(i, j, k, c[i], c[j], c[k], c[i] * c[j] * c[k]))

print(ans)


Measured memory_bytes: 3060
def change_str(str)
    current_chr = str[0]
    continue_count = 1
    new_string = ""
    (1..str.length).each do |index|
        break if index >= str.length
        if current_chr != str[index]
            new_string += continue_count.to_s + current_chr
            continue_count = 1
            current_chr = str[index]
            else
            continue_count += 1
        end
    end
    new_string += continue_count.to_s + current_chr
    new_string
end

while str = gets do
    num = str.chomp.to_i
    break if num == 0
    str = gets.chomp
    num.times do |n|
        str = change_str(str)
    end
    puts str
end

Measured memory_bytes: 92824
class Array
  def cumgcd;
    res = self[0];
    map{|t| res = t.gcd(res) }
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)

cg  = a.cumgcd
cgr = a.reverse.cumgcd.reverse

ans = cg[-2]
ans = cgr[1] if ans < cgr[1]

(n-2).times do |i|
  t = cg[i].gcd(cgr[i+2])
  ans = t if ans < t
end

p ans

Measured memory_bytes: 13316
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int A, P;
    cin >> A;
    cin >> P;

    cout << (A * 3 + P) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
const int INF=1e9;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,x;
    cin >> n >> m >> x;
    VI C(n);
    vector<VI>  A(n, VI(m));
    REP(i,n) {
        cin >> C[i];
        REP(j,m) {
            cin >> A[i][j];
        }
    }
    int ans=INF;
    REP1(mask, 1, 1<<n) {
        int res=0;
        VI v(m);
        REP(i,n) {
            if ( mask>>i&1 ){
                res+=C[i];
                REP(j,m) {
                    v[j]+=A[i][j];
                }
            }
        }
        bool ok=true;
        REP(j,m) {
            if ( v[j]<x ) {
                ok=false;
                break;
            }
        }
        if ( ok ) {
            chmin(ans,res);
        }
    }
    if ( ans<INF ) {
        cout << ans << '\n';
    }
    else {
        cout << -1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256