akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define Need_for_speed ios_base::sync_with_stdio(0);
using namespace std;
//cout<<fixed<<setprecision()
pair<int,int>g[90001];
int main(){
	Need_for_speed;
	int n,m,d;vector<int>v;
	cin>>n>>m>>d;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int s;
			cin>>s;
			g[s].first=i;
			g[s].second=j;
		}
	}
	int z;
	cin>>z;
	int dp[90001];
	for(int i = 1; i <= n * m; i++){
		if(i - d <= 0){
			dp[i]=0;
		}
		else{
			dp[i]=dp[i-d] + abs(g[i-d].first - g[i].first) + abs(g[i-d].second - g[i].second);
		}
	} 
	for(int k = 0; k < z; k++){
		int b,x;
		cin>>b>>x;
		v.pb(dp[x] - dp[b]);
	}
	for(int c = 0; c < v.size(); c++){
		cout<<v[c]<<endl;
	}
	exit(0);
}


Measured memory_bytes: 2680
import Control.Monad.Trans.State
 
main :: IO ()
main = do
  n <- readLn
  print $ evalState (step n) (2, 1)
 
step :: Int -> State (Int, Int) Int
step 0 = fst <$> get
step 1 = snd <$> get
step n = get >>= put . lucas >> step (n - 1)
 
lucas :: (Int, Int) -> (Int, Int)
lucas (x, y) = (y, x + y)

Measured memory_bytes: 508
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static boolean isOdd(int n, int k) {
		if (2 * k > n) {
			k = n - k;
		}
		if (k == 0) {
			return true;
		}
		int m = n - Integer.highestOneBit(n);
		return k <= m && isOdd(m, k);
	}

	static void solve() throws Exception {
		int n = scanInt();
		int a[] = new int[n];
		String s = scanString();
		boolean haveOne = false;
		for (int i = 0; i < n; i++) {
			a[i] = s.charAt(i) - '1';
			if (a[i] == 1) {
				haveOne = true;
			}
		}
		if (!haveOne) {
			for (int i = 0; i < n; i++) {
				a[i] >>= 1;
			}
		}
		boolean odd = false;
		for (int i = 0; i < n; i++) {
			if (a[i] == 1 && isOdd(n - 1, i)) {
				odd = !odd;
			}
		}
		out.print(odd ? haveOne ? 1 : 2 : 0);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 34296
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include<sstream>

using namespace std;
#define ll long long
#define mod 1000000007


int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);

    if (x > d) {
        ll t = x / d;
        if (t >= k) {
            cout << x - k * d << "\n";
            return 0;
        } else {
            x = x - t * d;
            k -= t;
        }
    }

    if (k % 2) {
        cout << d - x << "\n";
    } else {
        cout << x << "\n";
    }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop") 
#define all(a) a.begin(),a.end()
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
double dp[3000][3000];
double maxval(double ar[],ll i,ll n,ll h,ll t){
	//ll t=i-h;
	if(i==n){
		if(h>t) return 1.0;
		else return 0.0;
	}

	//cout<<i<<" "<<h<<" "<<dp[i][h]<<endl;
	if(dp[i][h]!=100.0){
		return dp[i][h];
	}

	double a=0.0,b=0.0;
	a=ar[i]*maxval(ar,i+1,n,h+1,t);
	b=(1.0-ar[i])*maxval(ar,i+1,n,h,t+1);

	dp[i][h]=(a+b);
	return dp[i][h];
}
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	
	for(i=0;i<3000;i++){
		for(j=0;j<3000;j++){
			dp[i][j]=100.0;
		}
	}

	double ar[n];
	for(i=0;i<n;i++){
		cin>>ar[i];
	}
	
	double an=maxval(ar,0,n,0,0);
	cout<<setprecision(10)<<an;
	return 0;
}
//ctrl H replace

Measured memory_bytes: 71040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair



int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int x, y, t;
	x = y = t = 0;
	int n;
	scanf("%d", &n);
	while(n--) {
		int nx, ny, nt;
		scanf("%d%d%d", &nt, &nx, &ny);
		x = abs(x - nx);
		y = abs(y - ny);
		t = nt - t;
		if ((x + y + t) & 1) {
			printf("No\n");
			return 0;
		}
		if (x + y > t) {
			printf("No\n");
			return 0;
		}
		x = nx;
		y = ny;
		t = nt;
	}
	printf("Yes\n");

	return 0;
}


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

