akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/
void swap(int* x, int* y);	/*値の交換*/
void downsort(int* a, int n);	/*降順ソート*/
void upsort(int* a, int n);	/*昇順ソート*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/

/*ここからmain関数*/

int main()
{
	int n, h[20];
	cin >> n;
	for (int i = 0;i < n;i++)
		cin >> h[i];

	int ans = 1;
	for (int i = 1;i < n;i++)
	{
		int judge = 0;
		for (int j = 0;j < i;j++)
			if (h[j] > h[i])
				judge = 1;
		if (judge == 0)
			ans++;
	}

	cout << ans;

	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

/*2数の値を交換する*/
void swap(int* px, int* py)
{
	int temp;

	temp = *px;
	*px = *py;
	*py = temp;
}

/*クイックソートによる降順並べ替え*/
void downsort(int* a, int n)
{
	//初期設定
	int l = 0, r = n - 1;

	// ピボットの決定
	int piv = *a;

	//ピボットより大を左に、ピボット以下を右に
	while (l < r)
	{
		if (*(a + l) > piv)
			l++;
		else if (*(a + r) <= piv)
			r--;
		else
			swap(a + l, a + r);
	}

	//再帰処理
	if (n == 2)
		return;
	else if (l == 1 || l == 0)
		downsort(a + 1, n - 1);
	else if (r == n - 1)
		downsort(a, n - 1);
	else
	{
		downsort(a, l);
		downsort(a + l, n - l);
	}
}

/*クイックソートによる昇順ソート*/
void upsort(int* a, int n)
{
	downsort(a, n);

	for (int i = 0;i < n / 2;i++)
		swap(a[i], a[n - 1 - i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x,y;
    cin >> n >> m;
    if (n%2){
        x = 1,y = n;
        rep(i,m){
            cout << x << " " << y << endl;
            x++;
            y--;
        }
    }
    else{
        x = 1,y = n;
        ll k = n/2;
        rep(i,min(m,k/2)){
            cout << x << " " << y << endl;
            x++;
            y--;
        }
        y--;
        rep(i,m-k/2){
            cout << x << " " << y << endl;
            x++;
            y--;
        }
    }
}


Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  if a[i] < b[i]:
    ans += a[i]
    if a[i+1] < b[i] - a[i]:
      ans += a[i+1]
      a[i+1] = 0
    else:
      ans += b[i] - a[i]
      a[i+1] -= b[i] - a[i]
  else:
    ans += b[i]
print(ans)

Measured memory_bytes: 81892
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,A,B; cin>>N>>A>>B;
  int dupli = min(A,B);
  int remain = N - A;
  int imin;
  if(remain > B) {
    imin = 0;
  } else {
    imin = B - remain;
  }

  printf("%d %d\n", dupli, imin);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final String BIG   = "a > b";
    private static final String SMALL = "a < b";
    private static final String EQUAL = "a == b";

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

        System.out.println((a == b) ? EQUAL : ((a > b) ? BIG : SMALL));
    }
}

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

using namespace std;

int main(void) {
  int N, K, S;
  cin >> N >> K >> S;

  int m = 1000000000;
  int k = 999999999;

  if (S != m) {
    if (K != N) {
      for (int i = 0; i < K; i++) {
        cout << S << " ";
      }
      for (int i = K; i < N-1; i++) {
        cout << m << " ";
      }
      cout << m << endl;
    } else {
      for (int i = 0; i < K-1; i++) {
        cout << S << " ";
      }
      cout << S << endl;
    }
  } else {
    if (K != N) {
      for (int i = 0; i < K; i++) {
        cout << S << " ";
      }
      for (int i = K; i < N-1; i++) {
        cout << k << " ";
      }
      cout << k << endl;
    } else {
      for (int i = 0; i < K-1; i++) {
        cout << S << " ";
      }
      cout << S << endl;
    }
  } 

  return 0;
}

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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long X;
	scanf("%lld",&X);
	long long Y;
	scanf("%lld",&Y);

	--X, --Y;

	vector<vector<ll>> table(N, vector<ll>(N, LONG_LONG_MAX));
	vector<ll> score(N, 0);
	for (ll i = 0; i < N; ++i)
	{
		table[i][i] = 0;
		for (ll j = 1; j < N; ++j)
		{
			if (i + j < N)
			{
				ll t = min(j, abs(Y - (i + j)) + abs(X - i) + 1);
				// fprintf(stderr, "(%lld, %lld) = %lld", i, i + j, t);
				table[i][i + j] = min(table[i][i + j], t);
				table[i + j][i] = min(table[i][i + j], table[i + j][i]);
				table[i][i + j] = min(table[i][i + j], table[i + j][i]);
				// fprintf(stderr, "-> = %lld\n", table[i][i + j]);
			}
			else
			{
				ll new_j = j - N;
				ll t = min(-new_j, abs(Y - i) + abs(X - (i + new_j)) + 1);
				// fprintf(stderr, "(%lld, %lld) = %lld", i, i + new_j, t);
				table[i][i + new_j] = min(table[i][i + new_j], t);
				table[i + new_j][i] = min(table[i][i + new_j], table[i + new_j][i]);
				table[i][i + new_j] = min(table[i][i + new_j], table[i + new_j][i]);
				// fprintf(stderr, "-> = %lld\n", table[i][i + new_j]);
			}
		}
	}
	for (ll i = 0; i < N; ++i)
	{
		++score[0];
		for (ll j = i + 1; j < N; ++j)
		{
			++score[table[i][j]];
		}
	}

	for (ll k = 1; k < N; ++k)
	{
		cout << score[k] << endl;
	}

	return 0;
}


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

