akhauriyash/Code-Regression huggingface dataset:
#解説方針#解法1
#https://qiita.com/ZhangChaoran/items/71fab0e4b8647a93d3a0
from collections import deque
from heapq import heappop, heappush
#標準入力
N = int(input())
MOD = 10 ** 9 + 7
L = [[] for i in range(N + 1)] #dfs用
for i in range(N - 1):
  a, b = map(int, input().split())
  L[a].append(b)
  L[b].append(a)

#木の探索
parent = [0] * (N + 1)
order = []
stack = [1]
while stack:
    x = stack.pop()
    order.append(x)  # 行きがけ順探索リスト
    for y in L[x]:
        if y == parent[x]:
            continue
        parent[y] = x  # 親ノードを記録
        stack.append(y)
#print(order, parent)

half = pow(2, MOD - 2, MOD)
power_inv = [1] * (N + 1)#2 ** N の逆元の集合
size = [1] * (N + 1)
for i, v in enumerate(order[::-1], 1):#iが1から
    p = parent[v]
    x = size[v]  # vの子孫ノード数（自分も含む）をとる
    size[p] += x  # 親にノード数を加算
    power_inv[i] = power_inv[i - 1] * half % MOD  # [1, 1/2, 1/4, ...]
#print(size)
# 辺iがSに含まれるための必要十分条件による辺の個数の期待値 
# (1 - (1/2) ** i)(1 - (1/2) ** (N - i))を展開して計算
# 根である1の頂点以外は、ある頂点とその親を結ぶ辺を考えた際
# i と N - i個の頂点に別れるので,size[2:]でOK
ans = sum((1 - power_inv[i] - power_inv[N - i] + power_inv[N]) %
          MOD for i in size[2:])  
#ans = sum((1 - (1/2) ** i- (1/2) ** (N - i) + (1/2) ** N) for i in size[2:])  
#print(ans)
ans += 1  # 木の頂点の個数は辺の個数+1
# -「すべての辺が含まれない、つまり空グラフの場合の誤加算」-N/2
ans -= power_inv[N] + N * power_inv[1]  
#ans -= N * power_inv[1]  
ans %= MOD

print(ans)

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

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

	vector<int> v(26, 0);
	for(int i = 0; i < s.length(); i++)
		v[s[i] - 'a']++;

	bool b = 1;
	for(int i = 0; i < 26; i++){
		if(v[i] & 1){
			b = 0;
			cout << "No" << endl;
			break;
		}
	}
	if(b)
		cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
n,w = map(int,input().split())
v = [0]*n
for i in range(n):
    v[i] = list(map(int,input().split()))
    
dp = [[float("Inf") for j in range(1000*n+1)] for i in range(n+1)]

for i in range(n+1):
    dp[i][0] = 0

for i,[W,V] in enumerate(v):
    for j in range(1000*n):
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        if dp[i][j] + W <= w:
            dp[i+1][j+V] = min(dp[i+1][j+V], dp[i][j] + W)
ans = 0
for i in range(1, n+1):
    for j in range(1000*n+1):
        if dp[i][j] <= w:
            ans = max(ans, j)
print(ans)

