akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)


ll N;
vector<pl> g[100010];
ll color[100010];
bool visited[100010] = {false};

void dfs(ll s, ll guki){
    visited[s] = true;
    rep(i,g[s].size()){
        if (visited[g[s][i].fi] == false){
            if (g[s][i].se % 2 == 0){
                if (guki == 0){
                    color[g[s][i].fi] = 1;
                    dfs(g[s][i].fi,0);
                }
                else{
                     dfs(g[s][i].fi,1);
                }
            }
            else {
                if (guki == 1){
                    color[g[s][i].fi] = 1;
                    dfs(g[s][i].fi,0);
                }
                else dfs(g[s][i].fi,1);
            }
        }
    }
}




int main() {
    cin >> N;
    rep(i,N-1){
        ll u,v,w;
        cin >> u >> v >> w;
        g[u-1].push_back(mp(v-1,w));
        g[v-1].push_back(mp(u-1,w));
        
    }
    color[0] = 1;
    dfs(0,0);
    rep(i,N){
        cout << color[i] << endl;
    }
    
   
    
    return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>

int main(void)
{
    int n;
    int rnd;
    int i, j;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d", &rnd);
        
        printf("Case %d:\n", i + 1);
        for (j = 0; j < 10; j++){
            rnd = ((rnd * rnd) / 100) % 10000;
            printf("%d\n", rnd);
        }
    }
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

void print_answer(vector<int>& ans){
    for(auto it = ans.begin(); it != ans.end(); it++){
        if(it != ans.begin()){
        	cout << " ";
        }
    	cout << *it;
    }
    cout << endl;
}

void rec(vector<int>& v, int n, int x){
    if(x == 0){
    	print_answer(v);
    	return;
    }
    for(int k = min(n, x); k > 0; k--){
        v.push_back(k);
        rec(v, k, x-k);
        v.pop_back();
    }
}

int main() {

    while(true){
    	int n;
    	cin >> n;

    	if(n == 0){
    		break;
    	}

    	vector<int> v;
        rec(v, n, n);
    }
    return 0;
}



Measured memory_bytes: 3056
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
X1, X2, Y1, Y2 = 0, W, 0, H

for x, y, a in P:
    if a == 1:
        X1 = max(X1, x)
    elif a == 2:
        X2 = min(X2, x)
    elif a == 3:
        Y1 = max(Y1, y)
    elif a == 4:
        Y2 = min(Y2, y)
else:
    if X2 <= X1 or Y2 <= Y1:
        print(0)
    else:
        print((X2 - X1) * (Y2 - Y1))

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

using namespace std;

namespace {

// SelectionSort sorts the array |a| in ascending order, and then returns
// the number of swap operations.
int SelectionSort(int* a, int n) {
  int nswap = 0;

  for (int i = 0; i < n; ++i) {
    int minj = i;
    for (int j = i + 1; j < n; ++j) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    if (i != minj) {
      ++nswap;
      const int t = a[i];
      a[i] = a[minj];
      a[minj] = t;
    }
  }

  return nswap;
}

void Print(const int* a, int n) {
  for (int i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
}

} // namespace

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  const int r = SelectionSort(a, n);
  Print(a, n);
  cout << r << endl;
  return 0;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int ans[3010][3010];
int memo[3010][3010];
string a, b;
int n, m;
int dp(int i, int j) {
  int &res = memo[i][j];
  if (res != -1) return res;
  if (i == n) return res = 0;
  if (j == m) return res = 0;
  int choices[3] = {
    dp(i + 1, j),
    dp(i, j + 1),
    -1};
  if (a[i] == b[j]) {
    choices[2] = 1 + dp(i+1, j+1); 
  }
  int max = 0;
  if (choices[1] > choices[max]) max = 1;
  if (choices[2] > choices[max]) max = 2;
  ans[i][j] = max;
  return res = choices[max];
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> a >> b;
    n = (int)a.size();
    m = (int)b.size();
    memset(memo, -1, sizeof memo);

    dp(0, 0);
    int i = 0, j = 0;
    string res = "";
    while (i != n && j != m) {
      if (ans[i][j] == 0) {
        i++;
      } else if (ans[i][j] == 1) {
        j++;
      } else {
        res += a[i];
        i++;
        j++;
      }
    }
    cout << res << endl;
}


Measured memory_bytes: 71552
#include <bits/stdc++.h>
#define fi first
#define se second
#define For(i, a, b) for (int i = (a); i <= (b); ++i)
#define Ford(i, a, b) for(int i = (a); i >=(b); --i)
#define endl '\n'
#define debug(a) cout << a << endl
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pll;
typedef vector <ll> vll;
 
const ll maxN = 1e18;
const ll minN = -1e18;
const ll MOD = 1e9 + 7;
 
const ll limit = 2e5 + 5;
const ll limit1 = 1e6 + 5;
const ll limit2 = 1e3 + 5;

ll n;
ll a[limit1], b[limit1];
ll res = 0, sum = 0, ans = 0, kd, hkd;


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

void ReadIn(){
    cin >> n;
    For(i, 2, n){
        cin >> a[i];
        b[a[i]]++;
    }
    a[1] = 0;
    For(i, 1, n){
        cout << b[i] << endl;
    }

}
int main(){
    FastIn();
    ReadIn();
}
    

Measured memory_bytes: 6772
#include<stdio.h>
#include<string.h>

#define M 1000003 
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2; 
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else  return 0;
}

int getKey(char str[]){ 
  int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ 
  return key%M; 
}

int h2(int key){ 
  return 1+key%(M-1); 
}

int find(char str[]){
  int i=0,key,sum;
  key=getKey(str);

  for(i=0;;i++){
    sum=(h1(key)+i*h2(key))%M;
    if(strcmp(H[sum],str)==0)return 1;
    else if(strlen(H[sum])==0) return 0;
  }
  return 0;
}

int insert(char str[]){
  int key,i=0,k; 
    key=getKey(str);
    for(i=0;;i++){
      k=(h1(key)+i*h2(key))%M;
      if(strcmp(H[k],str)==0)return 1;
      else if(strlen(H[k])==0){
	strcpy(H[k],str);
	return 0;
      }
    }
    return 0;
}
int main(){
  int i, n; 
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){ 
    scanf("%s %s", com, str);
    if ( com[0] == 'i' ){ 
      insert(str); 
    }
    else {
      if (find(str)){ 
	printf("yes\n");
      }
      else {
    printf("no\n");
    
      }
    }
  }
 
  return 0;
}