int main() {
  int N,sum,i;
  cin>>N;
  sum=0;
  for(i=0;i<N;i++){
    int l,r;
    cin>>l>>r,
    sum+=(r-l+1);
  }
  cout<<sum<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   string s, r;
   cin>>s;
   int q;
   cin>>q;
   bool fl=false;
   rep(_, q){
      int t;
      cin>>t;
      if(t==1){
         fl= !fl;
      }
      else{
         int f;
         char c;
         cin>>f>>c;
         if((f==1) ^ (fl)) r+=string(1, c);
         else s+=string(1, c);
      }
   }

   if(!fl){
      reverse(r.begin(), r.end());
      cout<<r<<s<<endl;
   }
   else{
      reverse(s.begin(), s.end());
      cout<<s<<r<<endl;
   }
   return 0;
}


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

int main() {
  int N, K, x;
  cin >> N;
  cin >> K;
  
  int l, r;
  int ans = 0;
  rep(i, N) {
    cin >> x;
    if (x * 2 < K) {
      ans += x;
    } else {
      ans += K - x;
    }
  }
  cout << ans * 2 << endl;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    int ans, min = 10000000000;
    int h[100001];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h, h+n);
    for(int i=0;i<n-k+1;i++){
        ans = h[i+k-1] - h[i];
        if(min > ans) min = ans;
    }
    cout << min << endl;
    return 0;
}


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

const int L[10] = {0, 1, 2, 3, 1, 0, 3, 1, 2, 3};

int c(char x) {
  return x - '0';
}

