akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "4", "2 5 4 6" ].solve == 5 );
	assert( [ "9", "0 0 0 0 0 0 0 0 0" ].solve == 45 );
	assert( [ "19", "885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1" ].solve == 37 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto ans = 0L;
	for( auto l = 0L, r = 0L, t = 0L; l < as.length; l++ )
	{
		for( ; r < as.length && ( t ^ as[ r ] ) == t + as[ r ]; r++ )
		{
			t ^= as[ r ];
		}
		t ^= as[ l ];
		ans += r - l;
	}
	return ans;
}


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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  int d = 0;
  for (int i = 1; ; i++) {
    d = (d+x)%360;
    if (!d) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static class Vertex implements Comparable <Vertex> {
		int id, d0;
		Vertex(int vertex, int d0){
			this.id = vertex;
			this.d0 = d0;
		}
		public boolean equals(Object v) {
			return this.id == ((Vertex)v).id;
		}
		public int compareTo(Vertex v) {
			return this.d0 - v.d0;
		}
	}
	
	final static int inf = 100000000;
	public static void main(String args[]){
		try(Scanner sc=new Scanner(System.in)){
			int n = sc.nextInt();  //頂点数
			int[] d = new int[n];  //始点からの距離
			Arrays.fill(d, inf);
			d[0] = 0;
			int[][] length=new int[n][n];//各頂点ごとの距離
			for(int i=0; i<n; i++) {
				int u=sc.nextInt();
				int k=sc.nextInt();
				for(int j=0; j<k; j++){
					int v=sc.nextInt();
					int c=sc.nextInt();
					length[u][v]=c;
				}
			}
			PriorityQueue<Vertex> pq = new PriorityQueue<Vertex>();
			Vertex[] vs = new Vertex[n];
			for(int i=0; i<n; i++) {
				vs[i] = new Vertex(i, d[i]);
				pq.add(vs[i]);
			}
			Map<Integer, Integer> prev=new HashMap<>();
			prev.put(0, 0);
			while(!pq.isEmpty()) { 
				Vertex u = pq.poll();
				prev.put(u.id, u.d0);
				for(Vertex v: vs) {
					int alt =  d[u.id]+length[u.id][v.id]; 
					if(length[u.id][v.id] > 0 && d[v.id] > alt) {
						pq.remove(v);//！ここで要素を削除したいです
						d[v.id] = alt;
						pq.add(new Vertex(v.id, alt));
					}
				}
			}
			for(int i=0; i<n; i++) {
				System.out.println(i + " " + prev.get(i));
			}
		}
	}
} 



Measured memory_bytes: 40232
import sys

group = [[1,3,5,7,8,10,12], [4,6,9,11]]

xy = list(map(int, input().split()))
x = xy[0]
y = xy[1]

if x == 2 or y == 2:
    print("No")
    sys.exit(0)
else:
    for g in group:
        if x in g and y in g:
            print("Yes")
            sys.exit(0)
    print("No")

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

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

int w,h,n,sx,sy,gx,gy,d;
bool G[202][202];

void initG(){
  fill(G[0],G[202],false);
  for(int i=0;i<2*h+1;i++) G[i][0] = G[i][2*w] = true;
  for(int i=0;i<2*w+1;i++) G[0][i] = G[2*h][i] = true;
}

