akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    char a, b;

    cin >> a >> b;

    if (a > b) {
        cout << ">" << endl;
    }
    else if (a < b) {
        cout << "<" << endl;
    }
    else {
        cout << "=" << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main
{
    static int dp[][];
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        int arr[][]=new int[n][3];
        for(int i=0;i<n;i++)
        {
            String str[]=br.readLine().split(" ");
            int a=Integer.parseInt(str[0]);
            int b=Integer.parseInt(str[1]);
            int c=Integer.parseInt(str[2]);
            int ele[]={a,b,c};
            arr[i]=ele;
        }
        dp=new int[arr.length][4];
        for(int i=0;i<dp.length;i++)
            for(int j=0;j<dp[0].length;j++)
                dp[i][j]=-1;
        System.out.println(calculate(arr,0,-1));


    }

    private static int calculate(int[][] arr, int index, int prev) {
        if(index>=arr.length)
            return 0;
        if(dp[index][prev+1]!=-1)
            return dp[index][prev+1];
        if(prev==-1)
            return dp[index][prev+1]= Math.max(arr[index][0]+calculate(arr,index+1,0),Math.max(arr[index][1]+calculate(arr,index+1,1),arr[index][2]+calculate(arr,index+1,2)));
        if(prev==0) {
            return dp[index][prev+1]= Math.max(arr[index][1] + calculate(arr, index + 1, 1), arr[index][2] + calculate(arr, index + 1, 2));
        }
            else if(prev==1)
        {
            return dp[index][prev+1]= Math.max(arr[index][0] + calculate(arr, index + 1, 0), arr[index][2] + calculate(arr, index + 1, 2));
        }
            else
            return dp[index][prev+1]= Math.max(arr[index][1] + calculate(arr, index + 1, 1), arr[index][0] + calculate(arr, index + 1, 0));


    }
}

Measured memory_bytes: 73124
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int  mod=1e9+7;
int pr[1005];
int vis[1005];

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int ans=1;
    for(int i=2;i<=1000;i++)
    {
        if(vis[i]==0)
        {
            pr[i]=1;
            for(int j=i;j<=1000;j+=i)
                vis[j]=1;
        }
    }
    for(int i=2;i<=n;i++)
    {
        if(!pr[i])
            continue;
        int z=n;
        int cnt=0;
        while(z!=0)
        {
                cnt+=z/i;
                z/=i;
        }
        ans=(ans*(cnt+1))%mod;
    }
    cout<<ans;

} 


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

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int s=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			s+=a[i]*a[j];
		}
	}
	cout<<s;
	return 0;
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define M 1000
 
int A[M+1][M+1];
int longest(char x[M+1],char y[M+1]){
  int i,j,a,b;
  a = strlen(x);
  b = strlen(y);
  for(i  = 1;i<=a; i++){
    for(j = 1; j <= b; j++){
      if(x[i-1] == y[j-1])A[i][j]=A[i-1][j-1] + 1;
      else if(x[i-1] != y[j-1])A[i][j] = max(A[i-1][j],A[i][j-1]);
    }
  }
  return A[a][b];
}
 
int max(int a,int b){
  if(a>= b)return a;
  else if(a < b)return b;
}
 
int main(){
  int i,n;
  char x[M+1],y[M+1];
  scanf("%d", &n);
  for(i = 0;i<n;i++){
    scanf("%s", x);
    scanf("%s",y);
    printf("%d\n", longest(x,y));
  }
 
  return 0;
}

Measured memory_bytes: 4524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

const ll MAX = 510000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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;
}

struct Info{
    Info(ll arg_to,ll arg_cost){
        to = arg_to;
        cost = arg_cost;
    }
    bool operator<(const struct Info &arg) const{
            return cost > arg.cost;
    };
    ll to,cost;
};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x;
    cin>>x;
    ll coun=(x/11)*2,y=x%11;
    ll i=0;
    while(y>0){
        if(i%2==0) y-=6;
        else y-=5;
        coun++;
        i++;
    }
    cout<<coun<<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++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  string s;cin>>s;
  int n=s.size();
  int x=1e9,y=0;
  rep(i,n){
    if(s[i]=='A')x=min(x,i+1);
    if(s[i]=='Z')y=max(y,i+1);
  }
  cout<<y-x+1<<endl;
}

Measured memory_bytes: 3676
// 'That's all it is. A leap of faith'

#include <bits/stdc++.h>