const long  double pi = 3.14159265358979297;
//3. 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6

int main()
{
    //std::cout << std::numeric_limits< long double>::digits10 << std::endl;
	long  double  r ;
	cin>>r;
	long  double  a = ((long double)2.000000000000000*pi*r);
	cout<<fixed<<setprecision(20)<<a<<endl;
}

// op : 458.67252742410979493570
// res :458.67252742410977361942

Measured memory_bytes: 3792
nums = list(map(int, input().split()))
R, G, B, N = nums[0], nums[1], nums[2], nums[3]

cnt = 0
for i in range(N // R + 1):
    rem = N - i*R
    for j in range(rem // G + 1):
        rem = N - i*R - j*G
        if rem % B == 0:
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
using static System.Console;

namespace dwyl.ABC._112
{
    public class Program
    {

        public void Solve()
        {
            var age = int.Parse(ReadLine());
            if (age == 1)
            {
                WriteLine("Hello World");
            }
            else
            {
                var a = int.Parse(ReadLine());
                var b = int.Parse(ReadLine());
                WriteLine(a + b);
            }
        }
        static void Main()
        {
            var solver = new Program();
            solver.Solve();
        }

    }
}


Measured memory_bytes: 11220
import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ref = sum(p[:k])
    ans = ref

    for i in range(1, n - k + 1):
        ref = ref - p[i - 1] + p[i + k - 1]
        if ref > ans:
            ans = ref

    print(ans/2 + k*0.5)

main()

Measured memory_bytes: 24404
N = int(input())
T,A = map(int,input().split())
now = 10000000
ans = 0
H = list(map(int,input().split()))
for i in range(N):
    tmp = T - H[i]*0.006
    if abs(A - tmp) < now:
        now = abs(A - tmp)
        ans = i+1
print(ans)

Measured memory_bytes: 9252
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
    string a,b,c,d,e,f;
    cin>>a>>b>>c;

    d=+a[0];
    e=+b[1];
    f=+c[2];

    cout<<d<<e<<f<<endl;


}


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

int main() {
  
  int a,b ; cin >> a >> b ; 
  //vector<int> vec(n); for ( int i = 0 ; i < n ; i++ ) cin >> vec[i] ; 
  int ans = 0 ;
  for (int i = 0 ; i < 50 ; i++ ){
      if ((a-1)*i +1 >= b) {ans = i ; 
      break ;}

  }
  cout << ans  << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int n, k;
    int a[100500];
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 2e9;
    for(int i = k; i <= n; i++){
        ans = min(a[i - 1] - a[i - k], ans);
    }
    cout << ans;
}


int main(){
    int q = 1;
    //cin >> q;
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 20:56:48 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

X = int(input())

for i in range(-500,501):
    for j in range(-500,501):
        if pow(i,5) - pow(j,5) == X:
            print(i,j)
            sys.exit()



Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    string d[8] = { "", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" };
    string s; cin >> s;
    loop(i, 8)
        if (d[i] == s)
            cout << i;

}

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


Measured memory_bytes: 3628
import sys

input = sys.stdin.readline


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

    count = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
    for _ in range(N):
        S = input().rstrip()
        count[S] += 1

    print(f"AC x {count['AC']}")
    print(f"WA x {count['WA']}")
    print(f"TLE x {count['TLE']}")
    print(f"RE x {count['RE']}")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

/* MACROS SAMPAH */
#define Jehian using
#define Norman namespace
#define Saviero std
#define cepet {ios_base::sync_with_stdio(0);cin.tie(0);}

Jehian Norman Saviero;

/* MACROS FOR TYPE */
typedef long l;
typedef long double ld;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

/* MACROS FOR PRINT */
#define nl printf("\n")
#define sp printf(" ")

/* MACROS FOR FUNCTION AND METHOD */
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define eb emplace_back
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for(int _je = sizeof(x)/sizeof(x[0]); _je--;) x[_je] = y
#define SQR(x) (x)*(x)
#define CUBE(x) SQR(x)*(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)

/* MACROS FOR ATTRIBUTE */
#define fi first
#define se second

/* MACROS FOR SCAN */
#define scc(x) scanf("%c", &x)
#define scd(x) scanf("%Lf", &x)
#define scf(x) scanf("%f", &x)
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scld(x) scanf("%Lf", &x)
#define scui(x) sci(x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main(){
	ll N;
	scll(N);
	vll data[2];
	for (ll i = 0; i < 2; ++i){
		ll tmp;
		for (ll j = 0; j < N; ++j){
			scll(tmp);
			data[i].pb(tmp);
		}
	}
	ll par[2];
	RESET(par);
	for (ll i = 0; i < N; ++i){
		if (data[0][i] > data[1][i]){
			par[1] += data[0][i]-data[1][i];
		} else {
			par[0] += (data[1][i]-data[0][i])/2;
		}
	}
	if (par[1] > par[0]){
		puts("No");
	} else {
		puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 512
import numpy as np
import sys

input = sys.stdin.readline

A,B,C ,K= map(int,input().split())


if K%2 == 1 and abs(B-A) < 1000000000000000000:
    print(B-A)
elif  K%2 == 0 and abs(A-B) < 1000000000000000000:
    print(A-B)
else:
    print("Unfair")



Measured memory_bytes: 21644
IDENTIFICATION DIVISION.
PROGRAM-ID. 170D.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(1600000).
*>
WORKING-STORAGE SECTION.
01 N          PIC  9(06).
01 P1         PIC  9(07) COMP.
01 P2         PIC  9(07) COMP.
01 I          PIC  9(06) COMP.
01 J          PIC  9(06) COMP.
01 IDX        PIC  9(07) COMP.
01 TBL1.
   03 A       PIC  9(07) COMP OCCURS 200000 DEPENDING ON N.
01 TBL2.
   03 TBL-M   OCCURS 1000000.
      05 B    PIC  9(07) COMP.
      05 C    PIC  9(01) COMP.
01 CNT        PIC  9(06).
01 OUT        PIC  Z(05)9.
*> 
PROCEDURE DIVISION.                          
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
*>MOVE ZERO TO TBL1 TBL2.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO A(I) IDX
    ADD  1               TO B(IDX)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  SORT A ASCENDING KEY A.
  MOVE 0 TO CNT.           
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (C(A(I)) = 0)
      IF (B(A(I)) > 1)
        MOVE 1 TO C(A(I))
      END-IF
*>
      PERFORM VARYING J FROM 2 BY 1 UNTIL A(I) * J >  A(N)
        MOVE 1 TO C(A(I) * J)
      END-PERFORM
    END-IF
  END-PERFORM.
*>
  MOVE 0 TO CNT.           
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    IF (C(A(I)) = 0)
      ADD 1 TO CNT
    END-IF
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 11612
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main() {
  vector<ll> A(50001,-1);
  FOR(i,50001){
    ll yen=i*1.08;
    if(yen<=50000){
      A[yen]=i;
    }
  }
  ll N;
  cin>>N;
  if(A[N]==-1){
    cout<<":("<<endl;
  }else{
    cout<<A[N]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	string ans = "";
	cin >> N;

	vector<string> S(N);
	int A[27][50];

	for (int i = 0;i < 27;i++)
		for (int j = 0;j < 50;j++)
			A[i][j] = 0;

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

		for (int j = 0;j < S[i].size();j++)
		{
			int p = S[i][j] - 'a';
			A[p][i]++;
		}
	}

	for (int i = 0;i < 27;i++)
	{
		bool flag = true;
		int Min = 100;
		for (int j = 0;j < N;j++)
		{
			if (A[i][j] > 0)
			{
				Min = min(A[i][j], Min);
			}
			else
				flag = false;
		}


		if (flag)
		{
			for (int j = 0;j < Min;j++)
				ans.push_back((char)(i + 'a'));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#include <cmath>
using namespace std;
int main(){
  int n,x,t;
  cin >>n>>x>>t;
  int ans;
  if(n%x ==0){
    ans= (n/x)*t;
  }
  else{
    ans= (n/x)*t+t;
  }
  cout << ans<<endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
  		int[] h=new int[n];
		for(int c=0;c<n;c++){
    		h[c]=sc.nextInt();
    	}
    	
  		int c=0;
  		int ans=0;
  		for(int d=0;d<n-1;d++){
        	if(h[d]>=h[d+1]){
              c++;
            }else{
              if(ans<c){
               ans=c;
              }
             c=0;
            }
        }
		if(ans<c){
         ans=c;
        }
    	System.out.println(ans);
    }
}



Measured memory_bytes: 50636
n, k, q = gets.split(" ").map(&:to_i)
q_ls = Array.new
score_ls = Array.new(n, 0)


q.times do |i|
  i = gets.chomp!.to_i
  q_ls << i
end

#puts score_ls

q_ls.each do |s|

  score_ls[s-1] += 1
end

for i in 0..n-1 do
  f = k - (q - score_ls[i])
  if f <= 0
    print("No\n")
  else
    print("Yes\n")
  end
end

Measured memory_bytes: 4148
def eachdigitsum(n):
	x = len(str(n))
	sum = 0
	for i in range(x):
		t = n//10**(x-i-1)
		n = n - t*10**(x-i-1)
		sum += t
	return sum

n = int(input())
if n%eachdigitsum(n) == 0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3060
K, N = map(int,input().split())
#print(K)
l = list(map(int, input().split()))
#print(l)
ans = l[-1] - l[0]
#print(ans)
for i in range(N-1):
  tempo_ans = l[i]+K -l[i+1]
  #print(tempo_ans)
  if ans > tempo_ans:
    ans = tempo_ans
print(ans)

Measured memory_bytes: 26420
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;


int main(){

    vector<string>n;
    string s,ans = "zzzzzzzzzzz";
    int k,a = 0;
    cin >> s >> k;
    
    for(int i = 0;i < s.size();i++){
    	for(int j = 1;j <= k;j++){
    	    n.resize(a+1);
    	    n.at(a) = s.substr(i,j);
    	    a++;
    	}    	    
    }
	
    sort(n.begin(),n.end());
    
    int x = 0;
    
    for(int i = 0;i < k;i++){
    	while(ans == n.at(x)){
    	   x++;	
    	}    	
    	ans = n.at(x);
    }
    
    cout << ans << endl;
	
	return 0;

}


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

bool cmp(int x,int y)
{
	return x<y;
}

int n,a[200005];
long long ans;
int main()
{
	scanf("%d",&n);
	for (int i=1 ; i<=n ; i++)
	    scanf("%d",&a[i]);
	
	sort(a+1,a+n+1,cmp);
	
	for (int i=1 ; i<n ; i++)
	{
		ans+=a[n-i/2];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2496
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

s = gc
t = gc

s.sort!
t.sort!.reverse!
a = [s.join,t.join];

a.sort!
puts a[0] == s.join  && s.join != t.join ? 'Yes' : 'No'


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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1

//x coordinate
//k moves
//d gap (x-d, x+d)

//      0  x-a*d  x-3*d  x-2*d   x-d   x 
void testCase() {
    ll x, k, d;
    cin >> x >> k >> d;
    // move until we reach nearest to 0.
    // 0   point
    ll ans = 0;
    //[x1  0  x2]
    if (x >= 0)
        d = -d;
    if (!(k&1))
        ans = abs (x);
    else
        ans = abs (x+d);
    // x - al*d >= 0
    // x >= al*d
    //al <= x / d

    // -x + al*d >= 0
    // al*d >= x
    // al >= x / d

    ll moves = min (k, abs(x)/abs(d));
    ll des = x + moves*d;
    ll rem = k - moves;
    if (!(rem&1))
        ans = min (ans, abs(des));
    ll temp = min (rem, 100ll);
    ll cnt = rem;
    x = des;
    while (temp--) {
        cnt--;
        x += d;
        if (!(cnt&1))
            ans = min (ans, abs(x));
    }
    temp = min (moves, 100ll);
    cnt = rem;
    x = des;
    while (temp--) {
        cnt++;
        x -= d;
        if (!(cnt&1))
            ans = min (ans, abs(x));
    }
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;

bool topo_sort(const Graph& G, VI& order){
  int N = G.size();
  VI color(N, 0);
  
  function<bool(int)> visit = [&](int v)->bool{
	color[v] = 1;
	for(const auto& e: G[v]){
	  if(color[e.to] == 2) continue;
	  if(color[e.to] == 1) return false;
	  if(!visit(e.to)) return false;
	}
	order.push_back(v);
	color[v] = 2;
	return true;
  };

  for(int u=0;u<N;++u)
	if(!color[u] && !visit(u))
	  return false;
  reverse(begin(order), end(order));
  return true;
}

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

  int V, E;
  cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int s, t;
	cin >> s >> t;
	G[s].emplace_back(t);
  }
  VI dump(V);
  cout << (topo_sort(G, dump)? 0: 1) << endl;

  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int digit(int n){
	int sum=0;

	while(n>0){
		sum += n % 10;
		n /= 10;
	}

	return sum;
}

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

	int sum=0;
	sum = digit(n);
	if(n % sum == 0) cout<< "Yes" <<endl;
	else cout<< "No" <<endl;
	
	return 0;
}

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

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for(int i=0; i<N; i++){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int m = h.at(h.size()-1);
    for(int i=0; i<N-K+1; i++){
        if(m>h.at(i+K-1)-h.at(i)){
            m = h.at(i+K-1)-h.at(i);
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	int z;
	cin >> z;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a') cout << 'b' << endl;
  if (c == 'b') cout << 'c' << endl;
  if (c == 'c') cout << 'd' << endl;
  if (c == 'd') cout << 'e' << endl;
  if (c == 'e') cout << 'f' << endl;
  if (c == 'f') cout << 'g' << endl;
  if (c == 'g') cout << 'h' << endl;
  if (c == 'h') cout << 'i' << endl;
  if (c == 'i') cout << 'j' << endl;
  if (c == 'j') cout << 'k' << endl;
  if (c == 'k') cout << 'l' << endl;
  if (c == 'l') cout << 'm' << endl;
  if (c == 'm') cout << 'n' << endl;
  if (c == 'n') cout << 'o' << endl;
  if (c == 'o') cout << 'p' << endl;
  if (c == 'p') cout << 'q' << endl;
  if (c == 'q') cout << 'r' << endl;
  if (c == 'r') cout << 's' << endl;
  if (c == 's') cout << 't' << endl;
  if (c == 't') cout << 'u' << endl;
  if (c == 'u') cout << 'v' << endl;
  if (c == 'v') cout << 'w' << endl;
  if (c == 'w') cout << 'x' << endl;
  if (c == 'x') cout << 'y' << endl;
  if (c == 'y') cout << 'z' << endl;
}
  
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main()
{
	int S,W;
	cin >> S >> W;
	if(W >= S)
		cout << "unsafe";
	else
		cout << "safe";

	return 0;	
}


Measured memory_bytes: 3640
n = int(input())
la = list(map(int, input().split()))

ct0 = 0
ctm = 0
minm = 100000000000000000
ans = 0

for i in range(n):
	if la[i] == 0:
		ct0 += 1
	elif la[i] < 0:
		ctm += 1
	
	m = abs(la[i])
	if m < minm:
		minm = m
	ans += m

if ct0 > 0 or ctm % 2 == 0:
	print(ans)
else:
	ans -= 2 * minm
	print(ans)

Measured memory_bytes: 14252
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)

a.each { |i| h[i] += 1 }
side = h.select { |k, v| v >= 2 }.sort_by { |k, v| -k }

if side.size == 0 || (side.size == 1 && side[0][1] != 4)
  puts 0
else
  puts side[0][1] >= 4 ? side[0][0]**2 : side[0][0] * side[1][0]
end


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

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a[100];
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    int curmax=-1;
    int ans=0;
    for(int i=0;i<n;++i){
        if(a[i]>=curmax){
            ++ans;
            curmax=a[i];
        }
    }
    cout<<ans<<endl;
}



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

int main(void){
  int a, b;
  cin >> a >> b;
  string str;
  cin >> str;
  bool is_wrong = false;
  for(int i = 0; i < a+b+1; i++){
    if (i != a){
      	int num = (int)str[i]-(int)'0';
    	if (num <10 && num >= 0);
      	else	is_wrong = true;
    }
    else{
      if (str[i] != '-')
        	is_wrong = true;
    }
  }
  if (is_wrong){
    cout << "No\n";
  }
  else{
    cout <<"Yes\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <deque>
#include <algorithm>
#include <time.h>

using namespace std;
long long n,h,m,x,y,cnt;
int main()
{
	scanf("%lld%lld%lld",&n,&h,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		if(x>=h&&y>=m)
		{
			cnt++;
		}
	}
	printf("%lld",cnt);
	return 0;
}

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 14.08.2020 12:51:05
**/

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

int main() {

    int k,t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i,t) cin >> a.at(i);
    sort(a.begin(),a.end(),greater<>());

    int ans=0;
    if(a.at(0)>(k+1)/2) ans+=2*(a.at(0)-(k+1)/2)-(k+1)%2; 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main (void)

{
	int a,b; 
	scanf("%d",&a);
	scanf("%d",&b);
	if(a>b)
	{
		printf("a > b\n",a,b);
	}
	else
	{  
		if(a==b)
		{
			printf("a == b\n");
		}
		else
		{
			printf("a < b\n");
		}
	}
	return 0;
}

Measured memory_bytes: 580
n = int(input())
point = [0] * n
total_b = 0
for i in range(n):
    a, b = map(int, input().split())
    point[i] = a + b
    total_b += b

point.sort(reverse = True)

sum_t = 0
for i in range(n):
    if i % 2 == 0:
        sum_t += point[i]

print(sum_t - total_b)


Measured memory_bytes: 13216
using System;

class Program
{
    static void Main()
    {

        while(true)
        {
            string[] s = Console.ReadLine().Split(' ');
            int m = int.Parse(s[0]);
            int f = int.Parse(s[1]);
            int r = int.Parse(s[2]);
            if (m < 0 && f < 0 && r < 0)
                break;
            if(m==-1||f==-1)
                Console.WriteLine("F");
            else if(m+f>=80)
                Console.WriteLine("A");
            else if(m+f>=65&&m+f<80)
                Console.WriteLine("B");
            else if(m+f>=50&&m+f<65)
                Console.WriteLine("C");
            else if (m + f >= 30 && m + f < 50)
            {
                if(r>=50)
                    Console.WriteLine("C");
                else
                    Console.WriteLine("D");
            }
            else if(m+f<=30)
                Console.WriteLine("F");
        }
    }
}

Measured memory_bytes: 8948
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int r;

  cin >> r;

  cout << 2 * M_PI * r << endl;
  
  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <iomanip>
#define ll long long
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	
	int n;
	cin >> n;

	long double x,total=0;
	while(n--){
		cin >> x;

		total+=1/x;
	}	

	cout << fixed << setprecision(14) << 1/total << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
d=[0]*151
t=[0]*151
p=2**150
x=0
y=1
ans=0
for i,j in enumerate(bin(k)[::-1]):
  if j=="b": break
  if j=="1": d[i]=1

for i in a:
  for j,k in enumerate(bin(i)[::-1]):
    if k=="b": break
    if k=="1": t[j]+=1
for i in range(150,-1,-1):
  if d[i]==1 and t[i]>n//2-(n+1)%2:
    y=0
  elif d[i]==1 and t[i]<=n//2:
    x+=p
  elif y==0 and t[i]<=n//2:
    x+=p
  p//=2
for i in a:
  ans+=x^i
print(ans)


Measured memory_bytes: 15144
import java.util.*;

class Main{
    static int[] sum;
    static int[] temp;
    static int[] A;
    static long tot1; // record the number of (i,j) s.t. sum[i]>sum[j]
    static long tot2;
    static int N;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        sum = new int[N+1];
        temp = new int[N+1];
        tot2 = ((long)N)*((long)N+1)/2;
        A = new int[N+1];
        for(int i=1;i<=N;i++) A[i]=sc.nextInt();
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for(int i=1;i<=N;i++){
            max = Math.max(max,A[i]);
            min = Math.min(min,A[i]);
        }
        int hi = max,lo=min;
        while(hi>lo+1){
            int mid = (hi+lo)/2;
            if(check(mid)) lo = mid;
            else hi=mid-1;
        }
        int ans = check(hi)?hi:lo;
        System.out.println(ans);


    }
    static boolean check(int mid){
        tot1=0;
        for(int i=1;i<=N;i++) sum[i]=(A[i]>=mid?1:-1);
        for(int i=1;i<=N;i++) sum[i] += sum[i-1];
        Merge(0,N);
        return (tot2-tot1)>=tot2/2;
    }


    static void Merge(int left, int right){
        if(left==right) return;
        int mid = (left+right)/2;
        Merge(left,mid);
        Merge(mid+1,right);
        int p = left,q=mid+1,r=left;
        while(p<=mid&&q<=right){
            if(sum[p]<=sum[q]) temp[r++]=sum[p++];
            else{
                tot1 += mid-p+1;
                temp[r++]=sum[q++];
            }
        }
        while(p<=mid) temp[r++]=sum[p++];
        while(q<=right) temp[r++]=sum[q++];
        for(int i=left;i<=right;i++) sum[i]=temp[i];
    }
}


Measured memory_bytes: 64672
import java.util.Scanner;

public class Main {

    static long H;
    static long W;

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

        H = sc.nextLong();
        W = sc.nextLong();

        // 縦方向か横方向に一つ目を分割し、
        // 二つ目三つ目を縦か横に分割する
        System.out.println(divide());
    }

    private static long divide() {

        if (H % 3 == 0 || W % 3 == 0) {

            return 0;

        } else {

            long hDividedDiff = calcDiff(H, W);
            long wDividedDiff = calcDiff(W, H);

            return Math.min(hDividedDiff, wDividedDiff);
        }

    }

    private static long calcDiff(long divlen1, long divlen2) {

        long diff = divlen1 * divlen2;

        for (int i = 1; i < divlen1; i++) {
            long s1 = i * divlen2;

            // 一つ目
            long s2 = (int)((divlen1 - i) / 2) * divlen2;
            long s3 = divlen1 * divlen2 - s1 - s2;

            diff = minDiff(s1, s2, s3, diff);

            // 二つ目
            s2 = (divlen1 - i) * (int)(divlen2 / 2);
            s3 = divlen1 * divlen2 - s1 - s2;

            diff = minDiff(s1, s2, s3, diff);
        }

        return diff;
    }

    private static long minNum(long a, long b, long c) {
        return Math.min(Math.min(a, b), c);
    }

    private static long maxNum(long a, long b, long c) {
        return Math.max(Math.max(a, b), c);
    }

    private static long minDiff(long s1, long s2, long s3, long minDiff) {
    
        long diff = maxNum(s1, s2, s3) - minNum(s1, s2, s3); 

        if (minDiff > diff) {
            minDiff = diff;
        }

        return minDiff;
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, h, d;
        cin >> w >> h >> d;
        if(w == 0)
            return 0;

        vector<vector<bool> > light(h, vector<bool>(w));
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                int a;
                cin >> a;
                light[i][j] = (a == 1);
            }
        }

        vector<bitset<626> > bs(h*w);
        for(int y0=0; y0<h; ++y0){
            for(int x0=0; x0<w; ++x0){
                int i = y0 * w + x0;
                bs[i][i] = true;
                bs[i][h*w] = light[y0][x0];

                int sy[] = {0, 1, 0, -1};
                int sx[] = {1, 0, -1, 0};
                int dy[] = {1, -1, -1, 1};
                int dx[] = {-1, -1, 1, 1};
                for(int j=0; j<4; ++j){
                    int y = y0 + sy[j] * d;
                    int x = x0 + sx[j] * d;
                    for(int k=0; k<d; ++k){
                        if(0 <= y && y < h && 0 <= x && x < w)
                            bs[i][y*w+x] = true;
                        y += dy[j];
                        x += dx[j];
                    }
                }
            }
        }

        int i = 0;
        int j = 0;
        for(;;){
            while(j < h*w){
                int k = i;
                while(k < h*w && !bs[k][j])
                    ++ k;
                if(k < h*w){
                    swap(bs[i], bs[k]);
                    break;
                }
                ++ j;
            }
            if(j == h*w)
                break;

            for(int k=i+1; k<h*w; ++k){
                if(bs[k][j])
                    bs[k] ^= bs[i];
            }
            ++ i;
            ++ j;
        }

        bool ok = true;
        for(int k=i; k<h*w; ++k){
            if(bs[k][h*w])
                ok = false;
        }

        if(ok)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}

Measured memory_bytes: 960
#include <iostream>
using namespace std;
int n,d[200],p;
char c[200];
string s;
int f(void){
    if('0'<=c[p]&&c[p]<='9')return c[p++]-'0';
    int k=p++,tmp=0;
    if(c[k]=='*')tmp=1;
    while(d[p]==d[k]+1){
        if(c[k]=='*')tmp*=f();
        else tmp+=f();
    }
    //cout<<tmp<<endl;
    return tmp;
}
int main(void){
    while(1){
    cin>>n;
    if(!n)return 0;
    for(int i=0;i<200;i++){d[i]=0;}
    for(int i=0;i<n;i++){
        cin>>s;
        d[i]=s.size();
        c[i]=s[s.size()-1];
    }
    p=0;
    cout<<f()<<endl;
    }
}



Measured memory_bytes: 2984
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,l;
    char str[4];
    l = 0;
    scanf("%s",str);
    j = 0;
    for(i = 0;i <= 3;i++){
        if(str[i] == 'R'){
            l++;
        }
        if(l > j){
            j=l;
        }
        if(str[i] == 'S'){
            l = 0;
        }
    }
    printf("%d\n",j);
    return 0;
}


Measured memory_bytes: 3756
N=int(input())
point=list()
for i in range(N):
    point.append([int(i) for i in input().split()])
#print(point)

list_a=sorted(point,key=lambda x:x[0]+x[1])
list_b=sorted(point,key=lambda x:x[1]-x[0])

ps=[list_a[0],list_a[N-1],list_b[0],list_b[N-1]]
#print(ps)
ans=0

for p1 in ps:
    for p2 in ps:
        ans=max(ans,abs(p1[0]-p2[0])+abs(p1[1]-p2[1]))

print (ans)

Measured memory_bytes: 54924
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

void rectangle(int h, int w) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cout << '#';
    }
    cout << '\n';
  }
}

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

  while (1) {
    int h, w; cin >> h >> w;
    if (h == 0 && w == 0) {
      break;
    }
    rectangle(h, w);
    cout << '\n';
  }

  return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll M, N;
    cin >> N >> M;
    vector<ll> A(N), B(N), C(M), D(M), ans;

    repi(i, N, 0)
    {
        cin >> A[i] >> B[i];
    }
    repi(i, M, 0)
    {
        cin >> C[i] >> D[i];
    }

    repi(i, N, 0)
    {
        ll sum = INF;
        ll cp = -1;
        repi(j, M, 0)
        {
            ll s = abs(A.at(i) - C.at(j)) + abs(B.at(i) - D.at(j));
            if(s < sum){
                sum = s;
                cp = j + 1;
            }
        }
        ans.push_back(cp);
    }

    for(auto a:ans){
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import bisect
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = LI()
B = LI()

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

cumB = [0]
for b in B:
  cumB.append(cumB[-1]+b)

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = bisect.bisect_right(cumB, rem)-1

  res = max(res, i+deskb)

print(res)

Measured memory_bytes: 127220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
#define forn(i,n) for(int i=0; i < int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fst first
#define snd second

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vll xs(n);
    forn(i, n) cin >> xs[i];
    ll best = 1ll << 60;
    for (int j = 0; j+k <= n; j++) {
        ll lo = xs[j], hi = xs[j+k-1];
        ll ans = llabs(lo)+llabs(hi)+min(llabs(lo), llabs(hi));
        if (lo >= 0) ans = min(ans, hi);
        if (hi <= 0) ans = min(ans, -lo);
        best = min(best, ans);
    }
    cout << best << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  int a,z,ans;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      a=i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s.at(i)=='Z'){
      z=i;
      break;
    }
  }
  ans=z-a+1;
  printf("%d",ans);
}

