akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * No 147
 * Time: 2h
 * Result : OK
 *
 */
public class Main {

	/** Group */
	private static class Group {
		/** group number */
		int i;
		
		int arriveTime;
		/** number of person */
		int person;
		
		/** Time to finish eating */
		int period;
		
		public Group(int i) {
			this.i = i;
			this.arriveTime = i * 5;
			this.person = i%5 == 1 ? 5 : 2;
			this.period = 17*(i % 2) + 3*(i % 3) + 19;
		}
		
		int eatStart = -1;
		public void setEatStart(int time) {
			this.eatStart = time;
		}
		public int waitingTime() {
			return eatStart - arriveTime;
		}
	}
	
	private static class Table {
		// this value is time to finish eating;
		private int[] table = new int[17];
		
		public void forwardTime(){
			for (int i = 0; i < table.length;i++) {
				if (table[i] > 0) {
					table[i] -= 1;
				}
			}
		}
		
		public boolean welcomeGroupIfavailable(Group g) {
			TreeMap<Integer, Integer> available = new TreeMap<Integer, Integer>();
			int hit=-1;
			// find continue 0;
			for (int i = 0; i < table.length;i++) {
				int t = table[i];
				
				if (t == 0){ // tabale is availabel
					if (hit < 0) {
						hit = i;
						available.put(hit, 1);
					} else {
						available.put(hit, available.get(hit)+1);
					}
				}else {
					hit = -1;
				}
			}
			for(Map.Entry<Integer, Integer> e : available.entrySet()) {
				if(e.getValue() >= g.person) { // table is available for group;
					for (int i = 0; i < g.person; i++) {
						table[i + e.getKey()] = g.period;
					}
					return true;
				}
			}
			return false;
		}
		public void dump(int time) {

			System.out.print(time + ":");
			for (int i :table) {
				System.out.print(i > 0 ? i+"" : "_");
				System.out.print(",");
			}
			System.out.println();
			
		}
		
	}
	
	public static void main(String[] args) {
		List<Group> groups = new ArrayList<Group>();
		for (int i = 0; i < 100; i++) {
			groups.add(new Group(i));
		}

		Table table = new Table();

		// start time loop
		LinkedList<Group> q = new LinkedList<Group>(); // waiting queue;
		int groupCount = 0;
		for (int time = 0; ; time++){
			// arrive next group
			
			Group next = groups.get(groupCount >= groups.size() ? groups.size()-1 : groupCount);
			if (time == next.arriveTime) {
				q.add(next);
				groupCount++;
			}
			
			// change table state;
			table.forwardTime();
			
			// welcome from q, if table is available
			while(!q.isEmpty()) {
				Group g = q.peek();
				if (table.welcomeGroupIfavailable(g)) {
					g.setEatStart(time);
					//System.out.println(g.i + ";" + g.arriveTime + "<" + g.eatStart + ":" +g.person);
					q.poll(); // remove from queue;
				} else {
					break; // not exit;
				}
			}
			//table.dump(time);
			// end if final group start eating;
			if (groupCount >= groups.size() && next.eatStart >= 0) {
				break;
			}
		}
		// calc is end. reading stdio. then	 answer;
		Scanner s = new Scanner(System.in);
		while(s.hasNextInt()) {
			System.out.println(groups.get(s.nextInt()).waitingTime());
		}
		s.close();
		
	}

}

Measured memory_bytes: 22776
import java.util.*;
 
/*
問題文
長さが奇数である文字列 S が以下の条件をすべて満たすとき、S は「強い回文」であるといいます。
 
S は回文である。
N を S の長さとするとき、S の 1 文字目から (N−1)/2 文字目まで(両端含む)からなる文字列は回文である。
S の (N+3)/2 文字目から 
N 文字目まで(両端含む)からなる文字列は回文である。
S が強い回文かどうかを判定してください。
*/
 
 
 
