akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  ll ans=0;
  if((N==1&&A==B)||(N>1&&A<=B)) ans=(N-2)*(B-A)+1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

const int MAX_N = 100;
int N;
ll x[MAX_N], y[MAX_N], h[MAX_N];
ll Cx, Cy, H;

void solve() {
    bool end = false;
    REP(cx, 100 + 1) {
        REP(cy, 100 + 1) {
            REP(i, N) {
                if (h[i] == 0)continue;
                H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                REP(j, N) {
                    if (max(H - abs(x[j] - cx) - abs(y[j] - cy), ll(0)) != h[j]) break;
                    if (j == N - 1) {
                        end = true;
                        Cx = cx, Cy = cy;
                        break;
                    }
                }
                if (end) break;
            }
            if (end) break;
        }
        if (end) break;
    }
    cout << Cx << ' ' << Cy << ' ' << H << endl;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> x[i] >> y[i] >> h[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] inputS = scan.nextLine().split(" ");
	int q = Integer.parseInt(scan.nextLine());
	String[] inputT = scan.nextLine().split(" ");
	int[] s = new int[n];
	int[] t = new int[q];
	for (int i = 0; i < n; i++) {
	    s[i] = Integer.parseInt(inputS[i]);
	}
	for (int i = 0; i < q; i++) {
	    t[i] = Integer.parseInt(inputT[i]);
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
	    for (int j = 0; j < n; j++) {
		if (t[i] == s[j]) {
		    cnt++;
		    break;
		}
	    }
	}
	System.out.println(cnt);
    }
}

Measured memory_bytes: 29832
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int n;
string x,y;

vector<vector<int> > q(1001,vector<int>(1001,-1));

int search(int i,int j){
  int ans;
  if(i<0 || j<0) return 0;
  if(q[i][j] != -1) return q[i][j];
  if( x[i] == y[j] ){
    ans=max( {search(i-1,j-1)+1,search(i-1,j),search(i,j-1)} );
    q[i][j]=ans;
    return ans;
  }
  else{
    ans=max( search(i-1,j),search(i,j-1) );
    q[i][j]=ans;
    return ans;
  }

}


int main(void){

  cin>>n;

  for(int i=0;i<n;i++){
    cin>>x;
    cin>>y;

    for(int ix=0;ix<1001;ix++){
      for(int iy=0;iy<1001;iy++){
        q[ix][iy]=-1;
      }
    }

    search( x.size(),y.size() );
    cout << q[x.size()-1][y.size()-1] << endl;
  }



  return 0;
}



Measured memory_bytes: 7116
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    int w = readint;
    int n = readint;

    auto xs = new int[w + 1];
    for (int i = 0; i < xs.length; i++)
        xs[i] = i;

    for (int i = 0; i < n; i++) {
        auto ab = readln.chomp.split(",").to!(int[]);
        int a = ab[0], b = ab[1];
        swap(xs[a], xs[b]);
    }

    foreach (x; xs[1 .. $])
        writeln(x);
}

