akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<string>
using namespace std;
queue<pair<string,int> > Q;
string p;
int n,q,t,_t;
int main(){
    scanf("%d %d",&n,&q);
    for(int i = 1;i <= n;++i){
        cin>>p>>t;
        Q.push(make_pair(p,t));
    }
    while(!Q.empty()){
        p = Q.front().first;
        t = Q.front().second;
        if(t <= q){
            _t += t;
            cout<<p<<" "<<_t<<endl;
            Q.pop();
        }
        else{
            _t += q;
            t -= q;
            Q.pop();
            Q.push(make_pair(p,t));
        }
    }
    return 0;
}


Measured memory_bytes: 6452
a, b, c, x, y = map(int, input().split())
max_count = max(x, y)
ans = 10**18

for i in range(max_count+1):
    tmp = i*2*c
    if x-i > 0:
        tmp += (x-i)*a
    if y-i > 0:
        tmp += (y-i)*b
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 65368
#include <bits/stdc++.h>
using namespace std;
vector<double> vi;
double dp[3002][3002];
bool vis[3002][3002];
double sol(int indx, int head)
{
	if(head>vi.size()-head)
		return 1;
	if(indx == vi.size())
		return 0.00;

	if(vis[indx][head])
		return dp[indx][head];

 	vis[indx][head] = true;
	double ret = 0;
 	ret += vi[indx] * sol(indx + 1, head + 1);
 	ret += (1.00 - vi[indx]) * sol(indx + 1, head);
 	return dp[indx][head] = ret;

}
int main()
{
	int n;cin>>n;
	vi.resize(n);
	for(int i = 0; i < n; i++)
		cin>>vi[i];
	cout<<fixed<<setprecision(10)<<sol(0,0)<<endl;
	return 0;
}


Measured memory_bytes: 79104
#include <cstdio>
#include <algorithm>
using namespace std;

long long n,i,j,a[100100],b[100100],c[100100],B[100100],ans;

