akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int hn[5];
	int i,j,fl1=0,fl2=0,fl3=0;
	while(1){
		for(i=0;i<5;i++){
			cin >> hn[i];
			if(hn[i]==1) fl1=1;
			if(hn[i]==2) fl2=1;
			if(hn[i]==3) fl3=1;
		}
		if(hn[0]==0) break;
		if((fl1==1 && fl2==1) && fl3==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "1" << endl;
				if(hn[j]==2) cout << "2" << endl;
			}
		}else if((fl1==1 && fl3==1) && fl2==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "2" << endl;
				if(hn[j]==3) cout << "1" << endl;
			}
		}else if((fl3==1 && fl2==1) && fl1==0){
			for(j=0;j<5;j++){
				if(hn[j]==2) cout << "1" << endl;
				if(hn[j]==3) cout << "2" << endl;
			}
		}else{
			for(j=0;j<5;j++) cout << "3" << endl;
		}
		fl1=0;
		fl2=0;
		fl3=0;
	}
	return 0;
}

Measured memory_bytes: 2960
using System;
using System.Collections.Generic;
class Solve{
    int N;
    int[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        int[] sort = new int[N];
        int[] linka = new int[N];
        int[] linkb = new int[N];
        long count = 0;
        for(int i=0;i < N;i++){
            sort[i] = i;
            linka[i] = i+1;
            linkb[i] = i-1;
        }
        Array.Sort(sort,(c,b) => a[b] - a[c]);
        for(int i=0;i<N;i++){
            int min = linkb[sort[i]];
            int max = linka[sort[i]];
            if(min != -1){
                linka[min] = max;
            }
            if(max != N){
                linkb[max] = min;
            }
            count += (long)(max-sort[i])*(long)(sort[i]-min)*(long)a[sort[i]];
        }
        Console.WriteLine(count);
    }
    void getinput(){
        N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        a = new int[N];
        for(int i=0;i<N;i++){
            a[i] = int.Parse(str[i]);
        }
    }    
}

Measured memory_bytes: 19032
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  cin >> n;

  vector<P> a(n);
  REP(i,n) cin >> a[i].fs >> a[i].sc;
  
  auto comp = [&](P x, P y){return atan2(x.fs,x.sc) < atan2(y.fs,y.sc);};

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

  double ans = 0;
  REP(i,n){
    int x = 0, y = 0;
    REP(j,n){
      int id = (i+j)%n;
      x += a[id].fs; y += a[id].sc;
      ans = max(ans,sqrt(x*x+y*y));
    }
  }

  cout << fixed << setprecision(12) << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;

#define V 10000
#define INF 100000000

typedef pair<int,int> P;

struct edge {
  int to,cap,cost,rev;
  edge(int a,int b,int c,int d){to = a;cap = b,cost = c;rev = d;}
};

int n,m[110],g,a;
int x[110][30],y[110][30],c[110][30];
vector<int> ar[110];

vector<edge> G[V];
int h[V];
int dist[V];
int prevv[V], preve[V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(edge(to,cap,cost,G[to].size()));
  G[to].push_back(edge(from,0,-cost,G[from].size() - 1));
}

