akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 1000000
void insertionSort(int *, int,int);
void shellSort(int *,int);
int cnt = 0;
int main()
{
  int i,n;
  int A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
    shellSort(A,n);
    for(i=0;i<n;i++)
    {
      printf("%d\n",A[i]);
    }
    return 0;
}

void insertionSort(int A[],int n,int g)
{
  int i,j,k;
  for(i=g;i<=n-1;i++)
  {
    k=A[i];
    j=i-g;
    while((j >= 0) && (A[j] > k))
    {
      A[j+g] = A[j];
      j-=g;
      cnt++;
      A[j+g] = k;
    }
  }
}

void shellSort(int A[],int n)
{
  int h=1,i,G[N];
  G[0]=1;
  while(1)
  {
    G[i+1] = 3*G[i] + 1;
    if(G[i+1] > n)
      {
        break;
      }
        h++;
        i++;
  }
  for(i = h-1; i >= 0; i--)
  {
    insertionSort(A,n,G[i]);
  }

  printf("%d\n",h);
  for(i = h-1; i > 0; i--)
  {
    printf("%d ",G[i]);
  }

  printf("%d\n",G[i]);
  printf("%d\n",cnt);
}



Measured memory_bytes: 5644
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
ll Layer[51],Patty[51];
void init(){
  ll i;
  Layer[0] = Patty[0] = 1;
  for(i=1;i<=50;i++){
    Layer[i] = Layer[i-1]*2+3;
    Patty[i] = Patty[i-1]*2+1;
  }
}
ll PattyCount(ll level,ll X){
  if(level == 0) return X == 1;
  if(X <= 1) return 0;
  X--;
  ll ans = 0;
  if(X >= Layer[level-1]){
    ans += Patty[level-1];
    X -= Layer[level-1];
  } else return PattyCount(level-1,X);
  if(X == 0) return ans;
  X--;ans++;
  if(X == 0) return ans;
  if(X >= Layer[level-1]){
    ans += Patty[level-1];
    X -= Layer[level-1];
  } else return ans+PattyCount(level-1,X);
  return ans;
}
int main(){
  init();
  ll N,X;scanf("%lld%lld",&N,&X);
  printf("%lld\n",PattyCount(N,X));
}

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
 
bool a[200010], b[200010];
 
int main() {
	int n, m, x, y;
	a[0] = false;
	b[0] = false;
 
	cin >> n >> m;
 
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		if (x == 1) {
			a[y] = 1;
		}
		if (y == n) {
			b[x] = 1;
		}
	}
 
	for (int i = 2; i <= n; i++) {
		if (a[i] == 1 && b[i] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
ll n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  n;
  string res;
  while(n > 0) {
    n--;
    res.push_back(n % 26 + 'a');
    n /= 26;
  }

  cout << string(res.rbegin(), res.rend()) << endl;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

// LRUD
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
// const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for (int i = 0; i < m; i++){
        cin >> l[i] >> r[i];
    }

    int left = 0, right = 9999999;
    for (int i = 0; i < m; i++){
        chmax(left, l[i]);
        chmin(right, r[i]);
    }

    int ans = max(0, right - left + 1);
    cout << ans << endl;

    return 0;
}



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

