akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Text;

class Problem {
    public static void Main() {
        var str = "";
        while ((str = Console.ReadLine()) != "0 0") {
            var data = str.Split().Select(int.Parse).ToArray();
            var line = "";
            for (var i = 0; i < data[1]; i++) line += "#";
            for (var i = 0; i < data[0]; i++) Console.WriteLine(line);
            Console.WriteLine();
        }
    }
}


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


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

    cout<<(x-a)%b<<endl;

    return 0;
}


Measured memory_bytes: 256
nq = gets.split.map(&:to_i)
ary = Array.new(nq[0]){[]}

nq[1].times do
  odr = gets.split.map(&:to_i)
  case odr[0]
  when 0
    ary[odr[1]] << odr[2]
  when 1
    puts ary[odr[1]].join(" ")
  when 2
    ary[odr[1]].clear
  end
end


Measured memory_bytes: 15816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final char[] input = sc.next().toCharArray();
		int[] counts = new int[26];
		int[] ans = new int[26];
		
		for(char ch : "AIDUNYAN".toCharArray()){
			ans[ch - 'A']++;
		}
		
		LinkedList<Character> buffer = new LinkedList<Character>();
		for(int i = 0; i < input.length; i++){
			buffer.offer(input[i]);
			counts[input[i] - 'A']++;
			
			if(buffer.size() >= "AIDUNYAN".length()){
				
				boolean ok = true;
				for(int j = 0; j < 26; j++){
					if(counts[j] != ans[j]){
						ok = false;
						break;
					}
				}
				
				if(ok){
					System.out.print("AIZUNYAN");
					Arrays.fill(counts, 0);
					buffer.clear();
				}else{
					System.out.print(buffer.peek());
					counts[buffer.poll() - 'A']--;
				}
			}	
		}
		
		while(!buffer.isEmpty()){
			System.out.print(buffer.poll());
		}
		System.out.println();
		
		sc.close();
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			if (tok == null) {
				return false;
			} else {
				return tok.hasMoreTokens();
			}
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public void close() throws IOException {
			br.close();
		}
	}

}

Measured memory_bytes: 17184
from sys import stdin
def main():
    n = int(input())
    ab = [list(map(int, stdin.readline().split())) for i in range(n)]
    ab.sort(key=lambda x:x[1])
    now = 0
    cnt = 0

    for a, b in ab:
        now += a
        if now > b: break
    else:
        print("Yes")
        return 0
    print("No")


if __name__=="__main__": main()

Measured memory_bytes: 53736
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005

using namespace std;
 
typedef long long ll;

int k,x;

