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

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

const int nax = 2e5+10;
const  ll mod =  1e9+7;

const ll INFL = 1e18L + 5;

/*//Modular Addition
inline void add_self(ll& a, ll b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

//Modular Subtraction
inline void sub_self(int& a , int b){
    a -= b;
    if(a < 0)
        a+= mod;
}

inline void mul_self(ll& a, ll b){
    a *= b;
    if(a >= mod)
        a-= mod;
}*/

ll tree[4*nax];

void build(int v, int tl, int tr, ll a[]){
    if(tl == tr)
        tree[v] = a[tl];
    else{
        int tm = (tl+tr)/2;
        build(2*v, tl, tm, a);
        build(2*v+1, tm+1, tr, a);
        tree[v] = max(tree[2*v], tree[2*v+1]);
    }

}

ll best(int v, int tl, int tr, int l, int r){
    if(l > r)
        return 0;
    if(l == tl && r == tr){
        return tree[v];
    }
    int tm = (tl+tr)/2;
    return max(best(v*2, tl, tm, l, min(r,tm)),
            best(2*v+1, tm+1, tr, max(l,tm+1), r));
}

void update(int v, int tl, int tr, int pos, ll new_val){
    if(tl == tr)
        tree[v] = new_val;
    else{
        int tm = (tl+tr)/2;
        if(pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        tree[v] = max(tree[v*2], tree[2*v+1]);
    }
}


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

    int n;
    cin>>n;

  /*  int base = 1;
    while(base <= n){
        base *= 2;
    }*/
    //base is smallest power of 2 that is not smaller than n
    // To calculate size of tree.

   // vector<ll>tree(2*base);
    int h[n+5], a[n+5];

    for(int i = 1; i <= n; i++)cin>>h[i];
    for(int i = 1; i <= n; i++)cin>>a[i];

   ll dp[n+5];
   memset(dp,0,sizeof dp);

    build(1,1,n,dp);
/*
    for(int i = 1; i <= n; i++){
        cout<<h[i]<<" : "<<a[i]<<"\n";
    }*/

/*
    for(int i = 0; i <= 4*n ;i++)
        cout<<tree[i]<<" ";
    cout<<endl;
*/

    for(int flower = 1; flower <= n; flower++) {
        // max dp[i] for i in [0, h[flower]-1].
        dp[h[flower]] = best(1, 1, n, 1, h[flower] - 1) + a[flower];
        update(1, 1, n, h[flower], dp[h[flower]]);
    }
/*
    for(int i = 0;i <= 4*n; ++i)
        cout<<tree[i]<<" ";
    cout<<endl;
*//*
    for(int i = 0; i <= n; i++)
        cout<<dp[i]<<"\n";*/

    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, dp[i]);
    }
    cout<<ans;


}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    ll n,a,b,ans;
    cin>>n>>a>>b;
    if((b-a)%2==0)
    {
        ans=(b-a)/2;
    }
    else
    {
        ll tmp1=(a+b-1)/2;
        ll tmp2=((n-a)+(n-b)+1)/2;
        ans=min(tmp1,tmp2);
    }
    

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

Measured memory_bytes: 256
#include<cstdio> 
#include<algorithm>  
#include<iostream>  
using namespace std;   
int gcd(int x,int y)
{        return x ? gcd(y%x,x) : y;    }  
  int main()   
   {        int n,a,Max,k;   
        int i;       
         cin>>n>>a>>k;   
              int tmp=k;     
                 Max=k;      
                   int ans=0;  
                         for(i=1;i<n;i++)   
                              {            int t;     
                                     cin>>t;      
                                           tmp=gcd(tmp,t);
                        Max=max(Max,t);        }  
                              //cout<<a<<endl;    
                                  if(n == 1)       
                 {            if(a == tmp)         
                        ans = 1;        }         
                                   else        {            if(a%tmp == 0 && a <= Max)
                                        ans = 1;        }               
                                             if(ans == 1)           
                                              puts("POSSIBLE");     
                                                         else        
                                                             puts("IMPOSSIBLE");   
                                                                              }



                                                                              


Measured memory_bytes: 3644
// 2011/09/20 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int A = 0;
		int B = 0;
		for(int i=0; i<n; i++){
			int a, b;
			cin >> a >> b;

			if(a>b)
				A += (a+b);
			else if(a<b)
				B += (a+b);
			else{
				A += a;
				B += b;
			}
		}

		cout << A << ' ' << B << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
  int cards[4][13] = {};
  int i,j,n;
  char c;

  scanf("%d", &n);
  while(n){
    scanf(" %c %d", &c, &j);
    if(c == 'S') i = 0;
    else if(c == 'H') i = 1;
    else if(c == 'C') i = 2;
    else  i = 3;
    cards[i][j-1] = 1;
    n--;
  }

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

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

