akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i=0; i<num; i++){
		  array[i] = sc.nextInt();
        }
        int sumL = 0;
        int sumR = 0;
        int min = 100;
        int sub = 0;
        int index = 0;
        for(int i=0; i<num-1; i++){
          sumL = 0;
          sumR = 0;
          for(int j=0; j<num; j++){
            if(j <= index) sumL += array[j];
            else sumR += array[j];
          }
          sub = Math.abs(sumL-sumR);
          //System.out.println(sub);
          if(sub < min) min = sub;
          index++;
        }
		System.out.println(min);
	}
}

Measured memory_bytes: 22740
e = list(map(int, input().split()))
e.sort()

frag = True
for i in range(1, 4):
    if e[0] != e[i]:
        frag = False
        break
for i in range(5, 8):
    if e[4] != e[i]:
        frag = False
        break
for i in range(9, 12):
    if e[8] != e[i]:
        frag = False
        break

print("yes" if frag else "no")

Measured memory_bytes: 7688
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
vector<string> gd={"dream","dreamer","erase","eraser"};
VI cr;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  in n=sz(s);
  cr.resize(n+1,0);
  cr[0]=1;
  forn(i,n){
    if(!cr[i])
      continue;
    forv(j,gd){
      if(sz(gd[j])+i<=n){
	if(s.substr(i,sz(gd[j]))==gd[j])
	  cr[i+sz(gd[j])]=1;
      }
    }
  }
  if(cr[n])
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 1232
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int cost[5];
	
	for (int i = 0; i < 5; i++){
		cin >> cost[i];
	}
	
	int total = min(cost[0], min(cost[1], cost[2])) + min(cost[3], cost[4]);
	total -= 50;
	
	cout << total << endl;
	
	return (0);
}

Measured memory_bytes: 1160
import numpy as np
def p(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
A, B = map(int, input().split())
M = np.min([A, B])
a = p(A)
b = p(B)
t = set(a) & set(b)
print(len(t) + 1)


Measured memory_bytes: 12488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int haikuarray[] = new int[3];
		for(int i = 0; haikuarray.length > i; i++) {
			haikuarray[i] = sc.nextInt();
		}
		sc.close();
		boolean j = retHaiku(haikuarray);
		if(j == true) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

	public static boolean retHaiku(int harray[]) {
		int sevencnt = 0;
		int fivecnt = 0;
		for(int i = 0; harray.length > i; i++) {
			if(harray[i] == 7 && sevencnt == 0) {
				sevencnt++;
			}else if(harray[i] == 5 && fivecnt < 2) {
				fivecnt++;
			}else {
				return false;
			}
		}
		return true;
	}

}

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

int main(){
  int N,K,S;
  cin >> N >> K >> S;
  
  for(int i=0; i<K; i++) cout << S << ' ';
  if(S==1000000000){
    for(int j=0; j<N-K; j++) cout << S-1 << ' ';
  }else{
    for(int j=0; j<N-K; j++) cout << S+1 << ' ';
  }
  return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<algorithm>
using std::max;
#define reg register
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
    reg bool f=false;
    reg char ch=getchar();
    reg int res=0;
    while(ch<'0'||'9'<ch)f|=(ch=='-'),ch=getchar();
    while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
    return f?-res:res;
}
int a,b;
int main(void){
    a=read(),b=read();
    printf("%d\n",max(a-(b<<1),0));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int x, y, s, t, T = 0, tmax = 0, u, U = 0, T1 = 0 , U1 = 0;
  int wa = 0;
  while(1){
    scanf("%d %d %d",&x, &y, &s);
    if(x == 0 && y == 0 && s == 0){
      break;
    }
  
    tmax = 0;
  
    for(t = 1 ; t < s ; t++){	
      for(u = 1 ; u < s ; u++){ 
	T = (t * (100 + x))/100;
	U = (u * (100 + x))/100;
	
	if((T + U) == s){
	  T1 = (t*(100 + y))/100;
	  U1 = (u*(100 + y))/100;
	  if((T1 + U1) > tmax){
	    tmax = (T1 + U1);
	  }
	}
      }
    }
    
    printf("%d\n",tmax);
  }
}

Measured memory_bytes: 600
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {
	static int[] vx = new int[]{0,1,0,-1};
	static int[] vy = new int[]{1,0,-1,0};
	static int[] Y  = new int[]{0,0,0,1,1,1,2,2,2};
	static int[] X  = new int[]{0,1,2,0,1,2,0,1,2};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			int[] p = new int[n];
			for(int i = 0; i < n; i++) {
				p[i] = sc.nextInt();
			}
			Arrays.sort(p);
			for(int i = 0; i < n-1; i++) {
				p[i+1] += p[i];
			}
			int sum = 0;
			for(int i = 0; i < n; i++) {
				sum += p[i];
			}
			System.out.println(sum);
		}
		
	}
 }

