akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


// 1白
// 2黒

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int co[100002]={};
	vector<P> tree[n];
	FOR(i,0,n-1){
		int a,b,w;
		cin >> a >> b >> w;
		a--;b--;
		tree[a].push_back({b,w&1});
		tree[b].push_back({a,w&1});
	}
	queue<int> q;
	q.push(0);
	co[0] = 1;
	while(!q.empty()){
		int now = q.front();
		q.pop();
		for(auto &&to:tree[now]){
			if(co[to.first]==0){
				if(to.second){
					co[to.first] = 3 - co[now];
				}else{
					co[to.first] = co[now];
				}
				q.push(to.first);
			}
		}
	}
	FOR(i,0,n){
		cout << co[i]-1 << endl;
	}
}


Measured memory_bytes: 8320
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int a,b,c;

int main(){
	cin >> a >> b >> c;
	int ans = INF;
	rep(x,100) rep(y,100) rep(z,100){
		int A = a, B = b, C = c;
		A += x; B += x;
		B += y; C += y;
		C += z; A += z;
		if(A%2 != B%2 || B%2 != C%2 || C%2 != A%2) continue;
		int mx = max(A,max(B,C));
		int zan = A-mx + B-mx + C-mx;
		if(ans > x+y+z-zan/2) ans = x+y+z-zan/2;
	}

cout<<ans<<endl;}


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

using namespace std;

const int N=2e5+5;

int n,maxx;
string s;
map <string, int> votes;

