akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = IR(n)
if A[0]:
    print(-1)
    exit()
ret = 0
ans = 0
for i in range(1, n):
    if A[i] > ret + 1:
        print(-1)
        exit()
    elif A[i] == ret + 1:
        ans += 1
    else:
        ans += A[i]
    ret = A[i]
print(ans)


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

int main(){
  string s;
  cin >> s;
  string ans = "";
  rep(i, s.size()){
    if (!(i%2)) ans += s[i];
  }
  cout << ans << endl;
}


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

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

    if(n % 2 != 0) cout << "No" << endl;
    else {
        for(int i = 0; i < n/2; i++) {
            if(s[i] != s[n/2 + i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std; 

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

int main(){

    int a,b,c;
    cin>>a>>b>>c;
    a*=100;
    a+=b*10;
    a+=c;

    if(a%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k;
	cin >> k;
	long long int sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int m = 1; m <= k; m++) {
				sum = sum + __gcd(i, __gcd(j, m));
			}
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int xCount = Math.min(n, k);
		int yCount = n - xCount;
		int result = xCount * x + yCount * y;
		
		System.out.println(result);
	}

}


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


class UnionFind
{
private:
	vector<int> par;
	vector<lli> sizes;
public:
	UnionFind(int N) : par(N), sizes(N, 1) {
		for (int i = 0; i < N; ++i) par[i] = i;
	}

	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);  // 経路圧縮
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (sizes[x] < sizes[y]) swap(x, y);
		par[y] = x;
		sizes[x] += sizes[y];
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	lli size(int x) {
		return sizes[find(x)];
	}
};



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

	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}
	for (int i = 0; i < M; ++i) {
		--A[i]; --B[i];
	}

	vector<lli> ans(M);
	UnionFind uf(N);

	ans[M - 1] = N * (N - 1) / 2;

	for (int i = M - 2; i >= 0; --i) {
		if (uf.same(A[i + 1], B[i + 1]))
			ans[i] = ans[i + 1];
		else {
			ans[i] = ans[i + 1] - uf.size(A[i + 1]) * uf.size(B[i + 1]);
			uf.unite(A[i + 1], B[i + 1]);
		}
	}

	for (int i = 0; i < M; ++i) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double p;
    vector<vector<double> > dp(n+1,vector<double> (n+1,0.0));
    dp[0][0]=1.0;
    for(int i=0;i<n;i++){
    	cin>>p;
    	for(int j=0;j<n;j++){
    		dp[i+1][j+1]+=dp[i][j]*p;
    		dp[i+1][j]+=dp[i][j]*(1.0-p);
    	}
    }
    double ans=0.0;
    for(int i=(n+2)/2;i<=n;i++){
    	ans+=dp[n][i];
    }
    doublecout(ans);
    return 0;
}


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

string A, B;

int hash_A[27];
int hash_B[27];

int main() {
	cin >> A >> B;
	for(int pos = 1; pos < A.size(); pos++)
		hash_A[A[pos] - 97]++;
	for(int pos = 1; pos < B.size(); pos++)
		hash_B[B[pos] - 97]++;
	sort(hash_A, hash_A + 27);
	sort(hash_B, hash_B + 27);
	for(int pos = 0; pos < 27; pos++)
		if(hash_A[pos] != hash_B[pos]) {
			cout << "No" << endl; return 0;
		}
	cout << "Yes" << endl;
}


Measured memory_bytes: 776
import numpy as np

def main():
    n = int(input())
    w = list(map( int, input().split()))

    minval = 10000
    for i in range(len(w)):
        hidari = np.sum(w[:i+1])
        migi = np.sum(w[i+1:])
        if minval > abs(hidari-migi):
            minval = abs(hidari-migi)

    print(minval)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 12504
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;