Measured memory_bytes: 226884
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int n, x, y;
  cin>>n>>x>>y;
  x--;y--;
  int dis[2010][2010] = {};
  REP(i, n){
    REP(j, n){
      dis[i][j] = abs(i - j);
      dis[i][j] = min(dis[i][j], abs(i-x) + abs(y-j) + 1);
      dis[i][j] = min(dis[i][j], abs(i-y) + abs(x-j) + 1);
    }
  }
  int ans[2010] = {};
  REP(i, n){
    REP(j, n){
      ans[dis[i][j]]++;
    } 
  }
  REPP(k, n-1){
    int res = ans[k] / 2;
    cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 16000
#include <stdio.h>
#include <iostream>
#include <algorithm>

int n;

using namespace std;


int main(){
    int a,b;
    bool first = true;
    while(cin>>a>>b){
        if(a==0&&b==0)break;
        else  if(first){
            first=false;
        }else{
            cout<<endl;
        }
        
        bool flag=true;
        
        for(int i=a; i<=b; i++){
            if(i%400==0){
                cout<<i<<endl;
                flag=false;
            }else if(i%100==0){
                
            }else if( i%4==0){
                cout<<i<<endl;
                flag=false;
            }
        }
        
        if(flag)cout<<"NA"<<endl;
       
    }
}

Measured memory_bytes: 1160
H, N = 0, 0
while (H < 1 or H > 10**9) and (N < 1 or N > 10**5):
  H, N = input().split()
  H, N = int(H), int(N)
#A = []
flag = False
while flag == False:
  A = input().split()
  flag = (sum([((int(i) >= 1) and (int(i) <= 10**4)) for i in A]) == len(A) and N == len(A))

A = [int(s) for s in A]

for a in A:
  H -= a

ans = ('Yes' if H <= 0 else 'No')
print(ans)



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

using namespace std;

int N;
string S;
int K;

int main()
{
  cin >> N >> S >> K;
  char mask = S[K-1];
  for(int i = 0; i < N; ++i) {
    if(S[i] != mask)
      S[i] = '*';
  }
    cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int tmp, a, b, c, d;
    std::cin >> tmp;

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

    while (1)
    {
        if (a + b + c + d == 7)
        {
            std::cout << a << "+" << b << "+" << c << "+" << d << "=7" << std::endl;
            break;
        }
        if (a + b + c - d == 7)
        {
            std::cout << a << "+" << b << "+" << c << "-" << d << "=7" << std::endl;
            break;
        }
        if (a + b - c + d == 7)
        {
            std::cout << a << "+" << b << "-" << c << "+" << d << "=7" << std::endl;
            break;
        }
        if (a + b - c - d == 7)
        {
            std::cout << a << "+" << b << "-" << c << "-" << d << "=7" << std::endl;
            break;
        }
        if (a - b + c + d == 7)
        {
            std::cout << a << "-" << b << "+" << c << "+" << d << "=7" << std::endl;
            break;
        }
        if (a - b + c - d == 7)
        {
            std::cout << a << "-" << b << "+" << c << "-" << d << "=7" << std::endl;
            break;
        }
        if (a - b - c + d == 7)
        {
            std::cout << a << "-" << b << "-" << c << "+" << d << "=7" << std::endl;
            break;
        }
        if (a - b - c - d == 7)
        {
            std::cout << a << "-" << b << "-" << c << "-" << d << "=7" << std::endl;
            break;
        }
    }
    
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> s(N);

    bool flag = true;
    ll ans = 0;
    REP(i, N){
        cin >> s[i];
        ans += s[i];
        if(s[i]%10 != 0) flag = false;    
    }

    if(flag){
        cout << 0 << endl;
        return 0;
    }

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

    if(ans%10 != 0){
        cout << ans << endl;
        return 0;
    }
    REP(i, N){
        if(s[i]%10 != 0){
            ans -= s[i];
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

#define rep(countName, left, right) for (int countName = left; countName < right; countName++)

long long GCD(long long a, long long b)
{
    if (a % b == 0)
    {
        return b;
    }
    else
    {
        return GCD(b, a % b);
    }
}

vector<long long> CUSUM(vector<long long> &&v)
{
    int n = v.size();
    vector<long long> cusum(n);
    cusum[0] = v[0];
    rep(i, 1, n)
    {
        cusum[i] = v[i] + cusum[i - 1];
    }
    return cusum;
}

long long partSum(vector<long long> &&v, long long left, long long right)
{
    return (v[right] - v[left]);
}

using namespace std;

const int MAX = 800000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
    {
        return 0;
    }
    if (n < 0 || k < 0)
    {
        return 0;
    }

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void)
{
    long long x, y;
    long long n, k;

    cin >> x >> y;

    if ((2 * x - y) % 3 != 0)
    {
        cout << 0 << endl;
    }
    else
    {
        n = (2 * x - y) / 3;
        k = (y - n) / 2;

        // 前処理
        COMinit();

        // 計算
        cout << COM(n + k, n) % MOD << endl;
    }

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ( a % 2 == 0 || b % 2 == 0 ) {
    cout << " Even " << endl;
  }
  else {
    cout << " Odd "  << endl;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPR(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define INF 1000000000000 
#define MOD 10000007 
#define MAXR 100000 
#define PB push_back 
#define PI 3.14159265358979323846


using namespace std;

signed main(){

    int n;
    cin >> n ;
    vector<int> A(n);
    REP(i, n){
        cin >> A[i];
    }
    REPR(i,n){
        if(i==0)break;
        cout << A[i] <<" ";

    }
    
    cout << A[0] <<endl ;
    

    return 0 ;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	
	ll n,k;
	cin >> n >> k;
	ll a[1010],sum[1010];
	sum[0]=0;
	FOR(i,n){
		cin >> a[i];
		
		sum[i+1]=sum[i]+a[i];
	}
	vector<ll> v;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			v.push_back(sum[j+1]-sum[i]);
		}
	}

	for(int i=40;i>=0;i--){
		vector<ll> a;
		FOR(j,(int)v.size()){
			if(1ll<<i & v[j])a.push_back(v[j]);
		}
		if(k<=(int)a.size()){
			v=a;
		}
	}
	ll ans=(1ll<<41)-1;
	FOR(i,(int)v.size()){
		ans&=v[i];
	}

	cout << ans << endl;

}

Measured memory_bytes: 6560
n = gets.to_i
s = []
n.times { s << gets.chomp }

sorted_s = s.map { |sn| sn.chars.sort.join }.sort

counts = []
successive = 0
sorted_s.each_with_index do |sn, i|
  if sn == sorted_s[i - 1] || i == 0
    successive += 1
  else
    counts << successive
    successive = 1
  end
end
counts << successive

answer = counts.map { |n| n * (n - 1) / 2 }

puts answer.inject(:+)


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pf push_front
#define sz(x) (int)(x).size()
#define lb lower_bound 
#define ub upper_bound 
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<string> vs;
typedef unsigned long long ull;
typedef long double ld;
typedef map<int,int> mii;

const int MOD = 1e9+7;
const ll INF = 1e18; //
const ld PI = acos((ld)-1);

void solve () {
	int n;
	cin >> n;
	string str;
	cin >> str;
	int i = 0,j = n-1;
	int cnt = 0;
	while (i < j) {
		if (str[i] == 'R') ++i;
		else if (str[j] == 'W') --j;
		else {
			swap(str[i],str[j]); 
			--j,++i;
			++cnt;
		}
	}
	cout << cnt << '\n';
}

int main () {
#ifndef ONLINE_JUDGE
	freopen("input1.txt","r",stdin);
	freopen("output1.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

bool func(vector<int> &a,vector<int> &f, ll &c, int &n, ll &k){
  ll s = 0;
  rep(i,n){
    s+= max(0ll, a[i]-c/f[i]);
  }
  return s <= k;
}
int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n),f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());
  ll l = -1, r = 1e12;
  while(l+1<r){
    ll c = (l+r)/2;
    bool ok = func(a,f,c,n,k);
    if (ok) r = c;
    else l = c;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,m;
int x[100010],y[100010],z[100010];int par[100010],siz[100010];
void init(int x){
    rep(i,x){
        par[i]=i;
        siz[i]=1;
    }
}
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return;
    if(siz[x]<siz[y])swap(x,y);
    par[y]=x;
    siz[x]+=siz[y];
}
bool same(int x,int y){
    return find(x)==find(y);
}
int size(int x){
    return siz[find(x)];
}
signed main(){
    cin>>n>>m;
    init(n);
    rep(i,m){
        cin>>x[i]>>y[i]>>z[i];
        z[i]%=2;
        unite(x[i]-1,y[i]-1);
    }
    set<int>st;
    rep(i,n)st.insert(find(i));
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 8832
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<functional>
#include<algorithm>


using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;


int main(void)
{
	int n;


	while(scanf("%d", &n)==1)
	{
		vi a(n);
		map<int,int> m_odd, m_even;

		for(int i=0;i<n;i++)
		{
			scanf("%d", &a[i]);
			if(i%2)
			{
				m_odd[a[i]]++;
			}
			else
			{
				m_even[a[i]]++;
			}
		}

		vector<pii> v_odd, v_even;

		for(auto it=m_odd.begin();it!=m_odd.end();++it)
		{
			v_odd.push_back(make_pair(it->second,it->first));
		}
		sort(v_odd.rbegin(), v_odd.rend());
		v_odd.push_back(make_pair(0, -1));

		for(auto it=m_even.begin();it!=m_even.end();++it)
		{
			v_even.push_back(make_pair(it->second,it->first));
		}
		sort(v_even.rbegin(), v_even.rend());
		v_even.push_back(make_pair(0, -1));

		int ans=-1;
		if(v_odd[0].second!=v_even[0].second)
		{
			ans=n-v_odd[0].first-v_even[0].first;
		}
		else if(v_odd[0].first==v_even[0].first)
		{
			ans=n-v_odd[0].first-max(v_odd[1].first, v_even[1].first);
		}
		else
		{
			int x1=n-v_odd[0].first-v_even[1].first;
			int x2=n-v_odd[1].first-v_even[0].first;
			ans=min(x1, x2);
		}
		printf("%d\n", ans);
	}

	return 0;
}


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

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

int main (){
    char moji;
    cin >> moji;
    if((moji>= 'a') && (moji<='z')){
    printf("a\n");
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A\n");
  }
  else {
    printf("その他の文字！\n");
  }

}

Measured memory_bytes: 3628
n = int(input())
s = list(map(int, input().split()))
total = sum(s)
lower_mean = total // n
upper_mean = total // n + 1
r1 = sum([(x-lower_mean) ** 2 for x in s])
r2 = sum([(x-upper_mean) ** 2 for x in s])
r = min(r1, r2)
print(r)

Measured memory_bytes: 3060
import java.io.IOException;
import java.util.Scanner;


public class Main{
	public static void main(String args[]) throws IOException{
		Scanner bf = new Scanner(System.in);
		int N = bf.nextInt();
		for(int n=0; n<N; n++){
			boolean failed = false;
			int a = 0;
			int b = 0;
			for(int i=0; i<10; i++){
				int tmp = bf.nextInt();
				if(tmp < a && tmp < b) failed = true;
				else if(tmp > a && tmp > b){
					if(a>b) a = tmp;
					else b = tmp;
				}else if(tmp > a) a = tmp;
				else b = tmp;
			}
			if(failed) System.out.println("NO");
			else System.out.println("YES");
		}
	}
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

using namespace std;

int main() {

    int h, n;
    cin >> h >> n;

    int sum = 0;
    int a;
    rep(i, n) {
        cin >> a;
        sum += a;
    }

    string ans = "No";
    if (h <= sum)
        ans = "Yes";

    AA(ans);
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        double D = sc.nextInt();
        double T = sc.nextInt();
        double S = sc.nextInt();
        String ans = "No";
        double time = D / S;
        if(time <= T) ans = "Yes";
         System.out.println(ans);
    } 
}

Measured memory_bytes: 27060
N = int(input())
A = list(map(int, input().split()))

b = [0] * (N+1)
b[0] = 1
flag = True

for i in range(N):
    if A[i] > b[i]:
        flag = False

    b[i+1] = (b[i] - A[i]) * 2

if A[N] > b[N]:
    flag = False
ans = 0
l = 0
for i in range(N, -1, -1):
    l += A[i]
    ans += min(l, b[i])

if flag:
    print(ans)
else:
    print(-1)



Measured memory_bytes: 674384
#include <iostream>
using namespace std;
bool ch(int a,int b){
	if (a==2){
		return 0;
	}
	if (b==2){
		return 1;
	}
	if (a==1){
		return 1;
	}
	if (b==1){
		return 0;
	}
	return (a>b);
}
int main(){
	int a,b;
	cin >> a >> b;
	if (a==b){
		cout << "Draw"<<endl;
		return 0;
	}
	if (ch(a,b)==1)cout<<"Alice"<<endl;
	else cout << "Bob" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

string s;

bool ok(int l,int r){
	for(int i=l;i<r;i++){
		if(s[i]=='#'&&s[i+1]=='#')return false;
	}
	return true;
}
int main(){
	int n;cin>>n;
	int a,b,c,d;cin>>a>>b>>c>>d;a--;b--;c--;d--;
	cin>>s;
	if(c<b){
		if(ok(a,c)&&ok(b,d)){
			puts("Yes");
		}
		else puts("No");
	}
	else if(a<b&&b<c&&c<d){
		if(ok(b,d)&&ok(a,c)){
			puts("Yes");
		}
		else puts("No");
	}
	else{
		if(!ok(a,c)||!ok(b,d)){
			puts("No");return 0;
		}
		bool flag=false;
		for(int i=b;i<=d;i++){
			if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
				flag=true;
			}
		}
		if(flag){
			puts("Yes");
		}
		else puts("No");
	}
}

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

const int N = 100000 + 5;

int dp[N];


int solve(int src, vector<vector<int>>& v) {
	if (dp[src] != -1)return dp[src];

	if (v[src].size() == 0){
		dp[src] = 0;
		return dp[src];
	}

	int ans = 0;

	for (auto x : v[src]) {
		if (dp[x] == -1)solve(x, v);
	}

	for (auto x : v[src]) {
		ans = max(ans, dp[x]);
	}


	dp[src] = ans + 1;
	return dp[src];

}

int32_t main() {
  
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v(n + 1);
	int i, j;
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
	}

	fill(dp,dp+n+1,-1);

	int ans = 0;

	for (i = 1; i <= n; i++) {
		solve(i, v);
	}

	for (i = 1; i <= n; i++)ans = max(ans, dp[i]);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define pr printf
#define sc scanf

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef long double ld;
int a, b;
int main () {
    sc("%d %d", &a, &b);
    if(abs(a-b) & 1) pr("IMPOSSIBLE\n");
    else pr("%d\n", (a+b)/2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll H, W;
  cin >> H >> W;
  ll ans;
  if (H==1||W==1) ans = 1LL;
  else if (H%2==0||W%2==0) ans = H*W/2;
  else ans = H*W/2+1;
  cout << ans << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;

int main() {
	int t,n;

	for(int i=0;i<4;i++){
		cin>>t>>n;
		if(t==1)cout<<n*6000<<endl;
		if(t==2)cout<<n*4000<<endl;
		if(t==3)cout<<n*3000<<endl;
		if(t==4)cout<<n*2000<<endl;
	}

	return 0;
}

Measured memory_bytes: 3080
import itertools
import math
N = int(input())
ps = list(itertools.permutations(range(N)))
sum_dist = 0

coos = []
for i in range(N):
    x, y = map(int, input().split())
    coos.append((x, y))

def dist(a, b):
    x1, y1 = a
    x2, y2 = b
    d = math.sqrt((x1-x2)**2 + (y1-y2)**2)
    return d

for p in ps:
    sum_val = 0.0
    for i in range(N-1):
        sum_val += dist(coos[p[i]], coos[p[i+1]])
    sum_dist += sum_val

print(sum_dist / len(ps))


Measured memory_bytes: 7972
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = mapM_ solve =<< (getc $ split toInt)

solve :: [Int] -> IO ()
solve [p,q] = case c of
  Just p -> putStrLn a >> putStrLn p
  Nothing -> putStrLn a
  where
    (a,c) = divNum [] [p] p q
    
divNum :: [Int] -> [Int] -> Int -> Int -> (String, Maybe String)
divNum as rs p q
  | m == 0 = ((concatMap show . reverse) (d:as), Nothing)
  | m `elem` rs = ((concatMap show . reverse) (d:as), Just ( replicate (length as - idx) ' ' ++ replicate (idx+1) '^'))
  | otherwise = divNum (d:as) (m:rs) m q
  where
    (d,m) = divMod (10 * p) q
    idx = maybe 0 id . findIndex (== m) $ rs
    
toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=false;

    ll ans=0,sum=0;

    int n;
    cin >>n;

    vector<ll> a(n),cr;

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

    int i=0;
    while (1){
        ll crust = 0;
        while (a[i] != 0 && i < n){
            crust += a[i];
            ++i;
        }
        cr.emplace_back(crust);
        if(i >= n)break;
        ++i;
    }

    for(ll c:cr){
        ans += c/2;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


/*
1 #
2 #
3 #
4 #
*/

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

int main(void)
{
    int n, p; cin >> n >> p;
    string s; cin >> s;
    if (p == 2 || p == 5)
    {
        int d;
        long long ans = 0;
        for (int i = 0; i < n; i++)
        {
            d = s[i] - '0';
            if (d % p == 0) ans += i + 1;
        }
        cout << ans << endl;
        return 0;
    }
    long long cnt_mod[10002] = {0};
    cnt_mod[0]++;
    int d = 0, q = 10;
    for (int i = n; i > 0; i--)
    {
        d = d + q * (s[i-1] - '0');
        d = d % p;
        cnt_mod[d]++;
        q = (q * 10) % p;
    }
    long long ans = 0;
    for (long long c:cnt_mod)
        ans += c * (c - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());

  for (int i = 0; i < s.length() && i < t.length(); i++)
  {
    if (s[i] < t[i])
    {
      cout << "Yes" << endl;
      return 0;
    }
    else if (s[i] > t[i])
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << (s.length() < t.length() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 2980
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>n;--i)

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,i;
    ll f=0;
    
    cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i] ;
    rep(i,n)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3==0||a[i]%5==0) continue;
            else 
            {
                f=1;
                break;
            }
            
        }
    }
    if(f==0) cout << "APPROVED" << endl ;
    else cout << "DENIED" << endl ;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
typedef long double ld;

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

    int count = 0;
    vector<vector<ld>> v;
    for (int i = 0; i < n; i++) {
        ld x, y;
        cin >> x >> y;
        if (x != 0 || y != 0) {
            count++;
            ld theta = atan2(y, x);
            v.push_back({theta - 2 * M_PI, x, y});
            v.push_back({theta, x, y});
            v.push_back({theta + 2 * M_PI, x, y});
        }
    }
    sort(v.begin(), v.end());

    long long ret = 0;
    for (int i = 0; i < v.size(); i++) {
        vector<long long> now(2);
        for (int j = i; j < v.size() && j - i + 1 <= count; j++) {
            now[0] += v[j][1], now[1] += v[j][2];
            ret = max(ret, now[0] * now[0] + now[1] * now[1]);
        }
    }
    cout << fixed << setprecision(20) << sqrt(ret) << endl;
    return 0;
}

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

#define pb push_back
using namespace std;
 
int main()
{
 


    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

 	
    int n,m;
    cin>>n>>m;
    vector<int> ar(n);
    int totalvotes=0;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        totalvotes+=ar[i];
    }
    int Min;
    if(totalvotes%(4*m))
    {
        Min=(totalvotes/(4*m))+1;
    }
    else
    {
        Min=(totalvotes/(4*m));
    }
    
    sort(ar.rbegin(),ar.rend());

    if(ar[m-1]>=Min)
        cout<<"Yes";
    else
        cout<<"No";


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct rob
{
	int x, l;
}a[maxn];
int b[maxn], f[maxn];
int n, ans;
bool cmp(const rob & a, const rob & b) { return a.x + a.l < b.x + b.l;}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &a[i].x, &a[i].l);
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; ++i) b[i] = a[i].x + a[i].l;
	for(int i = 1; i <= n; ++i)
	{
		int j = upper_bound(b + 1, b + i, a[i].x - a[i].l) - b - 1;
		f[i] = max(f[i - 1], f[j] + 1);
		ans = max(f[i], ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1792
import Control.Applicative
import Control.Monad


fromTimeToSec :: [Int] -> Int
fromTimeToSec [] = 0
fromTimeToSec (h:m:s:_) =
  let hsec = h * 3600
      msec = m * 60
  in
      hsec + msec + s
fromTimeToSec [_] = 0
fromTimeToSec [_, _] = 0

fromSecToTime :: Int -> [Int]
fromSecToTime sec =
  let s = sec `mod` 60
      m = (sec `mod` 3600) `div` 60
      h = sec `div` 3600
  in [h, m, s]

fromStoE :: [Int] -> [Int]
fromStoE [] = []
fromStoE (a:b:c:xs) = fromTimeToSec [a, b, c] : fromStoE xs
fromStoE [_] = []
fromStoE [_, _] = []

solver :: [[Int]] -> [[Int]]
solver [] = []
solver (x:xs) =
  let (b:e:_) = fromStoE x
      work = e - b
  in
      fromSecToTime work : solver xs

main :: IO()
main = do
  input <- map (map (read :: String -> Int) . words) <$> replicateM 3 getLine
  mapM_ ((putStrLn . unwords) . map show) (solver input)

Measured memory_bytes: 3700
package main

import (
	"fmt"
	"math"
)

func primeFactors(n int) []int {
	factors := make([]int, 0)
	i := 2
	for i*i <= n {
		r := n % i
		if r != 0 {
			i++
		} else if r == 0 {
			n /= i
			factors = append(factors, i)
		}
	}
	if n > 1 {
		factors = append(factors, n)
	}
	return factors
}

func main() {
	// Code for C - Factors of Factorial
	var N int
	fmt.Scan(&N)

	ans := make(map[int]int, 1000)
	for {
		if N == 1 {
			break
		} else {
			a := make([]int, 0)
			a = primeFactors(N)
			for i := 0; i < len(a); i++ {
				ans[a[i]]++
			}
			N--
		}
	}

	var sum int = 1
	for _, v := range ans {
		sum *= (v + 1)
		sum %= (int(math.Pow10(9)) + 7)
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1908
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.ss == b.ss) {
        return (a.ff < b.ff);
    }
    return (a.ss<b.ss);
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;

    return res;
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[100001];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}

//Define mx for maximum range and MOD for large numbers
#define mx 100004
#define MOD 1000000007;
// Declare all the variables and global functions here - 
int n;

int32_t main()
{
    IOS;
 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
	// #endif
    /********************* From here **********************/
    
    int a,p;
    cin >> a >> p;
    int t = a*3+p;
    cout << t/2 << endl;
    
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let mod_ = 1_000_000_007;
    let nxyz: Vec<usize> = get_vec();
    let (n, x, y, z) = (nxyz[0], nxyz[1], nxyz[2], nxyz[3]);
    let g = 1 << 16;
    let mut dp = vec![vec![0;g];n+1];
    dp[0][0] = 1;

    let v = validator(x, y, z);

    for i in 0..n {
        for j in 0..10 {
            for k in 0..g {
                let a = ((k << 1) + 1) << j;
                if ok(a, v) {
                    dp[i+1][a%g] += dp[i][k];
                    dp[i+1][a%g] %= mod_;
                }
            }
        }
    }

    let mut m: i64 = 1;
    for _ in 0..n {
        m *= 10;
        m %= mod_;
        m += mod_;
    }

    println!("{}", (m - dp[n].iter().fold(0, |acc, x| (acc+x)%mod_) + mod_) % mod_);

}

fn validator(x: usize, y: usize, z: usize) -> usize {
    let mut v = 1;
    v = v << x;
    v += 1;
    v = v << y;
    v += 1;
    v = v << z;
    v >> 1
}

fn ok(a: usize, v: usize) -> bool{
    v != (a & v)
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 30972
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    string s;
    cin >> s;
    if (s.at(s.length()-1)=='s')
    {
        cout << s << "es" << endl;
    }
    else
    {
        cout << s << 's' << endl;
    }
    
}

Measured memory_bytes: 3632
#include<stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],/*行*/ col[N]/*列*/;
int dpos[2*N-1],dneg[2*N-1]; /*dpos:左下方向 dneg:右下方向*/

int X[N][N];

void Initialize(); //初期化
void PrintBoard();
void recursive(int); //再帰


int main(){
  int i, j;
  int k, r, c;
  /*1行目に整数 k が与えられます。続く k 行にクイーンが配置されているマスが2つの整数 r, c で与えられます。r, c はそれぞれ0から始まるチェス盤の行と列の番号を表します。*/
  
  Initialize();

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      X[i][j] = -1;
    }
  }

  scanf("%d",&k);
  for(i = 0 ; i < k ; i++){
    scanf("%d %d",&r,&c);
    X[r][c] = 1;
  }

  recursive(0);

  return 0;
}

void Initialize(){
  int i;

  for(i = 0 ; i < N ; i++){
    row[i] = FREE;
    col[i] = FREE;
  }

  for(i = 0 ; i < 2 * N - 1 ; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void PrintBoard(){
  int i, j;

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(X[i][j] == 1){
	if(row[i] != j) return;
      }
    }
  }

  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;

  if(i == N){
    PrintBoard();
    return;
  }

  for(j = 0 ; j < N ;j++){
    if(col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i - j + N - 1] == NOT_FREE) continue;

    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + N -1] = NOT_FREE;

    recursive(i + 1);

    row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
  }
}



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



int main() 
{ 
int n;
cin >> n;
int a=0,b=0,c=0,d=0;
while(n>0)
{
     string str;
     cin >> str;
     if(str=="AC") a+=1;
     if(str=="WA") b+=1;
     if(str=="TLE") c+=1;
     if(str=="RE") d+=1;
     n--;
     
}
cout << "AC" << " " << "x" <<" " << a << endl;
cout << "WA" << " " << "x" <<" " << b << endl;
cout << "TLE" << " " << "x" <<" " << c << endl;
cout << "RE" << " " << "x" <<" " << d << endl;

     return 0; 
     
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    int x,y;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        a[i]=x-y;
    }
    x=2;
    for(int i=0;i<n-2;i++){
        if(a[i]==0){
            if(a[i+1]==0 && a[i+2]==0){
                x=0;
            }
        }
    }
    if(x==0){
        cout<<"Yes";
    }else
    cout<<"No";
}


