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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;


class UnionFind {
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;
    //つくるときはParentの値をすべて-1にする
    //こうするとすべてバラバラになる
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//親をとってきたい
    }
    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if(A == B) {
            //すでにくっついてるからくっつけない
            return false;
        }
        //大きい方（A）に小さいほう（B）をくっつけたい。
        //大小が逆だったらひっくり返しちゃう。
        if(size(A)<size(B)) swap(A,B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    } 
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    vector<int> a(m), b(m);
    REP(i,m){ 
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    
    vector<long long> ans(m);
    ans[m-1] = (long long)n * (n-1)/2;
    
    UnionFind Uni(n);

    for(int i = m-1; i>=1; i--){
        ans[i-1] = ans[i];

        if(Uni.root(a[i]) != Uni.root(b[i])){
            ans[i - 1] -= (long long)Uni.size(a[i]) * Uni.size(b[i]); 
            Uni.connect(a[i], b[i]);
        }
    }

    REP(i,m){
        cout<<ans[i]<<endl;
    }
    return 0;
}


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

int main(){
  char X, Y;
  cin >> X >> Y;
  if(X>Y){
    cout << ">" << endl;
  }else if(X<Y){
    cout << "<" << endl;
  }else{
    cout << "=" << endl;
  }
}

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


int selectionSort(vector <int> &a,int n){
  int count =0;
  for(int i =0;i < n-1;i++){
    int minj =i; //探索される最小値を格納したい場所
    for(int j =i;j<n;j++){
      if (a.at(j)<a.at(minj)){
        minj =j;
      }
    }
    if(minj != i){
      swap(a.at(i),a.at(minj));
      count++;
    }
  }
return count;
}



int main(){
  int n ,counter;
  cin >>n;
  vector <int> a(n);
  rep(i,n)cin >>a.at(i);
  counter = selectionSort(a , n);
  rep(i,n){
    if(i)cout<<" ";
    cout <<a.at(i);
  }
  cout<<endl;
  cout <<counter<<endl;
}



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

using namespace std;

const int mod = 1000000007;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int power(int a, long long b) {
    if (b == 0) {
        return 1 % mod;
    }
    if (b % 2 == 0) {
        return power(mul(a, a), b / 2);
    }
    return mul(a, power(a, b - 1));
}

int inv(int x) {
    return power(x, mod - 2);
}

int h, w, t;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> h >> w >> t;
    int gh = h / __gcd(h, t);
    int gw = w / __gcd(w, t);
    long long top = 1LL * (h / gh) * (w / gw);
    int ans = power(2, __gcd(gh, gw));
    ans += power(2, gh);
    ans %= mod;
    ans += power(2, gw);
    ans %= mod;
    ans += mod - 3;
    ans %= mod;
    ans = power(ans, top);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;


unsigned long long lcm( unsigned long long, unsigned long long );
unsigned long long gcd( unsigned long long, unsigned long long );


// 最小公倍数
unsigned long long lcm( unsigned long long x, unsigned long long y ) {
    return x / ( x > y ? gcd( x, y ) : gcd( y, x ) ) * y;
}