int main(){
	int N,M;
	cin>>N;
	set<string>st;
	REP(i,N){
		string str;
		cin>>str;
		st.insert(str);
	}
	cin>>M;
	int flag=0;
	REP(i,M){
		string str;
		cin>>str;
		if(st.find(str)!=st.end()){
			if(flag==0){
				cout<<"Opened by "<<str<<endl;
			}else{
				cout<<"Closed by "<<str<<endl;
			}
			flag++;
			flag%=2;
		}else{
			cout<<"Unknown "<<str<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
    public static void main (String args[]) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = "";
			
			while ((line = br.readLine()) != null) {
				String[] str = line.split(" ");
				
				if (str.length == 3) {
					double a = (double)Integer.parseInt(str[0]);
					double b = (double)Integer.parseInt(str[1]);
					double c = (double)Integer.parseInt(str[2]);
					
					double a2 = Math.pow(a, 2.0);
					double b2 = Math.pow(b, 2.0);
					double c2 = Math.pow(c, 2.0);
					
					if ((a2 + b2 == c2) || (b2 + c2 == a2) || (c2 + a2 == b2)) {
						System.out.println("YES");
					}else {
						System.out.println("NO");
					}					
				}else if(str.length == 0){
					System.exit(0);
				}	
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		finally {
			System.exit(0);
		}
    }
}

Measured memory_bytes: 20228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };

int main() {

	int n;
	cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x.at(i);
	sort(x.begin(), x.end());
	int ma = x.at(n - 1);
	int mi = x.at(0);
	int ans = 1000000007;
	for (int i = mi; i < (ma + 1); i++) {
		int score = 0;
		rep(j, n) {
			score += (x.at(j) - i) * (x.at(j) - i);
		}
		ans = min(ans, score);
	}
	cout << ans << endl;

	return 0;
}

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

const ll INF = 1LL << 60;

ll N, Q;
vector<ll> a, b, p, x;
vector<ll> g[500100];
vector<ll> ans;

map<ll, ll> mp;

void dfs(ll cur, ll par) {
    for (ll i = 0; i < g[cur].size(); i++) {
        ll to = g[cur][i];
        if (to == par) continue;
        // if (to < cur) continue;
        mp[to] += mp[cur];
        dfs(to, cur);
    }
}

int main() {
    cin >> N >> Q;
    a.resize(N); 
    b.resize(N);
    rep(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }

    ans.resize(N);
    p.resize(Q);
    x.resize(Q);

    rep(i, Q) {
        cin >> p[i] >> x[i];
        p[i]--;
        mp[p[i]] += x[i];
    }

    dfs(0, -1);

    rep(i, N) {
        cout << mp[i] << endl;
    }
}

Measured memory_bytes: 59392
#include <stdio.h>

int pm(int x){if(x > 0){return 1;}else if(x < 0){return -1;}return 0;}
int zt(int x){if(x < 0){return -x;}return x;}
int max(int a,int b){if(a < b){return b;}return a;}

int main(void) {
	int w,h,n,x1,y1,x2,y2,i,res = 0;
	scanf("%d%d%d%d%d",&w,&h,&n,&x1,&y1);
	for(i = 2;i <= n;i++){
		scanf("%d%d",&x2,&y2);
		if(pm(x2-x1) == pm(y2-y1)){res+=max(zt(x2-x1),zt(y2-y1));}
		else{res+=(zt(x2-x1)+zt(y2-y1));}
		x1 = x2;
		y1 = y2;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void){
	int a1,a2,a3,a4,b1,b2,b3,b4,s,t;
	scanf("%d %d %d %d",&a1,&a2,&a3,&a4);
	scanf("%d %d %d %d",&b1,&b2,&b3,&b4);
	s=a1+a2+a3+a4;
	t=b1+b2+b3+b4;
	if (t>s) printf("%d\n",t);
	else printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 592
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	//FastScannerクラス、普通の Scannerクラスだとメモリと時間を大幅に喰らうので高速化する内部クラス。
	
	public static void main(String[]args) {
		FastScanner sc = new FastScanner(System.in);
		int n= Integer.valueOf(sc.next());
		int []a  = new int[n];
		for(int i = 0;i<n;i++)a[i] = Integer.valueOf(sc.next());
		
		if((n-1)%2==1) {//最終こうが奇数かどうか
			for(int i = n-1;i>=1;i = i-2) {
				System.out.print(a[i]);
				System.out.print(" ");
			}
			System.out.print(a[0]);
			System.out.print(" ");
			for(int i = 2;i<=n-2;i = i+2) {
				System.out.print(a[i]);
				System.out.print(" ");
			}
			
			
		}else {
			for(int i = n-1;i>=2;i = i-2) {
				System.out.print(a[i]);
				System.out.print(" ");
			}
			System.out.print(a[0]);
			System.out.print(" ");
			for(int i = 1;i<=n-2;i = i+2) {
				System.out.print(a[i]);
				System.out.print(" ");
			}
			
			
		}
		
		
		
		
		
	}
	
	static class FastScanner {
		 
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
 
		public FastScanner(InputStream source) {
			in = source;
		}
 
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}
 
		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}
 
		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		}
 
		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}

}