int main()
{
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>s;
        votes[s]++;
    }
    for(auto x:votes)
    {
        //cout<<x.first<<" "<<x.second<<endl;
        if (x.second>=maxx)
        {
            maxx=x.second;
        }
    }
    for(auto x:votes)
    {
        if (x.second==maxx)
        {
            cout<<x.first<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")

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

int c[26];
int64_t csum;
int64_t s[366][26];

int64_t eval(const vector<int> &state, int d){
    int last[26] = {0};
    int64_t decl = -csum;
    int64_t score = 0;

    for(int i=1;i<=d;++i){
        score += s[i][state[i]];
        decl += (i - last[state[i]])*c[state[i]];
        last[state[i]] = i;
        score += decl;
        decl -= csum;
    }
    return score;
}

vector<int> beam(int D, int w){
    using Tp = tuple<vector<int>, array<int, 26>, int64_t, int64_t>;
    map<int64_t, Tp, greater<int64_t>> mp;
    for(int i=0;i<26;++i){
        array<int, 26> x;
        for(int j=0;j<26;++j) x[j] = 0;
        x[i] = 1;

        mp[s[1][i] + c[i] - csum] = make_tuple(vector<int>{2, i}, x, -csum+c[i], s[1][i] + c[i] - csum);
    }
    for(int d=2;d<=D;++d){
        int cnt = 0;
        vector<Tp> states;
        for(auto p: mp){
            states.push_back(p.second);
            ++cnt;
            if(cnt >= w) break;
        }
        mp.clear();
        for(const Tp &v: states){
            for(int i=0;i<26;++i){
                auto [state, last, decl, score] = v;
                state.emplace_back(i);
                score += s[d][i];
                decl += (d - last[i])*c[i];
                last[i] = d;
                score += decl;
                decl -= csum;
                mp[score] = make_tuple(state, last, decl, score);
            }
        }
    }
    return get<0>(mp.begin()->second);
}

int main(){
    int d;
    scanf("%d", &d);
    for(int i=0;i<26;++i) scanf("%d", &c[i]);
    for(int i=0;i<26;++i) csum += c[i];

    for(int i=1;i<=d;++i){
        for(int j=0;j<26;++j) scanf("%" SCNd64, &s[i][j]);
    }

    auto ans = beam(d, 330);
    for(int i=1;i<=d;++i) printf("%d\n", ans[i] + 1);

    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s;
i64 dp[101010][13];
void solve(){
	cin >> s;
	int n = s.size();
	
	dp[n][0] = 1;
	i64 d = 1;
	for(int i = n-1; i >= 0; i--){
		for(int j = 0; j < 13; j++){
			if(s[i] == '?'){
				for(int k = 0; k < 10; k++){
					int cnt = (d*k + j)%13;
					dp[i][cnt] += dp[i+1][j];
					dp[i][cnt] %= INF;
				}
			}
			else{
				int cnt = (d*(s[i]-'0') + j)%13;
				dp[i][cnt] += dp[i+1][j];
				dp[i][cnt] %= INF;
			}
		}
		d = mod(d*10, 13);
	}
	cout << dp[0][5] << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 10704
use std::io;
use std::str::FromStr;
use std::io::{stdout, Write, BufWriter};


macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[test]
fn test_1(){
   let l = vec![2, 4, 4, 3];
   let mut l_sort = l.clone();
   l_sort.sort();

   let expect = solve(4, 0, &l, &l_sort);
   assert_eq!(4, expect);
   let expect = solve(4, 1, &l, &l_sort);
   assert_eq!(3, expect);
   let expect = solve(4, 2, &l, &l_sort);
   assert_eq!(3, expect);
   let expect = solve(4, 3, &l, &l_sort);
   assert_eq!(4, expect);
}

#[test]
fn test_2(){
   let l = vec![1, 2];
   let mut l_sort = l.clone();
   l_sort.sort();

   let expect = solve(2, 0, &l, &l_sort);
   assert_eq!(2, expect);
   let expect = solve(2, 1, &l, &l_sort);
   assert_eq!(1, expect);
}


#[test]
fn test_3(){
    let l = vec![5, 5, 4, 4, 3, 3];
    let mut l_sort = l.clone();
    l_sort.sort();


    let expect = solve(6, 0, &l, &l_sort);
    assert_eq!(4, expect);   
    let expect = solve(6, 1, &l, &l_sort);
    assert_eq!(4, expect);
    let expect = solve(6, 2, &l, &l_sort);
    assert_eq!(4, expect);
    let expect = solve(6, 3, &l, &l_sort);
    assert_eq!(4, expect);
    let expect = solve(6, 4, &l, &l_sort);
    assert_eq!(4, expect);
    let expect = solve(6, 5, &l, &l_sort);
    assert_eq!(4, expect);

}

fn solve(n: u64, i:u64, xi:&Vec<u64>, xi_sort:&Vec<u64>) -> u64{
    let m1 = xi_sort[(n / 2 - 1) as usize];
    let m2 = xi_sort[(n / 2) as usize];
    if xi[i as usize] <= m1 {
        m2
    } else {
        m1
    }
}

fn main() {

    let n = get!(u64);
    
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();

    let xi: Vec<u64> = buf.split_whitespace()
        .map(|n| u64::from_str(n).unwrap())
        .collect();

    let mut xi_sort = xi.clone();
    xi_sort.sort();

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    
    for i in 0..n {
        let ans = solve(n, i, &xi, &xi_sort);
        writeln!(out, "{}", ans).unwrap();   
    }
}


Measured memory_bytes: 13432
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

ll light(ll x, ll y) {
    if(x == y) return x;
    else if(x > y) {
        if(x % y != 0) return 2 * y * (ll)(x / y) + light(y, x % y);
        return 2 * y * (ll)(x / y) - y;
    }
    else {
        if(y % x != 0) return 2 * x * (ll)(y / x) + light(x, y % x);
        return 2 * x * (ll)(y / x) - x;
    }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, X; cin >> N >> X;
  cout << N + light(X, N - X) << endl;
  return 0;
}

Measured memory_bytes: 256
program ABC116A
    implicit none
    integer(8)::i
    integer(8),dimension(3)::A
    read(5,*)(A(i),i=1,3)
    A=iqsort(A)
    print'(i0)',A(1)*A(2)/2

contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC116A

Measured memory_bytes: 512
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    x, n = i_map()
    if n == 0:
        print(x)
        exit()
    num_list = i_list()

    abs_num = INF
    ans_list = []

    for i in range(0,102):
        if i in num_list:
            continue
        if abs_num > abs(i-x):
            ans_list = []
            abs_num = abs(i-x)
            ans_list.append(i)
        elif abs_num == abs(i-x):
            ans_list.append(i)

    ans_list.sort()

    print(ans_list[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 72620
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let _n: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<usize> = it.map(|s| s.parse().unwrap()).collect();
    let mut ans = 0;
    let mut min = std::usize::MAX;
    for p in a.iter() {
        min = std::cmp::min(min, *p);
        if *p <= min {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 10492
import sys
n = int(input())
a = [int(a) for a in input().split()]

done = {}
flag = 0
for i in range(n):
  try:
    if done[a[i]] > 0:
      flag = 1
    done[a[i]] = 1
  except:
    done[a[i]] = 1

if flag:
  print('NO')
else:
  print('YES')

Measured memory_bytes: 109012
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n,k ;
	cin >> n >> k ;
	cout << YorN((n+1)/2>=k) << endl ;
}


Measured memory_bytes: 256
#include<bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    string s; cin >> s;
    if(s == "ABC") {
        println("ARC");
    } else {
        println("ABC");
    }

    return 0;
}


Measured memory_bytes: 3616
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

Measured memory_bytes: 5048
var
	H,W,i,j,x,y:Longint;
	S:Array[1..100]of String;
	dp:Array[1..100,1..100]of Longint;
begin
	readln(H,W);
	for i:=1 to H do begin
		readln(S[i]);
		for j:=1 to W do begin
			x:=100000;
			y:=100000;
			if i>1 then begin
				x:=dp[i-1,j];
				if(S[i-1][j]='.')and(S[i][j]='#')then inc(x);
			end;
			if j>1 then begin
				y:=dp[i,j-1];
				if(S[i][j-1]='.')and(S[i][j]='#')then inc(y);
			end;
			if x<y then dp[i,j]:=x else dp[i,j]:=y;
			if(i=1)and(j=1)then begin
				if S[i][j]='#'then dp[i,j]:=1 else dp[i,j]:=0;
			end;
		end;
	end;
	writeln(dp[H,W]);
end.


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
   int N;
   cin >> N;
   string S;
   int CNT[] = {0, 0, 0, 0, 0};

   for (int i = 0; i < N; i++) {
      cin >> S;
      if (S[0] == 'M') CNT[0]++;
      else if (S[0] == 'A') CNT[1]++;
      else if (S[0] == 'R') CNT[2]++;
      else if (S[0] == 'C') CNT[3]++;
      else if (S[0] == 'H') CNT[4]++;
   }
   ll ans = 0;
   int n = 5, k = 3;

   int bit = (1<<k)-1;
   for (;bit < (1<<n); bit = next_combination(bit)) {
      ll tmp = 1;
      vector<int> S;
      for (int i = 0; i < n; i++) {
         if (bit & (1<<i)) {
            S.push_back(i);
         }
      }
      for (int i = 0; i < (int)S.size(); i++) {
         tmp *= CNT[S[i]];
      }
      ans += tmp;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    double a[101];
    cin >> a[0];
    double sum = a[0];
    for (int i = 1; i < N; i++){
        cin >> a[i];
        sum *= a[i];
    }
    double sum2 = 0;
    for (int i = 0; i < N; i++){
        sum2 += sum/a[i];
    }
    cout << fixed << setprecision(10) << (double)sum/sum2 << endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge{int to,cap,rev;};
const int MAX_V = 1001;
const int INF = 1<<29;
vector<edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()});
}
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v] = true;
  for(int i = 0;i < (int)G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
    
  }
  return 0;
}
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0)return flow;
    flow += f;
  }
}
int main() {
  int n;
  cin >> n;
  for(int i = 1;i < n;i++){
    int tmp;
    cin >> tmp;
    if(tmp > 0){
      add_edge(i,n,INF);
    }
  
  }
  for(int i = 0;i  < n-1;i++){
    int t,f,c;
    cin >> f >> t >> c;
    add_edge(f,t,c);
  }
  cout << max_flow(0,n) << endl;
  
  return 0;
}