// 最大公約数
// 事前条件: x >= y
unsigned long long gcd( unsigned long long x, unsigned long long y ) {
    return y ? gcd( y, x % y ) : x;
}


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

    unsigned long long T[ N ];
    unsigned long long res = 1;
    for ( int i = 0; i < N; i++ ) {
        cin >> T[ i ];
        res = lcm( res, T[ i ] );
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import math

while True:
    N = int(input())
    if N == 0:
        break

    dp = (N+1)*[0]
    dp[0]=1

    for i in range(1,N+1):
        for j in range(1,min(4,i+1)):
            dp[i] += dp[i-j]

    print(math.ceil(dp[N]/3650))


Measured memory_bytes: 5660
n = int(input())
S = [list(input().split()) for i in range(n)]

for i in range(n):
    S[i].append(i)
    S[i][1]= int(S[i][1])

S = sorted(S,key=lambda x:x[1],reverse=1)
S = sorted(S,key=lambda x:x[0])

#print(S)

for i in range(n):
    print(S[i][2]+1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(){
  int W,H,x,y;
  cin>>W>>H>>x>>y;
  if(x==(double)W/2.0 && y==(double)H/2.0){
    cout<<(double)W*H/2.0<<" "<<1<<endl;
  }
  else{
    cout<<(double)W*H/2.0<<" "<<0<<endl;
  }
}

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

using i64 = int64_t;

using Graph = vector<vector<int>>;

constexpr int INF = 1e9;

bool dfs(int v, int c, vector<int> &color, const int n, const Graph &graph){
    color[v] = c;
    for(int i=0;i<n;++i){
        if(i == v)continue;
        if(graph[v][i] == 0)continue;
        if(color[i] == c)return false;
        if(color[i] == 0 && !dfs(i, -c, color, n, graph))return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    Graph graph(n, vector<int>(n));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            char c;
            cin >> c;
            if(c == '1')graph[i][j] = 1;
        }
    }
    vector<int> color(n);
    if(dfs(0, 1, color, n, graph)){
        vector<vector<int>> cost(graph);
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(i == j)continue;
                if(graph[i][j] == 0)cost[i][j] = INF;
            }
        }
        for(int k=0;k<n;++k){
            for(int i=0;i<n;++i){
                for(int j=0;j<n;++j){
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
        int ans = 0;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                //cerr << " " << cost[i][j];
                if(cost[i][j] < INF)ans = max(ans, cost[i][j]);
            }
            //cerr << endl;
        }
        cout << ans + 1 << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 10e15
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;

  int cost[10][10];
  int i, j, k;
  for(i = 0; i < 10; i++){
      for(j = 0; j < 10; j++){
          cin >> cost[i][j];
      }
  }

  for(k = 0; k < 10; k++){
      for(i = 0; i < 10; i++){
          for(j = 0; j < 10; j++){
              cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
          }
      }
  }

  int a;
  int count = 0;
  for(i = 0; i < h; i++){
      for(j = 0; j < w; j++){
          cin >> a;
          if(a != -1){
              count += cost[a][1];
          }
      }
  }

  cout << count << endl;
}






Measured memory_bytes: 256
N, M = map(int, input().split());
xList =list(map(int, input().split()))
xList.sort();

if N >= M:
  print(0);
else:
  diff = xList[M - 1] - xList[1];

  diffList = [];
  prevX = xList[0];
  for i in range(1, M):
      x = xList[i];
      diffList.append(x - prevX);
      prevX = x;
  diffList.sort();

  for i in range(N - 1):
      diffList.pop();

  length = len(diffList);
  result = 0;
  for i in range(length):
      result += diffList[i];

  print(result);

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
int main(){
	int j=0;
	string s;
	cin>>s;
	char a[10];
	for(int i=0;i<10;i++)a[i]=' ';
	for(int i=0;i<s.size();i++){
		if(s[i]!='B'){
			a[j]=s[i];
			j++;
		}
		else {
			a[j-1]=' ';
			if(j!=0)j--;
		}
	}
	for(int i=0;i<10;i++){
		if(a[i]!=' ')cout<<a[i];
		else break;
	}
	cout<<endl;
}


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


public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		ArrayList<Integer> intervalList = new ArrayList<Integer>();
		intervalList.add(1);
		int tmp = 1;
		for(;;){
			tmp = tmp*3+1;
			if(intervalList.size() > 100 || tmp >= num)
				break;
			intervalList.add(tmp);
		}
		Collections.reverse(intervalList);
		ArrayList<String> list = new ArrayList<String>();
		for(int i=0; i<num;i++)
			list.add(scan.next());
		scan.close();
		InsertionSort insSort = new InsertionSort(num);
		insSort.loadSequence((String[])list.toArray(new String[0]));
		for(int i=0; i<intervalList.size();i++)
			insSort.sort(intervalList.get(i));
			
		//output
		//line#1
		System.out.println(intervalList.size());
		//line#2
		String str="";
		for(int i=0; i<intervalList.size();i++)
			str = str + " " + intervalList.get(i);
		System.out.println(str.trim());
		//line#3
		System.out.println(insSort.count);
		//line#4~
		for(int i=0; i<insSort.sortList.size();i++)
			System.out.println(insSort.sortList.get(i));
		
		
	}

}

class InsertionSort extends SortingNumbers{
	int interval = 1;
	int count = 0;
	public InsertionSort(int n){
		super(n);
	}
	
	public void sort(int g){
		interval = g;
		sort();
	}
	@Override
	public void sort(){
		for(int i=interval; i<this.length;i++){
			comparable key = sortList.get(i);
			int j=i-interval;
			for(; j>=0 ;){
				if(sortList.get(j).compValue()<=key.compValue())
					break;
				sortList.set(j+interval,sortList.get(j));
				j-=interval;
				count++;
			}
			sortList.set(j+interval, key);
		}
	}
}


