akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    set<int>prime;
    map<int,int>primeMap;
    prime.insert(2);
    prime.insert(3);
    prime.insert(5);
    prime.insert(7);
    for(int i=1;i<=n;i++){
      int tmp = i;
      for(int p:prime){
        while(tmp % p == 0){
          tmp /= p;
          primeMap[p]++;
        }
      }
      if(tmp > 1){
        primeMap[tmp]++;
        prime.insert(tmp);
      }
    }

    int ans = 0;
    for(int i:prime){
      if(primeMap[i] >= 74)ans++;
    }
    for(int i:prime){
      for(int j:prime){
        if(i!=j){
          if(primeMap[i] >= 24 && primeMap[j] >= 2)ans++;
        }
      }
    }

    for(int i:prime){
      for(int j:prime){
        if(i!=j){
          if(primeMap[i] >= 14 && primeMap[j] >= 4)ans++;
        }
      }
    }
    
    for(int i:prime){
      for(int j:prime){
        for(int k:prime){
          if(i<j && j!=k && k!=i){
            if(primeMap[i] >= 4 && primeMap[j] >= 4 && primeMap[k] >= 2)ans++;
          }
        }
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

double dp[51][5001];

int main(){
	int x, y, z;
	int v[4] = {};
	int n, e[51] = {}, a[51] = {};

	while(scanf("%d%d%d", &x, &y, &z), x){
		for(int i = 0; i <= y; ++i){
			e[i] = a[i] = 0;
			for(int j = 0; j <= 5000; ++j){
				dp[i][j] = 0.0;
			}
		}

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

		dp[0][0] = 1.0;
		for(int i = 0; i < y; ++i){
			for(int j = 0; j < 5000; ++j){
				if(dp[i][j] == 0.0) continue;
				double prv = dp[i][j] / x;

				for(int k = 0; k < x; ++k){
					int to = min(i + v[k], y);
					int c = j;
					if(e[to] == 1){
						to = min(to + a[to], y);
					}
					else if(e[to] == 2){
						c += a[to];
					}
					else if(e[to] == 3){
						c = max(c - a[to], 0);
					}
					
					dp[to][c] += prv;
				}
			}
		}
		
		double ans = 0.0;
		for(int i = 0; i <= 5000; ++i){
			ans += dp[y][i] * i;
		}
		printf("%d\n", (int)ans);
	}
}

Measured memory_bytes: 3020
#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 F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#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;

class UnionFindS{
private:
    vector<int> par;
public:
    UnionFindS(int n){
        par=vector<int>(n,-1);
    }
    int find(int x){
        if(par.at(x)<0) return x;
        else return par.at(x)=find(par.at(x));
    }
    int size(int x){
        return -par.at(find(x));
    }
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(size(x)<size(y)) swap(x,y);
        par.at(x)+=par.at(y);
        par.at(y)=x;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

signed main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> vec(m);
    rep(i,n){
        int k; cin>>k;
        rep(j,k){
            int l; cin>>l;
            vec.at(l-1).push_back(i);
        }
    }
    UnionFindS uni(n);
    rep(i,m){
        rep(j,vec.at(i).size()){
            if(j)uni.unite(vec.at(i).at(j-1),vec.at(i).at(j));
        }
    }
    cout<<(uni.size(0)==n?"YES":"NO")<<endl;
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int A = scanner.nextInt();
		    int B = scanner.nextInt();
		    
		    if(A + B >= 24)
		    {
		    	System.out.println(A + B - 24);
		    }
		    else 
		    {
		    	System.out.println(A + B);
		    }
		    scanner.close(); }
		  }

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

using namespace std;

#define push_back

typedef pair <int, int> pii;

const int maxn = 60, maxans = 1e5;
int n, k, a[maxn], ans[maxans], answer;
bitset <maxn> mark;

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i <= k; ++i) {
		pii mn = {1e5, 0};
		for (int j = 0; j < n; ++j)
			if (!mark[j])
				mn = min(mn, {a[j], j});
		if (mn.first <= 0)
			return cout << "-1\n", 0;
		for (int j = 0; j < n; ++j)
			if (!mark[j] && j != mn.second) {
				ans[answer++] = j + 1;
				a[j]--;
			}
		a[mn.second]--;
		ans[answer++] = mn.second + 1;
		mark.reset();
		mark[mn.second] = true;
	}
	cout << answer << '\n';
	for (int i = 0; i < answer; ++i)
		cout << ans[i] << ' ';
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Power Calculus
public class Main{

