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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

struct edge {
    int to, cost;
};

int N;
vector<edge> graph[100010];
bool used[100010];
int ans[100010];

void dfs(int now, int num) {
    if (used[now] == true) {
        return;
    }

    used[now] = true;
    ans[now] = num;
    for (auto e : graph[now]) {
        if ((num + e.cost) % 2 == 0) {
            dfs(e.to, 0);
        } else {
            dfs(e.to, 1);
        }
    }

    return;
}

int main() { 
    cin >> N;
    REP(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;
        graph[u].push_back(edge {v, w});
        graph[v].push_back(edge {u, w});
    }

    memset(used, false, sizeof(used));
    dfs(0, 0);
    REP(i, N) {
        cout << ans[i] << endl;
    }
    return 0; 
}

Measured memory_bytes: 7680
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque

def check(x, y, now_add, color, high, width):
    global data
    move_dic = [(1, 0), (0, 1)]
    for move_x, move_y in move_dic:
        next_x = x + move_x
        next_y = y + move_y
        if 0 <= next_x < high and 0 <= next_y < width:
            if data[next_x][next_y] == 0:
                continue
            if data[next_x][next_y] != data[x][y]:
                now_add.add((i, j))
                color[data[next_x][next_y]] += 1
                check(next_x, next_y, now_add, color, high, width)


def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]

    ans = 0
    move_dic = [[1, 0], [0, 1], [-1, 0], [0, -1]]

    for i in range(high):
        for j in range(width):
            if data[i][j] == 0:
                continue

            all_ele = set()
            now_ele = set()
            next_ele = set()
            count = defaultdict(int)

            now_ele.add((i, j))
            all_ele.add((i, j))
            count[data[i][j]] += 1

            while len(now_ele) > 0:
                for x, y in now_ele:
                    for move_x, move_y in move_dic:
                        next_x = x + move_x
                        next_y = y + move_y
                        if 0 <= next_x < high and 0 <= next_y < width:
                            if data[next_x][next_y] == 0 or (next_x, next_y) in all_ele:
                                continue
                            if data[next_x][next_y] != data[x][y]:
                                next_ele.add((next_x, next_y))
                                all_ele.add((next_x, next_y))
                                count[data[next_x][next_y]] += 1
                now_ele = next_ele
                next_ele = set()

            ans += count['.'] * count['#']
            for x, y in all_ele:
                data[x][y] = 0

    print(ans)




if __name__ == '__main__':
    main()
    # test()


Measured memory_bytes: 70484
N,M=map(int, input().split())
inlist = [tuple([int(st) for st in input().split()]) for i in range(M)]
inlist.sort()
res=0
minright=100000000000
for fr, to in inlist:
    if to < minright: minright = to
    if minright <= fr:
        res += 1
        minright = to
print(res+1)


Measured memory_bytes: 59224
package main

import "fmt"

func main() {
	var n int64
	fmt.Scanln(&n)

	if n%2 == 1 {
		fmt.Println(0)
		return
	}

	ans := int64(0)
	m := n / 2
	for m > 0 {
		m /= 5
		ans += m
	}

	fmt.Println(ans)
}


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

