akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	pair <lli,lli> par[MaxN];
	void solve(){
		lli N,M,i,j,p,q,res=0,llevo=0;
		cin>>N>>M;
		for(i=0;i<N;i++){
			cin>>p>>q;
			par[i].fst=p,par[i].snd=q;
		}
		sort(par,par+N);
		for(i=0;i<N;i++){
			if(par[i].snd+llevo>=M){
				res+=(M-llevo)*par[i].fst;
				break;
			}	
			else {
				llevo+=par[i].snd;
				res+=par[i].fst*par[i].snd;
			}
		}
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5

/* prototype declaration */
void init(int *a);
void sort(int *a);
void swap(int *x, int *y);

int main(int argc, const char *argv[])
{
	int i, *a = malloc(SIZE*sizeof(int));
	init(a); sort(a);
	for(i=0; i<SIZE-1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[SIZE-1]);

	return 0;
}

void init(int *a)
{
	int i;
	for(i=0; i<SIZE; i++)
		scanf("%d", &a[i]);
}

void sort(int *a)
{
	int i, j, max;
	for(i=0; i<SIZE; i++){
		max = i;
		for(j=i+1; j<SIZE; j++){
			if(a[max] < a[j]) max = j;
		}
		swap(&a[i], &a[max]);
	}	
}

void swap(int *x, int *y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int M = 0;
	loop(i, 1, n){
		int cnt = 0;
		string s1 = s.substr(0, i);
		string s2 = s.substr(i, n-i);
		map<char, int> t;
		for(auto x : s1) if(t[x]==0) t[x]++;
		for(auto y : s2) if(t[y]==1) t[y]++;
		for(auto z : t) if(z.second == 2) cnt++;
		M = max(cnt, M);
	}
	cout << M << endl;
 	return 0;
}

Measured memory_bytes: 3620
while True:
    W, H = list(map(int, input().split()))
    if W == 0 and H == 0:
        break
    n = 0
    while n <= W-1:
        if n == 0 or n == W-1:
            print("#"*H)
        else:
            print("#"+"."*(H-2)+"#")
        n += 1
    print("")



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

using namespace std;

const int MAX_N = 200000, INDEX = 1;
const int MAX_VAL = 1000000000, INF = MAX_VAL + 1;

struct Ball {
    int bag;
    long long val;

    Ball() {
        ;
    }

    Ball(int bag, long long val) {
        this->bag = bag;
        this->val = val;
    }

    friend bool operator < (const Ball &a, const Ball &b) {
        if (a.val == b.val) {
            return a.bag < b.bag;
        }

        return a.val < b.val;
    }
};

int n;
long long x[MAX_N + INDEX], y[MAX_N + INDEX];

Ball balls[2 * MAX_N + INDEX];
bool usedBag[MAX_N + INDEX];

long long ans;

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

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }

    long long max_max = 0, max_min = 0, min_max = INF, min_min = INF;
    for (int i = 1; i <= n; i++) {
        max_max = max(max_max, max(x[i], y[i]));
        max_min = max(max_min, min(x[i], y[i]));
        min_max = min(min_max, max(x[i], y[i]));
        min_min = min(min_min, min(x[i], y[i]));
    }

    ans = (max_max - min_max) * (max_min - min_min);

    for (int i = 1; i <= n; i++) {
        balls[2 * i - 1] = Ball(i, x[i]);
        balls[2 * i] = Ball(i, y[i]);
    }

    sort(balls + INDEX, balls + INDEX + 2 * n, less<Ball>());

    int r = 2 * n + 1;
    while (!usedBag[balls[r - 1].bag]) {
        r--;

        usedBag[balls[r].bag] = true;
    }

    for (int l = 1; l <= 2 * n; l++) {
        while (r <= 2 * n && usedBag[balls[l].bag]) {
            usedBag[balls[r].bag] = false;

            r++;
        }

        usedBag[balls[l].bag] = true;

        if (r > 2 * n) {
            break;
        }

        ans = min(ans, (balls[2 * n].val - balls[1].val) * (balls[r - 1].val - balls[l + 1].val));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9856
#include<stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2592
n = gets.to_i
input = gets.split.map(&:to_i)
input.sort!
if n % 2 == 0
  n.times do |i|
    if input[i] != (i / 2) * 2 + 1
      puts "0"
      exit
    end
  end
else
  n.times do |i|
    if input[i] != ((i + 1) / 2) * 2
      puts "0"
      exit
    end
  end
end

puts ((2 ** (n / 2)) % (10 ** 9 + 7)).to_i


Measured memory_bytes: 8840
#include <stdio.h>

int main(void){
  int high[10];
  int i,max=0,max2=0,max3=0;

  for(i=0;i<10;i++){
	scanf("%d",&high[i]);
  
	if(max3<high[i]){
	  	if(max2<high[i]){

		  if(max<high[i]){
			max3 = max2;
			max2 = max;
			max = high[i];
		  }

		  else{
			max3 = max2;
			max2 = high[i];
		  }
		  
		}

		else{
		  max3 = high[i];
	}
		
  }
}

	printf("%d\n%d\n%d\n",max,max2,max3);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#define MOD 1000000009
#define e 32769

char s[1010][1010];
char t[1010][1010];
int tatehash[1010][1010];

int main(){
	int n,m,a,b;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf(" %s",s[i]);
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf(" %s",t[i]);

	long po=1;
	for(int j=0;j<b;j++)po=po*e%MOD;
	long popo=1;
	for(int i=0;i<a;i++)popo=popo*po%MOD;
	for(int j=0;j<m;j++){
		long hash=0;
		for(int i=0;i<a;i++)hash=(hash*po+s[i][j])%MOD;
		for(int i=a;i<=n;i++){
			tatehash[i-a][j]=hash;
			hash=((hash*po+s[i][j]-s[i-a][j]*popo)%MOD+MOD)%MOD;
		}
	}
	long thash=0;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)thash=(thash*e+t[i][j])%MOD;
		
	for(int i=0;i<=n-a;i++){
		long hash=0;
		for(int j=0;j<b;j++)hash=(hash*e+tatehash[i][j])%MOD;
		for(int j=b;j<=m;j++){
			if(thash==hash)printf("%d %d\n",i,j-b);
			hash=((hash*e+tatehash[i][j]-tatehash[i][j-b]*po)%MOD+MOD)%MOD;
		}
	}
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> t(n);
    rep(i,n) cin >> t[i];
    sort(t.begin(),t.end());
    int j=0,cnt=0,ans=0,res=t[0];
    while(1){
        if(j==n-1){
            ++ans;
            break;
        }
        if(cnt==c){
            ++ans;
            cnt=0;
            res=t[j];
            continue;
        }
        if(res+k<t[j+1]){
            ++j;
            ++ans;
            cnt=0;
            res=t[j];
        }else{
            ++j;
            ++cnt;
        }
    }
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3712
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

// const long long MAX = 100;
const int MOD = 1000000007;
long long bin[100];
long long H;

void COMinit() {
    bin[0] = 1;
    bin[1] = 2;
    for (int i = 2; i < 100; i++){
        bin[i] = bin[i-1] * 2;
    }
}

int main() {
  COMinit();
  cin >> H;
  long long ans = 0;
  long long i = 0;
  while(H) {
    H >>= 1;
    ans += bin[i];
    i = i+1;
    // cout << bin[i] << endl;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long double ld;

struct Point {
    ld x, y;
    Point(ld x=0, ld y=0) : x(x), y(y) {}
};

struct Circle {
    ld x, y, r;
    const static ld eps = 1e-9;
    Circle(ld x=0, ld y=0, ld r=0) : x(x), y(y), r(r) {}
    const bool isIntersect(const Circle& o) const {
        ld dx = x - o.x;
        ld dy = y - o.y;
        return (r + o.r) * (r + o.r) + eps >= dx*dx + dy*dy;
    }
    const pair<Point, Point> intersectionPoint(const Circle& o) const {
        ld dx = o.x - x;
        ld dy = o.y - y;
        ld a = (dx*dx + dy*dy + r*r - o.r*o.r) / 2.0;
        ld d = dx*dx+dy*dy;
        ld s = sqrt(d*r*r - a*a);
        Point p, q;
        p.x = (a * dx + dy * s) / d + x;
        q.x = (a * dx - dy * s) / d + x;
        p.y = (a * dy - dx * s) / d + y;
        q.y = (a * dy + dx * s) / d + y;
        return make_pair(p, q);
    }
    bool contains(const Circle& p) const {
        ld dx = x - p.x;
        ld dy = y - p.y;
        return r*r + eps >= dx*dx + dy*dy;
    }
};

int F(const Circle& o, const vector<Circle>& cs) {
    int cnt = 0;
    for (int i = 0; i < cs.size(); i++) 
        if (o.contains(cs[i]))
            cnt++;
    return cnt;
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<Circle> cs;
        for (int i = 0; i < n; i++) {
            ld x, y; 
            char d; // dummy
            cin >> x >> d >> y;
            cs.push_back(Circle(x, y, 1));
        }

        vector<Point> ips;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                if (cs[i].isIntersect(cs[j])) {
                    pair<Point, Point> ip = cs[i].intersectionPoint(cs[j]);
                    ips.push_back(ip.first);
                    ips.push_back(ip.second);
                }
            }
        }

        if (ips.empty()) {
            cout << 1 << endl;
            continue;
        }

        int m = 0;
        for (int i = 0; i < ips.size(); i++) {
            //cout << "point: " << ips[i].x << ' ' << ips[i].y << endl;
            m = max(m, F(Circle(ips[i].x, ips[i].y, 1), cs));
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 1372
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
int a,b,c,d;
scanf("%d %d %d %d",&a,&b,&c,&d);
if(abs((b-a))<=d&&abs((c-b))<=d){printf("Yes\n");}
else if(abs((c-a))<=d){printf("Yes\n");}
else {printf("No\n");}
 
}

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

#define    int               long long int
 #define    bp(x)         __builtin_popcount(x)
#define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
#define  mod  1000000007
#define  endl  "\n"
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int a[1000006];
int32_t main()
{
    fast
    int n,ans=0;  cin>>n;
    f(i,1,n)
    for(int j=i;j<=n;j+=i)
        a[j]++;
    f(i,1,n-1)    ans+=a[i];
    cout<<ans;
}

Measured memory_bytes: 11376
def main():
    n = int(input())
    dp=[0]*(10000+1)
    for x in range(1,101):
        for y in range(1, 101):
            for z in range(1, 101):
                num = x**2+y**2+z**2+x*y+y*z+z*x
                if num <= 10000:
                    dp[num] += 1
    [print(dp[i]) for i in range(1,n+1)]

if __name__ == '__main__':
    main()

Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int INF=1<<30;

int main(){
	string s;
	cin >> s;
	int n=0;
	REP(i,s.size()){
		if(s[i]=='p') n++;
	}
	cout << s.size()/2-n << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> luka(N+1);
  luka.at(0) = 2;
  luka.at(1) = 1;
  if( N > 1 ) {
    for(int i = 2; i <= N; i++ ) {
      luka.at(i) = luka.at(i-1) + luka.at(i-2);
    }
  }
  cout << luka.at(N) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys,bisect
input = sys.stdin.readline

n,p = map(int,input().split())
s = list(input())
for i in range(n):
    s[i] = int(s[i])


if p == 2:
    res = 0
    for i in range(n):
        if s[i]%2 == 0:
            res += i+1
    print(res)
elif p == 5:
    res = 0
    for i in range(n):
        if s[i]%5 == 0:
            res += i+1
    print(res)

else:
    d = 1
    q = [0]
    for i in range(n-1,-1,-1):
        q.append((q[-1]+s[i]*d)%p)
        d = d*10%p
    q.sort()
    res = 0
    i = 0
    while i < n+1:
        k = bisect.bisect_right(q,q[i])
        c = k-i
        res += c*(c-1)//2
        i = k
    print(res)


Measured memory_bytes: 75224
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int n; std::cin >> n;
	int prev = INT_MAX;
	int count = 0;
	for (auto i = 0; i < n; ++i) {
		int a; std::cin >> a;
		if (prev < a) {
			++count;
		}
		prev = a;
	}
	std::cout << count << std::endl;
}


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

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

  int a[N];

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

  int cnt =1;
  int s = a[0];
  
  while (s != 2) {
    s = a[s-1];
    cnt++;
    if (cnt > N) {cnt=-1;break;}
  }
    
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
String a=scan.next();
//int b=scan.nextInt();
//int c=scan.nextInt();
String b[]=new String[10];
for(int i=0;i<a.length();i++) {
	String str2=String.valueOf(a.charAt(i));
	b[i]=str2;
}
int c[]=new int[10];
for(int i=0;i<a.length();i++) {
	 c[i]=Integer.parseInt(b[i]);
}
int d[]=new int[10];
for(int i=0;i<a.length()-2;i++) {
	d[i]=c[i]*100+c[i+1]*10+c[i+2];
	 }
int ans=1000;
for(int i=0;i<a.length()-2;i++) {
	int kari=0;
	kari=753-d[i];
	if(kari<0) {
		kari*=-1;
	}
	if(kari<ans) {
		ans=kari;
	}
}
System.out.println(ans);

}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const int64_t INF =1e18;

int a[10];
int main () {
/* 方法１：
  int n1,n2,n3,n4;
  cin >> n1>>n2>>n3>>n4;
  if ((n1*n1 + n2*n2 + n3*n3 + n4*n4) == (1*1 + 7*7 + 9*9 + 4*4))
*/

/* 方法2：
  for (int i=0; i<4; i++) {
    int n; cin >> n;
    a[n]++;
  }
  if (a[1] == 1 && a[4] == 1 && a[7] == 1 && a[9] == 1)
*/
//方法3：
  
  vector<int>n(4);
  for (int i=0; i<4; i++) cin >>n[i];
  
  sort(n.begin(), n.end());
  
  if (n[0] = 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,j,d;
  scanf("%d %d",&a,&b);
  d=1;
  if(a>0) for(j=0;j<a;++j){d=d*100;}
  
  if( b!=100){
  printf("%d",b*d);}
  
  else {printf("%d",(b+1)*d);}

return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
using namespace std;
const int nx=2e5+5;
const int inf=1e18+7;
const int mod=1e9+7;
vector<int>adj[nx];
int a[102];

signed main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	int ans=inf;
	for(int i=1; i<=100; i++){
		int res =0;
		for(int j=1; j<=n; j++){
			res += pow((i-a[j]),2);
			//cout<<res<<endl;
		}
		ans=min(ans,res);
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4992
def solve(N, K, A):
    slow, fast = 1, 1
    is_first = True
    while is_first or slow != fast:
        is_first = False
        slow = A[slow - 1]
        fast = A[A[fast - 1] - 1]
    fast = 1
    steps_before_entering_cycle = []
    while slow != fast:
        steps_before_entering_cycle.append(fast)
        slow = A[slow - 1]
        fast = A[fast - 1]

    if K < len(steps_before_entering_cycle):
        return steps_before_entering_cycle[K]

    cycles = [slow]
    while A[slow - 1] != cycles[0]:
        cycles.append(A[slow - 1])
        slow = A[slow - 1]
    ret = cycles[(K - len(steps_before_entering_cycle)) % len(cycles)]
    return ret

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    print(solve(N, K, A))

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >>vec[i];
  }
  
  int a=1,cnt=0;
  while(a){
    for(int i=0;i<N;i++){
      if(vec[i]%2==0){
        vec[i]/=2;
      }
      else{
        a=0;
        break;
      }
      if(i==N-1){
        cnt++;
      }
    }
  }
  
  cout << cnt <<endl;
}

    
  
  

Measured memory_bytes: 3572
#include<cstdio>
using namespace std;
void func(int,int);
int main(void)
{
	int h,w,i,j,k,a[100][100],flg,cnt;
	char s[100][101];
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++)	scanf("%s",s[i]);
	for(i=0;i<h;i++)	{
		for(j=0;j<w;j++)	{
			flg=0;	cnt=0;
			for(k=j;k>=0;k--)	{
				if(s[i][k]=='c')	{
					flg=1;
					break;
				}
				cnt++;
			}
			if(flg==0)	{
				cnt=-1;
			}
			a[i][j]=cnt;
		}
	}
	for(i=0;i<h;i++)	{
		printf("%d",a[i][0]);
		for(j=1;j<w;j++)	{
			printf(" %d",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1080
#include <stdio.h>
#define N 101
#define INFTY 99999
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[N][N];
int prim(void);

int main()
{
  int i,j,a;
    
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  scanf("%d",&A[i][j]);
	  if(A[i][j]==-1)A[i][j]=INFTY;
	}
    }

  a=prim();
  printf("%d\n",a);
  return 0;
}

int prim(void)
{
  int u,minv,i,j,sum;
  int d[N],p[N],color[N];

  for(i=0;i<n;i++)
    {
      d[i]=INFTY;
      p[i]=-1;
      color[i]=WHITE;
    }
  d[0]=0;

  while(1)
    {
      minv=INFTY;
      u=-1;
      for(i=0;i<n;i++)
	{
	  if(minv>d[i] && color[i]!=BLACK)
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if(u==-1)break;
      color[u]=BLACK;
      
      for(j=0;j<n;j++)
	{
	  if(color[j]!=BLACK && A[u][j]!=INFTY)
	    {
	      if(d[j]>A[u][j])
		{
		  d[j]=A[u][j];
		  p[j]=u;
		  color[j]=GRAY;
		}
	    }
	}
    }
  
  sum=0;
  for(i=0;i<n;i++)
    {
      if(p[i]!=-1)sum+=A[i][p[i]];
    }
  return sum;
}



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

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

  for(int a=1;a<=9;a++)for(int b=1;b<=9;b++){
    if(a*b == N){
      cout <<"Yes" <<endl;
      return 0;
    }
    else{
    }
  }
  cout<<"No"<<endl;
  return 0;
//このようにしてmain関数に対する返し値は一つなのでこのようにかける
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL P = 1e9+7;

LL fp(LL a, LL n){
    if(n== 0)
        return 1;

    LL h = fp(a , n / 2);
    h = h*h %P;
    if(n&1){
        h = h * a %P;
    }

    return h;
}

vector<LL> fac(200010);
LL C(LL m, LL n){
    return fac[m] * fp(fac[m-n], P-2) % P * fp(fac[n], P-2) % P;
}
int main(){
    LL n,k;
    cin >>n>>k;

    fac[0] = fac[1] = 1;
    for(int i=2;i<=200000;i++){
        fac[i] = fac[i-1] * i % P;
    }

    LL ans = 0;

    for(int i=0;i<=min(n-1, k);i++){
        ans = ans + C(n, i) * C(n-1, i) % P;
        ans %= P;
    }

    cout <<ans;
}


Measured memory_bytes: 1792
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt()
	K := readInt()
	Q := readInt()

	A := make([]int, N)
	for i := 0; i < Q; i++ {
		a := readInt() - 1
		A[a]++
	}

	for i := range A {
		if 0 < K+A[i]-Q {
			println("Yes")
		} else {
			println("No")
		}
	}
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 3968
N=int(input())
S=input()
R=[]
G=[]
B=[]
for i in range(0,N):
    if S[i]=='R':
        R.append(i)
    elif S[i]=='G':
        G.append(i)
    else:
        B.append(i)

ans=len(R)*len(G)*len(B)
for i in range(0,len(R)):
    for j in range(0,len(G)):
        r=R[i]
        g=G[j]
        if N>2*g-r>=0:
            if S[2*g-r]=='B':
                ans-=1

        if N>2*r-g>=0:
            if S[2*r-g]=='B':
                ans-=1

        if (r+g)%2==0 and N>(r+g)//2>=0:
            if S[(r+g)//2]=='B':
                ans-=1

print(ans)

Measured memory_bytes: 74976
/* Author : tushar3105 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef pair<long long int,long long int> ii;					// Pair of integers
typedef vector<long long int> vi;                   				// Vector of integers
typedef vector<vector<long long int>> vvi;                 			// Vector of vi
typedef vector<pair<long long int, long long int>> vii;				// Vector of ii

#define pb push_back								// Push back to vectors
#define mp make_pair								// For pairs
#define ff first								// For pairs
#define ss second								// For pairs
#define all(c) (c).begin(),(c).end()						// Use in sorting
#define sz(a) ((long long int)(a).size())
#define lli long long int
#define ull unsigned long long int
#define ld long double
#define ref(i,x,y) for(long long int i=(x);i<=(y);++i)				// Loop to go forward
#define reb(i,x,y) for(long long int i=(x);i>=(y);--i)				// Loop to go backward
#define trf(c,it) for(auto it = (c).begin(); it != (c).end(); it++)		// Remember it is an iterator
#define trb(c,it) for(auto it = (c).end()-1; it != (c).begin()-1; it--)		// Remember it is an iterator
#define tc(t) long long int t; cin>>t;while(t--)				// Test cases
//fill (dist,dist+110000,pinf);							// For setting default

const long long int mod = 1e9+7;
const long long int pinf = 9223372036854775807;
const long long int ninf = -9223372036854775807;

/*-----------------------------Code begins----------------------------------*/

int main (void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	lli n, d, cnt=0, x, y;
	
	cin>>n>>d;
	
	ref(i,0,n-1)
	{
		cin>>x>>y;
		
		if (sqrt(x*x+y*y)<=d)
			cnt++;
	}
	
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
//const lli mod = 1000000007;

lli p2(lli n){lli ans=0;while(n>=1){n=n/2;ans++;}return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
//lli add(lli a,lli b){return(a+b)%mod;}
//lli mul(lli a,lli b){return (a*b)%mod;}
//lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///
void solve()
{
    int n;cin>>n;
    vi rs,ws;
    string a ;cin>>a;
    lli c=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='R')rs.pb(i);
        else ws.pb(i);
    }
    int wind=0,rind=rs.size()-1;
    while(wind<ws.size() and rind>=0 and ws[wind]<rs[rind])
    {
        wind++,rind--,c++;
    }
    cout<<c<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 4728
import math
import bisect
def prime(n):
    max=int(math.sqrt(n))
    li=[i for i in range(2,n+1)]
    primes=[]
    while li[0]<=max:
        primes.append(li[0])
        tmp=li[0]
        li=[i for i in li if i%tmp!=0]
    primes.extend(li)
    return primes

Q=int(input())
l=[]
r=[]
up=0
for i in range(Q):
    a,b=map(int,input().split())
    up=max([up,a,b])
    l.append(a)
    r.append(b)

s=prime(up)
like=[]

for i in range(len(s)):
    if((s[i]+1)/2==s[bisect.bisect_left(s,(s[i]+1)/2)]):
        like.append(s[i])
        
sumli=[0]*100001
tmp=0
for i in range(2,100001):
    if(i==like[tmp]):
        sumli[i]=sumli[i-1]+1
        if(tmp<(len(like)-1)):
            tmp+=1
    else:
        sumli[i]=sumli[i-1]

for i in range(Q):
    print(sumli[r[i]]-sumli[l[i]-1])

Measured memory_bytes: 15920
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	string s; cin>>s;
	if(s.substr(0,n/2)==s.substr(n/2,n/2) && s.size()%2==0)cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
string a;
int c[4];
int main ()
{
    cin>> n;
    for(int i=1; i<=n; i++){
        cin>> a;
        if(a[0]=='A')c[1]++;
        else if(a[0]=='W')c[2]++;
        else if(a[0]=='T')c[3]++;
        else c[4]++;
    }
    cout<<"AC x "<< c[1]<<endl;
    cout<<"WA x "<< c[2]<<endl;
    cout<<"TLE x "<< c[3]<<endl;
    cout<<"RE x "<< c[4]<<endl;
    return 0;
}


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

int main(){
  char b, ans;
  cin >> b;
  switch (b)
  {
    case 'A':
      ans = 'T';
      break;
    case 'T':
      ans = 'A';
      break;
    case 'G':
      ans = 'C';
      break;
    case 'C':
      ans = 'G';
      break;
    default:
      break;
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;
using ll = long long;
const ll mod = 1000000007;


int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a % 3 && b % 3 && (a + b)% 3 ? "Impossible" : "Possible") << endl;
}

Measured memory_bytes: 256
class BIT1():
    """
    Binary Indexed Tree (1-indexed)
    """
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (self.n + 1)
        self.data = [0] * (self.n + 1)

    def add(self, idx, x):
        # add x to idx-th element
        # idx: 1-indexed
        self.data[idx] += x
        while idx <= self.n:
            self.bit[idx] += x
            idx += (idx & (-idx))

    def sum(self, idx):
        # get sum of [1, idx]
        # idx: 1-indexed
        s = 0
        while idx:
            s += self.bit[idx]
            idx -= (idx & (-idx))
        return s


n = int(input())
s = [ord(si) - ord('a') for si in list(input())]
bit_list = [BIT1(n + 1) for _ in range(26)]
for i in range(n):
    bit_list[s[i]].add(i + 1, +1)

q = int(input())
for _ in range(q):
    k, a, b = input().split()
    k = int(k)
    a = int(a)
    if k == 1:
        b = ord(b) - ord('a')
        # type1: update
        bit_list[s[a - 1]].add(a, -1)
        bit_list[b].add(a, +1)
        s[a - 1] = b
    else:
        # type2: calc
        b = int(b)
        a -= 1
        cnt = 0
        for bit_i in bit_list:
            if bit_i.sum(b) - bit_i.sum(a) > 0:
                cnt += 1
        print(cnt)


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

int main(void){
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  int l=a+b;
  int r=c+d;
  if(l>r) cout<<"Left"<<endl;
  else if(l==r) cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  cout << (a+b+1)/2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<cmath>
#include<cstring>
using namespace std;
struct E{int to,next;long double cost;}g[5000005];
int xs,xt,ys,yt,x,y,r,n,h[2005],num,ringx[2005],ringy[2005],ringr[2005];
long double dis[2005],md;
bool vis[2005];
void ins(int u,int v,long double c){g[++num].to=v,g[num].next=h[u],g[num].cost=c,h[u]=num;}
long double dist(int a,int b){return sqrt(1ll*(ringx[a]-ringx[b])*(ringx[a]-ringx[b])+1ll*(ringy[a]-ringy[b])*(ringy[a]-ringy[b]))-ringr[a]-ringr[b];}
int main(){
	scanf("%d%d%d%d",&xs,&ys,&xt,&yt);
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d%d%d",&ringx[i],&ringy[i],&ringr[i]);
	ringx[n+1]=xs,ringy[n+1]=ys,ringx[n+2]=xt,ringy[n+2]=yt;
	for(int i=1;i<=n+2;++i)
		for(int j=i+1;j<=n+2;++j){
			long double d=dist(i,j);
			if(d<0) d=0;
			ins(i,j,d); ins(j,i,d);
		}
	for(int i=1;i<=n+2;++i) dis[i]=1e10;
    dis[n+1]=0;
    for(int i=1;i<=n+1;++i){
    	int u;md=1e10;
		for(int j=1;j<=n+2;++j)
			if(!vis[j]&&dis[j]<md)
				u=j,md=dis[j];
		vis[u]=1;
        if(u==n+2) break;
        for(int j=h[u];j;j=g[j].next){
            int v=g[j].to; long double c=g[j].cost;
            if(dis[v]>dis[u]+c) dis[v]=dis[u]+c;
        }
    }
    printf("%.15lf\n",(double)dis[n+2]);
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n[12], a;
  for(int i = 0; i < 3; scanf("%d", &a), n[a]++, i++);
  printf("%s\n", (n[5] == 2 && n[7] == 1) ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>

using namespace std;
struct point{
    double x;
    double y;
};
void koch(int d, point p1, point p2){
    if(d==0) return;
    point s,u,t;
    double theta=60*M_PI/180;
    s.x=(2*p1.x+p2.x)/3;s.y=(2*p1.y+p2.y)/3;
    t.x=(p1.x+2*p2.x)/3;t.y=(p1.y+2*p2.y)/3;
    u.x=(t.x-s.x)*cos(theta) - (t.y-s.y)*sin(theta)+s.x;
    u.y=(t.x-s.x)*sin(theta) + (t.y-s.y)*cos(theta)+s.y;
    koch(d-1,p1,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(d-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(d-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(d-1,t,p2);


}

int main()
{
    int d;
    scanf("%d",&d);

    point start,end;
    start.x=0; start.y=0;
    end.x=100; end.y=0;
    printf("%.8f %.8f\n",start.x,start.y);
    koch(d,start,end);
    printf("%.8f %.8f\n",end.x,end.y);


    return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 H,W,N;
    cin >> H >> W >> N;

    map<i64,set<i64>> xy,yx;
    rep(i,0,N){
        i64 X,Y;
        cin >> X >> Y;
        xy[X].insert(Y);
        yx[Y].insert(X);
    }

    if(xy[2].find(1)!=xy[2].end()){
        cout << 1 << endl;
        return;
    }

    i64 y=1,ans=H;
    rep(x,2,H+1){
        {
            auto it = yx[y].upper_bound(x);
            if (it != yx[y].end()) {
                ans = min(ans, *it - 1);
            }
        }
        {
            auto it=xy[x].upper_bound(y);
            if(it==xy[x].end() or *it>y+1){
                ++y;
            }
            if(xy[x+1].find(y)!=xy[x+1].end()) {
                ans = min(ans, x);
                break;
            }
        }
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 54400
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m,r;
    cin>>n>>m>>r;
    vector <int> v;
    for(int i=0;i<r;i++){
        int a;
        cin>>a;
        v.push_back(a-1);
    }
    int dp[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dp[i][j]=0;
            else dp[i][j]=1<<29;
        }
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        dp[a-1][b-1]=c;
        dp[b-1][a-1]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(dp[i][j]>dp[i][k]+dp[k][j]){
                    dp[i][j]=dp[i][k]+dp[k][j];
                }
            }
        }
    }
    int ans=1<<30;
    sort(v.begin(),v.end());
    do{
        int p=0;
        for(int i=0;i<r-1;i++)p+=dp[v[i]][v[i+1]];
        ans=min(ans,p);
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int c = 1;
    for (int i = 0; i < n; i++) {
        c = std::min(c * 2, c + k);
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, x;
  char c;
  cin >> A >> c >> B;
  if (c == '+') {
    x = A + B;
  }
  else {
    x = A - B;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
//rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
//if(y==0) return x;
//return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  while(true){
    int n,m; cin >> n >> m;
    if(n==0 && m==0) break;
    vector<int> s(n+m);
    rep(i,n+m) cin >> s[i];
    int a=0,b=0;
    rep(i,n) a+=s[i];
    for(int i=n; i<n+m; i++) b+=s[i];
    int t=0;
    rep(i,n){
      if(t==1) break;
      for(int j=n; j<n+m; j++){
        int c=a-s[i]+s[j];
        int d=b-s[j]+s[i];
        if(c==d){
          cout << s[i] << " " << s[j] << endl;
          t=1; break;
        }
      }
    }
    if(t==0) cout << -1 << endl;
  }
}



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

int main(void) {
  char c;
  cin >> c;

  cout << char(c + 1) << endl;

  return 0;
}

Measured memory_bytes: 256
class UnionFind:
	"""
	class UnionFind
	https://note.nkmk.me/python-union-find/
	
	order O(log(n))
	
	n = the number of elements
	parents = the list that contains "parents" of x. be careful that it doesn't contain "root" of x.
	"""
	def __init__(self, n):
		"""
		make UnionFind
		:param n: the number of elements
		"""
		self.n = n
		self.parents = [-1] * n
	
	def find(self, x):
		"""
		:param x: an element
		:return: the root containing x
		"""
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		"""
		:param x, y: an element
		"""
		# root
		x = self.find(x)
		y = self.find(y)
		if x == y:
			# already same group so do nothing
			return
		if self.parents[x] > self.parents[y]:
			# the root should be min of group
			x, y = y, x
		# remind that x, y is the root, x < y, then, y unions to x.
		self.parents[x] += self.parents[y]
		# and then y's parent is x.
		self.parents[y] = x
	def size(self, x):
		# return the size of group
		return -self.parents[self.find(x)]
	
	def same(self, x, y):
		# return whether the x, y are in same group
		return self.find(x) == self.find(y)
	
	def members(self, x):
		# return members of group
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]
	
	def roots(self):
		# return all roots
		return [i for i, x in enumerate(self.parents) if x < 0]
	
	def group_count(self):
		# return how many groups
		return len(self.roots())
	
	def all_group_members(self):
		# return all members of all groups
		return {r: self.members(r) for r in self.roots()}

n, m = map(int,input().split())
p = list(map(int,input().split()))
union = UnionFind(n)
ans = 0

for i in range(m):
	x, y = map(int,input().split())
	union.union(x-1, y-1)

for cnt, j in enumerate(p):
	if union.same(cnt, j-1):
		ans += 1

print(ans)

Measured memory_bytes: 20656
#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 999999999
#define llong long long

using namespace std;

int main(){
	
	int a,b;
	cin>>a>>b;
	int max1=a+(a-1);
	int max2=b+(b-1);
	int max3=a+b;
	if(2*a-1>a+b){
		cout<<2*a-1<<endl;
	}else if(2*b-1>a+b){
		cout<<2*b-1<<endl;
	}else{
		cout<<a+b<<endl;
	}
	return 0;

}


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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<int> h(n+1), w(m+1);
        for (int i = 1; i <= n; ++i){
            int h_;
            cin >> h_;
            h[i] = h[i-1] + h_;
        }
        for (int i = 1; i <= m; ++i){
            int w_;
            cin >> w_;
            w[i] = w[i-1] + w_;
        }
        vector<int> hh(1510*1010), ww(1510*1010);
        for(int i = 0; i <= n; ++i){
            for(int j = i+1; j <= n; ++j){
                hh[h[j]-h[i]]++;
            }
        }
        for(int i = 0; i <= m; ++i){
            for(int j = i+1; j <= m; ++j){
                ww[w[j]-w[i]]++;
            }
        }
        int ans = 0;
        for(int i = 0; i < 1510 * 1010; ++i){
            ans += hh[i] * ww[i];
        }
        cout << ans << endl;
    }

}



Measured memory_bytes: 14780
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int a,count=0;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (a%2==0) {
            while (a%2!=1) {
                a/=2;
                count++;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def main():
    n = int(input())

    sum_count = 0
    for i in range(1,n+1):
        tmp_list = []
        tmp_list.append(i)
        for j in range(1,n+1):
            tmp_list.append(j)
            for k in range(1,n+1):
                tmp_list.append(k)              
                sum_count += gcd_list(tmp_list)
                tmp_list.pop(2)
            tmp_list.pop(1)

    print(sum_count)        

if __name__ == '__main__':
    main()

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
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; }
const ll inf = 1ll << 60;


int main() {
    int l, r;
    scanf("%d%d", &l, &r);
    if (r - l >= 2019) {
        printf("%d", 0);
        return 0;
    }
    l %= 2019;
    r %= 2019;
    if (l >= r) printf("%d", 0);
    else if (l == 0) printf("%d", 0);
    else {
        int res = 2019;
        rp(i, l, r) {
            rp(j, 1, r-i+1) {
                chmin(res, (i * (i + j)) % 2019);
            }
        }
        printf("%d", res);
    }
    return 0;
} 

Measured memory_bytes: 256
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

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

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


int main(){
    
    string S,T; cin>>S>>T;
    int n = S.length();

    vector<int> s(27, -1);
    vector<int> t(27, -1);

    bool ans=true;

    for(int i=0; i<n;i++){
        int s_char = (int)S[i]-(int)'a';
        int t_char = (int)T[i]-(int)'a';

        if(s[s_char] == -1){
            s[s_char] = t_char;
        } else if (s[s_char] != t_char){
            ans = false;
            break;
        }

        if(t[t_char] == -1){
            t[t_char] = s_char;
        } else if (t[t_char] != s_char){
            ans = false;
            break;
        }    
        
    }

    if(ans) cout << "Yes" <<endl;
    else cout << "No" <<endl;


    return 0;

}


Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main() {
	int n,k;cin>>n>>k;
	vector<int>v(n);
	for(int i=0;i<n;i++)cin>>v[i];

	int best_ans = 0;
	for (int c = 0; c <= k; c++)
	{
		
		for (int l = 0; l <= min(c, n); l++)
		{
			vector<int>hold;

			int r = min(c-l, n-l);
			
			for (int i = 0; i < l; i++)
			{
				hold.push_back(v[i]);
			}
			for (int i = 0; i < r; i++)
			{
				hold.push_back(v[n-i-1]);
			}

			sort(hold.begin(), hold.end());
			reverse(hold.begin(), hold.end());

			int e = k - c;
			int cnt = 0;
			for (int i = (int)hold.size() - 1; i >= 0; i--)
			{
				if (hold[i] >= 0)break;
				if (cnt >= e)break;

				hold.pop_back();
				cnt++;
			}

			int ans = 0;
			for (int i = 0; i < hold.size(); i++)
			{

				ans += hold[i];
			}
			best_ans = max(ans, best_ans);
		}

	}

	cout<<best_ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int n;
cin >> n;
vl a(n),b(n);
rep(i,n) cin >> a[i] >> b[i];

vl dist(n);
ll t = 0;
rep(i,n) {
    t += a[i];
    dist[i] = a[i] + b[i];
}
sort(dist.rbegin(), dist.rend());
rep(i,n) {
    if(i % 2) t -= dist[i];
}

cout << t << endl;
return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define FASTIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N = 200005, M = 1000000007, BIG = 0x3f3f3f3f;

int ct = 0;
int n;
int a[N];

bool Read() {
  cin >> n;
  if (cin.eof())
    return 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  return 1;
}

ll Result(int x) {
  ll ans = 0;
  for (int i = 0; i < n; i++)
    ans += ((ll)x - (ll)a[i]) * ((ll)x - (ll)a[i]);
  return ans;
}

void Process() {
  ll ans = 0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i < 101; i++) 
    ans = min(ans, Result(i));
  cout << ans << "\n";
}

int main() {
  FASTIO();

  while (Read())
    Process();

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n, h;
    cin>>n>>h;
    vector<ll> vct(n);
    ll cc = 0;
    for(int i=0;i<n;i++){
        cin>>vct[i];
        if(vct[i] >= h)
            cc++;
    }
    cout<<cc<<endl;
    return 0;
}


Measured memory_bytes: 1024