Measured memory_bytes: 63916
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, k;
    string s;
    cin >> n >> k >> s;
    char upper = s.at(k-1);
    s.at(k-1) = upper + 32;
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <set>
#include <cmath>
#include <math.h>

using namespace std;
        
int main(){
    long int n,m;
    cin>>n>>m;
    long int ans=0;
    long int sumn=n-m;
    long int t=((sumn*100)+1900*m);
    long int kai=1;
    while(m>0){
        kai*=2;
        m--;
    }
    ans=t*kai;
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  for (auto &x: A) cin >> x;

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A[i] > A[j]) {
        if (i < j) ans = (ans+(K*(K+1))/2) % MOD;
        else ans = (ans+((K*(K+1))/2)-K) % MOD;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
struct Node {
  ll x, y;
  Node() = default;
  Node(int a, int b) : x(a), y(b) {}
  friend bool operator<(const Node& n1, const Node& n2) {
    if (n1.x != n2.x) return n1.x < n2.x;
    return n1.y < n2.y;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  vector<Node> v(N);

  int vmin = INT_MAX;
  int imin = -1;
  int vmax = INT_MIN;
  int imax = -1;
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    v[i].x = x;
    v[i].y = y;
  }

  sort(v.begin(), v.end());

  for (int i = 0; i < N; ++i) {
    int x = v[i].x;
    int y = v[i].y;
    if (vmin > x) {
      vmin = x;
      imin = i;
    }

    if (vmax < y) {
      vmax = y;
      imax = i;
    }
  }

  ll ret = 1LL << 62;
  const ll rmin = vmin;
  // if bmax = vmax;
  ll bmax = vmax;

  ll rmax = rmin;
  ll bmin = bmax;

  for (auto& n : v) {
    rmax = max(rmax, n.x);
    bmin = min(bmin, n.y);
  }

  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  // if rmax = vmax;
  rmax = vmax;


  bmin = min(v[0].y, v[imax].x);
  bmax = max(v[0].y, v[imax].x);
  
  vector<Node> bv;
  for (int i = 0; i < N; ++i) {
    if (i != imin && i != imax) {
      bv.push_back(v[i]);
      bmin = min(bmin, v[i].x);
      bmax = max(bmax, v[i].x);
    }
  }

  ll nbmin = min(v[0].y, v[imax].x);
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  for (int i = 0; i + 1 < bv.size(); ++i) {
    auto const& c = bv[i];
    if (c.x > nbmin) break;
    bmin = min({c.y, bv[i+1].x, nbmin});
    bmax = max(c.y, bmax);
    nbmin = min(nbmin, c.y);
    ret = min(ret, (rmax - rmin) * (bmax - bmin));
  }

  bmin = v[0].y;
  bmax = v[imax].x;
  for (auto& n : bv) {
    bmin = min(bmin, n.y);
    bmax = max(bmax, n.y);
  }
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  cout << ret << endl;
}

Measured memory_bytes: 9584
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d",&a);scanf("%d",&b);
    if(a<b){
        printf("a < b\n");
        }else if(a>b){
            printf("a > b\n");
        }else{
            printf("a == b\n");}
    return 0;
}



Measured memory_bytes: 2048
import std.algorithm, std.conv, std.range, std.stdio, std.string;

const ma = 10 ^^ 5;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto a = readln.split.to!(int[]);
  auto b = new int[](ma);

  foreach (ai; a) {
    if (ai > 0) ++b[ai-1];
    ++b[ai];
    if (ai < ma-1) ++b[ai+1];
  }

  writeln(b.reduce!max);
}


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