Measured memory_bytes: 2364
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
l = [[0] * W for _ in range(H)]
r = [[0] * W for _ in range(H)]
u = [[0] * W for _ in range(H)]
d = [[0] * W for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            if j != 0:
                r[i][j] = r[i][j - 1] + 1
            else:
                r[i][j] = 1

for i in range(H):
    for j in reversed(range(W)):
        if S[i][j] != '#':
            if j != W - 1:
                l[i][j] = l[i][j + 1] + 1
            else:
                l[i][j] = 1

for i in range(W):
    for j in range(H):
        if S[j][i] != '#':
            if j != 0:
                d[j][i] = d[j - 1][i] + 1
            else:
                d[j][i] = 1

for i in range(W):
    for j in reversed(range(H)):
        if S[j][i] != '#':
            if j != H - 1:
                u[j][i] = u[j + 1][i] + 1
            else:
                u[j][i] = 1

for i in range(H):
    for j in range(W):
        tmp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        ans = max(ans, tmp)

print(ans)

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

int k,res = 0;
int cnt = 0;
string s;
int main(){
    cin >> k;
    if(k % 2 == 0) {cout << -1 << endl;return 0;}
    while(cnt <= 1e6){
        res = res * 10 + 7;
        cnt++;
        if(res % k == 0) break;
        res %= k;
    }
    if(cnt > 1e6) cout << -1 << endl;
    else cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

	sort(l.begin(), l.end());

	int cnt = 0;
	for (int a = 0; a < n - 2; a++) {
		for (int b = a + 1; b < n - 1; b++) {
			for (int c = b + 1; c < n; c++) {
				if (l[a] + l[b] > l[c]) {
					cnt++;
				}
				else
				{
					break;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        inputs := strings.Fields(scanner.Text())
        a, _ := strconv.Atoi(inputs[0])
        b, _ := strconv.Atoi(inputs[1])
        c, _ := strconv.Atoi(inputs[2])
        if a*c <= b {
                fmt.Println(c)
                return
        } else {
                var cnt int
                for a <= b {
                        b -= a
                        cnt++
                }
                fmt.Println(cnt)
        }
}

Measured memory_bytes: 640
def lcm(a, b):
    return a * b // gcd (a, b)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
  A, B, C, D = map(int, input().split())
  E = lcm(C, D)
  a_c, a_d, a_cd = (A-1) // C, (A-1) // D, (A-1) // E
  b_c, b_d, b_cd = B // C, B // D, B // E
  a, b = a_c + a_d - a_cd, b_c + b_d - b_cd
  ans = (B - A + 1) - (b - a)
  print(ans)
  
main()

Measured memory_bytes: 9156
N, P = map(int, input().split())

if N == 1:
    ans = P
else:
    ans = 1
    p = 2
    while p * p <= P:
        e = 0
        while P % p == 0:
            P //= p
            e += 1  # 素数のカウント
        if e // N > 0:
            ans *= p ** (e // N)
        p += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	auto m = map<int, int>();
	for(auto i = 0; i < n; ++i){
		int a;
		cin >> a;
		++m[a];
	}
	auto b = vector<int>();
	for(auto p : m){
		b.push_back(p.second);
	}
	sort(b.begin(), b.end());
	int ans = 0;
	for(auto i = 0; i < (int)b.size() - k; ++i){
		ans += b[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int T,H,Z,E,N;
  cin>>N;
  T = N/1000;
  N = N -1000*T;
  H = N/100;
  N = N - 100*H;
  Z = N/10 ;
  N = N -10*Z;
  E = N;
  if(H==Z){
    if(T==H||Z==E){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
      cout<<"No"<<endl;
  }
}


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

int main()
{
	int y, x;
	char fl[50 + 10][50 + 10];

	int i,j,k;
	int s;

	int sumw=0, sumb=0, sumr=0;
	int min=INT_MAX;

	cin >> y >> x;

	for (i = 0; i < y; i++)
	{
		cin >> fl[i];
	}

	for (i = 0; i < y - 2; i++)
	{
		for (s = 0; s < x; s++)
		{
			if (fl[i][s] != 'W')
			{
				sumw++;
			}
		}

		sumb = 0;

		for (j = i+1; j < y - 1; j++)
		{
			for (s = 0; s < x; s++)
			{
				if (fl[j][s] != 'B')
				{
					sumb++;
				}
			}
			
			sumr = 0;

			for (k = j+1; k < y; k++)
			{
				for (s = 0; s < x; s++)
				{
					if (fl[k][s] != 'R')
					{
						sumr++;
					}
				}	
			}

			if (min > sumw + sumb + sumr)
			{
				min = sumw + sumb + sumr;
			}
		}
	}

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    int k[M];
    vector<int> s[M];
    for(int i=0; i<M; i++){
       cin >> k[i];
       for(int j=0; j<k[i]; j++){
           int t;
           cin >> t;
           s[i].push_back(t-1);
       }
    }

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

    int m = pow(2, N);
    int ans = 0;
    for(int cnt = 0; cnt<m; cnt++){
       bool f = true;
       for(int i=0; i<M; i++){
           int num = 0;
           for(int j=0; j<k[i]; j++){
               if((cnt >> s[i][j]) & 1) num++;
           }
           if(num % 2 != p[i]){
               f = false;
               //break;
           }
       } 
       if(f){
            ans++;
       }
    }

    cout << ans;


    return 0;


}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}
class Eratosthenes{
  public:
    int n, sqlim;
    vector<bool> prime;
    Eratosthenes(int N):n(N+1){
        sqlim=(int)ceil(sqrt(n));
        prime=vector<bool>(n,1); prime[0]=prime[1]=0;
        for(int i=2;i<=sqlim;i++) if(prime[i]) for(int j=i*i;j<=n;j+=i) prime[j]=0;}
    vector<int> primeArray(int s=0, int l=10000){vi ret; for(int i=s;ret.size()!=l;i++) if(prime[i]) ret.push_back(i); return ret;}
};


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	vi v=Eratosthenes(1299710).primeArray(0,100000);
	set<int> prime(all(v));
	vi ans(1299710,0);
	int p=0,l=0;
	rep(i,1299710){
	    if(prime.find(i)!=prime.end()){
	        range(j,p,i) ans[j]=l+1;
	        p=i+1,l=0;
	    }else l++;
	}
	int n;
	while(cin>>n,n){
		cout<<ans[n]<<endl;
	}
	return 0;
}



Measured memory_bytes: 12804
<?php

  $s = trim(fgets(STDIN));
  $t = trim(fgets(STDIN)); 

  if (strpos($t, $s) !== false) {
    // code...
    if (strlen($t) == strlen($s)+ 1) {
      // code...
      if(substr($t,0,-1) == $s){
      echo "Yes";
      return;
      }
    }
  }
 echo 'No'; 

Measured memory_bytes: 16124
N = int(input())
a = list(map(int, input().split()))
avr = sum(a)/N
d = []
judge = 'n'
for i in range(N):
    x = abs(avr-a[i])
    if x == 0:
        ans = i
        judge = 'z'
        break
    else:
        d.append(x)

if judge == 'z':
    print(ans)
else:
    print(d.index(min(d)))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int c1, c5, c10, c50, c100, c500;
	cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
	if (c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500 >= 1000) {
		cout << "1" << endl;
	}
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1160
# D - Megalomania

from operator import itemgetter

N = int(input())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=itemgetter(1), reverse=True)
deadline = AB[0][1]
for i in range(N):
    deadline = min(deadline, AB[i][1]) - AB[i][0]

print('Yes' if 0 <= deadline else 'No')


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

int main(){
  int a;
  int c=0;
  cin >> a ;
  for(int i=1; i<10; i++){
    if(a%i == 0){
      int b=a/i;
      if(0<b&&b<10){
        cout << "Yes" << endl;
        c=1;
        break;
      }
    }
  }
  if(c==0){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
dis = [[float("inf") for i in range(n)] for j in range(n)]
for i in range(n):
    dis[i][i] = 0
abc = []
for i in range(m):
    a, b, c = map(int, input().split())
    abc.append([a, b, c])
    dis[a-1][b-1] = c
    dis[b-1][a-1] = c
def warshall_floyd(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dis1 = dis[i][j]
                dis2 = dis[i][k] + dis[k][j]
                dis[i][j] = min(dis1, dis2)
    return dis
data = warshall_floyd(dis)
ans = 0
for i in range(m):
    a, b, c = abc[i][0], abc[i][1], abc[i][2]
    for j in range(n):
        if c + data[b-1][j] == data[a-1][j]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 9404
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    use itertools_num::ItertoolsNum as _;
    input! {
       N: usize,
       A:[usize;N],
    }

    let mut ans: usize = 0;
    let mut A = std::iter::once(&100000).chain(&A).map(|&x| x).toVec();
    mydbg!(A);
    A.push(0);
    let mut p = A[0];
    let mut c = 1000;
    let mut d = 0;
    let mut e = 0;
    let mut flag = false;
    for i in 1..N + 2 {
        mydbg!(flag, A[i], p, c, d, e);
        if flag && A[i] < p {
            flag = false;
            c += d * A[i - 1];
            d = 0;
        } else if !flag && A[i] > p {
            flag = true;
            d += c / A[i - 1];
            c = c % A[i - 1];
            e = A[i - 1];
        }
        p = A[i];
    }

    echo!(c + d * e);
}


Measured memory_bytes: 2164
h, w, k = [int(i) for i in input().split()]
s = [[int(i == "#") for i in input()] for _ in range(h)]
a = [[0 for _ in range(w)] for _ in range(h)]
c = 1
for i in range(h):
  if sum(s[i]) == 0:
    if i != 0:
      a[i] = a[i - 1].copy()
    continue
  t = False
  for j in range(w):
    if s[i][j] == 1:
      if t:
        c += 1
      t = True
    a[i][j] = c
    if j == w - 1:
      c += 1
for i in range(h):
  if sum(a[h - i - 1]) == 0:
    a[h - i - 1] = a[h - i].copy()
for ai in a:
  print(*ai)

Measured memory_bytes: 8228
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;


int main() {
    ll n;
    
    cin>>n;
    
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> ans(n);
    vector<ll> c(2 * 100000, 0);
    
    rep(i,n) cin>>a[i];
    rep(i,n) b[i] = a[i];
    
    Sort(b);
    
    ll d = b[0], count = 1;
    
    Rep(i,1,n){
        if(d==b[i]) count++;
        else{
            c[b[i-1]] = count;
            d = b[i];
            count = 1;
        }
    }
    c[d] = count;
    ll sum = 0;
    rep(i, c.size()){
        if(c[i] != 0){
            //cout<<(c[i]*(c[i]-1))/2<<endl;
            sum += (c[i]*(c[i]-1))/2;
        }
    }
    
    //cout<<sum<<endl;
    rep(i, n){
        cout<<sum-(c[a[i]]-1)<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 8832
N = int(input())

pre = list(map(int,input().split()))

flag = 0

for i in range (N):
    if pre[i] == 0:
        flag = 1

if flag == 0:

    ans = 1

    for i in range (N):
        ans *= pre[i]

        if ans > 10**18:
            print("-1")
            break

    if ans <= 10**18:
        print(ans)

else:
    print("0")

Measured memory_bytes: 84744
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  long long int l[n];
  l[0] = 2,l[1] = 1;
  for(int i = 1;i < n;i++){
    l[i + 1] = l[i] + l[i - 1];
  }
  printf("%lld",l[n]);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   long x = sc.nextInt();
   long ret = 1000*(x/500);
   x %= 500;
   ret += 5*(x/5);
   System.out.println(ret); 
}
}


Measured memory_bytes: 22996
def calc(n):
    if n>=10 and n<100:
        return (n//10)*(n%10)
    elif n>=100 and n<1000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        return max(r1,r2)
    elif n>=1000 and n<10000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        return max(r1,r2,r3)
    elif n>=10000 and n<100000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        return max(r1,r2,r3,r4)
    elif n>=100000 and n<1000000:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        return max(r1,r2,r3,r4,r5)
    else:
        r1=(n//10)*(n%10)
        r2=(n//100)*(n%100)
        r3=(n//1000)*(n%1000)
        r4=(n//10000)*(n%10000)
        r5=(n//100000)*(n%100000)
        r6=(n//1000000)*(n%1000000)
        return max(r1,r2,r3,r4,r5,r6)
n=int(input())


for i in range(n):
    cnt=0
    a=int(input())
    while a>=10:
        a=calc(a)
        cnt+=1

    print(cnt)



Measured memory_bytes: 5608
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print("")
    print("")



Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  ll tmp = n / k;
  ll ans = tmp * tmp * tmp;
  if(k % 2 == 0){
    ll tmp2 = n % k;
    if(tmp2 >= k / 2){
      tmp++;
    }
    ans += tmp * tmp * tmp;
  }

  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void max_heapify(vi &A, int H, int i) {
  auto l = 2 * i;
  auto r = 2 * i + 1;

  auto largest = (l <= H && A[l] > A[i]) ? l : i;
  if (r <= H && A[r] > A[largest]) largest = r;
  if (largest != i) {
    swap(A[i], A[largest]);
    max_heapify(A, H, largest);
  }
}

int main() {
  int H;
  cin >> H;
  vi A(H + 1);
  FOR(i, 1, H + 1) cin >> A[i];
  RFOR(i, 1, H / 2 + 1) max_heapify(A, H, i);
  FOR(i, 1, H + 1) cout << " " << A[i];
  cout << endl;
}


Measured memory_bytes: 4664
use std::io;


fn main() {
    let (r, g, b) = {
        let i = read::<isize>();
        (i[0], i[1], i[2])
    };

    if (r * 100 + g * 10 + b) % 4 == 0 { println!("YES"); }
    else { println!("NO"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

using namespace std;

#ifdef LOCAL
#include "/Users/thakchir/Desktop/CP/Library/Debug/Debug.cpp"
#else
#define debug(...) 42
#endif

void RunTestCase() {
  int x;
  cin >> x;
  cout << !x << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  RunTestCase();
  return 0;
}

Measured memory_bytes: 3552
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////



int main(){fastio
    ll n,m;cin>>n>>m;
    ll dp[m+1][1<<n];
    rep(i,0,m)rep(j,0,(1<<n)-1)dp[i][j]=inf;
    dp[0][0]=0;
    rep(i,1,m){
        ll a,b;cin>>a>>b;
        ll cnt=0;
        while(b--){
            ll c;cin>>c;
            cnt+=1<<(c-1);
        }
        rep(j,0,(1<<n)-1)dp[i][j]=dp[i-1][j];
        rep(j,0,(1<<n)-1){
            if((j&cnt)==cnt)Min(dp[i][j],dp[i-1][j-cnt]+a);
        }
        for(ll j=(1<<n)-1;j>=0;j--){
            rep(k,0,n-1){
                if((j&(1<<k))==0){
                    ll oldj=j+(1<<k);
                    Min(dp[i][j],dp[i][oldj]);
                }
            }
        }
       // rep(j,0,(1<<n)-1)cout<<dp[i][j]<<" ";cout<<endl;
    }
    if(dp[m][(1<<n)-1]>=inf/2)cout<<-1<<endl;
    else cout<<dp[m][(1<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 32256
//q026.cpp
//Fri Aug 14 22:09:59 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

vector<ll> visited(200000,0);
vector<ll> g[200000];
vector<ll> ans(200000,0);
vector<ll> p(200000,0);

ll score;
ll point;

void dfs(ll z){
	if (visited[z]==0){
		point += p[z];
		ans[z] = point;
		visited[z] = 1;
		rep(i,g[z].size()){
			ll tmp = g[z][i];
			if (visited[tmp]==0){
				dfs(tmp);
			}
		}
		point -= p[z];
	}
}

int main(){
	ll n,q;
	cin >> n >> q;

	rep(i,n-1){
		ll a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	rep(i,q){
		ll c,x;
		cin >> c >> x;
		c--;
		p[c] += x;
	}

	point = 0;
	dfs(0);

	rep(i,n){
		cout << ans[i] << " ";
	}
	printf("\n");
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 25080
#include<stdio.h>

int fibonacci(int);
int F[45];

int main(){
  int i,n;
  for(i=0;i<45;i++){
    F[i]=-1;
  }

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}


int fibonacci(int n){
  if(n==0||n==1){
    return F[n]=1;
  }
  if(F[n]!=-1){
    return F[n];
  }
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}



Measured memory_bytes: 2108
import math
N=int(input())
l = len(str(N))
if l == 1:
    print(N)
else:
    if l == 2:
        print(9)
    else:
        if l%2 == 1:
            a = [10**(l-i-2)-10**(l-i-3) for i in range(0,l+1,2)]
            print(math.floor(sum(a))+N-10**(l-1)+1)
        else:
            a = [10**(l-i-1)-10**(l-i-2) for i in range(0,l+1,2)]
            print(math.floor(sum(a)))

Measured memory_bytes: 3064
A,B=map(int,input().split())
S=input()
ass=True
for i in range(len(S)):
  if i==A:
    if S[i]!='-':
      ass=False
      break
  else:
    if S[i]=='-':
      ass=False
      break
if ass:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
W,H,N = gets.split.map(&:to_i)

ans = [0,0,W,H]
N.times do
  x,y,a = gets.split.map(&:to_i)
  case a
  when 1
    ans[0] = x if ans[0] < x
  when 2
    ans[2] = x if x < ans[2]
  when 3
    ans[1] = y if ans[1] < y
  when 4
    ans[3] = y if y < ans[3]
  end
end

x,y,w,h = ans
if x < w && y < h
  puts (w - x) * (h - y)
else
  puts 0
end

Measured memory_bytes: 3836
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, k := r.nextInt(), r.nextInt()
	r.Scan(true)
	a := append([]int{0}, r.nextStringArray().toInts()...)

	cur := 1
	mp := make([]int, 0, n+1)
	for {
		w := a[cur]
		a[cur] = 0
		mp = append(mp, cur)

		cur = w
		if a[cur] <= 0 {
			break
		}
	}

	idx := 0
	for i, mpi := range mp {
		if mpi == cur {
			idx = i
		}
	}
	if k > idx {
		k = (k-idx)%(len(mp)-idx) + idx
	}
	fmt.Fprintln(stdout, mp[k])
}


Measured memory_bytes: 13064
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MAXN 1e9+5
#define INF 100000
#define MOD 1e9+5

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int main(){
    int H, N;
    scanf("%d %d", &H, &N);    
    vii v(N);
    vector<ll> dp(H + 1, 1000000000);
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        scanf("%d %d", &v[i].F, &v[i].S);
    }
    for(int i = 1; i <= H; i++){
        for(int j = 0; j < N; j++){
            dp[i] = min(dp[i], dp[max(i-v[j].F, 0)] + v[j].S);
        }
    }
    cout << dp[H] << endl;
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

int main()
{
    string tWord, hWord;
    int n, tPoint = 0, hPoint = 0, i;
    cin >> n;

    for (i = 0; i < n; i++)
    {
        cin >> tWord >> hWord;
        if (tWord > hWord)
            tPoint += 3;
        else if (hWord > tWord)
            hPoint += 3;
        else
        {
            tPoint++;
            hPoint++;
        }
    }

    printf("%d %d\n", tPoint, hPoint);
}


Measured memory_bytes: 3180
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int N;
vector<int> adjlist[599];
double dptable[600];
double dp(int v) {
	if (dptable[v] > -0.5) return dptable[v];
	if (v == N - 1) return dptable[v] = 0;
	dptable[v] = 0;
	for (int i: adjlist[v]) dptable[v] += dp(i) / adjlist[v].size();
	return ++dptable[v];
}
int main() {
	int M, s, t;
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; ++i) {
		scanf("%d %d", &s, &t);
		adjlist[s - 1].push_back(t - 1);
	}
	for (int i = 0; i < N; ++i) dptable[i] = -1;
	double ans = dp(0);
	for (int i = 0; i < N - 1; ++i) {
		for (int j = 0; j < N; ++j) dptable[j] = -1;
		if (adjlist[i].size() > 1) {
			double temp = 0, maxval = 0;
			for (int j: adjlist[i]) {
				temp += dp(j);
				maxval = max(maxval, dp(j));
			}
			temp -= maxval;
			temp /= (adjlist[i].size() - 1);
			dptable[i] = temp + 1;
			ans = min(ans, dp(0));
		}
	}
	printf("%.9lf", ans);
	return 0;
}

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

int main() {
  int n, m, cnt = 0;
  scanf("%d %d", &n, &m);
  vector<vector<int>> v(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int x;
      cin >> x;
      v[i].push_back(x - 1);//電球番号は1始まりなのでずらすよ
    }
  }
  vector<int> p(m);
  for(int i = 0; i < m; i++) cin >> p[i];
  
  
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<10> s(tmp);
    bool all = true;
    for(int i = 0; i < m; i++) {
      int on = 0;
      for(int j = 0; j < v[i].size(); j++) {
        if(s.test(v[i][j])) on++;
      }
      if(on % 2 != p[i]) {
        all = false;
        break;
      }
    }
    if(all) cnt++;
  }
  cout << cnt;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <queue>

using namespace std;

const long long INF = 1LL << 60;
const int A_MAX = 2510;

struct Edge {
    int src, dst;
    long long weight;
    Edge(int src, int dst, long long weight)
        : src(src), dst(dst), weight(weight)
    {}
};
bool operator<(const Edge& e, const Edge& f) {
    return tie(f.weight, e.src, e.dst) < tie(e.weight, f.src, f.dst);
}

vector<long long> dijkstra(const vector<vector<Edge>>& g, int s)
{
    int n = g.size();
    vector<long long> dist(n, INF);
    dist[s] = 0;

    priority_queue<Edge> q;
    for (q.push(Edge(-2, s, 0)); !q.empty(); ) {
        Edge e = q.top();
        q.pop();
        for(auto &f : g[e.dst]) {
            if (dist[f.dst] > e.weight + f.weight) {
                dist[f.dst] = e.weight + f.weight;
                q.push(Edge(f.src, f.dst, e.weight + f.weight));
            }
        }
    }
    return dist;
}

int main()
{
    int N, M, S;
    cin >> N >> M >> S;

    vector<int> U(M), V(M), A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        --U[i];
        --V[i];
    }
    vector<int> C(N), D(N);
    for (int i = 0; i < N; ++i) {
        cin >> C[i] >> D[i];
    }

    vector<vector<Edge>> g(A_MAX * N);
    for (int i = 0; i < N; ++i) {
        for (int k = 0; k < A_MAX; ++k) {
            int src = A_MAX * i + k;
            int dst = A_MAX * i + min(A_MAX - 1, k + C[i]);
            int weight = D[i];
            Edge e(src, dst, weight);
            g[src].push_back(e);
        }
    }
    for (int i = 0; i < M; ++i) {
        for (int k = 0; k < A_MAX; ++k) {
            if (k < A[i]) {
                continue;
            }
            int src1 = A_MAX * U[i] + k;
            int dst1 = A_MAX * V[i] + (k - A[i]);
            int weight = B[i];
            Edge e1(src1, dst1, weight);
            g[src1].push_back(e1);

            int src2 = A_MAX * V[i] + k;
            int dst2 = A_MAX * U[i] + (k - A[i]);
            Edge e2(src2, dst2, weight);
            g[src2].push_back(e2);
        }
    }
    S = min(A_MAX - 1, S);

    auto d = dijkstra(g, S);
    for (int t = 1; t < N; ++t) {
        long long ans = *min_element(d.begin() + A_MAX * t, d.begin() + A_MAX * (t + 1));
        cout << ans << endl;
    }
}

Measured memory_bytes: 24224
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

ll 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;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
int main(){
  ll n;cin>>n;
  vll t(n),a(n);
  rep(i,0,n){
    cin>>t[i]>>a[i];
  }
  rep(i,1,n){
    ll tt=t[i-1]/t[i],aa=a[i-1]/a[i];
    if(t[i-1]%t[i])tt++;
    if(a[i-1]%a[i])aa++;
    t[i]*=max(tt,aa);
    a[i]*=max(tt,aa);
  }
  cout<<t[n-1]+a[n-1]<<endl;
}



Measured memory_bytes: 3640
#include <iostream>

int main() {
	int n;
	std::cin >> n;
	int a[n];
	int counter = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		while(!(a[i] % 2)) {
			a[i] /= 2;
			counter++;
		}
	}
	std::cout << counter << std::endl;
	return 0;
}

Measured memory_bytes: 256
class Entry
  attr_reader :size, :value
 
  def initialize(size, value)
    @size = size
    @value = value
  end
end
 
class PrefixQueue
  def initialize
    @list = []
    @prefix = ''
  end
 
  def empty?
    @list.empty?
  end
 
  def shift
    entry = @list.shift
    [@prefix[0...entry.size], entry.value]
  end
 
  def push(key, value)
    @list.each_with_index do |entry, i|
      target = @prefix[0...entry.size]
      case target <=> key
      when -1
        return nil unless key.start_with?(target)
      when 0
        return entry.value
      else
        if target.start_with?(key)
          @list.insert(i, nil)
        else
          @prefix = key
          @list.slice!(i+1..-1)
        end
        @list[i] = Entry.new(key.size, value)
        return value
      end
    end
    @prefix = key
    @list << Entry.new(key.size, value)
    return value
  end
end

class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def collect(n, arrows, goal)
  come_from = Array.new(n){[]}
  arrows.each do |arrow|
    come_from[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    come_from[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end
  reachable_from
end

def work(n, arrows, start, goal)
  reachable_from = collect(n, arrows, goal)
  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  go = Array.new(n){[]}
  arrows.each do |arrow|
    go[arrow.source] << arrow
  end

  max = n * arrows.map{|arrow| arrow.label.size}.max

  queue = PrefixQueue.new
  queue.push('', {start => true})
  until queue.empty?
    spell, map = queue.shift
    return spell if map[goal]

    return nil if spell.size > max

    map.each do |node, unused|
      go[node].each do |arrow|
        t = queue.push(spell + arrow.label, {})
        t[arrow.sink] = true if t
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts work(n, arrows, s, g) || 'NO'
end

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

int main(void){
    int n,m; cin >> n >> m;
    int cnt = pow(2,m);
    ll time = 100*(n-m) + 1900*(m);
    time *= cnt;
    cout << time << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define rep(i, n) for(int i = 0; i < n; i++)
#define irep(i,n) for(int i = n-1; i>=0; i--)
#define FOR(a,b) for(int i=a; i<b+1; i++)
using namespace std;
typedef long long ll;

vector<vector<int>> v;
vector<vector<int>> v1;
int n;
void a(int i,int s, int step){
    if(v1[s][i]>=0){
        return;
    }
    v1[s][i]=step;
    for(auto e:v[i]){
        a(e,s,step+1);
    }
}
int main() {
    cin >> n;
    v.resize(n);
    v1.assign(2,vector<int>(n,-1));
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    a(0,0,0);
    a(n-1,1,0);
    int ans=0;
    rep(i,n){
        if(v1[0][i]<=v1[1][i]){
            ans++;
        }
    }
    if(ans>n/2){
        cout << "Fennec" << endl;
    }
    else{
        cout << "Snuke" << endl;
    }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  string s;
  vector<ll> p(5);
  for(int i = 0; i < n; ++i)
  {
    cin >> s;
    if (s[0] == 'M') p[0]++;
    if (s[0] == 'A') p[1]++;
    if (s[0] == 'R') p[2]++;
    if (s[0] == 'C') p[3]++;
    if (s[0] == 'H') p[4]++;
  }

  ll ans = 0;
  for(int i1 = 0; i1 < 3; ++i1)
  {
    for(int i2 = i1 + 1; i2 < 4; ++i2)
    {
      for(int i3 = i2 + 1; i3 < 5; ++i3)
      {
        ans += p[i1] * p[i2] * p[i3];
      }
    }
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a=0,e;
  string b;
  string c,d;
  cin>>b;
  c[0]=b[0];
  for(int i=0;i<b.size();i++){
    d+=b[i];
    //cout<<i<<" "<<d<<"\n";
    //cout<<c<<" "<<d<<"\n";
    if(c==d){
      e=i;
      while(true){
        e++;
        if(e==b.size()) break;
        d+=b[e];
        //cout<<d<<"\n";
        if(c!=d) break;
      }
      i=e;
    }
    //cout<<i<<" "<<c<<" "<<d<<"\n";
    c={};
    c=d;
    d={};
    if(i<b.size()) a++;
   // cout<<i<<" "<<d<<"\n";
  }
  cout<<a<<"\n";
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static int count_p,count_q,p,q,n;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		p = 0;
		q = 0;
		int mul = pow(10 , n - 1);
		for(int i = 0 ; i < n ; i++) {
			p += sc.nextInt() * mul;
			mul /= 10;
		}
		mul = pow(10 , n - 1);
		for(int i = 0 ; i < n ; i++) {
			q += sc.nextInt() * mul;
			mul /= 10;
		}
		count_p = 0;
		count_q = 0;
		count("");

		System.out.println(Math.abs(count_p - count_q));

	}
	public static void count(String s) {
		if(s.length() == n) {
			int i = Integer.valueOf(s);
			if(p >= i)
				count_p++;
			if(q >= i)
				count_q++;
			return;
		}
		for(int i = 1 ; i <= n ; i++) {
			String s2 = s;
			if(!s2.contains(i + "")) {
				count(s2 += i);
			}
		}

	}
	public static int pow(int a,int b) {
        int ret = 1;
        int tmp = a;
        while(b>0) {
            if((b&1)==1) ret = (ret * tmp);  //2進数によるべき乗の高速計算
            tmp *= tmp;
            b = b>>1;
        }
        return ret;
    }
}



Measured memory_bytes: 58992
#include<stdio.h>
int main(void)
{
	int x, h, s, m;
	scanf("%d",&x);
	h=x/3600;
	m=(x%3600)/60;
	s=(x%3600)%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2720
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 21;
int n, m, f[1 << N][N];
int main(){
    scanf("%d%d", &n, &m);
    for(Rint i = 0;i <= n;++ i)
        for(Rint j = 0, x;j < (1 << i);++ j){
            for(x = getchar();x != '0' && x != '1';x = getchar());
            f[(1 << i) | j][i] = (x == '1');
        }
    for(Rint i = n;~i;-- i)
        for(Rint j = 0;j < (1 << i);++ j)
            for(Rint k = i;k;-- k) if(f[(1 << i) | j][k]){
                int t = f[(1 << i) | j][k], S = j >> k, T = j & ((1 << k) - 1);
//                cout<<"WTF:"<<i<<" "<<j<<" "<<k<<" "<<f[(1<<i)|j][k]<<" "<<S<<" "<<T<<endl;
                if(k) f[(1 << i - k) | S][0] += t;
                if(T){
                    int u = k - 1;
                    while(!((T >> u) & 1)) -- u;
                    f[(1 << i - k + u + 1) | (S << u + 1) | (1 << u) | (T & ((1 << u) - 1))][u] += t;
                }
                if((~T) & ((1 << k) - 1)){
                    int u = k - 1;
                    while((T >> u) & 1) -- u;
                    f[(1 << i - k + 1 + u) | (S << u + 1) | (T & ((1 << u) - 1))][u] += t;
                }
            }
//            for(register int i=n;~i;i--)
//            {
//            	for(register int j=0;j<(1<<i);j++)cout<<f[(1<<i)|j][0]<<" ";
//            	cout<<endl;
//			}
    for(Rint i = n;~i;-- i)
        for(Rint j = 0;j < (1 << i);++ j) if(f[(1 << i) | j][0] >= m){
            for(Rint k = i - 1;~k;-- k) putchar('0' + ((j >> k) & 1));
            return 0;
        }
}


Measured memory_bytes: 175796
#include <bits/stdc++.h>
#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 pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s, t = "qwertyuiopasdfghjklzxcvbnm";
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  s += '.';
  int ans = iinf;
  FOR(i, 0, 26){
    int c = 0, d = 0;
    s[sz(s)-1] = t[i];
    FOR(j, 0, sz(s)){
      if(s[j] == t[i]){
        maxs(c, d);
        d = 0;
      }else{
        d++;
      }
    }
    mins(ans, c);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int k;
    cin >> k;
    int o = (k + 1) / 2;
    int e = k / 2;
    cout << o * e << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

int main(){
   vector<int> a(3);
  for(int i = 0; i < 3; i++){
      cin >> a[i];
  }
  sort(a.begin(), a.end());


  cout << a[0] + a[1] << endl;


   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std; 

int main(int argc, char** argv) {
	
	int SN[550]={0};
	int Snext[550]={0};
	int C[550]={0};
	int S[550]={0},F[550]={0};
	int i,j,k,n;
	cin>>n;

	for(i=1;i<=n-1;i++)
	{
		cin>>C[i]>>S[i]>>F[i];
	}
	for(i=1;i<=n-1;i++)
	{
		Snext[i]=C[i]+S[i];
	}
	SN[n]=0;
	SN[n-1]=Snext[n-1];
	for(i=n-2;i>=1;i--)
	{
		if(Snext[i]<=S[i+1]) SN[i]=SN[i+1];
		else 
		{
			SN[i]+=Snext[i];
			for(j=i+1;j<=n-1;j++)
			if(SN[i]>S[j]) 
				if(F[j]!=1)
				{
					while(SN[i]%F[j]) SN[i]++;
					SN[i]+=C[j];
				 } 
				else SN[i]+=C[j];
			else
			{
				SN[i]=SN[j];
				break;
			 } 
		}
	}
	for(i=1;i<=n;i++)
	cout<<SN[i]<<endl;
	return 0;
} 

Measured memory_bytes: 256