int main() {
  string S;
  while(true) {
    cin >> S;
    if (S == "#") break;
    if (S.size() <= 2) {
      cout << 0 << endl;
      continue;
    }
    int res = (int) 1e7;
    for(auto k=0; k<2; k++) {
      int l = c(S[k%2]);
      int r = c(S[(k+1)%2]);
      bool w = (k==0);
      if (L[r] < L[l]) {
	continue;
      }
      int count = 0;
      for (auto i=0; i<S.size(); i++) {
	int n = c(S[i]);
	if (w) { // 次はlが踏み出すはず
	  if (L[r] < L[n]) {
	    count++;
	    r = n;
	  } else {
	    l = n;
	    w = false;
	  }
	} else {
	  if (L[l] > L[n]) {
	    count++;
	    l = n;
	  } else {
	    r = n;
	    w = true;
	  }
	}
      }
      if (res > count) res = count;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
int main()
{
	cin >>n>>m;
	cout <<n*m;
	return 0;
} 

Measured memory_bytes: 3588
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    vector<vector<char>> grid(100, vector<char>(100, '#'));
    rep(i,50)rep(j,100) grid[i][j] = '.';
    a--; b--;
    rep(i,100){
        if(i == 49 || i == 50) continue;
        if(i < 49){
            rep(j,100){
                if(b > 0){
                    if(i%2 == 0 && j%2 == 0){
                        grid[i][j] = '#';
                        b--;
                    }
                }
            }
        }
        else{
            rep(j,100){
                if(a > 0){
                    if(i%2 == 1 && j%2 == 0){
                        grid[i][j] = '.';
                        a--;
                    }
                }
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    rep(i,100){
        rep(j,100) cout << grid[i][j];
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                             it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))
#define eq ==

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

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){

    for(int loop = 1;;loop++){
        int N,W;
        cin >> W;
        if(W == 0) break;
        cin >> N;
        // value,weight
        vector<pair<int,int> > T(N);
        char c;
        rep(i,N) cin >> T[i].first >> c >> T[i].second;
        vector<vector<int> > DP(N,vector<int>(W+1));

        for(int i=0;i<=W;i++){
            if(T[0].second <= i){
                DP[0][i] = T[0].first;
            }
        }

        for(int i=1;i<N;i++){
            for(int j=0;j<=W;j++){
                if(0 <= j-T[i].second){
                    DP[i][j] = max(DP[i-1][j],DP[i-1][j-T[i].second]+T[i].first);
                }else{
                    DP[i][j] = DP[i-1][j];
                }
            }
        }

        int maxi = -1;
        int maxk = -1;
        for(int i=0;i<=W;i++){
            if(maxi < DP[N-1][i]){
                maxi = DP[N-1][i];
                maxk = i;
            }
        }
        cout << "Case " << loop << ":" << endl;
        cout << maxi << endl << maxk << endl;
    }
    return 0;
}

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

int toInt(char c) {
  if(c == 'T') return 10;
  if(c == 'J') return 11;
  if(c == 'Q') return 12;
  if(c == 'K') return 13;
  if(c == 'A') return 14;
  return c - '0';
}

int getValue(string C, char T, char S) {
  int res = toInt(C[0]);
  if(C[1] == T) res += 200;
  else if(C[1] == S) res += 100;
  return res;
}

int main() {
  for(char T; cin >> T && T != '#'; ) {
    string H[4][13];
    for(int i = 0; i < 4; ++i) {
      for(int j = 0; j < 13; ++j) {
        cin >> H[i][j];
      }
    }
    int res[2] = {};
    int p = 0;
    for(int j = 0; j < 13; ++j) {
      char S = H[p][j][1];
      int maxi = getValue(H[0][j], T, S);
      int winner = 0;
      for(int i = 1; i < 4; ++i) {
        int tmp = getValue(H[i][j], T, S);
        if(maxi < tmp) {
          maxi = tmp;
          winner = i;
        }
      }
      res[winner&1] += 1;
      p = winner;
    }
    if(res[0] > res[1])
      cout << "NS " << res[0] - 6 << endl;
    else
      cout << "EW " << res[1] - 6 << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
n,*a=`dd`.split.map &:to_i
h=Hash.new 0
a.each{|e|h[e]+=1}
p [(h.keys.select{|e|h[e]>=4}.max||0)**2,h.keys.select{|e|h[e]>=2}.max(2).reduce(:*)||0].max

Measured memory_bytes: 17412
#include <stdio.h>
#include <limits.h>

int main(void) {
	char exists[(int)UCHAR_MAX + 1] = {0};
	char S[32];
	int i;
	if (scanf("%31s", S) != 1) return 1;
	for (i = 0; S[i] != '\0'; i++) {
		int idx = (unsigned char)S[i];
		if (exists[idx]++) {
			puts("no");
			return 0;
		}
	}
	puts("yes");
	return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

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

    int N;
    cin >> N;

    for (int i = 1; i < 10; ++i) {
        if (N % i == 0 and N / i < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int K;
  cin >> K;
  string s;
  cin >> s;
  if(sz(s)<=K) {
    cout << s << endl;
    return 0;
  }
  s = s.substr(0,K);
  cout << s << "..." << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<ll> a(n), ans(n);
	rep(i, n) cin >> a[i];
	priority_queue<pair<ll, int>> pq;
	rep(i, n) {
		pq.emplace(a[i], i);
	}
	ll num = 0;
	int min_index = n;
	while(!pq.empty()) {
		auto now = pq.top();
		pq.pop();
		min_index = min(min_index, now.second);
		num++;
		while((!pq.empty()) && (pq.top().first == now.first)) {
			auto tmp = pq.top();
			pq.pop();
			num++;
			min_index = min(min_index, tmp.second);
		}
		ll add;
		if(!pq.empty()) {
			auto next = pq.top();
			add = now.first - next.first;
		} else {
			add = now.first;
		}
		ans[min_index] += num * add;
	}
	rep(i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4336
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
u =[]
for i in range(n):
    ll = []
    for j in range(n):
        if j != i :
            ll.append([l[i][0] - l[j][0], l[i][1] - l[j][1]])
    u += ll
su = 0
for i in u:
    a = u.count(i)
    su = max(su, a)
print(n - su)


Measured memory_bytes: 41580
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,ans,a[110000],b[110000];
signed main(){
  cin>>n;rep(i,n)cin>>a[i]>>b[i];
  for(int i = n-1;i >= 0;i--){
    a[i] += ans;
    if(a[i] % b[i] == 0)continue;
    ans += b[i] - (a[i]%b[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

p.insert(0, 10**9)
p.append(0)
q.insert(0, 10**9)
q.append(0)
r.append(0)

result = sum(p[1:x+1]) + sum(q[1:y+1])
i = 0
red_min = x
blue_min = y
flag = True

while flag == True:
    if r[i] > p[red_min] or r[i] > q[blue_min]:
        if p[red_min] < q[blue_min]:
            result = result - p[red_min] + r[i]
            i += 1
            red_min -= 1
        else:
            result = result - q[blue_min] + r[i]
            i += 1
            blue_min -= 1
    else:
        flag = False
print(result)

Measured memory_bytes: 22720
import java.util.Scanner;

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

        int symStrLen = -1;
        boolean isSymmetry = false;
        for(int i = 1;i < s.length();i++) {
            if((s.length() - i) % 2 == 1) continue;
            String leftStr = s.substring(0, (s.length() - i) / 2);
            String rightStr = s.substring((s.length() - i) / 2, s.length() - i);

            isSymmetry = leftStr.equals(rightStr);
            if(isSymmetry) {
                symStrLen = leftStr.length() + rightStr.length();
                break;
            }
        }

        System.out.println(symStrLen);
    }
}


Measured memory_bytes: 23764
#include <stdio.h>
int main()
{
	int k;
	scanf("%d",&k);
	getchar();
	char s[1000];
	gets(s);
	if(strlen(s)<=k) printf("%s",s);
	else{
		int i;
		for(i=0;i<k;i++){
			printf("%c",s[i]);
		}
		printf("...");
	}
	return 0;
} 

Measured memory_bytes: 1776
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int x, a, b;
  cin >> x;
  a = x / 500 * 1000;
  b = x % 500 / 5 * 5;
  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    long long n;
    cin>>n;
    long long ans=1e18;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,(i-1)+(n/i-1));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}



Measured memory_bytes: 2584
import java.util.*;

public class Main {
	public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
      int N = sc.nextInt();
      if (N == 1) {
        System.out.println("Hello World");
      } else {
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(A+B);
      }
    }
}

Measured memory_bytes: 20820
class Array
  def swap(x, y)
    self[x], self[y] = self[y], self[x]
  end
end

def selectionSort(n, a)
  c = 0
  (n-1).times{|i|
    min = i
    (i+1..n-1).each{|j|
      a[j]<a[min]&&min=j
    }
    i!=min&&a.swap(i,min)&&c+=1
  }
  return a, c
end

a, c = selectionSort(gets.to_i, gets.split.map(&:to_i))
puts a.join(" ")
puts c

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

#include <vector>

#include <algorithm>

using namespace std;

#define repeat(n) for(int _ = 1; _ <= (n); _++)

int main()
{
	ios::sync_with_stdio(false);
#ifdef CAI_WEI_HAN
	freopen("test.in", "r", stdin);
#endif
	
	int n, m, c;
	cin >> n >> m >> c;
	
	int b[25];
	for(int i = 1; i <= m; i++)
		cin >> b[i];
	
	int ans = 0;
	for(int _ = 1; _ <= n; _++) {
		int now = c;
		for(int i = 1; i <= m; i++) {
			int x;
			cin >> x;
			
			now += x * b[i];
		}
		
		ans += (now > 0);
	}
	
	cout << ans;
}


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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }
    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    for (auto a : S) {
        if (a == "AC")
            c0++;
        else if (a == "WA")
            c1++;
        else if (a == "TLE")
            c2++;
        else if (a == "RE")
            c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

bool kai(string x){
    string rev;
    for(int i=x.size()-1; i>=0; i--)rev+=x[i];
    return (x==rev);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    ll n = s.size();

    string s1 = s.substr(0,n/2);
    string s2 = s.substr(n/2+1,n/2);
    if(kai(s)&&kai(s1)&&kai(s2))cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    target="keyence"
    if s==target:
        print("YES")
        sys.exit()
    for i in range(n):#文字列開始
        for j in range(n):#文字列終了
            for k in range(i,j+1):
                #区間[i,j]が予想
                s_exp=s[:i]+s[j+1:]
                if s_exp==target:
                    print("YES")
                    sys.exit()
    print("NO")



if __name__=='__main__':
    main()

Measured memory_bytes: 40684
x,y,a,b,c = map(int, input().split())
p = sorted(list(map(int, input().split())),reverse=True)[:x]
q = sorted(list(map(int, input().split())),reverse=True)[:y]
pq = sorted(p + q,reverse=True)

r = sorted(list(map(int, input().split())),reverse=True)
ans = 0
data_pq = [0]
for s in pq:
    data_pq.append(data_pq[-1] + s)

data_r = [0]
for t in r:
    data_r.append(data_r[-1] + t)


for i in range(c+1):
    if x + y - i < 0:break
    ans = max(ans,data_r[i] + data_pq[x+y-i])

print(ans)

Measured memory_bytes: 112620
def euclid(x):
    def gcd(a,b):
        if b==0:return a
        return gcd(b,a%b)

    n = len(x)
    if n == 1:
        return x[0]
    else:
        element = gcd(x[0], x[1])
        if n == 2:
            return element
        else:
            for i in range(2,n):
                element = gcd(element,x[i])
            return element

N = int(input())
A = list(map(int, input().split()))
print(euclid(A))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int64_t mod=1000000007;
vector<int64_t> fact(100001),factinv(100001);
int64_t pow(int64_t x,int64_t y){
  int64_t z; 
  if(y==0) return 1;
  else{
    z=((pow(x,y/2)+mod)%mod)*((pow(x,y/2)+mod)%mod)%mod;
    if(y%2==1) z=z*x%mod;
    return (z+mod)%mod;
  }
}
int64_t comb(int64_t n,int64_t k){
  int64_t a,i;
  if(n<k) return 0;
  else{
    a=(fact.at(n)+mod)%mod;
    a=(a*factinv.at(k)+mod)%mod;
    a=(a*factinv.at(n-k)+mod)%mod;
    return (a+mod)%mod;
  }
}
int main(){
  int64_t n,k,i,ans=0;
  cin>>n>>k;
  vector<int64_t> a(n);
  for(i=0;i<n;i++) cin>>a.at(i);
  sort(a.begin(),a.end());
  fact.at(0)=1;
  factinv.at(0)=1;
  for(i=1;i<=n;i++){
    fact.at(i)=fact.at(i-1)*i%mod;
    factinv.at(i)=(factinv.at(i-1)*pow(i,mod-2)+mod)%mod;
  }
  for(i=0;i<n;i++) ans+=(comb(i,k-1)-comb(n-1-i,k-1))*a.at(i)%mod;
  cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
char str[20][20];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char pt[3][6]={"^<v>","|-|-","++++"};
string men[6];
char in[20];
int td[6][6]={
{1,2,3,4,5,6},
{2,6,3,1,5,4},
{3,2,6,4,1,5},
{4,1,3,6,5,2},
{5,2,1,4,6,3},
{6,2,5,4,3,1},
};
struct wolf{
	int t[6];
	wolf(){}
};
inline bool operator<(const wolf&a,const wolf&b){
	for(int i=0;i<6;i++)if(a.t[i]!=b.t[i])return a.t[i]<b.t[i];
	return false;
}
void rN(wolf &a){
	int tmp=a.t[0];
	a.t[0]=a.t[3];a.t[3]=a.t[5];a.t[5]=a.t[1];a.t[1]=tmp;
}
void rS(wolf &a){
	int tmp=a.t[0];
	a.t[0]=a.t[1];a.t[1]=a.t[5];a.t[5]=a.t[3];a.t[3]=tmp;
}
void rW(wolf &a){
	int tmp=a.t[0];
	a.t[0]=a.t[4];a.t[4]=a.t[5];a.t[5]=a.t[2];a.t[2]=tmp;
}
void rE(wolf &a){
	int tmp=a.t[0];
	a.t[0]=a.t[2];a.t[2]=a.t[5];a.t[5]=a.t[4];a.t[4]=tmp;
}
map<wolf,int>m;
wolf rev[100];
string dis[20][20][100];
int main(){
	int a,b;
	int sz=0;
	for(int i=0;i<6;i++){
		for(int j=0;j<4;j++){
			wolf tmp;
			tmp.t[0]=td[i][0];
			tmp.t[5]=td[i][5];
			for(int k=0;k<4;k++)tmp.t[k+1]=td[i][1+(j+k)%4];
			rev[sz]=tmp;
			m[tmp]=sz++;
		}
	}
	scanf("%d%d",&a,&b);
	//while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		for(int i=0;i<6;i++){
			scanf("%s",in);
			men[i]=in;
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)for(int k=0;k<sz;k++)
			dis[i][j][k]="~";
		int sr,sc,gr,gc;
		scanf("%d%d%d%d",&sr,&sc,&gr,&gc);
		sr--;sc--;gr--;gc--;
		for(int i=0;i<sz;i++)dis[gr][gc][i]=men[rev[i].t[0]-1];
		int upd=-1;
		for(int i=0;i<a*b*8;i++){
			bool con=false;
			for(int j=0;j<a;j++){
				for(int k=0;k<b;k++){
					for(int l=0;l<sz;l++){
						if(dis[j][k][l][0]=='~')continue;
						wolf at=rev[l];
						for(int d=0;d<4;d++){
							if(j+dx[d]<0||j+dx[d]>=a||k+dy[d]<0||k+dy[d]>=b)continue;
							bool ok=false;
							for(int e=0;e<3;e++)if(pt[e][d]==str[j+dx[d]][k+dy[d]])ok=true;
							if(!ok)continue;
							if(d==0)rS(at);
							if(d==1)rE(at);
							if(d==2)rN(at);
							if(d==3)rW(at);
							int to=m[at];
							if(dis[j+dx[d]][k+dy[d]][to]>men[at.t[0]-1]+dis[j][k][l]){
								dis[j+dx[d]][k+dy[d]][to]=men[at.t[0]-1]+dis[j][k][l];
								if(j+dx[d]==sr&&k+dy[d]==sc&&to==0)upd=i;
								con=true;
							}
							if(d==0)rN(at);
							if(d==1)rW(at);
							if(d==2)rS(at);
							if(d==3)rE(at);
						}
					}
				}
			}
			if(!con)break;
			if(upd>=a*b*4)break;
		}
		if(upd>=a*b*4){
			printf("infinite\n");
			return 0;
		//	continue;
		}
		if(dis[sr][sc][0][0]=='~'){
			printf("no\n");
			return 0;
		//	continue;
		}
		printf("%s\n",dis[sr][sc][0].c_str());
//	}
}

Measured memory_bytes: 17200
import sys;input=sys.stdin.readline
H, W, M = map(int, input().split())
dx = [0]*H
dy = [0]*W
HH = set()
for _ in range(M):
    x, y = map(int, input().split())
    dx[x-1] += 1
    dy[y-1] += 1
    HH.add((x-1, y-1))
mx=max(dx)
my=max(dy)
mxs = set()
mys = set()
for i in range(H):
    if dx[i] == mx:
        mxs.add(i)
for i in range(W):
    if dy[i] == my:
        mys.add(i)
#print(mxs, mys, mx, my)
for x in mxs:
    for y in mys:
        if (x, y) not in HH:
#            print(x, y)
            print(mx+my)
            sys.exit()
print(mx+my-1)


Measured memory_bytes: 167176
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<time.h>
#include<ctime>
#include<functional>
#define int long long
#define itn int
using namespace std;
typedef pair<int, int> P;
signed main() {
	int w, h, n, x[100][100]={},a;
	cin >> w >> h >> n;
	for (int i = 0; i < n;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		if (c == 1) {
			for (int j = 0; j < a; j++) {
				for (int k = 0; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 2) {
			for (int j = a; j < w; j++) {
				for (int k = 0; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 3) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < b; k++) {
					x[j][k] = 1;
				}
			}
		}
		if (c == 4) {
			for (int j = 0; j < w; j++) {
				for (int k = b; k < h; k++) {
					x[j][k] = 1;
				}
			}
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (x[i][j] == 0) {
				a++;
			}
		}
	}
	cout << a << endl;
    getchar();
    getchar();
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main (){
  int n,s[10000],q,t[500],i,j,count=0; 
    
  cin>>n;
  for(i=0;i<n;i++){
    cin>>s[i];
  }
  cin>>q;
  for(i=0;i<q;i++){
    cin>>t[i];
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(s[j]==t[i]){
	count++;
	break;
      }
    }
  }

  cout<<count<<endl;

  return 0;
}

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

const ll mod=1e9+7;

void pfact(ll n, map<ll,ll> &mp) {
  for (ll i = 2; i*i <= n; i++) {
    while (n % i == 0) {
      mp[i]++;
      n /= i;
    }
  }
  if (n != 1) mp[n] += 1;
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=1;cin>>n;
  map<ll,ll> mp;
  for(ll i=2;i<=n;++i) pfact(i,mp);
  for(auto itr:mp) {
    ans=ans*(itr.second+1)%mod;
  }
  print(ans);
  return 0;
}

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

using namespace std;

int main(void) {
	string s1,s2;
	cin >> s1 >> s2;
	reverse(s2.begin(),s2.end());
	if (s1 == s2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N=parse(Int,readline())
A=parse.(Int,split(readline()))
function solve(N,A)
buy=zeros(Int, N)
sell=zeros(Int, N)
buy_flag=false
dA=diff(A)
for i=1:(N-1)
    if dA[i]>0
        if !buy_flag
            buy[i]=1
            buy_flag=true
        end
    elseif dA[i]<0
        if buy_flag
            sell[i]=1
            buy_flag=false
        end
    end
end
if buy_flag 
        if dA[end]>=0
        sell[end]=1
    else 
        buy[buy.== 1][end]=0
        end
end

money=1000
stock=0
for i=1:N
#     println(money," ",stock)
    if buy[i]==1
        stock=div(money,A[i])
        money=money%A[i]
    end
    if sell[i]==1
        money=money+stock*A[i]
        stock=0
    end
end
print(money)
end
solve(N,A)

Measured memory_bytes: 214900
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

int main()
{
    int n, L, q, x[112345], a[112345], b[112345];

    cin >> n;
    REP(i, n)
    cin >> x[i];
    cin >> L >> q;
    REP(i, q)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        if (a[i] > b[i])
            swap(a[i], b[i]);
    }

    int d[20][112345];

    for (int i = 0; i < n; i++)
    {
        int l = i;
        int r = n;

        while (r - l > 1)
        {
            int mid = (r + l) / 2;

            if (x[mid] - x[i] <= L)
                l = mid;
            else
                r = mid;
        }

        d[0][i] = l;
    }
    for (int j = 1; j < 20; j++)
        for (int i = 0; i < n; i++)
            d[j][i] = d[j - 1][d[j - 1][i]];

    REP(i, q)
    {
        ll res = 0;
        int c = a[i];

        for (int j = 19; j >= 0; j--)
        {
            if (d[j][c] < b[i])
            {
                c = d[j][c];
                res += 1 << j;
            }
        }

        res++;

        /*
        while (true)
        {
            if (c == b[i])
                break;

            int l = -1;
            int r = 20;

            while (r - l > 1)
            {
                int mid = (r + l) / 2;

                if (d[mid][c] <= b[i])
                    l = mid;
                else
                    r = mid;
            }

            res += pow(2, l);

            c = d[l][c];
        }
        */

        cout
            << res << endl;
    }

    return 0;
}

Measured memory_bytes: 10752
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();
        System.out.println( solve(A, B) );
    }

    private static int solve(int A, int B) {
        int sum = A + B;
        int minus = A - B;
        int mul = A * B;

        return Math.max(Math.max(sum, minus),mul);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int N=10;
VI G[N];
bool used[N];
int n,m;
int ans=0;

void go ( int u, int cnt ) {
    if ( cnt==n ) ans++;
    used[u]=1;
    for ( int v:G[u] ) {
        if ( !used[v] ) {
            go(v,cnt+1);
        }
    }
    used[u]=0;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    REP(i,m) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        G[a].PB(b);
        G[b].PB(a);
    }
    go(0,1);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 3652
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    S = list(input())
    N = len(S)
    rud = ['R', 'U', 'D']
    lud = ['L', 'U', 'D']

    flag = True
    for i in range(N):
        if (i + 1) % 2 == 0:
            if not (S[i] in lud):
                flag = False
        else:
            if not (S[i] in rud):
                flag = False

    if flag:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()


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

int n;

vector < pair < int,int> > wek;

long long k;

long long mod=1000000007;
long long wyn=1;
 
int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		int p1;
		scanf("%d", &p1);
		wek.push_back({p1, 1});
	}
	for (int i=1; i<=n; i++)
	{
		int p1;
		scanf("%d", &p1);
		wek.push_back({p1, -1});
	}
	sort(wek.begin(), wek.end());
	for (int i=0; i<wek.size(); i++)
	{
		if (wek[i].second*k<0)
		{
			wyn*=abs(k);
			wyn%=mod;
		}
		k+=wek[i].second;
	}
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1505;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN][MAXN]; int n, a[MAXN][MAXN];
int l[MAXN][MAXN], r[MAXN][MAXN], res[MAXN][MAXN];
int main() {
	read(n);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
		for (int j = 1; j <= n; j++)
			if (s[i][j] == '#') a[i][j] = 0;
			else a[i][j] = s[i][j] - '0';
	}
	ll finalans = 0;
	for (int i = n; i >= 1; i--)
	for (int j = n; j >= 1; j--) {
		if (a[i][j] != 0) {
			if (a[i + 1][j] == 0 && a[i][j + 1] == 0) l[j][i] = r[j][i] = j;
			else if (a[i + 1][j] == 0) {
				for (int k = i; k <= n; k++) {
					l[j][k] = l[j + 1][k];
					r[j][k] = r[j + 1][k];
				} l[j][i] = j;
				res[i][j] = res[i][j + 1];
			} else if (a[i][j + 1] == 0) {
				l[j][i] = r[j][i] = j;
				res[i][j] = res[i + 1][j];
			} else {
				int Max = 0, ans = res[i + 1][j] + res[i][j + 1];
				l[j][i] = j, r[j][i] = r[j + 1][i];
				for (int k = i + 1; k <= n; k++) {
					if (r[j][k] >= l[j + 1][k] && l[j + 1][k] > Max) ans -= res[k][l[j + 1][k]];
					chkmax(Max, r[j][k]);
					chkmax(r[j][k], r[j + 1][k]);
					chkmin(l[j][k], l[j + 1][k]);
				}
				res[i][j] = ans;
			}
			finalans += a[i][j] * res[i][j];
			res[i][j] += a[i][j];
		} else {
			for (int k = i; k <= n; k++)
				l[j][k] = n + 1, r[j][k] = 0;
		}
	}
	cout << finalans << endl;
	return 0;
}

Measured memory_bytes: 22784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

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

using namespace std;

int main(void){
  string s;
  cin >> s;
  if(s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(void) {
  ll n;
  cin >> n;
  ll a[n], x[20][20], y[20][20];
  ll ans = 0;
  rep (i, n) {
    cin >> a[i];
    rep (j, a[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  for (ll bit = 0; bit < (1<<n); bit++) {
    
    vector<ll> shojiki(n, 0);
    for (ll i = 0; i < n; i++) {
      if (bit & (1 << i)) {

        shojiki[i] = 1;



      }
    }

    bool ok = true;
    rep (i, n) {

      
      rep (j, a[i]) {

        if (shojiki[i]) {
          if (y[i][j]) {
            if (!shojiki[x[i][j]]) ok = false;
          }
          else {
            if (shojiki[x[i][j]]) ok = false;
          }
        }

        
      }

    }
    if (ok) {
      ll tmp = 0;
      rep (i, n) if (shojiki[i]) tmp++;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
import math

n, m = map(int, input().split())
X = []
A = []
inter = range(1, m+1)
for i in range(n):
    X = list(map(int, input().split()))
    A = X[1:]
    inter = list(set(inter) & set(A))

print(len(inter))



Measured memory_bytes: 14552
primes = []
MAX_NUM = 100000
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False

def do_prime_factorization(x):
    res = {}
    for p in primes:
        if x == 1:
            break
        while x % p == 0:
            x /= p
            if not p in res:
                res[p] = 0
            res[p] += 1
    if x > 1:
        res[x] = 1
    return res.items()

def f(x, d, n, m, ps):
    if x >= n:
        return x
    if d < 0:
        return m
    p, num = ps[d]
    res = m
    for i in range(num+1):
        y = x * (p**i)
        res = min(res, f(y, d-1, n, m, ps))
    return res

def solve(n, m):
    ps = do_prime_factorization(m)
    q = f(1, len(ps)-1, n, m, ps)
    p = m // q
    return p

n, m = map(int, raw_input().split())
print(solve(n, m))

Measured memory_bytes: 8196
# -*- coding:utf-8 -*-

place = ['a','b','c']
time = list(map(int, input().split()))
dict = dict(zip(place,time))
time_list = []
for k1, v1 in dict.items():
        for k2, v2 in dict.items():
                if k1 != k2:
                        time_list.append(v1+v2)
print(min(time_list))

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

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int m = getInt();

  vector<int> box(n, 0);
  vector<int> cnt(n, 1);
  box[0] = 1;

  REP(i,m) {
    const int x = getInt() - 1;
    const int y = getInt() - 1;

    if(box[x]) box[y] = 1;
    if(cnt[x] == 1) box[x] = 0;
    cnt[x]--;
    cnt[y]++;
  }

  printf("%d\n", accumulate(box.begin(), box.end(), 0));

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#include <math.h> /* M_PI */
int main()
{
    string t;
    cin >> t;
    int n = t.size();
    rep(i, n)
    {
        if (t[i] == '?')
        {

            t[i] = 'D';
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3748
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  if( N%10 == 3 ){
    cout << "bon" << endl;
  }else if(( N%10 == 0 || N%10 == 1) || ( N%10 == 6 || N%10 == 8)){
    cout << "pon" << endl;
  }else if((( N%10 == 2 || N%10 == 4) || ( N%10 == 5 )) || (N%10 == 7 || N%10 == 9 )){
    cout << "hon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) begin(x),end(x)
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
int a,b;
set < int > se;
bool check(int val){
    int ret = (double)val*0.08;
    return (ret >= a);
}
int main(){
    fast,cin>>a>>b;
    int l = 0,r = 1000;
    while(r-l > 1){
        if(check(mid)) r = mid;
        else l = mid;
    }
    int x = (double)r*0.08;
    while(x == a){
        se.insert(r),r++;
        x = (double)r*0.08;
    }
    for(auto it=se.begin();it!=se.end();it++){
        int x = *it;
        int y = (double)x*0.1;
        if(y == b) cout<<x<<endl,exit(0);
    }
    cout<<"-1"<<endl;
}


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

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    int n,k;
    cin>>n>>k;
    VEC a(n);
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a.begin(),a.end(),greater<LL>());
    
    LL ans=0;
    for(int i=0;i<k;++i)ans+=a[i];
    cout<<ans<<endl;

}

Measured memory_bytes: 256
def main():
    s = input()
    l = int(s[0:2])
    r = int(s[2:4])

    if check(l) == 2 and check(r) == 2:
        print("AMBIGUOUS")
        return
    elif check(l) != 2 and check(r) == 2:
        print("YYMM")
        return
    elif check(l) == 2 and check(r) != 2:
        print("MMYY")
        return
    else:
        print("NA")

def check(num):
    if num == 0:
        return 1
    elif 1 <= num and num <= 12:
        return 2
    else:
        return 3

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

n, m, r = map(int, readline().split())
rr = list(map(int, readline().split()))
graph = [[0] * n for _ in range(n)]
for i in range(m):
    a, b, c = map(int, readline().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
cost = floyd_warshall(csr_matrix(graph))
ans = float('inf')
for bit in permutations(rr):
    cnt = 0
    for now, next in zip(bit, bit[1:]):
        cnt += cost[now - 1][next - 1]
    ans = min(cnt, ans)
print(int(ans))


Measured memory_bytes: 16160