Measured memory_bytes: 640
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                count +=1
print(count)

Measured memory_bytes: 3064
'''
@sksshivam007 - Template 1.0
'''
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))

INF = float('inf')
mod = 10 ** 9 + 7

n, k = MAP()

a = [0]*(k+1)

for i in range(k, 0, -1):
    temp = pow((k//i), n, mod)
    ans = temp%mod
    for j in range(2, k//i + 1):
        ans -= a[j*i]%mod
    a[i] = ans%mod
final = 0
for i in range(len(a)):
    final+=(a[i]*i)%mod

print(final%mod)

Measured memory_bytes: 70628
n = int(input())
a = [i for i in input().split()]

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)


Measured memory_bytes: 20592
#include<stdio.h>

int MatOrder(int *, int);
int m[101][101];

int main(){
 
  int n, i;
  int p[101];
   
  scanf("%d", &n);
   
  for(i = 0;i < n;i++){
    scanf("%d%d", &p[i], &p[i+1]);
  }
   
  printf("%d\n", MatOrder(p, n));
  return 0;
}
 
 
int MatOrder(int *p, int n){
  int i, j, k, l, q;
   
  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }
   
  for(l = 2; l <= n;l++){
    for(i = 1; i <= n-l+1;i++){
      j = i + l - 1;
 
      m[i][j] = 20000000;
 
      for(k = i;k <= j - 1;k++){
    q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
    m[i][j] = ((m[i][j] <= q) ? m[i][j] : q);
      }
 
    }
  }
 
  return m[1][n];
}

Measured memory_bytes: 636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC051_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(',');

            foreach (string i in s)
            {
                Console.Write(i + " ");
            }
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092