akhauriyash/Code-Regression huggingface dataset:
import numpy as np

N, Q = map(int,input().split())
S = str(input())
A = [list(map(int,input().split())) for i in range(Q)]

"""
import random
base_list = ['A', 'T', 'C', 'G']
S = ''
N = int(1e5)
Q = 1
A = [[100, 900]]
for i in range(N):
  S += random.choice(base_list)
"""

L_cnt = np.zeros(N-1)
R_cnt = np.zeros(N-1)

for i in range(N-2):
  L_cnt[i+1] = (S[i:i+2] == 'AC')
  R_cnt[i+1] = (S[N-2-i:N-i] == 'AC')

#print(L_cnt)
#print(R_cnt)
  
n_whole = S.count('AC')
L_cumsum = np.array(L_cnt).cumsum()
R_cumsum = np.array(R_cnt).cumsum()
for i in range(Q):
  ans = n_whole - (L_cumsum[A[i][0]-1] + R_cumsum[N-A[i][1]])
  print(int(ans))
  




"""
## 題意を愚直に表したもの（~10^10の計算量）
for i in range(Q):
  word = S[A[i][0]-1:A[i][1]]
  word_remove = word.replace('T', '').replace('G', '')
  ans = word_remove.count('AC')
  print(ans)
"""




Measured memory_bytes: 42596
#include<bits/stdc++.h>
#define M 100005
using namespace std;
int dep[M],dis[M],n,q,cnt[M],sz[M],fa[M][20],ans[M];
struct node {
	int id,c,d,f;
};
struct Node {
	int to,c,d;
};
vector<Node>G[M];
vector<node>Q[M];
void dfs(int x,int f,int d) {
	dis[x]=d,fa[x][0]=f;
	for(int i=0; i<G[x].size(); i++) {
		Node now=G[x][i];
		if(now.to==f)continue;
		dep[now.to]=dep[x]+1;
		dfs(now.to,x,d+now.d);
	}
}
void up(int &x,int step) {
	for(int i=0; i<20; i++)if(step&(1<<i))x=fa[x][i];
}
int lca(int x,int y) {
	if(dep[y]<dep[x])swap(x,y);
	up(y,dep[y]-dep[x]);
	if(x==y)return x;
	for(int i=19; i>=0; i--)
		if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void redfs(int x,int f) {
	for(int i=0; i<Q[x].size(); i++) {
		node now=Q[x][i];
		int c=now.c,d=now.d;
		ans[now.id]+=now.f*(dis[x]-cnt[c]+sz[c]*d);
	}
	for(int i=0; i<G[x].size(); i++) {
		Node now=G[x][i];
		if(now.to==f)continue;
		sz[now.c]++;
		cnt[now.c]+=now.d;
		redfs(now.to,x);
		sz[now.c]--;
		cnt[now.c]-=now.d;
	}
}
int main() {
	scanf("%d%d",&n,&q);
	for(int i=1; i<n; i++) {
		int x,y,c,d;
		scanf("%d%d%d%d",&x,&y,&c,&d);
		G[x].push_back((Node)<%y,c,d%>);
		G[y].push_back((Node)<%x,c,d%>);
	}
	dfs(1,0,0);
	for(int i=1; i<20; i++)for(int j=1; j<=n; j++)fa[j][i]=fa[fa[j][i-1]][i-1];
	for(int i=1; i<=q; i++) {
		int c,d,x,y;
		scanf("%d%d%d%d",&c,&d,&x,&y);
		int L=lca(x,y);
		Q[x].push_back((node)<%i,c,d,1%>);
		Q[y].push_back((node)<%i,c,d,1%>);
		Q[L].push_back((node)<%i,c,d,-2%>);
	}
	redfs(1,0);
	for(int i=1; i<=q; i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 31348
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> A = new ArrayList<Integer>();

        int n = sc.nextInt();
        int[][][] B = new int[4][3][10];
        for (int i=0; i<4; i++) {
            for (int j=0; j<3; j++) {
                Arrays.fill(B[i][j], 0);
            }
        }

        for (int i=0; i<n; i++) {
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            B[b-1][f-1][r-1] += v;
        }




        for (int i=0; i<4; i++) {
            for (int j=0; j<3; j++) {
                for (int k=0; k<10; k++) {
                    System.out.print(" ");
                    System.out.print(B[i][j][k]);
                }
                System.out.println();
            }
            if (i != 3) {
                for (int l = 0; l < 20; l++)
                    System.out.print("#");
                System.out.println();
            }
        }

    }
}


Measured memory_bytes: 29100
import sys

array = list(map(int, input().strip().split(' ')))

N = array[0]
M = array[1]


if N < 1:
    sys.exit()
if N > 10**5:
    sys.exit()

if M < 1:
    sys.exit()
if M > 10**5:
    sys.exit()

list_t = []

for i in range(M):

    array1 = list(map(int, input().strip().split(' ')))
    P = array1[0]
    Y = array1[1]

    if P < 1:
        sys.exit()
    if P > N:
        sys.exit()

    if Y < 1:
        sys.exit()
    if Y > 10**9:
        sys.exit()
    
    list_t.append([i,P,Y])



list_t.sort(key=lambda x:(x[1],x[2]))



test_P = list_t[0][1]

list_t[0][2] = 1

bango = 1


for j in range(1, M):


    test_P_next = list_t[j][1]

    if test_P == test_P_next:
        bango=bango+1
        list_t[j][2] = bango


    else:
        bango = 1
        list_t[j][2] = bango
        test_P = test_P_next

list_t.sort(key=lambda x:x[0])


for k in range(M):


    out1 = str(list_t[k][1])

    out_zero1 = out1.zfill(6)
    
    print(out_zero1,end='')

    out2 = str(list_t[k][2])

    out_zero2 = out2.zfill(6)
    
    print(out_zero2)

 

Measured memory_bytes: 32464
#include <bits/stdc++.h>
 
using namespace std;
 
const double PI = acos(-1);
 
int main()
{
  double n, m;
  cin >> m >> n;
  cout << fixed << setprecision(10) << m * sin(PI/m) * cos(n*PI / m) / cos((n - 1) * PI / m) << endl;
}

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




int main(){
	ll ans=0;
	int n,q;
	cin >> n;
	vector<ll> L(100001);
	rep(i,n){
		int a;
		cin >> a;
		ans += a;
		L[a]++;
	}
	cin >> q;
	vector<ll> l1;
	rep(i,q){
		int b,c;
		cin >> b >> c;
		L[c] += L[b];
		ans -= b*L[b];
		ans += c*L[b];
		L[b] = 0;
		l1.push_back(ans);
	}
	rep(i,l1.size()){
		cout << l1[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 5088
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

R = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        res = j - i
        if i <= X <= j <= Y:
            res = min(res, Y - j + X - i + 1)
        if X <= i <= Y <= j:
            res = min(res, i - X + j - Y + 1)
        if i <= X and Y <= j:
            res = min(res, j - Y + X - i + 1)
        if X <= i <= j <= Y:
            res = min(res, i - X + Y - j + 1)
        R[res - 1] += 1
for r in R:
    print(r)

Measured memory_bytes: 50940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader stdReader = new BufferedReader(new InputStreamReader(
				System.in));
		String line;
		while ((line = stdReader.readLine()) != null) {
			String[] tokens = line.split(" ");
			int x = Integer.parseInt(tokens[0]);
			int y = Integer.parseInt(tokens[1]);
			System.out.println(x + y);
		}

	}

}


Measured memory_bytes: 16980
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

#X = str(input()).split()
#a = [int(x) for x in input().split()]
#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]

S = str(input())
ans = 0
if(S=="SUN"):
  ans = 7
elif(S=="MON"):
  ans = 6
elif(S=="TUE"):
  ans = 5
elif(S=="WED"):
  ans = 4
elif(S=="THU"):
  ans = 3
elif(S=="FRI"):
  ans = 2
else:
  ans = 1


print(ans)


Measured memory_bytes: 38636
#include <stdio.h>
#include <string.h>

int main() {
  int N;
  char S[10000];
  scanf("%d", &N);
  scanf("%s", S);
  const int over = 'Z'-'A'+ 1;
  for(int i = 0; i < strlen(S); i++) {
    S[i] += N;
    if (S[i] > 'Z') {
      S[i] -= over;
    }
  }
  printf("%s", S);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INFTY=1<<29;

int main()
{
	for(int n;cin>>n,n;){
		vector<int> ps(n+1),ts(n+1);
		for(int i=1;i<=n;i++) cin>>ps[i]>>ts[i];
		
		vector<vector<int>> dp(n+1,vector<int>(4,INFTY));
		dp[0][0]=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=3;j++){
				if(dp[i-1][j-1]<INFTY && abs(ps[i]-ps[i-1])*j<=ts[i]-ts[i-1])
					dp[i][j]=min(dp[i][j],dp[i-1][j-1]+abs(ps[i]-ps[i-1]));
				if(dp[i-1][j]<INFTY && ps[i-1]*(j+1)+ps[i]<=ts[i]-ts[i-1])
					dp[i][1]=min(dp[i][1],dp[i-1][j]+ps[i]+ps[i-1]);
			}
		
		int total=*min_element(begin(dp[n]),end(dp[n]))+ps[n];
		if(total<INFTY)
			cout<<"OK "<<total<<endl;
		else
			for(int i=0;i<=n;i++)
				if(*min_element(begin(dp[i]),end(dp[i]))==INFTY){
					cout<<"NG "<<i<<endl;
					break;
				}
	}
}

Measured memory_bytes: 1216
H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]
H -= 1
W -= 1
for h, line in enumerate(grid[:]):
    hs = h,
    if 0 < h:
        hs += h - 1,
    if h < H:
        hs += h + 1,
    for w, g in enumerate(line):
        if g == '#':
            continue
        ws = w,
        if 0 < w:
            ws += w - 1,
        if w < W:
            ws += w + 1,
        c = 0
        for y in hs:
            for x in ws:
                if grid[y][x] == '#':
                    c += 1
        grid[h][w] = c
print(*map(lambda x: ''.join(map(str, x)), grid), sep='\n')


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

using i64 = int64_t;

struct Data{
    int y, x, y_, x_;
};

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> grid(h, vector<int>());
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            int a;
            cin >> a;
            grid[i].push_back(a);
        }
    }

    vector<Data> ans;
    for(int i=0;i<h;++i){
        for(int j=0;j<w-1;++j){
            if(grid[i][j]%2){
                grid[i][j]--;
                grid[i][j+1]++;
                ans.push_back({i, j, i, j+1});
            }
        }
    }
    for(int i=0;i<h-1;++i){
        if(grid[i][w-1]%2){
            grid[i][w-1]--;
            grid[i+1][w-1]++;
            ans.push_back({i, w-1, i+1, w-1});
        }
    }

    cout << ans.size() << endl;
    for(auto e: ans){
        cout << e.y+1 << " " << e.x+1 << " " << e.y_+1 << " " << e.x_+1 << endl;
    }

    return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vs = V<string>;