Measured memory_bytes: 1296
N,Q = map(int,input().split())
s = str(input())
data = [0]
cnt = 0
for i in range(1,N):
    if s[i-1] == 'A' and s[i] == 'C':
        cnt += 1
        data.append(cnt)
    else :
        data.append(cnt)
for i in range(Q):
    l,r = map(int,input().split())
    r -= 1
    l -= 1
    ans = data[r] - data[l]
    print(ans)

Measured memory_bytes: 6100
from operator import itemgetter

N = int(input())
l = []
x = 0
y = 1
for i in range(N):
  a = input().split()
  a[1] = int(a[1])
  l.append(a)
  l[x].insert(2,y)
  x +=1
  y +=1
# print(l)

# l.sort()
b = sorted(l, key=itemgetter(1), reverse=True)
c = sorted(b, key=itemgetter(0))

# print(c)
for i in c:
  # print(i)
  print(i[2])



Measured memory_bytes: 3064
if __name__ == '__main__':
    n = int(input())
    S = input().split()
    q = int(input())
    T = input().split() 
    a = set()
    count = 0
    for i in range(q):
        ch = 0
        j1 = 0
        j3 = len(S)-1
        j2 = int((j1+j3)/2)
        while j1<=j3:
            ch = j2
            if T[i] == S[j2]: 
                if T[i] in a: break
                else :
                    a.add(T[i])
                    count += 1
                    break
            elif int(T[i]) < int(S[j2]): 
                j3 = j2-1
                j2 = int((j1+j3)/2)
            elif int(T[i]) > int(S[j2]): 
                j1 = j2+1
                j2 = int((j1+j3)/2)
    
    print(str(count))


