akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            long k = long.Parse(ReadLine());
            //文字数1の処理
            if (s.Length == 1)
            {
                WriteLine(k / 2);
                return;
            }

            int cnt = 0;
            char remain = s[0];
            /// はじめと終わりの個数判定
            /// 
            int first = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (remain == s[i]) first++;
                else break;
            }
            int last = 0;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                if (s[s.Length - 1] == s[i]) last++;
                else break;
            }

            //全部同じ文字の時の処理
            if (first == s.Length)
            {
                if (s.Length % 2 == 0)
                {
                    WriteLine((s.Length / 2) * k);
                }
                else if (k % 2 == 0)
                {
                    WriteLine(s.Length * (k/2));
                }else WriteLine(
                    (s.Length * k) / 2
                    );
                return;
            }
            ///s.Length%2 == 0 ? (s.Length/2) * k : ((s.Length / 2) * k) + 1


            //通常処理
            //多分完成
            bool flug = false;
            for (int i = 1; i < s.Length; i++)
            {
                if (remain == s[i] && flug == false)
                {
                    cnt++;
                    flug = !flug;
                }
                else
                {
                    flug = false;
                    remain = s[i];
                }
            }
            if (s[0] == s[s.Length - 1])
            {
                //割り切れる時+1
                if ((first + last) % 2 == 0) 
                {
                    WriteLine(((long)cnt * k) + (k-1));
                }
                else
                {
                    WriteLine((long)cnt * k);
                }
            }
            else
            WriteLine((long)cnt * k);
        }
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}



Measured memory_bytes: 3184
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {

    var (A, B, N) = readInts()
    val a = readInts()
    val b = readInts()
    val x = (0 until N).map {
        readInts()
    }
    var best = a.min()!! + b.min()!!
    best = Math.min(best,
        x.map {
            sx -> a[sx[0] - 1] + b[sx[1] - 1] - sx[2]
        }.min()!!
    )
    println(best)
}

/*
1 1 5 -> 3
1 5 1 -> 2
5 1 1 -> 1
 */


Measured memory_bytes: 107028
// abco54c: One-stroke Path
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int n,m;
vvi v(8);
vi visit(8);

void dfs(int p, int c, int distance, int &count){
  if(distance==n-1){
    count++;
    return;
  }
  visit[c] = true;
  for(auto cc:v[c]){
    if(visit[cc]) continue;
    dfs(c,cc,distance+1,count);
  }
  visit[c] = false;
}

