akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,tot;bool spec=false;
void solve(int &x)
{
	int cnt=0,pw=1;
	string s="";
	while(x)
	{
		if(x%2==1)
			s+="1",cnt++;
		else
			s+="0";
		x/=2;
	}
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')
			x=(x+pw)%cnt;
		pw=pw*2%cnt;
	}
	tot+=s.size()*2;
}//no problem
int cal(int num)
{
	int res=0;
	while(num)
	{
		solve(num);
		res++;
	}
	return res;
}
string s;
vector<int> ANS;
int main()
{
	cin>>n>>s;
	int cnt=0,cnt1,cnt2,sum1=0,sum2=0,pw1=1,pw2=1;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
		if(s[i]=='1')
			cnt++;
	cnt1=cnt-1;
	if(cnt1==0)spec=true,cnt1=1;
	cnt2=cnt+1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')
		{
			sum1=(sum1+pw1)%cnt1;
			sum2=(sum2+pw2)%cnt2;
		}
		pw1=pw1*2%cnt1;
		pw2=pw2*2%cnt2;
	}
	pw1=1;pw2=1;
//	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')
		{
			if(spec)ANS.push_back(0);
			else{
				int ans=1;
				ans+=cal(((sum1-pw1)%cnt1+cnt1)%cnt1);
				ANS.push_back(ans);
			}
		}
		else
		{
			int ans=1;
			ans+=cal((sum2+pw2)%cnt2);
			ANS.push_back(ans);
		}
		pw1=pw1*2%cnt1;
		pw2=pw2*2%cnt2;
	}
	reverse(ANS.begin(),ANS.end());
	for(int i=0;i<ANS.size();i++)cout<<ANS[i]<<"\n";
	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll dp[120][55][3000];


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

  int n, m;
  ll s;
  cin >> n >> m >> s;

  chmin(s, ll(2500));

  vector<vector<tuple<int, ll, ll>>> G(n);

  rep(i, m){
    int u, v, a;
    ll b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].push_back(make_tuple(v, a, b));
    G[v].push_back(make_tuple(u, a, b));

  }

  vector<pair<ll, ll>> c(n);

  rep(i, n){
    ll c_, d_;
    cin >> c_ >> d_;
    c[i] = make_pair(min(c_, ll(2500)), d_);
  }

  rep(i, 120){
    rep(j, 55){
      rep(k, 3000){
        dp[i][j][k] = INF;
      }
    }
  }

  for(int i = 0; i <= s; i++){
    dp[0][0][i] = 0;
  }
  rep(k, 3000){
    chmin(dp[0][0][min(k+c[0].first, ll(2999))], dp[0][0][k] + c[0].second);
  }

  rep(i, 119){
    rep(j, n){
      
      for(int l = 0; l < int(G[j].size()); l++){

        int nv   = get<0>(G[j][l]);
        ll cost_ = get<1>(G[j][l]);
        ll time_ = get<2>(G[j][l]);

        rep(k, 3000){
          // cout << cost_ << endl;
          if(k-cost_ < 0) continue;
          chmin(dp[i+1][nv][k-cost_], dp[i][j][k] + time_);

        }

        rep(k, 3000){
          // 各kに対して、
          chmin(dp[i+1][nv][min(k+c[nv].first, ll(2999))], dp[i+1][nv][k] + c[nv].second);

        }
      }
    }
  }

  vector<ll> ans(n);
  rep(i, n) ans[i] = INF;
  rep(i, n){

    // 119回目の、k以上で一番小さいもの
    rep(j, 3000){
      rep(k, 120){
        chmin(ans[i], dp[k][i][j]);
      }
    }
  }

  for(int i = 1; i < n; i++){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 158352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n;
	cin>>n;
	int fl=1;
	string s;
	cin>>s;
	if(n%2!=0) {cout<<"No"; return 0;}
	for(int i=0;i<s.length()/2;i++)
	{
		if(s[i]==s[i+n/2])fl=fl*1;
		else fl=fl*0;
	}
	if(fl==1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
N = int(input())
X = [int(x) for x in input().split()]

for i in range(N):
    X[i] = [X[i], i]
    
X.sort(reverse=True)
B = [0 for i in range(N)]
for i in range(N):
    if (i+1) <= N*0.5:
        B[X[i][1]] = X[N//2][0]
    else:
        B[X[i][1]] = X[N//2-1][0]
        
for i in range(N):
    print(B[i])

Measured memory_bytes: 39840
def dfs(x):
    if visited[x]:
        return 
    visited[x] = True
    for i in range(n):
        if graph[x][i]:
            dfs(i)

n, m = map(int, input().split())
graph = [[False] * n for _ in range(n)] 
sides = []

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    sides.append([a, b])
    graph[a][b] = True
    graph[b][a] = True

ans = 0
for side in sides:
    visited = [False] * n
    l, r = side
    graph[l][r] = False
    graph[r][l] = False
    dfs(0)
    if False in visited:
        ans += 1
    graph[l][r] = True
    graph[r][l] = True

print(ans)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}



int main() {
ll S;
  ll W;
  cin >>S>>W;
  
  if(S<=W) {
cout<<"unsafe"<<endl;
  }
else {
cout<<"safe"<<endl;
}
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

ll fact[2000005];
ll power(ll x, ll y) 
{ 
    ll res = 1;    
    x = x % mod;  
  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % mod; 
        y = y>>1; 
        x = (x*x) % mod; 
    } 
    return res%mod; 
} 
ll modInverse(ll a) { 
     return  (power(a,mod-2))%mod;
}  

ll comb(ll n,ll r) {
	ll ans = fact[n];
	ans = (ans *modInverse(fact[r]))%mod;
	ans = (ans*modInverse(fact[n-r]))%mod;
	return ans%mod;
}
void solve() {

	int r1,c1,r2,c2;
	cin >> r1>>c1>>r2>>c2;
	fact[0]=1;
	for(int i=1;i<=2000003;i++) {
		fact[i] = (fact[i-1]%mod*i%mod)%mod;
	}
	ll x= comb(r2+c2+2,c2+1);
	ll y = comb(r1+c2+1,c2+1);
	ll z = comb(r2+c1+1,c1);
	ll w = comb(r1+c1,c1);
	ll ans = (x-y+mod)%mod;
	ans = (ans + w%mod)%mod;
	ans = (ans-z+mod)%mod;
	cout << ans << endl;
}

signed main() {
	boost;
	solve();
}

Measured memory_bytes: 15872
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	K := getInt()

	ans := K
	for i := 1; i < N; i++ {
		ans *= (K - 1)
	}
	out(ans)

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,a,b;
    cin>>k>>a>>b;
    if(k==1){
        cout<<"OK\n";
        return 0;
    }
    if((b/k)-((a-1)/k)>0){
        cout<<"OK\n";
    }else{
        cout<<"NG\n";
    }
    return 0;
}

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

ll dp[110][100010];

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

    ll n,w;
    cin >> n >> w;
    
    vector<ll> weight(n);
    vector<ll> value(n);
    
    rep(i,n) cin >> weight[i] >> value[i];
    
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j <= w; j++){
            if(j - weight[i] >= 0){
                dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    
    cout << dp[n][w] << endl;

}



Measured memory_bytes: 79360
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int N;
int bs[100001];
int main(){
  while(cin>>N&&N){
    int sum=0;
    for(int i=0;i<N;i++){
      cin>>bs[i];
      sum+=bs[i];
    }
    bool ok=false;
    int k=0;
    for(k=1;k*(k+1)/2<=sum;k++){
      if(k*(k+1)/2==sum){
        ok=true;
        break;
      }
    }
    int sz=N;
    if(!ok)cout<<-1<<endl;
    else{
      int iter=0;
      for(iter=0;iter<10000;iter++){
        ok=true;
        // check
        for(int i=0;i<k;i++)
          if(bs[i]!=i+1)ok=false;
        if(ok)break;
        // remake
        int cnt=0;
        int val=0;
        for(int i=0;i<sz;i++){
          if(bs[i]==0)cnt++;
          else{
            bs[i]--;
            val++;
          }
        }
        int pos=0;
        for(int i=0;i<sz;i++)
          if(bs[i]!=0)bs[pos++]=bs[i];
        bs[pos++]=val;
        sz=pos;
      }
      if(iter==10000)cout<<-1<<endl;
      else cout<<iter<<endl;
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 1176
n = int(input())

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

if n == 1:
    print(1)
else:
    print(n-max(difs.values()))

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	if(n<1200)cout<<"ABC";
	else if(n<2800)cout<<"ARC";
	else cout<<"AGC";
	cout<<endl;
	return 0;
	
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
for h in range(n-m+1):
    for w in range(n-m+1):
        wi = [a[w:w+m] for a in A[h:h+m]]
        if wi == B:
            print('Yes')
            exit()
print('No')

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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> v(5);
  for(int i=0;i<5;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  int64_t n=v.at(0);
  int64_t ans=5;
  int64_t count=N/n;
  if(N%n>0){
    count++;
  }
  ans+=count-1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
    
left_max = [0]*(N+1)
right_max = [0]*(N+1)
for i in range(1,N+1):
    left_max[i] = max(left_max[i-1],A[i-1])
    
for i in range(N-1,-1,-1):
    right_max[i] = max(right_max[i+1],A[i])
    
for i in range(N):
    print(max(left_max[i],right_max[i+1]))


Measured memory_bytes: 72664
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define ll long long 
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b) 
#define forn(n) for(ll i=0;i<n;i++) 
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
const int MOD = 1e9 + 7;
const int v1=1e5+5;
#define pi 3.141592653589793238
const int N=2e5+5;
 
 
//cout<<"Case #"<<p<<": "<<;
//f ile input  freopen("input.txt","r",stdin); 
//file output freopen("output.txt","w",stdout);
 
using namespace std;

vector <vector<ll>> adj(N);
vector <bool> visited(N);
ll ans=0;
vector <ll> dp;

void dfs(ll v)
{
  visited[v]=true;
  //ans=max(ans,count1);
  for(auto i:adj[v])
  {
    if(!visited[i])
      dfs(i);
    dp[v]=max(dp[v],1+dp[i]);
  }
}

int32_t main()
{
  IOS;
  ll n=0;
  ll m=0;ll x,y;
  cin>>n>>m;
  ll w=0;
  map <ll,ll> q;
  vector <ll> p;
  forn(m)
  {
    cin>>x>>y;
    adj[x].pb(y);
    q[x]++;
    if(q[x]==1)
    {
      p.pb(x);w++;
    }
    //adj[y].pb(x);
  }
  dp.resize(n+1);
  p.resize(w);
  forn(w)
  {
    if(!visited[p[i]])
    {
      dfs(p[i]);
    }
  }
  cout<<vmax(all(dp))<<"\n";
}
    


Measured memory_bytes: 18420
#include <iostream>

int main() {
  unsigned long X;
  std::cin >> X;

  unsigned long current = 100;

  unsigned long year = 0;
  while (current < X) {
    current += static_cast<unsigned long>(current * 0.01);
    year += 1;
  }

  std::cout << year << std::endl;
  return 0;
}


Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split(" ")))

b1=[]
b2=[]
b=[]
for i in range(0, n-1, 2):
    b1.append(a[i])
    b2.append(a[i+1])

if n%2 == 1:
    b1.append(a[n-1])
    b1.reverse()
    b.extend(b1)
    b.extend(b2)
else:
    b2.reverse()
    b.extend(b2)
    b.extend(b1)

for item in b:
    print(item, end=" ")


Measured memory_bytes: 26180
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int N,K;
    cin >> N >> K;
    multiset <int> ms;
    for (int i = 0; i < N; i++){
        int x; cin >>x;
        ms.insert(x);
    }
    int sum = 0;
    auto idx = ms.begin();
    for (int i = 0; i < K; i++){
        sum += *idx;
        idx++;
    }
    cout << sum << endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    ll n,k; cin>>n>>k;
    if (k>(n-1)*(n-2)/2){
        cout<<-1<<endl;
        return 0;
    }

    cout << n-1+ (n-1)*(n-2)/2 - k<<endl;
    REP(i,n-1) cout<<1<<' '<<2+i<<endl;
    ll count=0;
    FOR(i,2,n-1){
        FOR(j,i+1,n){  
            if(count==((n-1)*(n-2)/2 - k)) return 0;
            cout<<i<<' '<<j<<endl;
            count++;
            // cout << count<<endl;
        }
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    //cout << s[0] + s.size() + s[s.size() - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
K=int(input())

a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[K-1])

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

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if((a == b &&  b != c )|| (a == c && c != b ) ||(b == c && c != a)){
    cout << "Yes" << endl;
  }else{
        cout << "No" << endl;
  }
  
}

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

int main() {
    int A11;
    int A12;
    int A13;
    std::cin >> A11 >> A12 >> A13;
    int A21;
    int A22;
    int A23;
    std::cin >> A21 >> A22 >> A23;
    int A31;
    int A32;
    int A33;
    std::cin >> A31 >> A32 >> A33;

    int N;
    std::cin >> N;
    for (int i = 0; i < N; ++i) {
        int b;
        std::cin >> b;
        if (b == A11) {
            A11 = 0;
        } else if (b == A12) {
            A12 = 0;
        } else if (b == A13) {
            A13 = 0;
        } else if (b == A21) {
            A21 = 0;
        } else if (b == A22) {
            A22 = 0;
        } else if (b == A23) {
            A23 = 0;
        } else if (b == A31) {
            A31 = 0;
        } else if (b == A32) {
            A32 = 0;
        } else if (b == A33) {
            A33 = 0;
        }
    }
    if ((A11 == 0 && A12 == 0 && A13 == 0) ||
        (A21 == 0 && A22 == 0 && A23 == 0) ||
        (A31 == 0 && A32 == 0 && A33 == 0) ||
        (A11 == 0 && A21 == 0 && A31 == 0) ||
        (A12 == 0 && A22 == 0 && A32 == 0) ||
        (A13 == 0 && A23 == 0 && A33 == 0) ||
        (A11 == 0 && A22 == 0 && A33 == 0) ||
        (A13 == 0 && A22 == 0 && A31 == 0)) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){

  int n,m,r=1;
  cin>>n;
  vector <int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  cin>>m;
  for(int i=0;i<m;i++){
    int b;
    cin>>b;
    r&=binary_search(a.begin(),a.end(),b);
  }
  cout<<r<<endl;
  return 0;

}



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

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define mito(N) cout << N << endl

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
		for (int j = i * i; j < 1000001; j += i){
			f[j] = true;
		}
	}

	int n;
	while (in >> n){
		int c = 0;
		for (int i = 2; i <= n; i++){
			if (!f[i])c++;
		}
		mito(c);
	}

	return (0);
}