	int n;
	int[] k;
	boolean[] u;

	boolean reach(long b, long x, int rest){
		long r = b+x;
		while(rest--!=0)r+=r;
		return n<=r;
	}

	boolean dfs(int d, int x, int max, int len){
		if(d==0){
			return u[n];
		}
		if(d==1){
			return u[Math.abs(x-n)];
		}
		for(int i=len-1;i>=0;i--){
			int s = k[i]+x;
			if(!(2*n<s||u[s]||!reach(s, Math.max(max, s), d-1))){
				u[s] = true;
				k[len] = s;
				if(dfs(d-1, s, Math.max(max, s), len+1))return true;
				u[s] = false;
			}
			s = x-k[i];
			if(!(s<0||!reach(s, max, d-1)||u[s])){
				u[s] = true;
				k[len] = s;
				if(dfs(d-1, s, max, len+1))return true;
				u[s] = false;
			}
			s = k[i] - x;
			if(!(s<0||!reach(s, max, d-1)||u[s])){
				u[s] = true;
				k[len] = s;
				if(dfs(d-1, s, max, len+1))return true;
				u[s] = false;
			}
		}
		return false;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt();
			if(n==0)break;
			int x = 1, res = 0;
			while(x<n){
				x*=2; res++;
			}
			for(;;){
				u = new boolean[2500];
				k = new int[res+1];
				u[1] = true;
				k[0] = 1;
				if(dfs(res, 1, 1, 1)){
					System.out.println(res); break;
				}
				res++;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    cout << A[N-1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
// LM10: The next Ballon d'Or
import java.util.*;
import java.io.*;
import java.math.*;
import static java.lang.Math.*;
public class Main
{
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }
    public static void main(String[] args)throws IOException {
        /*

        */
        PrintWriter pw = new PrintWriter(System.out);
        FastReader fr = new FastReader();
        int t=1;
        for(int ti=0;ti<t;++ti)
        {
            int n=fr.i();
            int k=fr.i();
            int [] heights=new int [n];
            fr.scanIntArr(heights);
            int [] dp=new int[n];
            dp[0]=0;
            dp[1]=dp[0]+abs(heights[1]-heights[0]);
            for(int ni=2;ni<n;++ni)
            {
                int min=Integer.MAX_VALUE;
                for(int ki=1;ki<=k && ki<n && ni-ki>=0;++ki)
                {
                    min=min(dp[ni-ki]+abs(heights[ni-ki]-heights[ni]),min);
                }
                dp[ni]=min;
            }
            pw.println(dp[n-1]);
        }

        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 23252
while True:
    a, op, b = input().split()
    a, b = map(int, [a, b])
    if op == "+" :
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    elif op == "?":
        break


Measured memory_bytes: 7660
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
#define f first
#define s second
#define inf 100000001
using namespace std;
 
int w,h,d[20][20],ii,sum,map[20][20],a,dp[1<<12][20];
int x[4]={1,-1,0,0};
int y[4]={0,0,1,-1};
char c[20][20];
vector<pair<int,int> > v;
pair<int,int> u;
queue<pair<int,int> > q;
 
bool in(int a,int b)
{
  if(a<0 || b<0 || a>=h || b>=w)return false;
  return true;
}
/*
void solve()
{
  for(int S=0;S<1<<a;S++){
    fill(dp[S],dp[S]+a,inf);
  }
  dp[(1<<a)-1][0]=0;
 
  for(int S=(1<<a)-2;S>=0;S--){
    for(int v=0;v<a;v++){
      for(int u=0;u<a;u++){
    if(!(S>>u & 1)){
      dp[S][v]=min(dp[S][v],dp[S|1<<u][u]+map[v][u]);
    }
      }
    }
  }
  int ans=inf;
  for(int i=1;i<a;i++)ans=min(ans,dp[0][i]);
  if(ans>=inf)cout<<-1<<endl;
  cout<<ans<<endl;
}
*/
 
int rec(int S,int v)
{
  if(dp[S][v]>=0){
    return dp[S][v];
  }
  if(S==(1<<a)-1 && v==0){
    return dp[S][v]=0;
  }
  int res=inf;
  for(int i=0;i<a;i++){
    if(!(S>>i&1)){
      res=min(res,rec(S|1<<i,i)+map[v][i]);
    }
  }
  return dp[S][v]=res;
}
 
int main()
{
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    v.clear();
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
    cin>>c[i][j];
    if(c[i][j]=='o')v.push_back(make_pair(i,j));
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
    if(c[i][j]=='*')v.push_back(make_pair(i,j));
      }
    }
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++)map[i][j]=0;
    }
    for(int k=0;k<v.size();k++){
      q.push(make_pair(v[k].f,v[k].s));
      for(int i=0;i<20;i++){
    for(int j=0;j<20;j++)d[i][j]=inf;
      }
      d[v[k].f][v[k].s]=0;
      while(!q.empty()){
    u=q.front();q.pop();
    for(int i=0;i<4;i++){
      int xx=u.f+x[i],yy=u.s+y[i];
      if(in(xx,yy)){
        if(d[xx][yy]!=inf)continue;
        if(c[xx][yy]!='x'){
          q.push(make_pair(xx,yy));
          d[xx][yy]=d[u.f][u.s]+1;
        }
      }
    }
      }
      for(int i=0;i<v.size();i++)map[k][i]=d[v[i].f][v[i].s];
    }
    a=v.size();
    memset(dp,-1,sizeof(dp));
    int ans=inf;
    for(int i=1;i<a;i++){
      ans=min(ans,rec(0,i));
    }
    if(ans>=inf)cout<<-1<<endl;
    else cout<<ans<<endl;
      //solve();
  }
  return 0;
}


