akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

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

#define INF 1e16
#define mod 1000000007

int N,W;
ll w[100],v[100];
ll dp[2][100010];

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

  cin>>N>>W;
  rep(i,N)cin>>w[i]>>v[i];

  int crt=0,nxt=1;
  rep(i,2)rep(j,100010)dp[i][j]=INF;
  dp[crt][0]=0;
  rep(i,N){
    rep(j,100010)dp[nxt][j]=INF;
    rep(j,100010){
      if(dp[crt][j]==INF)continue;
      if(j+v[i]<=100000)minch(dp[nxt][j+v[i]],dp[crt][j]+w[i]);
      minch(dp[nxt][j],dp[crt][j]);
    }
    swap(crt,nxt);
  }
  ll res=0;
  rep(j,100010)if(dp[crt][j]<=W)maxch(res,j);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        aa: [chars; h],
    }
    let mut r = vec![1;h];
    let mut c = vec![1;w];
    for i in 0..h {
        let mut k = 0;
        for j in 0..w {
            if aa[i][j] == '.' { k+=1; }
        }
        if k == w { r[i] = 0; }
    }
    for j in 0..w {
        let mut k = 0;
        for i in 0..h {
            if aa[i][j] == '.' { k+=1; }
        }
        if k == h { c[j] = 0; }
    }
    for i in 0..h {
        if r[i] == 0 {
            continue;
        }
        for j in 0..w {
            if c[j] == 0 {
                continue;
            }
            print!("{}", aa[i][j]);
        }
        println!();
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;

namespace ABC117
{
    class C
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = input[0];
            int M = input[1];
            int[] X = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

            int[] lr = new int[M - 1];

            for (int i = 0; i < M - 1; i++)
            {
                lr[i] = X[i + 1] - X[i];
            }

            lr = lr.OrderByDescending(x => x).ToArray();

            int res = 0;
            for (int i = N - 1; i < lr.Length; i++)
            {
                res += lr[i];
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 24288
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};

void solve(){
  int a, b;
  cin >> a >> b;
  if(a > 8 || b > 8){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    map<ll, ll> mp;
    vector<ll> before_loop(0);
    ll before_loop_cnt = 0;
    vector<ll> after_loop(0);
    ll after_loop_cnt = 0;
    ll now = 1;
    mp[1] = -1;
    while (true) {
        mp[now] += 1;
        if (mp[now] <= 2) {
            before_loop.push_back(now);
            before_loop_cnt += 1;
        }
        if (mp[now] == 3) {
            after_loop.push_back(now);
            after_loop_cnt += 1;
        }
        if (mp[now] == 4) break;
        now = A[now - 1];
    }
    ll ans = 0;
    if (K <= 2*before_loop_cnt) ans = before_loop[K];
    else ans = after_loop[(K - before_loop_cnt) % after_loop_cnt];
    // rep(i, before_loop_cnt) cout << before_loop[i] << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 22656
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + c == 2 * b) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int n;
ll ans = 0;
unordered_map<string, ll> umap;

int main() {
   cin >> n;

   string s;
   rep(i, n) {
      cin >> s;
      sort(s.begin(), s.end());
      if (umap.count(s) == 0) {
          umap[s] = 1;
      } else {
          ans += umap[s];
          umap[s]++;
      };
   }

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

Measured memory_bytes: 10660
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            
            int i = 0;
            
            String line; 
            
            while ((line = br.readLine()) != null) {
                ++i;
            	int x = Integer.parseInt(line);
            	if(x==0){ break;}
            	System.out.println("Case "+i+": "+ x);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 31980
#include <stdio.h>

int main()
{
  int n1, n2, n3, tmp;

  scanf("%d %d %d", &n1, &n2, &n3);
  
  if (n1 > n2) {
    tmp = n1;  n1 = n2;  n2 = tmp;
  }
  if (n2 > n3) {
    tmp = n2;   n2 = n3;    n3 = tmp;
  }
  if (n1 > n2) {
    tmp = n1;   n1 = n2;    n2 = tmp;
  }
  
  printf("%d %d %d\n", n1, n2, n3);
  
  return 0;
}


Measured memory_bytes: 2044
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101 // マス目の行の上限
#define COL 101 // マス目の列の上限

int main(void){
	// br = black_row, bc = black_column
	// 黒が少なくとも1マス含まれている行,列を記録する 0で初期化
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
	// マス目の配色を受け取る2次元配列
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
	
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
			// マス目の配色を受け取り、黒が1マスでも含まれている行と列はbr[i], bc[j]を1に変える
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
		// 上から1行ずつ出力していく
		// 黒が1マスも含まれない行(すべて白の行)はループで飛ばす
        if(br[i] == 0)
            continue;
		// このfor文が実行される行には黒が少なくとも1マス含まれている
        for(j = 0; j < col; j++){
			// 黒が1マスも含まれない列(すべて白の列)はループで飛ばす
            if(bc[j] == 0)
                continue;
			// マス目を出力
            printf("%c", sq[i][j]);
        }
		// 1行出力し終えたので改行
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;


//A???65 a???97
int main() {
	vector<char> eki(52);
	eki[0] = 65;
	eki[26] = 97;
	for (int i = 1; i < 26; i++){
		eki[i] = eki[i-1] + 1;
		eki[26+i] = eki[26+i-1] + 1;
	}

	while(1){
		int n; cin >> n;
		if (n == 0) break;
		vi key(n);
		for (int i = 0; i < n; i++){
			cin >> key[i];
		}

		string station; cin >> station;
		string ans = "";
		for (int i = 0; i < station.size(); i++){
			if (isupper(station[i])){
				ans += eki[(station[i]-'A'-key[i%n]+52)%52];
			}else{
				ans += eki[(station[i]-'a'+26-key[i%n]+52)%52];
			}
		}
		cout << ans << endl;

	}

	return 0;
}

Measured memory_bytes: 3168
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

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 rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N;
  cin >> N;
  ll V[N], C[N];
  rep(i, N) cin >> V[i];
  rep(i, N) cin >> C[i];

  ll ans = -1000;
  rep(used, 1 << N){
    ll tmp = 0;
    ll mask = used;
    rep(i, N){
      tmp += (V[i] - C[i]) * (mask % 2);
      mask /= 2;
    }
    if(tmp > ans) ans = tmp;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    int s, w;   cin >> s >> w;
    if (s <= w)
        cout << "unsafe" << endl;
    else 
        cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3636
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s;
		cin>>s;
		int ans=1,i;
		string s1=s.substr(0,1),str;
		for(i=1;i<s.size();i++){
			str+=s[i];
			if(str!=s1){
				ans++;
				s1=str; str="";
			}else{
				str+=s[i];
			}
		}
		
		cout<<ans;
	}
	return 0;
}

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

int main() {
  int N, K, Q; cin >> N >> K >> Q;
  vector<int> A(N, 0);
  rep(i, Q) {
    int idx;
    cin >> idx;
    A[idx-1]++; 
  }
  rep(i, N) {
    if (K - Q + A[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
	int ans = inf;
	rep(i, n - m + 1) {
		string k = s.substr(i, m);
		int cnt = 0;
		rep(j, m) {
			if (k[j] != t[j]) cnt++;
		}
		chmin(ans, cnt);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3680
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
n, d = [int(x) for x in input().split()]
pts = [[int(x) for x in input().split()] for i in range(n)]
ans = 0
for x, y in pts:
    if x ** 2 + y ** 2 <= d ** 2:
        ans += 1
print(ans)


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

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


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

  int n, q;
  string s;
  cin >> n >> q >> s;
  s = '$' + s;
  vector<int> sum(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + (s[i] == 'A' && s[i + 1] == 'C');
  }
  debug(sum);

  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l] << '\n';
  }
  return 0;
}

Measured memory_bytes: 1388
#include <iostream>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  
  rep(i, 1000000000) {
    if(abs(a - i) == abs(b - i)) {
      cout << i << endl;
      return 0;
    }
  }

  cout << "IMPOSSIBLE" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(_,a,b) for(int _=a;_<b;_++)
#define per(_,a,b) for(int _=b-1;_>=a;_--)
typedef long long ll;

const double Pi=3.14159265358979;
int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double t,ans;
    h=h+(m/60.0);
    t=min(abs(h*30.0-m*6.0),360.0-abs(h*30.0-m*6.0));
    ans=sqrt(a*a+b*b-a*b*2.0*cos(t/180.0*Pi));
    printf("%.12lf",ans);
}


Measured memory_bytes: 4140
#include<bits/stdc++.h>
using namespace std;
int w,h;
int gx,gy;
int iro;
int mas[101][101];
int dy[4]={0,1,-1,0};
int dx[4]={1,0,0,-1};
int flag;
void solve(int x,int y){
  if(iro==0) return;
  if(x==gx-1 && y==gy-1){
    flag=1;
    return;
  }
  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(0<=ny && 0<=nx && ny<h && nx<w && mas[ny][nx]==iro){
      mas[ny][nx]=0;
      solve(nx,ny);
    }
  }
  return;
}
int main(){
  int n;
  int sx,sy;
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	mas[i][j]=0;
      }
    }
    cin>>sx>>sy;
    cin>>gx>>gy;
    cin>>n;
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin>>c>>d>>x>>y;
      if(d==0){
	for(int i=0;i<2;i++){
	  for(int j=0;j<4;j++){
	    mas[y-1+i][x-1+j]=c;
	  }
	}
      }else{
	for(int i=0;i<4;i++){
	  for(int j=0;j<2;j++){
	    mas[y-1+i][x-1+j]=c;
	  }
	}
      }
    }
    //for(int i=0;i<h;i++){
    //for(int j=0;j<w;j++){
    //	cout<<mas[i][j];
    //}
    //cout<<endl;
    //}

    iro=mas[sy-1][sx-1];
    //cout<<iro<<endl;
    flag=0;
    solve(sx-1,sy-1);
    if(flag){
      cout<<"OK"<<endl;
    }else{
      cout<<"NG"<<endl;
    }
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int k, n;
  cin >> n >> k;
  int i=0;
  while (n>0){
    n=n/k;
    i++;
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    string S;
    cin >> S;
    ll size = (ll)S.size();
    bool is_ok = true;
    for(ll idx=0;idx<size/2+1;idx++){
        // printf("idx = %lld, size - idx - 1 = %lld (size-1)/2 - idx - 1 = %lld\n", idx, size-idx-1, (size-1)/2-idx-1);
        // cout << S[idx] << ", " << S[size-idx-1] <<"," <<S[(size-1)/2-idx-1]<< endl;
        if(S[idx] != S[size-idx-1]){
            is_ok = false;
            break;
        }
        if((size-1)/2-idx-1>=0){
            // printf("hikaku!\n");
            if(S[idx] != S[(size-1)/2-idx-1]){
                is_ok = false;
                break;
            }
        }
    }
    if(is_ok){
        for(ll idx=(size+3)/2-1;idx<size;idx++){
            ll back_idx = idx - ((size+3)/2-1);
            // printf("idx=%lld, back idx=%lld\n", idx, back_idx);
            if(S[idx]!=S[size - back_idx -1]){
                is_ok = false;
                break;
            }
        }
    }
    if(is_ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;

    }

    // printf("%lld\n", total_num);


    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, x, y, cnt;
long long d;
long long dist(int x, int y) {
    return (x * 1LL * x + y * 1LL * y);
}
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "a", stdout);
    // #endif
    cin >> n >> d;
    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        if(dist(x, y) <= d * d) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

	
	int N;
	cin >> N;

	int G = 0;
	rep(i, N) {
		int A, K;
		cin >> A >> K;
		if (K > 1000) {
			while (A % K) {
				int kari = (A + K - 1) / K;
				int amari = A % K;
				int hiku = (amari + kari - 1) / kari * kari;
				A -= hiku;
			}
		}
		else {
			while (A % K) {
				A = (ll)A * (K - 1) / K;
				if (A < K) {
					A = 0;
					break;
				}
			}
		}
		G ^= A / K;
	}
	
	if (G) co("Takahashi");
	else co("Aoki");

	Would you please return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a.at(i);
  
  int count = 0;
  for(int i=1; i<n-1; i++) {
    int M = max(a.at(i-1), max(a.at(i), a.at(i+1)));
    int m = min(a.at(i-1), min(a.at(i), a.at(i+1)));
    if(a.at(i) != m && a.at(i) != M)
      count++;
  }
  
  cout << count << endl;
}

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

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

typedef long long lint;

using namespace std;

int main(){
  int N,D;
  cin>>N>>D;
  int X[N][D];
  REP(i,N)REP(j,D){
    cin>>X[i][j];
  }
  int ans=0;
  REP(n1,N)REP(n2,N){
    if(n1==n2)continue;
    int s=0;
    REP(d,D)s+=(X[n1][d]-X[n2][d])*(X[n1][d]-X[n2][d]);
    if(sqrt(s)-(int)sqrt(s)<=0.000001)ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
	int time,cost;
};
bool cmp(node a,node b)
{
	if(a.cost<b.cost) return true;
	else if(a.cost==b.cost&&a.time<b.time) return true;
	else return false;
}
int main()
{
	int n,t,min=999999999;
	cin>>n>>t;
	node f[n];
	for(int i=0;i<n;i++) cin>>f[i].cost>>f[i].time;
	stable_sort(f,f+n,cmp);
	for(int i=0;i<n;i++)
	if(f[i].time<=t&&f[i].cost<min) min=f[i].cost;
	if(min!=999999999) cout<<min;
	else cout<<"TLE";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	long long  n, a, b;
	cin >> n >> a >> b;
	long long ans = 0;
	long long key = n / (a + b);
	long long dog = n % (a + b);
	if (dog > a)dog = a;
	ans = key*a + dog;
	cout << ans;
	return 0;
}



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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const int MD = 998244353; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	
	VI d(n), ct(n+10);
	rep(i, n) cin >>d[i];
	rep(i, n) ct[d[i]]++;
	//for(auto x :ct) printf("%d, ",x); puts("");
	
	if(ct[0] != 1 || d[0] != 0){ puts("0"); return 0;}
	rep(i, n+1) if(ct[i]==0 && ct[i+1]>0){
		puts("0"); return 0;
	}
	ll ans =1;

	rep2(i, 1, n+1){
		if( ct[i]>=1){
			ll p = ct[i-1];
			rep(j, ct[i]){ ans *= p; ans %=MD;}
			dbg(i, p, ans);
		}
	}
	
	cout << ans<<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define N 100

void MatrixChain(void);
int M[N][N],P[N],m; 

int main(){
	int i,c;
	scanf("%d",&m);
 
	for(i=1;i<=m;i++){
		scanf("%d %d",&P[i],&c);
	}
	P[i] = c;
	MatrixChain();
	
	return 0;
}

void MatrixChain(){
	int i,j,k,l,n,q;
	n = m;
	for(i=1;i<=n;i++){
		M[i][i]=0;
	}
	
	for(k=2;k<=n;k++){
		for(i=1;i<=n-k+1;i++){
			j = i+k-1;
			M[i][j] = 1000000;
			for(l=i;l<=j-1;l++){
				q = M[i][l]+M[l+1][j]+P[i]*P[l+1]*P[j+1];  
				if(q<M[i][j]){
					M[i][j] = q;
				}
			}
		}
	}
	printf("%d\n",M[1][m]);
}

Measured memory_bytes: 636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int ans = B;
		if (A >= 6 && A <= 12)
			ans = B / 2;
		if (A <= 5)
			ans = 0;
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 24020
import java.util.*;

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

  int a=sc.nextInt();
int b=sc.nextInt();
int h=sc.nextInt();
int m=sc.nextInt();
  
  double angle= Math.abs((double)h/12+((double)m/60)/12.0 -(double)m/60.0)*2*Math.PI;
  double res= (double)a*a +(double)b*b -(double) 2*a*b*Math.cos(angle);
  res =Math.sqrt(res);
        System.out.printf("%.20f",res);
  
 
}
}


Measured memory_bytes: 35864
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int min = 1000;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      x -= a;
      min = Math.min(a, min);
    }

    System.out.println(n + (x / min));

  }
}