void displayG(int x, int y){
    for(int i=0;i<2*h+1;i++){
      for(int j=0;j<2*w+1;j++){
	if(i == y && x == j) cout << '*' << ' ';
	else cout << G[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
}

void solve(){
  int x = sx, y = sy, ans = 1;
  bool f[202][202][4];

  if(sx == gx && sy == gy){
    cout << 1 << endl;
    return;
  }


  for(int i=0;i<202;i++) for(int j=0;j<202;j++) for(int k=0;k<4;k++) f[i][j][k] = false;
  f[x][y][d] = true;

  while(1){
    bool f2 = false;
    for(int i=-1;i<=2;i++){
      int nd = (d + i + 4) % 4;
      int nx = x + dx[nd];
      int ny = y + dy[nd];

      if(G[ny][nx]) continue;

      nx += dx[nd];
      ny += dy[nd];
      if(f[nx][ny][nd]) break;

      x = nx;
      y = ny;
      d = nd;
      ans++;
      f[x][y][nd] = true;
      f2 = true;

      //displayG(x,y);

      if(x == gx && y == gy){
	cout << ans << endl;
	return;
      }

      break;
    }
    if(!f2) break;
  }
  cout << "Impossible" << endl;
}

int main(){
  int x1,y1,x2,y2;
  while(cin >> w >> h >> n && (w|h|n)){
    initG();

    for(int i=0;i<n;i++){
      cin >> x1 >> y1 >> x2 >> y2;
      if(x1 > x2) swap(x1,x2);
      if(y1 > y2) swap(y1,y2);
      if(x1 == x2) for(int j=2*y1;j<=2*y2;j++) G[j][2*x1] = true;
      if(y1 == y2) for(int j=2*x1;j<=2*x2;j++) G[2*y1][j] = true;
      //displayG();
    }

    cin >> x1 >> y1 >> x2 >> y2 >> gx >> gy;
    if(x1 > x2) swap(x1,x2);
    if(y1 > y2) swap(y1,y2);
    sx = x1 * 2 + 1;
    sy = y1 * 2 + 1;
    if(x1 == x2){
      if(x1 == 0) d = 1;
      else{
	d = 3;
	sx -= 2;
      }
    } else {
      if(y1 == 0) d = 0;
      else {
	d = 2;
	sy -= 2;
      }
    }

    gx = gx * 2 + 1;
    gy = gy * 2 + 1;
    //cout << sx << ' ' << sy << ' ' << d << endl;
    solve();
  }
}

Measured memory_bytes: 1360
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
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 (a > b) { a = b; return 1; } return 0; }


const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

//istream& operator>>(istream& is, const mint& a){return is >> a.x;}
//ostream& operator<<(ostream& os, const mint& a){return os << a.x;}

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> x(n);
	rep(i,n) cin >> x[i];
	mint ans = 0, cnt = 0;
	for(int i = 1; i < n; ++i){
		cnt += mint(i).inv();
		ans += cnt * (x[i] - x[i-1]);
	}
	for(int i = 1; i < n; ++i) ans *= i;
	cout << ans.x << endl;
	return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
 #include<vector>
 #include<math.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 // #include<chrono>
 using namespace std;
 // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define int         long long 
 #define vii        vector<int>
 #define big        1e18


  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}


void solve()
{
  
  int n;
  cin >> n ;
  int a[n];
  
  int rs=1,pr=1,bl=0;
  double ref=1;
  

  forf(i,0,n) 
  {
    cin >> a[i];
    if(a[i]==0) bl=1;
    ref *= a[i];
    rs *=a[i];
  }


  if(bl)
  {
    cout<<"0\n";
    return;
  }
  
  if(ref > (int)1e18 || rs > (int)1e18){
    cout<<"-1\n";
    return;
  }
  


  cout<<rs<<endl;
  
  

}

int32_t main()
{
  pr_init();
  fastio;
  
  
  solve();
  
 }


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    int a;
    cin >> a;
    if (a % 2 == 0)
    {
        cout << a;
    }
    else
    {
        cout << a * 2;
    }
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n+1);
    b[0] = 0;
    rep(i,0,n){
        cin >> a[i];
        b[i+1] = b[i]+a[i];
    }
    ll sa = 1e17;
    rep(i,0,n+1){
        if(sa > abs(2*b[i]-b[n])) sa = abs(2*b[i]-b[n]);
    }
    cout << sa << endl;


}