int main(){
  in(n);in(m);
  rep(i,m){
    int a,b; in(a);in(b);
    a--; b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  int count = 0;
  dfs(-1,0,0,count);
  oute(count);
}

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

const int INF = 1e9;

int main() {
  int n,m;
  cin>>n>>m;
  pair<int, int> e[m];
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    e[i]=make_pair(a,b);
  }
  int ans=m;
  for(int i=0;i<m;i++){
    vector<pair<int, int> > e2;
    int s,g;
    for(int j=0;j<m;j++){
      if(i!=j){
        e2.push_back(e[j]);
      }else{
        s=e[j].first;
        g=e[j].second;
      }
    }
    set<int> visited;
    queue<int> que;
    que.push(s);
    bool flag=false;
    while(!que.empty()) {
      int a=que.front();
      que.pop();
      if(a==g){
        flag=true;
        break;
      }
      visited.insert(a);
      for(pair<int, int> ei: e2){
        if(ei.first==a && visited.find(ei.second) == visited.end()){
          que.push(ei.second);
        }
        if(ei.second==a && visited.find(ei.first) == visited.end()){
          que.push(ei.first);
        }
      }
    }
    if(flag){
      --ans;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define loop(i, a, b) for(ll i = a; i < b; i++)
#define rloop(i, e, s) for(ll i = e; i >= s; i--)
const ll mod = 1e9 + 7;
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);

int main()
{
     //Rectangle cutting
    ld w, h, x, y, z;
    cin >> w >> h >> x >> y;
    ld p = (w/2.0);
    ld q = (h/2.0);
    //cout << setprecision(6) << fixed;
    z = (w*h)/2.0;
    if(p == x && q == y) cout << z << " " << "1" << endl;
    else cout << z <<  " " << "0" << endl;
}
    




Measured memory_bytes: 256
N,T = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
Min = A[0]
Profit = 0
for i in range(1,N):
    if A[i]-Min > Profit:
        Profit = A[i]-Min
        ans = 1
    elif A[i]-Min == Profit:
        ans += 1
    Min = min(A[i],Min)
print(ans)

Measured memory_bytes: 14252
#ABC084D 累積和
from itertools import accumulate
#エラトステネスの篩
def sieve(n: int) -> set: #返り値はset
    if n < 2:
        return set()
    
    num = [True]*n
    num[0] = num[1] = False
    for i in range(3,int(n**0.5)+1,2):
        if num[i]:
            num[i * i:: 2 * i] = [False] * ((n - i ** 2 - 1) // (2 * i) + 1)
    return {2}|{i for i in range(3,n,2) if num[i]}

primelist = sieve(10**5+1)
Q = int(input())
N = []
A = []
for i in range(Q):
    num = list(map(int, input().split()))
    N.append(num)
    
#prime = list(set(sieve(r))-set(sieve(l)))#重複がないlist同士の引き算
    
_2017_like = [1 if i in primelist and (i + 1) // 2 in primelist else 0 for i in range(10**5+1)]#2017likeな数のindexが求まる
sum = list(accumulate(_2017_like)) #ある数までの解の個数
for j in range(Q):
    ans = sum[N[j][1]]-sum[N[j][0]-1] #累積和
    A.append(ans)
print('\n'.join(map(str, A)))

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

using namespace std;

int main(){
    int x, z = 0;
    cin >> x;
    int y[3050];
    for(int a = 0; a < x; a++){
        cin >> y[a];
        z += y[a];
    }
    cout << z - x << endl;
    return 0;
}

Measured memory_bytes: 256
x = int(input())
if 400<=x<=599:
    print(8)
elif x<=799:
    print(7)
elif x<=999:
    print(6)
elif x<=1199:
    print(5)
elif x<=1399:
    print(4)
elif x<=1599:
    print(3)
elif x<=1799:
    print(2)
elif x<=1999:
    print(1)

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

using namespace std;

int main() {
  int N, M;
  cin >> N;
  map<string, int> list;
  string a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    list[a]++;
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> a;
    list[a]--;
  }

  int maxv = 0;
  for( auto i = list.begin(); i != list.end() ; ++i ) {
      maxv = max(maxv,i->second);
  }
  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 256
import copy
n = int(input())
s = input()
s += s[0]+s[1]

kouho = ['SS','SW','WS','WW']

for x in kouho:
    ans = copy.deepcopy(x)
    for i in range(1,n+1):
        if (s[i]=='o' and ans[i]=='S') or (s[i]=='x' and ans[i]=='W'):
            if ans[i-1]=='S':
                ans+= 'S'
            else:
                ans+='W'
        else:
            if ans[i-1]=='S':
                ans+='W'
            else:
                ans+='S'
    #円環成してるので正しければ頭二個と後ろ2個は同じになるはず
    if ans[-2:]==x:
       print(ans[:n])
       exit()
print(-1)

Measured memory_bytes: 3956
#include <cstdio>

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

#define MAX_S 12
#define MAX_N 1000000

// トライ木っぽいもの
struct t_Node {
	bool end;
	int child[ 4 ];
};

void Init( void );
void Insert( const char* );
bool Find( const char* );

t_Node nodes[ MAX_N ];
int next_id;

int main() {
	Init();
	char ch[ MAX_S + 1 ];
	int n;  scanf( "%d", &n );
	while( n-- ) {
		scanf( "%s", ch );
		if( ch[ 0 ] == 'i' ) {  // insert
			scanf( "%s", ch );
			Insert( ch );
		} else {  // find
			scanf( "%s", ch );
			if( Find( ch ) ) printf( "yes\n" );
			else printf( "no\n" );
		}
	}
	return 0;
}

int Index( char ch ) {
	switch( ch ) {
	case 'A' : return 0;
	case 'C' : return 1;
	case 'G' : return 2;
	case 'T' : return 3;
	};
	return -1;
}

void Init() {
	REP( i, MAX_N ) {
		nodes[ i ].end = false;
		REP( j, 4 ) nodes[ i ].child[ j ] = -1;
	}
	next_id = 1;
	return ;
}

void Insert( const char* word ) {
	int s = 0;
	for( int i = 0; word[ i ] != '\0'; ++i ) {
		int index = Index( word[ i ] );
		int next_s = nodes[ s ].child[ index ];
		if( next_s == -1 ) {
			nodes[ s ].child[ index ] = next_id;
			s = next_id++;
		} else s = next_s;
	}
	nodes[ s ].end = true;
	return ;
}

bool Find( const char* word ) {
	int s = 0;
	for( int i = 0; word[ i ] != '\0'; ++i ) {
		int index = Index( word[ i ] );
		int next_s = nodes[ s ].child[ index ];
		if( next_s == -1 ) return false;
		else s = next_s;
	}
	return nodes[ s ].end;
}

Measured memory_bytes: 20540
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	string a,b;
	cin>>a>>b;
	a+=b;
	int k = stoi(a);

	int sq = sqrt(k);

	if(sq*sq == k)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys, heapq

S = list(input())
N = len(S)

res = [0] * len(S)

i = 0
while i < len(S):
    s = S[i]
    h = i
    cntR = 0
    cntL = 0
    while s == "R":
        i += 1
        cntR += 1
        s = S[i]
    tmp = i
    res[tmp] += cntR // 2
    res[tmp - 1] += cntR // 2 + int(cntR % 2 == 1)
    while s == "L":
        i += 1
        cntL += 1
        if i < N:
            s = S[i]
        else:
            break
    res[tmp] += cntL // 2 + int(cntL % 2 == 1)
    res[tmp - 1] += cntL // 2

print(*res)

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

int main(){
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='?')
      cout << 'D';
    else
      cout << s.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3704
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            long n = long.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split(' ');
            long[] num = new long[n];
            long sum = 0;

            for(int i = 0;i < n;i++)
            {
                long temp = long.Parse(a[i]);
                num[temp -1]++;
            }

            for(int i = 0;i < n;i++)
            {
                sum += num[i] *(num[i] -1)/2;
            }

            for(int i = 0;i < n;i++)
            {
                long temp = long.Parse(a[i]);
                Console.WriteLine(sum - num[temp-1] +1);
            }
            
        }

 
    }

Measured memory_bytes: 35036
use self::dsu::Dsu;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m],
    };
    let mut dsu = Dsu::new(n);
    for &(a_i, b_i) in ab.iter() {
        dsu.merge(a_i, b_i);
    }
    let ans = (0..n).filter(|&i| dsu.leader(i) == i).count() - 1;
    println!("{}", ans);
}