int main()
{
    int H,A;

    cin >> H >> A;
    if(H%A == 0)
    {
        cout << H/A << endl;
    }
    else
    {
        cout << (H/A)+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
if n%4==0 or n%7==0:
  print("Yes")
elif n<7:
  print("No")
else:
  d=n
  c=0
  while d>=7:
    d=d-7
    c+=1
  if d>=4:
    d=d-4
  if d<=c:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 3064
import sys
def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, K, A):
    n = 1
    k = 0
    d = {n: k}
    while True:
        k += 1
        n = A[n - 1]
        if k == K or n == A[n - 1]:
            return n
        if not n in d:
            d[n] = k
        else:
            x = (K - d[n]) % (k - d[n]) + 1
            for i in d:
                if d[i] == d[n] - 1 + x:
                    return i
            return -1

    

(N, K) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
print(calc(N, K, A))

Measured memory_bytes: 104612
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
const int maxn=1005;
int n,t,a,aa;
double b[maxn],ans=0x3f3f3f3f;
int main()
{
	cin>>n>>t>>a;
	rep(i,1,n)
	{
		cin>>b[i];
		b[i]=((double)t-0.006*b[i]);
		if(abs(b[i]-(double)a)<ans)
		{
			ans=abs(b[i]-a);
			aa=i;
		}
	}
	cout<<aa;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x){
	int f=1;
	x=0;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-'){
			f=-1;
		}
		ch=getchar();
	}
	while(ch<='9' && ch>='0'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}
bool digck(int w,int l,int r){
	int p=w,t=0;
	while(p>=1){
		t+=p%10;
		p/=10;
	}
	if(t>=l && t<=r){
		return 1;
	}
	else{
		return 0;
	}
}
int main(){
	int n,a,b,coun=0;
	read(n);
	read(a);
	read(b);
	for(int i=1;i<=n;i++){
		if(digck(i,a,b)){
			coun+=i;
		}
	}
	cout<<coun<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  map<string, int> mp;
  string str;
  rep(i,n){
    cin >> str;
    mp.insert(make_pair(str,0));
  }
  cout << mp.size() << endl;
  return 0;
}


Measured memory_bytes: 19132
from collections import deque
import sys
#処理は72行目から開始。

#変数一覧
# 入力
#   H : 縦サイズ,  W : 横サイズ
#   (hs, ws) : 始点座標,  (hg, wg) : 終点座標
#   S : グラフ("#" or ".")
# 処理
#   task : タスクとなる点のリスト(deque)。後述のように、その点から行ける新しい点を探すタスクを行う）
#   visited : 処理中に訪れた点の集合 (taskに組み入れたタイミングで「訪れた」とみなす)


# 幅優先探索 
# 1, taskに入っているいずれかの点から、歩きで行ける点を列挙 
# 2, 見つかった点について、そこからワープで行ける新たな点を列挙

# 処理1のやり方
#  ① 初期点をtaskに格納
#  ② taskに格納した点から、直接行ける(新たな)点を見つける
#  ③ 見つかった点をtaskに格納
#  ④ taskが空になるまで、②と③を繰り返す
#  ※ 言葉の約束
#   点sを「訪れた(visited)」= 点sをtaskに格納した
#   (taskから取り出すことではないので注意)

def BFS(task, ct):
  D = [(1,0), (0,1), (-1,0), (0,-1)] #歩きによる動き
  semi_visited = set() #この処理中に訪れた点をメモしておく（あとでワープ先を調べるため）
  task_n = deque([]) #ワープ後に行ける点の集合を、新たなtaskとして導入
  
  for s in task: #最初にtaskに入っているものは、この処理中で訪れた点としてカウントする
    semi_visited.add(s)
    
  while task: # taskが空でないうちは続ける
    s = task.popleft() # 点を取り出し
    if s == (hg, wg): # ゴールに着いていたら終了する
      print(ct)
      sys.exit()
    x = s[0]
    y = s[1]
    for d in D:
      s_n = (x+d[0], y+d[1]) # 点sから歩いて行ける点
      if 0 <= s_n[0] <= H-1 and 0 <= s_n[1] <= W-1:
        if (s_n not in semi_visited) and S[s_n[0]][s_n[1]] == ".": 
          # 点s_nが、まだ訪れたことのない道マスのとき
          task.append(s_n) # taskに追加
          semi_visited.add(s_n) # 処理中に訪れた点をメモしておく
          visited.add(s_n)  # 訪れた点をメモしておく
          
  for s in semi_visited: # この処理中に訪れた全ての点sについて
    warp(s, task_n) # 点sからワープ可能な点の列挙を行い、task_nへ格納する
  
  return (ct+1, task_n) #更新したコストと、新たなタスクのリストを返す