Measured memory_bytes: 3536
///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Size(x) (int)(x).size()
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int y,m,d;char x;
    cin >> y >> x >> m >> x >> d;
    if(y > 2019){
    	cout << "TBD" << '\n';
    }
    else if(y < 2019) cout << "Heisei" << '\n';
    else{
    	if(m>4) cout << "TBD" << '\n';
    	else if(m<4) cout << "Heisei" << '\n';
    	else{
    		if(d>30){
    			cout << "TBD" << '\n';
    		}
    		else{
    			cout << "Heisei" << '\n';
    		}
    	}

    }
    
    
    return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Stdin, BufRead};

fn main() {
    let stdin = stdin();
    let args = read(&stdin);
    let args = args.split_whitespace();
    let args = args.into_iter().map(|s| s.parse().unwrap()).collect::<Vec<i32>>();
    let n = args[0];
    let a = args[1];
    let b = args[2];

    let mut numbers = Vec::new();
    for i in a..n+1 {
        let mut sum = 0;
        let mut res = i;
        loop {
            let modulo = res % 10;
            sum += modulo;

            res = (res / 10) as i32;
            if res < 10 {
                sum += res;
                break;
            }
        }

        if a <= sum && sum <= b {
            numbers.push(i);
        }

    }
    println!("{}", numbers.iter().sum::<i32>());
}

