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

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

    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000

int main(){

  int a,i,v,j,k;
  int A[N];

  scanf("%d",&a);

  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }

  for( k = 0 ; k < a-1 ; k++ ) printf("%d ",A[k]);
  printf("%d\n",A[a-1]);

  for( i = 1 ; i < a ; i++ ){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for( k = 0 ; k < a-1 ; k++ ){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[a-1]);
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    printf("%.10f\n", ((n + 1) / 2) / (double)n);
    return 0;
}


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

int binarySearch(int S[], int n, int key){
    int left = 0;
    int right = n;
    while ( left < right ){
        int mid;
        mid = (left + right) / 2;
        if ( S[mid] == key ) return mid;
        else if ( key < S[mid] ) right = mid;
        else left = mid + 1;
    }
    return -1;
}

int main(){
    int n, q;
    int S[100000], key;
    int sum = 0;
    cin >> n;
    for ( int i = 0; i < n; i++ ) cin >> S[i];
    cin >> q;
    for ( int i = 0; i < q; i++ ){
        cin >> key;
        if ( binarySearch(S, n, key) == -1 ) continue;
        else sum++;
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


vector<bool> used;
void dfs(vector<vector<int>> &G, int s){
    used[s] = true;
    for (auto v : G[s]){
        if(used[v] == true) continue;
        dfs(G, v);
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N+M);
    int K;
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> K;
        for (int j = 0; j < K; j++) {
            cin >> tmp;
            G[i].push_back(N+tmp-1);
            G[N+tmp-1].push_back(i);
        }
    }

    used.resize(N+M);
    fill(ALL(used), false);


    // for (int i = 0; i < N+M; i++) {
    //     for (int v : G[i]){
    //         printf("%d ", v);
    //     }
    //     printf("\n");
    // }
    dfs(G, 0);


    // for (int i = 0; i < N; i++) {
    //     if(used[i]){
    //         printf("1\n");
    //     }
    //     else{
    //         printf("0\n");
    //     }
        
    // }
    for (int i = 0; i < N; i++) {
        if(used[i]){
            continue;
        }
        else{
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");


}

Measured memory_bytes: 11396
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

ll d[100100];

int main(){
  clr(d,0);
  ll n,x,m;
  cin>>n>>x>>m;
  d[x] = 1;
  ll a = x;
  ll index = 2;
  ll s,e;
  while(1){
    a *= a;
    a %= m;
    if(d[a]!=0){
      s = d[a];
      e = index;
      break;
    }
    else{
      d[a] = index;
    }
    index++;
  }
  //cout << s << " " << e << endl;
  if(n<s){
    ll ans = 0;
    a = x;
    rep(i,0,n){
      ans += a;
      a *= a;
      a %= m;
    }
    cout << ans << endl;
    return 0;
  }
  ll l = e-s;
  a = x;
  ll ans = 0;
  rep(i,0,s){
    ans += a;
    a *= a;
    a %= m;
  }
  n -= s;
  if(l==0){
    cout << (ans+a*n)%m << endl;
    return 0;
  }
  ll b = a;
  ll ans2 = 0;
  rep(i,s,e){
    ans2 += b;
    b *= b;
    b %= m;
  }
  ll w = n/l;
  ans2 *= w;
  ll z = n%l;
  //cout << ans << endl;
  //cout << "a" <<  w << " " << z << endl;
  ll c = a;
  ll ans3 = 0;
  rep(i,0,z){
    //cout << c << endl;
    ans3 += c;
    c *= c;
    c %= m;
  }
  cout << ans+ans2+ans3 << endl;
  return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
// cout << "\t" << endl;

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

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	int n,z;
	int max = 0;
	int min = 0;
	scanf("%d",&n);
	int a[n];
	for(z = 0;z < n;z++){
		scanf("%d",&a[n]);
	if(max < a[n])
		max = a[n];
	if(min == 0)
		min = a[n];
	if(a[n] < min)
		min = a[n];
	}
	printf("%d",max - min);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  vector<int> Q(N);
  for (int i = 0; i < N; i++) cin >> Q.at(i);
  if (P > Q) swap(P, Q);
  int ans = 0;
  do {
    if (P == Q) break;
    ans++;
  } while (next_permutation(P.begin(), P.end()));
  cout << ans << "\n";
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  int K = nextLong();
  vector<ll> a(N);
  REP(i, N) a[i] = nextLong();

  double lo = 0;
  double hi = 1e9;
  REP(_, 100) {
    double mid = (hi + lo) / 2;
    ll cut = 0;
    REP(i, N) cut += ceil(a[i] / mid) - 1;
    if (cut <= K) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << (ll)ceil(hi) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main() {
    string s1, s2, ans = "No";
    cin >> s1 >> s2;
    s1 += s2;
    int n = stoi(s1);
    for(int i = 1; i*i <= n; ++i) {
        if(n%i == 0 && i == n/i) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n,l = inp
a = []
n.times{a<<gets.chomp}
puts a.sort.join 

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline


n, m = map(int, input().split())

AB = []
for _ in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort()

answer, count = 0, 0
for a, b in AB:
    answer += a * b
    count += b
    if count >= m:
        answer -= a * (count - m)
        break

print(answer)


Measured memory_bytes: 48476
//#pragma GCC optimize("Ofast")
//#pragma GCC optimization ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define push_back emplace_back
#define push emplace
#define insert emplace
//#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	string s[n];
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int prej[n][m],sucj[n][m],prei[n][m],suci[n][m];
	for(int i=0;i<n;i++){
		int x=-1;
		for(int j=0;j<m;j++){
			if(s[i][j]=='#')x=j;
			prej[i][j]=x;
		}
		x=m;
		for(int j=m-1;j>=0;j--){
			if(s[i][j]=='#')x=j;
			sucj[i][j]=x;
		}
	}
	for(int j=0;j<m;j++){
		int x=-1;
		for(int i=0;i<n;i++){
			if(s[i][j]=='#')x=i;
			prei[i][j]=x;
		}
		x=n;
		for(int i=n-1;i>=0;i--){
			if(s[i][j]=='#')x=i;
			suci[i][j]=x;
		}	
	}
	int x=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(s[i][j]=='#')continue;
			x=max(x,suci[i][j]+sucj[i][j]-prei[i][j]-prej[i][j]-2);
		}
	}
	x--;
	cout<<x;
	return 0;

}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    --p[i];
    q[p[i]] = i;
  }

  vector<int> d(n);

  for (int i = n - 1; i >= 0; --i) {
    if (i == n - 1 || q[i + 1] < q[i]) {
      d[i] = 1;
    } else {
      d[i] = 1 + d[i + 1];
    }
  }

  cout << n - *max_element(all(d)) << endl;

}



Measured memory_bytes: 2560
import sys

#+++++
		
def main():
	h,w,a,b = map(int, input().split())
	
	pp='1'*(w-a)+'0'*a
	bb='0'*(w-a)+'1'*a
	
	for _ in range(h-b):
		print(pp)
	for _ in range(b):
		print(bb)
	return 
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3956
ABC=list(map(int,input().split()))
ABC.sort()
ans=0
ans+=(ABC[2]-ABC[0])//2
if (ABC[2]-ABC[0])%2==1:
  ans+=(ABC[2]-ABC[1])//2
  if (ABC[2]-ABC[1])%2 == 1:
    ans+=1
  else:
    ans+=2  
else:
  ans+=(ABC[2]-ABC[1])//2
  if (ABC[2]-ABC[1])%2 == 1:
    ans+=2

print(ans)


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

 using namespace std;

 const string target = "CODEFESTIVAL2016";

 int main() {
     string s;
     cin >> s;
     int ans = 0;
     for (int i = 0; i < s.size(); i++)
         ans += s[i] != target[i];
     cout << ans << endl;
     return 0;
 }


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

int main() {
  size_t N, A, B, C, D;
  scanf("%zu %zu %zu %zu %zu", &N, &A, &B, &C, &D);
  --A;
  --B;
  --C;
  --D;

  char buf[262144];
  scanf("%s", buf);
  std::string S = buf;

  if (C < D) {
    while (B < D) {
      if (S[B+1] == '.') {
        ++B;
      } else if (S[B+2] == '.') {
        B += 2;
      } else {
        return puts("No"), 0;
      }
    }
    while (A < C) {
      if (S[A+1] == '.') {
        ++A;
      } else if (S[A+2] == '.') {
        A += 2;
      } else {
        return puts("No"), 0;
      }
    }
    return puts("Yes"), 0;
  }

  if (D < C) {
    size_t a = A;
    size_t b = B;
    while (b < D) {
      if (S[b+1] == '.') {
        ++b;
      } else if (S[b+2] == '.') {
        b += 2;
      } else {
        return puts("No"), 0;
      }
    }
    while (a < C) {
      if (S[a+1] == '.') {
        ++a;
      } else if (S[a+2] == '.') {
        a += 2;
      } else {
        return puts("No"), 0;
      }
    }

    bool ok = false;
    for (size_t i = B; i <= D; ++i) {
      if (S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') {
        ok = true;
        break;
      }
    }

    return puts(ok? "Yes":"No"), 0;
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
int main(){
    int q;
    std::cin >> q;
    if(q==1){
        std::cout << "Hello World" << std::endl;
    }
    else{
        int a,b;
        std::cin >> a>>b;
        std::cout << a+b << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] c = new boolean[3];
		c[0] = true;
		while(sc.hasNext()){
			char[] a = sc.next().toCharArray();
			int s = a[0]-'A';
			int t = a[2]-'A';
			boolean b = c[s];
			c[s] = c[t];
			c[t] = b;
		}
		for(int i=0;i<3;i++)if(c[i]){System.out.println((char)(i+'A'));break;}
	}
}

Measured memory_bytes: 17116
#include<cstdio>
main(){
 int a,b;
 while(1){
  scanf("%d%d",&a,&b);
  if(!a&&!b)break;
  else if(a>b){
   int buf;
   buf = a;
   a = b;
   b = buf;
  }
  printf("%d %d\n",a,b);
 }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	int n;
	cin >> n;
	int ans = n / 2;
	if (n % 2)
		ans++;
	cout << ans << endl;
	return (0);
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N,K; cin >> N >> K;
    ll _gcd = -1;
    ll mx = 0;
    REP(_,N) {
        ll A;
        cin >> A;
        chmax(mx,A);
        if(_gcd < 0) _gcd = A;
        else _gcd = gcd(_gcd,A);
    }
    while ( mx > 0 ) {
        if(mx == K) {
            cout << "POSSIBLE" << endl;
            return;
        }
        mx -= _gcd;
    }
    cout << "IMPOSSIBLE" << endl;
}

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

Measured memory_bytes: 3620
MOD = 10**9 + 7
def comb(n, k, MOD):
    if n < k or n < 0 or k < 0:
        return 0
    # k = min(k, n - k)
    if k == 0:
        return 1
    iinv = [1] * (k + 1)
    ans = n
    for i in range(2, k + 1):
        iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
        ans *= (n + 1 - i) * iinv[i] % MOD
        ans %= MOD
    return ans
X, Y = map(int,input().split())
if (X+Y) % 3 != 0:
    print(0)
    exit()
n = (2*Y-X)//3
m = (2*X-Y)//3
print(comb(n+m,m,MOD))

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

int f[10000],a[26][10000],y[10000],an[26],bn[26],n,z;

void ans(int d) {
	 int i;
	 z++;
	 for (i=0;i<an[y[d]];i++) {	if (f[a[y[d]][i]]==0) { f[a[y[d]][i]]=1; ans(a[y[d]][i]); }}
}

int main() {
	int i,j,sl;
	char c[33];
	while(cin >> n && n>0) {
		for (i=0;i<10000;i++) { f[i]=0; for (j=0;j<26;j++) { an[j]=bn[j]=0; a[j][i]=0;}}
		for (i=0;i<n;i++) {
			cin >> c;
			sl=strlen(c);
			a[c[0]-'a'][an[c[0]-'a']]=i; an[c[0]-'a']++; bn[c[sl-1]-'a']++;
			y[i]=c[sl-1]-'a';
		}
	for (i=0;i<26;i++) if (an[i]!=bn[i]) break;
	if (i<26) {cout << "NG" << endl; continue;}
	z=0; ans(0);
	if (z==n+1) cout << "OK" << endl; else cout << "NG" << endl;
    }
	return 0;
}

Measured memory_bytes: 2248
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
    int n; cin>>n;
    vector<string> w;
    bool flag=true;
    FOR(i,0,n){
        string s; cin>>s;
        w.PB(s);
        if(i)if(w[i][0]!=w[i-1][w[i-1].size()-1]) flag=false;
    }
    FOR(i,0,n){
        FOR(j,0,i){
            if(w[i]==w[j]) flag=false;
        }
    }
    Yes(flag);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

struct edge{int to, cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
    }

    void add_edge(int from, int to, int cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, int cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

};

signed main(){

    int N, A, B;
    cin >> N;
    Graph Tree(N);
    REP(i, N - 1){
        cin >> A >> B;
        Tree.add_edge2(A - 1, B - 1, 0);
    }
    
    vec ans(N, -1 * INF);
    map<int, set<int>> m;
    int n = -1 * INF;
    
    int K, V, P;
    cin >> K;
    REP(i, K){
        cin >> V >> P;
        ans[V - 1] = P;
        m[P].insert(V - 1);
        n = max(n, P);
    }

    bool f = true;
    while(m[n].size() > 0){
        for(int v: m[n]){
            REP(k, Tree.G[v].size()){
                int w = Tree.G[v][k].to;
                if(ans[w] > n) continue;
                if(ans[w] == -1 * INF){
                    ans[w] = n - 1;
                    m[n - 1].insert(w);
                }else if(ans[w] != n - 1){
                    f = false;
                    break;
                }
            }
        }
        if(!f) break;
        n--;
    }
    if(f){
        cout << "Yes" << endl;
        REP(i, N) cout << ans[i] << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 21760
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    # 開催日数
    D = int(input())
    # 満足度の下がりやすさ
    C = list(map(int, input().split()))
    # 得られる満足度
    S = [ list(map(int, input().split())) for _ in range(D) ]
    # 開催予定
    T = [ int(input())-1 for _ in range(D) ]
    # 最後に開かれた日付
    last = [0]*26

    def cp(d, t):
        c = 0
        for i in range(26):
            c += C[i] * (d - last[i])
        return c

    score = 0
    for i in range(D):
        score += S[i][T[i]]
        last[T[i]] = i+1
        c = cp(i+1, T[i])
        score -= c
        print(score)


main()

Measured memory_bytes: 9256
n = int(input())
H = list(map(int, input().split()))

if n != 1:
  for i in range(0, n):
    if i == 0:
      H[i] -= 1
    elif i == n-1:
      if H[i] >= H[i-1]:
        print('Yes')
      elif H[i] < H[i-1]:
        print('No')
    else:
      if H[i-1] < H[i]:
        H[i] -= 1
      elif H[i-1] == H[i]:
        continue
      elif H[i-1] > H[i]:
        print('No')
        break
elif n == 1:
  print('Yes')

Measured memory_bytes: 14396
#include <bits/stdc++.h>
 
using namespace std;
 
using tint = long long;
using ld = long double;
 
#define forsn(i, s, n) for(int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
 
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
 
#define DBG(x) cerr << #x << " = " << x << endl;
 
const int MOD = 1e9+7;
const int MX = 5e5+5;
const int INF = 1e9;
const ld PI = acos(ld(-1)); 
 
void NACHO(string name = "out"){
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen((name+".in").c_str(), "r", stdin);
    //freopen((name+".out").c_str(), "w", stdout);
}
 
int main(){
	NACHO();
	int n;
	cin >> n;
	if(n % 2 == 0) cout << n << endl;
	else cout <<2*n << endl;
}


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

int main() {
  string s;
  cin >> s;
  int i;
  for (i = 0; i < s.length(); i++) {
    if (s.at(i) > 'C') {
      s.at(i) -= 3;
    } else {
      s.at(i) += 'X' - 'A';
    }
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)


constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;


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

	int h, w, k; cin >> h >> w >> k;
	string s[9];
	rep(i, 0, h) cin >> s[i];

	int ans = 0;
	rep(bit1, 0, 1 << h) {
		rep(bit2, 0, 1 << w) {
			int cnt = 0;
			rep(i, 0, h) {
				if (bit1 >> i & 1) continue;
				rep(j, 0, w) {
					if (bit2 >> j & 1) continue;
					if (s[i][j] == '#') ++cnt;
				}
			}
			ans += cnt == k;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int n,cnt;
int a[100];
string s[100];
int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
  {
   cin>>s[i];
   a[i] = s[i].size();
  }
  for (int i = 0; i < n;i++)
  {
    for(int j=0;j<n;j++)
    {
      if(s[i]==s[j])
        cnt++;
    }
  }
  if(cnt>n)
  {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; i++)
  {
    if (s[i][s[i].size() - 1] != s[i + 1][0])
    {
        cout << "No" << endl;
        return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]){
    int a, b, c;
    double s, l, h, rad;
    scanf("%d %d %d", &a, &b, &c);
    rad = c * M_PI / 180;
    s = a * b * sin(rad) / 2;
    l = a + b + sqrt( a*a + b*b - 2*a*b*cos(rad) );
    h = b * sin(rad);
    printf("%f\n%f\n%f\n", s, l, h);
    return 0;
}

Measured memory_bytes: 636
// https://atcoder.jp/contests/abc083/tasks/arc088_a
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y, ans = 0;
    cin >> x >> y;
    while (x <= y) {
        x = x << 1LL;
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m, c) = listOfInt()
    val bb = listOfInt()

    var count = 0
    repeat(n) {
        val aa = listOfInt()
        aa.foldIndexed(0) { index, acc, i ->
            acc + i * bb[index]
        }.plus(c).let { if (it > 0) count++ }
    }

    println(count)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37732
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

typedef long long ll;
//vector<int>


using namespace std;

int main() {
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
  a.push_back(0);
    int cnt=0;
    for(int i=0;i<n;i++){
        if (a.at(i)==i+1){
            swap(a.at(i),a.at(i+1));
            cnt++;
        }
    }
    cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7
#define INF (int) 2e9

int main(){
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i, n){
        cin >> v[i] >> w[i];
    }

    int dp[105][10005] = {};

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < W+1; j++) {
            if (i==0) {
                if (j >= w[i]){
                    dp[i][j] = v[i];
                }else{
                    dp[i][j] = 0;
                }
            }else{
                if (j >= w[i]){
                    dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
                }else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
    }
    cout << dp[n-1][W] << endl;
    // printf("%d\n", N);
    return 0;
}


Measured memory_bytes: 7224
#include<stdio.h>
int main() {
    int i, a, b, c[10];
    for (i = 0; i < 10; i++)
        c[i] = 0;
    for (i = 0; i < 3; i++) {
        scanf("%d%d", &a, &b);
        c[a]++;
        c[b]++;
    }
    for (i = 1; i <= 4; i++) {
        if (c[i] == 0 || c[i] == 3) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> point;

int main(void) {
    int n;
    cin >> n;
    int a[n+2];
    for(int i=1; i<=n; i++)
        cin >> a[i];
    vector<int> b;
    for(int i=1; i<=n; i++) {
        if(i%2==1)
            b.push_back(a[i]);
        else
            b.insert(b.begin(), a[i]);
    }
    
    if(n%2==0) {
        for(int i=0; i<n; i++)
            printf("%d ", b[i]);
    }else {
        for(int i=n-1; i>=0; i--)
            printf("%d ", b[i]);
    }
}


Measured memory_bytes: 3828
#include<iostream>

int main(){
	while(1){
		int n,A,B,Ap=0,Bp=0;
		std::cin>>n;
		if(n==0)
			break;
		for(int i=0;i<n;++i){
			std::cin>>A>>B;
			if(A>B)
				Ap+=A+B;
			else if(A==B){
				Ap+=A;
				Bp+=B;
			}
			else Bp+=A+B;
		}
		std::cout<<Ap<<' '<<Bp<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

ll a[200000];

int main(void){
    ll n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    int i=0;
    while(1){
        int j,k;
        for(j=i;j<n-1;j++){
            if(a[j]>a[j+1]) break;
        }
        for(k=i;k<n-1;k++){
            if(a[k]<a[k+1]) break; 
        }
        i=max(j+1,k+1);
        ans++;
        if(i==n) break;
    }
    cout<<ans<<endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if(S[2]==S[3] && S[4]==S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
#define P 1000000007
const int N=1000005;
int h,n,ans,f[N],p[N];
vector<int> vec;
il void mo(int &p,ct q){p+=q,p=(p>=P?p-P:p);}
il void DFS(it x,it now){
	if(x>=n){
		x=p[x-n+1]+n-1,now=(0ll+now)*x%P;
		while(x) vec.push_back(x),mo(f[x],now),x>>=1,now=(0ll+now)*x%P;
		return;
	}
	DFS(x<<1,(0ll+now)*(x<<1)%P),DFS(x<<1|1,(0ll+now)*(x<<1|1)%P);
}
il void dfs(it x,it now){
	if(x>=n){
		x=p[x-n+1]+n-1,now=(0ll+now)*x%P;it fa;
		for(fa=x,x>>=1;x;fa=x,x>>=1)
			ans=(ans+(0ll+now)*f[x])%P,ans=(ans-(0ll+now)*f[fa]%P*x)%P,ans=(ans<0?ans+P:ans),now=(0ll+now)*x%P;
		return;
	}
	dfs(x<<1,(0ll+now)*(x<<1)%P),dfs(x<<1|1,(0ll+now)*(x<<1|1)%P);
}
il void solve(ct x){
	DFS(x<<1|1,x<<1|1),dfs(x<<1,(0ll+x)*(x<<1)%P);
	for(const int &j : vec) f[j]=0;vec.clear();
}
int main(){ 
	scanf("%d",&h),n=1<<h-1;it i;
	for(i=1;i<=n;++i) scanf("%d",&p[i]);
	for(i=1;i<n;++i) solve(i);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 12716
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a + b)
    if op == '-':
        print(a - b)
    if op == '*':
        print(a * b)
    if op == '/':
        print(int(a / b))



Measured memory_bytes: 5596
h, n = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(n)]
h_max = 10 ** 4
inf = 10 ** 9
dp = [inf] * (h_max + 1)
dp[0] = 0
for h_target in range(1, h_max + 1):
    for attack, mp in AB:
        h_remain = max(0, h_target - attack)
        dp[h_target] = min(dp[h_target], dp[h_remain] + mp)
print(dp[h])


Measured memory_bytes: 42972
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final long MOD = 998244353;
	static int N, M;

	public static void main(String[] args) {
		N = sc.nextInt();
		M = sc.nextInt();
		int[][] mat = new int[N][M];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				mat[i][j] = sc.nextInt();
			}
		}
		int dim = 0;
		int col = 0;
		boolean[] fix = new boolean[N];
		for (int i = 0; col < M; i++) {
			for (int j = 0; j < N; j++) {
				if (!fix[j] && mat[j][col] == 1) {
					for (int k = 0; k < N; k++) {
						if (k == j || mat[k][col] == 0) continue;
						for (int l = 0; l < M; l++) {
							mat[k][l] ^= mat[j][l];
						}
					}
					++dim;
					fix[j] = true;
					break;
				}
			}
			++col;
		}
//		for (int i = 0; i < N; i++) {
//			for (int j = 0; j < M; j++) {
//				System.err.print(mat[i][j] + " ");
//			}
//			System.err.println();
//		}

		long[] pow2 = new long[301];
		pow2[0] = 1;
		for (int i = 1; i < pow2.length; i++) {
			pow2[i] = pow2[i - 1] * 2 % MOD;
		}
		long[][] comb = new long[301][301];
		for (int i = 0; i < comb.length; i++) {
			comb[i][0] = comb[i][i] = 1;
		}
		for (int i = 0; i < comb.length; i++) {
			for (int j = 1; j < i; j++) {
				comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % MOD;
			}
		}
		long ans = 0;
		for (int i = 1; i <= dim; i++) {
			long here = 0;
			for (int j = 1; j <= i; j += 2) {
				here += comb[i][j];
				here %= MOD;
			}
			here *= comb[dim][i];
			here %= MOD;
			here *= pow2[M - i];
			here %= MOD;
			ans += here;
			ans %= MOD;
		}
		ans *= pow2[N - dim];
		ans %= MOD;
		System.out.println(ans);
	}

}


Measured memory_bytes: 52452
#include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
 
class dice {
  private:
    int f[6];
  public:
    dice(int *a){
      int i;
      rep(i, 6) f[i] = a[i];
    }
    void n(){
      int t;
      t = f[0];
      f[0] = f[1];
      f[1] = f[5];
      f[5] = f[4];
      f[4] = t;
    }
    void s() {
      int t;
      t = f[0];
      f[0] = f[4];
      f[4] = f[5];
      f[5] = f[1];
      f[1] = t;
    }
    void w() {
      int t;
      t = f[0];
      f[0] = f[2];
      f[2] = f[5];
      f[5] = f[3];
      f[3] = t;
    }
    void e() {
      int t;
      t = f[0];
      f[0] = f[3];
      f[3] = f[5];
      f[5] = f[2];
      f[2] = t;
    }
    int print(int num) {
      return f[num];
    }
};
 
int main(void) {
  int a[6], i, q, j;
  char s[150];
  rep(i, 6) scanf("%d", &a[i]);
  dice d(a);
  scanf("%d", &q);
  for(i = 0; i < q; ++i) {
    int t, s;
    scanf("%d%d", &t, &s);
    if(d.print(1) == t) d.n();
    else if(d.print(2) == t) d.w();
    else if(d.print(3) == t) d.e();
    else if(d.print(4) == t) d.s();
    else if(d.print(5) == t) d.n(), d.n();
    if(d.print(1) == s) printf("%d\n", d.print(2));
    else if(d.print(2) == s) printf("%d\n", d.print(4));
    else if(d.print(3) == s) printf("%d\n", d.print(1));
    else if(d.print(4) == s) printf("%d\n", d.print(3));
  }
  return 0;
}


Measured memory_bytes: 2724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <sstream>
#include <math.h>
#include <functional>

#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  For(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

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

int main() {
	int n;
	cin >> n;
	double result = 0;
	rep(i, n) {
		double t;
		cin >> t;
		result += 1 / t;
	}
	cout << 1/result << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll H, W, ans;
  cin >> H >> W;
  
  if(H == 1 || W == 1){
    ans = 1;
  }
  else{
    ans = (H * W + 1) / 2; 
  }
  cout <<  ans << endl;
} 

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

// Union find : O(α(V))
// verified : 
class UnionFind {
	typedef ll U;
	// v[i] : i番目の頂点が根 ? i番目の頂点の属する木のサイズ * -1
	//                       : i番目の頂点の親のindex
	vector<ll> v;
public:
	UnionFind(U n) : v(n, -1) {}
	U find(U x) { return v[x] < 0 ? x : (v[x] = find(v[x])); }
	bool same(U x, U y) { return find(x) == find(y); }
	U size(U x) { return (U)-v[find(x)]; }
	void unite(U x, U y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}
};

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, c, k; cin >> n >> c >> k;
	vl t(n); REP(i, n) cin >> t[i];
	ll cnt = 0;
	sort(ALL(t));
	ll cur = -1, num = -1;
	REP(i, n) {
		if (cur == -1 || cur < t[i] || num == 0) {
			cur = t[i] + k;
			num = c - 1;
			cnt++;
		} else {
			num--;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin>>S;
  int ans;
  int lenS=S.size();
  for(int i=lenS-2;i>0;i--)
  {
    if((i+1)%2==0)
    {
      string R,L;
      for(int k=0;k<(i+1)/2;k++)
      {
        L+=S[k];
        R+=S[k+((i+1)/2)];
      }
      if(R==L)
      {
        ans=i+1;
        break;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

class UnionFindTree {
private:
  int nodeSize;
  vector<int> parent;
  vector<int> rank;
  vector<int> treeSize;

public:
  UnionFindTree(int ns) {
    nodeSize = ns;
    parent = vector<int>(nodeSize);
    rank = vector<int>(nodeSize, 0);
    treeSize = vector<int>(nodeSize, 1);

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

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

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) {
      return false;
    }

    if (rank[x] < rank[y]) {
      parent[x] = y;
      treeSize[y] += treeSize[x];
    } else {
      parent[y] = x;
      treeSize[x] += treeSize[y];
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }

    return true;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int getSize(int x) {
    return treeSize[find(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> p(n);
  UnionFindTree uf(n);

  rep (i, n) cin >> p[i];

  rep (i, m) {
    int x, y;
    cin >> x >> y;
    uf.unite(x - 1, y - 1);
  }

  int ans = 0;

  rep (i, n) {
    if (uf.same(p[i] - 1, p[p[i] - 1] - 1)) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
from collections import defaultdict

N, M, K = map(int, input().split())
F = [tuple(map(lambda s: int(s) - 1, input().split())) for i in range(M)]
B = [tuple(map(lambda s: int(s) - 1, input().split())) for i in range(K)]


class DisjointSet():
    def __init__(self, n):
        self.root = [-1] * n

    def find(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.root[x] > self.root[y]:
            x, y = y, x
        self.root[x] += self.root[y]
        self.root[y] = x
        return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.root[self.find(x)]


d = DisjointSet(N)
friends = defaultdict(int)
for Ai, Bi in F:
    d.unite(Ai, Bi)
    friends[Ai] += 1
    friends[Bi] += 1
blocking = defaultdict(list)
for Ci, Di in B:
    blocking[Ci].append(Di)
    blocking[Di].append(Ci)

ans = [0] * N
for i in range(N):
    ans[i] = d.size(i) - friends[i] - 1
    for b in blocking[i]:
        if d.same(i, b):
            ans[i] -= 1
print(' '.join(list(map(str, ans))))


Measured memory_bytes: 66964
N = int(input())
S = input()

R = [X for X, x in enumerate(S) if x == 'R']
G = [Y for Y, y in enumerate(S) if y == 'G']
B = [Z for Z, z in enumerate(S) if z == 'B']

mae = len(R)*len(G)*len(B)

cnt=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        k = 2*j-i
        if k >=N:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            cnt+=1

print(mae-cnt)

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

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

    sort(a, a + n, greater<int>());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            Alice += a[i];
        }
        else {
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <stdio.h>



 int main(){

   int i;
   int a[1500];
   int n;



    scanf("%d",&n);


  for(i=0;i <n ;i++){
      scanf("%d",&a[i]);
    }


  for(i=0;i <n ;i++){
    if(i){
      printf(" ");
    }
    printf("%d",a[n-i-1]);
        }








  printf("\n");



return(0);
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define MOD 998244353LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int d[100005];
ll cnt[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
		if(i==0 && d[i]!=0){
			printf("0\n");
			return 0;
		}
		cnt[d[i]]++;
	}
	if(cnt[0]!=1){
		printf("0\n");
		return 0;
	}
	ll ans=1;
	for(int i=1;i<n;i++){
		if(cnt[i]!=0){
			if(cnt[i-1]==0){
				ans=0;
			}else{
				ll val=1;
				for(int j=0;j<cnt[i];j++){
					val=val*cnt[i-1]%MOD;
				}
				ans=ans*val%MOD;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

ll EuclideanAlgorithm (ll a, ll b);

ll EuclideanAlgorithm (ll a, ll b) {
    if (b == 0) {
        return a;
    } else {
        return EuclideanAlgorithm(b, a%b);
    }
}

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

    cin >> a >> b >> c >> d;
  
  	ll dc = b/c - (a-1)/c;
  	ll dd = b/d - (a-1)/d;
  	ll lcm = c*d / EuclideanAlgorithm(c, d);
  	ll dcd = b/lcm - (a-1)/lcm;
  	
	ll ans = (b-a+1) - ((dc+dd) - dcd);
  	
    cout << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[2][2020],x,n=1,ans;
string s;
int main()
{
	cin>>s;
	for(int i=0;i<=s.size()-1;i++)
	{
		int x=s[i]-'0';
		for(int j=0;j<=2019;j++)
			f[1][(j*10+x)%2019]+=f[0][j];
		f[1][x]++;
		for(int j=0;j<=2019;j++)
		{
			f[0][j]=f[1][j];
			f[1][j]=0;
		}
		ans+=f[0][0];
	}
	cout<<ans;
}


Measured memory_bytes: 3728
use std::vec::Vec;
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();
    let mut acc = HashMap::<i64, i64>::new();
    let mut ans = 0;
    for i in 0..n {
      let b =  (i as i64 + 1) + a[i];
      let c = - a[i] + (i as i64 + 1);
      if let Some(x) = acc.get(&c) {
        ans += x;
      }
     if let Some(x) = acc.get_mut(&b) {
       *x += 1;
     } else {
       acc.insert(b, 1);
     }
    }
    //println!("{:?}", acc);
    println!("{}", ans);
}


Measured memory_bytes: 12376
#include<stdio.h>
#define MAX 10000
#define NIL -1
typedef struct{int parent,left,right;}Node;
Node T[MAX];
int n,D[MAX],H[MAX];
void setDepth(int u, int d){
  if(u == NIL) return;
  D[u] = d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1 =0,h2 =0;
  if(T[u].left!=NIL)
	h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
	h2=setHeight(T[u].right)+1;
  return H[u]= (h1>h2 ? h1:h2);
}
int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL)
	return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL)
	return T[T[u].parent].right;
  return NIL;
}
void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if(T[u].left!=NIL) deg++;
  if(T[u].right!=NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent ==NIL){
	printf("root\n");
  }else if(T[u].left == NIL && T[u].right ==NIL){
	printf("leaf\n");
  }else{
	printf("internal node\n");
  }
}
int main(int argc, char *argv[]){
  int v,l,r,root=0,i;
  scanf("%d",&n);
  for( i=0;i<n;i++) T[i].parent=NIL;
  for(i=0;i<n;i++){
	scanf("%d %d %d",&v,&l,&r);
	T[v].left=l;
	T[v].right=r;
	if(l!=NIL) T[l].parent=v;
	if(r!=NIL) T[r].parent=v;
  }
  for(i=0;i<n;i++) if(T[i].parent==NIL) root=i;
  setDepth(root, 0);
  setHeight(root);
  for(i=0;i<n;i++) print(i);
  return 0;
}



Measured memory_bytes: 2048