akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; ll X; cin >> n >> X;
    vector<ll> x(n); rep (i, n) cin >> x[i];
    ll ans = abs(x[0] - X);
    rep (i, 1, n) ans = gcd(ans, abs(x[i] - X));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;
  vector<Int> A(N);
  cin>>A;

  priority_queue<Int> Q;
  for(Int i=0;i<N;i++) Q.push(A[i]);

  while(M--){
    Int t = Q.top(); Q.pop();
    Q.push(t/2);
  }

  Int ans = 0;
  while(!Q.empty()) ans += Q.top(), Q.pop();
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2168
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  x-=a;
  cout<<x%b<<endl;


  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    int n;cin>>n;
    vi a(n);rep(i,n)cin>>a[i];sort(all(a));
    vi b;
    for(int i=a[0];i<=a[n-1];++i){
        int sum=0;
        rep(j,n){
            sum+=(a[j]-i)*(a[j]-i);
        }
        b.PB(sum);
    }
    sort(all(b));
    cout<<b[0]<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n, k;
    cin >> n >> k;
    vi x(n);
    rep(i, n) cin >> x[i];

    int sum = 0;
    rep(i, n) {
        sum += min(x[i], abs(k-x[i])) * 2;
    }

    cout << sum << endl;

    return 0;
}


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

using namespace std;

namespace mod {

template<class T, int M>
class MInt;

template<class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp);

template<class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n);

template<class T, int M>
class MInt {
  T n_;
public:
  MInt() : n_(0) {}
  MInt(T n) : n_((n % M + M) % M) {}

  MInt& operator+=(const MInt &rhs) {
    n_ += rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }
  
  MInt& operator-=(const MInt &rhs) {
    n_ += M - rhs.n_;
    if (n_ >= M) {
      n_ -= M;
    }

    return *this;
  }

  MInt& operator*=(const MInt &rhs) {
    n_ = n_ * rhs.n_ % M;
    return *this;
  }

  MInt& operator/=(const MInt &rhs) {
    return (*this) *= Inv(rhs);
  }

  T Get() {
    return n_;
  }
};

template<class T, int M>
MInt<T, M> operator-(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res -= rhs;
}

template<class T, int M>
MInt<T, M> operator+(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res += rhs;
}

template<class T, int M>
MInt<T, M> operator*(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res *= rhs;
}

template<class T, int M>
MInt<T, M> operator/(const MInt<T, M> &lhs, const MInt<T, M> &rhs) {
  MInt<T, M> res(lhs);
  return res /= rhs;
}

template<class T, int M>
MInt<T, M> Pow(const MInt<T, M> &base, T exp) {
  if (exp == 0) {
    return 1;
  }
  
  auto a = Pow(base, exp / 2);
  a *= a;
  if (exp % 2 == 1) {
    a *= base;
  }
  
  return a;
}

template<class T, int M>
MInt<T, M> Inv(const MInt<T, M> &n) {
  return Pow(n, static_cast<T>(M - 2));
}
}

using MInt = mod::MInt<long long, 1000000007>;
class BinCoef {
  vector<MInt> f;
public:
  BinCoef(int n): f(n + 1) {
    f[0] = f[1] = 1;
    for (int i = 2; i <= n; i++) {
      f[i] = MInt(i) * f[i - 1];
    }
  }

  MInt NCM(int n, int m) {
    return f[n] * mod::Inv(f[m] * f[n - m]);
  }
};

int main(int argc, const char *argv[])
{
  int n, k;
  cin >> n >> k;
  k = min(k, n - 1);

  BinCoef bc(n);

  MInt ans(0);
  for (int i = 0; i <= k; i++) {
    ans += bc.NCM(n, i) * bc.NCM(n - 1, i);
  }

  cout << ans.Get() << "\n";
}


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

int main() {
    string s, t;
    cin >> s >> t;
    puts(s == t.substr(0, t.size() - 1) ? "Yes" : "No");
}

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