Measured memory_bytes: 35972
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int w, h, n,s = 0,d = 0;
	cin >> w >> h >> n;
	REP(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		if (c == 1) s = max(s, a);
		if (c == 2) w = min(w, a);
		if (c == 3) d = max(d, b);
		if (c == 4) h = min(h, b);
	}
	if (w > s && h > d) cout << (w - s) * (h - d) << endl;
	else cout << "0" << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char rec;
	cin >> rec;
	char ans;
	if (rec == 'A') {
		ans = 'T';
	}
	else if (rec == 'C') {
		ans = 'G';
	}
	else if (rec == 'G') {
		ans = 'C';
	}
	else {
		ans = 'A';
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;
typedef pair<int, int> P;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

char m[401][401];
bool d[401][401];
int H, W;
ll b, w;
ll ans;

int dfs(int x, int y){

    if(m[y][x] == '#') b++;
    if(m[y][x] == '.') w++;

    for(int i = 0; i < 4; i++){
        int nx = x + dx[i];
		int ny = y + dy[i];

        //  壁を越えないかつ、行ったことのない場所なら
		if(0 <= nx && nx <= W-1 && 0 <= ny && ny <= H-1 && d[ny][nx] == false && m[y][x] != m[ny][nx]){ 
            d[ny][nx] = true;
            dfs(nx, ny);
            
		}
    }
    
    return 0;
}

int main(){

    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> m[i][j];

    ll res = 0;
    rep(i, H){
        rep(j, W){
            if(m[i][j] == '#'){
                d[i][j] = true;
                b = 0; w = 0;
                dfs(j, i);
                //cout << "b = " << b << " w = " << w << endl;
                ans += b * w;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n, k;
    cin >> n >> k;
    int d[31] {0};
    d[0] = k;
    for(int i = 1; i <= 30; i++){
        if((k >> i) & 1){
            d[i] = ((k >> (i + 1)) << (i + 1)) | ((1 << i) - 1);
        }
    }
    int a[100002];
    ll b[100002];
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    ll ans = 0;
    for(int i = 0; i <= 30; i++){
        ll sum = 0;
        for(int j = 0; j < n; j++) if((d[i] & a[j]) == a[j]) sum += b[j];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define teto(a, b) ((a+b-1)/(b))
using namespace std;

const int MAX = 200010;
const int MOD = 1000000007;
const int INF = 1e8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;

// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define dbg(msg, var) cout << msg << " " << var << endl;
//

struct DSU {
    int n;
    vi parent, sz;

    DSU(int n) {
        this->n = n;
        parent.assign(n+1, 0);
        sz.assign(n+1, 1);

        for(int i=0;i<=n;i++)
            parent[i] = i;
    }

    int find(int v) {
        if(v==parent[v])
            return v;
        return parent[v]=find(parent[v]);
    }

    void join(int a, int b) {
        a = find(a);
        b = find(b);
        if(a!=b) {
            if(sz[a]<sz[b])
                swap(a, b);

            parent[b]=a;
            sz[a]+=sz[b];
        }
    }

    int size(int v) {
        return sz[find(v)];
    }
};

int main() {
    sws;
    int n, q;
    cin >> n >> q;

    vi res(q, -1);

    set<int> stop;
    map<int, vector<pii>> m;
    forn(i, n) {
        int l, r, x;
        cin >> l >> r >> x;

        m[x].pb(mp(l-x, r-x));
        stop.insert(x);
    }

    set<pii> pes;
    forn(i, q) {
        int d;
        cin >> d;
        pes.insert(mp(d, i));
    }

    for(auto x : stop) {
        for(auto p : m[x]) {
            int l, r;
            tie(l, r) = p;

            bool cont = true;
            while(pes.size() and cont) {
                auto it = pes.lower_bound(mp(l, -1));
                if(it == pes.end()) {
                    cont = false;
                }
                else {
                    int d, idx;
                    tie(d, idx) = *it;
                    if(d < r) {
                        pes.erase(it);
                        res[idx] = x;
                    }
                    else {
                        cont = false;
                    }
                }
            }
        }
    }


    for(auto val : res)
        cout << val << endl;
    return 0;
}


Measured memory_bytes: 44596
#include <bits/stdc++.h>
#define N 50001
#define M 100011
#define f first
#define s second
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int n,m,T;
vector<PP> G[M]; // to,cost,y,x
vector<int> g[M];
vector<P> D[M];

struct edge{
  int cost,cnt,y,x;
  bool operator > (edge a)const{return P(cost,cnt)>P(a.cost,a.cnt);}
};

priority_queue<edge,vector<edge>,greater<edge> >Q;  
P dijkstra(int a,int b){

  while(!Q.empty()){
    edge t=Q.top();Q.pop();
    int cost=t.cost,cnt=t.cnt;
    int y=t.y, x=t.x;
    int pos=g[y][x];
    if(D[y][x]<P(cost,cnt))continue;
    if(pos==b) return P(cost,cnt);
    
    for(int i=0;i<G[pos].size();i++){
      PP e=G[pos][i];
      int ncost=cost+e.f.s,ncnt=cnt;
      int ny=e.s.f,nx=e.s.s;
      if(pos!=a&&(ny!=y||abs(x-nx)!=1)) ncost+=T,ncnt++;
      if(D[ny][nx]>P(ncost,ncnt)){
	D[ny][nx]=P(ncost,ncnt);
	Q.push((edge){ncost,ncnt,ny,nx});
      }
    }
  }
  return P(-1,-1);
}

int main(){
  string s,t;
  cin>>m>>T>>s>>t;
  map<string,int> mp;
  mp[s]=n++;
  mp[t]=n++;

  for(int i=0,a;i<m;i++){
    cin>>a;
    D[i].resize(a,P(INF,INF));
    for(int j=0;j<a;j++){
      string str;
      cin>>str;
      if(!mp.count(str))mp[str]=n++;
      if(str==s)D[i][j]=P(0,0);
      if(str==s&&Q.empty())Q.push((edge){0,0,i,j});
      g[i].push_back(mp[str]);
    }

    for(int j=0,pre=g[i][0],cost;j<a-1;j++){
      cin>>cost;
      int pos=g[i][j+1];
      G[pre].push_back(PP(P(pos,cost),P(i,j+1)));
      G[pos].push_back(PP(P(pre,cost),P(i,j)));
      pre=pos;
    }
  }

  P ans=dijkstra(0,1);
  if(ans==P(-1,-1)) cout<<-1<<endl;
  else cout<<ans.f<<" "<<ans.s<<endl;
  return 0;
}

Measured memory_bytes: 23612
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

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;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#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 shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n,m;
    cin >> n >> m;
    ll a[n],b[n];
    vpl v;
    F0R(i,n){
      cin >> a[i] >> b[i];
      v.pb(mp(a[i],b[i]));
    }
    sort(v.begin(),v.end());
    // F0R(i,n) cout << v[i].first << " " << v[i].second << endl;
    ll ans = 0;
    F0R(i,n){
      if(m > v[i].second) {
        ans += v[i].second*v[i].first;
        m -= v[i].second;
      } else {
        ans += m*v[i].first;
        cout << ans<<endl; return 0;
      }
    }


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 3568
fn main() {
    let n: usize = read::<usize>();
    let mut v: Vec<Vec<i64>> = vec![vec![]; 3];
    for _ in 0..n {
        let (a, b, c): (i64, i64, i64) = (read::<i64>(), read::<i64>(), read::<i64>());
        v[0].push(a);
        v[1].push(b);
        v[2].push(c);
    }
    let mut dp = vec![vec![0i64; n]; 3];
    dp[0][0] = v[0][0];
    dp[1][0] = v[1][0];
    dp[2][0] = v[2][0];
    for i in 1..n {
        dp[0][i] = max(dp[1][i.saturating_sub(1)], dp[2][i.saturating_sub(1)]) + v[0][i];
        dp[1][i] = max(dp[0][i.saturating_sub(1)], dp[2][i.saturating_sub(1)]) + v[1][i];
        dp[2][i] = max(dp[1][i.saturating_sub(1)], dp[0][i.saturating_sub(1)]) + v[2][i];
    }
    println!("{}", max(dp[2][n - 1], max(dp[0][n - 1], dp[1][n - 1])));
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: isize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 12540
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long 

int main(){
  ll n;
  cin >> n;
  ll a[n], sum=0;
  map<ll,ll> mp;
  for(ll i=0;i<n;i++){	cin >> a[i]; sum+=a[i]; mp[a[i]]++;}
  ll q;
  cin >> q;
  while(q--){
    ll bi, ci;
    cin >> bi >> ci;
    sum+=(ci-bi)*mp[bi];
    ll temp=mp[bi];
    mp[bi]=0;
    mp[ci]+=temp;
    cout << sum << endl;
  }
   return 0;                   
}

Measured memory_bytes: 10224
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
      
      ios
      int n;
      cin >> n;
      string str;
      set<string> s;
      while(n--){
            cin >> str;
            s.insert(str);
      }
      cout << s.size() <<"\n";

      return 0;
}


Measured memory_bytes: 19200
import java.util.Scanner;

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

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		int[] map = new int[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextInt();
		}
		
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < Math.pow(4, N); i++) {
			String tmp = "00000000" + Integer.toString(i, 4);
			char[] s = tmp.substring(tmp.length()-N,tmp.length()).toCharArray();
			
			int join = 0;
			int a = 0;
			int b = 0;
			int c = 0;
			for (int j = 0; j < s.length; j++) {
				if (s[j] == '0') {
					if (a != 0)
						join++;
					
					a+= map[j];
				} else if (s[j] == '1') {
					if (b != 0)
						join++;
					
					b+= map[j];
				} else if (s[j] == '2') {
					if (c != 0)
						join++;
					
					c+= map[j];
				}
			}
			
			if (a == 0 || b == 0 || c == 0)
				continue;
			
			int totalMp = Math.abs(A - a) + Math.abs(B - b) + Math.abs(C - c) + (join * 10);
			
			min = Math.min(totalMp, min);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 40728
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int num[30],hehe[5],color[111][111];
int h,w; 
char s[1001];
bool dfs(int x,int y){
	if(x==h+1)return true;
	if(color[x][y]){
		if(y==w)return dfs(x+1,1);
		else return dfs(x,y+1);
	}
	for(int c=1;c<=27;c++)
	if(num[c]){
		int i,j,cnt=1;color[x][y]=c;
		i=h-x+1,j=w-y+1;if(!color[i][j]){cnt++;color[i][j]=c;}
		i=x,j=w-y+1;if(!color[i][j]){cnt++;color[i][j]=c;}
		i=h-x+1,j=y;if(!color[i][j]){cnt++;color[i][j]=c;}
		if(num[c]>=cnt){
			num[c]-=cnt;
			bool could;
			if(y==w) could=dfs(x+1,1);
			else could=dfs(x,y+1);
			if(could)return could;
			num[c]+=cnt;
		}
		color[x][y]=0;
		i=h-x+1,j=w-y+1;color[i][j]=0;
		i=x,j=w-y+1;color[i][j]=0;
		i=h-x+1,j=y;color[i][j]=0;
	}
	return false;
}
int main(){
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++){
		scanf("%s",s);
		for(int j=0;j<w;j++)
		num[s[j]-'a'+1]++;
	}
	if((w&1)&&(h&1)){
		hehe[1]=1;
		hehe[2]=(w-1)/2+(h-1)/2;
		hehe[4]=(h*w-1-hehe[2]*2)/4;
		for(int i=1;i<=27;i++){
			if(num[i]){
				if(num[i]&1){
					if(!hehe[1]){
						printf("No\n");
						return 0;
					}
					hehe[1]=0;
					num[i]--;
				}
				if(hehe[4]>=num[i]/4){
					hehe[4]-=num[i]/4;
					num[i]%=4;
				}
				if(hehe[2]>=num[i]/2){
					hehe[2]-=num[i]/2;
					num[i]%=2;
				}
			}
		}
		for(int i=1;i<=27;i++)if(num[i]){
			printf("No\n");
			return 0;
		}
		printf("Yes\n");
		return 0;
	}
	else{
		if(!(w&1)&&!(h&1)){
			hehe[4]=w*h/4;
			for(int i=1;i<=27;i++)
			if(num[i]){
				hehe[4]-=num[i]/4;
				num[i]%=4;
			}
			for(int i=1;i<=27;i++)if(num[i]){
				printf("No\n");
				return 0;
			}
			printf("Yes\n");
			return 0;
		}	
		if(w&1){
			hehe[2]=h/2;
			hehe[4]=(w*h-h)/4;
			for(int i=1;i<=27;i++){
			if(num[i]){
				if(hehe[4]>=num[i]/4){
					hehe[4]-=num[i]/4;
					num[i]%=4;
				}
				if(hehe[2]>=num[i]/2){
					hehe[2]-=num[i]/2;
					num[i]%=2;
				}
				}
			}
			for(int i=1;i<=27;i++)if(num[i]){
				printf("No\n");
				return 0;
			}
			printf("Yes\n");
			return 0;
		}
		else{
			hehe[2]=w/2;
			hehe[4]=(w*h-w)/4;
			for(int i=1;i<=27;i++){
			if(num[i]){
				if(hehe[4]>=num[i]/4){
					hehe[4]-=num[i]/4;
					num[i]%=4;
				}
				if(hehe[2]>=num[i]/2){
					hehe[2]-=num[i]/2;
					num[i]%=2;
				}
				}
			}
			for(int i=1;i<=27;i++)if(num[i]){
				printf("No\n");
				return 0;
			}
			printf("Yes\n");
			return 0;
		}
	}
	
}

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

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll tmp = 0;
  vector <ll> v(n);
  ll sum = 0;
  rep(i, n) {
    cin >> v.at(i);
    sum += v.at(i);
  }
  rep(i, n) {
    if (sum%(4*m) == 0) {
      if (v.at(i) >= sum/(4*m)) tmp++;
    } else {
      if (v.at(i) > sum/(4*m)) tmp++;
    }
  }
  if (tmp >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from collections import defaultdict
a = int(input())
idxs = defaultdict(int)
idxs[a] = 1
i = 1
ans = None
while True:
  i += 1
  if a % 2 == 0:
    a //= 2
  else:
    a = 3 * a + 1
    
  if not idxs[a]:
    idxs[a] = i
  else:
    ans = i
    break

print(ans)
    
    



Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;


int main() {
	int n;
	long long  ans;
	string s;
	cin >> n >> s;

	int r_cnt=0, g_cnt=0, b_cnt=0;
	for (int i=0; i<n; i++) {
		if (s[i] == 'R') r_cnt++;
		if (s[i] == 'G') g_cnt++;
		if (s[i] == 'B') b_cnt++;
	}
	ans = r_cnt * g_cnt * b_cnt;

	int k;
	for (int i=0; i<n-2; i++) {
		for (int j=i+1; j<n-1; j++) {
			k = 2*j-i;
			if (k>=n) continue;
			if (s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k]) ans--;
		}
	}

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

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

int main() {
    int x, y;
    cin >> x >> y;

    list<int> listA{1, 3, 5, 7, 8, 10, 12};
    list<int> listB{4, 6, 9, 11};

    bool flag = false;
    if (x == 2 && y == 2) {
        flag = true;
    }

    bool xFlagA = false;
    bool yFlagA = false;
    for (auto itr = listA.begin(); itr != listA.end(); ++itr) {
        if (x == *itr) {
            xFlagA = true;
        }
        if (y == *itr) {
            yFlagA = true;
        }
    }

    bool xFlagB = false;
    bool yFlagB = false;
    for (auto itr = listB.begin(); itr != listB.end(); ++itr) {
        if (x == *itr) {
            xFlagB = true;
        }
        if (y == *itr) {
            yFlagB = true;
        }
    }

    if (flag || (xFlagA && yFlagA) || (xFlagB && yFlagB)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
long long N,max,t,ka,ans;
  cin>>N;
  max=0;
  ans=0;
  long long A[N],B[N];
    for(int j=0;j<N;j++){
      cin>>A[j];  
      B[j]=0;
      if(A[j]>max){
        max=A[j];
      }
  }
  ka=0;
  t=max/2;
      for(int j=0;j<N;j++){
      if(A[j]>t){
        A[j]=max-A[j];
        B[j]=1;
      }
        if(ka<A[j]){
          ka=A[j];
          if(B[j]==1){
            ans=max-A[j];
          }
          else{
            ans=A[j];
          }
        }
      }
    cout<<max<<" "<<ans<<endl;
}

Measured memory_bytes: 5188
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i = 1; i<n+1; i++)
typedef long long ll;

using namespace std;
const int V = 100005;
int INF = 1000000000;

int x,y;
int n;


int main(){
  int ans = -1000000009;
  int m;
  int tmp;
  cin >> n;
  cin >> m;
  rep(i,n){
    if (i == 0) continue;
    cin >> tmp;
    ans = max(tmp-m,ans);
    if (m > tmp) m = tmp;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
#define W 1000000007
using namespace std;

int main(){
	int n;
	cin>>n;
	string w[n],j="Yes",a,b;
	cin>>w[0];
	lp3(i,1,n){
		cin>>w[i];
		a = w[i-1];
		b = w[i];
		//cout<<w[i-1]<<" "<<w[i]<<endl;
		if(a[a.size()-1]!=b[0])j="No";
		lp2(ja,i){
			if(b == w[ja])j="No";
		}
	}
	cout<<j<<endl;
	return 0;
}


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

typedef long long LL;

int a[305];
LL bin[55],n;

int main()
{
	scanf("%lld",&n);
	bin[0]=1;
	for (int i=1;i<=50;i++) bin[i]=bin[i-1]*2;
	int m=50;
	while (bin[m]>n) m--;
	int tot=0,p=m+1;
	for (int i=1;i<=m;i++) a[++tot]=i;
	for (int i=1;i<=m;i++) a[++tot]=i;
	a[++tot]=m+1;a[++tot]=m+1;
	for (int i=m-1;i>=0;i--)
		if (n&bin[i])
		{
			tot++;
			for (int j=tot;j>i+1;j--) a[j]=a[j-1];
			p++;a[i+1]=a[++tot]=p;
		}
	printf("%d\n",tot);
	for (int i=1;i<=tot;i++) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6;
const ll inf=1e6;
int n,a[N];
ll dp[N];
ll f(int i)
{
    if(dp[i]!=-1) return dp[i];
    if(i==n) return 0;
    ll p1=inf,p2=inf;
    if(i<=(n-1)) p1=abs(a[i]-a[i+1])+f(i+1);
    if(i<=(n-2)) p2=abs(a[i]-a[i+2])+f(i+2);
    dp[i]=min(p1,p2);
    return dp[i];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    memset(dp,-1,sizeof(dp));
    printf("%lld",f(1));
    //while(1);
    return 0;
}

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

int main()
{ ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
    cin>>n>>x;
     if(n-x>=0)
      cout<<n-x;
      else
      cout<<"0";
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
//const int maxn=;
typedef long long ll;
string s,t;
int n;
int main(){
	cin>>n>>s>>t;
	for (int i=0;i<n;i++){
		cout<<s[i];
		cout<<t[i];
	}
}

Measured memory_bytes: 256
n, x = map(int, input().split())
a = sorted(list(map(int,input().split())))

if x == sum(a):
  print(n)
  exit()

else:
  c = 0
  for i in a:
    x -= i
    c += 1
    if x < 0:
      break
  print(c-1)

Measured memory_bytes: 3060