akhauriyash/Code-Regression huggingface dataset:
object Main extends App {

  val n = io.StdIn.readLine().toInt
  val nums = io.StdIn.readLine().split(' ').map(_.toInt)
  calc(nums)

  def calc(nums: Array[Int], cnt: Int = 0): Array[Int] = {
    val t = for (x <- nums) yield {
      if (x % 2 != 0) {
        println(cnt)
        sys.exit
      }
      x / 2
    }
    calc(t, cnt + 1)
  }

}

Measured memory_bytes: 25540
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, x = MAP()
a = LIST()
ans = max(0, a[0]-x)
a[0] = min(a[0], x)

for i in range(1, N):
	if x < a[i-1] + a[i]:
		ans += (a[i] + a[i-1] - x)
		a[i] = x - a[i-1]

print(ans)

Measured memory_bytes: 16220
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m = nm()
    a = nl()

    if sum(a) > n:
        print(-1)
    else:
        print(n - sum(a))


if __name__ == '__main__':
    main()

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

int N,M;
int WA[105000]; // array storing # of incorrect, problem # is index
bool AC[105000]; // array to keep track of which problem # have been solved

void solve() {
    cin >> N >> M; // N problems and M submissions
    int WAnum = 0;
    int ACnum = 0;
    for(int i=1;i<=N;i++) { // initially setting everything
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S; // taking inputs problem # and submission result
        if(AC[p]) continue; // if problem # has already been ACed then skip
        if(S=="AC") { // first time AC
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        }
        else if(S=="WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

string S;

int main() {
    cin >> S;

    int ans = 0;
    int now = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'R') {
            now++;
        }
        else {
            ans = max(ans, now);
            now = 0;
        }
    }

    ans = max(ans, now);
    now = 0;

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


Measured memory_bytes: 3648
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    int[][] T;
    T.length = N;
    foreach (_; 0..N-1) {
        auto ab = readln.split.to!(int[]);
        T[ab[0]-1] ~= ab[1]-1;
        T[ab[1]-1] ~= ab[0]-1;
    }
    int[3] ns;
    foreach (i; 1..N+1) ++ns[i%3];

    auto cs = new int[](N);
    int o, t;
    void put(int i, int p, int c) {
        cs[i] = c;
        if (c == 1) ++o; else ++t;
        foreach (j; T[i]) if (j != p) put(j, i, c == 1 ? 2 : 1);
    }
    put(0, -1, 1);

    if (o <= ns[0] + ns[1] && t <= ns[0] + ns[2]) {
        o = 1; t = 2;
        auto r = 3;
        foreach (i; 0..N) {
            if (cs[i] == 1) {
                if (o <= N) {
                    cs[i] = o;
                    o += 3;
                } else {
                    cs[i] = r;
                    r += 3;
                }
            } else {
                if (t <= N) {
                    cs[i] = t;
                    t += 3;
                } else {
                    cs[i] = r;
                    r += 3;
                }
            }
        }
    } else {
        auto m = o > t ? 1 : 2;
        o = 1; t = 2;
        auto r = 3;
        foreach (i; 0..N) {
            if (cs[i] == m) {
                if (o <= N) {
                    cs[i] = o;
                    o += 3;
                } else if (t <= N) {
                    cs[i] = t;
                    t += 3;
                } else {
                    cs[i] = r;
                    r += 3;
                }
            } else {
                cs[i] = r;
                r += 3;
            }
        }
    }

    writeln(cs.to!(string[]).join(" "));
}

Measured memory_bytes: 32124
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, D, c{}; cin >> N >> D;
  int X[N][D]; for (int i{}; i < N; ++i) for (int &x : X[i]) cin >> x;
  for (int i{}; i < N; ++i) for (int j{i + 1}; j < N; ++j)
    {int d{}, n{}; for (int k{}, t; k < D; ++k) t = X[i][k] - X[j][k], d += t * t;
    while (n * n < d) ++n; if (n * n == d) ++c;}
  cout << c;}

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a*b,c) << endl;



    return 0;
}


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

typedef long long ll;
const int N = 2e5 + 7;

int n;
int a[N];
set<pair<int, int> > st;
int now;

void add(int ind, int c)
{
	if (!st.empty() && st.rbegin()->second == c)
		return;
	st.insert({ind, c});
}

void remove(int len)
{
	while (!st.empty() && st.rbegin()->first >= len)
		st.erase(*st.rbegin());
}