#define append push_back
#define L first
#define R second

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

template<typename Type>
long long sz(Type x) {
    return ll(x.size());
}

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

long long dp[N << 1], f[N << 1];

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, k; cin >> n >> k;

    vector<pair<long long, long long>> s(k);

    for(long long i = 0; i < k; i++) {
        cin >> s[i].L >> s[i].R;
    }

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

    dp[1] = 1;
    for(long long i = 1; i <= n; i++) {
        (f[i] += f[i - 1]) %= MOD;
        (dp[i] += f[i]) %= MOD;
        for(long long j = 0; j < k; j++) {
            long long l = i + s[j].L, r = min(i + s[j].R, n) + 1;
            if(l <= n) {
                (f[l] += dp[i]) %= MOD;
                (f[r] += MOD - dp[i]) %= MOD;
            }
        }
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 6708
n=int(input())
m=int(input())
s=list(map(int,input().split()))
ss=[0]*n

for f in range(m):
    z=list(map(int,input().split()))
    count=0
    for k in range(n):
        if z[k]==s[f]:
            ss[k]+=1
        else:
            count+=1
    ss[s[f]-1]+=count
for i in range(n):
    print(ss[i])
    



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
string S,T;
cin >> S >> T;
int count = 0;
for (int i = 0;i < 3;i++) {
    if (S.at(i) == T.at(i)) count++; 
}

cout << count << endl;

return 0;
}


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

#define int long long
int h , w , k ;
int32_t main(){
	cin >> h >> w >> k ;
	vector<vector<char>> ch(h,vector<char>(w)) ;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			cin >> ch[i][j] ;
		}
	}
	int cnt = 0 ;
	for(int i = 0 ; i < (1LL<<h) ; i++){
		for(int j = 0 ; j < (1LL<<w) ; j++){
			auto tp = ch ;
			for(int k = 0 ; k < h ; k++){
				if((1LL<<k)&i){
					for(int x = 0 ; x < w ; x++){
						tp[k][x] = '.' ;
					}
				}
			}
			for(int k = 0 ; k < w ; k++){
				if((1LL<<k)&j){
					for(int x = 0 ; x < h ; x++){
						tp[x][k] = '.' ;
					}
				}
			}
			int val = 0 ;
			for(auto x : tp){
				val += count(x.begin() , x.end() , '#') ;
			}
			cnt += (val == k) ;
		}
	}
	cout << cnt ;
	return 0 ;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> G;
vector<int> ans;

int main(){
    int n, m; cin >> n >> m;
    G.resize(n);
    ans.assign(n, -1);
    rep(i,m){
        int a, b; cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    //priority_queue<P, vector<P>, greater<P>> q;
    queue<int> q;
    q.push(0);
    ans[0] = 0;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(auto nv : G[v]){
            if(ans[nv] != -1) continue;
            q.push(nv);
            ans[nv] = v;
        }
    }
    bool isOK = true;
    for(int i = 0; i < n; i++){
        if(ans[i]==-1) isOK = false;
    }
    if(!isOK){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        for(int i = 1; i < n; i++){
            cout << ans[i]+1 << endl;
        }
    }
}

Measured memory_bytes: 10276
main :: IO ()
main = do
  [a, b, c] <- fmap words getLine
  let inta = read a :: Int
  let intb = read b :: Int
  let intc = read c :: Int
  putStrLn $ range inta intb intc

range :: Int -> Int -> Int -> String
range a b c| a < b && b < c = "Yes"
            | otherwise = "No"

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];

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

    int ans = 0;
    rep(i,K) ans += p[i];
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    int first = s.find('A');
    int end = s.rfind('Z');
    std::cout<<(end - first + 1)<<std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int N, M;
  cin >> N >> M;
  int x[M], y[M];
  rep(i, M){
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }
  // 入力終了

  // 箱iに赤ボールが入っている可能性があるかどうか
  bool red[N];
  // 箱iにあるボールの総数
  int ball_num[N];

  // 赤ボールは初め箱1のみに入っている
  // また，箱iの中のボールは初め1つだけ
  rep(i, N){
    red[i] = false;
    ball_num[i] = 1;
  }
  red[0] = true;

  rep(i, M){
    // 箱x[i]に赤ボールがあれば，箱y[i]にボールを移せる
    if(red[x[i] ] )
      red[y[i] ] = true;

    // ボールを箱x[i]からy[i]に移す
    ball_num[x[i] ]--;
    ball_num[y[i] ]++;

    // 箱の中身が空なら，そこに赤ボールは存在しない
    if(ball_num[x[i] ] == 0)
      red[x[i] ] = false;
  }

  // 赤ボールが入っている可能性のある箱の数を数える
  int ans = 0;
  rep(i, N)
    if(red[i] )
      ans++;

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4860
#include <iostream>
    #include <string>
    #include <math.h>
    #include<algorithm>
    using namespace std;
     
    int main(){
      int N;
      int K;
      cin >> N >> K;
      int D[K];
      for(int i=0;i<K;i++){
       cin >> D[i]; 
      }
      bool flag=false;
      int ans=N;
      while(flag==false){
        flag=true;
        int check=ans;
        while(check>0){
          for(int i=0;i<K;i++){
           if(check%10==D[i]) flag=false; 
          }
         check/=10;
        }
        if(flag==false) ans++;
      }
      cout << ans << endl;
      return 0;}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;