typedef pair<int, int> P;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll mod = 1e9+7;
    ll ans = 0;
    rep(i,60){
        ll one = 0;
        rep(j,n)if(a[j]>>i&1) one++;
        ll tmp = one*(n-one)%mod;
        rep(j,i) tmp = tmp*2%mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b, x;
  cin >> a >> b >> x;
  if(a <= x && x <= a+b ) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict as ddic, deque, Counter
from itertools import permutations, combinations, product
import bisect, heapq
import Queue as queue 
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())

lower = []  # stored as negative
upper = []
sums = [0, 0]
def add(x):
    if len(lower) <= len(upper):
        heapq.heappush(lower, -x)
        sums[0] += x
    else:
        heapq.heappush(upper, x)
        sums[1] += x
    while lower and upper and -lower[0] > upper[0]:
        left = -heapq.heappop(lower)
        right = heapq.heappop(upper)
        sums[0] -= left
        sums[1] -= right
        heapq.heappush(lower, -right)
        heapq.heappush(upper, left)
        sums[0] += right
        sums[1] += left
    
    
B = [0]
def update(a, b):
    # f(x) += |x-a| + b
    B[0] += b
    add(a)
    
def report():
    # x that minimizes f(x)
    
    median = -lower[0]
    val = B[0]
    val += len(lower) * median - sums[0]
    val += sums[1] - len(upper) * median
    return median, val
    

Q = rri()
for _ in xrange(Q):
    query = rrm()
    if query[0] == 1:
        update(query[1], query[2])
    else:
        m,v = report()
        print m, v


Measured memory_bytes: 49560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
int t[15][15];
int main(){
    int n;
    int ans=0;
    cin >> n;
    //ready for mentions
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            //if no mention, then -1
            t[i][j] = -1;
        }
    }
    //get mentions
    for(int i=0;i<n;i++){
        int Ai=0;
        cin >> Ai;
        for(int j=0;j<Ai;j++){
            //i represents who mentions
            //x represents who is mentioned (need to adjust for array number)
            int x,y; cin >> x >> y; x--;
            t[i][x] = y;
        }
    }
    //test all patern of honest and unkind
    for(int i=0; i < (1 << n); i++){
        bool ok=true;
        //vector person is made for convenience in terms of implementation.
        //if person[i]=1 then he/she is assumed to be honest
        //if person[i]=0 then he/she is assumed to be unkind
        vector<int> person(n);
        for(int j=0; j<n;j++){
            //if person[i] is honest, put flug to person[i]
            if(1 & (i>>j)) person[j] = 1;
        }
        //Check Integrity between assumption and mentions
        for(int j=0;j<n;j++){
            //ignore unkind person
            if(person[j]==1){
                //for honest person, verify his/her mention
                for(int k=0; k < n; k++){
                    // nothing menthioned
                    if(t[j][k] == -1) continue;
                    // It's not correct if assumption and mention differ.
                    if(t[j][k] != person[k]) ok=false;
                }
            }
        }
        // __builtin_popcount(i) means number of active bits of given value.
        if(ok) ans=max(ans,__builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    char c;
    cin >>c;
    cout << char(c+1) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n, i[1000], j[10000], x, a, b;
	while(1)
	{
		a=0;
		b=0;
		scanf("%d", &n);
		if(n==0)
		break;
		
		for(x=0; x<n; x++)
		{
			scanf("%d %d", &i[n], &j[n]);
			if(i[n]>j[n])
			a+=i[n]+j[n];
			
			if(i[n]<j[n])
			b+=i[n]+j[n];
			
			if(i[n]==j[n])
			{
				a+=i[n];
				b+=j[n];
			}
		}
		printf("%d %d\n", a, b);
	}
	
	return 0;
}


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

using namespace std;
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 1010
ll h,w,f[N][N];
char c[N][N];
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>c[i][j];
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
     if(i==0&&j==0)f[i][j]=1;
     else if(i==0){
      f[i][j]=f[i][j-1]*(c[i][j]=='.');   
     }
     else if(j==0){
      f[i][j]=f[i-1][j]*(c[i][j]=='.');   
     }
     else{
      f[i][j]=(f[i-1][j]+f[i][j-1])%mod*(c[i][j]=='.');
     }
    }
    cout<<f[h-1][w-1]<<endl;
 return 0;   
}

Measured memory_bytes: 9088
import math

t = [int(input()) for _ in range(5)]

