akhauriyash/Code-Regression huggingface dataset:
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let i, ans = ref 1, ref 1
let _ = while !ans < n do i := a_s.(!i - 1); if !i = 2 then (Printf.printf "%d\n" !ans; exit 0); incr ans done;
  print_endline "-1"

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int N;
    cin >> N;
    vector<pair<ll, int>> X;
    vector<ll> B(N);
    rep(i ,N) {
        ll x;
        cin >> x;
        X.push_back(make_pair(x, i));
    }
    sort(X.begin(), X.end());
    rep(i, N) {
        if (i <= N/2-1) {
            B[X[i].second] = X[N/2].first;
        }
        else {
            B[X[i].second] = X[N/2-1].first;
        }
    }
    rep(i, N) {
        cout << B[i] << endl;
    }
}

Measured memory_bytes: 7792
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s;
    cin>>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <iostream>

int main()
{
	int n, m;
	std::cin >> n >> m;

	int A[100][100] = { 0 };
	int b[100] = { 0 };
	int c[100] = { 0 };

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			std::cin >> A[i][j];
		}
	}

	for (int i = 0; i < m; i++) {
		std::cin >> b[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] += A[i][j] * b[j];
		}
		std::cout << c[i] << std::endl;
	}
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    ll ans = 0;
    exrep(i, 1, n) {
        ll a;
        cin >> a;
        if(i%2 == 1 && a%2 == 1) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

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

typedef long long ll;
static const ll INF = 1ll<<60;
static const int MOD = 1e9+7;

int main(){
    string s,t;
    cin>>s>>t;
    int cnt = 0;

    for(int i=0; i<(int)s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }

    cout<<cnt<<endl;
    
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int k, a, b;
    cin >> k >> a >> b;
    rep(i, a, b + 1) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    string s;
    int k;
    cin>>s>>k;
    char ans='1';
    for(int i=0;i<k;i++){
        if(s[i]!='1'){
            ans=s[i];
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

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

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

vector <ll> par; // 各元の親を表す配列
vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

void init_u(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
	for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}

// Member Function
// Find
ll root(ll x) { // 根の検索
	while (par[x] != x) {
		x = par[x] = par[par[x]]; // x の親の親を x の親とする
	}
	return x;
}

// Union(Unite, Merge)
bool merge(ll x, ll y) {
	x = root(x);
	y = root(y);
	if (x == y) return false;
	// merge technique（データ構造をマージするテク．小を大にくっつける）
	if (siz[x] < siz[y]) swap(x, y);
	siz[x] += siz[y];
	par[y] = x;
	return true;
}

bool issame(ll x, ll y) { // 連結判定
	return root(x) == root(y);
}

ll size(ll x) { // 素集合のサイズ
	return siz[root(x)];
}

ll N, M, K;
ll A[100010], B[100010], C[100010], D[100010];
ll si[100010];
ll ans;

void solve() {
	cin >> N >> M >> K;
	init_u(N + 1);
	rep(i, M) {
		cin >> A[i] >> B[i];
		merge(A[i], B[i]);
		si[A[i]]++, si[B[i]]++;
	}
	rep(i, K) {
		cin >> C[i] >> D[i];
		if (!issame(C[i], D[i])) continue;
		si[C[i]]++, si[D[i]]++;
	}
	for (ll i = 1; i <= N; i++) {
		cout << size(i) - si[i] - 1;
		if (i == N) cout << endl;
		else cout << ' ';
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 6528
//:::: Alien :::://
// Muhammad Eid //
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define prINT pair<int, int>

const int N = 4 +5;
int ar[N];

void Mo35(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

int main(){
Mo35();

    string s;
    int t; cin>> t;
    while(t--){
        cin>> s;
        if(s == "AC") ar[0]++;
        else if(s == "WA") ar[1]++;
        else if(s == "TLE") ar[2]++;
        else ar[3]++;
    }
    cout<< "AC x "<< ar[0]<< "\n";
    cout<< "WA x "<< ar[1]<< "\n";
    cout<< "TLE x "<< ar[2]<< "\n";
    cout<< "RE x "<< ar[3]<< "\n";

return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long cumuXor(long long A) {
  if(A == 0) return 0;

  long long ans = 0;

  long long pair = (A+1)/2;

  if(pair % 2 != 0) ans = 1;

  if(A % 2 == 0) ans ^= A;

  return ans;

}


int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  long long A, B;
  cin >> A >> B;
  if(A == 0) cout << cumuXor(B) << endl;
  else cout << (cumuXor(B)^cumuXor(A-1)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX],n;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> R[i];

    int min = R[0];
    int max = -1000000000;

    for (int i = 1; i < n; i++){
        if ( max < R[i] - min){
            max = R[i] - min;
        }
        if ( min > R[i]){
            min = R[i];
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 3792
import statistics as st
N = int(input())
a = [int(x) for x in input().split()]
m = st.mean(a)

#print(m)#
nbr = abs(a[0]-m)
idx = 0
for i in range(1,N):
    if abs(a[i]-m)<nbr:
        nbr = abs(a[i]-m)
        idx = i
print(idx)

Measured memory_bytes: 5400
H,W = map(int,input().split())
char = [0 for _ in range(26)]
rem = [0,0,0,0]

for i in range(H):
    a = input()
    for j in range(W):
        char[ord(a[j])-97] += 1

for i in range(26):
    rem[char[i]%4] += 1
    
if H%2==0 and W%2==0:
    print('Yes' if rem[0]==26 else 'No')
    
elif H%2!=0 and W%2!=0:
    print('Yes' if rem[1]+rem[3]==1 and rem[2]+rem[3]<=(H-1)//2+(W-1)//2 else 'No')
    
else:
    print('Yes' if rem[1]+rem[3]==0 and rem[2]<=(H%2)*(W//2)+(W%2)*(H//2) else 'No')

Measured memory_bytes: 3192
#include <iostream>

using namespace std;

int main(){
  int n,a,b;
  int total = 0;
  
  cin >> n >> a >> b;
  
  for(int i = 1 ; i <= n ; i++){
    int sum = 0;
    int temp = i;
    while(temp / 10 != 0){
      sum += temp % 10; 
      temp = temp / 10;
    }
    sum += temp;
    if(a <= sum && sum <= b) total += i;
  }
  
  cout << total << endl;
  
  return 0;
}

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

k = 1000
maxk = 1

for j in range(n,1,-1):#5,4,3,2で回す時
	for i in range(j-1,1,-1):
		#print(j,i)
		if j%i ==0 :
			k = j
			t = i
			while k>=t :
				#print('-------')
				#print(k,t)
				k = k/t
				#print(k)
				if k == 1 and maxk < j:				
					maxk = j
					#print('Yes')
					break
				
print(maxk)
	

	




Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S / 3600;
        S %= 3600;
        int m = S / 60;
        S %= 60;
        int s = S;
        System.out.println(h + ":" + m + ":" + s);
        sc.close();
    }
}


Measured memory_bytes: 26288
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

L, R = map(int, input().split())


MOD = 2019

l = L % 2019
r = R % 2019

if (R//MOD) - (L//MOD) > 0:
    r += 2019

res = 2019
for i in range(l, r):
    for j in range(i+1, r+1):
        res = min((i * j) % MOD, res)

print(res)



Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve() {
    int a,b; cin>>a>>b;
    int i=1;
    if(b==1){
        cout<<0;
        return 0;
    }
    while(a*i-(i-1)<b) i++;
    cout<<i;
    return 0;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

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

int n,q;
char s[252521];
char t[252521], d[252521];

int main(){
	scanf("%d%d",&n,&q);
	scanf("%s",s);
	REP(i,q)scanf("%s%s",t+i,d+i);
	int rp, lp;
	int ok = -1, ng = n;
	while(abs(ok-ng)>1){
		int x = (ok+ng)/2;
		bool right = false;
		int p = x;
		REP(i,q)if(s[p]==t[i]){
			p += d[i]=='R' ? +1 : -1;
			if(p==n){
				right = true;
				break;
			}
		}
		if(right){
			ng = x;
		}else{
			ok = x;
		}
	}
	rp = ok;
	ok = n, ng = -1;
	while(abs(ok-ng)>1){
		int x = (ok+ng)/2;
		bool left = false;
		int p = x;
		REP(i,q)if(s[p]==t[i]){
			p += d[i]=='R' ? +1 : -1;
			if(p==-1){
				left = true;
				break;
			}
		}
		if(left){
			ng = x;
		}else{
			ok = x;
		}
	}
	lp = ok;
	printf("%d\n",rp-lp+1);
	return 0;
}

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

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

main()
{
    int n;cin>>n;
    typedef long long ll;
    vector<ll> s(n);
    for(int i=0;i<n;i++)cin>>s[i];
    ll res=0;
    for(int p=1;p<=n-1;p++)
    {
        if((n-1)%p==0)
        {
            ll tmp=0;
            ll cur=0;
            int i=0,j=n-1;
            for(;i<j;i+=p,j-=p)
            {
                cur+=s[i]+s[j];
                chmax(tmp,cur);
            }
            chmax(res,tmp);
        }
        else
        {
            ll tmp=0;
            ll cur=0;
            int i=0,j=n-1;
            for(;i<n-1&&j>p;i+=p,j-=p)
            {
                cur+=s[i]+s[j];
                chmax(tmp,cur);
            }
            chmax(res,tmp);
        }
        
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int count = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) == t.charAt(i)) count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 22608
# input
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

# process
A.sort()
B.sort()

if N%2 == 1:
    m = (N+1)//2-1
    ans = B[m] - A[m] + 1
else:
    m1 = N//2-1
    m2 = m1+1
    ans = int(((B[m1]+B[m2])/2-(A[m1]+A[m2])/2)*2)+1
    
# output
print(ans)


Measured memory_bytes: 25540
#include <iostream>
using namespace std;
int main() {
long long A, B, K;
cin >> A >> B >> K;

if (K <= A){
    cout << A - K << ' ' << B << "\n";
}
else if (K <= A + B){
    cout << 0 << ' ' << A + B - K << "\n";
}
else{
    cout << 0 << ' ' << 0 << "\n";
}
}


Measured memory_bytes: 256
n,m=list(map(int,input().split()))
c=[]
for i in range(n):
    c.append([])
for i in range(m):
    a,b=list(map(int,input().split()))
    c[a-1].append(b-1)
    c[b-1].append(a-1)

for i in range(n):
    print(len(c[i]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define drep(i,x,y) for(int i=(x);i>=(y);--i)
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
char S[200010], T[200010];
int main(){
	int n = read(), m = read(), N = read();
	int sr = read(), sc = read();
	scanf("%s", S);
	scanf("%s", T);
	int lx = 1, rx = n, ly = 1, ry = m;
	for(int i = N - 1; i >= 0; -- i) {
		if(T[i] == 'L') ry = min(m, ry + 1);
		if(T[i] == 'R') ly = max(1, ly - 1);
		if(T[i] == 'U') rx = min(n, rx + 1);
		if(T[i] == 'D') lx = max(1, lx - 1);
		if(S[i] == 'L') ++ ly;
		if(S[i] == 'R') -- ry;
		if(S[i] == 'U') ++ lx;
		if(S[i] == 'D') -- rx;
		if(lx > rx || ly > ry) return puts("NO"), 0;
	}
	if(lx <= sr && sr <= rx && ly <= sc && sc <= ry) {
		puts("YES");
	}
	else puts("NO");
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll a;
  cin >> a;
  cout << a+a*a+a*a*a << '\n';
}

Measured memory_bytes: 3612
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
#input = sys.stdin.readline

s = list(input())
t = list(input())
s.sort()
t.sort(reverse=True)
for i in range(len(s)):
    if i>len(t)-1:
        print('No')
        break
    elif s[i]>t[i]:
        print('No')
        break
    elif s[i]<t[i]:
        print('Yes')
        break
else:
    if len(t)==len(s):
        print('No')
    else:
        print('Yes')


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, t;
  cin >> n >> t;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll profit = 0, sml = a[0], pattern = 0;
  for(int i = 1; i < n; i++) {
    if (sml > a[i]) sml = a[i];
    else if (a[i] - sml > profit) {
      profit = a[i] - sml;
      pattern = 1;
    } else if (a[i] - sml == profit) pattern++;
  }

  cout << pattern << endl;

	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static long[] ReadLongArray()
    {
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        long[] a = ReadLongArray();

        long[] b = new long[n+1];
        for (int i = 1; i <= n; i++)
            b[i] = b[i-1] + a[i-1];

        Array.Sort(b);

        long ans = 0;
        long curr = b[0] - 1;
        long num = 1;
        for (int i = 0; i <= n; i++)
        {
            if (b[i] == curr) num++;
            else
            {
                ans += num * (num - 1) / 2;
                curr = b[i];
                num = 1;
            }
        }
        ans += num * (num - 1) / 2;
        WriteLine(ans);
    }
}

Measured memory_bytes: 38880
open Printf
open Scanf

let id x = x
             
let () =
  let n = scanf "%d\n" id in
  let dp = Array.make_matrix n n 0 in
  let mxa = Array.init n (fun _ -> scanf "%d %d\n" (fun x y -> (x, y))) in
  let rec iter i j =
    if i = 0 && j = n then dp.(0).(n-1)
    else if j = n then iter 0 (n-i+1)
    else
      let rec min_mc mc k =
        if k = j then mc
        else let tmc = dp.(i).(k) + dp.(k+1).(j) + fst mxa.(i) * snd mxa.(k) * snd mxa.(j) in
             min_mc (min mc tmc) (k+1)
      in
      begin
        dp.(i).(j) <- min_mc max_int i;
        iter (i+1) (j+1)
        end
  in iter 0 1 |> printf "%d\n"

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N,S;
vpl x;
vi ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    F0R(i,N) {
        pi t; cin >> t.f >> t.s;
        x.pb(t);
    }
    int l = 0, r = N-1;
    while (1) {
        if (x[r].f < S) {
            ans.pb(x[l].f);
            ans.pb(S);
            break;
        }
        if (S < x[l].f) {
            ans.pb(x[r].f);
            ans.pb(S);
            break;
        }
        if (x[l].s >= x[r].s) {
            x[l].s += x[r].s;
            ans.pb(x[r].f);
            r --;
        } else {
            x[r].s += x[l].s;
            ans.pb(x[l].f);
            l ++;
        }
    }
    ll z = 0;
    F0R(i,sz(ans)-1) z += abs(ans[i]-ans[i+1]);
    cout << z;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

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

struct UnionFind {
    vector<long long> data;
    UnionFind(long long sz) { data.assign(sz, -1); }

    // 集合xとyを併合する. 併合済みの時 false, 未併合の時trueを返す.
    bool unite(long long x, long long y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    // 要素kが属する集合を求める.
    long long find(long long k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    // 要素kが属する集合の要素の数を求める.
    long long size(long long k) { return (-data[find(k)]); }
};

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

    long long N, M;
    cin >> N >> M;
    vector<pair<long long, long long>> AB(M);
    vector<long long> ans(M);
    ans[M - 1] = N * (N - 1) / 2;
    for (long long i = 0; i < M; i++) {
        long long a, b;
        cin >> a >> b;
        AB[i] = {--a, --b};
    }
    UnionFind uf(N);
    for (long long i = M - 1; i >= 1; i--) {
        if (uf.find(AB[i].first) == uf.find(AB[i].second)) {
            ans[i - 1] = ans[i];
        } else {
            ans[i - 1] = ans[i] - (uf.size(AB[i].first) * uf.size(AB[i].second));
            uf.unite(AB[i].first, AB[i].second);
        }
    }
    for (long long i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<ll> explode(string const & s, char delim) {
    vector<ll> result;
    string token;
    for (istringstream iss(s); getline(iss, token, delim);) result.push_back(stoll(token));
    return result;
}

void solve() {
    int n, c, k;
    cin >> n >> c >> k;
    int num = 0;
    int st = -1;
    int ans = 0;
    if (c == 1) {
        cout << n << endl;
        return;
    }
    vi t(n);
    REP(i, n) cin >> t[i];
    SORT(t);
    REP(i, n) {
        if (st != -1 and st + k < t[i]) {
            ans++;
            st = t[i];
            num = 1;
        } else {
            if (num + 1 >= c) {
                ans++;
                st = -1;
                num = 0;
            } else {
                if (num == 0) st = t[i];
                num++;
            }
        }
    }
    if (num > 0) ans++;
    cout << ans << endl;
}


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

int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	int x = (c + b - 1) / b;
	int y = (a + d - 1) / d;
	if(x <= y) {
		printf("%s\n", "Yes");
	}else {
		printf("%s\n", "No");
	}
}

Measured memory_bytes: 3768
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        LinkedList<Integer> L = new LinkedList<>();
        ListIterator<Integer> it = L.listIterator();
        for(int i=0;i<q;i++){
            int cmd = sc.nextInt();
            if(cmd==0) {
                it.add(sc.nextInt());
                it.previous();
            }
            else if(cmd==1){
                int d = sc.nextInt();
                if(d>0)for(int j=0;j<d;j++)it.next();
                else{
                    d = Math.abs(d);
                    for(int j=0;j<d;j++)it.previous();
                }
            }
            else{
                it.next();
                it.remove();
            }
        }
        StringBuilder opt = new StringBuilder();
        for(int i:L) opt.append(i+"\n");
        System.out.print(opt);
        }
}


Measured memory_bytes: 294652
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define ff first
#define ss second
#define ll long long
#define int long long
#define mod 1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	ll a,b,h;
	cin>>a>>b>>h;
	ll ans=((a+b)*h)/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int k;
    cin >> k;

    int odd, even;
    if (k % 2 == 0) {
        odd = k / 2;
        even = k / 2;
    }
    else {
        odd = int(k / 2);
        even = int(k / 2) + 1;
    }
    P(odd * even);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    char c[510][510];
    rep(i, 0, h) rep(j, 0, w) cin >> c[i][j];
    char r[510][510], b[510][510];
    rep(i, 0, h){
        rep(j, 0, w - 1){
            if(j == 0 || i % 2 == 0 || c[i][j] == '#') r[i][j] = '#';
            else r[i][j] = '.'; 
        }
        r[i][w - 1] = '.';
        b[i][0] = '.';
        rep(j, 1, w){
            if(j == w - 1 || i % 2 || c[i][j] == '#') b[i][j] = '#';
            else b[i][j] = '.';
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            cout << r[i][j];
        }
        cout << endl;
    }
    cout << endl;
    rep(i, 0, h){
        rep(j, 0, w){
            cout << b[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1664
def makeComb(num):
    if num == n:
        totalM = [0] * m
        totalC = 0
        for i in range(n):
            if s[i] == 1:
                for j in range(m):
                    totalM[j] += ca[i][j+1]
                totalC += ca[i][0]
        for i in range(m):
            if totalM[i] < x:
                return
        global ans
        ans = min(ans, totalC)
        return

    makeComb(num+1)
    s[num] = 1
    makeComb(num+1)
    s[num] = 0

n, m, x = map(int, input().split())

ca = [0] * n
for i in range(n):
    ca[i] = list(map(int, input().split()))

INF = 1001001001
ans = INF

s = [0] * n
makeComb(0)

if ans == INF:
    ans = -1
print(ans)

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

double dp[555][555];

int main()
{
	int n,m;cin >> n >> m;
	vector<double> v(n+1);
	REP(i,n)cin >> v[i+1];
	
	for(int k = 0;k < m;k++){
		for(int i = k;i < n;i++){
			if(!(i == 0 && k == 0)&& dp[i][k] == 0)continue;
			double sum = 0;
			for(int j = 1;i+j <= n;j++){
				sum += v[i+j];	
				dp[i+j][k+1] = max(dp[i+j][k+1],dp[i][k] + (sum/j));
			}
		}
	}
	
	//SHOW2d(dp,n+1,m+1);
	
	cout << Decimal << dp[n][m] << endl;

	
	return 0;
}


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

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((x[2] - x[1]) % 2 == 0 ? "Alice" : "Borys");
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = 3.141592654;
void solve()
{
   ll n,s;
   cin>>n>>s;
   ll arr[n+1];
   for(int i=0;i<n;i++)
    cin>>arr[i];
   sort(arr,arr+n);
   if(n<=s)
    cout<<0<<endl;
   else
   {
       ll sum=0;
       for(int i=0;i<n-s;i++)
        sum+=arr[i];

       cout<<sum<<endl;
   }
}

int main()
{

    //freopen("Input.txt","r",stdin);
    ios_base :: sync_with_stdio(false);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 1920
import java.io.PrintWriter
import kotlin.collections.*

val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

    fun func() {
        val n = nextInt()
        val a = emptyList<Int>().toMutableList()
      	for(i in 0 until n){a.add(nextInt())}
        val a_s = a.map{e-> e}.sortedDescending()
      	for(i in 0 until n){
          if(a[i]==a_s[0]){println(a_s[1])}
          else println(a_s[0])
        }
    }

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

fun println(value : Any) {
    pw.println(value)
}


Measured memory_bytes: 63280
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<ll> h;
  rep(i, n){
    ll x;
    cin >> x;
    h.pb(x);
  }
  sort(h.begin(), h.end());
  ll res = linf;
  for(int i = 0; i + k <= n; i++){
    res = min(res, h[i+k-1] - h[i]);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll N, M, X; cin >> N >> M >> X;
	ll A[100];
	ll total_L = 0, total_R = 0;
	rep(i, 0, M) {
		cin >> A[i];
		if (A[i] > X) {
			total_R++;
		}
		else {
			total_L++;
		}
	}
	cout << ((total_L > total_R) ? total_R : total_L) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N;
  cin >> N;
  ll ans = 1;
  for(int i=1;i<=100000;i++){
    if(i*i<=N) ans = i*i;
    else break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools

N = int(input())
M=len(str(N))
count=0
for i in range(3,M):
  for x in itertools.product('357',repeat=i):
    if '3' in x and '5' in x and '7' in x:
      count +=1
for x in itertools.product('357',repeat=M):
  if '3' in x and '5' in x and '7' in x:
    x_i =0
    for j in range(len(x)):
      x_i +=int(x[j])*10**(len(x)-j-1)
    if x_i<=N:
      count +=1
print(count)

Measured memory_bytes: 3064
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String inputed = new String(in.readLine());

		String value[] = inputed.split("[\\s]+");
		//int intInputed = Integer.parseInt(inputed);

		int first  = Integer.parseInt(value[0]);
		int second = Integer.parseInt(value[1]);
		int third  = Integer.parseInt(value[2]);

		if ((first < second) && (second < third)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 24608
from math import ceil

N = int(input())
A, B = map(int, input().split())
ans = 1
for i in range(1, N):
    x, y = map(int, input().split())
    ans = max(A//x+min(1, A%x), B//y+min(1, B%y))
    A = ans*x
    B = ans*y
print(A+B)


Measured memory_bytes: 3188
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define ar array
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll int a, b;
	cin >> a >> b;
	if((a+b)%2==0) {
		cout << (a+b)/2 << endl;
	}else{
		cout << "IMPOSSIBLE";
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
typedef long long ll;
int fst[SZ],nxt[SZ],vb[SZ],cap[SZ],ff[SZ],M=1,N=0;
#define ad_de ad_dl
void _ad_dl(int a,int b,int c) {++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;cap[M]=c;}
void ad_dl(int a,int b,int c)
{_ad_dl(a,b,c); _ad_dl(b,a,0);}
int S,T,q[SZ],d[SZ];
bool bfs()
{
    memset(d,-1,4*(N+1));
    d[T]=0; q[1]=T; int h=1,t=2;
    while(h!=t)
    {
        int cur=q[h++];
        for(int e=fst[cur];e;e=nxt[e])
        {
            int b=vb[e];
            if(d[b]==-1&&cap[e^1])
            {
                d[b]=d[cur]+1, q[t++]=b;
                if(b==S) return 1; //这是玄学 
            }
        }
    }
    return d[S]!=-1;
}
int dfs(int x,int f)
{
    if(f<=0) return 0;
    if(x==T) return f;
    int ca=0;
    for(int& e=fst[x];e;e=nxt[e]) //当前弧优化 
    {
        int b=vb[e];
        if(d[b]+1!=d[x]) continue;
        int w=dfs(b,(cap[e]<f-ca)?cap[e]:(f-ca));
        cap[e]-=w; cap[e^1]+=w; ca+=w;
        if(ca==f) break;
    }
    if(!ca) d[x]=-1; //另一个优化 
    return ca;
}
#define inf 2e9+3
int dinic()
{
    int ans=0;
    memcpy(ff,fst,4*(N+1));
    while(bfs())
    {
        //当前弧优化
        ans+=dfs(S,inf);
        memcpy(fst,ff,4*(N+1));
    }
    return ans;
}
int h,w,p[103][103][2],a[103],b[103];
char tmp[103];
int main()
{
	scanf("%d%d\n",&h,&w);
	for(int i=1;i<=h;i++) a[i]=++N;
	for(int i=1;i<=w;i++) b[i]=++N;
	for(int i=1;i<=h;i++)
	{
		scanf("%s",tmp);
		for(int j=1;j<=w;j++)
		{
			if(tmp[j-1]=='.') continue;
			p[i][j][0]=++N;
			p[i][j][1]=++N;
			ad_dl(p[i][j][1],a[i],1e9);
			ad_dl(a[i],p[i][j][0],1e9);
			ad_dl(p[i][j][1],b[j],1e9);
			ad_dl(b[j],p[i][j][0],1e9);
			if(tmp[j-1]=='S')
			{
				S=N; continue;
			}
			if(tmp[j-1]=='T')
			{
				T=N-1; continue;
			}
			ad_dl(N-1,N,1);
		}
	}
	int ans=dinic();
	if(ans>h*w) ans=-1;
	printf("%d\n",ans);
}

Measured memory_bytes: 14720
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        //Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        int M = cin.Nextint;

        var G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray();

        for (int i = 0; i < M; i++)
        {
            int a = cin.Nextint - 1, b = cin.Nextint - 1;
            G[a].Add(b);
            G[b].Add(a);
        }

        var Q = new Queue<int>();
        var R = new Queue<int>();

        Q.Enqueue(0);
        R.Enqueue(1); //2の0乗

        int ans = 0;
        //int cnt = 0;

        while (Q.Any())
        {
            int u = Q.Dequeue(), v = R.Dequeue();
           // Console.WriteLine(u);
            /*for (int i = 0; i < N; i++)
            {
                if ((v & (1 << (N - 1 - i))) != 0) Write(1);
                else Write(0);
            }
            WriteLine();*/
            if(v == (1 << N) - 1)
            {
                ans++;
                continue;
            }
            foreach (var x in G[u])
            {
                if ((v & (1 << x)) != 0)continue;
                Q.Enqueue(x);
                R.Enqueue((v | (1 << x)));
            }

        }

        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 13524
s = input()
i = 0
while True and i < len(s):
  # 奇数文字目
  if (i+1) % 2 == 1:
    if s[i] == "L":
      print("No")
      break
  # 偶数文字目
  if (i+1) % 2 == 0:
    if s[i] == "R":
      print("No")
      break
  if i == len(s)-1:
    print("Yes")
  i += 1

Measured memory_bytes: 2940
/*package whatever //do not write package name here */

import java.util.*;

class Main {
	public static void main (String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    int k=sc.nextInt();
	    int arr[]=new int[n];
	    for(int i=0;i<n;i++)
	    arr[i]=sc.nextInt();
	   // int dp[]=new int[100];
	    System.out.println(frog(arr,arr.length,k));
	}
static int frog(int arr[],int n,int k)
{
    int dp[]=new int[n];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        dp[i]=1000000000;
        for(int j=i;j>=0 && (i-j)<=k;j--)
        {
        int option1=Math.abs(arr[i]-arr[j])+dp[j];
        dp[i]=Math.min(option1,dp[i]);
        }
    }
    return dp[n-1];
}
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long N, x;
	cin >> N >> x;
	vector<long long>a(N+1);
	a[0] = 0;
	for (int i = 0; i <= N; i++){
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 1; i <= N; i++){
		long long tmp = a[i] + a[i - 1] - x;
		if (tmp > 0) {
			ans += tmp;
			a[i] -= tmp;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
def choco(a, d):
	return (d - 1) / a + 1

n = int(raw_input())
inpt = map(int, raw_input().split())
ans = inpt[1]

for i in range(0, n):
	a = int(raw_input())
	ans = ans + choco(a, inpt[0])

print ans

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

constexpr int INF = numeric_limits<int>::max() / 4;

#define REP(i, stop) for (signed i = 0; i < stop; ++i)

#define S(i, j) ip[i * (N + 1) + j]

const signed is = 1 << 16;
char ib[is], *ip = ib, it;
char S[201][201];
signed main() {
	fread_unlocked(ib, 1, is, stdin);
	int N = 0;
	while ((it = *ip++) != '\n') {
		N = N * 10 + it - '0';
	}
  queue<int> que;
  que.push(0);
  vector<bool> used(N, false);
  used[0] = 1;
  vector<int> parity(N, -1);
  parity[0] = 0;
  while (que.size()) {
    int i = que.front();
    que.pop();
    REP(j, N) {
      if (S(i, j) == '1') {
        if (used[j]) {
          if (parity[i] == parity[j]) {
		puts("-1\n");
		return 0;
          }
        } else {
          que.push(j);
          used[j] = true;
          parity[j] = 1 - parity[i];
        }
      }
    }
  }
	vector<vector<int>> d(N, vector<int>(N));
	REP(i, N) REP(j, N) {
		d[i][j] = i == j ? 0 : S(i, j) == '1' ? 1 : INF;
	}
	REP(k, N) REP(i, N) REP(j, N) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
	int ans = 0;
	REP(i, N) REP(j, N) {
		if (d[i][j] < INF)
			ans = max(ans, d[i][j]);
	}
	printf("%d\n", ans + 1);
}


Measured memory_bytes: 512
def binary_search(A, q):
    left = -1
    right = len(A)

    while (right - left) > 1:
        mid = (left + right) // 2 
        if q >= A[mid]:
            left = mid
        else:
            right = mid

    if A[left] == q:
        return True

    else:
        return False


def main():
    _ = int(input())
    S = list(map(int, input().split()))
    _ = int(input())
    T = list(map(int, input().split()))
    cnt = 0
    for t in T:
        if binary_search(S, t):
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16708
A,B,K=map(int,input().split())
a=[]
for i in range(1,A+1):
    if A%i==0:a.append(i)
b=[]
for i in range(1,B+1):
    if B%i==0:b.append(i)
c=set()
c=sorted(list(set(a)&set(b)))[::-1]
print(c[K-1])

Measured memory_bytes: 3064
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    ans=0
    for i in range(1,n+1):
        if (i%3)>0 and (i%5)>0:
            ans+=i
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16224
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	std::string str;
	int okasi[100];
	bool abpizza = false;
	int a = 0, b = 0, c = 0, x=0, y=0,price=0;
	std::cin >> a >>b>>c>>x>>y;
	if (c * 2 < a + b) {
		abpizza = true;
	}
	if (abpizza) {
		if (x < y) {
			price = min(c*x*2+b*(y-x),c*y*2);
	}
		else {
			price = min(c*y * 2 + a*(x - y), c*x * 2);
		}
	}
	else {
		price = a*x + b*y;
	}
	std::cout << price << endl;
}

Measured memory_bytes: 256