const int INF = 1999999999;

const int DX[4]= {-1,0,1,0};
const int DY[4]= {0,-1,0,1};

template<typename T>
T SUM(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

int main(){
    int h,w;
    cin>>h>>w;
    Vs s(h);
    REP(i,h){
        cin>>s[i];
    }

    V<Vi> dist(h*w,Vi(h*w,INF/2));
    REP(i,h*w){dist[i][i]=0;}

    REP(y,h){
        REP(x,w){
            REP(i,4){
                int dx = x + DX[i];
                int dy = y + DY[i];
                if(dx<0 || w<=dx) continue;
                if(dy<0 || h<=dy) continue;
                if(s[y][x] == '#') continue;
                if(s[dy][dx] == '#') continue;
                dist[y*w+x][dy*w+dx] = 1;
            }
        }
    }

    REP(k,h*w){REP(i,h*w){REP(j,h*w){dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);}}}

    int ans=0;
    REP(i,h*w){
        REP(j,h*w){
            if(dist[i][j] == INF/2) continue;
            ans = max(ans,dist[i][j]);
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 896
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
grid = []
for _ in range(3):
	temp = []
	temp = list(map(int,input().split()))
	grid.append(temp)
N = int(input())
b = []
for _ in range(N):
	b.append(int(input()))
for x in b:
	for i in range(3):
		for j in range(3):
			if grid[i][j]==x:
				grid[i][j]= -(grid[i][j])
ans = -1
# if not (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):	
for i in range(3):
	if grid[i][0]<0 and grid[i][1]<0 and grid[i][2]<0:
		ans  = 1
		break
	elif(grid[0][i]<0 and grid[1][i]<0 and grid[2][i]<0):
		ans = 1
		break
if ans!=1:
	if (grid[0][0]<0 and grid[1][1]<0 and grid[2][2]<0):
		ans = 1
	if( grid[0][2]<0 and grid[1][1]<0 and grid[2][0]<0):
		ans =1  
if(ans ==1):
	print("Yes")
else:
	print("No")
 


Measured memory_bytes: 38256
fn a() {
    input! {
        s: Chars,
        t: Chars,
    }

    let length = 1 <= s.len() && s.len() <= 10;
    let diff = s.len() + 1 == t.len();
    let str = t.into_iter().take(s.len()).zip(s).all(|(tn, sn)| tn == sn);

    if length && diff && str {
        println!("Yes");
    }
    else {
        println!("No");
    }
}

use proconio::input;
use proconio::marker::Chars;

fn main() {
    a();
}

Measured memory_bytes: 2128
#include <iostream>

int divisors(int n) {
    int res = 0;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ++res;
            if (n / i != i) ++res;
        }
    }
    return res;
}

int main() {
    int n, c=0;
    std::cin >> n;
    for (int i = 1; i <= n; i+=2) {
        if(divisors(i)==8) c++;
    }
    std::cout << c << '\n';
    return 0;
}

Measured memory_bytes: 3596
from math import sqrt

def func(x, y):
    return sqrt(x ** 2 + y ** 2)

N, D = map(int, input().split())
X = [0 for i in range(N)]
Y = [0 for i in range(N)]
for i in range(N):
    X[i], Y[i] = map(int, input().split())

ans = 0
for i in range(N):
    if func(X[i], Y[i]) <= D:
        ans += 1
print(ans)

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

int main(){
    
    long long a,b;
    cin >> a >> b;
    
    if(a*b <= 0)cout << "Zero"<<endl;
    else if(0 < a)cout << "Positive"<<endl;
    else if((-(a+b))%2==0)cout << "Negative"<<endl;
    else cout <<"Positive"<<endl;
}
    
    



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[2 * m][2];
        for(int i = 0;i < m;i++) {
            a[i][0] = sc.nextInt() - 1;
            a[2 * m - 1 - i][1] = a[i][0];
            a[i][1] = sc.nextInt() - 1;
            a[2 * m - 1 - i][0] = a[i][1];
        }

        System.out.println(dfs(n, m, a, new boolean[n], 0, 0));
    }

    private static int dfs(int n, int m, int[][] a, boolean[] footprints, int here, int count) {
        if(footprints[here]) return 0;

        footprints[here] = true;
        boolean hasConquered = true;
        for(int i = 0;i < footprints.length;i++) {
            if(!footprints[i]) {
                hasConquered = false;
                break;
            }
        }
        if(hasConquered) return 1;


        int tmpCount = count;
        for(int i = 0;i < 2 * m;i++) {
            if(a[i][0] == here && !footprints[a[i][1]]) {
                boolean[] tmpFootprints = new boolean[footprints.length];
                for(int j = 0;j < footprints.length;j++) tmpFootprints[j] = footprints[j];
                tmpCount += dfs(n, m, a, tmpFootprints, a[i][1], count);
            }
        }

        return tmpCount;
    }

}