Measured memory_bytes: 37636
#include <bits/stdc++.h>
using namespace std;
int h[100000];
int main() {
	int n,k;
	cin >> n>>k;
	vector < int > dp(n+3,1e9);
	dp[0]=0;
	for (int i=0;i<n;i++) {
		cin>>h[i];
	}
	for(int i=0;i<n;i++) {
		for(int j=i+1;j<n && j<=i+k;j++)
		dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> matrix;

ll fast(string s) {
  vector<char> v;
  ll ret = 0;
  for(int i = 0; i < s.size(); i++) {
    v.push_back(s[i]);
    if(v.size() == 1 && v[0] != 'A') v.clear();
    if(v.size() >= 2) {
      if(v[v.size()-2] == 'A' && v[v.size()-1] == 'C') v.clear();
      else if(v[v.size()-2] == 'B' && v[v.size()-1] == 'A') v.clear();
      else if(v[v.size()-2] == 'B' && v[v.size()-1] == 'B') v.clear();
      if(v.empty()) {
        v.push_back(s[i]);
      }
    }
    if(v.size() == 1 && v[0] != 'A') v.clear();
    if(v.size() >= 2) {
      if(v[v.size()-2] == 'B' && v[v.size()-1] == 'C') {
        v.pop_back();
        v.pop_back();
        ret += v.size();
      }
    }
  }
  return ret;
}

ll slow(string s) {
  vector<char> v;
  for(int i = 0; i < s.size(); i++) {
    v.push_back(s[i]);
  }
  ll ret = 0;
  while(true) {
    bool upd = false;
    for(int i = 0; i + 2 < s.size(); i++) {
      if(v[i] == 'A' && v[i+1] == 'B' && v[i+2] == 'C') {
        upd = true;
        v[i] = 'B';
        v[i+1] = 'C';
        v[i+2] = 'A';
        ret++;
      }
    }
    if(!upd) break;
  }
  return ret;
}

void solve() {
  string s;
  cin >> s;
  cout << fast(s) << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 1044
N = int(input())
A = list(map(int, input().split()))

B = [0] * N
if N % 2 == 0:
  for i in range(N):
    if i % 2 == 0:
      B[N//2+i//2] = A[i]
    else:
      B[N//2-(i//2+1)] = A[i]
else:
  for i in range(N):
    if i % 2 == 1:
      B[N//2+(i//2+1)] = A[i]
    else:
      B[N//2-(i//2)] = A[i]

print(*B)

Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,n,count=0;
    cin>>h>>n;
    vint a(n);
    rep(i,n){
        cin>>a[i];
        count+=a[i];
    }
    if(count>=h){
        cout<<"Yes"<<'\n';
    }
    else{
        cout<<"No"<<'\n';
    }
    return(0);
}

Measured memory_bytes: 640
s = input()
a1 = int(s[:2])
a2 = int(s[2:])
if a1 in range(1, 13):
  if a2 in range(1, 13): print("AMBIGUOUS")
  else: print("MMYY")
else:
  if a2 in range(1, 13): print("YYMM")
  else: print("NA")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

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;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N),b(N);
    rep(i,N){
        a[i]=N*i+1;
        b[N-1-i]=N*i+1;
    }
    rep(i,N){
        ll p;
        cin >> p;
        p--;
        a[p]+=i;
        b[p]+=i;
    }
    rep(i,N){
        cout << a[i];
        if (i!=N-1){
            cout << ' ';
        }
        else {
            cout << endl;
        }
    }
    rep(i,N){
        cout << b[i];
        if (i!=N-1){
            cout << ' ';
        }
        else {
            cout << endl;
        }
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

int gcd(int a, int b){
    if(b==0) return a;
    else return gcd(b, a%b);
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    std::vector<int> a(n); rep(i,n) cin >> a[i];

    // 12 15 18
    // 2^2 3^1
    // 2^0 3^1 5^1
    // 2^1 3^2
    //
    // 2^1 3^1 

    std::vector<int> left(n); left[0] = a[0];
    std::vector<int> right(n); right[n-1] = a[n-1];

    int cur = 1;
    for(int i=1; i<n; ++i){
        left[i] = gcd(left[i-1], a[i]);
    }

    for(int i=n-1; i>=0; --i){
        right[i] = gcd(right[i+1], a[i]); 
    }

    // rep(i,n) cout << left[i] << " ";
    // cout << '\n';

    // rep(i,n) cout << right[i] << " ";
    // cout << '\n';

    int mx = 1;

    for(int i=1; i<n-1; ++i){
        mx = max(mx, gcd(left[i-1], right[i+1]));
    }

    cout << max(max(mx, left[n-2]), right[1]) << endl;
    

    return 0;
}

Measured memory_bytes: 1408
def main():

    A, B, K = map(int, input().split())
    m = min(A, B)

    count = 0
    for i in range(m, 0, -1):
        if A % i == 0 and B % i == 0:
            count += 1
            if count == K:
                print(i)
                break


main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
char s[N];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int tot=0;
	LL ans=0;
	for (int i=1;i<=n;i++){
		if (s[i]=='W')
			ans+=tot;
		else
			tot++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    set<string> s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string tmp;
        cin>>tmp;
        s.insert(tmp);
    }

    cout<<s.size()<<endl;
    
    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<pair<int, int> > pairs(n);
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x; cin >> y;
		pairs[i].first = x;
		pairs[i].second = y;
	}
	int cnt = 0;
	bool flag = false;
	for (auto x : pairs) {
		if (x.first == x.second) {
			cnt++;
			if (cnt >= 3) {
				flag = true;
				break;
			}
		}
		else
			cnt = 0;
	}
	if (flag)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<tuple>
using namespace std;
int H, W, x[102][102], sx, sy, gx, gy, dist[102][102][32];
vector<pair<int, int>>vec;
queue<tuple<int, int, int>>Q;
int main() {
	cin >> W >> H;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			char c; cin >> c;
			if (c == '.')x[i][j] = 1;
			if (c == '#')x[i][j] = 9;
			if (c == 'S') { x[i][j] = 1; sx = i; sy = j; }
			if (c == 'G') { x[i][j] = 1; gx = i; gy = j; }
			if (c == 'M') { x[i][j] = 1; vec.push_back(make_pair(i, j)); }
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (x[i][j] != 9)continue;
			for (int k = -2; k <= 2; k++) {
				for (int l = -2; l <= 2; l++) {
					int cx = i + k, cy = j + l;
					if (cx <= 0 || cx > H || cy <= 0 || cy > W)continue;
					x[cx][cy] = max(x[cx][cy], 4 - max(abs(k), abs(l)));
				}
			}
		}
	}
	for (int i = 0; i < 102; i++) { for (int j = 0; j < 102; j++) { for (int k = 0; k < 32; k++)dist[i][j][k] = 999999999; } }
	Q.push(make_tuple(sx, sy, 0)); dist[sx][sy][0] = 0;
	while (!Q.empty()) {
		int a1 = get<0>(Q.front()), a2 = get<1>(Q.front()), a3 = get<2>(Q.front()); Q.pop();
		int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
		for (int i = 0; i < 4; i++) {
			int cx = a1 + dx[i], cy = a2 + dy[i];
			if (cx <= 0 || cx > H || cy <= 0 || cy > W)continue;
			if (x[cx][cy] == 9)continue;
			int a4 = dist[a1][a2][a3] + x[a1][a2];
			int a5 = a3;
			for (int j = 0; j < vec.size(); j++) {
				if (vec[j].first == cx && vec[j].second == cy && (a3 / (1 << j)) % 2 == 0)a5 += (1 << j);
			}
			if (dist[cx][cy][a5] > a4) {
				dist[cx][cy][a5] = a4; Q.push(make_tuple(cx, cy, a5));
			}
		}
	}
	cout << dist[gx][gy][(1 << vec.size()) - 1] << endl;
	return 0;
}

Measured memory_bytes: 4576
#include <iostream>
#include <vector>
#include <cstdlib>
#include<set>
#include <map>
using namespace std;


   
#include <iostream>

using namespace std;

int main()
{
   char s;
   cin >> s;

   if (isupper(s))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }

   return 0;
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll q,k;
vector<int> to[100010];
map<pair<int,int>, ll> mli;
map<int, ll> ans;
void solve(int i, int p, ll now){
    //cout << i << "start " << now << endl;
    for(auto u : to[i]){
        if(u == p) continue; 
        //if( i == 0 )cout << "Yes" << endl;
        ans[u] = now + mli[{i,u}];
        solve(u,i,now + mli[{i,u}]); 
    }
} 
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    rep(i,n-1){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        mli[{a,b}] = c;
        mli[{b,a}] = c;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    cin >> q >> k;
    k--;
    solve(k,-1,0);
    rep(i,q){
        int x,y;
        cin >> x >> y;
        x--; y--;
        cout << ans[x] + ans[y] << endl;
        //cout << ans[x] <<" " <<ans[y] << " ok?" <<endl;
    }
    //cout << ans[2] << endl;
    return 0;
}

Measured memory_bytes: 38780
Imports System

Public Class Program

    Public Shared Sub Main(args As String())

        Dim Input As String = Console.ReadLine

        Dim cnt As Integer = 0

        For i As Integer = 0 To Math.Floor(Input.Length / 2) - 1
            If Not (Input(i) = Input(Input.Length - i - 1)) Then
                cnt += 1
            End If
        Next

        Console.WriteLine(cnt)

    End Sub
End Class

Measured memory_bytes: 11092
#!/usr/bin/env ruby

result = []
while true do
    number = gets.to_i
    if number == 0 then
        break
    end
    points = gets.split.map(&:to_f)
    nijou = 0;ave = 0
    variance = 0

    points.each do |p|
        nijou +=  p ** 2
        ave += p
    end

    ave = (ave / number) ** 2
    nijou = nijou / number

    variance = nijou - ave
    standard_deviation = (variance) ** 0.5
    result << standard_deviation
end
puts result


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  string S; cin >> S;

  map<char,ll> m;
  for(auto c: S){
    m[c]++;
  }

  ll ans = m['R'] * m['G'] * m['B'];

  for(int j = 1; j < N-1; j++){
    for(int p = 1; (j-p>=0) && (j+p<N); p++){
      if(S[j] != S[j-p] && S[j] != S[j+p] && S[j-p] != S[j+p]){
        ans--;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3644
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  ll X[N], Y[N], H[N];
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> H[i];


  for (int cx = 0; cx <= 100; cx++){
    for (int cy = 0; cy <= 100; cy++){
      ll h;
      for (int i = 0; i < N; i++){
        if (H[i] > 0){
          h = H[i] + abs(X[i] - cx) + abs(Y[i] - cy);
          break;
        }
      }

      bool flag = true;
      for (int i = 0; i < N; i++){
        if (H[i] == 0){
          if (h - abs(X[i] - cx) - abs(Y[i] - cy) > 0) flag = false;
          continue;
        }

        ll now = H[i] + abs(X[i] - cx) + abs(Y[i] - cy);
        if (h != now) flag = false;
      }
      if (flag){
        cout << cx << " " << cy << " " << h << endl;
        return 0;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
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; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr ,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,0 }, dy[] = { 1,0,-1,0,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q,D;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE3][SIZE3], answer = zero;
LL A[SIZE], B[SIZE];
bool used[11];
inline LL dist(LL a,LL b) {
	return abs(a / 3 - b / 3) + abs(a % 3 - b % 3);
}
LL solve() {
	cin >> N >> D;
	LL maxim = 0;
	LL existing = 0;
	REP(i,N){
		cin >> A[i];
		A[i] -= 1;
		A[i] %= D + 1;
		if (A[i]) existing++;
		MX(maxim, A[i]);
	}
	if (maxim == 0) {
		return 1;
	}
	else {
		LL ans = 0;
		REP(i, N) {
			ans ^= A[i];
		}
		if (ans == 0) return 0;
		return 1;
	}

	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cout << three(solve(), "First", "Second") << endl;
//	cin >> N;
	return 0;
}


Measured memory_bytes: 12200
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

make :: B.ByteString -> VU.Vector (Int, Int)
make bs = VU.scanl' step (0,0) (VU.fromList $ B.unpack bs)
    where
        step (a,b) c
            | c == 'W' = (a + 1, b)
            | otherwise = (a, b + 1)

solve :: VU.Vector (Int, Int) -> (Int, Int) -> B.ByteString -> Int -> Int
solve vec (a, b) bs i
    | VU.null vec = 10^9
    | otherwise = min res (solve (VU.tail vec) (a, b) bs (i + 1))
        where
            curr = B.index bs i
            (lw, le) = VU.head vec
            (rw, re) = (a-lw, b-le) 
            res = if curr == 'W' then lw - 1 + re else lw + re

main = do
    n <- readLn :: IO Int
    s <- B.getLine
    let m = make s
    print $ solve (VU.tail m) (VU.last m) s 0

Measured memory_bytes: 47868
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    char ch[n];
    cin>>ch;

    for(int i=0; i<n; i++)
    {
        if(i==k-1)
        {
            char c=ch[i]+32;
            cout<<c;
        }
        else cout<<ch[i];
    }
    cout<<endl;
    return 0;

}

Measured memory_bytes: 256
// ------------------
// author: MatsuTaku
// date  : 22/02/2020
// ------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,M; cin>>N>>M;
  vector<unsigned int> l_mask(M, 0);
  for (int i = 0; i < M; i++) {
    int k; cin>>k;
    for (int j = 0; j < k; j++) {
      int s; cin>>s;
      l_mask[i] |= 1<<(s-1);
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin>>p[i];
  }

  int ans = 0;
  for (int s = 0; s < (1<<N); s++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      auto mask = s&l_mask[i];
      int popcnt = 0;
      for (int t = 0; t < N; t++) {
        if (mask & (1<<t))
          popcnt++;
      }
      if (popcnt%2 != p[i]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    ll offset;
    vector< vector<ll> > que(4);
    rep(i, 0, N){
        cin >> w[i] >> v[i];
        if(i == 0) offset = w[0];
        w[i] -= offset;
        que[w[i]].push_back(v[i]);
    }
    for(auto &e : que) sort(e.begin(), e.end(), greater<ll>());
    vector< vector<ll> > acc(4, vector<ll> (200, 0));
    rep(i, 0, 4){
        rep(j, 0, que[i].size()) acc[i][j+1] = acc[i][j] + que[i][j];
    }
    ll ans = 0;
    rep(i, 0, que[0].size()+1){
        rep(j, 0, que[1].size()+1){
            rep(k, 0, que[2].size()+1){
                rep(l, 0, que[3].size()+1){
                    ll weight = (i+j+k+l) * offset + j + 2*k + 3*l;
                    ll value = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l];
                    if(weight > W) continue;
                    ans = max(ans, value);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

def main():

    a=input()
    a2=[int(x) for x in list(str(a))]
    c=int(0)
    
    for b in a2:
        c=c+b

    if int(a)%c == 0:
        print("Yes")
    else:
        print("No")
    
if __name__ == '__main__':
    main()

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n,m;
  	ci(n>>m);
  vll A(n);
  vpll B(m);
  FOR(i,0,n){
    ci(A[i])
  }
  
  SORT(A);
  
  FOR(i,0,m){
    ci(B[i].se)
    ci(B[i].fi)
  }
  
  SORT(B);
  REV(B);
  ll nowa=0;
  ll nowb=B[0].se;
  FOR(i,0,n){
    if(A[i]<B[nowa].fi){
      A[i]=B[nowa].fi;
      nowb--;
    }
    else{
      break;
    }
    
    if(nowb==0){
      nowa++;
	  nowb=B[nowa].se;
    }
  }
  
  ll ans=0;
  FOR(i,0,n){
    ans+=A[i];
  }
  co(ans)
    
}


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

#define OM ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define pi 3.14159265358979323846

typedef long long ll;

/*LETS BEGIN WITH THE NAME OF MAHADEV*/

int main(){
	OM;
	char ch;
	ll res = 0;
	while(cin >> ch)
		res += ch - '0';
	if(res % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    string first = s.substr(0,2);
    string second = s.substr(2,2);
    if ("01"<=first && first <= "12" && "01"<=second && second <= "12") cout << "AMBIGUOUS" << endl;
    else if(second!="00" && second<"13") cout << "YYMM" << endl;
    else if (first!="00" && first<"13") cout << "MMYY" << endl;
    else cout << "NA" << endl;
}



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

using namespace std;

int main() {
    int n, m;   cin >> n >> m;
    int cities[50] = {};
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        cities[a-1]++;
        cities[b-1]++;
    }
    for (int i = 0; i < n; i++) cout << cities[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define fi first
#define se second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> p(n),a(n),b(n);
    rep(i,n){
        cin>>p.at(i);
        a.at(i)=i+1;
        b.at(i)=n-i;
    }
    for(int i=1; i<n; i++){
        for(int j=p.at(i)-1; j<n; j++){
            a.at(j)+=i;
        }
        for(int j=p.at(i)-1; j>=0; j--){
            b.at(j)+=i;
        }
    }
    rep(i,n-1)cout<<a.at(i)<<' ';
    cout<<a.back()<<endl;
    rep(i,n-1)cout<<b.at(i)<<' ';
    cout<<b.back()<<endl;
}


Measured memory_bytes: 1152
#!/usr/bin/perl

use strict;
use warnings;

chomp(my $in = <STDIN>);
my($a, $b) = split(" ", $in);
my $gcd = gcd($a, $b);
my $ans = ($a/$gcd*$b);
print "$ans\n";

sub gcd {
    my ($x, $y) = @_;

    my $c;

    while ($x > 0 && $y > 0) {
        if ($y > $x) {
            $c = $x;
            $x = $y;
            $y = $c;
        }
        $c = $y;
        $x = $x - $y;
        $y = $c;
    }
    return $c;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

int main()
{
    int n, p;
    double average = 0;
    long long int power = 0;
    int x[100];

    scanf("%d", &n);

    for (int i = 0; i<n; i++)
    {
        scanf("%d", &x[i]);

        average += (double)x[i];
    
    }

    p = (int)(average/n + 0.5);

    for (int i = 0; i<n; i++)
    {
        power += (x[i] - p)*(x[i] - p);
    }

    printf("%lld", power);

    return 0;
}

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

int main() {
  int A,B;
  int C[5];
  int sum=0;
  cin >> A >> B;
  for(int i=A;i<=B;i++){
    int As=i;
    C[0]=As%10;
    C[1]=(As/10)%10;
    C[2]=(As/100)%10;
    C[3]=(As/1000)%10;
    C[4]=As/10000;
    if(C[0]==C[4]){
      if(C[1]==C[3]){
        sum++;
      }
    }
    
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxS = 5000;

string s;
int K;
string ans;

signed main() {
  cin >> s;
  cin >> K;

  vector<string> ss;
  REP(i, s.length()) {
    REP(j, K) {
      if (i+j < s.length()) { ss.push_back(s.substr(i, j+1)); }
    }
  }
  sort(ss.begin(), ss.end());
  auto r = unique(ss.begin(), ss.end());
  ans = ss[K-1];

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1660
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 1005, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n,m,dp[N][N];
char g[N][N];

int main() {
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
        scanf("%s",g[i]);
    dp[n-1][m-1] = 1;
    for(int i=n-1; i>=0; i--) {
        for(int j=(i==n-1 ? m-2 : m-1); j>=0; j--) {
            if(g[i][j]=='#') continue;
            if(i+1<n && g[i+1][j]=='.') dp[i][j] = (dp[i][j] + dp[i+1][j])%MOD;
            if(j+1<m && g[i][j+1]=='.') dp[i][j] = (dp[i][j] + dp[i][j+1])%MOD;
        }
    } 
    printf("%d\n", dp[0][0]);
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Union Find Tree
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/DSL_1_A
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
ll n, q, com, x, y;
vll P;

// Union-Find Treeを初期化する
void init() {
  rep(i, n) { P.push_back(i); }
}

// 根の値を返す
ll root(ll x) {
  if (P[x] == x) { return x; }
  return (P[x] = root(P[x])); // パス圧縮しつつ返す
}

// 木を結合する（rankはとりあえず無視）
void unite(ll x, ll y) { P[root(x)] = root(y); }

// クエリを処理する．
void solve() {
  if (com == 0) {
    unite(x, y);
  } else {
    if (root(x) == root(y)) {
      cout << "1" << endl;
    } else {
      cout << "0" << endl;
    }
  }
}

int main() {
  cin >> n >> q;
  init();
  rep(i, q) {
    cin >> com >> x >> y;
    solve();
  }
  return 0;
}



Measured memory_bytes: 3348
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\135\\B'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'


class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class B(Common):

    def resolve(self):

        N = int(self.input_data())
        seq = [int(i) for i in self.input_data().split()]

        diff = []
        result = "NO"

        for i in range(N):
            if seq[i] != i+1:
                if len(diff) < 2:
                    diff.append([i+1, seq[i]])
                else:
                    break
        else:
            if len(diff) == 0:
                result = "YES"
            if len(diff) == 2:
                if diff[0][0] == diff[1][1] and diff[0][1] == diff[0][1]:
                    result = "YES"

        print(result)


solver = B(REL_PATH)
solver.exec_resolve()


Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

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 U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N < 10) {
		//1桁
		cout << N << endl;
	}else if (N < 100) {
		//2桁
		cout << 9 << endl;
	}else if (N < 1000) {
		//3桁
		cout << 9 + N - 99 << endl;
	}
	else if (N < 10000) {
		//4桁
		cout << 909 << endl;
	}
	else if( N < 100000){
		//5桁
		cout << 909 + N - 9999 << endl;
	}
	else {
		cout << 90909 << endl;
	}
	return 0;
}


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

int main() {
	int n,a,b; cin >> n >> a >> b;

	int ans = 0;
	for (int i=1; i<=n; ++i) {
		int c = 0;
		int tmp = i;
		for (int j=0; j<5; ++j) {
			c += tmp%10;
			tmp /= 10;
		}
		if (a<=c && c<=b) ans+=i;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include "iostream"

using namespace std;

int main()
{
	for (int i = 1; i < 10; i++)
	{
		for (int c = 1; c < 10; c++)
		{
			cout << i << "x" << c << "=" << i*c << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2984
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

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

    if(n==0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }


    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

		while (sc.hasNext()) {
			String x = sc.next();
			int sum = 0;
			char[] str1 = x.toCharArray();
			for (int i = 0; i < str1.length; i++) {
				sum += Character.getNumericValue(str1[i]);
			}

			if (x.equals("0")) {
				break;
			}
			System.out.println(sum);
		}

	}

}

Measured memory_bytes: 27028
#include<bits/stdc++.h>
//#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 100010, mod = 2147483647;
const double PI=3.1415926;
signed main()
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);
	int n;
	//double n;

	scanf("%d",&n);

	printf("%.2lf",2 * (double) n * PI);
	return 0;

}

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

int a[100010] = {0};

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int k;
        cin >> k;
        a[k] = i;
    }

    for (int i = 1; i <= n; i++){
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef struct {
    int plus, pos;
} Dungeon;

bool operator < (const Dungeon &a, const Dungeon &b)
{
    if (a.plus != b.plus){
        return (a.plus < b.plus);
    }
    else {
        return (a.pos < b.pos);
    }
}
int data[1 << 18], datb[1 << 18];

void add(int a, int b, int x, int k, int l, int r)
{
    if (a <= l && r <= b){ //comletely inclusive.
        data[k] += x; //add to all segmets corresponds to [l, r).
    }
    else if (l < b && a < r){ //some of the segments are inclusive.
        datb[k] += (min(b, r) - max(a, l)) * x;  //add the x to the segments that belongs to [max(a, l), min(r, b)).
        add(a, b, x, k * 2 + 1, l, (l + r) / 2); //go to the left vertex.
        add(a, b, x, k * 2 + 2, (l + r) / 2, r); //go to the right vertex.
    }
}

//*
int sum(int a, int b, int k, int l, int r)
{
    if (b <= l || r <= a){ //looking segment[l, r) cross with the segment [a, b).
        return (0);
    }
    else if (a <= l && r <= b){ //completely inclusive.
        return (data[k] * (r - l) + datb[k]);
    }
    else { //some of the segments are inclusive.
        ll res;
        res = (min(b, r) - max(a, l)) * data[k];
        res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
        res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
        return (res);
    }
}
//*/

int main(void)
{
    int N, H;
    int di[100000], hi[100000];
    int curLife;
    
    scanf("%d%d", &N, &H);
    
    for (int i = 0; i < N - 1; i++){
        scanf("%d%d", &di[i], &hi[i]);
    }
    
    curLife = H;
    
    ll ans = 0;
    priority_queue<Dungeon> que;
    for (int i = 0; i < N - 1; i++){
        add(i, i + 1, curLife, 0, 0, 1 << 17);
        Dungeon in;
        curLife -= di[i];
        
        in.plus = hi[i];
        in.pos = i;
        
        que.push(in);
        while (curLife <= 0){
            Dungeon heal = que.top();
            que.pop();
            
            /* O(logN)
            int segMax = getMax(heal.pos, i + 1, 0, 0, 1 << 17);
            //*/
            
            //* O(NlogN)
            int segMax = 0;
            for (int j = heal.pos; j <= i; j++){
                segMax = max(segMax, sum(j, j + 1, 0, 0, 1 << 17));
            }
            //*/
            
            if (heal.plus + segMax > H){
                heal.plus = H - segMax;
                que.push(heal);
                continue;
            }
            
            int howMany = min((-1 * curLife) / heal.plus + 1, (H - segMax) / heal.plus);
            ans += howMany;
            curLife += howMany * heal.plus;
            
            add(heal.pos, i + 1, howMany * heal.plus, 0, 0, 1 << 17);
            que.push(heal);
        }
    }
    
    printf("%lld\n", ans);
    
    return (0);
}

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

#define int long long
#define all(v) begin(v), end(v)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)

const int INF=11;

int n;


int keta(int n){
  int cnt=0;
  while(n){
    n/=10;
    cnt++;
  }
  return cnt;
}
signed main(){
  cin>>n;
  int temp=INF;
  int memo=-1;
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      int ret=keta(n/i);
      if(ret<temp){
        memo=ret;
      }
    }
  }


    cout<<memo<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

//ただの辺
struct edge {
    using lint = long long int;
    int to;
    lint cost;
    edge(lint t, lint c) : to(t), cost(c) {
    }
};

// dijkstra
// depend:edge
vector<long long int> dijkstra(vector<vector<edge>> g, int start) {
    using lint = long long int;
    int n = g.size();
    vector<lint> res(n, LLONG_MAX);
    res[start] = 0;
    // first:距離、second:行き先
    priority_queue<pair<lint, lint>, vector<pair<lint, lint>>,
                   greater<pair<lint, lint>>>
        pq;
    pq.push({0, start});
    while (!pq.empty()) {
        lint dist = pq.top().first, now = pq.top().second;
        pq.pop();
        if (res[now] < dist) continue;
        for (int i = 0; i < (int)g[now].size(); i++) {
            edge e = g[now][i];
            if (res[e.to] > res[now] + e.cost) {
                res[e.to] = res[now] + e.cost;
                pq.push(make_pair(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> key(m, 0);
    for (int i = 0; i < m; i++) {
        int b;
        cin >> a[i] >> b;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            c--;
            key[i] += 1 << c;
        }
    }
    vector<vector<edge>> g((1 << n));
    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < m; j++) {
            g[i].push_back(edge(i | key[j], a[j]));
        }
    }
    vector<lint> cost = dijkstra(g, 0);
    if (cost[(1 << n) - 1] == LLONG_MAX) {
        cout << -1 << endl;
    } else {
        cout << cost[(1 << n) - 1] << endl;
    }
}

Measured memory_bytes: 130304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll N, M;
vi X;

int main()
{
    cin >> N >> M;
    X = vi(M);
    REP(i, M)
    {
        cin >> X[i];
    }
    SORT(X);

    vi D = vi(M - 1);
    REP(i, M - 1)
    {
        D[i] = X[i + 1] - X[i];
    }
    SORT(D);
    ll ans = 0;
    REP(i, M - N)
    {
        ans += D[i];
    }

    OUT(ans);
}

Measured memory_bytes: 1792
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

const long double eps = 1e-9;
const long double PI = acos(-1);

void solve() {
	long double a, b, x;
	cin >> a >> b >> x;
	
	x /= a; /// turn this to 2D
	
	const long double val = 2.0 * (b - x / a) / a;
	
	/*
	long double lo = 0.0, hi = 90.0, mi;
	while (fabs(lo - hi) > eps) {
		/// x/a + a*tan0/2 > b ---> poured ///
		mi = (lo + hi) / 2.0;
		
		if (tan(mi * PI / 180.0) > )
		if (tan(mi * PI / 180.0) > val) {
			hi = mi;
		}
		else {
			lo = mi;
		}
	}
	*/
	
	cout << fixed << setprecision(9);
	// cout << mi << "\n";
	
	if (2.0 * x < a * b) cout << atan((b * b) / (2.0 * x)) * 180.0 / PI << "\n";
	else cout << atan(val) * 180.0 / PI << "\n";
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <queue>
#include <algorithm>
using namespace std;

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;
    
    typedef pair<int, int> P;
    vector<P> v(m);
    int s, t;
    for (int i = 0; i < m; i ++) {
        cin >> s >> t;
        v[i] = make_pair(t, s);
    }
    sort(v.begin(), v.end());

    int now = 0;
    int count = 1;
    for (int i = 1; i < m; i ++) {
        if (v[now].first <= v[i].second) {
            now = i;
            count ++;
        }
    }

    cout << count << endl;
    return 0;
}

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

using namespace std;

int main(){

	int d,n,m;

	while(cin >> d && d != 0){
		int storePlace[100001];

		cin >> n >> m;
		storePlace[0] = 0;
		storePlace[n] = d;
		for(int i = 1; i < n; i++){
			int tmp;
			cin >> tmp;
			storePlace[i] = tmp;
		}
		sort(storePlace,storePlace+n+1);
		// vZJn
		int sumCost = 0;
		for(int i = 0; i < m; i++){
			int place;
			cin >> place;
			// ezBêÉàÁÆàß¢XÜðñªTõÅT·
//			int *ub = upper_bound(storePlace,storePlace+n+1,place);
			int *lb = lower_bound(storePlace,storePlace+n+1,place);
			// ÊªêvµÈ©Á½êAß¢Ù¤ð©¦·
			if(place != *lb){
				int *pp = lb--;
				sumCost += min(abs(place - *lb),abs(place - *pp));
			}
		}
		cout << sumCost << endl;
	}

	return 0;
}

Measured memory_bytes: 1256
N = int(input())
A = [int(i) for i in input().split()]

def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1, 0, -1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i-1]
                A[i-1] = tmp
                flag = 1
                count += 1
    return A, count

A, count = bubbleSort(A, N)
print(' '.join([str(i) for i in A]))
print(count)

Measured memory_bytes: 7664
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
B=[[0 for x in range(N+1)] for y in range(N)]
for i in range(N):
    B[i][i+1]=A[i]
for l in range(1,N):
    for i in range( N-l):
        B[i][i+l+1]=max(A[i]-B[i+1][i+l+1], A[i+l] - B[i][i+l]  )
print B[0][N]
#for ll  in B:
#    print ll


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

int main(){
  int a,b,c,x;
  int counter=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x) counter++;
      }
    }
  }
  cout<<counter<<endl;

}


Measured memory_bytes: 256