akhauriyash/Code-Regression huggingface dataset:
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <utility>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long 
#define pii pair<int,int> 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

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

vector<int> cnt(100050);

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i,n){
		int a;
		cin >> a;
		++cnt[a];
	}
	int x = 2;
	rep(i,n / 2 - 1){
		x *= 2;
		x %= mod;
	}
	if(n == 1) x = 1;
	if(n % 2 == 0){
		for(int i = 1;i <= n-1;i += 2){
			if(cnt[i] != 2){
				cout << 0 << '\n';
				return 0;
			}
		}
		cout << x << '\n';
	}
	else{
		if(cnt[0] != 1){
			cout << 0 << '\n';
			return 0;
		}
		for(int i = 2;i <= n-1;i += 2){
			if(cnt[i] != 2){
				cout << 0 << '\n';
				return 0;
			}
		}
		cout << x << '\n';
	}
	return 0;
}


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

using namespace std;

const int N = 1e6 + 6;

char s[N];
int a[N], n, k;

int main() {
  scanf("%d %d %s", &n, &k, s);
  for (int i = 0; i < n; i++)
    a[i] = s[i] == 'A';
  int id = 0, now = -1;
  while (k > 0) {
    if (now == -1) {
      if (id >= n)
        break;
      now = a[id];
      if (id & 1)
        now ^= 1;
      id++;
    }
    now--;
    k--;
  }
  if (k == 0) {
    int cur = 0;
    if (now > -1)
      a[cur++] = now;
    while (id < n) {
      a[cur] = (id-cur) & 1 ? a[id] ^ 1 : a[id];
      cur++, id++;
    }
    while (cur < n) {
      a[cur] = (n-cur) & 1;
      cur++;
    }
  }
  else {
    if (now == -1) {
      now = n & 1;
    }
    a[0] = now;
    for (int i = 1; i < n; i++)
      a[i] = (n-i) & 1;
    if (n & 1) {
      if (k & 1)
        a[0] ^= 1;
    }
  }
  for (int i = 0; i < n; i++)
    printf("%c", a[i] ? 'A' : 'B');
  printf("\n");
  return 0;
}

Measured memory_bytes: 3328
// I - Coins  https://atcoder.jp/contests/dp/tasks/dp_i
/* 入力例
5
0.42 0.01 0.42 0.99 0.42
// →出力　0.3821815872
// ※注意※　　setprecision(15)　で桁数を指定しないとデフォルトでは６ケタしか出力しないのでWAになってしまう・・・
*/
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int N;
    cin >> N;
    double p[N+1][N+1],in;
    cin >> in;
    p[1][0]=1.0-in;
    p[1][1]=in;
    for(int j=2;j<=N;j++){
        p[1][j]=0.0;
    }
    for(int i = 2; i <= N; i++) {
        cin >> in;
        p[i][0]=p[i-1][0]*(1.0-in);
        for(int j=1;j<=N;j++){
            if(j<=i){
                p[i][j]=p[i-1][j-1]*in+p[i-1][j]*(1.0-in);
            }
            else{
                p[i][j]=0.0;
            }
        }
    }
    double answer=0.0;
    for(int i=0;i<=N;i++){
        if(i>N/2){
        answer += p[N][i];
        }
    }
    cout << setprecision(15) << answer << endl;
    return 0;
}


Measured memory_bytes: 70528
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();

    for (int c = M; c > 0; c--) {
      if (c <= M / N && M % c == 0) {
        System.out.println(c);
        return;
      }
    }
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    ll cnt=0;
    for(int i=0;i<3;i++)if(s[i]==t[i])cnt++;
    cout<<cnt;
    
}

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

int main() {
  int n; cin >> n;
  std::vector<int> d(n);
  rep(i,n) cin >> d.at(i);
  sort(d.begin(), d.end());
  cout << d.at(n/2) - d.at(n/2-1) << endl;
}


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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node<<1
#define rson (node<<1)+1
#define endl "\n"

const int maxn=2e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);

ll qpow(ll a,ll n)
{
    ll b=1;
    while(n)
    {
        if(n&1)
            b=b*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return b;
}
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b)
{
    return a*b/gcd(a,b);
}
//int prime[maxn],s,v[maxn];
//void prime_init()
//{
//    for(int i=2; i<=maxn; i++)
//    {
//        if(!v[i])
//        {
//            prime[s++]=i;
//            for(int j=1; j*i<=maxn; j++)
//                v[i*j]=1;
//        }
//    }
//}
int n,k;
int a[maxn];
int check(int x)
{
    int sum=0;
    for(int i=0; i<n; i++)
    {
        sum+=a[i]/x;
        if(a[i]%x==0)
            sum--;
        if(sum>k)
            return 0;
    }
    return 1;
}
signed main()
{
    sll2(n,k);
    int l=1,r=0;
    for(int i=0; i<n; i++)
    {
        sll(a[i]);
        r=max(r,a[i]);
    }
    r++;
    while(l<r)
    {
        int mid=(l+r)>>1;
        if(check(mid))
            r=mid;
        else
            l=mid+1;
    }
    printf("%lld",r);
    return 0;
}


