akhauriyash/Code-Regression huggingface dataset:
###出力関数
def output(W,H):
    i=1
    while i<=H:
        if i==1:
            print("#"* W)
        elif i==H:
            print("#"* W)
        else:
            print("#"+"."*(W-2)+"#")
        i=i+1
    print("")
#入力した文字を変数に格納する
input_number=input()

array=input_number.split()

#整数型に変換を行う
W=int(array[0])
H=int(array[1])

while not( W==0 and H==0):

    output(H,W)
    
    input_number=input()
    array=input_number.split()
    W=int(array[0])
    H=int(array[1])


Measured memory_bytes: 5616
#include <stdio.h>
int main()
{
   int n,m,i,sum=0,arr;
   scanf("%d %d",&n,&m);
   for(i=0;i<m;i++)
   {
       scanf("%d",&arr);
       sum=sum+arr;
   }
   if(sum<=n)
   {
       printf("%d\n",n-sum);
   }
   else{
    printf("-1\n");
   }

}

Measured memory_bytes: 1732
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

#define int unsigned long long

typedef unsigned long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n;
ll a[500000];
ll dif[500000];
ll st[500000];
ll b[500000];
ll phi[500000];
ll s, op;

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) s += a[i];
    for (int i = 0; i < n; i++) dif[i] = a[i] - a[(i - 1 + n) % n];
    for (int i = 1; i <= n; i++) op += i;
    op = s / op;
    for (int i = 0; i < n; i++)
    {
        ll cnt = (op - dif[i]) / n;
        st[i] += cnt;
        st[i + n] += -cnt;
        phi[i + n] += -cnt * n;
    }
    ll counter = 0, progressions = 0;
    for (int i = 0; i < 2 * n; i++)
    {
        progressions += st[i];
        counter += progressions + phi[i];
        b[i] = counter;
    }
    for (int i = 0; i < n; i++)
    {
        if (b[i] + b[i + n] != a[i])
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}


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

typedef long long LL;

int n, m, k, t[100007];
int res[107][107];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++)
        cin >> t[i];
    int x = 1;
    bool b = 0;
    for(int i = 1; i <= n; i++)
    {
        if(b == 0)
        {
            for(int j = 1; j <= m; j++)
            {
                if(t[x] == 0) x++;
                t[x] --;
                res[i][j] = x;
            }
        }
        else
        {
            for(int j = m; j >= 1; j--)
            {
                if(t[x] == 0) x++;
                t[x] --;
                res[i][j] = x;
            }
        }
        b ^= 1;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
            cout << res[i][j] << " ";
        cout << "\n";
    }
    return 0;
}


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

int main(){
    int y,m,d;
    char s1,s2;
    cin>>y>>s1>>m>>s2>>d;
    if (d<10){
        cout<<"2018/01/0"<<d<<endl;
    }else{
        cout<<"2018/01/"<<d<<endl;
    }
}


Measured memory_bytes: 256
/*
 * @Author: Luisvacson
 * @LastEditors: Luisvacson
 * @Descriptions: None
 * @Date: 2020-03-22 20:04:24
 * @LastEditTime: 2020-03-22 20:04:34
 * @FilePath: \VSCode\C++\Practice\AC abc159 A.cpp
 */
#include<bits/stdc++.h>
using namespace std;

int n,m;
signed main(){
    scanf("%d%d",&n,&m);
    printf("%d\n",(n*(n-1))/2+(m*(m-1))/2);
    return 0;
}

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

ans = 0
for i in range(1000):
    temp = '00' + str(i)
    temp = list(temp[-3:])

    check_num = temp.pop(0)
    cnt = 0
    for string in s:
        if check_num == string:
            cnt += 1
            if cnt == 3:
                ans += 1
                break
            check_num = temp.pop(0)
print(ans)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c <= 21) cout << "win" << endl;
  else cout << "bust" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define big 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define mem0(a) memset(a,0,sizeof(a))
    #define memf(a) memset(a,false,sizeof(a))
    #define mem1(a) memset(a,1,sizeof(a))
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
	{ 
    	if (y == 0) 
        	return 1; 
    	int p = power(x, y/2, m) % m; 
    	p = (p * p) % m; 
  
 	   return (y%2 == 0)? p : (x * p) % m; 
	} 
	int modInverse(int a, int m) 
	{   
    	return power(a, m-2, m);
	}
    signed main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=1;
    	// cin >> t;
    	/*SAARE INPUTS LENA*/
    	/*VARIABLES KI RANGE DEKHLENA*/
    	while(t-->0)
    	{
    		ll s=0,w=0;
    		cin>>s>>w;
    		if(w>=s)
    			cout<<"unsafe";
    		else
    			cout<<"safe";
    	}
    	return 0;
    }

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