using P = pair<int, int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MAX = 510000;
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;
}

signed main(){
	int n;
	cin>>n;
	int cnt[110]={};
	int k[110];
	rep(i,1,n+1)k[i]=i;
	rep(i,2,n+1){
		int c=0;
		rep(j,1,n+1){
			while(k[j]%i==0){
				k[j]/=i;
				c++;
			}
		}
		cnt[c]++;
	}
	int ans=0;
	for(int i=99;i>=0;i--)cnt[i]=cnt[i+1]+cnt[i];
	COMinit();
	cout<<COM(cnt[74],1)+COM(cnt[24],1)*COM(cnt[2]-1,1)+COM(cnt[14],1)*COM(cnt[4]-1,1)+COM(cnt[2]-2,1)*COM(cnt[4],2)<<endl;
}

Measured memory_bytes: 12160
import sys
sys.setrecursionlimit(10**6)
def rec(i):
    if C[i] != INFTY:
        return C[i]
    if i == 0:
        C[i] = 0
        return C[i]
    elif i == 1:
        C[i] = rec(i-1)+abs(H[i]-H[i-1])
        return C[i]
    C[i] = min(rec(i-1)+abs(H[i]-H[i-1]), rec(i-2)+abs(H[i]-H[i-2]))
    return C[i]
    
INFTY = 10**13
N = int(input())
H = list(map(int, input().split()))
C = [INFTY for i in range(N)]
print(rec(N-1))


Measured memory_bytes: 93592
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int N,A,B;