# 点p=(x,y)の周りでワープできる点を探す。
# それが訪れたことのない点なら、task_nに格納する。
def warp(p, task_n): 
  x = p[0]
  y = p[1]
  for dh in range(-2,3):   #周囲2マス
    for dw in range(-2,3):
      s_n = (x+dh, y+dw)
      if 0 <= s_n[0] <= H-1 and 0 <= s_n[1] <= W-1:
        if s_n not in visited and S[s_n[0]][s_n[1]] == ".": 
          #まだ訪れたことのない点であるとき
          task_n.append(s_n) # taskに組み入れる
          visited.add(s_n)   # taskに組み入れた点は、「訪れた」とみなす 

#処理始め
H, W = map(int, input().split())
hs, ws = map(int, input().split())
hs -= 1
ws -= 1
hg, wg = map(int, input().split())
hg -= 1
wg -= 1

S = [input() for _ in range(H)]

task = deque([(hs, ws)]) # taskに初期点を追加
visited = {(hs, ws)} # taskに入れた点は訪れたものとみなす
ct = 0

while task: # taskが空でない限り続ける
  ct, task = BFS(task, ct) 
  # 幅優先探索（1,歩いて行ける点の列挙 → 2,ワープで行ける点の列挙）

print(-1) # taskが空になってもゴールに着かないなら、ゴールにたどり着くことは不可能