Measured memory_bytes: 2136
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int H, W;
	cin >> H >> W;

	vector<vector<int>> a(H, vector<int>(W));
	vector<vector<bool>> moved(H, vector<bool>(W));
	int count = 0;
	rep(y, H) {
		rep(x, W) {
			cin >> a[y][x];
		}
	}
	rep(y, H - 1) {
		rep(x, W) {
			if (a[y][x] % 2) {
				a[y][x]--;
				a[y + 1][x]++;
				moved[y][x] = true;
				count++;
			}
		}
	}
	rep(x, W - 1) {
		if (a[H - 1][x] % 2) {
			a[H - 1][x]--;
			a[H - 1][x + 1]++;
			moved[H - 1][x] = true;
			count++;
		}
	}
	cout << count << endl;
	rep(y, H - 1) {
		rep(x, W) {
			if (moved[y][x]) {
				cout << (y + 1) << " " << (x+1) << " " << (y + 2) << " " << (x + 1) << endl;
			}
		}
	}
	rep(x, W - 1) {
		int y = H - 1;
		if (moved[y][x]) {
			cout << (y + 1) << " " << (x + 1) << " " << (y + 1) << " " << (x + 2) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3200
cards = {

"S" : [0 for i in range(13)],
"H" : [0 for i in range(13)],
"C" : [0 for i in range(13)],
"D" : [0 for i in range(13)]
}

n = int(input())
for i in range(n):
	a,b = input().split()
	cards[a][int(b)-1] = 1

for a in ("S","H","C","D"):
	for b in range(13):
		if cards[a][b] == 0:
			print(a,b+1)

Measured memory_bytes: 7636
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a, const void *b){
	int *A = (int *)a;
	int *B = (int *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}

int main(){
	int N,K,ans=1000000000;
	scanf("%d%d",&N,&K);
	int h[N];
	for(int i=0;i<N;i++)scanf("%d",&h[i]);
	qsort(h,N,sizeof(int),compare);
	for(int i=0;i+K-1<N;i++)ans=min(ans,h[i]-h[i+K-1]);
	printf("%d\n",ans);
	return 0;
}

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

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

  int n, m, x;
  cin >> n >> m >> x;

  int a = 0, b = 0;
  for (int i = 0; i < m; ++i) {
    int y; cin >> y;

    if (y < x) a++;
    else b++;
  }

  cout << min(a, b) << "\n";
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  string S;
  cin>>S;
  int N=S.size();
  for(int i=(N-1)/2*2;i>=0;i-=2)
    if(S.substr(0,i/2)==S.substr(i/2,i/2)){
      cout<<i<<endl;
      return 0;
    }
}

Measured memory_bytes: 3624
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    cnt = 1
    t_cnt = 0
    for i in range(1, n):
        if a[i] != a[i-1]:
            t_cnt += (cnt // 2)
            cnt = 1
        else:
            cnt += 1
    t_cnt += (cnt // 2)
    print(t_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    string s;
    while(cin>>s){
        if(s=="0")break;
        
        int a=0,b=0;
        for(int i=1;i<s.size();i++){
            if(s[i]=='A')a++;
            else b++;
        }
        if( (a==10 && b<10) || (a>b && a-b==1) )a++;
        else if( (b==10 && a<10) || (a<b && b-a==1) )b++;
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}

Measured memory_bytes: 1184
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long f = (long) Math.ceil(Math.sqrt(N));
        long min = N - 1;
        for (long i = 1; i <= f; i++) {
            if (N % i != 0) {
                continue;
            }
            if (N / i + i - 2 <= min) {
                min = N / i + i - 2;
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 23124
a,b,q = list(map(int,input().split()))
s = [int(input()) for i in range(0,a)]
t = [int(input()) for i in range(0,b)]
x = [int(input()) for i in range(0,q)]
import bisect

def bifind(r,z):
    if z < r[0]:
        return [r[0],r[0]]
    elif z > r[-1]:
        return [r[-1],r[-1]]
    y = bisect.bisect_left(r,z)-1
    return [r[y],r[y+1]]

for i in range(0,q):
    ls = bifind(s,x[i])
    lt = bifind(t,x[i])
    ans = list()
    for j in range(0,2):
        for k in range(0,2):
            ans.append(abs(ls[j]-x[i])+abs(lt[k]-ls[j]))
            ans.append(abs(lt[k]-x[i])+abs(lt[k]-ls[j]))
    print(min(ans))

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

int f[100010];
int dist[100010];

int find(int x){
  if(f[x]==x) return x;
  int a = f[x];
  int b = find(f[x]);
  f[x] = b;
  dist[x]+=dist[a];
  return b;
}

int dis(int x){
  if(f[x]==x) return 0;
  return (dis(f[x])+dist[x]);
}


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

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

  for(int i=0;i<m;i++){
    int l,r,d;
    cin>>l>>r>>d;
    int fl = find(l);
    int fr = find(r);
    if(fl==fr){
      if(dist[l]+d!=dist[r]){
        cout<<"No"<<endl;
        return 0;
      }
    }
    else{
      f[fr] = fl;
      dist[fr]=dis(l)-dis(r) + d;
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int m1=sc.nextInt();
		int d1=sc.nextInt();
		int m2=sc.nextInt();
		int d2=sc.nextInt();
		if(m1!=m2){
			System.out.println(1);
		}else{
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23124
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			String str = kb.readLine();
			String[] tmpArr = str.split( " " );
			int n = Integer.parseInt( tmpArr[0] );
			int m = Integer.parseInt( tmpArr[1] );
						
			int[][] a = new int[n][m];
			int[] b = new int[m];
			int c;


			for( int i=0; i<n; i++ ) {
				str = kb.readLine();
				tmpArr = str.split( " " );
				for( int j=0; j<m; j++ ) {
					a[i][j]=Integer.parseInt( tmpArr[j] );
				}
			}
			for( int j=0; j<m; j++ ) {
				str = kb.readLine();
				b[j]=Integer.parseInt( str );
			}
			
			for( int i=0; i<n; i++ ) {
				c=0;
				for( int j=0; j<m; j++ ) {
					c+=a[i][j]*b[j];
				}
				System.out.print( c+"\n" ); 
			}
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 22708
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
typedef pair <int , int> ii;

int main() {
    int n,l; scanf("%d%d" , &n , &l);
    int sum = 0;
    for (int i = l ; i < l + n ; i++)
        sum += i;
    ii sol = mp(INT_MAX , 0);
    for (int x = l ; x < l + n ; x++)
        if (sol.fi > abs(x))
            sol = mp(abs(x) , sum - x);
    printf("%d\n" , sol.se);
}


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

int digits(int a) {
    if(a == 0) return 1;
    int cnt = 0;
    while(a) {
        a /= 10;
        cnt++;
    }
    return cnt;
}

int main(void) {
    int a,b;
    int d;
    int aft;
    int base;
    cin >> a >> b;
    d = digits(b);
    aft = a * pow(10,d) + b;
    base = sqrt(aft);
    if((base*base) == aft) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC104 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter


mod = 10**9 + 7

s = list(input())
n = len(s)
#見るA,B,Cを仮定して
#dp[i][j] := i文字までみたとき、
#            j = 0 := A,B,C全部入っていない
#            j = 1 := Aだけ入っている
#            j = 2 := A,Bだけ入っている
#            j = 3 := A,B,C全て入っている
#           状態のABC数

dp = [[0]*4 for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
    if s[i] == '?':
        for j in range(4):
            #A,B,Cそれぞれに変換して進めることができるため3倍
            #jの状態変化なし
            dp[i+1][j] = 3*dp[i][j] % mod
    else:
        for j in range(4):
            dp[i+1][j] = dp[i][j]
    if s[i] == 'A':
        #状態0→1に変えることができる
        dp[i+1][1] += dp[i][0]
        dp[i+1][1] %= mod
    elif s[i] == 'B':
        #状態1→2に変えることができる
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] %= mod
    elif s[i] == 'C':
        #状態2→3に変えることができる
        dp[i+1][3] += dp[i][2]
        dp[i+1][3] %= mod
    elif s[i] == '?':
        #状態0→1,1→2,2→3に変えることができる
        for j in range(3):
            dp[i+1][j+1] += dp[i][j]
            dp[i+1][j+1] %= mod
print(dp[n][3])


Measured memory_bytes: 60536
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	string ans = "NG";
	for (int i = a; i <= b; i++) {
		if (i % k == 0)ans = "OK";
	}
	cout << ans << endl;

	return 0;
}


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

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

    vector <long int> vec;
    long int input;

    for(long int n=0; n<N; n++)
    {
        cin >> input;
        vec.push_back(input);
    }

    sort(vec.begin(),vec.end());

    for(long int i=1; i<vec.size(); i++)
    {
        if(vec[i] == vec[i-1])
        {
            vec.erase(vec.begin() + (i - 1));
            vec.erase(vec.begin() + (i - 1));

            i--;
        }
    }

    cout << vec.size();
    return 0;
}


Measured memory_bytes: 4288
#include <bits/stdc++.h>
#define len(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define chmax(x, v) x = max((x), (v))
#define chmin(x, v) x = min((x), (v))
using namespace std;
#define ll long long

/*string mycmp(string a,string b)
{
    string p=a,q=b;
    string x=p.append(q),y=b.append(a);
    //cout<<p<<"p "<<x<<"x "<<q<<"q "<<y<<endl;
    if(x.compare(y)>0)
        return x;
    else
        return y;
}

string largestNumber(const vector<int> &A) {
    vector<int>v;
    if(A.size()==0)
        return "";
    int t=-1;
    for(int i=0;i<A.size();i++){
        t+=A[i];
        v.push_back(to_string(A[i]));
    }
    t+=1;
    if(t==0)
        return "0";
    sort(v.begin(),v.end());
}

*/
int main() {
	/*ios::sync_with_stdio(false);
	cin.tie(0);*/
    string n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n.length();i++)
    {
        ans+=(n[i]-'0');
    }
    if(ans%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    //largestNumber(const vector<int> &A) {
    return 0;
}


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int a, b, k;
    cin >> a >> b >> k;
    rep(i, k)
    {
        if (i % 2)
        {

            if (b % 2 == 1)
                --b;
            a += b / 2, b /= 2;
        }
        else
        {
            if (a % 2 == 1)
                --a;
            b += a / 2, a /= 2;
        }
    }
    cout << a << " " << b << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3636
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
        int n = s.nextInt();
        int r = s.nextInt();
        if(n>=10)System.out.println(r);
        else System.out.println(r+(100*(10-n)));
       	
    }	
}





        
    

      
 

Measured memory_bytes: 32636
n, k = map(int, input().split())
count = 0
for b in range(1, n + 1):
    if k < b:
    #a < bを考える
        if k != 0:
            count += b - k
        else:
            count += b - 1
    # a > bを考える
        p = n // b - 1
        q = n % b - k + 1 if n % b - k + 1 > 0 else 0
        count += p * (b - k) + q
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int d[10][10] = {0},H,W,a[200][200];
  cin>>H>>W;
  for (int i(0);i<10;i++){
    for (int j(0);j<10;j++){
      cin>>d[i][j];
    }
  }
  for (int i(0);i<H;i++){
    for (int j(0);j<W;j++){
      cin>>a[i][j];
    }
  }
	for (int k = 0; k < 10; k++){       // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans(0);
  for (int i(0);i<H;i++){
    for (int j(0);j<W;j++){
      if (a[i][j]!=-1){
        ans += d[a[i][j]][1];
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
    int N;
    cin >> N;
    double D[N][N];
    vector<P> c(N);
    rep(i,N) {
	double x,y;
	cin >> x >> y;
	c[i] = make_pair(x,y);
    }
    rep(i,N) {
	rep(j,N) {
	    double x0 = c[i].first;
	    double y0 = c[i].second;
	    double x1 = c[j].first;
	    double y1 = c[j].second;
	    D[i][j] = sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));
	}
    }

    vector<int> l(N);
    rep(i,N) l[i] = i;
    double sum = 0;
    double n = 0;
    
    do{
	n++;
	rep(i,N-1) {
	    sum += D[l[i]][l[i+1]];
	}
    }while(next_permutation(l.begin(),l.end()));

    double ans = sum/n;
    printf("%.12lf\n",ans);
    
    return 0;
}



Measured memory_bytes: 3820
#include <iostream>
using namespace std;
 
int main(){
    int n;
 
    cin >> n;
    int* l = new int[n];
 
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
 
    for(int i = 0; i < n; i++){
        cout << l[n-i-1] << flush;
        if(i == n-1){
            cout << endl;
            break;
        }
        cout << ' ' << flush;
    }
 
    return(0);
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
typedef long long ll;
const ll MOD = 1e9+7;

/*ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}*/
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

/*ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}*/
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
  int n, m, g, h, ans=0; cin >> n >> m;
  UnionFind A(n);
  vector<int> P(n);
  rep(i, n) {cin >> g; P[i]=g-1;}
  rep(i, m) {cin >> g >> h; A.unite(g-1, h-1);}
  rep(i, n){
    if(A.same(i, P[i])) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

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

    string str;
    while(cin >> str && str != "#"){
        int y, m, d;
        cin >> y >> m >> d;
        if(y < 31){
            cout << str << " " << y << " " << m << " " << d << "\n";
        } else if(y == 31){
            if(m <= 4){
                cout << str << " " << y << " " << m << " " << d << "\n";
            }else{
                cout << "? " << y - 30 << " " << m << " " << d << "\n";
            }
        } else{
            cout << "? " << y - 30 << " " << m << " " << d << "\n";
        }
    }
}


Measured memory_bytes: 3180
import java.util.*;

class Main {
  public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
    final int n = sc.nextInt();
    final int x = sc.nextInt();
    final int[] l = new int[n];
    int dist = 0;
    for (int i = 0; i < n; ++i) {
      l[i] = sc.nextInt();
      dist += l[i];
      if (dist > x) {
        System.out.println(i + 1);
        return;
      }
    }
    System.out.println(n + 1);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
 
int main(){
  int m;
  cin >> m;
 
  for(int i=0;i<m;i++){
    string train;
    cin >> train;
    set<string> st;
    for( int i = 1, length = train.length() ; i < length ; ++i ){
      string forward, backward;
      forward = train.substr(0,i);
 backward = train.substr(i, length-i);
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(backward.begin(), backward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(forward.begin(), forward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(backward.begin(), backward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
    }
    cout << st.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=41 ;
int main()
{
   fast ;
   ll n,t ;
   cin>>n>>t ;
   vector<ll>v ;
   for(ll i=0;i<n;i++)
   {
       ll x ;
       cin>>x ;
       v.pb(x) ;
   }
   sort(all(v)) ;
   ll ans=0 ;
   ll mx=0 ;
   for(ll i=0;i<n;i++)
   {
       if(v[i]>=mx)
       {
           ans+=t ;
           mx=v[i]+t ;
       }
       else
       {
           ans+=(v[i]+t-mx) ;
           mx=v[i]+t ;
       }
   }
   cout<<ans<<endl ;

}


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

int main(){
  int64_t N, K ; 
  cin >> N >> K ; 
  vector<int64_t> H(N) ; 
  int64_t cnt = 0 ; 
  
  for(int i = 0 ; i < N ; i++){
    cin >> H.at(i) ; 
  }
  sort(H.begin() , H.end()) ; 
  reverse(H.begin() , H.end()) ; 
  
  for(int i = K ; i < N ; i++ ){
    cnt = cnt + H.at(i) ; 
  }
  
  cout << cnt << endl ; 
}



Measured memory_bytes: 4824
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}

ll n,m;
ll a[50],b[50];
bool graph[50][50],reached[50];

void dfs(ll v){
  reached[v]=true;
  rep(i,n){
    if(graph[i][v]==false) continue;
    if(reached[i]==true) continue;
    dfs(i);
  }
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  ll ans=0;
  ios::sync_with_stdio(false);
  cin>>n>>m;
  rep(i,50){
    rep(j,50){
      graph[i][j]=false;
    }
  }
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  rep(i,m){
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
    rep(i,n) reached[i]=false;
    dfs(0);
    bool bridge=false;
    rep(i,n) if(!reached[i]) bridge=true;
    if(bridge) ans++;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)

void Main()
{
	int H, W, K;
  	cin >> H >> W >> K;
  	vector<string> data(H);
  	vector<bool> isempty(H); // 第 i 行が空かどうか

  	rep(i, H){
      	cin >> data.at(i);
		rep(j, W){
    		isempty[i] = 1;
	        if(data[i][j] == '#'){
        		isempty[i] = 0; // 第 i 行は空でない
                break;
          	}
        }
    }

  	int ifirst = 0;
  	rep(i,H){	
  		if(isempty[i] == 1){
  			ifirst++;
    	}
      	else{
          	break;
        }
    }
  
  	
	// data[i][j] -> ans[i][j]
	vector<vector<int>> ans(H, vector<int>(W)); 
	int num = 1;
  	int flag0 = 0;
  	rep(i,H){
		if(isempty[i] == 0){ // 第 i 行は空でない
          	int flag = 0;
          	rep(j,W){
          		if(data[i][j] == '#'){
					if (flag == 0){
                  		flag = 1;
                  		ans[i][j] = num;
                    }
                  	else{
                  		num++;
                  		ans[i][j] = num;
                    }
                }
				else{
            	  	ans[i][j] = num;
                }
            }
          	num++;
        }
      	else{ // 第 i 行は空
          	if(i == 0){
              	// ans[ifirst][j] が決まってから処理
              	flag0 = 1;
            }
          	else{
              	rep(j,W){
              		ans[i][j] = ans[i-1][j];
              	}
			}
      	}
     }
  	if(flag0 == 1){ // ans[0][j] から ans[ifirst][j] まで揃える
		rep(i,ifirst){
      		rep(j,W){
				ans[i][j] = ans[ifirst][j];
        	}
    	}
    }

  	rep(i,H){
		rep(j,W){
  			cout << ans[i][j] << " ";
        }
	cout << endl;
    }  	
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 1280