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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    bool ans = false;
    auto rec = [&](auto &&f, int a, int b, int c, int remcnt) -> void {
        if (remcnt == 0) {
            if (b > a && c > b) ans = true;
            return;
        }
        f(f, a * 2, b, c, remcnt - 1);
        f(f, a, b * 2, c, remcnt - 1);
        f(f, a, b, c * 2, remcnt - 1);
    };
    rec(rec, a, b, c, k);
    if (ans)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    string s = to_string(N);
    if(s[0]==s[1] && s[1] == s[2]) cout << YES << endl;
    else if (s[1]==s[2] && s[2]==s[3]) cout<<YES<<endl;
    else cout << NO << endl;

}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
		int N, K;
	cin >> N >> K;
	vec(A);
	int r = 0;
	fx(N) {
		vecp(A);
		r = max(A[x], r);
	}
	int l = 1;
	int ans = r;
	r++;
	fx(50) {
		int mid = (l + r) / 2;
		int sum = 0;
		fy(N) {
			sum += (A[y]-1) / mid;
		}
		if (sum<=K) {
			ans = min(ans, mid);
			r = mid;
		}
		else {
			l = mid;
		}
	}
	ce(ans)
	
    return 0;
}



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

int main(){
  int H, W;
  while(1){
    cin>>H>>W;
    if(H == 0 && W == 0) break;
    int i, j;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(i == 0 || i == H - 1 || j == 0 || j == W-1) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }

  return 0;
}
	
    


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

int main() {
  int n,x,t;cin>>n>>x>>t;
  int ans=(n+x-1)/x*t;
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();
		String[] SSplit = S.split("");
		int[][] LR = new int[Q][2];
		for (int i = 0; i < Q; i++) {
			LR[i][0] = sc.nextInt();
			LR[i][1] = sc.nextInt();
		}
		int[] subSum = new int[N];
		subSum[0] = 0;
		boolean mode = SSplit[0].equals("A");

		for (int i = 1; i < N; i++) {
			if (SSplit[i].equals("A")) {
				subSum[i] = subSum[i - 1];
				mode = true;
			} else if (mode && SSplit[i].equals("C")) {
				subSum[i] = subSum[i - 1] + 1;
				mode = false;
			} else {
				subSum[i] = subSum[i - 1];
				mode = false;
			}
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(subSum[LR[i][1] - 1] - subSum[LR[i][0] - 1]);
		}
	}
}

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