int main() {
 long long A,B,C,K;
 cin>>A>>B>>C>>K;
 long long sum=0;
 if(K<A){sum+=K;
    
 }
 if(A<=K && K<A+B){sum+=A;}
 
 if(A+B<=K){sum+=A-(K-A-B);

}
cout<<sum<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, x;
    cin >> n >> x;
    int l, d = 0; 
    int ans = 1;
    rep(i, n) {
        cin >> l;
        d = d + l;
        if (d <= x) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;  
int main(){
     string S;
     getline(cin,S);
     int n = S.size();
     for(int i=0; i<n ; i++ ){
          int j= S.find(",");
          if(j==-1 || j>n ){
               cout<<S<<endl; break;
          }
          S.replace(j,1," ");
     }

}


Measured memory_bytes: 256
import java.util.*;


import java.io.*;
 
public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int[] a = na(n);
		double revsum = 0;
		for(int i:a) {
			revsum += Math.pow(i, -1);
		}
		System.out.println(Math.pow(revsum, -1));
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}
 
	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		int day = 0;
		int daymax = 0;
		for (int d=0;d < S.length() ;d++ ) {
			if (S.charAt(d) == 'R') {
				day++;
			} else {
				day = 0;
			}
			daymax = Math.max(daymax,day);
		}
		System.out.println(daymax);
	}

}


Measured memory_bytes: 35736
#include<stdio.h>
int main(void){
  int i,j,l,tmp,sum=0;
  scanf("%d",&l);
  int a[l];
  for(i=0;i<l;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<l;i++){
    for(j=i+1;j<l;j++){
      if(a[i]<a[j]){
        tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
      }
    }
  }
  for(i=0;i<l;i++){
    if(i==0){
      a[0]=a[0]/2;
    }
    sum+=a[i];
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
N, K, Q = list(map(int, input().split()))
lst = [K] * (N + 1)

for _ in range(Q):
    a = int(input())
    lst[a] += 1

for i in range(1, N + 1):
    if lst[i] - Q <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 50904
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define end "\n"
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define soa(arr,n) sort(arr,arr+n)
#define sov(arr) sort(arr.begin(),arr.end())
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    while(t--){
        ll n,d;
        int count=0;
        cin>>n>>d;
        fr(i,1,n){
            ll x,y;
            cin>>x>>y;
            if(x*x+y*y<=d*d) count++;
        }
        cout<<count<<end;
    }
    return 0;
}

Measured memory_bytes: 3648
from itertools import count, islice

def eratosthenes():
    d = {}
    for q in count(2):
        p = d.pop(q, None)
        if p:
            x = next(x for x in count(q + p, p) if x not in d)
            d[x] = p
        else:
            yield q
            d[q*q] = q

n = int(input())

ones = (prime for prime in eratosthenes() if prime % 10 == 1)
n_ones = islice(ones, n)
print(' '.join(map(str, n_ones)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define bitrep2(n) for(int bit2=0;bit2<(1<<n);bit2++)


int main() {

int A,B,C,D,N; cin >> N;
string S; cin >> S;

int ans=0,temp=0;

rep(i,N){
  if(S[i]=='I') temp++;
  else temp--;

  ans=max(ans,temp);
}

cout << ans << endl;

return 0;
}

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

//using ll = long long;
//typedef long ll;

using namespace std;

int main()
{
    long long int N = 0;
    // cin >> N;
    cin >> N;
    long long int show = N-1, i = 0, j = 0, exlen = 0;
    
    for(long long int len = 1; len*len < N; len++){
        i = len;
        if(N % i == 0 && i != 1){
            j = (long long int)(N / i);
            if(j+i-2 < show){
                show = j+i-2;
            }
        }
        exlen = (len+1);
    }

    if(N % exlen == 0 && (long long int)(N / exlen) + exlen - 2 < show){
        show = (long long int)(N / exlen) + exlen - 2;
    }
    cout << show << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

def to_int():
    s = sorted(input())
    res = 0
    for c in s:
        c = ord(c)
        res = (res * 1337 + c) % 10**19+7
    return res

n=getint()
values = [to_int() for _ in range(n)]

cnt = collections.Counter()

for v in values:
    cnt[v] += 1

res = 0
for m in cnt.values():
    res += m * (m - 1) // 2

print(res)

Measured memory_bytes: 73304
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define ld double
#define pb push_back
#define EPS 1e-9
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
using namespace std;
typedef pair<int, int> II;
typedef pair<II, int> III;

map<int, int> f;
int n, m, a[100010], s[100010];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    /*int n;
    cin >> n;
    if (n == 0) {
        cout << 0;
        return 0;
    }*/
    cin >> n >> m;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) s[i] = (s[i-1] + a[i]) % m;
    ll res = 0;
    f[0]++;
    FOR(i,1,n) {
        res += f[s[i]];
        f[s[i]]++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3968
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int a, b; cin >> a >> b;
	string s; cin >> s;
	if (s[a] == '-') {
		int A = count(s.begin(), s.begin() + a, '-');
		int B = count(s.begin() + a + 1, s.end(), '-');
		if (A + B == 0) {
			cout << "Yes" << "\n";
			return 0;
		}
	}
	cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)

Measured memory_bytes: 3188
function main(input){
  var n = input.split('\n')[0];
  var N = parseInt(n,10);
  var nums = input.split('\n')[1].split(' ').map(function(val){
    return parseInt(val,10);
  });
  
  var Alice = 0;
  var Bob = 0;
  
  var sorted = nums.sort(function(a,b){
    return (a < b ? 1 : -1);
  });

  for(var i = 0; i < N ; i ++){
    if(i % 2 == 0){
      Alice += sorted[i];
    }else{
      Bob += sorted[i];
    }
  }
  console.log(Alice - Bob);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = (a); i < (n); ++i)
#define repk(i,a,n) rep(i,a,n+1)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int MOD = 1e9 + 7;
class PF
{
private:
	vector<ll> data;
	vector<ll> tree_size;

public:
	PF(ll n)
	{
		data = vector<ll>(n);
		tree_size = vector<ll>(n, 1);
		for (ll i = 0; i < n; ++i)
		{
			data[i] = i;
		}
	}

	ll root(ll a)
	{
		if (data[a] == a) return a;
		else return data[a] = root(data[a]);
	}


	void combine(ll a, ll b)
	{
		ll root_a = root(a);
		ll root_b = root(b);
		if (root_a == root_b)
			return;
		else
		{
			tree_size[root_b] += tree_size[root_a];
			tree_size[root_a] = 0;
			data[root_a] = root_b;
			return;
		}
		return;
	}
	ll get_t(ll a)
	{
		return tree_size[root(a)];
	}

};
void sol() {
	ll N, M;
	cin >> N >> M;
	vector<ll> A(M), B(M);

	PF uf = PF(N);
	for (size_t i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];

		uf.combine(A[i] - 1, B[i] - 1);
	}
	ll max_size = 0;
	for (size_t i = 0; i < N; i++)
		max_size = max(max_size, ll(uf.get_t(i)));


	cout << max_size << '\n';
}

int main() {
	int _ = 1;
	// for (scanf("%d", &_); _; _--)
	sol();

	return 0;
}

Measured memory_bytes: 15552
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
			numbers.add(sc.nextInt());
		}
		Collections.sort(numbers);
		System.out.println(numbers.get(n-1) - numbers.get(0));
	}
}