int main(){
    
    long long int i, x, N , K, score, score_max, cycle, K_rem, ans;
    cin >> N >> K;
    score = 0;
    score_max = 0;
    cycle = 0;
    
    long long int P[N], C[N], Sc[N], Sm[N], Cy[N], Max[N];
    
    for (i = 0; i < N; i++){
        cin >> P[i];
        P[i] -= 1;
    }

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

    for (i = 0; i < N; i++){
        x = max(x, C[i]);
    }
    
    if (x <= 0){
        cout << x << "\n";
        return 0;
    }

    for (i = 0; i < N; i++){
        x = i;
        score = 0;
        cycle = 0;
        score_max = 0;

        while (1){
            x = P[x];
            score += C[x];
            score_max = max(score, score_max);
            cycle++;
            if (x == i) break;
        }

        Cy[i] = cycle;
        Sc[i] = score;
        Sm[i] = score_max;
    }
    
    for (i = 0; i < N; i++){
        x = i;
        score = 0;
        cycle = 0;
        score_max = 0;
        K_rem = (K - 1) % Cy[i] + 1;

        while (1){
            x = P[x];
            score += C[x];
            score_max = max(score, score_max);
            cycle++;
            if (cycle == K_rem) break;
        }
        
        if (Sc[i] <= 0){
            Max[i] = Sm[i];
        } else {
            Max[i] = (K - 1) / Cy[i] * Sc[i] + score_max;
        }

    }
    
    ans = 0;
    
    for (i = 0; i < N; i++){
        ans = max(ans, Max[i]);
    }
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
const int N=100050;
const int M=200050;
int n,m,low[N],dfn[N],dfstime,u,v,cnt;
vector<int>g[N];
struct node{
    int x,y;
}ans[N];
 
void Tarjan(int u,int fa)
{
    low[u]=dfn[u]=++dfstime;
    for(unsigned i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(!dfn[v])
        {
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ans[++cnt].x=u,ans[cnt].y=v;
        }
        else
            if(v!=fa) low[u]=min(low[u],dfn[v]);
    }
}
bool cmp(node x,node y)
{
    if(x.x==x.y) return x.y<y.y;
    return x.x<y.x;
}
 
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    Tarjan(1,1);
    cout<<cnt<<endl;
    // for(int i=1;i<=cnt;i++)
    //     if(ans[i].x>ans[i].y) swap(ans[i].x,ans[i].y);
    // sort(ans+1,ans+cnt+1,cmp);
    // for(int i=1;i<=cnt;i++)
    //     printf("%d %d\n",ans[i].x,ans[i].y);
    return 0;    
}

Measured memory_bytes: 2560
a,b,x = gets.strip.split.map(&:to_i)
if x >= ((a**2)*b).to_f/2
  puts (Math.atan((2*(((a**2)*b)-x)).to_f/a**3))*180.to_f/Math::PI
else
  puts (Math.atan(((b**2)*a).to_f/(2*x)))*180.to_f/Math::PI
end

Measured memory_bytes: 14572
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " "
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(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;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll X,A;
    cin >> X >>A;
    if(X < A)cout << "0\n";
    else cout << "10\n";
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int row,col;

bool valid(int i, int j){
    if(i<0 || i>row || j<0 || j>col)
        return 0;
    return 1;
}

int dfs(int i, int j, vector<vector<int>>&dp, vector<vector<char>>&mat ){
    //cout<<i<<" "<<j<<"\n";
    if(!valid(i,j) || mat[i][j]=='#')
        return 0;

    if(i==row && j==col)
        return 1;
    
    if(dp[i][j]!=-1)
        return dp[i][j];
    else{
        long long int r,d;
        r = dfs(i, j+1, dp, mat)%mod;
        d = dfs(i+1, j, dp, mat)%mod;
        return (dp[i][j]=(d+r)%mod);
    }
}
int main() {
    fast;
    int r,c;
    cin>>r>>c;
    row=r-1;
    col=c-1;
    vector<vector<int>>dp(r, vector<int>(c,-1));
    vector<vector<char>>mat(r, vector<char>(c,'.'));
    
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>mat[i][j];
        }
    }
    // for(auto i: dp){
    //     for(auto j: i)
    //         cout<<j<<" ";
    //     cout<<"\n";
    // }
    cout<<dfs(0, 0, dp, mat)%mod;
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int partition(vector<pair<int, char> > &Array, int p, int last)
{
    int i = p - 1;
    for (int j = p; j < last; ++j)
    {
        if (Array[j].first <= Array[last].first)
        {
            i++;
            swap(Array[i], Array[j]);
        }
    }
    swap(Array[i + 1], Array[last]);
    return i + 1;
}
void quicksort(vector<pair<int, char> > &Array, int p, int last)
{
    if (p < last)
    {
        int q = partition(Array, p, last);
        quicksort(Array, p, q - 1);
        quicksort(Array, q + 1, last);
    }
}
int main()
{
    int n;
    cin >> n;
    vector<pair<int, char> > A;
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        char c;
        cin >> c >> tmp;
        A.push_back(make_pair(tmp, c));
    }
    vector<pair<int, char> > B(A);
    quicksort(A, 0, n - 1);
    bool ans(true);
    for (int i = 0; i < n - 1; ++i)
    {
        for (int j = i + 1; A[i].first == A[j].first; ++j)
        {
            int t1, t2;
            for (int k = 0; k < n; ++k)
            {
                if (A[j - 1] == B[k])
                    t1 = k;
            }
            for (int k = 0; k < n; ++k)
            {
                if (A[j] == B[k])
                    t2 = k;
            }
            if (t1 > t2)
            {
                ans = false;
                break;
            }
        }
        if (!ans)
            break;
    }
    if (ans)
        cout << "Stable" << endl;
    else
    {
        cout << "Not stable" << endl;
    }

    for (int i = 0; i < n; ++i)
        cout << A[i].second << ' ' << A[i].first << endl;
}


Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  vector<int> vec = {10*a+b+c, 10*b+a+c,10*c+a+b};
  sort(vec.begin(),vec.end());
  cout << vec.at(2) << endl;
}