int main() {
	int n;
	cin >> n;
	int a[n], i = 0;
	while (cin >> a[i]) i++;
	for(i = 0; i < n; i++){
		cout << a[n -1 - i];
		if(n-1 != i) cout << " ";
	}
	cout << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main() {
	while (1) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if ((i + j) % 2 == 0)cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}
	


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

#define ll long long

ll N;
void func(ll cur, int use, ll& counter) {
  if (cur > N) return;
  if (use == 0b111) counter++; // 3桁のbitで，各桁が3,5,7をそれぞれ使っているかを表している

  // 7を追加７を追加したので，useの1桁目を1に更新 | はbit各桁のOR演算
  func(cur * 10 + 7, use | 0b001, counter); 
  func(cur * 10 + 5, use | 0b010, counter); // 5を追加
  func(cur * 10 + 3, use | 0b100, counter); // 7を追加
}

int main() {
  cin >> N;
  ll ans = 0;
  func(0,0,ans);
  cout << ans << endl;
  
}

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

const int MAX_N = 1000;
int N, K, p[MAX_N];
int main(){
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%d", &p[i]);
    }
    
    sort(p, p+N);
    int ans = 0;
    for(int i = 0; i < K; i++) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,m,x;
  cin >> n >> m >> x;
  ll cnt=0;
  vl a(m);
  rep(i,m){
    cin >> a[i];
    if(a[i]>x){
      cnt++;
    }
  }
  cout << min(cnt,m-cnt) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var w = sc.nextInt();
        var h = sc.nextInt();
        var x = sc.nextInt();
        var y = sc.nextInt();

        int ans = 0;
        if (x * 2 == w && y * 2 == h) ans = 1;

        Console.WriteLine("{0} {1}", (double)w * h / 2.0, ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



class UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<long long> weight;
public:
	UnionFind(int max_n) :par(max_n), rank(max_n), weight(max_n){}
	void init(int n, int w[]) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			weight[i] = w[i];
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (rank[x] < rank[y]) {
			par[x] = y;
			weight[y] += weight[x];
		}
		else {
			par[y] = x;
			weight[x] += weight[y];
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	long long w(int u)  {
		return weight[find(u)];
	}
};





int n, m;
int x[100000];
vector<tuple<int, int,int>> edges;
vector<pair<int,int>> edge[100000];




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

	cin >> n >> m;
	rep(i, n)cin >> x[i];

	rep(i,m) {
		int a, b, y;
		cin >> a >> b >> y;
		a--; b--;
		edges.emplace_back(y, a, b);
		edge[a].emplace_back(y, b);
		edge[b].emplace_back(y, a);
	}
	sort(all(edges));


	UnionFind uf(n);
	uf.init(n, x);
	vector<bool> use(m, false);

	for (int i = 0; i < m; i++) {
		int y, a, b;
		tie(y, a, b) = edges[i];
		if (!uf.same(a,b)) {
			if (uf.w(a) + uf.w(b) >= y) {
				use[i] = true;
			}
			uf.unite(a, b);
		}
		else {
			if (uf.w(a) >= y) {
				use[i] = true;
			}
		}
	}

	int ans = 0;
	vector<bool> usedv(n, false);
	for (int i = m - 1; i >= 0;i--) {
		if (!use[i])continue;
		int ymax, a, b;
		tie(ymax, a, b) = edges[i];
		if (usedv[a] || usedv[b])continue;

		queue<int> q;
		usedv[a] = true;
		q.push(a);
		while (!q.empty())
		{
			int u = q.front();
			q.pop();
			for (auto p : edge[u]) {
				int v = p.second;
				if (p.first <= ymax) {
					if (!usedv[v]) {
						usedv[v] = true;
						q.push(v);
					}
					ans++;
				}
			}
		}
	}
	cout << m - ans / 2 << endl;



	return 0;
}

Measured memory_bytes: 9396
#include <stdio.h>
#define MOD ((long long)(1e9) + 7)
typedef long long ll;

ll n;
char str[100005];
ll count[30];
ll ans;

int main()
{
	scanf("%lld", &n);
	scanf("%s", str);

	for (ll i = 0; i < n; i++) {
		count[str[i] - 'a']++;
	}

	ans = 1;
	for (ll i = 0; i < 30; i++) {
		if (count[i]) {
			ans = ans * (count[i] + 1);
		}
		ans = ans % MOD;
	}
	ans--;
	ans = ans % MOD;

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
# ABC159
# A The Number of Even Pairs
import math
n, m = map(int, input().split())
if n < 2:
    x = 0
else:
    x = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))

if m < 2:
    y = 0
else:
    y = math.factorial(m) // (math.factorial(m-2) * math.factorial(2))

print(x+y)
  

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

int n;

int gcd(int a, int b){
	while(b!=0){
		int r = a%b;
		a = b;
		b = r;
	}	
	return a;
}

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

int main(){
	cin >> n;
	int A[n];
	int end;
	
	for(int i=0; i<n; ++i){
		cin >> A[i];
	}
	
	int temp = A[0];
	
	for(int i=1; i<n; ++i){
		temp = gcd(temp,A[i]);
	}
	
	cout << temp ;
	
	return 0;
}


Measured memory_bytes: 640
N = int(input())
arm = []
for n in range(N):
    i, L = map(int, input().split())
    arm.append([i+L, i-L])
sarm = sorted(arm)
pre = -10**10
count = 0
for a in sarm:
    if pre <= a[1]:
        count += 1
        pre = a[0]
print(count)

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


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

	vector<int> l(m);
	vector<int> r(m);
	for(int i=0; i<m; i++){
		cin >> l.at(i) >> r.at(i);
	}
	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());
	sort(r.begin(), r.end());
	int num = r.at(0) - l.at(0) + 1;
	if(num <= 0){
		cout << 0 << endl;
	}else{
		cout << num << endl;
	}
}


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

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

    cout << "Yes" <<endl;
  }
}
 

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