min1 = map(lambda x: x % 10, t)
min1 = min([10 if i == 0 else i for i in min1])

print(sum(map(lambda x: math.ceil(x) * 10, [i/10 for i in t])) - (10 - min1))


Measured memory_bytes: 3060
import java.util.Arrays;
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 = new int[n];
        int max = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            max = Math.max(max, a[i]);
        }

        int[] b = new int[n];
        for (int i = 0 ; i < n ; i++) {
            b[i] = a[i];
        }

        Arrays.sort(b);

        int maxNum = b[b.length - 1];
        int secondNum = b[b.length - 2];
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == maxNum) {
                System.out.println(secondNum);
            } else {
                System.out.println(maxNum);
            }
        }

    }

}


Measured memory_bytes: 110124
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

static const int MOD = 998244353;

typedef long long ll;

int N;
int ans;
pair<int, int> pr[200005];

int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) {
      int A, B;
      scanf("%d %d", &A, &B);
      pr[i] = make_pair(B, -1*A);
     }

    sort(pr, pr+N);
    
    int t = 0;
    
    rep(i, 0, N) {
      t += pr[i].second * -1;
      if (t > pr[i].first) {
        puts("No");
        return 0;
      }
    } 
    

    puts("Yes");

	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

int main() {
  long n;
  std::cin >> n;

  std::vector<long> t(3);
  long m = n;
  long a = 2;
  while (m >= a * a) {
    if (m % a == 0) {
      ++t.at(a);
      m /= a;
    } else {
      ++a;
      t.push_back(0);
    }
  }
  if (m >= 2) {
    if ((int)t.size() - 1 == m)
      ++t.at(m);
    else
      t.push_back(1);
  }

  if (!t.size()) {
    std::cout << 0 << std::endl;
    return 0;
  }

  int ans = 0;
  for (auto i : t) {
    if (i == 0)
      continue;
    for (int j = 1; i >= 0; ++j) {
      if (i - j >= 0) {
        ++ans;
      }
      i -= j;
    }
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 15148
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    ll x; cin >> x;
    ll min = x/105;
    ll max = x/100 + 2;
    Rep(i, min, max) {
        if(100*i <= x && x <= 105*i) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

int main()
{
	speed;
	
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)+1-a-b;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const int INF = 1e8;

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

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

#define MP make_pair

using namespace std;

typedef pair<int, int> PII;

vector<vector<int>> vis;
vector<string> g;
int h, w;

PII dfs(int x, int y) {
	vis[x][y] = 1;
	PII res = MP(0, 0);
	if (g[x][y] == '#') {
		res.first += 1;
	} else {
		res.second += 1;
	}
	if (x && !vis[x - 1][y] && g[x - 1][y] != g[x][y]) {
		PII r = dfs(x - 1, y);
		res.first += r.first;
		res.second += r.second;
	}
	if (x < h - 1 && !vis[x + 1][y] && g[x + 1][y] != g[x][y]) {
		PII r = dfs(x + 1, y);
		res.first += r.first;
		res.second += r.second;
	}
	if (y && !vis[x][y - 1] && g[x][y - 1] != g[x][y]) {
		PII r = dfs(x, y - 1);
		res.first += r.first;
		res.second += r.second;
	}
	if (y < w - 1 && !vis[x][y + 1] && g[x][y + 1] != g[x][y]) {
		PII r = dfs(x, y + 1);
		res.first += r.first;
		res.second += r.second;
	}
	return res;
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		string l;
		cin >> l;
		g.push_back(l);
		vis.push_back(vector<int>(w, 0));
	}
	long long ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (vis[i][j]) {
				continue;
			}
			PII cnt = dfs(i, j);
			// cout << cnt.first << " " << cnt.second << endl;
			ans += 1LL * cnt.first * cnt.second;
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> m;
    m[a]++;
    m[b]++;
    m[c]++;
    if(m[5] == 2 && m[7] == 1)  cout << "YES" << endl;
    else                        cout << "NO" << endl;


 
    return 0;
}

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

bool ok(char c1, char c2) {
	if(c1 == c2) return c1 == 'i' || c1 == 'w';
	return c1 + c2 == '(' + ')';
}

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

	string s;
	cin >> s;

	const int len = s.size();

	int ans = ((len & 1) && !isalpha(s[len / 2])) ? 1 : 0;
	for(int i = 0; i < len / 2; ++i) {
		if(!ok(s[i], s[len - i - 1])) ++ans;
	}
	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1188
N = int(input())
gr = 0
A = []
B = [0]*31
for i in range(N):
  A.append(int(input()))
  B[len(bin(A[i]^(A[i]-1)))-3] += 1
for i in range(N):
  gr ^= A[i]
ans = 0
for i in range(31):
  k = 30 - i
  if gr & (2 ** k):
    if B[k] == 0:
      ans = -1
      break
    else:
      ans += 1
      gr = ~gr
print(ans)

Measured memory_bytes: 7104
m, d = map(int, input().strip().split())
k = 0

for i in range(1,d+1):
    if (i%10)*((i-i%10)/10) <= m and (i%10)*((i-i%10)/10) != 0 and i%10 >= 2 and i-i%10 >= 20:
        k += 1
        
print(k)  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
   ll k,n,ans=1000000000000;
 
   cin>>n>>k;
   vll a(n);
   rep(i,n)cin>>a.at(i);
   
   for (int tmp = 0; tmp < (1 << (n-1)); tmp++) {
    bitset<14> s(tmp);  
    
    int sum = 0;
    for (int i = 0; i < n-1; i++) {
      if (s.test(i)) {
        sum ++;
      }
    }
    if(sum>=k-1){
        
        ll h=a.at(0);
        ll money=0;
        
        rep(i,n-1){
            if(s.test(i)){
                if(h+1<=a.at(i+1)){
                    h=a.at(i+1);
                }else{
                    money+=(h+1-a.at(i+1));
                    h++;
                }
            }
            h=max(h,a.at(i+1));
        }
        ans=min(ans,money);
    }
   
  }
  if(k==1)cout<<0<<endl;
  else cout<<ans<<endl;

}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int m, n;
int l;

//i番目が0cmになるまでの時間
int memo[100002];
Array arr;
int dfs(int idx)
{
	if(memo[idx] != -1) return memo[idx];

	int lt = 0, rt = 0;
	if(arr[idx] < arr[idx - 1])
		lt = dfs(idx - 1);
	if(arr[idx] < arr[idx + 1])
		rt = dfs(idx + 1);

	return memo[idx] = max(lt, rt) + (l - arr[idx]);
}

int main(void)
{
	while(cin >> n >> l && n)
	{
		memset(memo, -1, sizeof(memo));
		memo[0] = 0;
		memo[n + 1] = 0;
		arr.resize(n + 2);
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i + 1];
		}

		int ans = 0;
		for (int i = 1; i < n + 1; i++)
		{
			ans = max(ans, dfs(i));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

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

        while(true) {
        	String cards = sc.nextLine();
        	if(cards.equals("-")) {
        		break;
        	}

            int count = Integer.parseInt(sc.nextLine());;
            for(int i = 0; i < count; i++) {
            	int shuffleNum = Integer.parseInt(sc.nextLine());
            	cards = cards.substring(shuffleNum) + cards.substring(0, shuffleNum);
            }
            System.out.println(cards);
        }
    }
}


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

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

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main(){
    long long int a,b;
    cin >> a >> b;
    if(a % b == 0){
        cout << -1 << endl;
        return 0;
    }
    if(lcm(a,b) == a){
        cout << -1 << endl;
        return 0;
    }

    for(long long int i = a; ; i += a){
        if(i % b != 0){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void){
	int x, n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        x = i;
        if (x % 3 == 0) {
            printf(" %d", x);
        } else {
            do {
                if (x % 10 == 3) {
                     printf(" %d", i);
                     break;
                }
                x /= 10;
            } while (x);
        }
    }
    printf("\n");
}




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

bool grid[22][22];

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < W; j++) grid[i][j] = true;
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < w; j++) grid[i][j] = true;
    }
    int cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j]) cnt++;
        }
    }
    cout << H * W - cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int[] ans = new int[n];
    boolean[] visited = new boolean[n];
    ArrayList<Integer>[] edge = new ArrayList[n];
    ArrayList<Integer> queue = new ArrayList<>();
    for(int i = 0; i < n; i++){
          edge[i] = new ArrayList<>();
          ans[i] = -1;
          visited[i] = false;
        }

    for (int i = 0; i < m; i++) {
          int a = sc.nextInt()-1;
    		  int b = sc.nextInt()-1;
    		  edge[a].add(b);
    		  edge[b].add(a);
    		}

    queue.add(0);
    while(queue.size() != 0){
    int x = queue.get(0);
    queue.remove(0);
    for(int i : edge[x]){
      if(visited[i] == false){
        queue.add(i);
        if(ans[i] == -1){
          ans[i] = x;
          visited[i] = true;
        }
      }
    }

    }

		int[] copyans = Arrays.copyOfRange(ans, 1, ans.length);
    if(Arrays.asList(ans).contains(-1)){
         System.out.println("No");
    }
    else{
      System.out.println("Yes");
        for(int a: copyans){
          System.out.println(a+1);
        }
    }
  }
}


