akhauriyash/Code-Regression huggingface dataset:
import numpy as np
sho_ls = []
amari_ls = []
a_ls = []
for _ in range(5):
    a = int(input())
    a_ls.append(a)
    sho, amari = divmod(a,10)
    sho_ls.append(sho)
    amari_ls.append(amari)

amari_ls_not0 = []
for i in range(5):
    if amari_ls[i] != 0:
        amari_ls_not0.append(amari_ls[i])

if amari_ls != [0,0,0,0,0]:
    amari_min_not0 = min(amari_ls_not0)
    arg_min = amari_ls.index(amari_min_not0)
else:
    arg_min = 0
ans = 0
for i in range(5):
    if i != arg_min:
        if amari_ls[i] != 0:
            plus = a_ls[i] + 10 - amari_ls[i]
            ans += plus
            
        else:
            plus = a_ls[i]
            ans += plus
plus = a_ls[arg_min]
ans += plus
print(ans)

Measured memory_bytes: 12504
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int Ans,n;
#define Maxn 200010
int a[Maxn];
int sum0[Maxn],sum1[Maxn],tmp[Maxn];
ll sum[Maxn];
int main(){
	scanf("%d",&n);
	Ans=2*n;
	for(register int i=1;i<=n;++i){
	    scanf("%d",&a[i]);
	    sum0[i]=sum0[i-1];sum1[i]=sum1[i-1];
	    if(a[i]&1)sum0[i]++;
	    else{
			sum1[i]++;
			if(!a[i])sum0[i]+=2;
	    }
	    sum[i]=sum[i-1]+a[i];
	}
	for(register int i=n;i>=1;--i){
		tmp[i]=tmp[i+1];
		if(a[i]&1)tmp[i]++;
		else if(!a[i])tmp[i]+=2;
	}
	for(register int i=1;i<=n;++i)
	if(sum[i]<=2*n){
		sum0[i]=sum[i];
		int haha=0;
		if(a[i]&1)haha++;
		else if(!a[i])haha+=2;
		haha+=sum0[i-1];
		sum0[i]=min(sum0[i],haha); 
	}else{
		int haha=0;
		if(a[i]&1)haha++;
		else if(!a[i])haha+=2;
		sum0[i]=sum0[i-1]+haha;
	}
	for(register int i=n;i>=1;--i)
	if(sum[n]-sum[i-1]<=2*n){
		ll dd=sum[n]-sum[i-1];
		tmp[i]=dd;
		int gg=0;
		if(a[i]&1)gg++;
		else if(!a[i])gg+=2;
		gg+=tmp[i+1];
		tmp[i]=min(tmp[i],gg);
	//	cout<<"i "<<i<<" "<<tmp[i]<<endl;
	}else{
		int gg=0;
		if(a[i]&1)gg++;
		else if(!a[i])gg+=2;
		tmp[i]=tmp[i+1]+gg;
	}
	int zz=0,at=0;
	for(register int i=1;i<=n;++i){
		if(sum0[i]-sum1[i]<zz)at=i;
		zz=min(zz,sum0[i]-sum1[i]);
	//	cout<<sum1[i]<<" "<<at<<endl;
		Ans=min(Ans,sum1[i]+tmp[i+1]+zz);
	//	cout<<"i "<<i<<" "<<tmp[i]<<endl;
	//	cout<<"Ans "<<Ans<<endl;
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string str;
    getline(cin, str);
    for(int i=0; i<1200; i++)
    {
        if(str[i] == '\0') break;
        if((str[i] >= 'A') && (str[i] <= 'Z'))
            str[i] += 'a'-'A';
        else if((str[i] >= 'a') && (str[i] <= 'z'))
            str[i] += 'A'-'a';
    }
    cout << str << "\n";

    return 0;
}


Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    ll n, m, ans1 = 0, ans2 = 0;
    cin >> n >> m;
    vector<bool> ac(n);
    vector<ll> cnt(n);
    for(int i = 0; i < m; i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(ac[p]){
            continue;
        }
        if(s == "AC"){
            ac[p] = true;
            ans1++;
            ans2 += cnt[p];
        }else{
            cnt[p]++;
        }
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


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


int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x-r<0 || x+r>W || y-r<0 || y+r>H){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
   return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scanner= new Scanner(System.in);
        int N = scanner.nextInt();
        int m = 0;
        String s = String.valueOf(N);
        for(int i = 0; i < s.length(); i++){
            m += s.charAt(i) - '0';
        }
        if(N % m == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define db double
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353
 
const ll N=1e12;
 
int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}
 
ll solve(){
    
    return 0;
}
 
signed main(){
    IOS
// 	#ifndef ONLINE_JUDGE
//     	freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	#endif
    string s,p;
  cin>>s>>p;
  ll ans=1e12;
  rep(i,0,s.size()-p.size()+1){
    ll a=0;
    rep(j,0,p.size()){
      if(s[i+j]!=p[j])++a;
    }
    ans=min(a,ans);
  }
  cout<<ans;
    return 0;
}
// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <set> 
 
using namespace std;
 
#define int long long
#define val(x) cout << #x << " equals to " << x << endl
 
const int N = 2e6 + 7;
const int INF = 1e18;

int n, m, k, q, ans, a[N];
string s[N], t[N];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef LOCAL
        freopen("C:/Users/emrey/Code/in.txt", "r", stdin);
    #endif

    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    for (int i = 0; i < (1 << (n + m)); i++) {
        for (int j = 0; j < n; j++) {
            t[j] = s[j];
        }
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < m; k++)
                    t[j][k] = '.';
            }
        }
        for (int j = n; j < n + m; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < n; k++)
                    t[k][j - n] = '.';
            }
        }
        int cnt = 0;
        for (int x = 0; x < n; x++)
            for (int y = 0; y < m; y++)
                cnt += (t[x][y] == '#');
        ans += (cnt == k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 128652
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		br.close();

		if (n % 2 == 1) {
			System.out.println(0);
		} else {
			long ans = 0;
			for (long b = 10; b <= n; b *= 5) {
				ans += n / b;
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    int n,k;cin>>n>>k;
    vi v(n);cin>>v;
    for(int &i:v)i--;
    
    
    vi pos;
    int cur=0;
    
    for(int i=0;i<2*n;i++){
        pos.push_back(cur);
        cur=v[cur];
    }
    
    map<int,int> mp;
    
    int cycle=-1;
    int cnt=0;
    for(int i:pos){
        if(mp[i]){
            cycle=i;
            break;
        }
        cnt++;
        mp[i]=1;
    }
    
    // 0 1 2 3 4 5 6 7 8 9 10
    // 1 2 3 4 5 3 4 5 3 4 5    //8
    
    if(k+1<=cnt){
        cout<<pos[k]+1;
    }else{
        k-=cnt;
        map<int,int> mp;
        vi pp;
        int i=cycle;
        for(int j=0;j<2*n;j++){
            if(mp[i])break;
            mp[i]=1;
            pp.push_back(i);
            i=v[i];
        }
        //cout<<pos<<"\n";
        //cout<<pp<<"\n";
        cout<<pp[k%pp.size()]+1;
    }
    
}


Measured memory_bytes: 29252
h, n = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
dp = [0]*20001

for i in range(1, h + 1):
    ref = 10**10
    for a, b in l:
        temp = dp[i - a] + b
        ref = min(ref, temp)
    dp[i] = ref

print(dp[h])

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

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a+b);
    }
    else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a-b);
    }
    else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a*b);
    }
    else {
      push(atoi(s));
    }
  }

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

  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  if(N%1000==0) cout<<0<<endl;
  else cout << (N/1000+1)*(1000)-N << endl;
}

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