Measured memory_bytes: 256
N = int(input())
W = [int(w) for w in input().split()]
ans = 100000000
for t in range(N):
  less_T = W[:t]
  more_T = W[t:]
  S_l = sum(less_T)
  S_m = sum(more_T)
  d = abs(S_l - S_m)
  if ans > d:
     ans = d
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    cin >> N;
    vector<ll> A(N),D(N);
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    ll b = (N+1)*N/2;
    if(sum % b != 0 ){
        cout << "NO" << endl;
        return 0;
    }
    ll k = sum / b;
    rep(i,N){
        D[i] = A[(i+1)%N] - A[i] - k;
    }
    ll cnt = 0;
    rep(i,N){
        if(D[i]% N !=0 || D[i]>0){
            cout << "NO" << endl;
            return 0;
        }else cnt += -D[i]/N;
    }
    if(cnt==k)cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1792
n = int(input())
h = list(map(int, input().split()))

INF = float('inf')
dp = [INF] * (n+1)

dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]))
    if i + 2 < n:
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]))

print(dp[n-1])

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);

		int d = a/b;
		int r = a%b;
		double f = (double)a/(double)b;

		System.out.printf("%d %d %05f", d, r, f);
	}
}

Measured memory_bytes: 24860
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');

            int a, b,c;
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);

            if (a < b)
            {
                if (b < c)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 8836
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  vi a(m),b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  int ans = 0;
  rep(i,m){
    UnionFind tree(n);
    rep(j,m){
      if(i == j) continue;
      tree.unite(a[j],b[j]);
    }
    if(!tree.same(a[i],b[i])) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    int N; cin >> N;
    ll a[1010];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    
    bool flag=true;

    for(int i=0; i<N; i++){
        if(a[i]>=0) flag=false;
    }
    if(flag){ //一番大きのだけ残す
        ll ans=-1001001001;
        int num;
        for(int i=0; i<N; i++){
            if( ans < a[i]){ num=i;}
            ans = max(a[i],ans);
        }
        cout << ans << endl;
        cout << N-1 << endl;
        for(int i=0; i<num; i++){
            cout << 1 << endl;
        }
        for(int i=num+1; i<N; i++){
            cout << N-i+1 << endl;
        }
        return 0;
    }


//奇数の場合の値
    ll sum0=0, sum1=0;
    int num0=0, num1=0;
    vector<int> list0(0), list1(0);
    for(int i=0; i<N; i++){
        if(i%2==0 && a[i]>=0 ){
            sum0+=a[i];
            num0++;
            list0.push_back(i);
        }
    }
//偶数の場合の値
    for(int i=0; i<N; i++){
        if(i%2==1 && a[i]>=0 ){
            sum1+=a[i];
            num1++;
            list1.push_back(i);
        }
    }


    if(sum0>sum1){ //奇数の時の処理
        cout << sum0 << endl;
        int fi=*list0.begin();
        int la=*(list0.end() -1);
        cout << fi+(la-fi)/2+N-1-la << endl;
        for(int i=0; i<fi; i++){
            cout << 1 << endl;
        }
        for(int i=0; i<list0.size()-1; i++){
            int now = list0.at(i);
            int next= list0.at(i+1);
            for(int j=0; j<(next-now)/2; j++){
                cout << 1+(next-now)/2-j << endl;
            }
        }
        int numlas = N-1-la;
        for(int i=0; i<numlas; i++){
            cout << numlas-i+1 << endl;
        }
    }
    else{
        cout << sum1 << endl;
        int fi=*list1.begin();
        int la=*(list1.end() -1);
        cout << fi+(la-fi)/2+N-1-la << endl;
        for(int i=0; i<fi; i++){
            cout << 1 << endl;
        }
        for(int i=0; i<list1.size()-1; i++){
            int now = list1.at(i);
            int next= list1.at(i+1);
            for(int j=0; j<(next-now)/2; j++){
                cout << 1+(next-now)/2-j << endl;
            }
        }
        int numlas = N-1-la;
        for(int i=0; i<numlas; i++){
            cout << numlas-i+1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
 
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e5 + 2;
const int M = 4e5;
const ll mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e16;
 
void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

int n, m, dp[N], ans[N];
vi g[N];

int add(int a, int b) {
	return (a + b) % m;
}

int mul(int a, int b) {
	return (1LL * a * b) % (1LL * m);
}

void calc(int v = 1, int p = 0) {
	dp[v] = 1;
	for (auto to : g[v]) {
		if (to == p)
			continue;
		calc(to, v);
		dp[v] = mul(dp[v], add(dp[to], 1));
	}
}

void dfs(int v = 1, int p = 0) {
	ans[v] = dp[v];
	int pref[sz(g[v]) + 1], suff[sz(g[v]) + 1];
	for (int i = 0; i < sz(g[v]); ++i)
		pref[i] = suff[i] = add(dp[g[v][i]], 1);
	for (int i = 1; i < sz(g[v]); ++i)
		pref[i] = mul(pref[i], pref[i - 1]);
	for (int i = sz(g[v]) - 2; i >= 0; --i)
		suff[i] = mul(suff[i], suff[i + 1]);
   	for (int i = 0; i < sz(g[v]); ++i) {   		
   		if (g[v][i] == p)
   			continue;
   		int to = g[v][i];
   		int tmp1 = dp[v];
   		int tmp2 = dp[to];
   		dp[v] = 1;
   		if (i)
   			dp[v] = mul(dp[v], pref[i - 1]);
   		if (i < sz(g[v]) - 1)
   			dp[v] = mul(dp[v], suff[i + 1]);
   		dp[to] = mul(dp[to], add(dp[v], 1));	
   		dfs(g[v][i], v);
   		dp[v] = tmp1;
   		dp[to] = tmp2;
   	}
}
	 
int main() {
	data();  	
	scanf("%d %d", &n, &m);
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
	}
	dp[0] = 0;
	calc();
	dfs();
	for (int i = 1; i <= n; ++i)
		printf("%d\n", ans[i] % m);
	debug;
}
 
/*
	Timus: 288481RF
	CodeForces: fractal
*/

Measured memory_bytes: 18944
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int sum = 0,maxi = 0;
    rep(i,0,N){
        int a;
        cin >> a;
        sum += a;
        maxi = max(maxi, a);
    }
    cout << sum - maxi/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	long long maxv=-10000000000000;
	long long minv=10000000000000;
	cin>>n;
	int a[n];
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		if (a[i]>maxv)  maxv=a[i];
		if (a[i]<minv)  minv=a[i];
	}
	cout<<maxv-minv;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int keta(int n) {
	int k = 0;
	for (int i = n; i > 0; i /= 10)k++;
	return k;
}

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


Measured memory_bytes: 3080
#include <iostream>

int main(int argc, char const *argv[]) {
    int n, count = 0, i = 0;
    std::cin >> n;
    int a[n];
    for (i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    i = 1;
    while (count < 100000) {
        i = a[i - 1];
        count++;
        if (i == 2) {
            std::cout << count << '\n';
            return 0;
        }
    }
    std::cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int H, W, i, j, f;
   
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0&&W==0)
            break;
        
        for (i=0; i<H; i++) {
            if ((i==0)||(i==H-1)) {
                for (f=1; f<=W; f++) {
                    printf("#");
                }
            }else{
                for (j=0; j<W; j++) {
                    if (j==0||j==W-1) {
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}




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

ll N, M, Q;
vector<vector<ll>> LR(501, vector<ll>(501, 0));

int main(void){
    
    cin >> N >> M >> Q;
    for(int i = 0; i < M; ++i){
        ll a, b; cin >> a >> b;
        ++LR[a][b];
    }
    for(int l = 1; l <= N; ++l){
        for(int i = 1; i + l <= N; ++i){
            ll j = i + l;
            LR[i][j] += LR[i + 1][j] + LR[i][j - 1] - LR[i + 1][j - 1];
        }
    }
    for(int i = 0; i < Q; ++i){
        ll a, b; cin >> a >> b;
        cout << LR[a][b] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 2944
class UnionFind:
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def is_same_root(self, x, y):
        return self.find(x) == self.find(y)

    def get_group_size(self, x):
        return -self.parents[self.find(x)]

N, M, K = map(int, input().split())
uf = UnionFind(N)

# friends = defaultdict(set)
friends = [0]*N
for _ in range(M):
    u, v = map(lambda x: int(x)-1, input().split())
    # friends[u].add(v)
    # friends[v].add(u)
    friends[u] += 1
    friends[v] += 1
    uf.union(u, v)
blocks = [0]*N
for _ in range(K):
    u, v = map(lambda x: int(x)-1, input().split())
    if uf.is_same_root(u, v):
        blocks[u] += 1
        blocks[v] += 1

res = [uf.get_group_size(i)-friends[i]-blocks[i]-1 for i in range(N)]
print(' '.join(map(str, res)))


Measured memory_bytes: 19604
#include<bits/stdc++.h>
using namespace std;
int a[200001],n,m,v[200001],cnf[200001],cx,cy,mx,my;
char s[200001];
struct yu
{
	int f[600001];
	void make(int x,int l,int r)
	{
		if (l==r){f[x]=-19260817;return;}
		make(x*2,l,l+r>>1),make(x*2+1,(l+r>>1)+1,r);
		f[x]=max(f[x*2],f[x*2+1]);
	}
	void chan(int x,int l,int r,int z,int o)
	{
		if (l==r){f[x]=o;return;}
		if ((l+r>>1)>=z)chan(x*2,l,l+r>>1,z,o);else chan(x*2+1,(l+r>>1)+1,r,z,o);
		f[x]=max(f[x*2],f[x*2+1]);
	}
	int find(int x,int l,int r,int st,int en)
	{
		if (l==st&&r==en)return f[x];
		int mid=l+r>>1;
		if (mid>=en)return find(x*2,l,mid,st,en);else
		if (mid<st)return find(x*2+1,mid+1,r,st,en);else
		return max(find(x*2,l,mid,st,mid),find(x*2+1,mid+1,r,mid+1,en));
	}
}od,ev;
bool che(int x,int q)
{
	if (q<0)return false;
	if (q%2==1)return od.find(1,1,n,max(x,1),n)>=q;else return ev.find(1,1,n,(max(x,1)),n)>=q;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]),v[i]=(a[i]>m?2:1),m=max(m,a[i]);
	od.make(1,1,n);
	for (int i=n;i;i--)
	{
		mx=od.find(1,1,n,a[i],n),my=ev.find(1,1,n,a[i],n);
		if (v[i]==1)od.chan(1,1,n,a[i],my+v[i]),ev.chan(1,1,n,a[i],mx+v[i]);else
		od.chan(1,1,n,a[i],mx+v[i]),ev.chan(1,1,n,a[i],my+v[i]);
	}
	for (int i=n;i;i--)cnf[i]=cnf[i+1]+v[i]-1;mx=my=0;
	for (int i=1;i<=n;i++)
	{
		od.chan(1,1,n,a[i],-19260817);ev.chan(1,1,n,a[i],0);
		if (che(my,cx+cnf[i+1]-cy+(a[i]>mx)))s[i]='0',cx+=a[i]>mx,mx=max(mx,a[i]);else
		if (che(max(mx,a[i]),cy+cnf[i+1]-cx-(a[i]>mx)))s[i]='0',cx+=a[i]>mx,mx=max(mx,a[i]);else
		s[i]='1',cy+=a[i]>my,my=max(my,a[i]);
	}
	if (cy!=cx)printf("-1\n");else printf("%s\n",s+1);
} 

Measured memory_bytes: 10340
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m1, m2, m3, m4, m5, m6, m7, m8, m9;
  cin >> n;
  m1=(n/1)%10, m2=(n/10)%10, m3=(n/100)%10, m4=(n/1000)%10, m5=(n/10000)%10;
  m6=(n/100000)%10,m7=(n/1000000)%10, m8=(n/10000000)%10, m9=(n/100000000)%10;
  if(n%(m1+m2+m3+m4+m5+m6+m7+m8+m9)==0){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
}

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

int N,M;

struct edge{int from,to,cost;};

edge E[2020];
int dist[1010];

vector<bool> ava;

const int INF = 1LL << 60;

void Bellmanford(const int &str){ 
  
  for(int i = 0; i < N; i++){ 
    dist[i] = -INF;
  }
  
  dist[str] = 0;
  
  
  vector<int> vec;
  
  for(int i = 0; i < N; i++){ 
    for(int j = 0; j < M; j++){
      
      int r1 = dist[E[j].from];
      int &r2 = dist[E[j].to];
      int w = E[j].cost;
      
      if( r2 < r1+w && r1 != -INF ){
        r2 = r1+w;
        if( i == N-1 ){ 
          vec.push_back(E[j].to); //この点はループに含まれる
        }
      }
    }
    
  }
  
  if( !vec.empty() ){ 
    for(int i = 0; i < (int)vec.size(); i++){ 
      if(ava[vec[i]]){ cout <<"inf" << endl; exit(0);}
      //N-1へと到達可能でないループは検出されても無視しなければならない
    }
    
  }
  
  cout << dist[N-1] << endl;
  
  
  return;
}
 

signed main(void){
  
  cin >> N >> M;
  
  vector<vector<int>> to(N);
  
  for(int i = 0; i < M; i++){ 
    
    int a,b,c; cin >> a >> b >> c; a--; b--;
    E[i].from = a; E[i].to = b; E[i].cost = c;
    
    to[b].push_back(a);

  }
  
  queue<int> Q;
  Q.push(N-1);
  ava = vector<bool>(N,false);
  ava[N-1] = true;
  
  while(!Q.empty()){ //N-1へと到達可能な点を全て列挙
    int p = Q.front(); Q.pop();
    for(auto q : to[p]){
      if( ava[q] ){ continue;}
      ava[q] = true;
      Q.push(q);
    }
  }
  
  Bellmanford(0);
  
  return 0;
} 


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=998244353;
int n,m,a[N],b[N],c[N];
ll dp[N][2];
void cal(int);
ll t=0;
bool flag=true;
unordered_map<int,int>vis[N];
int low=3,vv[N][10];
int get(int x,int y)
{
    return vv[x][x-y+low];
}
void ins(int x,int y,int z)
{
    vv[x][x-y+low]=z;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
void Dp()
{
    if(!vis[1][1]) dp[1][0]=dp[1][1]=1;
    else dp[1][vis[1][1]-1]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<2;j++)
            for(int k=0;k<2;k++)
                if(dp[i-1][k])
        {
            int v=(j^k);
            if(get(i-1,i)&&get(i,i-1))
            {
                int s=get(i-1,i)-1^get(i,i-1)-1;
                if(s^v) continue;
            }
            if(i!=n&&get(i+1,i-1)&&get(i-1,i+1))
            {
                int s=get(i-1,i+1)-1^get(i+1,i-1)-1;
                if(s^j) continue;
            }
            if(get(i,i)&&get(i,i)-1!=j) continue;
            int t1=2,t2=2;
            if(get(i-1,i)||get(i,i-1)) t1--;
            if(get(i+1,i-1)||get(i-1,i+1)||i==n) t2--;
            (dp[i][j]+=dp[i-1][k]*t1*t2)%=mod;
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        c[i]++;
        vis[a[i]][b[i]]=c[i];
        if(abs(a[i]-b[i])<=2) ins(a[i],b[i],c[i]);
    }
    Dp();
    if(n>3)
        t=((ll)n*n-n-(n-1)*2-(n-2)*2)/2;
    for(int i=1;i<=m;i++)
    {
        if(abs(a[i]-b[i])<=2) continue;
        if(vis[a[i]][b[i]]&&vis[b[i]][a[i]])
        {
            if(a[i]>b[i]) t--;
            if(vis[a[i]][b[i]]!=vis[b[i]][a[i]]) flag=false;
        }
        else t--;
    }
    if(!flag){printf("0\n");return 0;}
    printf("%lld\n",qpow(2,t)*(dp[n][0]+dp[n][1])%mod);
}


Measured memory_bytes: 15232
S = input()
tmp = 0
ans = 0
if len(S) == 1:
    print(S)
else:
    for i in range(2**(len(S)-1)):
        form = ''
        for j, x in enumerate(format(i ^ 0, '0'+str(len(S)-1)+'b')):
            form += S[j]
            if x == '0':
                continue
            form += '+'
        form += S[-1]
        ans += eval(form)

    print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    int ans=0;
    int active=0;
    for(int i=0;i<n;i++){
        if(active>=h[i]){
            active=h[i];
        }
        else{
            ans+=h[i]-active;
            active=h[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 2000000
int x,a[N];

void heap(int i){
  int l,r,large,t;
  l=2*i;
  r=2*i+1;
  if(l<=x && a[l]>a[i]){
    large=l;
  }
  else large=i;
  if(r<=x && a[r]>a[large]){
    large=r;
  }
  if(large!=i){
    t=a[i];
    a[i]=a[large];
    a[large]=t;
    heap(large);
  }
}
int extract(){
  int max;
  if(x<1) return;
  max=a[1];
  a[1]=a[x--];
  heap(1);
  return max;
}
void increase(int i,int key){
  int swap;
  if(key<a[i]) return;
  a[i]=key;
   while(i>1 && a[i/2]<a[i]){
    swap=a[i];
    a[i]=a[i/2];
    a[i/2]=swap;
    i=i/2;
  }
}
void insert(int key){
  x++;
  a[x]=-10000000;
  increase(x,key);
}

int main(){
  int key;
  char c[10000];
  while(1){
         scanf("%s",c);
    if(strcmp(c,"end")==0) break;
    if(c[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(c,"extract")==0){
      printf("%d\n",extract());
    }
    else break;
  }
  return 0;
}


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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

//long long hornest_search(long long bit, vector<vector<pair<long long, long long>>>)
bool honest_search(long long bit, vector<vector<pair<long long, long long>>> x_y, long long N)
{
    //i番目の人の発言を基にhonestを探す。
    for (long long i = 0; i < N; i++)
    {
        //bit & (1 << i) を使うことで、半自動的に全部の通りを割り当てている。
        // 11010101 ~ 0番目の人:正直,1の人:不親切,2の人:正直,3:不親切....
        //search対象がhonestではない場合
        if (!(bit & (1 << i)))
            continue;

        //i番目の人の証言確認
        for (pair<long long, long long> xy : x_y[i])
        {
            int x = xy.first;  //x番目の人が
            int y = xy.second; //0 or 1

            //iの話では不親切(y=1)だが,<bitset>(8)では正直者扱い
            if (y == 1 && !(bit & (1 << x)))
                return false;

            //iの話では正直(y=0)だが,bitでは不親切扱い
            if (y == 0 && (bit & (1 << x)))
                return false;

            //完全に一致するデータは一つだけ?
            //bitは2^N通りであり,その分だけ繰り返しているだけ,
        }
    }
    //正直者と嘘つきの分け方は,全ての証言+bitの照らし合わせで決まる。
    //なので,return trueはfor抜けた後、
    return true;
}

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

    vector<vector<pair<long long, long long>>> x_y(N);
    for (int i = 0; i < N; i++)
    {
        long long A;
        cin >> A;
        //x_y[i].resize(A);
        for (int j = 0; j < A; j++)
        {
            long long x, y;
            cin >> x >> y;
            x_y[i].push_back({x - 1, y}); //x_y[i][j].first >> x_y[i][j].secondでもok
            //cin >> x_y[i][j].first >> x_y[i][j].second;
            //--x_y[i][j].first; // 0-indexed に
        }
    }

    //bit < 2^N

    long long max_h = 0;
    for (long long bit = 0; bit < (1 << N); bit++)
    {
        if (honest_search(bit, x_y, N))
        {
            long long count = 0;
            for (int i = 0; i < N; i++)
            {
                if (bit & (1 << i))
                {
                    count++;
                }
            }
            max_h = max(max_h, count);
        }
    }
    cout << max_h << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int A[21];
    int B[21];
    int C[21];
    int sum1=0;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>B[i];
        sum1+=B[i];
    }
    for(int i=0;i<n-1;i++)
    {
        cin>>C[i];
    }
    for(int i=0;i<n-1;i++)
    {
        if(A[i+1]-A[i]==1)
          sum1+=C[A[i]-1];
    }
    cout<<sum1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#define int long long
using namespace std;
signed main(){
    int x; cin>>x;
    int ans=x/500*1000;
    x%=500;
    ans+=x/5*5;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  int c=0;
  cin>>s;
  rep(i,4){
    if(s[i]=='+') c++;
    else    c--;
  }
  cout<<c<<endl;
 return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int n;cin >> n;
    double x;
    string u;
    double y=0;
    rep(i,n){
        cin >> x >> u;
        if(u=="BTC"){
            y=y+x*380000;
        }
        else{
            y+=x;
        }
    }
    out(y);
    return 0;
}




Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int m, result = 0;
    string s;
    cin >> m >> s;
    s += "  ";
    for (int i = 0; i < m; i++)
      if (s[i] == 'I') {
        int count = 0;
        while (s[i+1] == 'O' && s[i+2] == 'I') {
          count++;
          i += 2;
        }
        result += max(0, count + 1 - n);
      }
    cout << result << endl;
  }
}

Measured memory_bytes: 1928
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<P> v(n);
    FOR(i,0,n){
      ll in;
      cin>>in;
      v[i] = P(in,i+1);
    }
    sortAl(v);
    FOR(i,0,n){
      cout<<v[i].second;
      if(i != n-1) cout<<" ";
      else cout<<endl;
    }
}


Measured memory_bytes: 2432
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long top = N;
		long sum = 0;
		for (long i = 1; i <= N; i++) {
			long bottom = N / (i + 1);
			if (top == bottom) {
				break;
			}

			for (long j = top; j > bottom; j--) {
				long mod = N % j;
				if (mod == i) {
					sum += j;
				}
				if (mod >= i) {
					break;
				}
			}
			top = bottom;
		}
		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 22484
import math 
N,D = map(int,input().split())
X=[]
count=0
for i in range(N):
    x = list(map(int,input().split()))
    X.append(x)
for i in range(N-1):
    for j in range(i+1,N):
        s = 0
        for k in range(D):
            s += (X[i][k]-X[j][k])**2
        if math.sqrt(s).is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

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

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

const int mod = 1e9 + 7; 

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

const int N = 2e5 + 5;
int l[N], r[N], k[N];
vector<int> g[N], g1[N];
bool vis[N];

void solve() {
	int n;
    sc(n);
    fr(i, 1, n) {
        g[i].clear();
        g1[i].clear();
        vis[i] = 0;
    }
    fr(i, 1, n) {
        sc(k[i], l[i], r[i]);
        g[k[i]].pb(i);
        g1[k[i] + 1].pb(i);
    }
    ll ans = 0;
    set<pii> s;
    rf(i, n, 1) {
        for(int j : g[i]) {
            s.insert({l[j] - r[j], j});
        }
        if(!s.empty()) {
            pii p = *s.rbegin();
            if(p.fi > 0) {
                vis[p.se] = 1;
                s.erase(p);
            }
        }
    }
    s.clear();
    fr(i, 1, n) {
        for(int j : g1[i]) {
            s.insert({r[j] - l[j], j});
        }
        if(!s.empty()) {
            pii p = *s.rbegin();
            if(p.fi > 0) {
                vis[p.se] = 1;
                s.erase(p);
            }
        }
    }
    fr(i ,1, n) {
        if(vis[i]) ans += max(l[i], r[i]);
        else ans += min(l[i], r[i]);
    }
    cout << ans << endl;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 27448
while True:
    L = map(int,raw_input().split())
    H = (L[0])
    W = (L[1])
    
    if H == 0 and W == 0:break
    for x in range(0,H):
        if x % 2 == 0:
            if W % 2 == 1:
                print "{}#".format("#."* (W / 2))
            else:
                print "#." * (W / 2)
        else:
            if W % 2 == 1:
                print "{}.".format(".#"* (W / 2))
            else:
                print ".#" * (W / 2)

    print ""

Measured memory_bytes: 6412
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cmath>

using namespace std;

typedef complex<double> P;
int n;
class Circle{
public:
  P cp;
  double r;
};

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double INF=-1;
const int band=10;
int main(){
  int n;
  while(cin>>n&&n!=0){
    int xsortedIdxs[100001];
    int ysortedIdxs[100001];
    vector<Circle> cs;
    vector<pair<double,int> > xsorted;
    vector<pair<double,int> > ysorted;
    double x,y,r;
    for(int i = 0; i < n; i++){
      Circle c;
      cin>>r>>x>>y;
      c.r=r;
      c.cp=P(x,y);
      cs.push_back(c);
      xsorted.push_back(make_pair(x,i));
      ysorted.push_back(make_pair(y,i));
    }
    sort(xsorted.begin(),xsorted.end());
    sort(ysorted.begin(),ysorted.end());
    for(int i = 0; i < n; i++){
      xsortedIdxs[xsorted[i].second]=i;
      ysortedIdxs[ysorted[i].second]=i;
    }
    double minDist=INF;
    for(int i = 0; i < n; i++){
      // x,zÀW»ê¼êÉÂ¢ÄA
      // ©ªÌê©ç-10,+10ÌÆ±ëðTõ
      int xsidx=xsortedIdxs[i];
      int ysidx=ysortedIdxs[i];
      for(int j = xsidx; j < min(xsidx+band,n);j++){
	int idx=xsorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = xsidx; j >= max(0,xsidx-band); j--){
	int idx=xsorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = ysidx; j < min(ysidx+band,n);j++){
	int idx=ysorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = ysidx; j >= max(0,ysidx-band); j--){
	int idx=ysorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
    }
    printf("%.8f\n",minDist);
    //cout<<minDist<<endl;
  }

  return 0;
}

Measured memory_bytes: 6596