Measured memory_bytes: 81408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = 1000000000;
ll inf = 1000000000000;
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; }
int main() {
	string s;
	cin >> s;
	string ans = "";
	int Len = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '0') {
			ans += "0";
			Len++;
		}
		if (s[i] == '1') {
			ans += "1";
			Len++;
		}
		if (s[i] == 'B' && Len >= 1) {
			ans.erase(Len - 1);
			Len--;
		}
	}
	cout << ans;
	return(0);
}

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

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll cnt(0);
    for(int i=1;i<n-1;i++){
        if( (a[i] < a[i+1] && a[i] > a[i-1] ) || ( a[i] > a[i+1] && a[i] < a[i-1]))
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
// ABC 073 B - Theater
#include <iostream>
#include <vector>
using namespace std;

int main(void){
  //input
  int N;
  vector<int> L,R,diff;
  int sum=0;
  
  cin >> N;

  for(int i=0; i<N ;++i){
    int tmp;
    cin >> tmp; L.push_back(tmp);
    cin >> tmp; R.push_back(tmp);
    diff.push_back(R.at(i)-L.at(i));
    sum = sum + diff.at(i) + 1;
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
lp = [3,5,7,11,13]

ans = 0
for i in (range(n)):
  li = []
  for k in lp:
    tmp = i+1
    cnt = 0
    while tmp%k == 0:
      tmp //= k
      cnt += 1
    if cnt > 0:
      li.append(cnt)
  if li in [[1,1,1], [3,1]]:
    ans += 1

print(ans)

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

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define smallk order_of_key
#define kth find_by_order
*/

#define nl '\n'
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

typedef long long ll;

const int N = (int)1e6 + 123;
const int M = 1e9 + 7;
const int K = 500;

int n, k, a[N], dp[N];
int main(){

    //ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #ifdef LOCAL
        freopen("C.txt", "r", stdin);
    #endif // LOCAL

    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    dp[1] = 0;
    for(int i = 2; i <= n; ++i){
        dp[i] = M;
        for(int j = 1; j <= k; ++j){
            if(i - j <= 0){
                break;
            }
            dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
        }
    }
    cout << dp[n];
    return 0;
}



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

int main() {
  int n,tot = 0;
  cin >> n;
  vector<int> w(n);
  rep(i,n) {
    cin >> w[i];
    tot += w[i];
  }
  int sum = 0,k,ans = 1000000;
  rep(i,n){
    sum += w[i];
    k = abs(tot - 2*sum);
    ans = min(ans, k);
  }

  cout << ans << endl;
  return 0;


}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <queue>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <ctime> 
using namespace std;

#define pb push_back
#define All(a) a.begin(), a.end()
#define met(a, b) memset(a, b, sizeof(a))
#define rep1(i, l, r) for(int i = l; i <= r; ++i)
#define rep2(i, l, r) for(int i = l; i < r; ++i) 
#define per(i, r, l) for(int i = r; i >= l; --i)
typedef long long ll;
typedef double db;
typedef long double ldb;
const int NIL = -1;
const int oo = 0x3f3f3f3f;
const ll INF = 2e18;
const db eps = 1e-8;
const db PI = acos(-1.0);
const int maxn = 2e5 + 7;

int T[maxn], c[maxn], a[maxn];

inline int read(void)
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{ if(ch == '-') f = -1; ch = getchar(); } 
	while(ch >= '0' && ch <= '9') {	x = (x << 1) + (x << 3) + ch - '0';	ch = getchar();	}
	return x * f;
}

inline void write(int x)
{
	if(x < 0) { putchar('-'); x = -x; }
    if(x >= 10) write(x/10); 
	putchar(x%10+'0'); 
}

int lowbit(int x)
{
	return x&(-x);
}

void upd(int idx, int val)
{
	for(int i = idx; i < maxn; i += lowbit(i))
	{
		c[i] += val;
	}
}

ll qry(int idx)
{
	ll ans = 0;
	for(int i = idx; i > 0; i -= lowbit(i))
	{
		ans += c[i];
	}
	return ans;
}

bool check(ll n)
{
	met(c, 0);
	ll sum = 0;
	rep1(i, 0, n)
	{
		sum += qry(T[i]);
		upd(T[i], 1);
	}
	return sum >= (n * (n - 1) / 2 + n - 1) / 2 + 1;
}

int main(void)
{
	int n = read();
	int l = 1, r = 0;
	rep1(i, 1, n)
	{
		a[i] = read();
		r = max(r, a[i]);
	}
	T[0] = 1e5 + 1;
//	if(n == 1)
//	{
//		printf("%d", a[1]);
//		return 0;
//	}
	while(l <= r)
	{
		int mid = (l + r) >> 1;
		rep1(i, 1, n)
		{
			T[i] = T[i-1] + (a[i]>=mid?1:-1);
		} 
		if(check(n)) l = mid + 1;
		else r = mid - 1;
	}
	printf("%d", l-1);
	
	return 0;
} 

Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		long a,b;


		while((str=br.readLine()) != null){
			a = Long.parseLong(str.substring(0, str.indexOf(" ")));
			b = Long.parseLong(str.substring(str.indexOf(" ")+1, str.length()));

			System.out.println(gcd(a, b) + " " + lcm(a,b));

		}
	}

	static long gcd(long a,long b){
		return b == 0 ? a : gcd(b,a%b);
	}

	static long lcm(long a, long b){
		return b*a/gcd(a,b);
	}
}

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