Measured memory_bytes: 3368
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import itertools

N, *A = mi()
L = [ii() for _ in range(N)]
L_ = [L[i] for i in range(N)]
N_ = N

A = sorted(A)
#sum_l = sum(L)
tmp = [0] * 3
ans = float('inf')

for k in itertools.product([0,1], repeat=N_):
    N = sum(k)
    if N < 3:
        continue
    L = []
    for x in range(N_):
        if k[x]:
            L.append(L_[x]*k[x])
    #L = [L_[x]*k[x] for x in range(N_)]
    sum_l = sum(L)

    for i in range(1, N+1):
        for koho_i in range(1, 2**i):
            for koho_j in range(1, 2**i):
                j = i
                #print(koho_i, koho_j)
                if koho_i & koho_j:
                    continue
                #tmp[0] = [L[x]*koho_i[x] for x in range(i)]
                tmp[0] = sum([L[x]*min((koho_i & 1<<x), 1) for x in range(i)])
                #tmp[1] = [L[x]*koho_j[x] for x in range(j)]
                tmp[1] = sum([L[x]*min((koho_j & 1<<x), 1) for x in range(j)])
                tmp[2] = sum_l - tmp[0] - tmp[1]
                #print(tmp)

                if 0 in tmp:
                    continue

                tmp = sorted(tmp)
                cost = (N-3) * 10 + sum([abs(tmp[x]-A[x]) for x in range(3)])
                #if cost < ans:
                    #print(tmp, cost, N)
                #if tmp[0] == 80 and tmp[1] == 91 and tmp[2] == 98:
                    #print(cost)
                ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3316
from collections import deque

S = deque(input())
Q = int(input())
Flag = False

for _ in range(Q):
    Query = input().split()
    if Query[0] == '1':
        if Flag == False:
            Flag = True
        else:Flag = False
    else:
        if Query[1] == '1':
            if Flag == False:S.appendleft(Query[2])
            else:S.append(Query[2])
        else:
            if Flag == False:S.append(Query[2])
            else:S.appendleft(Query[2])
l = list(S)
if Flag:print(''.join(l[::-1]))
else:print(''.join(l))

Measured memory_bytes: 10356
from collections import Counter

N = int(input())
S = input()

S1 = S[:N]
S2 = S[N:]
S2 = S2[::-1]
rb1 = Counter()
rb2 = Counter()
for i in range(2 ** N):
    flag = bin(i)[2:].zfill(N)
    r1 = ''
    b1 = ''
    r2 = ''
    b2 = ''
    for j in range(N):
        if flag[j] == '0':
            r1 += S1[j]
            r2 += S2[j]
        else:
            b1 = S1[j] + b1
            b2 = S2[j] + b2
    key1 = r1 + '&' + b1
    key2  =r2 + '&' + b2
    rb1[key1] += 1
    rb2[key2] += 1

ans = 0
for key in rb1.keys():
    ans += rb1[key] * rb2[key]

print(ans)


Measured memory_bytes: 125256
D, G = map(int, input().split())

p = [0 for i in range(10)]
c = [0 for i in range(10)]


for i in range(D):
    p[i], c[i] = map(int, input().split())

# print(D, G, p, c)