Measured memory_bytes: 3456
N = int(input())
h = list(map(int,input().split()))
h = [0] + h
dp = [0]*(N+1)
dp[2] = abs(h[2]-h[1])
for i in range(3,N+1):
  dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    ll n;
    cin>>n;
    vector<ii> v;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(i==0){
            v.push_back({a[i], 0});
        }
        else{
            if(a[i]!=v.back().F){
                v.push_back({a[i], i});
            }
        }
    }

    if(v.size()<=1){
        cout<<1000;
        return 0;
    }

    vector<ll> min_inds;
    vector<ll> max_inds;

    if(v[0].F<v[1].F){
        min_inds.push_back(0);
    }
    else{
        max_inds.push_back(0);
    }
    for (int i = 1; i < v.size(); ++i)
    {
        if((v[i].F<v[i-1].F) && (v[i].F<v[i+1].F)){
            min_inds.push_back(v[i].S);
        }
        else if((v[i].F>v[i-1].F) && (v[i].F>v[i+1].F)){
            max_inds.push_back(v[i].S);
        }
    }
    if(v[n-1].F<v[n-2].F){
        min_inds.push_back(v[v.size()-1].S);
    }
    else{
        max_inds.push_back(v[v.size()-1].S);
    }

    ll ans=1000;
    for (int i = 0; i < min_inds.size(); ++i)
    {
        ll bought_stocks = ans/a[min_inds[i]];
        ll rem_money = ans%a[min_inds[i]];
        auto it = lower_bound(max_inds.begin(), max_inds.end(), min_inds[i]);
        if(it!=max_inds.end()){
            ll sold_money = bought_stocks*a[*it];
            ans=sold_money+rem_money;
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 3664
import sys

readline = sys.stdin.readline

ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int((n+1)**0.5)+1):
        if is_prime[i]:
            for j in range(i *2, n + 1, i):
                is_prime[j] = False
    res = [i for i in range(n+1) if is_prime[i]]
    return res

def make_modinv_list(n, mod=10**9+7):
    inv_list = [0]*(n+1)
    inv_list[1] = 1
    for i in range(2, n+1):
        inv_list[i] = (mod - mod//i * inv_list[mod%i] % mod)
    return inv_list

def solve():
  mod = 998244353
  n = ni()
  a = nl()
  m = max(a)
  s = -sum(a) % mod
  l = [0]*(m+1)
  for x in a:
    l[x] += x
  a = make_modinv_list(m, mod)
  pr = primes(m) 
  for i in pr:
    for j in range(m//i, 0, -1):
      l[j] += l[j*i]
  for i in range(m+1):
    l[i] = l[i] * l[i] % mod
  for i in pr:
    for j in range(1, m//i + 1):
      l[j] = (l[j] - l[j*i]) % mod
  for i in range(1, m+1):
    if l[i]:
      s = (s + l[i] * a[i]) % mod
  print(s * a[2] % mod)
  return

solve()


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

int main(){
    int i,j;
    int N,M;
    cin>>N>>M;
    
    vector<int> X(M);
    vector<int> sa(M-1);
    
    int sum=0;
    
    for(i=0;i<M;i++){
        cin>>X.at(i);
    }
    
    sort(X.begin(),X.end());
    
    for(i=0;i<M-1;i++){
        sa.at(i)=X.at(i+1)-X.at(i);
    }
    
    sort(sa.begin(),sa.end());
    
    for(i=0;i<=(M-1)-N;i++){
        sum+=sa.at(i);
    }
    
    cout<<sum<<endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
ll form[314514], lat[314514];
signed main(){
	ll n;
	cin>>n;
	vector<ll> a;
	a.pb(0);
	for(ll i=0;i<3*n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	priority_queue<ll, vector<ll>, greater<ll> > que;
	for(ll i=1;i<=n;i++){
		que.push( a[i] );
		form[n] += a[i];
	}
	for(ll i=n+1;i<=2*n;i++){
		form[i] = form[i-1];
		que.push( a[i] );
		form[i] += a[i];
		form[i] -= que.top();
		que.pop();
	}
	priority_queue<ll> que2;
	for(ll i=3*n;i>=2*n+1;i--){
		que2.push(a[i]);
		lat[2*n+1] += a[i];
	}
	for(ll i=2*n;i>=n+1;i--){
		lat[i] = lat[i+1];
		que2.push(a[i]);
		lat[i] += a[i];
		lat[i] -= que2.top();
		que2.pop();
	}
	ll ans = -LINF;
	for(ll i=n;i<=2*n;i++){
		ll tmp = form[i] - lat[i+1];
		//cout<<i<<" "<<form[i]<<" "<<lat[i+1]<<endl;
		if(ans<tmp)ans=tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9580
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main() {
long long int a,b,k,flag=0,i;
cin>>a>>b;
if(a<b){
for(i=a;i<=b;i++)
{
    if(abs(a-i)==abs(b-i))
   { k=i;
   flag=1;
    break;}
}
}
else
{
    for(i=b;i<=a;i++)
{
    if(abs(a-i)==abs(b-i))
   { k=i;
   flag=1;
    break;}
}
}
if(flag==1)
cout<<k;
else
cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 256
import java.util.Scanner;


class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);

    while(true){
      int N = sc.nextInt();

      if(N == 0){
	break;
      }

      int top = 1;
      int north = 5;
      int south = 2;
      int east = 3;
      int west = 4;
      int bottom = 6;
      
      int S = 1;

      for(int i = 0; i < N; i++){
	String op = sc.next();
	
	if("North".equals(op)){
	  int old = top;
	  top = south;
	  south = bottom;
	  bottom = north;
	  north = old;
	}else if("South".equals(op)){
	  int old = top;
	  top = north;
	  north = bottom;
	  bottom = south;
	  south = old;
	}else if("East".equals(op)){
	  int old = top;
	  top = west;
	  west = bottom;
	  bottom = east;
	  east = old;
	}else if("West".equals(op)){
	  int old = top;
	  top = east;
	  east = bottom;
	  bottom = west;
	  west = old;
	}else if("Right".equals(op)){
	  int old = south;
	  south = east;
	  east = north;
	  north = west;
	  west = old;
	}else if("Left".equals(op)){
	  int old = south;
	  south = west;
	  west = north;
	  north = east;
	  east = old;
	}

	S += top;
      }

      System.out.println(S);
    } 
  }
}

Measured memory_bytes: 12000
import bisect
n = int(input())
nums = [int(input()) for _ in range(n)]

LIS = [nums[0]]

for num in nums:
    if LIS[-1] < num:
        LIS.append(num)
    else:
        LIS[bisect.bisect_left(LIS, num)] = num

print(len(LIS))



Measured memory_bytes: 10356
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	A, B, C := nextInt(), nextInt(), nextInt()

	ans := C - (A - B)

	if ans <= 0 {
		fmt.Println(0)
	} else {
		fmt.Println(ans)
	}
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int a, b, h;
    cin >> a >> b >> h;

    cout << (a+b)*h/2 << endl;
    return 0;
}


Measured memory_bytes: 3548
from itertools import accumulate, islice
from bisect import bisect_left

n = int(input())
xs = [int(x) for x in input().split()]
ys = list(accumulate(xs))
zs, total = ys[:-1], ys[-1]

rs = range(2, n-2)
v = []
for i, z in islice(enumerate(zs), 1, n-1):
    j = bisect_left(zs, z//2)
    splits = ((zs[j+k], z - zs[j+k]) for k in (-1, 0, 1) if 0 <= j+k <= i)
    a, b = min(splits, key=lambda s:abs(s[0]-s[1]))

    j = bisect_left(zs, (total - z)//2 + z)
    splits = ((zs[j+k] - z, total - zs[j+k]) for k in (-1, 0, 1) if i <= j+k <= n-2)
    c, d = min(splits, key=lambda s:abs(s[0]-s[1]))

    minn, _, _, maxx = sorted((a,b,c,d))
    v.append(maxx - minn)

print(min(v) if v else max(xs) - min(xs))

Measured memory_bytes: 29676
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    while(n-1000>=0)
        n-=1000;
    if(n>0)
    cout<<1000-n;
    else cout<<0;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3600
import bisect


n, k = map(int, input().split())
xs = list(map(int, input().split()))
index = bisect.bisect_right(xs, -1)

a = xs[:index][::-1]
cost = 0
if index < len(xs) and xs[index] == 0:
    cost += 1
    b = xs[index + 1:]
else:
    b = xs[index:]

cost_a = [0]
cost_b = [0]
for c in a:
    cost_a.append(abs(c))
for c in b:
    cost_b.append(c)

ret = float('inf')
if len(a) >= k - cost:
    ret = min(ret, cost_a[k - cost])
if len(b) >= k - cost:
    ret = min(ret, cost_b[k - cost])

for i in range(len(cost_a)):
    if 0 <= k - i < len(cost_b):
        ret = min(ret, 2 * cost_a[i] + cost_b[k - i])

for i in range(len(cost_b)):
    if 0 <= k - i < len(cost_a):
        ret = min(ret, 2 * cost_b[i] + cost_a[k - i])
print(ret)


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

	vi d(n);
	rep(i, 0, n) cin >> d[i];

	sort(all(d));

	int ans = d[n/2]-d[n/2-1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, b) for( int i = 0; i < b; i++ )
#define repi(i, a, b) for( int i = a; i < b; i++ )
typedef pair<int, int> P;
typedef vector<int> vec;

int main(){
    int x, y, z;
    while( cin >> x >> y >> z, x ){
        vec v(x);               // ルーレットの目
        rep(i, x){
            cin >> v[i];
        }
        vector<P> e(y, P(0,0));      // イベントマス
        rep(i, z){
            int n, E, a;
            cin >> n >> E >> a;
            e[n] = P(E,a);
        }
        vector<vector<double> > dp(y+1, vector<double>(5000,0));    // dp[i][j] はiマス目でj円所持している確率
        dp[0][0] = 1;
        rep(i, y){
            rep(j, 5000){
                rep(k, x){
                    int next = i+v[k];
                    if( next >= y ){  dp[y][j] += dp[i][j]/x; }     // ゴールを超えたとき
                    else if( e[next].first == 1 ){
                        dp[min(y, next+e[next].second)][j] += dp[i][j]/x;
                    }
                    else if( e[next].first == 2 ){
                        dp[next][j+e[next].second] += dp[i][j]/x;
                    }
                    else if( e[next].first == 3 ){
                        dp[next][max(0, j-e[next].second)] += dp[i][j]/x;
                    }else{
                        dp[next][j] += dp[i][j]/x;
                    }
                }
            }
        }
        double ans = 0;
        rep(i, 5000){ ans += dp[y][i] * i; }
        cout << (int)ans << endl;
    }
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	int n,a,b,c;
	cin>>n;
	ll ar[3][n],dp[3][n+1];
	for(int i=0;i<n;i++){
		cin>>ar[0][i]>>ar[1][i]>>ar[2][i];
	}
	dp[0][0]=dp[1][0]=dp[2][0]=0;
	for(int i=1;i<=n;i++){
		dp[0][i]=ar[0][i-1]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=ar[1][i-1]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=ar[2][i-1]+max(dp[0][i-1],dp[1][i-1]);
	}
	cout<<max(dp[0][n],max(dp[1][n],dp[2][n]))<<endl;
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main(){
  int n,a,b;
  cin>>n;
  stack<int>s;
  queue<int>q;
  if(n%2){
    for(int i=0;i<n/2;i++){
      cin>>a>>b;
      s.push(a);
      q.push(b);
    }
    cin>>a;
    s.push(a);
  }
  else{
    for(int i=0;i<n/2;i++){
      cin>>a>>b;
      q.push(a);
      s.push(b);
    }
  }
  while(!s.empty()){cout<<s.top()<<" ";s.pop();}
  while(!q.empty()){cout<<q.front()<<(q.size()==1?"":" ");q.pop();}
  return 0;
}

Measured memory_bytes: 2944
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

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

		String out = Arrays.asList(a, b, c).stream().map(i->String.valueOf(i)).collect(Collectors.joining(" "));
		System.out.println(out);
	}
}


Measured memory_bytes: 26836
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


# MOD = int(1e09) + 7
MOD = 998244353
INF = int(1e15)


def solve():
    MAX = 200010
    fac = [0] * MAX
    finv = [0] * MAX
    inv = [0] * MAX
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    N, M, K = Scanner.map_int()
    ans = 0
    for k in range(K + 1):
        tmp = M * pow(M - 1, N - 1 - k, MOD)
        tmp %= MOD
        cmb = fac[N - 1] * (finv[k] * finv[N - 1 - k] % MOD) % MOD
        tmp *= cmb
        tmp %= MOD
        ans += tmp
        ans %= MOD
    print(ans)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 34124
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();

            string a_a = input1.Substring(0, 1);
            string a_b = input1.Substring(1, 1);
            string a_c = input1.Substring(2, 1);

            string b_a = input2.Substring(0, 1);
            string b_b = input2.Substring(1, 1);
            string b_c = input2.Substring(2, 1);

            int count = 0;

            count = a_a == b_a ? ++count : count;
            count = a_b == b_b ? ++count : count;
            count = a_c == b_c ? ++count : count;

            Console.WriteLine($"{count}");
        }
    }
}


Measured memory_bytes: 13268
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if x ==500*i + 100*j + 50*k:
        cnt +=1
print(cnt)

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

int main(){
    string s;
    cin >> s;
    bool flag = false;
    for(int i=0;i<s.size()-1;++i){
        if(s[i] == 'A' && s[i+1] == 'C')flag = true;
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 768
N,L,T=map(int,input().split())
X=[]
p=0
for i in range(N):
  x,w=map(int,input().split())
  if w==1:
    x+=T
  elif w==2:
    x-=T
  p+=x//L
  X.append(x%L)
X.sort()
p%=N
for i in range(N):
  print(X[(i+p)%N])

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

long long n, W;
long long w[110];
long long v[110];
long long dp[110][100010];
long long INF = 1e9+7;

int main() {
    cin >> n >> W;
    for(int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    int mval = 1000*n;

    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= mval; ++j) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= mval; ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j]+w[i]);
        }
    }

    long long ans = 0;
    for(int i = 0; i <= mval; ++i) {
        if(dp[n][i] <= W) {
            ans = i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int a[N];
int main(){
	int n; scanf("%d", &n); for(int i = 1; i <= n; ++ i)scanf("%d", &a[i]);
	int mx1 = 0, mx2 = 0;
	for(int i = 1; i <= n; ++ i)
		if(a[i] > mx1)mx2 = mx1, mx1 = a[i];
		else if(a[i] > mx2)mx2 = a[i];
	for(int i = 1; i <= n; ++ i)
		if(a[i] != mx1)printf("%d\n", mx1);
		else printf("%d\n", mx2);
	return 0;
}

Measured memory_bytes: 2432
//g++  5.4.0

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll a,b;
    cin>>a>>b;
    if(a<=9&&a>=1&&b<=9&&b>=1)
        cout<<a*b;
    else
        cout<<"-1";
    return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> V(N);
  vector<int> C(N);
  for(int i=0; i<N; i++) cin >> V.at(i);
  for(int i=0; i<N; i++) cin >> C.at(i);

  int ans=0;
  for(int i=0; i<N; i++){
      ans = max(ans, ans+V.at(i)-C.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main() {
    int x,y;
    cin >> x >>y;
    int k,l;
    if((2*x-y)%3==0&&(2*y-x)%3==0&&(2*x-y)>=0&&(2*y-x)>=0){
        k = (2*x-y)/3;
        l = (2*y-x)/3;
        combination c(k+l);
        mint ans = c(k+l,l);
        cout << ans.x << endl;
        return 0;
    } else {
        cout << 0 << endl;
        return 0;
    }
}

Measured memory_bytes: 13796
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin>>N;
	char last;
	bool key=true;
	set<string> ff;
	for(int i=0;i<N;i++)
	{
		string w;
		cin>>w;
		if(key){
			if(i!=0&&last!=w[0])key=false;
			if(ff.find(w)!=ff.end())key=false;
			last=w[w.size()-1];
			ff.insert(w);
		}
	}
	if(key)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

public class Hello
{
    static int BC;
    public const int Height = 5000;

    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            BC = 0;
            var map = new bool[5, Height];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var d = int.Parse(line[0]);
                var p = int.Parse(line[1]);
                BC += p;
                var q = int.Parse(line[2]) - 1;
                if (d == 1) putH(map, p, q);
                else putV(map, p, q);
                var ret = eraseLine(map);
                if (ret.Count() > 0)
                    foreach (var x in ret) down(map, x);
            }
            Console.WriteLine(BC);
        }
    }
    public static void down(bool[,] map, int a)
    {
        for (int i = 0; i < 5; i++)
            for (int j = a; j < Height - 1; j++)
                map[i, j] = map[i, j + 1];
    }
    public static List<int> eraseLine(bool[,] map)
    {
        var ret = new List<int>();
        var nexti = -1;
        for (int i = 0; i < Height; i++)
            if (canErase(map, i))
            {
                nexti = i + 1;
                ret.Add(i);
                map[0, i] = false; map[1, i] = false; map[2, i] = false; map[3, i] = false; map[4, i] = false;
                BC -= 5;
                break;
            }
        if (nexti != -1)
            for (int i = nexti; i <= nexti + 4; i++)
                if (canErase(map, i)) { map[0, i] = false; map[1, i] = false; map[2, i] = false; map[3, i] = false; map[4, i] = false; ret.Add(i); BC -= 5; }
        ret.Reverse();
        return ret;
    }
    public static bool canErase(bool[,] map, int a)
    {
        return map[0, a] && map[1, a] && map[2, a] && map[3, a] && map[4, a];
    }
    public static void putH(bool[,] map, int p, int q)
    {
        var hmax = -1;
        for (int i = q; i < p + q; i++)
            for (int j = Height - 1; j >= 0; j--)
                if (map[i, j]) hmax = Math.Max(hmax, j);
        for (int i = q; i < p + q; i++)
            map[i, hmax + 1] = true;
    }
    public static void putV(bool[,] map, int p, int q)
    {
        var hmax = -1;
        for (int i = Height - 1; i >= 0; i--)
            if (map[q, i]) { hmax = i; break; }
        for (int i = 0; i < p; i++)
            map[q, hmax + 1 + i] = true;
    }
}



Measured memory_bytes: 9532
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for aa in range(a + 1):
    for bb in range(b + 1):
        for cc in range(c + 1):
            if 500 * aa + 100 * bb + 50 * cc == x:
                ans += 1
print(ans)

Measured memory_bytes: 9180
from itertools import combinations


def calc_int(arr):
    ret = 0
    for i in arr:
        ret += 1 << i
    return ret


n, k = map(int, input().split())
subsets = []
for sub in combinations(range(n), k):
    subsets.append((calc_int(sub), sub))
subsets.sort()

for sub in subsets:
    print('{}: {}'.format(sub[0], ' '.join(map(str, sub[1])))) if len(sub[1]) != 0 else print(f'{sub[0]}:')


Measured memory_bytes: 16672
#include <cmath>
#include <iostream>
#include <vector>

struct Point {
  double x;
  double y;
};
auto &
operator >> (
    std::istream & is,
    Point &        p)
{
    return is >> p.x >> p.y;
}
auto
distance (
    const Point & p1,
    const Point & p2)
{
    auto dx = p1.x - p2.x;
    auto dy = p1.y - p2.y;
    return std::hypot(dx, dy);
}
auto
distance (
    const Point &               p0,
    const std::vector<Point> &  ps)
{
    auto answer = 0.0;
    for (const auto & p : ps) {
      auto d = distance(p0, p);
      answer = std::max(answer, d);
    }
    return answer;
    /*
    return std::transform_reduce(
        std::begin(ps), std::end(ps),
        0.0, std::max,
        [&](const auto & p){ return distance(p0, p); }
    );
    */
}
template <typename T>
auto
internal_division (
    T       p1,
    T       p2,
    double  r1,
    double  r2)
{
    return (p1*r2 + p2*r1) / (r1 + r2);
}
template <typename Func>
auto
ternary_search (
    Func        f,
    double      c0,
    double      c3,
    std::size_t loop)
{
    auto division = [](auto p1, auto p2) {
      // [C++20] auto phi = std::numbers::phi;
      auto phi = (1 + std::sqrt(5)) / 2;
      return internal_division(p1, p2, 1.0, phi);
    };

    auto  c1 = division(c0, c3);
    auto  c2 = division(c3, c0);
    auto  v1 = f(c1);
    auto  v2 = f(c2);
    while (loop--) {
      if ( v1 < v2 ) {
        c3 = c2;
        c2 = c1;
        c1 = division(c0, c3);
        v2 = v1;
        v1 = f(c1);
      } else {
        c0 = c1;
        c1 = c2;
        c2 = division(c3, c0);
        v1 = v2;
        v2 = f(c2);
      }
    }
    return f(c0);
}

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

    std::vector<Point> ps(n);
    for (auto & p : ps) {
      std::cin >> p;
    }

    auto search = [](auto f) {
      return ternary_search(f, 0.0, 1000.0, 50);
    };
    auto d = search([&](auto x) {
      return search([&](auto y) {
        return distance(Point{x, y}, ps);
      });
    });
    std::printf("%.10f\n", d);
}


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

#define MAX 100

void Bubble(int *);

int n;//要素数は外部変数

int main(){
  int a[MAX];
  int i,j,k;
  int key,turn=0;

  scanf("%d",&n);//要素数の読取り
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);//要素の読取り
  }
  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      if(a[j]<a[j-1]){
	key=a[j];
	a[j]=a[j-1];
	a[j-1]=key;
	turn++;
      }
    }
  }
  
  for(i=0; i<n; i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",turn);
  return 0;
}




Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int arai = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        arai += a[i];
    }
    int sunuke = 0;
    int ans = 1e10;
    for(int i = 0;i < n - 1;i++){
        sunuke += a[i];
        int tmp = arai - sunuke;
        ans = min(ans, abs(sunuke - tmp));
    }
    cout << ans << endl;
 }