Measured memory_bytes: 22996
#binary_tree
class Node
  attr_accessor :myname,:parent,:left,:right,:depth,:height

  def initialize(n)
    @myname = n
    @parent = nil
    @left   = nil
    @right  = nil
    @depth  = 0
  end

  def add_left(child)
      self.left    = child
      child.parent = self
  end

  def add_right(child)
      self.right    = child
      child.parent = self
  end

  def set_depth(d)
    self.depth = d
    if(self.left != nil)
      self.left.set_depth(d+1)
    end
    if(self.right != nil)
      self.right.set_depth(d+1)
    end
  end

  def set_height
    if(self.left != nil)
      lh=self.left.set_height
    else
      lh=0
    end
    if(self.right != nil)
      rh=self.right.set_height
    else
      rh=0
    end
    if lh > rh 
      self.height = lh + 1
    else
      self.height = rh + 1
    end
  end

  def sibling
    p = self.parent
    if p == nil
      nil
    elsif self == p.left
      p.right
    else
      p.left
    end
  end

  def degree
    deg=0
    if self.left != nil
      deg += 1
    end
    if self.right != nil
      deg += 1
    end
    deg
  end

  def shubetu

    if self.parent == nil
      "root"
    elsif self.height == 1
      "leaf"
    else
      "internal node"
    end

  end

  def describe
    printf("node %d:",self.myname)
    if self.parent == nil 
      printf(" parent = -1,")
    else
      printf(" parent = %d,",self.parent.myname)
    end
    if self.sibling == nil 
      printf(" sibling = -1,")
    else
      printf(" sibling = %d,",self.sibling.myname)
    end
    printf(" degree = %d,",self.degree)
    printf(" depth = %d,",self.depth)
    printf(" height = %d,",self.height-1)
    printf(" %s\n",self.shubetu)
  end
