akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long LL;

#define INF 1000000000
#define INF_LL_YJ 1145141919810364364

using namespace std;

#define MAX_N 100005
int N;
string S;

void input()
{
  cin >> N;
  cin >> S;
}

int kind[MAX_N];

void calc(int pos = 1)
{
  int left, right;
  if(pos == 0){
    left = N-1;
  }
  else{
    left = pos-1;
  }
  right = (pos+1)%N;

  int k = kind[left];
  if(kind[pos] == 1){
    if(S[pos] == 'x'){
      if(k == 1){
        k = 2;
      }
      else{
        k = 1;
      }
    }

  }
  else{
    if(S[pos] == 'o'){
      if(k == 1){
        k = 2;
      }
      else{
        k = 1;
      }
    }
  }

  if(kind[right] != 0){
    return;
  }
  else{
    kind[right] = k;
    calc((pos+1)%N);
  }
}

bool check(int pos = 0)
{
  if(pos == N){
    return true;
  }

  int left = pos - 1, right = (pos+1)%N;
  if(left < 0){
    left = N-1;
  }

  int k = kind[left];
  if(kind[pos] == 1){
    if(S[pos] == 'x'){
      if(k == 1){
        k = 2;
      }
      else{
        k = 1;
      }
    }
  }
  else{
    if(S[pos] == 'o'){
      if(k == 1){
        k = 2;
      }
      else{
        k = 1;
      }
    }
  }

  if(k != kind[right]){
    return false;
  }

  return check(pos+1);
}

int main()
{
  input();

  for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 2; j++) {
      memset(kind, 0, sizeof(kind));
      kind[0] = i; kind[1] = j;
      calc();
      if(check()){
        for (int k = 0; k < N; k++) {
          if(kind[k] == 1){
            cout << "S";
          }
          else{
            cout << "W";
          }
        }
        cout << endl;
        return 0;
      }
    }
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	if(n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}





Measured memory_bytes: 256
#include "math.h"
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<vector>

using namespace std;

int main(void){
    int N,K;
	string S,ans;

    cin>>N;
    cin>>S;
    cin>>K;
	
	ans=S;

	for(int i=0;i<N;i++){
		if(S[K-1] != S[i]){
			ans[i] = '*';
		}
	}
    
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;
		static T MIN<T>(params T[] args) => args.Min();
		static T MAX<T>(params T[] args) => args.Max();

		static void Main(string[] args)
		{
			var n = R;
			var a = R;
			var b = R;
			var c = R;
			int count = 0;
			for(int i = 0;i < a.Length;i++)
			{
				if (a[i] == b[i] && b[i] == c[i]) continue;
				else if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i]) count++;
				else  count += 2;
			}
			Out(count);
		}
	}
}


Measured memory_bytes: 11092
from collections import defaultdict
N = int(input())
S = input()

cnt = defaultdict(int)
for i in range(N):
    s = S[i]
    cnt[s] += 1

ans = cnt["R"] * cnt["G"] * cnt["B"]

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if 2 * j - i < N:
            if S[i] != S[j] and S[i] != S[2 * j - i] and S[j] != S[2 * j - i]:
                ans -= 1
        else:
            break

print(ans)

Measured memory_bytes: 68812
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf int = 1050000000

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	h := make([]int, n)

	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		costmin := inf
		for j := max(i-k, 0); j < i; j++ {
			nowcost := dp[j] + abs(h[i]-h[j])
			costmin = min(costmin, nowcost)
		}

		dp[i] = costmin
	}

	fmt.Println(dp[n-1])

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4120
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int f(const vector<int>& a, int b){
    int x = 0;
    rep(i, (int)a.size()){
        x += abs(a[i] - (b+i+1));
    }
    return x;
}

int binary_search(const vector<int>& a){
    // 関数f(下に凸)の極小値
    int lo = -1e9;
    int hi = 1e9;
    while(hi - lo > 1){
        int m = (lo + hi) / 2;
        if(f(a, m) >= f(a, m+1)){
            lo = m;
        }else{
            hi = m;
        }
    }
    return f(a, hi);
}