int main()
{
    cin >> k >> x;

    for (int i = x - k + 1; i < x + k; ++i)
    {
    	cout << i << " ";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<algorithm>
#include<math.h>
#include"boost/algorithm/string.hpp"

using namespace std;

typedef struct {
	long long point;
	long long no;


}dish_t;


int main(){


	/*Q3*/
	/*Q2*/

	int n;
	int sum = 0;
	int max = 0;
	int tmp;

	cin >> n;

	for (int i = 0; i < n; ++i){
		cin >> tmp;
		sum += tmp;

		if (max < tmp){
			max = tmp;
		}
	}


	if (max < (sum - max)){
		cout << "Yes" << endl;

	}
	else{
		cout << "No" << endl;
	}




	return 0;

	/*Q1*/
	//typedef
	/*

	int x, t = 0;
	
	cin >> t >> x;

	double  ret = (double)t / x;

	cout << ret << endl;;

	return 0;

	/*Q2*/

	/*Q3*/

		/*Q4*/

		//return 0;
}


Measured memory_bytes: 256
def read_input():
    n = int(input())
    s = input()

    return n, s

def submit():
    n, s = read_input()

    max_common = 0
    for i in range(1, n):
        f = s[:i]
        l = s[i:]

        fc = set([c for c in f])
        lc = set([c for c in l])

        common = fc.intersection(lc)
        if max_common < len(common):
            max_common = len(common)

    print(max_common)

if __name__ == '__main__':
    submit()


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

int main() {
  string s;
  cin >> s;
  bool ok = true;
  if (s[0] != 'A') ok = false;
  int cnt = 0;
  for (int i = 1; i < s.size(); i++) {
    if (i >= 2 && i <= s.size() - 2) {
      if (s[i] == 'C') {
        cnt++;
        continue;
      }
    }
    if (!islower(s[i])) {
      ok = false;
    }
  }
  if (cnt != 1) ok = false;
  if (ok) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"


ll number=0;  // divisible


void printDivisibleNumber(int arr[], int n){
   unordered_set<int> s;
   int maxElement = INT_MIN;
   for (int i = 0; i < n; i++) {
      s.insert(arr[i]);
      maxElement = max(maxElement, arr[i]);
   }
   unordered_set<int> res;
   for (int i = 0; i < n; i++) {
      if (arr[i] != 0) {
         for (int j = arr[i] * 2; j <= maxElement; j += arr[i]) {
            if (s.find(j) != s.end())
               res.insert(j);
            }
         }
      }
   unordered_map<int, int> mp;
   for (int i = 0; i <n; i++)
      mp[arr[i]]++;
   unordered_map<int, int>::iterator it;
   vector<int> ans;
   for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= 2) {
         if (res.find(it->first) == res.end()) {
            int val = it->second;
            while (val--)
               ans.push_back(it->first);
         }
      }
      if (res.find(it->first) != res.end()) {
         int val = it->second;
         while (val--)
            ans.push_back(it->first);
      }
   }
   for (auto x : ans){
        number++;
   }

}
int main(){

    int n;
    cin>>n;

    int a[n];

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

    printDivisibleNumber(a,n);
    cout<<n-number;

    return 0;
}

Measured memory_bytes: 30584
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    char values[4] = {'A', 'C', 'G', 'T'};
    map<char, int> vals;
    vals.insert(mp('A', 3)); vals.insert(mp('C', 2)); vals.insert(mp('G', 1)); vals.insert(mp('T', 0));
    string data, ans; cin >> data;
    F0R(i, sz(data)) {
		ans += values[vals[data[i]]];
	}
	
	cout << ans << endl;
    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx,sy,tx,ty,dx,dy,j;
  cin>>sx>>sy>>tx>>ty;
  dx=tx-sx;
  dy=ty-sy;
  for(j=0;j<dx;j++) cout<<'R';
  for(j=0;j<dy;j++) cout<<'U';
  for(j=0;j<dx;j++) cout<<'L';
  for(j=0;j<=dy;j++) cout<<'D';
  for(j=0;j<=dx;j++) cout<<'R';
  for(j=0;j<=dy;j++) cout<<'U';
  cout<<"LU";
  for(j=0;j<=dx;j++) cout<<'L';
  for(j=0;j<=dy;j++) cout<<'D';
  cout<<'R'<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int a=0,b=0,ab=0,count=0;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        if(s[0]=='B'){
            if(s[s.size()-1]=='A')ab++;
            else b++;
        }
        else if(s[s.size()-1]=='A')a++;
        for(int i=0;i<s.size()-1;i++){
            if(s[i]=='A'&&s[i+1]=='B')count++;
        }
    }
    if(ab){
    count+=ab-1;
    if(a){
        count++;
        a--;
    }
    if(b){
        count++;
        b--;
    }
    count+=min(a,b);
    }
    else{
        count+=min(a,b);
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

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

	long long L[87];
	L[0] = 2;
	L[1] = 1;

	for (int i = 2; i <= N; i++)
	{
		L[i] = L[i - 1] + L[i - 2];
	}

	cout << L[N] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


const int max_comb=300000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}

int n,k;
vector<vector<int> > g;

ll ans;

bool dfs( int par, int curr)
{
    int siz=(int)g[curr].size();
    
    int cnt0=(par>=0? 2: 1);
    int cnt=0;
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(next==par) continue;
        cnt++;
    }
    int sel = k-cnt0;
    if(sel<cnt) {
        return false;
    }
    ans = ans * perm(sel, cnt) %MOD;

    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(next==par) continue;
        
        bool bOk=dfs(curr, next);
        if(!bOk) {
            return false;
        }
    }

    return true;
}