Measured memory_bytes: 15384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<int> a(X); REP (i, X) cin >> a[i];
  vector<int> b(Y); REP (i, Y) cin >> b[i];
  vector<int> c(Z); REP (i, Z) cin >> c[i];
  vector<int> bc;
  REP (y, Y) {
    REP (z, Z) {
      bc.push_back(b[y] + c[z]);
    }
  }
  sort(RALL(a));
  sort(RALL(bc));
  vector<int> xi(X);
  while (K--) {
    int ma = 0;
    int idx = -1;
    REP (x, X) {
      if (xi[x] < Y * Z && chmax(ma, a[x] + bc[xi[x]])) idx = x;
    }
    cout << ma << endl;
    xi[idx]++;
  }
}


Measured memory_bytes: 10608
while True:
    m, f, r = map(int, input().split())
    total = m + f
    if m == -1 and f == -1 and r == -1:
        break

    if m == -1 or f == -1:
        print("F")

    elif total >= 80:
        print("A")
    elif total >= 65:
        print("B")
    elif total >= 50:
        print("C")
    elif total >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

typedef long long ll;

int main()
{
    int n,ans;
    cin >> n;
    vector<int> a(100001);
    rep(i, n){
        int s;
        cin >> s;
        if(s>100000)
            ans++;
        else a[s]++;
    }
    forx(i,1,100001){
        if(a[i]!=0){
            if(a[i]>=i)
                ans += (a[i] - i);
            else
                ans += a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 1000000005
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
//#define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    ll n, k, i;
    cin>>n>>k; ll a[n+1];
    for(i=1;i<=n;i++)cin>>a[i];
    vector <ull> v;
    for(i=1;i<=n;i++){
        if(i<=k)continue;
        else{
            if(a[i-k]<a[i])cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5196
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=2007,mod=1e9+7;
typedef long long LL; 
typedef double db;
using namespace std;
int n,k;
LL dp[N][N],fac[N*N],inv[N*N];

template<typename T> void read(T &x) {
    char ch=getchar(); x=0; T f=1;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

LL C(int n,int m) {
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

//#define DEBUG
int main() {
#ifdef DEBUG
	freopen("1.in","r",stdin);
	//freopen(".out","w",stdout);
#endif
	read(n); read(k);
	fac[0]=inv[0]=inv[1]=1;
	For(i,1,n*k) fac[i]=fac[i-1]*i%mod;
	For(i,2,n*k) inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
	For(i,2,n*k) inv[i]=inv[i-1]*inv[i]%mod; 
	if(k==1) {
		puts("1");
		return 0;
	}
	dp[n][n]=1;
	Rep(i,n,0) {
		Rep(j,n,i) {
			if(i) 
				(dp[i-1][j]+=dp[i][j])%=mod;
			if(j>i) 
				(dp[i][j-1]+=dp[i][j]*(k>2?C(i+j*(k-1)-1,k-2):1)%mod)%=mod;
		}
	}
	LL ans=dp[0][0]*fac[n]%mod;
	printf("%lld\n",ans);
    return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 2e5 + 5;

int main(){
	int n,i,j;
	int a[maxn];
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	if(a[0]!=0){printf("-1\n"); return 0;}
	for(i=0;i<(n-1);i++){
		if((a[i+1] - a[i])>=2){printf("-1\n"); return 0;}
	}
	ll ans = 0;
	int x[maxn];
	memset(x,0,sizeof x);

	for(i=(n-1);i>=1;i--){
		// printf("i: %d\n",i);
		x[i] = a[i];
		ans+=a[i];
		int cnt = a[i];
		// printf("cntAwal: %d\n",cnt);
		// printf("ans jd: %lld\n",ans);
		for(j=i;j>=0;j--){
			// printf("j: %d\n",j);
			// printf("cnt sekarang: %d\n",cnt);
			if(a[j]!=cnt){
				i = j+1;
				// printf("i jd: %d\n",i);
				break;
			}
			x[j] = cnt;
			cnt--;
			// printf("cnt: %d\n",cnt);
			if(cnt==0){
				i = j;
				break;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
};

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <vector>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int n;
char s[16];
void DFS(int pos,char c){
    if(pos==n+1){
        printf("%s\n", s+1);
        return ;
    }
    for(int i='a';i<=min(c,'z');i++){
        s[pos]=i;
        if(i==c){
            DFS(pos+1,c+1);
        }
        else{
            DFS(pos+1,c);
        }
    }
}
int main(){
    read(n);
    DFS(1,'a');
}


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

int main()
{
  string s;
  cin >> s;

  string ans = "AC";
  if(s[0] != 'A'){
    ans = "WA";
  }
  int cnt = 0, m;
  for(int i = 2; i <= s.size() - 2; i++){
    if(s[i] == 'C') {
      cnt++;
      m = i;
    }
  }
  if(cnt != 1) ans = "WA";
    rep(i,s.size()){
      if (i == 0 || i == m) continue;
      if(s[i] < 'a' || s[i] > 'z') ans = "WA";
    }
  
  cout << ans << endl;
  return 0;
}


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

#define ll  long long

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

    int n,r;
    cin>>n>>r;
    if(n<10)
        r+=(10-n)*100;
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  priority_queue<int> pq;
  while (n--) {
    int a; cin >> a;
    pq.push(a);
  }
  while (m--) {
    int x = pq.top(); pq.pop();
    pq.push(x / 2);
  }
  lint res = 0;
  while (!pq.empty()) {
    int x = pq.top(); pq.pop();
    res += x;
  }
  cout << res << '\n';
}

Measured memory_bytes: 892
class UnionFind:
    def __init__(self,N):
        self.par=[i for i in range(N)]
        self.siz=[1 for _ in range(N)]
        self.rank=[0 for _ in range(N)]
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,a,b):
        a=self.find(a)
        b=self.find(b)
        if a==b:
            return 0
        else:
            if self.rank[a]>self.rank[b]:
                self.par[b]=a
                self.siz[a]+=self.siz[b]
            else:
                self.par[a]=b
                self.siz[b]+=self.siz[a]
                if self.rank[a]==self.rank[b]:
                    self.rank[b]+=1
    def size(self,a):
        return self.siz[self.find(a)]
    def same(self,a,b):
        return self.find(a)==self.find(b)

n,q=map(int,input().split())
uf=UnionFind(n)
for i in range(q):
    com,x,y=map(int,input().split())
    x,y=x-1,y-1
    if com:
        print(1 if uf.same(x,y) else 0)
    else:
        uf.union(x,y)


Measured memory_bytes: 6136
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;
using ll = long long;

ll solve(ll H, ll W){
    // 縦三分割
    ll ans1 = W * H;
    if(W % 3 == 0){
        ans1 = 0;
    }
    else if(W >= 3){
        ans1 = H;
    }

    // もう一個の方
    ll ans2 = W * H;
    for(ll w = 1; w < W; w++ ){
        ll area1 = w * H;
        ll tmp = max( abs( H / 2 * (W - w) - area1 ) , abs( (H / 2 + H % 2)  * (W - w) - area1 ) );
        ans2 = min(tmp, ans2);
    }

    return min(ans1, ans2);
}

int main(){

    long long H, W;
    cin >> H >> W;

    ll ans1 = solve(H, W);
    ll ans2 = solve(W, H);

    cout << min(ans1, ans2) << endl;

}

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

int main() {
  int a, b, c, d;

  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d ||
      (abs(a - b) <= d && abs (b - c) <=d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n){
        cin >> a[i];
        a[i] -= i+1;
    }
    sort(all(a));
    ll b;
    if(n%2==1) b = a[n/2];
    else b = (a[n/2-1] + a[n/2])/2;
    ll ans = 0;
    rep(i,n){
        ans += abs(a[i]-b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
x,y=t1*(a1-b1),t2*(a2-b2)
if (x+y)==0:
  print("infinity")
elif x*(x+y)>0:
  print(0)
else:
  if x>0:
    x1,x2=x,x+y
  else:
    x1,x2=-x,-(x+y)
  if x1%x2==0:
    print(2*abs(x1//x2))
  else:
    print(2*abs(x1//x2)-1)


Measured memory_bytes: 3064
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string _1, s, _2; readV(_1, s, _2);
  writeln('A', s[0], 'C');
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

int main()
{
	char a[5];
	cin >> a;
	sort(a, a + 3);
	if(a[0] == 'a' && a[1] == 'b' && a[2] == 'c') printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;


typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef vector<ii> vii; 
typedef vector<ff> vff;

bool mysort(const ii &a, const ii &b){
    if(a.second == b.second){
        return a.first < b.first;
    }return a.second < b.second;
}

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin>>n;
   vii ab(n);
   for (int i = 0; i < n; i++)
   {
       cin>>ab[i].first>>ab[i].second;
   }
   sort(ab.begin(), ab.end(), mysort);
   long long int a = ab[0].first;
   int i = 1;
   for (; i < n; i++)
   {
       a += ab[i].first;
       if(a>ab[i].second){
           break;
       }
   }
   if(a>ab[i-1].second){
       cout<<"No\n";
   }else{
       cout<<"Yes\n";
   }
   return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
	
	int n;
	int i;
	
	while(scanf("%d", &n) != EOF){
		
		i = 0;
		
		while(n > 0){
			
			n--;
			i++;
			
			if(i > 39){
				
				i = 1;
				
			}
			
		}
		
		if(i<10){
			
			printf("3C0%d\n", i);
			
		}
		else{
			
			printf("3C%d\n", i);
			
		}
		
	}
	
	return 0;
	
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

#define EPS 1e-14
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INFLL (ll)1e18 //Long long infinity
#define INF (int)1e9 //Int infinity
#define MX 100005

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<string> vstr;

#define us unordered_set
#define um unordered_map
#define bs bitset

typedef vector<um<int, int>> graph;

#define RANGE(i,a,b,d) for (int i=min((int)a,(int)b); i<max((int)a,(int)b); i+=d)
#define RRANGE(i,a,b,d) for (int i=max((int)a,(int)b); i>min((int)a,(int)b); i+=d)
#define FOR(i,a,b) RANGE(i,a,b,1)
#define RFOR(i,a,b) RRANGE(i,a,b,-1)
#define REP(i,s) FOR(i,0,s)
#define RREP(i,s) RFOR(i,s-1,-1)
#define FORIT(it,l) for (auto it = l.begin(); it != l.end(); it++)
#define EACH(x,v) for (auto &x : v)

#define sz(x) (int)(x).size()
#define len(x) (int)sizeof(x)/sizeof(*x)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define contains(m,x) (m.find(x) != m.end()) // check if an element in a map
#define isIn(S, s) (S.find(s) != string::npos) // check if substring

#define pv(v) EACH(x, v) cout << x << " "; cout << endl; // print vector/array
#define pvv(vv) EACH(xx, vv){pv(xx);} // print 2-d vector/2-d array
#define pm(m) EACH(x, m) cout << x.F << ":" << x.S << " "; cout << endl; //print map/lookup table

namespace std{
  // Used for hashing pair
  template <> struct hash<pi>{
    size_t operator()(const pi&x)const{
      ll P=38923, Q=109797901;
      return (size_t)((x.F*P+x.S)%Q);
    }
  };
};

// This is min queue
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
void print(T t){
  cout << t << endl;
}

//Python style printing
template<typename T, typename... Args>
void print(T t, Args... args){
  cout << t << " ";
  print(args...);
}

const int MAXN = 105, MAXC = 100005;
int n, c, w[MAXN], v[MAXN];
ll dp[MAXN][MAXC];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> c;
  REP(i, n) {
    cin >> w[i] >> v[i];
  }
  REP(i, n+1) {
    REP(j, c+1) {
      dp[i][j] = -INFLL;
    }
  }
  dp[0][0] = 0;
  REP(i, n) {
    REP(j, w[i]) dp[i+1][j] = dp[i][j];
    FOR(j, w[i], c+1) {
      dp[i+1][j] = max(dp[i][j-w[i]] == -INF ? -INF : dp[i][j-w[i]] + v[i], dp[i][j]);
    }
  }
  ll ans = 0;
  REP(i, c+1) ans = max(dp[n][i], ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		//AとBの各値で条件分岐
		if((A < 10) && (B < 10)) {
			System.out.println(A * B);
		}else {
			System.out.println(-1);
		}
	}
}

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

vector<vector<int>> memo;
int maxhappiness(vector<vector<int>> &h, int n, int prev_activity)
{
    int &ans = memo[n][prev_activity];
    if (ans != -1)
        return ans;
    if (n == 0)
        return ans = 0;
    ans = 0;
    for (int i = 0; i < 3; i++)
    {
        if (prev_activity == i)
            continue;
        ans = max(ans, h[n - 1][i] + maxhappiness(h, n - 1, i));
    }
    return ans;
}

int maxhappinessutil(vector<vector<int>> &h, int n)
{
    int ans = 0;
    for (int i = 0; i < 3; i++)
        ans = max(ans, maxhappiness(h, n, i));
    return ans;
}

int maxhappiness(vector<vector<int>> &h, int n)
{
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    dp[0][0] = 0;
    //no vacation no activity
    for (int v = 1; v <= n; v++) //vacations
    {
        for (int activity = 0; activity < 3; activity++)
        {
            if (v == 1)
                dp[v][activity] = h[v - 1][activity];
            else
            {
                for (int j = 0; j < 3; j++)
                    if (activity != j)
                        dp[v][activity] = max(dp[v][activity], h[v - 1][activity] + dp[v - 1][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < 3; i++)
        ans = max(ans, dp[n][i]);
    return ans;
}

int main()
{
    int n;
    cin >> n;
    memo = vector<vector<int>>(n + 1, vector<int>(3, -1));
    vector<vector<int>> hps(n, vector<int>(3, 0)); //happiness points
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
            cin >> hps[i][j];
    }
    //objective is to gain maximum happiness points here
    //each activity can't be done for two or more consecutive days
    cout << maxhappinessutil(hps, n) << "\n";
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    long long dp[100010][3];
    long long a[100010][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    long long res = 0;
    for(int j = 0; j < 3; j++){
        res = max(res, dp[n][j]);
    }
    cout << res << endl;


}

Measured memory_bytes: 8216
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c;
  cin>>a>>b>>c;
  int A=abs(a-b),B=abs(a-c),C=abs(b-c);
  cout<<min(A+B,min(A+C,B+C))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int num[30];

int main(void)
{
	int i;
	int n;
	
	for (i = 0;i < 28; i++){
		scanf("%d", &n);
		num[n - 1] = 1;
	}
	
	for (i = 0; i < 30; i++){
		if (num[i] == 0){
			printf("%d\n", i + 1);
		}
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
const ll mod = 1e9 + 7;
ll getpc(ll m, ll n) //m 中 选 n 个
{
    long long ans = 1;
    for (long long k = 1; k <= n; k++)
    {
        ans = (ans * (m - n + k)) % mod * powmod(k, mod - 2ll, mod) % mod;
        // ans %= mod;
    }
    return ans;
}
ll gao(ll n, ll m)
{
    return (getpc(n + m , m) - 1ll + mod) % mod;
}
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1++;
    c1++;
    r2++;
    c2++;
    ll ans = gao(r2, c2);
    // chu(ans);
    ans = (ans - gao(r1 - 1, c2) + mod) % mod;
    // chu(ans);
    ans = (ans - gao(r2, c1 - 1) + mod) % mod;
    // chu(ans);
    ans = (ans + gao(r1 - 1, c1 - 1)) % mod;
    printf("%lld\n", ans );
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<iterator>
#include<map>
#include<unordered_map>
#include<vector>
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define F first
#define S second

int32_t main() {
   
    string a,b,c;
    cin>>a>>b>>c;
    
    
    char next_card = 'a';
   while(1)
   {
       if(next_card=='a')
       {
           if(a.empty())
           {
               cout<<"A";
               return 0;
           }
           next_card = a[0];
           a.erase(a.begin());
       }
       else if(next_card=='b')
       {
           if(b.empty())
           {
               cout<<"B";
               return 0;
           }
           next_card = b[0];
           b.erase(b.begin());
       }
       
       else
       {
           if(c.empty())
           {
               cout<<"C";
               return 0;
           }
           next_card = c[0];
           c.erase(c.begin());
       }
   }
    
    
    
    
    
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
  long a,b;
  cin>>a>>b;
  int syou=a/b;
  int amari=a%b;
  double syousuu=(double)a/b;
  printf("%d %d %.10f\n",syou,amari,syousuu);
}


Measured memory_bytes: 3208
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> v(n,1);
    vector<bool> ok(n,false);
    ok[0]=true;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        if(ok[x]) ok[y]=true;
        v[x]--;
        v[y]++;
        if(v[x]==0) ok[x]=false;
    }
    cout<<accumulate(ok.begin(),ok.end(),0LL)<<endl;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N, 0);
	for (int i = 0; i < N; i++)cin >> a[i];
	vector<int> n;
	vector<int> num;
	bool ok;


	int out = 0;

	for (int i = 0; i < N; i++) {

		if (a[i] > 100000) {
			out++;
			continue;
		}
		ok = false;
		for (int j = 0; j < n.size(); j++) {
			if (n[j] == a[i]) {
				num[j]++;
				ok = true;
			}
		}
		if (ok)continue;

		n.push_back(a[i]);
		num.push_back(1);
	}

	for (int i = 0; i < num.size(); i++) {
		if (num[i] != n[i]) {
			if (num[i] - n[i] > 0)	out += num[i] - n[i];
			else out += num[i];
		}
	}

	cout << out << endl;

	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    ll ans =0;
    vector<ll> a(N),b(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    for(int i=0;i<N;i++){
        ll c = a[i]-b[i];
        if(c >0){
            ans += c;
        }else{
            ans += c/2;
        }
    }
    if(ans<=0){
        cout <<"Yes" <<endl;
    }else{
        cout <<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 384
#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<ll, ll> 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);
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for(ll m = 0; m <= n-1; ++m){
		if(c*(n-1-m)-d*m <= b-a && b-a <= -c*m+(n-1-m)*d){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>



using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
pair<int,int> map[100002];
int time[100002];



int main(){
		int N,L;
		scanf("%d %d",&N,&L);
		rep(i,N){
			int a;
			scanf("%d",&a);
			map[i]=make_pair(a,i);
		}
		sort(map,map+N,greater< pair<int,int> >() );
		int ans=0;
		rep(i,N){
			int sans=0;
			int yokomax=0;
			if(map[i].second!=0){yokomax=max(time[map[i].second-1],yokomax);}
			if(map[i].second!=N-1){yokomax=max(time[map[i].second+1],yokomax);}
			sans=yokomax+L-map[i].first;
			time[map[i].second]=sans;
			ans=max(ans,sans);
		}
		printf("%d\n",ans);
}

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

using namespace std;

typedef long long ll;

int main(){

    int X, N;
    cin >> X >> N;
    bool banned[100 + 10] = {};
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        banned[a] = true;
    }

    int ans = 1145141919;
    for (int i = 0; i <= 101; i++) {
        if (!banned[i] && abs(i - X) < abs(ans - X)) {
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  long long int X;
  cin >> X;
  vector<long long int> x(N);
  for (int i = 0; i < N; i++)
  {
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  vector<long long int> distance(N);
  for (int i = 0; i < N; i++)
  {
    distance.at(i) = abs(x.at(i) - X);
  }
  long long int ans = distance.at(0);
  for (int i = 1; i < N; i++)
  {
    ans = __gcd(distance.at(i), ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public sealed class Program
{
    public static void Main(string[] args)
    {
        string line = Console.ReadLine();
        string[] words = line.Split(new[] { ' ' });
        int n = int.Parse(words[0]);
        int m = int.Parse(words[1]);

        // 1回の提出で消費する時間
        int t = m * 1900 + (n - m) * 100;

        // 正解する確率
        double p = 1.0 / Math.Pow(2, m);

        // 不正解になる確率
        double q = 1 - p; 

        // 入力例1の解説から、期待値 x が次の無限級数で求まることが分かる。
        // x
        // = 1 * p * t + 2 * q * p * t + 3 * q^2 * p * t + ...
        // = p * t * (1 + 2 * q + 3 * q^2 + ...)

        // 無限級数を100万項まで展開する。
        double y = 0;
        double r = 1; // = q^i
        for (int i = 1; i < 1000000; i++)
        {
            y += i * r;
            r *= q;
        }

        // 四捨五入して整数にする。
        double x = p * t * Math.Round(y);

        Console.WriteLine("{0}", x);
        return;
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans,c1=0,c2=0,c3=0,c4=0;
  cin>>n;
  string s1="AC",s2="WA",s3="TLE",s4="RE";
  for(int i=0;i<n;i++){
    string str;
    cin>>str;
    //printf("String is");
    //cout<<str;
    if(str==s1)c1++;
    else if(str==s2)c2++;
    else if(str==s3)c3++;
    else if(str==s4)c4++;
  }
  printf("AC x %d\n",c1);
  printf("WA x %d\n",c2);
  printf("TLE x %d\n",c3);
  printf("RE x %d\n",c4);
}


Measured memory_bytes: 3724
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M, S = map(int, input().split())
e = dd(list)
for _ in range(M):
  u, v, a, b = map(int, input().split())
  u -= 1
  v -= 1
  for x in range(a, 2501):
    e[N * x + u].append((N * (x - a) + v, b))
    e[N * x + v].append((N * (x - a) + u, b))
for i in range(N):
  c, d = map(int, input().split())
  for x in range(2501):
    e[N * x + i].append((N * min(2500, x + c) + i, d))
import heapq
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        #print(p)
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
#print(len(e))
dij = dijkstra(2501 * N, e)
p = dij.path(min(S, 2500) * N, 0)
for i in range(1, N):
  res = float("inf")
  for j in range(2501):
    res = min(res, p[i + N * j])
  print(res)

Measured memory_bytes: 141792
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(2, 900), 'Yes')

    def test_2(self):
        self.assertEqual(think(1, 501), 'No')

    def test_3(self):
        self.assertEqual(think(4, 2000), 'Yes')


def solve():
    k, x = read()
    result = think(k, x)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, x):
    unit = 500
    return 'Yes' if unit * k >= x else 'No'


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

using Mint = modint998244353;

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

    int N;
    cin >> N;
    V<pii> pt(N);
    rep(i, N) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        pt[x] = mp(y, i);
    }

    dsu d(N);

    set<pii> st;

    rep(i, N) {
        int y = pt[i].fi;
        int id = pt[i].se;
        auto it = st.lower_bound(mp(y, -1));
        if (it != st.begin()) {
            --it;
            while (true) {
                d.merge(id, it->se);
                if (it == st.begin())
                    break;
                else
                    it = --(st.erase(it));
            }
        } else {
            st.insert(mp(y, id));
        }
    }

    map<int, int> cnt;
    rep(i, N) cnt[d.leader(i)]++;
    rep(i, N) { cout << cnt[d.leader(i)] << '\n'; }

    return 0;
}

Measured memory_bytes: 10508
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        char last = c[c.length-1];
        switch (last){
            case '3':
                System.out.println("bon");
                break;
            case '0':
            case '1':
            case '6':
            case '8':
                System.out.println("pon");
                break;
            default:
                System.out.println("hon");
        }
    }
}


Measured memory_bytes: 26968
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    flag = YES
    if 'L' in S[::2] or 'R' in S[1::2]:
        flag = NO
    print(flag)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n=int(input())
s=[]
z=0
d=0

for i in range(0,n):
    m=input()
    y=list(m)
    y.sort()
    m=''.join(y)
    s.append(m)

s.sort()

for j in range(0,n-1):
    if s[j]==s[j+1]:
        d=d+1
    else:
        if d==0:
            continue
        else:
            f=d*(d+1)//2
            z=z+f
            d=0
if d!=0:
    f=d*(d+1)//2
    z=z+f

print(z)

Measured memory_bytes: 10612
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int h, w;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> h >> w;

  int a[501][501];

  REP(i, h) REP(j, w) cin >> a[i][j];
  vector<int> ans;

  auto gp = [](int t) {
    int y = t / w;
    int x = (y % 2 == 0 ? t % w : w - (t % w + 1));
    return P(y, x);
  };

  REP(i, h * w - 1) {
    P yx = gp(i);
    P nyx = gp(i + 1);

    if(a[yx.first][yx.second] % 2) {
      a[yx.first][yx.second]--;
      a[nyx.first][nyx.second]++;
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;

  REP(i, ans.size()) {
    P p = gp(ans[i]);
    P np = gp(ans[i] + 1);
    cout << p.first + 1 << " " << p.second + 1 << " " << np.first + 1 << " " << np.second + 1 << endl;
  }
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define true 1
#define false 0
#define f(x, y, z) for (int x = y; x < z; x++)
#define fd(x, y, z) for (int x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define pi (ld)3.1415926535897
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace __gnu_pbds;
using namespace std;
lli tmod(lli x,lli m){return (x%m+m)%m;}
lli bit_cnt[60];
int main()
{
  fastio;
  lli n;cin>>n;
  lli a[n];
  f(i,0,n)cin>>a[i];
  f(i,0,n){
    f(j,0,60){
      if((((1ll)<<j)&a[i]))
        bit_cnt[j]++;
    }
  }
  lli ans=0;
  f(i,0,60){  
    lli x=(((1ll)<<i)%mod);
    lli cnt=(bit_cnt[i])*(n-bit_cnt[i]);
    cnt=cnt%mod;
    x=(x*cnt)%mod;
    ans=(ans+x)%mod;
  }
  cout<<tmod(ans,mod)<<"\n";
  return 0;    	
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    int sum=0;
    rep(i,n){
        cin>>vec[i];
        sum+=vec[i];
    }
    int ave=sum;
    int ans,minv;
    rep(i,n){
        if(i==0){
            minv=abs(n*vec[i]-ave);
            ans=i;
        }else if(abs(n*vec[i]-ave)<minv){
            minv=abs(n*vec[i]-ave);
            ans=i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100000 + 10;
int n;

int a[N];
int f[N];
namespace solver
{
  int abs(int x)
  {
    return x > 0 ? x : -x;
  }
  void solve()
  {
    scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%d",&a[i]);

    long long ans=0;
    for(int i=1; i<=n; ++i) 
	{
	  int p=min(a[i],a[i-1]);
	  ans+=1ll*p; a[i]-=p; a[i-1]-=p;
	  ans+=1ll*(a[i]>>1); a[i]&=1;
	}
	printf("%lld\n",ans);
  }
}
int main()
{
  solver :: solve();
}

Measured memory_bytes: 640