fn read(stdin: &Stdin) -> String {
    let mut buf = String::new();
    stdin.lock().read_line(&mut buf).unwrap();
    buf
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int n;
	cin >> n;

	string s;
	cin >> s;

	int cw = 0;
	for (char x: s)
		if (x == 'W')
			cw++;

	int cmw = 0;
	for (int i = n-cw; i < n; i++)
		if (s[i] == 'W')
			cmw++;

	// deb(n-cw-1);
	// deb(cw);
	// deb(cmw);

	cout << cw - cmw;

	return 0;
}

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

int n, m, p;
int dx[] = {1,0,0,1,1,0,1,1,0,1,-1,1,1};
int dy[] = {0,1,0,1,0,1,-1,0,1,1,1,-1,1};
int dz[] = {0,0,1,0,1,1,0,-1,-1,1,1,1,-1};
int  d[] = {1,-1};
int H[7][7], F[7][7][7];
string V[] = {"Black", "White"};

bool judge(int x, int y, int z, int mark, int m){
  for(int j = 0; j < 13; ++j){
    int c = 1;
    for(int i = 0; i < 2; ++i){
      int x2 = x + d[i]*dx[j];
      int y2 = y + d[i]*dy[j];
      int z2 = z + d[i]*dz[j];
      while(x2 >= 0 && x2 < n && y2 >= 0 && y2 < n && z2 >= 0 && z2 < n && F[x2][y2][z2] == mark){
	x2 += d[i]*dx[j];
	y2 += d[i]*dy[j];
	z2 += d[i]*dz[j];
	++c;
      }
    }
    if(c >= m) return true;
  }
  return false;
}