end


$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}

0.upto($n-1){|i|
  s = STDIN.gets.split
  id= s[0].to_i
  l = s[1].to_i
  r = s[2].to_i

#  printf("%d %d %d:\n",id,l,r)
  if(l != -1)
    $tree[id].add_left($tree[l])
  end
  if(r != -1)
    $tree[id].add_right($tree[r])
  end
}

def findroot
  0.upto($n-1){|i|
    if $tree[i].parent == nil 
      return i
    end
  }
end

rt = findroot
#printf("root=%d\n",rt)

$tree[rt].set_depth(0)
$tree[rt].set_height

0.upto($n-1){|i|
  $tree[i].describe 
}

Measured memory_bytes: 8696
# Problem: https://atcoder.jp/contests/abc057/tasks/abc057_c
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
import pprint as pp
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


# Const
MAXSIZE = ( 1 << 31 ) -1
MINSIZE = -( 1 << 31) + 1


def solver(input_int):
    result = len(str(input_int))
    for j in range(1, int(input_int**0.5) +1 , +1):
        divide_check = (input_int % j) != 0
        if divide_check:
            continue
        divide_value = input_int // j
        long_check = len(str(divide_value)) <= result
        if long_check:
            result = len(str(divide_value))
    # algorithm
    return result


if __name__ == "__main__":
    N = II()
    print("{}".format(solver(N)))


Measured memory_bytes: 9964
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		double t = sc.nextDouble();
		t = t+0.5;
		int ans = (int)(t/a)*b;
		System.out.print(ans);

	}
}


Measured memory_bytes: 24404
# AGC024B

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))



n = int(input())
a = [None] * n
for i in range(n):
    num = int(input())
    a[i] = num-1

seen = [False] * n
counts =[1] * n
for num in a:
    seen[num] = True
    if num>=1 and seen[num-1]:
        counts[num] = counts[num-1] + 1
print(n - max(counts))

Measured memory_bytes: 49756
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = il()
    print('No' if 2 in N else 'Yes')



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
 
def find_negative_loop(s,n,w,es):
  # s: start
  # n: number of nodes
  # w: number of edges
  # es[i]: from, to, cost
  
  # d: shortest dist of s -> i
  inf = float('inf')
  d = [inf for _ in range(n)]
  d[s] = 0
  for i in range(2*n):
    for j in range(w):
      p, q, r = es[j]
      if d[p] != inf and (d[q] > d[p] + r):
        d[q] = d[p] + r
        if i >= n:
          d[q] = (-1)*inf
    if i == n-1:
      temp = d[-1]
  return temp, d[-1]
         
n, m = map(int, input().split())
es = []
for i in range(m):
  a, b, c = map(int, input().split())
  es.append([a-1, b-1, c*(-1)])
  
temp, d = find_negative_loop(0, n, m ,es)
if temp == d:
  print(d*(-1))
else:
  print('inf')