int main(int argc, char* argv[])
{
    scanf("%d%d", &n, &k);

    g.resize(n);
    int i;
    for(i=0; i<n-1; i++) {
        int a,b;
        scanf("%d%d", &a, &b);
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }

    pre_comb();
    ans=k;
    bool bOk = dfs(-1, 0);
    if(!bOk) {
        printf("0\n"); return 0;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 13952
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;



public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();

		long N = fs.nextLong();
		long A = fs.nextLong();
		long B = fs.nextLong();
		long s = 0;


		long x = A + B;
		long y = (long) (N / x);
		s = y * A;
		long nokori = N - x * y;
		if(nokori < A) {
			s += nokori;
		}else {
			s+=A;
		}





		System.out.println(s);


	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n;
    string s;
    cin>>n>>s;
    bool is=true;
    if(n%2!=0){
        is=false;
    }else{
        REP(i,n/2){
            if(s[i]!=s[i+n/2]){
                is=false;
                break;
            }
        }
    }
    if(is){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;

public class Main {

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(st==null || !st.hasMoreElements()){
                try{
                    st=new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt(){
            return Integer.parseInt(next());
        }

        Long nextLong(){
            return Long.parseLong(next());
        }

        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str="";
            try{
                str=br.readLine();
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
      int a=in.nextInt();
      int b=in.nextInt();
      int c=in.nextInt();
      int d =in.nextInt();
      while(true){
          c=c-b;
          a=a-d;
          if(c<=0){
              System.out.println("Yes");
              break;
          }else if(a<=0){
              System.out.println("No");
              break;
          }
      }
    }
}



Measured memory_bytes: 32744
if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    roads=[0 for i in range(N)]
    for i in range(M):
        a,b=list(map(int,input().split()))
        roads[a-1]+=1
        roads[b-1]+=1

    for road in roads:
        print(road)

Measured memory_bytes: 38256
import java.util.*;
import java.io.*;
 
class Main{
    public static void main(String args[])throws IOException{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       String s;
       int[] num = new int[26];
       char c;
       while((s = br.readLine())!=null){
           if(s.length()>=1200)break;
           for(int j=0; j<s.length(); j++){
               c = s.charAt(j);
               if(c>=0x41 && c<=0x5a){
                   c -= 0x41;
                   num[c] += 1;
               }else if(c>=0x61 && c<=0x7a){
                   c -= 0x61;
                   num[c] += 1;
               }
           }
       }
       for(int i=0; i<26; i++){
           c = (char)(0x61 + i);
           System.out.println(c+" : "+num[i]);    
       }
    }
}

Measured memory_bytes: 16872
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


ll R[399];

int main() {

	int X,Y,Z;
	scanf("%d%d%d", &X,&Y,&Z);

	int ans;

	for (int i = 0; i < 100000; i++) {
		if (X - Y*i >=  Z * (i + 1)) {
			ans = i;
		}
		else {
			break;
		}
	}

	printf("%d", ans);


}


void  bubbleSort(char number[]) {
	for (int i = 0; i < strlen(number); i++)
		for (int j = i + 1; j < strlen(number); j++)
			if ((int)number[i] > (int)number[j]) {
				char tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

var (
	a []int
)

func main() {
	a = make([]int, 5)
	fmt.Scan(&a[0])
	fmt.Scan(&a[1])
	fmt.Scan(&a[2])
	fmt.Scan(&a[3])
	fmt.Scan(&a[4])

	last := 0
	for i, t := range a {
		if t % 10 == 0 {
			continue
		}
		if a[last] % 10 == 0 {
			last = i
		}
		if a[last] % 10 > t % 10 {
			last = i
		}
	}
	tmp := a[len(a)-1]
	a[len(a)-1] = a[last]
	a[last] = tmp

	sum := 0
	for _, t := range a[:len(a)-1] {
		if t%10 > 0 {
			t += 10 - (t % 10)
		}
		sum += t
	}
	sum += a[len(a)-1]

	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;
 
#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
#define mp make_pair
 
const ll INF = (ll)1e15;
const int N = 100100;
vector<pli> g[N];
vector<pli> G[N];
int s, t;
ll dist[N];
ll a[N];
ll ans[N];
int n, m;
 
void dijkstra(int v) {
	set<pli> setik;
	for (int i = 0; i < n; i++) {
		dist[i] = INF;
		if (i == v)
			dist[i] = 0;
		setik.insert(mp(dist[i], i));
	}
	while(!setik.empty()) {
		v = setik.begin()->second;
		setik.erase(setik.begin());
		for (pli e : g[v]) {
			int u = e.second;
			ll w = dist[v] + e.first;
			if (w >= dist[u]) continue;
			setik.erase(mp(dist[u], u));
			dist[u] = w;
			setik.insert(mp(dist[u], u));
		}
	}
}
 
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
 
	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--;t--;
	while(m--) {
		int v, u;
		ll a, b;
		scanf("%d%d%lld%lld", &v, &u, &a, &b);
		v--;u--;
		g[v].push_back(mp(a, u));
		G[v].push_back(mp(b, u));
		g[u].push_back(mp(a, v));
		G[u].push_back(mp(b, v));
	}
 
	dijkstra(s);
	swap(dist, a);
	for (int i = 0; i < n; i++)
		swap(g[i], G[i]);
	dijkstra(t);
 
	for (int i = 0; i < n; i++)
		ans[i] = a[i] + dist[i];
 
	for (int i = n - 2; i >= 0; i--)
		ans[i] = min(ans[i], ans[i + 1]);
	for (int i = 0; i < n; i++)
		printf("%lld\n", INF - ans[i]);
 
	return 0;
}

Measured memory_bytes: 25216
n, x = map(int, input().split())
x -= 1
npl = [0] * (n+1)
lbl = [0] * (n+1)
npl[0] = 1
lbl[0] = 1
for i in range(1, n+1):
    npl[i] = 2*npl[i-1] + 1
    lbl[i] = 2*lbl[i-1] + 3

ans = 0
while n >= 0:
    n -= 1
    if x == 0:
        # 左端
        if n == -1:
            ans += 1
        break
    elif 1 <= x <= lbl[n]:
        # 左側
        x -= 1
    elif lbl[n]+1 == x:
        # 真中
        ans += npl[n] + 1
        break
    elif lbl[n]+1 < x < 2*lbl[n]+2:
        # 右側
        x -= lbl[n]+2
        ans += npl[n]+1
    elif x == 2 + 2*lbl[n]:
        # 右端
        ans += 2*npl[n] + 1

print(ans)


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    } else if (a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main(){
  int n,m;
  cin >>n>>m;
  int a[m],b[m],ans[n];
  
  for(int i=0;i<m;i++)
    cin >> a[i]>>b[i];
  
  for(int i=0;i<n;i++){
    ans[i]=0;
    for(int j=0;j<m;j++){
      if(a[j]==i+1)
        ans[i]++;
      if(b[j]==i+1)
        ans[i]++;
    }
    cout<<ans[i]<<endl;
  }

  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a,b,c,d,ac,bd;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if (a > c) {
        ac = a;
    } else {
        ac = c;
    }
    if (b > d) {
        bd = d;
    } else {
        bd = b;
    }
    if (bd - ac > 0) {
        printf("%d\n",bd - ac);
    } else {
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

class Team{
public:
  int n,m,s;
  bool operator < (const Team &t)const{
    if(m == t.m) return s < t.s;
    else return m < t.m;
  }
};

int main(){
  int i,j,n;
  while(1){
    cin >> n;
    if(n == 0) break;
    Team t[1000000];

    for(i=0;i<n;i++){
      cin >> t[i].n;
      t[i].m = t[i].s = 0;

      for(j=0;j<4;j++){
	int m,s;
	cin >> m >> s;
	t[i].m += m;
	t[i].s += s;
      }

      while(t[i].s >= 60){
	t[i].m++;
	t[i].s -= 60;
      }
    }

    sort(t,t+n);
    cout << t[0].n << endl;
    cout << t[1].n << endl;
    cout << t[n-2].n << endl;
  }  
  return 0;
}

Measured memory_bytes: 908
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
#define N 1005
#define inf 1000000000
using namespace std;
int t;
int n;

int main(){
    char c=getchar();
    printf((c>='a' && c<='z') ? "a" :"A");
	return 0;
} 

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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s != "AAA" && s != "BBB") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int h, w;
map<char, int> mp;
void in(){
    cin >> h >> w;
    rep(i,0,h * w){
        char t;
        cin >> t;
        mp[t]++;
    }
}

void solve(){
    
    vi mods(5,0);
    for(auto e : mp) mods[e.second % 4]++;

    if(h % 2 == 0 && w % 2 == 0){
        for(auto e : mp){
            if(e.second % 4 != 0){
                print("No");
                return ;
            }
        }
        print("Yes");
        return ;
    }

    if(h % 2 == 1 && w % 2 == 1){
        bool isok = true;
        if(mods[3]) isok = false;
        if(mods[1] != 1) isok = false;
        if(mods[2] > (h - 1)/2 + (w - 1)/2) isok = false;

        print(isok ? "Yes" : "No");
        return ;
    }

    int even = (h % 2 == 0 ? h : w);
    bool isok = true;
    if(mods[1] or mods[3]) isok = false;
    if(mods[2] > even / 2) isok = false;

    print(isok ? "Yes" : "No");

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

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

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
  int main(){
   int n,h,i,j,x,apoint,bpoint;
    int a[10000],b[10000];
    for(h=0;h<10000;h++){
      a[h]=0;
       b[h]=0;
}
apoint=0;
bpoint=0;
   for(j=0;j>=0;j++){
    scanf("%d",&n);
     if(n==0){
      break;
}
     for(i=0;i<n;i++){
      scanf("%d %d",&a[i],&b[i]);
     
       if(a[i]<b[i]){
         bpoint += a[i]+b[i];
}else if(a[i]>b[i]){
          apoint += a[i]+b[i];
}else{
          apoint += a[i];
          bpoint += b[i];
}
}
printf("%d",apoint);
printf(" %d\n",bpoint);
apoint =0;
bpoint =0;
}
return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  string s;
  cin >> n >> s;
  int l = 0, count = 0;
  REP(i, n){
    if(s[i] == '(') count++;
    else{
      if(count > 0) count--;
      else l++;
    }
  }
  int r = count;
  string ans;
  if(l > 0) ans += string(l, '(');
  ans += s;
  if(r > 0) ans += string(r, ')');
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N, X; cin >> N >> X;
    vei m(N);
    rep(i,N) cin >> m[i];
    int sum = 0;
    rep(i,N) sum += m[i];

    int ans = N;
    X -= sum;
    int mi = *min_element(m.begin(),m.end());
    while(X >= mi){
        ans += 1;
        X -= mi;
    }
    cout << ans << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
string S[55],T[55];


int ok(int x,int y) {
	int i,j;
	FOR(i,M) FOR(j,M) if(S[i+x][j+y]!=T[i][j]) return 0;
	return 1;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) cin>>S[i];
	FOR(i,M) cin>>T[i];
	FOR(i,N-M+1) FOR(j,N-M+1) if(ok(i,j)) return _P("Yes\n");
	_P("No\n");
	 
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int main(){
	long long n,m,d;
	cin>>n>>m>>d;
	long long V=(n-d)*2;
	if(!d) V/=2;
	cout<<fixed<<setprecision(10)<<(long double)V/(n*n)*(m-1);
	return 0;
}


Measured memory_bytes: 256
import math
h,w = map(int,input().split())
ans = 0

if h == 1 or w ==1 :
  ans += 1

else:
    #奇数行目+偶数行目
    ans += math.ceil(h/2)*math.ceil(w/2)+(h//2)*(w//2)
 
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<limits>

using namespace std;

const int MAX_N = 100;
const int MAX_W = 100000;

int N, W;
long w[MAX_N+1];
long v[MAX_N+1];
long dp[MAX_N+2][MAX_W+2];  // dp[i][j] 残り重さが j で i 番目の品物選択後の最大価値


// i: 品物番号 j: 残り重さ
long rec(int i, int j) {
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    long res;
    if (i == N+1) {
        res = 0;
    } else if (j < w[i]) {
        res = rec(i+1, j);
    } else {
        res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
    }
    return dp[i][j] = res;
}

void solve() {
    memset(dp, -1, sizeof(dp));
    cout << rec(1, W) << endl;
}

int main() {
    cin >> N >> W;
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    solve();
}


Measured memory_bytes: 80000
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n, t;
  cin >> n >> t;
  int a[n];
  REP(i, n) cin >> a[i];
  map<int, int> m;
  priority_queue<int> q;
  q.push(a[n-1]);
  REP(i, n-1){
    int f = q.top();
    m[f-a[n-i-2]]++;
    q.push(a[n-i-2]);
  }
  int mp = 0, ans = 0;
  for(auto i = m.begin(); i != m.end(); ++i){
    if(i->first > mp){
      mp = i->first;
      ans = i->second;
    }
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5752
def weight
  master = Array.new(10) { |i| 2**i }
  while gets
    wei = $_.to_i
    spindles = master.select { |i| i <= wei }
    result = []
    while true
      break if wei <= 0
      minus = spindles.max
      if minus > wei
				spindles.delete(minus)
        next
      end
      foo = wei - minus
			wei = foo
      result << spindles.delete(minus)
    end
    puts result.sort.join(' ')
  end
end

weight

Measured memory_bytes: 8596
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

solv bs ass c = length $ filter id [f as | as <- ass] where
  f as = sum (zipWith (*) as bs) + c > 0

main = do
  [n,m,c] <- map read . words <$> getLine
  bs <- readInts m <$> B.getLine
  ass <- map (readInts m) . B.lines <$> B.getContents
  print $ solv bs ass c


Measured memory_bytes: 508
#include <iostream>
#include <fstream>
#include <vector>

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

using namespace std;

int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    long long ans = 0;
    int A_count = 0;
    FOR (i, n - 1){
        if (s[i] == 'A'){
            A_count++;
            continue;
        }
        if (s[i] == 'C'){
            A_count = 0;
            continue;
        }
        if (s[i] == 'B'){
            if (s[i + 1] == 'C'){
                ans += A_count;
                i++;
            }
            else{
                 A_count = 0;
                 continue;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
#include<stdio.h>
#include<stdlib.h>
void fun(int ,int );
void fun(int a,int b)
{
    if(a>0&&b>0)
    {
        printf("Positive\n");
    }
    if(a<=0&&b>=0)
    {
        printf("Zero\n");
    }
    if(a<0&&b<0)
    {
        if(abs(a-b)%2==1)
        {
            printf("Positive\n");
        }
        else
        {
            printf("Negative\n");
        }
    }
}
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    fun(a,b);
    return 0;
}

Measured memory_bytes: 128
#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>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n,0);
    for(int i=0;i<n-1;++i){
        int x;
        cin >> x;
        a[x-1] += 1;
    }
    rep(i,n) cout << a[i] << endl;
    
    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#define int long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define rc(s) return cout<<s,0
using namespace std;

int n,k,c2=1,c1,dp[100005],dp2[100005],rs,ans;
string s;


int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n >> k >> s;
    if(s[0]=='1') c2=0;
    else c2=1;
    for(int i=0;i<s.size();i++){
        int j=i;
        while(s[i]==s[i+1] && i+1<s.size()) i++;
        if(s[i]=='0') c1++,dp[c1]=(i-j+1);
        else c2++,dp2[c2]=(i-j+1);
    }
    k=min(k,c1);
    for(int i=1;i<=k;i++){
        ans+=dp[i];
        ans+=dp2[i];
    }
    ans+=dp2[k+1];
    rs=ans;
    for(int j=k+1;j<=c1;j++){
        ans+=dp[j];
        ans-=dp[j-k];
        ans-=dp2[j-k];
        ans+=dp2[j+1];
        rs=max(rs,ans);
    }
    cout<<rs;
}



Measured memory_bytes: 1232
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(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 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int dy[] = {1, -1, 0, 0};
const int dx[] = {0, 0, 1, -1};

void solve(int w, int h) {
    vector<vector<bool>> can_move_y(h-1, vector<bool>(w, true));
    vector<vector<bool>> can_move_x(h, vector<bool>(w-1, true));

    rep(i, 2*h-1) {
        if (i&1) {
            rep(j, w) {
                int a;
                cin >> a;
                can_move_y[(i-1)/2][j] = !a; 
            }
        } else {
            rep(j, w-1) {
                int a;
                cin >> a;
                can_move_x[i/2][j] = !a; 
            }
        }
    }

    queue<P> q;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    q.push(P(0, 0));
    dist[0][0] = 1;

    while (!q.empty()) {
        int y = q.front().first, x = q.front().second;
        q.pop();
        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if (dist[ny][nx] >= 0) continue;
            if (i == 0) {
                // 下に移動
                if (!can_move_y[y][x]) continue;
            }
            if (i == 1) {
                // 上に移動
                if (!can_move_y[y-1][x]) continue;
            }
            if (i == 2) {
                // 右に移動
                if (!can_move_x[y][x]) continue;
            }
            if (i == 3) {
                // 左に移動
                if (!can_move_x[y][x-1]) continue;
            }
            q.push(P(ny, nx));
            dist[ny][nx] = dist[y][x] + 1;
        }
    }
    if (dist[h-1][w-1] == -1) cout << 0 << endl;
    else cout << dist[h-1][w-1] << endl;
}

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

    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) return 0;
        else solve(w, h);
    }
}


Measured memory_bytes: 3260
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  while(true){
    string str;
    cin >> str;
    if(str=="#")return;
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31||(y==31&&m<5))
      cout << "HEISEI " << y << " " << m << " " << d << endl;
    else
      cout << "? " << y-30 << " " << m << " " << d << endl;
    
    

  }
}

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



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

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1<<14,p=998244353,R=3;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,L,ans,f[N],a[N],g[N],fac[N],inv[N];
int C(int n,int m){return (ll)fac[n]*inv[m]%p*inv[n-m]%p;}
int pl(int x,int y){return (x+y<p) ? (x+y) : (x+y-p);}
void NTT(int *a,int L,int typ){
	for (int i=0,j=0;i<L;i++){
		if (i<j) swap(a[i],a[j]);
		for (int k=L>>1;(j^=k)<k;k>>=1);
	}
	for (int k=1;k<L;k<<=1){
		int wn=qpow(R,(p-1)/(k<<1));
		if (typ==0) wn=qpow(wn,p-2);
		for (int i=0;i<L;i+=(k<<1)){
			int w=1;
			for (int j=i;j<i+k;j++,w=(ll)w*wn%p){
				int x=a[j],y=(ll)a[j+k]*w%p;
				a[j]=pl(x,y);a[j+k]=pl(x,p-y);
			}
		}
	}
	if (typ==0){
		int inv=qpow(L,p-2);
		for (int i=0;i<L;i++) a[i]=(ll)a[i]*inv%p;
	}
}
int main(){
	n=read();m=read();
	fac[0]=1;
	for (int i=1;i<=n+2;i++) fac[i]=(ll)fac[i-1]*i%p;
	inv[n+2]=qpow(fac[n+2],p-2);
	for (int i=n+2;i;i--) inv[i-1]=(ll)inv[i]*i%p;
	f[0]=1;int L=1;
	while (L<=n+n) L<<=1;
	for (int i=1;i<=n;i++) g[i]=inv[i+2];
	NTT(g,L,1);
	for (int i=1;i<=m;i++){
		for (int i=0;i<L;i++) a[i]=(i<=n) ? ((ll)f[i]*inv[i]%p) : 0;
		NTT(a,L,1);
		for (int i=0;i<L;i++) a[i]=(ll)a[i]*g[i]%p;
		NTT(a,L,0);
		for (int i=0;i<=n;i++) f[i]=((ll)f[i]*(i*(i+1)/2+1)+(ll)a[i]*fac[i+2])%p;
	}
	ans=0;
	for (int i=0;i<=n;i++) ans=(ans+(ll)C(n,i)*f[i])%p;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n, m, x, pl, leftCost = 0, rightCost = 0;
    cin >> n >> m >> x;
    
    while (m--) cin >> pl, leftCost += pl < x, rightCost += pl > x;
    
    cout << min(leftCost, rightCost) << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<ll> a(3);
	cin >> a[0] >> a[1] >> a[2];
	SORT(a);
	cout << a[2]*10+a[1]+a[0] << endl;
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    max_A = max(a for a, _ in AB)
    inf = float('inf')
    dp = [inf] * (H + max_A + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == inf:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()


Measured memory_bytes: 3680