int main(){
  while(cin >> n >> m >> p, n){
    for(int i = 0; i < 7; ++i){
      for(int j = 0; j < 7; ++j){
	H[i][j] = 0;
	for(int k = 0; k < 7; ++k){
	  F[i][j][k] = -1;
	}
      }
    }

    int x, y, z, X[p], Y[p], mark;
    for(int i = 0; i < p; ++i) cin >> X[i] >> Y[i];

    bool f = true;
    for(int i = 0; i < p; ++i){
      x = X[i]-1;
      y = Y[i]-1;
      z = H[x][y];
      mark = i%2;
      F[x][y][z] = mark;
      if(judge(x,y,z, mark, m)){
	cout << V[mark] << " " << i+1 << endl;
	f = false;
	break;
      }
      ++H[x][y];
    }
    if(f) cout << "Draw" << endl;
  }
  return 0;
}

Measured memory_bytes: 3160
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = lc()

left = 0
right = 0

cnt = 0

for si in s:
    if si == "(":
        right += 1
        
    elif si == ")":
        right -= 1
        
    if right < 0:
        left += 1
        right = 0
        
print("("*left + "".join(s) + ")"*right)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;


int main()
{
	map<int, int> memo;
	int p = 1234567;
	memo[p] = 0;
	queue<int> q;
	q.push(p);
	while (!q.empty())
	{
		int prev = q.front();
		q.pop();

		int puzzle[8];
		int t = prev;
		for (int i = 7; i >= 0; --i, t /= 10)
			puzzle[i] = t % 10;

		int zeroPos;
		for (zeroPos = 0; puzzle[zeroPos]; ++zeroPos)
			;

		const int d[] = { -1, 1, 4, -4 };
		for (int i = 0; i < 4; ++i)
		{
			int swapPos = zeroPos + d[i];
			if (swapPos < 0 || swapPos >= 8
				|| zeroPos == 3 && d[i] == 1
				|| zeroPos == 4 && d[i] == -1)
				continue;

			int copy[8];
			memcpy(copy, puzzle, sizeof(copy));
			swap(copy[zeroPos], copy[swapPos]);
			int next = 0;
			for (int j = 0; j < 8; ++j)
				next = next*10 + copy[j];

			if (!memo.count(next))
			{
				memo[next] = memo[prev] + 1;
				q.push(next);
			}
		}
	}
	while (true)
	{
		char buf[128];
		cin.getline(buf, sizeof(buf));
		if (strlen(buf) == 0)
			break;
		istringstream is(buf);
		int p = 0;
		for (int i = 0; i < 8; ++i)
		{
			int t;
			is >> t;
			p = p*10 + t;
		}
		printf("%d\n", memo[p]);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 2e5 + 50;
const ll mod = 1e9+7;
int a[maxn], h[maxn];
ll ans, dp[maxn], C[2*maxn];
int n;
int lowbit(int x) {return -x & x;}
void upd(int id, ll val){
    while(id < 2 * maxn){
        C[id] = max(C[id], val);
        id += lowbit(id);
    }
}
ll pre(int x){
    ll res = 0;
    while(x){
        res = max(res, C[x]);
        x -= lowbit(x);
    }
    return res;
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &h[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++){
        dp[i] = pre(h[i]) + a[i];
        ans = max(ans, dp[i]);
        upd(h[i], dp[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6016
import math

a,b,x = map(int,input().split())

if x > a*a*b//2:
    h = ((a*a*b-x)/(a*a)) * 2
    #print(h)
    theta = math.atan(h/a)
    #print(h/a)
    print(math.degrees(theta))

else:
    h = x*2 / (a*b)
    theta = math.atan(h/b)
    print(90 - math.degrees(theta))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
using namespace std;
 
int main() {
	int a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b;
    }else{
        cout<<b-a;
    }
	return 0;
}

Measured memory_bytes: 256