using namespace std;

int main(){
  int N,Y,ans[3] = {-1, -1, -1};
  cin >> N; 
  cin >> Y;
  for(int x = 0; x<=N; x++){
    for(int y = 0; y<=N; y++){
      if(N - x - y < 0)continue;
      if( 10000 * x + 5000 * y + (N - x - y) * 1000 == Y){
        ans[0] = x;
        ans[1] = y;
        ans[2] = N - x - y;
        
      }
    }
  }
  cout << ans[0] << " " << ans[1] << " " << ans[2] << " " <<  endl;
  return 0;
}

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


int main() {
    int n,k,ans;
	cin >> n>> k;
    ans=n-k;
    if(k==1)ans=0;
      cout <<ans<< endl;
}


Measured memory_bytes: 256
use std::io::stdin;
use std::iter::Iterator;
use std::collections::VecDeque;

fn main() {
    let mut cin = ConsoleInputWrapper::new();
    let N: usize = cin.input().parse().unwrap();
    let mut constraint = Vec::new();
    for i in 0..N {
        let x: i32 = cin.input().parse().unwrap();
        let y: i32 = cin.input().parse().unwrap();
        let h: i32 = cin.input().parse().unwrap();
        if h > 0 {
            constraint.insert(0, (x, y, h));
        } else {
            constraint.push((x, y, h));
        }
    }

    for x in 0..101 {
        for y in 0..101 {
            let &(xx, yy, hh) = &constraint[0];
            let h = hh + (x - xx).abs() + (y - yy).abs();
            let mut flg = true;
            for &(xx, yy, hh) in &constraint {
                if max(h - (xx - x).abs() - (yy - y).abs(), 0) != hh {
                    flg = false;
                    break;
                }
            }
            if flg {
                println!("{} {} {}", x, y, h);
                return;
            }
        }
    }
}

fn max(a: i32, b: i32) -> i32 {
    if b < a { a } else { b }
}

struct ConsoleInputWrapper {
    queue: VecDeque<String>
}

impl ConsoleInputWrapper {
    fn new() -> ConsoleInputWrapper {
        ConsoleInputWrapper {
            queue: VecDeque::new()
        }
    }
    fn input(&mut self) -> String {
        if self.queue.len() <= 0 {
            let mut s = String::new();
            stdin().read_line(&mut s).unwrap();
            let list: Vec<&str> = s.split_whitespace().collect();
            for string in list {
                self.queue.push_back(String::from(string));
            }
        }
        self.queue.pop_front().unwrap()
    }
}

Measured memory_bytes: 4352
#include "iostream"
using namespace std;

int main()
{
	long n, a, min=1000000, max=-1000000, sum=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a < min)
		{
			min = a;
		}
		if (a > max)
		{
			max = a;
		}
		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3104
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
using namespace std;
template <typename T> using vector2 = vector <vector  <T>>;
template <typename T> using vector3 = vector <vector2 <T>>;
template <typename T> using vector4 = vector <vector3 <T>>;
using lint = long long;
#define FOR( i, a, b ) for( lint i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( lint i= 0  ; i < (n) ; ++i )
#define ALL( v )       (v).begin(), (v).end()

//	cinからvectorへ入力
template<typename T>
istream& operator >> ( istream& is, vector<T>& vec ) {
    for( T& x: vec ) {
        is >> x;
    }
    return is;
}

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

    vector<int> H(N);
    cin >> H;

    int count = 0;
    while( true ) {
        bool flg = false;
        for( int i=0; i<N && (!flg || H[i]); i++ ) {
            if( !flg && H[i] ) {
                flg = true;
            }
            if( flg && H[i] ) {
                H[i] --;
            }
        }
        if( !flg ) {
            break;
        }
        count ++;
    }

    cout << count << endl;
}


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

int main() {
	int a,b;
  	cin >> a >> b;
  
  	int num = 0;
  	int c = b;
  	while(c > 0) {
    	c /= 10;
      	num++;
    }
  
  	for(int i = 0; i < num; i++) {
    	a *= 10;
    }
  
  	int newnum = a + b;
  	bool can = false;
  
  	for(int i = 0; i < 320; i++) {
    	if(newnum == i*i) {
          can = true;
        }
    }
  
  	if(can) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
}

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {
	int n; scanf("%d", &n);
	double ok;
	if(n%2) {
		ok = (double)(n/2 + 1)/n;
	}
	else {
		ok = (double)1/2;
	}
	printf("%f", ok);
	return 0;
}










