akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b);
}
    

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

using namespace std;

int main(){
  int N;
  int ans=0;
  int num=0;
  string s[60];
  int t[60];
  string X;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> s[i];
    cin >> t[i];
  }
  cin >> X;
  for(int i=0; i<N; i++){
    if(s[i]==X){
      num=i;
      break;
    }
  }
  for(int i=num+1; i<N; i++){
    ans+=t[i];
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
// <------------- Template -----------------------> //


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	if(n&1) cout<<0;
	else {
		n/=2;
		ll pro = 5;
		ll ans = 0;
		while(n/pro) {
			ans+=n/pro;
			pro*=5;
		}
		cout<<ans;
	}
 }

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
    int H, W, x, y;
    while(1)
    {
        scanf("%d %d",&H, &W);
        if(H == 0 && W == 0) break;
        for(y = 1; y <= H; y++)
        {
            for(x = 1; x <= W; x++)
            {
                if(y == 1 || y == H)
                {
                    printf("#");
                }
                else if(x == 1 || x == W)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include <stdio.h>

int main(void){
  int a[101][101];
  int i,j,r,c,sum_c,sum_r;

  scanf("%d%d",&r,&c);

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      scanf("%d",&a[i][j]);
    }
  }

  for(i=0;i<r;i++){
    sum_c=0;
    for(j=0;j<c;j++){
      sum_c+=a[i][j];
    }
    a[i][j]=sum_c;
  }

  for(j=0;j<=c;j++){
    sum_r=0;
    for(i=0;i<r;i++){
      sum_r+=a[i][j];
    }
    a[i][j]=sum_r;
  }

  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      printf("%d",a[i][j]);
      if(j!=c){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mi = a[0];
  int ma = a[0];
  for(int i = 0; i < n; i++) {
    mi = min(a[i],mi);
    ma = max(a[i],ma);
  }
  cout << (ma - mi) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}


void inorder(Node u){
  if(u==NIL) return ;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if (k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
          scanf("%d", &x);
          if(treeSearch(root, x)!=NIL)
	    printf("yes\n");
          else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

int main() {

	std::string c;

	std::cin >> c;

	if (c == "a") {
		std::cout << "vowel" << std::endl;
	}
	else if (c == "e") {
		std::cout << "vowel" << std::endl;
	}
	else if (c == "i") {
		std::cout << "vowel" << std::endl;
	}
	else if (c == "o") {
		std::cout << "vowel" << std::endl;
	}
	else if (c == "u") {
		std::cout << "vowel" << std::endl;
	}

	else {
		std::cout << "consonant" << std::endl;
	}

	return 0;
}

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int p[n];
    rep(i, 0, n){
        scanf("%d", &p[i]);
    }
    double sum[n + 1];
    sum[0] = 0;
    rep(i, 1, n+1){
        sum[i] = (double)(p[i-1] * (p[i-1] + 1) / 2) / p[i-1];
    }
    rep(i, 1, n+1){
        sum[i] += sum[i-1];
    }
    double ans = 0;
    rep(i, k, n+1){
        double buf = sum[i] - sum[i-k];
        if(buf > ans){
            ans = buf;
        }
    }
    printf("%.7lf", ans);

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
void quicksort(long int a[],int s,int t){
  if(s<t){
    int i=s,j=t,p=a[(s+t)/2];
    while(1){
      while(a[i]<p)i++;
      while(p<a[j])j--;
      if(i>=j)break;
      a[i]^=a[j]^=a[i]^=a[j];
      i++;j--;
    }
    quicksort(a,s,i-1);quicksort(a,j+1,t);
  }
}
int main(){
  long int a[100000],i,n,x=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++)scanf("%ld",&a[i]);
  quicksort(a,0,n-1);
  for(i=n-1;i>0&&a[i]!=a[i-1];i--);
  x=a[i];
  for(i-=2;i>0&&a[i]!=a[i-1];i--);
  if(i>0)printf("%ld",x*a[i]);
  else printf("0");
}


Measured memory_bytes: 2468
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;
import std.range;

alias real F;

F cross(F x1, F y1, F x2, F y2)
{
	return x1*y2-x2*y1;
}

void main()
{
	foreach(s;stdin.byLine())
	{
		auto m = s.split().map!(to!F);
		immutable x1=m[0], y1=m[1], x2=m[2], y2=m[3], x3=m[4], y3=m[5],
		xp=m[6], yp=m[7];
		immutable c1=cross(x2-x1,y2-y1,xp-x1,yp-y1);
		immutable c2=cross(x3-x2,y3-y2,xp-x2,yp-y2);
		immutable c3=cross(x1-x3,y1-y3,xp-x3,yp-y3);
		writeln((c1>=0&&c2>=0&&c3>=0)||(c1<=0&&c2<=0&&c3<=0)?"YES":"NO");
	}
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll count=0;
  map<ll,ll>mp;
  rep(i,0,n){
    mp[a[i]]++;
    mp[a[i]];
    if(a[i]!=0)count++;
  }

  bool e=true;
  rep(i,0,n){
    if(a[i]!=0&&mp[a[i]]!=2)e=false;
    else if(a[i]==0){
      if(n%2==0&&mp[a[i]]!=0)e=false;
      else if(n%2==1&&mp[a[i]]!=1)e=false;
    }
  }
  ll ans=1;
  rep(i,0,count/2){
    ans*=2;
    ans%=mod;
  }
  if(e)out(ans);
  else out(0);




  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,s;
    cin>>n>>k;
    int sum=0;
    while(k--){
        cin>>s;
        sum+=s;
    }
    if(n<=sum) cout<< "Yes";
    else cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod =1000000007;
int main()
{
  ll n,m;
  cin >> n >> m;
  int a;
  vector<int> broken(n+1);
  for (int i=0;i<m;i++){
      cin >> a;
      broken[a] = 1;
  }
  vector<int> dp(n+2);
  dp[n] = 1;
  for (int i=n-1;i>=0;i--){
      if(broken[i]){
          dp[i] = 0;
          continue;
      }
      dp[i] = (dp[i+1]+dp[i+2]) % mod;

  }
  cout << dp[0] << endl;
  return 0;
}
  
                                                                                                 


Measured memory_bytes: 1024
#include <iostream>
#include <set>

using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	string str;
	multiset<string> st;
	while(n--){
		cin >> str;
		st.insert(str);
	}
	for(auto s : st){
		cout << s;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1e9
using namespace std;
int w,h,ans = inf,gx,gy;
int grid[21][21];
int syoki[21][21];
int x[4] = {-1,0,1,0};
int y[4] = {0,1,0,-1};

bool in(int a,int b){
  if(a< 0 || b<0 || w<=a || h<=b)return false;
  return true;
}

void dfs(int w1,int h1,int count){
  //  cout<<h1<<" "<<w1<<" "<<count<<endl;
  if(count == 10)return;
  for(int i = 0;i < 4;i++){
    int a = w1,b = h1;
    if(in(a+y[i],b+x[i]) && grid[b+x[i]][a+y[i]]==0){
      while(1){
	if(!in(a+y[i],b+x[i]))break;
	if((b+x[i])==gy && (a+y[i]) == gx){
	  ans = min(ans,count+1);
	  return;
	}
	else if(grid[b+x[i]][a+y[i]] == 1){
	  grid[b+x[i]][a+y[i]] = 0;
	  dfs(a,b,count+1);
	  grid[b+x[i]][a+y[i]] = 1;
	  break;
	}
	a += y[i];
	b += x[i];
      }
    }
  }
}
  
int main(){
  int sx,sy;
  while(1){
    cin >> w >> h;
    if(w == 0)break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	cin >> grid[i][j];
	if(grid[i][j] == 2){
	  sx = j;
	  sy = i;
	  grid[i][j]=0;
	}
	if(grid[i][j] == 3){
	  gx = j;
	  gy = i;
	  grid[i][j]=0;
	}

      }
    }
    ans = inf;
    dfs(sx,sy,0);
    if(ans == inf)cout << -1 <<endl;
    else cout << ans <<endl;
  }
  return 0;
}

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

int main(){
  int n;
  string ans = "APPROVED";
  int flg = 1;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    if(a.at(i) % 2 == 0){
      if((a.at(i) % 3 == 0 || a.at(i) % 5 == 0) && flg){
        ans = "APPROVED";
      }else{
        ans = "DENIED";
        flg = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define INF 1e10
#define NMMAX 100

int cmp(const void *a, const void *b);
double width(int *x, int *y, int m, double a);

int main(void)
{
  int i, m, n, min1, max1, min2, max2, x1[NMMAX], y[NMMAX], x2[NMMAX], z[NMMAX], x[NMMAX*2];
  while (scanf("%d %d", &m, &n), m != 0 && n != 0) {
    double res = 0.0;
    scanf("%d %d", &x1[0], &y[0]);
    min1 = max1 = x[0] = x1[0];
    for (i = 1; i < m; i++) {
      scanf("%d %d", &x1[i], &y[i]);
      x[i] = x1[i];
      if (x1[i] < min1) min1 = x1[i];
      if (x1[i] > max1) max1 = x1[i];
    }
    scanf("%d %d", &x2[0], &z[0]);
    min2 = max2 = x[m] = x2[0];
    for (i = 1; i < n; i++) {
      scanf("%d %d", &x2[i], &z[i]);
      x[m+i] = x2[i];
      if (x2[i] < min2) min2 = x2[i];
      if (x2[i] > max2) max2 = x2[i];
    }
    qsort(x, m + n, sizeof(int), cmp);
    for (i = 0; i + 1 < m + n; i++) {
      double a = x[i], b = x[i+1], c = (a + b) / 2;
      if (c >= min1 && c <= max1 && c >= min2 && c <= max2) {
        double fa, fb, fc;
        fa = width (x1, y, m, a) * width(x2, z, n, a);
        fb = width (x1, y, m, b) * width(x2, z, n, b);
        fc = width (x1, y, m, c) * width(x2, z, n, c);
        res += (b - a) / 6 * (fa + 4 * fc + fb);
      }
    }
    printf("%.10f\n", res);
  }
}

int cmp(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}
double width(int *x, int *y, int m, double a)
{
  int i;
  double lb = INF, ub = -INF;
  for (i = 0; i < m; i++) {
    double x1 = x[i], y1 = y[i], x2 = x[(i+1)%m], y2 = y[(i+1)%m];
    if ((x1 - a) * (x2 - a) <= 0 && x1 != x2) {
      double yc = y1 + (y2 - y1) * (a - x1) / (x2 - x1);
      if (yc < lb) lb = yc;
      if (yc > ub) ub = yc;
    }
  }
  if (ub - lb > 0) return ub - lb;
  return 0;
}


Measured memory_bytes: 2028
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String ans = "No";
    if((a + b) >= c) ans = "Yes";
    System.out.println(ans);
  }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

ll pw(ll a, ll n)
{
    ll ans = 1;
    while (n > 0)
    {
        if (n % 2 != 0)
            ans = ans * a;
        a = a * a;
        n = n / 2;
    }
    return ans;
}

signed main()
{
    int n;
    cin >> n;
    // vector<vector<int, int> 
    int v[10][10];
    memset(v, 0, sizeof v); // Arrays
    int res = 0;
    map<int, bool> mp;
    rep(i, 1, n + 1)
    {
        string s = to_string(i);
        string t = s;
        int l = s.size()-1;
        // reverse(begin(t), end(t));
        // int j = stoi(t);
        int p = s[0] - '0';
        int d = s[l] - '0';
        v[p][d]++;
        // if (i <= n && j <= n && p != 0 && d != 0 && mp[i] == false)
        // {
        //     v[p][d]++;
        //     // if (p == 1 && d == 2)
        //     //     cout << i << " " << j << endl;
        //     mp[i] = true;
        //     mp[j] = true;
        //     // cout << i << " " << j << endl;
        // }
    }
    // cout << "a";
    // return 0;
    rep(i, 1, 10)
    {
        rep(j, 1, 10)
            res += v[i][j] * v[j][i];
            // if (i == j)
            //     res += pw(v[i][j], 2);
            // else 
            //     res += pw(v[i][j], 2) * 2;
        //     cout << v[i][j] << " ";
        // cout << endl;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main() {
    ll L, R;
    int min=2019;
    cin >> L >> R;
    if(L==0 || R-L>=2019){
        cout << 0;
        return 0;
    }else{
        for(ll i=L; i<=R; i++){
            if(i%2019==0){
                cout << 0;
                return 0;
            }
            for(ll j=i+1; j<=R; j++){
                if((i*j)%2019<min) min=(i*j)%2019;
            }
        }   
        cout << min;
        return 0;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] a = new Integer[n];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int min = Arrays.stream(a).mapToInt(i -> i).min().getAsInt();
        int max = Arrays.stream(a).mapToInt(i -> i).max().getAsInt();
        int result = max - min;

        // 出力
        System.out.println(result);
    }
}


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

int main(){
    int n;
    cin >> n;
    map<int, int> m;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(m[a] == 0) m[a] = 1;
        else if(m[a] == 1) m[a] = 0;
    }
    int ans = 0;
    for(auto p: m) ans += p.second;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int h, w, n;
  cin >> h >> w >> n;
  int k = max(h, w);
  cout << (n + k - 1) / k << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s1,s2;
    cin >> s1 >> s2;
    cout << ((s1[0] == s2[2] && s1[2] == s2[0] && s1[1] == s2[1]) ? "YES" : "NO") << endl;
}

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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define STDIO
#define mp make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front 
#define pb push_back
#define pp push
#define lb lower_bound 
#define ub upper_bound

inline void checkmin(int &x, int y){x = min(x, y);}
inline void checkmax(int &x, int y){x = max(x, y);}

string s;

int main() {
	#ifndef STDIO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>s;
    if(s == "AAA" || s == "BBB") {
    	cout<<"No"<<endl;
	}else {
		cout<<"Yes"<<endl;
	}
    /* end code */
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
using namespace std;
const ll inf =1e18+9;
const int MAX=1e5+5;
pair<ll,ll>tab[MAX];
ll dp[MAX];
int main()
{

    int n,w;
    scanf("%d%d",&n,&w);

    dp[0]=0;
    for (int i=1;i<=n;i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        tab[i].st=a;
        tab[i].nd=b;
    }

    for (int i=1;i<=n;i++)
    {
        for (ll j=w+1;j>=0;j--)
        {
           if (j+tab[i].st<=w && dp[j]!=inf)
           {
               dp[j+tab[i].st]=max(dp[j]+tab[i].nd,dp[j+tab[i].st]);
           }
        }
    }

    ll maximuma=0;
    for (int i=1;i<=w;i++)
    {
      if (dp[i]!=inf)    maximuma=max(maximuma,dp[i]);
    }

    printf("%lld",maximuma);

    return 0;
}





Measured memory_bytes: 1024
A, B = map(int, input().split())

xor = [0, 1, 3]
if A == 0:
    left = 0
elif A - 1 < 3:
    left = xor[A - 1]
else:
    amari = ((A - 1) - 3) % 4
    if amari == 0:
        left = 0
    elif amari == 1:
        left = A - 1
    elif amari == 2:
        left = 1
    elif amari == 3:
        left = (A - 1) ^ 1
    
if B == 0:
    right = 0
elif B < 3:
    right = xor[B]
else:
    amari = (B - 3) % 4
    if amari == 0:
        right = 0
    elif amari == 1:
        right = B
    elif amari == 2:
        right = 1
    elif amari == 3:
        right = B ^ 1

print(left ^ right)


Measured memory_bytes: 3064
#include<map>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn=200010;
map<ll,int>mp;
ll a[maxn],sum[maxn],ans;
int main()
{
	int N,i,j;
	scanf("%d",&N);
	mp[0]++;
	for(i=1;i<=N;i++){
		scanf("%lld",&sum[i]);
		sum[i]+=sum[i-1];
	//	cout<<sum[i]<<" ";
		ans+=mp[sum[i]];
		mp[sum[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define pii pair<ll,ll>
#define mod 1000000007
map<ll,ll>mm;
map<ll,ll>::iterator it;
int main()
{
    ll n;
    cin>>n;
    if(n<7)
    {
        cout<<1<<endl;
        return 0;
    }
    if(n==7)
        {cout<<2<<endl;
    return 0;}
    double t=n;
    ll ans=min(2*ceil(t/11),2*ceil((t+5)/11)-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//psudora
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define pi 3.1415926535
#define flash ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
const int INF = 1e9+5;
#ifdef _DEBUG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
int main()
{
    flash;
    int n;
    cin>>n;
	vector<int>vec;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		vec.push_back(x);
	}
	int y=0,z=0,w=0;
	for(int i=0;i<n;i++){
		if(vec[i]%2==0){
			if(vec[i]%3==0 || vec[i]%5==0){
				z++;
			}
			else 
		    w++;
		}
		else
		y++;
	}
	if(w>0)
	cout<<"DENIED"<<endl;
	else 
	cout<<"APPROVED"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n;
string s;
vector<int> v[20];
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	rep(i,0,s.size()-1){
		int x = s[i]-'0';
		v[x].pb(i);
	}
	rep(i,0,9) sort(all(v[i]));
	int ans = 0;
	vector<int> :: iterator it;
	rep(i,0,9){
		if(!v[i].size()) continue;
		int p1 = v[i][0];	
		rep(j,0,9){
			if(!v[j].size()) continue;
			it = upper_bound(all(v[j]),p1);
			if(it == v[j].end()) continue;
			int p2 = *it;
			rep(k,0,9){
				if(!v[k].size()) continue;
				it = upper_bound(all(v[k]),p2);
				if(it == v[k].end()) continue;
//				cout << i << " " << j << " " << k << " " << p1 << " " << p2 << " " << p3 << endl; 
				ans++;
			}
		}
	}	
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 512
import java.util.*;

class Pair{
    public int vertex, dist;
    public Pair(int v, int d){
        vertex = v; dist = d;
    }
}

class Graph{
    private int V; 
    private List<List<Pair>> adjLists;
    private int[] minDist;
    public Graph(int v){
        this.V = v;
        adjLists = new ArrayList<>();
        for(int i = 0; i < v; i++){
            adjLists.add(new ArrayList<>());
        }
        minDist = new int[v];
        Arrays.fill(minDist, Integer.MAX_VALUE);
    }
    public void addEdge(int s, int t, int d){
        adjLists.get(s).add(new Pair(t, d));
    }
    public void djkstra(int r){
        PriorityQueue<Pair> pq = new PriorityQueue<>(1000000, new Comparator<Pair>(){public int compare(Pair p1, Pair p2){
                                                                                            return p1.dist - p2.dist;
                                                                                    }});
        minDist[r] = 0;
        pq.add(new Pair(r, 0));
        while(!pq.isEmpty()){
            Pair p = pq.poll();
            List<Pair> adjList = adjLists.get(p.vertex);
            for(int i = 0; i < adjList.size(); i++){
                Pair c = adjList.get(i);
                if(minDist[c.vertex] > minDist[p.vertex] + c.dist){
                    minDist[c.vertex] = minDist[p.vertex] + c.dist;
                    pq.add(new Pair(c.vertex, c.dist));
                }
            }
        }
        for(int i = 0; i < this.V; i++){
            System.out.println(minDist[i] == Integer.MAX_VALUE? "INF": minDist[i]);
        }
    }
}

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int V, E, r;
        V = sc.nextInt(); E = sc.nextInt(); r = sc.nextInt();
        Graph g = new Graph(V);
        for(int i = 0; i < E; i++){
            int s, t, d;
            s = sc.nextInt(); t = sc.nextInt(); d = sc.nextInt();
            g.addEdge(s, t, d);
        }
        g.djkstra(r);
    }
}



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

int main(){
    string s;
    getline(cin,s);
    for(int i=0; i<s.size(); i++){
        if(isalpha(s[i])){
            if(islower(s[i])){
                s[i] = toupper(s[i]);
            }else{
                s[i] = tolower(s[i]);
            };
        }
    };
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3216
import sys
from collections import deque
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    edge=[[] for _ in range(N)]
    for _ in range(N-1):
        u,v,w=map(int,input().split())
        edge[u-1].append((v-1,w))
        edge[v-1].append((u-1,w))
    queue=deque()
    queue.append(0)
    used=[False]*N
    l=[0]*N
    while queue:
        node=queue.popleft()
        used[node]=True
        for childnode,weight in edge[node]:
            if not used[childnode]:
                if weight%2:
                    l[childnode]=int(not l[node])
                else:
                    l[childnode]=l[node]
                queue.append(childnode)
    for x in l:
        print(x)
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 70576
#include <stdio.h>

int main(){
  int H, W;
  scanf("%d %d",&H ,&W);

  int i, j;
  while(1)
  {
    if(H == 0 && W == 0){
      break;
    }
    else if(H == 0){
      for(i = 0; i < W; ++i){
        printf("#");
      }
      printf("\n");
    }
    else if(W == 0){
      for(i = 0; i < H; ++i){
        printf("#\n");
      }
    }
    else{
      for(i = 0; i < H; ++i){
        for (j = 0; j < W; ++j) {
          printf("#");
        }
        printf("\n");
      }
    }
    printf("\n");
    scanf("%d %d",&H ,&W);
  }

  return 0;
}

Measured memory_bytes: 572
def check(T, K, A, F):
    # check whether all members finish by the time T
    counts = [max(0, (a * f - T + f - 1) // f) for a, f in zip(A, F)]  # math.ceil((a * f - T) / f)
    return sum(counts) <= K


def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    A.sort()
    F = list(map(int, input().split(' ')))
    F.sort(reverse=True)
    ok = 10 ** 12
    ng = - 1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid, K, A, F):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    main()


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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int[] a =nextInts();
		int target=a[0];
		for(int i=1;i<N;i++){
			target=target^a[i];
		}
		if((target^a[0])==a[0]){
			System.out.println("Yes");

		}else{
			System.out.println("No");
		}


	}

	public static long[] disassemblyAlph(String s) {
		long[] alph = new long['z' - 'a' + 1];
		Arrays.fill(alph, 0);
		for (int i = 0; i < s.length(); i++) {
			alph[s.charAt(i) - 'a']++;
		}
		return alph;
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

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

int main(){
  string S;
  cin>>S;
  long long a[200010];
  for (int i=0;i<200010;i++){
    a[i]=0;
  }
  long long count = 0;
  int j=0;
  for (int i=0;i<S.length();i++){
    if(S.at(i)=='B'){
      count++;
    }
    else{
      a[j]=count;
      j++;
    }
  }
  long long sum=0;
  for (int i= 0;i<j+1;i++){
    sum=sum+a[i];
  }
  cout<<sum<<endl;
  return 0;
}

  
      

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(all(a));
    sort(all(f), greater<ll>());
    ll l = -1, h = inf;
    while((l + 1) < h) {
        ll m = (l + h) / 2;
        ll s = 0;
        rep(i, n) s += max(0LL, a[i] - m / f[i]);
        if (s <= k) h = m;
        else l = m;
    }
    cout << h << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    mat a(N-1,vec(0));
    ll level = 1;
    rep(i,N - 1){
        if((i + 1) == (1LL << level)) ++level;
        rep(j,i+1){
            if(j < (1LL << (level - 1))){
                a[j].push_back(level);
            }else{
                a[j].push_back(a[j - (1LL << (level - 1))][a[j].size()]);
            }
        }
    }
    rep(i,N-1){
        rep(j,a[i].size()){
            cout<<a[i][j]<<' ';
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 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); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int N,M;

int main(){
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;

    int G[60][60];

    memset(G,0,sizeof(G));

    vector<int> a(M),b(M);
    rep(i,M){
        cin >> a[i] >> b[i];
        --a[i];--b[i];
        G[a[i]][b[i]] = 1;
        G[b[i]][a[i]] = 1;
    }

    int ans = 0;
    
    rep(i,M){
        G[a[i]][b[i]] = 0;
        G[b[i]][a[i]] = 0;

        vector<bool> seen(N,false);

        queue<int> q;
        q.push(0);

        while(!q.empty()){
            int t = q.front();
            q.pop();
            rep(j,N){
                if(j != t){
                    if(G[t][j] && !seen[j]){
                        seen[j] = true;
                        q.push(j);
                    }
                }
            }
        }

        bool flag = true;
        rep(j,N){
            if(!seen[j]){
                flag = false;
            }
        }

        if(!flag)ans++;
        G[a[i]][b[i]] = 1;
        G[b[i]][a[i]] = 1;
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

int n,m;
int s[201];

int main(void){
	
	while(1){
		scanf("%d%d",&n,&m);
		if(n+m==0)break;
		int sum1=0,sum2=0;
		for(int i=0;i<n;i++){
			scanf("%d",&s[i]);
			sum1+=s[i];
		}
		for(int i=n;i<n+m;i++){
			scanf("%d",&s[i]);
			sum2+=s[i];
		}
		int flag=0,sum3=11451419,res1,res2;
		for(int i=0;i<n;i++){
			for(int j=n;j<n+m;j++){
				if(sum1-s[i]+s[j]==sum2-s[j]+s[i]){
					if(s[i]+s[j]<sum3){
						res1=s[i];
						res2=s[j];
						sum3=s[i]+s[j];
						flag=1;
					}
				}
			}
		}
		if(flag)printf("%d %d\n",res1,res2);
		else printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 1196
/*
        |___________________________Arshit Mangukiya_____________________________|
        |_______________________________DA-IICT__________________________________|
        |_____________________________201801173__________________________________|
*/
        /*______________________WRITE  YOUR  CODE  HERE_________________________*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;            
typedef long double ld;
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define all(a)      a.begin(),a.end()
//#define F(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 200005
#define sz size()
#define p(x) 		cout<< x << " ";
#define pe(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
		const ll N=1e5;
		ll i,j,k;
    		bool fun(pair<int,int>a , pair<int,int>b)
			{
				if(a.ff == b.ff)	return a.ss < b.ss;
				else			return a.ff > b.ff;
			}
	bool fun(string s,string t)
	{
		ll c=0;
		for(ll i=0;i<s.sz;i++)
		{
			if(c<t.sz && s[i]==t[c])c++;
			
		}
		return c==t.sz;
	}
	signed main(){
	FAST;
	ll a[3];
	cin>>a[0]>>a[1]>>a[2];
	cout<<a[2]<<" "<<a[0]<<" "<<a[1];
	
}
	
				


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

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long[] Solve(long N)
        {
            for (long h = 1; h <= 3500; ++h)
            {
                for (long n = 1; n <= 3500; ++n)
                {
                    long p = N * h * n;
                    long q = 4 * h * n - N * n - N * h;
                    if (q != 0 && p % q == 0 && p / q >= 1)
                    {
                        long w = p / q;
                        return new[] { h, n, w };
                    }
                }
            }
            return null;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            Console.WriteLine(string.Join(" ", Solve(N)));
        }
    }
}


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

h, n = map(int, input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] ,b[i] = map(int, input().split())

inf = float("inf")
# dp[i][j]:i-1番目までの魔法で体力をj減らした時の消耗魔力の最大値
dp = [[inf]*(h+2) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(h+1):
        dp[i+1][j] = min(dp[i+1][j],dp[i][j])
        dp[i+1][min(j+a[i],h)] = min(dp[i+1][min(j+a[i],h)],dp[i+1][j]+b[i])

print(dp[n][h])






Measured memory_bytes: 226620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int d = b-a;
        int s = 0;

        for (int i = 0;i <= d; i++){
            s=s+i;
        }
        System.out.println(s-b);
    }

}




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


int main()
{
int a,b,k;
  cin>>a>>b>>k;
int count=0,l=min(a,b)+1;
  while(count<k)
  {
    l--;
  if((a%l==0)&&(b%l==0))
  {  count++;
// cout<<l<<" ";
}
  }

  cout<<l;
return 0;
}


Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

a, b = MAP()
n = gcd(a, b)
s = sorted(divisor(n))
t = [1]*len(s)

ans = 0
for i in range(1, len(s)-1):
    if t[i] == 0:
        continue
    else:
        for j in range(i+1, len(s)):
            if t[j] == 0:
                continue
            else:
                if s[j] % s[i] == 0:
                    t[j] = 0
print(sum(t))

Measured memory_bytes: 10704
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

template <typename T>
using reverse_priority_queue = priority_queue <T, vector <T>, greater <T>>;

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

  size_t n, m; cin >> n >> m;
  reverse_priority_queue <pair <int64_t, int64_t>> q;
  rep (i, n)
  {
    int64_t a, b; cin >> a >> b;
    q.push (make_pair (a, b));
  }

  int64_t ans = 0;
  rep (i, m)
  {
    auto p = q.top ();
    q.pop ();
    int64_t a, b;
    tie (a, b) = p;
    ans += a;
    if (b > 1)
    {
      q.push (make_pair (a, b - 1));
    }
  }

  cout << ans << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n, m; scanf("%d%d", &n, &m);
	int L = 1, R = n;
	for (int i = 0; i < m; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		L = max(L, l);
		R = min(R, r);
	}
	printf("%d", max(R-L+1, 0));
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void sin4(int n)
{
  if(n<4){
    printf("%d",n);
    return;
  }
  sin4(n/4);
  printf("%d",n%4);
}


int main(void)
{
  int n;

  while(1){
    scanf("%d",&n);
    if(n == -1) break;
    sin4(n);
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 604
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	X,Y = inputMap()

	ans = 0
	if X == 1:
		ans += 300000
	elif X == 2:
		ans += 200000
	elif X == 3:
		ans += 100000

	if Y == 1:
		ans += 300000
	elif Y == 2:
		ans += 200000
	elif Y == 3:
		ans += 100000

	if X == Y and X == 1:
		ans += 400000

	print(ans)


if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


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

    cout <<(H+(A-1))/A << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    vector<ll> b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i, n)
    {
        ll left = min(a[i], b[i]);
        a[i] -= left;
        b[i] -= left;
        ans += left;

        ll right = min(a[i + 1], b[i]);
        a[i + 1] -= right;
        b[i] -= right;
        ans += right;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k):
        for j in range(i+1, k+1):
            sum += gcd(i, j)*6

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

Measured memory_bytes: 9148
#include "bits/stdc++.h"
using namespace std;
int main() {
    int A, B, C, kotae;
    cin >> A >> B >> C;
    if(A == B && A == C && B == C){
        kotae = 1;
    }
    else if(A == B || A == C || B == C){
        kotae = 2;
    }
    
    else{
        kotae = 3;
    }
    cout << kotae << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 1000005
#define INF 1e18
#define LL long long

int n, m, cnt, head[MAXN], vis[MAXN];
LL l=1, r=INF, root=-1, f[MAXN][5];

LL min(LL x, LL y) {if(x>y) return y; return x;}
LL max(LL x, LL y) {if(x<y) return y; return x;}

struct Edge{int next, to; LL dis;} edge[MAXN];

std::queue<int> q;

void addedge(int from, int to, LL dis)
{
	edge[++cnt].next=head[from];
	edge[cnt].to=to;
	edge[cnt].dis=dis;
	head[from]=cnt;
} 

void bfs(int x)
{
	vis[x]=1; q.push(x);
	f[x][0]=1; f[x][1]=0;
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(int i=head[x]; i; i=edge[i].next)
		{
			int to=edge[i].to;
			if(vis[to]) continue;
			f[to][0]=-f[x][0];
			f[to][1]=edge[i].dis-f[x][1];
			vis[to]=1; q.push(to);
		}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++)
	{
		int u, v, s;
		scanf("%d%d%d", &u, &v, &s);
		addedge(u, v, s);
		addedge(v, u, s);
	}
	bfs(1);
	for(int i=1; i<=n; i++)
	{
		if(f[i][0]==1) l=max(l, 1-f[i][1]);
		else r=min(r, f[i][1]-1);
		for(int j=head[i]; j; j=edge[j].next)
		{
			int to=edge[j].to;
			LL x=f[i][0]+f[to][0];
			LL y=f[i][1]+f[to][1];
			if(x==0 && y!=edge[j].dis) {printf("0\n"); return 0;}
			if(x!=0)
			{
				LL temp=edge[j].dis-y;
				if(temp%2 || temp/x<=0) {printf("0\n"); return 0;}
				if(root==-1) root=temp/x;
				if(root!=temp/x) {printf("0\n"); return 0;}
			}
		}
	}
	if(root==-1) printf("%lld\n", max(0, r-l+1));
	else printf("%d", (root>=l && root<=r));
}

Measured memory_bytes: 14976