akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  VI A(N);
  int X[N][N]={};
  int Y[N][N]={};
  rep(i,N){
    cin>>A[i];
    rep(j,A[i]){
      cin>>X[i][j]>>Y[i][j];
    }
  }
  ll cnt=1;
  rep(i,N) cnt*=2;
  int ans=0;
  rep(i,cnt){
    int F=1;
    int II=i;
    int Z[N]={};
    int M=0;
    rep(j,N){
      if(II%2){
        Z[j]=1;
        M++;
      }
      II/=2;
    }
    rep(j,N){
      rep(k,A[j]){
        if(Z[j]){
          if(Z[X[j][k]-1]!=Y[j][k]) F=0;
        }
      }
    }
    if(F) ans=max(ans,M);
  }
  cout<<ans<<endl;
}



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

    int all = 0;
    for(int i=0; i<n; i++) {
    	t[i] = sc.nextInt();
    	all += t[i];
    }
    int m = sc.nextInt();
    int[]p = new int[m];
    int[]x = new int[m];
    
    for(int i=0; i<m; i++) {
    	p[i] = sc.nextInt();
    	x[i] = sc.nextInt();
    }
    for(int i=0; i<m; i++) {
    	int ans = all - t[p[i]-1] + x[i];
    	
    	
    	System.out.println(ans);
    }
}
}

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

typedef long long int lli;