Measured memory_bytes: 23764
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define erep(i,n) for (int i = 1; i <= (n); ++i)
#define brep(i,n) for (int i = n; i >= 0; i--)
#define pb push_back
using namespace std;
using P = pair<int,int>;
using ll = long long;
using Graph = vector<vector<int> > ;


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


int main(){
    int h,w,k;
    int x1,x2,y1,y2;
    cin >> h >> w >> k;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;

    vector<vector<int> > dist(h,vector<int>(w,-1)); 
    vector<vector<int> > dist_pre(h,vector<int>(w,-1)); 

    dist[x1][y1] = 0;
    dist_pre[x1][y1] = 0;

    vector<string> f(h);

    rep(i,h){
        cin >> f[i];
    }


    queue<pair<int,int>> que;
    que.push(make_pair(x1, y1)); // スタートを push

    while (!que.empty()) {
        pair<int, int> current_pos = que.front(); 
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop(); 
        //cout << "xy" << x << y << endl;

        for (int direction = 0; direction < 4; ++direction) {
            for(int step = 1; step <= k; step++ ){
                int next_x = x + step * dx[direction];
                int next_y = y + step * dy[direction];
                if (next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) break;
                if (f[next_x][next_y] == '@') break; 
                if(dist[next_x][next_y] != -1 && dist[next_x][next_y] < dist[x][y]+1){
                    //cout << next_x << " " <<  next_y << endl;
                    break;
                }
                if(dist[next_x][next_y] == -1) {
                    //cout << next_x << next_y << endl;
                    que.push(make_pair(next_x, next_y));
                    dist[next_x][next_y] = dist[x][y] + 1; 
                    //if(next_x == x2 && next_y == y2){
                    //    cout << dist[x2][y2] << endl;
                    //    return 0;
                    //}
                }
            }
        }
    }

    cout << dist[x2][y2] << endl;
}