signed main(){
    int n;
    cin >> n;

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

    cout << binary_search(a) << endl;

    return 0;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc163/tasks/abc163_b

#include <iostream>
using namespace std;

int main(){
	int n, m, i, s;
	cin >> n >> m;
	s = 0;
	while(m-->0){
		cin >> i;
		s += i;
	}
	if(s<=n) cout << n-s << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
import java.math.BigInteger;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    BigInteger A[] = new BigInteger[N];
    BigInteger big = new BigInteger("1000000000000000000");
    BigInteger result = BigInteger.ONE;
    BigInteger zero = new BigInteger("0");
    int K = 0;
    for (int i = 0;i < N;i++) {
      A[i] = scan.nextBigInteger();
      if (A[i].compareTo(zero) == 0) {
        K = i;
      }
    }
    if (K > 0) {
      for (int i = K;i < N;i++) {
        result = result.multiply(A[i]);
        if (result.compareTo(big) > 0) {
          System.out.println(-1);
          return;
        }
      }
    }
    else{
      for (int i = 0;i < N;i++) {
        result = result.multiply(A[i]);
        if (result.compareTo(big) > 0) {
          System.out.println(-1);
          return;
        }
      }
    }
    System.out.println(result);
  }
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m;
  cin >> n >> m;
  vector<pair <int, pair<int,int>>> a(m);
  for (int i = 0; i < m; i++) {
      cin >> a[i].second.first >> a[i].first;
      a[i].second.second = i;
  }
  sort(a.begin(), a.end());
  map<int, int> pref_cnt;
  vector<pair<int, int>> pref_city(m);
  for (int i = 0; i < m; i++) {
      int pref = a[i].second.first;
      int city = ++pref_cnt[pref];
      int index = a[i].second.second;
      pref_city[index].first = pref;
      pref_city[index].second = city;
  }
  for (auto &i : pref_city) {
      printf("%06d%06d\n", i.first, i.second);
  }
  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define deb(x) cout<<#x<<" "<<x<<"\n"
using namespace std;
string s1,s2,u;
int x1,x2;
int main(){
    cin>>s1;
    int l=s1.length();
    while(l--){
        cout<<"x";
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<int> H(N);
    int i;
    for(i=0; i<N; i++) cin >> H.at(i);

    for(i=N-2; i>=0; i--){
        if(H.at(i+1) < H.at(i)) H.at(i)--;
    }

    for(i=0; i<N-1; i++){
        if(H.at(i) > H.at(i+1)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 640
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS
int x,y;
cin>>x>>y;
int k=0;
for(ll i=0;i<=x;i++)
{
    if((i*2)+((x-i)*4)==y)
    {
        cout<<"Yes";
        return 0;
    }
}
cout<<"No";
return 0;
}


Measured memory_bytes: 3612
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = []
for l in range(N):
    b = 0
    for r in range(l, N):
        b += A[r]
        B.append(b)
B.sort(reverse=True)
#print(B)

def trans2(n):
    A = bin(n)
    return str(A[2:])

C = []
maxl = 0
for i, b in enumerate(B):
    l = len(trans2(b))
    if i+1 <= K:
        maxl = l
    if i+1 > K and maxl != l:
        break
    C.append(trans2(b))
#print(C)
OK = [1 for _ in range(len(C))]

ans = 0
for l in range(maxl-1, -1, -1):
    update = []
    for i, c in enumerate(C):
        if c[-l-1] == '0' and OK[i] == 1:
            update.append(i)
            OK[i] = 0
    oks = sum(OK)
    if oks < K:
        for u in update:
            OK[u] = 1
    else:
        ans += 2**l
print(ans)
    

Measured memory_bytes: 42412
import itertools
N,M = map(int,input().split())
switch = [list(map(int,input().split())) for m in range(M)]
p = list(map(int,input().split()))
# スイッチのONとOFFの組合せ(1がONで0がOFF)
S = list(itertools.product([0,1], repeat=N))
ans = 0
for s in S:
    s_ok = 0
    # 全ての電球に対して
    for m in range(M):
        count = 0
        # 1つの電球の全てのスイッチに対して
        for i in range(1, switch[m][0]+1):
            if s[switch[m][i]-1] == 1:
                count += 1
        if count%2 == p[m]:
            s_ok += 1
        else:
            break
    if s_ok == M:
        ans += 1
print(ans)


Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int64 n;
  cin >> n;
  if (n % 2) {
    cout << 0 << endl;
  } else {
    n /= 2;
    int64 ret = 0;
    for (; n; n /= 5) ret += n / 5;
    cout << ret << endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val (M, D) = readLine()!!.split(" ").map { it.toInt() }

    var answer = 0
    (1..M).forEach { m ->
        (22..D).forEach { d->
            val d1 = d % 10
            val d10 = d / 10
            if (d1 * d10 == m && d1 > 1) {
                answer++
            }
        }
    }
    println(answer)
}

Measured memory_bytes: 38028
#include <cstdlib>  
#include <iostream>  
  
using namespace std;  
  
int main()  
{  
	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
		{
	       cout << i << "x" << j << "=" << i*j << endl;  
		}
	}
	return 0;  
}   

Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	ll mi=min(a,b),ma=max(a,b);
	for(ll i=0;i<ma;i++){
		cout << mi;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N = input()
A,B = map(int, raw_input().split())
C = input()
D = [input() for _ in range(N)]
D = sorted(D)[::-1]
price = A
cal = C
ans = cal/price
for d in D:
    cal += d
    price += B
    ans = max(ans, cal/price)
print ans

Measured memory_bytes: 6364
import math
h, w = map(int, input().split())
 
if h == 1 or w == 1:
  count = 1
else:
  if w % 2 == 0:
    count = int(w / 2) * h
  else:
    c1 = int(math.ceil(w / 2))
    c2 = int(math.floor(w / 2))
    if h % 2 == 0:
      count = (c1 + c2) * int(h / 2)
    else:
      count = (c1 + c2) * int(math.floor(h / 2)) + c1
print(count)

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

bool compare(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);
    vector<pair<int, int>> red(n);
    vector<pair<int, int>> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i) >> b.at(i);
        red.at(i) = make_pair(a.at(i), b.at(i));
    }
    for (int i = 0; i < n; i++) {
        cin >> c.at(i) >> d.at(i);
        blue.at(i) = make_pair(c.at(i), d.at(i));
    }    
    
    sort(begin(red), end(red), compare);
    sort(begin(blue), end(blue));

    vector<bool> red_used(n, false);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (red_used.at(j)) {
                continue;
            }
            int blue_x = blue.at(i).first;
            int blue_y = blue.at(i).second;
            int red_x = red.at(j).first;
            int red_y = red.at(j).second;
            if (blue_x > red_x && blue_y > red_y) {
                red_used.at(j) = 1;
                ans++;
                break;
            }
        }
    }

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