Measured memory_bytes: 256
#include<cstdio>

int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a > b){
    printf("a > b\n");
  }
  else if(a < b){
    printf("a < b\n");
  }
  else{
    printf("a == b\n");
  }
}

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

vector<int> v[100100];
int pnum[100100];
int ans[100100];

void dfs(int i) {
	for(int j: v[i]) if (--pnum[j] == 0) ans[j] = i + 1;
	for(int j: v[i]) if (pnum[j] == 0) dfs(j);
}

int main() {
	int n, m;
	cin >> n >> m;
        rep(i, n - 1 + m) {
                int s, t;
                cin >> s >> t;
                s--; t--;
                v[s].push_back(t);
		pnum[t]++;
        }
	int root;
	rep(i, n) if (pnum[i] == 0) root = i;
	dfs(root);
	rep(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
string a,b;
int x=1,s;
int main(){
	cin>>a>>b;
	a+=b;
	for(int i=a.size()-1;i>=0;i--) s+=(a[i]-'0')*x,x*=10;
	int q=sqrt(s);
	if(q*q==s) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

const int MAX = 20;
const int MAX_VALUE = 50001;
const int INF = 100000000;

int main() {
	int n, m;
	int c[MAX];
	int table[MAX_VALUE];

	cin >> n >> m;
	for (int i = 0; i <= n; i++) {
		table[i] = INF;
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i];
		table[c[i]] = 1;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + c[j] > n)continue;
			table[i + c[j]] = min(table[i] + 1, table[i + c[j]]);
		}
	}

	cout << table[n] << endl;
	return 0;
}

Measured memory_bytes: 3272
N = int(input())
dic = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = 0
for v in dic.values():
    ans += v * (v - 1) // 2

print(ans)




Measured memory_bytes: 17852
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	q := partition(&a, 0, len(a) - 1)

	if q > 0 {
		fmt.Print(strings.Trim(fmt.Sprint(a[:q]), "[]"))
		fmt.Print(" ")
	}
	fmt.Print("[")
	fmt.Print(a[q])
	fmt.Print("]")
	if q < len(a) - 1 {
		fmt.Print(" ")
		fmt.Print(strings.Trim(fmt.Sprint(a[q+1:]), "[]"))
	}
	fmt.Println()
}

func partition(a *[]int, p, r int) int {
	x := (*a)[r]
	i := p
	for j := p; j < r; j++ {
		if (*a)[j] <= x {
			(*a)[i], (*a)[j] = (*a)[j], (*a)[i]
			i++
		}
	}
	(*a)[i], (*a)[r] = (*a)[r], (*a)[i]
	return i
}



Measured memory_bytes: 5376
#include<iostream>
#include<cstdio>
using namespace std;
int partition(int* arr,int left,int right){
    int x = arr[right];
    int i,j;
    for(i=left-1,j=left;j<right;j++){
        if(arr[j] <= x)
            swap(arr[j],arr[++i]);
    }
    swap(arr[i+1],arr[right]);
    return i+1;
}
int main(){
    int len;
    cin>>len;
    int* arr=new int[len];
    for(int i=0;i<len;i++)
        cin>>arr[i];
    
    int p = partition(arr,0,len-1);
    for(int i=0;i<len;i++)
        if(i){
            if(i!=p)
                cout << " " << arr[i];
            else
                printf(" [%d]",arr[i]);
        }
        else{
            if(i!=p)
                cout << arr[i];
            else
                printf("[%d]",arr[i]);
        }
    cout << endl;
    delete[]arr;
    return 0;
}



Measured memory_bytes: 3340
N, K = map(int, input().split())
AB = (tuple(map(int, input().split())) for _ in range(N))

# 各商品の価格のビットが立っている位置を事前に見とく
bit = []
for a, b in AB:
    tmp = set()
    for i in range(31):
        if a & 1:
            tmp.add(i)
        a //= 2
    bit.append((tmp, b))

def cost(S):
    res = 0
    for T, b in bit:
        if S.issuperset(T):
            res += b
    return res

# Kのビットが立っている位置を調べる
Kbit = set()
Ktmp = K
for i in range(31):
    if Ktmp & 1:
        Kbit.add(i)
    Ktmp //= 2