int main() {
  int n;
  long cnt = 0;

  cin >> n;

  vector<long> l(n);

  for (int i = 0; i < n; i++) {
    cin >> l[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (l[i] == l[j]) continue;
      for (int k = j + 1; k < n; k++) {
        if (l[i] == l[k] || l[j] == l[k]) continue;
        if (l[i] != l[j] && l[j] != l[k] && l[i] + l[j] > l[k] &&
            l[j] + l[k] > l[i] && l[k] + l[i] > l[j])
          cnt++;
      }
    }
  }

  cout << cnt;

  return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();
		System.out.println((long) a * b / gcd(a, b));
	}

	private static int gcd(int a, int b) {
		if (a % b == 0)
			return b;
		return gcd(b, a % b);
	}
}


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


using namespace std;

int main()
{
    int n;
    cin>>n;
    int flag=0;
    if(n%100<=12&& n%100>=1 && n/100<=12 &&n/100>=1)
    {
        cout<<"AMBIGUOUS";
    }
    else if(n%100<=12 && n%100>=1)
    {
        cout<<"YYMM";
    }
    else if( n/100<=12 &&n/100>=1)
    {
        cout<<"MMYY";
    }
    else
    {
        cout<<"NA";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e18;

int main() {
	int N,M;
	cin >> N >> M;
	VI from(M), to(M);
	VL weight(M);
	REP(i, M) {
		cin >> from[i] >> to[i] >> weight[i];
		weight[i] *= (-1);
	}

	VVL node(2,VL(N + 1,INF));
	node[0][1] = 0;
	REP(i, N - 1) REP(j, M) if (node[0][to[j]] > node[0][from[j]] + weight[j]) node[0][to[j]] = node[0][from[j]] + weight[j];
	node[1] = node[0];
	REP(i, N - 1) REP(j, M) if (node[1][to[j]] > node[1][from[j]] + weight[j]) node[1][to[j]] = node[1][from[j]] + weight[j];
	if (node[0][N] > node[1][N]) cout << "inf" << endl;
	else cout << -node[0][N] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q,h,s,d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;
    h = min(h,2*q);
    s = min(s,2*h);
    if(2*s <= d){
        cout << (ll)n*s << endl;
    }else{
        if(n % 2 == 0){
            n /= 2;
            cout << (ll)n*d << endl;
        }else{
            n /= 2;
            cout << (ll)n*d + s << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    ll n, k;
    in(n); in(k);
    ll ans;
    while (n > k) n %= k;
    ans = min(n, k-n);
    out(ans);

	return 0;
}


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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

struct Kruskal{

  
  struct edge{
    Int from,to,cost,used;
    char color;
    edge(){}
    edge(Int from,Int to,Int cost,char color):
      from(from),to(to),cost(cost),used(0),color(color){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  Int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(Int sz):n(sz){}
  
  void add_edge(Int u,Int v,Int c,char d){
    edges.emplace_back(u,v,c,d);
  }

  void input(Int m,Int offset=0){
    Int a,b,c;
    char d;
    for(Int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      add_edge(a+offset,b+offset,c,d);
    }
  }
  
  Int build(){
    sort(edges.begin(),edges.end());
    UnionFind uf(n+1);
    Int res=0,cnt=0;
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
	res+=e.cost;
	uf.unite(e.from,e.to);
	e.used=1;
	cnt++;
      }
    }
    //cout<<cnt<<" "<<res<<endl;
    if(cnt+1!=n) return -1;
    return res;
  }

  Int count(char c){
    Int res=0;
    for(auto& e:edges)
      if(e.used&&e.color==c) res++;
    return res;
  }
};


signed main(){
  Int n,m,k;
  while(cin>>n>>m>>k,n){
    //cout<<n<<" "<<m<<" "<<k<<endl;
    Kruskal kr(n);
    kr.input(m,-1);
    Int ans=kr.build();
    if(ans<0){
      cout<<-1<<endl;
      continue;
    }
    
    auto es=kr.edges;
    Int A=kr.count('A');
    Int B=kr.count('B');
    
    auto check=[&](char c,char d,Int i){
      Int res=-1;
      UnionFind uf(n);
      for(Int j=0;j<m;j++)
	if(i!=j&&es[j].used)
	  uf.unite(es[j].from,es[j].to);
      
      for(Int j=0;j<m;j++)
	if(es[j].color==d&&!es[j].used)
	  if(!uf.same(es[j].from,es[j].to))
	    if(res<0||es[j].cost<es[res].cost)
	      res=j;
      
      return res;
    };

    //cout<<A<<" "<<B<<endl;
    while(A>k){
      Int res=-1,idx=-1,idy=-1;
      for(Int i=0;i<m;i++){
	if(es[i].color!='A'||!es[i].used) continue;
	Int tmp=check('A','B',i);
	if(tmp<0) continue;
	if(res<0||es[tmp].cost-es[i].cost<res){
	  res=es[tmp].cost;
	  idx=i;idy=tmp;
	}
      }
      if(idx<0) break;
      es[idx].used=0;ans-=es[idx].cost;
      es[idy].used=1;ans+=es[idy].cost;
      A--;B++;
    }
    while(A<k){
      Int res=-1,idx=-1,idy=-1;
      for(Int i=0;i<m;i++){
	if(es[i].color!='B'||!es[i].used) continue;
	Int tmp=check('B','A',i);
	if(tmp<0) continue;
	if(res<0||es[tmp].cost-es[i].cost<res){
	  res=es[tmp].cost;
	  idx=i;idy=tmp;
	}
      }
      if(idx<0) break;
      es[idx].used=0;ans-=es[idx].cost;
      es[idy].used=1;ans+=es[idy].cost;
      A++;B--;
    }
    if(A!=k) cout<<-1<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        int mod = 0;
        for(int i=0;i<s.length();i++){int a = (int)(s.charAt(i))-48;
                                      mod+=a;
                                      mod%=9;
                            }       
		if(mod==0){System.out.println("Yes");}
      else{System.out.println("No");}
	}
}

Measured memory_bytes: 40132
#include "bits/stdc++.h"
using namespace std;

constexpr long long MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	long long COUNT1 = 0, COUNT2 = 0;
	for (int i = 0; i < N; i++) {
		long long A;
		cin >> A;
		COUNT1 += A;
		COUNT1 %= MOD;
		COUNT2 += (A * A) % MOD;
		COUNT2 %= MOD;
	}
	long long ANS = (COUNT1 * COUNT1 - COUNT2 + MOD) % MOD;
	if (ANS % 2 == 0) cout << ANS / 2 << endl;
	else cout << (ANS + MOD) / 2 << endl;
}

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


/*
ll gcds(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    ll r=a%b;
    if(r==0){
        return b;
    }
    while(r>0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}


ll lcms(ll a,ll b){
    ll mmr=gcds(a,b);
    a=a/mmr;
    b=b/mmr;
    return a*b*mmr;
}
*/

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    int flag=0;
    for(int i=0;i<N;i++){
        if(A.at(i)%2==0){
            if(A.at(i)%3!=0 && A.at(i)%5!=0){
                flag++;
                break;
            }
        }
    }
    if(flag==0){
        cout<<"APPROVED"<<endl;
    }
    else{
        cout<<"DENIED"<<endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    replace(s.begin(), s.end(), '?', 'D');
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

bool prime[(1<<15) + 50];
// bool used[(1<<15) + 50][(1<<15) + 50];

void mp(void)
{
	fill(prime, prime + (1<<15) + 50, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i < (1<<15) + 50; i++){
		if (prime[i]){
			for (int j = i * 2; j < (1<<15) + 50; j += i){
				prime[j] = false;
			}
		}
	}

	return;
}

int main(void)
{
	int n;

	mp();
	while (cin >> n, n){
		// memset(used, false, sizeof(used));
		int ret = 0;

		for (int i = 0; i <= n / 2; i++){
			if (prime[i] && prime[n - i]){
				// cout << i << " " << n - i << endl;
				// if (!used[i][n - i]){
					ret++;
				// }
			}
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include <stdio.h>

int main(){
  int a,b;

  scanf("%d %d",&a,&b);

  if(b!=1&&(a>b||a==1)){
    printf("Alice\n");
  }else if(a!=1&&(a<b||b==1)){
    printf("Bob\n");
  }else if(a==b){
    printf("Draw\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    string s;
    if (!(cin >> s)) { return; }
    bool put = true;
    for(auto&& t: s){
        if(put){ cout << t ; }
        put = !put;
    }
}

int main(int argc, char *argv[]) {
    string FileName("ABC072"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


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

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;

#define int long long
using namespace std;

std::vector<int> PrimeFactoring(int N){
    std::vector<int> ans;
    while(N != 1){
        for(int a = 2;a <= N;a++){
            if(N % a == 0){
                N /= a;
                ans.push_back(a);
                break;
            }
        }
    }
    return ans;
}

signed main() {
    int N, M;cin >> N >> M;
    map<int, int> mp;
    for(int i = 0;i < N;i++){
        int a;cin >> a;
        mp[a]++;
    }
    for(int i = 0;i < M;i++){
        int a, b;cin >> a >> b;
        mp[b] += a;
    }
    vector<pair<int, int>> v;
    for(auto a : mp)v.push_back(a);
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int ans = 0;
    int cnt = 0;
    for(int i = 0;i < v.size();i++){
        if(cnt + v[i].second > N){
            ans += v[i].first * (N - cnt);
            break;
        }else{
            cnt += v[i].second;
            ans += v[i].second * v[i].first;
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 19968
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	ret = 1
	while pow_num > 0:
		if pow_num % 2 == 1:
			ret *= num
			ret %= MOD
		num *= num
		num %= MOD
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb %= MOD
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans

Measured memory_bytes: 8040
#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>;

// rep(i, 3){cout << i << endl;}

string S; 


int main(){
    cin >> S;

    if(S.compare("ABC") == 0){
        cout << "ARC" <<endl;
    }else{
        cout << "ABC" <<endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <stdlib.h>
#include <time.h>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define ll long long
#define INF 2000000000

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	cout << m * 2 - n << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=5000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int n,k;
int p[MAX_N];
int c[MAX_N];
int main()
{
    cin>>n>>k;
    int i;
    for(i=1;i<=n;i++)
        scanf("%d",&p[i]);
    for(i=1;i<=n;i++)
        scanf("%d",&c[i]);
    ll ans=-INF;
    for(i=1;i<=n;i++)
    {
        ll sum=0;
        int j;
        vector<ll>v;
        for(j=p[i];j!=i;j=p[j])
        {
            sum+=(ll)c[j];
            v.pb(sum);
        }
        sum+=(ll)c[i];
        v.pb(sum);
        int len=v.size();
        for(j=0;j<len;j++)
        {
            ll rest=k-j-1;
            if(rest<0)
                break;
            ans=max(ans,v[j]+(rest/len)*max(sum,(ll)0));
        }
    }
    cout<<ans<<endl;
    //system("pause");
    
}

Measured memory_bytes: 3840
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
int main() {
	
	while(true){
		string num;
		cin>>num;
		if (num=="0") break;
		int size = num.size();

		int a[1000];
		for (int i = 0; i < size; ++i)
		{
			a[i]=num[i]-'0';
		}
		int sum=0;
		for (int j = 0; j < size; ++j)
		{
			sum+=a[j];
		}
		cout<<sum<<endl;
	}
    return 0;
}

Measured memory_bytes: 3152
/*
[abc132] D - Blue and Red Balls
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2000;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    static int extgcd(int a, int b, int& x, int& y) {
        int d = a;
        if (b != 0) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
    static int mod_inv(int a, int m) {
        int x, y;
        extgcd(a, m, x, y);
        return (m + x) % m;
    }
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
    gf operator/(const gf x) const { return *this * x.inv(); }
    gf inv() const { return gf(mod_inv(n, MOD)); }
};

int N, K;
gf fact[MAX_N + 1];

gf c(int n, int k) {
    return (n < 0 || k < 0 || n - k < 0) ? 0
                                         : fact[n] / (fact[k] * fact[n - k]);
}

void solve() {
    if (N == K) {
        cout << 1 << endl;
        for (int i = 2; i <= K; i++) {
            cout << 0 << endl;
        }
        return;
    }

    fact[0] = 1;
    for (int i = 1; i <= N; i++) {
        fact[i] = fact[i - 1] * i;
    }

    for (int i = 1; i <= K; i++) {
        cout << (c(K - 1, i - 1) * c(N - K + 1, i)).n << endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

const int MAX = 100;

int main() {
	int N;
	int a[MAX];

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

	sort(a, a + N);

	cout << abs(a[0] - a[N - 1]) << endl;

	return 0;
}


Measured memory_bytes: 764
//おまじない
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;

vector<vector<int> > v(maxn);
int n;
ll num[maxn];
ll ans=0;

void bi(int i,ll n){
    int cnt=0;
    ll k=1;
    while(k<n){
      cnt++;
      k =k*2;
    }
    while(n>0){
        if(n>=k){
          n-=k;
          v[i].push_back(cnt);
        }
        k=k/2;
        cnt--;
    }
    
    return;
}

int main(){
    int r=0,l=0;
    int width=0;
    int table[30]={0};

    cin >> n;

    ans=n;

    rep(i,n){
      cin >> num[i];
      bi(i,num[i]);
    }

    while(true){
        bool k_1=false;
        rep(i,v[r].size()){     //num[r]のbitを足す
            table[v[r][i]]++;
            if(table[v[r][i]]>1)k_1=true;
        }
        if(k_1){    //bitの重複がある時
            while(true){
                bool k_2=false;
                rep(i,v[l].size()){
                    table[v[l][i]]--;
                }
                rep(i,21){
                    if(table[i]>1){
                        k_2=true;
                        break;
                    }
                }
                l++;
                if(!k_2){   //lのbitを引いて重複がなくなった時
                    width = r-l+1;
                    if(width>1)ans+=width-1;
                    break;
                }
            }
        }else{  //bitの重複がない時
            width++;
            if(width>1)ans+=width-1;
        }
        if(r==n-1)break;
        r++;
    }
    
    cout << ans<<endl;

  return 0;
}



Measured memory_bytes: 20480
import sys

N=int(sys.stdin.readline())
A=list(map(int,sys.stdin.readline().split()))
B=list(map(int,sys.stdin.readline().split()))

ANS=""
for i in range(1,30):
    k=2**i
    XA=sorted([a%k for a in A],reverse=True)
    XB=sorted([b%k for b in B])
    XB.append(k*2)

    b0=0
    b1=0
    b2=0
    count=N*N%2

    for xa in XA:
        for j in range(b0,N+1):
            if k//2<=xa+XB[j]:
                b0=j
                break

        if b1<b0:
            b1=b0

        
        for j in range(b1,N+1):
            if xa+XB[j]>=k:
                b1=j
                break

        if b2<b1:
            b2=b1

        for j in range(b2,N+1):
            if k*3//2<=xa+XB[j]:
                b2=j
                break

        count+=b1+b0+b2

    ANS+=str(count%2)

print(int(ANS[::-1],2))

Measured memory_bytes: 145120
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int S;
  int a;
  int b;
  int c;
  int d;
  cin >> S;

  a=S%10;
  S=S/10;
  b=S%10;
  S=S/10;
  c=S%10;
  S=S/10;
  d=S%10;

  if(a==b){
    cout << "Bad" << endl;
  }
  else if(b==c){
    cout << "Bad" << endl;
  }
  else if(c==d){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
d=list(map(int,input().split()))

ds = []
 
for i in range(0,n):
    sum = 0
    for j in range(i,n):
        sum += d[j]
        ds.append(sum)

ds.sort(reverse=True)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        ds = list(o)
  
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;


main(){
  ll h, w; cin >> h >> w;
  ll a,b,c;
  ll ans = 1ll << 60;
  ll smax,smin,tmp;
  
  FOR(i,1,h){
    a = i * w;
    tmp = (h - i) / 2;
    b = tmp * w;
    c = (h - i - tmp) * w;
    if(a !=0 and b != 0 and c != 0){
      smax = max(a,max(b,c));
      smin = min(a,min(b,c));
      if(ans > smax - smin){
	ans = min(ans,smax-smin);
      }
    }

    tmp = w / 2;
    b = (h - i) * tmp;
    c = (h - i) * (w - tmp);
    if(a !=0 and b != 0 and c != 0){
      smax = max(a,max(b,c));
      smin = min(a,min(b,c));
      if(ans > smax - smin){
	ans = min(ans,smax-smin);
      }
    }
  }
  swap(h,w);
  FOR(i,1,h){
    a = i * w;
    tmp = (h - i) / 2;
    b = tmp * w;
    c = (h - i - tmp) * w;
    if(a !=0 and b != 0 and c != 0){
      smax = max(a,max(b,c));
      smin = min(a,min(b,c));
      if(ans > smax - smin){
	ans = min(ans,smax-smin);      }
    }

    tmp = w / 2;
    b = (h - i) * tmp;
    c = (h - i) * (w - tmp);
    if(a !=0 and b != 0 and c != 0){
      smax = max(a,max(b,c));
      smin = min(a,min(b,c));
      if(ans > smax - smin){
	ans = min(ans,smax-smin);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
C = list(input())
c = 0
pi = 0
pj = n-1
while True:
    for i in range(pi, n):
        if C[i] == 'W':
            break
    else:
        break
    for j in range(pj, 0, -1):
        if C[j] == 'R':
            break
    else:
        break
    if i < j:
        C[i] = 'R'
        C[j] = 'W'
        c += 1
    else:
        break
    pi = i
    pj = j
print(c)

Measured memory_bytes: 10772
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
int main(void){
    int number;
    int demension;
    
    int i;
    int ii;
    int iii;
    int iiii;
    int answer=0;
    cin >> number;
    cin >> demension;
    vector<vector<int>> coordinate(number,vector<int>(demension));
    for(i=0;i<number;i++){
        for(ii=0;ii<demension;ii++){
            cin >> coordinate[i][ii];
        }
    }
    ii=0;
    while(ii+1<number){
        for(i=ii+1;i<number;i++){        
            iiii=0;
            for(iii=0;iii<demension;iii++){
                iiii+=pow(coordinate[ii][iii]-coordinate[i][iii],2);
            }
            if(sqrt(iiii)==(int)sqrt(iiii)){
                answer++;
            }
        }
        ii++;
    }
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {

  public static void main(String[] args) {

      Scanner scan = new Scanner(System.in);
      String chaineCaractere = scan.nextLine();

      String[] motChaine = chaineCaractere.split(" ");

      String raccourciChaine = "";

      for (int i = 0; i < motChaine.length; i++){
        raccourciChaine = raccourciChaine + motChaine[i].charAt(0);
      }

      System.out.println(raccourciChaine.toUpperCase());

  }
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  int x=0,y=0,z=0;
  for(auto it:a){
    if(it==1)x++;
    if(it==2)y++;
    if(it==3)z++;
  }
  vector<vector<vector<double>>>
    dp(301,vector<vector<double>>(301,vector<double>(301,-1)));
  dp[0][0][0]=0;

  auto Y=[](auto f){
    return [=](auto&&... args){
      return f(f,forward<decltype(args)>(args)...);
    };
  };

  auto func=[&](auto f,double i,double j,double k)->decltype(double()){
    if(dp[i][j][k]!=-1)return dp[i][j][k];
    double ret=0;
    if(i>0)ret+=f(f,i-1,j,k)*i;
    if(j>0)ret+=f(f,i+1,j-1,k)*j;
    if(k>0)ret+=f(f,i,j+1,k-1)*k;
    ret+=N;
    ret*=1./(i+j+k);
    dp[i][j][k]=ret;
    return ret;
  };

  cout<<fixed<<setprecision(20)<<Y(func)(x,y,z)<<endl;
  return 0;
}


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

const int mod = 1e9 + 7;

int main() {
	int n, m; cin >> n >> m;
	long long ans = 1;
	if (abs(n - m) >= 0 && abs(n - m) <= 1) {
		for (int i = n; !(i == 1); i--) {
			ans *= (i % mod);
			ans %= mod;
		}
		for (int i = m; !(i == 1); i--) {
			ans *= (i % mod);
			ans %= mod;
		}
		if (n == m) {
			ans *= 2;
			ans %= mod;
		}
	}
	else {
		ans = 0;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import itertools

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

ans = 0
for (a, b, c) in itertools.combinations(L, 3):
    if a == b or b == c or c == a:
        continue
    a, b, c = sorted((a, b, c))
    # print(a, b, c)
    if a + b > c:
        ans += 1
print(ans)

Measured memory_bytes: 9188
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

template<typename T>
using v = vector<T>;

int main() {
	int N;
	cin >> N;
	vi a(N);
	bool diff = true;
	int maxi = 0, mini = INF;
	rep(i, N) {
		cin >> a[i];
		maxi = max(maxi, a[i]);
		mini = min(mini, a[i]);
		if (a[i] != N - 1)diff = false;
	}
	if (diff) {
		cout << "Yes" << endl;
		return 0;
	}
	if (maxi - mini > 1) {
		cout << "No" << endl;
		return 0;
	}
	if (maxi == mini) {
		if (N >= maxi * 2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}

	int minn = 0;
	rep(i, N) {
		if (a[i] == mini)minn++;
	}
	int maxn = N - minn;
	if (minn >= maxi) {
		cout << "No" << endl;
		return 0;
	}
	if (N - minn >= 2 * (maxi - minn)) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
		return 0;
	}


	return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer>v = new ArrayList<>();
    List<Integer>c = new ArrayList<>();
    int ans = 0;
    for(int i=0;i<n;i++){
      v.add(sc.nextInt());
    }
    for(int i=0;i<n;i++){
      c.add(sc.nextInt());
    }
    for(int i=0;i<n;i++){
      int tmp=v.get(i)-c.get(i);
      if(tmp>0)ans+=tmp;
    }
    System.out.println(ans);

  }
}


Measured memory_bytes: 23764
#include<queue>  
#include<vector>  
#include<cstdio>  
#include<cstring>  
#include<algorithm>
using namespace std;  
const int maxn = 1e5+3;  
int cnt=0, id=0, Next[maxn],in[maxn],out[maxn];  
int fa[maxn][20], len[maxn];  
struct node  
{  
    int v, next;  
}
edge[maxn<<1];  
void add_edge(int u, int v)  
{  
    edge[cnt] = {v, Next[u]};  
    Next[u] = cnt++;  
    edge[cnt] = {u, Next[v]};  
    Next[v] = cnt++;  
}  
void dfs(int cur, int pre, int d)  
{  
    fa[cur][0] = pre;  
    len[cur] = d;  
    for(int i=1; i<20; ++i)  
        fa[cur][i] = fa[fa[cur][i-1]][i-1];  
    in[cur] = ++id;  
    for(int i=Next[cur]; i!=-1; i=edge[i].next)  
    {  
        int v = edge[i].v;  
        if(v == pre) continue;  
        dfs(v, cur, d+1);  
    }  
    out[cur] = id;  
}  
int main()  
{  
    int n, a, b;  
    scanf("%d",&n);  
    memset(Next, -1, sizeof(Next));  
    for(int i=1; i<n; ++i)  
    {  
        scanf("%d%d",&a,&b);  
        add_edge(a, b);  
    }  
    dfs(1, 0, 0);  
    int tmp=(len[n]-1)/2, now=n;  
    for(int i=0; i<20; ++i)  
        if(tmp>>i&1) now = fa[now][i];  
    int bl = n-(out[now]-in[now]+1)-len[n]/2-1;  
    int wh = out[now]-in[now]+1-tmp-1;  
    if(len[n]&1)  
    {  
        if(bl <= wh) puts("Snuke");  
        else puts("Fennec");  
    }  
    else  
    {  
        if(wh <= bl) puts("Fennec");  
        else puts("Snuke");  
    }  
    return 0;  
}   

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

int main() {
    
    int a[6];
    
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    
     for(int i=0;i<5;i++)
     {
         if(a[i]==0)
         cout<<i+1;
     }
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  if(s == string(n, s[0])) {
    cout << (long long)k * n / 2 << '\n';
  } else {
    int res = 0;
    for (int i = 0, j; i < n; i++) {
      for (j = i; j < n; j++) {
        if(s[j] != s[i]) {
          break;
        }
      }
      res += (j - i) / 2;
      i = j - 1;
    }
    long long ans = (long long)k * res;
    if(s.front() == s.back()) {
      int a = 0;
      for (int i = 0; i < n; i++) {
        if(s[i] == s[0]) {
          a++;
        } else break;
      }
      int b = 0;
      for (int i = n - 1; i >= 0; i--) {
        if(s[i] == s[n - 1]) {
          b++;
        } else break;
      }
      ans -= (long long)(k - 1) * (a / 2 + b / 2 - (a + b) / 2);
    }
    cout << ans << '\n';
  }

  return 0;
}

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

if N > 888:
    print(999)
elif N > 777:
    print(888)
elif N > 666:
    print(777)
elif N > 555:
    print(666)
elif N > 444:
    print(555)
elif N > 333:
    print(444)
elif N > 222:
    print(333)
elif N > 111:
    print(222)
else:
    print(111)

Measured memory_bytes: 3060