Measured memory_bytes: 157932
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//子の数が分かるUnionFind
struct UFT {
private:
	vector<int> par, rank;
	vector<int> c_n; //子の数
	void init(int n = 1) {
		par.resize(n); rank.resize(n); c_n.resize(n);
		for (int i = 0; i < n; i++)par[i] = i, rank[i] = 0, c_n[i] = 1;
	}
	void update(int x) {
		if (par[x] == x)return;
		else {
			int r = root(par[x]);
			c_n[par[x]] += c_n[x];
			par[x] = r;
			return;
		}
	}
	int root(int x) {
		if (par[x] == x)return x;
		else {
			int r = root(par[x]);
			return par[x] = r;
		}
	}
public:
	UFT(int n = 1) {
		init(n);
	}
	int weight(int x) {
		return c_n[root(x)];
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)false;
		if (rank[x] < rank[y])swap(x, y);
		if (rank[x] == rank[y])rank[x]++;
		par[y] = x;
		update(y);
		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> E(M);
	for (int i = 0; i < M; i++) {
		cin >> E[i].first >> E[i].second;
		E[i].first--;
		E[i].second--;
	}
	ll ans = 0;
	for (int i = 0; i < M; i++) {
		UFT a(N);
		for (int j = 0; j < M; j++) {
			if (i == j)continue;
			a.merge(E[j].first, E[j].second);
		}
		//cout << a.weight(0) << endl;
		if (a.weight(0) != N)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline

n, q = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

cons.sort(key=lambda x: x[2])
for i in range(n):
    cons[i][0] -= cons[i][2]
    cons[i][1] -= cons[i][2]

ans = [-1] * q
l = [-1] * q
for i in range(n):
    s = bisect.bisect_left(d, cons[i][0])
    t = bisect.bisect_left(d, cons[i][1])
    while s < t:
        if l[s] != -1:
            s = l[s]
        else:
            ans[s] = cons[i][2]
            l[s] = t
            s += 1
print(*ans, sep="\n")

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
ll A[MAX_N];
ll S[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  S[0] = 0;
  REP(i, N) S[i+1] = S[i] + A[i];
  ll ans = 0;
  map<ll, ll> count;
  REP(i, N) {
    if (S[i+1] == 0) ans++;
    ans += count[ S[i+1] ];
    count[ S[i+1] ]++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 15872
def get_prime_dic(n):
    dic = {}

    i = 2
    while i * i <= n:
        while n % i == 0:
            n //= i
            if i in dic:
                dic[i] += 1
            else:
                dic[i] = 1
        i += 1

    if n > 1:
        dic[n] = 1
    return dic
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b


def main():
    N, M = map(int, input().split())
    d = get_prime_dic(M)
    ans = 1
    for k, v in d.items():
        ans *= combination(v + N - 1, v)
        ans %= 1000000007

    print(ans)


main()


Measured memory_bytes: 3064
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)		for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {

    om_shree_ganeshaya_namah();

    string s;
    cin>>s;
    int ans=0;
    f(s.length()){
        ans+=(s[i]-'0');
    }
    string output = (ans%9)?"No":"Yes";
    cout<<output;
}

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

using namespace std;

string s;

//返り値が０でないならOK
int check(string buf,string &next,int i){
   if (buf != next){
     
  //    cout << "OKです　buf: " << buf << " next: " << next << " i: " << i << endl;
      return i;
   }

   i++;
   if (i > s.size()-1){
      next = s.at(i-1);
      if(buf==next)
         return 0;
      else
         return i;
   }

   next += s.at(i);
//   printf("次の文字に進みます i: [%d]\n", i);
   return check(buf, next, i);
}

int main(void){

   
   cin >> s;

   int n = s.size();

   string buf;
   buf = s.at(0);

   int i = 1;
   int cnt = 1;

   while (i < n){
     
      string next;
      next = s.at(i);
      
      //前回と違う文字列の場合
      int move = check(buf, next, i);
      
      if(move == 0)
         break;

      cnt++;

      if (move == i)
         i++;
      else
         i = move+1;

      buf = next;
   }
   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <random>
#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 11

#define P3(a,b,c) make_pair(make_pair(a,b),c)

int h, w;
int t[SIZE][SIZE], t2[SIZE][SIZE];
int max_size[11][11] = {};
int covered[11][11] = {};
map<pair<pair<ll,ll>,int>,int> visited;

int ans;

void dfs(int y, int x, int counter = 0, ll hash = 0, ll hash2 = 0){
  //debug(ans);
  int diff[11][11] = {};
  if(ans <= counter) return;
  auto it = visited.find(P3(hash,hash2,y*w+x));
  if(it != visited.end() && it->second <= counter) return;
  
  if(y == h){
    ans = min(ans, counter);
    return;
  }

  if(max_size[y][x] == 0 || covered[y][x])
    dfs(y + (x == w-1), (x + 1)%w, counter, hash, hash2);
  
  if(max_size[y][x] != 0){
    ll newhash = hash, newhash2 = hash2;
    int diffcounter = 0;
    for(int i=0;i<max_size[y][x];i++)
      for(int j=0;j<max_size[y][x];j++)
        if(covered[y+i][x+j] == 0){
          diff[y+i][x+j] = covered[y+i][x+j] = 1;
          newhash ^= t[y+i][x+j];
          newhash2 ^= t2[y+i][x+j];
          diffcounter++;
        }

    if(diffcounter)
      dfs(y + (x == w-1), (x + 1)%w, counter+1, newhash, newhash2);

    for(int i=0;i<max_size[y][x];i++)
      for(int j=0;j<max_size[y][x];j++)
        if(diff[y+i][x+j] == 1){
          covered[y+i][x+j] = 0;
        }
  }
  
  visited[P3(hash,hash2,y*w+x)] = counter;
}

bool solve(){
  int sp[11][11] = {};
  int p[11][11];
  //debug(clock());
  
  scanf("%d%d", &w, &h);

  if(h == 0) return false;


  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%d", p[i]+j);
      sp[i][j] = p[i][j];
    }
  }

  for(int i=h;i>0;i--)
    for(int j=0;j<=w;j++)
      sp[i-1][j] += sp[i][j];

  for(int i=0;i<=h;i++)
    for(int j=w;j>0;j--)
      sp[i][j-1] += sp[i][j];


  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int p = min(h-i, w-j);
      max_size[i][j] = 0;
      for(int k=1;k<=p;k++){
        if(sp[i][j] + sp[i+k][j+k] - sp[i+k][j] - sp[i][j+k] == k*k) max_size[i][j] = k;
        //debug(sp[i][j] + sp[i+k][j+k] - sp[i+k][j] - sp[i][j+k]);
      }
      //debug(max_size[i][j]);
    }
  }

  //debug(clock());

  visited = map<pair<pair<ll,ll>,int>,int >();
  ans = INF;
  dfs(0,0,0,0,0);
  printf("%d\n", ans);

  return true;
}

int main(){
  std::random_device rd;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      t[i][j] = ((ll)rd() << 32) + rd(); 
      t2[i][j] = ((ll)rd() << 32) + rd(); 
    }
  }

  //debug(clock());
  
  while(solve());
  
  return 0;
}