// https://raw.githubusercontent.com/rust-lang-ja/ac-library-rs/ad148b05b07e3ac59cbc2987b8834742ef3d497a/src/dsu.rs
pub mod dsu {
    /// Implement (union by size) + (path compression)
    /// Reference:
    /// Zvi Galil and Giuseppe F. Italiano,
    /// Data structures and algorithms for disjoint set union problems
    pub struct Dsu {
        n: usize,
        // root node: -1 * component size
        // otherwise: parent
        parent_or_size: Vec<i32>,
    }

    impl Dsu {
        // 0 <= size <= 10^8 is constrained.
        pub fn new(size: usize) -> Self {
            Self {
                n: size,
                parent_or_size: vec![-1; size],
            }
        }
        pub fn merge(&mut self, a: usize, b: usize) -> usize {
            assert!(a < self.n);
            assert!(b < self.n);
            let (mut x, mut y) = (self.leader(a), self.leader(b));
            if x == y {
                return x;
            }
            if -self.parent_or_size[x] < -self.parent_or_size[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.parent_or_size[x] += self.parent_or_size[y];
            self.parent_or_size[y] = x as i32;
            x
        }

        pub fn same(&mut self, a: usize, b: usize) -> bool {
            assert!(a < self.n);
            assert!(b < self.n);
            self.leader(a) == self.leader(b)
        }
        pub fn leader(&mut self, a: usize) -> usize {
            assert!(a < self.n);
            if self.parent_or_size[a] < 0 {
                return a;
            }
            self.parent_or_size[a] = self.leader(self.parent_or_size[a] as usize) as i32;
            self.parent_or_size[a] as usize
        }
        pub fn size(&mut self, a: usize) -> usize {
            assert!(a < self.n);
            let x = self.leader(a);
            -self.parent_or_size[x] as usize
        }
        pub fn groups(&mut self) -> Vec<Vec<usize>> {
            let mut leader_buf = vec![0; self.n];
            let mut group_size = vec![0; self.n];
            for i in 0..self.n {
                leader_buf[i] = self.leader(i);
                group_size[leader_buf[i]] += 1;
            }
            let mut result = vec![Vec::new(); self.n];
            for i in 0..self.n {
                result[i].reserve(group_size[i]);
            }
            for i in 0..self.n {
                result[leader_buf[i]].push(i);
            }
            result
                .into_iter()
                .filter(|x| !x.is_empty())
                .collect::<Vec<Vec<usize>>>()
        }
    }
}


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

int main() {
    long long n,a,b;
    cin>>n>>a>>b;
    if((a-b)%2==0) cout<<(max(a,b)-min(a,b))/2<<endl;
    else{
        if(max(a,b)-1<n-min(a,b)) {

            cout<<(a+b-1)/2<<endl;
        }
        else cout<<((n-a)+(n-b)+1)/2<<endl;
    }
}

Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1e9,maxn=2e5+5;

int n,k;
int a[maxn],f[maxn];
int check(int s){
	int ks=k;
	for(int i=1;i<=n;i++){
		if(a[i]*f[i]>s){
			int lwst = s/f[i];
			ks -= a[i]-lwst;
			if(ks<0)return 0;
		}
	}
	return 1;
}

signed main(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)scanf("%lld",&f[i]);
	sort(a+1,a+n+1);sort(f+1,f+n+1);reverse(f+1,f+n+1);
	int l=0,r=1e12,ans;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid))r=mid-1,ans=mid;
		else l=mid+1;
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3456
/// referenced: https://beta.atcoder.jp/contests/abc066/submissions/2252964
#include <iostream>
using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint pow(lint x,lint e){
  if(e==1) return x%MOD;
  if(e==0) return 1;
  return pow(x*x%MOD,e/2)*(e%2==0?1:x)%MOD;
}
lint inv(lint i){
  return pow(i,MOD-2);
}
lint fact[100002],factinv[100002];
lint C(lint n,lint r){
  return fact[n]*factinv[r]%MOD*factinv[n-r]%MOD;
}