int main() {
	scanf("%lld",&n);
	for (i=1;i<=n;i++) scanf("%lld",a+i);  sort(a+1,a+n+1);
	for (i=1;i<=n;i++) scanf("%lld",b+i);  sort(b+1,b+n+1);
	for (i=1;i<=n;i++) scanf("%lld",c+i);  sort(c+1,c+n+1);
	for (i=j=1;i<=n;i++) {
		while (j <= n && c[j] <= b[i]) ++j;
		B[i] = n-j+1;
	}
	for (i=n-1;i;i--) B[i] += B[i+1];
	for (i=j=1;i<=n;i++) {
		while (j <= n && b[j] <= a[i]) ++j;
		ans += B[j];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

// 入次数と出次数がともに1である ⇒ 辺の向きが揃ったループ（v1 -> v2 -> ... -> vn -> v1）
// ⇒ ある点を出発して戻って来られるかを調べる
//
// ループを構成する経路が複数あれば、より短い方が条件を満たす（(v1 -> v2 -> v3, v1 -> v3)の場合、条件に合わない(v1,v2,v3)を採用しない）
// ⇒最短経路のループを探せば良い
int main() {
  int N;  // 頂点の数
  int M;  // 辺の数
  std::cin >> N >> M;

  // 頂点の親子関係のマップを作る
  std::unordered_map<int, std::vector<int>> children_map;  // 親頂点から子供を探すためのマップ
  for (int i = 0; i < M; ++i) {
    int A, B;  // AからBへの辺
    std::cin >> A >> B;
    children_map[A].push_back(B);
  }

  // 最短のループを探す
  std::vector<bool> visited(N + 1);  // 訪問を記録するフラグ列
  std::vector<int> path;             // 現在たどっている頂点の経路
  std::vector<int> shortest_path;    // 見つけたループの最短経路
  path.reserve(N + 1);
  shortest_path.reserve(N + 1);
  bool quit = false;  // 処理を終了するためのフラグ
  for (int start = 1; start <= N; ++start) {
    // 初期化
    std::fill(visited.begin(), visited.end(), false);
    path.clear();
    visited[start] = true;
    path.push_back(start);

    while (true) {
      // まだ訪問していない子頂点に訪問する
      bool all_visited = true;  // すべての子頂点が訪問済みだったか
      for (const auto& child : children_map[path.back()]) {
        if (child == start) {
          // 始点に戻ってこられる最短経路を記録する
          if (shortest_path.empty() || path.size() < shortest_path.size()) {
            shortest_path = path;

            // これ以上ない最短経路が見つかれば、そこで終了する
            if (shortest_path.size() == 2) {
              quit = true;
              break;
            }
          }
        } else if (!visited[child]) {
          // 未訪問の子頂点があれば、その先も訪問する
          path.push_back(child);
          visited[child] = true;
          all_visited = false;
          break;
        }
      }

      // これ以上ない最短経路が見つかれば、そこで終了する
      if (quit) break;

      // すべての子頂点が訪問済みとなれば、1つ前の頂点に戻る
      if (all_visited) {
        path.pop_back();

        // すべての頂点を確認し終えたら調査を終了する
        if (path.empty()) break;
      }
    }

    // これ以上ない最短経路が見つかれば、そこで終了する
    if (quit) break;
  }

  // 結果発表
  if (shortest_path.empty()) {
    // ループが見つからなかった場合
    std::cout << "-1";
  } else {
    // ループを見つけた場合
    std::cout << shortest_path.size() << '\n';
    for (const auto& v : shortest_path) {
      std::cout << v << '\n';
    }
  }

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<map>
using namespace std;
int main(){
  int n,p=0;
  while(cin>>n,n){
    multimap<int,string,greater<int> >m;
    if(p)cout<<endl;
    p++;
    while(n--){
    string s;
    int a,b,c;  
    cin>>s>>a>>b>>c;
    a=a*3+c;
    m.insert( make_pair(a,s) );
    }
    for(multimap<int,string,greater<int> >::iterator it=m.begin();it!=m.end();it++){
      cout<<(*it).second<<','<<(*it).first<<endl;
      }
  }
}

Measured memory_bytes: 3224
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int temp;
        int index = 1;
        while(true){
            temp = input.nextInt();
            if(temp == 0)break;
            System.out.println("Case " + index + ": " + temp);
            index++;
        }

    }}


Measured memory_bytes: 41804
#include<bits/stdc++.h>
using namespace std;
int bubblesort(vector<int>&arr,int n)
{
    int swaps =0;
    for(int i=0;i<n;i++ )
    for(int j=n-1;j>=i+1;j--)
    if(arr[j]<arr[j-1])
    {
        swap(arr[j],arr[j-1]);
        swaps++;
    }
    return swaps;
    
}
int main()
{
    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        arr.push_back(x);
        
    }
    int swaps;
    swaps=bubblesort(arr,n);
    cout<<arr[0];
    for(int i=1;i<n;i++)
    cout<<" "<<arr[i];
    cout<<endl;
    cout<<swaps<<endl;
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;

int main(void) {
    ll n;
    string s;
    cin >> n;
    set<string> v;
    for(ll i=0;i<n;i++) {
        cin >> s;
        v.insert(s);
    }
    cout << v.size() << endl;
}



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

bool debug=true;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char d[21][21];

void init(){
  for(int i=0;i<21;i++)for(int j=0;j<21;j++)d[i][j]='#';
}

int dfs(int sx,int sy){
  int cnt=0;
  queue<int>que;
  que.push(sx);que.push(sy);
  while(que.size()){
    int x=que.front();que.pop();
    int y=que.front();que.pop();
    for(int i=0;i<4;i++){
      if(d[y+dy[i]][x+dx[i]]=='.'){
	que.push(x+dx[i]);que.push(y+dy[i]);
	d[y+dy[i]][x+dx[i]]='#';
	cnt++;
      }
    }
  }
  return cnt+1;
}

int main(){
  int w,h;
  
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    init();
    int x,y;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>d[i][j];
	if(d[i][j]=='@'){
	  x=j;y=i;
	}
      }
    }
    cout<<dfs(x,y)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3116
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=a%10;
		
    
 	if(b==3){
    		System.out.println("bon");
    	}else if(b==0||b==1||b==6||b==8){
     		System.out.println("pon");
   	 }else{

    	System.out.println("hon");
    }
    }
}

Measured memory_bytes: 35704
A,B,K = map(int,input().split())

if A+K-1< B-K+1:
  for i in range(A,A+K):
    print(i)
  for i in range(B-K+1,B+1):
    print(i)
