akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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 (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a+b<c ? "No\n" : "Yes\n") ;  
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n+1,0),b(n+1,0);
    rep(i,m){
      int f;
      string s;
      cin >> f >> s;
      if (s=="AC"){
        a[f]=1;
      }
      else{
        if (a[f]==0) b[f]++;
      }
    }
    int y=0,u=0;
    rep(i,n){
      if (a[i+1]==1){
        y++;
        u+=b[i+1];
      }
    }
    cout << y << " " << u << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a1 = new int[n];
        int[] a2 = new int[n];

        for (int i = 0; i < n; i++) {
            a1[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            a2[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 1; i < n + 1; i++) {
            int n1 = 0;
            int n2 = 0;
            for (int j = 0; j < i; j++) {
                n1 += a1[j];
            }
            for (int k = i -1; k < n; k++) {
                n2 += a2[k];
            }
            sum = Math.max(sum, n1 + n2);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int D = in.nextInt();
            System.out.print("Christmas");
            for (int i = D; i < 25; i++) {
                System.out.print(" Eve");
            }
            System.out.println();
        }
    }
}


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

int main(){
  int N, M;
  int a, b;
  cin >> N >> M;
  vector<vector<int>> adj(N+1);
  while(cin>>a>>b){
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  
  //bfs ***********
  vector<bool> marked(N+1, false);
  queue<int> data;
  vector<int> distance(N+1, -1);

  distance[1] = 0;
  data.push(1);
  marked[1] = true;
  
  while(data.size()>0){    
    int v = data.front();
    data.pop();
    for(int w: adj[v]){
      if(!marked[w]){
	marked[w] = true;
	data.push(w);
	distance[w] = distance[v] + 1;
      }
    }
  }

  if (distance[N] == 2)
    cout <<"POSSIBLE"<<endl;
  else
    cout<<"IMPOSSIBLE"<<endl;
  
  return 0;
}

Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
string S;

int main() {
  cin >> N >> S;

  int i = 0;
  int ans = 0;
  while (i < N) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      ans++;
      i += 3;
    } else {
      i++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
    ll n, m;
    cin >> n >> m;
    if (n * m == 1)
        cout << 1 << endl;
    else if (n == 1)
        cout << max(0ll, m - 2) << endl;
    else if (m == 1)
        cout << max(0ll, n - 2) << endl;
    else
        cout << max(0ll, n * m - 2 * m - 2 * n + 4) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

int main()
{
  int n;
  cin>>n;
  vector<int> v;
  int a, cnt = 1;
  rep(i, 0, n) cin>>a, v.pb(a);
  sort(v.begin(), v.end(), greater<int>());
  int curr = v[0];
  rep(i, 1, n)
  {
    if(v[i] != curr) cnt++, curr = v[i];
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W, A, B; cin >> H >> W >> A >> B; 
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if((i < B && j < A) || (i >= B && j >= A)) cout << 1; 
			else cout << 0; 
		}
		cout << endl; 
	}
}

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

int main() {
  int N;
  cin>>N;
  int n=0,m=0;
  vector<int>vec(N);
  rep(i,N){
    cin>>vec.at(i);
  }
  rep(i,1000000000){
    rep(i,N){
      if(vec.at(i)%2==0){
      m++;
      vec.at(i)=vec.at(i)/2;
      }
    }
    if(m==N){
      n++;
    }
    if(m!=N){
      break;
    }
    m=0;
  }
  cout<<n<<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  4 19:37:51 2020

@author: Kanaru Sato
"""

n = int(input())
a = list(map(int, input().split()))
dic = {}

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

count = 0
for nums in dic:
    count += (dic[nums]*(dic[nums]-1))//2

for i in range(n):
    print(count-(dic[a[i]]-1))

Measured memory_bytes: 25644
#include <stdio.h>
#include <stdlib.h>

#define NIL -1

typedef struct{ 
  int parent; // ???
  int left; // ???????????????
  int right;// ????????????
  int k; // ???????????°
}Node;

Node T[100000];

int calculateDepth(int);
void PrintType(int);
void PrintDegree(int);

int main(){
  int n, i, j, v, v2;
  int id, k;


  scanf("%d", &n);

  //T = (Node *)malloc(sizeof(Node) * n);

  for(i=0; i<n; i++){
    T[i].parent = -1;
    T[i].left = -1;
    T[i].right = -1;
  }

  for(i=0; i<n; i++){
    scanf("%d%d", &id, &k);
    T[id].k = k;
     for(j=0; j<T[id].k; j++){
       scanf("%d", &v);
      if(j == 0){
	T[id].left = v;
	T[v].parent = id;
	v2 = v;
      }else{
	T[v].parent = id;
	T[v2].right = v;
	v2 = v; 
      }
     }
  }
  
  for(i=0; i<n; i++){
    printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, calculateDepth(i));
    PrintType(i);
    PrintDegree(i);
  }

  return 0;
}

int calculateDepth(int n){
  int i, parent;

  if(T[n].parent == -1) return 0;

  parent = T[n].parent;

  for(i=1; T[parent].parent != -1; i++){
    parent = T[parent].parent;
  }
  return i;

}

void PrintType(int n){
  if(T[n].parent == -1) printf("root, ");
  else if(T[n].left == -1) printf("leaf, ");
  else printf("internal node, ");
}

void PrintDegree(int n){
  int i, right;

  printf("[");

  for(i=0; i<T[n].k; i++){

    if(T[n].k == 1){
      printf("%d",T[n].left);
      break;
    }

    if(i == 0){
      printf("%d", T[n].left);
      right = T[T[n].left].right;
    }else if( i == T[n].k - 1){
      printf("%d", right);
      break;
    }else{
      printf("%d", right);
      right = T[right].right;
    }
    printf(", ");
  }

  printf("]\n");

}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

 /* Coding Space*/
int main(){
  int n; cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(ALL(a));
  int ans = n;
  ll now = 0;
  ll tmp = 0;
  rep(i,n){
    if(i == 0) now += a[i],tmp++;
    else{
      if(now*2 < a[i]){
        ans -= tmp;
        tmp = 0;
      }
      now += a[i];
      tmp++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <cstdio>

int main() {
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  if (C == 0) {
    printf("YES\n");
    return 0;
  }

  for (int i=1; i<1000; ++i)
    if (i*A % B == C) {
      printf("YES\n");
      return 0;
    }

  printf("NO\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,A,T;
  cin >> N;
  T=0;
  if (N%2==1) {cout << 0 << endl;}
  else {
    long long A=5;
    while (N>=A) {
      T+=N/(A*2);
      A*=5;
    }
    cout << T << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
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;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int N,M,C; cin>>N>>M>>C;
    int B[M]; rep(i,M) cin >> B[i];
    int res=0;
    rep(i,N){
        int sum = 0;
        rep(j,M){
            int A; cin >> A;
            sum += B[j]*A;
        }
        if(sum+C>0) res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int N; cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    vector<int> dp(N,0);
    for ( int i = N-2; i>=0;i--){
        if (H[i] >= H[i+1]) dp[i]=dp[i+1]+1;
        else dp[i] = 0;
    }
    cout << MAX(dp) << endl;
}


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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second	
typedef pair < int , int > pp;
const int mod = 998244353;
const int N   = 4e3 + 3;

int C[N][N], M[N][N][3];

int f(int i, int k, int h){
    if(i == 0) return k == 0;
    int &r = M[i][k][h];
    if(r != -1) return r;
    r = f(i-1,k,0);
    if(k == 0) return r;
    
    if(h == 0) r = (r + f(i,k-1,1) + f(i,k-1,2)) % mod;
    if(h == 1) r = (r + f(i,k-1,1)) % mod;
    if(h == 2) r = (r + f(i,k-1,2)) % mod;
    return r;
}

int g(int a, int b){
    if(a < 0 || b < 0) return 0;
    if(a == 0) return 1;
    if(b == 0) return 0;
	return C[a+b-1][b-1];
}

signed main(){
	int n, k;
    cin >> k >> n;
    for(int i=0; i<N; i++)
        for(int j=C[i][0]=1; j<=i; j++)
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
    
    
    memset(M , -1 , sizeof M);
    for(int i=2; i<=k+k; i++){
        int ans = 0;
        for(int j=0; j<=n; j++){
            if(i & 1){
                int mn = min(i/2, k-i/2);
                ans = (ans + f(mn, j, 0) * g(n-j, k-2*mn)) % mod;
            }
            else{
                int mn = min(i/2-1, k-i/2);
                ans = (ans + f(mn, j, 0) * g(n-j, k-2*mn-1)) % mod;
                if(j < n)
                	ans = (ans + f(mn, j, 0) * g(n-j-1, k-2*mn-1)) % mod;
            }
        }
        
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 501120
#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 ALL(v) v.begin(), v.end()
typedef long long ll;
int main(){
    int h,w,a,b; cin >> h >> w >> a >> b;
    vector<vector<int>> s(h, vector<int>(w));
    rep(i,b){
        rep(j,a){
            s[i][j] = 1;
        }
    }
    FOR(i,b,h){
        FOR(j,a,w){
            s[i][j] = 1;
        }
    }

    rep(i,h){
        rep(j,w){
            cout << s[i][j];
        }
        cout << endl;
    }
    cout << endl;
}


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

typedef long long ll;
typedef complex<double> Vec;

ll N;
vector<Vec> Vs;
const double EPS = 1e-10;
double R;

bool good(Vec v, Vec w, int sign) {
  Vec dotcross = conj(v) * w;
  double dot = dotcross.real(), cross = dotcross.imag();
  cross *= sign;
  return cross > EPS || (abs(cross) <= EPS && dot > EPS);
}

int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    Vs.push_back(Vec(x, y));
  }
  for (Vec v : Vs) {
    for (int sign = -1; sign <= 1; sign += 2) {
      Vec sum;
      for (Vec w : Vs) {
        if (good(v, w, sign)) {
          sum += w;
        }
      }
      R = max(R, abs(sum));
      sum -= v;
      R = max(R, abs(sum));
    }
  }
  cout << setprecision(15) << R << endl;
  return 0;
}


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

int digitSum(int num){
	int sum = 0;
	while( num != 0){
		sum += num % 10;
		num /= 10;
	}
	return sum;
}

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int sum = 0;
	for(int i=0; i<=n; ++i){
		if( a<=digitSum(i) && digitSum(i)<=b ) sum += i;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	int N, T, c, t, i, cmin = 1001;
	cin >> N >> T;
	REP(i,N){
		cin >> c >> t;
		if (t <= T) {
			cmin = min(cmin, c);
		}
	}
	if (cmin < 1001)
		cout << cmin << endl;
	else
		cout << "TLE" << endl;
}

Measured memory_bytes: 384
import sys
from math import gcd


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    P = (A1 - B1) * T1
    Q = (A2 - B2) * T2

    if P > 0:
        P = P * (-1)
        Q = Q * (-1)

    if P + Q < 0:
        print(0)
        return
    elif P + Q == 0:
        print("infinity")
        return
    else:
        S = (-P) // (P + Q)
        T = (-P) % (P + Q)
        if T == 0:
            print(2 * S)
        else:
            print(2 * S + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
x = input()
y = input()

x = list(x)
y = list(y)
x_ = x
y_ = y
x_ = reversed(x)
y_ = reversed(y)
x_ = list(x_)
y_ = list(y_)


if y_ == x and x_ == y:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 61864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    int N,K;cin>>N>>K;
    int cnt=0;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        if(a>=K) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;

#define N 100000
#define M 100

int main(){
	int i,j,n, ans = 0;
	char  s[M], t[M], u[N];

	cin >> n;

	for(i = 0; i < n;i++){
		cin >> s[i];
	}

	for (i = 0; i < n; i++) {
		cin >> t[i];
	}

	for (i = 0; i < n; i++) {
		u[2 * i] = s[i];
		u[2 * i + 1] = t[i];
	}

	for (i = 0; i < 2*n; i++) {
		cout << u[i];
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

const ll mod = 1000000007;

struct {
	int a;
	int b;
	int c;
	int d;
} Q;

int n,m;
int q;
int a[50], b[50], c[50], d[50];

int solve(vector<int> can) {
	if (can.size() == n) {
		int sum_d = 0;
		rep(i, q) {
			if (can[b[i]] - can[a[i]] == c[i]) {
				sum_d += d[i];
			}
		}
		return sum_d;
	}

	int last = can.size() > 0 ? can[can.size() -1] : 0;
	int max_d = 0;
	for (int i = last; i < m; i++) {
		vector next = can;
		next.push_back(i); 
		max_d = max(max_d, solve(next));
	}
	return max_d;
}

int main() {

	cin >> n >> m >> q;

	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	vector< int> can;

	cout << solve(can) << endl;

	return 0;
}


Measured memory_bytes: 3172
n,y=map(int,input().split())
max_10000=y//10000
max_5000=y//5000
ans=0
for i in range(max_10000+1):
  for j in range(max_5000+1):
    if i+j<=n:
      if i*10000+j*5000+1000*(n-i-j)==y:
        print(i,j,n-i-j)
        break
  else:
    continue
  break
else:
  print(-1,-1,-1)

Measured memory_bytes: 3060
def f(n):
    dp = [0] * (n * 10 ** 4 + 1)
    bs = [list(map(int, input().split())) for _ in range(n)]
    bs.sort(key=lambda x: x[0] + x[1])
    for w, s, v in bs:
        for i in range(w + s, w - 1, -1):
            dpw = dp[i - w] + v
            if dpw > dp[i]:
                dp[i] = dpw
    print(max(dp))


n = int(input())
f(n)


Measured memory_bytes: 82036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    if(K % 2 == 0){
        ans = (N/K) * (N/K) * (N/K);
        ll tmp = N / K;
        if(N % K >= K / 2){
            tmp++;
        }
        ans += tmp * tmp * tmp;
    }
    else{
        ans = (N/K) * (N/K) * (N/K);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3744
n=int(input())
a=list(map(int,input().split()))
list=[0]*8
god=0
for i in range(n):
	if a[i]<400:
		list[0]=1
	elif a[i]<800:
		list[1]=1
	elif a[i]<1200:
		list[2]=1
	elif a[i]<1600:
		list[3]=1
	elif a[i]<2000:
		list[4]=1
	elif a[i]<2400:
		list[5]=1
	elif a[i]<2800:
		list[6]=1
	elif a[i]<3200:
		list[7]=1
	else:
		god+=1
color=list.count(1)

min_c=color
if min_c==0:
	min_c+=1
max_c=color+god
if max_c>8:
	mac_c=8
		
print(min_c,max_c)




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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll a, b, t;

    cin >> a >> b >> t;
    
    cout << (floor((t+0.5)/a))*b << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=[list(map(int, input().split())) for _ in range(n)]
c=[list(map(int, input().split())) for _ in range(m)]
for i in p:
    d=[abs(i[0]-c[j][0])+abs(i[1]-c[j][1]) for j in range(len(c))]
    print(d.index(min(d))+1)

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

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] array = new int[n];
		for(int i = 0; i < n; i++)
			array[i] = sc.nextInt();
		
		int m1 = 0, i1 = 0, m2 = 0, i2 = 0;
		for(int i = 0; i < n; i++) {
			if(array[i] >= m1) {
				m2 = m1;
				i2 = i1;
				m1 = array[i];
				i1 = i;
			} else if(array[i] > m2) {
				m2 = array[i];
				i2 = i;
			}
		}
		
		for(int i = 0; i < n; i++) {
			if(i == i1)
				System.out.println(m2);
			else
				System.out.println(m1);
		}
	}
}


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

class A {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int A = st[0];
        int B = st[1];

        if (A == B) {
            Console.WriteLine("Yes");
        } else {
            Console.WriteLine("No");
        }

        //Console.WriteLine();
    }
}

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

const int N=1e5+10;
vector <int> E[N];
int color[N],cnt[3];

int main(){
    ios::sync_with_stdio(false);
    queue<int> que;
    int n,x,y;
    cin>>n;
    for(int i=1;i<n;i++){ 
        cin>>x>>y;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    color[1]=1,color[n]=2;//标记颜色 
    que.push(1);//1点先手 
    que.push(n);//n点后手 
    while(!que.empty()){
        int tmp=que.front();
        que.pop();
        cnt[color[tmp]]++;//记录标记颜色的数量
    //遍历相邻的所有点,因为把对手堵住后这些点还是需要染色的.  
        for(int i=0;i<E[tmp].size();i++){
            int v=E[tmp][i];
            if(color[v]) continue;
            color[v]=color[tmp];
            que.push(v);
        }
    }
    //因为1点先手,所以数量相同的时候,1点会输. 
    if(cnt[2]>=cnt[1]) cout<<"Snuke"<<endl;
    else cout<<"Fennec"<<endl;
    return 0;
}

Measured memory_bytes: 6272
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b; cin >> a >> b;
    if(a+b==3)cout << 3 ENDL;
    if(a+b==4)cout << 2 ENDL;
    if(a+b==5)cout << 1 ENDL;
    
    return 0;
}

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

int main(){
    string st;
    cin >> st;
    bool f = true;
    for(int i=0;i<3;i++){
        if(st[i] == st[i+1]){
            f = false;
            break;
        } 
    }
    if(f) cout << "Good" << endl;
    else cout << "Bad" << endl;
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n);
    int total = 0;
    for (int i = 0; i < k; i++) total += p[i];
    cout << total << '\n';
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<string>

const int COLS = 10;
const int ROWS = 30;

using namespace std;

int RunAmida(int Amida[][COLS+2], int n, int d, int st){
	int ret = st;
	for(int i = 0; i < d; i++){
		for(int j = 1; j < n; j++){
			if(Amida[i][j] == 1){
				if(ret == j){
					ret = j + 1;
					break;
				}
				if(ret == j + 1){
					ret = j;
					break;
				}
			}
		}
	}
	return ret;
}

int main(void){
	while( true ){
		int Amida[ROWS][COLS+2] = {{0,},};
		bool Found = false;
		int n, m, s, d;

		cin >> n;
		if( n == 0 ) break;
		cin >> m >> s >> d;
		for(int i = 0; i < d; i++){
			string s;
			
			cin >> s;
			if( cin.eof() ) break;
			for(int j = 0; j < n - 1; j++){
				if( s[j] == '1' ) Amida[i][j+1] = 1;
			}
		}

		/* no additional bar */
		if( s == RunAmida(Amida, n, d, m) ){
			cout << "0\n";
			Found = true;
		}

		/* one additional bar */
		for(int i = 0; i < d && !Found; i++){
			for(int j = 1; j < n && !Found; j++){
				if( Amida[i][j-1] == 0 && Amida[i][j] == 0 && Amida[i][j+1] == 0 ){
					Amida[i][j] = 1;
					if( s == RunAmida(Amida, n, d, m) ){
						cout << i + 1 << " " << j << endl;
						Found = true;
						break;
					}else Amida[i][j] = 0;
				}
			}
		}

		if( !Found ) cout << "1\n";

	}
	return 0;
}

Measured memory_bytes: 0
n = gets.to_i
t,a = gets.strip.split.map(&:to_f)
num = gets.strip.split.map(&:to_i)
ary = []
n.times do |i|
  ary[i] = (t-num[i]*0.006-a).abs
end
puts ary.index(ary.min)+1

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

namespace AOJ1_4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            double r = double.Parse(Console.ReadLine());
            double S = r * r * Math.PI;
            double R = 2 * r * Math.PI;
            Console.WriteLine(S + " " + R);
        }
    }
}



Measured memory_bytes: 15952
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;
struct com{
	int t,s,d;
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,m;
	while(cin>>n>>m,n){
		vector<com> computer(m);
		vector<bool> infected(n,false);
		infected[0] = true;
		REP(i,m){
			int t,s,d;
			cin >> t >> s >> d;
			computer[i] = {--t,--s,--d};
		}
		sort(computer.begin(),computer.end(),[](com a,com b){
				return a.t < b.t;
			});
		REP(i,m){
			if(infected[computer[i].s]){
				infected[computer[i].d] = true;
			}
		}
		cout << accumulate(infected.begin(),infected.end(),0) << endl;
	}
  return 0;
}

Measured memory_bytes: 3392
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>

#define int long long

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for (auto& x : vec) cin >> x;
    int ans = 1000;
    for (int i = 1; i < n; ++i) {
        if (vec[i - 1] < vec[i]) ans = ans / vec[i - 1] * vec[i] + ans % vec[i - 1];
    }
    cout << ans;
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}

Measured memory_bytes: 3172
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    char x;
    cin >> x;
    x++;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] argv){
		//divisor();
		infinity();
	}
	static Scanner scan = new Scanner(System.in);
	public static void yard(){
		int a = scan.nextInt(), b = scan.nextInt();
		int area = (a-1)*(b-1);
		System.out.println(area);
	}
	//input: 1<=n<=200
	//n以下の奇数の内，約数をちょうど８個持つものの数を出力
	//①2*4, 2*2*2の３通り．
	public static void divisor(){
		int n = scan.nextInt();
		int count = 0;
		int[] prime = {3,5,7,11,13,17,19,23,29,31};//200以下の際に候補になりえる素数．
		
		//②指数が1と3のパターン
		if(n>=135){//a*3^3のパターン
			count++;
			if(n>=189)
				count++;
		}
		
		//③のパターン．全探索する．
		for(int i=0;i<prime.length;i++){
			for(int j=i+1;j<prime.length;j++){
				for(int k=j+1;k<prime.length;k++){
					if(prime[i]*prime[j]*prime[k]<=n)
						count++;
				}
			}
		}
		System.out.println(count);
	}
	public static void infinity(){
		String s = scan.next();
		Long k = scan.nextLong();
		char c;
		Long flag;
		for(int i=0;i<k;i++){
			if(s.charAt(i)!='1'){
				System.out.println(s.charAt(i));
				return;
			}
		}
		System.out.println("1");
	}
}

Measured memory_bytes: 23124
n = int(input())
b = {}
cities = []
for i in range(n):
    c, r = tuple([i for i in input().split(' ')])
    cities.append(c)
    if c in b:
        b[c].append((i + 1, int(r)))
    else:
        b[c] = [(i + 1, int(r))]

cities = list(set(cities))
cities.sort()
for c in cities:
    l = b[c]
    for i in sorted(l, key=lambda x: x[1], reverse=True):
        print(i[0])


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}


int main(){
  int H, A; cin >> H >> A;
  int ans = H / A;
  if (H % A != 0) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, A = map(int, input().split())
x = [int(i) for i in input().split()]
ans = 0

dp = [[[0]*(50*N+1) for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1 
for j in range(1,N+1):
  for k in range(N+1):
    for s in range(50*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s>=x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
for k in range(1,N+1):
  ans += dp[N][k][k*A]
print(ans)

Measured memory_bytes: 93004
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

string getAns(string S,string T)
{
    for(int i=0;i<S.size();i++)
        if(S[i]!=T[i])return "No";
    return "Yes";
}

int main()
{
    string S,T;
    cin>>S>>T;
    cout<<getAns(S,T);
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n, m;
    cin >> n >> m;
    vector<set<ll>> shown(n);
    vector< vector<ll> > G(n);
    rep(i, 0, n+m-1) {
        ll from, to;
        cin >> from >> to;
        from--; to--;
        G[from].push_back(to);
        shown[to].insert(from);
    }
    ll rt;
    rep(i, 0, n) if(shown[i].empty()) rt = i;
    vector<ll> rank(n, -1), access(n, 0), parent(n, -1);
    rank[rt] = 0;
    parent[rt] = -1;
    queue<ll> que;
    que.push(rt);
    while(!que.empty()){
        auto q = que.front();
        // cerr << q << endl;
        que.pop();
        for(auto g : G[q]) {
            access[g]++;
            if(access[g] < shown[g].size()) continue;
            ll mx = -100, prt = -1;
            for(auto e : shown[g]) {
                if(mx < rank[e]) {
                    mx = rank[e];
                    prt = e;
                }
            }
            parent[g] = prt;
            rank[g] = mx+1;
            que.push(g);
        }
    }
    rep(i, 0, n) cout << parent[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 20420
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int ans=0;
    REP(i,n) {
        int a;
        cin >> a;
        ans+=a-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int dp[1001][1001];
int main(){
	string t,b;
	cin>>t>>b;
	dp[0][0]=0;
	int MOD=1000000007;
	for(int i=1;i<=b.size();i++){
		for(int j=1+i-1;j<=t.size();j++){
		
			 if(b[i-1]==t[j-1]){
				if(i==1)dp[i][j]=(dp[i][j-1]+1)%MOD;
				else dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%MOD;
			}
			else dp[i][j]=dp[i][j-1]%MOD;
		}
	}
	cout<<dp[b.size()][t.size()]%MOD<<endl;
	return 0;
}

Measured memory_bytes: 7132
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,ans,vis[200001];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&k);
		vis[k]++;
	}
	for (int i=-1;i<=100001;i++)ans=max(ans,vis[i]+vis[i-1]+vis[i+1]);
	printf("%d",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#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, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()



template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


double pi = 3.141592653589793;
int main() {
    double a,b,h,n;
    cin >> a >> b >> h >> n;

    double x = (60 * h + n) /2.0;
    double y = 6.0 * n;
    double z = min(abs(x - y), 360 - abs(x - y));
    double ans = sqrt(a*a + b*b - 2*a*b*cos(z / 180.0 * pi));
    printf("%.16f",ans);
}


Measured memory_bytes: 4196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n;
vector<vector<int>> vec(10010);
vector<int> m, a, b;
bool bo[10010] = { false };
int ans[100010];
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a1, b1;
		cin >> a1 >> b1;
		a.emplace_back(a1);
		b.emplace_back(b1);
		vec[a1].emplace_back(b1);
		vec[b1].emplace_back(a1);
	}
	for (int i = 0; i < n; i++) {
		int m1;
		cin >> m1;
		m.emplace_back(m1);
	}
	sort(m.rbegin(), m.rend());
	queue<int> que;
	que.push(1);
	bo[1] = true;
	ans[1] = m[0];
	int now = 1;
	while (!que.empty()) {
		int t = que.front();
		for (int i = 0; i < vec[t].size(); i++) {
			if (!bo[vec[t][i]]) {
				que.push(vec[t][i]);
				ans[vec[t][i]] = m[now];
				now++;
				bo[vec[t][i]] = true;
			}
		}
		que.pop();
	}
	int sum = 0;
	for (int i = 0; i < n - 1; i++) {
		sum += min(ans[a[i]], ans[b[i]]);
	}
	cout << sum << endl;
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


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

int main() {
    long long int N;
    cin >> N;
    long long int M =floor(sqrt(N))+1;

    long long int d = N;
    for(long long int i=1; i<=M; i++){
        if(N%i==0){
            d = min( d, i + N/i -2);
        }
    }
    cout << d << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define fastio ios_base::sync_with_stdio(false)

typedef double db;
typedef long long ll;
typedef unsigned long long ull;

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



const int MOD = 1e9 + 7;
const int maxn = 1e3 + 5;

char input[maxn][maxn];


int main() {
	fastio;
	int h, w; cin >> h >> w;
	int dp[h + 1][w + 1];
	memset(dp, 0, sizeof(dp));
	
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) 
			cin >> input[i][j];
	}

	dp[0][0] = 1;

	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(i == 0 and j == 0)
				continue;
			if(input[i][j] == '.') {
				if(i == 0) {
					dp[i][j] = dp[i][j - 1] % MOD;
					continue;
				}
				if(j == 0) {
					dp[i][j] = dp[i - 1][j] % MOD;
					continue;
				}
				else {
					dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;  
				}
		  }
		}
	}

	cout << dp[h - 1][w - 1] << endl;
	return 0;
}

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

int main(){
  ll l,r,rl,i,j,ans=2019;
  cin >>l >>r;
  rl = r-l;
  if(rl>2018) ans = 0;
  else{
    for(i = 0; i<=rl; i++){
      for(j = i+1; j<=rl; j++) ans = min(ans, (l+i)*(l+j)%2019);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



double calcdist(double vi, double vf, double vm, double T){
    double dist;
    double vm2 = (T + vi + vf) / 2.0;
    if(vm2 > vm){
        dist = (vm + vi) * (vm - vi) / 2.0 + (vm + vf) * (vm - vf) / 2.0 + vm * (T - 2.0 * vm + vi + vf);
    }else{
        dist = (vm2 + vi) * (vm2 - vi) / 2.0 + (vm2 + vf) * (vm2 - vf) / 2.0;
    }
    return dist;
}
 
signed main(){
 
    int N;
    cin >> N;
    vector<int> t(N), v(N);
    readv(t);
    readv(v);
 
    vec v_max(N + 1);
    v_max[0] = 0;
    FOR(i, 1, N){
        v_max[i] = min(v[i - 1], v[i]);
    }
    v_max[N] = 0;

    priority_queue<Pii> que;
    REP(i, N + 1) que.push(Pii(-1 * v_max[i], i));

    while(!que.empty()){
        Pii p = que.top(); que.pop();
        int v0 = -1 * p.first;
        int i0 = p.second;
        if(v0 > v_max[i0]) continue;
        if(i0 != 0){
            if(v_max[i0] + t[i0 - 1] < v_max[i0 - 1]){
                v_max[i0 - 1] = v_max[i0] + t[i0 - 1];
                que.push(Pii(-1 * v_max[i0 - 1], i0 - 1));
            }
        }
        if(i0 != N){
            if(v_max[i0] + t[i0] < v_max[i0 + 1]){
                v_max[i0 + 1] = v_max[i0] + t[i0];
                que.push(Pii(-1 * v_max[i0 + 1], i0 + 1));
            }
        }
    }
 
    double ans = 0.0;
    REP(i, N) ans += calcdist((double)v_max[i], (double)v_max[i + 1], (double)v[i], t[i]);
 
    cout << setprecision(10) << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define pp pair<ll,ll>
#define maxn 100005
#define mod 998244353
using namespace std;
void solve()
{
	ll x;
	cin >> x;
	ll ans = (x/500)*1000;
	x =x - (500*(x/500));
	ans += (x/5)*5;
	cout << ans;
}
int main()
{
	ll t=1,i=1;
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
    std::cout.precision(10);
    std::cout.setf( std::ios::fixed, std:: ios::floatfield ); 
	//cin >> t;
	//cin >> n;
	while(i<=t)
	{
		solve();
		i++;
	}
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

CB = []
for i in BC:
    CB.append([i[1], i[0]])

A.sort()
CB.sort(reverse=True)

cnt = 0
for i in CB:
    for j in range(i[1]):
        if cnt < N:
            if A[cnt] < i[0]:
                A[cnt] = i[0]
                cnt += 1
            else:
                print(sum(A))
                exit()
        else:
            print(sum(A))
            exit()

print(sum(A))

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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 (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int a,b,c,n;
	ll ans = 0;
	cin >> a>>b>>c>>n;
	for(int i=0;i<=n;i+=a){
		for(int j=0;i+j<=n;j+=b){
			if((n-i-j)%c==0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

bool check[1000010];

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        check[a[i]] = true;
    }
    sort(all(a));
    rep(i, n)
    {
        if (!check[a[i]])
            continue;
        if (i < n - 1 && a[i] == a[i + 1])
            check[a[i]] = false;
        for (int j = 2; j * a[i] < 1000010; j++)
            check[a[i] * j] = false;
    }
    int ans = 0;
    rep(i, 1000010) if (check[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 5848
#include <stdio.h>

int main(void){
  int d;
  scanf("%d", &d);
  d -= 25;
  if(d < 0) d = -d;
  char c[] = "Christmas";
  char e[] = "Eve";
  printf("%s ", c);
  for(int i = 0; i < d; i++){
    printf("%s ", e);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
import scala.collection.mutable
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val map = mutable.HashMap[Int,Int]()

  val n = in.readLine.toInt
  in.readLine.split(" ").map(_.toInt)
    .foreach(e => {
      if(!map.contains(e)) map += e -> 1
      else map(e) +=1
    })

  val x = map.keySet

  val ans = {
    x./:(0)((acc,e) => {
      val cnt = map.getOrElse(e-1,0) + map.getOrElse(e,0) + map.getOrElse(e+1,0)
      math.max(acc, cnt)
    })
  }

  println(ans)
}

Measured memory_bytes: 48348
def resolve():
    N, M = map(int, input().split())
    A = [list(input()) for _ in range(N)]
    B = [list(input()) for _ in range(M)]

    ans = 'No'
    for i in range(N):
        for j in range(N):
            if A[i][j] == B[0][0]:
                count = 0
                for k in range(M):
                    for l in range(M):
                        if i+k>= N or j+l>= N:
                            continue
                        if A[i+k][j+l] == B[k][l]:
                            count += 1
                    if count == M * M:
                        ans = 'Yes'
                        break
    print(ans)

resolve()


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

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = 0, t = 1;
    while (t<b) {
        t += a-1;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int a,b;
  	cin>>a>>b;
  
  	int c=a+b;
  	int d=a-b;
  	int e=a*b;
  
  	cout<<max(c,max(d,e))<<endl;
}

Measured memory_bytes: 256