int main(){
  lint n,a;
  bool c[100002];
  for(lint i=1;i<=n;i++) c[i]=false;
  lint p[100002];
  lint x,y;

  cin >> n;
  for(lint i=0;i<=n;i++){
    cin >> a;
    if(c[a]){
      x=p[a];
      y=i;
    }
    c[a]=true;
    p[a]=i;
  }


  fact[0]=1;
  for(lint i=1;i<=n+1;i++) fact[i]=i*fact[i-1]%MOD;
  for(lint i=0;i<=n+1;i++) factinv[i]=inv(fact[i]);

  for(lint i=1;i<=n+1;i++){
    lint ans;
    ans=C(n+1,i);
    if(i-1<=n-(y-x)) ans+=MOD-C(n-(y-x),i-1);
    cout << (ans%MOD) << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    i = input()
    if i == 'A':
        print('T')
    elif i == 'T':
        print("A")
    elif i == "C":
        print("G")
    else:
        print("C")

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
string itos(int a){
  string s="";
  while(a){
    s=(char)(a%10+'0')+s;
    a/=10;
  }
  if(s=="")s="0";
  return s;
}
int main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    int co=0;
    while(s.size()!=1){
      co++;
      int maxi=0;
      rep(i,s.size()-1){
	string a=s.substr(0,i+1);
	string b=s.substr(i+1);
	maxi=max(maxi,atoi(&a[0])*atoi(&b[0]));
      }
      s=itos(maxi);
    }
    cout<<co<<endl;
  }
}