bool incone(int len)
{
	if (st.empty())
		return false;
	int val = st.rbegin()->second;
	if (st.rbegin()->first == len-1)
		st.erase(*st.rbegin());
	if (st.empty() || st.rbegin()->second != val + 1)
		st.insert({len-1, val + 1});
	return true;
}

bool inc(int len, int x)
{
	if (st.empty())
		return false;
	bool ok = true;
	if (st.rbegin()->second == x-1)
	{
		int ind = st.rbegin()->first;
		st.erase(*st.rbegin());
		ok &= incone(ind);
		st.insert({ind, 0});
	}
	else
		ok &= incone(len);
	return ok;
}

bool valid(int m)
{
	now = 0;
	st.clear();
	bool ok = true;
	for (int i=0; i<n; i++)
	{
		if (a[i] > now)
			add(now, 0);
		else
		{
			remove(a[i]);
			ok &= inc(a[i], m);
		}
		if (!ok)
			break;
		now = a[i];
	}
	return ok;
}

int main()
{
	ios::sync_with_stdio(false);

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

	int l = 0, r = n;
	while (r - l > 1)
	{
		int mid = (l + r) / 2;
		if (valid(mid))
			r = mid;
		else
			l = mid;
	}
	cout << r << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

bool b[1000009], c[1000009];

int n;
int a[1000009];

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

    vector<ll> p;

    b[0] = b[1] = 1;
    FOR(i, 2, 1000009)
    if(!b[i]) {
        for(int j = i + i; j < 1000009; j += i)
            b[j] = 1;
        p.push_back(i);
    }

    cin >> n;
    int g = 0;
    bool pai = true;
    rep(i, n) {
        cin >> a[i];
        g = gcd(g, a[i]);
        if(pai) {
            if(!b[a[i]]) {
                if(c[a[i]]) pai = false;
                c[a[i]] = true;
            }
            for(int j = 0; p[j] * p[j] <= a[i]; j++) {
                if(a[i] % p[j] == 0) {
                    if(c[p[j]] || c[a[i] / p[j]]) {
                        pai = false;
                    }
                    c[p[j]] = c[a[i] / p[j]] = 1;
                }
            }
        }
    }

    if(pai) {
        cout << "pairwise coprime\n";
        return 0;
    }

    if(g == 1)
        cout << "setwise coprime\n";
    else
        cout << "not coprime\n";

    return 0;
}

Measured memory_bytes: 8928
import sys
input = sys.stdin.readline
N,Q =map(int,input().split())
bond = [[]for _ in range(N)]
for i in range(N-1):
    a,b = [int(i)-1 for i in input().split()]
    bond[a].append(b)
    bond[b].append(a)

qlis = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    qlis[p-1] += x

stat = [True]*N
stat[0] =False
que =[]
for i in bond[0]:
    que.append([0,i])

for _ in range(N-1):
    ue,sita = que.pop()
    if stat[sita]:
        for i in bond[sita]:
            if stat[i]:
                que.append([sita,i])
        qlis[sita] += qlis[ue]
    stat[sita] = False
anstr = " ".join([str(i)for i in qlis])
print(anstr)


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