int a[2];
int main(){
  while(1){

    scanf("%d %d",&a[0],&a[1]);
    if(a[0] == 0&&a[1]==0)
      break;
    sort(a,a+2);
    printf("%d %d\n",a[0],a[1]);
  }
  return 0;
}

Measured memory_bytes: 1204
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,Time = MI()
    T=LI()
    ans = 0
    end = -1
    for t in T:
        if end < t:
            ans += Time
            end = t+Time
        else:
            ans += t+Time-end
            end = t + Time
    print(ans)
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 80060
import numpy as np
from scipy.sparse.csgraph import dijkstra
from collections import defaultdict

import sys
input = sys.stdin.readline

[H,W]= [int(x) for x in input().split()]
c=np.array([[int(x) for x in input().split()] for _ in range(10)])

A=[]
for _ in range(H):
  A+=[int(x) for x in input().split()] 

dd = defaultdict(int)
for key in A:
  if key!=1 and key!=-1:
    dd[key] += 1

res=0
scores=dijkstra(c.T,indices = 1).astype(int)
for k, v in dd.items():
  res+= v*scores[k]
print(res)

Measured memory_bytes: 14060
use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        n: usize,
        d: [(i32, i32, i32); n],
    }

    let mut dp = vec![[0, 0, 0]; n+1];
    for i in 0..n {
        for j in 0..3 {
            for k in 0..3 {
                if j == k {
                    continue;
                }
                if k == 0 {
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + d[i].0);
                } else if k == 1 {
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + d[i].1);
                } else {
                    dp[i+1][k] = max(dp[i+1][k], dp[i][j] + d[i].2);
                }
            }
        }
    }
    let res = max(max(dp[n][0], dp[n][1]), dp[n][2]);
    println!("{}", res);
}

