akhauriyash/Code-Regression huggingface dataset:
use std::collections::VecDeque;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();

    let mut graph: Vec<Vec<usize>> = (0..n).map(|_| Vec::new()).collect();
    for _ in 0..(n - 1) {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }

    let dist_first = calc_dist(0, n, &graph);
    let dist_second = calc_dist(n - 1, n, &graph);
    let mut first = 0;
    let mut second = 0;
    for i in 0..n {
        if dist_first[i] <= dist_second[i] { first += 1; } else { second += 1; }
    }

    if first > second {
        println!("Fennec");
    } else { println!("Snuke"); }
}

fn calc_dist(start: usize, n: usize, graph: &Vec<Vec<usize>>) -> Vec<usize> {
    let mut q = VecDeque::new();
    let mut dist = vec![std::usize::MAX; n];
    dist[start] = 0;
    q.push_back(start);
    while !q.is_empty() {
        let v = q.pop_front().unwrap();
        for next in &graph[v] {
            if dist[*next] <= dist[v] { continue; }
            dist[*next] = dist[v] + 1;
            q.push_back(*next);
        }
    }
    return dist;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



Measured memory_bytes: 12540
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin>>s;
	char a,aa;//一番左端の数,aの反転数(0,1)
	int b(0),c(0),ans(0);//左端の同じ文字の数,次の連続する数の数,取り除いた数
	if(s[0]=='1')a='1',aa='0';else a='0',aa='1';
	for(int i=0;i<s.size();i++){
		if(s[i]==a)++b;else break;
	}
	while(s.size()>b){
		c=0;
		for(int i=0;i<s.size()-b;i++){
			if(s[b+i]==aa)++c;else break;
		}
		
		if(b<c){
			s.erase(0,2*b);
			ans+=2*b;
			char aaa=a;
			a=aa;aa=aaa;
			b=c-b;
		}
		else{
			s.erase(b-c,2*c);
			ans+=2*c;
			b=0;
			if(s.empty())break;
			else{
				for(int i=0;i<s.size();i++){
					if(s[i]==a)++b;else break;
				}
			}
		}
		//cout<<b<<c<<' '<<s<<endl;
		
	}
	cout<<ans;
}