int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P ,vector<P>, greater<P> > q;
    fill(dist,dist+V,INF);
    dist[s] = 0;
    q.push(P(0,s));
    while(!q.empty()){
      P p = q.top(); q.pop();
      int v = p.second;
      if(dist[v] < p.first)continue;
      for(int i=0;i<G[v].size();i++){
	edge &e = G[v][i];
	if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
	  dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
	  prevv[e.to] = v;
	  preve[e.to] = i;
	  q.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t] == INF)return -1;

    for(int v=0;v<V;v++)h[v] += dist[v];

    int d = f;
    for(int v=t;v!=s;v = prevv[v]){
      d = min(d,G[prevv[v]][preve[v]].cap);
    }

    f -= d;
    res += d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main(){
  while(scanf("%d",&n) != EOF, n){
    m[0] = 1; ar[0].clear(); ar[0].push_back(0);
    x[0][0] = 0; y[0][0] = 0; c[0][0] = 0;
    for(int i=1;i<n;i++){
      scanf("%d",&m[i]);
      ar[i].clear();
      for(int j=0;j<m[i];j++){
	scanf("%d %d %d",&x[i][j],&y[i][j],&c[i][j]);
	ar[i].push_back(y[i][j]);
      }
      sort(ar[i].begin(),ar[i].end());
      ar[i].erase(unique(ar[i].begin(),ar[i].end()),ar[i].end());
    }
    m[n] = 1; ar[n].clear(); ar[n].push_back(INF);
    x[n][0] = INF; y[n][0] = INF; c[n][0] = 0;
    scanf("%d",&g);
    for(int ans = g;ans>=0;ans--){
      for(int i=0;i<V;i++)G[i].clear();
      for(int i=0;i<n;i++){
        for(int j=0;j<ar[i].size();j++){
    	  for(int k=0;k<m[i+1];k++){
            if(ar[i][j]<=x[i+1][k]){
              for(int l=0;l<ar[i+1].size();l++){
	        if(y[i+1][k] == ar[i+1][l]){
	       	  a = l;
		  break;
	        }
	      }
	      add_edge(i*50 + j*2 + 1, (i+1)*50 + a*2, 1, c[i+1][k]);
	    }
  	  }
        }
        for(int j=0;j<ar[i+1].size();j++){
	  add_edge((i+1)*50 + j*2,(i+1)*50 + j*2 + 1, 1, 0);
        }
      }
    
      int res = min_cost_flow(1,n*50,ans);
      if(0<=res){
        cout << ans << " " << res << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3692
import numpy as np
from numpy.fft import rfft,irfft

p = 200003
N = int(input())
A = list(map(int,input().split()))
a = np.zeros(p-1)

g = 1
d = {}
p2 = [1]*(p-1)
for i in range(p-1):
    d[g] = i
    p2[i] = g
    g *= 2
    g %= p

for i in range(N):
    if A[i]==0:
        continue
    a[d[A[i]]] += 1

b = rfft(a,2*p-2)
b = irfft(b*b,2*p-2)
b = np.rint(b).astype(np.int64)

ans = 0
for i in range(p-1):
    ans += (b[i]+b[i+p-1])*p2[i]

for i in range(N):
    ans -= A[i]**2%p
ans //= 2
print(ans)

Measured memory_bytes: 143312
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535
#define EPS (1e-10)
#define rep(i,n) for (int i = 0; i < (n); ++i)


int main()
{
  ll x, k;
  cin >> x >> k;
  ll a = x % k;
  ll ans = min(a, k - a);
  cout << ans << endl;

}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	for(int i = 1; i <= n; i++){
		int ans = 0;

		for(int x = 1; x <= (int)sqrt(n); x++){
			for(int y = x; y <= (int)sqrt(n); y++){
				if(i <= x * x + y * y + x * y) break;
				
				for(int z = (int)sqrt(n); y <= z; z--){
					if(x * x + y * y + z * z + x * y + y * z + z * x == i){
						// cout << n << " : " << x << " " << y << " " << z << endl;
						if(x == y && y == z && z == x) ans++;
						else if(x == y && y != z && z != x || x != y && y == z && z != x || x != y && y != z && z == x) ans += 3;
						else ans += 6;

						break;
					}
					else if(x * x + y * y + z * z + x * y + y * z + z * x < i){
						break;
					}
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int k = in.nextInt();
		int[] a = getIntArr(in, n);
		long r = solve(n, k, a);
		System.out.println(r);
		in.close();
	}

	private static long solve(int n, int k, int[] a) {
		long[][] dp = new long[n + 1][k + 1];
		long[][] prefixSum = new long[n + 1][k + 1];
		for (int i = 0; i <= n; i++) {
			dp[i][0] = 1;
			prefixSum[i][0] = 1;
		}
		for (int i = 0; i <= k; i++) {
			prefixSum[0][i] = 1;
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= k; j++) {
				dp[i][j] = prefixSum[i - 1][j];
				if (j >= a[i - 1] + 1) {
					dp[i][j] = (dp[i][j] - prefixSum[i - 1][j - a[i - 1] - 1] + mod) % mod;
				}
				prefixSum[i][j] = (prefixSum[i][j - 1] + dp[i][j]) % mod;
			}
		}
		return dp[n][k];
	}

	static long mod = 1000000007;

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 241612
#include <iostream>
using namespace std;
int main(void){
    int n, x, cnt;
    while(cin >> n){
        x = 0;
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                for(int k = 0; k < 10; k++){
                    for(int l = 0; l < 10; l++){
                        if(i + j + k + l == n)  x++;
                    }
                }
            }
        }
        cout << x << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
H, W = map(int, raw_input().split())
N, = map(int, raw_input().split())
A = map(int, raw_input().split())
s = []
for i in range(N):
  s += [str(i+1)]*A[i]
for y in range(H):
  print " ".join(s[W*y:W*(y+1)][::1-((y%2)*2)])

Measured memory_bytes: 3588
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b,c;
    cin >> a >> b >> c;
    c = c%b;
    bool good = false;
    rp(i,b) {
        if(a*i%b == c) good = true;
    }
    if(good) cout << "YES" <<endl;
    else cout << "NO" << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
program base_2Number
    implicit none
    integer(8):: n, ia, i, sgn=1
    character(1), allocatable:: ans(:)

    read*, n
    if (n==0) then
        print*, 0
    end if
    allocate(ans(1))
    ia=0
    do while(abs(n) >= 1)
        ia=ia+1
        call append(ia,mod(n,2))
        n = (n-abs(mod(n,2))*sgn) / 2
        sgn=-1*sgn
    end do

    print*, ans(ia:1:-1)

    contains
    subroutine append(i, num)
        integer(8):: i, num
        character(1), allocatable:: tmp(:)

        if (i > size(ans)) then
            allocate(tmp(size(ans)))
            tmp(:) = ans(:)
            deallocate(ans)
            allocate(ans(size(tmp)*2))
            ans(1:size(tmp)) = tmp(:)
        end if
        ans(i) = char(abs(num)+ichar('1')-1)
    end subroutine
end program base_2Number

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
#define int long long 
int32_t main(){
	int n ;
  	cin >> n ;
  	int ans = 0 ;
	int x ;
  	for(int i = 0 ; i < n ; i++){
    	cin >> x ;
  		ans = __gcd(ans , x) ;
  	}
  	cout << ans << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1e17
#define ninf -1e17
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll n;
ll dp[3005][3005][3];
ll a[3005];
ll compute(ll s, ll e, ll turn)
{
    if(s>e)
    {
        return 0;
    }
    if(dp[s][e][turn]!=ninf) return dp[s][e][turn];
    ll ans;
    if(turn == 0)
    {
        ans = ninf;
        ans = MAX2(ans, a[s] + compute(s+1, e, 1-turn));
        ans = MAX2(ans, a[e] + compute(s, e-1, 1-turn));
    }
    else 
    {
        ans = inf;
        ans = MIN2(ans, -a[s] + compute(s+1, e, 1-turn));
        ans = MIN2(ans, -a[e] + compute(s, e-1, 1-turn));
    }
    return dp[s][e][turn] = ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n;
    int i;
    FOR0(i, n) cin>>a[i];
    int j, k;
    FOR0(i, n+1)FOR0(j, n+1)FOR0(k, 3) dp[i][j][k] = ninf;
    cout<<compute(0, n-1, 0);
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 211840
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a;}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b;}

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

    int n;
    cin >> n;
    ll ans = 1;
    rep(i, n) {
        ll x;
        cin >> x;
        ans = lcm(ans, x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m,x;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>x;
        n-=x;
    }
    if(n<0) cout<<"-1";
    else cout<<n;
	return 0;
}


Measured memory_bytes: 3636
n = input()
k = int(input())
m = len(n)
if k == 1:
    print(int(n[0])+9*(m-1))
elif k == 2:
    if m<2:ans = 0
    else:
        ans = 81*(m-1)*(m-2)//2+(int(n[0])-1)*(m-1)*9
        for i in range(1,m):
            if int(n[i]) != 0:
                ans += (m-i-1)*9+int(n[i])
                break
    print(ans)
else:
    if m<3:ans = 0
    else:
        ans = (m-1)*(m-2)*(m-3)//6*9**3 + (int(n[0])-1)*(m-1)*(m-2)//2*81
        for i in range(1,m):
            if int(n[i])!=0:
                ans += (m-i-1)*(m-i-2)//2*81+(int(n[i])-1)*(m-i-1)*9
                break
        for j in range(i+1,m):
            if int(n[j]) != 0:
                ans += (m-j-1)*9+int(n[j])
                break
    print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int[] a=new int[n];

int i=0;
for(i=0;i<n;i++){
    a[i]=scan.nextInt();
}
  
int sum=0;
for(i=0;i<n;i++){
  if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0){
    sum=sum+1;
  }
}

if(sum==0){     
System.out.println("APPROVED");
}else{
  System.out.println("DENIED");
}
}
}

Measured memory_bytes: 23892
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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! {
        n: usize,
        aa: [usize;n]
    }
    let mut aa = aa;
    aa.sort();
    aa.dedup();
    let m = aa.len();
    println!("{}", if (n - m) % 2 == 0 {m} else {m-1});
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
bool solve(string s)
{
    string t=s;
    reverse(t.begin(),t.end());
    if(s==t) return true;
    else return false;
}
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    string s1=s.substr(0,(n-1)/2),s2=s.substr((n+3)/2-1);
    if(solve(s)==true&&solve(s1)==true&&solve(s2)==true) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
  long long a, b, c, k;
  long long sum = 0;

  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);

  for (long long i = a; i > 0; i--){
    if (k == 0) {
      printf("%lld", sum);
      return 0;
    }
    else{
      sum++;
      k--;
    }
  }

  for (long long i = b; i > 0; i--){
    if (k == 0) {
      printf("%lld", sum);
      return 0;
    } else k--;
  }

  for (long long i = c; i > 0; i--){
    if (k == 0) {
      printf("%lld", sum);
      return 0;
    }
    else{
      sum--;
      k--;
    }
  }
  
  printf("%lld", sum);

  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
using namespace std;
int main(void){
    
    int a, b, s, f, N, ans = 0;

    cin >> a >> b;
    cin >> N;
    
    for(int i = 0; i < N; i++){
        cin >> s >> f;
        if(b > s && f > a) ans = 1;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair

using namespace std;
//map <ll,ll> fc;
ll ans(ll x){
	if(x==1)return 1;
	else return 2ll*ans((x/2ll))+1ll;
}

void run(){
ll n,k;
cin>>n>>k;
vector <ll> v;
for(ll i=0;i<n;i++){
	ll x;cin>>x;
	v.PB(x);
}
sort(v.begin(),v.end());
if(k>=n)cout<<0;
else {
	ll ans=0;
	for(ll i=0;i<n-k;i++){
		ans+=v[i];
	}
	cout<<ans<<endl;
}

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 3444
#include <iostream>

int main() {
    int N, M;
    int s[11][11];
    int k[11];
    int p[11];
    std::cin >> N >> M;
    for (int i = 1; i <= M; ++i) {
        std::cin >> k[i];
        for (int j = 1; j <= k[i]; ++j) {
            std::cin >> s[i][j];
        }
    }
    for (int i = 1; i <= M; ++i) {
        std::cin >> p[i];
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        bool ok = true;
        for (int i = 1; i <= M; ++i) {
            int sum = 0;
            for (int j = 1; j <= k[i]; ++j) {
                if (bit & (1 << (s[i][j] - 1))) {
                    sum += 1;
                }
            }
            if (sum % 2 != p[i]) {
                ok = false;
                continue;
            }
        }
        if (ok) {
            ans += 1;
        }
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n, k, late;
	
	scanf("%d %d", &n, &k);
	
	if(n >= 10){
		late = k;
	}
	else{
		late = k + (100 * (10 - n));
	}
	
	printf("%d", late);
	
	return 0;
}

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

#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 all(a)        a.begin(), a.end()
#define in(c,x)       ((c).find(x) != (c).end())
#define isp(c,x)      (find(all(c),x) != (c).end())
#define pb             push_back
#define ppb            pop_back
#define sz(x)          (int)x.size()
#define fill(a,v)      memset(a, v, sizeof a)
#define fs first
#define sc second
#define ub upper_bound
#define lb lower_bound
#define en '\n'

typedef long long int lli;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair< int, int > pii;
typedef pair< lli, lli > plli;
typedef list<int> li;
typedef map<int, int> mi;
typedef map<lli, lli> mlli;
lli gcd(lli a,lli b){return (!b)?a:gcd(b,a%b);}
//int t = 1; int ti;



const int N = 3e3 + 5;
lli a[N], mem[N][N], n;

lli rec(int l, int r){
    if(l > r)
    return 0;
    
    if(l == r)
    return a[l];

    if(mem[l][r] != -1)
    return mem[l][r];

    lli ans;

    ans = a[r] + min(rec(l, r-2) - a[r-1], rec(l+1, r-1) - a[l]);
    ans = max(ans, a[l] + min(rec(l+1, r-1) - a[r], rec(l+2, r) - a[l+1]));

    return mem[l][r] = ans;
}

void solve(){
    cin>>n;

    fori(i, 1, n)
    cin>>a[i];

    fill(mem, -1);

    cout<<rec(1, n);    
}
//THINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL

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

    // cin>>t;

    // for(ti= 1; ti <= t; ti++)
    solve();

//    cout<<"\nTHINK OF SPECIAL CASES, ARRAY LIMITS, LLI vs INT, 1LL";
}

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main(){
    int N;
    cin >> N;
    vi a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vb rem(a[N-1]+1,true);
    for(int i=0;i<N;i++){
        int j=2;
        while(a[i]*j<=a[N-1]){
            //if(!rem[a[i]*j]) break;
            rem[a[i]*j]=false;
            j++;
        }
        if(i!=0){
            if(a[i]==a[i-1])
                rem[a[i]] = false;
        }
    }

    int count=0;
    for(int i=0;i<N;i++){
        if(rem[a[i]]){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    vector<int> p(n);
    ll i,j;
    ll iti=0,ni=0,san=0;
    for(i=0;i<n;i++){
        cin >> p.at(i);
        if(p.at(i)<=a)iti++;
        else if(p.at(i)<=b)ni++;
        else san++;
    }
    cout << min({iti,ni,san}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int tv[1000006][30];
int rec[1000006];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int C; cin >> C;
  FOR(i,0,N) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    tv[s*10][c]++;
    tv[t*10][c]--;
  }
  FOR(i,0,1000005) {
    FOR(j,0,C) {
      if(tv[i][j] > 0) {
        rec[max(0, i - 5)]++;
      } else if(tv[i][j] < 0) {
        rec[i]--;
      } 
    }
  }
  int ans = rec[0];
  FOR(i,0,1000005) {
    rec[i+1] += rec[i];
    ans = max(ans, rec[i+1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 121344
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector <long long> vec(n,0);
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    int cnt_0=0,cnt_2=0,cnt_4=0;
    for(int i=0;i<n;i++){
        if(vec.at(i)%4==0){
            cnt_4+=1;        //4の倍数の個数
        }
        else if(vec.at(i)%2==0){
            cnt_2+=1;        //2の倍数の個数
        }
        else{
            cnt_0+=1;        //その他
        }
    }
    if(cnt_2<=1){       //2の倍数が1個以下なら、その2の倍数は「その他」と同然の扱いになる（2の倍数同士で4の倍数を生成できないため）。
        if (vec.size()/2<=cnt_4){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    else if((vec.size()-cnt_2)%2==0 && (vec.size()-cnt_2)/2<=cnt_4){
        cout << "Yes" << endl;
    }
    else if((vec.size()-cnt_2)%2==1 && (vec.size()-cnt_2)/2+1<=cnt_4){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }




    return 0;
}

Measured memory_bytes: 1024
/*
	* ernestvw
	* C++
	* May 2020
*/

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

#define int long long

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define veci vector<int>
#define vecs vector<string>
#define amax(x, v) x = max(x, (v))
#define amin(x, v) x = min(x, (v))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define nl '\n'

using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

const int oo = 1e9; // INT_MAX
const long long OO = 1e18; // LLONG_MAX
const double eps = 1e-9;
const int p197 = 1000000007;
const int p998 = 998244353;
const int p103 = 1000003;

#define TEST_CASES 0

void solve(int test_case);

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int T = 1;
	if(TEST_CASES) cin >> T;
	for(int t = 1; t <= T; t++)
		solve(t);

	return 0;
}

// ---------------------------------------------------

struct T {
	int a, b, c, d;
};

int n, m, q;
veci a, b, c, d;

vector<veci> dp;

int best = 0;
vector<int> cur;

void f(int i, int v) {
	if(i == n) {
		int sc = 0;
		for(int j = 0; j < q; j++) if(cur[b[j]-1] - cur[a[j]-1] == c[j]) sc += d[j];
		amax(best, sc);
		return;
	}
	for(int V = v; V <= m; V++) {
		cur[i] = V;
		f(i+1, V);
	}
}

void solve(int test_case) {
	cin>>n>>m>>q;
	a.resize(q),b.resize(q),c.resize(q),d.resize(q);
	for(int i = 0; i < q; i++) {
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	cur.resize(n);
	f(0, 1);
	cout << best << endl;
}



















































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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main(){
  ll n, m, a, b;
  cin >> n >> m;
  vecll city(n);
  forll(i, 0, m){
	cin >> a >> b;
	city[a-1] += 1;
	city[b-1] += 1;
  }
  forll(i, 0, n)
	cout << city[i] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a,b,c,i,j;
j=0;
scanf("%d %d %d",&a,&b,&c);
for(i=a;i<=b;i++){
   if((c%i)==0){
      j++;
   }
}
printf("%d\n",j);
return 0;
}      

Measured memory_bytes: 596
#include"bits/stdc++.h"
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int64_t i,j,k,l;//preparation for
int main(){
    int a[5];
    for(i=0;i<5;i++){
        cin>>a[i];
    }
    int p;

    for(i=0;i<5;i++){
        if(a[i]==0){
            p=i+1;
        }
    }

    cout<<p;
    return 0;
}

Measured memory_bytes: 3620
from operator import itemgetter
N,K = map(int,input().split())
c = [list(map(int,input().split())) for i in range(N)]
c.sort(key=itemgetter(0))
s = 0
for i in range(N):
    if s+c[i][1] < K:
        s += c[i][1]
    else:
        ans = c[i][0]
        break
print(ans)


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

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    int B[M];
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        int tmp=0;
        for(int j=0;j<M;j++){
            int A;
            cin >> A;
            tmp+=B[j]*A;
        }
        if(tmp+C>0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
F = sorted(list(map(int, input().split())))


def binary_search(min_n, max_n):

    while max_n - min_n != 1:
        tn = (min_n + max_n) // 2
        if judge(tn):
            max_n = tn
        else:
            min_n = tn

    return max_n


def judge(tn):

    k = 0
    for i in range(N):
        if A[i] * F[i] > tn:
            k += A[i] - (tn // F[i])
        if k > K:
            return False

    return True


def solve():

    ans = binary_search(-1, 10**12)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 114816
N = int(input())
x = [int(input()) for i in range(N)]
cnt = 1
num = x[0]
if num != 2:
    cnt = 2
    for i in range(N):
        num = x[num-1]

        if(num == 2):
            break
        cnt += 1
if cnt == N + 2:
    cnt = -1
print(cnt)

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

using namespace std;
typedef long long ll;

int main() {
    string s, t;
    cin >> s >> t;
    int res = 1e6;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int cur = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i + j] != t[j]) cur++;
        }
        res = min(res, cur);
    }
    cout << res << "\n";
}


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
    int a,b,d,e,f;
    scanf("%d%d",&a,&b);
    d = a-b;
    e = a*b;
    f = a+b;
    if (d>=e && d>=f)
        printf("%d",d);
    else if(e>=d && e>=f)
        printf("%d",e);
    else if (f>=d && f>=e)
        printf("%d",f);
    else if (a==0 && b==0)
        printf("%d",a);
        return 0;
}



Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  if(a+2*k-1<=b){
    for(int i=0;i<k;i++)
      cout<<a+i<<endl;
    for(int i=0;i<k;i++)
      cout<<b-k+1+i<<endl;
  }else
    for(int i=a;i<=b;i++)
      cout<<i<<endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3];
    rep(i, 3) cin >> A[i];
    int K; cin >> K;
    sort(A, A + 3, greater<int>());
    int cnt = pow(2, K) + 0.5;
    cout << A[0] * cnt + A[1] + A[2] << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a;
string s[12];
void dfs(int y,int x){
  s[y][x]='0';
  if(y+1<12&&s[y+1][x]=='1')dfs(y+1,x);
  if(y-1>=0&&s[y-1][x]=='1')dfs(y-1,x);
  if(x+1<12&&s[y][x+1]=='1')dfs(y,x+1);
  if(x-1>=0&&s[y][x-1]=='1')dfs(y,x-1);
}
int main(){
  while(cin>>s[0]){
    a=0;
  r(i,11)cin>>s[i+1];
  r(i,12)r(j,12)if(s[i][j]=='1'){dfs(i,j);a++;}
  cout<<a<<endl;
    }
}

Measured memory_bytes: 3088
#include <iostream>

using namespace std;

typedef long long   ll;
typedef long double ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(ll X) {
  // TODO: edit here
  if (400 <= X && X <= 599 ) return 8;
  if (600 <= X && X <= 799 ) return 7;
  if (800 <= X && X <= 999 ) return 6;
  if (1000 <= X && X <= 1199 ) return 5;
  if (1200 <= X && X <= 1399 ) return 4;
  if (1400 <= X && X <= 1599 ) return 3;
  if (1600 <= X && X <= 1799 ) return 2;
  if (1800 <= X && X <= 1999 ) return 1;
  return 0;
}

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

  ll X;
  cin >> X;

  auto ans = solve(X);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.StringTokenizer;

public class Main  implements Runnable {
	int[][] ta = new int[16][4096];
	int ptr = 0;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 64 * 1024 * 1024).start();
    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
    	//int[] ar = new int[3];
    	//ar[0]=Integer.parseInt(sc.next());
    	//Arrays.parallelSort(ar);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		//long a = Long.parseLong(sc.next());
		//String s = sc.next();
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//ArrayList<Str_4> lists = new ArrayList<Str_4>();
		//lists = new ArrayList;
		PrintWriter out = new PrintWriter(System.out);
		//int[] ra = new int[r];
		//ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
		if(a%2 == b%2)
		{
			out.println((a+b)/2);
		}
		else
		{
			out.println("IMPOSSIBLE");
		}
		
		out.flush();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }
}

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

int main(){
  int N, K, x, X;
  X = 0;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    cin >> x;
    if(x < K - x){
      X += x * 2;
    }else{
      X += (K - x) * 2;
    }
  }
  cout << X << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    int count=0;
    for (long long i=1; i<=N; ++i)
    {
        for (long long j=1; j*i<N; ++j)
        {
            count++;
        }
    }
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int n , p;
  string S;
  cin >> n >> p >> S;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    s[i] = S[i] - '0';
  }
  ll c = 0;
  
  if (p == 2) {
    for (int i = n-1; i >= 0; i--) {
      if (s[i] % 2 == 0) {
        c += (i + 1);
      }
    }
  }
  else if (p == 5) {
    for (int i = n-1; i >= 0; i--) {
      if (s[i] % 5 == 0) {
        c += (i + 1);
      }
    }
  }
  
  
  else{
  vector<ll> k(p);
  vector<ll> a(n+1, 0);
  k[0]++;
  ll p10 = 1;
  for (int i = n-1; i >= 0; i--) {
    a[i] = (p10 * s[i] + a[i+1]) % p;
    p10 *= 10;
    p10 %= p;
    k[a[i]]++;
  }
  for (int i = 0; i < p; i++) {
    if (k[i] > 1) {
      c += (k[i] * (k[i] - 1) / 2);
    }
  }
  
  }
  printf("%lld\n", c);
} 



Measured memory_bytes: 2948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
inline int read()
{
    int X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
    if(flag) return X;
    return ~(X-1);
}
 
int n;
ll res;

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();

	for(int i=1;i<=n;++i){
		int cnt=n/i;
		if(n%i==0) cnt--;
		res+=cnt;
	}

	printf("%lld\n",res);

    return 0;
}

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

typedef long long LL;

const int N=100000,INF=(1<<30)-1;

int n;
struct seg{
  int l,r;
}a[N+9];

bool cmp(const seg &a,const seg &b){return a.r<b.r||a.r==b.r&&a.l<b.l;}

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	int x,l;
	scanf("%d%d",&x,&l);
	a[i].l=x-l;a[i].r=x+l;
  }
}

int ans;

void Get_ans(){
  sort(a+1,a+n+1,cmp);
  int now=-INF;
  for (int i=1;i<=n;++i)
	if (now<=a[i].l) now=a[i].r,++ans;
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4600
#include<stdio.h>
int main(void)
{
	int L,A,B,C,D;
	int count;
	int count1;

	count=0;
	count1=0;
	
	scanf("%d %d %d %d %d",&L,&A,&B,&C,&D);
		while(0<A){
			A-=C;
			count++;
		}
		while(0<B){	
			B-=D;
			count1++;
		}
				if(count>count1){
					printf("%d\n",L-count);
				}
				else if(count=count1){
					printf("%d\n",L-count);
				}
				else{
					printf("%d\n",L-count1);
				}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    int L = (int)s.size();
    
    int locA = 0;
    int locZ = 0;
    for (int i = 0; i < L; i++) {
        if(s[i] == 'A') {
            locA = i;
            break;
        }
    }
    
    for (int i = 0; i < L; i++) {
        if(s[L-1-i] == 'Z') {
            locZ = L-1-i;
            break;
        }
    }
    
    cout << locZ - locA + 1 << endl;
    
    
    
    
}



Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define inf 100000000000000000LL
#define fast_io	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;
ll dp[100+1][100000+1];
ll S[100+1][100000+1];
ll n,k;
int main()
{
	cin>>n>>k;
	
	ll A[n+1];
	
	for(ll i=1;i<=n;i++)
	cin>>A[i];
	
//	memset(dp,0,sizeof(dp));
	
	
	S[1][0]=dp[1][0]=1;	
	
	for(ll j=1;j<=k;j++)	
	{
		if(j<=A[1])
		dp[1][j]=1;
		S[1][j]=(S[1][j-1]%mod+dp[1][j]%mod)%mod;
		
//		cout<<S[0][j]<<" ";
	}
//	cout<<"\n\n";
	for(ll i=2;i<=n;i++)
	{
		S[i][0]=dp[i-1][0];
		dp[i][0]=dp[i-1][0];
		for(ll j=1;j<=k;j++)
		{

			
			dp[i][j]=(S[i-1][j]%mod-((j-A[i]-1>=0)?S[i-1][j-A[i]-1]:0LL)%mod+mod)%mod;

			S[i][j]=(S[i][j-1]%mod+dp[i][j]%mod)%mod;
//			cout<<dp[i][j]<<" ";
		}
//		cout<<endl;
	}
	cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 159812