akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True

ans=0

n,m=LI()
a=LI()

t=sum(a)
ans=n-t
if ans<0:
    ans=-1
print(ans)






Measured memory_bytes: 78160
#include<bits/stdc++.h>
class x{public:long f,s;};x P[1<<17];long c[1<<17],n,i,w=1e9;main(){for(std::cin>>n;i<n;P[i].s=i++)std::cin>>P[i].f;std::sort(P,P+n,[](x p,x q){return p.f-q.f?p.f<q.f:p.s>q.s;});for(;i--;)c[w=w>P[i].s?P[i].s:w]+=(n-i)*(P[i].f-P[i-1].f);for(;++i<n;)std::cout<<c[i]<<"\n";}

Measured memory_bytes: 3456
def nCr(n, r, mod):
    x, y = 1, 1
    for i in range(1, r+1):
        x = x*(n+1-i)%mod
        y = y*i%mod
    return x*pow(y, mod-2, mod)%mod
a,b = map(int,input().split())
s=2*a-b
t=2*b-a
if s%3!=0 or s<0 or t%3!=0 or t<0:
  print(0)
else:
  print(nCr((s+t)//3,(t//3),10**9+7))

Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 1e9 + 7;
using namespace std;

int main() {

	string s; cin >> s;

	if (s == "Sunny")cout << "Cloudy";
	else if (s == "Cloudy")cout << "Rainy";
	if (s == "Rainy")cout << "Sunny";


	return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	ll N, K;
	cin >> N >> K;
	int A[200000], F[200000];
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> F[i];
	sort(A, A + N);
	sort(F, F + N);
	reverse(F, F + N);


	ll L = -1, R = 1e18;
	while (L + 1 < R) {
		ll M = (L + R) / 2;

		ll kazu = 0;
		rep(i, N) {
			if ((ll)A[i] * F[i] > M) {
				kazu += ((ll)A[i] * F[i] - M + F[i] - 1) / F[i];
			}
		}
		if (kazu <= K) R = M;
		else L = M;
	}

	co(R);


	Would you please return 0;
}

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

int main(){
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    int max=h>w?h:w;
    if(n%max==0)
    printf("%d",n/max);
    else
        printf("%d",n/max+1);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif

#define p std::pair
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
void stat();
constexpr ll mod = 1000000000 + 7;

int main()
{
    ll x, a, b;
    cin >> x >> a >> b;
    if (b > a + x ) { cout << "dangerous" << endl; }
    else if ( a+ x>=b && b > a)
    {
        cout << "safe" << endl;
    }else{
	    cout<<"delicious"<<endl;
    }
    return 0;
}
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat()
{
#ifdef local
    rep(i, 2) { std::cout << "local enable" << std::endl; }
#endif
#ifdef hacks
    rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compare(const void *a, const void *b){//qsort引数用の比較関数(-1,0,1のいずれかを返すものに限る)
	return (strcmp((char *)a, (char *)b));//aのほうが辞書的に小さいとき負、大きいとき正、等しいとき0を返す
}

int main(){
	int N,i,count=0;
	char s[200001][11];

	scanf("%d", &N);

	for(i=0; i<N; i++){
		scanf("%s", s[i]);
	}

	qsort(s, N, sizeof(*s), compare);//ソートしたい配列・要素数・要素の単位サイズ・比較用関数

	for(i=0; i<N; i++){
		if(strcmp(s[i], s[i+1])!=0) count++;
	}

	printf("%d", count);
	return 0;

}


Measured memory_bytes: 5696
#include <stdio.h>

int main(void) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        
        int start = a > c ? a : c;
        int end   = b < d ? b : d;
        int ans = end - start;

        if (ans > 0) {
                printf("%d\n", ans);
        } else {
                puts("0");
        }

        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
const int N=7;
int dic[N],w;
string s;
int e=0,n=0;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  FOR(i,1,7){
  	cin>>dic[i];
  }
  cin>>s;
  FOR(i,0,s.size()){
  	if(s[i]=='E'){
  		w=dic[1];
  		dic[1]=dic[4];
  		dic[4]=dic[6];
  		dic[6]=dic[3];
  		dic[3]=w;
  	}else if(s[i]=='W'){
  		w=dic[1];
  		dic[1]=dic[3];
  		dic[3]=dic[6];
  		dic[6]=dic[4];
  		dic[4]=w;
  	}else if(s[i]=='N'){
  		w=dic[1];
  		dic[1]=dic[2];
  		dic[2]=dic[6];
  		dic[6]=dic[5];
  		dic[5]=w;
  	}else{
  		w=dic[1];
  		dic[1]=dic[5];
  		dic[5]=dic[6];
  		dic[6]=dic[2];
  		dic[2]=w;
  	}
  }
  cout<<dic[1]<<endl;
  return 0;
}



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

int main() {
    int n;
    while(cin >> n) {
        vector<int> res;
        for(int i=0; i<10; ++i) {
            if(n & (1 << i)) {
                res.push_back(1 << i);
            }
        }
        for(int i=0; i<res.size(); ++i) {
            cout << res[i] << " \n"[i == res.size()-1] << flush;
        }
    }
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

typedef vector<vector<int>> Graph;

Graph G;
unordered_map<int, unordered_map<int, int>> edgeColor;

void dfs(int node, int color) {
    int c = 1;
    edgeColor[node] = unordered_map<int, int>();
    for (int to: G[node]) {
        if (c == color) c++;
        edgeColor[node][to] = c;
        dfs(to, c);
        c++;
    }
}

void Main()
{
    ll n;
    cin >> n;

    vector<ll> a(n - 1), b(n - 1);
    rep(i, n - 1) cin >> a[i] >> b[i];
    
    G.assign(n, vector<int>());
    rep(i, n - 1) {
        G[a[i] - 1].push_back(b[i] - 1);
    }

    dfs(0, -1);

    int res = 1;
    rep(i, n - 1) {
        res = max(res, edgeColor[a[i] - 1][b[i] - 1]);
    }
    put(res);
    rep(i, n - 1) {
        put(edgeColor[a[i] - 1][b[i] - 1]);
    }

}
signed main(){ Main();return 0;}

Measured memory_bytes: 26044
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI 3.1415926535897932384
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s,t,x;
	cin>>s>>t;
	for(int i=0;i<t.size()-1;i++) x+=t[i];
	if(s==x) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3596
N=int(input())
A=[]
for i in range(N):
  x,y=map(int, input().split())
  A.append((x,y))

def c(P1, P2, P3):
    x1, y1 = P1; x2, y2 = P2; x3, y3 = P3
    a = 2*(x1 - x2); b = 2*(y1 - y2); p = x1**2 - x2**2 + y1**2 - y2**2
    c = 2*(x1 - x3); d = 2*(y1 - y3); q = x1**2 - x3**2 + y1**2 - y3**2
    det = a*d - b*c
    x = d*p - b*q; y = a*q - c*p
    if det < 0:
        x = -x; y = -y; det = -det
    if det!=0:
      x /= det; y /= det
    r = ((x - x1)**2 + (y - y1)**2)**.5
    return x,y,r
ans=20000
for i in range(N-1):
  for j in range(i+1,N):
    f=0
    x1,y1=A[i][0],A[i][1]
    x2,y2=A[j][0],A[j][1]
    x,y=(x1+x2)/2,(y1+y2)/2
    r=((x1-x)**2+(y1-y)**2)**0.5
    for a,b in A:
      d=((a-x)**2+(b-y)**2)**0.5
      if d>r:
        f=1
        break
    if f==0:
      ans=min(ans,r)


if N>2:
  for i in range(N-2):
    for j in range(i,N-1):
      for k in range(j,N):
        f=0
        x,y,r=c(A[i],A[j],A[k])
        for a,b in A:
          d=((a-x)**2+(b-y)**2)**0.5
          if d>r:
            f=1
            break
        if f==0:
          ans=min(ans,r)
print(ans)


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

using namespace std;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  for (int i = 0; i + 1 < n; i++) {
    int c = 'z' - s[i];
    c++;
    if (c <= k && c != 26) {
      k -= c;
      s[i] = 'a';
    }
  }

  if (0 < k) {
    int c = 'z' - s.back();
    c++;
    if (c <= k) {
      k -= c;
      s.back() = 'a';
      if (0 < k) {
        k %= 26;
        s.back() = (char)('a' + k);
      }
    } else {
      s.back() = (char)(s.back() + k);
    }
  }
  cout << s << endl;

  return 0;
}

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

using namespace std;

typedef signed long long ll;
typedef long double ld;

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

#define __INT_MAX__ 2147483647

#define DEBUG

int main()
{
	string str;
	cin >> str;
	if(str == "Sunny") cout << "Cloudy" << endl;
	if(str == "Cloudy") cout << "Rainy" << endl;
	if(str == "Rainy") cout << "Sunny" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define INF 1000000000
#define MOD 100000007

int n, k, ans;
int s, e, mid;

int possible(){
  int dap = mid;
  for(int i=1; i<n; i+=k-1)
    dap--;
  return dap >= 0;
}
int main(){
    scanf("%d%d", &n, &k);

    s = 1; e = n;
    while (s<=e){
      mid = (s+e)/2;
      if ( possible() ){
        ans = mid;
        e = mid - 1;
      }
      else 
        s = mid + 1;
    }
    
    printf("%d", ans);
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, p;

int main() {
    cin >> n >> p;
    int s = n * 3 + p;
    cout << s / 2 << endl;
    return 0;
}


Measured memory_bytes: 3528
#include <iostream>

int main()
{
    int a,b,c,d,e;
    std::cin>>a>>b>>c>>d>>e;
    if(a>=c+e&&b>=d+e&&c-e>=0&&d-e>=0)
    std::cout<<"Yes"<<std::endl;
    else std::cout<<"No"<<std::endl;
   return 0;
}


Measured memory_bytes: 1156
///byYerko
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int MXX = 2e3 + 7;
const int MXN = 1e6 + 7;
const int N = 1e9 + 7;

ll n, x, y;

int main() {
  cin >>n >>x >>y;
  cout <<(n - x) % y;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	ll N,A,B; cin>>N>>A>>B;
	vector<int> town(N);
	rep(i,N)cin>>town[i];
	ll ans = 0;
	rep(i,N-1){
		ll walk = (town[i+1] - town[i]) * A;
		ans += min(walk, B);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3768
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int m = stdIn.nextInt();
		for(int k=0;k<m;k++){
			int money = stdIn.nextInt();
			int copy_money = money;
			int year = stdIn.nextInt();
			int n = stdIn.nextInt();
			int[] pattern = new int[n];
			double[] rate = new double[n];
			int[] com = new int[n];
			int[] ans = new int[n];

			for(int i=0;i<n;i++){
				money = copy_money;
				pattern[i] = stdIn.nextInt();
				rate[i] = stdIn.nextDouble();
				com[i] = stdIn.nextInt();

				if(pattern[i] == 0){
					int plus_money = 0;
					for(int j=0;j<year;j++){
						plus_money += money * rate[i];
						money -= com[i];
					}
					money += plus_money;
				}
				else{
					for(int j=0;j<year;j++){
						money += money * rate[i] - com[i];
					}
				}

				ans[i] = money;
			}

			int max = ans[0];
			for(int i=0;i<n;i++){
				max = Math.max(max,ans[i]);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 41980
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod= 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e17;
const int inf = 2e9+100;
const int nmax = 1e5+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

ll bigmod(ll a, ll p, ll m=mod){
    ll res = 1, x = a;
    while(p){
        if(p&1) res = (res*x)%m;
        x = (x*x)%m, p/=2;
    }
    return res;
}

ll modinv(int a){
    return bigmod(a, mod-2);
}

ll fact[nmax];
ll infact[nmax];

ll ncr(int n, int r){
    if(r>n or n<0) return 0;
    return fact[n] * infact[r] % mod * infact[n-r] % mod;
}

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

    fact[0] = infact[0] = 1;
    for(int i=1; i<nmax; i++) fact[i] = fact[i-1] * i % mod;
    infact[nmax-1] = modinv(fact[nmax-1]);
    for(int i=nmax-2; i>=1; i--) infact[i] = infact[i+1] * (i+1) % mod;

    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int &x : v) cin>>x;
    sort(v.begin(), v.end());
    ll sam = 0;
    for(int i=0; i<n; i++){
        sam -= ncr(n-1-i, k-1) * v[i] % mod;
        sam += ncr(i, k-1) * v[i] % mod;
        sam%=mod;
    }

    cout<<sam<<endl;
}


Measured memory_bytes: 2176
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i > 0 and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]

print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
long long m,n,a[100005];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	long long ans=0;
	for(int i=0;i<n;i++)
	{
	ans+=a[i]/2;
	a[i]%=2;
	if(a[i]&&a[i+1])
	{
	ans++;
	a[i+1]--;
	} 
	}
	cout<<ans<<endl; 
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>QUE;//きゅー
ll int S[1000010];
int yakusu(ll int a)
{

	int j = 0;
	for (ll int i = 1; i * i <= a; ++i) {
		if (a % i == 0) {
			S[j++] = i;
			S[j++] = a / i;
			//printf("%lld %lld\n", i, a / i);
		}
	}
	sort(S, S + j);
	int ans = S[j / 2];
	return ans;
}
int keta(ll int ba) {
	int ans=1;
	while (true) {
		if (ba / 10 == 0) {
			return ans;
		}
		ba = ba / 10;
		ans++;
	}
}
int main(void)
{
	ll int N;
	scanf("%lld", &N);
	int a = yakusu(N);
	//printf("%d\n", a);

	printf("%d",keta(a));

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0031>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int n;
    while(cin >> n){
        vector<int> w;
        for(int i = 0; i < 10;i++) if((n>>i)&1) w.push_back(1<<i);
        cout << w << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 1e5 + 5;

int n, s;
int a[N], p[N];
ll b[N];
int m;

ll dg(int x, int y, int z) {
	if(y <= m) {
		if(z == y) return s - a[y];
		return s - a[x];
	}
	if(x > m) {
		if(z == x) return a[x] - s;
		if(z == y) return a[y] - s;
	}
	if(b[x] >= b[y]) {
		b[x] += b[y];
		return dg(x, y - 1, x) + (z == y ? (a[y] - a[x]) : 0);
	} else {
		b[y] += b[x];
		return dg(x + 1, y, y) + (z == x ? (a[y] - a[x]) : 0);
	}
}

int main() {
	scanf("%d %d", &n, &s);
	fo(i, 1, n) scanf("%d %d", &a[i], &p[i]);
	fo(i, 1, n) if(a[i] < s) m = i;
	fo(i, 1, n) b[i] = p[i];
	ll ans = dg(1, n, 1);
	fo(i, 1, n) b[i] = p[i];
	ans = max(ans, dg(1, n, n));
	pp("%lld\n", ans);
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,d,A,p[200005],cf[200005],rr[200005];
pii a[200005];
ll ans;
int main()
{
    scanf("%d%d%d",&n,&d,&A);
    rep(i,1,n) {
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        t2=(t2+A-1)/A;
        a[i]=mpr(t1,t2);
    }
    sort(a+1,a+n+1);
    rep(i,1,n) p[i]=a[i].se;
    int r=0;
    rep(l,1,n){
        while(r<n&&a[r+1].fi-a[l].fi<=2*d) r++;
        rr[l]=r;
    }
    ll cur=0;
    rep(i,1,n){
        cur+=cf[i];
        if(cur+p[i]>0){
            ans+=cur+p[i];
            cf[rr[i]+1]+=cur+p[i];
            cur-=cur+p[i];
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4096
#include<cstdio>
#include<vector>
#include<queue>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<cstring>
#include<cmath>
using namespace std;

typedef long long LL;

const int INF = 2147483647;

int n,k,ans;

inline LL getint()
{
    LL ret = 0,f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0',c = getchar();
    return ret * f;
}

int main()
{
    #ifdef AMC
        freopen("AMC1.txt","r",stdin);
    #endif
    n = getint(); k = getint();
    n -= k;
    ans = 1 + ceil(n * 1.0 / (k - 1));
    printf("%d",ans);
    return 0;
}


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

typedef long long ll;

const ll mod=1000000000+7;


int main() {
    int n;
    string str;

    cin>>n>>str;

    ll dp[30]={0};

    for(int i=0;i<n;i++){
        dp[str[i]-'a']++;
    }

    for(int i=25;i>=0;i--){
        dp[i]=(dp[i]%mod+dp[i+1]%mod+(dp[i]*dp[i+1])%mod)%mod;
    }
    cout<<dp[0]<<endl;


}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<iomanip>

#define	rep(i, n) for(int i=0; i<n; i++)

#define P pair<int, int>

typedef long long ll;

using namespace std;

#include <string>
#include <cctype>
typedef string::const_iterator State;
class ParseError {};


ll gcb(ll a, ll b) {
	if (b == 0) return a;
	return gcb(b, a%b);
}
ll lcm(ll a, ll b) {
	return a * b / gcb(a, b);
}
int main() {
	ll N, p[25];
	set<ll> cnt;
	cin >> N;
	rep(i, N) {
		cin >> p[i];
	}
	rep(i, 1 << N) {
		if (i == 0) continue;
		ll tmp = 1;
		rep(j, N) {
			if (i & 1 << j) {
				tmp = lcm(tmp, p[j]);
			}
		}
		cnt.insert(tmp);
	}
	cout << cnt.size() << endl;

	return 0;
}


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

int main(){
string S;
cin>>S;
if(S=="ABC"){
    cout<<"ARC"<<endl;
}else{
    cout<<"ABC"<<endl;
}
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
 
#define jyldam ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(NULL);

#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define sz size()
#define fi first
#define se second
 
#define cmp_all(x) (x).begin(), (x).end(), cmp
#define batr ONLINE_JUDGE
#define all(x) (x).begin(),(x).end()
#define skip continue
 
using namespace std;

typedef long long ll;
typedef long double ld;
 
const int N = 1e6 + 17, maxN = 4 * N, D = 1e3 + 17, mod = 1e9 + 7;

ll ct;
ll dp[N];
string s;

int main () {
	jyldam;
	cin >> s;
	if (s[0] == 'B') {
		dp[0] = 1;
	}
	for (int i = 1; i < s.sz; i++) {
		if (s[i] == 'B') {
			dp[i] = dp[i-1] + 1;
		}
		else {
			dp[i] = dp[i-1];
		}
	}
	for (int i = 0; i < s.sz; i++) {
		if (s[i] == 'W') {
			ct += dp[i];
		}
	}
	cout << ct;
	return 0;
}

Measured memory_bytes: 2180
import java.util.*

fun main(args:Array<String>){
    val (a,b) = readLine()!!.split(" ").map{it.toInt()}
    val ans = Array(100){CharArray(100)}
    for(i in 0 until 100){
        for(j in 0 until 100){
            ans[i][j] = if(i < 50) '.' else '#'
        }
    }
    var white = 1
    var black = 1
    for(i in 0 until 50 step 2){
        for(j in 0 until 100 step 2){
            if(black < b){
                ans[i][j] = '#'
                black++
            }
        }
    }
    for(i in 99 downTo 50 step 2){
        for(j in 0 until 100 step 2){
            if(white < a){
                ans[i][j] = '.'
                white++
            }
        }
    }
    println("100 100")
    val st = StringBuilder()
    for(i in 0 until 100){
        for(j in 0 until 100){
            st.append(ans[i][j])
        }
        st.append('\n')
    }
    println(st)
}

Measured memory_bytes: 38028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long a, b, c;

	std::cin >> a >> b >> c;

	std::cout << c << " " << a <<" "<< b << std::endl;

	return 0;
}

Measured memory_bytes: 384
def is_odd(n):
    if n % 2 == 1:
        return True
    else:
        return False
    
def p105(n):
    count = 0
    for s in range(n,0,-1):
        if is_odd(s):

            divisors = [s]

            for i in range(1,s):
                if s % i == 0:
                    divisors.append(i)
            if len(divisors) == 8:
                #print(divisors)
                count += 1
    return count

if __name__ == "__main__":
    n = int(input())
    print(p105(n))


Measured memory_bytes: 3060
import itertools
from collections import deque

n, m = map(int,input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    
ans = 0
for p in itertools.permutations([i+1 for i in range(n-1)]):
    pp = [0]+list(p)
    #print('pp',pp)
    now = pp[0]
    for i in range(1,n):
        if pp[i] in edge[now]:
            now = pp[i]
        else:
            break
    else:
        ans += 1
    
print(ans)

Measured memory_bytes: 9320
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {
	os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T,class U> ostream& operator<<(ostream &os, const tuple<S,T,U> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class S, class T,class U,class V> ostream& operator<<(ostream &os, const tuple<S,T,U,V> &t) { return os<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<","<<get<3>(t)<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
#else
#define out
#endif
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	vector<ll> a(n),b(n);
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];
	reps(i,1,n) a[i]+=a[i-1];
	rreps(i,1,n) b[i-1]+=b[i];
	ll re=0;
	rep(i,n) MX(re,a[i]+b[i]);
	cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <deque>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		char visited[255] = {};
		string input;
		cin >> input;

		visited[input[0]] = 1;
		deque<char> output;
		output.push_back(input[0]);
		for (int i = 1; input[i]; i += 3){
			if (!visited[input[i + 2]]){
				if (input[i] == '-') output.push_back(input[i + 2]);
				else output.push_front(input[i + 2]);
				visited[input[i + 2]] = 1;
			}
		}
		for (int i = 0; i < output.size(); i++){
			cout << output[i];
		}
		cout << endl;
	}
	return (0);
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define MOD 1000000007LL
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev,ng;
	edge(){}
	edge(int tt,int cc,int rr,int nng){
		to=tt;
		cap=cc;
		rev=rr;
		ng=nng;
	}
};

vector<edge> G[10000];
vector<int> id[10001];
int level[10000];
int iter[10000];
bool used[10001];

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

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(e.cap,f));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

bool get_path(int v,int t,int p){
	if(v==t)return true;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i].cap>0 && p!=G[v][i].to && !used[G[v][i].to]){
			if(get_path(G[v][i].to,t,v))return true;
		}
	}
	return false;
}


int n,m;

int s[5005],t[5005],c[5005];
int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&s[i],&t[i],&c[i]);
		add_edge(s[i],t[i],c[i]);
	}
	int val=max_flow(0,n-1);
	/*
	for(int i=0;i<n;i++){
		G[i].clear();
	}
	for(int i=0;i<m;i++){
		if(c[i]>=2)add_edge(s[i],t[i],c[i]);
		else add_edge(s[i],t[i],0);
	}
	int val2=max_flow(0,n-1);
	if(val!=val2)val--;
	*/
	bool flag2=false;
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<id[i].size();j++){
			cnt++;
			if(G[i][id[i][j]].cap==0){
				memset(used,false,sizeof(used));
				if(!flag2 && !get_path(i,G[i][id[i][j]].to,-1)){
					flag2=true;
					val--;
				}
			}
		}
	}
	printf("%d\n",val<=10000?val:-1);
	return 0;
}

Measured memory_bytes: 4312
#include<stdio.h>
#include<string.h>
int main(){
    char m[21];
    int i,n;
    scanf("%s",m);
    n=strlen(m)-1;
    for(i=n;i>=0;i--){
        printf("%c",m[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
import itertools

n,m,x = map(int, input().split())
result_list = [[0 for i in range(m+1)] for i in range(2**n)]
book_list=[]
zero_one = [0,1]
combi_list = list(itertools.product(zero_one, repeat=n))
for i in range(n):
    can = list(map(int, input().split()))
    book_list.append(can)
#2^n通りの組み合わせ
for i in range(2**n):
    #n個全部足す
    for j in range(n):
        #価格とスキルを全部足す
        for k in range(m+1):
            result_list[i][k] +=  book_list[j][k] * combi_list[i][j]
Ans_list = []
for i in range(len(result_list)):
    kari_list = result_list[i][1:]
    if min(kari_list) >= x:
        Ans_list.append(result_list[i][0])
if Ans_list == []:
    print(-1)
else:
    Ans = min(Ans_list)
    print(Ans)

Measured memory_bytes: 11984
#include <bits/stdc++.h>
int th(int x, int y, int tx, int ty, int hh)
{
  return std::max(hh - std::abs(x - tx) - std::abs(y - ty), 0);
}
int main(void)
{
  int n, x[100], y[100], h[100];
  int k = 0;
  std::cin >> n;
  for(int i = 0; i != n; i++)
    std::cin >> x[i] >> y[i] >> h[i];
  // get sample
  while(h[k] == 0) k++;
  for(int tx = 0; tx <= 100; tx++){
    for(int ty = 0; ty <= 100; ty++){
      int hh = h[k] + std::abs(x[k] - tx) + std::abs(y[k] - ty);
      bool flg = true;
      for(int m = 0; m != n; m++){
        if(th(x[m], y[m], tx, ty, hh) != h[m]){
          flg = false;
          break;
        }
      }
      if(flg){
        std::cout << tx << " " << ty << " " << hh << std::endl; 
        return 0;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main() {
  int X;
  cin >> X;
  int ans = 0;
  for (int i = 1; i <= X; ++i) {
    for (int j = 2; j <= 1000; ++j) {
      int ex = pow(i, j);
      if (ex > X) break;
      ans = max(ans, ex);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{ int i,j,k,l,n,y,z;
long int sum=0;
    cin>>n;
  for(i=1;i<=n;i++)
    {for(j=1;j<=n;j++)
        {for(k=1;k<=n;k++)

 {y=__gcd(i,j);
  y=__gcd(y,k);
  sum=sum+y;}}} cout<<sum;}




Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define MOD 1000000007
#define ll long long

using namespace std;
int main(){
  int n;
  cin>>n;
  ll ans=1;
  ll fl[1010]={};
  for(int i=1;i<=n;i++){
    int now=i;
    int cntt=1;
    for(int j=2;j<=i;j++){
      int cnt=0;
      while(now%j==0){
	now/=j;
	fl[j]++;
      }
    }
  }
  for(int i=2;i<=1000;i++){
    ans=ans%MOD*(fl[i]+1);
    //cout<<ans<<endl;
    //cout<<fl[i]<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
}

Measured memory_bytes: 19664
#include <iostream>
using namespace std;
int main()
{
    //cout<<"Enter number n of squares.\n";
    int N;
    cin>>N;
    int *num = new int[N];
    //cout<<"Enter n integers separated by a space.\n";
    int counter=0;
    for (int i=1; i<=N; i++)
    {
        cin>>num[i-1];
        if (i%2 != 0 && num[i-1]%2 != 0)
            counter++;
    }
    delete num;
    cout<<counter;
    return 0;
}

Measured memory_bytes: 3540
n = int(input())
b = list(map(int, input().split()))

a = [0 for i in range(n)]
a[0] = b[0]

for i in range(1,n-1):
    a[i] = min(b[i-1],b[i])
a[-1] = b[n-2]
ans = 0
for i in range(n):
    ans += a[i]
print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, a, b;
    cin >> n >> a >> b;
    if ((n == 1 && a != b) || a > b) {
        cout << 0 << endl;
        return 0;
    }
    ll min = (n-1)*a + b;
    ll max = a + (n-1)*b;
    ll ans = max - min + 1;
    cout << ans << endl;
}

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

void swap(int a, int b)
{
  int temp;
  temp = a;
  a = b;
  b = temp;
}

int main()
{
  int i, j, k, N;
  int p[60];
  int temp, count = 0;

  scanf("%d", &N);
  for(i=0; i<N; i++){
    scanf("%d", &p[i]);
  }
  
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      temp = p[i];
      p[i] = p[j];
      p[j] = temp;
      //printf("%d\n", p[i]);
      //printf("%d\n", p[j]);
      for(k=0; k<N-1; k++){
         //printf("%d", count); 
        if(p[k+1]-p[k]>0){
          count++;
          //printf("%d", count);  
          if(count == N-1){
            printf("YES");
            return 0;
          }
        }
      }
      temp = p[i];
      p[i] = p[j];
      p[j] = temp;
      count = 0;
    }
  }

  printf("NO");

  return 0;

}

Measured memory_bytes: 128
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val H, W = sc.nextInt
  val as = Vector.fill(H, W)(sc.nextInt)

  @tailrec private def loop(pos: (Int, Int), prev: Int, acc: Seq[(Int, Int, Int, Int)]): Seq[(Int, Int, Int, Int)] = {
    val (i, j) = pos
    val next = nextOf(pos)
    if (i == H) {
      if (prev == 0)
        acc
      else
        acc.tail
    } else {
      if ((prev + as(i)(j)) % 2 == 0) {
        loop(next, 0, acc)
      } else {
        loop(next, 1, (i, j, next._1, next._2) +: acc)
      }

    }
  }

  private def nextOf(pos: (Int, Int)): (Int, Int) = pos match {
    case (i, j) if i % 2 == 0 && j + 1 < W => (i, j + 1)
    case (i, j) if i % 2 == 0 => (i + 1, j)
    case (i, j) if j == 0 => (i + 1, j)
    case (i, j) => (i, j - 1)
  }

  val ans = loop((0, 0), 0, Seq.empty).reverse
    println(ans.size)
    ans.foreach(a => println(s"${a._1 + 1} ${a._2 + 1} ${a._3 + 1} ${a._4 + 1}"))
}


Measured memory_bytes: 123140
X,Y,A,B,C=(int(x) for x in input().split())
ps = sorted([int(x) for x in input().split()],reverse=True)
qs = sorted([int(x) for x in input().split()],reverse=True)
rs = sorted([int(x) for x in input().split()],reverse=True)
sta = sorted(ps[:X] + qs[:Y])
res = sum(sta)
for i in range(C):
  a = rs[i]
  s = sta[i]
  if a> s:
    res += a-s
  else:
    break
print(res)

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

const int MAX = 500005;
const long long int mod = 1e9+7;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}



int main(){
    int n,m;
    cin >> n >> m;
    COMinit();
    long long int ans = 0;
    for(int i=0;i<=n;i++){
        if(i%2==0)ans += COM(n,i)%mod*fac[m]%mod*finv[m-i]%mod*fac[m-i]%mod*fac[m-i]%mod*finv[m-n]%mod*finv[m-n]%mod;
        else ans += mod - COM(n,i)%mod*fac[m]%mod*finv[m-i]%mod*fac[m-i]%mod*fac[m-i]%mod*finv[m-n]%mod*finv[m-n]%mod;
        ans %= mod;
    }
    cout << ans;
}

Measured memory_bytes: 15276
import itertools
N = int(input().strip())
seq_list = [''.join(sorted(input().strip())) for _ in range(N)]
hash = {}
result = 0
for seq in seq_list:
  if seq in hash:
    result += hash[seq]
    hash[seq] += 1
  else:
    hash[seq] = 1
print(result)


Measured memory_bytes: 19528
#include<stdio.h>

int main()
{
  int x=0,y=0,t,c,sum=0;
  for(c=0;c<=3;c++){
    scanf("%d",&t);
	sum+=t;
  }
  x=sum/60;
  y=sum%60;
  printf("%d\n",x);
  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 0
# coding: utf-8
# coding: Shift_JIS
# coding: EUC-JP
# coding: cp932
import math

r,c = map(int,input().split())
ans = [[0 for j in range(c+1)] for i in range(r+1)]
for i in range(r):
    sum = 0
    li = list(map(int,input().split()))
    for j in range(c):
        ans[i][j] = li[j]
        ans[r][j] += li[j]
        sum += li[j]
    ans[i][c] = sum
    ans[r][c] += sum

for i in range(0,r+1):
    print("%d"%(ans[i][0]),end="")
    for j in range(1,c+1):
        print(" %d"%(ans[i][j]),end = "")
    print()


Measured memory_bytes: 6380
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


int N, M, Q;
vector<int>a, b, c, d;

int select_num(vector<int> ary, int n, int count);

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

	a = b = c = d =vector<int>(Q);
	for (int i = 0;i<Q;i++) {
		cin >> a[i];
		cin >> b[i];
		cin >> c[i];
		cin >> d[i];
	}

	int ans = select_num(vector<int>(1,0),1,N);


	cout << ans << endl;

	return 0;
}

int select_num(vector<int> ary,int n, int count)
{
	int ret = 0;
	if (count > 0) {
		for (int i = n ;i<=M; i++) {
			vector<int>na = ary;
			na.push_back(i);
			ret = max(ret,select_num(na,i,count-1));
		}
	}
	else {

		for (int i = 0; i < Q; i++) {
			if (ary[b[i]] - ary[a[i]] == c[i]) {
				ret += d[i];
			}
		}
	}

	return ret;
}

Measured memory_bytes: 3628
N = int(input())
arr = input()
guzai = arr.split(" ")
guzai_int = [int(i) for i in guzai]

for i in range(1, N):
  guzai_int.sort()
  x = guzai_int.pop(0)
  y = guzai_int.pop(0)
  guzai_int.append((x+y)/2)

print(guzai_int.pop())

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  for (int i = 0; 4 * i <= N; ++i) {
    if ((N - 4*i) % 7 == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3636
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
list_sum = [0]*(len(a)+1)
for i in range(n):
    list_sum[i + 1] = list_sum[i] + a[i]
c = Counter(list_sum)
ans = 0
for v in c.values():
    if v >= 2:
        ans += v*(v-1)//2
print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  int weight=0;
  for(int i=0; i<N; i++){
    cin >> W[i];
    weight+=W[i];
  }
  int S1=0;
  int S2=weight;
  int ans=-1;
  for(int i=0; i<N; i++){
    S1+=W[i];
    S2-=W[i];
    int temp=abs(S1-S2);
    if(ans==-1) ans=temp;
    else ans=min(ans, temp);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";
   
void solve(std::string S){
  ll N = S.length();
  string x = S;reverse(all(x));
  bool a = (S == x ? true:false);
  string n = S.substr(0,(N-1)/2);
  string nx = n;reverse(all(nx));
  bool b = (n == nx ? true:false);
  string m = S.substr(((N+3)/2)-1 , S.length());
  string mx = m;reverse(all(mx));
  bool c = (m == mx ? true:false);
  cout << (a && b && c ? YES : NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<pair<int,int> > pii;
    int pa=0,pb=0;
    for(int i=0;i<n;i++){
      int a,b;
      cin>>a>>b;
      pii.push_back(make_pair(a,b));
      if(pii[i].first>pii[i].second)
	pa+=(pii[i].first+pii[i].second);
      else if(pii[i].first<pii[i].second)
	pb+=(pii[i].first+pii[i].second);
      else{
	pa+=pii[i].first;pb+=pii[i].second;
      }
    }
    cout<<pa<<" "<<pb<<endl;
  }
  return 0;
}

Measured memory_bytes: 3200