Measured memory_bytes: 1224
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const int inf = 1e9*2;
const int mod = 1e9+7;
int n;
int a[2000009];
map < int , int > mp;
int main(){
    fast,cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        if(mp[a[i]]) cout<<"NO"<<endl,exit(0);
        mp[a[i]] = 1;
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 10368
def insertionSort(A, n, g):
    global cnt 

    for i in range(g,n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt+=1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    g = 1
    G = [1]
    m = 1
    for i in range(1,101):
        tmp = G[i-1]+(3)**i
        if tmp <= n:
            m = i+1
            G.append(tmp)
            g += 1
        else:
            break
    G.reverse() 
    print(m)  # 1行目
    print(" ".join(list(map(str,G))))  # 2行目

    for i in range(0,m):
        insertionSort(A, n, G[i])
    print(cnt)  # 3行目
    for i in range(0,len(A)):
        print(A[i]) # 4行目以降

cnt = 0
n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
shellSort(A,n)


Measured memory_bytes: 45516
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m; cin>>n;
  string u[n];
  for(int i=0;i<n;++i) cin>>u[i];
  cin>>m;
  bool o=false;
  for(int i=0;i<m;++i){
    string t; cin>>t;
    bool flag=false;
    for(int j=0;j<n;++j)
      if(t==u[j]){
        flag=true;
        if(o) o=false;
        else o=true;
      }
    if(flag)
      if(o) cout<<"Opened by "<<t<<endl;
      else cout<<"Closed by "<<t<<endl;
    else cout<<"Unknown "<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 3168
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int *a;
    int n;
    int i;
    
    scanf("%d", &n);
    
    a = (int *) malloc(sizeof(int)*n);
    
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    
    for(i=n-1; i>=0; i--){
        if(i==0){
            printf("%d\n", a[i]);
        }
        else{
            printf("%d ", a[i]);
        }
    }
    
    free(a);
    return 0;
}

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

int main() {
  int N, M, i;
  cin >> N >> M;
  
  vector<int> count(N, 0);

  for (i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    
    for( int j = 0; j< N; j++) {
	    if ((j + 1 == a || j + 1 == b ) && a != b) {
			count.at(j)++;
        }
    }
  }
  
  for (i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }
}
  

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

using i64 = long long int;

const i64 MAX_N = 1ll << 20;
const i64 INF = 1e12;

struct Node{
    i64 id, point;
    bool operator<(const Node &obj)const{
        if(point == obj.point)return id > obj.id;
        return point < obj.point;
    }
};

i64 n, times[MAX_N]={0};
Node dat[2*MAX_N-1];

void init(i64 n_){
    n = 1;
    while(n < n_)n *= 2;
    for(i64 i=0;i<2*n-1;i++)dat[i] = (Node){INF, -INF};
    for(i64 i=0;i<n_;++i)dat[i+n-1] = (Node){i, 0};
}

void update(i64 k, i64 a){
    k += n - 1;
    dat[k].point += a;
    while(k > 0){
        k = (k - 1) / 2;
        dat[k] = max(dat[k*2 + 1], dat[k*2 + 2]);
    }
}

Node query(i64 a, i64 b, i64 k, i64 l, i64 r){
    if(r <= a || b <= l)return (Node){INF, -INF};

    if(a <= l && r <= b)return dat[k];
    else{
        Node vl = query(a, b, k*2+1, l, (l+r)/2);
        Node vr = query(a, b, k*2+2, (l+r)/2, r);
        return max(vl, vr);
    }
}

int main(){
    i64 N, R, L;
    cin >> N >> R >> L;
    init(N);
    i64 team = 0, prev_time = 0;
    for(int i=0;i<R;++i){
        i64 d, t, x;
        cin >> d >> t >> x;
        times[team] += (t - prev_time);
        prev_time = t;
        update(d-1, x);
        Node top = query(0, N, 0, 0, N);
        team = top.id;
    }
    times[team] += (L - prev_time);

    i64 maxi = LLONG_MIN, max_team = 0;
    for(int i=0;i<N;++i){
        if(times[i] > maxi){
            maxi = times[i];
            max_team = i;
        }
    }

    cout << max_team + 1 << endl;

    return 0;
}



Measured memory_bytes: 7964
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print1(a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,k,a[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	rep(k) cin >> a[i];
	rep(k) n-=a[i];
	print1(n<=0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
long long qq(long long x,long long y){
    if(y==0){
        return x;
    }
    else{
        return qq(y,x%y);
    }
}
int main(){
    int n;
    cin>>n;
    long long ans,d;
    cin>>ans;
    for(int i=1;i<n;i++){
        cin>>d;
        ans=ans*d/qq(ans,d);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3112
N,Q = map(int,input().split())
S = input()
index = [0] *(N+1)
for i in range(N):
  index[i+1] = index[i] + (1 if S[i:i+2] =='AC' else 0)
for _ in range(Q):
  r, l = map(int,input().split())
  print(index[l-1] - index[ r -1])

Measured memory_bytes: 51032
import scala.io.StdIn.{readInt, readLong};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val arr = (0 until n).map(a => readLong).toArray;
        val interval = fetchInterval(n);
        val cnt = shellSort(arr, n, interval);
        println(interval.length);
        println(interval.mkString(" "));
        println(cnt);
        println(arr.mkString("\n"));
    }
    
    def fetchInterval(n: Int): List[Int] = { 
        def go(g: Int, ret: List[Int]): List[Int] = {
            val ng = (g * 3) + 1;
            if (ng < n) go(ng, ng :: ret) else ret;
        }
        go(1, List(1));
    }
    
    def shellSort(arr: Array[Long], n: Int, interval: List[Int]): Int = {
        interval.foldLeft(0) { (cnt, i) =>
            (0 until n).foldLeft(cnt) { (cnt, j) =>
                insertionSort(arr, j, i) + cnt;
            }
        }
    }
    
    def insertionSort(arr: Array[Long], index: Int, interval: Int): Int = {
        val insert = arr(index);
        var cnt = 0;
        def go(curr: Int): Unit = {
            val prev = curr - interval;
            if (prev < 0 || arr(prev) <= insert) {
                arr(curr) = insert;
            } else {
                arr(curr) = arr(prev);
                cnt += 1;
                go(prev);
            }
        }
        go(index);
        cnt
    }
}


Measured memory_bytes: 458888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		int count = 0;
		for(int i = 0; i < N - 2; i++) {
			String tmp = S.substring(i, i + 3);
			if(tmp.equals("ABC")) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21716
s=input()
from collections import Counter
cs=Counter(s)
if len(cs.keys())==2:
  print('Second')
elif s[0]!=s[-1]:
  if len(s)%2==0:
    print('Second')
  else:
    print('First')
else:
  if len(s)%2!=0:
    print('Second')
  else:
    print('First')

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

int main() {				
  string AtC,s,Con,Ans;					// *constarint*
  cin >> AtC >> s >> Con;		    // 1 <= s <= 100
  							        //1文字目は大文字2文字目以降小文字
  Ans += AtC.at(0);
  Ans += s.at(0);
  Ans += Con.at(0);
  cout << Ans << endl;
}


Measured memory_bytes: 3640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

struct UnionFind {
    vector<int> par;
    vector<int> rnk;
    vector<int> siz;
    UnionFind(int N):par(N),rnk(N),siz(N){
        for (int i=0;i<N;i++){
            par[i]=i,rnk[i]=0,siz[i]=1;
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        int rx=find(x);
        int ry=find(y);
        if (rx==ry) return;
        if(rnk[rx]<rnk[ry]){
            par[rx]=ry;
            siz[ry]+=siz[rx];
            siz[rx]=0;
        }
        else{
            par[ry]=rx;
            siz[rx]+=siz[ry];
            siz[ry]=0;
            if(rnk[rx]==rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size (int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M;
    cin >> N >> M;
    UnionFind tree(N);
    vl A(M),B(M);
    rep(i,M){
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
    }
    vl ans(M);
    rep(i,M){
        if(i==0){
            ans[M-1]=N*(N-1)/2;
        }
        else{
            if(tree.same(A[M-i],B[M-i])){
                ans[M-1-i]=ans[M-i];
            }
            else{
                ll a=tree.size(A[M-i]),b=tree.size(B[M-i]);
                ans[M-1-i]=ans[M-i]-a*b;
                tree.unite(A[M-i],B[M-i]);
            }
        }
    }
    rep(i,M){
        cout << ans[i] << endl;
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


Measured memory_bytes: 6880
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int countOperate = 0;//最大操作数
		int N = 0;
		int[] number;

		String num = sc.nextLine();//Nの読み込み
		String line = sc.nextLine();//数字の読み込み
		String[] lines = line.split(" ");
		number = new int[lines.length];

		N = Integer.parseInt(num);
		for (int i = 0; i < lines.length; i++) {
			number[i] = Integer.parseInt(lines[i]);
			//System.out.println(number[i]);
		}


		//System.out.println("while");
		boolean flag = true;//ループを抜け出すためのもの
		while(flag) {
			for(int i = 0; i < lines.length; i++) {
				if(number[i] % 2 == 1) {
					flag = false;
					break;
				}else {
					number[i] = number[i] / 2;
				}
			}

			if(flag) {
				countOperate++;
			}
		}


		System.out.println(countOperate);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int l = 0;
  int r = 1001001001;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    int nk = 0;
    rep(i, n) {
      nk += (a[i] - 1) / mid;
    }

    if (nk <= k) r = mid;
    else l = mid;
  }
  int ans = ceil(l);
  
  cout << r << endl;
}

Measured memory_bytes: 3944
#include <cstdio>
#include <iostream>

using namespace std;

static void call(int n) {
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }

    int x = i;
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);
  return 0;
}

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

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  REP(i, 0, N) A[i] -= i + 1;
  sort(A.begin(), A.end());

  ll b = A[N / 2];
  ll ans = 0;
  REP(i, 0, N) ans += abs(A[i] - b);
  cout << ans << endl;
}

Measured memory_bytes: 1792
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

int N, X, Y;;
int sY, sX;
int[] cY, cX;
int[][] G;
int dist2(int sy, int sx, int gy, int gx) {
    int dy = gy - sy,
        dx = gx - sx;
    return dx * dx + dy * dy;
}

void input() {
    scanf("%d %d %d\n", &N, &X, &Y);
    scanf("%d %d\n", &sX, &sY);
    cY = new int[N];
    cX = new int[N];
    foreach (i; 0 .. N) {
        scanf("%d %d\n", &cX[i], &cY[i]);
    }
    G = new int[][N];
    foreach (i; 0 .. N) {
        foreach (j; i + 1 .. N) {
            if ( dist2(cY[i], cX[i], cY[j], cX[j]) <= 50 * 50 ) {
                G[i] ~= j;
                G[j] ~= i;
            }
        }
    }
}

struct S {
    int v, time;
}

void solve() {
    auto isInit = new bool[N];
    auto lastFinished = new int[N];
    lastFinished[] = int.min / 2;
    BinaryHeap!(Array!S, "a.time > b.time") PQ;
    foreach (i; 0 .. N) {
        //writeln(dist2(sY, sX, cY[i], cX[i]));
        if ( dist2(sY, sX, cY[i], cX[i]) <= 10 * 10 ) {
            PQ.insert(S(i, X));
            lastFinished[i] = X;
            isInit[i] = true;
        }
    }
    int Ans = 0;
    while (!PQ.empty) {
        S cur = PQ.front; PQ.removeFront;
        //writeln(cur);
        Ans = max(Ans, cur.time);
        foreach (next; G[cur.v]) {
            if (lastFinished[next] + Y >= cur.time) continue;
            if (isInit[next]) {
                writeln("You're always welcome!"); return;
            }
            lastFinished[next] = cur.time + X;
            PQ.insert(S(next, cur.time + X));
        }
    }
    writeln(Ans);
}

void main() {
    int T; scanf("%d\n", &T);
    foreach (t; 0 .. T) {
        input; solve;
    }
}

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

#define fi first
#define se second

const int N = 2020;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int d[N];
vector < int > v[N];

void bfs(int x, int y)
{
        for(int i = 1; i <= n; i++){
                d[i] = n + 1;
        }
        d[x] = d[y] = 0;
        queue < int > q;
        q.push(x);
        q.push(y);
        while(!q.empty()){
                x = q.front();
                q.pop();
                for(int y: v[x]){
                        if(d[x] + 1 < d[y]){
                                d[y] = d[x] + 1;
                                q.push(y);
                        }
                }
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        int k;
        cin >> n >> k;
        for(int i = 1; i < n; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        int res = n;
        for(int i = 1; i <= n; i++){
                for(int j: v[i]){
                        if(k % 2){
                                bfs(i, j);
                        } else{
                                bfs(i, i);
                        }
                        int cnt = 0;
                        for(int j = 1; j <= n; j++){
                                if(d[j] > k / 2){
                                        cnt += 1;
                                }
                        }
                        res = min(res, cnt);
                }
        }
        cout << res << "\n";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int N,K;cin>>N>>K;
    vl l(N);
    rep(i,N)cin>>l[i];
    sort(all(l));
    ll ans=0;
    rep(i,K)ans+=l[N-1-i];
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define ll long long 
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 10010;
static const ll INFTY = 1e12;
static const ll NUMMAX = 1000000007;
static const ll MOD = 1000000007;
 #define LOOP 10000000

int main() {

    ll A, B, K;


    cin >> A >> B >> K;

    if( (A + B) <= K  ){
        A = 0;
        B = 0;
    } else if( A <= K ){
        B -= ( K - A ); 
        A = 0;
    } else {
        A -= K;
    }

    cout << A << " " << B << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
/*bool isPrime(long long n) 
{ long long i;
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false;
  
    return true; 
}

long long factorial(long long n) 
{    if(n==0||n==1)
     return 1;
     else
     return n*factorial(n - 1);  
} 

long long binarySearch(long long arr[], long long l, long long r, long long x) 
{ 
    while (l <= r) { 
        long long  m = l + (r - l) / 2; 
  
        
        if (arr[m] == x) 
            return m; 
  
      
        if (arr[m] < x) 
            l = m + 1; 
  
       
        else
            r = m - 1; 
    } 
    return -1; 
} 
*/

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int i,l,r,d,c=0;
    cin>>l>>r>>d;
    for(i=l;i<=r;i++)
     { if(i%d==0)
        c++;
     }
    cout<<c<<endl;
    
    
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  double x, t;
  cin >> x >> t;

  cout << x / t << endl;
  return 0;
}



Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B
import Control.Arrow (second)

lowerBound :: Int -> V.Vector Int -> Int
lowerBound x xs = go (-1) (V.length xs) where
  go l r
    | l==r-1 = r
    | x<=(xs V.! m) = go l m
    | otherwise = go m r
    where m = (l+r)`div`2

inf = 1000000000

solv :: V.Vector Int -> Int -> Int
solv xs k = go inf rini (k-rini) where
  base = lowerBound 0 xs
  rini = min k base
  go m r l
    | r<0 || l+base>V.length xs = m
    | r==0 = go (min m ld) (r-1) (l+1)
    | l==0 = go (min m rd) (r-1) (l+1)
    | otherwise = go (min m (min (2*rd+ld) (rd+2*ld))) (r-1) (l+1)
    where
      rd = if r==0 then 0 else abs $ xs V.!(base-r)
      ld = if l==0 then 0 else abs $ xs V.!(base+l-1)

main = do
  [n,k] <- map (fst . (\(Just x) -> x) . B.readInt) . B.words <$> B.getLine
  xs <- V.unfoldrN n (fmap (second B.tail) . B.readInt) <$> B.getLine
  print $ solv xs k
  

Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/numeric/interval.hpp>
// #include <boost/numeric/interval/io.hpp>
// #include <boost/intrusive/rbtree.hpp>
// #include <boost/geometry.hpp>
// #include <boost/geometry/geometries/linestring.hpp>
// #include <boost/geometry/geometries/polygon.hpp>
// #include <boost/geometry/geometries/point_xy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace::std;
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cfloat;
// typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
#define MOD 1000000007
#define endl "\n"
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

int main(){
    lint n,k,q;
    cin>>n>>k>>q;
    vec v(n,0);
    rep(i,q){
        lint x;
        cin>>x;
        v[x-1]++;
    }
    rep(i,n){
        if(k+v[i]-q<=0)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d) cout<<"Left"<<endl;
	if(a+b<c+d) cout<<"Right"<<endl;
	if(a+b==c+d) cout<<"Balanced"<<endl;
	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

int main(void){
    ll t1,t2;
    ll a1,a2,b1,b2;
    cin>>t1>>t2>>a1>>a2>>b1>>b2;
    ll v1=b1-a1;
    ll v2=b2-a2;
    ll p=v1*t1;
    ll q=v2*t2;
    if(p+q==0)cout<<"infinity"<<endl;
    else{
        if(p<0){
            if(p+q<0)cout<<0<<endl;
            else{
                ll x=-p/(p+q);
                if((-p)%(p+q)==0)cout<<2*x<<endl;
                else cout<<2*x+1<<endl;
            }
        }
        else{
            if(p+q>0)cout<<0<<endl;
            else{
                ll x=-p/(p+q);
                if(p%(p+q)==0)cout<<2*x<<endl;
                else cout<<2*x+1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n), f(n);
    
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), [](ll x, ll y) {
        return x > y;
    });

    auto check = [&](ll x) {
        ll t = 0;

        REP(i, n) {
            t += max(0LL, a[i] - x / f[i]);
        }

        return t <= k;
    };

    ll l = -1, r = 1e18;
    while(r - l > 1) {
        ll m = (l + r) / 2;
        if (check(m)) {
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << endl;
    
    return 0;
}


Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		double[] arr = new double[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextDouble();
		}
		double r = solve(n, arr);
		System.out.println(r);
		in.close();

	}

	private static double solve(int n, double[] arr) {
		double[] dp = new double[n + 1];
		dp[0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = i; j >= 0; j--) {
				dp[j] = dp[j] * (1 - arr[i - 1]);
				if (j > 0) {
					dp[j] += dp[j - 1] * arr[i - 1];
				}
			}
		}
		double r = 0;
		for (int i = n; i > n - i; i--) {
			r += dp[i];
		}
		return r;
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  int k[M];
  int s[M][N];

  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < N; j++)
    {
      s[i][j] = 0;
    }
  }

  for (int i = 0; i < M; i++)
  {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++)
    {
      int S;
      cin >> S;
      s[i][S - 1] = 1;
    }
  }
  int p[M];
  for (int i = 0; i < M; i++)
  {
    cin >> p[i];
  }

  int ans = 0;

  int sw[N];
  int sum;
  for (int i = 0; i < (1 << N); i++)
  {
    for (int n = 0; n < N; n++)
    {
      sw[n] = (i >> n) & 1;
    }

    bool good = true;
    for (int m = 0; m < M; m++)
    {
      sum = 0;
      for (int n = 0; n < N; n++)
      {
        sum += s[m][n] * sw[n];
      }
      if (sum % 2 != p[m])
      {
        good = false;
        break;
      }
    }
    if (good)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256