interface comparable{
	int compValue();
}
class numbers implements comparable{
	Integer num;
	public numbers(String str){
		num = Integer.parseInt(str);
	}
	@Override
	public int compValue(){
		return num;
	}
	@Override
	public String toString(){
		return num.toString();
	}
}
class SortingNumbers extends Sorting{
		public SortingNumbers(int n){
		super(n);
	}
	@Override
	public void loadSequence(String[] str){
		for(int i=0; i<this.length;i++)
			sortList.add(new numbers(str[i]));
	}
	@Override
	public void sort(){};
}

abstract class Sorting{
	int swapTimes;
	int length;
	ArrayList<comparable> sortList;
	public Sorting(int n){
		swapTimes=0;
		length=n;
		sortList = new ArrayList<comparable>();
	}
	
	@Override
	public String toString(){
		String tmp = "";
		for(int i=0; i<length; i++)
			tmp = tmp + " " + sortList.get(i);
		return tmp.trim();
	}
	void swap(int i, int j){
		swapTimes++;
		comparable tmp = sortList.set(i,sortList.get(j));
		sortList.set(j,tmp);
	}
	abstract public void loadSequence(String[] str);
	abstract public void sort();
}

Measured memory_bytes: 285040
if __FILE__ == $0
	n = gets.to_i
	n.times {
		args = gets.split(" ").map{|e|e.to_i}.sort
		result = (((args[0] ** 2) + (args[1] ** 2)) == args[2] ** 2)
		if result
			puts "YES"
		else
			puts "NO"
		end
	}
end

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



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


Measured memory_bytes: 256
from itertools import permutations
n = int(input())
arr = [list(map(int, input().split())) for i in range(n)]
sm = 0
cnt = 0
for p in permutations(range(n)):
    for i, j in zip(p, p[1:]):
        x1, y1 = arr[i]
        x2, y2 = arr[j]
        sm += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
    cnt += 1
print(sm / cnt)

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

int main(){
  char c; cin >> c;
  if (c == 'a' or  c == 'i' or c == 'u'
      or c == 'e' or c == 'o'){
    cout <<"vowel" <<endl;
  }else{
    cout << "consonant" <<endl;
  }
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <istream>
#include <sstream>

int main(void){
	int i, j, n, length, count, number;
	int cards[4][14];
	char buf[8];
	std::string str, interpreter[2];
	std::stringstream ss;

	for(i=0;i<4;i++){
		for(j=0;j<14;j++) cards[i][j] = 0;
	}

	scanf("%d", &n);
	fgets(buf, sizeof(buf), stdin);
	for(i=0;i<n;i++){
		fgets(buf, sizeof(buf), stdin);
		length = strlen(buf);
		buf[length-1] = '\0';
		count = 0;
		ss << buf;
		while(std::getline(ss, str, ' ')){
			interpreter[count++] = str;
		}
		number = atoi(interpreter[1].c_str());

		if(interpreter[0].c_str()[0]=='S') cards[0][number] = 1;
		else if(interpreter[0].c_str()[0]=='H') cards[1][number] = 1;
		else if(interpreter[0].c_str()[0]=='C') cards[2][number] = 1;
		else if(interpreter[0].c_str()[0]=='D') cards[3][number] = 1;

		ss.str("");
		ss.clear(std::stringstream::goodbit);
	}

	for(i=0;i<4;i++){
		for(j=1;j<14;j++){
			if(cards[i][j]==0){
				if(i==0) printf("S %d\n", j);
				else if(i==1) printf("H %d\n", j);
				else if(i==2) printf("C %d\n", j);
				else if(i==3) printf("D %d\n", j);
			}
		}
	}

	return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, k;
	cin>>n>>k;
	int pos = -1;
	for(int i = 1; i <= n; i++){
		int x; cin>>x;
		if(x == 1)pos = i;
	}
	int ans = n;
	for(int i = pos - k + 1; i <= pos; i++){
		if(i < 0 || i + k - 1 > n)continue;
		int tmp = 1 + (i + k - 3)/(k - 1) + (n - i - 1)/(k - 1);
		// cout<<i<<" "<<tmp<<endl;
		ans = min(ans, tmp);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n;
  int p[50];
  int i,j;
  int a,b;
  int x,y;
  int c;
  int sum=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  
  a=-1;
  b=-1;
  
  for(i=0;i<n;i++)
  {
    if(p[i]!=i+1)
    {
      a=i;
      x=p[i];
      
      break;
    }
  }
  for(i=a+1;i<n;i++)
  {
    if(p[i]!=i+1)
    {
      b=i;
      y=p[i];
      
      break;
    }
  }
  if(a==-1&&b==-1)
    printf("YES");
  else{
  if(b==-1)
    printf("NO");
  else
  {
    c=p[a];
    p[a]=p[b];
    p[b]=c;
    for(i=0;i<n;i++)
    {
      if(p[i]!=i+1)
        break;
      sum++;
    }
    if(sum==n)
      printf("YES");
    else
      printf("NO");
  }
  }
  return 0;
}

Measured memory_bytes: 128
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::*;
use std::iter::FromIterator;
use num::integer;

fn main() {
    input! {
        a: [usize]
    }

    let mut primes = vec![2, 3, 5, 7, 11];
    'b: for i in 13..=999 {
        for &p in &primes {
            if i % p == 0 {
                continue 'b;
            }
        }
        primes.push(i);
    }

    let mut factor = std::collections::BTreeSet::new();

    let mut pw = true;

    'c: for &n in &a {
        let mut mn = n;
        for &p in &primes {
            if mn % p == 0 {
                if factor.contains(&p) {
                    pw = false;
                    break 'c;
                } else {
                    factor.insert(p);
                }
                while mn % p == 0 {
                    mn /= p;
                }
            }
        }

        if mn != 1 && factor.contains(&mn) {
            pw = false;
            break 'c;
        } else {
            factor.insert(mn);
        }
    }

    let gcd = a.iter().copied().fold1(integer::gcd).unwrap();

    if pw {
        println!("pairwise coprime");
    } else if gcd == 1 {
        println!("setwise coprime");
    } else {
        println!("not coprime");
    }
}


