akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Map;
import java.util.LinkedList;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line = br.readLine().split(" ");
    int n = Integer.parseInt(line[0]);
    int q = Integer.parseInt(line[1]);
    LinkedList<String> queue = new LinkedList<String>();
    int time = 0;
    int cnt = n;
    Map<String, Integer> map = new HashMap<>();

    for(int i = 0; i < n; i++){
      line = br.readLine().split(" ");
      map.put(line[0], Integer.parseInt(line[1]));
      queue.add(line[0]);
    }

    while(true){
      String x = queue.poll();
      if(map.get(x) > q){
        time += q;
        map.put(x, map.get(x) - q);
        queue.add(x);
      }else{
        time += map.get(x);
        map.put(x, time);
        System.out.println(x + " " + map.get(x));
        n--;
      }
      if(n == 0)  break;
    }
  }
}

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

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

	if (a < b) {
		cout << "a < b" << endl;
	}
	else if (a == b) {
		cout << "a == b" << endl;
	}
	else{
		cout << "a > b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;

#define all(A) (A).begin(), (A).end()
#define II(A) int (A); scanf("%d",&(A));
#define DBG if(1)
#define NDBG if(0)
#define end _asdf_asdf_bumsoo

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

const int MN = 100000 + 1;

int N;
int A[MN];
int end[MN] = {};

int val(int x,int y){
	if(x>=N) return true;
	if(y>=A[x])	return true;
	return end[x]^((A[x]-1-y)&1);
}

int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++) scanf("%d",&A[i]);
	sort(A, A+N, greater<int>());
	end[N-1] = 0;
	for(int i=N-2;i>=0;i--){
		if(A[i] == A[i+1]) end[i] = end[i+1]^1;
		else end[i] = 0;
	}
	int x=0,y=0;
	while(x<N-1 && y+1 < A[x+1]) x++, y++;
	if(!val(x,y+1) || !val(x+1,y)){
		puts("First");
	}
	else puts("Second");
	return 0;
} 


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

int main(){ 
    string S;
    cin >> S;
    int a = 0;
    int b = 0;
    
    for(int i = 0; i < int(S.size()); i++){
        if(S.at(i) == 'A'){
            a = 1;
        }else{
            b = 1;
        }
    }
    
    if(a == 1 and b == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
   
}
        


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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> ax(n), ay(n), cx(m), cy(m);
    for(int i = 0; i < n; i++){
        cin >> ax[i] >> ay[i];
    }
    for(int i = 0; i < m; i++){
        cin >> cx[i] >> cy[i];
    }
    for(int i = 0; i < n; i++){
        ll dist = LLONG_MAX;
        int idx = -1;
        for(int j = 0; j < m; j++){
            ll cur = abs(ax[i] - cx[j]) + abs(ay[i] - cy[j]);
            if(dist > cur){
                dist = cur;
                idx = j;
            }
        }
        cout << idx + 1 << nl;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i=0;i<n;++i) {
    cin>>a[i];
  }
  int ans=0;
  int ans_2=0;
  for (int i=0;i<(n-1);++i) {
    if (a[i]>=a[i+1]) {
      ans+=1;
    } else {
      ans_2=max(ans,ans_2);
      ans=0;
    }
  }
  ans=max(ans,ans_2);
  cout<<ans<<endl;
}



Measured memory_bytes: 640
/**

Heart beats fast
Colours and promises
How to be brave?
How can I love when I'm afraid to fall?
But watching you stand alone,
All of my doubt suddenly goes away somehow.

One step closer

I have died every day waiting for you
Darling, don't be afraid.
I have loved you for a thousand years
I'll love you for a thousand more

Time stands still
Beauty in all she is
I will be brave
I will not let anything take away
What's standing in front of me
Every breath
Every hour has come to this

One step closer
One step closer

I have died every day waiting for you
Darling, don't be afraid.
I have loved you for a thousand years
I'll love you for a thousand more

And all along I believed I would find you
Time has brought your heart to me
I have loved you for a thousand years
I'll love you for a thousand more

*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

long long a[N], s[N];
long long pre[N], suf[N], best[N];

long long find(int l, int r) {
  if (l > r) return 0;
  return s[r] - s[l-1];
}

int main() {
  int n, t;
  scanf("%d %d", &n, &t);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    s[i] = s[i - 1] + a[i];
  }
  int maxi = -1, p = -1;
  for (int i = 1; i <= n; i++) {
    if (a[i] > maxi) {
      maxi = a[i];
      p = i;
    }
    pre[i] = find(1, p - 1);
    suf[i] = find(p + 1, i);
    best[i] = maxi;
  }
  for (int i = 1; i <= n; i++) {
    long long l = 1, r = 2e9;
    while (l < r) {
      long long ke = (l + r) >> 1;
      long long tot = pre[i] + suf[i] + best[i] * ke;
      if (t < tot) {
        r = ke;
      } else {
        l = ke + 1;
      }
    }
    printf("%lld\n", l);
  }
  return 0;
}

Measured memory_bytes: 7120
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

/*Binary Indexed Tree*/
struct BIT{
	int n;
	vvi bit;//i:=[1,n].
	