Measured memory_bytes: 17840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 105;
const int MXN2 = 1e5;
int weight[MXN], profit[MXN];
ll dp[MXN][MXN2+5];
int N,W;

ll rec(int pos, int rem){

    if(rem<0) return INT_MIN;
    if(pos>N) return 0;
    ll &ret = dp[pos][rem];
    if(ret!=-1) return ret;
    return ret = max( rec(pos+1,rem-weight[pos]) + profit[pos] , rec(pos+1,rem)  );
}

void read(){
    cin>>N>>W;
    for(int i=1; i<=N; i++)
        cin>>weight[i]>>profit[i];
}

void solve(){

    memset(dp,-1,sizeof(dp));
    read();
    cout<< rec(1,W) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 85668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector <ll> v(n, 0);
  rep(i, k) {
    ll d;
    cin >> d;
    rep(j, d) {
      ll a;
      cin >> a;
      v.at(a-1)++;
    }
  }
  ll res = 0;
  rep(i, n) {
    if (v.at(i) == 0) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n; cin >> n;
    vll a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    ll c = 0;
    rep(i, 0, n){
        rep(j, i+1, n){
            rep(k, j+1, n){
                ll m = max(max(a[i], a[j]), max(a[j], a[k]));
                ll s = a[i] + a[j] + a[k]; 
                ll mn = min(min(a[i], a[j]), min(a[j], a[k]));
                ll md = s - m - mn;
                if(a[i] == a[j]||a[j] == a[k]||a[i] == a[k]){
                    continue;
                }
                if(m < mn + md){
                    c++;
                }
            }
        }
    }
    prtl(c);
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int n,k;
int a[maxn];
double ans[maxn],pre[maxn];
double mx=0;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		ans[i]=((double)a[i]+1.0)/2.0;
	}
	for(int i=1;i<=n;i++)
	{
		pre[i]=pre[i-1]+ans[i];
	}
	for(int i=k;i<=n;i++)
	{
		mx=max(mx,pre[i]-pre[i-k]);
	}
	printf("%0.12f\n",mx);
	return 0;
}