using namespace std;

int solve(string s,char c,int n){
    bool flag=1;
    string s1;
    for(int j=0;j<s.length()-1;++j){
        if(s[j]==c || s[j+1]==c){
            s1+=c;
        }else{
            flag=0;
            s1+=s[j];
        }
    }
    if(flag)return n;
    else return solve(s1,c,n+1);
}

int main(){
    string s;
    cin>>s;
    int mi=1000;
    for(char i='a';i<='z';++i){
        mi=min(mi,solve(s,i,1));
    }
    bool flag=1;
    for(int i=0;i<s.length()-1;++i){
        if(s[i]!=s[i+1])flag=0;
    }
    if(flag)mi=0;
    cout<<mi<<endl;
}


Measured memory_bytes: 384
h,w=map(int,input().split())

ans=[[0]*w for i in range(h)]
s=[[""]*w for i in range(h)]
for i in range(h):
  s[i]=input()

for i in range(h):
  for j in range(w):
    if (s[i][j]=="#"):
      ans[i][j]="#"
      if (i-1>=0 and j-1>=0):
        if (ans[i-1][j-1]!="#"):
            ans[i-1][j-1]+=1
      if (i-1>=0):
         if (ans[i-1][j]!="#"):
            ans[i-1][j]+=1
      if (i-1>=0 and j+1<w):
        if (ans[i-1][j+1]!="#"):
          ans[i-1][j+1]+=1
      if (j-1>=0):
        if (ans[i][j-1]!="#"):
          ans[i][j-1]+=1
      if (j+1<w):
        if (ans[i][j+1]!="#"):
          ans[i][j+1]+=1
      if (i+1<h and j-1>=0):
        if (ans[i+1][j-1]!="#"):
          ans[i+1][j-1]+=1
      if (i+1<h):
        if (ans[i+1][j]!="#"):
          ans[i+1][j]+=1
      if (i+1<h and j+1<w):
        if (ans[i+1][j+1]!="#"):
          ans[i+1][j+1]+=1
    