int main(void) {
  cin >> N >> A >> B;
  
  if(N*A >= B)  cout << B << endl;
  else  cout << N*A << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll ma=0;
    REP(i,5){
        ll a;cin>>a;
        if(n%a!=0) chmax(ma,n/a+1);
        else chmax(ma,n/a);
    }
    cout<<ma+4<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<map<char, int>> table;

  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;

    map<char, int> m;
    for (int j = 0; j < s.length(); j++)
    {
      if (m.count(s[j]))
      {
        m[s[j]]++;
      }
      else
      {
        m[s[j]] = 1;
      }
    }

    table.push_back(m);
  }

  map<char, int> common;
  map<char, int> fir = table[0];
  for (map<char, int>::iterator it = fir.begin(); it != fir.end(); it++)
  {
    char ch = it->first;
    int count = it->second;
    for (int i = 1; i < table.size(); i++)
    {
      count = std::min(count, table[i][ch]);
    }

    common[ch] = count;
  }

  string res = "";

  for (auto it = common.begin(); it != common.end(); it++)
  {
    for (int i = 0; i < it->second; i++)
    {
      res += it->first;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

int main() {

	string s;
	cin >> s;
	Int len = s.size();
	s.push_back('R');//右端の処理用

	vector<Int> ans(len, 0);

	Int flag = 0;
	Int count = 0;

	for (Int i = 0; i < len; i++) {
		if (flag == 0 && s[i + 1] == 'R') {
			count++;
			continue;
		}
		if (flag == 0 && s[i + 1] == 'L') {
			count++;
			flag = 1;
			ans[i] += (count + 1) / 2;
			ans[i + 1] += count / 2;
			count = 0;
			continue;
		}
		if (flag == 1 && s[i + 1] == 'L') {
			count++;
			continue;
		}
		if (flag == 1 && s[i + 1] == 'R') {
			count++;
			flag = 0;
			ans[i - count] += count / 2;
			ans[i - count + 1] += (count + 1) / 2;
			count = 0;
		}
	}

	for (Int i = 0; i < len; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>

int main( void ) 
{
	int n;
	int i;
	double s[1001];
	double m,sum;
	
	while( 1 ) {
		scanf( "%d", &n );
		if( 0== n ) { break; }
		m=0;
		for( i=0; i<n; i++ ) {
	    	scanf( "%lf", &s[i] );
	    	m+=s[i];
	    }
	    m/=n;
	    sum=0;
		for( i=0; i<n; i++ ) {
	    	sum += pow( (s[i]-m), 2 );
	    }
	    sum=sum/n;
		printf( "%.4lf\n", sqrt( sum ) );
	}
		
	return 0;
}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T> constexpr void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int h, w, a, b;
int cnt[1005];
int ans[1005][1005];
void solve() {
    cin >> h >> w >> a >> b;

    if (w - a < a || h - b < b) { cout << -1 << endn; return; }

    rep(i, b) {
        rep(j, w) {
            if (j < a) cout << 1;
            else cout << 0;
        }
        cout << endn;
    }

    rep(i, h - b) {
        rep(j, w) {
            if (j < a) cout << 0;
            else cout << 1;
        }
        cout << endn;
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> idx(n);
  rep(i,n){
    int p;
    cin >> p;
    idx[p-1] = i;
  }

  ll ans = 0;
  set<int> s;
  for(int x = n-1; x>=0; --x){
    int i = idx[x];
    vector<ll> l(2,-1), r(2,n);

    s.insert(i);
    auto itrl = s.find(i);
    auto itrr = itrl;
    rep(ii,2){
      if(itrl==s.begin()) break;
      --itrl;
      l[ii] = *itrl;
    }
    rep(ii,2){
      ++itrr;
      if(itrr==s.end()) break;
      r[ii] = *itrr;
    }
    ans += (x+1)*((i-l[0])*(r[1]-r[0])+(l[0]-l[1])*(r[0]-i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include<stdio.h>
int main(void)
{
	int r,g,b,i;
	scanf("%d %d %d",&r,&g,&b);
	g=g*10;
	b=g+b;
	if(b%4==0)	printf("YES\n");
	else	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def main():
    X, N = map(int, input().split())
    p = set(list(map(int, input().split())))
    table = set()
    for i in range(1, 101):
        table.add(i)
    table = table - p
    lis = list(table)
    ans = -1
    diff = 10 ** 9
    for i, a in enumerate(lis):
        if abs(a-X) < diff:
            diff = abs(a-X)
            ans = a
        elif abs(a-X) == diff:
            ans = min(ans, a)
    if abs(X-ans) > abs(X-101):
        ans = 101
    if abs(X-ans) >= abs(X):
        ans = 0
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 61948
from collections import deque

N, M = map(int, input().split())
graph = {i+1:[] for i in range(N)}

for i in range(M):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

num = [0 for _ in range(N)]
num[0] = 1

dist = [10**15 for _ in range(N)]
dist[0] = 0

queue = deque([1])
visited = [False for _ in range(N)]

while queue:
    v = queue.popleft()
    if(visited[v-1]):
        continue
    visited[v-1] = True
    for value in graph[v]:
        if(visited[value-1]):
            continue
        if(dist[value-1] > dist[v-1]+1):
            dist[value-1] = dist[v-1]+1
            num[value-1] = v
        queue.append(value)

if(0 not in num):
    print("Yes")
    for i in range(1, len(num)):
        print(num[i])
else:
    print("No")

Measured memory_bytes: 43304
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    char t = 'a';
    while (1)
    {
        if (t == 'a')
        {
            if (sa.size() == 0)
            {
                cout << 'A' << endl;
                return 0;
            }
            t = sa[0];
            sa.erase(sa.begin());
        }
        else if (t == 'b')
        {
            if (sb.size() == 0)
            {
                cout << 'B' << endl;
                return 0;
            }
            t = sb[0];
            sb.erase(sb.begin());
        }
        else if (t == 'c')
        {
            if (sc.size() == 0)
            {
                cout << 'C' << endl;
                return 0;
            }
            t = sc[0];
            sc.erase(sc.begin());
        }
    }
}

Measured memory_bytes: 256
io = STDIN
n,x=io.gets.chomp.split.map(&:to_i)
ar=io.gets.chomp.split.map(&:to_i)
cnt=0
if ar[0]>x
  cnt+=ar[0]-x
  ar[0]=x
end
(1...ar.size).each do|i|
  sum=ar[i-1]+ar[i]
  if sum>x
    cnt+=sum-x
    ar[i]-=sum-x
  end
end
puts cnt

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] str = br.readLine().split(" ");
		Set<Integer> S = new TreeSet<Integer>();
		for(int i = 0; i < n; i++){
			S.add(Integer.parseInt(str[i]));
		}
		int m = Integer.parseInt(br.readLine());
		str = br.readLine().split(" ");
		Set<Integer> S2 = new TreeSet<Integer>();
		for(int i = 0; i < m; i++){
			if(S.contains(Integer.parseInt(str[i]))) S2.add(Integer.parseInt(str[i]));
		}
		for(Integer num : S2) System.out.println(num);
	}
}



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

ll gcd(ll x, ll y){

    if(x%y == 0)return y;

    return gcd(y, x%y);
}
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll sum = b - a + 1;
    ll x, y, z;//c,d,cdの倍数

    if(a%c == 0) x = b/c - a/c + 1;
    else x = b/c - a/c;

    if(a%d == 0) y = b/d - a/d + 1;
    else y = b/d - a/d;

    ll e = c*d/gcd(c, d);
    if(a%e== 0) z = b/e - a/e + 1;
    else z = b/e - a/e;

    sum = sum - x - y + z;

    cout << sum << endl; 
}

Measured memory_bytes: 3604
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let length: usize = iter.next().unwrap().parse().unwrap();
    let inquiries: usize = iter.next().unwrap().parse().unwrap();
    let s: String = iter.next().unwrap().parse().unwrap();
    let ranges: Vec<(usize, usize)> = (0..inquiries)
        .map(|_| {
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
            )
        })
        .collect();

    let mut cumulative_sum: Vec<usize> = (0..length).map(|_| 0).collect();
    //let chars = s.chars().collect::<Vec<char>>();
    for n in 1..length {
        if s[n - 1..n + 1] == "AC".to_string() {
            cumulative_sum[n] = cumulative_sum[n - 1] + 1;
        } else {
            cumulative_sum[n] = cumulative_sum[n - 1];
        }
    }

    for range in ranges {
        println!(
            "{}",
            cumulative_sum[range.1 - 1] - cumulative_sum[range.0 - 1]
        );
    }
}


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

int main()
{
  int n,t,a;
  cin >> n >> t >> a;
  long long h[1000];
  for (int i = 0; i < n; i++)
  {
    cin >> h[i];
  }

  double m = 100000000;
  int place = 0; 
  for (int i = 0; i < n; i++) {
    double temp = t - h[i] * 0.006;
    double diff = abs(a - temp);
    if (diff < m)
    {
      m = diff;
      place = i + 1;
    }
  }

  cout << place;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

void trace(const std::vector<int> &a){
	for(int i = 0; i < a.size(); ++i){
		std::cout << a[i] << (i == a.size() - 1 ? '\n' : ' ');
	}
}

void insertionSort(std::vector<int> &a){
	trace(a);
	for (int j = 1; j < a.size(); ++j){
		int tmp = a[j];
		int i = j - 1;
		while (i >= 0 && a[i] > tmp){
			a[i + 1] = a[i];
			i = i - 1;
		}
		a[i + 1] = tmp;
		trace(a);
	}
}

int main() {
	int n;
	
	std::cin >> n;
	std::vector<int> a(n);
	for(int i = 0; i < n; ++i){
		std::cin >> a[i];
	}
	insertionSort(a);
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int M = 4e5 + 233;
const int N = 2e5 + 233;
struct E {
    int nxt, to, id;
}e[M];
int n, m, T;
int head[N], e_cnt = 1, h[N];
int out[N], in[N], has[M];
vector <int> circle;
map < int, vector <int> > mp;
set <int> alive;
#define GG (puts("No"), exit(0))
inline void replace() {
    memset(has, 0, sizeof has);
    circle.clear();
    mp.clear();
    alive.clear();
    memcpy(head, h, sizeof head);
}
inline void add(int x, int y, int id) {
    e[++ e_cnt] = (E) {head[x], y, id}; head[x] = e_cnt;
}

inline void dfs(int u) {
    for (int &i = head[u]; i; i = e[i].nxt) if (!has[abs(e[i].id)]) {
            has[abs(e[i].id)] = true; int tmp = e[i].id;
            dfs(e[i].to);
            circle.push_back(tmp);
        }
}

int main(void) {
    read(n); read(m);
    vector < pair <int, int> > r(m + 2);
    rep (i, m) {
        int x, y; read(x); read(y);
        ++out[x]; ++out[y];
        r[i] = {x, y};
        add(x, y, i);
        add(y, x, -i);
    }
    memcpy(h, head, sizeof h);
    rep (i, n) if (out[i] & 1) GG;
    vector <int> v(n + 1, 0);
    srand(20021214);
    rep (i, n) v[i] = i;
    rep (_, 10) {
        dfs(rand() % n + 1);
        reverse(circle.begin(), circle.end());
        vector <int> tmp = circle; circle.clear();
        for (int i : tmp) {
            circle.push_back(i > 0 ? r[i].first : r[-i].second);
        }
        circle.push_back(circle.front());
        // for (int i : circle) cout << i << " "; cout << "\n";
        int tot = 0;
        re0 (i, circle.size()) {
            int p = circle[i];
            // cout << i << "\n";
            if (mp.count(p) && mp[p].size()) {
                ++tot;
                int t = mp[p].back();
                while (true) {
                    auto it = alive.lower_bound(t + 1);
                    if (it == alive.end()) break;
                    mp[circle[*it]].pop_back();
                    alive.erase(it);
                }
            } else {
                mp[p].push_back(i);
                alive.insert(i);
            }
        }
        replace();
        if (tot >= 3) return cout << "Yes\n", 0;
    }
    cout << "No\n";
}  


Measured memory_bytes: 26744
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,W;
    cin >> N >> W;
    long long w[N];
    long long v[N];
    long long v_max = 0LL;
    for(long long i=0;i<N;i++){
        cin >> w[i] >> v[i];
        v_max = max(v[i],v_max);
    }
 
    long long V = v_max*N;
 
 
    long long dp[N+1][V+1];
    for(long long i=0;i<N+1;i++){
        for(long long j=0;j<V+1;j++){
            dp[i][j] = INT_MAX;
        }
    }
 
    dp[0][0] = 0;
 
    for(long long i= 0;i<N;i++){
        for(long long j=0;j<V+1;j++){
            if(v[i] > j){
                dp[i+1][j] = dp[i][j];
                //cout << dp[i+1][j] << endl;
            }else{
                dp[i+1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
                //cout << dp[i+1][j] << endl;
            }
        }
    }
 
    long long ans = 0LL;
    for(long long i=0;i<V+1;i++){
        if(dp[N][i] <= W){
            ans = i;
        }
    }
 
    cout << ans << endl;
 
    return 0;
}

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[i] = i + 1;
		printArray(a, pw);
		for(;;){
			int[] b = next_permutation(a);
			if(a == b) break;
			printArray(b, pw);
			a = b;
		}
		pw.close();
	}
	public static void printArray(int[] a, PrintWriter pw){
		for(int i = 0; i < a.length; i++){
			pw.print(a[i]);
			if(i != a.length - 1) pw.print(" ");
		}
		pw.print("\n");
	}
	public static int[] next_permutation(int[] a){
		int[] ret = new int[a.length];
		int front = -1, rear = -1;
		ArrayList<Integer> la = new ArrayList<Integer>();
		for(int i = a.length - 1; i >= 0; i--){
			if(i < a.length - 1 && a[la.get(la.size() - 1)] > a[i]){
				front = i;
				for(;;){
					rear = la.get(la.size() - 1);
					la.remove(la.size() - 1);
					if(la.isEmpty() || a[la.get(la.size() - 1)] < a[front]) break;
				}
				break;
			}
			else la.add(i);
		}
		if(front == -1) return a;
		for(int i = 0; i < a.length; i++){
			if(i == front) ret[i] = a[rear];
			else if(i == rear) ret[i] = a[front];
			else ret[i] = a[i];
		}
		Arrays.sort(ret, front + 1, a.length);
		return ret;
	}
}



Measured memory_bytes: 64692
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int P = nextInt();
        int Q = nextInt();
        int R = nextInt();

        int a = P+Q;
        int b = Math.min(P+R, a);
        int c = Math.min(Q+R, b);

        println(c);
    }

    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 22612
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String str = s.next();
		String[] arr2 = str.split("");

		int count = 0;
		int indexC = 0;
		int indexF = 0;
		int flag = 0;
		int flagC = 0;
		int flagF = 0;
		for(int i=0;i<arr2.length;i++){
			if(arr2[i].equals("C")){
				indexC = i;
				flagC = 1;
			}else if(arr2[i].equals("F")){
				indexF = i;
				flagF = 1;
			}
		}

		if(indexF>indexC && flagC==1 && flagF==1){
			flag = 1;
		}
		if(flag ==1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 9044
"use strict";

const main = (arg) => {
  const input = arg.trim().split("\n");
  const A = parseInt(input[0].split(" ")[0]);
  const V = parseInt(input[0].split(" ")[1]);
  const B = parseInt(input[1].split(" ")[0]);
  const W = parseInt(input[1].split(" ")[1]);
  const T = parseInt(input[2]);

  if (V - W === 0) return console.log("NO");

  // 追いつく時間
  // マイナスの場合追いつけない
  const time = Math.abs(A - B) / (V - W);
  console.log(time > 0 && time <= T ? "YES" : "NO")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


Measured memory_bytes: 29620
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int K;
string iso[101];
string naka[101];

string solve() {
    int pow1=0,pow2=0;
    rep(i,K) {
        if(iso[i]=="tameru") pow1++;
        if(naka[i]=="tameru") pow2++;
        pow1=min(pow1,5);
        pow2=min(pow2,5);
        if(iso[i]=="kougekida"&&naka[i]=="kougekida") {
            if(pow1==pow2) {
                pow1=pow2=0;
                continue;
            }
            else if(pow1<pow2) {
                pow1=pow2=0;
                return "Nakajima-kun";
            }
            else {
                pow1=pow2=0;
                return "Isono-kun";
            }
        }
        if(iso[i]=="kougekida"&&pow1==0) return "Nakajima-kun";
        if(naka[i]=="kougekida"&&pow2==0) return "Isono-kun";

        if(iso[i]=="kougekida"&&naka[i]=="tameru") {
            return "Isono-kun";
        }
        if(iso[i]=="kougekida"&&naka[i]=="mamoru") {
            if(pow1==5) return "Isono-kun";
            pow1=0;
        }
        if(iso[i]=="mamoru"&&naka[i]=="kougekida") {
            if(pow2==5) return "Nakajima-kun";
            pow2=0;
        }
        if(iso[i]=="tameru"&&naka[i]=="kougekida") {
            return "Nakajima-kun";
        }
    }

    return "Hikiwake-kun";
}
int main() {
    cin>>K;
    rep(i,K) cin>>iso[i];
    rep(i,K) cin>>naka[i];
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  if(s.size()==2){
    cout << s << endl;
  } else {
    reverse(s.begin(),s.end());
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d%d%d%d", $n, $a, $b, $c, $d);
$s = "#".trim(fgets(STDIN));
 
//連続する#が存在しない
$flag1 = true;
for($i = $a; $i < $c ; $i++){
  if($s[$i]=="#" && $s[$i+1]=="#"){
    $flag1 = false;
  }
}
for($i = $b; $i < $d ; $i++){
  if($s[$i]=="#" && $s[$i+1]=="#"){
    $flag1 = false;
  }
}
if($c > $d){
  $flag2 = false;
  //bとcの間に3個連続する.が存在する
  for($i = $b - 1; $i < $d; $i++){
    if($s[$i]=="." && $s[$i+1]=="." && $s[$i+2]=="."){
      $flag2 = true;
    }
  }
}else{
  $flag2 = true;
}
echo ($flag1 && $flag2) ? "Yes" : "No";

Measured memory_bytes: 4728
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,int>m;
    rep(i,n){    
      int a,b,c;
      cin>>a>>b>>c;
      m[b+c]=a;
    }
    map<int,int>::it it=m.end();it--;
    cout<<it->second<<" "<<it->first<<endl;
  }

}

Measured memory_bytes: 1664
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
mod=998244353
from operator import itemgetter
l.sort(key=itemgetter(1))
for i in range(n):
    l[i][1]=i
l.sort(key=itemgetter(0))

No=2
while No<=n:
    No*=2
tree=[0]*(2*No)

def add(k,x):
    k+=No-1
    while k>=0:
        tree[k]+=x
        k=(k-1)//2
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=0
    while L<=R:
        if R&1:
            s+=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s+=tree[L]
        L>>=1;R>>=1
    return s
pow2=[1 for i in range(n+2)]
t=2
for i in range(1,n+2):
    pow2[i]=t
    t*=2
    t%=mod
ans=0
for x,y in l:
    lu=query(y,n)
    ld=query(0,y)
    ru=n-1-y-lu
    rd=y-ld
    ans+=pow2[n-1]+(pow2[lu]-1)*(pow2[rd]-1)%mod*(pow2[ru]+pow2[ld]-1+(pow2[ld]-1)*(pow2[ru]-1))%mod+(pow2[ld]-1)*(pow2[ru]-1)%mod*(pow2[rd]+pow2[lu]-1)%mod
    ans%=mod
    add(y,1)
print(ans)

Measured memory_bytes: 107100
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")


#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(x,n)           for(int i=0;i<n;i++)  cin>>x[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll long long
#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	if (n % 1000 == 0) {
		cout << "0" << "\n";
	} else {
		ll v = n % 1000;
		cout << 1000 - v << "\n";
	}


	return 0;
}


Measured memory_bytes: 3648
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

if __name__ == "__main__":
    import sys
    input = sys.stdin.readline # faster input

    a, b = list(map(int, input().split()))
    print(gcd(a, b))





Measured memory_bytes: 5604
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0][0]*B[1][0])