Measured memory_bytes: 14984
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn 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(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void) {
    
    int a=INF,b=INF;
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)v[i]=i+1;
    vi p(n),q(n);
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    int count=1;
    do {
        if(v==p)a=count;
        if(v==q)b=count;
        count++;
    } while (next_permutation(v.begin(), v.end()));

    fin(abs(a-b));

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();

        int[] multiply = new int[M];
        for (int i = 0 ; i < M; i++)
            multiply[i] = sc.nextInt();
        int ans = 0;
        for (int i = 0 ; i < N; i++){
            long sum = 0;
            for (int j = 0 ; j < M ; j++){
                sum += (multiply[j] * sc.nextInt());
            }
            sum += C;
            if(sum > 0)
                ans ++;
        }
        System.out.println(ans);
        sc.close();
    }
}


Measured memory_bytes: 22228
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        h, w, n = map(int, raw_input().split())
        board = [[None for j in range(w+1)] for i in range(h+1)]
        s = (None, None)
        ans = 0
        for i in range(1, h+1):
            row = raw_input()
            for j in range(1, w+1):
                board[i][j] = row[j-1]
                if board[i][j] == 'S':
                    s = (i, j, ans)
                elif board[i][j] == '1':
                    g = (i, j)
        # print board
        # print s
        # print board[3][3]
        d = [(0, 1), (1, 0), (0, -1), (-1, 0)]

        used = set(s)
        # print nxt
        q = [s]
        for nxt in range(1, n+1):
            # print q
            while q != []:
                y, x, ans = q.pop(0)
                # print y, x, ans, used
                # if (y, x) == (3, 3):
                #     print nxt
                #     print board[y][x]
                #     print nxt == board[y][x]
                # if board[y][x] == str(nxt):
                #     q = [(y, x, ans)]
                #     # print 'nxt: ' + str(nxt)
                #     break
                if y == g[0] and x == g[1]:
                    break
                ans += 1
                for dy, dx in d:
                    if 0 < y + dy <= h and 0 < x + dx <= w and board[y+dy][x+dx] != 'X' and (not (y + dy, x + dx) in used):
                        used.add((y + dy, x + dx))
                        q.append((y + dy, x + dx, ans))
                        
            q = [(y, x, ans)]
            used = set((y, x))            
            for i in range(1, h+1):
                for j in range(1, w+1):
                    if board[i][j] == str(nxt+1):
                        g = (i, j)
        # print q
        print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 92084
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

typedef long long s64;

const int MaxN = 500000;
const int MaxM = 500000;
const int M = 998244353;
const int I2 = M + 1 >> 1;

inline int modpow(int a, const int &n)
{
	int res = 1;
	for (int i = n; i; i >>= 1)
	{
		if (i & 1)
			res = (s64)res * a % M;
		a = (s64)a * a % M;
	}
	return res;
}

int n, m;

int fact[MaxN + MaxM + 1];
int rfact[MaxN + MaxM + 1];

inline void init_fact(int n)
{
	fact[0] = 1;
	for (int i = 1; i <= n; ++i)
		fact[i] = (s64)fact[i - 1] * i % M;

	rfact[n] = modpow(fact[n], M - 2);
	for (int i = n; i; --i)
		rfact[i - 1] = (s64)rfact[i] * i % M;
}

inline int binom(int n, int m)
{
	return (s64)fact[n] * rfact[m] % M * rfact[n - m] % M;
}
inline int binom_r(int n, int m)
{
	return (s64)rfact[n] * fact[m] % M * fact[n - m] % M;
}

