akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
    ll n,a,b;cin>>n>>a>>b;
    ll ans = 0;
    if(n%(a+b)==0)
    {
    	cout<<a*(n/(a+b));
    }
    else
    {
    	ans+=(n/(a+b))*(a);
    	if(n%(a+b)>=a)
    	{
    		ans+=a;
    	}
    	else
    		ans+=(n%(a+b));
    	cout<<ans;
    }
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll is_prime(ll x){
	ll num=sqrt(x);
	if(x==2)return 1;
	if(x%2==0)return 0;
	for(int i=3;i<=num;i+=2)if(x%i==0)return 0;
	return 1;
}
int main(){
	ll n;
	cin>>n;
	while(1){
		if(is_prime(n)){
			cout<<n;
			return 0;
		}
		n++;
	}
	return 0;
}


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

int main() {
    double dist, x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    dist = sqrt(pow(fabs(x1 - x2), 2) + pow(fabs(y1 - y2), 2));
    printf("%.15lf\n", dist);
}



Measured memory_bytes: 2104
A,B,C = map(int,input().split())
k = int(input())
ans = 'No'
for m in [(i,j,k-i-j) for i in range(k+1) for j in range(k-i+1)]:
    if A*2**m[0]<B*2**m[1]<C*2**m[2]:
        ans = 'Yes'
        break
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N, Q; cin >> N >> Q;
    pair<int, pair<int, int>> XST[N];
    rep(i, N) {
        cin >> (XST[i].second).first >> (XST[i].second).second >> XST[i].first;
    }
    sort(XST, XST + N);
    int D[Q];
    vector<int>ans(Q, INF);
    rep(i, Q) {
        cin >> D[i];
        D[i] *= -1;
    }
    sort(D, D + Q);
    int next[Q + 1];
    next[Q] = Q;
    rep(i, Q) next[i] = i;
    rep(i, N) {
        int l = (upper_bound(D, D + Q, XST[i].first - (XST[i].second).second) - D);
        int r = (upper_bound(D, D + Q, XST[i].first - (XST[i].second).first) - D) - 1;
        //一度探索した範囲はスルーしてオッケー
        //x[l] = rまでとばしてよし
        for(int j = next[l]; j <= r; ++j) {
            if(ans[j] == INF) ans[j] = XST[i].first;

            next[j] = max(r + 1, next[j]);
        }
    }
    rep(i, Q) {
        if(ans[Q - 1 - i] == INF) cout << -1 << endl;
        else cout << ans[Q - 1 - i] << endl;
    }
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(31, 0);

    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int a;
            cin >> a;
            cnt[a - 1]++;
        }
    }
    
    int ans = 0;
    rep(i, m){
        if(cnt[i] == n) ans++;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int n,W;
    scanf("%d%d", &n,&W);

    vector<int> v(n), w(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d%d", &w[i], &v[i]);
    }

    vector<ll> dp(W+1,-1);
    long j;
    dp[0]=0;
    for(i=0; i<n; i++) {
        for(j=W; j>=0; j--) {
            if(j>=w[i] && dp[j-w[i]]>=0) dp[j]=MAX(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    ll ans=0;
    for(j=0; j<=W; j++) {
        ans = MAX(ans, dp[j]);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1024
import os, sys, re, math

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N,X = map(int,input().split(' '))
cities = list(map(lambda x: abs(int(x) - X),input().split(' ')))
D = cities[0]

for i in range(len(cities)):
    D = gcd(D, cities[i])

print(D)


Measured memory_bytes: 14500
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

a = inputSLs(3)

print(a[0][0]+a[1][1]+a[2][2])


Measured memory_bytes: 63980
// atcoder/abc148/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;
    vector<int> b;
    int x = 1;
    each (i, a) {
      if (x == i) {
        b.push_back(i);
        ++x;
      }
    }
    if (b.empty()) cout << -1 << endl;
    else cout << n - b.size() << endl;
  }

  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define sllf(n) scanf("%lld",&n)
#define pllf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,greater<int> > q;
const int N=2e3+10;
const int mod=1e9+7;
int n,a[N],sum=0;
int main()
{
	sf(n);
	double x=n,y=0.5;
	if(n%2==0)printf("%.10f",y);
	else printf("%.10f",(n/2+1)/x);
	return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){

  int N;  cin >> N;
  int even_count = 0;
  for(int i = 0 ; i < N ; i++){
    int a;  cin >> a;
    if(a % 2 == 0)  even_count += 1;
  }

  if(even_count == N)  cout << "second" << endl;
  else                 cout << "first" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace program{
	long long a,b,c,k;
	inline void work(){
		cin>>a>>b>>c>>k;
		int oo=abs(a-b);
		if(oo>=(1e18)){
			puts("Unfair");
			exit(0);
		}
		if(k&1){
			cout<<b-a;
		}else{
			cout<<a-b;
		}
	}
}
int main(){
	program::work();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
main()
{
	int t;
	scanf("%d",&t);
	cin>>a>>b;
	if(a==b)
	printf("%d",t);
	else
	{
		int co=0,ck=0,mx=0;
		for(int i = 0;i < t;i++)
		{
			ck=0;
			co=0;
			for(int j = 0;j < t && i+j<=t-1;j++)
			{
				if(a[i+j]==b[j])
				co++;
				else
				break;
				if(i+j==t-1)
				ck=1;
			}
			if(ck==1)
			{
				printf("%d",2*t-co);
				return 0;
			}
		}
		printf("%d",2*t);
	}
}
/*
abcd
bcde
edcb
*/

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

int main()
{
  int N;scanf("%d",&N);
  int d[N];
  for(int i=0;i<N;i++)scanf("%d",&d[i]);
  set<int> s;int ans=0;
  for(int i=0;i<N;i++)if(!s.count(d[i])){ans++;s.insert(d[i]);}
  printf("%d\n",ans);
}

Measured memory_bytes: 3688
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define BITCOUNT(mask) ( __builtin_popcount((mask)) )

int f(int n) {
   if (n == 0) return 0;
   return 1 + f(n % BITCOUNT(n));
}

VI powers2(int N, int MOD) {
   VI res(N+1);
   res[0] = 1 % MOD;
   FOR(n, 1, N)
      res[n] = (res[n-1] * 2LL) % MOD;
   return res;
}

VI solve(int N, string S) {
   if (N == 1) {
      if (S[0] == '0')
         return {1};
      else
         return {0};
   }

   int M = 0;
   for (char c : S)
      if (c == '1')
         ++M;

   if (M == 0) {
      return VI(N, 1);
   }
   
   if (M == 1) {
      VI res(N);
      if (S.back() == '1') {
         REP(i, N-1)
            res[i] = 2;
      }
      else {
         REP(i, N-1)
            if (S[i] == '0')
               res[i] = 1;
         res.back() = 2;
      }
      return res;
   }

   DEBUG(M);

   reverse(S.begin(), S.end());

   VI P2_under = powers2(N, M-1);
   VI P2_over  = powers2(N, M+1);

   int x_under = 0, x_over = 0;
   REP(i, N) {
      int d = S[i]-'0';
      if (d == 1) {
         x_under = (x_under + P2_under[i]) % (M-1);
         x_over  = (x_over  + P2_over[i]) % (M+1);
      }
   }
   DEBUG(x_under, x_over);

   VI res(N);

   REP(i, N) {
      if (S[i] == '0') {
         // 0 => 1
         int x = (x_over + P2_over[i]) % (M+1);
         res[i] = 1 + f(x);
      }
      else {
         // 1 => 0
         int x = (x_under - P2_under[i] + M-1) % (M-1);
         res[i] = 1 + f(x);
      }
   }

   reverse(res.begin(), res.end());

   return res;
}

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

   int N;
   cin >> N;
   string S;
   cin >> S;

   VI res = solve(N, S);
   for (int x : res)
      cout << x << '\n';

   return 0;
}


Measured memory_bytes: 5984
#include <iostream>
using namespace std;
int main(void){
  int a, b;
  cin >> a >> b;
  if(a%3 == 0 | b%3 == 0 | (a+b)%3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int main()
{
    speed
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
        cout<<"x";

    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  if(a%3==0){
    cout << "Possible" << endl;
  }
  else if(b%3==0){
    cout << "Possible" << endl;
  }
  else if((a+b)%3==0){
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

double n, m, d;

signed main() {
	cin >> n >> m >> d;
	printf("%.14lf\n", (1+(d!=0))*(m-1)*(n-d)/n/n);
}

Measured memory_bytes: 256
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
anas = [''.join(sorted(input())) for _ in range(n)]
c = Counter(anas)


cnt = 0
for v in c.values():
    if v < 2:
        continue
    else:
        cnt += cmb(v, 2)

print(cnt)


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

#define ALL(c) c.begin(), c.end()
#define SZ(c) ((int)c.size())
#define REP(i, n) for (int i = 0, loop_num_##i = n; i < loop_num_##i; i++)

const int MOD = 1e9 + 7;
int w[202];
signed dp[2][202][10001];

signed main() {
	int N, W;
	cin >> N >> W;
	REP(i, N) cin >> w[i];
	
	dp[0][201][0] = 1;
	REP(i, N) {
		REP(j, 202) {
			REP(k, W + 1) {
				if (k + w[i] <= W) {
					(dp[(i + 1) % 2][j][k + w[i]] += dp[i % 2][j][k]) %= MOD;
				}
				if (j == 201) {
					(dp[(i + 1) % 2][i][k] += dp[i % 2][j][k]) %= MOD;
				} else {
					(dp[(i + 1) % 2][w[j] > w[i] ? i : j][k] += dp[i % 2][j][k]) %= MOD;
				}
				dp[i % 2][j][k] = 0;
			}
		}
	}
	
	int ans = 0;	
	REP(i, 202) {
		int mn = w[i];
		for (int j = (i == 201 ? 0 : W - mn + 1); j <= W; j++) {
			(ans += dp[N % 2][i][j]) %= MOD;
		}
	}
	cout << ans << endl;
}



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

int main(){

    int n,k;

    cin >> n >>k;

    vector<int> x(n);

    rep(i,n){
        cin >> x[i];
    }

    int ans=0;

    rep(i,n){
        if(x[i]<k-x[i]){
            ans+=x[i]*2;
        }else{
            ans+=(k-x[i])*2;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  ll K;
  cin >> S >> K;
  smatch what;
  if (regex_match(S, what, regex("^(1+)([1-9]*)$"))) {
    if (what.length(1) >= K) {
      cout << 1 << endl;
    } else if (what.size() > 2) {
      cout << what.str(2).front() << endl;
    } else {
      assert(false);
    }
  } else {
    cout << S.front() << endl;
  }
  return 0;
}


Measured memory_bytes: 3728
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <string>
#include <iostream>
#include <climits>
using namespace std;

#define int long long
const int INF = LLONG_MAX*0.8;
typedef pair<int, int> PII;

int N;
vector<PII> v;

signed main()
{
	int mi = INF, ma = -INF;
	int rMax = -INF, bMin = INF;
	cin >> N;
	v.resize(N);
	for (int i = 0; i < N; i++)
	{
		cin >> v[i].first >> v[i].second;
		if (v[i].first > v[i].second) swap(v[i].first, v[i].second);
		mi = min(mi, v[i].first);
		ma = max(ma, v[i].second);
		rMax = max(rMax, v[i].first);
		bMin = min(bMin, v[i].second);
	}
	int ans = (rMax - mi)*(ma - bMin);

	int rMin = INF;
	sort(v.begin(), v.end());
	for (int i = 0; i < N - 1; i++)
	{
		rMax = max(rMax, v[i].second);
		rMin = min(rMin, v[i].second);
		ans = min(ans, (rMax - min(rMin, v[i + 1].first))*(ma - mi));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = 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 (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> v(n, INF);
    rep(i, n-1){
        int b;
        cin >> b;
        chmin(v[i], b);
        chmin(v[i+1], b);
    }
    int ans = 0;
    rep(i, n) ans += v[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr long long MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

bool issame(string a, string b) {
    map<int, int> ma;
    map<int, int> mb;
    for(int i = 0; i < a.length(); i++) {
        ma[a[i]]++;
        mb[b[i]]++;
    }
    if(ma == mb) {
        return true;
    } else {

        return false;
    }
}

int main() {
    long long N;
    cin >> N;
    vector<string> s(N);
    REP(i, N) {
        string tmp;
        cin >> tmp;
        sort(ALL(tmp));
        s[i] = tmp;
    }
    map<string, unsigned long long> ms;
    for(int i = 0; i < s.size(); i++) {
        ms[s[i]]++;
    }
    unsigned long long res = 0;
    for(auto x : ms) {
        if(x.second >= 2) {
            res += x.second * (x.second - 1) / 2;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 12032
// F

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  int N,u,v;
  cin>>N>>u>>v;
  u--;
  v--;
  vector <int>G[100000];
  for (int i(0);i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--; 
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> ta(100000,-1),a(100000,-1);
  queue<int> q;
  q.push(u);
  ta[u] = 0;
	while(!q.empty()){
    int now = q.front();
    q.pop();
    for (int i(0);i<G[now].size();i++){
      int next = G[now][i];
      if (ta[next] == -1){
        q.push(next);
        ta[next] = ta[now] + 1;
      }
    }
  }
  //for (int i(0);i<5;i++) cout << ta[i] << " ";
  q.push(v);
  a[v] = 0;
	while(!q.empty()){
    int now = q.front();
    q.pop();
    for (int i(0);i<G[now].size();i++){
      int next = G[now][i];
      if (a[next] == -1){
        q.push(next);
        a[next] = a[now] + 1;
      }
    }
  }
  //for (int i(0);i<5;i++) cout << a[i] << " ";
  int ans(0);
  for (int i(0);i<N;i++){
    if (G[i].size() == 1 && a[i] > ta[i]){
      ans = max(ans,a[i]);
    }
  }
  cout << ans - 1<< endl;
  return 0;
}


Measured memory_bytes: 6656
#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define ll long long
    #define int long long
    #define lb long double
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define take(a,n) f(i,0,n)cin>>a[i];
    #define show(a,n) f(i,0,n){cout<<a[i]<<" ";}
    #define ashow(a)  for(auto i:a)cout<<i<<" ";
    #define khtm     cout<<endl;
    #define all(s) s.begin(),s.end()
    #define len(a) a.length()
    #define INF 1e18
    #define MAXN 2000009
    const double pi=3.14159265358979323;
    const int mod=1e9+7;
    bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
     signed main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);  
        cout.tie(0);  
     // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1;
    // cin>>t;
    while(t--)
    {
      

        int n,k,x=1,y=0;
        int mx=-1,mi=INF,mn=INF;
        int tm=0;
         // char c;
        cin>>n;
        string s="";
        
        k=1;
      while(n){
      	n--;
        char c='a'+(n)%26;
        // if((n%k)%26==0)c='z';
        s+=c;
        n/=26;
        // k*=26;
        // n/=26;
      }
      
      reverse(s.begin(),s.end());
      cout<<s<<endl;
}

 }

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <cstring>
//#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define de(x,y) cout<<#x<<" :"<<x<<y;
#define int long long
#define SZ(xx) ((int)xx.size())
#define lowbit(xx) (xx&(-xx))
#define pb push_back
typedef pair<int,int> pii;

const int maxn = 4e5+5;
const int mod = 1e9 + 7;

int dp[1005][1005];
char c[1005][1005];

main() {
	IOS
	int n, m;
	cin >> n >> m;
//	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> c[i][j];
			if (c[i][j] == '#') dp[i][j] = 0;
			else dp[i][j] = dp[i-1][j] + dp[i][j-1];
			dp[i][j] %= mod;
			if (i == 1 && j == 1) dp[1][1] = 1;
		}
	} 
	cout << dp[n][m] << "\n";
}


Measured memory_bytes: 12412
n = int(input())
ans = 0
for i in range(1, n+1):
	fix = 0
	L = int(str(i)[0])
	R = int(str(i)[-1])
	if L * R == 0:
		continue
	if L == R:
		fix += 1
	cur = 10
	dig = R*cur + L
	while dig <= n:
		fix += min(cur, max(0, n-dig+10)) // 10
		cur *= 10
		dig = R*cur + L
	ans += fix
	# print(i, fix)
print(ans)

Measured memory_bytes: 41708
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}





///////////////////////////


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

	ll dp[101][4][4][4][4] = {};

	dp[0][3][3][3][3] = 1;

	repn(i, N) {
		rep(a, 4)rep(b, 4)rep(c, 4)rep(d, 4) {
			rep(e, 4) {
				dp[i][a][b][c][d] += dp[i - 1][e][a][b][c]; 
				dp[i][a][b][c][d] %= MOD;
			}
		}

		rep(a, 4) {
			dp[i][a][0][2][1] = 0;
			dp[i][0][a][2][1] = 0;
			dp[i][0][2][a][1] = 0;
			dp[i][a][2][0][1] = 0;
			dp[i][a][0][1][2] = 0;

		}

	}

	ll ans = 0;

	rep(a, 4)rep(b, 4)rep(c, 4)rep(d, 4) {
		ans += dp[N][a][b][c][d];
		ans %= MOD;
	}

	cout << ans;

	

	system("PAUSE");

}


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

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

    if ( S[S.size()-1] != 's' ) {
        S.push_back('s');
    } else {
        S.push_back('e');
        S.push_back('s');
    }

    cout << S << endl;

    return 0;
}

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

using namespace std;
const int N = 100000 + 5;
const int INF = 0x3f3f3f3f;

int a[N];
vector<int> v;
//using P = pair<int,int>;
//using LL = long long;

void Init(){
    for(int i = 0; i < N; i++)
        a[i] = 0;
}

int main(){
    int a, b;
    cin >> a >> b;
    if(b >= a)
        cout << a << endl;
    else
        cout << a - 1 << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> ad(n);
  rep(i,n){
    int a,b,c;
    cin >> a >> b >> c;
    int ans=0;
    ans+=195*(a-1);
    ans+=5*((a-1)/3);
    if(a%3==0){
      ans+=20*(b-1)+c-1;
    }
    else{
      ans+=20*(b-1)-((b-1)/2);
      ans+=c-1;
    }
    ad[i]=196470-ans;
  }
  rep(i,n){
    cout << ad[i] << endl;
  }
  return 0;
}



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

 using namespace std;

 int main() {
 int M, D; cin >> M >> D;
 int ans = 0;
 for (int m = 1; m <= M; ++m) {
 for (int d = 10; d <= D; ++d) {
 int d_1 = d % 10, d_10 = d / 10;
 if (d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m) {
 ++ans;
 }
 }
 }
 cout << ans << endl;
 }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()


int gcd(int x, int y){
    if (x > y)
        return gcd(y, x);
    
    int m = 1;
    while(m != 0){
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}

int main(){
    int n; cin>>n;
    int a[100001]; rep(i,n) cin>>a[i];
    int g = a[0];
    repn(i,n-1) g = gcd(g, a[i]);
    cout<<g<<endl;
}

Measured memory_bytes: 1144
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

int main()
{
	ll d, g;
	cin >> d >> g;

	vector<pair<ll, ll>> p(d);
	for (int i = 0; i < d; i++)
	{
		ll a, b;
		cin >> a >> b;

		p.at(i).first = a;
		p.at(i).second = b;
	}

	ll res = inf;


	for (int bit = 0; bit < (1 << d); bit++)
	{
		ull s = 0;
		ll cnt = 0;
		for (int i = 0; i < d; i++)
		{
			if (bit & (1 << i))
			{
				cnt += p.at(i).first;
				s += 100 * (i + 1) * p.at(i).first + p.at(i).second;
			}
		}

		if (s >= g)
		{
			res = min(res, cnt);
		}
		else
		{
			for (int i = d - 1; i >= 0; i--)
			{
				if (bit & (1 << i))
				{
					continue;
				}
				else
				{
					for (int j = 0; j < p.at(i).first; j++)
					{
						if (s >= g)
						{
							break;
						}
						s += 100 * (i + 1);
						cnt++;
					}
				}
			}
			res = min(res, cnt);
		}
	}

	cout << res << endl;
}

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

int top;
int S[1000];

void push(int x) {
  top++;
  S[top] = x;
}

int pop() {
  return S[top--];
}

int main() {
  top = 0;
  string str[210];
  int i = 0;
  while (cin >> str[i]) {
    int a, b;
    if (str[i] == "+") {
      b = pop();
      a = pop();
      push(a + b);
    } else if (str[i] == "-") {
      b = pop();
      a = pop();
      push(a - b);
    } else if (str[i] == "*") {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      int x = atoi(str[i].c_str());
      push(x);
    }
    i++;
  }

  cout << S[top] << endl;
  
  return 0;
}


Measured memory_bytes: 3152
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int cost = scanner.nextInt();
        int numDigits = scanner.nextInt();
        boolean[] badDigits = new boolean[10];
        
        for (int i=0; i<numDigits; i++) {
            int badDigit = scanner.nextInt();
            badDigits[badDigit] = true;
        }
        
        // we can have possible change of 1 to 100,000
        // In case we can't pay the initial amount with x digits we pad one more digit.
        
        for (int change=cost; change<100000; change++) {
            // give up on change amount if she hates a digit
            int currChange = change;
            while (currChange > 0) {
                int currDigit = currChange % 10;
                if (badDigits[currDigit])
                    break;
                else {
                    currChange /= 10;
                }
            }
            // currChange = 0 OR we had a bad digit
            if (currChange == 0) {
                System.out.println(change);
                break;
            }
            
        }
        scanner.close();
    }
}


Measured memory_bytes: 35884
import itertools
K = int(input())
if K%2 == 0:
  A = range(2,K+1,2)
  B = range(1,K,2)
else:
  A = range(2,K,2)
  B = range(1,K+1,2)
print(len(list(itertools.product(A,B))))

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int N,l1[MAXN],l2[MAXN];
int num[MAXN];char c[MAXN];
int main(){
	scanf("%s",c+1);
	N=strlen(c+1);
	for(int i=1;i<=N;i++)
		if(c[i]=='L'){
			if(c[i-1]=='R')l1[i]=i;
			else l1[i]=l1[i-1];
		}
	for(int i=N;i>=1;i--)
		if(c[i]=='R'){
			if(c[i+1]=='L')l2[i]=i;
			else l2[i]=l2[i+1];
		}
	for(int i=1;i<=N;i++){
		if(c[i]=='L')
			num[l1[i]-(i-l1[i])%2]++;
		if(c[i]=='R')
			num[l2[i]+(l2[i]-i)%2]++;
	}
	for(int i=1;i<N;i++)
		printf("%d ",num[i]);
	printf("%d\n",num[N]);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector
#define inf LONG_MAX
#define gets getline
#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define makestring(x) to_string(x)
#define endl "\n"
#define ss second
#define ff first
#define fast  ios_base::sync_with_stdio(false)
using namespace std;
vl<ll> divisor(ll n)
{
    vl<ll> v;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0) 
        {
            if(n/i==i) v.pb(i);
            else
            {
                v.pb(i);
                v.pb(n/i);
            }
        }
    }
    return v;
}

bool isprime(int n)
{
    int i;
    for(i=2;i*i<=n;i++) if(n%i==0) return 0;
    return 1;
}

vl<ll> sieve()
{
    vl<ll> v(1000001);
    int i,j;
    for(i=0;i<1000001;i++) v[i]=1;
    for(i=2;i<=sqrt(1000001);i++) if(v[i]==1) for(j=i*i;j<=1000000;j+=i) v[j]=0;
    v[1]=0;
    return v;
}

string dectobi(ll n)
{
    string s;
    while(n>0)
    {
        if(n&1) s.pb('1');
        else s.pb('0');
        n>>=1;
    }
    reverse(all(s));
    return s;
}

ll power(ll a, ll b, ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b%2) res=(res*a)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res%m;
}

int main()
{
    fast;
    ll c,d,e,sum=0,flag=0,j=0,i=1,count=0;
    ll x,y,o;
    set<ll> se;
    ll n,m,t,k,l,r;
    string s;
    ld dis,p,a,b;
    cin>>n>>dis;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        p=(a*a)+(b*b);
        p=sqrt(p);
        if(p<=dis) count++;
    }
    cout<<count;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

long long lcm(long long x, long long y) {
	return x / gcd(x, y)*y;
}
int main(void){
	int n;
	cin >> n;
	vector<ll> t(n);
	rep(i, 0, n)cin >> t[i];
	rep(i, 1, n)
		t[i] = lcm(t[i], t[i - 1]);
	cout << t[n - 1] << endl;
	return 0;
}

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

num_idx = [0]*(n+1)

# 自分のidxからみて右側で，自身の値より大きな値をもつ，一番近いidx
right_idx_over_current_pos = list(range(1, n+1)) + [n, n]
# 自分のidxからみて左側で，自身の値より大きな値をもつ，一番近いidx
left_idx_over_current_pos = list(range(-1, n-1)) + [-1, -1]

# 1から見ていくとすると，上記2つとも，自分のすぐ隣のidxがそのまま該当する

for idx, num in enumerate(P):
    num_idx[num] = idx

ans = 0
for num in range(1, n+1):  # 小さいほうから決める
    now = num_idx[num]
    r1 = right_idx_over_current_pos[now]
    r2 = right_idx_over_current_pos[r1]
    l1 = left_idx_over_current_pos[now]
    l2 = left_idx_over_current_pos[l1]

    r_pattern = (r2-r1) * (now-l1)
    l_pattern = (l1-l2) * (r1-now)

    right_idx_over_current_pos[l1] = r1  # l1にある値 > nowからr1までにある値 なので nowをスキップして r1までいける
    left_idx_over_current_pos[r1] = l1  # 上の左向きver
    ans += (r_pattern + l_pattern) * num

print(ans)


Measured memory_bytes: 20180
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<ll> a(n), csum(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if (i == 0) csum[i] = a[i];
        else {
            csum[i] = a[i] + csum[i-1];
        }
    }

    // for (auto elem : csum) cout << elem << " "; cout << endl;

    ll min_diff = inf;
    for (size_t i = 0; i < n-1; i++)
    {
        min_diff = min(min_diff, abs(csum[i] - (csum[n-1] - csum[i])));
    }
    cout << min_diff << endl;
    
    return 0;
}

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

using namespace std;

#define ll long long

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> ab(N), cd(M);
    for(int i=0; i<N; ++i){
        cin >> ab[i].first >> ab[i].second;
    }
    for(int i=0; i<M; ++i){
        cin >> cd[i].first >> cd[i].second;
    }

    for(int i=0; i<N; ++i){
        ll mind = 1e16;
        int mini = 0;
        for(int j=0; j<M; ++j){
            ll dist = abs(ab[i].first - cd[j].first)+abs(ab[i].second - cd[j].second);
            if(dist < mind){
                mind = dist;
                mini = j+1;
            }
        }
        cout << mini << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

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

	int A, B;
	cin >> A >> B;

	cout << (A + 49) / 50 * 2 + (B + 49) / 50 * 2 << " 100\n";

	string w(100, '.'), b(100, '#');
	for (int i = 0; i < 2 * (B - 1); i++) {
		
		if (i % 2) cout << '#';
		else cout << '.';
		if (i % 100 == 99) cout << "\n" << w << "\n";

	}
	for (int i = 0; i < 100 - 2 * (B - 1) % 100; i++) {
		cout << '.';
	}

	cout << "\n" << w << "\n" << b << "\n";

	for (int i = 0; i < 2 * (A - 1); i++) {

		if (i % 2) cout << '.';
		else cout << '#';
		if (i % 100 == 99) cout << "\n" << b << "\n";
	}
	for (int i = 0; i < 100 - 2 * (A - 1) % 100; i++) {
		cout << '#';
	}
	cout << "\n";

	return 0;
}

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

using namespace std;

int main(){
	
	long long int n, ans;
	
	int a[20000];
	
	cin >> n;
	
	while(n != 0){
		
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		sort(a, a + n);
		
		ans = 0;
		
		for(int i = 0; i < n; i++){
			ans += a[i] * (n - i - 1);
		}
		
		printf("%lld\n", ans);
		
		cin >> n;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

typedef long long ll;
const ll INF = 1000000000000000;

int main(){
  int w,h,n;
  scanf("%d%d%d",&w,&h,&n);
  int x[n],y[n],sx[n],sy[n];
  for(int i=0;i<n;i++){
    scanf("%d%d",x+i,y+i);
    sx[i] = x[i], sy[i] = y[i];
  }
  sort(sx,sx+n);
  sort(sy,sy+n);
  int xx[] = {sx[(n-1)/2],sx[(n-1)/2],sx[(n-1)/2+1],sx[(n-1)/2+1]};
  int yy[] = {sy[(n-1)/2],sy[(n-1)/2+1],sy[(n-1)/2],sy[(n-1)/2+1]};
  ll ans = INF;
  int xxx,yyy;
  for(int jugontyan=0;jugontyan<4;jugontyan++){
    int dekai = 0;
    ll t = 0;
    int px = xx[jugontyan], py = yy[jugontyan];
    for(int i=0;i<n;i++){
      if(dekai<abs(x[i]-px)+abs(y[i]-py)) dekai = abs(x[i]-px) + abs(y[i]-py);
      t += abs(x[i]-px) + abs(y[i]-py);
    }
    t = t * 2 - dekai;
    if(ans>t){
      ans = t;
      xxx = px, yyy = py;
    }
  }
  printf("%lld\n%d %d\n",ans,xxx,yyy);
  return 0;
}

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

int  main() {
  long long a,b;
  cin>>a>>b;
  if(0<a&&a<b) {
    cout<<"Positive"<<endl;
  }
  else if(a<0&&0<b) {
    cout<<"Zero"<<endl;
  }
  else if(a<0&&b<0) {
    if((b-a+1)%2==1) {
      cout<<"Negative"<<endl;
    }
    else if((b-a+1)%2==0) {
      cout<<"Positive"<<endl;
    }
  }
}

Measured memory_bytes: 256
n,a,b,k=map(int,input().split())
mod=998244353
s=0
fac=[1]*(n+1)
rev=[1]*(n+1)

for i in range(1,n+1):
  fac[i]=i*fac[i-1]%mod
  rev[i]=pow(fac[i],mod-2,mod)

f=lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

for i in range(n+1):
  j,r=divmod((k-a*i),b)
  if r==0 and 0<=j<=n:
    s+=(f(n,i)*f(n,j))%mod

print(s%mod)


Measured memory_bytes: 26976
#include <iostream>
#include <cstring>

using namespace std;

std::string str;

int main()
{
    cin >> str;
    int lg = str.length();
    if(lg == 2)
        cout << str;
    else{
        for (std::string::reverse_iterator rit = str.rbegin(); rit != str.rend(); ++rit)
            std::cout << *rit;
    }
    return 0;
}


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


int main(){
	long long n,k;
	cin>>n>>k;
	
	long long A[n];
	long long F[n];
	
	for (int i=0; i<n; i++) cin>>A[i];
	for (int i=0; i<n; i++) cin>>F[i];
	
	sort(A,A+n);
	sort(F,F+n);
	
	long long l=0;
	long long r=1000000000010;
	long long res=-1;
	
	while(l<=r){
		long long mid=(l+r)/2;
		
		long long cont=0;
		int t=n-1;
		
		for (int i=0; i<n; i++){
			long long maximo=mid/F[i];
			
			cont+=max(A[t]-maximo,1LL*0);
			
			t--;
		}
		
		if (cont<=k){
			res=mid;
			r=mid-1;
		}
		
		else l=mid+1;
	
	}
	
	cout<<res<<endl;

}


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

int main()
{
	int n, a, b, br1=0, br2=0;
	cin >> n >> a >> b;
	int ar[99999];
	for(int i=0; i<a; i++){
		cin >> ar[i];
		if(ar[i]<b){
			br1++;
		}
		if(ar[i]>b){
			br2++;
		}
	}

	if(br1< br2) cout << br1 << endl;
	else cout << br2 <<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s; cin>>s;
  map<int,int> mp; mp[0]=1;
  int n=s.size(),t=1,m=0;
  while(n--){
    m+=(int)(s[n]-'0')*t;
    if(m>2018) m%=2019;
    t*=10;
    if(t>2018) t%=2019;
    ++mp[m];
  }
  n=mp.size();
  int res=0;
  for(auto& itr:mp) res+=itr.second*(itr.second-1)/2;
  cout<<res;
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>

using namespace std;

int main() {
    int N, C[500], S[500], F[500];
    cin >> N;

    for (int i = 0; i < N-1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }

    for (int i = 0; i < N-1; i++) {
        int ans = C[i] + S[i];
        for (int j = i+1; j < N-1; j++) {
            if (S[j] < ans) {
                int n = ((ans - S[j]) % F[j] == 0) ? (ans - S[j]) / F[j] : (ans - S[j]) / F[j] + 1;
                ans = C[j] + S[j] + F[j] * n;
            }
            else {
                ans = C[j] + S[j];
            }
        }
        cout << ans << endl;
    }
    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define mod 1000000007
#define maxn 200005
int n,val[maxn],dp[maxn],la[maxn],pos[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&val[i]);
		la[i]=pos[val[i]],pos[val[i]]=i;
	}
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if(val[i]!=val[i-1]&&la[i]) dp[i]=(dp[i]+dp[la[i]])%mod;
	}
	printf("%d\n",dp[n]);
}

Measured memory_bytes: 3328