akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val countMap = mutableMapOf<Char, Int>()
    val inf = 51
    for (c in 'a'..'z') {
        countMap[c] = inf
    }
    repeat(n) {
        val s = br.readLine()!!.toList()
        val charCount = elementCountMap(s)
        for (c in 'a'..'z') {
            countMap[c] = min(countMap[c]!!, charCount.getOrDefault(c, 0))
        }
    }
    for (e in countMap) {
        repeat(e.value) {
            out.print(e.key)
        }
    }
    out.println()
}

/** O(n) */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
        countMap.merge(e, 1) { oldValue, value -> oldValue + value }
    }
    return countMap
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36524
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
S = input()

ans = 0
x = 0

for i in range(N):
	if S[i] == "I":
		x += 1
	if S[i] == "D":
		x -= 1
	ans = max(ans, x)

print(ans)

Measured memory_bytes: 13596
for n in range(int(input())) :
    s=input()
    for i in range(1,26):
        for j in range(27):
            a=[]
            for k in range(len(s)):
                if s[k].islower():#小文字か判別
                    a+=chr(((ord(s[k])-ord("a"))*i+j)%26+ord("a"))#文字の変換
                else:
                    a+=s[k]
            a="".join(a)
            #print(a)
            if "this" in a or "that" in a:
                print(a)
                break



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <sstream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int n,a[1000];
bool broken[1000];
int To_int(string s){
	istringstream is(s);
	int ret;
	is>>ret;
	return ret;
}
string To_string(int a){
	ostringstream os;
	os << a;
	return os.str();
}
string solve(){
	rep(i,n){
		string s;
		cin>>s;
		if(s[0]=='x') broken[i]=true;
		else a[i]=To_int(s),broken[i]=false;
	}
	rep(i,n-1) if(broken[i]&&broken[i+1]) return "none";
	rep(i,n-1){
		if(!broken[i]&&!broken[i+1]){
			if(i%2==0&&a[i]>=a[i+1]) return "none";
			if(i%2==1&&a[i]<=a[i+1]) return "none";
		}
	}
	int ub=1e9+4,lb=-1e9-4;
	rep(i,n){
		if(broken[i]){
			if(i>0){
				if(i%2==1) lb=max(lb,a[i-1]+1);
				else ub=min(ub,a[i-1]-1);
			}
			if(i<n-1){
				if(i%2==1) lb=max(lb,a[i+1]+1);
				else ub=min(ub,a[i+1]-1);
			}
		}
	}
	if(ub<lb) return "none";
	if(ub==lb) return To_string(ub);
	return "ambiguous";
}
int main(){
	while(true){
		cin>>n;
		if(n==0) break;
		cout<<solve()<<endl;
	}
}

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

const int INF = 1001001001;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> dp(h+1, INF);
  dp[0] = 0;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    rep(j,h) {
      int nj = min(j+a,h);
      dp[nj] = min(dp[nj], dp[j]+b);
    }
  }
  cout << dp[h] << endl;
  return 0;
}


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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s2 = (s - s1 * 100) / 10;
  s3 = (s - s1 * 100 - s2 * 10) / 1;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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 LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif





/*
	DP?
	
	dp[i][j] : [i,j)の範囲を全て食べたとき、その右側と左側に加算する数。1つの数ではなく、vector<pair<ll,ll>>で
	
	
	
*/


vector<pll> tmp;
vector<pll> dp[18][18];
vector<ll> a;
ll n;

void f( int i, int j ){
	if ( i+1 == j ){
		dp[i][j].push_back({a[i],a[i]});
	}
	else {
		
		tmp.clear();
		for ( int k = i; k < j; k++ ){
			// [i,k)と[k+1,j)を食べて、kを食べる
			for ( auto l : dp[i][k] ){
				for ( auto r : dp[k+1][j] ){
					tmp.push_back({l.first+l.second+a[k]+r.first, l.second+a[k]+r.first+r.second});
				}
			}
		}
		sort(tmp.begin(),tmp.end(),[&](const pll& l, const pll &r){
			return l.first < r.first || (l.first == r.first && l.second < r.second);
		});
		
		for ( int k = 0; k < SZ(tmp); k++ ){
			if ( k == 0 || tmp[k-1].second > tmp[k].second ){
				dp[i][j].push_back(tmp[k]);
				//eprintf( "%d %d : + %lld %lld\n", i, j, tmp[k].first, tmp[k].second );
			}
			else {
				//eprintf( "%d %d :   %lld %lld\n", i, j, tmp[k].first, tmp[k].second );
			}
		}
	}
}


