akhauriyash/Code-Regression huggingface dataset:
add :: [Int] -> [Int] -> [Int]
add [] _ = []
add _ [] = []
add (x:xs) (y:ys) = (x+y):(add xs ys)

acm :: [[Int]] -> [Int]
acm (x1:[]) = x1
acm (x1:xs) =
  add x1 $ acm xs
  
ans :: [[Int]] -> [[Int]]
ans lst =
  let s1 = map (\r -> r ++ [sum r]) lst
      s2 = acm s1
  in
    s1 ++ [s2]

to_str :: [[Int]] -> String
to_str [] = ""
to_str (line:lines) =
  let sl = unwords $ map show line
      ss = to_str lines
  in
    (sl++"\n"++ss)

main = do
  c <- getContents
  let l = map (map read) $ map words $ lines c :: [[Int]]
      o = ans $ drop 1 l
  putStr $ to_str o

Measured memory_bytes: 5452
import math

N, K = map(int, input().split())
ans = 0

if N > K:
    ans += (N - K) / N

for i in range(min(N, K)):
    logk = math.ceil(math.log2(K / (i+1)))
    ans += 1 / N * (0.5 ** logk)

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#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++)

int main()
{
    int N, K; cin >> N >> K;
    vector<int> A(N + 5); rep(i, N) cin >> A[i];

    if (N == K) cout << 1 << endl;
    else cout << (N - K - 1) / (K - 1) + 2 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int p[100005];
string s[100005];
int wa[100005];
int ans;
int used[100005];
int anss;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>p[i];
		cin>>s[i];
		if(used[p[i]]){
			continue;
		}
		if(s[i]=="AC"){
			used[p[i]]=1;
			anss++;
			ans+=wa[p[i]];
		}else{
			wa[p[i]]++;
		}
	}
	cout<<anss<<" "<<ans;
	return 0;
}

Measured memory_bytes: 6784
n = int(input())
a = list(map(int,input().split()))
a.append(0)
a.insert(0,0)
s = 0
for i in range(n+1):
    s += abs(a[i]-a[i+1])
for i in range(1,n+1):
    print(s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))


Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> a(3);
    cin>>a[1]>>a[2]>>a[0];
    sort(a.begin(),a.end());
    if((a[0]==a[1]&&a[1]!=a[2])||(a[0]!=a[1]&&a[1]==a[2])){cout<<"Yes";}
    else{cout<<"No";}
}

Measured memory_bytes: 256
N,X = map(int,input().split())
D = 0
ans = 1
L = list(x for x in input().split())
for i in range(N):
    
    if D <=X:
        D+=int(L[i])
        ans+=1
    else:
        continue
if D >X:
    ans-=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
  	int a,b,c;
	cin >> a >> b >> c;
	
	if(a != b || a !=c || b != c)
	{
		cout<< "No" <<endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}

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

int main() {
    int N;
    
    cin >> N;
    vector<int> a(N + 1); 

    for (int i = 1; i < a.size(); i++) {
        cin >> a.at(i);
    }
    int ans = 1;
    int i;
    for (i = 1; i < N + 1; i++) {
        ans = a.at(ans);
        if (ans == 2)
            break;
    }

    if (i == N + 1)
        i = -1;

    cout << i << endl;
}

Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) {
    abc080c()
}

fun abc080c() {
    val n = readLine()!!.toInt()
    val fList = (1..n).map { readLine()!!.split(" ").map { it[0] == '1' }.toBooleanArray() }.toTypedArray()
    val pList = (1..n).map { readLine()!!.split(' ').map { it.toLong() }.toLongArray() }.toTypedArray()

    var answer = Long.MIN_VALUE / 10

    for (i in 1L..bits(10)) {
        val bitSet = BitSet.valueOf(longArrayOf(i))

        val sum = fList.mapIndexed { index, f ->
            val count = f.withIndex().count { it.value && bitSet[it.index] }
            pList[index][count]
        }.sum()

        answer = Math.max(answer, sum)
    }

    println(answer)
}

private fun bits(x: Int) = (1 shl x) - 1