	BIT(string s,int n_):n(n_-1),bit(n_,vi(26,0)){
		for(int i=1;i<=n;++i){
			int j=i;
			while(j<=n){
				bit[j][s[i]-'a']++;
				j+=j&-j;
			}
		}
	}
	
	vi q2(int i){
		vi res(26,0);
		while(i>0){
			REP(j,26) res[j]+=bit[i][j];
			i-=i&-i;
		}
		return res;
	}
	void q1(string &s,int i,char c){
		int j=i;
		while(j<=n){
			bit[j][s[i]-'a']--;
			bit[j][c-'a']++;
			j+=j&-j;
		}
		s[i]=c;
	}
};

int main(){
	int n;
	string s;
	int q;
	cin>>n>>s>>q;
	s=" "+s;
	
	BIT tree(s,s.size());
	REP(i,q){
		int num;
		cin>>num;
		if(num==1){
			int j;
			char c;
			cin>>j>>c;
			
			tree.q1(s,j,c);
		}else{
			int l,r;
			cin>>l>>r;
			
			vi vl;
			if(l-1==0) vl=vi(26,0);
			else vl=tree.q2(l-1);
			vi vr=tree.q2(r);
			
			int ans=0;
			//line(vl);
			//line(vr);
			REP(j,26){
				if(vr[j]-vl[j]) ans++;
			}
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 69656
# ABC061D - Score Attack
import sys
input = sys.stdin.readline

def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
    INF = float("inf")
    dist = [INF] * (N + 1)
    dist[1] = 0

    # relax edges
    for i in range(N):
        for v, u, w in E:  # w: positive -> -w
            if dist[v] - w < dist[u]:
                dist[u] = dist[v] - w
                if i == N - 1 and u == N:  # detect negative cycles
                    return None
    return dist[-1]


def main():
    # reverse weights -> shortest path problem containing negative cycles
    N, M = tuple(map(int, input().split()))  # vertices, edges
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    ans = bellman_ford(N, M, E)
    flg = ans is not None
    print(-ans if flg else "inf")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3312
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int main(void){
  int n, both, max = INT_MIN; string s;
  cin >> n >> s;

  for(int i = 0; i < n; i++){
    both = 0;
    for(int j = 0; j <= i; j++){
      if(count(s.begin(), s.begin()+j, s[j]) > 0) continue;
      if(count(s.begin()+i+1, s.end(), s[j]) > 0) both++;
    }
    if(max < both) max = both;
  }

  cout << max << endl;
  return 0;
}


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

int main()
{
       int a[4];

       scanf("%d %d %d", &a[0], &a[1], &a[2]);

       if( a[0] + a[1] + a[2] >= 22 ) puts("bust");
       else puts("win");

       return 0;
}

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

int main() {
    string A, B;
    cin >> A;
    cin >> B;
    string ans = " ";
    if(A.size() > B.size()) {
        ans = "GREATER";
    } else if(A.size() < B.size()) {
        ans = "LESS";
    } else {
        for(int i = 0; i < A.size(); i++) {
            int a = int(A[i]);
            int b = int(B[i]);
            if(a > b) {
                ans = "GREATER";
                break;
            } else if(a < b) {
                ans = "LESS";
                break;
            } 
        }
        if(ans == " ") {
            ans = "EQUAL";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var A, B int
	fmt.Scanf("%d %d", &A, &B)

	if (A+B)%2 == 0 {
		fmt.Println((A + B) / 2)
	} else {
		fmt.Println("IMPOSSIBLE")
	}

}


Measured memory_bytes: 1832
#include <cstdio>
#include <algorithm>
#include <cassert>

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 100050;
int a[maxn];
int ansx[maxn], ansy[maxn], ap;
int fg = 0;
inline int flag(int x) {
	if(x > 0) return 1;
	if(x < 0) return -1;
	return fg;
}

int main() {
	int n = input();
	for(int i = 1; i <= n; i ++)
		a[i] = input();
	if(n == 1) {
		printf("%d\n", a[1]);
		return 0;
	}
	std::sort(a + 1, a + n + 1);
	if(a[1] == 0 and a[n] == 0) {
		puts("0");
		for(int i = 1; i < n; i ++)
			puts("0 0");
		return 0;
	}
	if(a[1] == 0)
		fg = -1;
	else if(a[n] == 0)
		fg = 1;
	if(flag(a[1]) == 1) {
		ansx[++ ap] = a[1];
		ansy[ap] = a[n];
		a[1] = a[1] - a[n];
		n --;
		std::sort(a + 1, a + n + 1);
		if(a[1] == 0)
			fg = -1;
		else if(a[n] == 0)
			fg = 1;
	} else if(flag(a[n]) == -1) {
		ansx[++ ap] = a[n];
		ansy[ap] = a[1];
		a[1] = a[n] - a[1];
		n --;
		std::sort(a + 1, a + n + 1);
		if(a[1] == 0)
			fg = -1;
		else if(a[n] == 0)
			fg = 1;
	}
	int first = 0;
	for(int i = 1; i <= n; i ++)
		if(flag(a[i]) == 1) {
			first =	i;
			break;
		}
	assert(first);
	for(int i = first + 1; i <= n; i ++) {
		ansx[++ ap] = a[1];
		ansy[ap] = a[i];
		a[1] = a[1] - a[i];
	}
	for(int i = 1; i < first; i ++) {
		ansx[++ ap] = a[first];
		ansy[ap] = a[i];
		a[first] = a[first] - a[i];
	}
	printf("%d\n", a[first]);
	for(int i = 1; i <= ap; i ++)
		printf("%d %d\n", ansx[i], ansy[i]);
}


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

int main(){
  int a,b,c;
  int na,nb,nc;
  cin >> a >> b >> c;

  int ans = 0;
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
    na = b/2+c/2;
    nb = a/2+c/2;
    nc = a/2+b/2;
    a = na;
    b = nb;
    c = nc;
    if(a == b && b == c){
      cout << -1 << endl;
      return 0;
    }
    ans++;
  }

  cout << ans << endl;

  return 0;
}


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

ll gcd(ll a, ll b) {
    ll tmp = a % b;
    while (tmp != 0) {
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}

int main() {
    int N;
    cin >> N;
    ll ans = 1;
    rep(i, N) {
        ll T;
        cin >> T;
        ans = ans/gcd(ans, T)*T;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for i in range(m)]
 
for i in range(10**n):
  ans = str(i)
  if len(ans) != n:
    continue
  if all([ans[s-1] == str(c) for s, c in sc]):
    print(ans)
    exit()

print(-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(){cout << -1 << '\n';}
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    string t = "";
    REP(i,SZ(s)/2) t += "hi";
    Yes(s == t);
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> p(n);
    REP(i, n) { cin >> p[i]; }
    lint ans=0;
    lint tmp = 1000000;

    REP(i,n){
        if(p[i]<=tmp){
            tmp = p[i];
            ans ++;
        }
    }



    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 1920
n, t = map(int, list(input().split(' ')))
ti = list(map(int, list(input().split(' '))))
result = t
for i, item in enumerate(ti):
  temp = t
  if i == len(ti) - 1:
    break
  if ti[i+1] - ti[i] < t:
    temp = ti[i+1] - ti[i]
  result = result + temp

print(result)


Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<string> ans{"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    cout << ans[n%10] << "\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(string, s);
  map<char, int> mp;
  for (auto e : s) mp[e]++;

  if (mp['N'] > 0 and mp['S'] == 0) {
    puts("No");
    return;
  }
  if (mp['E'] > 0 and mp['W'] == 0) {
    puts("No");
    return;
  }
  if (mp['W'] > 0 and mp['E'] == 0) {
    puts("No");
    return;
  }
  if (mp['S'] > 0 and mp['N'] == 0) {
    puts("No");
    return;
  }
  puts("Yes");
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

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

namespace Contest20191112
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int sum = 0;

            if (a >= b)
            {
                sum += a;
                a--;
            }
            else
            {
                sum += b;
                b--;
            }

            if (a >= b)
            {
                sum += a;
            }
            else
            {
                sum += b;
            }

            Console.WriteLine(sum);
        }
    }
}


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

using namespace std;


typedef long long int64;

int main()
{
  int X, Y, Z, A, B, C, N;
  int64 a[1000] = {}, b[1000] = {}, c[1000] = {};

  cin >> X >> Y >> Z >> A >> B >> C >> N;
  for(int i = 0; i < X; i++) ++a[abs(i - A) % N];
  for(int i = 0; i < Y; i++) ++b[abs(i - B) % N];
  for(int i = 0; i < Z; i++) ++c[abs(i - C) % N];

  int64 d[2000] = {}, ret[3000] = {};
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) d[i + j] += a[i] * b[j];
  }

  for(int i = 0; i < N + N; i++) {
    for(int j = 0; j < N; j++) {
      ret[i + j] += d[i] * c[j];
    }
  }

  for(int i = 0; i < N; i++) {
    if(i > 0) cout << " ";
    cout << ret[i] + ret[i + N] + ret[i + N + N];
  }
  cout << endl;

}

Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 2005

const int INF = 1e9+7;

int dp[ARRAY_MAX][ARRAY_MAX];
//dp[i][j]:=i番目のジャンルの本までのなかでj冊売る時の最大金額

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> num[10];
    vector<int> sum[10];

    for(int i = 0;i < n;i++){
        int c,g;
        cin >> c >> g;
        num[g-1].push_back(c);
    }

    for(int i = 0;i < 10;i++){
        //降順ソート
        sort(num[i].begin(),num[i].end(),greater<int>());
    }

    for(int i = 0;i < 10;i++){
        //累積和
        sum[i].resize(num[i].size()+1,0);
        for(int j = 1;j < sum[i].size();j++){
            sum[i][j] = sum[i][j-1] + num[i][j-1];
        }
    }

    for(int i = 0;i < 10;i++){
        for(int j = 0;j <= k;j++){
            for(int m = 0;m < sum[i].size();m++){
                dp[i+1][j+m] = max(dp[i+1][j+m],dp[i][j] + sum[i][m] + m*(m-1));

            }
        }
    }
    cout << dp[10][k] << endl;

    return 0;
}


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

const int N = (int)1e5 + 5;

int n,m,deg[N],dist[N];

vector<int> g[N];

bool used[N];

void dfs(int v){
	used[v] = 1;
	for(int to : g[v]){
		dist[to] = max(dist[to],dist[v] + 1);
		deg[to]--;
		if(deg[to] == 0) dfs(to);
	}
}

int main(){
    cin >> n >> m;
   	for(int i = 1; i <= m; i++){
   		int a,b;
   		cin >> a >> b;
   	    deg[b]++;
   		g[a].push_back(b);
   	}
   	for(int i = 1; i <= n; i++){
   		if(!used[i] && deg[i] == 0){
   			dfs(i);
   		}
   	}
   	int ans = 0;
   	for(int i = 1; i <= n; i++){
   		ans = max(ans,dist[i]);
   	}
   	cout << ans;
	return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <vector>

using namespace std;

typedef pair<int ,int> pii;
typedef long long ll;
const int maxn = 1e5 + 10;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;

int main()
{
	int a,b,t;
   while (cin>>a>>b>>t){
   		if (a*b<t){
   			printf ("%d\n",a*b);
		   }
		   else printf ("%d\n",t);
   }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, x, a, b, c, ans;
    
    while(1)
    {
        ans = 0;
        
        scanf(" %d %d", &n, &x);
        
        if(n == 0 && x == 0) break;
        
        for(a=1; a<n+1; a++)
        {
            for(b=a+1; b<n+1; b++)
            {
                for(c=b+1; c<n+1; c++)
                {
                    if(x == (a+b+c))
                    {
                        ans++;
                    }
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string ABCD;

int main()
{
  std::cin >> ABCD;

  rep( i, 1<<3 )
  {
    int sum = ABCD[0]-'0';
    std::string t;
    t += ABCD[0];

    rep( j, 3 )
    {
      sum += (i >> j & 1 ? ABCD[j+1]-'0' : -(ABCD[j+1]-'0'));
      t += (i >> j & 1 ? '+' : '-');
      t += ABCD[j+1];
    }

    if( sum == 7 )
    {
      std::cout << t << "=7" << std::endl;

      return 0;
    }
  }
  
  return 0;
}

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

int main(void) {
    int N, X, cnt;

    while(true) {
        cin >> N >> X;
        if(N == 0 && X == 0) break;

        cnt = 0;
        for(int i=1; i <= N; i++)
            for(int j=i+1; j <= N; j++)
                for(int k=j+1; k <= N; k++)
                    if((i + j + k) == X) cnt++;

        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

# H = deque(list(map(int, input().split())))
max_K = 100
H = list(map(int, input().split()))
H += [0] * max_K
# for _ in range(max_K):
#   H.append(0)

dp = [float('inf')] * (N + max_K)
dp[0] = 0

for n in range(N):
  for offset in range(1, K + 1):
    new_index = n + offset
    cost = dp[n] + abs(H[n] - H[new_index])
    if (dp[new_index] > cost):
      dp[new_index] = cost

print(dp[N - 1])


Measured memory_bytes: 54620
#include <bits/stdc++.h>
using namespace std ;
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ALL(x) (x).begin(),(x).end() 
#define UNQ(x) (x).erase( unique(ALL(x)) , (x).end() ) 
#define lwb( x , y ) lower_bound(ALL(x) , (y) ) - (x).begin() 
#define upb( x , y ) upper_bound(ALL(x) , (y) ) - (x).begin() 
#define sz(x) (int)(x).size() 
#define pb push_back
typedef long long ll ;

int n , m , col , arr[10010] , tab[105][105] ; 

int main(){
	// freopen("in.txt" , "r" , stdin);
	// freopen("out.txt" , "w" , stdout) ;
	scanf("%d%d%d",&n,&m,&col) ;
	int cnt = 0 , x , y;
	for(int i=0;i<col;i++){
		scanf("%d" , arr + i ) ;
		arr[i] += arr[i-1] ;
		for( ; cnt < arr[i] ; cnt++ ){
			x = cnt/m ; y = cnt%m ; 
			if(x&1) y = m - y - 1 ; 
			tab[x][y] = i+1 ; 
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) printf("%d " , tab[i][j]); 
		cout << endl ; 
	}
	return  0 ;
}


Measured memory_bytes: 384
//#include "SaveFuncs.cpp"

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
//#define int long long
constexpr int INF = 2000000100;
constexpr int DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
string strMulti(string t, int n) { string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }

/*****/

int Main()
{
	int N;
	cin >> N;
	vector<int> H(N);
	rep(i, N)	cin >> H.at(i);

	bool isYes = true;

	for (int i = N - 2; i > 0; i--)
	{
		if (H.at(i) - H.at(i + 1) == 1)
		{
			H.at(i)--;
		}
		else if (H.at(i) - H.at(i + 1) > 1)
		{
			isYes = false;
			break;
		}
	}

	cout << (isYes ? "Yes" : "No") << endl;

	return 0;
}

/*****/

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

	Main();

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define LL long long

int min(int a, int b)
{
  return a > b ? b : a;
}

int digits(int a)
{
  int d = 0;
      while(a){
        a /= 10;
        d++;
      }
  return d;
}

int main()
{
  LL N;
  int ans=1000000000;
  int A,B;

  scanf("%lld", &N);
  LL n = sqrt((double)N);

  for(A=1; A<=n; A++)
  {
    if(N%A != 0)
      {continue;}
    B = N/A;

    ans = min(ans,digits(B));
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int k,a,b;
  std::cin >> k >> a >> b;

  bool f = false;
  for(int i = a; i <= b; i++){
    if(i%k == 0){
      f = true;
      break;
    }
  }

  std::cout << (f ? "OK" : "NG") << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

ll ones(int x){
	ll ret=0;
	for(;x--;) ret=10*ret+1;
	return ret;
}

ll get_kth(int k){
	--k;
	ll ret = 0;
	for(int dep=1; dep<=9; ++dep){
		if(!k && dep>1){
			break;
		}
		if(dep>1) --k;
		for(int i=(dep==1); i<=9; ++i){
			if(ones(10-dep) <= k){
				k -= ones(10-dep);
			} else {
				ret=10*ret + i;
				break;
			}
		}
	}
	return ret;
}

bool Test(ll x){
	printf("? %lld\n", x);
	fflush(stdout);
	char buf[5]; scanf("%s", buf);
	return buf[0] == 'Y';
}

int main()
{
	if(Test(1e9)){
		ll A=1;
		while(true){
			if(Test(10*A-1)) break;
			A *= 10;
		}
		printf("! %lld\n", A);
	} else {
		ll l=1, r=1e9;
		while(l < r){
			ll mid=(l+r)/2;
			ll q = get_kth(mid);
			while(q <= ll(1e10)) q*=10;
			if(Test(q)) r=mid;
			else l=mid+1;
		}
		ll ap = get_kth(l);
		ll co = 1;
		while(true){
			co *= 10;
			if(!Test((ap-1)*co)) break;
		}
		ap *= co/10;
		printf("! %lld\n", ap);
	}
	return 0;
}


Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
using namespace std;
int n,ans;
int cal(int x){
    int ret=0;
    while (x) ret+=x%10,x/=10;
    return ret;
}
int main(){
    scanf("%d",&n);
    ans=inf;
    rep (A,1,n-1) ans=min(ans,cal(A)+cal(n-A));
    cout<<ans<<'\n';
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  lvector x(n,0),y(n,0),v_(n,0);
  rep(i,n) cin>>x[i]>>y[i];
  map<P,vector<P>> mp;
  for(ll i=0;i<n;++i) {
    for(ll j=i+1;j<n;++j) {
      ll x_=x[i]-x[j], y_=y[i]-y[j];
      mp[P(x_,y_)].emplace_back(P(i,j));
      mp[P(-x_,-y_)].emplace_back(P(i,j));
    }
  }
  ll mx=0;
  for(auto i:mp) mx=max(mx, (ll)(i.second).size());
  const ll ans=n-mx;
  print(ans);
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		Map<Integer, Integer> prime = new LinkedHashMap<Integer, Integer>();
		List<Integer> result = new ArrayList<Integer>();
		
		prime.put(1,2); prime.put(2,5);
		int[] p = new int[10000];
		p[0] = 2; p[1] = 3;
		int k = 2;
	outer:	for(int i = 5; k < 10000; i += 2){
			for(int j = 1; p[j] <= Math.sqrt(i); j++){
				if( i%p[j] == 0 ){
					continue outer;
				}
			}
			p[k] = i;
			k++;
			prime.put(k, prime.get(k-1)+i);
		}
		
		int n;
		while( (n = stdIn.nextInt()) != 0 ){
			result.add(prime.get(n));
		}
		
		for(Integer sum : result){
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
#define P pair<int,int>
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int INF = 1001001001;
 
int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    for(int si=0;si<h;si++)
    {
        for(int sj=0;sj<w;sj++)
        {
            if (s[si][sj] == '#') 
            continue;
            vector<vector<int>> dist(h, vector<int>(w, INF));
            queue<P> q;
            dist[si][sj] = 0;
            q.push({si,sj});
            while (!q.empty()) 
            {
                int x = q.front().first, y = q.front().second;
                q.pop();
                for(int k=0;k<4;k++)
                {
                    int ni = x+dir[k][0], nj = y+dir[k][1];
                    if (ni<0||ni>=h||nj<0||nj>=w || s[ni][nj] == '#' || dist[ni][nj] != INF) 
                    continue;
                    dist[ni][nj] = dist[x][y] + 1;
                    q.push({ni,nj});
                }
            } 
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
            }
        }
      }
    }
    cout << ans << endl;
    return 0;
}

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

#define MAX 100000

vector<int> T[MAX + 1];
int ans[MAX + 1];

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		T[A].push_back(B);
		T[B].push_back(A);
	}

	for (int i = 1; i <= N; i++)
		ans[i] = -1;
	queue<int> Q;
	Q.push(1);
	while (!Q.empty()) {
		int u = Q.front();
		Q.pop();
		for (int i = 0; i < T[u].size(); i++) {
			if (ans[T[u][i]] == -1) {
				ans[T[u][i]] = u;
				Q.push(T[u][i]);
			}
		}
	}

	cout << "Yes" << endl;
	for (int i = 2; i <= N; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 10408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100;

int n, u, k, v;

vector<int> G[MAX_N];
int d[MAX_N]; // distance from 0

int main() {
    // input
    cin >> n;
    REP(i, n) {
        cin >> u >> k;
        REP(j, k) {
            cin >> v;
            G[u-1].PB(v-1);
        }
    }

    // init d
    REP(i, n) d[i] = -1;

    // BFS
    queue<int> Q;
    Q.push(0);
    d[0] = 0;
    while (Q.size()) {
        int pos = Q.front(); Q.pop();
        REP(i, G[pos].size()) {
            int to = G[pos][i];
            if (d[to] != -1) continue;
            Q.push(to);
            d[to] = d[pos] + 1;
        }
    }

    // output
    REP(i, n) {
        int id = i + 1;
        printf("%d %d\n", id, d[i]);
    }

    return 0;
}


Measured memory_bytes: 3264
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = (0 until n).map { 
        sc.next().toString()
     }

    val map = HashMap<String, Int>()
    for (si in s) {
        if (map.containsKey(si)) {
            map[si] = map[si]!! + 1
        } else {
            map[si] = 1
        }
    }

    val max = map.values.max()!!
    
    var ans = map.filter { it.value == max }.map { it.key }.sorted().joinToString("\n")
    println(ans)
}


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

using namespace std;

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

int main(void) {
    char c;
    cin >> c;

    char ans;

    switch(c) {
        case 'A':
        ans = 'T';
        break;
        case 'C':
        ans = 'G';
        break;
        case 'G':
        ans = 'C';
        break;
        case 'T':
        ans = 'A';
        break;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  int a = 0;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(A[i] == 1) cnt++;
    else cnt = 0;
    a = max(a, cnt);
  }
  cout << a + 1 << "\n";
  return 0;
}


Measured memory_bytes: 3188
import numpy as np

N,M= map(int, input().split())
A = np.array(sorted(list(map(int , input().split()))))
diff = np.diff(A)
sort_list = list(np.argsort(diff)[::-1])
dev_place = sorted(sort_list[:N-1]) + [len(A)]
start_point = 0
ans = 0

for i in dev_place:
	tmp = A[start_point:i+1]
	ans += max(tmp)- min(tmp)
	start_point = i+1

print(ans)

Measured memory_bytes: 23096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
 int N,K,wa;
 cin>>N>>K;

 for(int i=0;i<N;i++){
  int x;
  cin>>x;
  wa+=2*min({x,abs(K-x)});
 }
 cout<<wa<<endl;
 return 0;
}

Measured memory_bytes: 256
//I am so vegetable
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define _for(i,a,b) for(ll i = (a);i<(b);++i)
#define _defor(i,a,b) for((i) = (a);(i)<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
//#define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 105;
const int MOD = 998244353;
const double exps = 1e-6;
int main() {
#ifdef _LOCAL_
	ifstream cin("E:\\acm dream\\in.txt");
	ofstream cout("E:\\acm dream\\out.txt");
#endif
	//srand((unsigned)time(nullptr));
	FIO;
	ll n, a, b; cin >> n >> a >> b;
	ll res = n - a - b;
	ll sum = 0;
	if (a == 0)sum = 0;
	else if (n <= a + b)sum = n > a ? sum = a : sum = n;
	else {
		ll a1 = res / (a + b) * a;
		ll a2 = (res - res / (a + b) * (a + b) >= a ? a : res - res / (a + b) * (a + b));
		sum = a1 + a2 + a;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n;
  m = n / 1000 * 1000;
  if ((n / 10 % 111) == 0) cout << "Yes" << endl;
  else if ((n - m) % 111 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int i, rs;
int MOD = 1e9 + 7;

int main() {
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;
  for(rs = i = 1; i <= n; ++i) rs = (1LL * rs * i) % MOD;

  cout << rs << '\n';

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

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

int main(int argc, char const* argv[])
{
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> a;
  for(int i = 0; i < n; i++){
    ll y;
    cin >> y;
    a.pb(abs(y - x));
  }
  ll res = a[0];
  for(int i = 1; i < n; i++)res = gcd(res, a[i]);
  cout << res << endl;
	return 0;
}


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

int main() {

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

    int n;
    cin >> n;

    string s;

    while (n != 0) {
        int r = n % 2;
        if (r < 0)
            r += 2;

        if (r == 1) {
            s += '1';
        } else {
            s += '0';
        }

        n = (n - r) / (-2);
    }

    reverse(s.begin(), s.end());

    if (s.empty()) {
        s = '0';
    }

    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll a=0,b=0;
	for(i=0;i<s.length();i++)
	{
		if(s[i]=='W')
			a++;
		else
			b++;
	}
	ll c=0,d=0;
	for(i=0;i<b;i++)
	{
		if(s[i]=='W')
			c++;
		else
			d++;
	}
	//cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	ll r=0,w=0;
	ll h1r = d;
	ll h1w = c;
	ll h2r = b - h1r;
	ll h2w = a - h1w;
	ll ans = 0;
	if(h1r==b)
		cout<<0<<endl;
	else
	{
		ans += min(h1w,h2r);
		h1r += min(h1w,h2r);
		if(h1r==b)
			cout<<ans<<endl;
		else
			cout<<ans + (b-h1r)<<endl;
	}
	
	
	


	
	return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, A, B, C, D; 
  cin >> N >> A >> B >> C >> D;

  A = abs(A-B);

  bool ans = false;
  REP(i, N){
    if(IN(C*i-D*(N-i-1), A, D*i-C*(N-i-1)+1)) ans = true;
  }

  ans? YES: NO;

  return 0;
}

Measured memory_bytes: 256
N,Y = map(int,input().split())
S = []
ans = []
tn = Y//10000
for i in range(tn+1):
    y1 = 0
    y1 = Y-10000*i
    fn = y1//5000
    for j in range(fn+1):
        y2 = 0
        y2 = y1 - 5000*j
        on = y2//1000
        if i+j+on == N:
            ans = [i,j,on]
            break
if len(ans)<=0:
    print("-1 -1 -1")
else:
    ans = [ str(x) for x in ans]
    print(ans[0]+" "+ans[1]+" "+ans[2]+" ")


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"l=[0]*2**17\n"
"for i in open(0).read().split()[2:]:l[int(i)]+=1\n"
"print('YNEOS'[any(i%2for i in l)::2])\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 20560
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> s;
	RREP(i, s.size())
	{
		cout << s[i];
	}
	cout << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	faster;

	ll n, m, t, in, tot = 0, time = 0;
	cin >> n >> m >> t;

	vector<ll> a(n + 1), b(m + 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int i, j;
	for (i = 0; i < n; i++) {
		if (a[i] + time <= t) {
			time += a[i];
			tot++;
		} else {
			break;
		}
	}
	i--;

	ll temp = tot;

	for (j = 0; j < m; j++) {
		time += b[j];
		temp++;
		while (i >= 0 && time > t) {
			time -= a[i];
			i--;
			temp--;
		}

		if (time <= t) {
			tot = max(tot, temp);
		} else {
			break;
		}
	}

	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 6328
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();

    let mut ans:u32 = 0;
    for i in 1..n+1 {
        let mut cnt:u32 = 0;
        let mut i = i;
        loop {
            i /= 10;
            cnt += 1;
            if i == 0 {break}
        }
        if cnt % 2 != 0 { ans += 1; }
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
using namespace std;

int main(){
    int n,m,tmp,tmp2,ans;
    while(cin >> n >> m,m||n){
        ans = 0;
        bool ju[m+1],ju2[m+1];
        memset(ju,false,sizeof(ju));
        memset(ju2,false,sizeof(ju2));
        vector <pair<int,int> > vec;
        for(int i=0;i<m;i++){
            cin >> tmp >> tmp2;
            vec.push_back(make_pair(tmp,tmp2));
        }
        for(int i=0;i<m;i++){
            if(vec[i].first == 1) ju[vec[i].second] = true;
            else if(vec[i].second == 1) ju[vec[i].first] = true;
        }
        for(int i=0;i<m;i++){
            if(ju[vec[i].first]) ju2[vec[i].second] = true;
            else if(ju[vec[i].second]) ju2[vec[i].first] = true;
        }
        for(int i=2;i<=m;i++){
            if(ju[i] || ju2[i]) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1348
import java.util.*;
import java.io.*;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), k = scan.nextInt();
        
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = scan.nextInt();
        
        boolean[] dp = new boolean[k + 1];
        dp[0] = false;
        for (int i = 1; i <= k; i++)
            for (int j = 0; j < arr.length; j++)
                if (i - arr[j] >= 0 && dp[i] != true)
                    dp[i] = !dp[i - arr[j]];

        if (dp[k])
            System.out.println("First");
        else
            System.out.println("Second");
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i=0; i < n; i++){
        set<string> s;
        string t;
        cin >> t;
        for(int j=1; j < t.size(); j++){
            string r, l;
            r = t.substr(0, j);
            l = t.substr(j);
            s.insert(r+l);
            s.insert(l+r);
            reverse(r.begin(), r.end());
            s.insert(r+l);
            s.insert(l+r);
            reverse(l.begin(), l.end());
            s.insert(r+l);
            s.insert(l+r);
            reverse(r.begin(), r.end());
            s.insert(r+l);
            s.insert(l+r);
        }
        cout << s.size() << endl;
    }
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int x1 = h1*60+m1;
  int x2 = h2*60+m2;
  int r = x2 - x1;
  cout << max(0,r-k) << endl;
}

Measured memory_bytes: 3600