Measured memory_bytes: 42332
/*
Educational DP Contest - G - Longest Path
https://atcoder.jp/contests/dp/tasks/dp_g
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 

int main()  
{ 
    FAST_INP;
    int n,m,x,y;
    cin >> n >> m;
	vector<int> dp(n+1,0); 
	vector<vector<int>> g(n+1);
    for(int i=0;i<m;i++){
    	cin >> x >> y;
    	// g does not contain directed cycles
    	g[x].push_back(y);
	}
	// traverse each node and count the path
	// use dp[from] to store the result and use it directly next time if necessary 
	function<int(int)> solve = [&](int from) {
		if(dp[from]) return dp[from];
		int ans=0;
		for(int to:g[from]){
			ans=max(ans,solve(to)+1);
		}
		return dp[from]=ans;	
	};
	int ans=0;
	for(int i=0;i<n;i++){
		// start from 1
		ans=max(ans,solve(i+1));
	}
	cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 12280
package main

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

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Split(bufio.ScanWords)

        var n, m int
        scanner.Scan()
        n, _ = strconv.Atoi(scanner.Text())
        scanner.Scan()
        m, _ = strconv.Atoi(scanner.Text())

        a := make([]int, n)
        for i := range a {
                scanner.Scan()
                a[i], _ = strconv.Atoi(scanner.Text())
        }

        b := 0
        c := map[int]int{0: 1}
        cnt := 0
        for _, a := range a {
                b = (b + a) % m
                if _, ok := c[b]; !ok {
                        c[b] = 1
                        continue
                }
                cnt += c[b]
                c[b]++
        }
        fmt.Println(cnt)
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(a>c){
		cout << "NO" << endl;
	}
	else if(a+b<c){
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int INF = 10000007;

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> mp(h, vector<char>(w));
	queue<pair<int, int>> que;
	vector<vector<int>> ans(h, vector<int>(w, INF));
	rep(i, h) {
		rep(j, w) {
			cin >> mp[i][j];
			if (mp[i][j] == '#') {
				que.push(make_pair(i, j));
				ans[i][j] = 0;
			}
		}
	}
	int anss = 0;

	while (que.size()) {
		int a = que.front().first;
		int b = que.front().second;
		que.pop();
		rep(i, 4) {
			if (a + dy[i] >= 0 && a + dy[i] < h && b + dx[i] >= 0 && b + dx[i] < w && mp[a+dy[i]][b+dx[i]] == '.') {
				mp[a+dy[i]][b+dx[i]] = '#';
				que.push(make_pair(a + dy[i], b + dx[i]));
				ans[a + dy[i]][b + dx[i]] = ans[a][b] + 1;
				anss = max(anss, ans[a + dy[i]][b + dx[i]]);
			}
		}
	}
	cout << anss << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  reverse(h.begin(), h.end());
  ll ans = 0;
  for (int i = k; i < n; ++i) {
    ans += h[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int i,n,N[1000000],q,cnt=0,j,p,m,l,r;
  //arry input
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&N[i]);
  //-------
  scanf("%d",&q);
  for(i=0;i<q;i++){
    l=0;
    r=n;
    scanf("%d",&p);
    //Binary search
    while(l<r){
      m=(l+r)/2;
      if(N[m]==p){
	cnt++;
	break;
      }
      if(p>N[m]){
	l=m+1;
      }
      if(p<N[m]){
	r=m;
      }
    }    
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2100
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,b = LS()
    a = int(a)
    b = int(b.replace(".", ""))

    return a * b // 100

print(main())





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

using namespace std;

int mv[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

int main(){
    int H,W,answer=0;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }

    for(int sy=0;sy<H;sy++){
        for(int sx=0;sx<W;sx++){
            if(S[sy][sx]=='#'){
                continue;
            }

            int ans[H][W] = {0};

            memset(ans,-1,sizeof(ans));

            ans[sy][sx] = 0;

            queue<pair<int,int>> Q;
            pair<int,int> P;
            P.first = sy;
            P.second = sx;
            Q.push(P);

            while(!Q.empty()){
                P = Q.front();
                Q.pop();
                for(int i=0;i<4;i++){
                    if(P.first+mv[i][0]<H && 0<=P.first+mv[i][0] && P.second+mv[i][1]<W && 0<=P.second+mv[i][1] && ans[P.first+mv[i][0]][P.second+mv[i][1]]==-1 && S[P.first+mv[i][0]][P.second+mv[i][1]]!='#'){
                        ans[P.first+mv[i][0]][P.second+mv[i][1]] = ans[P.first][P.second]+1;
                        Q.emplace(P.first+mv[i][0],P.second+mv[i][1]);
                    }
                }
            }

            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    answer = max(answer,ans[i][j]);
                }
            }
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll calcNumOfCombination(ll n, ll r){
  ll num = 1;
  for(ll i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  map<ll, int> mp;
  rep(i, n){
    ll in;
    cin >> in;
    mp[in]++;
  }
  int co = 0;
  ll sum = 0, pans = 0;
  bool f = false;
  rrepit(itr, mp){
    if(a - itr->second - co > 0){
      co += itr->second;
      sum += itr->first*itr->second;
      f = true;
    }else{
      sum += itr->first*(a-co);
      if(f == false){
        rep2(i, a-co, min(b-co+1, itr->second+1)){
          pans += calcNumOfCombination(itr->second, i);
        }
      }else{
        pans += calcNumOfCombination(itr->second, a-co);
      }
      break;
    }
  }
  double ans = (double)sum/a;
  printf("%.10f\n", ans);
  cout << pans << endl;
  // vector<ll> v(n);
  // rep(i, n) cin >> v.at(i);
  // sort(v.rbegin(), v.rend());
  // ll mx = 0;
  // rep(i, a){
  //   mx += v.at(i);
  // }
  // int ans = 1;
  // rep2(i, a, n){
  //   if(v.at(a-1) == v.at(i)) ans++;
  // }
  // double p = (double)mx / a;
  // cout << p << endl;
  // cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3764
require 'prime'

### constant

MAX_N = 123456
MAX_N2 = 2 * MAX_N

### main

psums = [0]
for k in (1..MAX_N2)
  psums[k] = Prime.prime?(k) ? psums[k - 1] + 1 : psums[k - 1]
end

loop do
  n = gets.to_i
  break if n == 0

  puts psums[2 * n] - psums[n]
end

Measured memory_bytes: 8272
#include <bits/stdc++.h>
/*    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;       */
using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define ld long double
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define print(x) cerr << #x << " is " << x << endl;
//      typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "rt", stdin);
//     freopen("output.txt", "wt", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll r;
    cin >> r;
    ll ans = 3 * r * r;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> p;