Measured memory_bytes: 3584
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();

    if c >= a && c <= b {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
// ARC 077D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int mod = 1000*1000*1000+7;
int Pow(int x,int k)
{
	if(k==0)
		return 1;
	LL res;
	res=Pow(x,k/2);
	res=(LL)(res*res)%mod;
	if(k&1)
		res=(LL)(res*x)%mod;
	return res;
}
int a[111111];
int main()
{
	int n,i,x,f,l,r,m;
	LL c,cc;
	cin>>n;
	n++;
	f=-1;
	for(i=1;i<=n;i=i+1){
		cin>>x;
		if(x>=n)
			f=0;
		else{
			if(a[x]){
				f=x;
				l=a[x];
				r=i;
			}
			else
				a[x]=i;
		}
	}
	m=n+l-r-1;
	c=1;
	cc=1;
	for(i=1;i<=n;i=i+1)
	{
		c*=(n+1-i);
		c%=mod;
		c*=Pow(i,mod-2);
		c%=mod;
		if(i>1&&i<=m+2&&f){
			cc*=(m+2-i);
			cc%=mod;
			cc*=Pow(i-1,mod-2);
			cc%=mod;
		}
		if(f)
			cout<<(c+mod-cc)%mod<<endl;
		else
			cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long int

using namespace std ;

const int N = 2e6 + 100 ;
int n , a[N] , dp[N] ;

int32_t main(){
	cin >> n ;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i] ;
	}
	//reverse(a , a + n) ;
	dp[0] = dp[1] = 0;
	dp[2] = abs(a[0] - a[1]) ; 
	for(int i = 3 ; i <= n ; i++){
		dp[i] = min(abs(a[i - 1] - a[i - 2]) + dp[i - 1] , abs(a[i - 1] - a[i - 3]) + dp[i - 2]) ;
	}
	cout << dp[n] << '\n' ;
	return 0 ;
}
/*
#include <radman/roderc++.h>
                     ....._____
                 .~~~~~////////\\                                                                                           ...
              .:::::////////////\\                                          ....::////////..                              (/\\\\...
           .::::://////   \\\\///\\              .:::://                ..:::::///////////////.                           \\\\\$$$$$$
         \\\\\//////      \\\\///\\           //\\\//////             \\\\\////////////////////.                           ""\\$$$$$$$
         \\\\\////         \\\\////         |||||////////.            \\\\\/////     ~~~~~//////          ...                  "\$$$$
         \\\\\//\         ////|||/          \\\\\/////////            \\\\\//\       ~~~~~//////        (/\\\\...                   .
         \\\\\//\        ////|||/          |||||////*\\///.           \\\\\//\       ~~~~~//////        \\\\\$$$$$$                 .@@@@@.
         \\\\\//\       ////|||/           \\\\\///|\\\////           \\\\\//\       ~~~~~//////         ""\\$$$$$$$               @@@@////\
         \\\\\//\ ____---/|||/            |||||///|\\\\\///.          \\\\\//\       ~~~~~//////             "\$$$$                @@@@\///\
         \\\\\//\--|||||||_-'             \\\\\///|\\\\\////          \\\\\//\       ~~~~~//////                                  ,@@@@|///|
         \\\\\//\|||||_"-\\\\\           |||||///|  ~~~~~///.         \\\\\//\      ~~~~~//////     .@@@@.                    /@@@@@|/////
         \\\\\//\///"""\\\\\\\\          \\\\\///|~~~~[[[////.        \\\\\//\     ~~~~~//////      @@@@@@@@                ..@@@@@.//////
         \\\\\//\    \"""\\\\\\\        |||||///|~~[[[[["\////.       \\\\\//\    ~~~~~//////      '@@@@/////\       .:;@@@@@@@..///////"
         \\\\\//\      \"""\\\\\\       \\\\\///|[[[[*\\\\\////.      \\\\\//\   ~~~~~//////        *@@@\//////\@@@@@@@@..//////////"
         \\\\\//\       \:::\\\\/      |||||///|[[[*   \\\\\\///      \\\\\//\~~~~~///////'            *@@\/////////////////////"
         \\\\\//\        \___\\/       \\\\\///|*       \\\\\/"       \\\\\//\~~////////'                 **"///////////"""
         \\\\\//\                     |||||///|                       \\\\\//\///////"
         \\\\\//\                     \\\\\///|                       \\\\\//\////"
         \\\\\///                    |||||////|                       \\\\\////"
         \\\\\/"                     \\\\\///*                        \\\\\/"
                                     """""*
*/


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

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;

  long long count_c = (b / c) - (a / c) + (a % c == 0);
  long long count_d = (b / d) - (a / d) + (a % d == 0);
  long long g = gcd(c, d);
  long long e = g * (c / g) * (d / g);
  long long count_cd = (b / e) - (a / e) + (a % e == 0);
  // cout << "C  " << count_c << endl;
  // cout << "D  " << count_d << endl;
  // cout << "CD " << count_cd << endl;

  cout << b - a - count_c - count_d + count_cd + 1 << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<long long int> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  
  if (N == 1) cout << T.at(0) << endl;
  else {
    long long int ans = T.at(0) / __gcd(T.at(0), T.at(1)) * T.at(1);
    for (int i = 2; i < N; i++) ans = ans / __gcd(ans, T.at(i)) * T.at(i);
    cout << ans << endl;
  }
}

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