Measured memory_bytes: 17608
n=int(input())
data=[]
for i in range(n):
    data.append(list(map(int,input().split())))
ttl_len=0
for j in range(n):
    for k in range(n):
        if k<j:
            ttl_len+=2*((data[j][0]-data[k][0])**2+(data[j][1]-data[k][1])**2)**(1/2)
        else:
            continue
print(ttl_len/n)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
    int N, Q;
    cin >> N >> Q;
    rev_priority_queue<tuple<i64, i64, int, bool>> time;
    for(int i = 0; i < N; i++) {
        i64 S, T, X;
        cin >> S >> T >> X;
        time.emplace(S - X, X, i, true);
        time.emplace(T - X, X, i, false);
    }
    set<pair<i64, int>> s;
    for(int i = 0; i < Q; i++) {
        i64 D;
        cin >> D;
        while(time.size() && get<0>(time.top()) <= D) {
            auto a = time.top(); time.pop();
            i64 t, x;
            int i;
            bool b;
            tie(t, x, i, b) = a;
            if(b) {
                s.insert({x, i});
            } else {
                s.erase({x, i});
            }
        }
        if(s.size()) {
            cout << s.begin()->first << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 24808
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;

	cin >> n;

	vector<int> vec(n, 0);
	int tmp, a;

	cin >> a;

	vec[a]++;

	for (int i = 1; i < n; i++) {
		cin >> tmp;

		vec[tmp]++;
	}

	if (vec[0] != 1 || a != 0) {
		cout << 0 << endl;

		return 0;
	}

	for (int i = 1; i < n - 1; i++) {
		if (vec[i] == 0 && vec[i + 1] != 0) {
			cout << 0 << endl;

			return 0;
		}
	}

	long long ans = 1;

	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < vec[i + 1]; j++) {
			ans = (ans * vec[i]) % 998244353;
		}
	}

	printf("%llu\n", ans);

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
  int n;
  cin>>n;
  int a,b;
  vector<pair<int,int>> p(n);
  rep(i,n){
    cin>>a>>b;
    p.at(i).first=b;
    p.at(i).second=a;
  }
  
  sort(p.begin(),p.end());
  long long sum=0;
  
  rep(i,n){
    sum+=p.at(i).second ;
    if(sum>p.at(i).first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  }



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 


    fast;


    ll a,b;
    cin>>a>>b;

    if(a<=b)
    {
      for(ll i=0;i<b;i++)
        cout<<a;
    }
    else
    {
      for(ll i=0;i<a;i++)
        cout<<b;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int [][]a=new int [n][m];
int []b=new int [m];
for(int i=0;i<n;i++) {
	for(int s=0;s<m;s++) {
		int A=sc.nextInt();
		a[i][s]=A;
	}
}
for(int q=0;q<m;q++) {
	int B=sc.nextInt();
	b[q]=B;
}
int y;
for(int w=0;w<n;w++) {
	y=0;
	for(int e=0;e<m;e++) {
		y+=a[w][e]*b[e];
	}
	System.out.println(y);
}
sc.close();
  }
}



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