Measured memory_bytes: 3936
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int a, b, c; cin >> a >> b >> c;
    int x, y; cin >> x >> y;

    long cost = 0;
    if (a + b > 2*c) {
        auto t = min(x, y);
        cost += 2 * c * t;
        x -= t;
        y -= t;
    }
    if (x > 0) {
        if (a > 2*c) {
            cost += 2*c*x;
        } else {
            cost += a*x;
        }
    }
    if (y > 0) {
        if (b > 2*c) {
            cost += 2*c*y;
        } else {
            cost += b*y;
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
void solve()
{
    int n; cin>>n;
    n=n%10;
    if(n==0 || n==6 || n==8 || n==1)
    cout<<"pon";
    else if(n==3)
    cout<<"bon";
    else
    cout<<"hon";
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1; //cin>>test;
    int x=1;
    while(test--)
    {
        //cout<<"Case #"<<x++<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

// 提出時にclass Main に書き換え
public class Main {
	public static void main(String[] args)  {
		// 標準入力を受け取る
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(); // int Nを受け取る
		Integer[] a = new Integer[N];
		for(int i=0; i < N; i++) {
			a[i] = sc.nextInt(); // int a[i]を受け取る
		}
		sc.close(); // 標準入力を終了

		// a[i](Integer型配列)を降順にソート
		Arrays.sort(a, Collections.reverseOrder());

		int alice = 0; // アリスの得点
		int bob = 0; // ボブの得点

		for(int i=0; i < N; i++) {
			if(i % 2 == 0) {
				// iが偶数の時は、アリスがカードを取る
				alice += a[i];
			} else {
				// iが偶数の時は、ボブがカードを取る
				bob += a[i];
			}
		}

		// alice - bobを出力
		System.out.println(alice - bob);
	}

}

Measured memory_bytes: 36004
a, b, c = gets.strip.split.map(&:to_i)

cd = []
min = a < b ? a : b
1.upto(100) do |i|
  cd.push(i)  if (a % i) == 0 && (b % i) == 0
  break if min <= i
end

puts cd[cd.size - c]


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int A[N]; rep(i, N){int a; cin >> a; A[i]=a-1;}
    int ans = 0;
    rep(i, N-1) if(A[i] == i){swap(A[i],A[i+1]); ans++;}
    if(A[N-1] == N-1) cout << ans+1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using ll = long long;
const int INF = 100000000, mod = 1000000007;
using namespace std;

ll n, k;
ll cnt[100005];

int main(void) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    for (int ans = 1; ans <= 100000; ans++) {
        if (k <= cnt[ans]) {
            cout << ans << endl;
            break;
        }
        k -= cnt[ans];
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        if(n < 1200){
            System.out.println("ABC");
        }else if(n < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, INF = 0x3f3f3f3f, M = 2e6 + 5;

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])
int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int sm = 0;
	int mn = min(a, k);
	sm += mn;
	k = k - mn;
	mn = min(b, k);
	k = k - mn;
	mn = min(c, k);
	sm = sm - mn;
	cout << sm << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	ll n; cin >> n;
	ll a[n], s, count = 0, sub_count = 0;
	bool flag = false, sub_flag = false;
	Rep(i, n) cin >> a[i];
	int x = 1; s = 0;
	Rep(i, n){
		s += a[i];
		if(s * x <= 0){
			count += abs(s) + 1;
			s = x;
		}
		x *= -1;
	}
	x = -1; s = 0;
	Rep(i, n){
		s += a[i];
		if(s * x <= 0){
			sub_count += abs(s) + 1;
			s = x;
		}
		x *= -1;
	}
	cout << min(count, sub_count) << endl;
	//cout << count << " " << sub_count << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    ll a, b, k;
    cin >> a >> b >> k;

    auto yaru = [](ll &x, ll &y) {
        if (x % 2 != 0)
            x--;
        y += x / 2;
        x /= 2;
    };
    REP(i, k) {
        if (i % 2 == 0) {
            yaru(a, b);
        } else {
            yaru(b, a);
        }
    }
    print(a, b);

    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    
    long long n;
    cin >> n;
    vector<long long> v(6);
    long long mi = 1e15;
    for(int i = 0; i < 5; i++) {
    	cin >> v[i];
    	mi = min(mi, v[i]);
    }
    long long ans = (n + mi - 1) / mi + 4;
    cout << ans << endl;
}

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

int main(){
    int n;
    string str;
    string str2;

    cin >> n;
    cin >> str;
    if(n%2) {
        cout << "No" << endl;
        return 0;
    }
    else
    {
        str2 = str.substr(0,n/2);
        str = str.substr(n/2);
        if(str==str2){
            cout << "Yes";
            return 0;
        }
        else {
            cout << "No";
            return 0;
        }
    }
    
}

Measured memory_bytes: 384
def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

n, k = map(int, input().split())
mod = 10**9+7
ans = 0
k_ = min(n-1, k)
for i in range(k_+1):
    ans += cmb1(n, i, mod) * cmb1(n-i-1+i, i, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 122048
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

template <typename T>
void compression(vector<T> &v)
{
    vector<T> t = v;
    sort(ALL(t));
    t.erase(unique(ALL(t)), t.end());
    for (size_t i = 0; i < v.size(); i++)
    {
        v[i] = distance(t.begin(), lower_bound(ALL(t), v[i]));
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    compression<int>(a);
    int cnt = 0;
    for(int i=0;i<n;i++){
        if((a[i]+1)%2 != (i+1)%2) cnt++; 
    }
    cout << cnt / 2 << endl;
}

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

// Define
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define elif else if
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

// Debug
#define debug(...)                                                             \
    cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                         \
    for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";                   \
    cerr << endl;

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

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

ll N, S, A[1000], B[1000], T = 0;
char C;
signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i] >> B[i];
        if (i) {
            if (((A[i] + B[i]) & 1) != S) {
                T = 1;
            }
        } else {
            S = (A[0] + B[0]) & 1;
        }
    }
    if (T) {
        cout << -1 << endl;
        return 0;
    }
    S = 32 - S;
    cout << S << endl;
    ll M[S];
    M[0] = 1LL << 30;
    rep(i, S) {
        if (i == 31) M[i] = 1;
        else if (i) M[i] = M[i - 1] >> 1;
        if(i) cout << ' ' << M[i];
        else cout << M[i];
    }
    cout << endl;

    rep(i, N) {
        string K = "";
        rep(j, S) {
            if (abs(A[i]) > abs(B[i])) {
                if(A[i] > 0) {
                    K += 'R';
                    A[i] -= M[j];
                } else {
                    K += 'L';
                    A[i] += M[j];
                }
            } else {
                if(B[i] > 0) {
                    K += 'U';
                    B[i] -= M[j];
                } else {
                    K += 'D';
                    B[i] += M[j];
                }
            }
        }
        cout << K << endl;
    }
}

// for compilation: g++ -O3 -o _ _.cpp -std=c++17


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 4000000000;
constexpr auto MOD = 1000000007;

int main() {
	int n;
	cin >> n;
	bool b=true;
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 2)b = false;
		}

	if (b)cout << "second" << endl;
	else cout <<"first"<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A[i]; }

  int64_t answer = 0;
  while (true) {
    bool ok = true;
    rep(i, N) {
      if (A[i] >= N) {
        ok = false;
        int64_t times = A[i] / N;
        answer += times;
        A[i] -= (N * times);
        rep(j, N) {
          if (i != j) A[j] += times;
        }
      }
    }
    if (ok) break;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>

using namespace std;

int main(){
    string S;
    cin >> S;
    string out_S = "";
    for (int i = 4; i < S.size(); i++){
        out_S = out_S + S[i];
    }
    cout << "2018"+out_S << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = input()

w2e = [0] * n
e2w = [0] * n

for i in range(n):
    if i == 0:
        if s[i] == 'W':
            w2e[i] = 1
    else:
        if s[i] == 'W':
            w2e[i] = w2e[i-1] + 1
        else:
            w2e[i] = w2e[i-1]

for i in reversed(range(n)):
    j = n - i - 1
    if j == 0:
        if s[i] == 'E':
            e2w[j] = 1
    else:
        if s[i] == 'E':
            e2w[j] = e2w[j-1] + 1
        else:
            e2w[j] = e2w[j-1]

out = n
for i in range(n):
    if i == 0:
        temp = e2w[n-1]
    elif i == n-1:
        temp = w2e[n-1]
    else:
        temp = w2e[i-1] + e2w[n-i-1]
    if temp < out:
            out = temp

print (out)



Measured memory_bytes: 17644