elif A+K-1>= B-K+1:
  for i in range(A,B+1):
    print(i) 

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

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

    vector<int> x(5);
    rep(i, 5) {
        cin >> x[i];
        if(x[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<array>
#include<cstring>
#include<numeric>
#include<string>
#include<set>
#include<cstdio>
#include<cmath>
#include<unordered_map>
#include<bitset>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    char x;
    cin>>x;
    if(x>='a' && x<='z') cout<<"a\n";
    else cout<<"A\n";
    return 0;
}


Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int A = sc.nextInt();
		int P = sc.nextInt();

		double peace = P;

		if(A > 0){
			peace = peace + (A * 3);
		}

				System.out.println(String.format("%,d", ((int) Math.floor(peace) / 2 )));

		sc.close();
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int maxt(int x){
  return (x+9)/10*10;
}
int ret(int x){
  return maxt(x)-x;
}
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int sum=maxt(a)+maxt(b)+maxt(c)+maxt(d)+maxt(e);
  sum-=max({ret(a),ret(b),ret(c),ret(d),ret(e)});
  cout<<sum<<endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

def c(a, m, x, y):
  tmp = []
  for i in range(m):
    tmp.append(a[y+i][x:x+m])
  return tmp

for x in range(n - m + 1):
  for y in range(n - m + 1):
    if c(a, m, x, y) == b:
      print("Yes")
      exit(0)
print("No")

Measured memory_bytes: 8880
#include<stdio.h>
int main(void){
    int x,y,z;
    int temp;
    scanf("%d %d %d",&x,&y,&z);
    temp=x;
    x=y;
    y=temp;
    temp=x;
    x=z;
    z=temp;
    printf("%d %d %d\n",x,y,z);
    return 0;
}

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

bool pt[10005];

int main()
{
    int N;
    scanf("%d", &N);
    int S[N], sm = 0;
    for(int i = 0; i < N; ++i) {
        scanf("%d", &S[i]); sm += S[i];
    }
    sort(S, S + N);
    pt[0] = true;
    vector<int> P;
    P.push_back(0);
    for(int i = 0; i < N; ++i) {
        int sz = P.size();
        for(int j = 0; j < sz; ++j) {
            int k = P[j] + S[i];
            if(pt[k]) continue;
            pt[k] = true; 
            P.push_back(k);
        }
    }
    for(int i = sm; i >= 0; --i) 
        if(pt[i] && i%10) {
            printf("%d\n", i); return 0;
        }
    printf("0\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a+b)==(c+d)){
    cout<<"Balanced"<<endl;
  }else if((a+b)<(c+d)){
    cout<<"Right"<<endl;
  }else{
    cout<<"Left"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int n;
	cin >> n;
	vll a(n + 1, 0);
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
	}
	ll x = 1000, y = 0, cur = 1;
	for(int i = 2; i <= n; i ++)
	{
		if(a[i] > a[i - 1])
		{
			ll mn = 1e9;
			for(int j = i - 1; j >= cur; j --)
			{
				mn = min(mn, a[j]);
			}
			ll o = x / mn;
			x -= o*mn;
			y += o;
			x += o*a[i];
			y = 0;
			cur = i;
		}
	}
	cout << x;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3628
/*input
3
28 27 24
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	bool good = true;
	int n, i;
	cin >> n;
	for(i=0; i<n; i++) {
		int x;
		cin >> x;
		if(x % 2 == 0 && (x%3!=0 && x%5 !=0)) good = false;
	}
	if(good) cout <<"APPROVED" << endl;
	else cout <<"DENIED" << endl;
}

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


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	private static Scanner s = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		int N=s.nextInt();			
		String S=s.next();
		char v;//82 71 66
		int R[]=new int[N];
		int G[]=new int[N];
		int B[]=new int[N];
		int rr=0,gg=0,bb=0;
		for(int i=0;i<N;i++) {
			v=S.charAt(i);
			if(v==82)rr++;
			if(v==71)gg++;
			if(v==66)bb++;
			R[i]=rr;
			G[i]=gg;
			B[i]=bb;
		}
		long ans=0;
		char a,b,c=0;
		
		for(int i1=0;i1<N;i1++) {
			a=S.charAt(i1);
			for(int i2=i1+1;i2<N;i2++) {
				b=S.charAt(i2);
				if(a==b)continue;
				if(a!=82&&b!=82) {
					c=82;//R
					ans+=R[N-1]-R[i2];
				}
				else if(a!=71&&b!=71) {
					c=71;//G
					ans+=G[N-1]-G[i2];
				}
				else if(a!=66&&b!=66) {
					c=66;//B
					ans+=B[N-1]-B[i2];
				}
				if(i2*2-i1<N&&S.charAt(i2*2-i1)==c) {
					ans--;
				}
			}
		}
	
		
		
		p(ans);
				
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
}


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

int main() {
	int n, x;
	vector<int> arr;
	cin>>n;
	for (int i = 0; i < n; i++) {
		cin>>x;
		arr.push_back(x);
	}
	sort(arr.begin(), arr.end());
	reverse(arr.begin(), arr.end());
	long long ans = arr[0];
	n-=2;
	int k = 1;
	while (1) {
		if (n == 0) {
			break;
		}
		if (n == 1) {
			ans += arr[k];
			break;
		}
		ans += arr[k];
		ans += arr[k];
		n = n - 2;
		k++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n, x, t;
  cin >> n >> x >> t;
  int ans = (n + x - 1)/x;
  ans *= t;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    import math as m
    A, B, H, M = map(int, read().split())
    theta = ((360/60)*M/180)*m.pi
    phi = ((360/720)*(H*60+M)/180)*m.pi
    ans = abs(m.sin(theta)*B - m.sin(phi)*A)**2 + abs(m.cos(theta)*B - m.cos(phi)*A)**2
    ans = m.sqrt(ans)
    print(ans)
    return

if __name__ == '__main__':
    main()


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

int n;
vector<string> ans;

void rec(string s, int maxi, int curr) {
    if (curr == n) {
        ans.emplace_back(s);
        return;
    }
    for (int i = 0; i <= maxi; i++) {
        rec(s, maxi, curr+1);
        s[curr]++;
    }
    rec(s, maxi+1, curr+1);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    string s(n, 'a');
    rec(s, -1, 0);
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << "\n";
    return 0;
}

Measured memory_bytes: 7796
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
    int n,k,min,min1;
    cin>>n>>k;
    if (n%k==0){
        cout<<"0\n";
        return 0;
    }
    else{
        min=n/k;
        min1=min+1;
        cout<<abs(min-min1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 888
/*================================================
# ~  file:C.cpp
# ~~ date:2020-02-22
# ~~~author: SoMnus_L
#        |everybody finds love,in the end|
#   人の運命か,人の希望は悲しみにつづられているね
=================================================*/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;

int n;
int a[N];
int s=0;
int ans1=0,ans2=0;
int main(){
 ios::sync_with_stdio(false);
  cin>>n;
   for(int i=1;i<=n;i++){
     cin>>a[i];
      s+=a[i];
   }
   int x=s/n;
   for(int i=1;i<=n;i++)    ans1+=(a[i]-x)*(a[i]-x);
   x++;
   for(int i=1;i<=n;i++)    ans2+=(a[i]-x)*(a[i]-x);
   int  ans=min(ans1,ans2);
   cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x, k, d; cin >> x >> k >> d;
    if(x < 0) x *= -1;

    double kd = double(k) * double(d);

    if(double(x) > kd){
        cout << x - k * d << endl;
        return 0;
    }

    ll cand1 = x % d;
    ll cand2 = d - cand1;

    ll n_step = x / d;
    if(n_step % 2 == k % 2){
        cout << cand1 << endl;
    }
    else{
        cout << cand2 << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,Pll> a,pair<ll,Pll> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se.fi>b.se.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int h1,h2,m1,m2,k;cin>>h1>>m1>>h2>>m2>>k;
    int ans=(h2-h1)*60;
    if(m2>=m1){
        ans+=m2-m1;
    }
    else{
        ans-=60;
        ans+=m2+60-m1;
    }
    cout<<mmax(0,ans-k)<<endl;
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------










































Measured memory_bytes: 3652
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val cumsum = Array(n+1) { IntArray(n+1) }
    for (y in 1..n) {
        var subtotal = 0
        for (x in 1..n) {
            subtotal += sc.nextInt()
            cumsum[y][x] = subtotal + cumsum[y-1][x]
        }
    }

    var result = -10000000
    for (y in 1..n) {
        for (x in 1..n) {
            for (x2 in x-1 downTo 0) {
                for (y2 in y-1 downTo 0) {
                    result = Math.max(result, cumsum[y][x] - cumsum[y2][x] - cumsum[y][x2] + cumsum[y2][x2])
                }
            }
        }
    }
    println(result)
}


Measured memory_bytes: 41624
//
//  main.cpp
//  test3
//
//  Created by 黒田浩揮 on 2019/04/21.
//  Copyright © 2019 黒田浩揮. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    // insert code here...
    int a,b,c,d;
    d=0;
    
    cin>>a>>b;
    int number[a+1][b+1];
    int number2[a+1];
    int number3[b];
    for (int u=0; u<a; u++) {
        number2[u]=0;
    }
    for (int u=0; u<b; u++) {
        number3[u]=0;
    }
    for(int v=0;v<a;v++){
        for(int l=0;l<b;l++){
            cin>>c;
            
            number[v][l]=c;
            number2[v]+=c;
            number3[l]+=c;
            
            
        }
    }
    for(int n=0;n<a;n++){
        number[n][b]=number2[n];
    }
    for(int y=0;y<b;y++){
        number[a][y]=number3[y];
    }
    for(int y=0;y<b;y++){
        d+=number3[y];
    }
    number[a][b]=d;
    for(int v=0;v<a+1;v++){
        for(int l=0;l<b+1;l++){
            if(l==0){
                cout<<number[v][l];
            }else{
                cout<<" "<<number[v][l];
            }
            if(l==b){
                cout<<endl;
            }
        }
    }
}



Measured memory_bytes: 3140
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M,X;cin>>N>>M>>X;
  vint A(M);
  repeat(i,M){
    cin>>A[i];
  }
  int a = lower_bound(A.begin(),A.end(),X)-A.begin();
  cout << min(a,M-a) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H,W,K = map(int, readline().split())
    S = [list(map(int, readline().strip())) for j in range(H)]

    white = 0
    for line in S:
        white += sum(line)

    if white <= K:
        print(0)
        exit()

    # 横線の決め方を全探索
    ans = 10**5
    for pattern in range(2**(H-1)):
        # 初期化
        impossible = False
        x = 0
        ly = bin(pattern).count("1")
        y = [[0]*W]*(ly + 1)
        line = 0
        for i in range(H):
            y[line] = [y[line][j] + S[i][j] for j in range(W)]
            if (pattern >> i) & 1:
                line += 1

        # 各列の値を加算していく
        count = [0]*(ly + 1) 
        for col in zip(*y):
            # Kより大きい値を加算する場合は不成立
            if any(a > K for a in col):
                impossible = True
                break
            for i, a in enumerate(col):
                count[i] += a
                # 和がKより大きければカット数を増やす
                if count[i] > K:
                    x += 1
                    count = list(col) 
                    break
            if x + ly > ans:
                impossible = True
                break
        if impossible:
            x = 10**6

        ans = min(ans, x + ly)

    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
	string s;
	cin>>s;
	int aindex;
	int zindex;
	int aget=0;
	for (int i=0;i<s.length();++i){
		if((s[i]=='A') && (aget==0)){
			aindex=i;
			aget=1;
		}
		if(s[i]=='Z') zindex=i;
	}
	cout<<zindex-aindex+1<<endl;
}


Measured memory_bytes: 640
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import re
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  S=pin()[:-1]
  if re.fullmatch(r"(hi)+",S)==None:
    print("No")
    return 
  print("Yes")
  return 

main()

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int t[101];
int tt[101];

int main()
{
	CIN(int, A);
	CIN(int, B);
	CIN(int, C);
	CIN(int, D);
	reps(i, A, B+1) t[i] = 1;
	reps(i, C, D+1) tt[i] = 1;
	int res = 0;
	rep(i, 101) res += t[i]*tt[i];
	cout << max(res-1, 0) << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		long[] S = new long[1 << N];
		for (int i = 0; i < S.length; ++i) {
			S[i] = sc.nextLong();
		}
		Arrays.sort(S);
		PriorityQueue<Long> pq = new PriorityQueue<>();
		pq.add(-S[S.length - 1]);
		S[S.length - 1] = 1L << 60;
		for (int g = 0; g < N; ++g) {
			PriorityQueue<Long> npq = new PriorityQueue<>();
			int p = S.length - 1;
			while (!pq.isEmpty()) {
				long v = -pq.poll();
				while (p >= 0 && S[p] > v - 1) {
					--p;
				}
				if (p >= 0 && S[p] <= v - 1) {
					npq.add(-S[p]);
					npq.add(-v);
					S[p] = 1L << 60;
					--p;
				} else {
					System.out.println("No");
					return;
				}
			}
			pq = npq;
		}
		System.out.println("Yes");
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 50280
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static char[][] map;
	public static int w, h;
	public static boolean[][] used;
	public static int[][][] val;
	public static int[][] len;
	public static final int[] dx = {1, 0};
	public static final int[] dy = {0, 1};
//	public static int turn;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			w = in.nextInt();
			h = in.nextInt();
			if(w == 0) break;
			map = new char[h][w];
			val = new int[h][w][h+w];
			len = new int[h][w];
			used = new boolean[h][w];
			int[] max = new int[h+w];
			int mlen = 0;
			for(int i=0; i<h; i++){
				map[i] = in.next().toCharArray();
				for(int j=0; j<w; j++){
					if(!Character.isDigit(map[i][j])) continue;
					val[i][j][0] = map[i][j]-'0';
					if(val[i][j][0] == 0) continue;
					len[i][j] = 1;
					if(val[i][j][0] > max[0]){
						mlen = 1;
						max[0] = val[i][j][0];
					}
				}
			}
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(!Character.isDigit(map[i][j])) continue;
					if(len[i][j] == 0) continue;
					for(int k=0; k<2; k++){
						int ny = i+dy[k];
						int nx = j+dx[k];
						if(out(ny, nx)) continue;
						if(!Character.isDigit(map[ny][nx])) continue;
						val[i][j][len[i][j]] = map[ny][nx]-'0';
						len[i][j]++;
						if(larger(val[i][j], len[i][j], val[ny][nx], len[ny][nx])){
							val[ny][nx] = val[i][j].clone();
							len[ny][nx] = len[i][j];
							if(larger(val[i][j], len[i][j], max, mlen)){
								max = val[i][j].clone();
								mlen = len[i][j];
							}
						}
						len[i][j]--;
						val[i][j][len[i][j]] = 0;
					}
				}
			}
			for(int i=0; i<mlen; i++){
				System.out.print(max[i]);
			}
			System.out.println();
		}
	}
	
	public static boolean out(int y, int x){
		return x<0 || x>=w || y<0 || y>=h;
	}
	
	public static boolean larger(int[] s1, int l1, int[] s2, int l2){
		// is 1 larger than 2 ?
		if(l1 > l2) return true;
		if(l1 < l2) return false;
		int length = l1;
		for(int i=0; i<length; i++){
			if(s1[i] == s2[i]) continue;
			if(s1[i] < s2[i]) return false;
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 67560
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t W,H,k;
std::unordered_map<uint64_t, int8_t> block;
inline uint64_t to_b_index(uint64_t x, uint64_t y) {
	return (x << 32) | (y & 0b11111111'11111111'11111111'11111111);
}
inline int32_t getx(uint64_t index) {
	return (index >> 32);
}
inline int32_t gety(uint64_t index) {
	return index & 0b11111111'11111111'11111111'11111111;
}

int32_t result = 2;
//??????????????????
void func(uint64_t pos, bool jumpable)
{
	auto x = getx(pos);
	auto y = gety(pos);
	if (x == 0 || y == H - 1) {
		result = std::min(result, (jumpable?0:1));
		return;
	}
	if (block.count(pos)) {
		if (block[pos] == 2 || (!jumpable&&block[pos] == 1)) { return; }
		block[pos] = jumpable ? 2 : 1;
	}

	for (int nx = std::max<int32_t>(0, x-1), endx= std::min<int32_t>(W-1, x+1); nx <= endx; nx++)
		for (int ny = std::max<int32_t>(0, y - 1), endy = std::min<int32_t>(H - 1, y + 1); ny <= endy; ny++)
	{
		auto npos = to_b_index(nx, ny);
		if (block.count(npos)) {
			func(npos, jumpable);
		}
		else if (jumpable) {
			func(npos, false);
		}
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> W >> H>>k;
	for (int32_t i = 0; i < k; i++)
	{
		uint64_t x, y;
		in >> x >> y;
		block.emplace(to_b_index(x, y), false);
	}

	for (size_t i = 2; i < W; i++)
	{
		func(to_b_index(i, -1), true);
	}
	for (size_t i = 0; i < H-2; i++)
	{
		func(to_b_index(W, i), true);
	}
	out << result << endl;

	return 0;
}
#endif

Measured memory_bytes: 16348
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Dice {
	int n;
	int s;
	int e;
	int w;
	int top;
	int bottom;
};

Dice control_dice(Dice d, char c) {
	if (c == 'N') {
		int toptmp = d.top;
		d.top = d.s;
		d.s = d.bottom;
		d.bottom = d.n;
		d.n = toptmp;
	} else if (c == 'S') {
		int toptmp = d.top;
		d.top = d.n;
		d.n = d.bottom;
		d.bottom = d.s;
		d.s = toptmp;
	} else if (c == 'E') {
		int toptmp = d.top;
		d.top = d.w;
		d.w = d.bottom;
		d.bottom = d.e;
		d.e = toptmp;
	} else if (c == 'W') {
		int toptmp = d.top;
		d.top = d.e;
		d.e = d.bottom;
		d.bottom = d.w;
		d.w = toptmp;
	}
	return d;
}

Dice default_dice() {
	Dice d;
	d.n = 5;
	d.s = 2;
	d.e = 3;
	d.w = 4;
	d.top = 1;
	d.bottom = 6;
	return d;
}

int main() {
	vector<int> dice(6);
	for (int i = 0; i < 6; i++) {
		cin >> dice[i];
	}

	Dice d = default_dice();

	string control;
	cin >> control;
	for (int i = 0; i < control.size(); i++) {
		d = control_dice(d, control[i]);
	}

	cout << dice[d.top-1] << endl;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
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;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N=50;
const int MAX_M=20;
int N;
vector<int>G[MAX_N];
vector<int> bitM(MAX_M);
vector<int> depth(MAX_N);
map<pair<int,int>,int>memo;
typedef pair<int,int>P;

int POW(int x,int r){
    if(r==0)return 1;
    if(r%2==0)return POW(x,r/2)*POW(x,r/2);
    else return POW(x,r-1)*x;
}

void dfs(int b,int j){
  	if(depth[b]==0) return;
    for(auto v:G[b]){
        if(depth[b]-depth[v]==1){
            bitM[j]=(bitM[j]|(1ll<<memo[{b,v}]));
            dfs(v,j);
        }
    }
}

signed main(){
    cin>>N;
    REP(i,N-1){
        int a,b;cin>>a>>b;a--;b--;
        G[a].pb(b);
        G[b].pb(a);
        memo[{a,b}]=i;
        memo[{b,a}]=i;
    }
    int M;cin>>M;
    bitM.resize(M);
    depth.resize(N);
    REP(i,M)bitM[i]=0;
    //制約Mに含まれる辺をビットで管理する
    REP(i,M){
        int a,b;cin>>a>>b;a--;b--;
        //AからBへの距離を求める(bfs)
      	REP(i,N)depth[i]=INF;
        queue<P>que;
        que.push({a,0});
        while(que.size()){
            P p=que.front();que.pop();
            depth[p.first]=p.second;
            if(p.first==b)break;
            for(auto v:G[p.first]){
                if(depth[v]==INF){
                    que.push({v,p.second+1});
                }
            }
        }
        //Bから逆順で戻して、使う辺をbitにいれる
        dfs(b,i);
    }
    int ans=0;
    //反する制約をbit全探索(bitが1のところの制約に反するものの個数を求める)
    for(int i=0;i<(1<<M);i++){
        int sum=0;
        int count=0;
        //辺の集合の和集合を求める+反した制約の個数を求める
        REP(j,M){
            if((i >> j) & 1){
                sum=(sum|bitM[j]);
                count=1-count;
            }
        }
        //包除原理で答えを求める
        int henc=0;
        while(sum>0){
            if(sum & 1)henc++;
            sum=(sum >> 1);
        }
        ans+=(count==0?1:-1)*POW(2,N-1-henc);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int dp[2005][2005];
int n,m,K;
const int mod=1000000007;
void chadd(int& a,int b){
  a+=b;
  if(a>=mod) a-=mod;
}
int rec(int zero,int one){
  if(zero<0 || one<0) return 0;
  if(zero+one==1) return 1;
  if(zero==0 || one==0) return 0;
  if(zero+one==K) return 1;
  int& res=dp[zero][one];
  if(~res) return res;
  res=0;

  REP(i,K){//n.o. zero
    chadd(res,rec(zero-i,one-(K-1-i)));
  }
  return res;
}
int main(){
  cin>>n>>m>>K;
  memset(dp,-1,sizeof(dp));
  int res=0;
  for(int i=n;i>0;i-=K-1) for(int j=m;j>0;j-=K-1){
    chadd(res,rec(i,j));
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 16128
#include <iostream>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i < (b); ++i)

using namespace std;
//const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  

signed main (){
    int N ,K;
    cin >> N >> K;
    int h[N];
    int dp[100100];

    REP(i,N) cin >>h[i];
    fill(dp,dp+N,INF);
    dp[0] = 0;
    REP(i,N){
        //dp[i]はi+1番目のところに行きつくまでの最短コスト
        FOR(j,1,K+1) if(i+j <= N) dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
    
   cout << dp[N-1]<<endl;
}



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
  string s,t;
  int a;
  cin>>s>>t;
  if(s[0]==t[0])a++;
  if(s[1]==t[1])a++;
  if(s[2]==t[2])a++;
  cout<<a<<endl;
  return 0;
}

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

const int END = -1;
struct StNod
{
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
     m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

enum EnDir
{
  D_Left,
  D_Right,
};

void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq)
{
  int nMaxSiz;

  cin >> nMaxSiz;
  rvnPodr.resize(nMaxSiz + 1);
  rvnIodrSeq.resize(nMaxSiz + 1);

  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    int nNode;
    cin >> nNode;
    rvnPodr[i] = nNode;
  }

  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    int nNode;
    cin >> nNode;
    rvnIodrSeq[nNode] = i;
  }
}

void fnStructTree(const vector<int> &cnrvnPodr, const vector<int> &cnrvnIodrSeq, vector<StNod> &rvoNod)
{
  int nRoot = cnrvnPodr[1];

  for (int i = 2; i < cnrvnPodr.size(); i++)
  {
    int nParnt = END;
    int nx = nRoot;
    EnDir enDir;
    while (nx != END)
    {
      nParnt = nx;
      if (cnrvnIodrSeq[ cnrvnPodr[i] ] < cnrvnIodrSeq[nx])
      {
        nx = rvoNod[nx].m_nLeft;
        enDir = D_Left;
      }
      else
      {
        nx = rvoNod[nx].m_nRigt;
        enDir = D_Right;
      }
    }

    rvoNod[ cnrvnPodr[i] ].m_nParnt = nParnt;
    if (enDir == D_Left)
      rvoNod[nParnt].m_nLeft = cnrvnPodr[i];
    else
      rvoNod[nParnt].m_nRigt = cnrvnPodr[i];
  }
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx, int &nOCnt)
{
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft, nOCnt);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt, nOCnt);
  if (nOCnt++) cout << " ";
  cout << nx;
}

void fnResult(const vector<StNod> &cnrvoNod, int &nOCnt)
{
  int nx = 1;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  fnPostOrder(cnrvoNod, nx, nOCnt);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnPodr, vnIodrSeq;
  vector<StNod> voNod;

  fnInput(vnPodr, vnIodrSeq);

  StNod oNod;
  voNod.resize(vnPodr.size(), oNod);
  fnStructTree(vnPodr, vnIodrSeq, voNod);

  int nOCnt = 0;
  fnResult(voNod, nOCnt);
  return 0;
}

Measured memory_bytes: 1200
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

// i 枚目が必要かどうか
bool is_needed(vll& a, ll target, int K) {
    swap(a.back(), a.at(target));

    vector<vector<bool>> s(a.size(), vector<bool>(K, false));
    s[0][0] = true;
    rep(i, a.size() - 1) {
        for(ll j = 0; j < K; j++)
            if (j >= a[i]) 
                s[i + 1][j] = s[i][j - a[i]] || s[i][j];
            else
                s[i + 1][j] = s[i][j];
    }

    bool ret = false;
    for (ll j = max(K - a.back(), 0LL); j <= K - 1; j++)
        if (s.back()[j]) ret = true;

    swap(a.back(), a.at(target));

    return ret;
}

void solve() {
    ini(N, K);
    vll a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());

    if (is_needed(a, 0, K))
        out(0);
    else if (!is_needed(a, a.size() - 1, K))
        out(a.size());
    else {
        ll left = 0, right = a.size() - 1;
        while (left + 1 != right) {
            ll mid = (left + right) / 2;
            if (is_needed(a, mid, K))
                right = mid;
            else
                left = mid;
        }
        out(right);
    }
}


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

passwd = ["{:03}".format(x) for x in range(1000)]
ans = 0

for p in passwd:
    p = iter(p)
    c = next(p)
    n = 0
    for t in s:
        if c == t:
            n += 1
            if n == 3:
                ans += 1
                break
            c = next(p)

print(ans)


Measured memory_bytes: 42524
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a, b = [int(_) - 1 for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = list(filter(lambda c: c[0] != pv, edge[v]))
    for ((cv, ci), color) in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)


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

int main()
{
	int a, b, d, r;
	double f, c, e;	
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	c = a;
	e = b;
	f = c / e;
	printf("%d %d %lf", d, r, f);
	return 0;
}


Measured memory_bytes: 2752
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
vec mem(20,-1);
vector<vec> G(N);
int now=0;
ll ans[N],c[N];
void dfs(int x,int p){
    for(auto u:G[x]){
        if(u!=p){
            dfs(u,x);
        }
    }
    ans[x]=c[now];
    now++;
}


main(){
    ll n=in();
    rep(i,n-1){
        int a=in(),b=in();
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i,n)c[i]=in();
    sort(c,c+n);
    dfs(1,0);
    ll sum=0;
    rep(i,n-1)sum+=c[i];
    cout<<sum<<endl;
    rep2(i,1,n)cout<<ans[i]<<" ";
}



Measured memory_bytes: 14976