int main()
{
	cin >> n >> m;

	if (n < m)
		swap(n, m);

	init_fact(n + m);

	int res = n;
	for (int i = 1; i <= m; ++i)
		res = (res + (s64)I2 * binom(i + i, i) % M * binom(n + m - i - i, n - i) % M * binom_r(n + m, n)) % M;

	cout << res << endl;

	return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;
    puts(S == T.substr(0, S.size()) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

  int N; cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  ll ans = 0, p = A[0];
  int count = 1, left = 0;
  for (int i = 1; i < N; i++) {
    if ((p & A[i]) == 0) {
      count++;
      p ^= A[i];
    }
    else {
      ans += count;
      p -= A[left];
      count--;
      left++;
      i--;
    }
  }
  ans += 1LL * (count + 1) * count / 2;
  cout << ans << "\n";
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,pair<int,int>> P;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

map< pair<int,int>, vector< pair< pair<int,int>, int> > > mp;
int n,m;

void add_edge(int pa, int pb, int line) {
  mp[{pa,-1}].pb({{pa,line},1});
  mp[{pb,-1}].pb({{pb,line},1});
  mp[{pa,line}].pb({{pa,-1},1});
  mp[{pb,line}].pb({{pb,-1},1});
  mp[{pa,line}].pb({{pb,line},0});
  mp[{pb,line}].pb({{pa,line},0});
}

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

  cin >> n >> m;

  REP(i,m) {
    int a,b,line;
    cin >> a >> b >> line;
    add_edge(a,b,line);
  }

  priority_queue<P, vector<P>, greater<P>> que;
  map<pair<int,int>,int> d;
  d[{1,-1}] = 0;
  que.push({0,{1,-1}});

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    pair<int,int> v = p.se;
    if (d[v] < p.fi) continue;
    for (auto p: mp[v]) {
      int dist = p.se;
      if (d.count(p.fi) == 0 || d[p.fi] > d[v] + dist) {
        d[p.fi] = d[v] + dist;
        que.push({d[p.fi], p.fi});
      }
    }
  }

  if (d[{n,-1}] == 0) {
    cout << -1 << endl;
  } else {
    cout << d[{n,-1}] / 2 << endl;
  }
  return 0;
}


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

int m, n;
int field[92][92];
bool visited[92][92];
int max_dist;
int dist;

void dfs(int i, int j){
	visited[i][j] = true;
	if(dist > max_dist){
		max_dist = dist;
	}
	if(field[i + 1][j] == 1 && visited[i + 1][j] == false){
		dist++;
		dfs(i + 1, j);
		visited[i + 1][j] = false;
		dist--;
	}
	if(field[i][j + 1] == 1 && visited[i][j + 1] == false){
		dist++;
		dfs(i, j + 1);
		visited[i][j + 1] = false;
		dist--;
	}
	if(field[i - 1][j] == 1 && visited[i - 1][j] == false){
		dist++;
		dfs(i - 1, j);
		visited[i - 1][j] = false;
		dist--;
	}
	if(field[i][j - 1] == 1 && visited[i][j - 1] == false){
		dist++;
		dfs(i, j - 1);
		visited[i][j - 1] = false;
		dist--;
	}
	return;
}

int main(){
	for(;;){
		cin >> m >> n;
		if(m == 0) break;
		for(int i = 0; i <= m + 1; i++){
			for(int j = 0; j <= n + 1; j++){
				field[i][j] = 0;
			}
		}
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= n; j++){
				cin >> field[i][j];
			}
		}
		max_dist = 0;
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= n; j++){
				for(int k = 0; k <= m + 1; k++){
					for(int l = 0; l <= n + 1; l++){
						visited[k][l] = false;
					}
				}
				dist = 0;
				dfs(i, j);
			}
		}
		cout << max_dist << endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
    vl A(50), B(50), C(50);
    cin >> A[0] >> B[0] >> C[0];

    int ans = 0;
    bool flag = false;
    for(int i = 0;i < 40;i++){
        if(A[i]%2 != 0 || B[i]%2 != 0 || C[i]%2 != 0){
            flag = true;
            break;
        }
        A[i + 1] = (B[i] + C[i])/2;
        B[i + 1] = (A[i] + C[i])/2;
        C[i + 1] = (A[i] + B[i])/2;
        ans++;
    }

    if(flag) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll N, M;
	cin >> N >> M;

	vector < vector<ll>> g(N + 1);

	repn(i, M) {
		ll a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	repn(i, N) {
		cout << g[i].size() << endl;
	}
	
	system("PAUSE");
}


Measured memory_bytes: 504
# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 

n = int(input())
nums = [int(input()) for _ in range(n)]

ans = 0
for idx, m in enumerate(nums):
    if m > 0:
        ans += m // 2
        # m -= (m // 2) * 2
        m = m & 1
    if m == 1 and idx != n-1 and nums[idx+1] >= 1:
        ans += 1
        m -= 1
        nums[idx+1] -= 1

print(ans)


Measured memory_bytes: 7200
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;


int main(){
int N; cin >> N;
vector<int> a(N);
rep(i,N) cin >> a[i];
set<int> S;
rep(i,N){
	if(! S.count(a[i])){
		S.insert(a[i]);
	}
	else{
		S.erase(a[i]);
	}
}
	cout << S.size() << endl;
}

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