Measured memory_bytes: 41084
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	int cont = 0;;
	
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v.push_back(a);
	}

	bool flag = false;
	while (true) {
		for (const auto& i : v) {
			if (i % 2 == 1) {
				flag = true;
			}
		}
		if (flag) {
			break;
		}
		cont++;
		for (auto& i : v) {
			i /= 2;
		}
	}
	cout << cont << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,m;
	scanf("%d",&n);
	for(m=0;m<n;m++)
	{
		int a[10],b=0,c=0,l,ans;
		for(l=0;l<10;l++)
		{
			scanf("%d",&a[l]);
		}
		for(l=0;l<10;l++)
		{
			if(a[l]>b)
			{
				b=a[l];
			}
			else if(a[l]>c)
			{
				c=a[l];
			}
			else
			{
				ans=0;
				break;
			}
			ans=100;
		}
		if(ans==0)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}
	return 0;
}

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

using namespace std;

template<typename T> std::ostream& operator<<(std::ostream&o, const std::vector<T>&t) {
	// this way helps deal with empty vector
	for (size_t i = 0; i < t.size(); ++i) {
		o << t[i] << " \n"[i == t.size() - 1];
	}
	return o;
}

int N;
vector<int> a;
void solve(){
	cin>>N;

	a.reserve(N);
	for (int i=0;i<N;i++){
		int x;
		cin>>x;
		a.push_back(x);
	}
	vector<int> b(a);
	nth_element(a.begin(), a.begin()+(N-1)/2, a.end());
	int m1 = a[(N-1)/2];
	int m2 = *min_element(a.begin()+(N+1)/2, a.end());
//	cout<<m1<<','<<m2<<endl;
	for (int i=0;i<N;i++){
		if (b[i]<=m1){
			cout<<m2<<'\n';
		}
		else{
			cout<<m1<<'\n';
		}
	}
}

int main(){
// 	freopen("in.txt","r",stdin);
// 	freopen("out.txt","w",stdout);
	std::ios::sync_with_stdio(false);

		solve();

	return 0;
}



Measured memory_bytes: 3840
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int a;
        cin >> a;
        cout << a * a * a << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;

template <class T>
void out(const T param) {
    cout << param << "\n";
}

int main() {
    
    long N;
    
    cin >> N;
    
    if(N%2 == 0) {
        out(N);
    }else {
        out(2*N);
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;


template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){d = extgcd(b,a%b,y,x); y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,mod);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
struct combination {
    ll M = mod;
    vector<ll> fact;vector<ll> ifact;
    combination(ll n):fact(n+1),ifact(n+1){
        fact[0]=1;ifact[0]=1;
        for (ll i = 0; i<n; i++) {fact[i+1] = fact[i]*(i+1) % M;ifact[i+1] = ifact[i]*modpow(i+1, M-2, M) % M;}
    }
    ll com(ll a, ll b){
        if(a == 0 && b == 0)return 1;if(a < b || a < 0)return 0;
        ll tmp = ifact[a-b]* ifact[b] % M;
        return tmp * fact[a] % M;
    }
};

int main()
{
    ll X,Y;
    cin >> X>> Y;
    ll a = 2*X-Y;
    ll b = 2*Y-X;

    if(a >= 0 && b >= 0 && a%3==0 && b%3==0){

        combination C((a+b)/3);
        out(C.com((a+b)/3,a/3));
    }else{
        out(0);
    }


    return 0;
}


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

int main() {
    string N;
    cin >> N;
    for(int i = 0; i < 3; ++i){
        char c = N[i];
        int n = (int)(c - '0');
        if (n == 7) {
           cout << "Yes";
           return 0;
        }
    }
    cout << "No";
    return 0;
}

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

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	int A[8][8]={};
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		A[u][v]=A[v][u]=1;
	}

	int ans=0,p[8];
	rep(u,n) p[u]=u;
	do{
		bool ok=true;
		rep(i,n-1) if(A[p[i]][p[i+1]]==0) ok=false;
		if(ok) ans++;
	}while(next_permutation(p+1,p+n));
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
ll dp[1010][5000];
int main()
{
    cout << fixed << setprecision(30);
    ll N, M;
    cin >> N >> M;
    vec a(M), b(M), c(M, 0);
    loop(i, M)
    {
        cin >> a[i] >> b[i];
        loop(j, b[i])
        {
            ll x;
            cin >> x;
            x--;
            c[i] += 1 << x;
        }
    }
    loop(i, 1010) loop(j, 5000) dp[i][j] = 1e18;
    dp[0][0] = 0;
    loop(i, M)
    {
        loop(bit, 1 << N)
        {
            //i番目の鍵を使わない
            dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][bit]);
            //i番目の鍵を使う
            dp[i + 1][bit | c[i]] = min(dp[i + 1][bit | c[i]], dp[i][bit] + a[i]);
        }
    }
    ll ans = dp[M][(1 << N) - 1];
    if (ans == 1e18)
        putout(-1);
    else
        putout(ans);
    return 0;
}