int main()
{
   int n , x, t;
   cin>>n>>x>>t;
   int num = (n/x);
   if(n%x!=0)
   num++;
   //cout<<"num = "<<num<<endl;
   int ans = num*t;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	const int32_t RATES = 8;
	vector<int32_t> colors(RATES);
	fill(begin(colors), end(colors), 0);

	int32_t targets = 0;
	for (int32_t i = 0; i < N; i++) {
		int32_t score;
		cin >> score;
		if (score < 400)
			colors[0]++;
		else if (score < 800)
			colors[1]++;
		else if (score < 1200)
			colors[2]++;
		else if (score < 1600)
			colors[3]++;
		else if (score < 2000)
			colors[4]++;
		else if (score < 2400)
			colors[5]++;
		else if (score < 2800)
			colors[6]++;
		else if (score < 3200)
			colors[7]++;
		else
			targets++;
	}

	int32_t _min = 0;
	for (int32_t i = 0; i < RATES; i++) {
		if (colors[i] > 0)
			_min++;
	}

	int32_t _max;
	if (_min == 0) {
		_min = 1;
		_max = targets;
	} else {
		_max = _min + targets;
	}

	cout << _min << " " << _max << endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    int s[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
        s[i]=A[i];
    }
    int max=0;
    for(int i=0;i<N;i++){
        if(max<A[i]){
            max=A[i];
        }
    }

    sort(s,s+N);

    for(int i=0;i<N;i++){
        if(A[i]==max){
            cout << s[N-2] << endl;
        }else{
            cout << max << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

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

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

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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 solve() {
    int n,k;
    cin >> n >> k;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VLL ru(n+1), ss(n);
    REP(i,0,n) ru[i+1] = ru[i] + max(0LL, a[i]);
    REP(i,0,k) ss[k-1] += a[i];
    REP(i,k,n) ss[i] = ss[i-1] + a[i] - a[i-k];
    LL ans = ru[n-k];
    REP(i,k-1,n) {
        chmax(ans, ru[n]-ru[i+1]+ru[i+1-k] + max(0LL, ss[i]));
    }
    cout << ans << endl;
}

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

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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	ll n, m, k;

	cin >> n >> m >> k;

	vector<ll> sumA(n + 1), sumB(m + 1), a(n), b(m);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	
	for(int i = 0; i < n; i++){
		sumA[i + 1] = sumA[i] + a[i];
	}
	for(int i = 0; i < m; i++){
		sumB[i + 1] = sumB[i] + b[i];
	}
	
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		ll rem = k - sumA[i];
		
		if(rem < 0) continue;
		
		ll l = lower_bound(sumB.begin(), sumB.end(), rem) - sumB.begin();
		
		if(l > m || sumB[l] > rem){
			l--;
		}
		
		ans = max(ans, i + l);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9484
#include <cstdio>

#define MAX 1000001
int n,x,v;
bool prm[MAX]={false};
bool dp[MAX]={false};

int main(){
	for(int i = 2; i < MAX; i++){
		if(!prm[i]){
			for(int j = i*2; j < MAX; j += i){
				prm[j] = true;
			}
		}
	}
	while(scanf("%d%d",&n,&x), n != 0){
		for(int i = 0; i < MAX; i++){
			dp[i] = false;
		}
		dp[0] = true;
		for(int i = 0; i < n; i++){
			scanf("%d",&v);
			for(int j = 0; j <= x; j++){
				if(dp[j] && j + v <= x){
					dp[j+v] = true;
				}
			}
		}
		
		bool no = true;
		for(int i = x; i > 0; i--){
			if(!prm[i] && dp[i]){
				printf("%d\n",i);
				no = false;
				break;
			}
		}
		if(no){
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 4600
n, w = map(int, input().split())
W = [0] * n
V = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    W[i] = a
    V[i] = b


dp = [[0] * (10 ** 5 + 10) for _ in range(n + 10)]
for i in range(n):
    for sum_num in range(w + 1):
        if sum_num - W[i] >= 0:
            dp[i + 1][sum_num] = max(dp[i][sum_num - W[i]] + V[i], dp[i][sum_num])
        else:
            dp[i + 1][sum_num] = dp[i][sum_num]

print(dp[n][w])

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

int main()
{
	int x[5], y[5];
	scanf("%d %d %d %d", &(x[1]), &(y[1]), &(x[2]), &(y[2]));
	
	x[3] = x[2] + (y[1] - y[2]);
	y[3] = y[2] + (x[2] - x[1]);
	x[4] = x[3] + (y[2] - y[3]);
	y[4] = y[3] + (x[3] - x[2]);
	
	printf("%d %d %d %d\n", x[3], y[3], x[4], y[4]);
	fflush(stdout);
	return 0;
}

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

int main(){
        int n;
        scanf("%d", &n);
        std::vector<int> a(n);
        for(int i=0; i<n; i++) scanf("%d", &a[i]);

        int l=0, r=1e9+1;
        while(r-l>1){
                int mid = (r-l)/2 + l;
                std::vector<int> ans(n+1);
                ans[0] = mid;
                for(int i=1; i<=n; i++){
                        ans[i] = a[i-1] - ans[i-1];
                }

                if(ans[0]<=ans[n]) l = mid;
                else r = mid;
        }

        int prev = l;
        for(int i=1; i<n; i++){
                printf("%d ", 2*prev);
                prev = a[i-1] - prev;
        }
        printf("%d\n", 2*prev);

        return 0;
}

Measured memory_bytes: 2040
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int p = 0;
    String ans = "Yes";
    for(int i = 0; i < s.length(); i++) {
      if(((i % 2) == 0) && (s.charAt(i) == 'L')) p++;
      if(((i % 2) == 1) && (s.charAt(i) == 'R')) p++;
    }
    if(p > 0) ans = "No";
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;


int main()
{
	int A, B;

	cin >> A >> B;

	int ans = -1000000;

	ans = max(ans, A + B);
	ans = max(ans, A - B);
	ans = max(ans, A * B);

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 256
/*

    HARSH KHATRI
    DA-IICT     

		 */

           	 

#include <bits/stdc++.h>

#define LOCAL 0
bool debug = true;

using namespace std;

int main(void) {
	
	if(LOCAL) {
    	freopen("in.txt", "r", stdin);
	    freopen("out.txt", "w", stdout);
	}

	int i, j;
	long long x;
	vector<int> a(3);
	for(i=0; i<3; i++) scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	x = a[2]; x -= a[0];
	printf("%lld\n", x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//F6編譯，右上三角形執行，ctrl+c強制停止執行  F5開啟exe
#define ll long long
#define maxn 100005
#define mod 998244353
using namespace std;

typedef pair<int, int> P;

int r;

int main()
{
    cin >> r;
    cout << 3 * r * r;
    return 0;
}


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

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        W: i64,
        H: i64,
        N: usize,
        XYA: [(i64,i64,i64); N],
    }
    let (mut x0, mut x1, mut y0, mut y1) = (0,W,0,H);
    for i in 0..N{
        let (x,y,a) = (XYA[i].0, XYA[i].1, XYA[i].2);
        match a{
            1 => { x0 = max(x0,x) }
            2 => { x1 = min(x1,x) }
            3 => { y0 = max(y0,y) }
            _ => { y1 = min(y1,y) }
        }
    }
    println!("{}", max(0,x1-x0)*max(0,y1-y0));
}

Measured memory_bytes: 4352
from collections import Counter

def solve():
    N = int(input())
    S = [input() for _ in range(N)]
    counter = Counter(S)
    ret_t = sorted(counter.most_common(), key=lambda x:(-x[1],x[0]))
    ret_t = [t for t in ret_t if t[1] == ret_t[0][1]]
    print('\n'.join(map(lambda x:x[0],ret_t)))
    
solve()

Measured memory_bytes: 63380
#include "stdio.h"
#include <queue>
#include <set>
#include <string.h>
using namespace std;

int N, M;
int a[28], b[28];
struct para{
  set<int> s;
  int n;
};
void solve(){
  int res = 0;
  queue<para> que;
  para p;
  p.n = 1;
  for(int i=1; i<N; i++){
    p.s.insert(i+1);
  }
  que.push(p);

  while(que.size()){
    para pp = que.front(); que.pop();
    if(pp.s.empty()){
      res++;
      continue;
    }
    for(int i=0; i<M; i++){
      int next;
      if(a[i] == pp.n)  next = b[i];
      else if(b[i] == pp.n) next = a[i];
      else continue;
      set<int>::iterator ite = pp.s.find(next);
      if(ite != pp.s.end()){
        para np;
        np.s = pp.s;
        np.n = next;
        np.s.erase(next);
        que.push(np);
      }
    }
  }
  printf("%d\n", res);


}

int main(){

  scanf("%d %d", &N, &M);
  for(int i=0; i<M; i++){
    scanf("%d %d", &a[i], &b[i]);
  }

  solve();

  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	string S;cin>>S;
    
	// 解法
    bool ans = false;
	REP(i,S.size()-1){
        if (S[i]==S[i+1]){
            ans = true;
            break;
        }
    }
    
	//出力
	if (ans) printf("Bad\n");
	else printf("Good\n");
}


Measured memory_bytes: 256
import java.util.Scanner;
	public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
				int N = scanner.nextInt();
				int[] a = new int[N];
				int[] flg = new int [8];
				
				flg[0] = 0;
				flg[1] = 0;
				flg[2] = 0;
				flg[3] = 0;
				flg[4] = 0;
				flg[5] = 0;
				flg[6] = 0;
				flg[7] = 0;
				int count = 0;
				int min = 0;
				int max = 0;
				
				for (int i = 0; i < N; i++) {
				    a[i] = scanner.nextInt();
				    if (1 <= a[i] && a[i] <= 399) {
				        flg[0] = 1;
				    }
				    if (400 <= a[i] && a[i] <= 799) {
				        flg[1] = 1;
				    }
				    if (800 <= a[i] && a[i] <= 1199) {
				        flg[2] = 1;
				    }
				    if (1200 <= a[i] && a[i] <= 1599) {
				        flg[3] = 1;
				    }
				    if (1600 <= a[i] && a[i] <= 1999) {
				        flg[4] = 1;
				    }
				    if (2000 <= a[i] && a[i] <= 2399) {
				        flg[5] = 1;
				    }
				    if (2400 <= a[i] && a[i] <= 2799) {
				        flg[6] = 1;
				    }
				    if (2800 <= a[i] && a[i] <= 3199) {
				        flg[7] = 1;
				    }
				    if (3200 <= a[i]) {
				        count++;
				    }
				}
				
				for (int i = 0; i < 8; i++) {
				    if (flg[i] == 1) {
				        min ++;
				    } 
				} 
				
				
				max = min + count;
				if (min == 0) {
				    min = 1;
				}
				
				System.out.print(min + " " + max);
		}
		}

Measured memory_bytes: 23764
// 2016-11-30
#include <iostream>
using namespace std;

int main() {
	int n, a, b, c, x;
	int y[100];
	while (cin >> n >> a >> b >> c >> x, n || a || b || c || x) {
		for (int i = 0; i < n; i++) {
			cin >> y[i];
		}
		int f, r;
		for (f = 0, r = 0; f <= 10000; f++) {
			if (x == y[r]) {
				r++;
				if (r >= n) {
					break;
				}
			}
			x = (a * x + b) % c;
		}
		cout << (f <= 10000 ? f : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 2972
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m = inpl()
p = []
res = [[] for i in range(m)]
for i in range(m):
    a,b = inpl()
    p.append((a,b,i))
p.sort(key=lambda x:x[1])
p.sort(key=lambda x:x[0])
cnt = 0
tmp = 0
for i,j in enumerate(p):
    if i == 0:
        tmp = j[0]
    if tmp == j[0]:
        cnt += 1
    else:
        tmp = j[0]
        cnt = 1
    res[j[2]] = [j[0],cnt] 
for i in res:
    print('{}{}'.format(str(i[0]).zfill(6),str(i[1]).zfill(6)))

Measured memory_bytes: 104988
#include <stdio.h>
 
int main(void){
  int l,r;
  int i,j;
  int min;
  if(scanf("%d %d",&l,&r)==1);
  if(r-l>=2019){
    printf("0\n");
    return 0;
  } 
  if(l>=2019){
    l = l % 2019;
  }
  if(r>=2019){
    r = r % 2019;
  }
  if(l>r){
	printf("0\n");
    return 0;
  }
  else{
    min = 2020;
    for(i=l;i<r;i++){
      for(j=i+1;j<=r;j++){
        if(min>(i*j%2019)){
          min = (i*j%2019);
        }
      }
    }
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
ll dp[10][20];//dp[i][j]代表以i开头的j位数有多少个lunlun 
ll sum[20], pos;
ll k;
void dfs(ll num, ll lst) {
	if (num > pos) return;
	if (num == 1) {
		for (ll i = 1; i < 10; i++) {
			if (k > dp[i][pos - num + 1]) {
				k -= dp[i][pos - num + 1];
			} else {
				cout << i;
				dfs(num + 1, i);
				break;
			}
		}
	} else {
		for (ll i = lst - 1; i <= lst + 1; i++) {
			if (i < 0 || i > 9) continue;//记住特判 
			if (k > dp[i][pos - num + 1]) {
				k -= dp[i][pos - num + 1];
			} else {
				cout << i;
				dfs(num + 1, i);
				break;
			}
		}
	}
}
int main() {
	cin >> k;
	for (ll i = 0; i < 10; i++) {
		dp[i][1] = 1;
	}
	sum[1] = 9;
	for (ll j = 2; j <= 10; j++) {
		for (ll i = 0; i < 10; i++) {
			if (i != 0 && i != 9) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1] + dp[i + 1][j - 1];
			else if (i != 0) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
			else if (i != 9) dp[i][j] = dp[i][j - 1] + dp[i + 1][j - 1];
			if (i != 0) sum[j] += dp[i][j];
		}
	}
	for (ll i = 1; i <= 20; i++) {
		if (k > sum[i]) {
			k -= sum[i];
		} else {
			pos = i;
			break;
		}
	}
	dfs(1, 0);
	return 0;
}

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

using namespace std;

#define ll long long

int main() {
	int k;
	int cnt = 1;
	cin>>k;
	int last = 7;
	while(cnt<10000000){
		if(last%k==0){
			break;
		}
		last%=k;
		last*=10;
		last+=7;
		cnt++;
	}
	if(cnt==10000000)
		cout<<-1;
	else{
		cout<<cnt;
	}
}


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

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

    int l = a;
    int r = a + n - 1;
    int eat = 0;
    if (r <= 0)
        eat = r;
    else if (l >= 0)
        eat = l;
    else
        eat = 0;
    int ans = (l + r) * (r - l + 1) / 2 - eat;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
ans = 0
f = False
place_a = len(s)
place_z = 0
for i in range(len(s)):
    if s[i] == "A":
        place_a = min(place_a,i)
    if s[i] == "Z":
        place_z = max(place_z,i)
print(place_z-place_a+1)

Measured memory_bytes: 3512
H, W, K = map(int, input().split(' '))
ls = []

for i in range(H):
    ls.append(list(input()))

rst = 0
for i in range(1 << H):
    for s in range(1 << W):
        cnt = 0
        for j in range(H):
            if i>>j & 1:
                continue
            for t in range(W):
                if s>>t & 1:
                    continue
                if ls[j][t] == '#':
                    cnt += 1
        if cnt == K:
            rst += 1
print(rst)

Measured memory_bytes: 9132
#include <stdio.h>

int main() {

    int a, b, c, m1, m2, m3;

    scanf("%d %d %d", &a, &b, &c);

   m1 = a, m2 = b, m3 = c;

   if (a < b) {
       m1 = b, m2 = a;
       
       if (b < c)
           m1 = c, m2 = b, m3 = a;
       else {
           if (a > c)
               m2 = a, m3 = c;
           else
               m2 = c, m3 = a;
       }
    }
    else {
        m1 = a, m2 = b;

        if (a < c)
            m1 = c, m2 =a, m3 = b;
        else {
            if (b > c)
                m2 = b, m3 = c;
            else
                m2 = c, m3 = b;
            }
       }
    printf("%d %d %d\n", m3, m2, m1);
 
    return 0;

}

Measured memory_bytes: 596
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
string s[300];
int num[300][300];
int main(){
  int H,W,K;
  cin>>H>>W>>K;
  int str=1;
  for(int i=0;i<H;i++){
    cin>>s[i];
    int judge=0;
    for(int j=0;j<W;j++){
      if(j==0) num[i][j]=-1;
      else num[i][j]=num[i][j-1];
      if(s[i][j]=='#'){
       num[i][j]=str;
        str++;
        if(judge==0){
          for(int k=0;k<=j;k++) num[i][k]=num[i][j];
          judge++;
        }
      }
    }
  }
  for(int j=0;j<W;j++){
    int judge=0;
    for(int i=0;i<H;i++){
      if(i!=0&&num[i][j]==-1) num[i][j]=num[i-1][j];
      if(num[i][j]!=-1&&judge==0){
        for(int l=0;l<=i;l++) num[l][j]=num[i][j];
        judge++;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(j!=W-1) cout<<num[i][j]<<' ';
      else cout<<num[i][j]<<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long A,B;
    double b;
    cin >> A;
    cin >> b;
    B = b * 100 + 1e-7;
   // cout << B << endl;
    cout << (A * B) / 100 << endl;

}

Measured memory_bytes: 3180
N,M = map(int,input().split())
h_arr = [0] + list(map(int,input().split()))
c_arr = h_arr.copy()
cnt_arr = [0]*(N+1)
for _ in range(M):
  a,b = map(int,input().split())
  if h_arr[b]>=c_arr[a]:
    c_arr[a] = -1
  if h_arr[a]>=c_arr[b]:
    c_arr[b] = -1

print(N-c_arr.count(-1))

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

int N;

void f(string s) {
    if (s.size() == N) {
        cout << s << '\n';
        return;
    }
    rep(j, 10) {
        set<char> used(s.begin(), s.end());
        if (j <= used.size()) {
            char x = 'a' + j;
            f(s + x);
        }
    }
}

void Main() {
    cin >> N;
    f("");
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1536
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();	//K <= N
		int a = N - K;
		int b = K - 1;
		int c = 0;
		if( a%b!=0 ){
			c = 1;
		}
		System.out.println(1+a/b+c);
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

string change(string& s, string& a, string& b) {
    string t;
    for (int i = 0; i < s.size(); i++) {
        if (s.substr(i, a.size()) == a) {
            t += b;
            i += (int)a.size() - 1;
        }
        else {
            t += s[i];
        }
    }
    return t;
}
void solve() {
    int n; cin >> n; if (n == 0) exit(0);
    vector<pair<string, string>> vp(n); for (int i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;
    string s;
    string t;
    cin >> s >> t;
    map<string, int> mp;
    queue<string> q;
    q.emplace(s);
    mp[s] = 0;
    while (!q.empty()) {
        string s = q.front();
        q.pop();
        for (int i = 0; i < n; i++) {
            string nxt = move(change(s, vp[i].first, vp[i].second));
            if (mp.count(nxt)) continue;
            if (t == nxt) {
                cout << mp[s] + 1 << "\n";
                return;
            }
            if (t.size() <= nxt.size()) continue;
            mp[nxt] = mp[s] + 1;
            q.emplace(nxt);
        }
    }
    cout << -1 << "\n";
}
int main()
{
    
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int kkt = 89;
    while (kkt) {
        solve();
    }
    return 0;
}


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

using namespace std;

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

  if (e - a > k)
  {
    cout << ":(" << endl;
  }
  else
  {
    cout << "Yay!" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

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

	bool jud = false;
	int aa = a;
	REP(i, b){
		if(aa%b == c){
			jud = true;
			break;
		}
		aa += a;
	}

	if(jud) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}//解説参考.

Measured memory_bytes: 256
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second or(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll a,b,k;
  cin>>k>>a>>b;
  if(a/k!=b/k)
  {
    cout<<"OK";
  }
  else if((a%k==0)||(b%k==0))
  {
    cout<<"OK";
  }
  else cout<<"NG";
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll ans = INF;
int main() {
	ll n;
	cin >> n;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	REP(i, 110) {
		ll now = 0;
		REP(j, n) {
			now += abs(s[j] - i) * abs(s[j] - i);
		}
		ans = min(ans, now);
	}
	cout << ans << endl;
}



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

int main()
{
  int n;
  cin>>n;
  int l = n/100;
  int j = l*100 + l*10 + l;
  int t = (l+1)*100 + (l+1)*10 + l+1;
  if(n<=j)
    cout<<j;
  else
    cout<<t;
  return 0;
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let towns = Array.init m (fun i -> 
    Scanf.scanf " %d %d" @@ fun p y -> y, i, p) in
  let l6 = Array.make n 1 in
  let answers = Array.make m "" in
  Array.sort compare towns;
  towns |> Array.iter (fun (y,i,p) ->
    answers.(i) <-
      Printf.sprintf "%06d%06d" p l6.(p-1);
    l6.(p-1) <- l6.(p-1) + 1);
  answers |> Array.iter print_endline



Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
vector<int> h(100001);
vector<int> dp(100001);
/* https://atcoder.jp/contests/dp/tasks/dp_b */

int main(){
    int n, k, res;
    cin >> n >> k;
    // memset(dp, -1, sizeof(dp));
    for(int i=1;i<=n;i++){
        cin >> h.at(i);
    }
    dp[1] = 0;
    for(int i=2;i<=n;i++){
        dp[i] = dp[i-1] + abs(h[i-1] - h[i]);
        for(int j=1;j<=k;j++){
            if(i-j>0){
                dp[i] = min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
                // cout << i << ' ' << j << ' ' << dp[i] << endl;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

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

const long long INF = 1LL << 60;
const long long mod = 1000000007;


int main(void){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll t = min({a,b,c,d,e});
    if(n%t==0) cout << n/t + 4 << endl;
    else cout << n/t + 5 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		// 出力
		//System.out.println("");
		
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();

		int max,mid,min;
		max=0;
		mid=0;
		min=0;
		
		if(A>=B && B>=C){
			max=A;
			mid=B;
			min=C;
		}else if(A>=C && C>=B){
			max=A;
			mid=C;
			min=B;
		}else if(B>=A && A>=C){
			max=B;
			mid=A;
			min=C;
		}else if(B>=C && C>=A){
			max=B;
			mid=C;
			min=A;
		}else if(C>=A && A>=B){
			max=C;
			mid=A;
			min=B;
		}else if(C>=B && B>=A){
			max=C;
			mid=B;
			min=A;
		}
		int count=0;
		int dif=((max - mid) + (max - min));
		int dn=mid-min;
		if(dn%2==0){
			count = dn/2 + (max-mid);
		}else if(dif%2 ==0){
			count=dif/2;
		}else{
			count=1+((mid+1)-min)/2 + (max - mid);
		}
		
		System.out.println(count);
	}
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



//#define int int64_t
signed main()
{
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i];
	vector<int> ans(n);
	int sum{};
	int halfsum{};

	//editorialのやり方
	//22:08:30のやつが動画のやり方

	//(  X_2+x_3+...+x_n == 2*(A_2+A_4+...+A_n-1)  )
	//x2~xnの和は偶数番号のダムの和の二倍と等しい
	//*1

	for(int i = 0; i < n; ++i){
		//全体のダムの和と偶数のダムの和を求める
		sum+=a[i];
		if(i&1) halfsum += a[i];//iが0(even)のときダムは1番目(odd)
	}
	//最初のダム
	ans[0]=sum - 2*halfsum;// S - 2*(偶数番号のダムの和)
	//残りを漸化式で
	for(int i = 0; i < n-1; ++i){
		ans[i+1] = 2*a[i] - ans[i];
	}

	for(int i = 0; i < n; ++i){
		cout << ans[i] << '\n';
	}

}

/*
*1.

 X_1 = S - (X_2~X_n), X_i+X_i+1=2*A_iより

X_2 = 2*A_2 - X_3
-X_3がS-(X_2~X_n)のX_3と打ち消すので,繰り返すと2*A_i(i==even)だけ残る

i.e.
X_2+x_3+...+x_n == 2*(A_2+A_4+...+A_n-1)

*/

Measured memory_bytes: 2176
def main():
    S, W = map(int, input().split())

    print('unsafe' if S <= W else 'safe')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9152
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    ans = 0
    for i in s:
        if i == '+':
            ans += 1
        else:
            ans -= 1
    
    print(ans)

solve()


Measured memory_bytes: 2940
"""

a,bの組み合わせから u,vを作っていく
a,bが違うのに u,vが同じになるパターンはbit入れ替えのみ？

a1 ^ b1 == a2 ^ b2 とする
bit入れ替えでなく, 左右のabが等しくないとき、 00 と 11になっている
和にすると片方が片方より 2**[桁+1]大きい
→各桁について 2,4,8,16…の差が生まれるが、これらが相殺されることは無い。

よってabの各桁の組み合わせが (0,0)(0,1)(1,1)のどれかだけ調べればよい
u <= vより、vの条件だけ考えていく。


現時点でのNとの差が
0 * 2**(d+1) → (0,0)のみ設置可能
1 * 2**(d+1) → (0,0)(0,1)のみ設置可能
                (0,0) → 差は2 * (2**d)
2 *

(1,1)が来ると繰り上がってしまう。→ 2**(d+1)増える

dp[桁][乖離度]
"""
mod = 10**9+7
N = int(input())

NB = format(N,"b")

dp = [ [0]*3 for i in range(len(NB)) ]

dp[0][0] = 1
dp[0][1] = 1

for i in range(len(NB) - 1):

    if NB[i+1] == "0":
        #(0,0)を加える場合
        dp[i+1][0] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] += dp[i][2]

        #(0,1)を加える場合
        #dp[i][0]にはくわえられない
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][2]

        #(1,1)を加える場合
        dp[i+1][0] += dp[i][1]
        dp[i+1][2] += dp[i][2]

    else:
        
        #(0,0)を加える
        dp[i+1][1] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] += dp[i][2]

        #(0,1)
        dp[i+1][0] += dp[i][0]
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] += dp[i][2]

        #(1,1)
        #dp[i][0]にはくわえられない
        dp[i+1][1] += dp[i][1]
        dp[i+1][2] += dp[i][2]

    dp[i+1][0] %= mod
    dp[i+1][1] %= mod
    dp[i+1][2] %= mod

print (sum(dp[-1]) % mod)

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String str[];
		int n, m, a, b;
		int cost[][] = new int[100][100];
		int time[][] = new int[100][100];
		
		while(true){
			str = reader.readLine().split(" ");
			n = Integer.valueOf(str[0]);
			m = Integer.valueOf(str[1]);
			if(n == 0 && m == 0) break;
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					cost[i][j] = time[i][j] = 1000 * 1000;
				}
			}
			for(int i = 0; i < n; i++){
				str = reader.readLine().split(" ");
				a = Integer.valueOf(str[0]) - 1;
				b = Integer.valueOf(str[1]) - 1;
				cost[a][b] = cost[b][a] = Integer.valueOf(str[2]);
				time[a][b] = time[b][a] = Integer.valueOf(str[3]);
			}
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					for(int k = 0; k < m; k++){
						cost[j][k] = Math.min(cost[j][k], cost[j][i] + cost[i][k]);
						time[j][k] = Math.min(time[j][k], time[j][i] + time[i][k]);
					}
				}
			}
			n = Integer.valueOf(reader.readLine());
			for(int i = 0; i < n; i++){
				str = reader.readLine().split(" ");
				a = Integer.valueOf(str[0]) - 1;
				b = Integer.valueOf(str[1]) - 1;
				switch(Integer.valueOf(str[2])){
				case 0 : System.out.println(cost[b][a]); break;
				case 1 : System.out.println(time[b][a]);
				}
			}
		}
		reader.close();
	}
}

Measured memory_bytes: 72336
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
int n,a[MN];
long long lmn,lmx;
int main(){
	n=read();register int i,last=2;
	for(i=1;i<=n;i++) a[i]=read();
	if(a[n]!=2){printf("-1");return 0;}
	lmn=2;lmx=3;
	for(i=n-1;i>=1;i--){
		if(a[i]==last) continue; last=a[i];
		if(lmn<a[i]&&a[i]<=lmx) lmn=a[i];
		if(a[i]>lmx){printf("-1");return 0;}
		lmn=(long long)((lmn+a[i]-1)/a[i])*a[i];
		lmx=(long long)(lmx/a[i])*a[i]+a[i]-1;
	}
	if(lmn>lmx){printf("-1");return 0;}
	printf("%lld ",lmn);
	printf("%lld",lmx);
	return 0;
}

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

typedef complex<int> C;

main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  C d = {tx - sx, ty - sy};
  cout << string(d.imag(), 'U') << string(d.real(), 'R');
  cout << string(d.imag(), 'D') << string(d.real(), 'L');
  d += C(1, 1);
  cout << 'L' << string(d.imag(), 'U') << string(d.real(), 'R') << 'D';
  cout << 'R' << string(d.imag(), 'D') << string(d.real(), 'L') << 'U';
  cout << endl;
}


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

int main() {
  ll x;
  cin >> x;
  ll a = x/500LL;
  x -= a*500LL;
  ll b = x/5LL;
  cout<<a*1000+b*5<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        xx, yy = map(int, input().split())
        x[i].append(xx)
        y[i].append(yy)

def zeroone(n):
    if n == 1:
        return [[0],[1]]
    a = zeroone(n-1)
    b = zeroone(n-1)
    for i in range(len(a)):
        a[i].append(0)
    for i in range(len(b)):
        b[i].append(1)
    a.extend(b)
    return a

answer = zeroone(n)

def is_possible(line):
    l = len(line)
    for i in range(l):
        if line[i] == 1:
            for j in range(a[i]):
                if y[i][j] != line[x[i][j] - 1]:
                    return False
    return True

max = 0
for i in range(2**n):
    if is_possible(answer[i]):
        if max < answer[i].count(1):
            max = answer[i].count(1)
print(max)

Measured memory_bytes: 55640
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	o := readString()
	e := readString()
	bo := []byte(o)
	be := []byte(e)

	ans := make([]byte, 0)
	i := 0
	for ; i < len(e); i++ {
		ans = append(ans, bo[i], be[i])
	}
	if i < len(o) {
		ans = append(ans, bo[i])
	}
	println(string(ans))
}


Measured memory_bytes: 640
#include <stdio.h>
char*n[]={"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
int main(void){
	int m,d;
	for(;scanf("%d%d",&m,&d),m;puts(n[(d-13*~m/5)%7]))m<3?d-=2,m+=12:0;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back



int main(){
    int n;
    cin >> n;
    int x=1;
    map<string,int> mp;
    vector<string> ss;
    string s;
    for(int i=0;i<n;i++){
        cin >> s;
        mp.insert(make_pair(s,1));
        
        if(mp.size()!=x){
            mp[s]++;
            x--;
        }else{
            ss.pb(s);
        }
        x++;
    }

    int max=0;
    vector<string> ans;
    
    for(int i=0;i<ss.size();i++){
        if(max<mp[ss[i]]){
            max=mp[ss[i]];
            ans.clear();
            ans.pb(ss[i]);
        }else if(max==mp[ss[i]]){
            ans.pb(ss[i]);
        }
    }

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

    for(int i=0;i<ans.size();i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 28400
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int p, q;

int main(){
	int n;
	scanf("%d",&n);
	while(n--){
		int x;
		scanf("%d",&x);
		if(x % 2 == 1) p++;
		else q++;
	}
	if(p % 2 == 0){
		puts("YES");
		return 0;
	}
	else if(p == 1 && q == 0){
		puts("YES");
		return 0;
	}
	else puts("NO");
}



Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let k = iter.next().unwrap().parse().unwrap();
    let s:i32 = iter.next().unwrap().parse().unwrap();
    let mut ans = 0;
    for x in 0..(k+1) {
        for y in 0..(k+1){
            let z = s - x - y;
            ans += if (z>=0) && (z<=k) {1} else {0};
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int amari = X%500;
        int ans = (X/500)*1000 + (amari/5)*5;
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 35892