Measured memory_bytes: 5276
#include<bits/stdc++.h>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin >>w>>h>>x>>y>>r;
    if((x>=r)&&(y>=r)&&(x+r<=w)&&(y+r<=h))cout <<"Yes"<<endl;
    else cout << "No"<<endl;
}


Measured memory_bytes: 3116
/*
	* ernestvw
	* C++
	* May 2020
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define veci vector<int>
#define vecs vector<string>
#define amax(x, v) x = max(x, (v))
#define amin(x, v) x = min(x, (v))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define nl '\n'

using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

const int oo = 1e9; // INT_MAX
const long long OO = 1e18; // LLONG_MAX
const double eps = 1e-9;
const double pi = 4.0 * atan(1.0);
const int p197 = 1000000007;
const int p998 = 998244353;
const int p103 = 1000003;

#define TEST_CASES 0

void solve(int test_case);

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

	int T = 1;
	if(TEST_CASES) cin >> T;
	for(int t = 1; t <= T; t++)
		solve(t);

	return 0;
}

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

string t;
int n;

void solve(int test_case) {
	cin>>t;
	n=sz(t);
	FOR(i,n)if(t[i]=='?')t[i]='D';
	cout<<t<<endl;
}



















































Measured memory_bytes: 3716
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import core.stdc.stdlib;
import std.numeric;
import std.math;

void main() {
  real a, b, x; readf("%g %g %g\n", &a, &b, &x);
  auto water_height = x/a/a;
  auto yoyuu = b - water_height;

  if (yoyuu <= water_height) {
    auto theta = atan2(yoyuu, 0.5L*a);
    writefln("%.10f", theta*180.0L/PI);
  } else {
    auto theta = atan2(b, 2*x/a/b);
    writefln("%.10f", theta*180.0L/PI);
  }
}


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

int main() {
	string s;
	while (cin >> s) {
		if (s == "#")break;
		bool br[10][10];
		for (int i = 0; i < 10; i++)
			for (int j = 0; j < 10; j++)br[i][j] = false;

		int now = 0;
		int rt = 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'b') {
				br[rt][now] = true;
				now++;
			}
			else if (s[i] == '/') {
				now = 0;
				rt++;
			}
			else {
				now += s[i] - '0';
			}
		}

		int a, b, c, d;
		cin >> a >> b >> c >> d;
		swap(br[a - 1][b - 1], br[c - 1][d - 1]);

		string ans;
		for (int i = 0; i <= rt; i++) {
			int nm = 0;
			for (int j = 0; j < now; j++) {
				if (br[i][j]) {
					if(nm)ans.push_back(nm+'0');
					ans.push_back('b');
					nm = 0;
				}
				else nm++;
			}
			if (nm)ans.push_back(nm + '0');
			ans.push_back('/');
		}
		ans.pop_back();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3164
S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1)


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);
  int k,l;
  for (int i = 0; i < m; i++) {
    cin >> k >> l;
    vec.at(k-1) += 1;
    vec.at(l-1) += 1;
  }
  for (int i = 0; i < n; i++) {
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 3624
import sys

s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()

memo = [[0 for i in range(len(s1)+1)] for j in range(len(s2)+1)]
for i in range(len(s1)+1):
    memo[0][i] = i
for j in range(len(s2)+1):
    memo[j][0] = j

for i in range(0, len(s2)):
    for j in range(0, len(s1)):
        if s2[i] == s1[j]:
            memo[i+1][j+1] = memo[i][j]
        else:
            memo[i+1][j+1] = min(memo[i][j+1] + 1, memo[i+1][j] + 1, memo[i][j] + 1)

print memo[-1][-1]

Measured memory_bytes: 36644
from collections import deque
S = input()
Q = deque([S])

while Q:
    s = Q.pop()
    if s == "ABC":
        print("Yes")
        break
    s = s.replace("ABC", "x")
    if not "x" in s:
        continue
    for y in "ABC":
        if not y in s:
            Q.append(s.replace("x", y))
else:
    print("No")



Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int n;
  cin >> n;
  vector<int> v=input(n);
  bool f=true;
  sort(v.begin(),v.end());
  for(int i=1;i<n;i++){
    if(v[i-1]==v[i]){
      f=false;
      break;
    }
  }
  sayYES(f);
}

Measured memory_bytes: 3960
A, B, C, D = map(int, input().split())
# A//C
ac = A // C # 4
bc = B // C # 2
ad = A // D # 3
bd = B // D # 1


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

cd = C * D // gcd(C,D)
acd = A // cd
bcd = B // cd

res = B - A + 1 - bc + ac - bd + ad + bcd - acd
 

if A % C == 0:
    res -= 1
if A % D == 0:
    res -= 1
if A % cd == 0:
    res += 1

print(res)


Measured memory_bytes: 3060
def gcd(a, b):
    if a < b:
        a, b = b , a
    while b != 0:
        a, b = b, a % b
    return a
K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        tmp_ans = gcd(a, b)
        for c in range(1, K + 1):
            ans += gcd(tmp_ans, c)
print(ans)


Measured memory_bytes: 68336
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;


int main(){
	  long long a[100010];
    //cout << fixed << setprecision(15);
    int N; cin >> N;
    int cnt=0;
    long long minV =1e9;
    for(int i=0; i<N; ++i){
        long long v; cin >> v;
        if(v<0){
            cnt++;
        }
        a[i] = v;
        minV = min(minV, abs(v));
    }

    long long ans=0;
    for(int i=0; i<N; ++i){
        ans += abs(a[i]);
    }

    if(cnt%2==0){  //if even number of negatives
        cout << ans << endl;
    }else{ //odd number of negatives
        cout << ans-2*minV << endl; // subtracting 2 into min because total has sbtract 2 times the minimum value
    }
    return 0;
}


Measured memory_bytes: 1024
n, m = gets.split.map(&:to_i)
v = gets.split.map(&:to_i).sort.reverse
s = 0

v.each do |vv|
  s += vv
end

c = 0

v.each do |vv|
  if vv * 4 * m >= s
    c += 1
  end
end

puts (c >= m) ? "Yes" : "No"


Measured memory_bytes: 1788
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  a,b,c = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  #a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = []
  
  print(a*b//2)

if __name__ == '__main__':
  main()

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



int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	int n;
   	cin>>n;
   	vector<int> arr(n);
   	for(int i =0 ; i< n; i++) {
   		cin>>arr[i];
   	}

   	for(int i = n-1; i > 0; i--) {
   		int left = arr[i-1];
   		int right = arr[i] + 1;
   		if(left == right) {
   			arr[i-1]--;
   		}
   	}

   	for(int i = 0; i < n - 1; i++) {
   		
   		if(arr[i] > arr[i+1]) {
   			cout<<"No";
   			return 0;
   		}
 
   	}
   	cout<<"Yes";
	return 0;		
}


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

#define BR "\n"
#define SP " "

ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  ll x, y;
  cin >> x >> y;
  cout << gcd(x, y) << BR;
  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP_ll(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VREP_int(v) for(std::vector<int>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int h,w;
	cin >> h >> w;

	char m[h][w];
	REP(y,h){
		string s;
		cin >> s;
		REP(x,w){
			m[y][x] = (s[x]=='.') ? 0:1;
		}
	}

//	REP(y,h){
//		REP(x,w){
//			printf("%d",m[y][x]);
//		}
//		printf("\n");
//	}

	int dx[h][w];
	int dy[h][w];
	REP(y,h){
		REP(x,w){
			dx[y][x] = dy[y][x]=0;
		}
	}

	REP(y,h){
		int from=-1,to=-1;
		bool inPath=false;
		REP(x,w){
			if(!inPath && m[y][x]==0){
				from = to = x;
//				printf("[%d][%d] : start\n",y,x);
				inPath=true;
			}else if(inPath && m[y][x]==0){
				to = x;
			}else if(inPath && m[y][x]==1){
//				printf("[%d][%d] : end\n",y,x-1);
//				printf("[%d][%d-%d]:%d\n",y,from,to,to-from);
				FOR(i,from,to) dx[y][i] = to-from;
				inPath=false;
			}
		}
		if(inPath){
//			printf("[%d][%d] : end\n",y,w-1);
//			printf("[%d][%d-%d]:%d\n",y,from,to,to-from);
			FOR(i,from,to) dx[y][i]=to-from;
			inPath=false;
		}
//		printf("\n");
	}
//	println("----------------");


	REP(x,w){
		int from=-1,to=-1;
		bool inPath=false;
		REP(y,h){
			if(!inPath && m[y][x]==0){
				from = to = y;
//				printf("[%d][%d] : start\n",y,x);
				inPath=true;
			}else if(inPath && m[y][x]==0){
				to = y;
			}else if(inPath && m[y][x]==1){
//				printf("[%d][%d] : end\n",y,x-1);
//				printf("[%d][%d-%d]:%d\n",y,from,to,to-from);
				FOR(i,from,to) dy[i][x] = to-from;
				inPath=false;
			}
		}
		if(inPath){
//			printf("[%d][%d] : end\n",y,w-1);
//			printf("[%d][%d-%d]:%d\n",y,from,to,to-from);
			FOR(i,from,to) dy[i][x]=to-from;
			inPath=false;
		}
//		printf("\n");
	}
//	println("----------------");


//	REP(y,h){
//		REP(x,w){
//			printf("%d",dx[y][x]);
//		}
//		printf("\n");
//	}
//	println("----------------");
//
//	REP(y,h){
//		REP(x,w){
//			printf("%d",dy[y][x]);
//		}
//		printf("\n");
//	}
//
//	println("----------------");
//
	int ret = 0;
	REP(y,h){
		REP(x,w){
			ret = max(ret,dy[y][x]+dx[y][x]);
		}
//		printf("\n");
	}

	println(ret+1);



	return 0;
}


Measured memory_bytes: 35456
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Measured memory_bytes: 9284
class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N, M = map(int, input().split())
P = list(map(lambda a: int(a) - 1, input().split()))

tree = UnionFind(N)
for _ in range(M):
    fr, to = map(int, input().split())
    tree.union(fr - 1, to - 1)

ans = 0
for i, p in enumerate(P):
    ans += tree.isSameRoot(i, p)
print(ans)


Measured memory_bytes: 14452
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		long sum = 0;
		for(int i = 0; i < n; i++) {
			int t = scan.nextInt();
			sum += (long)t;
			if(t < min) {
				min = t;
			}
			if(t > max) {
				max = t;
			}
		}
		scan.close();
		System.out.println(min + " " + max + " "+ sum);
	}
}


Measured memory_bytes: 42632
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string>s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if(s[i][j]=='.') continue;
      bool p = false;
      for (int k = 0; k < 4; k++) {
	int x = i + dx[k];
	int y = j + dy[k];
	if(0<=x && x<h && 0<=y && y<w && s[x][y]=='#'){
	  p = true;
	  break;
	}
      }
      if(!p){
	cout << "No" << endl;
	return 0;
      }
    }
  }

  cout << "Yes" << endl;
  
  return 0;
}


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

vector<int> edge[10000];
queue<int> q;
int ans[10000];
int v[10000];
bool visit[10000];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1,x,y;i<n;i++){
		cin>>x>>y;
		x--;y--;
		edge[x].emplace_back(y);
		edge[y].emplace_back(x);
	}
	for(int i=0;i<n;i++)
		cin>>v[i];
	sort(v,v+n);
	int stp=n-1;
	q.push(0);
	while(!q.empty()){
		int now=q.front();q.pop();
		ans[now]=v[stp--];visit[now]=true;
		for(int it:edge[now])
			if(!visit[it])
				q.push(it);
	}
	long long int tmp=0;
	for(int i=0;i<n-1;i++)
		tmp+=v[i];
	cout<<tmp<<endl;
	for(int i=0;i<n;i++){
		if(i!=0)	cout<<' ';
		cout<<ans[i];
	}
	cout<<endl;

}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int n, abc[3];
    cin >> n >> abc[0] >> abc[1] >> abc[2];
    vector<string> s(n); rep(i,n) cin >> s[i];
    vector<char> ans;
    rep(i,n) {
        int x = s[i][0]-'A', y = s[i][1]-'A';
        if (abc[x] == 0 and abc[y] == 0) {
            cout << "No" << endl;
            return 0;
        }
        int dx = 1, dy = -1;
        if (abc[x] == 1 and abc[y] == 1) {
            if (i == n-1) {
                ans.push_back(s[i][0]);
                break;
            }
            if (s[i][0] == 'A' and s[i+1][0] == 'A') {
                ans.push_back('A');
            } else if (s[i][1] == 'C' and s[i+1][1] == 'C') {
                ans.push_back('C');
                dx = -1, dy = 1;
            } else {
                ans.push_back('B');
                if (s[i][1] == 'B') dx = -1, dy = 1;
            }
        } else {
            if (abc[x] < abc[y]) {
                ans.push_back(s[i][0]);
            } else {
                ans.push_back(s[i][1]);
                dx = -1, dy = 1;
            }
        }
        abc[x] += dx, abc[y] += dy;
        cerr << abc[0] << " " << abc[1] << " " << abc[2] << endl;
    }
    cout << "Yes" << endl;
    rep(i,n) cout << ans[i] << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll X[20][20];

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

    ll N, D;
    cin >> N >> D;
    REP(i, N){
    	REP(j, D){
    		cin >> X[i][j];
    	}
    }

    ll res = 0;
    REP(i, N){
    	REP(j, N){
    		if(i<j){
    			ll dist = 0;
    			REP(k, D){
    				dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
    			}
    			ll sd = (ll)sqrt(dist);
    			if(dist == sd*sd) res++;
    		}
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

n, m, x = nm()
l = [nl() for _ in range(n)]
ans = 10**10
for bit in range(1<<n):
    cst = 0
    g = [0]*m
    for i in range(n):
        if bit & (1<<i):
            f = l[i]
            cst += f[0]
            for j in range(m):
                g[j] += f[j+1]
    if min(g) >= x:
        ans = min(ans, cst)
print(ans if ans < 10**10 else -1)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const double pi=acos(-1.0);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	if(c>=a && c<=b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
template <typename Iter> std::string join(Iter begin, Iter end, std::string const& separator){ std::ostringstream result; if (begin != end){ result << *begin++; }; while (begin != end){ result << separator << *begin++; }; return result.str(); }
using namespace std;
typedef long long ll;
void solve() {
  ll N; cin >> N;
  vector<ll> H(N);
  REP(i, N) {
    cin >> H[i];
  }
  vector<ll> ans(N);
  ans[N-1] = 0;
  REPR(i, N - 1) {
    if(H[i-1] >= H[i]) {
      cerr << H[i-1] << " >= " << H[i] << endl;
      ans[i-1] = ans[i] + 1;
    } else {
      cerr << H[i-1] << " > " << H[i] << endl;
      ans[i-1] = 0;
    }
  }
  cout << *max_element(ALL(ans)) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 1792
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
 
#print(A)
C=[0,0,0,0,0]
for i in range(len(A)) :
    C[A[i][0]]+=1
    C[A[i][1]]+=1
 
#print(C)
co=0
for i in range(1,5):
    if C[i]==1 or C[i]==3 :
        co+=1
 
if co==0 or co==2 :
    print("YES")
else :
    print("NO")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;



int main(){
    string s;
    LL k;
    cin >> s >> k;
    for(int i=0;i<k;i++){
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    puts("1");
    return 0;
}

Measured memory_bytes: 256
H1 = [int(i) for i in input().split()]
H2 = [int(i) for i in input().split()]
H3 = [int(i) for i in input().split()]
N = int(input())
num = [int(input()) for i in range(N)]

L1 = [H1[0], H2[0], H3[0]]
L2 = [H1[1], H2[1], H3[1]]
L3 = [H1[2], H2[2], H3[2]]

S1 =[H1[0], H2[1], H3[2]]
S2 = [H1[2], H2[1], H3[0]]

ans = []
for i in [H1,H2,H3,L1,L2,L3,S1,S2]:
    i.extend(num)

ans = []
for i in [H1,H2,H3,L1,L2,L3,S1,S2]:
    ans.append(len(set(i)))

if min(ans) == N:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n, k = gets.split.map(&:to_i)
snk = Array.new(n+1, 0)
for i in 0..(k-1)
  d = gets.to_i
  a = gets.split.map(&:to_i)
  a.each{|an| snk[an] += 1}
end
cnt = 0
for i in 1..n
  cnt += 1 if snk[i] == 0
end
puts cnt

Measured memory_bytes: 14348
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long ll;
#define INF 100000000
#define MOD 1000000007

int main()
{
	const int N = 100000;
	int n; 
	ll a[N];
	ll sum = 0, ans, ans1 = 0, ans2 = 0;
	//bool sign1;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	// 奇数番目までの和が正の場合と偶数番目までの和が正の場合を考える
	// 2回の試行で良い方を答えとする
	// 各試行においては，もし決めた符号と一致していたら操作は行わない
	// 不一致の場合，和を1もしくは-1になるように操作する
	// その操作回数は(sumの絶対値 + 1)回
	// 操作後の和は1もしくは-1になる
	for (int i = 0; i < n; i++) { // 奇数番目までの和が正の場合
		sum += a[i];
		if (((i + 1) % 2) != 0) { // 奇数番目まで → sum > 0
			if (sum == 0) {
				sum++;
				ans1++;
			} else if (sum < 0){
				ans1 += abs(sum) + 1;
				sum = 1;
			}
		} else { // 偶数番目まで → sum < 0
			if (sum == 0) {
				sum--;
				ans1++;
			} else if (sum > 0){
				ans1 += abs(sum) + 1;
				sum = -1;
			}
		}
	}
	//cout << ans1 << endl;
	sum = 0;
	for (int i = 0; i < n; i++) { // 偶数番目までの和が正の場合
		sum += a[i];
		if (((i + 1) % 2) == 0) { // 偶数番目まで → sum > 0
			if (sum == 0) {
				sum++;
				ans2++;
			} else if (sum < 0){
				ans2 += abs(sum) + 1;
				sum = 1;
			}
		} else { // 奇数番目まで → sum < 0
			if (sum == 0) {
				sum--;
				ans2++;
			} else if (sum > 0){
				ans2 += abs(sum) + 1;
				sum = -1;
			}
		}
	}
	//cout << ans2 << endl;
	if (ans1 <= ans2) ans = ans1;
	else ans = ans2;

	cout << ans << endl;

	return (0);
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ABC135B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var ans = 0;

            for (var i = 0; i < p.Length; i++)
            {
                if (p[i] != i + 1)
                    ans++;
            }

            Console.WriteLine(ans <= 2 ? "YES" : "NO");
        }
    }
}

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

int main() {
  int k;
  string s;
  cin >> k >> s;
  cout << s.substr(0, k) << (s.size() > k ? "..." : "") << endl;
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int hug=0;
  for(int i=0; i<S.size()/2; i++){
    if(S[i]!=S[S.size()-1-i]) hug++;
  }
  cout << hug << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    vector<int> q(n);
    rep(i,n) q[i] = i+1;

    int cnt=0;
    rep(i,n){
        if(p[i]!=q[i]) cnt++;
    }

    if(cnt>2) cout << "NO" <<endl;
    else cout << "YES" <<endl;

}

Measured memory_bytes: 256
#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 SIZE=305;
const LL INF=1<<30;
int maps[SIZE][SIZE];
int CAL[SIZE][SIZE];
int DP[SIZE][SIZE];
int H,W;
LL calc(int a,int b,int x){
	if(max(a,b)==H) return 0;
	if(CAL[a][b]!=-1) return CAL[a][b];
	return CAL[a][b]=calc(a+1,b+1,x)+(maps[a][x]==maps[b][x+1]);
}
LL solve3(int a,int b,int x){
	if(max(a,b)==H) return 0;
	if(DP[a][b]!=-1) return DP[a][b];
	int ans=0;
	ans=calc(a,b,x);
	return DP[a][b]=min(solve3(a,b+1,x),solve3(a+1,b,x))+ans;


}
LL solve2(int x){
	REP(i,SIZE) REP(j,SIZE) DP[i][j]=-1;
	REP(i,SIZE) REP(j,SIZE) CAL[i][j]=-1;
	return solve3(0,0,x);
}
LL solve(){
	cin >> H >> W;
	REP(i,H){
		string s;
		cin >> s;
		REP(j,W){
			maps[H-i-1][j]=s[j]-'a';
		}
	}
	int ans=0;
	REP(i,W-1) ans+=solve2(i);
	return ans;
}
int main(){

	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int Cin()
{
    int n; cin >> n; return n;
}

int main()
{
    int A, B, C; cin >> A >> B >> C;
    if (A == B && A != C)
    {
        cout << "Yes" << endl;
    }
    else if (A == C && A != B)
    {
        cout << "Yes" << endl;
    }
    else if (B == C && A != B)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

int main() {

    int N;
    cin >> N;

    int result = 0;
    if(N % 7 == 0) result = 1;
    while(1) {
        N -= 4;
        if(N % 7 == 0) {
            result = 1;
            break;
        }
        if(N < 0) {
            break;
        }
    }
    if(result == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * (360 / (60 * 12))
deg_b = m * (360 / 60)
deg = abs(deg_a - deg_b)
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)

Measured memory_bytes: 9504
#include <stdio.h>

int main()
{
	int s[11],		/*section [0]ÍgíÈ¢B*/
		upT,downT,	/*ãèdÔAºèdÔ@Ì¬x*/
		distance,
		i;
	double y;		/*y:æÔI¤ÌI[w©çÌ£,*/
	
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"
				,&s[1],&s[2],&s[3],&s[4],&s[5],&s[6]
				,&s[7],&s[8],&s[9],&s[10],&upT,&downT) != EOF)
	{
		for(distance=0,i=1;i<=10;i++) distance += s[i];
		y = (double)upT * ( (double)distance/(double)(upT+downT) );
		
		for(i=1; (y-=(double)s[i]) > 0; i++);
		
		printf("%d\n",i);
	}
	
	return 0;
}