public class Main {
    public static void main(String[] args){
 
        //スキャン
        Scanner s = new Scanner(System.in);
        String text =s.next();
        int textlen = text.length();
        boolean cyc1 = cycloid(text);
        boolean cyc2 = cycloid(
            text.substring(
                0,
                (textlen)/2)
                );
 
 
        boolean cyc3 = cycloid(
            text.substring(
                (textlen+3)/2-1,
                textlen)
            );
 
        if(cyc1 ==true && cyc2 == true && cyc3 == true){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    
    }
 
    //回文判定処理
    private static boolean cycloid(String hoge){
        //文字列長
        int stLong = hoge.length();
        for(int i=0;i <= stLong/2;i++){
            if(hoge.charAt(i) 
                != 
                hoge.charAt(stLong-1 - i) ){
                    return false;
            };
        } 
        return true;
    }
 
    
}


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


int main() {
	string S;
	int R, B, n;
	R = 0;B = 0;
	cin >> n >> S;
	for (int i = 0;i < n;i++) {
		if (S[i] == 'R')
			R++;
		else
			B++;
	}
	if (R > B)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.parse();
    let k = sc.parse();
    let ab = sc.pairs(n);
    println!("{}", solve(ab, k));
}


fn solve(ab: Vec<(usize, u32)>, k: i64) -> u32 {
    let mut counter = [0; 100001];
    for p in ab {
        counter[p.0] += p.1;
    }
    let mut k = k;
    let mut last_i = 0;
    for i in 0..100001 {
        let n = counter[i];
        if n != 0 {
            k -= n as i64;
            if k <= 0 {
                return i as u32;
            }
            last_i = i;
        }
    }
    last_i as u32
}

#[test]
fn test() {
    assert_eq!(2, solve(vec![(1, 1), (2, 2), (3, 3)], 3));
    assert_eq!(3, solve(vec![(1, 1), (2, 2), (3, 3)], 4));
    assert_eq!(1,
               solve(vec![(1, 100000),
                          (1, 100000),
                          (1, 100000),
                          (1, 100000),
                          (1, 100000),
                          (100000, 100000),
                          (100000, 100000),
                          (100000, 100000),
                          (100000, 100000)],
                     500000));
}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.parse(), self.parse())).collect()
    }
}


Measured memory_bytes: 6780
#include <stdio.h>