int main() {
  int ans;
  int N;
  cin >> N;
  ans = N % 10;
    
    if(ans == 3){
      cout << "bon" << endl;
    }
   
    if(ans == 0){
      cout << "pon" << endl;
    }
    
    if(ans == 1){
      cout << "pon" << endl;
    }
  
    if(ans == 6){
      cout << "pon" << endl;
    }
    
    if(ans == 8){
      cout << "pon" << endl;
    }
  
    if(ans == 2){
      cout << "hon" << endl;
    }
  
    if(ans == 4){
      cout << "hon" << endl;
    }
    
    if(ans == 5){
      cout << "hon" << endl;
    }
  
    if(ans == 7){
      cout << "hon" << endl;
    }
  
    if(ans == 9){
      cout << "hon" << endl;
    }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define mod 1500000007
using namespace std;

using ll = long long;
using ld = long double;

const ll inf = LONG_LONG_MAX;

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1){
            res = (res * a)%mod;
        }
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}

signed main(){
	ll t;
	//cin >> t;

	t = 1;

	while(t--){
		ll x;
		cin >> x;

		for(ll i=150;i>=(-150);i--){
			for(ll j=(-150);j<=150;j++){
				if((ll)(pow(i,5)) - (ll)(pow(j,5)) == x){
					cout << i << " " << j << "\n";
					return 0;
				}
			}
		}
	}

	//cout << (ll)(pow(150,5)-pow(-99,5)) << "\n";
	return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int N;
    cin >> N;
    int ans = 1;
    int flag = 0;
    int prev;
    rep(i, N){
        int now ;
        cin >> now;
        if(i == 0){
            prev = now;
        }
        if(flag == 0 && now - prev != 0){
            flag = now - prev > 0 ? 1 : -1;
        }
        if((now - prev) * flag < 0){
            flag = 0;
            ans ++;
        }
        prev = now;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
sumlist = [0]*(n-1)
cursum = 0
for i in range(n-1):
  cursum += a[n-1-i]
  sumlist[n-2-i] = cursum
totalsum = 0
for j in range(n-1):
  totalsum += a[j]*sumlist[j]
print(totalsum%((10**9)+7))

Measured memory_bytes: 31676
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;

ll a[114514];
ll b[114514];
int main(){
	int n;
	cin>>n;
	ll ans=0;
	vector<pair<ll,int> > hoge;
	rep(i,n){
		cin>>a[i]>>b[i];
		hoge.pb(mp(a[i]+b[i],i));
	}
	sort(all(hoge));
	reverse(all(hoge));
	rep(i,n){
		if(i%2==0){
			ans+=a[hoge[i].second];
		}else{
			ans-=b[hoge[i].second];
		}
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;

const int N=10;

int n,m,k,ans;
char a[N][N],b[N][N];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++) scanf(" %s",a[i]);

	for(int rmask=0;rmask<(1<<n);rmask++)
	{
		for(int cmask=0;cmask<(1<<m);cmask++)
		{
			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++) b[i][j]=a[i][j];

			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++)
					if((rmask&(1<<i)) or (cmask&(1<<j))) b[i][j]='R';

			int black=0;
			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++)
					if(b[i][j]=='#') black++;
			if(black==k) ans++;
		}
	}

	printf("%d",ans);
}

Measured memory_bytes: 3752
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    /////////////////////
    // Write code below /
    /////////////////////
    int numberOfJewel;
    cin >> numberOfJewel;
    
    vector<int> values(numberOfJewel);
    vector<int> costs(numberOfJewel);
    
    for (int jewel_i = 0; jewel_i < numberOfJewel; jewel_i++) {
        cin >> values.at(jewel_i);
    }
    for (int jewel_i = 0; jewel_i < numberOfJewel; jewel_i++) {
        cin >> costs.at(jewel_i);
    }
    
    int maxGain = 0;
    for (int jewel_i = 0; jewel_i < numberOfJewel; jewel_i++) {
        int gain = values.at(jewel_i) - costs.at(jewel_i);
        if (gain > 0) {
            maxGain += gain;
        }
    }
    
    cout << maxGain << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
int a[100001];

void init()
{
}

