akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#define N 2000005

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll fac[N], rev[N];
ll fexp(ll x, ll y) {
  ll ans = 1;
  while (y) {
    if (y & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ans;
}
ll C(ll n, ll k) {
  ll ans = fac[n] * rev[k] % MOD;
  ans = ans * rev[n - k] % MOD;
  return ans;
}
int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  fac[0] = 1;
  rev[0] = 1;
  for (int i = 1; i <= n + k; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    rev[i] = fexp(fac[i], MOD - 2);
  }
  ll tot = fexp(26, n + k);
  ll bad = 0;
  for (int i = 0; i < n; ++i) {
    bad = (bad + fexp(25, n + k - i) * C(n + k, i) % MOD) % MOD;
  }
  tot = (tot - bad + MOD) % MOD;
  cout << tot;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

#define mod 1000000007

ll powmod(ll a, ll b, ll p){ // a^b(mod p)
  if(b == 0) return 1;
  if(b%2 == 0){
    ll d = powmod(a,b/2,p);
    return (d*d)%p;
  }else return (a*powmod(a,b-1,p))%p;
}

main(){
  ll h,w,a,b; cin >> h >> w >> a >> b;
  vector<ll> fact(h+w-1),factinv(h+w-1);

  fact[0] = 1;
  factinv[0] = powmod(fact[0],mod-2,mod);
  for(ll i = 1; i < h + w - 1; i++){
    fact[i] = (fact[i-1] * i) % mod;
    factinv[i] = powmod(fact[i],mod-2,mod);
  }

  ll ans = 0;

  for(ll i = b; i < w; i++){
    ans += (((((((((fact[h-a-1+i] * factinv[h-a-1]) % mod) * factinv[i]) % mod) * fact[a-1+w-1-i]) % mod ) * factinv[a-1]) % mod) * factinv[w-1-i]) % mod;
    ans %= mod;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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


const int MAX = 1000000;
bool is_prime[MAX + 10];

int memo[MAX + 10];
int key(int n)
{
	if (is_prime[n])
		return n;
	else if (~memo[n])
		return memo[n];

	int sum = 0, last;
	for (int i = 2; i <= n; ++i)
	{
		if (is_prime[i] && n % i == 0)
		{
			sum += i, last = i;
			while (n % i == 0)
				n /= i;
		}
	}
	return memo[n] = 2*last - sum;
}
int main()
{
	fill_n(is_prime, MAX, true);
	for (int i = 2; i*i <= MAX; ++i)
		if (is_prime[i])
			for (int j = 2*i; j <= MAX; j += i)
				is_prime[j] = false;

	fill_n(memo, MAX, -1);
	int a, b;
	while (scanf("%d%d", &a, &b), a | b)
		puts(key(a) > key(b) ? "a" : "b");
}

Measured memory_bytes: 5724
#include <stdio.h>
#include <cstring>
#include <array>

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

constexpr int N = 1e5;
std::array<short, N+1> vS, vT;
constexpr short K = 'A' - 1;

int main(void){
    int i = 0;char c;
    vS[0] = 0; while((c = getchar()) != '\n'){ vS[i+1] = (vS[i] + c - K) % 3; i++;}
    i = 0;
    vT[0] = 0; while((c = getchar()) != '\n'){ vT[i+1] = (vT[i] + c - K) % 3; i++;}
    int q; scanf("%d", &q);
    while(q--){
        int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); a--; c--;
        short sss = (vS[b] - vS[a] + 3) % 3;
        short ttt = (vT[d] - vT[c] + 3) % 3;
        puts(sss == ttt ? "YES" : "NO");
    }
    return 0;
}

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

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

using namespace std;

int main(){
  int a,b,x;
  cin>>a>>b>>x;
  
  if(x<a || x>b+a){
    cout<<"NO";
  }else{
    cout<<"YES";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int
int main(void)
{
 ll i,j,k,t,n;
 cin>>n;
 ll a[n+1][3];
 ll dp[n+1][3];
 for(i=1;i<=n;i++)
    {
     cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
 dp[1][0]=a[1][0];
 dp[1][1]=a[1][1];
 dp[1][2]=a[1][2];
 for(i=2;i<=n;i++)
    {
     dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
     dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
     dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
 ll x=max(dp[n][0],dp[n][1]);
 cout<<max(x,dp[n][2])<<endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var pq=new Pq<Mo<int>>(100000,true);
		bool[] b=new bool[100000];
		pq.Push(new Mo<int>(1,1));
		b[1]=true;
		while(pq.Top.d!=0){
			int p=pq.Top.n,q=pq.Top.d;
			pq.Pop();
			b[q]=true;
			if(!b[(q*10)%n]){pq.Push(new Mo<int>(p,(q*10)%n));}
			if(!b[(q+1)%n]){pq.Push(new Mo<int>(p+1,(q+1)%n));}
		}
		Console.WriteLine("{0}",pq.Top.n);
	}
}
public class Mo<T>:IComparable{
	public int n;
	public T d;
	public Mo(int n,T d){this.n=n;this.d=d;}
	public int CompareTo(object obj){
		Mo<T> mymo=(Mo<T>)obj;
		if(mymo.n>n){return -1;}
		else if(mymo.n<n){return 1;}
		else{return 0;}
	}
}
public class Pq<T> where T:IComparable{
	private T[] he;
	public int cnt=0;
	private Func<T,T,int> compare;
	public Pq(int max,bool mm){
		he=new T[max];
		if(mm){compare=Ao;}
		else{compare=Do;}
	}
	public void Push(T x){
		int j=cnt;
		while(j!=0&&compare(x,he[(j-1)/2])>0){he[j]=he[(j-1)/2];j=(j-1)/2;}
		he[j]=x;
		cnt++;
	}
	public void Pop(){
		cnt--;
		T r=he[cnt];
		int j=0;
		while(true){
			if(j*2+1<cnt){
				if(compare(he[j*2+1],he[j*2+2])>0){j=j*2+1;}
				else{j=j*2+2;}
			}
			else if(j*2<cnt){j=j*2+1;}
			else{break;}
			if(compare(he[j],r)<=0){j=(j-1)/2;break;}
			he[(j-1)/2]=he[j];
		}
		he[j]=r;
	}
	private int Ao(T x,T y){return y.CompareTo(x);}
	private int Do(T x,T y){return x.CompareTo(y);}
	public T Top{get{return he[0];}}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 20704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

int a, b;
string s;

int main() {
#ifdef LOCAL
  freopen("c.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  bool ans = true;
  cin >> a >> b >> s;
  if (SZ(s) <= a)
    ans = false;
  else if (s[a] != '-')
    ans = false;
  dbg(ans);
  for (int i = 0; i < SZ(s) && ans; i++) {
    if (i == a) continue;
    ans = s[i] >= '0' && s[i] <= '9';
  }
  dbg(ans);
  ans = ans && (SZ(s) == (a + b + 1));
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3672
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		Integer[] a = new Integer[N];
		for(int i = 0; i < N; i++) {
			a[i] = stdIn.nextInt();
		}
		Arrays.sort(a, Collections.reverseOrder());
		
		int A = 0;
		int B = 0;
		for(int i = 0; i < N; i++) {
			if(i%2 == 0) A += a[i];
			else B += a[i];
		}
		System.out.println(A-B);

	}

}

Measured memory_bytes: 21716
#include <stdio.h>

int main(void)
{
    int x, y;

    while(scanf("%d %d", &x, &y))
    {
        if(x == 0 && y == 0)
        {
            return 0;
        }

        if(x > y)
        {
            int z = x;
            x = y;
            y = z;
        }

        printf("%d %d\n", x, y);
    }
}

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

int main(){
  int N;
  cin>>N;
  vector<int> H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  int ans=1;
  int k=0;
  for(int i=1;i<N;i++){
    if(H.at(i)>=H.at(k)){
      k=i;
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
 
const int MAXN = 2002;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;
 
template<typename T> inline void CheckMax(T &A, T B) {
	A < B ? A = B : A;
}
 
template<typename T> inline void CheckMin(T &A, T B) {
	A > B ? A = B : A;
}
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool f = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            f = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (f) {
        x = -x;
    }
}

int n, X, a[200];

signed main() {
	read(n), read(X);
	for(int i = 1; i <= n; i++) read(a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(X >= a[i]) X -= a[i], ans++;
	}
	if(ans == n && X) ans--;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append([a for a in input()])
    removeR = []
    for i in range(H):
        if all(A[i][j] == "." for j in range(W)):
            removeR.append(i)
    removeC = []
    for j in range(W):
        if all(A[i][j] == "." for i in range(H)):
            removeC.append(j)
    B = []
    for i in range(H):
        if i not in removeR:
            temp = []
            for j in range(W):
                if j not in removeC:
                    temp.append(A[i][j])
            B.append(temp)

    return B

if __name__ == '__main__':
    B = main()
    for i in range(len(B)):
        print("".join(B[i]))

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

bool dfs(const string &s,int i){
    if(i==n) return true;

    if(s.substr(i,5) == "erase"){
        if(dfs(s,i+5)) return true;
        else if(s[i+5] == 'r') {
            if(dfs(s,i+6)) return true;
        }else return false;
    }else if(s.substr(i,5) == "dream"){
        if(dfs(s,i+5)) return true;
        else if(s[i+5] == 'e'&&s[i+6] == 'r') {
            if(dfs(s,i+7)) return true;
        }else return false;
    }

    return false;
}
int main(){
    string s;
    cin >> s;
    n = s.size();

    if(dfs(s,0)) cout <<"YES"<<endl;
    else cout << "NO"<<endl;
 }


Measured memory_bytes: 5656
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Pair> pairs = new ArrayList<Pair>();
        for (int i = 0; i < m; i++) {
            pairs.add(new Pair(sc.nextInt(), sc.nextInt()));
        }
        Collections.sort(pairs);

        int hashi = pairs.get(0).to;
        int ans = 1;
        for (int i = 0; i < m; i++) {
            int left = pairs.get(i).from;
            if (left < hashi)
                continue;
            hashi = pairs.get(i).to;
            ans++;
        }
        System.out.println(ans);

    }

}

class Pair implements Comparable {
    int from;
    int to;

    Pair(int from, int to) {
        this.from = from;
        this.to = to;
    }

    @Override
    public int compareTo(Object other) {
        Pair otherPair = (Pair) other;
        if (this.to == otherPair.to)
            return this.from - this.to;
        return this.to - otherPair.to;
    }
}

Measured memory_bytes: 90284
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n,x,y; cin>>n>>x>>y;
    vector<int> dist(n-1,0);
    for (int i = 1; i <= n-1; i++)
    {
        for (int j = i+1; j <= n; j++)
        {
            dist[min(abs(i-j),abs(i-x)+1+abs(j-y))-1]++;
        }
    }
    rep(i,n-1) cout<<dist[i]<<endl;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) {
		ps(0)
	}
	else {
		ps(10)
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
#define endl "\n";



void run_case() {
    int n; LL k;
    cin >> n >> k;
    vector<int> a(n+1), vis(n+1), b;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    int pre, cir, nex = 1;
    for(int i = 1;;++i) {
        if(vis[nex]) {
            cir = i - vis[nex];
            pre = vis[nex];
            int sta = nex;
            do{
                b.push_back(sta);
                sta = a[sta];
            } while(sta != nex);
            
            break;
        } else {
            vis[nex] = i;
            nex = a[nex];
        }
    }
    int ans;
    if(k <= pre) {
        ans = 1;
        while(k--) {
            ans = a[ans];
        }
    } else {
        k -= pre;
        ans = b[(k+1+cir)%cir];
    }
    cout << ans;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 5412
ans = {
    3: [
        'aa.',
        '..a',
        '..a'
    ],
    4: [
        'aacd',
        'bbcd',
        'cdaa',
        'cdbb'
    ],
    5: [
        'aabbc',
        'bcc.c',
        'b..ba',
        'c..ba',
        'cddee'
    ],
    6: [
        'aabbcc',
        'bbccdd',
        'a.a.a.',
        'a.a.a.',
        '.a.a.a',
        '.a.a.a'
    ],
    7: [
        'aabbaa.',
        'ccaa..b',
        'aacc..b',
        '....bca',
        '....bca',
        '....cbc',
        '....cbc'
    ]
}
N = int(input())
if N < 8:
    if N in ans:
        for line in ans[N]:
            print(line)
    else:
        print(-1)
else:
    div = N // 4
    for i in range(div-1):
        for line in ans[4]:
            print('.'*(i*4) + line + '.'*(N-(i*4)-4))
    m = (N % 4) + 4
    for line in ans[m]:
        print('.'*(N-m) + line)

Measured memory_bytes: 4084
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int N=gi();
        int[] P=new int[N];
        
        for(int i=0; i<N;i++) {
            P[i]=gi();
        }
        Arrays.sort(P);
        P[P.length-1]=P[P.length-1]/2;
        int s=0;
        for(int i=0; i<N;i++) {
            s+=P[i];
        }
	    System.out.println(s);
	    
//        if (min==Integer.MAX_VALUE) {
//        	System.out.println("TLE");
//        }else {
//        	System.out.println(min);
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35508
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int ans[27] = {0};
	int lw, lal;
	int i, j;
	int tag = 0;
	char al[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
	char w[110];
	scanf("%s", &w);
	lw = strlen(w);
	lal = strlen(al);
	memset(ans, 0, sizeof(ans));
	for(i = 0; i < lw; i++)
	for(j = 0; j < lal; j++)
	{
		if(w[i] == al[j])
		ans[j]++;
	}
	for(i = 0; i < 27; i++)
	{
		if((ans[i] % 2) != 0)
		{
			tag++;
			break;
		}
	}
	if(tag == 0)
		printf("Yes\n");
		else
			printf("No\n");
		return 0 ;
}

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

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


int main(){

  ll k;
  cin >> k;
  ll ans = 0;
  ll total = 0;
  ll q = 7;
  while(ans < k+5){
    ans ++;
    total += q;
    total %= k;
    if (total==0){
      cout << ans << endl;
      return 0;
    }

    q *= 10;
    q %= k;
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3616
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
    int a;
    cin >> a;
    QECHO("ABC");QECHO(a);QECHO("\n");
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        int n;
        cin>>n;
        vector<int>a(n+1,0);
        for(int i=1;i<=n;i++){
            for(int j=0;j<=n;j+=i)
                a[j]++;
        }
        ll total=0;
        for(ll i=1;i<=n;i++)
            total+=(i*(ll)a[i]);
        cout<<total;
    }
    int main(){
        
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 42304
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t,a,b,tut[N],dist[N],dp[N];

int main()
{
	fast;
	cin>>n>>m>>b>>a;
	a%=2;
	for(int i=1;i<=a;i++)
		swap(n,m);
	cout<<n-m;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 2304
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    (a, b, c, k)
  }

  def max(a: Int, b: Int, c: Int): Int = Math.max(Math.max(a, b), c)

  def pow(x: Int, k: Int): Int = {
    if (k == 1) x
    else x * pow(x, k - 1)
  }

  def main(args: Array[String]): Unit = {
    val (a, b, c, k) = read()
    val maxvalue = max(a, b, c)
    // 黒板の書き換えで maxvalue * 2^k - maxvalue 増える
    val result = a + b + c + maxvalue * pow(2, k) - maxvalue
    println(result)
  }
}

Measured memory_bytes: 25524
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
vvl G;
vl visited;
vl finished;
vl hist;
 
ll pos1 = -1;  // サイクル中に含まれる頂点pos1。-1のときサイクルを含まない
 
void dfs(ll v) {
    visited[v] = 1;
    hist.pb(v);
    for(auto u : G[v]) {
        if(finished[u]) {
            continue;
        }
        // サイクルを検出
        if(visited[u] && !finished[u]) {
            pos1 = u;
            return;
        }
        dfs(u);
        if(pos1 != -1) {
            return;
        }
    }
    hist.pop_back();
    finished[v] = 1;
}
 
int main() {
    ll n, k;
    cin >> n >> k;
    
    G.resize(n);
    rep(i, n) {
        ll a;
        cin >> a;
        a--;
        G[i].pb(a);
    }
    
    const ll sv = 0;
    visited.assign(n, 0);
    finished.assign(n, 0); 
    dfs(sv);
 
    // 有向サイクルを復元 
    vl cycle;
    while(!hist.empty()) {
        ll t = hist.back();
        cycle.pb(t);
        hist.pop_back();
        if(t == pos1) {
            break;
        }
    }
    reverse(all(cycle));
 
    // BFS。計算量はO(V+E)
    vl dist(n, -1);  // dist[v] : 頂点svから頂点vへの最短距離(-1のとき未訪問)
    queue<ll> Q;
    dist[sv] = 0;
    Q.push(sv);
    while(!Q.empty()) {
        ll v = Q.front();
        Q.pop();
        for(auto u : G[v]) {
            if(dist[u] == -1) {
                dist[u] = dist[v] + 1;
                Q.push(u);
            }
        }
    }
    
    ll C = cycle.size();  // サイクルの長さ
    ll T = dist[pos1];  // サイクルに到達するまでの長さ
    
    if(k <= T) {  // 移動後サイクルに到達していない場合
        rep(v, n) {
            if(dist[v] == k) {
                out(v+1);
                re0;
            }
        }
    }

    // 以下、移動後サイクルに到達している
    ll x = k%C;  // x = k%C
    
    ll pos2 = (x + (C*T - T)%C)%C;
    
    out(cycle[pos2] + 1);
    re0;
}

Measured memory_bytes: 30444
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define inf 21474836478965499999
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 1000000007;
/*------------------------------------- THE GAME IS ON ---------------------------------------------*/
void solve()
{
     int n; cin>>n;
     queue<int>q;
     for(int i=0;i<n;i++)
     {
            int x;
            cin>>x;
            q.push(x);
     }
     int ht=0;
     int prev=q.front();
     q.pop();
     while(q.size()>0)
     {
            int temp=q.front();
            ht+=max(ll(0),prev-temp);
            prev=max(temp,prev);
            q.pop();
     }
     cout<<ht<<endl;
}       
int32_t main()
{
   high_functioning_sociopath
   ll t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 4780
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val _graph = new Array[((Int, Int), Long)](M)
  for (i <- 0 until M) {
    val L, R = in.next().toInt
    val C = in.next().toLong
    _graph(i) = ((L, R), C)
  }

  val graph = _graph.sorted


  //
  val rmq = new RMQ(1<<17)
  var ans = 0L

  var right = 1 // 届く右端

  var nowL = 0
  var now = 0L
  rmq.update(1, 0)

  breakable {
    for (node <- graph) {
      val L = node._1._1
      val R = node._1._2
      val C = node._2

      if (L > right) {
        ans = -1
        break
      }
      else {
        if (L != nowL) {
          nowL = L
          now = rmq.query(L, N+1)
        }

        right = Math.max(right, R)
        rmq.update(R, now + C)
      }
    }
  }

  if (right != N)
    ans = -1
  if(ans != -1)
    ans = rmq.query(N, N+1)
  

  println(ans)
}

// MaxN : 2の乗数でないといけない。要素数に応じた値。(e.g. 10^5なら1<<17にしておくとよい)
class RMQ(MaxN: Int) {

  val dat = Array.fill[Long](2*MaxN - 1)(Long.MaxValue)

  // k番目の値(0-indexed)をaに変更
  def update(_k: Int, a: Long): Unit = {
    // 葉の節点
    var k = _k + (MaxN - 1)
    dat(k) = Math.min(dat(k), a)

    // 登りながら更新
    while (k > 0) {
      k = (k-1) / 2
      dat(k) = Math.min(dat(2*k + 1), dat(2*k + 2))
    }
  }

  // [a, b) の最小値を求める
  // 後ろの方の引数は、計算の簡単のための引数
  // kは節点の番号。l, r はその節点が[l, r) に対応づいていることを表す。
  def query(a: Int, b: Int): Long = {
    def func(k: Int, l: Int, r: Int): Long = {
      if (r <= a || b <= l) // [a, b)と[l, r)が交差しなければ、Int.MaxValue
        Long.MaxValue
      else if (a <= l && r <= b) // [a, b)が[l, r)を完全に含んでいれば、この節点の値
        dat(k)
      else { // そうでなければ、２つの子の最小値
        val vl = func(2*k + 1, l, (l+r)/2)
        val vr = func(2*k + 2, (l+r)/2, r)

        Math.min(vl, vr)
      }
    }

    func(0, 0, MaxN)
  }

  def print(n: Int): Unit = {
    println(dat.take(n).deep)
  }

}


class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}


Measured memory_bytes: 78144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	set<string> a;
	for (int i = 0; i < N; ++ i) {
		string x;
		cin >> x;
		a.insert(x);
	}
	cout << a.size() << endl;
}


Measured memory_bytes: 19176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	int ans = 0;
	if (a < b) swap(a, b);
	for (int i = b; i > 0; i--){
		if (a % i == 0 and b % i == 0) ans++;
		if (ans == k){
			cout << i << endl;
			return 0;
		}

	}

}


Measured memory_bytes: 256
//██████╗ ██╗   ██╗██╗      ██████╗ ███████╗
//██╔══██╗██║   ██║██║      ██╔══██╗██╔════╝
//██████╔╝██║   ██║██║█████╗██║  ██║█████╗
//██╔══██╗██║   ██║██║╚════╝██║  ██║██╔══╝
//██║  ██║╚██████╔╝██║      ██████╔╝███████╗
//╚═╝  ╚═╝ ╚═════╝ ╚═╝      ╚═════╝ ╚══════╝
#include <iostream>
#include <random>
#include <vector>
#include <set>
#include <algorithm>
#include <iomanip>
#include <chrono>
#include <cstdio>


// #pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define sqr(x) ((x) * (x))

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;

#define next ajksdslk
#define prev aklsfjk

mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());

template<typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); }
template<typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); }

const int maxn = (int) 1e6 + 100;
const int maxlog = 21;
const int base = 1e9 + 7;
const ld eps = (ld) 1e-9;
const ld PI = acos(-1.);
//const int pp = 41;
const int inf = 2e9;
const ll llinf = 1e18;

ld dist(pii a, pii b) {
  return sqrt( sqr(a.first - b.first) + sqr(a.second - b.second));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
#endif

  int n; cin >> n;
  vector<pii> a(n);
  for (int i =0 ; i < n; i ++) {
    cin >> a[i].first >>  a[i].second;
  }
  vector<int> p(n);
  iota(all(p), 0);
  ld ans = 0;
  int cnt = 0;
  do {

    for (int i = 0; i + 1 < n; i ++) {
      ans += dist( a[p[i]], a[p[i + 1]] );
    }
    cnt ++;

  } while(next_permutation(all(p)));
  cout << fixed << setprecision(10) << ans / cnt << '\n';
  return 0;
}

Measured memory_bytes: 888
while(True):
    H, W = map(int, raw_input().split())

    if H == 0 and W == 0:
        break

    for i in range(H):
        if i == 0 or i == H-1:
            print "#"*W
        else:
            print "#" + "."*(W-2) + "#"
    print

Measured memory_bytes: 6436
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;
	vector<P> p;
	rep(i, n){
		int a;cin>>a;
		p.push_back(P(a, i+1));
		//debug("    %d\n", i+1);
	}
	sort(all(p));
	rep(i, n){
		//debug("  %d  %d\n", p[i].first, p[i].second);
		cout << p[i].second;
		if(i != n-1){cout << ' ';}
	}cout << endl;
	return 0;
}


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

#define int long long

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

int N;
int a[1100];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int even_sum = 0, odd_sum = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] >= 0) {
            if (i % 2 == 0) {
                even_sum += a[i];
            } else {
                odd_sum += a[i];
            }
        }
    }
    int xxx = max(even_sum, odd_sum);
    if (xxx == 0) {
        int max_i, max_a_i = LLONG_MIN;
        for (int i = 0; i < N; i++) {
            if (a[i] > max_a_i) {
                max_a_i = a[i];
                max_i = i;
            }
        }
        cout << max_a_i << endl;
        cout << N - 1 << endl;
        for (int i = 0; i < max_i; i++) {
            cout << 1 << endl;
        }
        for (int i = N - max_i; i > 1; i--) {
            cout << i << endl;
        }
        return 0;
    }
    cout << xxx << endl;
    int start = even_sum > odd_sum ? 0 : 1;
    bool flag = start == 1;
    int erased = 0;
    vector<int> ans;
    for (int i = start; i < N; i += 2) {
        if (a[i] < 0) {
            ans.push_back(i - erased + 1);
            erased += 2;
            if (i == 0)
                flag = true;
            if (i == 0 || i == N - 1) {
                erased--;
            }
        }
    }
    if (flag) {
        ans.push_back(1);
        erased++;
    }
    while (N - erased > 1) {
        ans.push_back(2);
        erased += 2;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
Created on Fri Aug 25 16:34:06 2020

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
const int mod = 1e9+7;
#define endl "\n"
#define append push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

string a, b;

string weird(int n, int m) {
	int dp[n+1][m+1];
  	for(int i = 0; i<n+1; i++) {
  		for(int j = 0; j<m+1; j++) {
  			if(i == 0 || j == 0) dp[i][j] = 0;
  			
  			else if(a[i-1] == b[j-1]) dp[i][j] = 1+dp[i-1][j-1];
  			
  			else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
		}
	}
	int i = n, j = m;
	string res = "";
	while(i>0 && j>0) {
		if(a[i-1] == b[j-1]) {
			res.append(a[i-1]);
			i--;
			j--;
		}
		else {
			if(dp[i-1][j] > dp[i][j-1]) {
				i--;
			}
			else j--;
		}
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	roastedcoder
	cin>>a>>b;
  	int n = a.length(), m = b.length();
	cout<<weird(n, m);
}

//__________________________________________________________________
/*
Sample Input:
axyb
abyxb

Sample Output:
ayb

*/

Measured memory_bytes: 38840
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
    ll l, r;
    cin >> l >> r;
    ll ans = 2029;
    for (ll i = l; i <= min(l + 2019, r); i++)
    {
        for (ll j = i + 1; j <= min(i + 2019, r); j++)
        {
            ans = min(ans, i * j % 2019);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
tbl = [[0] * (N + 1) for _ in range(N)]

for _ in range(M):
    l, r = [int(x) - 1 for x in input().split()]
    tbl[l][r] += 1

for i in range(N):
    for j in range(1, N):
        tbl[i][j] += tbl[i][j - 1]

for i in range(1, N):
    for j in range(N):
        tbl[i][j] += tbl[i - 1][j]

for _ in range(Q):
    p, q = [int(x) - 1 for x in input().split()]
    if p == 0:
        print(tbl[q][q])
    else:
        print(tbl[q][q] - tbl[p - 1][q] - tbl[q][p - 1] + tbl[p - 1][p - 1])

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int h,w;
	cin >> h >> w;
	int ans = INF;
	if(h % 3 == 0){
		ans = 0;
	}else{
		ans = min(ans, w);
	}
	if(w % 3 == 0){
		ans = 0;
	}else{
		ans = min(ans, h);
	}
	ans = min(ans, (w - w / 3) * ((h + 1) / 2) - (w / 3) * h);
	ans = min(ans, (w + 2) / 3 * h - (w - (w + 2) / 3) * (h / 2));
	ans = min(ans, (h - h / 3) * ((w + 1) / 2) - (h / 3) * w);
	ans = min(ans, (h + 2) / 3 * w - (h - (h + 2) / 3) * (w / 2));
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  int a,v,b,w,t;
  string ans;
  cin>>a>>v>>b>>w>>t;
  
  if (w>=v){
    cout<<"NO";
    return 0;
  }
  int dis = abs(b-a);
  REP(i,t){
    dis-=v-w;
    if(dis<=0){
      cout<<"YES";
      return 0;
    }
  }
  cout<<"NO";
  return 0;
}


Measured memory_bytes: 3592
from time import time
import random
from collections import Counter


def main():
    random.seed(0)

    start = time()

    MAX = 26

    # 入力
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]

    # 初期解を貪欲法で求める
    t = []
    prev = [0] * MAX
    for day, row in enumerate(s, 1):
        mxi = 1
        mx = 0
        for i, (es, ec) in enumerate(zip(row, c), 1):
            point = es + ec * (day - prev[i - 1])
            if point > mx:
                mx = point
                mxi = i

        prev[mxi - 1] = day
        t.append(mxi)

    # 初期解に対する満足度を計算
    last = [0] * MAX
    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    # 変更を検討する日にちの選ばれやすさ
    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    di_max = len(d_li) - 1

    # 各日にちにおいて変更を検討するコンテストの選ばれやすさ
    sc = []
    for row in s:
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            app += [i] * max(1, (es + ec * d) // 20)

        sc.append(app)

    # 時間の許す限り更新を検討する
    #cnt = 0
    #no_change = 0
    #counter = Counter()
    while time() - start <= 1.85:
        #cnt += 1
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            val = (score - prev_score) / (1000 * (time() - start))
            #print(time() - start, val)
            if val > -10:
                continue
            #counter[int(val)] += 1
            #no_change += 1
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")
    #print("#############")
    #print("cnt", cnt)
    #print("no change", no_change)
    #print(sorted(counter.items()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 264396
n=list(map(int,input().split()))
men=list([n[1]-n[2]]*n[0])
a=[int(input())-1 for i in range(n[2])]
for i in a:
    men[i]+=1
y = ["Yes" if i > 0 else "No" for i in men]
print('\n'.join(map(str, y)))

Measured memory_bytes: 64076
# -*- coding: utf-8 -*-
"""
C - Align
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c

"""
import sys


from collections import deque

def solve(N, numbers):
    res = deque([numbers[0]])
    numbers = deque(numbers[1:])
    while numbers:
        bb = abs(numbers[-1] - res[-1])
        bf = abs(numbers[-1] - res[0])
        ff = abs(numbers[0] - res[0])
        fb = abs(numbers[0] - res[-1])
        t = sorted([[bb, 'bb'], [bf, 'bf'], [ff, 'ff'], [fb, 'fb']])
        if t[-1][1] == 'bb':
            res.append(numbers.pop())
        elif t[-1][1] == 'bf':
            res.appendleft(numbers.pop())
        elif t[-1][1] == 'ff':
            res.appendleft((numbers.popleft()))
        elif t[-1][1] == 'fb':
            res.append(numbers.popleft())

    res = list(res)
    return sum([abs(a-b) for a, b in zip(res, res[1:])])



def main(args):
    N = int(input())
    numbers = sorted([int(input()) for _ in range(N)])
    ans = solve(N, numbers)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 13216
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{ ll n,m,count=0,sum=0;
   cin>>n>>m;
   ll a[m];
   for(ll i=0;i<m;i++){
   cin>>a[i];
   sum+=a[i];}
  if(sum>n)
    cout<<"-1";
 else if(sum==n)
   cout<<"0";
 else if(sum<n)
   cout<<n-sum;
   else
     assert(0);
   
  return 0;
}

Measured memory_bytes: 3628
/*=======================
Author    : Shounak Dey
=======================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define PB push_back
#define MK make_pair
#define SZ(a) (int)(sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define read(n) scanf("%d",&n)
#define readl(n) scanf("%lld",&n)
#define readul(n) scanf("%llu",&n);
#define SORTV(a) sort(a.begin(),a.end())
#define TEST int Test;cin >> Test;while(Test--):
#define gcd(a,b) __gcd(a,b)
#define ffs(a) __builtin_ffs(a) // find first set
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
vector<string> split(const string& s, char c) {
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}
int main()
{
    fast_io;
    ll n;
    cin >> n;
    vector<ll> arr(n);
    REP(i,n) cin >> arr[i];
    SORTV(arr);
    ll s=0;
    REP(i,n-1)
        s += arr[i];
    if(arr[n-1]<s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256