int main(){
  int a, b;
  cin >> a >> b;

  if ((a+b)%2) cout << "IMPOSSIBLE";
  else cout << (a+b)/2; 
  //cout << flag1 << " " << flag2 << " " << flag3 << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
a -= 1
from fractions import gcd
divac = a // c
divad = a // d
divbc = b // c
divbd = b // d
divacd = a // (c*d//gcd(c,d))
divbcd = b // (c*d//gcd(c,d))
Acd = divac + divad - divacd
Bcd = divbc + divbd - divbcd
wareru = Bcd - Acd
ans = b-a-wareru
print(ans)


Measured memory_bytes: 5076
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

h,w = miinps()
ans = 0
k = w%2
l = w//2
p = h//2
q = h%2

if h == 1:
  print(1)
  exit()
if w == 1:
  print(1)
  exit()
if k == 1:
  ans += (h*l)
  if q == 1:
    ans += (p+1)
  else:
    ans += p
else:
  ans += (h*l)

print(ans)

Measured memory_bytes: 3064
N = int(input())
l1 = [int(i) for i in input().split(" ")]
l2 = [int(i) for i in input().split(" ")]
l1_sum = l1[0]
l2_sum = sum(l2)
Max = l1_sum + l2_sum
for i in range(1,N):
    l1_sum += l1[i]
    l2_sum -= l2[i-1]
    if Max<l1_sum+l2_sum:
        Max = l1_sum+l2_sum
print(Max)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max=max(a)

check = [0]*(a_max+1)

for i in a:
    if check[i] != 0:
        check[i] = 2
        continue
    if check[i] == 0:
        check[i] = 1
        for j in range(1,a_max//i):
            check[(j+1)*i] = 2

print(check.count(1))

Measured memory_bytes: 32300
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int lim=1005,mm=1000000007;
int i,j,k,n,m,l1,l2,r1,r2,c[1101][1101],f[1101][1101],fac[1101],faci[1101];
ll pw(ll b,ll p){
	ll res=1;
	for (;p;p>>=1,b=b*b%mm)
	 if (p&1) res=res*b%mm;
	return res;
}
ll work(ll n,ll m,ll x){
	ll res=1,i;
	for (i=1;i<=x;i++) res=res*c[n-(i-1)*m][m]%mm;
	return res*faci[x]%mm;
}
int main(){
	for (i=0;i<=lim;i++)
	 for (c[i][0]=c[i][i]=1,j=1;j<i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mm;
	for (i=1,fac[0]=faci[0]=1;i<=lim;i++) fac[i]=fac[i-1]*(ll)i%mm,faci[i]=pw(fac[i],mm-2);
	while (scanf("%d%d%d%d%d",&n,&l1,&r1,&l2,&r2)!=EOF){
		memset(f,0,sizeof(f));
		f[l1-1][0]=1;
		for (i=l1;i<=r1;i++){
			for (j=0;j<=n;j++) f[i][j]=f[i-1][j];
			for (j=l2;j<=r2;j++)
			 for (k=0;k<=n-i*j;k++)
			  f[i][k+i*j]=(f[i][k+i*j]+(ll)f[i-1][k]*work(n-k,i,j)%mm)%mm;
		}
		printf("%d\n",f[r1][n]);
	}
	return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n)cin>>a[i];

  ll t = a[0];
  rep(i,n){
    t = gcd(t,a[i]);
  }
  print(t);
  return 0;
}

Measured memory_bytes: 1024
class Map
  def initialize(x,y,number,move)
    @x = x
    @y = y
    @move = move
    @number = number
  end
  attr_accessor :x,:y,:move,:number
  def +(map)
    x = self.x + map.x
    y = self.y + map.y
    m = self.move
    n = self.number + 1
    tmp = Map.new(x,y,n,m)
  end
end
@b = []
@b << Map.new(1,0, 1,0) #sita
@b << Map.new(0,1, 1,1) #migi
@b << Map.new(1,-1,1,2) #hidarisita
@b << Map.new(-1,1,1,3) #migiue

def work(map,m)
  n=m-1
  if map.move==3 && map.x!=0 && map.y!=n then
    return map+@b[3]
  elsif map.move==2 && map.y!=0 && map.x!=n then
    return map+@b[2]
  elsif (map.move==3&&map.x==0)||(map.move==2&&map.x==n) then
    if map.move==3 then
      move = 2
    else
      move = 3
    end
    temp = map + @b[1]
    temp.move = move
    if map.y==n then
      temp.move = 2
      temp.x = 1
      temp.y = n
      return temp
    else
      return temp
    end
  else
    if map.move==3 then
      move = 2
    else
      move = 3
    end
    temp = map + @b[0]
    temp.move = move
    return temp
  end
end
$m = Map.new(0,0,1,2)
$n = 3
def w(m,n)
  return work( m, n )
end
$COU = 0
def printmap(n)
  $COU = $COU + 1
  puts "Case %d:" % $COU
  c=[$m]
  i=1
  while i<n*n
    c << w(c[i-1],n)
    i = i+1
  end
  i=0
  while i < n
    for mapp in c do
      if mapp.y==i then
        print "%3d" % mapp.number
      end
    end
    puts
  i=i+1
  end
end
while true
  a = gets.to_i
  if a==0 then
    break
  end
  printmap(a)
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n;std::cin>>n;
    longlong x=2,y=1;
    for(int i=1;i<n;i++){
        std::tie(x,y)=std::make_pair(y,x+y);
    }
    std::cout<<y<<std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

const int INF=2000000000;

int main(){
    int n,h,t[100],ansa=0,ansb=0;
    char s[100][16],in[2];
    
    scanf("%d%d",&n,&h);
    
    for(int i=0;i<n;i++){
        scanf("%s%d",s[i],&t[i]);
    }
    
    for(int i=0;i<n;i++){
        
        for(int j=0;j<s[i][j]!='\0';j++){
            printf("? %s\n",s[i]);
            fflush(stdout);
            
            scanf("%s",in);
            ansa++;
            
            if(in[0]==s[i][j] || in[0]==s[i][j]+0x20){
                s[i][j]='_';
                ansb++;
            }else{
                t[i]--;
                j--;
            }
            
            if(t[i]<0){
                h--;
                break;
            }
        }
        
        if(h==0){
            printf("! Game Over\n");
            fflush(stdout);
            return 0;
        }
        
    }
    
    printf("! Game Clear %.1lf\n",(int)(ansb*1000.0/ansa)/10.0);
    fflush(stdout);
    
    return 0;
}

Measured memory_bytes: 1300
N = gets.to_i
A = gets.split.map(&:to_i).sort

b = Array.new((10 ** 6) + 1, 0)

A.each do |a|
  if b[a] == 2
    next
  end
  a.step(10 ** 6, a) do |i|
    b[i] += 1
  end
end

puts A.select {|a| b[a] == 1 }.size

Measured memory_bytes: 38424
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX=101;
const int INF=(1<<21);

int main(){

  int n,k;
  int zero_one;
  int a,b;
  int c,d,e;
  int w_f[MAX][MAX];

  

  while(cin>> n>> k){
    if(n==0&&k==0) break;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	w_f[i][j]=INF;
      }
      w_f[i][i]=0;
    }
    
    for(int i=0;i<k;i++){
    cin>> zero_one;
    if(zero_one==1){
      cin>> c>> d>> e;
      if(w_f[c-1][d-1]>e){
	w_f[c-1][d-1]=e;
	w_f[d-1][c-1]=e;
	for(int j=0;j<n;j++){
	  for(int k=0;k<n;k++){
	    for(int l=0;l<n;l++){
	      w_f[j][k]=w_f[k][j]=min(w_f[j][k],w_f[j][l]+w_f[l][k]);
	  }
	  }
	}
      }
    } else {
      cin>> a>> b;
      if(w_f[a-1][b-1]==1<<21){
	cout<< "-1"<< endl;
      } else {
	cout<< w_f[a-1][b-1]<< endl;
      }
    }
    }
  }
}