int main() {
    string s; cin >> s;
    string t = "CODEFESTIVAL2016";
    int ans = 0;
    for (int i = 0; i < 16; i++) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
  n = input()
  if n==0: break
  s = 0
  for _ in [0]*n:
    x,y,h,w = map(int, raw_input().split())
    rank = max(max(5-(160-x-y-h)/20,0), [0,5-(25-w)/5][w>2])
    if rank < 6: s+= 600 + rank*200
  print s

Measured memory_bytes: 4276
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    c, d = (int(_) for _ in input().split())      
    print(((c-1)*(d-1)))
    
if __name__ == '__main__':
    main()


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

void NO(int where = 0) {
//   dump(where);
  cout << -1 << endl;
  exit(0);
}

// 解けた〜たぴゃ〜 (ちょっとミスってたけど)
// D_iは相異なる，まじか〜

const int N = 1e5;
vector<vector<int>> g(N);
using Value = ll;
map<int, Value> dp[N];
map<int, int> sz[N];
int n;
Value dfs(int i, int p, int f = 0) {
  if(dp[i].count(p)) return dp[i][p];
  int cnt = 0;
  Value res = 0;
  if(f || p == -1) {
    // O(deg(i))
    // go only child
    sz[i][p] = 1;
    for(int j : g[i]) if(j != p) {
      cnt++;
      res += dfs(j, i, f);
      res += sz[j][i];
      sz[i][p] += sz[j][i];
    }
  } else {
    // O(1)
    dfs(i, -1, f);
    dfs(p, i, f);
    res = dp[i][-1] - (dp[p][i] + sz[p][i]);
    cnt = g[i].size() - 1;
    sz[i][p] = sz[i][-1] - sz[p][i];
  }
  return dp[i][p] = res;
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<ll> d(n);
  for(int i = 0; i < n; i++) cin >> d[i];
  vector<int> ord(n);
  iota((ord).begin(), (ord).end(), 0);
  sort((ord).begin(), (ord).end(), [&](int i, int j) { return d[i] < d[j]; });
  map<ll, int> mp;
  for(int i = 0; i < n; i++) mp[d[i]] = i;
  auto rnk = ord;
  for(int i = 0; i < n; i++) rnk[ord[i]] = i;
  vector<int> v(n);
  vector<pair<int,int>> ans;
  ll base = n - 2 * (n - 1);
  for(int i = n - 1; i >= 1; i--) {
    // dump(d[ord[i]], v[i], i);
    ll s = d[ord[i]] + (base + v[i] * 2);
    // dump(s);
    if(s >= d[ord[i]]) NO(1);
    if(!mp.count(s)) NO(2);
    v[rnk[mp[s]]] += v[i] + 1;
    int a = mp[s], b = ord[i];
    // dump(a, b);
    ans.emplace_back(a, b);
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  // dump("here");
  dfs(0, -1, 1);
  for(int i = 0; i < n; i++) if(d[i] != dfs(i, -1, 0)) NO();
  for(int i = 0; i < n - 1; i++) cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  return 0;
}


Measured memory_bytes: 74612
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin>>s;
  bool ok=false;
  REP(i,3) if (s[i] == '7') ok=true;
  cout<<(ok?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
    // Your code here!
    ll x,y;
    cin>>x>>y;
    if(!(2*y>=x && (2*y-x)%3==0 &&2*x>=y && (2*x-y)%3==0)){
        cout<<0<<endl;
        return 0;
    }
    ll n1=(2*y-x)/3, n2=(2*x-y)/3;
    COMinit();
    cout<<COM(n1+n2,n1)<<endl;
}

Measured memory_bytes: 23680
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N);
            var rate = new int[9];
            for(int i = 0; i < 9; i++)
            {
                rate[i] = 0;
            }
            for(int i = 0; i < N; i++)
            {
                if(a[i] > 3200)
                {
                    a[i] = 3200;
                }
                rate[a[i] / 400]++;
            }
            var min = 0;
            for(int i = 0; i < 8; i++)
            {
                if(rate[i] != 0)
                {
                    min++;
                }
            }
            var max = min + rate[8];
            if (min != 0)
            {
                WriteLine(min + " " + max);
            }
            else
            {
                WriteLine(1 + " " + max);
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, 0, N) cin >> a[i];
    ll ans = 1000000000LL * 2010;
    vector<int> b(N);
    rep(i, 0, N) b[i] = a[i];
    rep(k, 0, N)
    {
        ll time = 0;
        rep(i, 0, N)
        {
            b[i] = min(b[i], a[((i - k) + N) % N]);
            time += b[i];
        }
        chmin(ans, time + static_cast<ll>(x) * k);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define mp make_pair
const int maxn=2e5;
int a[maxn+5];
double b[maxn+5];
int n,k;
int main()
{

    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        b[i]=(1+a[i])*0.5;
    }
    for(int i=2;i<=n;++i) b[i]+=b[i-1];
    double ans=0.0;
    for(int i=1;i+k-1<=n;++i) ans=max(ans,b[i+k-1]-b[i-1]);
    printf("%.9f\n",ans);
    return 0;
}

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

const int maxn = 1e5+5;
const ll mod = 1e9+9;

ll key(string s){
    ll ans = 0;
    for(int i=0;i<(int)s.length();i++){
        ans = ((ans * 233LL) + s[i]);
    }
    return ans;
}

int main()
{
    int n;
    while(cin>>n){
        string s;
        map<ll, ll>hash;
        for(int i=0;i<n;i++){
            cin>>s;
            sort(s.begin(), s.end());
            ll temp = key(s);
            hash[temp]++;
        }
        ll ans = 0;
        for(auto it:hash){
            ans+=(it.second-1)*(it.second) / 2LL;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6528
N,*M=`dd`.split.map &:to_i;X,Y,*A=M.shift N;D=[*0..1e6];s=0;(N-3).times{|i|s+=A[i];1.upto(A[i]){|j|D.unshift D[j*2-1]}};M.map{|e|p (D[e]||e-s)+X-Y}

Measured memory_bytes: 86848
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	int n;
  	cin >> n;
  	vector<int> a(n);
  	rep(i, n) cin >> a[i];
  
  	ll ans = 0;
  	int h = 0;
  	rep(i, n){
    	h = max(h, a[i]);
      	ans += h - a[i];
    }
  
    cout << ans << endl;
}

Measured memory_bytes: 4040
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MaxN 100010
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
typedef long long LL;
typedef pair<int,int> PII;
typedef unsigned long long ULL;
int A[4];	
string strA;
int main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>strA;
		if( strA == "AC" ) A[0]++;
		if( strA == "WA" ) A[1]++;
		if( strA == "TLE" ) A[2]++;
		if( strA == "RE" ) A[3]++;
	} 
	cout<<"AC x "<<A[0]<<endl;
	cout<<"WA x "<<A[1]<<endl;
	cout<<"TLE x "<<A[2]<<endl;
	cout<<"RE x "<<A[3]<<endl;
	return 0;
}

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

using namespace std;

using Memo = vector<vector<vector<int>>>;

long long solve(string &s, int offset, bool is_less, int nonzero_cnt, Memo &memo) {
  if (offset == s.size()) {
    return nonzero_cnt == 0 ? 1 : 0; 
  } else if (nonzero_cnt < 0) {
    return 0;
  }

  if (memo[offset][is_less][nonzero_cnt] < 0) {
    int digit = s[offset] - '0';
    long long ans = 0;
    for (int i = 0; i <= (is_less ? 9 : digit); i++) {
      ans += solve(s, offset + 1, is_less || i < digit, i != 0 ? nonzero_cnt - 1 : nonzero_cnt, memo);
    }

    memo[offset][is_less][nonzero_cnt] = ans;
  }

  return memo[offset][is_less][nonzero_cnt];
}

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

  Memo memo(n.size() + 1, vector<vector<int>>(2, vector<int>(k + 1, -1)));
  cout << solve(n, 0, false, k, memo) << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    double n,d;
    cin>>n>>d;
    cout<<(int)ceil(n/(2*d+1))<<endl;
    
    return 0;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "strconv"
)