ans = cost(Kbit)
for i in Kbit:
    T = Kbit.copy()
    T -= {i}            #位置iのビットを0にする
    T |= set(range(i))  #i未満のビットを全部1にする
    ans = max(ans, cost(T))

print(ans)


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

int main(){
  int h, w;
  char c[101][101];
  cin >> h >> w;
  for ( int i = 0; i < h; i++ ){
    for ( int j = 0; j < w; j++ ){
      cin >> c[i][j];
    }
  }
  for ( int i = 0; i <= h + 1; i++ ){
    if ( i == 0 || i == h + 1 ){
	  for ( int j = 0; j <= w + 1; j++ ){
        cout << "#";
      }
    }else{
      for ( int j = 0; j <= w + 1; j++ ){
        if ( j == 0 || j == w + 1 ){
          cout << "#";
        }else{
          cout << c[i-1][j-1];
        }
      }
    }
    cout << endl;
  }
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 0; i < (ll)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    int a, b;

    cin >> a >> b;

    int n = 0;

    while(n*(a - 1) + 1 < b){
        n++;
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535
unsigned int fact(unsigned int n) 
{ 
    if (n == 0) 
        return 1; 
    return n * fact(n - 1); 
} 
int main(){
    int n;
    cin >> n;
    int arr[n];
    int ans[n+1];
    ans[n]=0;
    memset(ans,0,sizeof(ans));
    for(int i=1;i<n;i++){
        cin >> arr[i];
        ans[arr[i]]++;
    }
    for(int i=1;i<=n;i++){
        cout << ans[i] <<endl;
    }
    
    
}


Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int main()
{
	int x[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> x[i];
		if (x[i] == 0)
		{
			cout << i + 1 << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    char c;
    cin >> c;
    char ans;
    if(c=='A'){
        ans = 'T';
    }else if(c=='T'){
        ans ='A';
    }else if(c=='G'){
        ans = 'C';
    }else if(c=='C'){
        ans = 'G';
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

const int N = 4005;

int a[N][4];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = n - 1; i >= 0; i--) {
    a[i][1] += (s[i] == 'R') + a[i + 1][1];
    a[i][2] += (s[i] == 'B') + a[i + 1][2];
    a[i][3] += (s[i] == 'G') + a[i + 1][3];        
  }
  map<char, int> m;
  m['R'] = 1;
  m['B'] = 2;
  m['G'] = 3;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] != s[j]) {
        int x = m[s[i]];
        int y = m[s[j]];
        sum += (long long)a[j + 1][6 - x - y];
        int diff = j - i;
        if ((j + diff) < n && s[j + diff] != s[j] && s[j + diff] != s[i]) sum--;
      }
    }
  }
  cout << sum << '\n';
  return 0;
}

Measured memory_bytes: 3684
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        HashSet<Integer> rem = new HashSet<>();
        long ans = 0;
        int def = 7%k;
        while ((!rem.contains(def))&&(!rem.contains(0))){
            rem.add(def);
            def = (def*10+7)%k;
            ans++;
        }
        if (rem.contains(0))System.out.println(ans);
        else System.out.println(-1);
    }
}


Measured memory_bytes: 93540
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
int n, k, a[N][3], b[N], c[N];
int dp[N][3];
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) scanf("%d %d %d", a[i], a[i] + 1, a[i] + 2);
	for (int i = 0; i < 3; ++i) dp[1][i] = a[1][i];
	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (j != k) {
					dp[i][k] = max(dp[i][k], dp[i - 1][j] + a[i][k]);
				}
			}
		}
	}
	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
}


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

template <class _T> inline bool chmax (_T& a,_T b){if(a<b){a=b;return true;}return false;}
template <class _T> inline bool chmin (_T& a,_T b){if(a>b){a=b;return true;}return false;}

const long long INF = 1LL << 60;
const long long mod = 1000000007;