Measured memory_bytes: 512
from sys import stdin
from math import isinf
n, e = map(int, stdin.readline().split())
d = [[float('inf')] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(e):
    u, v, c = map(int, stdin.readline().split())
    d[u][v] = c
for k in range(n):
    for i in range(n):
        if d[i][k] == float('inf'): continue
        for j in range(n):
            if d[k][j] == float('inf'): continue
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
for i in range(n):
    if d[i][i] < 0:
        print("NEGATIVE CYCLE")
        exit(0)
for di in d:
    print(' '.join(('INF' if isinf(dij) else str(dij) for dij in di)))

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<vector<int>> dp(N);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      dp[i].push_back(0);
    }
  }

  for(int i = 1; i < N; i++){
    if(S[0] == S[i]){
      dp[0][i] = 1;
      dp[i][0] = 1;
    }
  }

  for(int i = 1; i < N; i++){
    for(int j = 1; j < N; j++){
      if(S[i] == S[j] && i != j){
        dp[i][j] = min(1 + dp[i-1][j-1], abs(i-j));
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      chmax(ans, dp[i][j]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 118144
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    
    int n;cin>>n;
    vector<int>x(n);
    for(int i=0;i<n;i++)
        cin>>x[i];

    int ans=IINF;
    for(int i=1;i<=100;i++){
        int tmp=0;
        for(int j=0;j<n;j++){
            tmp+=(x[j]-i)*(x[j]-i);
            
        }
        chmin(ans,tmp);
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Max 10

typedef struct node *link;
struct node{
	int key;
	link left,right;
};

link insert(link head,link z){
	link y=NULL;
	link x=head;
	
	while(x!=NULL){
		y=x;
		if(z->key < x->key)x=x->left;
		else x=x->right;
	}
	
	if(y==NULL)head=z;
	else if(z->key < y->key)y->left=z;
	else y->right=z;
	return head;
}

void preorder(link x){
  if(x==NULL)return;
	printf(" %d",x->key);
	preorder(x->left);
	preorder(x->right);
}

void inorder(link x){
	if(x==NULL)return;
	inorder(x->left);
	printf(" %d",x->key);
	inorder(x->right);
}

int find(link x,int key){
	if(x==NULL)return 0;
	if(x->key==key)return 1;
	if(x->key>key)return find(x->left,key);
	return find(x->right,key);
}

int search(link x){
	if(x->left==NULL)return x->key;
	return search(x->left);
}

link delete(link x,int key){
	if(x==NULL)return NULL;
	if(x->key==key){
		if(x->left==NULL && x->right==NULL)return NULL;
		else if(x->right==NULL){
			return x->left;
		}else if(x->left==NULL){
			return x->right;
		}else{
			x->key=search(x->right);
			x->right=delete(x->right,x->key);
		}
	}else if(x->key >key){
		x->left=delete(x->left,key);
	}else{
		x->right=delete(x->right,key);
	}
	return x;
}
int main(void){
	int h,i,key;
	char cmd[Max];
	link head=NULL,z;
	scanf("%d",&h);
	for(i=0;i<h;i++){
		scanf("%s",cmd);
		if(!strcmp(cmd,"insert")){
			scanf("%d",&key);
			z = malloc(sizeof(*z));
			z->key=key;z->left=NULL;z->right=NULL;
			head=insert(head,z);
		}else if(!strcmp(cmd,"print")){
			inorder(head);
			printf("\n");
			preorder(head);
			printf("\n");
		}else if(!strcmp(cmd,"find")){
			scanf("%d",&key);
			if(find(head,key)!=0)printf("yes\n");
			else  printf("no\n");
		}else if(!strcmp(cmd,"delete")){
			scanf("%d",&key);
			head=delete(head,key);
		}
	}
	return 0;
}



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

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var T = Console.ReadLine();

        var start = new int[26];
        var end = new int[26];
        for (int i = 0; i < 26; i++)
        {
            start[i] = -1;
            end[i] = -1;
        }

        for (int i = 0; i < S.Length; i++)
        {
            int a = S[i] - 'a';
            int b = T[i] - 'a';

            if (start[a] != -1 || end[b] != -1)
            {
                if (start[a] != b || end[b] != a)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            start[a] = b;
            end[b] = a;
        }

        Console.WriteLine("Yes");
    }

}



Measured memory_bytes: 13208
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[int]"):
    A_ = sorted(A)
    s = sum(A)
    count = 0
    for i in range(N):
        if A_[i] >= (s/4/M):
            count += 1
    if count > M - 1:
        print(YES)
    else:
        print(NO)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
# S=numpp.assaray(S)=="#"
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
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 LLS(): return [list(sys.stdin.readline().rstrip()) for _ 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 main():
    M1, D1 = list(map(int,input().split()))
    M2, D2= LI()
    if M1==M2:
        print(0)
    else:
        print(1)

    # print(A,B)


if __name__ == "__main__":
    main()

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		MySet S=new MySet();
		int q=Integer.parseInt(in.next());
		for(int i=0;i<q;i++) {
			int odr=Integer.parseInt(in.next());
			
			switch(odr) {
			case 0:
				int x0=Integer.parseInt(in.next());
				S.add(x0);
				out.println(S.size());
				break;
				
			case 1:
				int x1=Integer.parseInt(in.next());
				out.println((S.contains(x1))? 1 : 0);
				break;
				
			case 2:
				int x2=Integer.parseInt(in.next());
				S.remove(x2);
				break;
				
			case 3:
				int l=Integer.parseInt(in.next()),r=Integer.parseInt(in.next());
				for(int j=l;j<=r;j++) {
					if(S.index[j]) out.println(j);
				}
			}
		}
		out.flush();
	}

}

class MySet{
	boolean index[];int size;
	
	MySet(){
		index=new boolean[1000000001];
		Arrays.fill(index, false);
		size=0;
	}
	
	void add(int x) {
		if(!index[x]) {
			index[x]=true;
			size++;
		}
	}
	
	int size() {
		return this.size;
	}
	
	boolean contains(int x) {
		return index[x];
	}
	
	void remove(int x) {
		if(index[x]) {
			index[x]=false;
			size--;
		}
		
	}
	
	List<Integer> dump(int a,int b) {
		List<Integer> ls=new ArrayList<>();
		for(int i=a;i<=b;i++) {
			if(index[i]) ls.add(i);
		}
		
		return ls;
	}
}



Measured memory_bytes: 1106544
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    VI dp;
    REP(i,n){
        int x = upper_bound(ALL(dp), -a[i]) - dp.begin();
        if (x == dp.size()) dp.push_back(-a[i]);
        else dp[x] = -a[i];
    }
    cout << dp.size() << endl;
    return 0;
}


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

int main() {
    string n;
    cin >> n;
    rep(i,3){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

bool ok(int x){
  rep(i,0,10)rep(j,0,10)if(i*j == x)return true;
  return false;
}


int main(){
  int x; cin>> x;
  if(ok(x))cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
K = int(input())

A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]


print (A[K-1])

Measured memory_bytes: 3316
a,b,c,d=map(int,input().split())
import fractions
def warikire(x,y,z):
    return (y//z*z-((x-1)//z*z+z))//z +1
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
print(b-a+1 - warikire(a,b,c) - warikire(a,b,d) + warikire(a,b,lcm(c,d)))

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

int main(){
  const int Nmax= 100000;
  // 下準備として[1:N]の中の2017に似た数が何個あるかを調べる
  vector<int> data(Nmax+1);
  //// -素数判定
  bitset<Nmax+1> bits;
  bits.set(); bits.reset(0); bits.reset(1);

  int div= 2;
  while( div*div <= Nmax ){
    if( bits.test(div) ){
      for(int i=2*div; i<=Nmax; i+=div){
        bits.reset(i);
      }
    }
    div++;
  }
  //// -データ格納
  for(int i=3; i<=Nmax; i+=2){ // i:奇数
    if( bits.test(i) && bits.test( (i+1)/2 )  ){
      data.at(i)= data.at(i-2)+ 1;
    }
    else{
      data.at(i)= data.at(i-2);
    }
  }
  for(int i=2; i<=Nmax; i+=2){ // i:偶数
    data.at(i)= data.at(i-1);
  }

  // クエリ処理
  int Q, left, right;
  cin >> Q;
  for(int i=0; i<Q; i++){
    cin >> left >> right;

    cout << data.at(right)- data.at(left-1) << endl;
  }
}

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

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String input = reader.readLine();
			String[] array = input.split(" ");
			int r = Integer.parseInt(array[0]);
			int c = Integer.parseInt(array[1]);
			
			int[][] cell = new int[r][c];
			for (int i = 0; i < r; i++) {
				input = reader.readLine();
				array = input.split(" ");
				for (int j = 0; j < c; j++) {
					cell[i][j] = Integer.parseInt(array[j]);
				}
			}
			
			int sumRow = 0;
			int sumCol[] = new int[c + 1];
			int sum = 0;
			for (int k = 0; k < r; k++) {
				for (int l = 0; l < c; l++) {
					System.out.print(cell[k][l] + " "); 
					sumRow += cell[k][l];
					sumCol[l] += cell[k][l];
				}
				System.out.println(sumRow);
				sum += sumRow;
				sumRow = 0;
			}
			
			for (int m = 0; m < c; m++) {
				System.out.print(sumCol[m] + " ");
			}
			System.out.println(sum);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repi(i, x) for (auto &i : (x))

#ifndef __SOULTCH
#define endl '\n'
#define debug(...) 
#else
#define __debug_a(v) cout << " [+] " << #v << " = " << (v) << endl
#define __debug_b(v) cout << "     " << #v << " = " << (v) << endl
#define debug1(v1) __debug_a(v1);
#define debug2(v1, v2) __debug_a(v1), __debug_b(v2);
#define debug3(v1, v2, v3) __debug_a(v1), __debug_b(v2), __debug_b(v3);
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define debug(...) GET_MACRO(__VA_ARGS__, debug3, debug2, debug1)(__VA_ARGS__)
#endif

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> s) {
    for (T p : s) cout << p << ' ';
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

template<typename T> void umax(T &a, T b) {a = max(a, b);}
template<typename T> void umin(T &a, T b) {a = min(a, b);}

ll N;

ll test(ll v) {
    if (v == 0) return 0;
    ll q = N/v, c = N%v;
    if (q == c) return v;
    return 0;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N;
    ll res = 0;
    for (ll i = 1; i*i < N; i++) {
        if (N%i == 0) {
            res += test(i-1)+test(N/i-1);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        String s = r.s();
        int ans = 0;
        for(char c : s.toCharArray())
            if(c == '1')
                ans++;
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main(int argc, char *argv[]) {
  string result = "Good";
  string S;
  cin >> S;
  rep(i, 3){
    if(S[i] == S[i+1]){
      result = "Bad";
      break;
    }
  }
    
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,i,j;
	cin>>n>>k;
	if(k==1)cout<<"0";else
	cout<<n-k;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// 桁和
int digsum10(int n) {
  int res = 0;
  while (n>0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  if (N%digsum10(N)==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(ns())

n = ni()
a = na()

x = 1
for i in range(0, n):
    if a[i] == x:
        x += 1


print(n-x+1 if x > 1 else -1)


Measured memory_bytes: 25456
from math import sqrt
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
 
d = 0
for i in range(n):
    for j in range(i):
        x = a[i] - a[j]
        y = b[i] - b[j]
        d += sqrt(x**2 + y**2)
d *= 2
d /= n
print(d)

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

int main() {
  int N;
  cin >> N;
  
  vector<string> s(N);
  rep(i, N) {
    cin >> s.at(i);
  }
  
  int M;
  cin >> M;
  
  vector<string> t(M);
  rep(i, M) {
    cin >> t.at(i);
  }
  
  int ans = 0;
  rep(i, N) {
    int cntN = 0;
    rep(j, N) {
      if (s.at(i) == s.at(j)) {
        cntN++;
      }
    }
       
    int cntM = 0;
    rep(j, M) {
      if (s.at(i) == t.at(j)) {
        cntM++;      
      }
    }
    
    ans = max(ans, cntN - cntM);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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 {
        int mod = 1_000_000_007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            String[] b = new String[n];
            for (int i = 0; i < n; i++) b[i] = in.next();
            char[][] board = new char[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    board[i][j] = b[i].charAt(j);
                }
            }
            int[][] dp = new int[n][m];
            dp[0][0] = 1;
            for (int row = 0; row < n; row++) {
                for (int col = 0; col < m; col++) {
                    for (int i = 0; i < 2; i++) {
                        if (i == 0) {
                            if (row + 1 < n && board[row + 1][col] == '.')
                                dp[row + 1][col] = (dp[row + 1][col] + dp[row][col]) % mod;
                        } else {
                            if (col + 1 < m && board[row][col + 1] == '.')
                                dp[row][col + 1] = (dp[row][col + 1] + dp[row][col]) % mod;
                        }
                    }
                }
            }

            out.println(dp[n - 1][m - 1] % mod);
        }

    }
}



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

#define l long
#define ll long long
#define pb push_back
#define vb vector<bool>
#define vi vector<int>
#define vll vector<ll>
#define MOD 998244353
#define nl "\n"
#define sp " "
#define gcd __gcd
#define pf printf
#define sf scanf

int main()
{
    long x;
    cin>>x;
    long temp = 100;
    int years = 0;
    while(x > temp){
        temp += floor(temp/100);
        years++;
    }
    cout<<years<<nl;
}

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

int main(){
	long long int dogs, nim;
	char name [30];
	scanf("%lld", &dogs);
	int i = 0;

	while (dogs != 0){
		dogs--;		//kurangin biar nanti ditambah 'a' jadi sesuai
		nim = dogs % 26; //modulo untuk cari sisa yang akan ditampung ke char
		name[i] = nim+'a';
		i++;
		dogs/=26;	//utk lanjut ke baris selanjutnya
	}
	for (int k=i-1; k>=0; k--){
		printf ("%c", name[k]);
	}
	return 0;
}

Measured memory_bytes: 1660
S = gets.chomp
N = S.length

a = 0
ab = 0
ans = 0
all = 1

MOD = 10**9+7

N.times do |i|
    if S[i] == 'A'
        a += all
    elsif S[i] == 'B'
        ab += a
    elsif S[i] == 'C'
        ans += ab
    elsif S[i] == '?'
        ans = ans*3 + ab
        ab = ab*3 + a
        a = a*3 + all
        all *= 3
    end
    a %= MOD
    ab %= MOD
    ans %= MOD
    all %= MOD
end
puts ans

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 int n,x,t;
 cin>>n>>x>>t;
 int ans=n/x;
 if(n%x!=0){ans++;}
 cout<<ans*t;
}


Measured memory_bytes: 3640
#include<iostream> 
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath> 
#include<algorithm>
#define ll long long 
using namespace std;
const int maxn=500010, inf=1e9;
struct edge{int too, pre;}e[maxn];
int n, m, x, y, tot;
int fa[maxn], a[maxn], b[maxn], last[maxn], pos[maxn];
ll ad[maxn], sum[maxn];
bool v[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;
}

inline void add(int x, int y){e[++tot]=(edge){y, last[x]}; last[x]=tot;}

inline bool cmp(int x, int y){return a[x]<a[y];}

int gf(int x){return fa[x]==x?x:fa[x]=gf(fa[x]);} 

int main()
{
	read(n); read(m);
	for(int i=1;i<=n;i++) read(a[i]), read(b[i]), a[i]=max(a[i]-b[i], 0);
	for(int i=1;i<=m;i++) read(x), read(y), add(x, y), add(y, x);
	for(int i=1;i<=n;i++) pos[i]=i, fa[i]=i, ad[i]=a[i], sum[i]=b[i];
	sort(pos+1, pos+1+n, cmp);
	for(int i=1;i<=n;i++)
	{
		int x=pos[i]; v[x]=1;
		for(int j=last[x], too;j;j=e[j].pre)
		if(v[too=e[j].too])
		{
			int fx=gf(x), fy=gf(too);
			if(fx==fy) continue;
			sum[fx]+=sum[fy]; fa[fy]=fx;
			ad[fx]=min(ad[fx], ad[fy]+max(0ll, a[x]-ad[fy]-sum[fy]));
		}
	}
	printf("%lld\n", sum[pos[n]]+ad[pos[n]]);
}

Measured memory_bytes: 15488
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class CModuloSummation {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<int> a(n);
    REP(i,n) in >> a[i];
    int sum = 0;
    for_each(a.begin(),a.end(),[&](int v){
      sum += v - 1;
    });
    out << sum << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	CModuloSummation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#define llint long long

using namespace std;

int n;
llint b[105];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n-1; i++) cin >> b[i];
	b[0] = b[n] = 1e9;
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans += min(b[i-1], b[i]);
	cout << ans << endl;
	
	return 0;
}

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

using ld=long double;
const int LOOP=1000;
const ld eps=1e-15;
int main(){
    vector<ld> p(6),q(6);
    for(int i=0;i<6;i++) cin>>p[i],p[i]/=100;
    for(int i=0;i<6;i++) cin>>q[i],q[i]/=100;
    ld lb=0,ub=1;
    auto calc=[&](ld pp){
        ld pq=1-pp;
        ld res=0;
        for(int x=0;x<6;x++){
            ld ppx=p[x]*pp;
            ld pqx=q[x]*pq;
            res+=max(ppx,pqx);
        }
        return res;
    };
    for(int loop=0;loop<LOOP;loop++){
        ld midl=(lb*2+ub)/3,midu=(lb+ub*2)/3;
        ld pl=calc(midl),pu=calc(midu);
        if(pl<pu){
            ub=midu;
        }
        else{
            lb=midl;
        }
    }
    cout<<fixed<<setprecision(10);
    cout<<calc(lb)<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    if (400 <= x && x <= 599)
        cout << 8 << endl;
    if (600 <= x && x <= 799)
        cout << 7 << endl;
    if (800 <= x && x <= 999)
        cout << 6 << endl;
    if (1000 <= x && x <= 1199)
        cout << 5 << endl;
    if (1200 <= x && x <= 1399)
        cout << 4 << endl;
    if (1400 <= x && x <= 1599)
        cout << 3 << endl;
    if (1600 <= x && x <= 1799)
        cout << 2 << endl;
    if (1800 <= x && x <= 1999)
        cout << 1 << endl;
}

Measured memory_bytes: 3636
use strict;
use warnings;
package FenwickTree;
sub new{
	return bless[(0)x$_[1]],$_[0];
}
sub add{
	my$self=shift;
	my($p,$x)=@_;
	$p++;
	while($p<=@{$self}){
		$self->[$p-1]+=$x;
		$p+=$p&-$p;
	}
}
sub sum{
	my$self=shift;
	return$self->prefixsum($_[1])-$self->prefixsum($_[0]);
}
sub prefixsum{
	my$self=shift;
	my$r=shift;
	my$s=0;
	while($r>0){
		$s+=$self->[$r-1];
		$r-=$r&-$r;
	}
	return$s;
}
package main;
my($N,$Q)=split$",<>;
my$fenwicktree=FenwickTree->new($N);
my@a=split$",<>;
for(0..$#a){
	$fenwicktree->add($_,$a[$_]);
}
for(1..$Q){
	my($t,$a,$b)=split$",<>;
	if($t==0){
		$fenwicktree->add($a,$b);
	}
	else{
		print$fenwicktree->sum($a,$b),$/;
	}
}


Measured memory_bytes: 69048
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
int n, a, b;
int main() {
	scanf("%d%d%d", &n, &a, &b);
	if(n < a + b - 1 || n > 1ll * a * b) { puts("-1"); return 0; }
	if(a == 1) {
		for(int i=n; i>=1; i--) printf("%d ", i);
		return 0;
	}
	if(b == 1) {
		for(int i=1; i<=n; i++) printf("%d ", i);
		return 0;
	}
	for(int i=b; i>=1; i--) printf("%d ", i);
	int curr = b + 1;
	for(int i=0; i<a-1; i++) {
		int len = ((n - curr + 1) + a - i - 2) / (a - i - 1);
		for(int j=curr+len-1; j>=curr; j--) printf("%d ", j);
		curr += len;
	}
	return 0;
}

Measured memory_bytes: 2176
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[2];
            string[] s = Console.ReadLine().Split(' ');
            a[0] = int.Parse(s[0]);
            a[1] = int.Parse(s[1]);
            int b = a[0] * a[1];
            int c = 2 * (a[0] + a[1]);
            Console.WriteLine(b + " " + c);
        }
    }
}

Measured memory_bytes: 8984
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    string s;
    cin >> s;
    ll sum = 0;
    rep(i,s.size()){
        sum += (s[i] - '0');
        sum %= 9;
    }
    if(sum == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3732
import math
def count_div(n):
    ans=0
    u = int(math.sqrt(n))+1
    for i in range (1,u):
        if n%i==0:
            ans+=2
    return ans

n = int(input())
res=0
for i in range (1,n+1):
    if i%2==0:
        continue
    if count_div(i)==8:
        res+=1
print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;cin >> N;
    vector<int> a(N);
    rep(i,N)cin >> a[i];
    int sum = 0;
    rep(i,N)sum+=a[i];
    int m=a.size();
    int k = round(sum/(double)m);
    int res = 0;
    rep(i,N){
        res+=(a[i]-k)*(a[i]-k);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
/**
 *    author:  Atreus
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
vector<int> g[maxn], topol;
bool visited[maxn];
int dp[maxn];

void dfs(int v){
	visited[v] = 1;
	for (auto u : g[v])
		if (!visited[u])
			dfs(u);
	topol.push_back(v);
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int v, u;
		cin >> v >> u;
		g[v].push_back(u);
	}
	for (int v = 1; v <= n; v++)
		if (!visited[v])
			dfs(v);
	for (auto v : topol){
		for (auto u : g[v]){
			dp[v] = max(dp[v], dp[u] + 1);
		}
	}
	cout << *max_element(dp + 1, dp + n + 1) << endl;
}


Measured memory_bytes: 8824
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  int h,w;cin>>h>>w;
  char s[h][w];
  rep(i,h)rep(j,w) cin>>s[i][j];
  vector<int> dx,dy;
  int ans=0;
  dx={1,0,-1,0};
  dy={0,1,0,-1};
  queue<P> q;
  rep(i,h){
    rep(j,w){
      int dist[h][w];
      rep(l,h)rep(k,w) dist[l][k]=-1;
      if(s[i][j]=='#') continue;
      q.push(P(i,j));
      dist[i][j]=0;
      while(!(q.empty())){
        P now=q.front();q.pop();
        rep(l,4){
          int nx=now.fi+dx[l];
          int ny=now.se+dy[l];
          if(nx<0||ny<0||nx>=h||ny>=w) continue;
          if(s[nx][ny]=='.'&&dist[nx][ny]==-1){
            q.push(P(nx,ny));
            dist[nx][ny]=dist[now.fi][now.se]+1;
            ans=max(dist[nx][ny],ans);
          }
        }
      }
    }
  }
  
  cout<<ans<<endl;
}
            

Measured memory_bytes: 256
# Q2
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a_list = LI()

total = 0
for i in range(len(a_list)):
    if (i+1) % 2 == 1 and a_list[i] % 2 == 1:
        total += 1
print(total)

Measured memory_bytes: 9120
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 10000000
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[200010], ans[200010];
signed main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	for (int i = n; i >= 1; i--) {
		int cnt = 0;
		for (int j = 2 * i; j <= n; j += i)cnt += ans[j];
		if (cnt % 2 != a[i] % 2)ans[i]++;
	}
	vector<int> vec;
	REP(i, n) {
		if (ans[i])vec.push_back(i);
	}
	cout << vec.size() << endl;
	if(!vec.empty())cout << vec[0];
	REP(i, (int)vec.size() - 1)cout << " " << vec[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 4852
N = int(input())
xyh = [list(map(int,input().split())) for i in range(N)]
for i in range(N):
    if xyh[i][2] != 0:
        xs, ys, hs = xyh[i]
for xt in range(101):
    for yt in range(101):
        ht = hs + abs(xt - xs) + abs(yt - ys)
        if all([xyh[i][2] == max(0, ht - abs(xt-xyh[i][0]) - abs(yt-xyh[i][1])) for i in range(N)]):
            xa, ya, ha = xt, yt, ht
print(xa,ya,ha)

Measured memory_bytes: 3064
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,A,B,C = readInts()
    L = [] * n
    for i in range(n):
        l = int(input())
        L.append(l)

    def rec(i,a,b,c):
        if i == n:
            if not a or not b or not c:
                return float('inf')
            return abs(a-A) + abs(b-B) + abs(c - C)
            # 一番最後まで行ったら、その差が延長魔法や短縮魔法を使うMPであるからこうする

        # 今ある竹を採用しない場合
        res = rec(i+1, a, b, c)

        # A,B,Cを使う場合 (どこにどれを足す？)
        # 1本目はコストなし、2本目からコスト10
        res = min(res,rec(i+1,a+L[i],b,c) + (10 if a >= 1 else 0)) # aにL[i]を足す
        res = min(res,rec(i+1,a,b+L[i],c) + (10 if b >= 1 else 0)) # bにL[i]を足す
        res = min(res,rec(i+1,a,b,c+L[i]) + (10 if c >= 1 else 0)) # cにL[i]を足す
        return res

    print(rec(0,0,0,0))


if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
const int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
typedef long long ll;
const int N=805;
int n,m,K,dis[N][N];
char mp[N][N];
using namespace std;

struct node
{
	int x,y;
};
queue<node> Q;
int main()
{
	#ifdef Kay
		freopen ("code.in","r",stdin);
		freopen ("code.out","w",stdout);
	#endif
	scanf ("%d %d %d",&n,&m,&K);
	int i,j;
	for (i=1;i<=n;i++) scanf ("\n%s",mp[i]+1);
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		if (mp[i][j]=='S') break;
		if (j<=m) break;
	}
	int s=i,t=j,nx,ny;
	memset(dis,-1,sizeof(dis));
	Q.push((node){i,j});dis[i][j]=0;
	while (!Q.empty())
	{
		node now=Q.front();Q.pop();
		for (i=0;i<4;i++)
		{
			nx=now.x+dx[i],ny=now.y+dy[i];
			if (nx<1 || ny<1 || nx>n || ny>m) continue;
			if (mp[nx][ny]=='#') continue;
			if (dis[nx][ny]==-1){dis[nx][ny]=dis[now.x][now.y]+1;Q.push((node){nx,ny});}
		}
	}
	int ans=n*m;
	for (i=1;i<=n;i++)
	for (j=1;j<=m;j++)
	if (mp[i][j]!='#' && dis[i][j]<=K && dis[i][j]!=-1)
	{
		if (i==1 || i==n || j==1 || j==m) ans=1;
		else ans=min(ans,(min(min(i-1,n-i),min(j-1,m-j))-1)/K+1+1);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3584
import Control.Applicative
import Data.Function
import Control.Monad
import Data.List
import Data.Char
import Text.Printf

t :: [Double] -> [Double]
t [a,b,c] = [s,l,h]
    where s  = (a*b*(sin cr)/2)
          l  = a+b+(sqrt (a^2+b^2-2*a*b*cos cr))
          h  = b*(sin cr)
          cr = c*pi/180

main :: IO ()
main = do
    a <- map read . words <$> getLine
    let [s,l,h] = t a
    printf "%.10f %.10f %.10f\n" s l h


Measured memory_bytes: 4200
//dp(i , x)  -> on tossing first i coins probabilty of getting heads >= x
//dp(N , (N+1)/2) -> we need atlest (N+1)/2 heads
//dp(i ,  x) = pi*dp(i-1 , x-1) + (1-pi)*dp(i-1 , x)
//base case dp(0 ,x) = 0 where x!=0 and dp(0 , 0) = 1
#include <bits/stdc++.h>
using namespace std;
double dp[3002][3002];
double solve(double *a , int i , int x){
    if(x == 0){
        return 1;
    }
    if(i == 0){
        return 0;
    }
    if(dp[i][x] > -0.9){
        return dp[i][x];
    }
    return dp[i][x] = a[i]*solve(a , i-1 , x-1) + (1-a[i])*solve(a , i-1 , x);
}
int main() {
    memset(dp , -1 , sizeof(dp));
    int n;
    cin>>n;
    double a[n+1];
    for(int i=1 ; i<=n ; i++){
      cin>>a[i];
    }
    cout<<fixed<<setprecision(10)<<solve(a , n , (n+1)/2);
    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;

    int len = s.length();
    int j = 0;
    for(int i = 0; i < len; i++) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = s.back() + s.substr(0, s.length()-1);
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define mn(a,b) (a < b ? a : b)
#define mx(a,b) (a > b ? a : b)
#define f first
#define s second
#define mp make_pair
#define all(v) (v).begin(),(v).end()

using namespace std;

int const MAXn = 1e5 + 10;
int arr[MAXn];
unordered_map < int , int > mapa;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
        mapa[arr[i]]++;
        mapa[arr[i] - 1]++;
        mapa[arr[i] + 1]++;
    }
    int best = 0;
    for(int i = 0; i < n; i++)
        best = mx(best, mapa[arr[i]]);
    cout<<best;
    return 0;
}


Measured memory_bytes: 4644
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>

using namespace std;
//max heap size
#define N 2000001

int heap_size=0;
int key[N];

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

//function maxHeapify
void maxHeapify(int i){
  int l,r,largest;
  int st;
 
  l=leftc(i);
  r=rightc(i);

  if(l<=heap_size && key[l]>key[i]) largest=l;
  else largest=i;
 
  if(r<=heap_size && key[r]>key[largest]) largest=r;
 
  if(largest!=i){
    st=key[i];
    key[i]=key[largest];
    key[largest]=st;
    maxHeapify(largest); 
  }
}

//function heap increase key
int heapIncreaseKey(int i,int data){
  int st;
  if(data<key[i]) return -1;
  key[i]=data;
  while(i>1 && key[parent(i)]<key[i]){
    st=key[i];
    key[i]=key[parent(i)];
    key[parent(i)]=st;
    i=parent(i);
  }
  return 0;
}

//function max heap insert
void maxHeapInsert(int data){
  heap_size++;
  key[heap_size]=-2147483648;
  heapIncreaseKey(heap_size,data);
}

//function extract
int heapExtractMax(void){
  int max;

  if(heap_size <1) return -1;
  max=key[1];
  key[1]=key[heap_size];
  heap_size--;
  maxHeapify(1);
  return max;
}

int main(){

  int data;
  char str[10];
  int st;

  while(1){
    //load string
    scanf("%s",str);
    //insert
    if(str[0]=='i'){
      scanf("%d",&data);
      maxHeapInsert(data);
    }
    //extract
    else if(strcmp("extract",str)==0){
      st=heapExtractMax();
      if(st!=-1) printf("%d\n",st);
    } 
    //end
    else break;
  }

  return 0;
}

Measured memory_bytes: 4796
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0
for i in range(n):
  s = input()
  if s[0] == "M":
    m += 1
  if s[0] == "A":
    a += 1
  if s[0] == "R":
    r += 1
  if s[0] == "C":
    c += 1
  if s[0] == "H":
    h += 1
ans = m * a * r +m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h
print(ans)

Measured memory_bytes: 3064
import math

dp = [float('inf') for _ in range(200000)]
withdraw = []

N = int(input())

#引き出し可能な金額の配列にする
withdraw.append(1)

for i in range(20):
    if 100000 >= 6**i:
        withdraw.append(6**i)
    if 100000 >= 9**i:
        withdraw.append(9**i)

withdraw = sorted(list(set(withdraw)))

dp[0] = 0

for i in range(N+1):
    for j in withdraw:
        dp[i+j] = min(dp[i+j],dp[i]+1)
        
print(dp[N])


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

int main()
{
  int n;
  int s;
  int i;
  
  cin >> n;
  vector<int> a(n); 
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  
  s = 0;
  i = 0;
  while (i < n)
  {
    s = a.at(s) - 1;
    i++;
    if (s == 1)
    {
      cout << i << endl;
      return (0);
    }
  }
  cout << -1 << endl;
  return (0);
}
  

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;


int main (int argc, char const *argv[])
{
    int N;
    cin>>N;

    
    if (N<1000) {
        cout<<"ABC"<<endl;
    }
    else
    {
        cout<<"ABD"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
# ABC130, B - bounding
n, x = map(int, input().split(' '))
L = [int(el) for el in input().split(' ')]

count = 1
d = 0
for i in range(n):
    d += L[i]
    if d <= x:
        count += 1
    else:
        break
print(count)


Measured memory_bytes: 2940