int a[100010], n, k;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    int pos = min_element(a + 1, a + n + 1) - a;
    cout << (n - 1 + k - 2) / (k - 1);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll N;
    ll M;
    cin >> N >> M;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    ll ng = 0;
    ll ok = 100000000000;
    ll mid; //幸福度がmid以上
    ll count = 0;
    while(ok - ng > 1) {
        mid = (ok + ng) / 2;
        ll cnt = 0;
        for(int i = 0;i < N;i++) {
            ll cnt2 = mid - vec.at(i);
            auto itr = lower_bound(vec.begin(),vec.end(),cnt2);
            ll A = itr - vec.begin();
            cnt += N - A;
        }
        if(cnt <= M) {
            ok = mid;
            count = cnt;
        }
        else {
            ng = mid;
        }
    }
    vector<ll> Sum(N + 1);
    for(int i = 0;i < N;i++) {
        Sum.at(i + 1) = Sum.at(i) + vec.at(i);
    }
    ll ret = 0;
    for(int i = 0;i < N;i++) {
        ll cnt2 = ok - vec.at(i);
        auto itr = lower_bound(vec.begin(),vec.end(),cnt2);
        ll A = itr - vec.begin();
        ret += vec.at(i) * (N - A) + (Sum.at(N) - Sum.at(A));
    }
    ret += (M - count) * ng;
    cout << ret << endl;
}  

Measured memory_bytes: 4828
K,N = map(int,input().split())
A = list(map(int,input().split()))

mx = K - A[N-1] +A[0]
for i in range(N-1):
  if A[i+1] - A[i] > mx:
    mx = A[i+1] - A[i]
    
ans = K - mx
print(ans)

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