S = [0 for i in range(10)]
for i in range(D):
    S[i] = 100 * (i + 1) * p[i] + c[i]

a = [0 for i in range(10)]
minno = float('inf')
for a[0] in range(2):
    for a[1] in range(2):
        for a[2] in range(2):
            for a[3] in range(2):
                for a[4] in range(2):
                    for a[5] in range(2):
                        for a[6] in range(2):
                            for a[7] in range(2):
                                for a[8] in range(2):
                                    for a[9] in range(2):
                                        sums = 0
                                        min_tmp = 0
                                        for i in range(D):
                                            sums = sums + a[i] * S[i]
                                            min_tmp = min_tmp + a[i] * p[i]
                                        if sums >= G:
                                            minno = min(minno, min_tmp)
                                        else:
                                            rest = G - sums
                                            for j in range(10):
                                                if (p[9 - j] != 0) and (a[9 - j] == 0):
#                                                    print(p[9 - j], a[9 - j])
                                                    for k in range(p[9 - j] - 1):
                                                        rest = rest - 100 * (10 - j)
                                                        min_tmp = min_tmp + 1
#                                                        print(rest, min_tmp)
                                                        if rest <= 0:
                                                            minno = min(minno, min_tmp)
#                                        print(min_tmp)

print(minno)


Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		String line2 = sc.nextLine();
		int ixlen = line1.length()-line2.length()+1;
		int reti = -1;
		int kouhoi = -1;
		for(int i=0; i<ixlen ;i++){
			if(line1.charAt(i) == '?' || line1.charAt(i) == line2.charAt(0)){
				kouhoi = i;
				for(int j=i+1,k=1;k<line2.length();j++,k++){
					if(line1.charAt(j) != '?' && line1.charAt(j) != line2.charAt(k)){
						kouhoi = -1;
						break;
					}
				}
				if(kouhoi!=-1){
					reti = kouhoi;
				}
			}
		}
		if(reti == -1){
			line1 = "UNRESTORABLE";
		}
		else{
			StringBuilder sb = new StringBuilder();
			for(int i=0;i<reti;i++){
				if(line1.charAt(i)=='?'){
					sb.append('a');
					continue;
				}
				sb.append(line1.charAt(i));
			}
			sb.append(line2);
			for(int j=sb.length();j<line1.length();j++){
				if(line1.charAt(j)=='?'){
					sb.append('a');
					continue;
				}
				sb.append(line1.charAt(j));
			}
			line1 = sb.toString();
		}
        System.out.println(line1);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    if(A >= 6) ans = B / 2;
    if(A >= 13) ans = B;
    cout << ans;
    return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);

	int a, b, c;
	cin >> a >> b >> c;

	int sum = a + b + c;

	if (sum >= 22) cout << "bust" << endl;
	else cout << "win" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1;
    s2="";
    for(int i=0;i<s1.size();i++)
        if(s1[i]!='B') s2+=s1[i];
    else if(s2.size()>0) s2.erase(s2.size()-1,1);
    cout<<s2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n;
  string s;
  cin>>n>>s;
  ll count = 0;
  rep(i,10) rep(j,10) rep(k,10){
    string pin = to_string(i) + to_string(j) + to_string(k);
    int p1 = 0;
    int p2 = 0;;
    bool ok1 = false;
    rep(l,n){
      if (pin[0]==s[l]){
        p1 = l;
        ok1 = true;
        break;
      }
    }
    bool ok2 = false;
    for (int l=p1+1; l<n; l++){
      if (pin[1]==s[l]){
        p2 = l;
        ok2 = true;
        break;
      }
    }
    bool ok3 = false;
    for (int l=p2+1; l<n; l++){
      if (pin[2]==s[l]){
        ok3 = true;
        break;
      }
    }
    if (ok1==true && ok2 ==true && ok3 ==true) count++;
  }
  cout << count << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

class UnionFind {
public:
	UnionFind(int size);
	int unite(int v, int w);
	int find(int v);
	int get_size_eq(int v);
	int get_size_part();
	virtual ~UnionFind();

private:
	int *parent;
	int *size_eq;
	int size_part;
};

UnionFind::UnionFind(int size) {
	parent = new int[size];
	size_eq = new int[size];
	for(int i = 0; i < size; i++) { parent[i] = -1; size_eq[i] = 1; }
	size_part = size;
}