Measured memory_bytes: 43100
while True:
    H,W = [int(x) for x in input().split()]
    if H == 0 and W == 0: break
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0: print("#", end="")
            else: print(".", end="")
        print()
    print()


Measured memory_bytes: 7012
import java.util.Scanner;

class Card{
    public String suit;
    public int value;
    public int index;
}

public class Main{
    public static void main(String[] args){
	int i, q;
	
	Scanner scanner = new Scanner(System.in);
	int n = scanner.nextInt();
    	Card[] A = new Card[n];
	Card[] B = new Card[n];

	for(i=0; i<n; i++){
	    A[i] = new Card();
	    B[i] = new Card();
	}

	for(i=0; i<n; i++){
	    A[i].suit = scanner.next();
	    A[i].value = scanner.nextInt();
	    A[i].index = i; 
	}

	quickSort(A, n, 0, n-1);

	

	if(isStable(A) == true){
	    System.out.println("Stable");
	}else{
	    System.out.println("Not stable");
	}
	for(i=0; i<n; i++){
	    System.out.printf("%s %d\n", A[i].suit, A[i].value);
	    
	}
    }
    
    public static int partition(Card[] A, int n, int p, int r){
	int x, i, j;
	Card tmp;
	x = A[r].value;
	i = p-1;
	for(j=p; j<r; j++){
	    if(A[j].value<=x){
		i++;
		tmp = A[i]; A[i] = A[j]; A[j] = tmp;
	    }
	}
	tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp;
	return i+1;
    }

    public static void quickSort(Card[] A, int n, int p, int r){
	int q;
	if(p < r){
	    q = partition(A, n, p, r);
	    quickSort(A, n, p, q - 1);
	    quickSort(A, n, q + 1, r); 
	}
    }
    static boolean isStable(Card[] A){
	for(int i = 0; i < A.length; i++){
	    for(int j = i + 1; j < A.length; j++){
		if(A[i].value == A[j].value && A[i].index > A[j].index)
		    return false;
	    }
	}
    return true;
    }	    
}


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