Measured memory_bytes: 18528
const N,K=map(x->parse(Int,x),split(readline()))
const G=[Int[] for _=1:N]
const M=10^9+7
function init()
	for s=readlines()
		a,b=map(x->parse(Int,x),split(s))
		push!(G[a],b)
		push!(G[b],a)
	end
end
init()
ans=1
function dfs(u,p,c)
	global ans=ans*(K-c)%M
	cnt=1+(p>0)
	for v=G[u]
		if v!=p
			dfs(v,u,cnt)
			cnt+=1
		end
	end
end
dfs(1,0,0)
println(ans)


Measured memory_bytes: 169488
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef unsigned long long/*-----------*/ulli;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define lb/*---------------------------*/lower_bound
#define ub/*---------------------------*/upper_bound
#define pb/*---------------------------*/push_back
#define popb/*-------------------------*/pop_back

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz/*---------------------------*/size()

#define MP/*---------------------------*/make_pair
#define bs/*---------------------------*/binary_search
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()

#define ff/*---------------------------*/first
#define ss/*---------------------------*/second

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/100005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	string s;
	cin >> s;
	if((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3]))
        cout << "Yes\n";
    else
        cout << "No\n";
	return 0;
}










Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

LL primes[78498];
int osa_k[1000000+1];
int M[1000000+1];
LL temp[10000];

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N);
	VLL Aold(N);
	for (LL n = 0; n < N; n++) {
		cin >> A[n];
		Aold[n] = A[n];
	}
	for (LL n = 0; n < N; n++)temp[n] = 1;
	sort(A.begin(), A.end(), [](LL a, LL b) {
		return a > b;
	});
	for (LL n = 0; n <= 1000000; n++)osa_k[n] = n;
	for (LL n = 2; n <= 1000000; n++) {
		if (osa_k[n] != n)continue;
		LL t = 2 * n;
		while (t <= 1000000) {
			if(osa_k[t] == t)osa_k[t] = n;
			t += n;
		}
	}
	for (LL m = 0; m < 1000000; m++)M[m] = 0;
	for (LL n = 0; n < N; n++) {
		LL a = A[n];
		LL count = 1;
		LL prev = 1;
		while (a > 1) {
			if (prev != osa_k[a]) {
				count = 1;
				prev = osa_k[a];
				a /= osa_k[a];
				M[prev] = max(M[prev], (int)count);
			}
			else {
				count++;
				a /= osa_k[a];
				M[prev] = max(M[prev], (int)count);
			}
		}
	}
	LL ans = 0;
	M[1] = 1;
	for (LL p = 2; p <= 1000000; p++) {
		if (osa_k[p] != p)continue;
		if (M[p] == 0)continue;
		for (LL n = 0; n < N; n++) {
			LL count = 0;
			while (A[n] % p == 0) {
				A[n] /= p;
				count++;
			}
			for (LL t = 0; t < M[p] - count; t++) {
				temp[n] = (temp[n] * p) % MOD;
			}
		}
	}
	for (LL n = 0; n < N; n++)ans += temp[n];
	cout << ans % MOD << "\n";
	return 0;
}


Measured memory_bytes: 8576