func main() {
  
  //入力値を分割
  var str string
  fmt.Scan(&str)
  var m [4]int
  for i := 0; i < 4; i++ {
    m[i],_ = strconv.Atoi(string(str[i]))
  }
  
  //+,-を格納
  var s [3]string
  
  //全パターン試して正解を見つけたら終了
  for i := 0; i < 8; i++ {
    ans := m[0]
    for j := 0; j < 3; j++ {
      p := i & (1<<(uint(j))) 
      if p == 0 {
        s[j] = "-"
        ans -= m[j+1]
      } else {
        s[j] = "+"
        ans += m[j+1]
      }
    }
    if ans == 7 { 
      fmt.Printf("%d%s%d%s%d%s%d=7", m[0], s[0], m[1], s[1], m[2], s[2], m[3])
      break
    }
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
long long int n,i,j,m,sum[200000],sumend,dr,aa[2006811],ch,v[2006811],c[2006811],s1[2006811],s2[2006811],a,b,c1,k;
bool cmp(int a,int b)
{
	return a>b;
}
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
long long int maxx(int a,int b)
{
    if(a>=b)
        return a;
    return b;
}
long long int lhd(long long int a)
{
	if(a<=0)
		return -a;
	return a;
}
long long int lhdmin(long long int a,long long int b)
{
	if(a<=b)
		return a;
	return b;
}
long long int dcecs(long long int n)
{
	if(n<2)
		return 0;
	if(n==2)
		return 1;
	for(int i=3;i<=sqrt(n);i+=2)
		if(n%i==0)
			return 0;
	return 1;
}
bool gqt(int x,int y)
{
	if(x+y==-2)
		return 1;
	if(x!=-1&&y!=-1&&v[x]==v[y]&&gqt(s2[x],s1[y])&&gqt(s1[x],s2[y]))
		return 1;
	return 0;
}
void xjbs(int n)
{
	c[n]=1;
	if(s1[n]!=-1)
	{
		xjbs(s1[n]);
		c[n]+=c[s1[n]];
	}
	if(s2[n]!=-1)
	{
		xjbs(s2[n]);
		c[n]+=c[s2[n]];
	}	
}
long long int minnn(long long int a,long long int b)
{
    if(a<=b)
        return a;
    return b;
}
long long int gqt(long long int b,long long int p,long long int k)
{
    /*if(p==0)
        return 1;
    if(k==1)
        return 0;
    if(b%2==1)
        return gqt(b,p/2,k)%k*b%k*gqt(b,p/2,k)%k;
    else if(b%2==0)
        return gqt(b,p/2,k)%k*gqt(b,p/2,k)%k;*/
    long long int sum=1;
    while(p!=0)
	{
	    if(p%2==1)
		{
			sum*=b;
			sum%=k;
		}
		b*=b;
		b%=k;	
		p/=2;
	}
	return sum;
}
const int k1=1e9+9;
string a1,a2;
long long int la2,x1,x2,x3,flag[205]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
//long long int n,m,i,j,sum,sumend,a[71720],b,la,left1[71720],right1[71720],dp[5271720],maxx,minn,sj,x,y,p;
int main()
{
    /*cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>aa[i];
    for(i=1;i<=n;i++)
        sum[i]=sum[i-1]+aa[i];
    for(i=k;i<=n;i++)
        sumend=maxx(sumend,sum[i]-sum[i-k]);
    cout<<sumend<<endl;*/
    /*cin>>a1;
    int la=a1.size();
    for(i=0;i<la;i++)
    {
        if(a1[i]=='0')
        {
            a2[la2]='0';
            la2++;
            //break;
        }
        if(a1[i]=='1')
        {
            a2[la2]='1';
            la2++;
            //break;
        }
        if(a1[i]=='B')
            if(la2!=0)
            {
                la2--;
                //break;
            }
                
    }
    for(i=0;i<la2;i++)
        cout<<a2[i];
    cout<<endl;*/
    cin>>x1>>x2>>x3;
    for(i=1;i<=10000;i++)
        if(x1*i%x2==x3)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int N = int.Parse(Console.ReadLine());
			int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] L = new int[N + 1];
			int[] R = new int[N + 1];
			for (int i = 0; i < N; i++) {
				L[i + 1] = (int)GCD(L[i], A[i]);
				R[N - 1 - i] = (int)GCD(R[N - i], A[N - 1 - i]);
			}
			int ans = 0;
			for (int i = 0; i < N; i++) {
				ans = Math.Max(ans, (int)GCD(L[i], R[i + 1]));
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		#region 最大公約数 long GCD(long a, long b)
		public static long GCD(long a, long b)
		{
			if (b == 0) { return a; }

			long tmp = a % b;
			while (tmp != 0) {
				a = b;
				b = tmp;
				tmp = a % b;
			}
			return b;
		}
		#endregion

	}
}

Measured memory_bytes: 29020
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,u,v,ans=0;
vector<int> adj[maxn];

void dfs(int u, int pa){
    if(pa==-1) ans+=(u+1)*(n-u);
    else if(pa>u) ans+=(u+1)*(pa-u);
    else ans+=(u-pa)*(n-u);
    for(auto v: adj[u]) if(v!=pa) dfs(v,u);
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    rep(n-1){
        cin >> u >> v;
        u--,v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(0,-1);
    print1(ans);
    return 0;
}


Measured memory_bytes: 23804
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;
char str[N];
int n;
int sum;
void addnine(){
    int carry = 9;
    for(int i = 0 ; carry ; ++i){
        sum -= str[i];
        carry += str[i];
        str[i] = carry % 10;
        carry /= 10;
        sum += str[i];
    }
}
void multnine(){
    int carry = 0;
    for(int i = 0 ; i < n || carry; ++i){
        carry += 9 * str[i];
        str[i] = carry % 10;
        carry /= 10;
        sum += str[i];
    }
}
int main(){
    scanf("%s" , str);
    n = strlen(str);
    reverse(str , str + n);
    sum = 0;
    for(int i = 0 ; i < n ; ++i){
        str[i] -= '0';
    }
    for(int i = n ; i < N ; ++i){
        str[i] = 0;
    }
    multnine();
    for(int k = 1 ; k <= n ; ++k){
        addnine();
        if(sum <= k * 9){
            printf("%d\n" , k);
            return 0;
        }
    }
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
const int mod=1e9+7;
void solve()
{
  int n;
  cin>>n;
  vector<ll> V(n);
  for(int i=0;i<n;i++)
    cin>>V[i];
  ll x=0;
  for(int i=0;i<n;i++)
  x^=V[i];

  vector<int> ans;
  for(int i=0;i<n;i++)
  ans.pb(V[i]^x);

  for(int i=0;i<n;i++)
  cout<<ans[i]<<" ";
  cout<<endl;

}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 5816
N, M = map(int, input().split())
im = [0] * (N + 1)
for i in range(M):
    l, r = map(int, input().split())
    im[l - 1] += 1
    im[r] -= 1
for i in range(N):
    im[i + 1] += im[i]
ans = 0
for i in range(N):
    if im[i] == M:
        ans += 1
print(ans)

Measured memory_bytes: 6900
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int p = s.length() - 1;
    String ans = "NO";
//    String str = "";
    while(p >= 0) {
      if(s.charAt(p) == 'm') {
//        str = "dream" + str;
        p -= 5;
      } else if(s.charAt(p) == 'e') {
//        str = "erase" + str;
        p -= 5;
      } else if(s.charAt(p) == 'r') {
        p -= 2;
        if(p >= 0) {
          if(s.charAt(p) == 'm') {
            if(p >= 4) {
              if((s.charAt(p - 4) == 'd') && (s.charAt(p - 3) == 'r') && (s.charAt(p - 2) == 'e') && (s.charAt(p - 1) == 'a') && (s.charAt(p) == 'm') && (s.charAt(p + 1) == 'e') && (s.charAt(p + 2) == 'r')) {
 //               str = "dreamer" + str;
                p -= 5;
              } else {
                break;
              }
            } else {
              break;
            }
          } else if(s.charAt(p) == 's') {
            if(p >= 3) {
              if((s.charAt(p - 3) == 'e') && (s.charAt(p - 2) == 'r') && (s.charAt(p - 1) == 'a') && (s.charAt(p) == 's') && (s.charAt(p + 1) == 'e') && (s.charAt(p + 2) == 'r')) {
 //               str = "eraser" + str;
                p -= 4;
              } else {
                break;
              }
            } else {
              break;
            }
          } else {
            break;
          }
        } else {
          break;
        }
      } else {
        break;
      }
    }
    if(p == -1) ans = "YES";
    System.out.println(ans);
  }
}

Measured memory_bytes: 24936
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long A, long double B) { cout << (lli)((double)A * B) << endl; }