int main(void){
    char input;
    bool s[3] = {false, false, false};
    int i;
    for(i = 1; i <= 3; i++){
        cin >> input;
        s[input - 'a'] = true;
    }
    
    if(s[0] && s[1] && s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
string s;
int dp[100010][13] = {0}, m[10];
int main() {
    cin >> s;
    int len = s.length();
    for(int i = 0; i < 10; i++) m[i] = (i * 10) % 13;
    if(s[len-1] == '?') {
        for(int i = 0; i < 10; i++) dp[len-1][i] = 1;
    }
    else dp[len-1][s[len-1]-'0'] = 1;
    for(int i = len - 2; i > -1; i--) {
        if(s[i] == '?') {
            for(int j = 0; j < 10; j++) {
                for(int k = 0; k < 13; k++) {
                    dp[i][(m[j]+k)%13] += dp[i+1][k];
                    dp[i][(m[j]+k)%13] %= M;
                }
            }
        }
        else {
            int c = s[i] - '0';
            for(int j = 0; j < 13; j++) dp[i][(m[c]+j)%13] += dp[i+1][j], dp[i][(m[c]+j)%13] %= M;
        }
        for(int j = 0; j < 10; j++) m[j] = (m[j] * 10) % 13;
    }
    cout << dp[0][5];
}

Measured memory_bytes: 5504
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  map<str,ll> mp;
  REP(i,n){
    str st;
    cin >> st;
    mp[st]++;
  }
  ll m;
  cin >> m;
  REP(i,m){
    str st;
    cin >> st;
    mp[st]--;
  }
  ll max = 0;
  for(auto itr = mp.begin(); itr!=mp.end(); itr++){
    if(max<itr->second) max = itr->second;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<float.h>
using namespace std;
#define equals(a,b) fabs((a)-(b))<DBL_EPSILON*fmax(1,fmax(fabs(a),fabs(b)))
class Point{
    public:
        double x,y;
        Point(double x=0,double y=0):x(x),y(y){}

        Point operator + (Point p){return Point(x+p.x,y+p.y);}
        Point operator - (Point p){return Point(x-p.x,y-p.y);}
        Point operator * (double a){return Point(a*x,a*y);}
        Point operator / (double a){return Point(x/a,y/a);}
            
        double norm(){return x*x+y*y;}
        double abs(){return sqrt(norm());}    
        
        bool operator < (const Point &p)const{
            return x!=p.x?x<p.x:y<p.y;
        }
        bool operator == (const Point &p)const{
            return equals(x,p.x)&&equals(y,p.y);
        }
};
typedef Point Vector;
struct Segment{
    Point p1,p2;
};
typedef Segment Line;

double dot(Vector a,Vector b){//内積
    return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){//外積
    return a.x*b.y-a.y*b.x;
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){//直角条件
    return equals(dot(a1-a2,b1-b2),0.0);
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){//平行条件
    return equals(cross(a1-a2,b1-b2),0.0);
}

int main(){
    int q;

    cin>>q;
    Point p[4];
    for(int i=0;i<q;i++){
        cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y;
        cin>>p[2].x>>p[2].y>>p[3].x>>p[3].y;
        if(isOrthogonal(p[0],p[1],p[2],p[3]))cout<<1<<"\n";
        else if(isParallel(p[0],p[1],p[2],p[3]))cout<<2<<"\n";
        else cout<<0<<"\n";
    }
    return 0;

}



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

using namespace std;
using ll = long long;

const ll mod = 1'000'000'007;

auto main (void) -> int {
  int n;
  cin >> n;

  vector<int> a (n);
  for (auto i = 0; i < n; i++) cin >> a[i];

  auto tmp_0 = 0LL;
  auto tmp_1 = 0LL;

  for (auto i : a) {
    auto c = static_cast<ll> (i);
    tmp_0 += c;
    tmp_1 += c * c;
    if (tmp_0 > mod) tmp_0 %= mod;
    if (tmp_1 > mod) tmp_1 %= mod;
  }
  tmp_0 = (tmp_0 * tmp_0) % mod;

  auto b = tmp_0 < tmp_1 ? tmp_0 - tmp_1 + mod : tmp_0 - tmp_1;

  cout << (b + (b % 2) * mod) / 2 << endl;

  return 0;
}


Measured memory_bytes: 3988
#include <stdio.h>
int gcd(int ,int); 
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",gcd(a,b));
  return 0;
}
int gcd(int x, int y){
  int tmp;
  if(x<y){
    tmp=x;
    x=y;
    y=tmp;
  }
  if(x%y==0)return y;
  gcd(x%y,y);
}

Measured memory_bytes: 592
def partition(A,p,r):
    x = A[r] 
    i = p
    for j in range(p,r):
        if A[j] <= x:
            A[i],A[j] = A[j],A[i]
            i += 1
    A[i],A[r] = A[r],A[i]
    return i

if __name__=='__main__':
    n=int(input())
    A = list(map(int,input().split()))
    ref = partition(A,0,n-1)
    print(*A[:ref],end='')
    print(' ['+str(A[ref])+'] ',end='')
    print(*A[ref+1:])

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll x, y;
	cin >> x >> y;
	cout << (x%y ? x : -1) << endl;

}



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

int H,W;
char S[110][110];

int main()
{
    scanf("%d%d",&H,&W);
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            scanf(" %c",&S[i][j]);
        }
    }
    for(int i = 0; i < W + 2; i++)printf("#");printf("\n");
    for(int i = 0; i < H; i++)
    {
        printf("#");
        for(int j = 0; j < W; j++)printf("%c",S[i][j]);
        printf("#\n");
    }
    for(int i = 0; i < W + 2; i++)printf("#");printf("\n");
    return 0;
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end());
    ll sum = 0;
    ll last = -1;
    for (int i=0;i<N-1;i++){
        sum += A[i];
        if (A[i+1] > 2*sum) {
            last = i;
        }
    }
    cout << N - last - 1 << "\n";
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;
struct order { int a, b, o; };