int main(){
	cin >> n;
	a.resize(n);
	rep(i,n)
		cin >> a[i];
	
	rep(i,18)
		dp[i][i].push_back({0,0});
	
	for ( int d = 1; d < n; d++ ){
		for ( int i = 1; i+d < n; i++ ){
			f( i, i+d );
		}
	}
	
	//rep(i,n){
	//	rep(j,n){
	//		cout << dp[i][j].size() << " ";
	//	}
	//	cout << endl;
	//}
	
	ll result = LLONG_MAX;
	for ( auto it : dp[1][n-1] ){
		chmin(result, it.first+it.second);
	}
	cout << a[0]+result+a[n-1] << endl;
	
	return 0;
}




Measured memory_bytes: 34936
#import <Foundation/Foundation.h>
#import <stdio.h>

int main(int argc, char **argv) {
  int N;
  
  scanf("%d", &N);
  
  BOOL hasSeven = NO;

  while (N > 0) {
    if (N % 10 == 7) {
      hasSeven = YES;
      break;
    }
    N /= 10;
  }
  printf("%s", hasSeven ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 12500
fn main() {
    let (k, a, b) = read();
    let ans = solve(k, a, b);
    write(if ans {"OK"} else {"NG"});
}

fn read() -> (u32, u32, u32) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let k: u32 = l1.trim().parse().unwrap();
    let mut l2 = String::new();
    std::io::stdin().read_line(&mut l2).ok();
    let mut iter = l2.trim().split_whitespace();
    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();

    (k, a, b)
}

fn write(s: &str) {
    println!("{}", s);
}

fn solve(k: u32, a: u32, b: u32) -> bool {
    for i in a..=b {
        if i % k == 0 {
            return true;
        }
    }

    return false;
}


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

main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;
    cin>>n;
    int a[n+1],b[n];
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }

    int ans=0;
    for(int i=0;i<n;i++){
        int k=min(b[i],a[i]);
        b[i]-=k;
        a[i]-=k;    
        ans+=k;

        k=min(b[i],a[i+1]);
        b[i]-=k;
        a[i+1]-=k;
        ans+=k;
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

int main(int argc, char *argv[]){
    int N, K;
    std::cin >> N >> K;
    std::deque<long int> V;
    long int v;
    for(int i=0; i<N; ++i){
        std::cin >> v;
        V.push_back(v);
    }

    std::vector<long int> sumValue;
    std::vector<long int> subsequent;
    int left,right;
    int lSubsequent;
    long int sumSubsequent;
    int dequeIdx;
    int nGet, nReturn;
    while(K>=0){
        for(lSubsequent=0; lSubsequent<=N; ++lSubsequent){
            nGet = (lSubsequent<<1) - K;
            if(nGet > N){
                break;
            }else if(nGet < 0){
                continue;
            }
            nReturn = K - lSubsequent;
            if(nReturn > lSubsequent){
                continue;
            }else if(nReturn < 0){
                break;
            }
            for(left=N-lSubsequent; left<=N; ++left){
                right = left+lSubsequent;
                subsequent.clear();
                for(dequeIdx=left; dequeIdx<right; ++dequeIdx){
                    subsequent.emplace_back(V[dequeIdx%N]);
                }
                std::sort(subsequent.begin(),subsequent.end());
                sumSubsequent = 0;
                for(auto iter = subsequent.begin()+nReturn; iter!=subsequent.end(); ++iter){
                    sumSubsequent += *iter;
                }
                sumValue.emplace_back(sumSubsequent);
            }
        }
        --K;
    }

    long int maxValue = *std::max_element(sumValue.begin(),sumValue.end());

    std::cout << maxValue << std::endl;
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main(){
  bool n[11]={0};
  int a,b,c;
  while(cin>>a>>b>>c){
    for(int i=0;i<11;i++){
      n[i]=true;
    }
    n[a]=false; n[b]=false; n[c]=false;
    int all=0,ok=0;
    for(int i=1;i<11;i++){
      if(n[i]){
	if(i+a+b<=20){
	  ok++;
	}
	all++;
      }
    }
    // cout<<all<<ok<<endl;
      if(all<=ok*2)cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,k;
		cin>>n>>k;
		ll arr[n],i,ans[n],x,y,mini=INT_MAX,j,l;
		for(i=0;i<n;i++)
			cin>>arr[i];
		ans[0]=0;
		for(i=1;i<n;i++)
		{
			mini=INT_MAX;
			for(j=1;j<=k;j++)
			{
				l=i-j;
				if(l<0)
				{
					j=k+1;
					break;
				}
				mini=min(mini,(ans[l]+abs(arr[i]-arr[l])));
			}
			ans[i]=mini;
		}
		cout<<ans[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
//		 static int mod =  (int) (Math.pow(10,9)+7);
		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        long[] a = new long[N];
	        int[][] f = new int[N][10];
	        int[][] p = new int[N][11];
	        for (int i=0 ; i<N; i++) {
	        	for(int j=0;j<10;j++) {
		            f[i][j] = Integer.parseInt(sc.next());	        		
	        	}
	        }
	        for (int i=0 ; i<N; i++) {
	        	for(int j=0;j<11;j++) {
		            p[i][j] = Integer.parseInt(sc.next());	        		
	        	}
	        }
	        long ans=-1001001001;
	        for(int i=1;i<(2<<9);i++) {
		        int[] fcnt = new int[N];
	        	for(int j=0;j<10;j++) {
	        		int t = (i>>j)&1;
	        		if(t==1) {
	        			for(int k=0;k<N;k++) {
	        				if(f[k][j]==1) {
	        					fcnt[k]++;
	        				}
	        			}
	        		}
	        	}
		        int sum = 0;
		        for(int j=0;j<N;j++) {
		        	sum = sum + p[j][fcnt[j]];
		        }
		        ans=Math.max(ans, sum);
	        }
	        
	        System.out.println(ans);
	        

	    }
	    
	    

	}

Measured memory_bytes: 28968
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int[] antenna = new int[5];

      for (int i = 0; i < antenna.length; ++i) {
        antenna[i] = in.nextInt();
      }

      int k = in.nextInt();
      boolean canDirect = true;
      for (int i = 0; i < antenna.length && canDirect; ++i) {
        for (int j = i + 1; j < antenna.length; ++j) {
          if (Math.abs(antenna[i] - antenna[j]) > k) {
            canDirect = false;
            break;
          }
        }
      }

      if (canDirect) {
        System.out.println("Yay!");
      } else {
        System.out.println(":(");
      }
    }
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
  int N;
  int K;
  cin >> N >> K;
  vector<int> v;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  int sum = 0;
  for(int i=0;i<K;i++){
    sum += v[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3612
using System;

class Program
{
  static void Main(string[] args)
  {
    int A = int.Parse(Console.ReadLine());
    int B = int.Parse(Console.ReadLine());
    int C = int.Parse(Console.ReadLine());
    int X = int.Parse(Console.ReadLine());
    int ans = 0;

    for (int i = 0; i <= A; ++i)
    {
      for (int j = 0; j <= B; ++j)
      {
        for (int k = 0; k <= C; ++k)
        {
          if (i * 500 + j * 100 + k * 50 == X) ++ans;
        }
      }
    }

    Console.WriteLine(ans);
  }
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
template <typename Val>
void show_vec(vector<Val> v){
  cout<<endl;
  rep(i,v.size()){
    cout<<v.at(i)<<" ";
  }
  cout<<endl;
}

template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->emplace_back(count,A->at(i));
        count = 1;
      }
    }else{
      R->emplace_back(count,A->at(i));
    }
  }
}


//---------------------------------------------------------------
int main(){
  string S,T,ans,Q,K;
  cin>>S;
  cin>>T;
  rep(i,S.size()){
    Q.push_back('?');
  }

  rep(i,S.size()-T.size()+1){
    K = Q;
    rep(j,T.size()){
      K.at(i+j) = T.at(j);
    }
    //cout<<K<<endl;
    int count = 0;
    rep(j,S.size()){
      if(K.at(j)=='?'||K.at(j)==S.at(j)||S.at(j)=='?'){
        if(S.at(j)!='?')K.at(j)=S.at(j);
        count++;
      }else{
        break;
      }
    }
    //cout<<count<<endl;
    if(count == S.size()){
      ans = K;
    }


  }


  if(ans.size()==0){
    ans = "UNRESTORABLE";
  }else{
    rep(i,ans.size()){
      if(ans.at(i)=='?')ans.at(i)='a';
    }
  }

  cout<<ans<<endl;



}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

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

int N, K;
int a[101];
int dp[123][123456];	// n人目まででk個を分ける方法。n: 0-index
int s[123][123456];	

signed main(){

	cin >> N >> K;
	rep(i, N) cin >> a[i];

	rep(i, a[0] + 1)
		dp[0][i] = 1;

	rep(i, K + 1)
		s[0][i + 1] = s[0][i] + dp[0][i];

	for (int n = 1; n < N; n++){
		for (int k = 0; k <= K; k++){
			dp[n][k] = (s[n - 1][k + 1] - s[n - 1][max(0LL, k - a[n])])%mod;
			s[n][k + 1] = (s[n][k] + dp[n][k])%mod;

//			for (int i = 0; i <= a[n]; i++)
//				(dp[n][k] += dp[n - 1][k - i])%=mod;
		}
	}

	cout << (dp[N - 1][K] +mod)%mod<< endl;


	return 0;
}

Measured memory_bytes: 196480
#include<bits/stdc++.h>
using namespace std;
#define ll long long
class activity
{
public:
	ll int A;
	ll int B;
	ll int C;
};

ll int solve(ll int i, ll int n, vector<activity>&v, ll int prev, vector<vector<ll int>>&dp)
{
	if (i == n)
	{
		return 0;
	}
	if (dp[i][prev] != -1)
	{
		return dp[i][prev];
	}

	if (prev == 0)//pichla A ho to
	{
		//agar B chuno
		ll int B_ans = v[i].B + solve(i + 1, n, v, 1 , dp);
		//agar C chuno
		ll int C_ans =  v[i].C + solve(i + 1, n, v, 2, dp);
		ll int ans = max(B_ans, C_ans);
		return dp[i][prev] = ans;
	}
	else if (prev == 1)// pichla B ho to
	{
		//agar A chuno
		ll int A_ans = v[i].A + solve(i + 1, n, v, 0, dp);

		//agar C chuno
		ll int C_ans = v[i].C + solve(i + 1, n, v, 2, dp );
		ll int ans = max(A_ans, C_ans);
		return dp[i][prev] = ans;
	}
	else //agar pichla C ho to
	{
		//agar A chuno
		ll int A_ans = v[i].A + solve(i + 1, n, v, 0, dp );
		ll int B_ans = v[i].B + solve(i + 1, n, v, 1, dp);
		ll int ans = max(A_ans, B_ans);
		return dp[i][prev] = ans;
	}
}


int main()
{
	ll int n;
	cin >> n;
	vector<activity>v(n);
	for (ll int i = 0; i < n; i++)
	{
		ll int a, b, c;
		cin >> a >> b >> c;
		v[i].A = a;
		v[i].B = b;
		v[i].C = c;
	}
	vector<vector<ll int>>dp(n, vector<ll int>(3, -1));

	ll int A_ans = solve(0, n, v, 0, dp);
	ll int B_ans = solve(0, n, v, 1, dp);
	ll int C_ans = solve(0, n, v, 2, dp);
	ll int ans = max(A_ans, max(B_ans, C_ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18792
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int m = sc.nextInt();
		int d = sc.nextInt();
		int d1 = 2;
		int d10 = 2;
		int count = 0;
		while (d10 * 10 + d1 <= d) {
			if (d1 * d10 <= m) {
				count++;
			}
			if (d1 < 9) {
				d1++;
			} else {
				d1 = 2;
				d10++;
				if (d10 >= 10) {
					break;
				}
			}
		}
		System.out.println(count);
	}
}

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 || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<long long,long long>
#define FOR(i,a,b)  for(long long i=a;i<b;++i)
#define RFOR(i,a,b) for(long long i=a;i>b;--i)
#define f           first
// #define se          second
#define maxn        400005
#define all(v)      v.begin(),v.end()
#define sz(x)       (long long)x.size()
//#define mod         1000000007
#define pqueue      priority_queue<long long>
#define pdqueue     priority_queue< long long,vector<long long> ,greater< long long >>
 
typedef long long ll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long long md = 998244353;
 
/*const long long mod = 998244353;
long long power(long long a,long long n)
{
	if(n == 1)return a%mod;
	if(n == 0)return 1;
	if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
	return power((a*a)%mod,n/2)%mod;
}
*/

vector<ll> s;
vector<ll> t;

int main()
{
	ll a, b, q;
	cin >> a >> b >> q;

	s.resize(a+2);
	t.resize(b+2);
	
	s[0] = LLONG_MIN/4;
	t[0] = LLONG_MIN/4;
	s[a+1] = LLONG_MAX/4;
	t[b+1] = LLONG_MAX/4;

	FOR (i,1,a+1)
		cin >> s[i];
	FOR (i,1,b+1)
		cin >> t[i];

	// construct dp
	FOR (i,0,q) {
		ll x;
		cin >> x;
		auto se = upper_bound(all(s), x);
		auto te = upper_bound(all(t), x);
		auto sw = prev(se);
		auto tw = prev(te);
		// cerr << *sw << ", " << *se << ", " << *tw << ", " << *te << endl;
		// cerr << x << ", " << (*tw) << ", " << (x - *tw) << endl;

		ll ans = (*se > *te) ? (*se - x) : (*te - x);
		ll a1 = (*sw < *tw) ? (x - *sw) : (x - *tw);
		ll a2 = (*se-x+*se-*tw);
		ll a3 = (x-*tw+*se-*tw);
		ll a4 = (*te-x+*te-*sw);
		ll a5 = (x-*sw+*te-*sw);
		// cerr << ans << ", " << a1 << ", " << a2 << ", " << a3 << ", " << a4 << ", " << a5 << endl;
		ans = min(ans, (*sw < *tw) ? (x - *sw) : (x - *tw));
		ans = min(ans, (*se-x+*se-*tw));
		ans = min(ans, (x-*tw+*se-*tw));
		ans = min(ans, (*te-x+*te-*sw));
		ans = min(ans, (x-*sw+*te-*sw));
		cout << ans << endl;
	}

	return 0;
}


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

int main() {
  string n;
  int Min=753;
  
  cin>>n;
  for(int i=0;i<n.size()-2;i++){
    string s;
    s.push_back(n.at(i));
    s.push_back(n.at(i+1));
    s.push_back(n.at(i+2));
    
    int d=stoi(s);
 
    Min=min(Min,abs(753-d));
  }
  
  cout<<Min<<endl;
  
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    int xs[n];
    int ys[n];
    xs[0] = 0;
    ys[0] = 0;
    int dxs[] = {-1, 0, 1, 0};
    int dys[] = {0, -1, 0, 1};
    int mxx = 0;
    int mnx = 0;
    int mxy = 0;
    int mny = 0;
    for(int i = 0; i < n - 1; i++) {
      int ni, di;
      cin >> ni >> di;
      xs[i+1] = xs[ni] + dxs[di];
      ys[i+1] = ys[ni] + dys[di];
      if(mxx < xs[i+1]) mxx = xs[i+1];
      if(mnx > xs[i+1]) mnx = xs[i+1];
      if(mxy < ys[i+1]) mxy = ys[i+1];
      if(mny > ys[i+1]) mny = ys[i+1];
    }
    cout << (mxx - mnx + 1) << " " << (mxy - mny + 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    ll ans1   = 0;
    ll ans2   = 0;
    ll mysum1 = 0;
    ll mysum2 = 0;
    // aは変更しない 変更するのは累積和のみ
    // 正負正負
    FOR(i, 0, N) {
        mysum1 += a.at(i);
        // 累積和が正であるべきところが負なら 1になるようにする
        if ((i % 2 == 0) & (mysum1 <= 0)) {
            ans1 += abs(mysum1) + 1;
            mysum1 = 1;
        } else if ((i % 2 == 1) & (mysum1 >= 0)) {
            ans1 += abs(mysum1) + 1;
            mysum1 = -1;
        }
    }
    // 負正負正
    FOR(i, 0, N) {
        mysum2 += a.at(i);
        // 累積和が正であるべきところが負なら 1になるようにする
        if ((i % 2 == 1) & (mysum2 <= 0)) {
            ans2 += abs(mysum2) + 1;
            mysum2 = 1;
        } else if ((i % 2 == 0) & (mysum2 >= 0)) {
            ans2 += abs(mysum2) + 1;
            mysum2 = -1;
        }
    }
    cout << min(ans1, ans2) << endl;
}


Measured memory_bytes: 3928
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
//author_name:w4y 
//date:2018/11/18
//title:AGC 010 E Rearranging
//ÒòÎªÇÓÅ³£¬ËùÒÔÌÓ±ÜÉúÃü£¬ÒÔ²»µÖ¿¹ÔÚ×îºÚ°µµÄ³ÁÂÙÖÐÉú³ö½¾°Á£¬ÒòÎª½¾°Á£¬ËùÒÔ²»Ñ¡ÔñÉú£¬ËùÒÔ¾Ü³â´Ö±ÉµÄÀÖ¹ÛÖ÷Òå¡£
//Ìì²ÅµÄ±¯¾çµØÓÚ±»Ð¡¶øÊæÊÊµÄÃûÍûËùÊø¸¿¡£
//It's human to lie. Most of the time we can't even be honest with ourselves.

bool d[2020][2020];
int a[2020];
bool used[2020];
int ans[2020];
vector<int> ord;
int bloc[2020];
int n;

void dfs(int u)
{
	used[u]=true;
	ord.push_back(u);
	for(int i=0;i<n;i++)
		if(d[i][u]&&!used[i])
			dfs(i);
	return;
}
	
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(__gcd(a[i],a[j])>1)
				d[i][j]=d[j][i]=true;
	for(int i=0;i<n;i++) if(!used[i])
		dfs(i);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(d[ord[i]][ord[j]])
				bloc[ord[j]]++;
	memset(used,0,sizeof used);
	for(int z=0;z<n;z++)
	{
		for(int i=n-1;i>=0;--i)
		{
			if(used[i]||bloc[i]) continue;
			ans[z]=i;
			int pos=0;
			while(ord[pos]!=i) pos++;
			for(int j=pos+1;j<n;j++)
				if(d[i][ord[j]])
					bloc[ord[j]]--;
			used[i]=true;
			break;
		}
	}
	for(int i=0;i<n;i++)
		cout<<a[ans[i]]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4480
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())

    for i in range(1, N + 1):
        if 2 * N == i * (i + 1):
            L = i
            break
    else:
        print("No")
        return

    ans = [[] for _ in range(L + 1)]
    used = [deque([]) for _ in range(L + 1)]
    no = deque(range(1, N + 1))

    for i in range(L + 1):
        if i == 0:
            for _ in range(L):
                j = no.popleft()
                ans[i].append(j)
                used[i].append(j)
        else:
            for j in range(i):
                k = used[j].popleft()
                ans[i].append(k)
            for _ in range(L - i):
                j = no.popleft()
                ans[i].append(j)
                used[i].append(j)

    print("Yes")
    print(L + 1)
    for a in ans:
        print(len(a), end=" ")
        print(*a, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 10568
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")

#include <ctype.h>
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>

int main() {
  long double a, b, c;
  scanf("%Lf%Lf%Lf", &a, &b, &c);
  puts(((c - a - b) * (c - a - b) <= 4 * a * b) || (c < a + b) ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 128
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		cout << c << endl;
	}
	if (b == c) {
		cout << a << endl;
	}
	if (a == c) {
		cout << b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#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 PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


  int dist[1005][1005];


int main() {
  int H,W;
  scanf("%d%d", &H,&W);
  char a[H][W];
  queue<pint> que;
  

  for (int i = 0; i < H; ++i) {
    FOR(j,0,W-1){
      cin >> a[i][j];
      if(a[i][j]=='.') dist[i][j] = -1;
      else {
        dist[i][j] = 0;
        que.push(pint(i,j));
      }
    }
  }

  // cout  << 999 << endl;

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

  while(!que.empty()){
      FOR(i,0,3){
      // cout << que.size() << endl;

      int nx = que.front().first + dx[i];
      int ny = que.front().second + dy[i];

      // cout << nx << " " << ny << endl;

      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(dist[nx][ny]==-1){
      dist[nx][ny] = dist[que.front().first][que.front().second] +1;
      // cout << nx << " " << ny << " " << dist[nx][ny] << endl;
      que.push(pint(nx,ny));
      }
    }
    que.pop();
  }

  

  int ans = 0;
  FOR(i,0,H-1){
    FOR(j,0,W-1){
      chmax(ans,dist[i][j]);
      // if(ans == 3) cout << i << " " << j << endl;
    }
  }

  cout << ans << endl;




}



Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long int
using namespace std;















void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n + 1, 0);
    while (k--)
    {
        int d;
        cin >> d;
        while (d--)
        {
            int x;
            cin >> x;
            v[x]++;
        }

    }

    int ans = 0;

    for (int i = 1; i <= n; i++)
    {
        if (v[i] == 0)
            ans++;
    }

    cout << ans << "\n";












}




int main()
{


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




Measured memory_bytes: 3616
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int)1e3 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;
int dp[MAXN][MAXN];
char a[MAXN],b[MAXN];

void work(){
    int q; scanf("%d",&q);
    while(q--){
        scanf("%s%s",a+1,b+1);
        int lena=strlen(a+1);
        int lenb=strlen(b+1);
        for(int i=1;i<=lena;i++)
            for(int j=1;j<=lenb;j++) dp[i][j]=INF;
        for(int i=1;i<=lena;i++){
            for(int j=1;j<=lenb;j++){
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+(a[i]==b[j]));
            }
        }
        printf("%d\n",dp[lena][lenb]);
    }
}
/*
3
abcbdab
bdcaba
abc
abc
abc
bc
*/

int main(){
    work();
    return 0;
}





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


int main()
{
    int H, W, D, Q;
    int A[301][301];
    cin >> H >> W >> D;
    for( int i = 0; i < H; ++i ){
        for( int j = 0; j < W; ++j ){
            cin >> A[i][j];
        }
    }
    cin >> Q;
    vector<int> L(Q), R(Q);
    for( int i = 0; i < Q; ++i ) cin >> L[i] >> R[i];


    vector<pair<int,int>> coord((H+1)*(W+1));
    for( int i = 0; i < H; ++i ){
        for( int j = 0; j < W; ++j ){
            coord[A[i][j]] = make_pair( i, j );
        }
    }

    // d[i]: i % D -> i となるのに必要な MP
    vector<int> d(H*W, 0);
    for( int i = D+1; i <= H*W; ++i ){
        d[i] = d[i-D] + abs(coord[i].first - coord[i-D].first)
                      + abs(coord[i].second - coord[i-D].second);
    }

    for( int i = 0; i < Q; ++i ){
        cout << d[R[i]] - d[L[i]] << endl;
    }

    return 0;
}

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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    vi v(3);
    rep(i,3)cin>>v[i];
    sort(all(v));
    cout<<v[2] - v[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

ll dp[100'005][2];

int main()
{
    ciosup;
    int n;
    string s;
    cin >> s;
    n = s.size();
    dp[0][0] = 1;
    REP(i, n)
    {
        int now = s[i] - '0';
        REP(j, 2)
        {
                for (int k = 0; k <= (j ? 1 : now); k++)
                {
                    if (k == 0)
                    {
                        dp[i + 1][j || (k < now)] = (dp[i + 1][j || (k < now)] + dp[i][j]) % MOD;
                    }else
                    {
                        dp[i + 1][j || (k < now)] = (dp[i + 1][j || (k < now)] + 2*dp[i][j]) % MOD;
                    }
                }
        }
    }
    cout << (dp[n][0] + dp[n][1]) % MOD << endl;
}

Measured memory_bytes: 2000
from math import sin, cos, sqrt, radians
A, B, H, M = map(int, input().split())
tan = [0, A]
tyou = [0, B]
tan_angle = H * 30 + 0.5 * M
tyou_angle = M * 6
tan = [A*sin(radians(tan_angle)), A*cos(radians(tan_angle))]
tyou = [B*sin(radians(tyou_angle)), B*cos(radians(tyou_angle))]
print(sqrt((tan[0]-tyou[0])**2 + (tan[1]-tyou[1])**2))




Measured memory_bytes: 9520
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 210000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<ll, pii>pi3;
ll dat[202020];
vector<pi3>pat;
#define INF 1000000000000000000LL
void dfs(int beg, int end, ll dis)
{
	if (beg == end)return;
	int med = (beg + end) / 2;
	ll mini1 = INF, mini2 = INF;
	int r1 = -1, r2 = -1;
	for (int i = beg; i <= med; i++)if (mini1 > dis*(med - i) + dat[i])mini1 = dis*(med - i) + dat[i], r1 = i;
	for (int i = med + 1; i <= end; i++)if (mini2 > dis*(i - med) + dat[i])mini2 = dis*(i - med) + dat[i], r2 = i;
	for (int i = beg; i <= med; i++)pat.push_back(make_pair(dis*(r2 - i) + dat[i] + dat[r2], make_pair(i, r2)));
	for (int i = med + 1; i <= end; i++)pat.push_back(make_pair(dis*(i - r1) + dat[i] + dat[r1], make_pair(i, r1)));
	dfs(beg, med, dis), dfs(med + 1, end, dis);
}
int main()
{
	int num;
	ll dis;
	scanf("%d%lld", &num, &dis);
	for (int i = 0; i < num; i++)scanf("%lld", &dat[i]);
	dfs(0, num - 1, dis);
	sort(pat.begin(), pat.end());
	uf.init();
	ll s = 0;
	for (int i = 0; i < pat.size(); i++)
	{
		int u = pat[i].second.first, v = pat[i].second.second;
		if (uf.find(u) != uf.find(v))
		{
			uf.unite(u, v);
			s += pat[i].first;
		}
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 102112
while 1:
	n,m=map(int,raw_input().split())
	if n==0:break
	field=[int(raw_input()) for i in range(n)]
	dice=[int(raw_input()) for i in range(m)]
	now=0
	for i in range(m):
		now+=dice[i]
		try:now+=field[now]
		except:pass
		if now>=n-1:
			print i+1
			break

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  int H1, M1, H2, M2, K;

  void init() {
    cin >> H1 >> M1 >> H2 >> M2 >> K;
  }

  void solve() {
    int a1 = H1 * 60 + M1;
    int a2 = H2 * 60 + M2;
    int a3 = a2 - K;
    cout << a3 - a1 << "\n";
  }
}

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

Measured memory_bytes: 3640
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;
int N,A[200005],F[200005],nxt[200005];
long long Ans;
inline void read(int &Res){
	char ch=getchar();
	for (Res=0;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) Res=(Res<<3)+(Res<<1)+ch-48;
}
int main(){
	read(N),nxt[N]=N+1;
	for (int i=1;i<=N;++i) read(A[i]);
	for (int i=N;i;--i) if (A[i]) nxt[i-1]=i; else nxt[i-1]=nxt[i];
	for (int i=1,sum,sux;i<=N;++i){
		sum=sux=0;
		int& j=F[i]=N;
		for (int k=i;k<=N;k=nxt[k]){
			sum+=A[k],sux^=A[k];
			if (sum^sux){
				j=k-1;
				break;
			}
		}
		Ans+=j-i+1;
	}
	printf("%lld",Ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int imax = INT_MAX;
int imin = INT_MIN;
ll llmax = LLONG_MAX;
ll llmin = LLONG_MIN;

int main()
{
	char a, b;
	cin >> a >> b;
	if (a == b)
		cout << "H" << endl;
	else 
		cout << "D" << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    map<ll,int> cnt;
    rep(i,n){
        ll a; cin>>a;
        cnt[a]++;
    }
    rep(i,m){
        ll b,c; cin>>b>>c;
        cnt[c]+=b;
    }
    ll ans=0;
    RITR(itr,cnt){
        if (n<=itr->se){
            ans+=(ll)n*itr->fi;
            break;
        }else{
            n-=itr->se;
            ans+=itr->fi*itr->se;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 12800
import java.util.*
fun main(args:Array<String>) {
    val (N,M) = readLine()!!.split(" ").map(String::toInt)
    val passibles = (1..M).map {
        val (l,r ) = readLine()!!.split(" ").map(String::toInt)
        Pair(l,r)
    }

    // var intersection = Array(N) {false}
    
    var result = Pair(1,N)
    for(nos in passibles) {
        val (l,r) = nos
        if( r < result.first || l > result.second) {
            result = Pair(0,0)
            break
        }
        result = when(Pair(l > result.first, r < result.second)) {
            Pair(false,false) -> result
            Pair(true,false) -> Pair(l,result.second)
            Pair(false,true) -> Pair(result.first,r)
            else -> Pair(l,r)
        }
    }

    if(result == Pair(0,0)) {0} else {
        result.second - result.first + 1 
    }.run(::println)
}

Measured memory_bytes: 62052
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int flag[1024][1024], cr[2][2], M, N;

int countF(int y, int x){
  int res = 0,i,j;
  for(i=y-1;i<=y;i++){
    for(j=x-1;j<=x;j++){
      int f = 1;
      rep(k,2) rep(l,2) if(flag[i+k][j+l]!=cr[k][l]) f = 0;
      if(f) res++;
    }
  }
  return res;
}

int main(){
  scanf("%d%d", &M, &N);
  memset(flag, -1, sizeof(flag));
  char in[1024];
  rep(i, M){
    scanf("%s", in);
    for(int j=0;j<N;j++){
      flag[i+1][j+1] = (in[j]=='J')?0:(in[j]=='O')?1:2;
    }	
  }

  rep(i,2){
    scanf("%s", in);
    for(int j=0;j<2;j++)
      cr[i][j] = (in[j]=='J')?0:(in[j]=='O')?1:2;
  }

  /*  rep(i, M+1){
    rep(j, N+1) cout << flag[i][j] << " ";
    cout << endl;
    }*/

  //  cout << cr[0][0] << cr[0][1] << endl << cr[1][0] << cr[1][1] << endl;

  int res = 0;
  int origin = 0;
  REP(i,1,M)REP(j,1,N){
    if(flag[i][j]==cr[0][0] && flag[i+1][j]==cr[1][0] &&
       flag[i][j+1]==cr[0][1] && flag[i+1][j+1]==cr[1][1]) origin++;
  }

  res = origin;

  REP(i,1,M+1) REP(j,1,N+1){
    int diff = countF(i, j);
    rep(d, 3){
      flag[i][j] = (flag[i][j]+1)%3;
      int add = countF(i, j);
      res = max(res, origin-diff+add);
    }
  }
  printf("%d\n", res);
  return 0;
}

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

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll MOD = 1e9+7;

int main(){

    string s,t;
    cin >> s >> t;

    vector<vector<int>> dp(3001,vector<int>(3001,0));
    rep(i,0,s.size()){
        rep(j,0,t.size()){
            if (s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
            }
            
        }
    }

    //cout << dp[s.size()][t.size()] << endl;

    string ans = "";

    int x = s.size() , y = t.size();
    while (x > 0 && y > 0){
        if (s[x-1] == t[y-1]){
            ans = s[x-1] + ans;
            x--;
            y--;
        }else if (dp[x-1][y] > dp[x][y-1]){
            x--;
        }else{
            y--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <vector>
#include <algorithm>

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

using namespace std;

lli calc(lli n){
	lli ans=0;
	while(n){
		ans += n%10;
		n/=10;
	}
	return ans;
}

double g(long long n){
	return (double)(n)/calc(n);
}

int main(){

	vector<lli> res;
	lli base=1;

	//10^15まで候補を全部列挙*/
	for(lli i=0;i<15;i++){
		for(lli j=1;j<150;j++){
			res.push_back(base*(j+1)-1);
		}
		base*=10;
	}

	sort(res.begin(),res.end());
	res.erase(unique(res.begin(),res.end()),res.end());

	//だめなやつを除く
	for(lli i=0;i<res.size();i++){
		for(lli j=i+1;j<res.size();j++){
			if(g(res[i])>g(res[j])){
				res.erase(res.begin()+i--);
				break;
			}
		}
	}

	lli k;
	cin>>k;
	REP(i,k){
		cout<<res[i]<<endl;
	}

	return 0;

}

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

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for (int i = 0; i < N; i++){
    cin >> x.at(i);
    cin >> y.at(i);
  }
  int count = 1;
  for (int i = 1; i < N; i++){
    count *= i;
  }
  count *= 2;
  int A = 1;
  for (int i = 1; i <= N; i++){
    A *= i;
  }
  
  double ans = 0.0000000000;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      ans += sqrt((x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) + (y.at(i) - y.at(j)) * (y.at(i) - y.at(j)));
    }
  }
  cout << fixed << setprecision(10);
  cout << count * ans / A << endl;
}



Measured memory_bytes: 256