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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int MAXN = 333;
double dp[MAXN][MAXN][MAXN];
bool mark[MAXN][MAXN][MAXN];
int n;

double f(int k1, int k2, int k3) {
	if(k1 < 0 || k2 < 0 || k3 < 0)
		return 0;
	if(mark[k1][k2][k3])
		return dp[k1][k2][k3];
	if(k1 + k2 + k3 == 0)
		return 0;
	double ret = n;
	ret += k1 * f(k1 - 1, k2, k3);
	ret += k2 * f(k1 + 1, k2 - 1, k3);
	ret += k3 * f(k1, k2 + 1, k3 - 1);
	ret /= k1 + k2 + k3;
	mark[k1][k2][k3] = 1;
	return dp[k1][k2][k3] = ret;
}

int32_t main() {
	cin >> n;
	vi a(n);
	int kk1 = 0, kk2 = 0, kk3 = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] == 1)
			kk1++;
		else if(a[i] == 2)
			kk2++;
		else if(a[i] == 3)
			kk3++;
	}	
	for(int k3 = 0; k3 <= n; k3++) {
		for(int k2 = 0; k2 <= n; k2++) {
			for(int k1 = 0; k1 <= n; k1++) {
				if(k1 + k2 + k3 == 0)
					continue;
				int k0 = n - k1 - k2 - k3;
				dp[k1][k2][k3] = n;
				if(k1)
					dp[k1][k2][k3] += k1 * dp[k1 - 1][k2][k3];
				if(k2)
					dp[k1][k2][k3] += k2 * dp[k1 + 1][k2 - 1][k3];
				if(k3)
					dp[k1][k2][k3] += k3 * dp[k1][k2 + 1][k3 - 1];
				if(k1 + k2 + k3)
					dp[k1][k2][k3] /= (k1 + k2 + k3);
			}
		}
	}
	cout << fixed << setprecision(15) << dp[kk1][kk2][kk3] << '\n';
}


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

