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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

int n;
int M;
vector<pair<int,int>> pp;
vector<map<int,int>> d(100010);
vvi l(100010,vi(0));//隣接リスト

void dfs(int x,int frm,int col){
    int now=1;
    for (int i=0;i<int(l[x].size());i++){
        if(l[x][i]==frm){
            continue;
        }
        else{
            if (now==col){
                now+=1;
            }
            d[x][l[x][i]]=now;
            d[l[x][i]][x]=now;
            M=max(M,now);
            dfs(l[x][i],x,now);

            now+=1;
        }
    }
}


int main() {
    cin>>n;
    M=0;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        pp.push_back(make_pair(a,b));
        l[a].push_back(b);
        l[b].push_back(a);
    }
    dfs(1,0,0);
    cout<<M<<endl;
    rep(i,n-1){
        int a=pp[i].first;
        int b=pp[i].second;
        cout<<d[a][b]<<endl;
    }
    

    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll N,A,B,C,D,E;
    cin>>N>>A>>B>>C>>D>>E;

    ll m = min(A,min(B,min(C,min(D,E))));
    cout << ll(ceil((double)N/m)+4) << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let d: usize = read();
    let x: usize = read();
    let mut ans = 0;
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }

    for i in 0..a.len() {
        let ai = a[i];
        let mut head = 1;

        while head as usize <= d {
            ans += 1;
            head += ai;
        }
    }
    println!("{}", ans + x);
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        Set<Character> set = new HashSet<>();
        for(int i = 0; i < str.length(); i++){
            if(!set.add(str.charAt(i))){
                System.out.println("no");
                return;
            }
        }
        System.out.println("yes");
    }

}


Measured memory_bytes: 22996
#include<iostream>
using namespace std;
long gcd(int a,int b){
    if(a % b == 0){
        return b;
    }else{
        return gcd(b, a % b);
    }
}