/*
	y=upT*t
	y=distance-downT*t
	
	
	upT*t = distanze - downT*t
	(upT + downT)*t = distance
	
	t = distance/(upT + downT)
	
	
	y = upT * ( distance/(upT + downT) )
*/

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

int main()
{
    string s1,s2;
    int flag = 0;
    cin >> s1 >> s2;
    for(int i = 0;i < s1.size();i++)
    {
        if(s2[i] == s1[0])
        {
            int cnt = 1;
            int c = s1.size() - i;
            for(int j = i + 1;j < s2.size();j++)
            {
                if(s2[j] != s1[j - i])
                cnt = 0;
            }
            for(int j = 0;j < i;j++)
            {
                if(s2[j] != s1[j + c])
                    cnt = 0;
            }
            if(cnt == 1) flag = 1;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define itn int
#define REP(i,n) for(int i=0;i<n;i++)
#define IREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define REPEACH(itr,k) for(auto itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

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


int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  REP(i,n){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  int ans=v[n/2]-v[n/2-1];
  cout << ans << endl;
}


Measured memory_bytes: 640
n, w = map(int, input().split())

ws = [0] * n
vs = [0] * n

for i in range(n):
  a, b = map(int, input().split())
  ws[i] = a
  vs[i] = b
  
dp = [0] * (w + 1)

for i in range(n):
  for j in range(w, -1, -1):
    if j + ws[i] <= w:
      dp[j + ws[i]] = max(dp[j + ws[i]], dp[j] + vs[i])
      
print(dp[w])

Measured memory_bytes: 41836
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(){
  int n;
  cin>>n;
  vector<int> a(n+2,0),b(n+2,0),c(n+2,0);
  int tmp;
  r(i,n)cin>>a.at(i);

  b.at(0)=abs(a.at(0));
  c.at(n-1)=abs(a.at(n-1));

  for(int i=1;i<n;i++){
    b.at(i)=b.at(i-1)+abs(a.at(i-1)-a.at(i));
  }

  for(int i=n-2;i>=0;i--){
    c.at(i)=c.at(i+1)+abs(a.at(i+1)-a.at(i));
  }

  r(i,n){
    cout<<b[i-1]+c[i+1]+abs(a[i+1]-a[i-1])<<endl;
  }

  return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,mn=242343423;

    cin>>n>>k;
    long long int x,x1;
    if(n%k==0)
    {
       cout<<"0"<<endl;
    }
    else
    {
        x=n%k;
        x1=min(x,abs(x-k));
        cout<<x1<<endl;
    }
}


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

int main()
{
    int N,A=0,W=0,T=0,R=0;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N;i++)
    {
        cin >> S.at(i);
        if(S.at(i)=="AC")
        {
            A++;
        }else if(S.at(i)=="WA")
        {
            W++;
        }else if(S.at(i)=="TLE")
        {
            T++;
        }else if(S.at(i)=="RE")
        {
            R++;
        }
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", A, W, T, R);

}


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

const int NMAX = 1e5 + 5;
int n;
long long dp[NMAX];
bool vis[NMAX];
queue<int> q;
vector<pair<int, int>> graf[NMAX];

int main() {
    
    cin >> n;
    for(int i = 1; i < n; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        graf[x].push_back({y, w});
        graf[y].push_back({x, w});
    }
    q.push(1);
    while(!q.empty()) {
        int nod = q.front();
        vis[nod] = 1;
        q.pop();
        for(int i = 0; i < (int)graf[nod].size(); i++) {
            int next = graf[nod][i].first;
            int cost = graf[nod][i].second;
            if(!vis[next]) {
                dp[next] = dp[nod] + cost;
                q.push(next);
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << dp[i] % 2 << '\n';
    }
    return 0;
}

Measured memory_bytes: 10412
N=int(input())
G=[[] for i in range(N)]
for i,a in enumerate(input().split()):
  G[int(a)-1].append(i+1)

X=[int(i) for i in input().split()]
def dfs(x):
  s=len(G[x])
  if s==0:
    return (0,X[x])
  dp=[[False]*(X[x]+1) for i in range(s+1)]
  dp[0][0]=True
  S=0
  for i in range(s):
    p,q=dfs(G[x][i])
    S+=p+q
    for j in range(X[x]+1):
      if dp[i][j]:
        if j+p<=X[x]:
          dp[i+1][j+p]=True
        if j+q<=X[x]:
          dp[i+1][j+q]=True
  a=-1
  for j in range(X[x]+1)[::-1]:
    if dp[s][j]:
      a=j
      break
  if a<0:
    print("IMPOSSIBLE")
    exit()
  return (X[x],S-a)
dfs(0)
print("POSSIBLE")

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

#define fast                     ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int                      long long 
#define pb                       push_back
#define pii                      pair<int,int>
#define vi                       vector<int>
#define vii                      vector<pii>
#define mi                       map<int,int>
#define mii                      map<pii,int>
#define all(a)                   (a).begin(),(a).end()
#define F                        first
#define S                        second
#define sz(x)                    (int)x.size()
#define endl                     '\n'
#define MOD                      1000000007
#define loop(i,a,b)              for(int (i)=(a);(i)<(b);(i)++)
#define rloop(i,a,b)             for(int (i)=(a);(i)>=(b);(i)--)
#define Unique(A)                (A).resize(distance((A).begin(),unique(all((A)))))
#define MXe(A)                   *max_element(all(A))
#define MNe(A)                   *min_element(all(A))
#define SP(val,precision)        fixed << setprecision((precision)) << (val)
#define setBits(x)               __builtin_popcountll(x)
#define zroBits(x)               __builtin_ctzll(x)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define mem(name,val)            memset(name,val,sizeof(name))
#define traceA(A,x)              cerr<<#A<<": ";loop(i,0,x)cerr<<A[i]<<' ';cerr<<endl
#define traceV(A)                cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define traceM(A,n,m)            cerr<<#A<<": "<<endl;loop(i,0,n){loop(j,0,m) cerr << A[i][j] << ' ';cerr << endl;}
#define maxheap                  priority_queue<int>
#define minheap                  priority_queue<int,vector<int>,greater<int>>

using namespace std;

const int N = 3e5+77;
int X[N] , Y[N] , A[N] , B[N] , n , m , k , a , b , aa ,bb , c;

int32_t main(){
    fast;
    clock_t clk = clock();

    // =========s============
    cin >> n >> m >> k; 
    loop(i,0,k){
        cin >> X[i] >> Y[i];
        A[X[i]]++; B[Y[i]]++;
    }
    
    loop(i,1,n+1) a = max(a,A[i]);
    loop(i,1,n+1) if(A[i]==a) aa++;
 
    loop(i,1,m+1) b = max(b,B[i]);
    loop(i,1,m+1) if(B[i]==b) bb++;

    loop(i,0,k) if(A[X[i]]==a && B[Y[i]]==b) c++;
    if(c==aa*bb) cout << a+b-1 << endl;
    else cout << a+b << endl;
    // =====================

    cerr << endl << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << endl;
    return 0;
}
    

Measured memory_bytes: 13176
N = gets.to_i
arr = gets.split(" ").map(&:to_i)
sum1 = 0
sum2 = 0
sum3 = 0
index = 0
tmp = 0

roop = true

arr.each do |n|
    sum1 += n
end

N.times do
    if sum2 < sum1/2
        sum2 += arr[index]
    else
        if roop
            tmp = index - 1
            sum3 += arr[index]
            roop = false
        else
            sum3 += arr[index]
        end
    end
    index += 1
end

sum2 -= arr[tmp]
if sum2 == sum3
    puts arr[tmp]
elsif sum2 > sum3
    puts (sum2 - (sum3+arr[tmp])).abs
else
    puts (sum3 - (sum2+arr[tmp])).abs
end
    

Measured memory_bytes: 16676
def f(n):
    k = 0
    while n*2**k<K:
        k += 1
    return k
N,K = map(int,input().split())
if K<=N:
    P = (N-K+1)/N
    for i in range(1,K):
        P += 2**(-f(i))/N
else:
    P = 0
    for i in range(1,N+1):
        P += 2**(-f(i))/N
print(P)

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

#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 MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

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

  set<int> s1;
  set<int> s2;

  REP(i,M){
    int a,b;
    cin >> a >> b;

    if(a==1)s1.insert(b);
    if(a==N)s2.insert(b);
    if(b==1)s1.insert(a);
    if(b==N)s2.insert(a);
  }

  for(auto itr = s1.begin(); itr != s1.end(); itr++){
    if(s2.find(*itr) != s2.end()){
      cout << "POSSIBLE" << endl;
      exit(0);
    }
  }
  cout << "IMPOSSIBLE" << endl;

}



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

int main(){
    int n; cin >> n;
    if(n/100*100+n/100*10+n/100 >= n){
    cout << (n/100)*100+(n/100)*10+(n/100) << endl;
    }
    else cout << (n/100+1)*100+(n/100+1)*10+(n/100+1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 100000000;
const double EPS = 1e-10;


int setsleep(vector<pair<bool, int> > &v, int id, int width){
	rep(i, v.size()){
		if(v[i].first == false){
			int cnt = 0;
			for(int j = i; j < i+width; j++){
				if(j >= v.size()) break;
				if(v[j].first != false) break;
				cnt++;
			}
			if(cnt == width){
				for(int j = i; j < i+width; j++){
					v[j] = MP(true, id);
				}
				return i;
			}
		}
	}
	return -1;
}

void wake(vector<pair<bool, int> > &v, int id){
	rep(i, v.size()){
		if(v[i].first && (v[i].second == id)){
			v[i] = MP(false, 0);
		}
	}
}


int main(){
	//freopen("test.txt", "r", stdin);
	while(1){
		int w, q;
		cin >> w >> q;
		if(!w)break;
		vector<pair<bool, int> > v(w, MP(false, 0));
		rep(i, q){
			char c;
			int id;
			cin >> c >> id;
			if(c == 's'){
				int width;
				cin >> width;
				int pos = setsleep(v, id, width);
				if(pos!=-1){
					cout << pos << endl;
				}else{
					cout << "impossible" << endl;
				}
			}else{
				wake(v, id);
			}
		}
		cout << "END" << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> fun [| a; b; c |] ->
    Seq.init b (fun i -> a * (i + 1) % b)
    |> Seq.tryFind (fun x -> x = c)
    |> fun x ->
        match x with
        | Some _ -> "YES"
        | None -> "NO"
    |> printfn "%s"


Measured memory_bytes: 29588
#include <bits/stdc++.h>
#define dbg(x) cout << #x << ": " << (x) << '\n'
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const ll inf = 1e18;

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

   ll a;
   long double b;
   cin >> a >> b;
   long double c = a * b;
   ll d = floor(c);
   cout << d << '\n';

   return 0;
}

Measured memory_bytes: 3744