signed main() {
  long long A;
  scanf("%lld", &A);
  long double B;
  scanf("%Lf", &B);
  solve(A, B);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


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

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

using namespace std;

const int MOD=1000000007;

int main(){
	string s; cin>>s;
	int n=s.length();

	reverse(s.begin(),s.end());

	int dp[100001][13]={},ten=1;
	dp[0][0]=1;
	rep(i,n){
		if(s[i]=='?'){
			rep(j,13) rep(k,10) {
				dp[i+1][(j+k*ten)%13]+=dp[i][j];
				dp[i+1][(j+k*ten)%13]%=MOD;
			}
		}
		else{
			int d=s[i]-'0';
			rep(j,13){
				dp[i+1][(j+d*ten)%13]+=dp[i][j];
				dp[i+1][(j+d*ten)%13]%=MOD;
			}
		}
		ten=ten*10%13;
	}
	printf("%d\n",dp[n][5]);

	return 0;
}


Measured memory_bytes: 5504
from sys import setrecursionlimit
setrecursionlimit(10 ** 6)

N, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

def dfs(cur, par):
    dist, ter = 0, cur
    for nxt in E[cur]:
        if nxt == par:
            continue
        d, t = dfs(nxt, cur)
        if dist < d + 1:
            dist, ter = d + 1, t
    return (dist, ter)

L, _ = dfs(dfs(1, -1)[1], -1)

if L % 3 != 1:
    print("First")
else:
    print("Second")

Measured memory_bytes: 219148
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            double n = sc.nextDouble();
            double[] a=new double[10];
            a[0]=n;
            double sum=n;
            for(int i=1;i<10;i++) {
                if(i%2==1) {
                    a[i]=a[i-1]*2;
                }else {
                    a[i]=a[i-1]/3;
                }
                sum+=a[i];
            }
            System.out.println(sum);
        }
    }
}



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