Measured memory_bytes: 6396
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    int T = S.length();
    for(int i=0; i<T; i++){
    	if(i==0) {
    		S="";
    	}
    	S=S+"x";
    }
    System.out.println(S);
  }
}

Measured memory_bytes: 22100
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int ans = 0;
            if (A >= 13)
            {
                ans = B;
            }
            else if (A >= 6)
            {
                ans = B / 2;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  string S;
  cin>>N>>S;



  
  if(N%2==0&&S.substr(0,N/2)==S.substr(N/2,N/2)){
  cout<<"Yes"<<endl;
    return 0;
  }
  else{
  cout<<"No"<<endl;
    return 0;
  }

}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

const int mod=1e9+7;
inline int add(int x,int y)
{
  x+=y;
  if (x>=mod)
    return x-mod;
  return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if (x<0)
    return x+mod;
  return x;
}
inline int mul(int x,int y)
{
  return (x*1ll*y)%mod;
}
inline int power(int x,int y)
{
  int ans=1;
  while(y)
    {
      if (y&1) ans=mul(ans,x);
      x=mul(x,x);
      y>>=1;
    }
  return ans;
}
inline int inv(int x)
{
  return power(x,mod-2);
}
inline int gcd(int x, int y)
{
  return(y!=0)?gcd(y, x%y):x;
}
inline ll nPr(int n, int r)
{
  ll i,result=1;
  rep(i,r)
    {
      result*=(ll)(n-i);
    }
  return result;
}
inline ll nCr(int n,int r)
{
  ll i,result=1;
  rep(i,min(r,n-r))
    {
      result*=(ll)(n-i);
      result/=(ll)(i+1);
    }
  return result;
}
bool prime(int n)
{
  for (int i=2; i<n/2; i++)
    {
      if(n%i==0)
	return false;
    }
  return true;
}

/*------------CODE-----------*/