int main(void)
{
	lli n, x;
	scanf("%lld%lld", &n, &x);
	lli A[n], res = 0;
	for(lli i = 0;i < n;i++) scanf("%lld", &A[i]);

	for(lli i = 1;i < n;i++)
	{
		if(A[i]+A[i-1] > x)
		{
			res += min(A[i]-(x-A[i-1]), A[i]);
			A[i] = max(x-A[i-1], 0ll);
			if(A[i]+A[i-1] > x)
			{
				res += A[i-1]-(x-A[i]);
			}
		}
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

ll dp1[3010][3010];
ll dp2[3010][3010];

int main(){
    int n,t;
    cin >> n >> t;
    vector<int>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    for(int i=1;i<=n;i++){
        for(int j=0;j<=t-1;j++){
            chmax(dp1[i][j],dp1[i-1][j]);
            if(j-a[i-1]<0)continue;
            chmax(dp1[i][j],dp1[i-1][j-a[i-1]]+b[i-1]);
        }
    }
    for(int i=n;i>=1;i--){
        for(int j=0;j<=t-1;j++){
            chmax(dp2[i][j],dp2[i+1][j]);
            if(j-a[i-1]<0)continue;
            chmax(dp2[i][j],dp2[i+1][j-a[i-1]]+b[i-1]);
        }
    }
    ll ans = 0;
    rep(i,n){
        ll now = 0;
        rep(j,t){
            ll tmp = dp1[i][j]+dp2[i+2][t-1-j];
            chmax(now,tmp);
        }
        chmax(ans,now+b[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 141568
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;

ll mod = 1000000007;
ll times(ll x, ll y) {
  return (x * y) % mod;
}

ll add(ll x, ll y) {
  return (x + y) % mod;
}

ll fact_mod(ll x, ll n) {
  if(n == 0) return 1;
  return times(x, fact_mod(x, n - 1));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll max_digits = 60;
  ll n;
  cin >> n;
  ll digits[max_digits];
  for(int i = 0; i < max_digits; i++) {
    digits[i] = 0;
  }
  for(int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    for(int i = 0; i < max_digits; i++) {
      digits[i] += ((a >> i) & 1);
    }
  }
  ll result = 0;
  for(int j = 0; j < max_digits; j++) {
    ll base = fact_mod(2, j);
    result = add(result, times(base, times(digits[j], n - digits[j])));
  }
  cout << result << "\n";
  
  return 0;
}



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

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

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<int> l(n);
    vector<int> r(n);

    rep(i,n-1) {
        l[i+1] = gcd(l[i], a[i]);
    }
    for(int i = n-1; i >= 1; --i) {
        r[i-1] = gcd(r[i], a[i]);
    }
    int ans = 0;
    rep(i, n) ans = max(ans, gcd(l[i], r[i]));
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  double debt;
  int debt_i;
  cin >> n;
  debt = 100000;
  for (int i=0; i<n; i++) {
    debt *= 1.05;
    debt = ceil(debt/1000.0)*1000;
  }
  cout << (int)debt << endl;
}

Measured memory_bytes: 1164
#include<cstdio>
    #include<cmath>
    using namespace std;
    int gcd(int a, int b) {
      if (b == 0) return a;
      return gcd(b, a % b);
    }
    int n, x, g, X;
     
    int main() {
      scanf("%d%d%d", &n, &X, &x);
      g = x - X;
      for (int i = 1; i < n; i++) {
        scanf("%d", &x);
        g = gcd(x - X, g);
      }
      printf("%d\n", g>0?g:-g);
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

int main(){

	int N;
	cin>>N;
	
	vector<pair<long long,int>> P(N);
	
	for(int i=0;i<N;i++){
		cin>>P[i].first;
		P[i].second = i;
	}
	
	sort(P.rbegin(),P.rend());
	P.push_back({0,0});
	
	vector<long long> ans(N,0);
	
	for(int i=0;i<N;i++){
		if(i!=0)P[i].second = min(P[i].second,P[i-1].second);
		ans[P[i].second] += (P[i].first - P[i+1].first) * (i+1);
	}
	
	for(int i=0;i<N;i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4964
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double x1 = cosl(M_PI * 2 * (m / 60.0)) * b;
  double y1 = sinl(M_PI * 2 * (m / 60.0)) * b;
  double x2 = cosl(M_PI * 2 * (h / 12.0 + (m / 60.0 / 12.0))) * a;
  double y2 = sinl(M_PI * 2 * (h / 12.0 + (m / 60.0 / 12.0))) * a;
  cout.precision(17);
  cout << sqrtl((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) << "\n";
}

Measured memory_bytes: 4152
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 200 + 10
#define ll long long int
int N[MAXN];
int v[MAXN];
int w[MAXN];
ll dp[100000 + 10];
ll all_w = 0,all_v = 0;
const ll INF=(ll)1<<60;
int main()
{
    ll n, max_V;
    cin>>n>>max_V;
    for(int i = 0;i < n;++i)
    {
        cin>>w[i]>>v[i];
        all_w+=w[i];
        all_v+=v[i];
    }
    for(int i = 0;i < all_v;++i)
        dp[i] = INF;
    dp[all_v] = all_w;
    for(int i = 0;i < n;++i)
        for(int j = 0;j <= all_v;++j)
        {
            if(j - v[i] >= 0)
            {
                if(dp[j] - w[i] >= 0)
                      dp[j-v[i]]=min(dp[j-v[i]],dp[j]-w[i]);
            }
        }
    for(int i = all_v;i >= 0;--i)
    {
        if(dp[i] <=max_V)
        {
            printf("%d\n",i);
            break;
        }
    }
    return 0;


}


Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static int n;
	static int m;
	static int q;
	
	static int[] a;
	static int[] b;
	static int[] c;
	static int[] d;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		n = sc.nextInt();
		m = sc.nextInt();
		q = sc.nextInt();
		
		a = new int[q];
		b = new int[q];
		c = new int[q];
		d = new int[q];
		
		for (int i = 0; i < q; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
			
			a[i]--;
			b[i]--;
		}
		
		Queue<List<Integer>> que = new ArrayDeque<>();
		for (int i = 1; i <= m; i++) {
			List<Integer> list = new ArrayList<>();
			list.add(i);
			que.add(list);
		}
		
		int max = 0;
		
		while (!que.isEmpty()) {
			List<Integer> list = que.poll();
			
			int size = list.size();
			if (size == n) {
				max = Math.max(max, calcPoint(list));
				continue;
			}
			
			int lastNum = list.get(size - 1);
			for (int i = lastNum; i <= m; i++) {
				List<Integer> nList = new ArrayList<>();
				for (int j = 0; j < size; j++) {
					nList.add(list.get(j));
				}
				nList.add(i);
				que.add(nList);
			}
		}
		
		System.out.println(max);
	}
	
	static int calcPoint(List<Integer> list) {
		int sumD = 0;
		for (int i = 0; i < q; i++) {
			if (list.get(b[i]) - list.get(a[i]) == c[i]) {
				sumD += d[i];
			}
		}
		
		return sumD;
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,m,h;
ll res=0;
ll g[10][10];

bool check(ll i){
  ll win=0,lose=0,rest=0;
  rep(j,n)if(i!=j){
    if(g[i][j]==1)win++;
    if(g[i][j]==0)lose++;
    if(g[i][j]==-1)rest++;
  }
  if(win<=h&&lose<=h)return true;
  else return false;
}

void dfs(ll i,ll j){ // i<j
  if(i==n-1&&j==n){
    res++;
    return ;
  }
  ll ni,nj;
  if(j==n-1){
    ni=i+1; nj=ni+1;
  }else{
    ni=i; nj=j+1;
  }
  if(g[i][j]!=-1){
    if(check(i)&&check(j))dfs(ni,nj);
  }else{
    g[i][j]=0; g[j][i]=1;
    if(check(i)&&check(j))dfs(ni,nj);
    g[i][j]=1; g[j][i]=0;
    if(check(i)&&check(j))dfs(ni,nj);
    g[i][j]=-1; g[j][i]=-1;
  }
  return ;
}

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

  while(1){
    cin>>n;
    if(n==0)break;
    h=n/2;
    cin>>m;
    memset(g,-1,sizeof(g));

    rep(i,m){
      ll a,b;
      cin>>a>>b;
      a--;b--;
      g[a][b]=1;
      g[b][a]=0;
    }

    res=0;
    dfs(0,1);
    cout<<res<<endl;
  }

  return 0;
}



Measured memory_bytes: 3164
import java.util.Scanner;

public class Main{

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

		int n = sc.nextInt();
		int R[] = new int[n];

		for (int i = 0; i < n; i++) {
			R[i] = sc.nextInt();
		}
		sc.close();
		
		int minv = R[0];
		int maxv = R[1] - R[0];
		
		for( int i = 1; i < n; i++){
			
			maxv = Math.max(maxv , R[i]-minv);
			minv = Math.min(minv ,  R[i]);
		}
		
		System.out.println(maxv);
		
	}

}



Measured memory_bytes: 101364
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int i,j=0,k=0,cnt=1,cn=1,l=a-2,m=b-2;
    for(i=2;i<=a;i++)
    {
        if(i>l)
        cnt=cnt*i;
        j++;
    }
    for(i=2;i<=b;i++)
    {
        if(i>m)
        cn=cn*i;
        k++;
    }
    cnt=cnt/2;
    cn=cn/2;
    if(j==0 && k==0)
        cout<<"0"<<endl;
    else
        cout<<(cnt)+(cn)<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <cassert>

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

ll n, m;
ll ans = (ll)1e18;

int main() {
                        
	cin >> n >> m;	
	
	ans = min(n, m);

	if(n % 3 == 0 || m % 3 == 0) {
		cout << 0;
		return 0;
	}

	for(ll i = 1; i < m; i++) {

 		{
			ll part1 = n * i;
		     ll part2, part3;			
			part2 = (m - i) / 2  * n;
			part3 = n * m - part1 - part2;
			ans = min(ans, max(abs(part1 - part2), max(abs(part1 - part3), abs(part3 - part2))));
		}

		{
			ll part1 = n * i;
		     ll part2, part3;
			part2 = n/2 * (m - i);
			part3 = n * m - part1 - part2;
			ans = min(ans, max(abs(part1 - part2), max(abs(part1 - part3), abs(part3 - part2))));
		}
	}

	for(ll i = 1; i < n; i++) {
		{
			ll part1 = m * i;
		     ll part2, part3;			
			part2 = (n - i) / 2  * m;
			part3 = n * m - part1 - part2;						
			ans = min(ans, max(abs(part1 - part2), max(abs(part1 - part3), abs(part3 - part2))));
		}

		{
			ll part1 = m * i;
		     ll part2, part3;
			part2 = m/2 * (n - i);
			part3 = n * m - part1 - part2;
			ans = min(ans, max(abs(part1 - part2), max(abs(part1 - part3), abs(part3 - part2))));
		}
	}

	//cout << ans << endl;

	cout << ans;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
long long gcd(long long a, long long b) { /* the greatest common divisor*/
  while (b != 0) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { /*the least common multiple*/
  return (a / gcd(a, b)) * b;
}

int main() {
  // REP(x, 0, 1000) {
  //   printf("%5d %5d %5d %5d\n", x,14*x+7, 22*x+11, 40*x+20);
  //   if (x - 7 >= 0 && (x - 7) % 14 == 0) {
  //     if (x - 11 >= 0 && (x - 11) % 22 == 0) {
  //       if (x - 20 >= 0 && (x - 20) % 40 == 0) {
  //         cout <<"Found"<< x << endl;
  //       }
  //     }
  //   }
  // }
  LL N, M;
  cin >> N >> M;
  VEC<LL> A(N);
  REP(i, 0, N) cin >> A[i];
  LL lcmv = A[0];
  REP(i, 1, N) { lcmv = lcm(lcmv, A[i]); }
  // DUMP(lcmv);
  sort(ALL(A));

  VEC<LL> B(N);
  REP(i, 0, N) B[i] = A[i] / 2;
  sort(ALL(B));

  LL ma = B[N - 1];
  LL mi = B[0];
  LL lim = ma + lcmv + 1000;
  REP(i, 0, N-1) {
    if (B[i] % 2 != B[i + 1] % 2) {
      cout << 0 << endl;
      return 0;
    }
  }
  while (mi != ma && ma <= lim && ma <= M) {
    // DUMP(B, mi, ma);
    REP(i, 0, N) {
      if (B[i] < ma) B[i] += (ma - B[i]) / A[i] * A[i];
    }

    mi = LLONG_MAX;
    ma = 0;
    REP(i, 0, N) {
      ma = max(ma, B[i]);
      mi = min(mi, B[i]);
    }
    if (mi != ma) {
      B[N - 1] += A[N - 1];
      ma = max(ma, B[N - 1]);
    }
  }
  if (mi != ma) {
    cout << 0 << endl;
    return 0;
  }
  LL first = B[0];
  // DUMP(B);
  // DUMP("first", first);
  LL cnt = (M - first) / lcmv + 1;
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

vector<ll> t;
vector<pair<ll, ll>> monsters;

void build(ll v, ll tl, ll tr) {
  if (tl == tr) {
    t[v] = monsters[tl].second;
  } else {
    ll tm = tl + (tr - tl) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = 0;
  }
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll x) {
  if (l > r) return;
  if (l == tl && r == tr) {
    t[v] += x;
  } else {
    ll tm = tl + (tr - tl) / 2;
    update(v * 2, tl, tm, l, min(tm, r), x);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, x);
  }
}
ll query(ll v, ll tl, ll tr, ll i) {
  if (tl == tr) {
    return t[v];
  } else {
    ll tm = tl + (tr - tl) / 2;
    return t[v] + (i <= tm ? query(v * 2, tl, tm, i)
                           : query(v * 2 + 1, tm + 1, tr, i));
  }
}

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

  ll n, d, a;
  cin >> n >> d >> a;
  monsters = vector<pair<ll, ll>>(n);
  t = vector<ll>(n * 4);
  for (auto &x : monsters) {
    cin >> x.first >> x.second;
    x.second = (x.second + a - 1) / a;
  }
  sort(monsters.begin(), monsters.end());

  build(1, 0, n - 1);

  ll res = 0;
  for (ll i = 0; i < n; ++i) {
    ll h = query(1, 0, n - 1, i);
    if (h <= 0) continue;

    ll lo = i, hi = n - 1;
    ll ans = -1;
    while (lo <= hi) {
      ll mid = lo + (hi - lo) / 2;
      if (monsters[mid].first <= monsters[i].first + d * 2) {
        ans = mid;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    update(1, 0, n - 1, i, ans, -h);
    res += h;
  }

  cout << res;
}


Measured memory_bytes: 9600
#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>;
const ll MOD = 1000000007;
const ll INF = 10000000000;
#define all(v) v.begin(), v.end()

ll modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}
ll modComb(ll n,ll a){
  ll x=1,y=1;
  rep(i,a){
    x*=n-i;
    x%=MOD;
    y*=i+1;
    y%=MOD;
  }
  y=modPow(y,MOD-2);
  return (x*y)%MOD;
}


int main(){
  ll N,K,ans=0;
  cin >> N >> K;
  vector<ll> comb(N),comb1(N);
  comb.at(0)=1;
  rep(i,N-1){
    comb.at(i+1)=(comb.at(i)*(N-i))%MOD;
    comb.at(i+1)*=modPow(i+1,MOD-2);
    comb.at(i+1)%=MOD;
  }
  comb1.at(0)=1;
  rep(i,N-1){
    comb1.at(i+1)=(comb1.at(i)*(N-i-1))%MOD;
    comb1.at(i+1)*=modPow(i+1,MOD-2);
    comb1.at(i+1)%=MOD;
  }
  rep(i,min(K,N-1)+1){
    ans+=(comb.at(i)*comb1.at(N-1-i))%MOD;
    ans%=MOD;
  }
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3328
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    x, k, d = [int(i) for i in input().strip().split()]
    div = x // d
    L = x - d * k
    R = x + d * k
    if L >= 0:
        print(L)
        return
    if R < 0:
        print(-R)
        return
    if k <= div:
        ans = x - (d * k)
    else:
        k = k - div
        even = x % d
        odd = abs(d - even)
        if k % 2 == 1:
            ans = odd
        else:
            ans = even
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61912
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

struct node
{
    int x,y,id;
};
struct edge
{
    int u,v;
    double cost;
    edge() {}
    edge(int x,int y,double z)
    {
        u=x;
        v=y;
        cost=z;
    }
    bool operator <(const edge& a) const
    {
        return cost>a.cost;
    }
};

edge es[50010];
int par[10010];
node p[10010];
int n,m;
void init()
{
    for(int i=1;i<=n;i++) par[i]=i;
}

int find(int x)
{
    return x==par[x]?x:par[x]=find(par[x]);
}

void unite(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x!=y) par[x]=y;
}

double dis(int a,int b)
{
    return sqrt(1.0*(p[a].x-p[b].x)*(p[a].x-p[b].x)+1.0*(p[a].y-p[b].y)*(p[a].y-p[b].y));
}

double kruskal()
{
    sort(es,es+m);
    //for(int i=0;i<m;i++) printf("%d %d %lf\n",es[i].u,es[i].v,es[i].cost);
    double s=0;
    for(int i=0;i<m;i++)
    {
        edge e=es[i];
        if(find(e.u)!=find(e.v))
        {
            unite(e.u,e.v);
        }
        else
        {
            s+=e.cost;
        }
    }
    return s;
}
int main()
{
    //freopen("a.txt","r",stdin);
    int a,b;
    double c,sum;
    while(~scanf("%d%d",&n,&m))
    {
        init();
        sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            c=dis(a,b);
            es[i]=edge(a,b,c);
        }
        printf("%.3lf\n",kruskal());
    }
    return 0;
}

Measured memory_bytes: 1676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }






int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    map<int, int> mp;
    rep(i, n) mp[a[i]]++;
    for (auto e : mp) {
        // cout << e.F << " " << e.S << endl;
        if (n % 2 != 0 && e.F == 0) {
            if (e.S != 1) {
                cout << 0 << endl;
                return 0;
            }
        } else if (e.S != 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    int m = 0;
    int cnt = 0;
    ll ans = (n % 2 == 0 ? 2 : 1);
    for (auto e : mp) {
        if (cnt++ == 0) {
            m = e.F;
        } else {
            if (e.F != m + 2) {
                cout << 0 << endl;
                return 0;
            } else {
                (ans *= 2) %= inf;
            }
            m = e.F;
        }
        
    }
    cout << ans << endl;
}




Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  
  repi(i,1,N-2) {
    string X = S.substr(0,i);
    string Y = S.substr(i);
    
    set<char> st;
    rep(j,i) {
      rep(k,N-i) {
        if (X.at(j) == Y.at(k)) {
          st.insert(X.at(j));
          continue;
        }
      }
    }
    ans = max(ans, (int)st.size());
  }
  
  cout << ans << endl;
}

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

int N;
long D, A;
int now, nex;
long atk, ans;
long temp1, temp2;
vector<tuple<long, long>> XH;
vector<long> X;
struct LazySegmentTree
{
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main() {
    cin >> N >> D >> A;
    for (int i = 0; i < N;i++){
        cin >> temp1 >> temp2;
        XH.push_back(make_tuple(temp1, temp2));
    }
    sort(XH.begin(),XH.end(),[](const auto& x,const auto& y){return get<0>(x)<get<0>(y);});
    for (int i = 0; i < N;i++){
        X.push_back(get<0>(XH[i]));
    }
    LazySegmentTree seg(vector<ll>(N, 0));
    for(int i=0; i<N; i++) {
        seg.add(i, i+1, get<1>(XH[i]));
    }
    for(int i=0; i<N; i++) {
        now = seg.getsum(i, i+1);
        atk = (now - 1) / A + 1;
        if (now<=0){
            continue;
        }
        nex = upper_bound(X.begin(), X.end(), X[i] + 2 * D) - X.begin();
        seg.add(i, nex, -atk*A);
        ans += atk;
    }
    cout << ans << endl;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<pair<int,int>> av(n + 1, pair<int,int>(0, 0));
	int a;
	for(int i = 1; i <= n;++i){
		av[i].first = i;
		cin >> a;
		++av[a].second;
	}

	sort(av.begin(), av.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
		return a.second < b.second;
	});

	int ret = 0;
	for (int i = 1; i <= n - k; ++i) {
		ret += av[i].second;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1792
using System;

namespace _5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            for (int i = 1; i <= N; i++)
            {
                if (i % 3 == 0 || i % 10 == 3 || i % 100 / 10 == 3 || i % 1000 / 100 == 3 || i % 10000 / 1000 == 3)
                {
                    Console.Write(" " + i);
                }
            }
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9348
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  int a[m];
  for (int i = 0; i < m; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int num;
      cin >> num;
      a[num - 1]++;
    }
  }

  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] == n) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    if (a == b)
        cout << "Draw" << endl;
    else if (a == 1)
        cout << "Alice" << endl;
    else if (b == 1)
        cout << "Bob" << endl;
    else if (a > b)
        cout << "Alice" << endl;
    else
        cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&a[i]);
    }

    int count2 = 0;
    for(int i = 0; i < N; i++){
        for(int j = 1;; j++){
            if(a[i] % 2 == 0){
                a[i] = a[i] / 2;
                count2++;
            }else{
                break;
            }
        }
    }

    printf("%d\n",count2);

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, buf;

int main(){
	cin >> n;
	multiset<ll, greater<ll>> s;
	vector<ll> b;
	
	for(ll i = 0; i < (1 << n); i++){
		cin >> buf;
		s.insert(buf);
	}
	b.push_back(*(s.begin()));
	s.erase(s.begin());

	for(ll t = 0; t < n; t++){
		for(ll i = 0; i < (1 << t); i++){
			auto si = s.upper_bound(b[i]);
			
			if(si == s.end()){
				cout << "No" << endl;
				return 0;
			}
			
			b.push_back(*si);
			s.erase(si);
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 14712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int a,b,c;cin>>a>>b>>c;
    int left=a-b;
    if(left<=c)cout<<c-left;
    else cout<<0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define int long long
using namespace std;
const int INF = 10000000000000;//5000000000000000

signed main() {
	int N;
	cin >> N;
	vector<int> num(N);
	vector<int> order(N);
	vector<int> ans(N);
	for (int i = 0; i < N; i++) {
		cin >> order[i];
		num[i] = i + 1;
	}
	for (int i = 0; i < N; i++) {
		ans[order[i] - 1] = i + 1;
	}
	for (int i = 0; i < N; i++) cout << ans[i] << " ";
	cout << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;

    ll A,B,C,D;

int main(){
  scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
  A=A*B;
  C=C*D;
  if(A<C){
    cout<<C;
  }else{
    cout<<A;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dj = {-1, 1};

int main() {
  int h, w, k, cnt = 1;
  cin >> h >> w >> k;
  vector<vi> g(h + 2, vi(w + 2, -1));
  stack<pair<int, int>> st1, st2;
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
    char c;
    cin >> c;
    if(c == '#') {
      g[i][j] = cnt;
      cnt++;
      st1.push({i, j});
    } else
      g[i][j] = 0;
  }
  while(!st1.empty()) {
    int i = st1.top().first;
    int j = st1.top().second;
    st1.pop();
    st2.push({i, j});
    rep(k, 2) {
      int nj = j + dj[k];
      if(g[i][nj] != 0) continue;
      g[i][nj] = g[i][j];
      st1.push({i, nj});
    }
  }
  while(!st2.empty()) {
    int i = st2.top().first;
    int j = st2.top().second;
    st2.pop();
    rep(k, 2) {
      int ni = i + dj[k];
      if(g[ni][j] != 0) continue;
      g[ni][j] = g[i][j];
      st2.push({ni, j});
    }
  }
  rep2(i, 1, h + 1) {
    rep2(j, 1, w + 1) cout << g[i][j] << ' ';
    cout << '\n';
  }
}

Measured memory_bytes: 4700
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
#define FF first
#define SS second

ll sze, numComp;
ll sz[111111], id[111111];
void build(ll N) {
	sze = numComp = N;
	for ( ll k = 0; k < N; k++ ){
		sz[k] = 1;
		id[k] = k;
	}
}

ll find(ll p) {
	ll root = p;
	while (root != id[root]){ root = id[root]; }
	while (p != root){
		ll temp = id[p];
		id[p] = root;
		p = temp;
	}
	return root;
}

bool connected(ll p, ll q) { return find(p) == find(q); }
ll componentSize(ll p) { return sz[find(p)]; }

void unify(ll p, ll q) {
		ll root1 = find(p);
		ll root2 = find(q);
		if (root1 == root2) return;
		if (sz[root1] < sz[root2]) {
			sz[root2] += sz[root1];
			id[root1] = root2;
		} else {
			sz[root1] += sz[root2];
			id[root2] = root1;
		}
		numComp--;
}

int main(){
  FASTIO;
  ll n, m; cin >> n >> m;
  build(n);
  for ( int k = 0; k < m; k++ ){
    ll x, y; cin >> x >> y; --x, --y;
    unify(x, y);
  }
  cout << numComp - 1 << endl;
  return 0;
}

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

using namespace std;

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (1e10)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x) { cout << setprecision(16) << x << endl; }
template<class T, class... A> void print(const T& first, const A& ... rest) { cout << first << " "; print(rest...); }
struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); } } premain;


#define MAX_V	(100)
#define MAX_V2	(MAX_V * MAX_V)

struct edge {
	ll to;
	ll cap;
	ll rev;
};

vector<edge> G[MAX_V2 * 2 + 10];
bool used[MAX_V2 * 2 + 10];

void append_edge(ll from, ll to, ll cap) {
	G[from].emplace_back(edge{ to, cap, (ll)G[to].size() });
	G[to].emplace_back(edge{ from, 0, (ll)G[from].size() - 1 });
}

int dfs(ll v, ll t, ll f) {
	if (v == t) return f;
	used[v] = true;
	for (ll i = 0; i < G[v].size(); i++) {
		auto& e = G[v][i];
		if (!used[e.to] && (0 < e.cap)) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (0 < d) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(ll s, ll t) {
	ll flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		ll f = dfs(s, t, numeric_limits<ll>::max());
		if (f == 0) return flow;
		flow += f;
	}
}

int main() {
	int H, W;
	cin >> H >> W;

	vector<string> S(H);
	ll source = 0;
	ll sink = 0;


	REP(h, H) {
		cin >> S[h];
		REP(w, W) {
			switch (S[h][w]) {
			case 'S':
				source = h * MAX_V + w;
				S[h][w] = 'o';
				break;
			case 'T':
				sink = h * MAX_V + w + MAX_V2;
				S[h][w] = 'o';
				break;
			case 'o':
				break;
			default:
				continue;
			}
			append_edge(h * MAX_V + w + MAX_V2, h * MAX_V + w, 1);
			append_edge(h * MAX_V + w, h * MAX_V + w + MAX_V2, 1);
		}
	}

	REP(h, H) {
		REP(w, W) REP(w2, w) {
			if ((S[h][w] == 'o') && (S[h][w2] == 'o')) {
				append_edge(h * MAX_V + w, h * MAX_V + w2 + MAX_V2, 100001);
				append_edge(h * MAX_V + w2, h * MAX_V + w + MAX_V2, 100001);
			}
		}
	}

	REP(w, W) {
		REP(h, H) REP(h2, h) {
			if ((S[h][w] == 'o') && (S[h2][w] == 'o')) {
				append_edge(h * MAX_V + w, h2 * MAX_V + w + MAX_V2, 100001);
				append_edge(h2 * MAX_V + w, h * MAX_V + w + MAX_V2, 100001);
			}
		}
	}

	int ret = max_flow(source, sink);
	
	if ((MAX_V2) < ret) {
		ret = -1;
	}

	print(ret);

	return 0;
}


Measured memory_bytes: 123520
L,R= map(int,input().split())


ans = 2020
if R-L>=2019:
    ans = 0
L %= 2019
R %= 2019


if L>=R:
    R+=2019

# print(L,R)

    
for i in range(L,R):
    for j in range(i+1,R+1):
        rem = (i*j)%2019
        ans = min(ans,rem)


        

print(ans)








Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
a,b = list(map(int,input().split()))

from decimal import Decimal

n_list = [(int(i*0.08),int(i*0.1)) for i in range(1500)]

for i,v in enumerate(n_list):
    if v==(a,b):
        print(i)
        import sys
        sys.exit()
print(-1)

Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define MM 1e9
#define Pair pair<int,int>

int H,W;
char a[1001][1001];
int dist[1001][1001];
queue<Pair> que;

void init(){
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			dist[i][j] = MM; // initialize
		}
	}
}

void bfs(){
	while(que.size()){
		Pair p = que.front();
		que.pop();
		int h = p.first;
		int w = p.second;
		if(h+1 < H && dist[h+1][w] == MM){
			dist[h+1][w] = dist[h][w]+1;
			que.push(Pair(h+1,w));
		}
		if(w+1 < W && dist[h][w+1] == MM){
			dist[h][w+1] = dist[h][w]+1;
			que.push(Pair(h,w+1));
		}
		if(h >= 1 && dist[h-1][w] == MM){
			dist[h-1][w] = dist[h][w]+1;
			que.push(Pair(h-1,w));
		}
		if(w >= 1 && dist[h][w-1] == MM){
			dist[h][w-1] = dist[h][w]+1;
			que.push(Pair(h,w-1));
		}
	}
}

void input(){
	cin >> H >> W; 
	init();
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> a[i][j];
			if(a[i][j] == '#'){
				dist[i][j] = 0;
				que.push(Pair(i,j));
			}
		}
	}
}

void check(){
	int mx = 0;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			mx = max(mx,dist[i][j]);
		}
	}

    /*for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << dist[i][j] << " ";
        }
        cout << endl;
    } */

	cout << mx << endl;
}