int main(void) {
  int N;
  int a[111111];
  int ah[111111] = {0};
  int i, k;
  
  scanf("%d", &N);
  for(i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  
  k = 0;
  for(i = 0; i < N; i++) {
    /*printf("%d %d %d\n", k, a[k], ah[k]);*/
    if(ah[k] == 1) {
      printf("-1\n");
      return 0;
    }
    ah[k]++;
    k = a[k];
    if(k == 1) {
      break;
    }
  }
  printf("%d\n", i + 1);
  
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {


            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
        public static long gcd(long a,long b)
        {
            if (a < b) gcd(b, a);
            while (b > 0)
            {
                long z = b;
                b = a % b;
                a = z;
            }
            return a;
        }
        public static long lcm(long a,long b)
        {
            return a * b / gcd(a, b);
        }




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var nk = Reads();
            var n = nk[0];
            var k = nk[1];
            var rsp = Reads();
            var r = rsp[0];
            var s = rsp[1];
            var p = rsp[2];
            var t = ReadLine().ToArray();

            long ans = 0;

            for (int i = 0; i < k; i++)
            {
                if (t[i] == 'r') ans+=p;
                if (t[i] == 's') ans+=r;
                if (t[i] == 'p') ans+=s;
                var j = i + k;
                bool fp = true;
                bool fr = true;
                bool fs = true;
                while (j < n)
                {
                    if (t[j] == 'r')
                    {
                        if (t[j - k] == 'r')
                        {
                            if (fr) fr = false;
                            else { ans += p; fr=true; }
                        }
                        else { ans += p; fr = true; }
                    }
                    if (t[j] == 's')
                    {
                        if (t[j - k] == 's')
                        {
                            if (fs) fs = false;
                            else { ans += r; fs = true; }
                        }
                        else { ans += r; fs = true; }
                    }
                    if (t[j] == 'p')
                    {
                        if (t[j - k] == 'p')
                        {
                            if (fp) fp = false;
                            else { ans += s; fp = true; }
                        }
                        else { ans += s; fp = true; }
                    }
                    j += k;

                }

            }
            WriteLine(ans);

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 14304
package main

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

var (
	sDash string
	t     string
	s     string
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	sDash = scanner.Text()
	scanner.Scan()
	t = scanner.Text()

	//check if t can apply to sDash
	for i := len(sDash) - len(t); 0 <= i; i-- {
		k := 0
		match := false
		for j := i; j < i+len(t); j++ {
			if sDash[j] != '?' && sDash[j] != t[k] {
				match = false
				break
			}

			k++
			match = true
		}
		if match {
			s = sDash[:i] + t + sDash[(i+len(t)):]
			s = strings.Replace(s, "?", "a", -1)
			fmt.Println(s)
			return
		}

	}
	fmt.Println("UNRESTORABLE")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#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)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int calc_sec(int x){
    return x % 60;
}

int calc_min(int x){
    return (x / 60) % 60;
}

int calc_hour(int x){
    return (x / (60 * 60)) % 24;
}

int calc_day(int x){
    return x / (60 * 60 * 24);
}


int main() {
    int n;
    cin >> n;
    int h,m,s;
    s = calc_sec(n);
    m = calc_min(n);
    h = calc_hour(n);
    cout << h << ':' << m << ':' << s << endl;;
    return 0;
}
 
 



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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a == b && b != c || b == c && c != a || c == a && a != b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define Bye return 0
#define ll long long
const ll MAX = 1e2;

void solve(){
    int a, b, c; cin>>a>>b>>c;
    cout<<((b-a == c-b)?"YES":"NO")<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3608
from collections import deque

s = input()

left = deque(s+"@")
right = deque(s[::-1]+"@")

ans = 0

while left or right:
    if left[0] == right[0]:
        left.popleft()
        right.popleft()
    elif left[0] == "x":
        ans += 1
        left.popleft()
    elif right[0] == "x":
        ans += 1
        right.popleft()
    else:
        ans = -1
        break

ans //= 2
print(ans)

Measured memory_bytes: 5108
import sys;sys.setrecursionlimit(10**9);h,w=map(int,input().split());b=[[0]*(w+1)]
for i in range(h):
  b.append([0])
  for j in input():
    if j==".":b[-1].append(1)
    else:b[-1].append(2)
  b[-1].append(0)
b.append([0]*(w+1));d=[[0,1],[0,-1],[1,0],[-1,0]];a=0
def s(i,j):
  global B;B[b[i][j]-1]+=1;v=b[i][j];b[i][j]=0
  for k in d:
    if v^3!=b[i+k[0]][j+k[1]]:continue
    s(i+k[0],j+k[1])
for i in range(1,h+1):
  for j in range(1,w+1):B=[0,0];s(i,j);a+=B[0]*B[1]
print(a)

Measured memory_bytes: 149364
#include<stdio.h>

int main(){
    int n,i,j,k,num,graph[101][101];
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            graph[i][j]=0;
        }
    }
    for(i=1;i<=n;i++){
        scanf("%d%d",&i,&num);
        for(j=0;j<num;j++){
            scanf("%d",&k);
            graph[i][k]=1;
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(j==1) printf("%d",graph[i][j]);
            else printf(" %d",graph[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1996
#pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(int argc, char *argv[]) {
	// Something to do
	FOR(i, 1, 10)
		FOR(j, 1, 10)
			cout << i << "x" << j << "=" << i*j << endl;
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include<cmath>
using namespace std;
int main() {
	long long int n;cin >> n;
	int ans = 110;
	int g = floor(sqrt(n)),k;
	for (int i = g; i > 0;i--) {
		if (n % i == 0) {
			k = n / i;
			break;
		}
	}
	cout << floor(log10(k)) + 1 << endl;
}

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

int main() {
	
	int city[50] = {0};
	int n, m;
	int max = 0;
	cin >> n>> m ;

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		city[a-1]++;
		city[b-1]++;
	
	}

	for (int i = 0; i < n; i++) {
		cout << city[i]<< endl;
	}

	return 0;
}

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

struct RQ {
 using RQV = LL;
 using RQRV = LL;
 static RQV Zero(){ return 0; }
 static RQRV RZero(){ return 0; }
 // addition
 static RQV f(RQV a,RQV b){ return max(a,b); }
 // update function
 static void uf(RQV& a,RQV b){ a = b; }
 // effect of range queries n-sized
 static void ef(RQV& a,RQRV b,int n){  }
 // range query update
 static void ruf(RQRV& a,RQRV b){  }
 // comparation
 static bool cmp(RQV l,RQV r){ return l<=r; }
 struct Node{
  RQV v; RQRV r;
 };
 int N;
 vector<Node> V;

 void init(int n){
  N=1; while (N<n) N*=2;
  V.assign(N*2,{Zero(),RZero()});
 }

 void spread(int i,int z){
  if (z!=1) {
   ef(V[i*2].v,V[i].r,z/2);
   ruf(V[i*2].r,V[i].r);
   ef(V[i*2+1].v,V[i].r,z/2);
   ruf(V[i*2+1].r,V[i].r);
  }
  V[i].r = RZero();
 }

 void upd(int p,RQV v){
  for(int d=N; d>=1; d/=2) spread(p/d,d);
  p+=N; uf(V[p].v,v);
  int z=1;
  while(p!=1){
   p/=2; z*=2;
   V[p].v = f(V[p*2].v,V[p*2+1].v);
   ef(V[p].v,V[p].r,z);
  }
 }

 void updr(int l,int r,RQRV v,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  spread(i,b-a);
  if(r<=a || b<=l) return;
  if(l<=a && b<=r){
   ruf(V[i].r,v);
   ef(V[i].v,V[i].r,b-a);
   return;
  }
  updr(l,r,v,a,(a+b)/2,i*2);
  updr(l,r,v,(a+b)/2,b,i*2+1);
  V[i].v = f(V[i*2].v,V[i*2+1].v);
  ef(V[i].v,V[i].r,b-a);
 }

 RQV query(int l,int r,int a=0,int b=0,int i=-1){
  if(i==-1){ a=0; b=N; i=1; }
  if(r<=a || b<=l) return Zero();
  if(l<=a && b<=r) return V[i].v;
  RQV q1 = query(l,r,a,(a+b)/2,i*2);
  RQV q2 = query(l,r,(a+b)/2,b,i*2+1);
  q1 = f(q1,q2);
  ef(q1,V[i].r,min(r,b)-max(l,a));
  return q1;
 }

 int find(int l,RQV v,int a=0,int b=0,int i=-1){
  static RQV x;
  if(i==-1){ a=0; b=N; i=1; x=Zero(); }
  spread(i,b-a);
  if(b<=l) return N;
  if(l<=a && !cmp(v,f(x,V[i].v))){ x=f(x,V[i].v); return N; }
  if(b-a==1) return a;
  int q1 = find(l,v,a,(a+b)/2,i*2);
  if(q1!=N) return q1;
  return find(l,v,(a+b)/2,b,i*2+1);
 }
};

int N,Q;
RQ G;

int main(){
 scanf("%d%d",&N,&Q);
 G.init(N);
 rep(i,N){
  int a; scanf("%d",&a);
  G.upd(i,a);
 }
 rep(q,Q){
  int c; scanf("%d",&c);
  if(c==1){
   int x,v; scanf("%d%d",&x,&v); x--;
   G.upd(x,v);
  }
  if(c==2){
   int l,r; scanf("%d%d",&l,&r); l--;
   printf("%lld\n",G.query(l,r));
  }
  if(c==3){
   int x,v; scanf("%d%d",&x,&v); x--;
   printf("%d\n",min(G.find(x,v),N)+1);
  }
 }
 
 return 0;
}


Measured memory_bytes: 11436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, k, h[maxn];
int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    while(cin >> n >> k) {
        if(n == k) cout << n + k << endl;
        else cout << 2*max(n, k)-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector< pair<int, int> > bfs(const vector< vector< pair<int, int> > > &G,
                             int v) {
    int N = G.size();
    vector< pair<int, int> > res(N, make_pair(INF, INF));
    res[v] = make_pair(0, v);

    // コスト、最小 idx、現在地
    deque< tuple<int, int, int> > deq;
    deq.emplace_back(0, v, v);
    while(deq.size()) {
        int cost, min_idx, pos; tie(cost, min_idx, pos) = deq.front();
        deq.pop_front();

        for(auto e : G[pos]) {
            int to, c; tie(to, c) = e;
            int n_cost = cost + c, n_min_idx = min(min_idx, to);
            if(res[to] > make_pair(n_cost, n_min_idx)) {
                res[to] = make_pair(n_cost, n_min_idx);
                if(c == 1) deq.emplace_back(n_cost, n_min_idx, to);
                else deq.emplace_front(n_cost, n_min_idx, to);
            }
        }
    }
    return res;
}

int main() {
    int N, A, B, C; cin >> N >> A >> B >> C;
    vector< vector< pair<int, int> > > G(N + 3);
    int PA = N, PB = N + 1, PC = N + 2;
    for(int i=0; i<A; i++) {
        int a; cin >> a; a--;
        G[a].emplace_back(PA, 0);
        G[PA].emplace_back(a, 0);
    }
    for(int i=0; i<B; i++) {
        int b; cin >> b; b--;
        G[b].emplace_back(PB, 0);
        G[PB].emplace_back(b, 0);
    }
    for(int i=0; i<C; i++) {
        int c; cin >> c; c--;
        G[c].emplace_back(PC, 0);
        G[PC].emplace_back(c, 0);
    }

    int M; cin >> M;
    for(int i=0; i<M; i++) {
        int x, y; cin >> x >> y; x--; y--;
        G[x].emplace_back(y, 1);
        G[y].emplace_back(x, 1);
    }

    auto da = bfs(G, PA);
    auto db = bfs(G, PB);
    auto dc = bfs(G, PC);

    pair<int, int> ans(INF, INF);
    for(int i=0; i<N; i++) {
        int cost = da[i].first + db[i].first + dc[i].first;
        int midx = min({da[i].second, db[i].second, dc[i].second});
        if(ans > make_pair(cost, midx)) ans = make_pair(cost, midx);
    }
    cout << ans.first << " " << ans.second + 1 << endl;
    return 0;
}




Measured memory_bytes: 15052
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  ll a=100;
  ll b=0;
  ll ans=0;
  cin >> b;
  while (a < b) {
    a*=1.01;
    ans++;
  }
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

const int MOD = 1000000007;

int modpow(int a, int e){
  int ret = 1;
  while(e > 0){
    if(e&1) ret = (1ll*ret*a)%MOD;
    a = 1ll*a*a%MOD;
    e>>=1;
  }
  return ret;
}

typedef std::pair<ll, ll> PLL;

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
  int n;
  std::cin >> n;

  std::map<PLL, PII> map;
  int solo = 0;

  FOR(i, n){
    ll a, b;
    std::cin >> a >> b;
    if(a == 0 && b == 0){
      solo++;
      continue;
    }
    if(a == 0){
      map[MP(0ll, 1ll)].X++;
    }else if(b == 0){
      map[MP(0ll, 1ll)].Y++;
    }else{
      if(b < 0) a *= -1, b *= -1;
      ll gc = std::gcd(std::abs(a), std::abs(b));
      a /= gc;
      b /= gc;
      if(a < 0) map[MP(b, -a)].Y++;
      else map[MP(a, b)].X++;
    }
  }

  int ans = 1;

  TRAV(pr, map){
    int cur = 1;
    cur = (cur+modpow(2, pr.Y.X)-1)%MOD;
    cur = (cur+modpow(2, pr.Y.Y)-1)%MOD;
    if(cur < 0) cur += MOD;
    
    ans = (1ll*ans*cur)%MOD;
  }

  std::cout << (ans-1+MOD+solo)%MOD << "\n";

	return 0;
}

Measured memory_bytes: 16120
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


N,X =[int(i) for i in input().split()]
c = [int(i) for i in input().split()]

for i in range(N):
    c[i] = abs(c[i] - X)

print(gcd_list(c))

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;  
  int d = 0;
  multiset<int> s;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    d = max(d, x);
    s.insert(x);
  }
  if (d % 2 == 0) {
    for (int i = d / 2 + 1; i <= d; i++) {
      for (int j = 0; j < 2; j++) {
        if (!s.count(i)) {
          cout << "Impossible\n";
          return 0;
        }
        s.erase(s.find(i));
      }
    }
    if (!s.count(d / 2)) {
      cout << "Impossible\n";
      return 0;
    }
    s.erase(s.find(d / 2));
    for (auto& it : s) {
      if (it < d / 2 + 1) {
        cout << "Impossible\n";
        return 0;
      }
    }
  } else {
    for (int i = d / 2 + 1; i <= d; i++) {
      for (int j = 0; j < 2; j++) {
        if (!s.count(i)) {
          cout << "Impossible\n";
          return 0;
        }
        s.erase(s.find(i));
      }
    } 
    for (auto& it : s) {
      if (it < d / 2 + 2) {
        cout << "Impossible\n";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  return 0;
}

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

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin.exceptions(cin.failbit);
	int n, s = 0;
	cin >> n;
	int tmp = n;
	while (tmp) {
		s += tmp % 10;
		tmp /= 10;
	}
	cout << (n % s == 0? "Yes": "No") << endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<tuple<string, int, int>> vec(N);
	for (int i = 0; i < N; i++)
	{
		cin >> get<0>(vec.at(i)) >> get<1>(vec.at(i));
		get<1>(vec.at(i)) *= -1;
		get<2>(vec.at(i)) = i + 1;
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < N; i++)
		cout << get<2>(vec.at(i)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;

int main() {
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  int e = 0;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    if (c <= 0) {
      e = 1;
      break;
    }
    a -= d;
    if (a <= 0) {
      e = 0;
      break;
    }
  }
  if (e == 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 3620
import java.util.*;

public class Main{
	
	public static void main(String[] args){

		Map<String, List<Integer>> index = new TreeMap<>();
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNextLine()){
			String line = sc.nextLine();
			String keyWord = line.split(" ")[0];
			if(keyWord.equals("end")) break;
			int page = Integer.valueOf(line.split(" ")[1]);
			index.merge(keyWord, new ArrayList<Integer>(){{add(page);}}, (O, N) -> {N.addAll(O); return N;});
		}
		
		index.keySet().forEach(S -> {
			System.out.println(S);
			index.get(S).stream().mapToInt(Integer::intValue).sorted().findFirst().ifPresent(System.out::print);
			index.get(S).stream().mapToInt(Integer::intValue).sorted().skip(1).forEach(I -> System.out.print(" " + I));
			System.out.println();
		});
		sc.close();
	}
}

Measured memory_bytes: 32228
#include <stdio.h>

int main(void){
  int i,sum;
  char num[1001];

  for(;;){
    scanf("%s", &num);
    if(num[0] == '0') break;
    
    sum = 0;
    for(i=0;num[i]!='\0';i++)
      sum += num[i] - '0';
    printf("%d\n", sum);
  }
  
  return 0;
}

Measured memory_bytes: 536
package main

import (
	"fmt"
	"strings"
)

// 2018-08-03T23:01:50+0800
// 2018-08-03T23:12:52+0800
func main() {
	var S string
	fmt.Scanf("%s", &S)
	n := len(S)
	for ; true; {
		S = strings.Replace(S, "WW", "W", -1)
		S = strings.Replace(S, "BB", "B", -1)
		if n == len(S) {
			break
		}
		n = len(S)
	}
	switch len(S) {
	case 1:
		fmt.Println(0)
	case 2:
		fmt.Println(1)
	default:
		fmt.Println(len(S) - 1)
	}
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>


int ASC(const void *a,const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int main(void)
{
	char s[100];
	scanf("%s",s);
	int n = strlen(s);
	for (int i = 0; i < n/2; i++) {
		if (s[i] != s[n - 1 - i]) {
			printf("No");
			return 0;
		}
	}
	for (int i = 0; i < (n - 1) / 4; i++) {
		if (s[i] != s[(n - 1) / 2 - i - 1]) {
			printf("No");
			return 0;
		}
	}

	for (int i = (n + 3)/2 -1 ; i < n - 1; i++) {
		if (s[i] != s[n-i-1]) {
			printf("No");
			return 0;
		}
	}
	
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void push(int);
int pop (void);

int stack[100];
int top=0;

int main(){

  int a,b;
  char s[100];  

  while(scanf("%s",s)!=EOF){
      if(s[0]=='+'){
	a=pop();
	b=pop();
	push(a+b);
      }
      else if(s[0]=='-'){
	a=pop();
	b=pop();
	push(b-a);
      }
      else if(s[0]=='*'){
	a=pop();
	b=pop();
	push(a*b);
      }
      else{
	push(atoi(s));
      }
  }

  printf("%d\n",pop());

  return 0;
}

void push(int x){

  top=top+1;
  stack[top]=x;
  
}

int pop(void){
    top=top-1;
    return stack[top+1];
}

Measured memory_bytes: 548
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<string>
using std::string;

int main()
{
  string s;
  cin >> s;
  
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;

  return 0;
}


Measured memory_bytes: 3624
#                               #
    # author : samars_diary #
    # 18-09-2020 │ 15:00:33 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a=i()
    if a.isupper():
        print('A')
    else:
        print('a')

for _ in range(1):
    solve()

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) >= K) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int, in){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}

#define all(o) o.begin(), o.end()

void radix_sort(vector<int> &v) {
	vector<int> t(v.size());
	array<int, 256> c, s;
	for (int i = 0; i < 32; i += 8) {
		fill(all(c), 0);
		for_each(all(v), [&](int j) {c[(j >> i) & 255]++;});
		s.front() = 0;
		partial_sum(all(c) - 1, s.begin() + 1);
		for_each(all(v), [&](int j) {t[s[(j >> i) & 255]++] = j;});
		swap(v, t);
	}
}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		radix_sort(u);
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			r = max(r, *i + *e);
		}
		outl(r);
	}
}


Measured memory_bytes: 6284
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  ll N,M,l,r,C=1;cin >> N >> M;
  pii P[100007];
  bool T=false;
  rep(i,M){
    cin >> P[i].first >> P[i].second;
  }
  psortsecond(P,M);
  psortfirst(P,M);
  rep(i,M){
    if(T==false){
      l=P[i].first;
      r=P[i].second;
      T=true;
    }
    else{
      if(P[i].first>=r){
        l=P[i].first;
        r=P[i].second;
        C++;
      }
      else if(P[i].second<r){
        r=P[i].second;
      }
    }
  }
  cout << C << endl;
}

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

int n, k, a[555];

int isGood(int g)
{
  int b[555];
  for (int i = 0; i < n; i++)
    b[i] = a[i] % g;
  sort(b, b + n);
  long long cost = 0;
  for (int i = 0, j = n - 1; i <= j;)
  {
    if (i == j)
      return 0;
    int use = min(b[i], g - b[j]);
    cost += use;
    b[i] -= use;
    b[j] += use;
    if (!b[i])
      i++;
    if (b[j] == g)
      j--;
  }
  return cost <= k;
}

int main()
{
  int sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }

  int ans = 1;
  for (int i = 1; i * i <= sum; i++)
  {
    if (isGood(i))
      ans = max(ans, i);
    if (isGood(sum / i))
      ans = max(ans, sum / i);
  }

  cout << ans << endl;
}


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

int main() {	
	ll n,m,a;
	scanf("%lld%lld",&n,&m);
	a = min(n,m/2);
	if(n-a == 0) a += (m-a*2)/4;
	printf("%lld\n",a);
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    priority_queue<int, vector<int>, greater<int>> L;
    priority_queue<int> R;
    ll lsum = 0, rsum = 0;
    rep(i, 0, N) {
        int a; cin >> a;
        L.push(a);
        lsum += a;
    }
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) {
        int a; cin >> a;
        R.push(a);
        rsum += a;
    }
    ll ans = lsum - rsum;
    vector<ll> left(N+1), right(N+1);
    left[0] = lsum;
    right[0] = rsum;
    rep(i, 0, N) {
        L.push(A[i]);
        lsum += A[i];
        lsum -= L.top();
        L.pop();
        left[i+1] = lsum;
    }
    reverse(A.begin(), A.end());
    rep(i, 0, N) {
        R.push(A[i]);
        rsum += A[i];
        rsum -= R.top();
        R.pop();
        right[i+1] = rsum;
    }
    rep(i, 0, N+1) ans = max(ans, left[i] - right[N-i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll h, w, d;
    cin >> h >> w >> d;
    vvll a(h, vll(w));
    vll x(h*w+1, 0);
    vll y(h*w+1, 0);
    vll cost(h*w+1-d, 0);
    vll costcs(h*w+1-d, 0);
    rep(i, h)rep(j, w){
        cin >> a[i][j];
        x[a[i][j]] = i;
        y[a[i][j]] = j;
    }
    repr(i, 1, h*w+1-d){
        cost[i] = abs(x[i+d]-x[i])+abs(y[i+d]-y[i]);
    }
    repr(i, 1, min(d+1, h*w+1-d)){
        costcs[i] = cost[i];
    }
    repr(i, min(d+1, h*w+1-d), h*w+1-d){
        costcs[i] = costcs[i-d] + cost[i];
    }
    dump(cost);
    dump(costcs);
    ll q;
    cin >> q;
    rep(i, q){
        ll ans = 0;
        ll l, r;
        cin >> l >> r;
        if(l == r) ans = 0;
        else if(l-d >= 1) ans = costcs[r-d]-costcs[l-d];
        else ans = costcs[r-d];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int max(int a,int b)
{
	if(a<=b)
		return b;
	return a;
}
int main()
{
	int n;
	cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	vector<vector<int>> table(n,vector<int>(3,0));
	table[n-1][0] = max(b[n-1],c[n-1]);
	table[n-1][1] = max(a[n-1],c[n-1]);
	table[n-1][2] = max(a[n-1],b[n-1]);
	if(n==1)
	{	
		cout<<max(table[n-1][0],max(table[n-1][1],table[n-1][2]));
		return 0;
	}
	for(int i=n-2;i>=1;i-=1)
	{
		table[i][0] = max(b[i]+table[i+1][1],c[i]+table[i+1][2]);
		table[i][1] = max(a[i]+table[i+1][0],c[i]+table[i+1][2]);
		table[i][2] = max(a[i]+table[i+1][0],b[i]+table[i+1][1]);
	}	
	cout<<max(a[0]+table[1][0],max(b[0]+table[1][1],c[0]+table[1][2]));
	return 0;
}

Measured memory_bytes: 9792
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

struct Edge {
    int to;
    int timeCost;
    int silverCost;
    Edge() {
    }

    Edge(int pt, int ptc, int psc) : to(pt), timeCost(ptc), silverCost(psc) {
    }
};

struct Node {
    int now;
    int silver;
    long long timeCost;
    Node() {
    }

    Node(int n, int s, long long t) : now(n), silver(s), timeCost(t) {
    }

    bool operator<(const Node& n) const {
        return timeCost > n.timeCost; // reverse pq order
    }
};

using VLL = vector <long long>;
using VVLL = vector< VLL >;

using VI = vector <int>;
using VVI = vector< VI >;

using VE = vector<Edge>;
using VVE = vector<VE>;

const long long INF = 1000000LL * 1000000000LL;

int main() {
    int N;
    int M;
    int S;

    cin >> N >> M >> S;

    VVE adja(N);

    VI goldSilver(N);
    VI goldTime(N);

    for (int i = 0; i < M; ++i) {
        int from;
        int to;
        int T;
        int C;
        cin >> from >> to >> C >> T;
        --from;
        --to;
        adja[from].emplace_back(Edge(to, T, C));
        adja[to].emplace_back(Edge(from, T, C));
    }

    for (int i = 0; i < N; ++i) {
        cin >> goldSilver[i] >> goldTime[i];
    }

    const int UPPER = 60;
    VVLL best(N, VLL(N*UPPER + 1, INF));

    priority_queue < Node > pq;
    pq.push(Node(0, min(S, UPPER*N), 0));
    best[0][min(S, UPPER*N)] = 0;

    while (!pq.empty()) {
        Node now = pq.top();
        pq.pop();
        int nowv = now.now;

        if (now.timeCost > best[nowv][now.silver]) {
            continue;
        }

        // cout << "DEBUG " << nowv << " " << now.silver << " " << now.timeCost << endl;

        for (int i = 0; i < adja[nowv].size(); ++i) {
            int nextv = adja[nowv][i].to;

            // cout << "INN " << nowv << " " << nextv << endl;

            for (int j = 0; true; ++j) {
                int newS = now.silver + j*(long long)goldSilver[nowv];
                long long timeCost = best[nowv][now.silver] + j*(long long)goldTime[nowv];

                if (newS <= UPPER*N || j == 0) {
                    int nnewS = newS - adja[nowv][i].silverCost;
                    if (nnewS < 0) {
                        continue;
                    }
                    long long nnewT = timeCost + adja[nowv][i].timeCost;

                    // cout << "TRY " << nextv << " " << nnewS << " " << nnewT << endl;

                    if (nnewT < best[nextv][nnewS]) {
                        best[nextv][nnewS] = nnewT;
                        pq.push(Node(nextv, nnewS, nnewT));
                    }
                } else {
                    break;
                }
            }
        }
    }

    for (int i = 1; i < N; ++i) {
        long long minVal = INF;
        for (int j = 0; j <= UPPER*N; ++j) {
            minVal = min(minVal, best[i][j]);
        }

        cout << minVal << endl;
    }

    return 0;
}

Measured memory_bytes: 37400
import sys
import math
sys.setrecursionlimit(10**9)

X, Y = map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if (X + Y) % 3 == 0:
    n_plus_m = (X + Y) // 3
    if X > Y:
        diff = X - Y
    else:
        diff = Y - X
    n = (n_plus_m + diff) // 2 
    print(cmb(n_plus_m, n, mod))
else:
    print(0)

Measured memory_bytes: 121856
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF 999999999999999999
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll x,i;
       cin>>x;
       for(i=1;;i++)
       {
           if((x*i)%360==0)
           {
               cout<<i<<"\n";
               return 0;
           }
       }       
   }
}

Measured memory_bytes: 3636
/**
 *    author:  math2do
 *    created: 18.01.2020 22:04:36
**/

#include <bits/stdc++.h>

using namespace std;

const int mod = (int) (1e9 + 7);

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector <vector <char>> mat(n, vector <char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
    }
  } 
  vector <vector <int>> dp(n, vector <int>(m, 0));
  dp[0][0] = 1;
  for (int j = 1; j < m; j++) {
    if (mat[0][j] == '#') {
      dp[0][j] = 0;
      continue;
    }
    dp[0][j] = dp[0][j - 1]; 
  }

  for (int i = 1; i < n; i++) {
    if (mat[i][0] == '#') {
      dp[i][0] = 0;
      continue;
    }
    dp[i][0] = dp[i - 1][0]; 
  }
   
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (mat[i][j] == '#') {
        dp[i][j] = 0;
        continue;
      }
      add(dp[i][j], dp[i - 1][j]);
      add(dp[i][j], dp[i][j - 1]);
    }
  } 
  
  cout << dp[n - 1][m - 1] << '\n';
  return 0;
}


Measured memory_bytes: 5248
#include <stdio.h>

int main(void) {
	int x, y;
	
	while (scanf("%d %d", &x, &y), x || y) {
		if (x > y) printf("%d %d\n", y, x);
		else printf("%d %d\n", x, y);
	}
	
	return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> pri(n);
    for(int i=0; i<n; i++){
        cin >> pri[i];
    }
    sort(pri.begin(), pri.end());
    int sum = 0;
    for(int i=0; i<k; i++){
        sum += pri[i];
    }
    cout<< sum <<endl;
    
    return 0;
}

Measured memory_bytes: 3660