long calc(int a,int b,int c){
    long temp = gcd(a,b);
    temp = gcd(temp,c);
    return temp;
}
int main(){
    long k;
    cin >> k;
    long ans = 0;

    for(int a = 1;a <= k;a++){
        for(int b = 1;b <= k;b++){
            for(int c = 1;c <= k;c++){
                ans += calc(a,b,c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    vector<ll> v(n, 0);
    REP(i, n) {
        cin >> v[i];
    }
    sort(ALL(v));
    ll sum = 0;
    // 1 3 4
    // iまでのsumよりも次のやつが2倍以上だったら、そのiはNG
    // 1 2 7 20 30 40
    // 1, 2はならない？
    // ならないな...
    ll ng = 0;
    ll tmp = 0;
    REP(i, n-1) {
        sum += v[i];
        tmp++;
        if (sum * 2 < v[i+1]) {
            ng += tmp;
            tmp = 0;
        }
    }
    cout << n - ng << endl;
    return 0;
}

Measured memory_bytes: 4008
import kotlin.math.ceil
import kotlin.math.floor

fun main(args: Array<String>) {
    //val n = 1001
    val n = readLine()!!.toInt()

    val tax = 1.08

    val expect1 = ceil(n / tax).toInt()
    val expect2 = floor(n / tax).toInt()
    
    when (n) {
        floor(expect1 * tax).toInt() -> {
            println("$expect1")
        }
        floor(expect2 * tax).toInt() -> {
            println("$expect2")
        }
        else -> println(":(")
    }
}


Measured memory_bytes: 34484
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl

int main() {
    int n, c, ma=0;
    bool ans=true;
    cin >> n;
    vector<int> data(n);
    rep(i,n) {
        cin >> c;
        if (ma-c > 1) {ans = false; break;}
        ma = max(ma, c);
    }
    if (ans) ct("Yes");
    else ct("No");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){

  //input
  int N;
  cin >> N;
  int A[4]={0,0,0,0};
  
  
  //setup
  for(int i=0;i<N;i++){
    string tmp;
    cin >> tmp;
    if(tmp=="AC")A[0]++;
    if(tmp=="WA")A[1]++;
    if(tmp=="TLE")A[2]++;
    if(tmp=="RE")A[3]++;
  }
  
  cout << "AC x ";
  cout << A[0] << endl;
  cout << "WA x ";
  cout << A[1] << endl;
  cout << "TLE x ";
  cout << A[2] << endl;
  cout << "RE x ";
  cout << A[3] << endl;
  
}

Measured memory_bytes: 3628
def main():
    n, k = map(int, input().split())
    answer = 0.0
    for i in range(1, n + 1):
        now = i
        count = 0
        while now < k:
            now *= 2
            count += 1
        answer += pow(0.5, count)
    answer /= n
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



template<typename T>
class SegTree {
    int n;
    T def;
    function<T(T, T)> operation;
    function<T(T, T)> update;
    vector<T> data;
    
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return data[k];
        T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
        T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
    
public:
    SegTree<T>(int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update)
    : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) n *= 2;
        data = vector<T>(2 * n - 1, def);
    }
    
    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }
    
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }
    
    T operator[](int i) { return data[i + n - 1]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    SegTree<int> sgt(n, n,
                     [](int a, int b) { return min(a, b); },
                     [](int a, int b) { return b; });
    SegTree<int> sgt2(n, -1,
                     [](int a, int b) { return max(a, b); },
                     [](int a, int b) { return b; });
    
    vector<pii> v(n);
    rep(i, n) cin >> v[i].F;
    rep(i, n) v[i].S = i;
    
    sort(all(v));
    
    ll ans = 0;
    rep(i, n) {
        ans += (ll)v[i].F * (sgt.query(v[i].S, n) - v[i].S) * (v[i].S - sgt2.query(0, v[i].S));
        // cout << endl << sgt.query(0, v[i].S) << " " << sgt.query(v[i].S, n) << endl;
        // cout << sgt2.query(0, v[i].S) << " " << sgt2.query(v[i].S, n) << endl;
        sgt.change(v[i].S, v[i].S);
        sgt2.change(v[i].S, v[i].S);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5888
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_SQRT_B = 1000001;
const int MAX_RANGE = 1000001;

typedef unsigned long long U;

vector<U> primes;

void elatos(U a, U b){
  if(a < 2) a = 2;
  if(a >= b) return;

  bool isp_r[MAX_RANGE];
  bool isp_sqrtb[MAX_SQRT_B];
  memset(isp_r , 1 , sizeof(isp_r));
  memset(isp_sqrtb , 1 , sizeof(isp_sqrtb));

  for(U i=2; (U)i*i < b; i++)
    if(isp_sqrtb[i]){
      for(U j=2*i; (U)j*j < b; j+=i) isp_r[j] = 0;
      for(U j = max((U)2,(a+i-1)/i)*i; j<b; j+=i) isp_r[j-a] = 0;
    }
  for(U i=a; i<b; i++) if(isp_r[i-a]) primes.push_back(i);
}

bool isp(U n){
  vector<U>::iterator i = lower_bound(primes.begin(), primes.end(), n);
  return *i == n;
}

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

int p[31];
int m[31];
int dp[1000001];

int main(){
  elatos(0,1000001);
  int n;
  int bu;
  while(cin >> n >> bu , n + bu){
    rep(i,n){
      cin >> p[i];
      m[i] = bu/p[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    rep(i,n){
      rep(j,bu+1){
	if(dp[j] >= 0){
	  dp[j] = m[i];
	}
	else if(j < p[i] || dp[j-p[i]] <= 0){
	  dp[j] = -1;
	}
	else {
	  dp[j] = dp[j - p[i]] - 1;
	}
      }
    }
    int ans = -1;
    for(int i=bu+(bu+1)%2; i>=1; i-=2){
      if(dp[i] >= 0 && isp(i)){
	ans = i;
	break;
      }
    }
    if(ans > 0){
      cout << ans << endl;
    } else {
      cout << "NA" << endl;
    }
  }
  return 0;
}

      
    
    

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

int main()
{
	int st, go;
	int ko, o, hu;

	int tim = 0;

	int i;

	cin >> st >> go >> ko >> o >> hu;

	for (i = st; i < go; i++)
	{
		if (i < 0)
		{
			tim += ko;
		}

		else if (i > 0)
		{
			tim += hu;
		}

		else
		{
			tim += o + hu;
		}
	}

	cout << tim << endl;

	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
using namespace std;
int main(){
  int n,i,a;cin >> n;
  int s[n];
  for(i=1;i<=n;i++){
    cin >> a;
    s[a-1] = i;
  }
  for(i=0;i<n;i++) cout << s[i] << " ";
  cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

ll D = 365;
ll C[26] = {};
ll S[365][26] = {};

ll score(const vector<ll> &ans){
  ll ret = 0;
  ll last[26] = {};
  rep(i,D){
    ret += S[i][ans[i]];
    last[ans[i]] = i+1;
    rep(j,26){
      ret -= C[j] * (i+1 - last[j]);
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  cin>>D;
  rep(i,26){
    cin>>C[i];
  }
  rep(i,D){
    rep(j,26){
      cin>>S[i][j];
    }
  }

  vector<ll> ans(D), last(26, -30);
  rep(i,D){
    ll best_eval = 0;
    ll best_type = -1;
    rep(j,26){
      if(best_eval < S[i][j] && i - last[j] >= 20){
        best_eval = S[i][j];
        best_type = j;
      }
    }
    ans[i] = best_type;
    last[best_type] = i;
  }
  cerr << "score:" << score(ans) << endl;

  rep(i,D){
    cout<<ans[i] + 1 << endl;
  }
  return 0;
}

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

int main() {
    int X,Y,Z,K;
    cin>>X>>Y>>Z>>K;
    vector<ll> A(X),B(Y),C(Z);
    for(int i=0;i<X;i++) cin>>A[i];
    for(int i=0;i<Y;i++) cin>>B[i];
    for(int i=0;i<Z;i++) cin>>C[i];
    
    vector<long long> AB;
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AB.push_back(A[i]+B[j]);
        }
    }
    sort(AB.begin(),AB.end(),greater<ll>());
    AB.resize(K);
    
    vector<ll> ABC;
    for(int i=0;i<AB.size();i++){
        for(int j=0;j<Z;j++){
            ABC.push_back(AB[i]+C[j]);
        }
    }
    sort(ABC.begin(),ABC.end(),greater<ll>());
    
    for(int i=0;i<K;i++) cout<<ABC[i]<<endl;
}

Measured memory_bytes: 43240
X,K,D=map(int,input().split())

if X < 0:
    X=-X
    
a=X//D
if a >= K:
    print(X-D*K)
else:
    if X%D<D-X%D:
        if (K-a)%2 == 0:
            print(X%D)
        else:print(D-X%D)
    else:
        if (K-(a+1))%2==0:
            print(D-X%D)
        else:print(X%D)

          

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

struct Point
{
    double x, y;
};

void KochCurve(int n, Point p1, Point p2)
{
    if (n == 0)
    {
        return;
    }

    // p1とp2を三分割する
    double sx = (p2.x - p1.x) / 3 + p1.x;
    double sy = (p2.y - p1.y) / 3 + p1.y;
    Point s = {sx, sy};

    double tx = (p2.x - p1.x) * 2 / 3 + p1.x;
    double ty = (p2.y - p1.y) * 2 / 3 + p1.y;
    Point t = {tx, ty};

    // 分割点から正三角形を作る
    double rad = M_PI * 60 / 180;
    double ux = (tx - sx) * cos(rad) - (ty - sy) * sin(rad) + sx;
    double uy = (tx - sx) * sin(rad) + (ty - sy) * cos(rad) + sy;
    Point u = {ux, uy};

    KochCurve(n - 1, p1, s);
    cout << sx << " " << sy << endl;
    KochCurve(n - 1, s, u);
    cout << ux << " " << uy << endl;
    KochCurve(n - 1, u, t);
    cout << tx << " " << ty << endl;
    KochCurve(n - 1, t, p2);
}

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

    Point p1 = {0.0, 0.0};
    Point p2 = {100.0, 0.0};

    cout << p1.x << " " << p1.y << endl;
    KochCurve(n, p1, p2);
    cout << p2.x << " " << p2.y << endl;
}



Measured memory_bytes: 3256
import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int B = (int)Math.pow(N, 0.5)+1;
    	LinkedHashMap<Integer, Integer> ans = new LinkedHashMap<Integer,Integer>();
    	for(int x=1;x<=B;x++) {
    		for(int y=1;y<=B;y++) {
    			for(int z=1;z<=B;z++) {
    				int n = x*x+y*y+z*z+x*y+y*z+z*x;
    				if(ans.containsKey(n)) {
    					ans.put(n,ans.get(n)+1);
    				} else {
    					ans.put(n,1);
    				}
    			}
    		}
    	}
    	for(int i=1;i<=N;i++) {
    		if(ans.containsKey(i)) {
        		System.out.println(ans.get(i));
    		} else {
    			System.out.println(0);
    		}

    	}

    }
}


Measured memory_bytes: 59108
x1,y1, x2,y2 = map(int,input().split())

# 図開して、直角三角形を各四角形の隅に置いたと仮定して点3は点2を基準に,点4は点1を基準に愚直に算出
y3 = y2 + x2 - x1
x3 = x2 + y1 - y2

x4 = x1 + y1 - y2
y4 = y1 + x2 - x1

print(x3,y3,x4,y4)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int sub = 0;
        int bef = 0;
        int temp = 0;
        int idx = 0;
        for (int i = 0; i < n; i++) {
            temp = Integer.parseInt(sc.next());
            if (i != 0 && sub < temp - bef) {
                sub = temp - bef;
                idx = i - 1;
            }
            if (i == n - 1) {
                if (sub < Math.abs(k - temp + a[0])) {
                    idx = i;
                }
            }
            bef = temp;
            a[i] = temp;
        }
        int ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (idx == 0) {
                ans += k - a[n - 1] + a[idx];
                idx = n - 1;
            } else {
                ans += a[idx] - a[idx - 1];
                idx--;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 51068
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int H = scan.nextInt();
    int W = scan.nextInt();

    long[][] matrix = new long[H][W];
    for (int i = 0; i < H; i++) {
      String line = scan.next();
      for (int j = 0; j < W; j++) {
        matrix[i][j] = '#' == line.charAt(j) ? -1 : 0;
      }
    }

    scan.close();

    System.out.println(gridPaths(matrix));
  }

  private static long gridPaths(long[][] matrix) {
    int I = matrix.length;
    if (I == 0) return 0;
    int J = matrix[0].length;

    matrix[0][0] = 1;

    for (int i = 0; i < I; i++) {
      for (int j = 0; j < J; j++) {
        if (i == 0 && j == 0) continue;
        if (matrix[i][j] < 0) {
          matrix[i][j] = 0;
          continue;
        }

        long top  = i > 0 ? matrix[i - 1][j] : 0;
        long left = j > 0 ? matrix[i][j - 1] : 0;

        matrix[i][j] = (top + left) % 1000_000_007;
      }
    }
    return matrix[I - 1][J - 1];
  }
}

Measured memory_bytes: 37668
import sys
input = sys.stdin.buffer.readline


class DiGraph:
    def __init__(self, n, decrement=True, destroy=False, edges=[]):
        """
        incs[p]: 頂点 p に流入するリンク数
        """
        self.n = n
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.incs = [0]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        self.incs[y] += 1

    def topological_sort(self):
        next_set = {p for p, inc in enumerate(self.incs) if inc == 0}
        while next_set:
            p = next_set.pop()
            yield p+self.decrement
            for q in self.edges[p]:
                self.incs[q] -= 1
                if self.incs[q] == 0:
                    next_set.add(q)

    def draw(self):
        """
        :return: グラフを可視化
        """
        import matplotlib.pyplot as plt
        import networkx as nx

        G = nx.DiGraph()
        for x in range(self.n):
            for y in self.edges[x]:
                G.add_edge(x + self.decrement, y + self.decrement)

        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos)
        plt.axis("off")
        plt.show()


################################################################################

def main():
    N, M = map(int, input().split())

    M = N - 1 + M
    graph = DiGraph(N, decrement=True, destroy=False)
    for _ in range(M):
        A, B = map(int, input().split())
        graph.add_edge(A, B)

    res = [0]*N
    for p in graph.topological_sort():
        for q in graph.edges[p-1]:
            res[q] = p
    print(*res, sep="\n")

if __name__ == '__main__':
    main()


Measured memory_bytes: 107868
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	// ll n,m, db,dc, b,c, maxi = INT_MIN, sum =0; cin>>n>>m; //tle aaya tha but impelementation dekh;
	// vector<ll> a(n);
	// for(ll i = 0 ; i < n ; i++) cin>>a[i]; 
	// sort(a.begin(),a.end());
	// vector<ll>::iterator it;
	// for(ll i = 0 ; i < m ; i++)
	// {
	// 	cin>>b>>c;
	// 	it = lower_bound(a.begin(), a.end(), c);
	// 	ll pos = it - a.begin()-1;
	// 	if(pos>=0)
	// 	fill(a.begin(), a.begin()+min(b,pos),c);
	// 	sort(a.begin(),a.end());
	// }
	// for(int i = 0 ; i< n; i++)
	// 	sum+=a[i];
	// cout<<sum<<endl;
	ll n,m, b,c, sum =0; cin>>n>>m;
	map<ll,ll> freq;
	for(int i = 0 ; i < n; i++)
	{
		cin>>b; freq[b]++;
	}
	for(int i = 0 ; i < m;i++)
	{
		cin>>b>>c;
		freq[c]+=b;
	}
	map<ll,ll>::iterator it;
	it = freq.end();
	--it;
	ll req = n;
	for(; it!=freq.begin(); it--)
	{
		if(it->second>=req)
			{
				sum+=it->first*req;
				req = 0;
				break;
			}
		else
		{
			sum+=it->first*it->second;
			req-=it->second;
		}

	}
	if(req)
	{
		it= freq.begin();
		sum+=it->first*req;
	}
	cout<<sum<<endl;

}

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

int main() {
  long long n,min = 1000000000000+1;
  cin >> n;
  for(int i = 1;i <= sqrt(n);i++){
    if(n%i == 0){
      if(i+n/i < min) min = i+n/i;
    }
  }
  cout << min-2 << endl;
}


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

int main()
{
	int64_t r, g, b, n;

	cin >> r >> g >> b >> n;

	int64_t ans = 0;

	for (int64_t i = 0; i * r <= n; i++)
	{
		for (int64_t j = 0; i * r + j * g <= n; j++)
		{
			if ((n - i * r - j * g) % b != 0)
			{
				continue;
			}
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

#define ll long long int

int main(){

    ll h;
    cin >> h;

    ll i;
    ll h1 = h;

    ll count = 0;

    while(h1>0){
        h1 = h1/2;
        count++;
    }

    ll sum = 0;

    for(i=0;i<count;i++){
        sum = sum + pow(2,i);
    }

    cout << sum;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int A,B,C,D;
   cin>>A>>B>>C>>D;
   
   int ans=min(A,B)+min(C,D);
   cout<<ans<<endl;
  
}

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

int main(){
uint64_t A,B,K;
cin>>A>>B>>K;
if(A<=K)K-=A,A=0;
else A=A-K,K=0;
if(K){
    if(B<=K) B=0;
    else B=B-K;
}
cout << A<< " " << B;
return 0;
}


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

int main(int argc, char *argv[])
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a * b > c * d)
		cout << a * b;
	else if (a * b < c * d)
		cout << c * d;
	else
		cout << a * b;

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=1e5+10;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,m,a[maxn],b[maxn];

long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>n>>m;
    _rep(i,1,n) cin>>a[i],b[i]=a[i]/2;
    long long gbs=1;
    _rep(i,1,n)
    {
        gbs=lcm(gbs,b[i]);
        if(gbs>m)
        {
            cout<<0<<endl;
            return 0;
        }
    }
    _rep(i,1,n)
        if(gbs/b[i]%2==0)
        {
            cout<<0<<endl;
            return 0;
        }
    cout<<(m/gbs+1)/2<<endl;

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 200005
#define M 1000005
#define LOG 19
#define KOK 32000
#define EPS 0.000000001
using namespace std;

int main() {

	//freopen("input.txt","r",stdin);

	int x,y;

	scanf("%d %d",&x,&y);

	if(abs(x)<abs(y)) {

		printf("%d",abs(y)-abs(x)+(x<0)+(y<0));

	}
	else {

		printf("%d",abs(x)-abs(y)+(x>0)+(y>0));

	}

}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int w, a,b;
    int s1,s2;
    scanf("%d%d%d",&w,&a,&b);
    if(b>=a)
    {
        s1=a+w;
        if((b-s1)>=1)
            printf("%d\n",b-s1);
        else printf("0\n");
    }
    else
    {
        s2=b+w;
        if(s2>=a)
            printf("0\n");
        else
            printf("%d\n",a-s2);
    }


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxn 200010
#define modn 1000000007
int a[maxn],f[maxn],cnt[maxn],n,i;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	f[0]=1;
	for (i=1;i<=n;i++)
		if (a[i]==a[i-1]) f[i]=f[i-1];
			else
			{
				f[i]=(f[i-1]+cnt[a[i]])%modn;
				cnt[a[i]]=f[i];
			}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main()
{
  int h,w;
  while(1)
  {
    cin>>h>>w;
    if((h==0)&&(w==0)) break;
    for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
        cout<<'#';
      cout<<endl;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[200000],n,a[200000],b[200000],MOD=1000000007,ans;
ll f(ll x,ll y){
    if(y<=0)return 1;
    if(y%2==1)return f(x,y-1)*x%MOD;
    return f(x,y/2)*f(x,y/2)%MOD;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>dp[i];
    sort(dp,dp+n);
    for(ll i=0LL;i<n;i++){
        a[i]=f(2,i);
        b[n-i-1]=(f(2,i)+i*f(2,i-1)%MOD)%MOD;
    }
    for(int i=0;i<n;i++){
        ans+=dp[i]*a[i]%MOD*b[i]%MOD;
        ans%=MOD;
    }
    cout<<ans*f(2,n)%MOD<<endl;
}


Measured memory_bytes: 4992
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
 
for i in range(N):
    k = B[i] - A[i]
    if k > 0:
        ans += A[i]
        A[i] = 0 
        if A[i+1] < k:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += k
            A[i+1] -= k
    else:
        ans += B[i]
        A[i] =- k

print(ans)


Measured memory_bytes: 18476
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int N,X;
    cin >> N >> X;
    int m[N];
    int sum=0;
    REP(i,N){
        cin >> m[i];
        sum += m[i];
    }
    sort(m,m+N);
    cout << N + (X-sum)/m[0];
}

Measured memory_bytes: 256
#include <stdio.h>
typedef unsigned int uint;

#pragma GCC optimize ("O3")
inline static uint gl(void){
    uint x = 0;
    for(;;){
        const uint c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}
#pragma GCC optimize ("Ofast")
#define H 200000
uint v[H] __attribute__((aligned(64)));
int main(void){
    const uint h = gl();
    gl();
    const uint n = gl();
    for(uint i=0; i<H; i++){ v[i] = 0xffffff; }
    for(uint i=0; i<n; i++){
        const uint x = gl()-1;
        const uint y = gl()-1;
        v[x] = y<v[x] ? y : v[x];
    }
    uint right = 0;
    for(uint x=1; x<h; x++){
        const auto b = v[x];
        const auto r = right+1;
        if(b<r){
            printf("%d\n", x);
            return 0;
        }else if(b>r){
            right=r;
        }
    }
    printf("%d\n", h);
    return 0;
}


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

typedef pair<char, bool> P;

vector< P > vec;
long long n,cntA=0,cntB=0;
char tmp;

bool find(int x,int judge){
    if(judge){//後
        for(int i=x+1;i<n;i++){
            P a = vec[i];
            if(a.first == ')' && a.second){
                vec[i] = make_pair(a.first,false);
                return true;
            }
        }
    }else{//前
        for(int i=x-1;i>=0;i--){
            P a = vec[i];
            if(a.first == '(' && a.second){
                vec[i] = make_pair(a.first,false);
                return true;
            }
        }
    }
    return false;
}

int main(void){
    char a[101];
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> a[i];
        vec.push_back(make_pair(a[i],true));
    }

    for(int i=0;i<n;i++){
        if(a[i] == '('){
            if(!find(i,1)){
                cntA++;
            }
        }else{
            if(!find(i,0)){
                cntB++;
            }
        }
    }
    for(int i=0;i<cntB;i++){
        cout << "(";
    }
    for(int i=0;i<n;i++){
        cout << a[i];
    }
    for(int i=0;i<cntA;i++){
        cout << ")";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n,m;
    cin >> n >> m;
    vector<VP> d(m);
    map<int,int> cnt;
    int in;
    REP(i,0,n) {
        cin >> in;
        cnt[in]++;
    }
    for (auto p: cnt) {
        int key = p.first, value = p.second;
        d[key%m].pb(key, value);
    }
    REP(i,0,m) sort(all(d[i]), [](auto &l, auto &r) {
        return l.second % 2 > r.second % 2;
    });
    LL ans = 0;
    REP(i,1,(m+1)/2) {
        LL tmp = 0;
        LL sum1 = 0, sum2 = 0;
        REP(j,0,d[i].size()) sum1 += d[i][j].second;
        REP(j,0,d[m-i].size()) sum2 += d[m-i][j].second;
        //dump(sum1);
        //dump(sum2);
        int n = abs(sum1 - sum2);
        if (sum1 <= sum2) {
            tmp += sum1;
            RREP(j,0,d[m-i].size()) {
                if (d[m-i][j].second <= n) {
                    tmp += d[m-i][j].second / 2;
                    n -= (d[m-i][j].second / 2) * 2;
                } else {
                    tmp += n / 2;
                    break;
                }
            }
        } else {
            tmp += sum2;
            RREP(j,0,d[i].size()) {
                if (d[i][j].second <= n) {
                    tmp += d[i][j].second / 2;
                    n -= (d[i][j].second / 2) * 2;
                } else {
                    tmp += n / 2;
                    break;
                }
            }
        }
        ans += tmp;
        //dump(i);
        //dump(tmp);
    }
    if (m % 2 == 0) {
        LL tmp = 0;
        REP(i,0,d[m/2].size()) tmp += d[m/2][i].second;
        ans += tmp / 2;
    }
    LL tmp = 0;
    REP(i,0,d[0].size()) tmp += d[0][i].second;
    ans += tmp / 2;
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}
// 21:17-22:22, 23:34-

Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[100005], finv[100005], inv[100005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge>>G;

int main() {
	int n, a, b;
	cin >> n;
	string h;
	map<int, string>m;
	cout << 0 << endl;
	fflush(stdout);
	cin >> h;
	if (h == "Vacant") { return 0; }
	m[0] = h; m[n] = m[0];
	a = 0, b = n;
	while (1) {
		cout << (a + b) / 2 << endl;
		fflush(stdout);
		string mon;
		cin >> mon;
		m[(a + b) / 2] = mon;
		if (mon == "Vacant") { return 0; }
		int monn = (a + b) / 2;
		if (m[a] == m[monn] && a % 2 == monn % 2) { a = monn; }
		else if (m[a] == m[monn]) { b = monn; }
		else if (a % 2 == monn % 2) { b = monn; }
		else { a = monn; }
	}
}

Measured memory_bytes: 976
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    string S;cin>>S;
    for(int i=0;i<S.size();i++){
        int n=S[i]+N;
        if(n<=90){
            S[i]=S[i]+N;
        }
        else{
            S[i]=S[i]+N-26;
        }
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
k=[list(map(int,input().split())) for _ in range(M)] 
*p,=map(int,input().split())
t=0
a=0
for i in range(2 ** N): # 点灯しているスイッチ
    t=0
    for j in range(M): # それぞれの電球
        #print(k[j][0],k[j][1:],p[j])
        o=sum(1 for h in k[j][1:] if i>>(h-1)&1) # onしているスイッチの個数
        #print('{:05b}'.format(i),j+1,o)
        if o%2==p[j]:
            t+=1
    if t==M:
        a+=1
print(a)

Measured memory_bytes: 9160
from sys import stdin
N = int(stdin.readline())
A = sorted([int(stdin.readline()) for i in range(N)])

a = [0] * N
b = [0] * N
j = 1

for i in range(N-1):
    a[i] += -j
    a[i+1] += j
    b[i] += j
    b[i+1] += -j
    j = -j

a.sort()
b.sort()
s1 = s2 = 0
for i in range(N):
    s1 += a[i] * A[i]
    s2 += b[i] * A[i]
print(max(s1, s2))

Measured memory_bytes: 8744
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define lol long long

int main()
{
	int N;
	cin >> N;
	string A, B, C;
	cin >> A >> B >> C;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == B[i] && B[i] == C[i]) {
			ans += 0;
		}
		else if (A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) {
			ans += 2;
		}
		else {
			ans += 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
List = [list(map(str, input().split())) for i in range(N)]
for i in range(N):
    List[i].append(str(i+1))
    List[i][1] = int(List[i][1])

List.sort(key=lambda x:(x[0],-x[1]))
for i in range(N):
    print(List[i][2])

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;

int main(){

    int n;
    cin >> n;
    for (int i = 0; i < n;i++)
    {
        double x1, y1, x2, y2, x3, y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        double p = ((y1 - y3)*(pow(y1, 2) - pow(y2, 2) + pow(x1, 2) - pow(x2, 2)) - (y1 - y2)*(pow(y1, 2) - pow(y3, 2) + pow(x1, 2) - pow(x3, 2))) / (2 * (y1 - y3)*(x1 - x2) - 2 * (y1 - y2)*(x1 - x3));
        double q = ((x1 - x3)*(pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2)) - (x1 - x2)*(pow(x1, 2) - pow(x3, 2) + pow(y1, 2) - pow(y3, 2))) / (2 * (x1 - x3)*(y1 - y2) - 2 * (x1 - x2)*(y1 - y3));
        double r = pow((pow((x1 - p), 2) + pow((y1 - q), 2)), 0.5);

        printf("%.3f %.3f %.3f\n", p, q, r);
    }

    return 0;
}

Measured memory_bytes: 1296
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;
#define n_max 100000

#define rep(i,n) for(int i = 0; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;
typedef pair<ll, ll> PI;

int main() {

    int a, b;
    cin >> a >> b;
    cout << a + b/2 << endl;

    return 0;
}


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

l=[[0 for i in range(n)] for j in range(n)]##静的確保

for i in range(n):
    p=[int(x) for x in input().split()]
    
    for j in range(n):
        if j+1 in p[2:]:
            l[i][j]=1

for i in range(n):
    print(*l[i])
            



Measured memory_bytes: 6392
#include <bits/stdc++.h>
    
using namespace std;
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
    
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
    
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
    
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a+b) % 24 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#define numof(array) (sizeof(array)/sizeof *(array))

bool InputAndSearch(int* pnData, int nNumOf);
int BinSearch(int *sData,int n,int* tData,int q);

int main()
{
    int s[100000],t[100000];
	int n,q;

	cin>>n;
	for(int i=0;i<n;i++) cin>>s[i];//*(sData+i)ともかけたはず
	
	cin>>q;
	for(int i=0;i<q;i++) cin>>t[i];

	cout<<BinSearch(s,n,t,q)<<endl;


    
}

int BinSearch(int *sData,int n,int* tData,int q){
	int first,last;
	int cnt=0;
	int comp;//比較要素
	
	
	for(int j=0;j<q;j++){
	   first=0;
	   last=n-1;

		while((last-first)>=0){
			comp=(first+last)/2;
			if(tData[j]==sData[comp]){
				
				cnt++;
				break;
			}
			else if(tData[j]<sData[comp]){//求めたい数より小さい場合
				last=comp-1;
			}
			else{
				first=comp+1;
			}
			
		}


	}

	return cnt;
}




Measured memory_bytes: 3564
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2018-6-3 21:00:30
# Powered by Visual Studio Code
#

n = gets.to_i
ans = 10000

for a in 1...n
  b = n - a
  # puts "#{a}, #{b}"
  sum = 0
  a.to_s.chars{|c|
    sum += c.to_i
  }
  b.to_s.chars{|c|
    sum += c.to_i
  }
  ans = [ans, sum].min
end

puts ans

Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nmk = Console.ReadLine().Split(' ');
            int n = int.Parse(nmk[0]);
            int m = int.Parse(nmk[1]);
            int k = int.Parse(nmk[2]);
            int[] a = new int[m];
            int[] b = new int[m];
            int[] yujins = new int[n];
            UnionFind uni = new UnionFind(n);


            int[] blocking = new int[n];
            for (int i = 0; i < m; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                a[i] = int.Parse(ab[0])-1;
                b[i] = int.Parse(ab[1])-1;
                yujins[a[i]]++;
                yujins[b[i]]++;
                uni.Unite(a[i], b[i]);
            }
            int[] c = new int[k];
            int[] d = new int[k];
            for (int i = 0; i < k; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                c[i] = int.Parse(ab[0])-1;
                d[i] = int.Parse(ab[1])-1;

                if(uni.IsSameGroup(c[i],d[i]))
                {
                    blocking[c[i]]++;
                    blocking[d[i]]++;
                }
            }
            for (int i = 0; i < n; i++)
            {
                int kore = uni.Root(i);
                int kouhos = uni.data[uni.Root(i)];
                Console.Write(-kouhos - yujins[i] - blocking[i]-1);
                if (i != n - 1) { Console.Write(" "); }
            }
            Console.WriteLine();

            
        }
    }

    public class UnionFind
    {
        public int[] data;

        public UnionFind(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }
}


Measured memory_bytes: 18344
def lcm(a, b):
  gcd = a
  _ = b
  while _:
    gcd, _ = _, gcd%_
  return a*b // gcd

def run():
  N = int(input())
  T_li = [int(input()) for n in range(N)]
  i = T_li[0]
  for T in T_li[1:]:
    i = lcm(T, i)
  print(i)
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(void)
{
  int n; cin>>n;
  int sum=0;
  int l,r;
  for(int i=0;i<n;i++){
    cin>>l>>r;
    sum+=r-(l-1);
  }
  
  cout<<sum<<endl;
  return 0;
}



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

#define N 100000

int main(void){
    bool prime[N+1];
    for (size_t i = 2; i <= N; i++)
    {
        prime[i]=true;
    }
    const int max = sqrt(N);
    for (size_t i = 0; i <= max; i++)
    {
        if (prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=false;
            }
        }
    }
    int likeCnt[N]={};
    for (size_t i = 1; i <= N; i++)
    {
        likeCnt[i]=likeCnt[i-1];
        if (i%2==1&&prime[i]&&prime[(i+1)/2])
        {
            likeCnt[i]++;
        }
    }
    /**************************************/
    int q;
    cin >> q;
    int l[q],r[q];
    for (size_t i = 0; i < q; i++)
    {
        cin >>l[i]>>r[i];
    }
    for (size_t i = 0; i < q; i++)
    {
        cout << likeCnt[r[i]]-likeCnt[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+7;

LL covered(const vector< LL > &A, LL z) {
    LL ans = 0;
    for (LL i = 0; i < A.size(); i++) {
        LL y = z-A[i];
        ans += A.end() - lower_bound(A.begin(), A.end(), y);
    }
//    cout << z << " -> " << ans << endl;
    return ans;
}

int main() {
    LL n, m;
    cin >> n >> m;

    vector< LL >A(n);
    for (LL i = 0; i < n; i++) cin >> A[i];

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

    LL lo = A.front()*2, hi = A.back()*2;

    while (lo <= hi) {
        LL mid = (lo+hi)/2;

        if (covered(A, mid) < m) hi = mid-1;
        else lo = mid+1;
    }

    ///hi has ans
    vector< LL >suffix(A);
    suffix.push_back(0);
    for (LL i = n-1; i >= 0; i--) suffix[i] += suffix[i+1];

    LL ans = 0;
    for (LL i = 0; i < n; i++) {
        LL idx = upper_bound(A.begin(), A.end(), hi-A[i])-A.begin();
        m -= n-idx;
        ans += suffix[idx]+(n-idx)*A[i];
//        cout << i << " -> " << idx << endl;
    }

    assert(m >= 0);
    ans += m*hi;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<(n/(a+b))*a+min(a,n%(a+b));
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
def determine_digit(digit_num, acm, n):
    mod = 2 ** (digit_num + 1)
    if (n - acm) % mod:
        return 1
    else:
        return 0


def convert(n):
    if n == 0:
        return '0'

    result = ''
    acm = 0
    digit_num = 0
    # print('n:', n)
    while n != acm:
        # print(digit_num, acm, result)
        d = determine_digit(digit_num, acm, n)
        # print('d: ', d)

        # incremental procedure
        acm += d * (-2)**digit_num
        digit_num += 1
        result += str(d)

    return result[::-1]


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

    print(convert(n))


Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

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

template<class T> bool chmin(T& a,T b){
    if(a > b){ a = b; return true; }else return false;
}
template<class T> bool chmax(T& a,T b){
    if(a < b){ a = b; return true; }else return false;
}
typedef int64_t ll;
//素因数分解 O(√n)
map<ll,ll>prime_factor(ll n){
    map<ll,ll> res;
    for(ll i = 2;i * i <= n;i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1LL;
    return res;
}

class DDivGame {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
        int64_t n;cin >> n;

        auto M = prime_factor(n);

        int64_t ans = 0;
        for(auto e : M){
            int64_t v = e.second;
            int64_t i = 1;
            while(true){
                if(i <= v){
                    v -= i;
                    i++;
                    ans++;
                }else break;
            }
        }
        cout << ans << '\n';

	}
	void main2(istream& cin,ostream& cout){

	}
};


int main() {
	DDivGame solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3656