akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 300 + 5;

double n;
int a[N];
double cache[N][N][N];

double find(int a, int b, int c)
{
	// a = 1, b = 2, c = 3, d = 0

	int d = n - a - b - c;
	int total = a + b + c;

	if (a < 0 || b < 0 || c < 0)
		return 0.0;

	if (total == 0)
		return 0.0;

	double &memo = cache[a][b][c];

	if (memo != 0)
		return memo;

	double zerolol = 1.0 / (1.0 - (d / n));
	// zerolol accounts for the selection of zero sushi in a move.
	// It is the summation of an infinite GP.
	memo = zerolol + (a / (n - d)) * find(a - 1, b, c);
	memo += (b / (n - d)) * find(a + 1, b - 1, c);
	memo += (c / (n - d)) * find(a, b + 1, c - 1);
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(cache, 0, sizeof cache);

	cin >> n;
	int f[4] = {};
	forl(i, 0, n)
	{
		cin >> a[i];
		f[a[i]]++;
	}
	double ans = find(f[1], f[2], f[3]);
	cout << fixed << setprecision(10) << ans << "\n";

	// forl (i, 0, 4) forl(j, 0, 4) forl(k, 0, 4)
	// 	if (cache[i][j][k] != 0)
	// 		cout <<	 "a : " << i << " b : " << j << " c : " << k << " " << cache[i][j][k] << "\n";

	return 0;
}


Measured memory_bytes: 221952
#include <cstdio>//C语言io
#include <cstring>//以下是c语言常用头文件
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cmath>
#include <iostream>//c++IO
#include <sstream>
#include <string>
#include <list>//c++常用容器
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>//c++泛型的一些函数
#include <functional>//用来提供一些模版
#define fo0(i,n) for(int i = 0;i < n; ++i)
#define fo1(i,n) for(int i = 1;i <= n; ++i)
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
//......................................................
const int maxn = 60;
vector<int>  G[maxn];
int edge[maxn][2];
int cnt = 0;
int jude(int a,int b)
{
    return !(a==edge[cnt][0]&&b==edge[cnt][1]||a==edge[cnt][1]&&b==edge[cnt][0]);
}
int vis[maxn];
void Dfs(int node)
{
    for(int i = 0;i < G[node].size();++i)
    {
        if(!vis[G[node][i]]&&jude(G[node][i],node))
        {
            vis[G[node][i]] = 1;
            Dfs(G[node][i]);
        }
    }
}
int main()
{
    int N,M;
    cin>>N>>M;
    for(int i = 0;i < M; ++i)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
//        edge[a][
        edge[i][0] = a;
        edge[i][1] = b;
    }
    int ans = 0;
    for(int i = 0;i < M; ++i)
    {
        me(vis);
        vis[1] = 1;
        Dfs(1);
        int j;
        for( j = 1;j <= N; ++j)
        {
            if(!vis[j])
                break;
        }
        if(j==N+1)
            ans++;
        cnt++;
    }
    cout<<M-ans<<endl;


    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