int main()
{
  IOS;
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans;
  if (a>=k)
    ans=k;
  else if (a+b>=k)
    ans=a;
  else
    ans=2*a+b-k;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3656
for i in range(int(input())):
    m, n = map(int, input().split())
    count = 0
    for p in range(142):
        for q in range(142):
            if p == q == 0:
                continue

            pq = p * p + q * q
            if pq > 20000:
                break

            if (m * p + n * q) % pq == 0 and (n * p - m * q) % pq == 0:
                count += 1

    if count < 5:
        print("P")
    else:
        print("C")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 

int main(){
	ll A,B,H;
    cin>>A>>B>>H;
    cout<<(A+B)*H/2;
    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

namespace io {
	#define isdigit(c)  (c >= '0' && c <= '9')
	#define getchar()   (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufsz, stdin), p1 == p2) ? EOF : *p1++)
	#define flush()     (fwrite(puf, 1, pp - puf, stdout), pp = puf)
	#define putchar(c)  (*pp++ = c, pp - puf == bufsz && flush())
	
	const int bufsz = 1 << 22;
	static char buf[bufsz], puf[bufsz], *p1, *p2, *pp = puf;
	struct flusher { ~flusher() { flush(); } } flusher;
	
	void inline read(int &a) {
		int c = getchar();
		for (; !isdigit(c); c = getchar());
		for (a = 0; isdigit(c); a *= 10, a += c & 15, c = getchar());
	}
	
	void inline write(int a, char c = ln) {
		static char d[20];
		int s = d[0] = 0;
		for (; a; d[s++] = a % 10, a /= 10);
		for (s || (s = 1); s; putchar(d[--s] + 48));
		putchar(c);
	}
}
using namespace io;

const int nsz = 2e5;
int n, a[nsz + 5], rt, lst, ans;
int ql, qr, q[2 * nsz + 5];

int sz, ls[nsz + 5], rs[nsz + 5], pri[nsz + 5], key[nsz + 5];

int inline node(int w) {
	int u = ++sz;
	key[u] = w, pri[u] = rand();
	return u;
}

int merge(int v1, int v2) {
	if (!v1 || !v2)  return v1 | v2;
	return pri[v1] < pri[v2] ? (rs[v1] = merge(rs[v1], v2), v1) : (ls[v2] = merge(v1, ls[v2]), v2);
}

void split(int u, int w, int &v1, int &v2) {
	if (!u) { v1 = v2 = 0; return; }
	key[u] <= w ? (v1 = u, split(rs[u], w, rs[u], v2)) : (v2 = u, split(ls[u], w, v1, ls[u]));
}

void inline push_back(int &rt, int w) { rt = merge(rt, node(w)); }

void inline pop_back(int &rt, int w) { split(rt, w - 1, rt, *new int); }

int inline mn(int u) {
	for (; ls[u]; u = ls[u]);
	return key[u];
}

int inline mx(int u) {
	for (; rs[u]; u = rs[u]);
	return key[u];
}

void inline init() {
	cont (i, n) {
		if (i == 1 || a[i] < a[i - 1])  ++qr;
		push_back(q[qr - 1], a[i]);
	}
	
	for (lst = n; mx(q[qr - 1]) == lst && lst; pop_back(q[qr - 1], lst--));
}

void inline deal() {
	for (++ans; !q[ql] && ql != qr; ++ql);
	
	int u = q[ql++], cur = mx(u), v1, v2;
	for (int k = ql; k != qr && cur != lst; ++k) {
		int d = mx(q[k]);
		if (d < cur)  continue;
		
		split(q[k], cur, v1, v2);
		q[k] = v1, u = merge(u, v2), cur = d;
		
		int &r1 = q[k - 1], &r2 = q[k];
		if (r1 && mx(r1) < mn(r2))  r2 = merge(r1, r2), r1 = 0;
	}
	
	int &r1 = q[qr - 1], &r2 = u;
	if (r1 && mx(r1) < mn(r2))  r2 = merge(r1, r2), r1 = 0;
	for (; mx(u) == lst && lst; pop_back(u, lst--));
	
	q[qr++] = u;
}

int main() {
	read(n);
	cont (i, n) {
		read(a[i]);
	}
	for (init(); lst; deal());
	write(ans);
}


Measured memory_bytes: 16768
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
cnt = 0

x = a[0]
cnt += b[a[0]-1]

for i in range(1,n):
        cnt += b[a[i]-1]
        if x == a[i] - 1:
                cnt += c[x - 1]
        x = a[i] 
print(cnt)

Measured memory_bytes: 3064
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>
 
typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;
 
#define N 524288
#define P 200003
 
constexpr ulli PRIME = 0xffffffff00000001;
constexpr ulli ntt_add(ulli a, ulli b)
{
    if(b>PRIME) b -= PRIME;
    ulli res = 0;
    bool f = __builtin_uaddll_overflow(a,b,&res);
    res -= -(ulli)f & PRIME;
    return res;
}
constexpr ulli ntt_sub(ulli a, ulli b)
{
    if(b>PRIME) b -= PRIME;
    ulli res = 0;
    bool f = __builtin_usubll_overflow(a,b,&res);
    res += -(ulli)f & PRIME;
    return res;
}
constexpr ulli ntt_mul(ulli a, ulli b)
{
    unsigned __int128 k = (unsigned __int128)a*b;
    ulli hh = k>>64>>32, hl = (uint)(k>>64), res = k;
    res = ntt_add(res,hl*-PRIME);
    res = ntt_sub(res,hh);
    return res;
}
constexpr ulli ntt_pow(ulli a, ulli b)
{
    ulli r = 1;
    while(b)
    {
        if(b&1) r = ntt_mul(r,a);
        a = ntt_mul(a,a);
        b >>= 1;
    }
    return r;
}
constexpr ulli ntt_find()
{
    ulli res = 2;
    while(ntt_pow(res,PRIME/2) != PRIME-1) ++res;
    return res;
}
constexpr ulli OMEGA = (ntt_pow(ntt_find(),PRIME/N));
static_assert(__builtin_popcount(N) == 1);
static_assert(PRIME%N == 1);
static_assert(ntt_pow(OMEGA,N/2) == PRIME-1);
uint ricr(uint k)
{
    k ^= (N-1);
    k ^= -1u >> 1 >> __builtin_clz(k);
    return k;
}
template <int n, ulli w>
void ntt_rec(ulli *a)
{
    constexpr int n2 = n/2;
    constexpr ulli w2 = ntt_pow(w,2);
    ntt_rec<n2, w2>(a);
 
    for(ulli *p=a; p!=a+N; p+=n)
    {
        ulli k = 1;
        for(int i=0,j=n2;i<n2;++i,++j)
        {
            ulli e = p[i], o = p[j];
            ulli ok = ntt_mul(o,k);
            p[i] = ntt_add(e,ok);
            p[j] = ntt_sub(e,ok);
            k = ntt_mul(k,w);
        }
    }
}
template <>
void ntt_rec<1, 1>(ulli *a)
{
}
 
template <ulli w=OMEGA>
void ntt(ulli *a)
{
    for(int i=0,ii=0;i<N;++i,ii=ricr(ii))
        if(i<ii) std::swap(a[i],a[ii]);
    ntt_rec<N,w>(a);
}
void ntt_inv(ulli *a)
{
    ntt<ntt_pow(OMEGA,PRIME-2)>(a);
    for(int i=0;i<N;++i) a[i] = ntt_mul(a[i],ntt_pow(N,PRIME-2));
}
 
int cnt[N];
ulli a[N];
 
int main()
{
    int n;
    lli ans = 0;
    scanf("%d", &n);
    for(int i=0;i<n;++i)
    {
        int k;
        scanf("%d", &k);
        ++cnt[k];
    }
    for(int i=0, k=1; i<P-1; ++i, k=k*2<P?k*2:k*2-P) a[i] = cnt[k];
    for(int i=0; i<P-1; ++i) cnt[i] = a[i];
    ntt(a);
    for(int i=0;i<N;++i) a[i] = ntt_mul(a[i],a[i]);
    ntt_inv(a);
    for(int i=0; i<P-1; ++i) a[i*2] = ntt_sub(a[i*2], cnt[i]);
    for(int i=0,k=1; i<N; ++i, k=k*2<P?k*2:k*2-P)
    {
        if(a[i] >= PRIME) a[i] -= PRIME;
        ans += k * a[i];
    }
    assert(ans%2==0);
    ans /= 2;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159265358979323846264
int main()
{
	int h,w,k;
	cin>>h>>w>>k;
	char mat[h][w];
	int b=0;
	//map<char,int> mr,mc;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>mat[i][j];
			if(mat[i][j]=='#'){
			b++;}
		}
	}
	int x=h;
	int y=w;
	int r=pow(2,x);
	int c=pow(2,y);
	int ans=0;
	if(b==k)
	ans++;
	for(int i=0;i<r;i++)
	{
		for(int j=0;j<c;j++)
		{
			if(i==0 && j==0)continue;
			int cnt=0;
			for(int p=0;p<h;p++)
			{
				if((i&(1<<p))!=0)continue;
				for(int q=0;q<w;q++)
				{
					if(mat[p][q]=='#' && (j&(1<<q))==0)
					{
					cnt++;}
				}
			}
			if(cnt==k){
			ans++;}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4092
#include<iostream>
#include<algorithm>
using namespace std;
#define mod 1000000007
typedef long long LL;
int main() {
	LL n,m;
	cin >> n >> m;
	LL ans = 0;
	LL a = min(n, m / 2);
	ans += a;
	n -= a;
	m -= 2 * a;
	ans += (m / 4);
	cout << ans << endl;
	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[] box = new int[n];
    int[] red = new int[n];
    for(int i = 0;i<n;i++){
      box[i] = 1;
    }
    red[0]++;
    for(int i = 0;i<m;i++){
      int x = sc.nextInt()-1,y = sc.nextInt()-1;
      if(red[x]==1)red[y]=1;
      box[x]--;
      box[y]++;
      if(box[x]==0){
        red[x]=0;
      }
    }
    int count = 0;
    for(int i:red){
      if(i == 1)count++;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 59416
#include <stdio.h>

int
main(int argc, char *argv[])
{
    unsigned long n, i, score_a, score_b;
    unsigned int a, b;

    while (1) {
        if (1 != scanf("%lu\n", &n)) {
            fprintf(stderr, "Invalid number of datasets at line 0.");
            return 1;
        }
        if (0 == n) {
            break;
        }

        score_a = 0, score_b = 0;
        for (i = 1; i <= n; i++) {
            if (2 != scanf("%u %u\n", &a, &b)) {
                fprintf(stderr, "Invalid data at line %lu.", i);
                continue;
            }
            if (a < b) {
                score_b += (a + b);
                continue;
            }
            if (b < a) {
                score_a += (a + b);
                continue;
            }
            score_a += a;
            score_b += b;
        }
        printf("%lu %lu\n", score_a, score_b);
    }

    return 0;
}

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

using namespace std;

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

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll l, r;
  cin >> l >> r;

  if (r - l >= 2019 || l % 2019 > r % 2019) {
    cout << 0 << endl;
  } else {
    ll ans = INF;
    for (ll i = l; i <= r - 1; i++) {
      for (ll j = i + 1; j <= r; j++) {
        chmin(ans, i * j % 2019);
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import math
n,d = (int(i) for i in input().split()) 
x = []
for i in range(n):
    x.append([int(i) for i in input().split()])
c = 0
for i in range(n):
    for j in range(n):
        if i>=j :
            continue
        dis = 0.0
        for k in range(d):
            dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
        dis = math.sqrt(dis)
        if dis.is_integer():
            c+=1
print(c)

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

using namespace std;

typedef pair<int, int> P;

vector<P> data(2 * (1 << 20)); 

int n;

void init(int k, int l, int r) {
	data[k].first = l;
	data[k].second = 0;
	if (r-l == 1) {
	} else {
		int chl = k*2+1;
		int chr = k*2+2;
		init(chl, l, (l+r)/2);
		init(chr, (l+r)/2, r);
	}
}

void update(int k, int a) {
	k += (1 << 20)-1;
	data[k].second += a;
	while (k > 0) {
		k = (k-1)/2;
		if (data[k*2+1].second >= data[k*2+2].second) {
			data[k].first = data[k*2+1].first;
			data[k].second = data[k*2+1].second;
 		} else {
			data[k].first = data[k*2+2].first;
			data[k].second = data[k*2+2].second;
		}
	}
}

int main() {
	int q;
	cin >> n >> q;
	int a, v;
	init(0, 0, (1 << 20));
	for (int i = 0; i < q; i++) {
		cin >> a >> v;
		update(a-1, v);
		cout << data[0].first+1 << ' ' << data[0].second << endl;
	}
	return 0;
}

Measured memory_bytes: 17432
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool judge = true;
    for(int i = 0;i < s.size();i++){
        if(i % 2 == 0){
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
            else{
                judge = false;
                break;
            }
        }else{
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
            else{
                judge = false;
                break;
            }
        }
    }
    if(judge)cout << "Yes" << endl;
    else cout << "No" << endl;
    //cin >> s;
}

Measured memory_bytes: 256
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<cstdio>
#include<set>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define per(i,a,b) for(long long int i=a;i<=b;++i)
#define rep(i,a,b) for(long long int i=a;i>=b;--i)
#define inf 0xf3f3f3f
#define ll long long 
using namespace std;
int w[1005],val[1005];
int dp[50005];
int main()
{
    int t,m,minn=inf;
    scanf("%d%d",&t,&m);
    per(i,1,50005) dp[i]=inf;
    for(int i=1;i<=m;i++) scanf("%d%d",&w[i],&val[i]);
    per(i,1,m){
    	per(j,w[i],20000){
    		dp[j]=min(dp[j],dp[j-w[i]]+val[i]);
		}
	}
	per(i,t,t+20000){
		minn=min(minn,dp[i]);
	}
    cout<<minn;
    return 0;
}

Measured memory_bytes: 384
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    s = sum(A) % MOD
    ans = 0

    for x in A:
        s = s - x
        s %= MOD
        ans += s * x
        ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()


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

class MyDictionary
{
    private string[] keys;
    private int[] value;
    public MyDictionary()
    {
        keys = new string[10000000];
        value = new int[10000000];
        for (int i = 0; i < 10000000; i++) value[i] = 0;
    }
    private int ConvertChar(char c)
    {
        return (c == 'A')? 1:
               (c == 'C')? 2:
               (c == 'G')? 3:
               (c == 'T')? 4: 0;
    }
    private int CalcHash(string str)
    {
        int res = 0;
        int temp = 1;
        for (int i = 0; i < str.Length; i++)
        {
            res += ConvertChar(str[i]) * temp;
            temp *= 5;
        }
        return res;
    }
    public void Insert(string str)
    {
        int idx = CalcHash(str);
        keys[idx] = str;
        value[idx] = 1;
    }
    public void Find(string str)
    {
        int idx = CalcHash(str);
        Console.WriteLine((value[idx] == 1)? "yes": "no");
    }
}

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        MyDictionary md = new MyDictionary();
        for (int i = 0; i < n; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            if (s[0] == "insert")
            {
                md.Insert(s[1]);
            }
            if (s[0] == "find")
            {
                md.Find(s[1]);
            }
        }
    }
}


Measured memory_bytes: 152932
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
from fractions import gcd

NN = 202020
MOD = 10**9+7
INF = float("inf")

n = int(input())
testi = defaultdict(dict)
for i in range(n):
    m = int(input())
    for j in range(m):
        x, y = map(int, input().split())
        testi[i][x-1] = y

# print(testi)
max_honest = 0
for num in range(1 << n):
    valid = True
    for p in range(n):
        if num >> p & 1:
            for k, v in testi[p].items():
                # print(num, p, k, v)
                if v ^ ((num >> k) & 1):
                    valid = False
                    break
        if not valid:
            break

    if valid:
        # print(bin(num)[2:])
        max_honest = max(max_honest, bin(num)[2:].count("1"))

print(max_honest)


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

#define ll long long

using namespace std;

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

    vector<int> a(n);

    int d, tmp;
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> tmp;
            a[tmp - 1] = 1;
        }
    }

    cout << count(a.begin(), a.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 3632
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int res1 = a * x + b * y;
  int res2 = min(x, y) * c * 2;
    if(x > y) res2 += a * (x-y);
    else res2 += b *= (y-x);
  int res3 = max(x, y) * c * 2;

  cout << min({res1, res2, res3}) << endl;
  return 0;
}

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



int main(){
  ll n,m;
  cin>>n >>m;
  ll ans=0;
  vector<pair<ll,ll>> p(n);
    for(int i=0;i<n;i++){
    long long  a,b;
    cin >> a >> b;
    p[i] = make_pair(a,b);
  }
  sort(p.begin(),p.end());

  rep(i,n){
    if(m>p[i].second){
      m-=p[i].second;
      ans+=p[i].first*p[i].second;
      }else{
        ans+=m*p[i].first;
        break;
      }
  }
  cout << ans << endl;
}

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

int main(){
  int H,W,N;
  cin >> H >> W >> N;
  map<pair<int,int>,int> m;
  for (int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    for (int i=-1;i<=1;i++){
      for (int j=-1;j<=1;j++){
        int na=a+i,nb=b+j;
        if (0<na&&na<H-1&&0<nb&&nb<W-1){
          m[make_pair(na,nb)]++;
        }
      }
    }
  }
  vector<long long> count(10,0);
  for (auto x:m){
    count[x.second]++;
  }
  count[0]=(long long)(H-2)*(W-2)-m.size();
  for (int i=0;i<10;i++){
    cout << count[i] << endl;
  }
}

Measured memory_bytes: 56448
#include <stdio.h>

int main(void)
{
  int n, i;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    int a, b, c;
    int s;

    scanf("%d %d %d", &a, &b, &c);
    a *= a;
    b *= b;
    c *= c;
    s = a + b + c;
    if (s == 2 * a || s == 2 * b || s == 2 * c) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }
  return (0);
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define ll              long long int
#define int             int64_t
#define ff              first
#define ss              second
#define pb              push_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define en              cout<<endl
using namespace std;
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}
void system_output(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
}
void solve(){
       int n;cin>>n;
       vector<int>a(n);
       map<int,int>mp;
       int pairs = 0;
       for(int  i =0;i<n;i++)
        {
			 cin>>a[i];
			 if(mp.find(i-a[i])!=mp.end())
			   pairs+=mp[(i - a[i])];
			 mp[(a[i]+i)]++;	
		}
       cout<<pairs<<endl;
            
}
signed main(void)
{
      fast();
      //w(t)
      solve();

}


Measured memory_bytes: 17136
import java.util.*;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();


    if ((a == b  && a != c) || (b == c  && a != c) || (a == c  && a != b)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}


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

const int MAX=100000;

int parent(int i){ return i/2; }
int left(int i){ return 2*i; }
int right(int i){ return 2*i+1; }

int main(void){
    int n; cin >> n;
    int A[n+1];
    for(int i=1; i<=n; i++) cin >> A[i];

    for(int i=1; i<=n; i++){
        printf("node %d: key = %d, ", i, A[i]);
        if(parent(i)>=1) printf("parent key = %d, ", A[parent(i)]);
        if(left(i)<=n) printf("left key = %d, ", A[left(i)]);
        if(right(i)<=n) printf("right key = %d, ", A[right(i)]);
        printf("\n");
    }
}


Measured memory_bytes: 3188
from sys import stdin
from collections import Counter
h,w,k = map(int,stdin.readline().split())
bl = 0
arr = [list(stdin.readline()) for _ in range(h)]
row = Counter()
col = Counter()
for i in range(h):
    for j in range(w):
        if arr[i][j] == '#':
            bl += 1
            row[i] += 1
            col[j] += 1
ans = 0
for i in range(2**h):
    for j in range(2**w):
        x,y = bin(i)[2:],bin(j)[2:]
        val = bl
        for bit in range(len(x)-1,-1,-1):
            if x[bit] == '1':
                val -= row[len(x)-1-bit]
                for bit1 in range(len(y)-1,-1,-1):
                    if y[bit1] == '1':
                        val += (arr[len(x)-1-bit][len(y)-1-bit1]=='#')
        for bit in range(len(y)-1,-1,-1):
            if y[bit] == '1':
                val -= col[len(y)-1-bit]
        if val==k:
            ans += 1
print(ans)

Measured memory_bytes: 69228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (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 fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl

int N, A, B, C;
std::vector<long long> l(9);

int dfs(int current, int a, int b, int c) {
  if (N == current) {
    if (min(a,min(b, c)) > 0) {
      return abs(A - a) + abs(B - b) + abs(C - c) - 30;
    } else {
      return INT_MAX;
    }
  }

  int ret1 = dfs(current + 1, a, b, c);
  int ret2 = dfs(current + 1, a + l.at(current), b, c) + 10;
  int ret3 = dfs(current + 1, a, b + l.at(current), c) + 10;
  int ret4 = dfs(current + 1, a, b, c + l.at(current)) + 10;

  // dv("ret1", ret1);
  // dv("ret2", ret2);
  // dv("ret3", ret3);
  // dv("ret4", ret4);
  // dv("min", min(min(ret1, ret2), min(ret3, ret4)));
  return min(min(ret1, ret2), min(ret3, ret4));
}

signed main(){
  scanf("%lld",&N);
  scanf("%lld",&A);
  scanf("%lld",&B);
  scanf("%lld",&C);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&l[i]);
  }
  cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	

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

		int i,j,x,c;
		double max=0.0;
		int tn=sc.nextInt();
		Integer [] tc= new Integer [tn];
		
		int  pv=sc.nextInt();
		int  tv=sc.nextInt();
		int  pc=sc.nextInt();
		
		for(i=0;i<tn;i++){
			tc[i]=sc.nextInt();
		}
		
		Arrays.sort(tc, Collections.reverseOrder());
		
		c=0;
		
		for(i=0;i<tn;i++){
			if(i==0) max=pc;
			if(max/(pv+c*tv) < ((max+tc[i])/(pv+(c+1)*tv))){
				max=max+tc[i];
				c++;
			}
		}
		
		System.out.printf("%d\n",(int)max/(pv+c*tv));
		sc.close();
		System.exit(0);
	}
}

Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
using Graph = vector< vector<int> >;
bool seen[200010];
long long ct[200010];
long long dist[200010];
void dfs(int v,Graph &G);
int main(){
    int n,q; cin >> n >> q;
    Graph G(n);
    for(int i=0;i<n-1;++i){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<q;++i){
        int p,x; cin >> p >> x;
        p--;
        ct[p] += x;
    }
        dfs(0,G);
    
    
    for(int i=0;i<n;++i){
        cout << dist[i] << ' ';
    }
    cout << endl;
    return 0;
}

void dfs(int v,Graph &G){
    seen[v] = true;
    dist[v] += ct[v];
    for(auto nv : G[v]){
        if(seen[nv]) continue;
        dist[nv] += dist[v];
        dfs(nv,G);
    }
}

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

using namespace std;


int main() {
    int D,G; cin >> D >> G;
    vector<int> p(D), c(D);
    for(int i=0;i<D;i++) {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;

    for(int i=0;i<(1<<D);i++) {
        int count = 0;
        int score = 0;
        vector<int> res;
        for(int j=0;j<D;j++) {
            if(((i>>j)&1)==0) {
                res.insert(res.begin(), j);
                continue;
            }
            count += p[j];
            score += 100*(j+1)*p[j] + c[j];
        }
        for(auto r : res) {
            for(int k=0;k<p[r]-1;k++) {
                if(score >= G) break;
                count++;
                score += 100*(r+1);
            }
        }
        if(score >= G) ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String[] r = s.split("");
		int c =0;

		for(int i = 0;i<n-1;i++) {
	
			if(r[i].equals(r[i+1])){
				r[i] = r[i].replace(r[i],"");
			}
		}
		
		for(int i = 0;i<n;i++) {
			if(!(r[i].equals(""))) {
				c++;
			}
		}
		


		

		System.out.println(c);
 
		sc.close();
	}
}

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

def f(a,b):
    return max(len(str(a)), len(str(b)))

ans = 10**10
i = 1
while i*i <= n:
    
    if n%i==0:
        ans = min(ans, f(i, n//i))
        
    i+=1
    
print(ans)

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

int main() {
    int n;
    double t, a;
    cin >> n >> t >> a;
    int index = -1;
    double mn = 1001001001001;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        if (mn > abs(t - 0.006 * h - a)) {
            index = i + 1;
            mn = abs(t - 0.006 * h - a);
        }
    }
    cout << index << endl;
}


Measured memory_bytes: 256
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

int n, m, k;

int main() {
  scanf("%d %d %d",&n,&m,&k);
  REP(x, n + 1) {
    REP(y, m + 1) {
      if (x * m + y * n - 2 * x * y == k) {
        puts("Yes");
        return 0;
      }
    }
  }

  puts("No");
  return 0;
}


Measured memory_bytes: 888
S = list(input())
T = list(input())

direct_graph1 = {}
direct_graph2 = {}
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
for i in list(ascii_lowercase):
    direct_graph1[i] = None
    direct_graph2[i] = None

flg = 0
for s,t in zip(S,T):
    if direct_graph1[s] == None or direct_graph1[s] == t:
        direct_graph1[s] = t
    else:
        flg =1
    
    if direct_graph2[t] == None or direct_graph2[t] == s:
        direct_graph2[t] = s
    else:
        flg = 1

    if flg == 1:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 6704
# -*- coding: utf-8 -*-
import copy

# input
N = int(input())
A = list()
for _ in range(N):
    A.append(int(input()))

# solve & output
ans = copy.copy(A)
ans.sort()
m = ans[-1]
for i in range(N):
    if A[i] != m:
        print(m)
    else:
        print(ans[N - 2])

Measured memory_bytes: 14560