Measured memory_bytes: 1204
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

const ll INF = 1e18;

bool srt (P a, P b) {
    return a.first + a.second < b.first + b.second;
}

int main () {
    int n; cin >> n;
    V<P> v(n);
    rep(i, n) cin >> v[i].first >> v[i].second;
    sort(all(v), srt);
    V<V<ll>> dp(n+1, V<ll> (n+1, INF));//dp[i][j]:iまでみてj人選ぶ時のpの総和のmin
    dp[0][0] = 0;
    rep(i, n) {
        dp[i+1][0] = 0;
        for (int j = 0; j <= i; j++) {
            chmin(dp[i+1][j+1], dp[i][j+1]);
            if (dp[i][j] <= v[i].first) chmin(dp[i+1][j+1], dp[i][j] + v[i].second);
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (dp[n][i] != INF) ans = i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 198848
import numpy as np
k = int(input())
D = {}
for a in range(1, k + 1):
    for b in range(1, k + 1):
        try:
            D[np.gcd(a, b)] += 1
        except:
            D[np.gcd(a, b)] = 1
ans = 0
for c in range(1, k + 1):
    for key, cnt in D.items():
        ans += cnt * np.gcd(c, key)
print(ans)


Measured memory_bytes: 27116
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int N=scan.nextInt();
    int l=1;
    int h=N;
    int l_tmp=1;
    int h_tmp=N;
    while(h-l>1){
      if(l*h<N){
        while(l*h<N){
          l++;
        }
      }
      if(l*h>N){
        while(l*h>N){
          h--;
        }
      }
      if(l*h==N){
        l_tmp=l;
        h_tmp=h;
        l++;
        h--;
      }
    }
  
    if(l_tmp<=9&&h_tmp<=9){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
ll mod = 1000000007;


int main()
{
	// 入力
	ll N, M;
	ll C;
	cin >> N >> M >> C;

	mat A(M, vec(N, -1));
	vec B(M);

	REP(i, M) {
		cin >> B[i];
	}

	REP(i, N) {
		REP(j, M) {
			cin >> A[j][i];
		}
	}

	ll ans = 0;
	REP(i, N) {
		ll res = 0;
		REP(j, M) {
			res += B[j] * A[j][i];
		}
		res += C;
		// debug(res);
		if (res > 0) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, M;
    cin >> N >> M;
    pair<ll, ll> ans;
    if(N&1){
        repe(i,1,M+1){
            cout << i << " " << N - i + 1 << '\n';
        }
    }
    else{
        ll t = (N / 2 + 1) / 2;
        if ((N / 2) % 2 == 0) t++;
        repe(i,1,M+1){
            if(i>=t){
                cout << i << " " << N - i << '\n';
            }else{
                cout << i << " " << N - i + 1 << '\n';
            }
        }
    }
}

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

int main() {
  int N; cin >> N;
  int ans = 0;
  int maxCnt = 0;
  if ( N == 1 ) {
    cout << 1 << endl;
    return 0;
  }
  for ( int i = 1; i <= N; i++ ) {
    int x = i;
    int cnt = 0;
    int tmp;
    // cout <<"i " << i << endl;
    while(1) {
      if ( x % 2 == 0){
	cnt++;
	x/=2;
      }else {
	break;
      }
    }
    if ( cnt > maxCnt ) {
      maxCnt = cnt;
      ans = max(ans,i);
    }
  }

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


Measured memory_bytes: 256
def solve(string):
    a, b = map(int, [string[:2], string[2:]])
    a_is_mm = True if 1 <= a <= 12 else False
    b_is_mm = True if 1 <= b <= 12 else False
    if a_is_mm and b_is_mm:
        return "AMBIGUOUS"
    if a_is_mm:
        return "MMYY"
    if b_is_mm:
        return "YYMM"
    return "NA"


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
int N,K;
int A[111111];
int dep[111111];
vint G[111111];
void dfs(int v,int p,int d){
    dep[v]=d;
    for(auto u:G[v]){
        if(u!=p)dfs(u,v,d+1);
    }
}
 
bool rem[111111];
 
void col(int v,int p){
    if(rem[v])return;
    rem[v]=true;
    for(auto u:G[v]){
        if(u!=p)col(u,v);
    }
 
}
signed main(){
    cin>>N>>K;
    rep(i,N){
        cin>>A[i];A[i]--;
    }
 
    int cost=0;
    if(A[0]!=0){
        A[0]=0;
        cost++;
    }
    reps(i,1,N)G[A[i]].pb(i);
    dfs(0,-1,0);
 
    vpint vec;
    rep(i,N)vec.pb(pint(dep[i],i));
    sort(all(vec));reverse(all(vec));
    for(int i=0;i<N;i++){
        int v=vec[i].se;
        int d=vec[i].fi;
        if(rem[v])continue;
        if(d<=K)continue;
        int u=v;
        for(int j=0;j<K-1;j++)u=A[u];
        col(u,A[u]);
        cost++;
    }
    cout<<cost<<endl;
    return 0;
}

Measured memory_bytes: 14452
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> id(n);
    REP(i, n) {cin >> v[i]; id[i] = i;}
    int l1 = distance(v.begin(), max_element(v.begin(), v.end()));
    v[l1] *= -1;
    int l2 = distance(v.begin(), max_element(v.begin(), v.end()));
    v[l1] *= -1;
    REP(i, n) {
        cout << (i == l1 ? v[l2] : v[l1]) << endl;
    }
}


Measured memory_bytes: 3200
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	int last = a[0];
	rep(i, n - k) {
		printyn(a[i + k] > last);
		last = a[i + 1];
	}

	Please AC;
}

Measured memory_bytes: 4048
s=str(input())
flag=0
for i in range(len(s)//2):
    if flag==0:
        s=s[:-2]
        for j in range(len(s)//2):
            if s[j]!=s[(len(s)//2)+j]:
                break
            elif s[j]==s[(len(s)//2)+j] and j==(len(s)//2)-1:
                print(len(s))
                flag=1
                break
            
        

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

int main(void)
{
	/* code */
	int err, inp, a, b;
	err = scanf("%d", &inp);
	if (err!=1 || (inp!=1 && inp!=2)) exit(1);
	switch(inp)
	{
		case 1:
			printf("Hello World\n");
			break;
		case 2:
			err=scanf("%d\n%d", &a, &b);
			if (err !=2 || (a<1 || b>9)) exit(1);
			printf("%d\n", a+b);
			break;
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int n, x[10], y[10], f;
double ans;
string s;
vector<int> p;


void A() {
	cin>>n;
	cout<<n*n<<endl;
}

unsigned long long int fact(int x) {
	if (x==0) return 1;
	return (x*fact(x-1))%((int)1e9+7);
}

void B() {
	cin>>n>>s; 
	if (n%2) cout<<"No"<<endl;
	else for (int i=0; i<n/2; i++) {
		if (s[i]!=s[i+n/2]) {
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}

unsigned long long int nck(int n, int k) {
	cout<<n<<" "<<k<<endl;
	if (n==0) return 1;
	return (nck(n-1,k-1) + nck(n-1,k)) % 1000000007;
}

void C() {
	cin>>n;
	for (int i=0; i<n; i++) {cin>>x[i]>>y[i]; p.push_back(i);}
	for (int i=0; i<n; i++) {
		for (int j=0; j<i; j++) {
			ans+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))/n;
			//cout<<i<<" "<<j<<" "<<dist[i][j]<<endl;
		}
	}
	printf("%.10f\n", ans*2);
}

void D() {
	int x, y;
	cin>>x>>y;
	if ((2*y-x)%3) {cout<<0<<endl; return;}
	int n = (2*y-x)/3, m = (2*x-y)/3;
	cout<<n<<" "<<m<<endl;
	cout<<nck(n+m,n)<<endl;
	
}


int main() {
	C();
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::cmp::max;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
    let (A, B) = {
        let v: Vec<i32> = read_line().split_whitespace().map(|a| a.parse().unwrap()).collect();
        (v[0], v[1])
    };
    if (A - B) % 2 == 0 {
        println!("{}", (A+B) / 2);
    } else {
        println!("IMPOSSIBLE");
    }
}


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

int main() {
 int A ,B ;
 cin >> A >> B ;
 int ans =0;
 if ((A + B) % 2 == 1 ){
   cout << "IMPOSSIBLE" ;
 }
  else {
  ans = (A+B)/2;
  cout << ans ;
  }   
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if((a * b) % 2 == 0){
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
maxa = max(a)
# print(maxa)
if a.count(maxa) == 1:
    b = sorted(a, reverse=True)

    maxa2 = b[1]
    for i in range(n):
        if a[i] == maxa:
            print(maxa2)
        else:
            print(maxa)

else:
    for i in range(n):
        print(maxa)


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

using namespace std;

int a,b;

inline int readin(){
    int x=0,s=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')s=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*s;
}

int main(){
    a=readin();b=readin();
    if(a+b==15)puts("+");
    else if(a*b==15)puts("*");
    else puts("x");
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
h = Hash.new { |h,k| h[k] = {} }
n.times do |i|
  gets.chomp.split(' ').map(&:to_i).each.with_index do |j, idx|
    h[i][idx] = j
  end
end

def max(a, b)
  a > b ? a : b
end

dp = Hash.new { |h,k| h[k] = {} }
dp[0] = h[0]
(0...(n-1)).each do |i|
  3.times do |j|
    3.times do |k|
      next if j == k
      dp[i+1][k] = max(dp[i+1][k].to_i, dp[i][j] + h[i+1][k])
    end
  end
end

print(dp[n-1].values.max)


Measured memory_bytes: 61064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String[] str = s.split("");
		
		int c = 0;
		for(int i =0; i <n-1;i++) {
			if(str[i].equals(str[i+1])){
				c++;
			}
		}
		System.out.println(n-c);
	}

}


Measured memory_bytes: 31428
import java.math.BigInteger

fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map(String::toInt)
    val inputs = readLine()!!.split(" ").map(String::toLong)

    var border: BigInteger = BigInteger.valueOf(10).pow(18)

    if(inputs.contains(0L)) {
        println(0)
        return
    } 
    var sum: BigInteger = BigInteger.valueOf(1L)
    for (i in inputs) {
        sum = sum.multiply(BigInteger.valueOf(i))
        if(sum > border) {
            println(-1)
            return
        }
    }

    println(sum.toLong())
}


Measured memory_bytes: 63252
function main(input) {
    var lines = input.split('\n');
    var line1 = lines[0];
    var line2 = lines[1].split(' ');

    var N = parseInt(line1);

    var XList = line2.map(function (str) { return parseInt(str) });

    var orderedList = line2.sort(function (a, b) {
        return parseInt(a) - parseInt(b);
    });

    var lowerMedian = parseInt(orderedList[N / 2 - 1]);
    var higherMedian = parseInt(orderedList[N / 2]);

    var str = '';
    XList.forEach(function (Xn, index) {
        var num = Xn <= lowerMedian ? higherMedian : lowerMedian;
        str += num;
        if (index < N - 1) str += '\n';
    });
    console.log(str);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));




Measured memory_bytes: 65044
#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int dpl[102][50000];
int dph[102][50000];

int main()
{
    ll n, k;
    cin >> n >> k;
    ll m = 1;
    for(; m * m <= n; m++);
    m--;
    for(ll j = 1; j <= m; j++){
        dpl[1][j] = j;
        dph[1][j] = n / j;
    }
    for(int i = 2; i <= k; i++){
        for(int j = 1; j <= m; j++){
            dpl[i][j] = (dph[i - 1][j] + dpl[i][j - 1]) % MOD;
        }
        if(m * (m + 1) > n) dph[i][m] = dpl[i][m];
        else dph[i][m] = (dpl[i - 1][m] * (n / m - m) + dpl[i][m]) % MOD;
        for(int j = m - 1; j >= 1; j--){
            dph[i][j] = (dpl[i - 1][j] * (n / j - n / (j + 1)) + dph[i][j + 1]) % MOD;
        }
    }
    cout << dph[k][1] << endl;
}

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


int main(){
  int n;
  cin>>n;
  vector<int> v(n);

  for(int i=0;i<n;i++){
    cin >>v[i];
  }
  sort(v.begin(),v.end());
  double tmp=v[0];
  for(int i=1;i<n;i++){
    tmp=(tmp+v[i])/2;
  }
  cout <<tmp<<endl;

}





Measured memory_bytes: 256
n, m = map(int, input().split())
k = []
for i in range(m):
    k.append(list(map(int, input().split())))
p = list(map(int, input().split()))
count = 0
for i in range(2**n):
    flag = True
    for q_idx, query in enumerate(k):
        count_p = 0
        for q in query[1:]:
            if (i & 2**(q-1)) > 0:
                count_p += 1
        if count_p % 2 != p[q_idx]:
            flag = False
    if flag:
        count += 1
print(count)


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

int main(int argc, char const *argv[]) {

    while (1) {

        int n, max=0;
        double ave, v_sum=0, V;

        cin >> n;
        
        if (n == 0) {
            break;
        }

        int s[n];
        for (int i=0; i<n; i++) {
            cin >> s[i];
            max += s[i];
        }

        ave = (double)max/n;
        for (int i = 0; i < n; i++) {
            v_sum += (s[i] - ave) * (s[i] - ave);
        }

        V = sqrt((double)v_sum/n);
        cout << fixed << setprecision(10) << V << endl;

    }




    return 0;
}



Measured memory_bytes: 3228
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hsy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n, k;
            n = in.nextInt();
            k = in.nextInt();
            int[] num = new int[200000 + 10000];
            List<Integer> list = new ArrayList<>();
            List<Integer> list2 = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                if (num[x] == 0) {
                    list.add(x);
                }
                num[x]++;
            }
            if (list.size() <= k) {
                out.println("0");
            } else {
                for (int x : list) {
                    list2.add(num[x]);
                }
                int sum = 0;
                Collections.sort(list2);
                int g = list.size();
                for (int x : list2) {
                    if (g <= k) {
                        break;
                    }
                    sum += x;
                    g--;
                }
                out.println(sum);
            }
        }

    }
}



Measured memory_bytes: 94372
N = int(input())
amount = 0

for i in range(N):
    xu = input()
    xutable = xu.split()
    if xutable[1] == "JPY":
        amount += float(xutable[0])
    elif xutable[1] == "BTC":
        amount += float(xutable[0])*380000.0

print(amount)


Measured memory_bytes: 2940
N, M = map(int, input().split())
T = [[] for _ in range(N+1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    T[L].append((R, D))
    T[R].append((L, -D))
X = [None] * (N + 1)
for i in range(1, N+1):
    if X[i] is not None: continue
    X[i] = 0
    stack = [i]
    while stack:
        L = stack.pop()
        for R, D in T[L]:
            if X[R] is None:
                X[R] = X[L] + D
                stack.append(R)
            else:
                if X[R] - X[L] != D:
                    print("No")
                    exit()
print("Yes")

Measured memory_bytes: 65972
// マス目
import 'dart:io';

void main() {
  List hw = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int h = hw[0];
  int w = hw[1];
  List sList;
  int count;
  List ans;
  var an;
  ans = [];
  sList = [];
  for (int i = 0; i < h; i++) {
    sList.add(stdin.readLineSync());
  }

  for (int i = 0; i < h; i++) {
    an = (sList[i].split(''));
    for (int j = 0; j < w; j++) {
      count = 0;

      if (sList[i][j] == "#") continue;
      if ((i - 1 >= 0 && j - 1 >= 0)) {
        if (sList[i - 1][j - 1] == "#") count++;
      }

      if (i - 1 >= 0) {
        if (sList[i - 1][j] == "#") count++;
      }
      if (i - 1 >= 0 && j + 1 < w) {
        if (sList[i - 1][j + 1] == "#") count++;
      }

      if (j - 1 >= 0) {
        if (sList[i][j - 1] == "#") count++;
      }
      if (j + 1 < w) {
        if (sList[i][j + 1] == "#") count++;
      }
      if (i + 1 < h && j - 1 >= 0) {
        if (sList[i + 1][j - 1] == "#") count++;
      }
      if (i + 1 < h) {
        if (sList[i + 1][j] == "#") count++;
      }
      if (i + 1 < h && j + 1 < w) {
        if (sList[i + 1][j + 1] == "#") count++;
      }

      an[j] = count.toString();
    }
    ans.add(an);
  }
  for (int i = 0; i < h; i++) {
    print(ans[i].join());
  }
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    string s, t;
    cin >> s;
    cin >> t;
    int cnt = 0;
    rep(i, s.size())
    {
        if(s[i] != t[i])
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	string s="keyence";
	string s2="";
	sc(s2);
	if(s2==s)re pr("YES"),0;
	
	fu(i,0,le(s2)-1)fu(j,i,le(s2)-1){
		t=1; v=0;
		fu(h,0,le(s2)-1){
			if(h>=i and h<=j)continue;
			else{
				if(v<=le(s) and s2[h]==s[v])v++;
				else{
					t=0;break;
				}
			}
		}
		if(t==1 and v==le(s))re pr("YES"),0;
	}
	 pr("NO");


	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W;
	cin >> H >> W;
    vector<string> S(H+1,"#");
    for(int i=1; i<=H; ++i){
        string tmp;
        cin >> tmp;
        S[i] += tmp;
    } 

    vector<vector<vector<int>>> dp(4,vector<vector<int>>(H+2,vector<int>(W+2,0)));
    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            if(S[i][j]=='#') continue;
            dp[0][i][j] = dp[0][i][j-1]+1;
            dp[2][i][j] = dp[2][i-1][j]+1;
        }
    }
    for(int i=H; i>=1; --i){
        for(int j=W; j>=1; --j){
            if(S[i][j]=='#') continue;
            dp[1][i][j] = dp[1][i][j+1]+1;
            dp[3][i][j] = dp[3][i+1][j]+1;
        }
    }

    int ans=0;
    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            ans = max(ans, dp[0][i][j]+dp[1][i][j]+dp[2][i][j]+dp[3][i][j]);
        }
    } 
	cout << ans-3 << endl;
}

Measured memory_bytes: 82816
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key)
{
	int left = 0;
	int right = n;
	int mid;
	while( left < right ){
		mid = (left + right) / 2;
		if( key == A[mid] ) return 1;
		if( key > A[mid] ) left = mid + 1;
		else if( key < A[mid] ) right = mid;
	}
	return 0;
}

// 計算量はO(qn)
int main()
{
	int i, q, key, sum = 0;

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

	scanf("%d", &q);
	for (i = 0; i < q; i++)
	{
		scanf("%d", &key);
		if( binarySearch(key) ) sum++;
	}

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

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define Jai_Hind_Dosto ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define carry_is_Live ll bakchodi; cin>>bakchodi; while(bakchodi--)
typedef  int ll;
#define pahli_fursat 0
#define mithai_ki_dukan 200
int main() {
    Jai_Hind_Dosto;
    //carry_is_Live
    {
          ll a,b,h,m;
          cin>>a>>b>>h>>m;
          long double x,y,u,ans,l;
          x=360.0;
          y=360.0;
          x*=(60*h+m);
          x/=720.0;
          y*=m;
          y/=60.0;
          u=abs(x-y);
          //cout<u<<endl;
          if(u>180){
              u=360-u;
          }
          u*=3.1415926535897932;
          u/=180;
          ans=a*a;
          ans+=(b*b);
          l=cos(u);
          //cout<<l<<endl;
          l*=2;
          l*=(a*b);
          //cout<<l<<endl;
          ans-=(2*a*b*cos(u));
          ans=sqrt(ans);
          cout<<fixed<<setprecision(12)<<ans<<endl;
    }
	return pahli_fursat;
}


Measured memory_bytes: 4176