constexpr ll mod = 1000000007;
vector<ll> v;
ll cnt[2010] = {};
ll pw(ll a,ll x){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

int main(){
    ll i,j,n,k; cin >> n >> k;
    for(i=1;i*i<=n;i++){
        if(n%i==0){
            v.push_back(i);
            if(i*i!=n) v.push_back(n/i);
        }
    }
    sort(v.begin(),v.end());
    for(i=0;i<v.size();i++){
        ll num = pw(k,(v[i] + 1)/2);
        for(j=0;j<i;j++){
            if(v[i]%v[j]==0){
                num -= cnt[j];
                if(num<0) num += mod;
            }
        }
        cnt[i] = num;
    }
    ll ans = 0;
    for(i=0;i<v.size();i++){
        if(v[i]&1) (ans += v[i]*cnt[i]%mod) %= mod;
        else (ans += v[i]/2*cnt[i]%mod) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	int N,K,ans=1;
	cin >> N >> K;
	for(int i=0;i<N;i++){
		if(ans<K){
			ans = ans * 2;
		}else{
			ans = ans + K;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
 int N, K;
 cin >> N >> K;
 int a=1;

 for(int i=0;i<N;i++){
 	if(a+K<2*a){
      a=a+K;
 	}else{ 
      a=a*2;
  	}
 }
 cout << a << endl;
}

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 100005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll minim(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

ll power(ll x, ll y) 
{ 
    ll res = 1;      
     x = x;    
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) ; 
            y = y>>1;  
            x = (x*x) ;   
    } 
    return res; 
}

ll lcm(ll a,ll b){
  return (a*b)/__gcd(a,b);
}

bool comp(const point &p1,const point &p2){
	if(p1.first!=p2.first)return p1.first<p2.first;
	else return p1.second<p2.second;
}

string to(char x){
	string s(1,x);
	return s;
}

vl dectobinary(ll n) 
{  
    vl binaryNum(64,0); 
    ll i = 0; 
    while (n > 0) 
    { 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
    return binaryNum;
} 

int main()
{
	fio;
	bool flag=false;
	ll k;cin>>k;
	ll a,b;cin>>a>>b;
	for(ll i=a;i<=b;i++){
		if(i%k==0){
			flag=true;
			break;
		}
	}
	if(flag){
		cout<<"OK\n";
	}else{
		cout<<"NG\n";
	}
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;

int n;
int adj[110][110] = {};

int main() {
  cin >> n;
  rep(i, n) {
    int id, deg;
    cin >> id >> deg;
    --id;    // 0-indexedに直す
    rep(j, deg) {
      int v;
      cin >> v;
      --v;    // 0-indexedに直す
      ++adj[id][v];
    }
  }
  rep(i, n) {
    rep(j, n) {
      cout << adj[i][j] << ((j != n - 1)? " " : "\n");
    }
  }
  return 0;
}



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

typedef long long ll;

using namespace std;

#define INF 1000000

ll mas[101];

int main()
{
    ll n, x, diff = INF;

    cin >> n;

    for (ll i = 1; i <= n; i++) {
        cin >> x;
        mas[i] += mas[i-1]+x;
    }

    for (ll i = 1; i <= n; i++) {
        diff = min(abs(mas[n] - 2*mas[i]), diff);
    }

    cout << diff;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
	#include<string.h>
	int main(){
		
		int a,b,c,e,d,f;
		
		scanf("%d %d", &a,&b);
		
		c=a+b;
		d=a-b;
		f=b*a;
		if(c>=d&&c>f){
			printf("%d\n", c);
		}
		else if(d>=c&&d>f){
			printf("%d\n", d);
		}
		else printf("%d\n", f);
		return 0;
	}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int n;
vector<int> child[SIZE];
ll pow2[SIZE];
int allchild[SIZE], maxdepth[SIZE];
int counter[SIZE];

struct DATA{
  ll value[3];
  int last_merged;

  DATA(){
    value[0] = value[1] = value[2] = 0;
    last_merged = 0;
  }

  DATA(ll first, ll second, ll third, int _last_merged){
    value[0] = first;
    value[1] = second;
    value[2] = third;
    last_merged = _last_merged;
  }
};

inline DATA merge(const DATA &A, const DATA &B, int depth){
  ll A0 = A.value[0] * pow2[A.last_merged - depth] % mod;
  ll A1 = A.value[1] * pow2[A.last_merged - depth] % mod;
  ll A2 = A.value[2] * pow2[A.last_merged - depth] % mod;
  ll B0 = B.value[0] * pow2[B.last_merged - depth] % mod;
  ll B1 = B.value[1] * pow2[B.last_merged - depth] % mod;
  ll B2 = B.value[2] * pow2[B.last_merged - depth] % mod;
  return DATA(A0 * B0 % mod,
              (A0 * B1 + A1 * B0)%mod,
              (A1 * B1 + (B0 + B1)%mod * A2 + (A0 + A1)%mod * B2)%mod,
              depth);
}

inline void compress(DATA &A){
  A.value[0] = (A.value[0] + A.value[2])%mod;
  A.value[2] = 0;
}

map<int,DATA> dfs(int now, int depth = 0){
  map<int,DATA> results;
  vector< pair<int,int> > vec;
  vector<int> vec2;
  
  for(int i=0;i<child[now].size();i++){
    auto res = dfs(child[now][i], depth+1);

    if(res.size() > results.size()) swap(res, results);

    for(auto it = res.begin(); it != res.end(); it++){
      int d = it->first;
      const DATA &qq = results[d];
      const DATA &pp = it->second;
      results[d] = merge(qq, pp, depth);
      vec2.push_back(d);
    }
    
    allchild[now] += allchild[child[now][i]];
    maxdepth[now] = max(maxdepth[now], maxdepth[child[now][i]]);
  }
  
  sort(vec.begin(), vec.end(), greater<pair<int,int> >());
  
  for(int i=0;i<vec2.size();i++){
    compress(results[vec2[i]]);
  }

  results[depth] = DATA(pow2[allchild[now]], pow2[allchild[now]], 0, depth-1);
  
  allchild[now]++;
  maxdepth[now] = max(maxdepth[now], depth);
  counter[maxdepth[now]+1]++;
  return results;
}

int main(){
  int p;
  
  scanf("%d",&n);
  n+=1;
  pow2[0] = 1;
  
  for(int i=1;i<n;i++){
    scanf("%d",&p);
    child[p].push_back(i);
    pow2[i] = (pow2[i-1] * 2)%mod;
  }
  pow2[n] = (pow2[n-1] * 2)%mod;

  auto res = dfs(0);

  ll ans = 0;
  
  for(auto it = res.begin(); it!=res.end(); it++){
    auto p = it->second;
    ans = (ans + p.value[1] * pow2[p.last_merged+1] % mod * pow2[counter[it->first]])%mod;
    counter[it->first+1] += counter[it->first];
  }

  printf("%lld\n",ans);
  
  return 0;
}


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

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

  vector<int> a;

  for (int i = 0; i < N; i++) {
    int z;
    cin >> z;
    z--; // 1-indexed -> 0-indexed
    a.push_back(z);
  }
  
  int now = 0, c = 0;
  for(;;) {
    if (now == 1) {
      cout << c << endl;
      break;
    }
    if (c >= N)
    {
      cout << -1 << endl;
      break;
    }
    c++; // ボタンを押す
    now = a.at(now); // 次のボタンが光る
  }
}

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

using namespace std;

int main()
{
	long long n, a, b;
	cin >> n >> a >> b;
	cout << max((long long)0, (n - 2) * b - (n - 2) * a + 1) << endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val inputs = readLine()!!.split(" ").map { it.toInt() }

    // inputs 合計 / n  で，近い整数に丸めた値へ合わせることを考える
    // コストの式 微分から求めた

    val targetD = inputs.sum().toDouble() / n

    // 最も近い整数に丸める関数
    val targetI = Math.rint(targetD)

    val ans = inputs.map { Math.pow(targetI + (-1) * it, 2.0) }.sum()

    println(ans.toInt())
}

Measured memory_bytes: 39980
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int maxw = sc.nextInt();
        Sina sina[] = new Sina[4];
        for (int i = 0; i < 4; i++) {
            sina[i] = new Sina();
        }

        long w1 = sc.nextLong();
        int v1 = sc.nextInt();
        sina[0].vs.add(v1);
        for (int i = 1; i < n; i++) {
            sina[(int) (sc.nextLong() - w1)].vs.add(sc.nextInt());
        }

        for (int i = 0; i < 4; i++) {
            sina[i].vs.sort((o1, o2) -> o2 - o1);

            sina[i].sums = new long[sina[i].vs.size() + 1];

            sina[i].sums[0] = 0;
            int j = 1;
            for (int v : sina[i].vs) {
                sina[i].sums[j] = sina[i].sums[j - 1] + v;
                j++;
            }
        }

        long ans = 0;
        for (int a = 0; a <= sina[0].vs.size(); a++) {
            for (int b = 0; b <= sina[1].vs.size(); b++) {
                for (int c = 0; c <= sina[2].vs.size(); c++) {
                    for (int d = 0; d <= sina[3].vs.size(); d++) {
                        if (maxw < (w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d)) {
                            break;
                        }
                        ans =
                            Math.max(ans, sina[0].sums[a] + sina[1].sums[b] + sina[2].sums[c]
                                + sina[3].sums[d]);
                    }
                }
            }
        }

        System.out.println(ans);
    }

    private class Sina {
        List<Integer> vs;
        long sums[];

        public Sina() {
            vs = new ArrayList<>();
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 28240
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/26/20 20:17:32
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int s,w; cin>>s>>w;
  cout << (s <= w ? "unsafe" : "safe") << endl;

  return 0;
}


Measured memory_bytes: 3648
#include<cmath>
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int a, b,c,k;
	cin >> a >> b >> c>>k;
	if (a < b)swap(a, b);
	if (a < c)swap(a, c);
	int ans = a * pow(2, k) + b + c;

	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char ch;

  while(1){
    scanf("%c",&ch);
    if('A'<=ch && ch<='Z'){
      ch+='a'-'A';
    }
    else if('a'<=ch && ch<='z'){
      ch-='a'-'A';
    }
    printf("%c",ch);
    if(ch=='\n')break;
  }
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
//Problem Code

#define TC int t; cin>>t; while(t--)
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, st, en, in) for (int i=st ; i<en ; i+=in)
#define RFOR(i, st, en, in) for (int i=st ; i>=en ; i-=in)
#define REP(i, n) FOR(i, 0, n, 1)
#define RREP(i, n) RFOR(i, n-1, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define sz(a) int(a.size())
#define SORT(c) sort(all(c))
#define RSORT(c) sort(rall(c))

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

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

ll bs(ll s,ll e,ll a[],ll v){
    ll m =(s+e)/2;
    if(v>a[m]) return bs(m+1,e,a,v);
    else if(v<a[m]) return bs(s,m-1,a,v);
    return m;
}

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

void testingio(){
	freopen("input.txt","r",stdin); //redirects standard input
    freopen("output.txt","w",stdout); //redirects standard output	
}

int main(){
	//testingio();
	fastio();
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int tot = 0,c=0,max_c=0;
    int i=0,j=0;
    while(tot<2*n){
        if(i==n)  i=0;
        if(j==n)  j=0;
        if(s[i]==t[j]) {
            c++;
            i++;
            j++;
            max_c=max(max_c,c);
        }        
        else {
            c=0;
            i++;
       }
       tot++;
    }
    if(max_c>=n) cout<<"Yes";
    else cout<<"No";    
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	String [] dic = {"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		sc.nextLine();
		int [][] data = new int[38][38];
		while(dataset-- > 0){
			String s = sc.nextLine();
			int prevind = -1;
			for(int i = 0; i < s.length(); i++){
				char c1 = s.charAt(i);
				if(c1 == ' '){
					prevind = -1;
					continue;
				}
				boolean isfind = false;
				if(i + 1 < s.length()){
					char c2 = s.charAt(i + 1);
					int res = find(c1,c2);
					if(res >= 0){
						isfind = true;
						if(prevind == -1){
							
						}
						else{
							data[prevind][res + 26]++;
						}
						prevind = res + 26;
						i++;
					}
				}
				if(! isfind){
					if(prevind == -1){
						
					}
					else{
						data[prevind][c1 - 'a']++;
					}
					prevind = c1 - 'a';
				}
			}
		}
		for(int i = 0; i < 38; i++){
			StringBuilder sb = new StringBuilder();
			int max = -1;
			int ind = -1;
			for(int j = 0; j < 38; j++){
				if(max < data[i][j]){
					max = data[i][j];
					ind = j;
				}
			}
			
			if(i < 26){
				sb.append((char)(i + 'a'));
			}
			else{
				sb.append(dic[i - 26]);
			}
			sb.append(" ");
			if(ind < 26){
				sb.append((char)(ind + 'a'));
			}
			else{
				sb.append(dic[ind - 26]);
			}
			sb.append(" " + data[i][ind]);
			System.out.println(sb.toString());
		}
	}

	private int find(char c1, char c2) {
		for(int i = 0; i < dic.length; i++){
			if(dic[i].charAt(0) == c1 && dic[i].charAt(1) == c2){
				return i;
			}
		}
		return -1;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

int n,d,x[10][10],c,b;
double a;

int main(){
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            a=0;
            for(int k=0;k<d;k++){
                a+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            a=sqrt(a);
            if(ceil(a)==floor(a)){c++;}
        }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


const double PI = acos(-1);
const int M = 1000005;

int n,w;

vector<int> a;

bool rec(int i, int sum){
    
    if(i == n){
        if(sum == w)return true;
        else return false;
    }
    
    if(rec(i+1, sum + a[i])){
        return true;
    }
    if(rec(i, sum)){
        return true;
    }
    
    return false;
}

int main(){
    ll k;
    cin>>k;
    ll x = 7%k;
    set<ll> s;
    ll i = 1;
    
    while(s.count(x) == 0){
        if(x == 0){
            cout<< i <<endl;
            return 0;
        }
        s.insert(x);
        x = (x*10+7)%k;
        i++;
    }
    cout<<-1<<endl;
    return 0;
}


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

using namespace std;

const int nax=1e5+5;
int a[nax];
int dp[nax];

int main()
{
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[0]=1000000000;
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
N = input() 
a=0
b=0
c=[[2,3],[1,3],[1,2]]

for i in range(1,4):
		if N[i] == N[0]:
			a+=1
			b=i			
if a==1:
	if N[c[b-1][0]] == N[c[b-1][1]]:
		print("Yes")
	else:
		print("No")

else:
	print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	if(s>"AAA" && s<"BBB")
	 cout<<"Yes";
	else
	 cout<<"No";
	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b;
  cin>>a>>b;
  if((a+b)%2==1){
    cout<<(a+b)/2+1<<endl;
  }else{
    cout<<(a+b)/2<<endl;
  }
  return 0;
}


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

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		PriorityQueue<Edge> pQue = new PriorityQueue<Edge>(11,COMPARATOR);

		for (int i=0; i<n; i++) {
			String line = br.readLine();
			String[] str = line.substring(1).split(" ");
			for (int j=0; j<n; j++) {
				int cost = Integer.parseInt(str[j]);
				if (cost != -1){
					Edge edge = new Edge(cost,i,j);
					pQue.add(edge);
				}
			}
		}

		UnionFind forest = new UnionFind(n);
		int ans = 0;

		while (pQue.size() != 0) {
			Edge edge = pQue.poll();
			if (!forest.same(edge.node1,edge.node2)) {
				forest.unite(edge.node1,edge.node2);
				ans += edge.cost;
			}
		}

		System.out.println(ans);

		br.close();
	}

	static class Edge {
		int cost;
		int node1;
		int node2;

		Edge(int cost,int node1,int node2){
			this.cost = cost;
			this.node1 = node1;
			this.node2 = node2;
		}
	}

	public static final Comparator<Edge> COMPARATOR = new Comp();
	
	private static class Comp implements Comparator<Edge>{
		public int compare(Edge x,Edge y){
			return (x.cost > y.cost) ? 1 : ((x.cost == y.cost) ? 0 : -1);
		}
	}
}

class UnionFind {

	int[] node;

	UnionFind(int n){
		node = new int[n];
		for (int i=0; i<n; i++)
			node[i] = i;
	}

	int find(int x){
		if(node[x] == x)
			return x;
		return node[x] = find(node[x]);
	}

	boolean same(int x,int y){
		return find(x) == find(y);
	}

	void unite(int x,int y){
		if (find(x) == find(y))
			return;
		node[find(x)] = find(y);
	}
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b;
	while (cin >> a >> b)cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int V,E;
    cin >> V >> E;
    int u,v,d;
    REP(i,E){
        cin >> u >> v >> d;
    }
    int T;
    cin >> T;
    int n;
    REP(i,T){
        cin >> n;
        REP(i,n){
            int id,dst;
            cin >> id >> dst;
        }
    }
    REP(i,T){
        cout << -1 << endl;
    }
    return 0;
}

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

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        long n = long.Parse(cin[0]);
        long m = long.Parse(cin[1]);
        Console.WriteLine(Math.Abs((n - 2) * (m - 2)));

        // 試しに10*10でやってみた

        //for (int i = 1; i <= 10; i++)
        //{
        //    for (int j = 1; j <= 10; j++)
        //    {
        //        Console.Write(Minyami(j, i) + "\t");
        //    }
        //    Console.Write("\n");
        //}
    }

    static int Minyami(int n, int m)
    {
        bool[,] map = new bool[n, m];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (j - 1 >= 0)
                {
                    if (i - 1 >= 0) map[i - 1, j - 1] = !map[i - 1, j - 1];
                    map[i, j - 1] = !map[i, j - 1];
                    if (i + 1 < n) map[i + 1, j - 1] = !map[i + 1, j - 1];
                }
                if (i - 1 >= 0) map[i - 1, j] = !map[i - 1, j];
                map[i, j] = !map[i, j];
                if (i + 1 < n) map[i + 1, j] = !map[i + 1, j];
                if (j + 1 < m)
                {
                    if (i - 1 >= 0) map[i - 1, j + 1] = !map[i - 1, j + 1];
                    map[i, j + 1] = !map[i, j + 1];
                    if (i + 1 < n) map[i + 1, j + 1] = !map[i + 1, j + 1];
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (map[i, j]) ans++;
            }
        }

        return ans;
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  vector<ll> A(N), F(N);
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>F[i];
  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());
  ll l=0, r=big, m;
  ll cost;
  while(l<r) {
    m = (l+r)/2;
    cost = 0;
    for(int i=0;i<N;++i) {
      if(A[i]*F[i]<=m) continue;
      cost += A[i]-m/F[i];
    }
    if(cost>K) l=m+1;
    else r=m;
  }
  cout<<l<<endl;
}



Measured memory_bytes: 6416
#include <iostream>
#include <set>

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    set<int> st;
    int tmp=A%B;
    bool flag=false;
    while(st.find(tmp)==st.end()) {
        st.insert(tmp);
        if(tmp!=0) {
            if(C%tmp==0) {
                flag=true;
                break;
            }
        }
        
        tmp += A%B;
        tmp %= B;
    }
    
    if(flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
    
}

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


int main (int argc, char const *argv[])
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    cout<<min(A,B)+min(C,D)<<endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N, L = map(int, input().split())

A = [L+i-1 for i in range(1, N+1)]

A_abs = [abs(x) for x in A]
abs_min = min(A_abs)
index = A_abs.index(abs_min)
eat = A[index]
ans = sum(A) - eat
print(ans)

Measured memory_bytes: 3060
class D_Linked_List:
    class Node:
        def __init__(self, key, next = None, prev = None):
            self.next = next
            self.prev = prev
            self.key = key

    def __init__(self):
        self.nil = D_Linked_List.Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil

    def insert(self, key):
        node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
        self.nil.next.prev = node_x
        self.nil.next = node_x

    def _listSearch(self, key):
        cur_node = self.nil.next
        while (cur_node != self.nil) and (cur_node.key != key):
            cur_node = cur_node.next
        return cur_node

    def _deleteNode(self, node):
        if node == self.nil:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._deleteNode(self.nil.next)

    def deleteLast(self):
        self._deleteNode(self.nil.prev)

    def deleteKey(self, key):
        node = self._listSearch(key)
        self._deleteNode(node)

    def show_keys(self):
        cur_node = self.nil.next
        keys = []
        while cur_node != self.nil:
            keys.append(cur_node.key)
            cur_node = cur_node.next
        print(' '.join(keys))


import sys

d_ll = D_Linked_List()

for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d_ll.insert(x)
    elif 'deleteFirst' in i:
        d_ll.deleteFirst()
    elif 'deleteLast' in i:
        d_ll.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d_ll.deleteKey(x)
    else:
        pass

d_ll.show_keys()

Measured memory_bytes: 228852
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

int ans;

int max(int x,int y){return x>y?x:y;}

ll min(ll x,ll y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
ll minn,f[5];
int main()
{
	int n;
	read(n);
	for (int i=1;i<=n;i++)
	{
		int x;
		read(x);
		minn=f[0];f[0]+=x;
		minn=min(minn,f[1]), f[1]=minn+(x?x&1:2);
        minn=min(minn,f[2]), f[2]=minn+(x?x+1&1:1);
        minn=min(minn,f[3]), f[3]=minn+(x?x&1:2);
        minn=min(minn,f[4]), f[4]=minn+x;
	}
	cout<<min(f[2],min(f[3],f[4]));
	return 0;
}









Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr front()
#define tp top()
typedef long long int ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
#define iofast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define iofile freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
const ll LLINF = 1e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 100005;

int N;
int A[SIZE][4];
int dp[SIZE][4];

int main (){
	
	for(int i=0;i<SIZE;i++){
		for(int j=0;j<4;j++){
			dp[i][j]=0;
		}
	}
	scanf("%d", &N);
	for(int i=1;i<=N;i++){
		scanf("%d %d %d", &A[i][0], &A[i][1], &A[i][2]);
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(j==k) continue;
				dp[i][j]=max(dp[i][j],dp[i-1][k]+A[i][k]);
			}
		}
	}
	int Mx=0;
	for(int i=0;i<3;i++){
		Mx=max(Mx,dp[N][i]);
	}
	printf("%d\n", Mx);
	
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
 
bool arr[1010];
 
int main(){
    int N,M,c,d;
    cin >> N >> M;
    for(int i = 0 ; i < M ; i++){
	cin >> c >> d;
	for(int j = c ; j < d ; j++){
	    arr[j] = true;
	}
    }
    cout << N+2*count(arr,arr+N,1)+1 << endl;
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
  
  if(A <= 5){
    cout << 0 << endl;
  }
  else if(A >= 13){
    cout << B << endl;
  }
  else{
    cout << B / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;



int main(){
    ll ans = 0;
    ll n;
    cin >> n;
    for(int i=1;i<n;i++){
        ll tmp = n-1;
        tmp /= i;
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int W, H, N;
  cin >> W >> H >> N;
  
  int mn_x = 0, mx_x = W;
  int mn_y = 0, mx_y = H;
  
  for (int i = 0; i < N; i++)
  {
    int x, y, a;
    cin >> x >> y >> a;
    
    if (a == 1)
    {
      mn_x = max(mn_x, x);
    }
    else if (a == 2)
    {
      mx_x = min(mx_x, x);
    }
    else if (a == 3)
    {
      mn_y = max(mn_y, y);
    }
    else // (a == 4)
    {
      mx_y = min(mx_y, y);
    }
  }
  
  int area = max(mx_x - mn_x, 0) * max(mx_y - mn_y, 0);
  
  cout << area << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    cards = string_to_int(inputs[0])
    cards.sort(reverse=True)
    count_a = 0
    count_b = 0
    turn_a = True
    for card in cards:
        if turn_a:
            count_a += card
        else:
            count_b += card
        turn_a = not turn_a
    return count_a - count_b


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3812
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll N,K,S;
	cin >> N >> K >> S;
	
	ll cnt = 0;

	rep(i, K) {
		if (cnt != N - 1) {
			cout << S << " ";
			cnt++;
		}
		else {
			cout << S << endl;
		}
	}

	ll nots;
	if (S == 1e9) {
		nots = 1;
	}
	else {
		nots = S + 1;
	}
	rep(i, N - K) {
		if (cnt != N - 1) {
			cout << nots << " ";
			cnt++;
		}
		else {
			cout << nots << endl;
		}
		
	}

	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
main()
{
    int a[1001],b,c,e,d,f,t,i,j,k;
    cin>>t;
    for(i=0;i<t;i++)
        cin>>a[i];
    sort(a,a+t);
    b=a[t-1]/2;
    for(i=0;i<t-1;i++)
        b+=a[i];
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
h,w,n=map(int,input().split())
d={}
for _ in range(n):
    a,b=map(int,input().split()) 
    for i in (-1,0,1):
        for j in (-1,0,1):
            if 2<=a+i<=h-1 and 2<=b+j<=w-1:
                d.setdefault((a+i,b+j),0)
                d[a+i,b+j]+=1
r=[0]*10
for i in d.values():
    r[i]+=1
r[0]=(h-2)*(w-2)-sum(r)
for i in r:
    print(i)

Measured memory_bytes: 140192
# スペース区切りの整数の入力
n, k = map(int, input().split())
# スペース区切りの整数の入力
data =  list(map(int, input().split()))
l = sorted(data, reverse=True)
ans = 0

for i in range(k):
    ans += l[i]

print(ans)

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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int>m(n);
	int mi = 100000;
	for (int i = 0;i < n;i++) {
		cin >> m[i];
		mi = min(mi, m[i]);
		x -= m[i];
	}
	int ans = n + (x / mi);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "strings"
)

func stringIndex(ss []string, s string) int {
  i := -1
  for j := 0; j < len(ss); j++ {
    if ss[j] == s {
      i = j 
      break
    }
  }
  return i
}

func main() {
  day := strings.Split("SUN, MON, TUE, WED, THU, FRI, SAT", ", ")
  var s string 
  fmt.Scan(&s)
  fmt.Println(7 - stringIndex(day, s))
}

Measured memory_bytes: 640
import collections
N = int(input())
P = [[0 for _ in range(N)] for _ in range(N)] 
for i in range(N):
    u,k,*varray = map(int,input().split()) # u,k は数, varray は配列
    for v in varray:
        P[u-1][v-1] = 1    

D = [-1 for _ in range(N)]
D[0] = 0 # 始点への距離は 0, 他の距離は-1
Q = collections.deque()
Q.append(0)
while len(Q) > 0:
    c = Q.popleft()
    for i in range(N):
        if P[c][i]==1 and D[i]==-1:
            D[i] = D[c]+1
            Q.append(i)
for v in range(N):
    print(v+1, D[v])         


Measured memory_bytes: 6100
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        Double[] x = new Double[N];
        String[] u = new String[N];
        int sum1 = 0;
        Double sum2 = 0.0;
        for(int i=0; i<N; i++) {
            x[i] = Double.parseDouble(sc.next());
            u[i] = sc.next();
            if(u[i].equals("JPY")) {
                sum1 += x[i];
            }else {
                sum2 += x[i]*380000.0;
            }
        }
        System.out.println(sum1+sum2);
    }
}

Measured memory_bytes: 23632
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    ld a,b,x;
    cin >> a >> b >> x;
    ld pi=3.141592653589793238,v=180;
    pi=v/pi;
    if (a*a*b<x*2){
        x=a*a*b-x;
        ld t=2*x/a/a;
        cout << fixed << setprecision(10) << pi*atan(t/a) << endl;
    }
    else {
        ld t=2*x/b/a;
        ld u=90;
        // cout << t << " " << b << endl;
        cout << fixed << setprecision(10) << u-pi*atan(t/b) << endl;
    }
}


Measured memory_bytes: 256
/*
    author: Salam_35
    Created at :

*/

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

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int t;cin >> t;while(t--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

vector<ll>inp[2000005];
ll vis[2000005];
ll color[2000005];

int main()
{
    int k,a,b;
    cin >> k>>a >> b;
    int c=b/k;
    k*=c;
    if(k>=a and k<=b)
        cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 50504
#include <bits/stdc++.h>
using namespace std;
long int getTaroScore(long int start, long int end, long int sum, vector<long int> &elem, vector<vector<long int> > &score) {
    if (start == end)
        return elem[start];
    if (start+1 == end)
        return max (elem[start], elem[end]);
    if (score[start][end] != -1)
        return score[start][end];
    long int left = sum - getTaroScore(start+1, end, sum-elem[start], elem, score);
    long int right = sum - getTaroScore(start, end-1, sum-elem[end], elem, score);
    return score[start][end] = max (left, right);
}
int main() {
    long int n;
    cin>>n;
    long int sum = 0;
    vector<long int> elem(n);
    for (long int i = 0; i < n; i++) {
        cin>>elem[i];
        sum += elem[i];
    }
    vector<vector<long int> > score(n, vector<long int>(n, -1) );
    long int start = 0, end = n-1;
    long int taroScore = getTaroScore(start, end, sum, elem, score);
    long int jiroScore = sum - taroScore;
    cout<<taroScore - jiroScore<<"\n";
    return 0;
}


Measured memory_bytes: 74008
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

vector<int> compress(const vector<int>& C) {
  vector<int> res;
  for (int x : C) {
    if (res.empty() || res.back() != x) {
      res.push_back(x);
    }
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<int> C(N);
    for (int& x : C) cin >> x;
    C = compress(C);
    N = C.size();
    vector<ll> dp(N), sum(200010, 0);
    for (int i = 0; i < N; i++) {
      (sum[C[i]] += i > 0 ? dp[i - 1] : 1) %= MOD;
      dp[i] = sum[C[i]];
    }
    cout << dp[N - 1] << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

int solve(int x)
{
    int ans=0;
    while(x)
        x%=__builtin_popcount(x),
        ans++;
    return ans;
}

int ppow(int a,int b,int mod)
{
    int ans=1;
    while(b)
    {
        if(b&1)
            ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}

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

    int n;
    string x;
    cin>>n>>x;
    int cur=count(x.begin(),x.end(),'1');
    int p=0;
    for(char c:x)
        p*=2,
        p+=c-'0',
        p%=cur+1;
    int m=0;
    if(cur>=2)
        for(char c:x)
            m*=2,
            m+=c-'0',
            m%=cur-1;
//    cout<<cur<<" "<<p<<" "<<m<<"\n";
    reverse(x.begin(),x.end());
    for(int i=n-1;i>=0;i--)
        if(x[i]=='0')
        {
            int mod=cur+1,val=p;
            val+=ppow(2,i,mod);
            val%=mod;
            cout<<solve(val)+1<<"\n";
        }
        else
        {
            int mod=cur-1,val=m;
            if(mod==0)
            {
                cout<<0<<"\n";
                continue;
            }
            val-=ppow(2,i,mod);
            val%=mod;
            val+=mod;
            val%=mod;
            cout<<solve(val)+1<<"\n";
        }
}


Measured memory_bytes: 3764
n, m = (int(x) for x in input().split())
S = [[int(x) for x in input().split()] for i in range(m)]
P = [int(x) for x in input().split()]

res = 0
for bit in range(2 ** n): #スイッチの状態
  cc1 = 0
  for i in range(m): #各電球が点くか調べる
    k = S[i][0]
    cc = 0
    for j in range(1, k+1):
      if (bit >> (S[i][j]-1)) & 1:
        cc += 1
    if cc%2 == P[i]:
      cc1 += 1
  if cc1 == m:
    res += 1
print(res)


Measured memory_bytes: 3064