int L[500010];
int R[500010];
int cnt;
int INF = 1000000007;

void merge (int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (int i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (int i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = INF;
  R[n2] = INF;
  int i = 0;
  int j = 0;
  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort (int A[], int n, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  
  int A[500010];
  int n;
  cin >> n;

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

  mergeSort(A, n, 0, n);

  for (int i = 0; i < n; i++) {
    cout << A[i];
    if (i != n - 1) {
      cout << " ";
    }
  }
  cout << endl;

  cout << cnt << endl;

  return 0;

}


Measured memory_bytes: 6988
N,M=gets.chomp.split(' ').map{|n| n.to_i}
P = Array.new(N)
Y = Array.new(N)
@h = {}
def add(p,y)
	@h[p].nil? ? @h[p] = [y] : @h[p] << y
end
for i in 0..(M-1)
	p,y=gets.chomp.split(' ').map{|n| n.to_i}
	add(p,y)
	P[i] = p
	Y[i] = y
end
@h = @h.map{|key,val| 
	hh = {}
	val.sort.each_with_index{|v,i|
		hh[v] = i
	}
	[key,hh]
}.to_h
for i in 0..(M-1)
	puts P[i].to_s.rjust(6, "0")+(@h[P[i]][Y[i]]+1).to_s.rjust(6, "0")
end


Measured memory_bytes: 62844
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    int n, m, c[21];
    cin >> n >> m;
    rep(i,m){ cin >> c[i]; }
    sort(c, c + m, greater<int>());

    int dp[50005];
    rep(i,50005) dp[i] = INF;
    dp[0] = 0;
    rep(i,m){
        rep(j,n + 1){
            if(j + c[i] <= n){
                dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 3360