int main(){
  string S;
  cin >> S;
  
  if (S == "RRR"){
    cout << 3 << endl;
  }
  else if (S == "RRS" || S == "SRR"){
    cout << 2 << endl;
  }
  else if (S == "SSS"){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3564
#include<iostream>

using namespace std;

int mouth[]={-1,31,29,31,30,31,30,31,31,30,31,30,31};

int main(void){

	int mo,da,wa;

	while(1){
		wa=0;
		cin>>mo>>da;
		if(mo==0||da==0) break;
		for(int i=1;i<mo;i++) wa+=mouth[i];
		wa+=da;
		switch(wa%7){
		case 1:
			cout<<"Thursday"<<endl;
			break;
		case 2:
			cout<<"Friday"<<endl;
			break;
		case 3:
			cout<<"Saturday"<<endl;
			break;
		case 4:
			cout<<"Sunday"<<endl;
			break;
		case 5:
			cout<<"Monday"<<endl;
			break;
		case 6:
			cout<<"Tuesday"<<endl;
			break;
		case 0:
			cout<<"Wednesday"<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
 
using namespace std;
 
int main(){
    int A, B;
    char op;

    cin >> A >> op >> B;
    
    int ans;
    if(op == '+') ans = A + B;
    else ans = A - B;

    cout << ans << endl;     


    return 0;
}

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

using namespace std;

int main()
{
    string s, t, u;
    int a, b;

    cin >> s >> t >> a >> b >> u;

    if (u == s)
        a--;
    if (u == t)
        b--;

    cout << a << " " << b << "\n";

    return 0;
}

Measured memory_bytes: 256
# ABC 108: B – Ruined Square
x1, y1, x2, y2 = [int(s) for s in input().split()]
x3, y3 = x2 - (y2 - y1), y2 + (x2 - x1)
x4, y4 = x1 - (y2 - y1), y1 + (x2 - x1)
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

vector<ll> built(ll k) {
	vector<ll> ans;
	ll d = k % 50;
	rep(i, 50 - d) ans.push_back(49 - d);
	rep(i, d) ans.push_back(50);
	ll a = k / 50;
	rep(i, 50) ans[i] += a;
	return ans;
}

int main()
{
	ll k;
	cin >> k;
	auto ans = built(k);
	int n = ans.size();
	cout << n << endl;
	rep(i, n) {
		if (i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0
I = []
for i in range(n-2):
    if s[i] not in I:
        I.append(s[i])
    else:
        continue
    J = []
    for j in range(i+1, n-1):
        if s[j] not in J:
            J.append(s[j])
        else:
            continue
        K = []
        for k in range(j+1, n):
            if s[k] not in K:
                K.append(s[k])
                ans += 1
print(ans)

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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, L, t;
long long a[N], w[N];

bool read() {
    if (!(cin >> n >> L >> t))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i] >> w[i];

    return true;
}

void solve() {
    auto cnt = 0ll;
    vector<long long> x;

    auto dist = [](int i) {
        if (w[0] == 1)
            return a[i] - a[0];

        return (L + a[0] - a[i]) % L;
    };

    for (int i = 0; i < n; ++i) {
        auto nx = a[i] + t * (w[i] == 1 ? 1 : -1);
        x.emplace_back((L + nx % L) % L);
        cnt += (nx - (nx % L + L) % L) / L;
    }

    cnt = (n + cnt % n) % n;
    sort(x.begin(), x.end());

    for (int i = 0; i < n; ++i)
        cout << x[(i + cnt) % n] << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll mod = 1e9+7;

struct UnionFind {
    vll par;
    vll _size;

    UnionFind(ll N) : par(N), _size(N, 1) {
        rep(i, N) par[i] = i;
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        _size[ry] += _size[rx];
        _size[rx] = 0;
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x) {
        return _size[root(x)];
    }
};

ll modinv(ll a, ll m) {
    ll x = a, y = m, u = 1, v = 0;
    while (y) {
        ll div = x / y;
        x -= div * y; swap(x, y);
        u -= div * v; swap(u, v);
    }
    return (u % m + m) % m;
}

ll comb(ll n, ll k) {
    ll dividend = 1, divisor = 1;
    rep(i, k) {
        dividend = (dividend * (n - i)) % mod;
        divisor = (divisor * modinv(i + 1, mod)) % mod;
    }
    return (dividend * divisor) % mod;
}

int main()
{
    ll N, M; cin >> N >> M;
    UnionFind uf(N);
    vll A(M), B(M);
    rep(i, M) {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    vll ans(M, 0);
    ll origin = N * (N - 1) / 2;
    for (ll i = M - 1; i >= 0; i--) {
        ll a = A[i], b = B[i];
        ans[i] = origin;
        if (!uf.same(a, b)) origin -= uf.size(a) * uf.size(b);
        uf.unite(a, b);
    }

    for (auto elem : ans) {
        cout << elem << endl;
    }
    return 0;
}


Measured memory_bytes: 5248
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
bool isPrime(int n) {
  // returns whether n is prime number or not
  // n should be in range [0, lim].
  // to see detail, search "Sieve of Eratosthenes"
  static int lim = 1e5;
  static bool done = false;
  static vector<bool> isp(lim + 1, 1);
  if (!done) {
    isp[0] = isp[1] = false;
    for (int i = 2; i <= lim; i++) {
      if (isp[i]) {
        for (int j = i + i; j <= lim; j += i) {
          isp[j] = false;
        }
      }
    }
    done = true;
  }
  return isp[n];
}

int main() {
  LL n;
  cin >> n;
  VEC<LL> prime;
  REP(i, 0, 1001) {
    if (isPrime(i))
      prime.push_back(i);
  }
  int m = prime.size();
  int num = 1;
  VEC<int> p(m, 0);
  REPC(num, 1, n) {
    REP(i, 0, m) {
      int tmp = num;
      while (tmp>1 &&tmp % prime[i]==0) {
        ++p[i];
        tmp /= prime[i];
      }
    }
  }
  DUMP(prime);
  DUMP(p);
  LL ans = 1;
  REP(i, 0, m) { ans = (ans * (p[i] + 1)) % ((LL)1e9 + 7); }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 7 * 17 * (1 << 23) + 1;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, a, b, c, d;
int main() { //DINIC ORZ, FFT ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> a >> b >> c >> d;
	b-=a;
	n--;
	for(ll neg = 0; neg <= n; neg++) {
		ll L = (n-neg)*c-neg*d;
		ll R = (n-neg)*d-neg*c;
		if(b>=L&&b<=R) return cout << "YES", 0;
	}
	cout << "NO\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, l, r;
    cin >> N >> M;
    int maxL = 1, minR = N;
    REP(i, M)
    {
        cin >> l >> r;
        if (l > maxL)
        {
            maxL = l;
        }
        if (r < minR)
        {
            minR = r;
        }
    }
    cout << ((minR - maxL >= 0) ? (minR - maxL + 1) : 0) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N;
	cin>>N;
	vector<string>AA(100000);
	vector<int>ans(10);
	
	for(int i=0;i<N;i++){
		cin>>AA.at(i);
	}
	for(int i=0;i<N;i++){
		if(AA.at(i)=="AC")ans.at(0)++;
		if(AA.at(i)=="WA")ans.at(1)++;
		if(AA.at(i)=="TLE")ans.at(2)++;
		if(AA.at(i)=="RE")ans.at(3)++;
	}

	cout<<"AC x "<<ans.at(0)<<endl;
	cout<<"WA x "<<ans.at(1)<<endl;
	cout<<"TLE x "<<ans.at(2)<<endl;
	cout<<"RE x "<<ans.at(3)<<endl;
}

Measured memory_bytes: 6424
#include <iostream>
#include <climits>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a;
  int max = INT_MIN;
  int total = 0;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    total+=a;
    if(a>max)
      max=a;
  }	
  if(total-max>max)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";


int main(){
    int N,D; cin >> N >> D;
    int num = 1 + 2*D;
    if(N % num != 0) cout << N/num + 1 << "\n";
    else cout << N/num << "\n";

}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end

vector<int> g[101000];
int dist[101000],res[101000]={};
void dfs(int v,int d,int c){
   if(d<0)return;
   if(d<=dist[v])return;
   dist[v]=d; if(!res[v])res[v]=c; d--;
   for(int to:g[v])dfs(to,d,c);
}
int que[101000][3];

int main(){
   int n,m,q; scanf("%d%d",&n,&m);
   memset(dist,-1,sizeof(dist));
   rep(i,0,m){
      int u,v; scanf("%d%d",&u,&v); u--; v--;
      g[u].push_back(v); g[v].push_back(u);
   }
   scanf("%d",&q);
   rep(i,0,q)rep(j,0,3)scanf("%d",&que[i][j]);
   rrep(i,q-1,-1){que[i][0]--; dfs(que[i][0],que[i][1],que[i][2]);}
   rep(i,0,n)printf("%d\n",res[i]);
   return 0;
}

Measured memory_bytes: 8440
n,k = map(int, input().split())
okasi = [0] * n
for i in range(k):
    d = int(input())
    As = list(map(int, input().split()))
    for a in As:
        okasi[a-1] += 1
# print(okasi)
print(sum([1 for o in okasi if o == 0]))

Measured memory_bytes: 9180
def factorial(n):
    if n == 0 or n == 1 or n < 0:
        return 1
    return n * factorial(n-1)

N,M = map(int,input().split())

even = int(factorial(N) / (2 * (factorial(N-2))))
odd = int(factorial(M) / (2 * (factorial(M-2))))
print(even+odd)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
multiset<int> s;
multiset<int>::iterator it;
int main(){
  int Lj4PdHRW, i, j, k=1<<30, res=0;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(i);
    s.insert(i);
  }
  while(s.size()){
    it = s.end();
    it--;
    i = *it;
    s.erase(it);
    while(k/2 > i){
      k /= 2;
    }
    j = k - i;
    it = s.lower_bound(j);
    if(j == *it){
      res++;
      s.erase(it);
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180730-1

// --- original code ---
// int N;
// multiset<int> s;
// multiset<int>::iterator it;
// {
//   int i, j, k = 1<<30, res = 0;
// 
//   rd(N);
//   rep(N){
//     rd(i);
//     s.insert(i);
//   }
// 
//   while(s.size()){
//     it = s.end();
//     it--;
//     i = *it;
//     s.erase(it);
//     
//     while(k/2 > i) k /= 2;
//     j = k - i;
//     it = s.lower_bound(j);
//     if(j == *it){
//       res++;
//       s.erase(it);
//     }
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define PAIR pair<int,int>
#define N 200005
#define oo (1<<30)
#define LL long long
using namespace std;
int n,mx,mn,Min,Max; PAIR a[N]; LL ans;
int main()
{
	int i;
	scanf("%d",&n),mx=-oo,mn=oo;
	for(i=1;i<=n;i++){
		scanf("%d %d",&a[i].first,&a[i].second);
		if(a[i].first>a[i].second) swap(a[i].first,a[i].second);
		mx=max(mx,a[i].second);
		mn=min(mn,a[i].second);
	  }
	sort(a+1,a+n+1);
	ans=1LL*(a[n].first-a[1].first)*(mx-mn);
	Min=Max=a[1].second;
	for(i=2;i<=n;i++){
		ans=min(ans,1LL*(mx-a[1].first)*(max(Max,a[n].first)-min(Min,a[i].first)));
		Min=min(Min,a[i].second);
		Max=max(Max,a[i].second);
	  }
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  set<string> a;
  cin >> n;
  rep(i,n) {
    string s;
    cin >> s;
    a.insert(s);
  }
  cout << a.size() << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 19296
import sys
input = sys.stdin.readline
N, K = (int(i) for i in input().split())
A = [int(x) for x in input().split()]
#A = [[int(i) for i in input().split()] for i in range(N)]

orders = []
visited = {}
cur = 1
count = 0
diff = 0
start = 0
while True:
    cur = A[cur-1]
    orders.append(cur)
    if cur not in visited:
        visited[cur] = count
    else:
        start = visited[cur]
        diff = count - start
        break

    count += 1

if K-1 < start:
    #print("he", start)
    print(orders[K-1])
else:
    #print(start, diff)
    #print(orders)
    print(orders[start+(K-1-start)%diff])


Measured memory_bytes: 124808
#include<bits/stdc++.h>
using namespace std;
vector<int>g[30];
int main(){
  string s, t;
  long long int ans=0, c=-1;
  cin>>s>>t;
  for(int i=0;i<s.length();i++){
    g[s[i]-'a'].push_back(i+1);
  }
  vector<int>::iterator it;
  bool flag =false;
  for(int i=0;i<30;i++)g[i].push_back(1000000);
  if(g[t[0]-'a'][0]!=1000000){
    ans+=g[t[0]-'a'][0];
    c=ans;
    flag=true;
  }
  for(int i=1;i<t.length();i++){
    int f=t[i]-'a';
    if(g[f][0]==1000000){
      cout<<-1<<endl;
      exit(0);
    }
    it=upper_bound(g[f].begin(), g[f].end(), c);
    if(*it==1000000){
      ans+=g[f][0];
      ans+=(s.length()-c);
      c=g[f][0];
    }
    else {
      ans+=(*it-c);
      c=*it;
    }
  }
  if(flag)cout<<ans<<endl;
  else {
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

int n;

main()
{
    int a,b,c;
    cin>>a>>b>>c;

    if(a==b&&b==c)
    {
        cout<<"No"<<endl;
        return 0;
    }
    if(a!=b&&b!=c&&c!=a)
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import sys
from itertools import permutations, combinations

n, c = map(int, sys.stdin.readline().split())
d = [[int(x) for x in sys.stdin.readline().split()] for _ in range(c)]
grid = [[int(x) - 1 for x in sys.stdin.readline().split()] for _ in range(n)]

cost = [[0] * c for _ in range(3)]
for i in range(n):
  for j in range(n):
    k = (i + j) % 3
    for l in range(c):
      cost[k][l] += d[grid[i][j]][l]
  
def main():
  res = []
  for comb in combinations(range(c), 3):
    for i, j, k in permutations(comb):
      res.append(cost[0][i] + cost[1][j] + cost[2][k])
  print(min(res))

if __name__ == '__main__':
  main()

Measured memory_bytes: 44892
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > matrix;

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

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && c!=a) || (a==c && b!=a) || (b==c && a!=b)){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
	exit(0);
}


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

constexpr ll INF = ll(1e+18) + 1;

ll add(ll ctr_lt, ll ctr_gt) {
    ll small, large;
    small = min(ctr_lt, ctr_gt);
    large = max(ctr_lt, ctr_gt);

    return large*(large+1)/2 + (small-1)*small/2;
}

int main(){
    string s;
    int n;
    ll ctr_lt = 0, ctr_gt = 0;// lt:<, gt:>
    ll sum = 0;

    cin >> s;
    n = s.size();

    rep(i, n) {
        (s[i]=='<') ? ctr_lt++ : ctr_gt++;

        if (s[i]=='>' && s[i+1]=='<') {
            sum += add(ctr_lt, ctr_gt);
            ctr_lt = 0;
            ctr_gt = 0;
        }
    }
    sum += add(ctr_lt, ctr_gt);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
#include <iomanip>
using namespace std;
int main()
{
	int M,D;
	cin>>M>>D;
	int count = 0;
	for(int j=1; j<=M; j++)
	{
		for(int i=22; i<=D; i++)
		{
			int d1 = i % 10;
			int d2 = i / 10;

			if(d1<2 || d2 < 2)
			{
				continue;
			}
			if(d1 * d2 == j)
			{
				count++;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
typedef pair <int, int> pii;
const int maxn = 2010, P = 1e9 + 7;
int S;

int dp[750][maxn];

void solve() {
  cin >> S;
  if (S < 3) return puts("0"), void();
  dp[0][0] = 1;
  int ans = 0;
  rep(i, 1, 750) {
    static int data[maxn];
    rep(j, 0, S) data[j] = (dp[i - 1][j] + (j ? data[j - 1] : 0)) % P;
    rep(j, 3, S) {
      dp[i][j] = data[j - 3];
    }
    ans = (ans + dp[i][S]) % P;
  }
  cout << ans << endl;
}

signed main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 9448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int D;
vector<int> c(26);
vector<vector<int>> s;

int scoring(const vector<int>& t) {
    int v = 0;
    vector<int> last(26, -1);
    rep(i, D) {
        v += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) {
            v -= c[j] * (i - last[j]);
        }
    }
    return v;
}

// int diff_scoring(const vector<int>&t, int v, int to_d, int to_t) {
//     int last = -1;
//     rep(i, D) {
//         if (t[i] == to_t) v -= s[i][t[i]], last = i;
//         v += c[to_t] * (i - last)
//     }
//     last = -1;
//     rep(i, D) {
//         if (i == to_d || t[i] == to_d) {
//             v += s[i][t[i]], last = i;
//         }
//         v -= c[to_t] * (i - last);
//     }
//     return v;
// }

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

    auto start = chrono::system_clock::now();
    
    cin >> D;
    rep(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> t(D);

    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand_d(0, D-1);
    uniform_int_distribution<> rand_t(0, 25);
    
    rep(i, D) t[i] = rand_t(mt);

    int v = scoring(t);
    
    while (true) {
        int to_d = rand_d(mt);
        int to_t = rand_t(mt);
        if (t[to_d] == to_t) continue;
        int old = t[to_d];
        t[to_d] = to_t;
        if (!chmin(v, scoring(t))) {
            t[to_d] = old;
        }
        auto end = chrono::system_clock::now();
        auto dur = end - start;
        auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
        if (msec >= 1950) break;
    }
    
    rep(i, D) cout << t[i] + 1 << '\n';
}


Measured memory_bytes: 3712
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
tmp = []
for i in range(1, 10):
    for j in range(1, 10):
        tmp.append(i*j)

if N in tmp:
    print('Yes')
else:
    print('No')


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

#define ll long long
// #define endl '\n'

// void max_self(int &a, int b){a = max(a, b);}
// void min_self(int &a, int b){a = min(a, b);}

void solve(){
	ll a, b; cin>>a>>b;
	cout<<(a * b) / (__gcd(a, b))<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1; //cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,l,r) for (ll i=l;i<=r;i++)
using namespace std;
typedef long long ll;
ll a,b,c,ans,N,K,M,tt,t,va[7],vb[7],dp[10007];
int main(){
	scanf("%lld",&N);
	rep(i,1,3) scanf("%lld",&va[i]);
	rep(i,1,3) scanf("%lld",&vb[i]);
	rep(i,1,N) dp[i]=-1e9;
	rep(k,1,3) if (va[k]<vb[k])
		for (ll i=N;i>=1;i--) rep(j,1,i/va[k])
			dp[i]=max(dp[i],dp[i-j*va[k]]+j*vb[k]);
	rep(i,0,N) ans=max(ans,N-i+dp[i]);
	ll nn=0;
	rep(k,1,3) if (va[k]>vb[k]){
		nn++;
		if (b==0) b=k;else c=k;
	}
	if (nn==1) ans=ans%vb[b]+ans/vb[b]*va[b];
	if (nn==2){
		ll ma=ans,s=0,kk=ans/vb[b];
		ans=max(ans,s+ma%vb[c]+ma/vb[c]*va[c]);
		rep(i,1,kk){
			ma=ma-vb[b]; s=s+va[b]; 
			ans=max(ans,s+ma%vb[c]+ma/vb[c]*va[c]);
		}
	}
	if (nn==3){
		rep(k,1,3) for (ll i=N;i>=1;i--) rep(j,1,i/vb[k])
			dp[i]=max(dp[i],dp[i-j*vb[k]]+j*va[k]);
		rep(i,0,N) ans=max(ans,N-i+dp[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

int n, ga, gb, sa, sb, ba, bb;
LL m, res[25000005];

LL getMax(int n, int ga, int gb, int sa, int sb, int ba, int bb) {
	res[0] = 0;
	for (int i = 1;i<=n;i++) {
		res[i] = i;
		if (gb > ga && ga <= i) res[i] = max(res[i], res[i - ga] + gb);
		if (sb > sa && sa <= i) res[i] = max(res[i], res[i - sa] + sb);
		if (bb > ba && ba <= i) res[i] = max(res[i], res[i - ba] + bb);
		//printf("%d %d\n", i, res[i]);
	}
	return res[n];
}

int main() {
scanf("%d %d %d %d %d %d %d", &n, &ga, &sa, &ba, &gb, &sb, &bb);
m = getMax(n, ga, gb, sa, sb, ba, bb);
m = getMax(m, gb, ga, sb, sa, bb, ba);
printf("%lld\n", m);
return 0;
}

Measured memory_bytes: 195584
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	string str;
	
	while(cin>>str)
	{
		int ans=0,cnt=0;
		
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='R')
			{
				cnt++;
				
				if(cnt>ans)
					ans=cnt;
			}
			else
			{
				cnt=0;
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}

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

int main(){
  int N;cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i,N){
    cin>>A[i];
    B[i]=A[i];
  }
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  int max=B[0];
  int max_a=B[1];
  
  rep(i,N){
    if(A[i]==max) cout<<max_a<<endl;
    else cout<<max<<endl;
  }
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    ll X,t;cin>>X>>t;
    cout<<max(0LL,X-t)<<endl;
}

Measured memory_bytes: 3604
n,m=map(int,input().split())
s_a=set()
s_b=set()
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    s_b.add(b)
  if b==n:
    s_a.add(a)
print("IMPOSSIBLE" if len(s_a&s_b)==0 else "POSSIBLE")

Measured memory_bytes: 19024
def euclideanAlgo(a,b):
    cond = True
    while cond:
        mod = a%b
        if mod == 0:
            cond = False
            return(b)
        a = b
        b = mod

a,b,c,d = map(int, input().split())
e = (c*d)//euclideanAlgo(c,d)
ALL = b-a+1
c_kosuu = b//c-(a-1)//c
d_kosuu = b//d-(a-1)//d
e_kosuu = b//e-(a-1)//e
print(ALL -c_kosuu - d_kosuu +e_kosuu)

Measured memory_bytes: 3064
import java.util.*;
import java.math.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static BigInteger a, b;
	public static void main(String[] args) {
		while(read()){
			
		}
	}
	static boolean read(){
		if(!sc.hasNext())return false;
		n = sc.nextInt();
		for(int i = 0; i < n; i++){
			a = sc.nextBigInteger(); b = sc.nextBigInteger();
			solve();
		}
		return true;
	}
	static void solve(){
		if(a.add(b).toString().length() > 80){
			System.out.println("overflow");
		}else{
			System.out.println(a.add(b));
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int h,w,n;cin >>w>>h>>n;
	int a=0,b=0,c=h,d=w;
	
	REP(i,n)
	{
		int x,y,z;cin >> x >> y >> z;
		switch(z)
		{
			case 1:a = max(a,x);break;
			case 2:d = min(d,x);break;
			case 3:b = max(b,y);break;
			case 4:c = min(c,y);break;
		}
	}
	
	if(d-a < 0 || c-b < 0)cout << 0 << endl;
	else cout << (d-a)*(c-b) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=22;
int n, g[N],dp[N][1<<N],idx[1<<N];
const int MOD=1e9+7;

int main(){FIN;
	cin >> n;
	fore(x,0,n){
		idx[1<<x]=x;
		fore(y,0,n){int v;cin>>v;g[x]=2*g[x]+v;}
	}
	dp[n][0]=1;
	for(int i=n-1; i>=0; i--){
		fore(m,0,1<<n){
			int mm=m&g[i];
			while(mm){
				int j=idx[mm&-mm];
				mm^=mm&-mm;
				dp[i][m]+=dp[i+1][m^(1<<j)];
				if(dp[i][m]>=MOD)dp[i][m]-=MOD;
			}
		}
	}
	cout<<dp[0][(1<<n)-1]<<"\n";
}

Measured memory_bytes: 221440
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

string s;

bool input() {
    s = readln.chomp;
    if (s == "0") return false;
    return true;
}

void solve() {
    //writeln("x: ", iota(0, 11, 1).array);
    auto C = new int[][](2, 11);
    auto N = s.length;
    int ans = 0;
    foreach (i; 0 .. N) {
        auto x = cast(int)(s[i] - '0');
        C[i & 1][] = 0;
        C[i & 1][x] = 1;
        if (x == 0) ans--;
        if (i >= 1) {
            auto p = cast(int)(s[i - 1] - '0');
            if (p == 0) C[(i + 1) & 1][0]--;
        }
        foreach (j; 0 .. 11) {
            C[i & 1][(j * 10 + x) % 11] += C[(i + 1) & 1][j];
        }
        ans += C[i & 1][0];
        //writeln(i, ": ", C[i & 1]);
    }
    writeln(ans);
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define FIR first
#define SEC second
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<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main() {
  IN(ll,A);
  IN(ll,B);
  if(B >= A){
    REP(i,B)
      cout << A;
  }else{
    REP(i,A)
      cout << B;
    OUT("");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<int, int, int> T;
// get<K>(tuple型の変数)

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

ll gcd(ll a, ll b){
    if(a<b) swap(a, b);

    while(b!=0){
        ll t = a;
        a = b;
        b = t%b;
    }
    return a;
}


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

    ll a, b; cin >> a >> b;
    ll g = gcd(a, b);
    
    ll ans=1;
    for(ll i=2; i*i<=g; ++i){
        if(g%i == 0){
            ++ans;
            while(g%i == 0) g /= i;
        }
    }
    if(g!=1) ++ans;
    cout << ans << endl;

    return 0;
} 

Measured memory_bytes: 256
a = []
b = []
h, n = map(int, input().split())
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

dp = [float("inf")]*(h+1)
dp[0] = 0

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

print(dp[h])

Measured memory_bytes: 48604
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut chars : Vec<char> = buf.chars().collect();
    chars.sort_by(|a, b| b.cmp(a));

    if chars[0] == chars[1] && chars[2] == chars[3] && chars[0] != chars[2] {
        println!("Yes")
    } else {
        println!("No")
    }
}


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for(int i = 0; i <= b;) {
        if(i >= a) {
            cout << "OK" << endl;
            return 0;
        }
        i += k;
    }
    cout << "NG" << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,q,c,up,low,t,x,y,arr[4],a,b;
string str,str1;
bool f;

int main()
{
    cin >> a >> b;
    arr[a]=1;
    arr[b]=1;
    for (ll i=1;i<=3;i++)
    {
        if (arr[i]==0)
            cout << i;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

typedef long long ll;
int N,M,P;
ll D[2510];
bool negative[2510];
ll inf = 1e18;
struct edge {int from,to; ll cost;};

vector<edge> v;

void shortest_path(int s){
	for(int i=1;i<=N;i++) D[i] = inf;
	D[s] = 0;
	for(int j=0;j<N-1;j++){
		for(int i=0;i<v.size();i++){
			edge e = v[i];
			if(D[e.from] != inf && D[e.to] > D[e.from] + e.cost){
				D[e.to] = D[e.from] + e.cost;
			}
		}
	}
}

void find_negative_loop(){
	for(int i=1;i<=N;i++) negative[i] = false;
	for(int i=1;i<=N;i++){
		for(int j=0;j<v.size();j++){
			edge e = v[j];
			if(D[e.from]!=inf && D[e.to] > D[e.from] + e.cost){
				D[e.to] = D[e.from] + e.cost;
				negative[e.to] = true;
			}
			if(negative[e.from]) negative[e.to] = true;
		}
	}
}

int main(){
	cin >> N >> M >> P;
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		v.push_back((edge{a,b,P-c}));
	}
	shortest_path(1);
	ll ans = max(-D[N],0LL);
	find_negative_loop();
    cout << (negative[N]? -1:ans) << endl;
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

    // input
    ll N;
    cin >> N;

    string s;
    cin >> s;

    ll K;
    cin >> K;

    char a = s[K-1];

    for(char c : s){
        if(a==c){
            cout << c;
        }else{
            cout << '*';
        }
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
int n, x, y, ans[2005];
int abs(int a){ return a > 0 ? a : -a; }
int main() {
	scanf("%d%d%d", &n, &x, &y);
	for (register int i = 1; i <= n; ++i)
		for (register int j = i + 1; j <= n; ++j){
			int d = std::min(j - i, abs(i - x) + abs(j - y) + 1);
			++ans[d];
		}
	for (register int i = 1; i < n; ++i) printf("%d\n", ans[i]);
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll n, x;
    cin >> n >> x;
    ll a[n];
    rep(i, n)cin >> a[i];

    ll ans = 0;
    if(a[0] > x)ans += a[0] - x, a[0] = x;
    for(ll i = 1; i < n;  ++i){
        if(a[i-1]+a[i] > x)ans += a[i-1]+a[i]-x, a[i] -= a[i-1]+a[i]-x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024