int main(){
   long long n,k,q;//n人　初期値ｋポイント　ｑ問行われた。 
   cin>>n>>k>>q;
   vector<long long> A(q);
   rep(i,q){
	   cin>>A[i];//正解したのが誰か。
	 }
	 vector<long long> B(n,0);//n人分の配列。q-k<正解数なら生存
	 rep(i,q){
	 long long a = A[i];//aが正解　つまりｂのa-1に＋1
	 B[a-1]++;
	 }//Bの入力は終わり
	 long long safe = q-k;
	 rep(i,n){
		 if(B[i]>safe){
			 cout<<"Yes"<<endl;
		   }
		   else{
			   cout<<"No"<<endl;
			 }
	   }
 }	


Measured memory_bytes: 2176
def lcm(data):
    from fractions import gcd
    x = data[0]
    for i in range(1, len(data)):
        x = (x * data[i]) // gcd(x, data[i])
    return x


k = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
z = lcm(a)
answer = 0
for j in range(n):
    answer += z // a[j]
print(answer % k)


Measured memory_bytes: 5684
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;



int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll C = A + B;
    ll D = N/C * A;
    ll E = N%C;
    if (E > A) {
      E = A;
    }
    cout << D + E << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<long long> march(5);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
    if(S.at(i).at(0)=='M')  march.at(0)++;
    else if(S.at(i).at(0)=='A')  march.at(1)++;
    else if(S.at(i).at(0)=='R')  march.at(2)++;
    else if(S.at(i).at(0)=='C')  march.at(3)++;
    else if(S.at(i).at(0)=='H')  march.at(4)++;
  }

  long long ans=0;
  for(int i=0;i<5-2;i++){
    for(int j=i+1;j<5-1;j++){
      for(int k=j+1;k<5;k++){
        ans+=march.at(i)*march.at(j)*march.at(k);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 
int main(){
    int n,m;cin >> n >> m;
    vector<int> s(n),t(m);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    vector<vector<LL>> dp(n+2,vector<LL> (m+2,0));
    vector<LL> dp1(m+2,0);
    dp[0][0]=1;
    for (int i = 0; i <= m; i++) {
        dp1[i]=1;
    }
    for (int i = 0; i < n; i++) {
        LL sum = 0;
        vector<LL> d(m+2,0);
        for (int j = 0; j < m; j++) {
            if(s[i]==t[j]){
                dp[i+1][j+1] = (dp[i+1][j+1]+dp1[j])%mod;
            }
            sum = (sum+dp[i+1][j+1])%mod;
            d[j+1] = sum;
        }
        for (int j = 0; j < m; j++) {
            dp1[j+1] = (dp1[j+1] + d[j+1])%mod;
        }
    }
    LL ans = 0;
    for (int i = 0; i <=n; i++) {
        for (int j = 0; j <=m; j++) {
            ans = (ans + dp[i][j])%mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 31744
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int i;
    for (i=1;i<=n;i++) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        } else {
            while (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using Graph=mat;

struct UnionFind{
    vector<int> par,rank;
    
    //初期化
    UnionFind(int n){
        for(int i=0;i<=n;++i){
            par.push_back(i);
            rank.push_back(0);
        }
    }

    //根をFind
    int find(int i){
        if(par[i]==i)return i;

        return par[i]=find(par[i]);
    }

    //Union
    void unite(int x,int y){
        int rx=find(x);
        int ry=find(y);

        if(rx==ry)return;

        if(rank[rx]>rank[ry])par[ry]=rx;
        else{
            par[rx]=ry;
            if(rank[rx]==rank[ry])
                rank[ry]++;
        }
    }

    //同じ木に属するか判定
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

int N;
Graph G;
vec par;
void dfs(int s,int p){
    for(int chi:G[s]){
        if(chi==p)continue;
        par[chi]=s;
        if(chi==N)return;
        dfs(chi,s);
    }
}
int main(){
    G.resize(100010);
    par.resize(100010);
    cin>>N;
    int a[100010],b[100010];
    for(int i=0;i<N-1;i++){
        cin>>a[i]>>b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    dfs(1,0);
    int x,y;
    x=N,y=par[N];
    vec v;
    v.push_back(N);
    while(y!=1){
        x=y;
        y=par[x];
        v.push_back(x);
    }
    v.push_back(1);

    int A,B;
    A=v[v.size()/2];
    B=v[v.size()/2-1];

    UnionFind UF(N);
    for(int i=0;i<N-1;i++){
        if(!((a[i]==A && b[i]==B) || (a[i]==B && b[i]==A)))
            UF.unite(a[i],b[i]);
    }
    int count=1;
    for(int i=2;i<=N;i++)
        if(UF.same(1,i))count++;
    if(count>N-count)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    return 0; 
}

Measured memory_bytes: 13176
#include<bits/stdc++.h>
using namespace std;
long long solve (long long n, long long k){
	if(k == 0) return n;
	if(n >= k){
		long long rem = n % k;
		long long ans = min(rem, k - rem);  
		return ans;
	}		
}
int main(){
	long long n, k;
	cin >> n >> k;
	long long result = solve(n , k); 	
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x >= 0 && y >= 0 && x + r <= W && y + r <= H) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return(0);
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using Pi = pair<P,int>;
#define rep(i,n) for(int i=0;i<n;i++)
const int mx = 200005;
int n, q[mx], p, c;
vector<int> ch[mx];
P ans[mx];
priority_queue<Pi, vector<Pi>, greater<Pi>> qu;
struct SegTree{
	int sz;
	P ide = P(1e9,0);
	vector<P> dat;
	SegTree(int n){
		for(sz = 2; sz < n; sz *= 2);
		dat.assign(sz*2, ide);
	}
	void set(int x, P n){
		dat[x += sz] = n;
		while(x /= 2) dat[x] = min(dat[x*2], dat[x*2+1]);
	}
	P query(int a, int b, int k = 1, int l = 0, int r = -1){
		if(r == -1) r = sz;
		if(r <= a || b <= l) return ide;
		if(a <= l && r <= b) return dat[k];
		return min(query(a, b, k*2, l, (l+r)/2), query(a, b, k*2+1, (l+r)/2, r));
	}
} sg[2] = {SegTree(mx), SegTree(mx)};

void solve(int s, int v, int pr){
	if(s == v) return;
	P ss = sg[s&1].query(s, v);
	P vv = sg[s&1^1].query(ss.second+1, v+1);
	if(c) ch[pr].push_back(c);
	ans[pr = c++] = P(ss.first,vv.first);
	solve(s, ss.second, pr);
	solve(ss.second+1, vv.second, pr);
	solve(vv.second+1, v, pr);
}
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &p);
		sg[i&1].set(i,P(p,i));
	}
	solve(0,n,0);
	qu.push(Pi(ans[0],0));
	while(!qu.empty()){
		auto it = qu.top(); qu.pop();
		printf("%s%d %d", (it.second ? " " : ""), it.first.first, it.first.second);
		for(auto t: ch[it.second]) qu.push(Pi(ans[t],t));
	}
	puts("");
}

Measured memory_bytes: 40192
N,K=map(int,input().split())
H=list(map(int,input().split()))
cost =10**10
DP=[0]*(N+10)
DP[0]=0
DP[1]=abs(H[1]-H[0])
for i in range(2,N):
  cost=10**10
  for k in range(max(i-K,0),i):
    cost=min(cost,(abs(H[i]-H[k])+DP[k]))
  DP[i]=cost
print(DP[N-1])

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <deque>

#define endl '\n'
#define ll long long

using namespace std;

int check[200000];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, k, c;
	string s;
	deque<int> bound;
	cin >> n >> k >> c >> s;

	int count = 0;
	for (int i = 0; i < n && count < k; i++)
	{
		if (s[i] == 'o')
		{
			check[count++] = i;
			i += c;
		}
	}

	count = k - 1;
	for (int j = n - 1; j >= 0 && count >= 0; j--)
	{
		if (s[j] == 'o')
		{
			if (check[count--] == j) bound.push_front(j);
			j -= c;
		}
	}

	for (auto a : bound)
	{
		cout << a + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3348
use std::str::FromStr;
use std::fmt::Debug;

fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn sub() -> bool
{
    let dates : Vec<u32> = read_line();
    let mut m = dates[0];
    let     d = dates[1];
    if m == 0 || d == 0 {
        return false;
    }
    let mut y = 2004;
    if m < 3 {
        y -= 1;
        m += 12;
    }
    let dayofweek = (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + d) % 7;
    let ans = match dayofweek {
        0 => "Sunday",
        1 => "Monday",
        2 => "Tuesday",
        3 => "Wednesday",
        4 => "Thursday",
        5 => "Friday",
        6 => "Saturday",
        _ => "",
    };
    println!("{}", ans);
    return true;
}

fn main() {
    while sub() {}
}


Measured memory_bytes: 5016
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

map<int, int> T;

void CountNum(int n) {
  if (T.count(n) > 0) {
    // cout << "n:" << n << ", increment" << endl;
    T[n]++;
  } else {
    T.insert(make_pair(n, 1));
    // cout << "n:" << n << ", insert" << endl;
  }
}

int main() {
  int N;
  cin >> N;
  int n;
  vector<int> a;
  for (int i = 0; i < N; ++i) {
    cin >> n;
    a.push_back(n);
  }
  sort(a.begin(), a.end());
  
  for (int i = 0; i < N; ++i) {
    n = a[i];
    CountNum(n);
    if (n > 0) {
      CountNum(n-1);     
    }
    CountNum(n+1);
    // cout << "----------" << endl;
  }

  int max = 0;
  for(map<int, int>::iterator it = T.begin(); it != T.end(); it++) {
    pair<int, int> T = *it;
    if (T.second > max) {
      max = T.second;
    }
    // cout << "k:" << T.first << ", v:" << T.second << endl;
  }
  
  cout << max << endl;

}

Measured memory_bytes: 5112
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
map<ll, ll> city[100005];
vector<LP> py;
int main(){
    int n,m; cin >> n >> m;
    REP(i,m){
        ll p,y; cin >>p >> y;
        py.push_back(make_pair(p,y));
        city[p][y] = 1;
    }
    REP(i,n+1){
        auto it = city[i].begin();
        ll count = 1;
        while(it!=city[i].end()){
            it->second = count;
            count++;
            it++;
        }
    }
    REP(i,m){
        ll p,y;
        p = py[i].first;
        y = py[i].second;
        ll num = city[p][y];
        printf("%06d%06d\n" ,p, num);

    }


}

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

typedef long long ll;
int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll l = 4 * a * b;
    ll r = c - a - b;
    if (r < 0) {
        cout << "No\n";
        return 0;
    }
    r *= r;
    if (l < r) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int N = sc.nextInt();
		int[] stones = new int[N];
		String stone_string = sc.next();

		int tmp = 0;
		int red_num = 0;

		for(int i=0;i<N;i++) {
			if(stone_string.charAt(i) == 'R') {
				red_num++;
				stones[i] = 0;
			}else {
				stones[i] = 1;
			}
		}

		if(red_num == N || red_num == 0) {
			System.out.println(0);
			return;
		}

		int result = 0;
		for(int i=0;i<red_num;i++) {
			if(stones[i] == 1) {
				result++;
			}
		}

		sc.close();
		System.out.println(result);

	}
}


Measured memory_bytes: 32172
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 55
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int h, w;
vector<string> s;
int d[MAX][MAX];
int di[]={0, -1, 0, 1}, dj[]={-1, 0, 1, 0};
ll ans=0;

int bfs(int i, int j, int gi, int gj){
  queue<P> que;
  rep(i, h)rep(j, w){
    d[i][j]=INF;
  }
  que.push(P(i, j));
  d[i][j]=0;

  while(que.size()){
    P p=que.front(); que.pop();
    if(p.first==gi && p.second==gj)break;
    rep(k, 4){
      int ni=p.first+di[k], nj=p.second+dj[k];
      if(ni>=0 && ni<h && nj>=0 && nj<w && s[ni][nj]!='#' && d[ni][nj]==INF){
        d[ni][nj]=d[p.first][p.second]+1;
        que.push(P(ni,nj));
      }
    }
  }
  return d[gi][gj];
}


int main(){
  cin >> h >> w;
  s.resize(h);
  int whitenum=0;
  rep(i, h){
    cin >> s[i];
    rep(j, w){
      if(s[i][j]=='.'){
        whitenum++;
      }
    }
  }

  int minwhite= bfs(0, 0, h-1, w-1);
  if(s[0][0]=='#' || minwhite==INF){
    cout << -1 << endl;
    return 0;
  } else {
    cout << whitenum-minwhite-1 << endl;
    return 0;
  }

}


Measured memory_bytes: 256
#include<stdio.h>

int main (void){
	
	int n,pm,pe,pj,i;
	
	for(;;){
		scanf("%d",&n);
		if(n == 0) break;
		
		for(i=0;i<n;i++){
			scanf("%d %d %d",&pm,&pe,&pj);
			if(pm == 100 || pe == 100 || pj == 100){
				printf("A\n");
			}else if((pm + pe)/2 >= 90){
				printf("A\n");
			}else if((pm + pe + pj)/3 >= 80){
				printf("A\n");
			}else if((pm + pe + pj)/3 >= 70){
				printf("B\n");
			}else if((pm + pe + pj)/3 >= 50 && (pm >= 80 || pe >= 80)){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 584
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons

main = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  qs <- map read . words <$> getLine :: IO [Int]

  let allPermutations = V.fromList . sort $ permutations [1..n]
      a = fromJust $ V.elemIndex ps allPermutations
      b = fromJust $ V.elemIndex qs allPermutations
      ans = abs $ a - b

  print ans


Measured memory_bytes: 20092
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0 ; i < n ; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        int min = Integer.MAX_VALUE;
        for (int i = 0 ; i < n - k + 1 ; i ++ ) {
            min = Math.min(min, h[i + k - 1] - h[i]);
        }


        System.out.println(min);
    }

}


Measured memory_bytes: 49948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d  =sc.nextInt();

		int a = n / ((2*d) + 1);
		int b = n %((2*d) + 1);
		if (b > 0) a++;

		System.out.println(a);

		sc.close();
	}
}


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

int div2(vector<int> &Ai, int &cnt){
    vector<int> div(Ai.size(), 0);
    int c = 0;

    for(int i = 0; i < Ai.size(); i++){
        div.at(i) = Ai.at(i) % 2;
    }
    for(int i = 0; i < Ai.size(); i++){
        c += div.at(i);
    }

    if(c != 0){//ベースケース　これ以上割れない要素がある
        return 0;
    }
    else{//まだ割れる
        cnt ++;
        for(int i = 0; i < Ai.size(); i++){
            Ai.at(i) = Ai.at(i) / 2;
            if(i == Ai.size() -1);
        }
        div2(Ai, cnt);
        return 0;
    }
}

int main(){
    int N = 0;
    int ans = 0;
    cin >> N;
    vector<int> A(N, 0);
    
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    div2(A, ans);
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <cstdio>
int main(){
	int l;
	while(scanf("%d", &l), l){
		int cm = -1;
		for(int i=1;i<=12;i++){
			int m, n;
			scanf("%d%d", &m, &n);
			l -= m - n;
			if(l <= 0 && cm < 0)
				cm = i;
		}
		if(cm<0)puts("NA");
		else printf("%d\n", cm);
	}
}

Measured memory_bytes: 0