void solve()
{
    int sum = 0;
    REP(i, N+1){
        sum += abs(a[i%(N+1)] - a[(i+1)%(N+1)]);
    }
    FOR(i, 1, N+1){
        int ans = sum;
        ans -= abs(a[(i-1)%(N+1)] - a[i%(N+1)]);
        ans -= abs(a[i%(N+1)] - a[(i+1)%(N+1)]);
        ans += abs(a[(i-1)%(N+1)] - a[(i+1)%(N+1)]);
        cout << ans << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 1, N+1) cin >> a[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n,m;
long long dp[1005][1005];
char a[1005][1005];
int main()
{
	scanf("%d%d",&n,&m);
	dp[1][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf(" %c",&a[i][j]);
			if(a[i][j]=='.')
				dp[i][j]=MOD(dp[i-1][j]+dp[i][j-1]);
		}
	}
	printf("%lld",dp[n][m]);
	return 0;
}



Measured memory_bytes: 9088
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int N, K;
    cin>>N>>K;
    vector<int> W(N);
    int l = 0;
    int r = 0;
    for(int i=0; i<N; i++){
        cin>>W[i];
        r+=W[i];
    }
    r*=2;
    int res = 0;
    while(r>l){
        int m = (l+r)/2;
        vector<int> A(K, 0);
        int x = 0;
        bool ok = true;
        for(int i=0; i<N; i++){
            if(W[i]>m or x>=N){
                ok = false;
                break;
            }
            if(A[x]+W[i]<= m) A[x] += W[i];
            else{
                x++;
                if(x<K){
                    A[x] = W[i];
                } else{
                    ok =false;
                    break;
                }
            }
        }

        if(ok){ 
            r = m;
            res = m;
         }
        else { l=m+1;}
    } 
    cout<< res << endl; 
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	double d,e;
	double x,y,m=100000009,l;
	while(true){

		cin>>d>>e;

		if(d+e==0) return 0;

		else{
			for(int i=0;i<=d;i++){
				x=i;
				y=d-i;
				l=pow(x*x+y*y,0.5);
				m=min(m,fabs(l-e));
			//	cout<<x<<" "<<y<<" "<<l<<endl;

			}
		}
		cout<<m<<endl;
		m=100000009;
	}
}

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

class Dmondai
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];
        var A = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        if (K == 0)
        {
            Console.WriteLine(A.Sum(x=>x));
            return;
        }
        var length = (long)Math.Log(K, 2);
        var count = new int[length+1];
        var bit = 1L;
        for (int i=0;i<=length;++i)
        {
            for (long j = 0; j < N; ++j) if ((bit & A[j]) != 0) count[i]++;
            bit <<= 1;
        }
        bit = 1L;
        bit <<= (int)length;
        var num = 0L;
        var temp = 0L;
        for (long i=length;0<=i;--i)
        {
            if (count[i] < ((N+1) / 2) ) temp |= bit;
            if (temp <= K) num = temp;
            else temp = num;
            bit >>= 1;
        }
        var ans = 0L;
        for (int i = 0; i < N; ++i) ans += (num ^ A[i]);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 31324