for i in range(h):
  answer=""
  for j in range(w):
    answer+=str(ans[i][j])
  print(answer)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long

#define nl printf("\n")
#define pb(x) push_back(x)

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define P(a) printf("%d",a)

#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)

#define PL(a) printf("%lld",a)
#define PLN(a) printf("%lld\n",a)
#define PLC(a) printf("%lld ",a)
#define SL(a) scanf("%lld",&a)
#define SL2(a,b) scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define SL4(a,b,c,d) scanf("%lld%lld%lld%lld",&a,&b,&c,&d)

#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define FOOL(a) memset(a,false,sizeof(a))
#define fr(i,a,n) for(i=a;i<=n;i++)
#define frv(i,v) for(i=0;i<(int)v.size();i++)
#define pi acos(-1.0)
#define po 1000000
#define co 1000000
#define mod 786433

using namespace std;
ll f[100000];
bool pal(ll x)
{
     vector<ll> v;
     ll y,i;
     while(x!=0)
     {
         y=x%10;
         v.pb(y);
         x/=10;
     }
     y=v.size();
     for(i=0;i<y;i++)
         if(v[i]!=v[y-1-i])
             return false;
     return true;
}
int main()
{   
    ll i,a,b,ans;
    CLR(f);
    for(i=10000;i<=99999;i++)
    {
        f[i]=f[i-1];
        if(pal(i))f[i]++;
    }
    SL(a),SL(b);
    ans=f[b]-f[a-1];
    PLN(ans);
}



Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n;
string a, b, c;
int solve() {
  vector<vector<int>> t(3, vector<int>(n));
  REP(i, n) {
    if (a[i] != b[i])
      ++t[0][i];
  }
  REP(i, n) {
    if (a[i] != c[i])
      ++t[1][i];
  }
  REP(i, n) {
    if (b[i] != c[i])
      ++t[2][i];
  }
  int ret{};
  REP(i, n) {
    int sum{};
    REP(k, 3) {
      if (t[k][i] > 0)
        ++sum;
    }
    if (sum == 2)
      ++ret;
    else if (sum == 3)
      ret += 2;
  }
  return ret;
}