int UnionFind::unite(int v, int w) {
	int fv = find(v);
	int fw = find(w);
	if(fv == fw) { return fv; }
	
	size_part--;
	int &sv = size_eq[fv];
	int &sw = size_eq[fw];
	
	if(sv < sw) {
		parent[fv] = fw;
		sw += sv;
		return fw;
	} else {
		parent[fw] = fv;
		sv += sw;
		return fv;
	}
}

int UnionFind::find(int v) {
	if(parent[v] == -1) { return v; }
	return parent[v] = find( parent[v] );
}

int UnionFind::get_size_eq(int v) {
	return size_eq[ find(v) ];
}

int UnionFind::get_size_part() {
	return size_part;
}

UnionFind::~UnionFind() {
	delete[] parent;
	delete[] size_eq;
}

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

int n, m, a[10000], b[10000];

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
	
	int ans = 0;
	inc(q, m) {
		UnionFind uf(n);
		inc(i, m) {
			if(i == q) { continue; }
			uf.unite(a[i], b[i]);
		}
		if(uf.get_size_part() != 1) { ans++; }
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;
using ll = long long;

ll mod = 1000000007;

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void Cinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll nCk(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

ll mpow(ll a, ll b)
{
  if (b == 0)return 1;
  ll z = mpow(a, b / 2);
  z = z*z%mod;
  if (b % 2 == 1)z = z*a%mod;
  return z;
}

int main() {
  Cinit();
  ll A, B, C, N;
  cin >> N >> A >> B >> C;
  ll ka = A * inv[A + B] % mod;
  ll kb = B * inv[A + B] % mod;
  ll r = 0;
  for (int i = 0; i <= N - 1; i++)
  {
    ll sa = nCk(N - 1 + i, N - 1)*ka%mod*mpow(ka, N - 1) % mod*mpow(kb, i);
    ll sb = nCk(N - 1 + i, N - 1)*kb%mod*mpow(kb, N - 1) % mod*mpow(ka, i);
    r = (r + (sa + sb) % mod*(N + i)) % mod;
  }
  cout << r * 100 % mod*inv[A + B] % mod << endl;
}


Measured memory_bytes: 12160
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, P = 1000000007, ans = 1;std::cin >> n;
  string s, t;std::cin >> s; std::cin >> t;
  ll pre = -1;
  for(int i=0;i<n;i++){
    //std::cout << i << " " << ans << '\n';
    if(s[i]==t[i]){
      if(pre==-1) ans = (ans*3)%P;
      else if(pre == 0) ans = (ans*2)%P;
      pre = 0;
    }else{
      i++;
      if(pre==-1) ans = (ans*6)%P;
      else if(pre==0) ans = (ans*2)%P;
      else ans = (ans*3)%P;
      pre = 1;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		long n=sc.L;
		int m=50;
		long[] a=new long[m];
		for(int i = 0;i<m;i++){
			a[i]=m-1+(n/m);
			if(i<n%m){a[i]+=m+1-(n%m);}
			else{a[i]-=n%m;}
		}
		Console.WriteLine(m);
		Console.WriteLine(String.Join(" ",a));
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 13268
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = []
for _ in range(N):
  A.append(read())

A.sort()
ans = A[N-1] - A[0]
l = 1; r = N-2
while l < r:
  ans += A[r+1] - A[l] + A[r] - A[l-1]
  l += 1
  r -= 1
if l == r:
  ans += max(A[l+1] - A[l], A[l] - A[l-1])
print(ans)

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

int main() {
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
# AGC002A - Range Product
def main():
    A, B = map(int, input().split())
    if A <= 0 <= B:
        print("Zero")
    else:
        flg = 0 < A or (abs(A - B) + 1) % 2 == 0
        print("Positive" if flg else "Negative")


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define INF (1<<31)-1
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main() {
	string a;
	cin >> a;
	if (a == "A") {
		cout << "T";
	}
	if (a == "T") {
		cout << "A";
	}
	if (a == "C") {
		cout << "G";
	}
	if (a == "G") {
		cout << "C";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int r; cin >> r;
    cout << r * r << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

int n;
vector<int> p;
vector<int> j;
long long solve(){
    sort(j.begin(),j.end());
    long long psum = 0;
    long long jsum = 0;
    for(int i=0;i<n;i++){
        psum += p[i];
    }
    for(int i=0;i<n-1;i++){
        jsum += j[i];
    }
    long long ans = psum+jsum;
    for(int i=0;i<n-1;i++){
        jsum -= j[i];
        long long a = (psum+jsum)*(i+2);
        ans = max(a,ans);
    }
    return ans;
}

int main(){
    while(true){
        cin >> n;
        if(n == 0)break;
        p.clear();
        j.clear();
        for(int i=0;i<n;i++){
            int tmp;
            cin >> tmp;
            p.push_back(tmp);
        }
        for(int i=0;i<n-1;i++){
            int tmp;
            cin >> tmp;
            j.push_back(tmp);
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 1728
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
	int n;
	Scanner in = new Scanner(System.in);
	HashMap<Integer, Character> map = new HashMap<Integer, Character>();
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		while(true){
			n = in.nextInt();
			if(n==0)break;
			new AOH1226().doIt();
		}
	}

	class AOH1226{
		void doIt(){
			if(n==0)return;
			double[] a = new double[n];
			double[] b = new double[n];
			double[] c = new double[n];
			double[] d = new double[n];
			for(int i=0;i<n;i++)a[i] = in.nextDouble();
			for(int i=0;i<n;i++)b[i] = in.nextDouble();
			for(int i=0;i<n;i++)c[i] = in.nextDouble();
			for(int i=0;i<n;i++)d[i] = in.nextDouble();
			Line2D[][] lines = new Line2D[n][2];
			for(int i=0;i<n;i++){
				lines[i][0] = new Line2D.Double(new Point2D.Double(a[i], 0),new Point2D.Double(b[i],1));
				lines[i][1] = new Line2D.Double(new Point2D.Double(0,c[i]),new Point2D.Double(1,d[i]));
			}
			int p_n = (n+2)*(n+2);
			Point2D p[] = new Point2D[p_n];
			for(int i=0;i<=n+1;i++){
				for(int s=0;s<=n+1;s++){
					if(i==0){
						if(s==0)p[0] = new Point2D.Double(0,0);
						else if(s==n+1)p[n+1] = new Point2D.Double(0,1);
						else p[s] = new Point2D.Double(0,c[s-1]);
					}else if(i==n+1){
						if(s==0)p[i*(2+n)+s] = new Point2D.Double(1,0);
						else if(s==n+1)p[i*(2+n)+s] = new Point2D.Double(1,1);
						else p[i*(2+n)+s] = new Point2D.Double(1,d[s-1]);
					}else{//i=1~n
						if(s==0)p[i*(2+n)+s] = new Point2D.Double(a[i-1],0);
						else if(s==n+1)p[i*(2+n)+s] = new Point2D.Double(b[i-1],1);
						else p[i*(2+n)+s] = intersectionPoint(lines[i-1][0], lines[s-1][1]);
					}
				}
			}
			double max = Double.MIN_VALUE;
			
//			
			
			for(int i=0;i<n+1;i++)for(int s=0;s<n+1;s++){
//				System.out.println(p[i*(n+2)+s]+" "+p[(i+1)*(n+2)+s]+" "+p[i*(n+2)+s+1]+" "+p[(i+1)*(n+2)+s+1]);
				Point2D v1 = diff(p[(i+1)*(n+2)+s], p[i*(n+2)+s]),
						v2 = diff(p[i*(n+2)+s+1], p[i*(n+2)+s]);
				double area = Math.abs(cross(v1, v2) /2);
				Point2D v3 = diff(p[i*(n+2)+s+1], p[(i+1)*(n+2)+s+1]),
						v4 = diff(p[(i+1)*(n+2)+s], p[(i+1)*(n+2)+s+1]);
				area += Math.abs(cross(v3, v4)/2);
				max = Math.max(max, area);
			}
			System.out.printf("%.6f\n",max);
		}

		Point2D intersectionPoint(Line2D l1,Line2D l2){
			return intersectionPoint(l1.getP1(), l1.getP2(), l2.getP1(), l2.getP2()); 
		}
		Point2D intersectionPoint(Point2D a1,Point2D a2,Point2D b1,Point2D b2){
			Point2D a=diff(a2,a1),
					b=diff(b2,b1);
			return sum(a1, mul(cross(b, diff(b1,a1))/cross(b,a), a));
		}
		Point2D sum(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()+p2.getX(),p1.getY()+p2.getY());
		}
		Point2D diff(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()-p2.getX(),p1.getY()-p2.getY());
		}
		Point2D mul(double n,Point2D p1){
			return new Point2D.Double(p1.getX()*n,p1.getY()*n);
		}

		double cross(Point2D p1,Point2D p2){
			return p1.getX()*p2.getY()-p1.getY()*p2.getX();
		}
	}

}

Measured memory_bytes: 47948
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
int H[MAX_N];
vector<int> G[MAX_N];

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,N)
	{
		cin >> H[i];
	}
	rep(i,M)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans = 0;
	rep(i,N)
	{
		bool flag = true;
		rep(j,G[i].size())
		{
			if (H[i] <= H[G[i][j]]) flag = false;
		}
		if (flag) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double N,M;
    cin >> N>>M;
    double s=0;
    int m=0;
    vector<double> A(N);
    for (int i=0;i<N;i++) 
    {
        cin >> A[i];
        s+=A[i];
    }
    for (int i=0;i<N;i++)
    {
        if(A[i]/s>=1/(4*M)) m++;
    }
    if (m>=M) cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	char a, b; cin >> a >> b;
	if (a < b) cout << "<" << endl;
	else if (a > b)cout << ">" << endl;
	else cout << "=" << endl;
 	return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    ll n, a, b; cin >> n >> a >> b;
    vector<ll> x;
    REP(i,n){
        ll xx; cin >> xx ; x.push_back(xx);
    }
    long double step = (long double)b/a;
    int i = 0;
    ll ans = 0;
    while(i!=n-1){
        int j = i;
        while(j!=n-1){
            if(x[j+1]>x[i]+step){
                break;
            }
            j++;
        }
        if(i==j){
            ans += b;
            i++;
        }else{
            ans += (x[j] - x[i]) * a;
            i = j;
        }
    }
    cout << ans << endl;

}

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

namespace AizuOnlineJudge {
    class Program {
        static void Main() {
            var deque = new Deque<int>(int.Parse(Console.ReadLine()));

            for (var i = 0; i < deque.Capacity; ++i) {
                var query = Console.ReadLine().Split().Select(int.Parse).ToArray();

                switch (query[0]) {
                    case 1:
                        Console.WriteLine(deque[query[1]]);
                        break;

                    default:
                        switch (query[0] + query[1]) {
                            case 0:
                                deque.PushFirst(query[2]);
                                break;

                            case 1:
                                deque.PushLast(query[2]);
                                break;

                            case 2:
                                deque.PopFirst();
                                break;

                            case 3:
                                deque.PopLast();
                                break;
                        }
                        break;
                }
            }
        }
    }

    class Deque<T>: IEnumerable<T> {
        public int Count { get; private set; }
        public int Capacity { get; }
        private T[] array;
        private int first;
        private int last;

        public Deque(int capacity) {
            array = new T[Capacity = capacity];
        }

        public void PushFirst(T value) {
            if (--first < 0) {
                first += Capacity;
            }
            array[first] = value;
            ++Count;
        }

        public void PushLast(T value) {
            array[last++] = value;
            if (last >= Capacity) {
                last -= Capacity;
            }
            ++Count;
        }

        public void PopFirst() {
            ++first;
            if (first >= Capacity) {
                first -= Capacity;
            }
            --Count;
        }

        public void PopLast() {
            --last;
            if (last < 0) {
                last += Capacity;
            }
            --Count;
        }

        public IEnumerator<T> GetEnumerator() {
            for (var i = 0; i < Count; ++i) {
                yield return this[i];
            }
        }

        IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();

        public T this[int index] {
            get {
                return array[(first + index) % Capacity];
            }
        }
    }
}



Measured memory_bytes: 22684
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = list(map(int, read().decode().rstrip()))

U = N + 10
fact_ord = [0] * U
for n in range(1,U):
    fact_ord[n] = fact_ord[n//2] + (n//2)

def solve_01(A):
    ret = 0
    N = len(A) - 1
    comb_ord = [fact_ord[N] - fact_ord[i] - fact_ord[N-i] for i in range(N+1)]
    return sum(x * (y==0) for x,y in zip(A, comb_ord)) % 2

def solve(A):
    if len(A) == 1:
        return A[0]
    A = [abs(x - y) for x,y in zip(A, A[1:])]
    if all(x != 1 for x in A):
        B = [x // 2 for x in A]
        return 2 * solve_01(B)
    # 1 が存在
    A = [x % 2 for x in A]
    return solve_01(A)

print(solve(A))


Measured memory_bytes: 137112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  long long kazu = 0;
  long long k = 0;
  cin >> kazu >> k;
  vector<long long> h(kazu);
  for(long long i = 0;i <= kazu - 1;i++){
    cin >> h[i];
  }
  vector<long long> dp(kazu);
  for(long long i = 0;i <= kazu - 1;i++){
    dp[i] = 1000000000000000000;
  }
  dp[0] = 0;
  for(long long i = 1;i <= kazu - 1;i++){
    dp[i] = min(dp[i],dp[i - 1] + abs(h[i] - h[i - 1]));
    for(long long j = 1;j <= k - 1;j++){
      if(i > j){
       	dp[i] = min(dp[i],dp[i - j - 1] + abs(h[i] - h[i - j - 1]));
      }
    }
  }
  cout << dp[kazu - 1] << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	
	string t;
	cin >> t;
	sort(t.begin(), t.end());
    /*
    ・sort関数
    ソートする。algorithmのincludeが必要。
    */

	reverse(t.begin(), t.end());
    /*
    逆順に入れ替える。algorithimのinclude必要。
    */
	
	if (s < t) cout << "Yes" << endl;
    /*
    文字列の比較はバイト配列の比較をしている。
    ((文字).bytes)
    文字数，アルファベットの比較ができてしまう。
    */
	else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long x[100000];
int next_hotel[30][100000];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  long long L;
  cin >> L;

  for(int i = 0; i < N; i++){
    auto it = upper_bound(x, x + N, x[i] + L);
    next_hotel[0][i] = it - x - 1;
  }

  for(int i = 1; i < 30; i++){
    for(int j = 0; j < N; j++){
      next_hotel[i][j] = next_hotel[i - 1][next_hotel[i - 1][j]];
    }
  }

  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    int a;
    int b;
    cin >> a >> b;
    if(a > b){
      int tmp = a;
      a = b;
      b = tmp;
    }
    a--;
    b--;
    long long ans = 0;
    int cur_hotel = a;
    for(int j = 29; j >= 0; j--){
      if(next_hotel[j][cur_hotel] < b){
        ans += (1 << j);
        cur_hotel = next_hotel[j][cur_hotel];
      }
    }
    cout << ans + 1 << endl;
  }

  /*
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 30; j++){
      cout << next_hotel[j][i] << " ";
    }
    cout << endl;
  }
  */
  return 0;
}


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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define MOD 1000000007
const double PI=3.14159265358979323846;
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 (b<a) { a=b; return 1; } return 0; }
template<typename T> T Ceil(T a, T b){return (a+b-1)/b;}

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

int main() {
    cout<<fixed<<setprecision(10);

    ll x;cin>>x;

    ll c = 100;
    ll ans = 0;
    while(true){
        ans++;
        c += c/100;
        if(c>=x){
            cout<<ans<<endl;
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll N,M; cin >> N >> M;
    ll A[1010];
    vector<vector<ll> > C(1010);
    rep(i,M){
        ll b; cin >> A[i] >> b;
        rep(j,b) {
            ll c; cin >> c;
            c--;
            C[i].push_back(c);
        }
    }
    vector<ll> dp(5000,INF); dp[0] = 0;
    rep(i,M){
        ll now = 0;
        rep(j,C[i].size()){
            now |= (1<<C[i][j]);
        }
        for(ll S = 0;S<1<<N;S++){
            chmin(dp[S|now],dp[S]+A[i]);
        }
    }
    if(dp[(1 << N) - 1] == INF) dp[(1 << N) - 1] = -1;
    cout << dp[(1 << N) - 1] << endl;
}

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

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

  vector<int> W(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>W[i];
    sum += W[i];
  }

  int mini=sum;
  int prefix_sum=0;
  for(int i=0;i<N;i++){
    prefix_sum += W[i];
    mini=min(mini,abs((sum-prefix_sum)-prefix_sum));
  }

  cout<<mini;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int d = sc.nextInt();
		if (n % (2 * d + 1) == 0) {
			System.out.println(n / (2 * d + 1));
		} else {
			System.out.println((n / (2 * d + 1)) + 1);
		}
		
	}
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 22868
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vvi v(n, vi(m));
	REP(i, n)REP(j, m)cin >> v[i][j];
	vector<pair<pii, pii>> ans;
	REP(i, n) {
		REP(j, m - 1) {
			if (v[i][j] & 1) {
				v[i][j]--;
				v[i][j + 1]++;
				ans.push_back({ { i + 1,j + 1 }, { i + 1,j + 2	} });
			}
		}
		if (v[i][m - 1] & 1 && i != n - 1) {
			v[i][m - 1]--;
			v[i + 1][m - 1]++;
			ans.push_back({ {i + 1,m},{i + 2,m} });
		}
	}
	cout << ans.size() << endl;
	REP(i,ans.size())cout<<ans[i].first.first<<" "<<ans[i].first.second<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
}

Measured memory_bytes: 5236