/*input
1000000000000000000
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll X;
    cin >> X;
    ll m = 100;
    ll i = 0;
    while (m < X) {
        m += (m/100);
        i++;
    }
    cout << i << endl;
}

Measured memory_bytes: 3632
N, M =map(int, input().split())
A = list(map(int, input().split()))
A.sort()
BC = []

cards = [0 for i in range(10+1)]
for i in range(M):
    b,c = map(int, input().split())
    BC.append([b,c])
BC.sort(key=lambda x:x[1], reverse=True)

sum_val = 0
a_idx = 0
for i in range(M):
    num, val = BC[i]
    while num > 0 and a_idx < N and A[a_idx] < val:
        sum_val += val
        num -= 1
        a_idx += 1
    if a_idx < N and A[a_idx] > val:
        break
print(sum_val + sum(A[a_idx:]))
# print(a_idx, A, BC)


Measured memory_bytes: 25624
import java.util.Scanner;
public class Main {

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int ans = Integer.MAX_VALUE;
		for(int i = 0 ; i < a ; i++){
			long temp = scan.nextLong();
			int cnt = 0;
			while(true){
				if(temp % 2 == 0){
					temp = temp / 2;
					cnt ++;
				}else{
					break;
				}
			}
			if(cnt < ans){
				ans = cnt;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();

  ll x;
  cin >> x;
  int cnt = 0;
  ll a = 100;
  while (a < x)
  {
    cnt++;
    a = a + a / 100;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int k, length, pointer;
string S, s[100005];

int main()
{
    cin >> S >> k;
    length = S.size();

    for (int i = 1; i <= 5; i++) {
        for (int j = 0; j <= length-i; j++) {
            s[pointer++] = S.substr(j,i);
        }
    }

    sort(s, s+pointer);
    unique(s, s+ pointer);

    cout << s[k-1];
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s, rs;
    int q, a = 0;
    cin >> s >> q;
    rs = s;
    reverse(all(rs));
    rep(i, q){
        int t;
        cin >> t;
        if(t == 1){
            a++;
            a %= 2;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(a == 0){
                    s.insert(s.begin(), c);
                    rs.push_back(c);
                }
                else{
                    s.push_back(c);
                    rs.insert(rs.begin(), c);
                }
            }
            else{
                if(a == 0){
                    s.push_back(c);
                    rs.insert(rs.begin(), c);
                }
                else{
                    s.insert(s.begin(), c);
                    rs.push_back(c);
                }
            }
        }
    }
    if(a == 0)cout << s << endl;
    else cout << rs << endl;
}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

bool check(ll N, ll k){
    if(k <= 1 || k > N){ return false; }
    while(N % k == 0){
        N /= k;
    }
    return (N - 1) % k == 0;
}


void solve(long long N){
    set<ll> ok;
    for(ll k = 1; k * k <= N; ++k){
        if(N % k != 0){ continue; }
        if(check(N, k)){
            ok.insert(k);
        }
        if(check(N, N / k)){
            ok.insert(N / k);
        }
    }
    const ll N2 = N - 1;
    for(ll k = 1; k * k <= N2; ++k){
        if(N2 % k != 0){ continue; }
        if(check(N, k)){
            ok.insert(k);
        }
        if(check(N, N2 / k)){
            ok.insert(N2 / k);
        }
    }
    cout << ok.size() << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 19 22:37:09 2019

@author: lucifer
"""
n=int(input())
if n%500==0:
  print(1000*int(n/500))
else:
  s=int(n/500)
  x=1000*s+int((n-(s*500))/5)*5
  print(x)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define ll long long
#define ull unsigned long long

ull gcd(ull a, ull b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
ull lcm(ull a, ull b) {
  return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    ull T[n];
    rep(i, 0, n) cin >> T[i];

    ull ans = T[0];
    rep(i, 1, n){
        if(ans == T[i]) continue;
        ans = lcm(ans, T[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
   int a, b, c, d, e, k;

   scanf("%d", &a);
   scanf("%d", &b);
   scanf("%d", &c);
   scanf("%d", &d);
   scanf("%d", &e);
   scanf("%d", &k);

   if((e - a) <= k) {
      printf("Yay!\n");
   }
   else {
      printf(":(\n");
   }

   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
using namespace std;
typedef long long unsigned int ll;

int min(int a, int b)
{
    if (a > b)
    {
        return b;
    }
    else
    {
        return a;
    }
}

int main()
{
    int n, m, x, c[12], A[12][12], i, j, k, l, bit[12], p = 0, alg[12], min1 = 2147483647, min2 = 2147483647, tmp = 2147483647, flag = 0;
    cin >> n;
    cin >> m;
    cin >> x;
    for (i = 0; i < 12; i++)
    {
        alg[i] = 0;
        c[i] = 0;
        bit[i] = 0;
        for (j = 0; j < 12; j++)
        {
            A[i][j] = 0;
        }
    }

    for (i = 0; i < n; i++)
    {
        cin >> c[i];
        for (j = 0; j < m; j++)
        {
            cin >> A[i][j];
        }
    }
    for (i = 0; i < 1 << n; i++)
    {
        for (j = 0; j < m; j++)
        {
            alg[j] = 0;
        }
        for (j = 0; j < n; j++)
        {
            bit[j] = ((i & (1 << j)) >> j);
        }
        for (j = 0; j < n; j++)
        {
            if (bit[j] == 1)
            {
                min1 = min1 + c[j];
                for (k = 0; k < m; k++)
                {
                    for (l = 0; l < n; l++)
                    {
                        if (bit[l] == 1)
                        {
                            alg[k] = alg[k] + A[l][k];
                        }
                    }
                    if (alg[k] < x)
                    {
                        flag = 1;
                        min1 = 2147483647;
                        break;
                    }
                }
                if (flag == 1)
                {
                    break;
                }
            }
        }
        min2 = min(min1, tmp);
        tmp = min2;
        min1 = 0;
        flag = 0;
    }
    if (min2 != 2147483647)
    {
        cout << min2 << endl;
    }
    else
    {
        min2 = -1;
        cout << min2 << endl;
    }
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e2 + 5;
const int M = 1e3 + 5;
const ll INF = 1e15;

int n,W,h[N],v[N],w[N];

ll dp[N][N * M];

ll f(int cur,int rem) {
  if (rem < 0)
    return INF;
  if (cur == n + 1) {
    if (rem == 0)
      return 0;
    return INF;
  }
  ll &res = dp[cur][rem];
  if (res != -1)
    return res;
  res = f(cur + 1,rem);
  res = min(res,f(cur + 1,rem - v[cur]) + w[cur]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> W;
  for (int i = 1 ; i <= n ; i++)
    cin >> w[i] >> v[i];
  memset(dp,-1,sizeof dp);
  for (int i = N * M - 5 ; i >= 0 ; i--) {
    if (f(1,i) <= W) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main(){
    string str1,str2;
    unsigned long index = 0;
    
    cin >> str1 >> str2;
    
    while(1){
        unsigned long tmp = str1.find(str2,index);
        if(tmp == string::npos){
            break;
        }
        else{
            cout << tmp << endl;
            index = tmp + 1;
        }
    }
    return 0;
}


Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    if (n == 0){
        cout << 0 << "\n";
        return 0;
    }
    vector<int>ans;
    while (n != 0){
        if (n % 2 == 0){
            ans.push_back(0);
            n /= -2;
        }
        else if (n < 0){
            ans.push_back(1);
            n /= -2;
            n++;
        }
        else {
            ans.push_back(1);
            n /= -2;
        }
    }
    for (int i = ans.size() - 1; i >= 0; i--){
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

ll gcd(ll a, ll b){
    if(a < b) return gcd(b, a);
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
ll lcm(ll a, ll b){
    ll ret = (a * b)/gcd(a,b);
    return ret;
}

int main(){
    ll n, ans;
    cin >> n >> ans;
    rep(i, 1, n){
        ll tmp; cin >> tmp;
        ans = gcd(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//AOJ ALDS1_1_D by bal4u
#include <stdio.h>

int main() {
	int n, c, max, min;

	scanf("%d", &n);
	int r[n];

	for (c = 0; c < n; c++) {
		scanf("%d", &r[c]);
	}

	max = r[1] - r[0],min = r[0];

	for (c = 0; c < (n - 1); c++) {
		if (((r[c+1] - min) >= 0) && ((r[c+1] - min) > max)) {
			max = r[c+1] - min;
		}else if (((r[c+1] - min) < 0) && (r[c+1] < min)) {
			min = r[c+1];
		}
	}

	printf("%d\n", max);

	return 0;
}




Measured memory_bytes: 2488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, m;

void solve(){
    ll ans = 0;
    cin >> n >> m;
    while(m--){
        ll x;
        cin >> x;
        ans += x;
    }
    cout << max(-1LL, n - ans);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int k,s;
    cin >> k >> s;
    int count = 0;
    for(int i = 0; i <= k; i++) {
        for(int j = 0; j <= k; j++) {
            if(s-(i+j) <= k && s-(i+j) >= 0) {
                count++;
            }
        }
    }
    cout << count;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

template <typename T>
vector<T> divisor( T n )
{
	vector<T> res;
	for( T i = 1; i * i <= n; ++i )
	{
		if( n % i == 0 )
		{
			res.push_back( i );
			if( i != n / i ) res.push_back( n / i );
		}
	}
	sort( ALL( res ) );
	return res;
}

int main()
{
	ll n;
	cin>>n;
	auto vec = divisor( n );

	ll c = 0;
	REP(i,vec.size())
	{
		if( vec[i] < 2 ) continue;
		ll a = n / vec[i];
		if( vec[i] - 1 > a ) c += vec[i] - 1;
	}

	cout << c << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e6+5;
ll n,m,p;
char str[maxn];
int main()
{
    scanf("%lld%s",&n,str+1);
    int len=strlen(str+1);
    int res=0;
    for(int i=1;i<=len-2;i++)
    {
        if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C') res++;
    }
    printf("%d\n",res);
    return 0;
}





Measured memory_bytes: 256
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())

        max_pair = (N - 1) * (N - 2) // 2
        if K > max_pair:
            print(-1)
            exit()

        star = []
        for i in range(1, N):
            star.append((i, N))

        leaves = []
        for i in range(1, N):
            for j in range(1, i):
                leaves.append((i, j))

        star += leaves[:max_pair - K]
        print(len(star))
        for pair in star:
            print(" ".join(map(str, pair)))


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 41584