int main() {
  cin >> n >> a >> b >> c;
  cout << solve() << endl;
}

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

using namespace std;

typedef long long ll;

ll n;
ll ans;

int main()
{
    cin>>n;
    ans += n / 500 * 1000;
    n %= 500;
    ans += n / 5 * 5;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    ll n, k;
    cin >> n >> k;
    vll a(n);
    vector<bool> vis(n, 0);
    vll time(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }

    //rep(i,n)cout << a[i] << ((i < n-1)?" ":"\n");

    ll pos = 0, s, g;
    while(1){
        vis[pos] = 1;
        pos = a[pos];
        if(vis[a[pos]]){
            s = a[pos];
            g = pos;
            break;
        }
    }
    //cout << endl << s << " " << g << endl;
    
    pos = 0;
    ll l1 = 0, l2 = 1;
    bool cn = 0;
    while(pos != g){
        //cout << pos << " ";

        if(pos == s)cn = 1;
        pos = a[pos];
        if(cn)l2++;
        else l1++;
    }
    //cout << endl << l1 << " " << l2 << endl;


    //cout << k << " " << (k-l1)%l2 << endl;
    pos = 0;
    if(l1 <= k){
        //cout << "ok" << endl;

        k = (k - l1) % l2;
        pos = 0;
        while(pos != s)pos = a[pos];
    }
    while(k > 0){
        pos = a[pos];
        k--;
    }
    cout << pos + 1 << endl;

    return 0;
}  

Measured memory_bytes: 6376
(def A (read))
(def B (read))
(println (cond
  (and (= A 1) (= B 2)) 3
  (and (= A 1) (= B 3)) 2
  (and (= A 2) (= B 1)) 3
  (and (= A 2) (= B 3)) 1
  (and (= A 3) (= B 1)) 2
  (and (= A 3) (= B 2)) 1))