int main()
{
    int n,t,a,i,h,aux;
    double minn=999999;
    cin>>n>>t>>a;
    for(i=1;i<=n;i++)
    {
        cin>>h;
        if(fabs(a-(t-h*0.006))<minn) minn=fabs(a-(t-h*0.006)),aux=i;
    }
    cout<<aux;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int n = 1;//個数のため
  int max=0;//最大値を知るため
  int sumMinasMax=0;
  
  scanf("%d",&n);//要素数nを入力
  int array[n];//配列を用意
  for(int i=0;i<n;i++){
    scanf("%d",&array[i]);//要素ひとつひとつをぶちこむ
  }
  for(int j=0;j<n;j++){
    if(max<array[j]){//最大値を知る
      max = array[j];//見つけ次第ぶちこむ
    }
  }
  for(int k=0;k<n;k++){//要素全ての合計
    sumMinasMax += array[k];
  }
  
  sumMinasMax = sumMinasMax - max;//最大値だけ引く
  
  if(max<sumMinasMax){//定理に基づいて判断
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin>>N;
  
  int k = N % 1000;
  if(k == 0)
  {
  	cout<<0<<endl;
    return 0;
  }
  int p = 1000 - k;
  
  cout<<p<<endl;
  return 0;
}

Measured memory_bytes: 3636
N = int(input())
l = [0] * 4
for i in range(N):
    t = input()
    if t == 'AC':
        l[0] += 1
    elif t == 'WA':
        l[1] += 1
    elif t == 'TLE':
        l[2] += 1
    else:
        l[3] += 1
print('AC','x',l[0],sep=' ')
print('WA','x',l[1],sep=' ')
print('TLE','x',l[2],sep=' ')
print('RE','x',l[3],sep=' ')

Measured memory_bytes: 9204
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5, alpha = 26;

char s0[MAXN + 5];
int S[MAXN + 5];

int n, N;
LL L, R;

inline void input()
{
	scanf("%s", s0 + 1), n = strlen(s0 + 1), N = n / 2;
	for(int i = 1; i <= n; ++i) S[i] = s0[i] - 'a';
	L = read<LL>(), R = read<LL>();
}

int T[MAXN + 5];
int M;

inline void calc_T(int *s, int len)
{
	static int fail[MAXN + 5];

	for(int i = 2, j = 0; i <= len; ++i)
	{
		while(j && s[j + 1] != s[i]) j = fail[j];
		if(s[j + 1] == s[i]) ++j;
		fail[i] = j;
	}

	M = fail[len] ?  len - fail[len] : len;
	for(int i = 1; i <= M; ++i) T[i] = s[i];
}

struct vec
{
	LL cnt[alpha];

	inline LL &operator [] (int pos) { return cnt[pos]; }
	inline const LL &operator [] (int pos) const { return cnt[pos]; }

	inline vec operator + (const vec &rhs) const
	{
		static vec res;
		for(int i = 0; i < alpha; ++i) res[i] = (*this)[i] + rhs[i];
		return res;
	}
	inline vec operator - (const vec &rhs) const
	{
		static vec res;
		for(int i = 0; i < alpha; ++i) res[i] = (*this)[i] - rhs[i];
		return res;
	}

	vec() { memset(cnt, 0, sizeof cnt); }
};

const int MAX_LOG = 100;

vec cnt[MAX_LOG + 1];
LL len[MAX_LOG + 1];
int k;

inline vec prefix(LL LIM)
{
	if(LIM == 0) return vec();
	for(int i = k; i >= 1; --i) if(len[i] <= LIM) return cnt[i] + prefix(LIM - len[i]);

	vec res;
	for(int i = 1; i <= LIM; ++i) ++res[S[i]];
	return res;
}

inline void solve()
{
	calc_T(S, N);

	len[1] = N;
	for(int i = 1; i <= N; ++i) ++cnt[1][S[i]];

	len[2] = N + M;
	for(int i = 1; i <= N; ++i) ++cnt[2][S[i]];
	for(int i = 1; i <= M; ++i) ++cnt[2][T[i]];

	for(k = 2; len[k] * 2 < R; )
	{
		++k;
		len[k] = len[k - 1] + len[k - 2];
		for(int i = 0; i < alpha; ++i) cnt[k][i] = cnt[k - 1][i] + cnt[k - 2][i];
	}

	vec ans;
	if(R > len[k]) ans = prefix(len[k]) - prefix(L - 1) + prefix(R - len[k]);
	else ans = prefix(R) - prefix(L - 1);
	for(int i = 0; i < alpha; ++i) printf("%lld ", ans[i]);
	puts("");
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 2048
import numpy as np
import heapq
# 1までの距離を作成する。
# 逆向きに辺があると思って、1からの距離の一覧を作成

H,W = map(int,input().split())

cost = np.zeros((10,10),dtype=np.int64)
for i in range(10):
  temp = map(int,input().split())
  for j,x in enumerate(temp):
    cost[j,i] = x

d = np.zeros(10,dtype=np.int64)

h = []
heapq.heappush(h,(0,1))
while h:
  dx,x = heapq.heappop(h)
  for y in range(10):
    if y in [1,x]:
      continue
    if d[y] == 0 or dx + cost[x,y] < d[y]:
      d[y] = dx+cost[x,y]
      heapq.heappush(h,(d[y],y))

answer = 0
for _ in range(H):
  row = input().split()
  for x in row:
    x = int(x)
    answer += 0 if x == -1 else d[x]
    
print(answer)

Measured memory_bytes: 21640
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
a1 ... an

n 100
ai 1000
 */
int n,a[100];

int main(){
  cin>>n;
  REP(i,n){
    cin>>a[i];
  }

  sort(a,a+n);

  cout<<a[n-1]-a[0]<<endl;

  return 0;
}


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

int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int ans = 0;

void dfs(vector<int> A) {
  if (A.size() == N+1) {
    int sum = 0;
    for (int i = 0; i < Q; i++) {
      if (A[b[i]] - A[a[i]] == c[i]) {
        sum += d[i];
      }
    }
    ans = max(ans, sum);
    return;
  }
  A.push_back(A.back());
  while (A.back() <= M) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> N >> M >> Q;
  a = b = c = d = vector<int>(Q);
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1, 1));
  cout << ans << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    String[] a = new String[h];
    char[][] b = new char[h][w];
    for(int i = 0; i < h; i++) {
      a[i] = sc.next();
      for(int j = 0; j < w; j++) {
        b[i][j] = a[i].charAt(j);
      }
    }
    for(int i = 0; i < h + 2; i++) {
      for(int j = 0; j < w + 2; j++) {
        if(i == 0 || i == h + 1) {
          System.out.print("#");
        }else{
          if(j == 0 || j == w+1) {
            System.out.print("#");
          }else{
            System.out.print(b[i-1][j-1]);
          }
        }
      }
      System.out.println();
    }
  }
}


Measured memory_bytes: 24660
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int N = sc.nextInt();
				if(N == 0) break;
				
				int[] dx = {-1, 0, 1, 0};
				int[] dy = {0, -1, 0, 1};
				int[] x = new int[N];
				int[] y = new int[N];
				x[0] = 0;
				y[0] = 0;
				
				int minx = 0;
				int maxx = 0;
				int miny = 0;
				int maxy = 0;
				
				for(int i=1; i<N; i++) {
					int n = sc.nextInt();
					int d = sc.nextInt();
					x[i] = x[n] + dx[d];
					y[i] = y[n] + dy[d];
					
					minx = Math.min(x[i], minx);
					maxx = Math.max(x[i], maxx);
					miny = Math.min(y[i], miny);
					maxy = Math.max(y[i], maxy);
				}
				
				int xdif = maxx - minx + 1;
				int ydif = maxy - miny + 1;
				System.out.printf("%d %d\n", xdif, ydif);
			}
		}
	}
}