int main(void){
    cout.precision(17);
    int n,k; cin >> n >> k;
    vector<double> v(n);
    vector<double> s(n+1);
    s[0] = 0.;
    for(int i=0;i<n;i++){
	int a;
	cin >> a;
	v[i] = (a+1)/2.0; 
	s[i+1] = s[i] + v[i];
    }
    double ans=0;
    for(int i=0;i<=n-k;i++){
	ans = max(ans,s[i+k]-s[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 200000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int main() {
    ll a, b;
    cin >> a >> b;
    printf("%lld\n", a * b / std::__gcd(a, b));
    return 0;
}

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


int main(){
    int n, x ;
    cin >> n >> x;
    int l[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> l[i];
    }
    
    int d[n + 2];
    d[1] = 0;
    for(int i = 2; i <= n + 1; i++){
        d[i] = d[i - 1] + l[i - 1];
    }
     
    int ans = 0;
    for(int i = 1; i <= n + 1; i++){
        if(d[i] <= x) ans++;
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n;

int main() {
	cin >> n;
	if (n/10==9 || n%10==9) cout << "Yes" << ln;
	else cout << "No" << ln;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;

const int MAXN = 5001;

int n;
pair<ll, ll> c[3];

ll bruteforce() {
	ll ans = 0;
	for(ll x = 0; c[0].X * x <= n; x++) {
		ll m = n - c[0].X * x;
		for(int y = 0; c[1].X * y <= m; y++) {
			ll mm = m - c[1].X * y;
			ll z = mm / c[2].X;
			ll mmm = mm - c[2].X * z;
			ans = max(ans, mmm + c[0].Y * x + c[1].Y * y + c[2].Y * z);
		}
	}
	return ans;
}

ll solve(vector<int> is) {
	auto a = c[is[0]];
	auto b = c[is[1]];

	ll ans = 0;

	for(int x = 0; a.X * x <= n; x++) {
		ll m = n - a.X * x;
		ll y = m / b.X;
		ll mm = m - y * b.X;
		ans = max(ans, mm + a.Y * x + b.Y * y);
	}
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	
	cin >> n;
	for(int j = 0; j < 3; j++) {
		cin >> c[j].X;
	}
	for(int j = 0; j < 3; j++) {
		cin >> c[j].Y;
	}

	int cnt = 0;
	vector<int> fst;
	for(int i = 0; i < 3; i++) {
		if(c[i].X <= c[i].Y) {
			cnt++;
			fst.push_back(i);
		} else swap(c[i].X, c[i].Y);
	}

	ll ans;
	if(cnt == 3 || cnt == 0) {
		ans = bruteforce();
	} else if(cnt == 1) {
		int k = fst[0];
		ll x = n / c[k].X;
		n = (n % c[k].X) + x * c[k].Y;
		vector<int> is;
		for(int i = 0; i < 3; i++) {
			if(i != k) is.push_back(i);
		}
		ans = solve(is);
	} else {
		n = solve(fst);
		int k = 3 - fst[0] - fst[1];
		ll x = n / c[k].X;
		ans = (n % c[k].X) + x * c[k].Y;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[m+1];
        a[0]=0;
        b[0]=0;
        for (int i=1;i<=n;i++)a[i]=a[i-1]+sc.nextInt();
        for (int i=1;i<=m;i++)b[i]=b[i-1]+sc.nextInt();
        int ans = 0;
        int j = m;
        for (int i=0;i<=n;i++){
            if (a[i]>k)continue;
            while (b[j]>k-a[i])j--;
            ans=Math.max(ans,i+j);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 63104
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <cassert>
#include <cmath>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = (1 << 30);
int ted[maxn];
bool mark[maxn];

int main(){
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        ted[i] = 1;
    mark[1] = 1;
    for (int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        ted[a] --;
        ted[b] ++;
        if (mark[a] == 1)
            mark[b] = 1;
        if (ted[a] == 0)
            mark[a] = 0;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        if (mark[i] == 1)
            cnt ++;
    cout << cnt << endl;
}

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

int main(void){
        string S,T,U;
        int A,B;
        cin >> S >> T;
        cin >> A >> B;
        cin >> U;
        if(U == S){
                A--;
        }else if(U == T){
                B--;
        }
        cout << A << " " << B << "\n";
        return 0;
}

Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    d = collections.defaultdict(list)
    for _ in range(m):
        a, b = list(map(int, readline().split()))
        if a == 1 or a == n:
            if a not in d[b]:
                d[b] += [a]
        elif b == 1 or b == n:
            if b not in d[a]:
                d[a] += [b]
    for k, v in d.items():
        if k != 1 and k != n:
            if len(v) == 2:
                print("POSSIBLE")
                exit()
    print("IMPOSSIBLE")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 78172
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long LL;
const int N=2e5+10;
const LL inf=1e18;

LL n,x,a[N],d[N],sum[N];

int main(){
    scanf("%lld%lld",&n,&x);
    for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
    for(int i=1;i<=n;++i)sum[i]=sum[i-1]+a[i];
    for(int i=1,j=n;i<=n;++i){
        while((LL)(2*j+1-5)*a[i]>x)--j;
        d[i]=j;
    }
    LL ans=inf;
    for(int t=1;t<=n;++t){
        LL tmp=x*t+2ll*(sum[n]-sum[n-t]);
        bool flag=1;
        int p=1;
        for(int i=n;i>0;i-=t,++p){
            if(d[i]<p)flag=0;
            tmp+=(LL)(2*p+1)*(sum[i]-sum[max(0,i-t)]);
        }
        if(flag&&tmp<ans)ans=tmp;
    }
    ans+=n*x;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 4864
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

string s;
int dfs(vvi& dp, int i, int t) {
	if (i == s.size())return 0;
	if (dp[i][t] != -1)return dp[i][t];
	if (t == 0) {
		int ret = -INF;
		if (s[i] != s[i - 1])chmax(ret, dfs(dp, i + 1, 0)+1);
		if (i + 1 < s.size())chmax(ret, dfs(dp, i + 2, 1)+1);
		return dp[i][t] = ret;
	}
	else {
		int ret = -INF;
		chmax(ret, dfs(dp, i + 1, 0)+1);
		if (i + 1 < s.size() && !(s[i - 2] == s[i] && s[i - 1] == s[i + 1]))chmax(ret, dfs(dp, i + 2, 1)+1);
		return dp[i][t] = ret;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	int n = s.size();
	if (n == 1)cout << 1 << endl;
	else if (n == 2) {
		if (s[0] == s[1])cout << 1 << endl;
		else cout << 2 << endl;
	}
	else {
		vvi dp(n, vi(2, -1));
		dfs(dp, 1, 0);
		dfs(dp, 2, 1);
		cout << max(dp[1][0], dp[2][1]) + 1;
	}
}

Measured memory_bytes: 26516
#include <stdio.h>

char A[1000 * 1000 * 1000];
int main() {
    int n;
    scanf("%d", &n);
    for (int i =0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if (A[a] == 1) {
            printf("NO");
            return 0;
        } else {
            A[a] = 1;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 975360
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=1e9+7;
const int MAX=300010;

ll x[MAX],y[MAX];
pll p[MAX];
signed main(){
    ll h,w,m;cin>>h>>w>>m;
    ll mx=0,my=0;
    rep(i,m){
        ll a,b;cin>>a>>b;
        a--;b--;
        x[a]++;
        y[b]++;
        mx=max(mx,x[a]);
        my=max(my,y[b]);
        p[i]=(mp(a,b));
    }
    ll cnt=0;
    rep(i,m){
        ll xx=p[i].fi;
        ll yy=p[i].se;
        if(x[xx]==mx&&y[yy]==my)cnt++;
    }
    ll cntx=0;
    ll cnty=0;
    rep(i,h){
        if(x[i]==mx)cntx++;
    }
    rep(i,w){
        if(y[i]==my)cnty++;
    }
    cout<<mx+my-(!(cntx*cnty>cnt))<<endl;
}

Measured memory_bytes: 12992
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const ll MOD = 1000000007;

/*

caa cbb
cbb caa

ccbb ccaa ccaa
aacc aacc aabb


bba
cca

ba bc
ba bc

*/


ll ans;
int N;
char S1[55], S2[55];

int main(void) {
    scanf("%d", &N);
    scanf("%s %s", S1, S2);

    int i;
    if (S1[0] == S2[0]) {ans = 3; i = 1;}
    else { ans = 6; i = 2;}

     while (i < N) {
         ll c;
        if (S1[i] != S2[i]) {
            if (S1[i-1] != S2[i-1]) c = 3;
            else c = 2;
            
            ans *= c;
            ans %= MOD;
            i += 2;
        } else {
            if (S1[i-1] == S2[i-1]) {
                ans *= 2;
                ans %= MOD;
            }
            i++;
        }
    }
   

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

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, m;
	cin >> n >> m;
	lli maxL=0;
	lli minR=INF;
	loop(i, 1, m+1){
		lli L, R;
		cin >> L >> R;
		if(maxL < L) maxL = L;
		if(minR > R) minR = R;
	}
	lli ans = minR - maxL + 1;
	if(ans < 1) cout << "0" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

x,y=map(int,input().split())
if (x+y)%3==0 and x<=2*y and y<=2*x:
    a=abs(2*y-x)//3
    b=abs(y-2*x)//3
    print(cmb(a+b,min(a,b),mod))
else:print(0) 

Measured memory_bytes: 122016
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void){
  char X, Y;

  scanf("%c %c", &X, &Y);
  X -= 'A';
  Y -= 'A';
  
  if(X > Y){
    printf(">");
  }else if(X == Y){
    printf("=");
  }else{
    printf("<");
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(void) {
	int n, m;
	scanf("%d %d", &n, &m);
	printf("%d\n", (n-1)*(m-1));
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}
//const int NAX = (int)3e5+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
  int n, m; cin >> n >> m;
  priority_queue<int> pq;
  forn(i, n) {
     int x; cin >> x;
     pq.push(x);
  }
  forn(i, m) {
    int x = pq.top();
    pq.pop();
    pq.push(x/2);
  }
  ll res = 0ll;
  forn(i, n) {
    res += pq.top();
    pq.pop();
  }
  cout << res << "\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int a[100100];
int a_min[100100];
int main(){
  int n, t; cin >> n >> t;
  rep(i,n) cin >> a[i];
  rep(i,n) {
    if(i == 0){
      a_min[i] = 1e9; // a_min[0] は未定義
      continue;
    }
    a_min[i] = min(a_min[i-1], a[i-1]);
  }

  int tmp = 0;
  rep(i,n) chmax(tmp,a[i]-a_min[i]);
  int ans = 0;
  rep(i,n) if(tmp == a[i]-a_min[i]) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int a[6];
string s;
void C(int i,int j,int k,int l){
  int t;t=a[i];a[i]=a[j];a[j]=a[k];a[k]=a[l];a[l]=t;
}
int main(){
  for(int i=0;i<6;i++)cin>>a[i];
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='E')for(int j=0;j<3;j++)C(0,2,5,3);
    if(s[i]=='W')C(0,2,5,3);
    if(s[i]=='S')for(int j=0;j<3;j++)C(0,1,5,4);
    if(s[i]=='N')C(0,1,5,4);
  }
  cout<<a[0]<<endl;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if (N >= 195){
    cout << 5 << endl;
  }
  else if (N >= 189){
    cout << 4 << endl;
  }
  else if (N >= 165){
    cout << 3 << endl;
  }
  else if (N >= 135){
    cout << 2 << endl;
  }
  else if (N >= 105){
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
}
    

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var nums = new List<Number>();
        for (int i = 0; i < N; i++)
        {
            nums.Add(new Number(i, array[i]));
        }
        var sorted = nums.OrderByDescending(x => x.Value).ToArray();
        for (int i = 0; i < N; i++)
        {
            var isFormer = array[i] > sorted[(N + 1) / 2].Value;
            if (isFormer)
            {
                Console.WriteLine(sorted[(N + 1) / 2].Value);
            }
            else
                Console.WriteLine(sorted[(N + 1) / 2-1].Value);
            
        }
    }
}
public struct Number
{
    public Number(int index, int value)
    {
        Index = index;
        Value = value;
    }
    public int Index, Value;
}


Measured memory_bytes: 47564
#include <iostream>
#include <algorithm>
using namespace std;
 
int ord2(int N) {
	int count = 0; 
	while(N % 2 == 0) {
		N /= 2;
		count++;
	}
	return count;
}
 
int main() {
	int N; 
   	cin >> N;
	int kaisuu = 0;  
	for(int i = 0; i < N; ++i) 
	{int s;
	cin >> s;
   	int n = ord2(s); 
	kaisuu = n + kaisuu;
	} 
	cout << kaisuu << endl; 
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

map<string, int> mmp,mmp2;
vector<string>v;
int n, m;

int main() {
	cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		v.emplace_back(s);
		mmp[s]++;
	}
	cin >> m;
	REP(i, m) {
		string s;
		cin >> s;
		mmp2[s]++;
	}
	int ans = 0;
	REP(i, n) {
		ans = max(ans, mmp[v[i]] - mmp2[v[i]]);
	}
	cout << ans << endl;
}

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

using namespace std;

using ll = long long;
const int MOD = 998244353;
const int BASE = 716070898;

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N;
   vector<int> pw(N + 1);
   pw[0] = 1;
   for (int i = 0; i < N; ++i) {
      pw[i + 1] = ll(pw[i]) * BASE % MOD;
   }
   vector<array<int, 512>> cnts;
   for (int z = 0; z < 3; ++z) {
      int M;
      cin >> M;
      vector<vector<int>> adj(N);
      for (int i = 0; i < M; ++i) {
         int v, u;
         cin >> v >> u;
         --v, --u;
         if (v > u) swap(v, u);
         adj[v].emplace_back(u);
      }
      array<int, 512> cnt = {};
      vector<int> sg(N);
      for (int v = N - 1; v >= 0; --v) {
         set<int> nxts;
         for (int u : adj[v]) {
            nxts.emplace(sg[u]);
         }
         sg[v] = 0;
         while (nxts.count(sg[v])) sg[v]++;
         cnt[sg[v]] += pw[v + 1];
         if (cnt[sg[v]] >= MOD) cnt[sg[v]] -= MOD;
      }
      cnts.emplace_back(cnt);
   }
   int ans = 0;
   for (int x = 0; x < 512; ++x) {
      for (int y = 0; y < 512; ++y) {
         ans += ll(cnts[0][x]) * cnts[1][y] % MOD * cnts[2][x ^ y] % MOD;
         if (ans >= MOD) ans -= MOD;
      }
   }
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>K;
    ll ans = 0;
    rep(i,N){
        cin>>A;
        ans += A >= K;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque
def bfs():
  while len(q) > 0:
    p = q.popleft()
    for e in g[p]:
      if d[e] < 0:
        q.append(e)
        d[e] = d[p] + 1
        f[e] = p
      elif d[e] > d[p] + 1:
        d[e] = d[p] + 1
        f[e] = p       

  
  
n, m = map(int, input().split())
g = [[] for i in range(3 * (n+1))]
for i in range(m):
  u, v = map(int, input().split())
  g[3*u].append(3*v+1)
  g[3*u+1].append(3*v+2)
  g[3*u+2].append(3*v)

s, t = map(int, input().split())

d = [-1] * (3 * (n+1))
f = [-1] * (3 * (n+1))
d[3*s] = 0
f[3*s] = 0
q = deque([3*s])
bfs()
c = 0
if f[3*t] == -1:
  print(-1)
  exit()

t = 3 * t
while f[t] > 0:
  c += 1
  t = f[t]
  
print(c // 3) 


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

import sys
from io import StringIO
import unittest
import copy

def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    arr=list(map(int, readline().rstrip().split()))
    n=len(arr)
    be=[0]*(10**6+1)
    xxx=n
    for i in range(n):
        be[arr[i]]+=1
    is1=True
    is2=True
    for i in range(2,10**6+1):
        x = i
        found=0
        while x <= 10**6:
            found+=be[x]
            x += i
        if found >= 2:
            is1=False
        if found == xxx:
            is2=False
    if is1==True:
        print("pairwise coprime")
    elif is2==True:
        print("setwise coprime")
    else:
        print("not coprime")

    return

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

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

Measured memory_bytes: 187240
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,N,a[200005],b[200005];
bool check(int mid){
	for(int i=0;i<N;i++)b[i]=(a[i]>mid);
	for(int i=n-1;i;i--){
		if(b[i]==b[i-1])return b[i];
		if(b[N-i-1]==b[N-i])return b[N-i];
	}
	return b[0];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	N=2*n-1;
	for(int i=0;i<N;i++)cin>>a[i];
	int lb=0,ub=N;
	while(ub-lb>1){
		int mid=(lb+ub)>>1;
		if(check(mid))lb=mid;
		else ub=mid;
	}
	cout<<ub<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int dy[4] = {1,0,-1,0};
int dx[4] = {0,-1,0,1};
int N,M;
int x[21],y[21];
int vis[21][21];

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

  while (cin >> N, N) {
    REP(i,N) cin >> x[i] >> y[i];
    cin >> M;
    int yy = 10, xx = 10;
    ZERO(vis);
    vis[10][10] = 1;
    REP(i,M) {
      char dir;
      int dis;
      cin >> dir >> dis;
      REP(j,dis) {
        if (dir == 'N') {
          yy += dy[0];
          xx += dx[0];
        } else if (dir == 'W') {
          yy += dy[1];
          xx += dx[1];
        } else if (dir == 'S') {
          yy += dy[2];
          xx += dx[2];
        } else {
          yy += dy[3];
          xx += dx[3];
        }
        vis[yy][xx] = 1;
      }
    }
    int ok = 1;
    REP(i,N) ok &= vis[y[i]][x[i]];
    cout << (ok ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> as(n);
  int minus = 0;
  int zeros = 0;
  int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    int64_t a;
    std::cin >> a;
    if (a < 0) {
      a = -a;
      minus++;
    } else if (a == 0) {
      zeros++;
    }
    as[i] = a;
    sum += a;
  }
  if (zeros == 0) {
    if ((minus % 2) != 0) {
      std::sort(as.begin(), as.end());
      sum -= as.front() * 2;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 1024