Measured memory_bytes: 4096
//26/04/2020
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'


#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

//Number Theory
template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}

//Geometry
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan2( double(y1-y2) , double(x1-x2));}


/*Containers*/
vector<ll>v;
deque<ll>dq;
stack<ll>stk;
map<ll,ll>mp;
unordered_map<ll,ll>ump;
set<ll>st;
multiset<ll>mst;
unordered_set<ll>ust;
unordered_multiset<ll>umst;
priority_queue<ll,deque<ll>,greater<ll>>pq;
Pbds<ll>ost;


int main(){
    _fastio
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    for(ll i=1;;i++){
        if(a<=0||c<=0) break;
        if(i%2) c-=b;
        else a-=d;
    }
    if(a<=0) cout<<"No"<<en;
    else cout<<"Yes"<<en;



    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n;
    long double x[1001];
    string u[101], t;
    long double ans = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> u[i];
        if (u[i] == "JPY") {
            ans += x[i];
        }
        else {
            ans += (x[i] * 380000);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long x;
  cin >> x;
  long sum = 0;
  for(long i=1;i<1e9;i++){
    sum += i;
    if(x <= sum){
      cout << i << endl;
      return 0;
    }
  }
}


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


int a[200050];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    long long phi=0,ans=0;
    for(int i=n;i>=1;i--)
    {
        if(a[i]<phi)
        {
            ans=-1;
            break;
        }
        else
        {
            if(a[i]>=i)
            {
                ans=-1;
                break;
            }
            if(a[i]>phi)
            {
                ans+=a[i];
                phi=a[i];
            }
            phi=max(0ll,phi-1);
        }
    }
    printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int n,a[110],p,odd=0,even=0;
  std::cin >> n >> p;
  for(int i=0; i<n; i++){
    std::cin >> a[i];
    if(a[i]%2) odd++;
    else even++;
  }

  if(odd==0 && even>0){
    if(p%2) std::cout << "0" << '\n';
    else{
      ll ans=1;
      for(int i=1; i<=n; i++) ans*=2;
      std::cout << ans << '\n';
    }
  }
  else{
    ll ans=1;
    for(int i=1; i<n; i++) ans*=2;
    std::cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

int mod = 1000000007;
ll exp(ll m, ll n) {
  if(n == 0) {return 1;}
  if(n == 1) {return m % mod;}
  ll tmp;
  tmp = exp(m * m % mod, n/2) % mod;
  if(n%2) {tmp = tmp * m % mod;}
  return tmp;
}

int main() {
  ll m, n;
  cin >> m >> n;
  cout << exp(m, n) << endl;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	string S;
	cin >> S;
	int ans = 0;
	int N = S.length();

	for (int i = 0; i < N / 2; i++) {
		if (S[i] != S[N - i - 1]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
char num[1001];

    while(1){
        int i=0,sum=0;

        scanf("%s", num);
        if(num[0]-'0'==0) break;
        
        while(num[i]){
        sum+=num[i]-'0';
        i++;
        }
    printf("%d\n",sum);
    }
    
    return(0);
}

Measured memory_bytes: 536
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]
    print(sum(N if all(S[(i - a) % N][j] == S[(j - a) % N][i] for i in range(N) for j in range(N)) else 0 for a in range(N)))


if __name__ == "__main__":
    main()


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

int main() {
    int n, m, a, b, bad[100000] = {}, h[100000];
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> h[i];
    for (int j = 0; j < m; ++j) {
        cin >> a >> b;
        --a;
        --b;
        if (h[a] < h[b]) bad[a] = 1;
        else if (h[a] > h[b]) bad[b] = 1;
        else {
            bad[a] = 1;
            bad[b] = 1;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (bad[i] == 0) ++cnt;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
#define all(x) x.begin(),x.end()
typedef pair<int,int>pii;

int p[2][200001];
int r[2][200001];
int uni(int j,int i){
	return p[j][i]=p[j][i]&&p[j][i]!=i?uni(j,p[j][i]):i;
}

int N,KL[2];
pair<pii,int>s[200001];
int ans[2000001];

main(){
	cin>>N>>KL[0]>>KL[1];
	for(int j=0;j<2;++j){
		for(int i=0;i<KL[j];++i){
			int a,b;
			cin>>a>>b;
			a=uni(j,a);
			b=uni(j,b);
			if(a!=b){
				if(r[j][a]<r[j][b]){
					p[j][a]=b;
				}else{
					p[j][b]=a;
					if(r[j][a]==r[j][b]){
						++r[j][a];
					}
				}
			}
		}
	}
	for(int i=1;i<=N;++i){
		s[i]={{uni(0,i),uni(1,i)},i};
	}
	sort(s+1,s+1+N);
	for(int i=1;i<=N;){
		int j=i+1,c=1;
		for(;j<=N&&s[i].first==s[j].first;++j){
			++c;
		}
		for(;i<j;++i){
			ans[s[i].second]=c;
		}
	}
	for(int i=1;i<=N;++i){
		cout<<ans[i]<<(i==N?"\n":" ");
	}
}


Measured memory_bytes: 8576
#include <iostream>
#include <bits/stdc++.h> 
#include <cmath>
#include <vector>

using namespace std ;

    int main(){
    	
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

        long long a,b,c,d;

        cin>>a>>b>>c>>d;
		
		vector<long long> v ;
		
		v.push_back(a*c);
		v.push_back(a*d);
		v.push_back(b*c);
        v.push_back(b*d);
        
        sort(v.begin(), v.end()); 
        
        cout<<v.at(3);
    }
    

Measured memory_bytes: 3580
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as Maybe
import qualified Debug.Trace as Trace

solve :: Int -> Int
solve n = solveImpl (maxBound :: Int) 1 n

solveImpl :: Int -> Int -> Int -> Int
solveImpl tmpAns i n
    | i * i > n = tmpAns
    | otherwise =
        if (mod n i == 0)
            then if (tmp < tmpAns)
                then solveImpl tmp (i + 1) n
                else solveImpl tmpAns (i + 1) n
            else solveImpl tmpAns (i + 1) n
    where tmp = (i + (div n i)) - 2

main = do
    n <- (fst . Maybe.fromJust . BS.readInt) <$> BS.getLine
    let ans = solve n
    print ans

Measured memory_bytes: 3772
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(1,0); }
	V<V<pin>> qab(2);
  int sz=ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
	for (pin x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2,x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2,(x.second + 1) / 2)); }
	}
	V<vel> c(2, vel(2));
	rep(i, 2) {
		for (pin x : qab[i]) {
			int qc = (2 * x.first + x.second) % 3;
          c[i][0]^=((qc+1)&1);
			if (qc) { c[i][1] ^= 1; }
		}
	}
	rep(i, 2) {
		if (!c[1 - i][0]&&!c[1-i][1]) {
			pin ans = solve(qab[i], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += i;
			return ans;
		}
	}
	for(pin &v:ab) { v.first++; }
	pin ans = solve(ab, ex); ans.first--;
	return ans;
}
signed main() {
	long long inf = 2e17;
	int n; scanf("%lld", &n);
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; scanf("%lld", &a); scanf("%lld", &b);
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf << "\n";
}

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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	ll K = 0;
	while ((ct = *ci++) >= '0') K = K * 10 + ct - '0';

	int A[200000];
	int *sei = A, *fu = A + 199999;
	int zero = 0;
	rep(i, N) {
		int a = getint();
		if (a > 0) *sei++ = a;
		else if (a < 0) *fu-- = -a;
		else zero++;
	}
	int seik = sei - A;
	int fuk = A + 199999 - fu;
	sei = A;
	fu++;
	pakuri_sort(seik, sei);
	pakuri_sort(fuk, fu);
	ll k0 = ll(seik) * fuk + ll(zero) * (zero - 1) / 2 + ll(zero) * (N - zero);

	ll L = -1000000000000000001, R = 1000000000000000000;
	while (L + 1 < R) {
		ll M = (L + R) / 2;
		ll k = 0;
		if (M >= 0) {
			k += k0;
			if (k >= K) { R = M; continue; }
			int i = 0;
			int j = seik - 1;
			while (i < seik) {
				while (j > i && ll(sei[i]) * sei[j] > M) j--;
				if (i == j) break;
				k += j - i;
				i++;
			}
			if (k >= K) { R = M; continue; }
			i = 0;
			j = fuk - 1;
			while (i < fuk) {
				while (j > i && ll(fu[i]) * fu[j] > M) j--;
				if (i == j) break;
				k += j - i;
				i++;
			}
		}
		else {
			int j = 0;
			rep(i, seik) {
				while (j < fuk && ll(sei[i]) * fu[fuk - j - 1] >= -M) j++;
				k += j;
			}
		}
		if (k >= K) R = M;
		else L = M;
	}

	printf("%lld\n", R);

	Would you please return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}

uint64_t dp[100000+5][13];

void solve(){
  string S;
  cin >> S;

  int N = S.size();
  dp[0][0] = 1;
  rep(i, N){
    int c;
    if(S[i] == '?') c = -1;
    else c = S[i] - '0';

    rep(j, 10){
      if(c != -1 && c != j) continue;
      rep(k, 13){
        dp[i+1][(k * 10 + j) % 13] += dp[i][k];
      }
    }

    rep(j, 13) dp[i+1][j] %= mod;
  }

  cout << dp[N][5] << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 10624
# データを入れる配列
data = gets.chomp.split("\s")
middle = data[0].to_i
final = data[1].to_i
reexam = data[2].to_i

until data == ["-1", "-1", "-1"]	#<= dataは文字列のまま

	# 中間試験 + 期末試験の点数の和で判別
	sum = middle + final
	
	# 中間試験 or 期末試験の欠席者: F
	if (middle == -1) or (final == -1)
		puts "F"
	elsif sum >= 80
		puts "A"
	elsif sum >= 65
		puts "B"
	elsif sum >= 50
		puts "C"
	elsif sum >= 30
		if reexam >= 50
			puts "C"
		else
			puts "D"
		end
	else
		puts "F"
	end
	
	data = gets.chomp.split("\s")
	middle = data[0].to_i
	final = data[1].to_i
	reexam = data[2].to_i
end

Measured memory_bytes: 6108
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
char s[1000001];
char t[1000001];
bool check(int n)
{
	for(int i=1;i<=n;i++)
		if(s[i]!=t[i])
			return false;
	return true;
}
deque<int> q;
signed main()
{
	int n;
	scanf("%d",&n);
	cin>>s+1>>t+1;
	if(check(n)){printf("0");return 0;}
	int pos=n;
	int ans=0;
	for(int i=n;i>=1;i--)
	{
		if(t[i]!=t[i-1])
		{
			pos=min(pos,i);
			while(pos&&s[pos]!=t[i])pos--;
			if(!pos){printf("-1");return 0;}
			while(!q.empty()&&q.front()-q.size()+1>i)
				q.pop_front();
			q.push_back(pos);
			if(i!=pos)ans=max(ans,(int)q.size());
		}
	}
	printf("%d",ans+1);
	return 0;
}
/*
5
abaca
aaabc
*/


Measured memory_bytes: 6272
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;

int main() {
  cin >> N;
  vector<long> A(N);
  vector<long> sum(N);
  long tmp = 0;
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
    tmp += A.at(i);
    sum.at(i) = tmp;
  }
  long ans = LONG_MAX;
  for (int i=1; i<N-2; i++) {
    long pq = sum.at(i);
    long p, q;
    if (i==1) {
      p = A.at(0);
      q = A.at(1);
    } else {
      long posp = distance(sum.begin(), lower_bound(sum.begin(), sum.begin()+i-1, (pq+1)/2));
      // cout << "posp: " << posp << endl;
      p = sum.at(posp);
      if (posp >= 1) {
        long p1 = sum.at(posp-1);
        if (abs(pq - 2*p1) < abs(pq - 2*p)) {
          p = p1;
        }
      }
      q = pq - p;
      // cout << "p: " << p << " q: " << q << endl;
    }
    long rs = sum.at(N-1) - sum.at(i);
    long r, s;
    if (i==N-3) {
      r = A.at(N-2);
      s = A.at(N-1);
    } else {
      long posr = distance(sum.begin(), lower_bound(sum.begin()+i+1, sum.end(), (rs+1)/2 + sum.at(i)));
      // cout << "posr: " << posr << endl;
      r = sum.at(posr) - sum.at(i);
      if (posr >= i+2) {
        long r1 = sum.at(posr-1) - sum.at(i);
        if (abs(rs - 2*r1) < abs(rs - 2*r)) {
          r = r1;
        }
      }
      s = rs - r;
      // cout << "r: " << r << " s: " << s << endl;
    }
    long ma = max(max(max(p,q),r),s);
    long mi = min(min(min(p,q),r),s);
    ans = min(ans, ma-mi);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

//Istiyak Hossain

int main()
{
    int a, b, i, j;

    scanf("%d %d", &a, &b);

    while(a | b)
    {
        for(i = 0; i < a; i++)
        {
            for(j = 0; j < b; j++)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &a, &b);
    }

    return 0;
}



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

using namespace std;

int main(void)
{
    int n, i, ans=0;
    string S;

    cin >> S;

    n = S.size();

    if(n%2==0){
        for(i=0; i<=n/2-1; i++){
            if(S[i] != S[n-1-i]){
                ans++;
            }
        }
    }

    else{
        for(i=0; i<=(n-1)/2-1; i++){
            if(S[i] != S[n-1-i]){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char cube[3][3];

	scanf("%s", cube[0]);
	scanf("%s", cube[1]);
	scanf("%s", cube[2]);
	printf("%c", cube[0][0]);
	printf("%c", cube[1][1]);
	printf("%c\n", cube[2][2]);
	return 0;
}

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

int main(){
	int N,K,P;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>K>>P;
		if(K%P==0){
			cout<<P<<endl;
		}else{
			cout<<K%P<<endl;
		}
	}
return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	string s;
	cin >> s;
	int c_count = 0;
	if (s[0] == 'A') {
		for (int i = 2; i < s.length() - 1; i++) {
			if (s[i] == 'C')c_count++;
		}
		if (c_count == 1) {
			s.erase(s.begin());
			bool clr = true;
			for (int i = 0; i < s.length(); i++) {
				if (s[i] == 'C' || ('a' <= s[i] && s[i] <= 'z')) {
					continue;
				}
				else clr = false;
			}
			if (clr) {
				print("AC");
				return 0;
			}
		}
	}
	print("WA");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

void go(string s, int mx, int n, vector<string>& ans) {
	if (n == 0) {
		ans.push_back(s);
		return;
	}
	for (int i = 0; i <= mx; ++i) {
		go(s + char('a' + i), max(mx, i + 1), n - 1, ans);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string> ans;
	go("", 0, n, ans);
	for (auto& s: ans) {
		cout << s << endl;
	}
}

Measured memory_bytes: 7796