akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ITP1_11_D
{
	class Dice
	{
		public static int[] label = new int[6];
		public static void Roll(string s)
		{
			foreach (char c in s)
			{
				switch (c)
				{
					case 'E': { East(); break; }
					case 'N': { North(); break; }
					case 'S': { South(); break; }
					case 'W': { West(); break; }
				}
			}
		}
		static void East()
		{
			int x = label[0];
			label[0] = label[3]; label[3] = label[5];
			label[5] = label[2]; label[2] = x;
		}
		static void North()
		{
			int x = label[0];
			label[0] = label[1]; label[1] = label[5];
			label[5] = label[4]; label[4] = x;
		}
		static void South()
		{
			int x = label[0];
			label[0] = label[4]; label[4] = label[5];
			label[5] = label[1]; label[1] = x;
		}
		static void West()
		{
			int x = label[0];
			label[0] = label[2]; label[2] = label[5];
			label[5] = label[3]; label[3] = x;
		}
	}
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[,] dices = new int[n, 6];
			for (int i = 0; i < n; i++)
			{
				int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
				for (int j = 0; j < 6; j++) dices[i, j] = x[j];
			}
			string[] c = new string[] { "E", "N", "S", "W", };
			bool ret = true;
			for (int i = 0; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					int[] a = new int[6];
					for (int k = 0; k < 6; k++)
					{
						Dice.label[k] = dices[i, k];
						a[k] = dices[j, k];
					}
					if (Array.IndexOf(Dice.label, a[0]) >= 0
				&& Array.IndexOf(Dice.label, a[1]) >= 0)
					{
						Random rand = new Random();
						int count = 0;
						while (!(Dice.label[0] == a[0] && Dice.label[1] == a[1]) && count < 1333)
						{
							int b = (int)(rand.NextDouble() * 100000);
							Dice.Roll(c[b % 4]);
							rand = new Random(b);
							count++;
						}
						bool flag = true;
						for (int k = 0; k < 6; k++)
						{
							if (Dice.label[k] != a[k]) flag = false;
						}
						if (flag) ret = false;
					}
				}
			}
			Console.WriteLine(ret ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 20376
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    string s1, s2;
    cin>>s1;
    cin>>s2;
    int n1 = s1.size(), n2 = s2.size();
    vector<vector<int>> dp(n1+1,vector<int>(n2+1,0));
    for(int i=1;i<=n1; i++){
        for(int j=1;j<=n2;j++){
            if(s1[i-1]==s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string res = "";
    int i = n1, j = n2;
    while (i>=1 && j>=1 && dp[i][j]!=0){
        if(i-1>=0 && dp[i-1][j]==dp[i][j])
            i--;
        else if(j-1>=0 && dp[i][j-1]==dp[i][j])
            j--;
        else{
            res += s1[i-1];
            i--;
            j--;
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
    fastio;
    float l;
    cin >> l;
    float s=l/3.0;
    double v=s*1.0*s*1.0*s;
    cout <<     fixed << setprecision(7) << v << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    ll n,t,maxd = 0,ans = 0;
    cin >> n >> t;
    vector<ll> a(n),Min(n + 1);
    Min[0] = 1e9 + 1;
    rep0(i, n){
        cin >> a[i];
        Min[i + 1] = min(a[i],Min[i]);
        maxd = max(a[i] - Min[i],maxd);
    }
    rep0(i, n)if(a[i] - Min[i] == maxd)++ans;
    pf(ans)
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll INF=10000000;
ll a[100010],b[100010];
int n;
ll cnt1,cnt2,x;;
int main() {
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++){
		x+=b[i]-a[i];
		if(a[i]<b[i]){
			if((b[i]-a[i])%2==1)cnt2++;
			cnt1+=(b[i]-a[i]+1)/2;
		}
		else if(a[i]>b[i]) cnt2+=a[i]-b[i];
	}
	if (cnt1<=x&&cnt2<=x)cout<<"Yes";
	else cout<<"No";
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int NUM_BITS = 18;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

// Returns a tuple of (l, u) s.t.
// - l is the minimum value s.t. is_upper_fn(l) is false.
// - r is the minimum value s.t. is_upper_fn(r) is true.
//
// Required:
// - is_upper_fn is a function s.t.
//   - There exists a constant c s.t. is_upper_fn(x) is true for x >= c and
//     is_upper_fn(x) is false for x < c.
// - is_upper_fn(min_value) is false.
// - is_upper_fn(max_value) is true.
//
// Verified: ABC144E
tuple<int64, int64> BinarySearch(function<bool(int64)> is_upper_fn, int64 l, int64 u) {
  while (u - l >= 2) {
    int64 m = (l + u) / 2;
    if (is_upper_fn(m)) u = m; else l = m;
  }
  return make_tuple(l, u);
}

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  int64 c;
  cin >> c;

  auto next_table = Make2DVector(NUM_BITS, n, -1);
  for (int i = 0; i < n; i++) {
    next_table[0][i] = i;
    if (i > 0) next_table[0][i] = next_table[0][i - 1];
    while (next_table[0][i] + 1 < n && xs[next_table[0][i] + 1] - xs[i] <= c) {
      next_table[0][i]++;
    }
  }

  for (int b = 1; b < NUM_BITS; b++) {
    for (int i = 0; i < n; i++) {
      next_table[b][i] = next_table[b - 1][next_table[b - 1][i]];
    }
  }

  int q_count;
  cin >> q_count;
  for (int q = 0; q < q_count; q++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (a > b) swap(a, b);

    auto is_upper_fn = [&](int k) -> bool {
      int v = a;
      for (int b = 0; b < NUM_BITS; b++) {
        if (k & (1 << b)) {
          v = next_table[b][v];
        }
      }
      return v >= b;
    };

    int l = 0;
    int u = n - 1;
    tie(l, u) = BinarySearch(is_upper_fn, l, u);
    cout << u << endl;
  }
}

Measured memory_bytes: 8696
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>X(N);
  vector<int>Xcopy(N);
  for(int i=0;i<=N-1;i++)cin>>X[i];
  Xcopy=X;
  sort(X.begin(),X.end());
  int check1=X[N/2-1];
  int check2=X[N/2];
  for(int i=0;i<=N-1;i++){
  
    if(Xcopy[i]<=check1)cout<<check2<<endl;
    else cout<<check1<<endl;
  }
  return 0;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define int long long
typedef pair<int,int>pii;
typedef vector<int> vi;
typedef vector<vi> vii;
const int mxN=1e4+5,M=1e9+7,mxW=2e4+5;
//did u check when n=1?
//is mxN correct?
int dp[mxW],n;
struct t{
    int  w,s,v;
    bool operator<(const t &o) const{
        return w+s<o.w+o.s;
    }
} a[mxN];
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].w>>a[i].s>>a[i].v;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        for(int j=a[i].s;j>=0;j--){
            dp[j+a[i].w]=max(dp[j+a[i].w],dp[j]+a[i].v);
        }
    }
    int ans=0;
    for(int i=0;i<mxW;i++)ans=max(ans,dp[i]);
    cout<<ans;


}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll a,b,c; cin>>a>>b>>c;
    vector<ll> v={a,b,c};
    sort(v.begin(), v.end(), greater<ll>());
    ll res=0;
    res+=v[0]-v[1];
    v[2]+=v[0]-v[1];
    v[1]=v[0];
    if((v[0]-v[2])%2==1) res+=2;
    res+=(v[0]-v[2])/2;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c){
        cout<<1;
    }else if(a!=b&&b!=c&&a!=c){
        cout<<3;
    }else{
        cout<<2;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;


/*
  let's try computer shogi!!!
 */

struct ab{
  long long int a;
  long long int b;
};

bool comp(const ab &ab1, const ab &ab2){
  if(ab1.a == ab2.a){
    return ab1.b > ab2.b;
  } 
  return ab1.a < ab2.a;
  
}

long long int K;
int N;
bool bits[30];
bool abits[100000][30];
long long int values[30];
long long int icchi[30];

vector<ab> abb;


int main(){
  cin >> N;
  cin >> K;
  abb.resize(N);
  for(int i=0;i<30;++i){
    values[i] = 0;
    icchi[i] = 0;
    if(K >> i & 1){
      bits[i] = true;
      //cerr<<"1 ";
    }else{
      bits[i] = false;
      //cerr<<"0 ";
    }
  }
  
  for(int i=0;i<N;++i){
    cin >> abb[i].a;
    cin >> abb[i].b;
  }

  sort(abb.begin(), abb.end(), comp);
  //cerr<<"sort"<<endl;
  for(int i=0;i<N;++i){
    for(int j=0;j<30;++j){
      if((abb[i].a >> j) & 1){
	abits[i][j] = true;
      }else{
	abits[i][j] = false;
      }
    }
  }

  //cerr<<"tag"<<endl;
  long long int ans = 0;
  
  for(int lp = 0; lp < 30; ++lp){
    long long int tans = 0;
    long long int prev = 0;

    if(lp != 0){
      if(!bits[lp]){
	continue;
      }
    }
    for(int i=0;i<N;++i){
      
      /*
      if(prev == abb[i].a){
	//cerr<<"skip "<<abb[i].a<<","<<abb[i].b<<endl; 
	continue;
      } 
      */
      prev = abb[i].a;

      if(lp!=0 && abits[i][lp]){
	//cerr<<"reject" << abb[i].a<<"in bit"<<lp<<endl;
	continue;
	
      }
      
      bool reject = false;
      int start = lp+1;
      if(lp==0){start=0;}
      for(int j=start; j<30;++j){
	if(abits[i][j] && !bits[j]){
	  reject = true;
	  //cerr<<"reject" << abb[i].a << "in bit"<<j<<endl;
	  break;
	}
      }
      if(!reject){
	tans += abb[i].b;
      }
    }
    cerr<<tans<<endl;
    if(tans > ans){
      ans = tans;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>
 
int main(void){
    double a,b,c,d,e,f;
    double x,y;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&e,&c,&d,&f) != EOF){
        x = (e*d - b*f)/(a*d - b*c);
        y = (a*f - e*c)/(a*d - b*c);
        if(x == 0) x = 0;
        if(y == 0) y = 0;
        printf("%.03lf %.03lf\n", x, y);
    }
    return 0;
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<61)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  int C[] = {500, 100, 50, 10, 5, 1};
  while (cin >> N, N) {
    int rem = 1000 - N;
    int ans = 0;
    int i = 0;
    while (rem)  {
      if (rem >= C[i]) {
        ans += rem / C[i];
        rem -= (rem / C[i]) * C[i];
      }
      i += 1;
    }
    cout << ans << endl;
  }
  return 0; 
}

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

int main() {
  string a, b;
  cin >> a >> b;
  if(a == b) {
    cout << "EQUAL" << endl;
  }
  else if(a.size() > b.size()) {
    cout << "GREATER" << endl;
  }
  else if(a.size() < b.size()) {
    cout << "LESS" << endl;
  }
  else if(a.size() == b.size() && a > b) {
    cout << "GREATER" << endl;
  }
  else if(a.size() == b.size() && a < b) {
    cout << "LESS" << endl;
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>

using namespace std;

int main() {
    int k;
    string s;

    cin >> k >> s;

    if (s.length() > k) {
        cout << s.substr(0, k)  << "..." << endl;
    } else {
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int N, Q;
vector<int> E[201000];
int val[201000];

void dfs(int cur, int p) {
    for(auto &to : E[cur]) {
        if(p != to) {
            val[to] += val[cur];
            dfs(to, cur);
        }
    }
}

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

    cin >> N >> Q;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    rep(q, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        val[p] += x;
    }

    dfs(0, -1);

    rep(i, N) {
        if(i) cout << " ";
        cout << val[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 23680
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
sum=0
for i in range(n):
  sum += b[a[i]-1]

for i in range(n-1):
  if a[i]+1==a[i+1]:
    sum += c[a[i]-1]
    
print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll D; cin >> D;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D, vector<ll>(26));
  rep(i,D) {
    rep(j,26) {
      cin >> s[i][j];
    }
  }
  vector<ll> t(D);
  rep(i,D) {
    cin >> t[i];
    t[i]--;
  }
  ll m; cin >> m;
  vector<ll> d(m), q(m);
  rep(i,m) {
    cin >> d[i] >> q[i];
    d[i]--; q[i]--;
  }
  
  vector<set<int>> st(26);
  rep(i,26) {
    st[i].insert(-1);
    st[i].insert(D);    
  }
  rep(i,D) {
    st[t[i]].insert(i);
  }

  ll res = 0;
  // ペナルティ
  vector<ll> pen(26, 0);
  rep(i,26) {
    auto it = st[i].begin();
    it++;
    while(it != st[i].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[i];
      pen[i] += x * (x + 1) / 2 * c[i];
      it++;
    }
  }
  rep(i,D) {
    res += s[i][t[i]];
  }

  rep(i,m) {
    ll old = t[d[i]];
    ll neww = q[i];
    res += s[d[i]][neww] - s[d[i]][old];
    st[old].erase(d[i]);
    st[neww].insert(d[i]);    
    // old
    res += pen[old];
    pen[old] = 0;
    auto it = st[old].begin();
    it++;
    while(it != st[old].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[old];
      pen[old] += x * (x + 1) / 2 * c[old];
      it++;
    }
    // new
    res += pen[neww];
    pen[neww] = 0;
    it = st[neww].begin();
    it++;
    while(it != st[neww].end()) {
      auto it2 = it;
      it2--;
      ll x = *it - *it2 - 1;
      res -= x * (x + 1) / 2 * c[neww];
      pen[neww] += x * (x + 1) / 2 * c[neww];
      it++;
    }
    t[d[i]] = neww;
    cout << res << "\n";
  }

  
  return 0;
}


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

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int main()
{
	int h, w;
	cin >> h >> w;
	char c[h][w];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin >> c[i][j];
		}
	}


	
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			bool flag = 0;
//			cout << "(" << j << ", " << i << ")" << endl;
			if (c[i][j] == '.') continue;
			for (int k = 0; k < 4; k++){
				int nx = j+dx[k];
				int ny = i+dy[k];
				if (0 <= nx and nx < w and 0 <= ny and ny < h){
//					cout << "(" << nx << ", " << ny << ") = " << c[ny][nx] <<  endl;
					if (c[ny][nx] == '#') flag = 1;
				}
			}
//			cout << endl;
			if (!flag){
				cout << "No" << endl;
				return 0;
			}

			
		}
	}

	cout << "Yes" << endl;

}


Measured memory_bytes: 256
n,m = map(int,input().split())
A=[list(map(int,input().split())) for i in range(m)]
#print(A)
P=list(map(int,input().split()))
B=[]
for i in range(2**n):
    B.append(format(i,'b').zfill(n))
#print(B)


ans = 0
for i in range(len(B)):
    ok = 1
    for j in range(m): # 電球
        aa = 0
        for k in range(1,len(A[j])):
            if B[i][A[j][k]-1]=="1":
                aa += 1
        #print(aa)
        if aa%2 != P[j]:
            ok=0
    if ok==1:
        ans+=1
print(ans)
    


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	int n;
	cin>>n;
  for(int i=0;i<n;i++)cout<<"ACL";
}



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

typedef long long LL;

const int N=100;

char s[N+9];
int n,m;

void into(){
  scanf("%s%d",s+1,&m);
  n=strlen(s+1);
}

LL ans;

void Get_ans(){
  int c0=0,c1=0,l,r;
  for (int i=1;i<=n;++i){
	if (s[i]^s[1]) {l=i;break;}
	++c0;
  }
  if (c0==n) {ans=(LL)n*m>>1;return;}
  for (int i=n;i>=1;--i){
	if (s[i]^s[n]) {r=i;break;}
	++c1;
  }
  int lst=l,now=0;
  for (int i=l;i<=r+1;++i)
	if (s[i]==s[lst]) ++now;
    else{
	  ans+=(LL)m*(now>>1);
	  lst=i;now=1;
	}
  if (s[1]==s[n]){
    ans+=c0>>1;
    ans+=c1>>1;
    ans+=(LL)(m-1)*(c0+c1>>1);
  }else{
	ans+=(LL)m*(c0>>1);
	ans+=(LL)m*(c1>>1);
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3772
// AOJ 3006: Chairs
// 2017.10.4 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX		100003
int p[MAX];
int sp[MAX], top;
int *q[MAX], hi[MAX], hh[MAX];
int ans[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, a, i;
	
	n = in();
	for (i = 1; i <= n; i++) {
		p[i] = a = in();
		hh[a]++;
	}
	for (i = 1; i <= n; i++) q[i] = malloc(hh[i]*sizeof(int));
//	memset(hi, 0, (n+1)<<2);
	for (i = 1; i <= n; i++) {
		a = p[i];
		q[a][hi[a]++] = i;
	}

	top = 0, a = 0;
	while (1) for (i = 1; i <= n; i++) {
		while (hi[i]) sp[top++] = q[i][--hi[i]];
		if (!ans[i] && top) {
			ans[i] = sp[--top];
			if (++a == n) goto done;
		}
    }
done:   
	for (i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 7208
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var S = Console.ReadLine();

            var red = S.Count(elem => elem == '0');
            var blue = S.Length - red;

            var answer = Math.Min(red, blue) * 2;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((L + R) >> 1)
using namespace std;
typedef long long LL;
const int N = 105;
const int mod = 1e9 + 7;
char s[2][N];
int n;
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d%s%s", &n, s[0], s[1]);
	LL ans = 6 - 3 * (s[0][0] == s[1][0]);
	// cout << ans << endl;
	for (int i = 1; i < n; ++i) {
		if (s[0][i] == s[1][i]) {
			ans *= (2 - (s[0][i - 1] != s[1][i - 1]));
		} else if (s[0][i] != s[0][i - 1] && s[1][i] != s[1][i - 1]) {
			ans *= (3 - (s[0][i - 1] == s[1][i - 1]));
		}
		while (ans >= mod) ans -= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,k;
signed main(){
	scanf("%lld%lld%lld",&n,&m,&k);
	if (n%2==0||m%2==0||k%2==0)puts("0");
	else printf("%lld",min(min(n*m,n*k),m*k));
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	static int inf = 123456789;
	static int max_coord = 200001;
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int[] X = new int[N];
		int[] Y = new int[N];
		int[] S = new int[N];
		int[] T = new int[N];
		int[] ord = new int[N];
		int[] cnt = new int[max_coord + 1];
		int[] pa = new int[max_coord * 2 + 1];
		int[] pb = new int[max_coord * 2 + 1];
		char[] D = new char[N];
		for(int i = 0; i < N; ++i) {
			String[] sp = br.readLine().split(" ");
			X[i] = Integer.parseInt(sp[0]);
			Y[i] = Integer.parseInt(sp[1]);
			D[i] = sp[2].charAt(0);
		}
		int ans = inf;
		Arrays.fill(cnt, 0);
		for(int i = 0; i < N; ++i) ++cnt[Y[i] + 1];
		for(int i = 0; i < max_coord; ++i) cnt[i + 1] += cnt[i];
		for(int i = 0; i < N; ++i) pa[cnt[Y[i]]++] = i;
		Arrays.fill(cnt, 0);
		for(int i = 0; i < N; ++i) ++cnt[X[i] + 1];
		for(int i = 0; i < max_coord; ++i) cnt[i + 1] += cnt[i];
		for(int i = 0; i < N; ++i) ord[cnt[X[pa[i]]]++] = pa[i];
		for(int i = 0; i < N; ++i) pa[i] = X[ord[i]];
		for(int i = 0; i < N; ++i) X[i] = pa[i];
		for(int i = 0; i < N; ++i) pa[i] = Y[ord[i]];
		for(int i = 0; i < N; ++i) Y[i] = pa[i];
		for(int i = 0; i < N; ++i) pa[i] = (int)D[ord[i]];
		for(int i = 0; i < N; ++i) D[i] = (char)pa[i];
		for(int i = 0; i < N; ++i) {
			S[i] = X[i] + Y[i];
			T[i] = X[i] - Y[i] + max_coord;
		}
		// CALCULATION - direction #1
		Arrays.fill(pa, -inf);
		Arrays.fill(pb, -inf);
		for(int i = 0; i < N; ++i) {
			if(D[i] == 'U') pa[X[i]] = Y[i];
			if(D[i] == 'R') pb[Y[i]] = X[i];
			if(D[i] == 'D') ans = Math.min(ans, Y[i] - pa[X[i]]);
			if(D[i] == 'L') ans = Math.min(ans, X[i] - pb[Y[i]]);
		}
		// CALCULATION - direction #2
		Arrays.fill(pa, -inf);
		Arrays.fill(pb, -inf);
		for(int i = 0; i < N; ++i) {
			if(D[i] == 'D') pa[S[i]] = T[i];
			if(D[i] == 'R') pb[S[i]] = T[i];
			if(D[i] == 'L') ans = Math.min(ans, T[i] - pa[S[i]]);
			if(D[i] == 'U') ans = Math.min(ans, T[i] - pb[S[i]]);
		}
		// CALCULATION - direction #3
		Arrays.fill(pa, -inf);
		Arrays.fill(pb, -inf);
		for(int i = 0; i < N; ++i) {
			if(D[i] == 'U') pa[T[i]] = S[i];
			if(D[i] == 'R') pb[T[i]] = S[i];
			if(D[i] == 'L') ans = Math.min(ans, S[i] - pa[T[i]]);
			if(D[i] == 'D') ans = Math.min(ans, S[i] - pb[T[i]]);
		}
		// PRINT THE ANSWER
		if(ans == inf) {
			System.out.println("SAFE");
		}
		else {
			System.out.println(ans * 5);
		}
	}
}

Measured memory_bytes: 67948
#include <stdio.h>

int f_debt(int n)
{
	n *= 1.05;
	if(n % 1000 != 0)
	{
		n = n - (n%1000) + 1000;
	}
	return n;
}

int main()
{
	int i,n,debt=100000;
	scanf("%d",&n);

	for(i=0;i<n;i++)
	{
		debt = f_debt(debt);
	}
	printf("%d\n",debt);
	return 0;
}

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


int main(){
  string a;
  cin >> a;
  ll n=a.size();
  ll ans=n*(n-1)/2;
  map<char,ll> mp;
  for(int i=0;i<n;++i){
    mp[a[i]]++;
  }
  for(auto p : mp){
    if(p.second>1){
      p.second--;
      while(p.second>0){
        ans-=p.second;
        p.second--;
      }
    }
  }
  ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    while (a!=0 || b!=0) {
        if(a < b) printf("%d %d\n", a, b);
        else printf("%d %d\n", b, a);
        scanf("%d %d", &a, &b);
    }
}


Measured memory_bytes: 2660
/*
    C - One Quadrillion and One Dalmatians
    https://atcoder.jp/contests/abc171/tasks/abc171_c
*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define ll long long // 10 ^ 18
#define forn(i, s, n) for (int i = s; i < n; i++)
#define whilen(val, n) while(n-- && cin >> val)
#define r_1(v) cin >> v
#define r_2(v1, v2) cin >> v1 >> v2

int main() {
    ll n;
    r_1(n);
    if (n >= 1 && n <= 26) cout << string(1, (char)(96 + n));
    else {
        string res = "";
        while(n > 0) {
            n--;
            char ch = ('a' + (n % 26));
            res = ch + res;
            n /= 26;
        }
        cout << res;
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    // bool state = false;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            // state = true;
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

void solve(){
    ll N, P;
    cin >> N >> P;
    map<ll, ll> primes = factor(P);

    if (N == 1) {
        cout << P << endl;
        return;
    }

    if (P == 1) {
        cout << 1 << endl;
        return;
    }

    // vector<ll> commondivisors;
    ll ans = 1;
    for (auto itr = primes.begin(); itr != primes.end(); itr++) {
        // cout << itr->first << " " << itr->second << endl;
        // if (itr->second >= N) {
        //     commondivisors.push_back(itr->first);
        // }
        ans *= (ll)pow(itr->first, (itr->second)/N);
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int N, X;
  cin >> N >> X;
  int m[100];
  int min = 10001;
  for (int i = 0; i < N; i++) {
    cin >> m[i];
    if (m[i] < min) { min = m[i]; }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    X -= m[i];
    ans++;
    if (X <= 0) { break; }
  }

  cout << ans + X / min << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char q[100001];
int main()

{
	
	gets(q);
	int sum=-1,a=0,b=0;
	for(int i=0;i<strlen(q);i++){
		if(q[i+1]!=q[i]) sum++;
	}
	cout<<sum;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

unsigned long long int N;

int main() {
	cin >> N;
	unsigned long long int power = 1;
	for (unsigned int i = 1; i <= N; ++i) {
		power = (power*i) % 1000000007;
	}
	
	cout << power;
	
	return 0;
}

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

int main() {
	long long N, M; cin >> N >> M;
	vector<long long>A(N, 1);
	vector<bool>D(N, false);
	D.at(0) = true;
	for (long long i = 0; i < M; i++) {
		long long B, C; cin >> B >> C;
		A.at(B - 1)--;
		A.at(C - 1)++;
		if (D.at(B - 1))D.at(C - 1) = true;
		if (A.at(B - 1) == 0) D.at(B - 1) = false;
	}
	long long ans = 0;
	for (long long i = 0; i < N; i++) {
		if (D.at(i)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3952
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main(){
  int n,m,a;
  while(cin>>n>>m>>a,n!=0){
    vector<int> l(n+1);
    for(int i=0;i<l.size();i++){
      l[i]=i;
    }
    vector<pair<int,pair<int,int>>> lift;
    for(int i=0;i<m;i++){
      int h,p,q;
      cin>>h>>p>>q;
      lift.push_back(make_pair(h,make_pair(p,q)));
    }
    sort(lift.rbegin(),lift.rend());
    for(int i=0;i<lift.size();i++){
      swap(l[lift[i].second.first],l[lift[i].second.second]);
    }
    for(int i=0;i<l.size();i++){
      if(l[i]==a){
        cout<<i<<endl;
      }
    }
  }
}

Measured memory_bytes: 1220
n=int(input())
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 3, 6, 9, 12, 15, 18, 21, 24, 27, 4, 8, 12, 16, 20, 24, 28, 32, 36, 5, 10, 15, 20, 25, 30, 35, 40, 45, 6, 12, 18, 24, 30, 36, 42, 48, 54, 7, 14, 21, 28, 35, 42, 49, 56, 63, 8, 16, 24, 32, 40, 48, 56, 64, 72, 9, 18, 27, 36, 45, 54, 63, 72, 81]

if n in L:
    print('Yes')
if n not in L:
    print('No')

Measured memory_bytes: 9192
import bisect

n=int(input())
s=list(map(int,input().split()))
s.sort()
a=s[-1]
index=bisect.bisect_left(s,a//2)
diff1=abs(a//2-s[index-1])
diff2=abs(a//2-s[index])
if diff1>=diff2:
    k=s[index]
else:
    k=s[index-1]
if a==k:
    k=s[0]
print(a,k)

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


def main():
    import numpy as np

    n = int(input())
    # 通常のリストを生成する感覚で使える
    a = np.array([int(ai) for ai in input().split()])
    mod = 10 ** 9 + 7
    ans = 0

    # See:
    # https://img.atcoder.jp/abc147/editorial.pdf
    # KeyInsight:
    # XORを取る操作で各ビットは干渉しないため，それぞれ独立として扱ってよい
    # XORが1となるのは，Ai != Aj，つまり0と1の組み合わせを求めることと同じ

    # numpyを使うと実装が楽になる
    # See:
    # https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d
    for i in range(60):
        # a & 1で最下位のbitが0/1を判定している

        # 0でない個数を数える
        # See:
        # https://docs.scipy.org/doc/numpy/reference/generated/numpy.count_nonzero.html
        count = np.count_nonzero(a & 1)
        # 下からiビット目: bitが0の個数×同1の個数
        ans += (2 ** i) * (n - count) * count
        # b ビット右シフト
        # See:
        # http://www.tohoho-web.com/python/operators.html
        a >>= 1

    print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48752
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int ans=0;
	string s;

	cin >> s;
	for(auto c: s){
		if( c == 'C' ) ans |= 1;
		if( c == 'F' && ans > 0 ) ans |= 2;
	}

	cout << (ans==3?"Yes":"No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){

int a,b,c;

b=0;
c=0;
int S[13],H[13],C[13],D[13]={0};
char ca;

for(b=0;b<13;b++){
S[b]=b+1;
H[b]=b+1;
C[b]=b+1;
D[b]=b+1;
}

//#########################;
scanf("%d",&c);
//#########################
for(b=0;b<c;b++){
scanf(" %c %d",&ca,&a);

//printf("a=%d,b=%d,c=%d,ca=%c\n",a,b,c,ca);

if(ca=='S'){
S[a-1]=0;
}
if(ca=='H'){
H[a-1]=0;
}
if(ca=='C'){
C[a-1]=0;
}
if(ca=='D'){
D[a-1]=0;
}

}
//########################
for(b=0;b<13;b++){
if(S[b]!=0){
printf("S %d\n",S[b]);
}
}
for(b=0;b<13;b++){
if(H[b]!=0){
printf("H %d\n",H[b]);
}
}
for(b=0;b<13;b++){
if(C[b]!=0){
printf("C %d\n",C[b]);
}
}
for(b=0;b<13;b++){
if(D[b]!=0){
printf("D %d\n",D[b]);
}
}
return 0;
}

Measured memory_bytes: 596
#!/usr/bin/python
# -*- coding: utf-8 -*-

# f = open("1124_input.txt")

while True:
    amount, require = map(int, input().split())
    if amount == require == 0: break

    dates = []

    for _ in range(amount):
        date = list(map(int, input().split()))
        if not date.pop(0) == 0:
            # print("Appending date ... {0}".format(date))
            dates.append(date)
        else:
            dates.append([0])

    # print("date list: {0}".format(dates))
    max_d = 0
    for date in dates:
        if max(date) >= max_d:
            max_d = max(date)

    meet_count = 0
    can_meet = False
    x_day = 0
    for day in range(1, max_d+1):
        temp = 0
        for date in dates:
            # print("Investing date: {0}".format(date))
            if day in date:
                # print("day {0} is in date {1}.".format(day, date))
                temp += 1

            # print("{0} people can meet in the day {1}.".format(temp, day))
        if temp >= require:
            # print("temp:{0}, meet_count:{1}, require:{2}".format(temp, meet_count, require))
            if temp > meet_count:
                # print("temp {0} > meet_count {1}".format(temp, meet_count))
                x_day = day
                meet_count = temp
                can_meet = True

    if can_meet:
        print(x_day)
    else:
        print(0)

# f.close()

Measured memory_bytes: 6724
from sys import stdin
def main():
    h, w, n = map(int, stdin.readline().split())
    r, c = map(int, stdin.readline().split())
    s = stdin.readline().strip()
    t = stdin.readline().strip()
    x = r
    y = c
    blx = 0
    brx = h + 1
    bly = 0
    bry = w + 1
    for i in xrange(n - 1, -1, -1):
        a, b = s[i], t[i]
        if b == 'U':
            if brx <= h:
                brx += 1
        elif b == 'D':
            if blx >= 1:
                blx -= 1
        elif b == 'L':
            if bry <= w:
                bry += 1
        else :
            if bly >= 1:
                bly -= 1
        if a == 'U':
            blx += 1
        elif a == 'D':
            brx -= 1
        elif a == 'L':
            bly += 1
        else:
            bry -= 1
        if brx - blx <= 1 or bry - bly <= 1:
            print 'NO'
            return
    if blx < r < brx and bly < c < bry:
        print 'YES'
    else:
        print 'NO'
main()


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

using namespace std;

long long a, b, n;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0)
        cout << (b - a) / 2;
    else cout << (b - a - 1) / 2 + 1 + min(a - 1, n - b);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long
 
int cmpfunc(const void *a, const void *b){
    return *(int *)a - *(int *)b;
}
 
int main(int argc, char **argv){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a%3==0 || b%3==0 || (a+b)%3==0) printf("Possible\n");
    else printf("Impossible\n");
    return 0;
}

Measured memory_bytes: 128
# int(input()) # 入力が1つ
n, m = map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字

prefec = [[] for _ in range(n)] 

for i in range(m):
    p, y = map(int, input().split())
    prefec[p - 1].append((y, i))

ans = [0] * m
for i in range(n):
    cities = prefec[i]
    cities.sort(key=lambda x: x[0])
    for j in range(len(cities)):
        _, index = cities[j]
        p = i + 1
        num = j + 1
        ans[index] = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(num))) + str(num)

for i in range(m):
    print(ans[i])


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

int p;

bool check(int x) {
  cout << x << endl;
  string s; cin >> s;
  if (s == "Vacant") exit(0);
  if (x%2 == p && s == "Male") return true;
  if (x%2 != p && s == "Female") return true;
  return false;
}

void solve() {
  string s; int n;
  cin >> n;
  cout << 0 << endl;
  cin >> s;
  if (s == "Vacant") return;
  if (s == "Female") p = 1;
  int lo = 0, hi = n;
  while (lo+1 < hi) {
    int mid = (lo+hi)/2;
    if (check(mid)) lo = mid;
    else hi = mid;
  }
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 852
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

  int n, d;
  cin >> n >> d;
  int x[10][10];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int dist = 0;
      for (int k = 0; k < d; k++) {
        dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      int root = (int)sqrt(dist);
      if (root * root == dist) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static char[][] field;
	static int[][] dp; 
	static int n;

	public static void main(String[] args) {
		while(read()){
			slove();
		}

	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)
			return false;
		field = new char[n+1][n+1];
		dp = new int[n+1][n+1];
		String line;
		for(int i = 1; i <= n; i++){
			line = sc.next();
			for(int j = 1; j <= n; j++){
				field[i][j] = line.charAt(j-1);
				dp[i][j] = 0;
			}
		}
		for(int k = 1; k <= n; k++){
			dp[k][0] = 1;
			dp[0][k] = 1;
			}
		return true;
	}
	static int min(int a, int b, int c){
		int temp = Math.min(a, b);
		int min = Math.min(c, temp);
		return min;
	}
	static void slove(){
		int maxWidth = 0;
		int count = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(field[i][j] == '*'){
					dp[i][j] = 0;
				}else{
					dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1])+1;
					maxWidth = Math.max(maxWidth, dp[i][j]);
				}
			}
		}
		System.out.println(maxWidth);
	}

}

Measured memory_bytes: 16000
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
class UnionFind{
    public:
    int N;
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;
    vector<int> count;
    UnionFind(int N=1){
        par.resize(N);
        diff_weight.resize(N);
        rank.resize(N);
        count.resize(N, 1);
        for(int i=0; i<N; i++) par[i] = i, rank[i] = diff_weight[i] = 0;
    }
    int root(int x){
        if(par[x]==x) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    int weight(int x){
        root(x);
        return diff_weight[x];
    }
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
    bool isSame(int x, int y){
        return root(x)==root(y);
    }

    bool merge(int x, int y, int w=0){
        w += weight(x);
        w -= weight(y);
        int rx = root(x);
        int ry = root(y);
        if(rx==ry) return false;
        if(rank[rx]<rank[ry]) swap(rx, ry), w=-w;
        if(rank[rx]==rank[ry]) ++rank[rx];
        par[ry] = rx;
        count[rx] += count[ry];
        diff_weight[ry] = w;
        return true;
    }
    int getCount(int x){
        return count[root(x)];
    }
};

int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N, M, K;
    cin>>N>>M>>K;
    vector<vector<int>> E(N, vector<int>());
    vector<vector<int>> F(N, vector<int>());
    UnionFind uf(N);
    REP(i, M){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        F[a].emplace_back(b);
        F[b].emplace_back(a);
        uf.merge(a, b);
    }
    REP(i, K){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        //bl[i] = P(a, b);
        E[a].emplace_back(b);
        E[b].emplace_back(a);
    }
    REP(i, N){
        int res = uf.getCount(i) - F[i].size() - 1;
        for(auto j: E[i]){
            if(uf.isSame(i, j)){
                res--;
            }
        }
        if(i) cout << " ";
        cout << res;
    }
    cout << endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
    char alpha;

    cin >> alpha;
    if (alpha >=  97 && alpha <= 122) {
        cout << 'a' << endl;
    } else if (alpha >= 65 && alpha <= 90) {
        cout << 'A' << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] dif = new int[n];
        for (int i = 0; i < n - 1; i++) {
            dif[i] = a[i + 1] - a[i];
        }
        dif[n - 1] = k - a[n - 1] + a[0];
        int max = dif[0];
        for (int i = 1; i < n; i++) {
            max = Math.max(max, dif[i]);
        }
        System.out.println(k - max);
        sc.close();
    }
}

Measured memory_bytes: 66236
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double distance(int a[],int b[],int p,int n){
    double d=0,max=0;

    if(p!=0){
        for(int i=0;i<n;i++){
            d += pow(abs(a[i]-b[i]),p);
        }
        d =pow(d,1.0/p);
    }
    else{
        for(int i=0;i<n;i++){
            max=abs(a[i]-b[i]);
            if (max>d){
                d = max;
            }
        }
    }


    return d;
}

int main()
{
    int n;
    int x[100],y[100];
    double d;

    cin >> n;

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

    cout<<fixed<<setprecision(5)<<distance(x,y,1,n)<<endl;
    cout<<fixed<<setprecision(5)<<distance(x,y,2,n)<<endl;
    cout<<fixed<<setprecision(5)<<distance(x,y,3,n)<<endl;
    cout<<fixed<<setprecision(5)<<distance(x,y,0,n)<<endl;

    return 0;
}






Measured memory_bytes: 3476
#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 INF 1e8 // cf. INT_MAX ≒ 2x10^9
#define ALL(a) a.begin(), a.end()
#define MAXEL max_element
#define MINEL min_element
#define POW (long long)pow
#define BIT(i) (long long)pow(2, i)
typedef long long Lint;
#define LINF 1e18 // cf. LLONG_MAX ≒ 9x10^18

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

  auto itr1 = find(ALL(s), '1');
  if (itr1 == s.end()) {
    cout << s[0] << endl;
  } else {
    auto itrNot1 = s.begin();
    //イテレータを最初に1でないところまで動かす
    while (*itrNot1 == '1') {
      itrNot1++;
    }
    if (distance(s.begin(), itrNot1) > k - 1) {
      cout << 1 << endl;
    } else {
      cout << *itrNot1 << endl;
    }
  }
}


Measured memory_bytes: 256