int main()
{
  int R, C, Q;
  while (scanf("%d %d %d", &R, &C, &Q) != EOF && R != 0) {
    static const int K = 50000;
    static bool doner[K], donec[K];
    fill_n(doner, R, false);
    fill_n(donec, C, false);
    static order os[K];
    for (int i = 0; i < Q; i++) {
      scanf("%d %d %d", &os[i].a, &os[i].b, &os[i].o);
    }

    long long row = R, col = C;
    long long ans = 0LL;
    for (int i = Q-1; i >= 0; i--) {
      if (os[i].a) {
        // column
        if (!donec[os[i].b]) {
          donec[os[i].b] = true;
          --col;
          if (os[i].o) {
            ans += row;
          }
        }
      } else {
        // row
        if (!doner[os[i].b]) {
          doner[os[i].b] = true;
          --row;
          if (os[i].o) {
            ans += col;
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    a, b = map(str, input().split())
    a = int(a)
    b = int(b[0] + b[2:])
    print((a * b) // 100)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 61904
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int x, t;
  cin >> x >> t;
  if (x - t >= 0) P(x- t);
  else P(0);
  return 0;
}

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

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

    vector<int> p(n);
    for(int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    
    int total = 0;
    for (int i = 0; i < k; i++) {
        total += p.at(i);
    }
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3540
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef pair<int, int> P;

int N;
int ans = 0;
int A[1000][1000];
int pointer[1000];

int CNT1 = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1; j++)cin >> A[i][j], A[i][j]--;
	}

	set<int> nxt, nnxt;
	while (1) {
		
		bool f = false;
		vector<P> candidate;
		if(ans == 0){
			for (int i = 0; i < N; i++) {
		
				if (pointer[i] >= N - 1) {
					continue;
				}
				int a = i, b = A[i][pointer[i]];
				if (A[b][pointer[b]] == a && a > b) {
					candidate.push_back(P(a, b));
				}
			}
		}
		else {
			if (nxt.size() == 0) {
				break;
			}
			for (auto it = nxt.begin(); it != nxt.end(); it++) {
				int a = (*it), b = A[a][pointer[a]];
				if (A[b][pointer[b]] == a && a > b) {
					candidate.push_back(P(a, b));
				}
			}
		}

		for (int i = 0; i < candidate.size(); i++) {
			int a = candidate[i].first, b = candidate[i].second;

			if (pointer[a] < N - 2) {
				pointer[a]++;
				nnxt.insert(a), nnxt.insert(A[a][pointer[a]]);
			}
			if (pointer[b] < N - 2) {
				pointer[b]++;
				nnxt.insert(b),nnxt.insert(A[b][pointer[b]]);
			}
			f = true;
		}

		if (!f) {
			cout << -1 << endl;
			return 0;
		}
		ans++;
		nxt.clear(), swap(nxt, nnxt);
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<n;)
    {
        int j=i;
        while(j<n and s[i]==s[j])
        {
            j++;
        }
        i=j;
        c++;
    }
    cout<<c;

    return 0;
}


Measured memory_bytes: 3716
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }
    public void Exe()
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        
        int a, p;
        a = input[0];
        p = input[1];

        p += a * 3;
        Console.WriteLine(p/2);

    }
}



Measured memory_bytes: 27244
#include <stdio.h>

int main(){
    int a[4] = {}, b[4] = {};
    int i, j, hit, blow;
    
    while(scanf("%d %d %d %d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3]) != EOF){
    	hit = 0; blow = 0;
        for (i = 0; i < 4; i++){
            for (j = 0; j < 4; j++){
                if (a[i] == b[j] && i == j) hit++;
                if (a[i] == b[j] && i != j) blow++;
            }
        }
        printf("%d %d\n", hit, blow);
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,c;cin>>a>>b>>c;
  int m=max(max(a,b),c);
  int ans=a+b+c-m;
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] size; // size of subtree, including self
    List<Integer>[] graph;
    long[] dp,ans;
    final long mod = 1000000000+7;
    long[] frac,inv; // inv[i] = the inversion of i! mod M
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
        out.flush();
//        System.out.println(main.solve());
    }
    long solve() throws IOException{
        int n = sc.nextInt(), k = sc.nextInt(), c = sc.nextInt();
        int[] prev = new int[n], suf = new int[n];
        char[] s = sc.next().toCharArray();
        if(c==0){
            int cnt = 0;
            for(char cha:s) cnt += cha=='o'?1:0;
            if(cnt==k){
                for(int i=0;i<n;i++){
                    if(s[i]=='o') out.println(i+1);
                }
            }
            return 0;
        }
        int tempc = c;
        // calculate prev
        prev[0] = s[0]=='o'?1:0;
        for(int i=1;i<n;i++){
            if(s[i]=='o'){
                if(i-tempc-1<0) prev[i] = 1;
                else prev[i] = Math.max(prev[i-1],prev[i-tempc-1]+1);
            } else{
                prev[i] = prev[i-1];
            }
        }
        // calculate suf
        suf[n-1] = s[n-1]=='o'?1:0;
        for(int i=n-2;i>=0;i--){
            if(s[i]=='o'){
                if(i+tempc+1>=n) suf[i] = 1;
                else suf[i]= Math.max(suf[i+1],1+suf[i+tempc+1]);
            } else{
                suf[i] = suf[i+1];
            }
        }
        // finally answer
        TreeSet<Integer> start = new TreeSet<>();
        for(int left = -c;left <n;left++){
            int front = left>=0?prev[left]:0;
            int back = left+c+1<n?suf[left+c+1]:0;
            if(front+back>=k) start.add(left);
        }
        for(int i=0;i<n;i++){
            if(s[i]=='x') continue;
            Integer key = start.lower(i);
            if(key==null || key+c<i) out.println(i+1);
        }
        return 0;
    }
}



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

int main() {
    int N;
    cin >> N;
    
    string result = "No";
    int sum = 0;
    int num = N;
    
    while(num > 0)
    {
        int buf = num % 10;
        sum += buf;
        num /= 10;
    }
    
    if(N % sum == 0)
    {
        result = "Yes";
    }
    
    cout << result << endl;
}


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

ll digit_len(ll num){
    ll cnt = 0;
    while(num){
        num = num / 10;
        ++cnt;
    }
    return cnt;
}

ll digit_sum(ll num){
    ll sum = 0;
    ll mod = 0;
    while(num){
        mod = num % 10;
        num = num / 10;
        sum += mod;
    }
    return sum;
}

ll digit_first(ll num){
    return num % 10;
}

ll digit_last(ll num){
    ll mod = 0;
    while(num){
        mod = num % 10;
        num = num / 10;
    }
    return mod;
}

void solve(long long N){
    ll max1;
    if(digit_last(N) > 1) max1 = (digit_len(N) - 1) * 9 + digit_last(N) - 1;
    else max1 = (digit_len(N) - 1) * 9;
    ll max2 = digit_sum(N);
    ll max3 = digit_sum(N - digit_first(N) - 1);
    /*
    cout << "max1: " << max1 << endl;
    cout << "max2: " << max2 << endl;
    cout << "max3: " << max3 << endl;
    cout << "digit_first(N): " << digit_first(N) << endl;
    cout << "number of max3 " << N - digit_first(N) - 1 << endl; 
    */
    cout << max(max1, max(max2, max3)) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,a,b; cin>>N>>M;
    bool t1[200005] = {},tN[200005] = {};
    rep(i,M){
        cin>>a>>b;
        if(a==1){
            t1[b] = true;
        }else if(b==1){
            t1[a] = true;
        }else if(a==N){
            tN[b] = true;
        }else if(b==N){
            tN[a] = true;
        }
    }
    repp(i,1,200001){
        if(t1[i]&&tN[i]){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}


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

typedef long long int ll;

int main(){
	int n, l; scanf("%d %d",&n,&l);
	int tab[n+1];
	int sum=0;
	for(int i=1;i<=n;i++){
		tab[i] = l+i-1;
		sum+=tab[i];
	}
	
	int mn = INT_MAX;
	int ind = 0;
	for(int i=1;i<=n;i++){
		if(abs(sum-(sum-tab[i])) < mn){
			mn = abs(sum-(sum-tab[i]));
			ind = i;
			//~ printf("i=%d\n",i);
		}
	}
	printf("%d",sum-tab[ind]);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// ?§?????????¨????????¨???????????????????¨???????????§???????
template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};
#define Graph(type) vector< vector< Edge<type> > >

// Kahn????????????????????????????????¢?????´????????? (Verified: AOJ GRL_4_B: Topological Sort)
template <typename T>
vector<int> tpsort_Kahn(const vector< vector< Edge<T> > > &g) {
    const int V = g.size();
    vector<int> indeg(V, 0);
    stack<int> S;

    rep(i,0,V) rep(j,0,g[i].size())
        indeg[ g[i][j].to ]++;
    rep(i,0,V) if(indeg[i] == 0) S.push(i);

    vector<int> ans;
    while(S.size() > 0) {
        int u = S.top(); S.pop();
        ans.pb(u);
        rep(i,0,g[u].size()) {
            indeg[ g[u][i].to ]--;
            if(indeg[ g[u][i].to ] ==  0)
                S.push( g[u][i].to );
        }
    }
    return ans;
}

signed main() {
    int v, e, s, t;
    cin >> v >> e;
    Graph(int) G(v);
    rep(i,0,e) {
        cin >> s >> t;
        G[s].pb(Edge<int>(t, 1));
    }

    vector<int> ret = tpsort_Kahn(G);
    if(ret.size() != v) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3200
n=int(input())
import bisect as bi
A=[] ; B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

A.sort() ; B.sort()
if n%2==1:
    a=A[(n-1)//2] ; b=B[(n-1)//2]
  
    print(b-a+1)
else:
    a=(A[n//2-1]+A[n//2])/2 ; b=(B[n//2-1]+B[n//2])/2
  
    print(int((b-a)/0.5)+1)


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


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

	for (int i = 0; i < s.size(); i++){
		for (int j = i+1; j < s.size(); j++){
			if(s[i]==s[j]){
				cout<<"no"<<endl;
				return 0;
		}
	}
	}
	cout<<"yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=1000000007;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

template <int n> struct COMB{
    int_fast64_t fc[n],ifc[n];
    constexpr COMB():fc(),ifc(){
        fc[0]=1;
        for(int i=1;i<n;++i) fc[i]=fc[i-1]*i%modint::MOD;
        int_fast64_t N=1,A=fc[n-1],b=modint::MOD-2;
        while(b){
            if(b&1) (N*=A)%=modint::MOD;
            (A*=A)%=modint::MOD;
            b>>=1;
        }
        ifc[n-1]=N;
        for(int i=n-1;i>=1;--i) ifc[i-1]=ifc[i]*i%modint::MOD;
    };
    modint operator()(int N,int R)const{
        if(N<0||R<0||N<R) return 0;
        return fc[N]*ifc[R]%modint::MOD*ifc[N-R];
    }
    modint operator[](int N)const{
        modint _;
        _.a=fc[N];
        return _;
    }
    modint operator()(int N)const{
        modint _;
        _.a=ifc[N];
        return _;
    }
};
constexpr COMB<666670> comb;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int x,y;
    in>>x>>y;
    if((x+y)%3!=0||x>2*y||y>2*x)return cout<<0<<endl,0;
    cout<<comb((x+y)/3,x-(x+y)/3)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, W, w[MAXN], v[MAXN];
ll dp[100010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> W;
    FOR(i,1,n) cin >> w[i] >> v[i];
    FOR(i,1,100000) dp[i] = 1e18;
    dp[0] = 0;
    FOR(i,1,n)
        FORE(j,100000,0)
            if (j - v[i] < 0) break;
            else dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
    FORE(i,100000,0)
        if (dp[i] <= W) {
            cout << i;
            return 0;
        }
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    string s,t;cin>>s>>t;
    int sn[30],tn[30];memset(sn,0,sizeof(sn));memset(tn,0,sizeof(tn));
    rep(i,0,s.size()){
        sn[s[i]-'a']++;
    }
    sort(sn,sn+26);
    rep(i,0,s.size()){
        tn[t[i]-'a']++;
    }sort(tn,tn+26);
    rep(i,0,26){
        if(sn[i]!=tn[i]){
            cout<<"No"<<endl;return 0;
        }
        //cout<<tn[i]<<" ";
    }cout<<"Yes"<<endl;return 0;
}

Measured memory_bytes: 776
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# 1 2 3
# a, b, c = LI()


def I(): return int(sys.stdin.buffer.readline())
# a = I()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# abc def
# a, b = LS()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# a = S()


def IR(n): return [I() for i in range(n)]
# 2
# 1
# 2
# [1, 2]


def LIR(n): return [LI() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def SR(n): return [S() for i in range(n)]
# 2
# abc
# def
# [abc, def]


def LSR(n): return [LS() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def SRL(n): return [list(S()) for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


n, h = LI()
a, b = [], []

for i in range(n):
    A, B = LI()
    a.append(A)
    b.append(B)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
b.sort(reverse=True)
life = 0
cnt = 0
for x in b:
    life += x
    cnt += 1
    if life >= h:
        print(cnt)
        break
if life < h:
    cnt += (h - life - 1) // a_max + 1
    print(cnt)


Measured memory_bytes: 81760
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;


int main() {
string a;
  cin>>a;
  deque<string>op;
  op.push_back(a);
  int64_t b;
  cin>>b;
  int64_t x=0;
  for(int64_t i=0;i<b;i++)
  {
  int64_t m;
    cin>>m;
    if(m==1) x=(x+1)%2;
  else{
  if(x==0)
  {
  int64_t p;
    cin>>p;
    string q;
    cin>>q;
    if(p==1) op.push_front(q);
    if(p==2) op.push_back(q);
  }
    if(x==1)
  {
  int64_t p;
    cin>>p;
    string q;
    cin>>q;
    if(p==1) op.push_back(q);
    if(p==2) op.push_front(q);
  }
  }
  }
  if(x==0){
  string r=op.front();
    op.pop_front();
    cout<<r;
    while(op.size()!=0)
    {
    string w=op.front();
      
    op.pop_front();
      cout<<w;
    }
   
  }
  else{
    string r=op.back();
    op.pop_back();
      cout<<r;
    while(op.size()!=0)
    {
    string w=op.back();
     reverse(w.begin(), w.end());
    op.pop_back();
    cout<<w;
    }
  
  
  }
  
  
}
 

Measured memory_bytes: 11648
#include<stdio.h>
#define N 100


main(){

  int i,j,c[N],n,t,s=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(c[j]<c[j-1]){
	t=c[j];
	c[j]=c[j-1];
	c[j-1]=t; 
	s++;
      }
    }

  }
 
 for(i=0;i<n-1;i++){
   
    printf("%d ",c[i]);
 }
 printf("%d\n",c[n-1]);

 printf("%d\n",s);
 return 0;
}

Measured memory_bytes: 600