int main(){
	input();
	bfs();
	check();
}


Measured memory_bytes: 13328
import java.util.Scanner;


public class Main {
	
	private void doIt() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) return ;
			int[] dx = new int[1001];
			int tmp = sc.nextInt(), max, min;
			max = tmp;
			min = tmp;
			dx[0] = tmp;
			boolean maxb = true, minb = true;
			for(int i = 1; i < n; i++){
				tmp = sc.nextInt();
				dx[i] = tmp;
				if(max < tmp) max = tmp;
				if(min > tmp) min = tmp;
			}
			int sum = 0;
			for(int i = 0; i < n; i++){
				if(max == dx[i] && maxb) maxb = false;
				else if(min == dx[i] && minb) minb = false;
				else sum += dx[i];
			}
			System.out.println(sum / (n - 2));
		}
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}

}

Measured memory_bytes: 12000
days_of_fine, day_befoe_exparitation, eating_day = map(int, input().split())

if eating_day <= days_of_fine:
    print('delicious')
elif day_befoe_exparitation < eating_day <= days_of_fine + day_befoe_exparitation:
    print('safe')
else:
    print('dangerous')

Measured memory_bytes: 9096
/*
[abc165] A - We Love Golf
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

int K;
int A, B;

ll solve() {
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            return true;
        }
    }

    return false;
}

int main() {
    cin >> K;
    cin >> A >> B;

    cout << (solve() ? "OK" : "NG") << endl;

    return 0;
}


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

using ll = long long;

std::map<ll, int> m;
int n;

int main() {
    std::cin >> n;
    ll b;
    for (int i = 0; i < n; i++) {
        std::cin >> b;
        m[b]++;
        if (m[b] > 1) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void rdi(ll &x){
	ll f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
inline void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(ll x){
	write(x);
	putchar(' ');
}
inline void print(ll x){
	write(x);
	putchar('\n');
}
struct dsu{
	int par[200200];
	inline void init(int _n){for(int i=0;i<_n;++i) par[i]=i;}
	inline int find(int now){
		if(par[now]==now) return now;
		return par[now]=find(par[now]);
	}
	inline bool unite(int a, int b){
		int Pa(find(a)),Pb(find(b));
		if(Pa==Pb) return false;
		par[Pa]=Pb;
		return true;
	}
};
pair<int,int> e[4];
bool use[4];
bool t[4];
void dfs(int x){
//	cout<<x<<endl;
	t[x]=1;
	bool ok=1;
	for(int i=1;i<=4;++i) if(!t[i]) ok=0;
	if(ok){
		cout<<"YES\n";
		exit(0);
	}
	for(int i=1;i<=3;++i) if(!use[i] and (e[i].first==x or e[i].second==x)){
		use[i]=1;
		if(e[i].first==x) dfs(e[i].second);
		else dfs(e[i].first);
		use[i]=0;
	}
	t[x]=0;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i,j,k,x,y,n=3;
	for(i=1;i<=n;++i){
		cin>>x>>y;
		e[i]=make_pair(x,y);
	}
	for(i=1;i<=4;++i){
//		cout<<"II "<<i<<endl;
		memset(use,0,sizeof(use));
		memset(t,0,sizeof(t));
		dfs(i);
	}
	cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,k;
    cin>>n>>k;
    V<ll> g(n),c(n);
    for(int i=0;i<n;i++){
        cin>>g[i];
        g[i]--;
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    ll ans=-inf;
    for(int i=0;i<n;i++){
        ll res=0;
        int now=i;
        V<bool>visited(n,false);
        V<ll> val;
        ll d=k-1;
        ll sum=0;
        for(int j=0;j<=n;j++){
            if(visited[g[now]]){
                d++;
                break;
            }
            res+=c[g[now]];
            sum+=c[g[now]];
            val.push_back(c[g[now]]);
            visited[g[now]]=true;
            now=g[now];
            chmax(ans,res);
            if(d==0){
                if(visited[g[now]]){
                    d++;
                }
                break;
            }
            d--;
        }
        if(d==0)continue;
            ll m=val.size();
             ll tmp=res;
             res+=ll((k-m)/m)*sum;
             chmax(ans,res);
             now=i;
             for(int j=0;j<(k-m)%m;j++){
                  res+=val[j];
                  chmax(ans,res);
             }
             if(ll((k-m)/m)>0){
                 res=tmp;
                 res+=ll((k-m)/m-1)*sum;

            for(int j=0;j<m;j++){
                  res+=val[j];
                  chmax(ans,res);
             }
             }
    }
    cout<<ans<<"\n";

}

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

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	char s[100];
	stack<int> S;
	while (scanf("%s", s) != -1)
	{
		if (s[0] == '+')
		{
			int a = S.top(); S.pop();
			int b = S.top(); S.pop();
			S.push(a + b);
		}
		else if (s[0] == '-')
		{
			int a = S.top(); S.pop();
			int b = S.top(); S.pop();
			S.push(b - a);
		}
		else if (s[0] == '*')
		{
			int a = S.top(); S.pop();
			int b = S.top(); S.pop();
			S.push(a * b);
		}
		else
		{
			int x = atoi(s);
			S.push(x);
		}
	}

	cout << S.top() << endl;
	return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  string S;
  getline(cin, S);
  i64 N = sz(S), ans = 0, i;
  REP(0, N/2, i) {
    if(S[i] != S[N-i-1])
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


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

typedef pair<ll, ll> P;
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n, m; cin >> n >> m;
    vector<P> A;
    ll a, b;
    rep(i, m) {
        cin >> a >> b;
        a--; b--;
        if(a < b) A.PB( P( a, b ) );
        else A.PB( P( b, a ) );
    }
    sort(ALL(A));

    vector<ll> res(n, 1);
    vector<vector<int>> S(n);

    a = -1; b = -1;
    rep(i, m){
        if(!(A[i].F == a && A[i].S == b)){
            S[A[i].S].PB(A[i].F);
            S[A[i].F].PB(A[i].S);
        }
        a = A[i].F; b = A[i].S;
    }

    ll ans = 0;

    rep(i, n){
        if(res[i] == 1) {
            res[i] = 0;
            set<int> st; st.insert(i);
            queue<int> que;
            que.push(i);
            while(!que.empty()){
                ll t = que.front(); que.pop();
                for (const auto& e : S[t]){
                    if(res[e] == 1){
                        res[e] = 0;
                        que.push(e);
                        st.insert(e);
                    }
                }
            }
            ll cnt = st.size();
            ans = max(cnt, ans);
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;	cin>>n;
	long long ans=0;
	for(int i=0; i<n; i++){
		long long x;	cin>>x;
		while(x%2==0){
			x/=2;
			ans++;
		}
	}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256