akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<vector<char>, int>::iterator;

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

	vector<long> vA(N);
	for (int i = 0; i != N; ++i) {
		long a = 0;
		cin >> a;
		vA[i] = a;
	}

	vector<long> vB(N);
	int sign_c = 1;
	for (int i = 0; i != N; ++i) {
		vB[0] += vA[i] * sign_c;
		sign_c *= -1;
	}

	for (int i = 1; i != N; ++i) {
		vB[i] = 2 * vA[i - 1] - vB[i - 1];
	}

	for (int i = 0; i != N; ++i) {
		cout << vB[i] << " ";
	}

	cout << endl;
	
	return 0;
}

Measured memory_bytes: 2944
def g(n):
    D = [[0]*10 for i in range(10)]
    for i in range(1,n+1):
        si = str(i)
        D[int(si[0])][int(si[-1])] += 1

    res = 0
    for i in range(10):
        for j in range(10):
            res += D[i][j]*D[j][i]
    return res
print(g(int(input())))


Measured memory_bytes: 3060
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)


int main()
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  list<int> data;
  list<int>::iterator it;
  int n;
  cin >>n;
  int x;
  string str;
  for(int i = 0;i < n;i++){
    cin >>str;
    if(str =="insert"){
      cin >>x;
      data.push_front(x);
    }else if(str =="delete"){
      cin >>x;
      for(it =data.begin();it !=data.end();it++){
	if(*it ==x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str =="deleteFirst")
      data.pop_front();
    else
      data.pop_back();
  }
  it =data.begin();
  while(it !=data.end()){
    cout<<*it;
    it++;
    (it ==data.end())?cout<<endl:cout<<" ";
  }
  return 0;
}

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

typedef long long ll;

int f(ll x){
  int ret = 0;
  while(x){
    x/=10; ret++;
  }
  return ret;
}

int main(){
  ll n;
  cin>>n;
  int ans = 252521;
  for(ll x=1;x*x<=n;x++){
    if(n%x!=0)continue;
    ll y = n/x;
    ans = min(ans, max(f(x), f(y)));
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

char s[100010];
char q[200010];
bool r[200010];

int main()
{
    scanf("%s",s);
    int num;scanf("%d",&num);
    int rev=0;int len=0;
    for (int i=0;i<num;++i){
        int tmp;scanf("%d",&tmp);
        if (tmp==1){
            rev=1-rev;
            continue;
        }
        int tmp2;scanf("%d",&tmp2);
        --tmp2;
        if (tmp2!=rev) r[len]=1;
        else r[len]=0;
        char ch=getchar();while (ch==' ') ch=getchar();
        q[len]=ch;
        len++;
    }
    for (int i=len-1;i>=0;--i)
    if (r[i]==rev) printf("%c",q[i]);
    if (rev==0) printf("%s",s);
    else{
        int ll=0;while (s[ll])ll++;
        for (int i=ll-1;i>=0;--i)
            printf("%c",s[i]);
    }
    for (int i=0;i<len;++i)
    if (r[i]!=rev) printf("%c",q[i]);

}


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

void printArray(int A[], int N){
    
    for(int i=0; i<N; i++){
        cout << A[i];
        if(i<N-1) cout << " ";
    }
    
    cout << endl;
    
}

void insertionSort(int A[], int N){
    
    printArray(A, N);
    
    for(int i=1; i<N; i++){
        int v = A[i];
        int j = i - 1;
        while( j>=0 && A[j]>v ){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printArray(A, N);
        //if(i<N-1) cout << endl;
    }
    
}

int main() {
    
    int N;
    cin >> N;
    
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    insertionSort(A, N);
    
    return 0;
    
}



Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		double[] A = new double[N];
		string[] str = Console.ReadLine().Split();
		for(int i=0;i<N;i++){
			A[i] = double.Parse(str[i]);
		}
		double a = 0;
		for(int i=0;i<N;i++){
			double b = 1;
          	b /= A[i];
          	a += b;
		}
		double ans = 1/a;
		Console.WriteLine(ans);
	}
}

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

int main() {
    string s;
    cin >> s;
    string ans;
    rep(i,s.size()) {
        if(i%2==0) ans.push_back(s[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std ;
int main()
{
   int n ; 
   cin>>n;
   int arr[101];
   int sum = 0 ;
   for( int i=0 ; i<n ; i++)
   {
       cin>>arr[i];
       sum+=arr[i];
   }
   sort( arr, arr+n);
  // cout<<sum;
   if(sum - arr[n-1]<= arr[n-1] )
   {
       cout<<"No"<<endl;
   }
   else 
   cout<<"Yes"<<endl;
   


return 0;
}


Measured memory_bytes: 256
a=int(input())
s=0
d=1
si=[]
while a>0:
    b=a%26
    si.append(b)
    a=a//26
    if b==0:
      a-=1
    
    
 
c=""
for i in si:
  if i==0:
    i=26
  c+=chr(i+96)
c=c[::-1]
print(c)

Measured memory_bytes: 61784
#include <bits/stdc++.h>
using namespace std;
char seq[8001];
int orderx[8001], ordery[8001];
int orderx_index = 0, ordery_index = 0, sumx = 0, sumy = 0;
bool mycmp(const int& a, const int& b)
{
	return a>b;
}
int main()
{
	char c;
	int countt, x, y, i, countf;
	countt = 0;
	countf = 0;
	while (c = getchar(), c == 'T' || c == 'F')
	{
		if (c == 'F')
		{
			countf++;
		}
		else if (c == 'T')
		{
			if (countt % 2 == 0)
				orderx[orderx_index++] = countf;
			else
				ordery[ordery_index++] = countf;
			countt++;
			countf = 0;
		}
	}
	if (countt % 2 == 0)
		orderx[orderx_index++] = countf;
	else
		ordery[ordery_index++] = countf;
	scanf("%d%d", &x, &y);
	sort(orderx + 1, orderx + orderx_index, mycmp);
	sort(ordery, ordery + ordery_index, mycmp);
	sumx += orderx[0];
	for (i = 1; i<orderx_index; i++)
	{
		if (sumx <= x)
			sumx += orderx[i];
		else
			sumx -= orderx[i];
	}
	for (i = 0; i<ordery_index; i++)
	{
		if (sumy <= y)
			sumy += ordery[i];
		else
			sumy -= ordery[i];
	}
	if (sumx == x&&sumy == y)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2120
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
g=gcd(C,D)
d=(C//g)*(D//g)*(g)
ansA=A-(A//C+A//D-A//d)
ansB=B-(B//C+B//D-B//d)
print(ansB-ansA)


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


int main(){
 int n,m,b=0,a=0;
  cin >> n >> m;
  rep(i,m){
    cin >> a;
    b += a;
  }
  if(n>=b) cout << n-b << endl;
  else cout << -1 << endl;
}

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

int main(){
    int N;
    cin>>N;
    int d[8]={0};
    int count=0;
    
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(a>=3200)count++;
        else{
            d[a/400]++;
        }
    }
    
    int ans=0;
    for(int i=0;i<8;i++){
        if(d[i]>0)ans++;
    }
    
    
    cout<<((count!=N)?ans:1)<<" "<<ans+count<<endl;
}

Measured memory_bytes: 764
#include <iostream>

int 
main (int argc,char *argv[])
{
    int a,b,c;
    int x,y,z;
    int tmp;

    std::cin >> a >> b >> c;

    tmp = b;
    b = a;
    a = tmp;

    tmp = a;
    a = c;
    c = tmp;

    std::cout << a <<" " << b <<" "<< c;

    return 0;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,LEN_BASE;
char BASE[100];
char TMP[100];

bool is_num(char ch){

	return ch >= '0' && ch <= '9';
}

int main(){

	scanf("%d",&N);

	scanf("%s",BASE);
	for(LEN_BASE = 0; BASE[LEN_BASE] != '\0'; LEN_BASE++);

	int tmp_length;
	int base_index,tmp_index;
	ll num_base,num_tmp;
	bool FLG;

	for(int i = 0; i < N; i++){

		scanf("%s",TMP);
		for(tmp_length = 0; TMP[tmp_length] != '\0'; tmp_length++);

		FLG = false;

		for(int k = 0; k < min(tmp_length,LEN_BASE); k++){

			if(is_num(BASE[k]) && is_num(TMP[k])){

				num_base = 0;
				for(base_index = k;base_index < LEN_BASE && is_num(BASE[base_index]) == true; base_index++){

					num_base = 10*num_base+BASE[base_index]-'0';
				}

				num_tmp = 0;
				for(tmp_index = k;tmp_index < tmp_length && is_num(TMP[tmp_index]) == true; tmp_index++){

					num_tmp = 10*num_tmp+TMP[tmp_index]-'0';
				}

				if(num_base < num_tmp){

					printf("+\n");
					FLG = true;
					break;

				}else if(num_base > num_tmp){

					printf("-\n");
					FLG = true;
					break;
				}


			}else if(BASE[k] != TMP[k]){

				if(BASE[k] < TMP[k]){

					printf("+\n");
				}else{

					printf("-\n");
				}
				FLG = true;
				break;
			}
		}

		if(FLG)continue;

		if(LEN_BASE <= tmp_length){

			printf("+\n");

		}else{

			printf("-\n");
		}
	}

	return 0;
}



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

int main () {
  int N;
  cin >> N;
  int a[N];
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    while (a[i] % 2 == 0) {
     a[i] /= 2; sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


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

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q; cin >> n >> q;
	set<pair<int, int>> se[2];
	se[0].insert({n, n});
	se[1].insert({n, n});
	while (q--) {
		int ty, i; cin >> ty >> i;
		ty--;
		auto it = se[ty].lower_bound({i, -1});
		int k = (*it).second;
		se[ty ^ 1].insert({(k - 1), i});
	}
	long long ans = 1LL * (n - 2) * (n - 2);
	for (int i = 0; i < 2; i++) {
		for (auto x: se[i]) {
			if (x.second != n) ans -= x.first - 1;
		}
	}	
	cout << ans << '\n';
    return 0;
}

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

int main()
{
  string S;
  cin >> S;
  
  vector<char> red_and_white(S.length());
  
  for(int i = 0; i < S.length(); ++i)
  {
    red_and_white.at(i) = S[i];
  }
  
  int delta = count(red_and_white.begin(), red_and_white.end(), '0') - count(red_and_white.begin(), red_and_white.end(), '1'); 
  cout << red_and_white.size() - abs(delta) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL<<60;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  cout << setprecision(15) << std::fixed;
  int n;
  cin>>n;
  double p[n];
  double dp[3300][3300];
  for(int i=0;i<n;i++) cin>>p[i];
  dp[0][0]=1.0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      dp[i+1][j+1]+=dp[i][j]*p[i];
      dp[i+1][j]+=dp[i][j]*(1-p[i]);
    }
  }
  double ans=0.0;
  for(int j=(n+1)/2;j<=n;j++){
    ans+=dp[n][j];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int d[2005];
int main()
{
	
	int mod=1e9+7;
		d[0]=1;
		int s;cin>>s;
		for(int i=1;i<=s;i++)
		{
			for(int j=0;j<=i-3;j++)
			{
				d[i]=(d[i]+d[j])%mod;	
			}
		}
	cout<<d[s];
	
}

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

int main() {
    int n;
    cin >> n;    
    double ans = 0.0;

    for (int i = 0; i < n; i++) {
    	int x; cin >> x;
    	ans += 1.0 / x;
    }

    cout << fixed << setprecision(12) << 1.0 / ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
    char s[101]={};
    int N=0;
    int flag=0;
    int ha=0;
    scanf("%d",&N);
    scanf("%s",s);
    ha=N/2;
    if(ha*2!=N){
        flag=1;
    }
    for(int i=0;i<ha;i++){
        if(s[i]!=s[i+ha]){
            flag=1;
        }
    }
    if(flag==0){
printf("Yes\n");
    }else{
printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Majority of Balls
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 99;
const int MAX_N2 = MAX_N * 2;

const char crs[] = { 'R', 'B' };

/* typedef */

/* global variables */

int cs[MAX_N2];

/* subroutines */

int query(int n, int k, int t = -1) {
  int n2 = n * 2;
  putchar('?');
  if (t < 0)
    for (int i = 0; i < n; i++) printf(" %d", (k + i) % n2 + 1);
  else {
    printf(" %d", t + 1);
    for (int i = 0; i < n - 1; i++) printf(" %d", (k + i) % n2 + 1);
  }
  putchar('\n');
  fflush(stdout);

  char s[8];
  scanf("%s", s);
  if (s[0] == 'R') return 0;
  if (s[0] == 'B') return 1;
  return -1;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int n2 = n * 2;

  int b0 = query(n, 0);
  int a0 = 0, a1 = n;
  while (a0 + 1 < a1) {
    int a = (a0 + a1) / 2;
    if (query(n, a) == b0) a0 = a;
    else a1 = a;
  }
  //printf("%d %d\n", a0, a1); fflush(stdout);

  memset(cs, -1, sizeof(cs));
  cs[a0] = b0, cs[a0 + n] = b0 ^ 1;
  int k0 = a0 + 1, k1 = (a0 + n + 1) % n2;

  for (int i = 0; i < n - 1; i++) {
    int k = (k0 + i) % n2;
    cs[k] = query(n, k1, k);
  }
  for (int i = 0; i < n - 1; i++) {
    int k = (k1 + i) % n2;
    cs[k] = query(n, k0, k);
  }

  putchar('!'); putchar(' ');
  for (int i = 0; i < n2; i++) putchar(crs[cs[i]]);
  putchar('\n'); fflush(stdout);
  return 0;
}


Measured memory_bytes: 724
package main

import "fmt"

func main() {
	var K, x int
	fmt.Scan(&K)
	q := make([]int, 0)
	for i := 1; i < 10; i++ {
		q = append(q, i)
	}
	for i := 0; i < K-1; i++ {
		x = q[0]
		q = q[1:]
		for j := -1; j <= 1; j++ {
			a := (x % 10) + j
			if a >= 0 && a <= 9 {
				q = append(q, x*10+a)
			}
		}
	}
	fmt.Println(q[0])

}


Measured memory_bytes: 6400
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
  string S;
  cin >> S;
  
  bool ok = true;
  int count = 0;
  rep(i,S.length()){
    bool chk = true;
    if(i == 0){
      if(S[i] == 'A')chk = false;
      else ok = false;
    }
    if( 1 < i && i < S.length() - 1 ){
      if(S[i] == 'C'){
        chk = false;
      	++count;
      }
    }
    if(chk){
      if( S[i] <97) ok = false;
    }
  }
  if ( count != 1) ok = false;
  if(ok) cout << "AC" <<endl;
  else cout << "WA" <<endl;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().strip().split())
list = []
list1 = []
a = input().split()
for i in range(0, len(a)):
    list1.append(int(a[i]))
sum = sum(list1)
if (n-sum)>=0:
    print(n-sum)
else:
    print('-1')

Measured memory_bytes: 10192
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f[100009];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a;
	for(b=1; b<=a; b++){
		cin>>f[b];
	}
	f[1]--;
	for(b=2; b<=a; b++){
		if(f[b]>f[b-1]) f[b]--;
		if(f[b]<f[b-1]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	string s; cin >> s;
	bool ok = true;
	FOR (i,1,4) {
		if (s[i] == s[i-1]) {
			ok = false;
		}
	}
	if (ok) cout << "Good" << endl;
	else cout << "Bad" << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

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

using namespace std;

int N, K;

map<int, int> a;

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

    for (int i = 0; i < N; ++i) {
        int ai;
        cin >> ai;
        if (a.find(ai) != a.end()) {
            a[ai]++;
        } else {
            a[ai] = 1;
        }
    }

    vector<int> v;

    for (auto itr = a.begin(); itr != a.end(); ++itr) {
        v.push_back((*itr).second);
    }

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

    int ans = 0;
    for (int i = 0; i < (int)v.size() - K; ++i) {
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 10744
#include <iostream>
using namespace std;
main () {
	int n, x;
	while (cin >> n >> x, n) {
		int a = 0;
		for (int i=1; i<=n-2; i++)
			for (int j=i+1; j<=n-1; j++)
				for (int k=j+1; k<=n; k++)
					if (i+j+k == x) a++;
		cout << a << endl;
	}
}

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

int main (int argc, char const* argv[])
{
    int n,count = 0;
    vector<int> N;
    cin >> n;
    for (int i = 0; i < n; i += 1)
    {
        int j;
        cin >> j;
        N.push_back(j);
    }
    
    for (int i = 0; i < N.size(); i += 1)
    {
        int mini = i;
        bool flag = false;
        for (int j = i; j < N.size(); j += 1)
        {
            if(N[j] < N[mini]){
                mini = j;
                flag = true;
            }
        }
        
        if(flag){
            int tmp = N[i];
            N[i] = N[mini];
            N[mini] = tmp;
            ++count;
        }
    }
    
    for (int i = 0; i < N.size(); i += 1)
    {
        cout << N[i];
        if(i != N.size()-1)
            cout << " ";
    }
    cout << endl;
    cout << count << endl;
    
    return 0;
}

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VS s(n);
    REP(i,n){
        cin >> s[i];
    }

    VVI a(n,VI(26,0));
    REP(i,n){
        REP(j,s[i].length()){
            a[i][s[i][j]-'a']++;
        }
    }

    REP(i,26){
        int t = INT_MAX;
        REP(j,n){
            t=min(t,a[j][i]);
        }
        REP(j,t){
            printf("%c",'a'+i);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String a = sc.next();
    if (Character.isLowerCase(a.charAt(0))) {
      System.out.println("a");
    } else {
      System.out.println("A");
    }
  }
}

Measured memory_bytes: 32668
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias SugarWater = Tuple!(long, "swater", long, "sugar");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    auto p = aryread();
    auto q = p.dup;
    q.sort();
    long count;
    foreach (i; iota(0, p.length))
        if (p[i] != q[i])
            count++;

    if (count <= 2)
        writeln("YES");
    else
        writeln("NO");
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        double res = 0;
        
        sc.nextLine();
        
        for(int i = 0; i < n; i++){
            String s = sc.nextLine();
            
            String[] split = s.split(" ");
            
            if(split[1].equals("JPY")){
                res+=Double.parseDouble(split[0]);
            }else{
                res+=Double.parseDouble(split[0]) * 380000;
            }
        }
        
        System.out.println(new BigDecimal(res).toPlainString());
    }
}


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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



int main(){
	ll n;
	ll a;
	cin >> n >> a;
	ll x[n];
	FOR(i,n)cin >>x[i];
	ll array[n][n*a+1][n+1];
	//FOR(i,20) cout <<i%10 <<" ";
	//cout <<"\n";
	FOR(i,n)
		FOR(j,n*a+1)
			FOR(w,n+1)
				array[i][j][w]=0;
	FOR(i,n) 
		FOR(t,a+1)
			array[i][t][0]=(t==0) ? 1:0 ;
	//cout << array[1][0][0];
	FOR(i,n)
		FOR(t,n*a+1)
			for(int k=1; k < n+1;k++)
				{
					if(i!=0){
						if(t >=x[i]) 
							array[i][t][k]=array[i-1][t-x[i]][k-1] + array[i-1][t][k];
						else
							array[i][t][k]=array[i-1][t][k];
					}
					else{ 
						//if(k==0) array[i][t][k]=(t==0)? 1: 0;
						if(k==1) array[i][t][k]=(t==x[0])?1:0;
						else array[i][t][k]=0;
					}				
				}
	ll count=0;

	for(int k=1; k<n+1;k++){
		count+=array[n-1][k*a][k];
		//cout << k<<" : "<<array[n-1][k*a][k]<<"\n";
	}
	cout <<count;

	return 0;
}

Measured memory_bytes: 50048
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

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

    int n, k;
    cin >> n >> k;
    double ans;
    for(int i = 1; i <= n; ++i){
        int x = i;
        double t = 1.0;
        while(x < k){
            t /= 2;
            x = x << 1;
        }

        ans += (t/n);
    }

    cout << setprecision(10) << ans << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<cstring>
#include<stack>

using namespace std;

int main(){
  int max_c = 0;
  map<string, int> cnt;
  stack<string> words;
  string word, freq, max_l;
  
  while(cin >> word) {
    if(word.length() > max_l.length()) max_l = word;
    if(cnt[word] == 0) words.push(word);
    cnt[word]++;
  }
  
  while(!words.empty()){
    word = words.top();
    words.pop();
    if(max_c < cnt[word]) {
      max_c = cnt[word];
      freq = word;
    }
  }

  cout << freq << ' ' << max_l << endl;

  return 0;
}

Measured memory_bytes: 1196
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        a: isize, b: isize, c: isize
    }
    let mut hash = HashMap::new();
    *hash.entry(a).or_insert(0) += 1;
    *hash.entry(b).or_insert(0) += 1;
    *hash.entry(c).or_insert(0) += 1;
    println!("{}", hash.len());
}

Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long K, vector<long long> x) {
  ll ans = 0;
  REP(i, N) {
    ll a = x[i] * 2;
    ll b = abs(x[i] - K) * 2;

    ans += min(a, b);
    dump(i, a, b);
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long K;
  cin >> N;
  vector<long long> x(N - 1 + 1);
  cin >> K;
  for (int i = 0; i <= N - 1; i++) {
    cin >> x[i];
  }
  solve(N, K, x);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

main()
{
	int n,x;
	int counter;
	int i,j,k; //i<j<k, i+j+k=9
	
	do{
		counter=0;
		scanf(" %d %d",&n,&x);
		if(n==0 && x == 0){
			break;
		} else {
			for(i=1;i<=n-2;i++){
				if(3*i+3>x){
					break;
				}
				for(j=i+1;j<=n-1;j++){
					k = x-i-j;
					if( k<=j){
						break;
					} else if(k<=n){
						counter++;
					}
				}
			}
		}
		printf("%d\n",counter);
	}while(1);
	return 0;
}
						
			

Measured memory_bytes: 600
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

std::string solve(int k, const std::string& s)
{
  if (static_cast<int>(s.size()) <= k) return s;
  return s.substr(0, k) + "...";
}

int main()
{
  int k;
  std::string s;
  std::cin >> k >> s;

  std::cout << std::setprecision(20);
  std::cout << solve(k, s) << std::endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main()
{
	int m,n,count=0,No=0;
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		for(int j=1;j<=i;j++){
			if(i%j==0){count++;}
			}
		if(count==8&&i%2==1){
			No++;
			}
		count=0;
		}
	printf("%d",No);
	
	return 0;
}

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

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

string dp=s;
int res=0;
int temp=0;
for(int i=0;i<(int)s.size();i++){
if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
temp++;
}else{
res=max(temp,res);
temp=0;
}
}

res=max(temp,res);

cout << res;



}


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

int main(void){
    int N,A,B,C;
    cin>>N>>A>>B;
    if(A+B>N){
        C=A+B-N;

    }else{
        C=0;
    }
    cout<<min(A,B)<<' '<<C<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#define INF 0x3f3f3f3f


using namespace std;
int main(){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int pla=n*a;
    printf("%d",pla<b?pla:b);
    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

double s(int[] v) {
    v ~= 360 - v.sum;
    double ans = 0;
    foreach(vi; v) {
        ans += sin(vi*PI/180/2) * cos(vi*PI/180/2);
    }
    return ans;
}

void main(){
    while(true) {
        auto m = readInt();
        if(m == 0) {
            return;
        }
        int[] v;
        foreach(i; iota(m-1)) {
            v ~= readInt();
        }
        auto n = readInt();
        int[] u;
        foreach(i; iota(n-1)) {
            u ~= readInt();
        }
        auto diff = v.s - u.s;
        if(abs(diff) < eps) {
            writeln(0);
        } else {
            writeln(diff > 0 ? 1 : 2);
        }
    }
}

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

#define     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{
    /*string str;
    cin>>str;
    int sz=str.size();
    if(str[sz-1]!='s')cout<<str<<"s\n";
    else cout<<str<<"es\n";*/
    /*int n;
    cin>>n;
    int A[n+5],B[n+5],cnt=0;
    for(int i=0;i<n;i++)cin>>A[i]>>B[i];
    for(int i=0;i<n;){
        if(A[i]==B[i]){
            cnt=0;
            while(A[i]==B[i]){
                i++;
                cnt++;
                if(i>=n)break;
            }
            if(cnt>=3){
                cout<<"Yes\n";
                return 0;
            }
        }
        else i++;
    }
    cout<<"No\n";*/
    int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n/i;j++){
            int m=i*j;
            int dif=n-m;
            if(dif>0 && dif<n)cnt++;
        }
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight; // 親nodeとの差分

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]]; // 経路圧縮しながらdiff_weightを加算していく
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    Abel weight(int x) {
        root(x); // 経路圧縮のついでにweightを取得できる
        return diff_weight[x];
    }

    Abel diff(int x, int y) {
            return weight(y) - weight(x);
        } // rooo(x) != root(y) の時は未定義動作

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y); // root同士を繋ぐので、その補正
        x = root(x); y = root(y);
        if (x == y) return false; // xとyが既にmergeされていたらfalse
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    } // weight(y) - weight(x) = w となるようにmergeする、
};

int main(){
    ll n, m; cin >> n >> m;
    UnionFind<int> data(n);
    rep(i,m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if(data.issame(a,b)){
            if(c != data.diff(a,b)){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            data.merge(a,b,c);
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4576
from collections import Counter
from itertools import accumulate
import bisect

n = int(input())
a = list(map(int, input().split()))
b = sorted(Counter(a).values())
exist = len(b)
b = [0]*(n-exist)+b
c = list(accumulate([0]+b))

print(n)
for k in range(2,n//2+1):
    l = 0
    r = n+1
    while r-l>1:
        x = (r+l)//2
        i = bisect.bisect_left(b,x)
        if c[i]+(n-i)*x>=x*k:
            l = x
        else:
            r = x
    print(l)

for k in range(max(n//2+1,2),n+1):
    if exist>=k:
        print(1)
    else:
        print(0)



Measured memory_bytes: 123420
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int cnt=1<<30;
  vector<pair<int,int>>as;
  map<int,int>ma;
  rep(i,n)ma[a[i]]++;
  ma[1e9]++;
  as=vector<pair<int,int>>(all(ma));
  int res=0;
  int l=as.size();
  for(int i=l-1;i>=0;i--)
  {
    if(as[i].second==0)continue;
    while(cnt>2*as[i].first)cnt/=2;
    pair<int,int> tp={cnt-as[i].first,1};
    int  f=lower_bound(all(as),tp)-as.begin();
    if(as[f].first==cnt-as[i].first)
    {
      if(i==f)
      {
        res+=as[f].second/2;
        as[f].second=as[f].second&1;
      }
      else
      {
        int tmp=min(as[i].second,as[f].second);
        res+=tmp;
        as[i].second-=tmp;
        as[f].second-=tmp;
      }
    }
  }
  cout<<res<<endl;
}


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

const int N = 100 * 1000 + 5, LG = 20;
int ans = 0;

vector <int> adj[N];
int dp[N];
int cnt[N][LG];
bool mark[N];

int get(int x, int y) {
	return (x >> y) & 1;
}

void dfs(int v) {
	mark[v] = true;
	for (auto u : adj[v]) {
		if (!mark[u]) {
			dfs(u);
			dp[v] |= dp[u];
			for (int i = 0; i < LG; i++) {
				if (get(dp[u], i)) {
					cnt[v][i]++;
				}
			}
		}
	}
	int x = -1;
	for (int i = 0; i < LG; i++) {
		if (cnt[v][i] > 1) {
			x = i;
		}
	}
	x++;
	while (cnt[v][x]) {
		x++;
	}
	ans = max(ans, x);
	for (int i = 0; i < x; i++) {
		dp[v] &= (1 << LG) - 1 - (1 << i);
	}
	dp[v] |= (1 << x);
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1);
	cout << ans;
	return 0;
}


Measured memory_bytes: 17408
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int Max=3e5+100;
char str[Max];
int main(){
    scanf("%s", str);
    int len=strlen(str);
    if(str[len-1]!=str[0]){
        if(len%2)printf("First\n");
        else printf("Second\n");
    }
    else {
        int num=0, ans=0;
        char pos=str[0];
        for(int a=0; a<len; a++){
            if(str[a]==pos)ans+=max(0, num-1), num=0;
            else num++;
        }
        //printf("%d\n", ans);
        if(ans%2==0)printf("Second\n");
        else printf("First\n");
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main() {
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed;
    cout << setprecision(8);

    cout << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;

    return 0;
}

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

#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)

int main() {
  int N;
  int A, B;
  cin >> N;
  cin >> A >> B;
  vector<int> P(N);
  REP(i, N) {
    cin >> P[i];
  }
  int c1 = 0;
  int c2 = 0;
  int c3 = 0;
  REP(i, N) {
    if(P[i] <= A) {
      c1++;
    } else if(A < P[i] && P[i] <= B) {
      c2++;
    } else {
      c3++;
    }
  }
  int ans = min(c1, min(c2, c3));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]) {
    val N = readLine().toLong
    var min = N
    for(i <- 1l to Math.sqrt(N).toLong) {
      if(N % i == 0 && (i + N / i - 2) < min) min = i + N / i - 2
    }
    println(min)
  }
}


Measured memory_bytes: 37052
#include<iostream>
#include<string>
using namespace std;
int main(){
  int count=0;
  string S;
  cin>>S;
  int N = (int)(S.length());
  for(int i=0;i<N;i++){
    if(i%2==0){
      if(S[i]=='L'){
        count++;
        break;
      }
    }else{
      if(S[i]=='R'){
        count++;
        break;
      }
    }
  }
    if(count==0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
    cin.tie();
    
    int n;
    cin>>n;
    if(n>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3616
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int f = a * e;
	int g = b + max(0, e - c)*d;
	cout << min(f, g)<<endl;
	return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	
	int k, s;
	int ans = 0;
	cin >> k >> s;

	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
				int z = s - x - y;
				if (0 <= z && z <= k) {
					ans++;
				}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long s;
  long x1,x2,y1,y2;
  long max = 1000000000;
  scanf("%ld",&s);
  if(s == max*max){
    printf("0 0 %ld 0 0 %ld\n",max,max);
  }else{
    x2 = 1;
    y1 = max - (s % max);
    x1 = max;
    y2 = (s/max + 1);
    printf("0 0 %ld %ld %ld %ld\n",x1,y1,x2,y2);
  }
  return 0;
}

Measured memory_bytes: 128