Measured memory_bytes: 41688
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int d,n;cin>>d>>n;
  int ans=1;
 if(n==100)
   n=101;
  if(d==0)
    cout<<n<<endl;
  else
  {
    for(int i=0;i<d;i++)
    {
      ans*=100;
    }
    cout<<ans*n;
  }
}
      


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const A = arg[1].split(" ").map(n=>parseInt(n));
    const B = arg[2].split(" ").map(n=>parseInt(n));
    const C = arg[3].split(" ").map(n=>parseInt(n));
    
    let answer = 0;
    let lastEaten = -1;
    
    for(let i in A) {
        answer += B[A[i]-1];
        
        // ボーナスがあればもらう
        if(lastEaten + 1 === A[i]) {
            answer += C[lastEaten-1];
        }
        
        lastEaten = A[i];
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
N = int(input())
A = [list(map(int, input().split()))] + [list(map(int, input().split()))]
B = [[[] for _ in range(N)]] + [[[] for _ in range(N)]]
B[1][N - 1] = A[1][N - 1]
B[0][N - 1] = A[1][N - 1] + A[0][N - 1]
for i in range(2, N + 1):
    B[1][N - i] = A[1][N - i] + B[1][N - i + 1]
    B[0][N - i] = A[0][N - i] + max(B[1][N - i], B[0][N - i + 1])
print(B[0][0])

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	while(1){
		int max=0;
		char sec;
		for(int i=0;i<5;i++){
			int a,b;
			scanf("%d%d",&a,&b);
			if(i==0&&(a|b)==0)return 0;
			if(max<a+b){
				max=a+b;
				sec='A'+i;
			}
		}
		printf("%c %d\n",sec,max);
	}
}

Measured memory_bytes: 0
N, M = map(int, input().split())
ab = []
for _ in range(N):
    ab.append(list(map(int, input().split())))
cd = []
for _ in range(M):
    cd.append(list(map(int, input().split())))
    
for x in ab:
    a = x[0]
    b = x[1]
    cnt = []
    for y in cd:
        c = y[0]
        d = y[1]
        k = abs(a-c)+abs(b-d)
        cnt.append(k)
    print(cnt.index(min(cnt))+1)

Measured memory_bytes: 9208
#include <stdio.h>

struct t{
  int p,s;    //??£?§£??°
  int lank;
};

int main(void){
  struct t team[100];
  int lank[100];
  int ti=1,li=1,j,k;
  scanf("%d,%d",&team[0].p,&team[0].s);
  team[0].lank=1;
  lank[0]=team[0].s;
  //printf("%d %d %d\n",team[0].p,team[0].s,team[0].lank);
  while(scanf("%d,%d",&team[ti].p,&team[ti].s)){
    if(team[ti].p==0&&team[ti].s==0)  break;
    else{
      //???????¢????
      for(j=0;j<li;j++){
	if(lank[j]<team[ti].s){
	  //printf("a\n");
	  for(k=li;k>j;k--){
	    lank[k]=lank[k-1];
	  }
	  lank[j]=team[ti].s;
	  li++;
	  team[ti].lank=j+1;
	  for(k=0;k<ti;k++){
	    if(j+1<=team[k].lank) team[k].lank++;
	  }
	  break;
	}else if(lank[j]==team[ti].s){
	  //printf("b\n");
	  team[ti].lank=j+1;
	  break;
	}else if(j==li-1){
	  //printf("last\n");
	  lank[j+1]=team[ti].s;
	  li++;
	  team[ti].lank=j+2;
	  break;
	}
      }
      ti++;

      /*??¨??¨????????????
      printf("team:%d lank:%d\n",ti,li);
      for(j=0;j<ti;j++){
	printf("/team[%d]\n",j);
	printf("p=%d s=%d lank=%d\n",team[j].p,team[j].s,team[j].lank);
      }
      for(j=0;j<li;j++){
	printf("%d???:%d\n",j+1,lank[j]);
      }
      */
    }
  }
  int q;
  while(scanf("%d",&q)!=EOF){
    for(j=0;j<ti;j++){
      if(q==team[j].p){
	printf("%d\n",team[j].lank);
	break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 600