Measured memory_bytes: 77780
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  int count=0;
  while(true){
    if(b<=0 || (b==1 && count==0)){
      break;
    }
    if(count!=0){
      b++;
    }
    b-=a;
    count++;
  }
  cout<<count<<'\n';
  return(0);
}


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

int main() {
  int N;
  cin >> N;
  string S;
  int check = 0; // ひなあられ 'Y' が見つかったかどうかを判定する変数
  for(int i = 0; i < N ; i++){
     cin >> S;
     if(S == "Y"){
     	check = 1;
        break;
     }
  }
  if(check == 0){
  	cout << "Three" << endl;
  }else{
  	cout << "Four" << endl;
  }
}


Measured memory_bytes: 3580
function parseInt(x) parse(Int, x) end

function main()
	n = parseInt(readline())
	s = split(readline())
	flg = 0
	for i in 1:n
		if s[i] == "Y"
			flg = 1
		end
	end
	if flg == 0
		print("Three")
	else
		print("Four")
	end
end
main()

Measured memory_bytes: 108680
N,K,Q=map(int,input().split()) #Nは人の人数、Kはみなが最初に持っているポイント、Qはクイズの回数
L=[K-Q]*N #
for i in range(Q):
    m=int(input())-1
    L[m]+=1
for k in range(N):
    if L[k]>0:
        print("Yes")
    else:
        print("No")

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.14159265359;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[5] = {0, 1, 0, -1};

using namespace std; 

ll nCr(ll n, ll r)
{
    ll x = 1;
    ll y = 1;

    irep(i, r) {
        x *= n-i;
        y *= r-i;    
    }

    return x / y;
}

int main(void)
{
    int n;
    cin >> n;

    map<int, int> a;
    v_int v(n);

    irep(i, n) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
        v[i] = tmp;
    }
    
    map<ll, ll> comb1;
    map<ll, ll> comb2;
    
    ll sum = 0;
    for(auto mp : a) {
        int x = mp.first;
        int y = mp.second;
        if(2 <= y) { 
            comb1[x] = nCr(y, 2);
        }
        if(2 <= y-1) { 
            comb2[x] = nCr(y-1, 2);
        }
        //printf("%d,%d\n", comb1[x], comb2[x]); 
        sum += comb1[x];
    }
    
    irep(i, n) {
        cout << sum - comb1[v[i]] + comb2[v[i]] << endl;
    }
    return 0;
}
/** atcoder **/



Measured memory_bytes: 24064
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long N;
    cin >> N;

    long long sq = sqrt((double)N);
    vector <int> pows;

    for (int v = 2; v <= sq; ++v) {
        int cnt = 0;

        while (N % v == 0) {
            ++cnt;
            N /= v;
        }

        if (cnt) {
            pows.push_back(cnt);
        }
    }

    if (N != 1) { // prime
        pows.push_back(1);
    }

    int ans = 0;
    for (int i = 0; i < pows.size(); ++i) {
        // x(x+1)/2 <= pows[i]
        // x(x+1) <= 2*pows[i]
        int low = 0;
        int up = 2*pows[i];
        int res = 0;

        while (low <= up) {
            int mid = (low+up) / 2;

            if (mid*(mid+1) <= 2*pows[i]) {
                res = mid;
                low = mid+1;
            } else {
                up = mid-1;
            }
        }

        ans += res;
    }

    cout << ans << endl;

    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll x;
    cin>>x;
    ll cnt=0;
    ll money=100;
    while (money<x)
    {
        money = (ll)(money*1.01);
        cnt++;
    }
    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
// luogu-judger-enable-o2
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int sabs(int a){
    if(a<0)return a*-1;
    return a;
}
int main(){
    int n,x=0,y=0,t=0;
    cin>>n;
    while(n--){
        int c,a,b;
        cin>>c>>a>>b;
        if(abs(x-a)+abs(y-b)>c-t){
            cout<<"No";
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1){
            cout<<"No";
            return 0;
        }
        if((abs(x-a)+abs(y-b))%2==1 &&(c-t)%2==0){
            cout<<"No";
            return 0;
        }
        x=a;y=b;t=c;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int r;
    cin >> r;
    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256