Measured memory_bytes: 1792
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = cin.getIntArray(N);
    let ans = A.reduce((ac, v) => ac + v - 1, 0);    
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0;this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');if(t<1)throw new Error('引数は1以上であること！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  /*
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  */
  string s;
  cin>>s;
  string a="keyence";
  if(a==s){
    cout<<"YES"<<endl;
    return 0;
  }

  for(int i=0;i<s.size();i++){
    for(int j=i+1;j<s.size();j++){
      string S=s;
      S.erase(S.begin()+i,S.begin()+j);
      if(S==a){
        cout<<"YES"<<endl;
        return 0;
      }
    }
  }

  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long H = sc.nextInt();
    long W = sc.nextInt();
    int ans = 0;
    for(int i=0; i<N; i++){
      long tmpH = sc.nextLong();
      long tmpW = sc.nextLong();
      if(tmpH - H >= 0 && tmpW-W >= 0){
        ans++;
      }
    }
    System.out.print(ans);
  }
}
        


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

int main()
{
	string s;
	cin >> s;
	if(s[0]==s[1]&&s[1]==s[2])
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
	
}

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

vector<ll> v(105);

int main(){
  ll n;
  cin >> n;
  
  for(int i=0; i<n; i++)
    cin >> v[i+1];
  
  ll ans = 0;
  for(ll hi = 105; hi >= 0; hi--){
    for(ll idx = 1; idx < n+1; idx++){
      if(v[idx-1] <= hi && hi < v[idx])
        ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a_cnt,p_cnt = [0]*n,[0]*n #正答数、ペナルティ数
for i in range(m):
	p,s = input().split()
	if a_cnt[int(p)-1] == 0: #まだ正答してなかったら
		if s == "AC":
			a_cnt[int(p)-1] = 1
		elif s== "WA": #"WA"
			p_cnt[int(p)-1] += 1
for i in range(n):
	if a_cnt[i] == 0:
		p_cnt[i] = 0
print(sum(a_cnt),sum(p_cnt))

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

using namespace std;

int main(){
    string s; cin >> s;
    int count = 0;
    bool s1 = (s[0] == 'A');
    bool s2 = false;
    bool s3 = true;
    for(int i = 2; i < s.size()-1; ++i){
        if(s[i] == 'C') count++;
    }
    if(count == 1) s2 = true;
    for(int i = 1; i < s.size(); ++i){
        if(s[i] == 'C') continue;
        if(isupper(s[i])) s3 = false;
    }
    cout << (s1 && s2 && s3  ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n;
    cin >> n;
    int x,a=0;
    rep(i,4){
        x = n %10;
        if(x==2)a++;
        n/=10;
    }

    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
///                   _ooOoo_
///                  o8888888o
///                  88" . "88
///                  (| -_- |)
///                  O\  =  /O
///               ____/`---'\____
///             .'  \\|     |//  `.
///            /  \\|||  :  |||//  \
///           /  _||||| -:- |||||-  \
///           |   | \\\  -  /// |   |
///           | \_|  ''\---/''  |   |
///           \  .-\__  `-`  ___/-. /
///         ___`. .'  /--.--\  `. . __
///      ."" '<  `.___\_<|>_/___.'  >'"".
///     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
///     \  \ `-.   \_ __\ /__ _/   .-` /  /
///======`-.____`-.___\_____/___.-`____.-'======
///                   `=---='
///^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
///
///         佛祖保佑       永无BUG
///  本模块已经经过开光处理，绝无可能再产生bug
///
///=============================================
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k)
#define ll long long
int rd()
{
	int num = 0;char c = getchar();bool flag = true;
	while(c < '0'||c > '9') {if(c == '-') flag = false;c = getchar();}
	while(c >= '0' && c <= '9') num = num*10+c-48,c = getchar();
	if(flag) return num;else return -num;
}
int main()
{ 
    int n = rd(),m = rd();
	int M = sqrt(m);
	int ans = 0;
	rep(i,1,M)
		if(m % i == 0)
		{
			if(m/i >= n) ans = max(ans,i);
			if(i >= n){ans = m/i;break;}
		}
	printf("%d\n",ans);
	return 0;
}

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


int main(){
    int in;
    cin >> in;
    int A[4];

    A[3] = in / 1000;
    A[2] = (in - 1000 * A[3]) / 100;
    A[1] = (in - 1000 * A[3] - 100 * A[2]) / 10;
    A[0] = in - 1000 * A[3]- 100 * A[2] - 10 * A[1];

    if(A[3] + A[2] + A[1] + A[0] == 7){
        cout << A[3] << "+" << A[2] << "+" << A[1] << "+" << A[0];
    }else if(A[3] + A[2] + A[1] - A[0] == 7){
        cout << A[3] << "+" << A[2] << "+" << A[1] << "-" << A[0];
    }else if(A[3] + A[2] - A[1] + A[0] == 7){
        cout << A[3] << "+" << A[2] << "-" << A[1] << "+" << A[0];
    }else if(A[3] - A[2] + A[1] + A[0] == 7){
        cout << A[3] << "-" << A[2] << "+" << A[1] << "+" << A[0];
    }else if(A[3] + A[2] - A[1] - A[0] == 7){
        cout << A[3] << "+" << A[2] << "-" << A[1] << "-" << A[0];
    }else if(A[3] - A[2] + A[1] - A[0] == 7){
        cout << A[3] << "-" << A[2] << "+" << A[1] << "-" << A[0];
    }else if(A[3] - A[2] - A[1] - A[0] == 7){
        cout << A[3] << "-" << A[2] << "-" << A[1] << "-" << A[0];
    }else if(A[3] - A[2] - A[1] + A[0] == 7){
        cout << A[3] << "-" << A[2] << "-" << A[1] << "+" << A[0];
    }
    cout << "=7" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
double a,b,n;
double calc(double x){
	return floor(a*x/b) - a*floor(x/b);
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> a >> b >> n;
	cout << calc(min(b-1,n)) << endl;
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3780