akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp109 {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            var S = new string[n];
            var S_list = new List<List<string>>();

            var kari = new List<char>();

            for (int i = 0; i < n; i++) {
                S[i] = Console.ReadLine();

                kari = S[i].ToCharArray().OrderBy(x => x).ToList();
                var replaced_list = new List<string>();
                int index = 0;
                for (int k = 0; k < kari.Count(); k++) {
                    if (k == 0) {
                        
                    } else if (kari[k] == kari[k - 1]) {
                        index++;
                    } else {
                        index = 0;
                    }
                    replaced_list.Add(kari[k].ToString() + index.ToString());
                }

                S_list.Add(replaced_list);
            }

            var ans = S_list[0];

            for (int i = 0; i < n; i++) {
                ans = ans.Intersect(S_list[i]).ToList();
            }

            var finalList = new List<char>();

            for (int i = 0; i < ans.Count(); i++) {
                finalList.Add(ans[i][0]);
            }

            Console.WriteLine(string.Join("", finalList.OrderBy(x => x).ToList()));


        }
    }
}


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

int main ()
{
	int n;
  	cin >> n;
  	for (int i = 0; i < 100000;  i++)
    {
    	if (i * 108 / 100 == n)
        {
        	cout << i << endl;
          	break;
        }
      	else if (i == 100000 - 1)
        {
        	cout << " :(" << endl;
        }
    }
}


Measured memory_bytes: 256
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(len(S_str)):
        digits = len(S_str) - i
        if digits < 3:
            break

        # 全部7の状態からはじめて、次は5次は3というふうにやる
        bfs(digits, '')

    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()


Measured memory_bytes: 4852
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int answer = 700;

    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) == 'o') {
        answer += 100;
      }
    }

    System.out.println(answer);
  }
}


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

string v[12];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void visit(int x, int y) {
	if (x<0 || 11<x || y<0 || 11<y || v[y][x]=='0') return ;
	v[y][x] = '0';
	for (int i=0; i<4; ++i) {
		visit(x+dx[i], y+dy[i]);
	}
}

int main() {
	while (1) {
		for (int i=0; i<12; ++i) {
			if ( ! cin.eof()) {
				cin >> v[i];
			} else {
				return 0;
			}
		}

		int ans = 0;
		for (int y=0; y<12; ++y) {
			for (int x=0; x<12; ++x) {
				if (v[y][x] != '0') {
					visit(x, y);
					++ ans;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1188
k = input()
d = int(input())

mod = 10 ** 9 + 7

dp = [[0] * d for _ in range(2)]
dp[1][0] = 1

for i in k:
    i = int(i)
    dp2 = [[0] * d for _ in range(2)]

    for j in range(d):
        dp2[1][(j + i) % d] += dp[1][j]

    for j in range(d):
        for k in range(i):
            dp2[0][(j + k) % d] += dp[1][j]

    for j in range(d):
        for k in range(10):
            dp2[0][(j + k) % d] += dp[0][j]

    dp = [[j % mod for j in k] for k in dp2]

print((dp[0][0] + dp[1][0] - 1) % mod)


Measured memory_bytes: 45276
#include <stdio.h>
int main(void){
    int i ,dice[7] ;
    char order[101] ;
    
    for(i = 1 ; i < 7 ; i++){
        scanf("%d" , &dice[i]) ;
    }
    
    scanf("%s" , order) ;
    
    for(i = 0 ; order[i] != '\0' ; i++){
        dice[0] = dice[1] ;
        
        switch(order[i]){
            
            case 'E' :
                dice[1] = dice[4] ;
                dice[4] = dice[6] ;
                dice[6] = dice[3] ;
                dice[3] = dice[0] ;
                break ;
                
            case 'S' :
                dice[1] = dice[5] ;
                dice[5] = dice[6] ;
                dice[6] = dice[2] ;
                dice[2] = dice[0] ;
                break ;
                
            case 'W' :
                dice[1] = dice[3] ; 
                dice[3] = dice[6] ;
                dice[6] = dice[4] ;
                dice[4] = dice[0] ;
                break ;
                
            case 'N' :
                dice[1] = dice[2] ;
                dice[2] = dice[6] ;
                dice[6] = dice[5] ;
                dice[5] = dice[0] ;
                break ;
        }
    }
    printf("%d\n" , dice[1]) ;
    return 0 ;
}


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

void Main()
{
    vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    k--;
    cout << v[k] << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n, ans;
    double t, a;
    int mn = 1e9;
    cin >> n >> t >> a;
    rep(i,n) {
        int h, d;
        cin >> h;
        d = (t*1000-h*6)-a*1000;
        if(d<0) d*=-1;
        if(mn>d) {
            mn = d;
            ans = i+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    string s;
    cin>>s;
    int r=0,b=0;
    rep(i,N){
        if(s.at(i)=='R')r++;
        else b++;
    }
    if(r>b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3524
# -*- coding: utf-8 -*-
n,k = map(int,raw_input().split())
d = map(int,raw_input().split())
flg = 1
num = n-1
while(flg):
    num += 1
    strnum = str(num)
    check = [strnum.find(str(i))+1 for i in d]
    flg = sum(check)
print(num)

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

int main() {
    
    char a, b;
    cin >> a >> b;
    
    if(a=='H' && b=='D') cout << "D" << endl;
    else if(a=='D' && b=='H') cout << "D" << endl;
    else if(a=='H' && b=='H') cout << "H" << endl;
    else if(a=='D' && b=='D') cout << "H" << endl;
    
    
    
	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

char m[16][16];

void rec(int x, int y) {
  if (x < 0 || x >= 12 || y < 0 || y >= 12 || m[x][y] == '0')
    return;
  m[x][y] = '0';
  rec(x+1, y);
  rec(x-1, y);
  rec(x, y+1);
  rec(x, y-1);
}

int main() {
  while (scanf("%s", m[0]) == 1) {
    int i, x, y, c = 0;
    for (i = 1; i < 12; i++)
      scanf("%s", m[i]);
    for (x = 0; x < 12; x++)
      for (y = 0; y < 12; y++)
        if (m[x][y] == '1') {
          rec(x, y);
          c++;
        }
    printf("%d\n", c);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

bool reverseStr(string mem, string sx) {
    reverse(mem.begin(), mem.end());
    if (mem.at(0) == sx.at(0)) return true;
    else return false;
}

int main() {
    ll N; cin >> N;
    map<string, int> ch;
    vector<string> W(N);
    rep(i, N) {
        cin >> W.at(i); ch[W[i]]++;
    }
    rep(i, N) {
        if (2 <= ch[W[i]]) {
            cout << "No" << endl;
            return 0;
        }
    }

    string mem = W.at(0);
    reps(i, N - 1) {
        string sx = W.at(i);
        if (!reverseStr(mem, sx)) {
            cout << "No" << endl;
            return 0;
        }
        mem = W.at(i);
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3636
import math

a,b,h,m = map(int, input().split())

angle_h = 30*h + 0.5*m
angle_m = 6*m

vertex_c = abs(angle_h - angle_m)
if (vertex_c > 180):
    vertex_c = 360 - vertex_c

c = a**2 + b**2 - 2*a*b*(math.cos(math.radians(vertex_c)))

print(c**(1/2))

Measured memory_bytes: 9504
#include <bits/stdc++.h>
/**
*   author: j o s e m a g o
*   date:
**/
using namespace std;
#pragma GCC optimize ("Ofast")
#define f first
#define s second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mset(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define sz(x) ((int)(x).size())
#define rsz resize
#define ln "\n"

typedef double db;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ld PI = 2*acos(0.0);
const int MOD = 1000000007;
const int JJJ = 1009;

char matrix[JJJ][JJJ];
int dp[JJJ][JJJ],f,c;




int main(){

  //freopen("input.in","r",stdin);
  //freopen("input.out","w",stdout);

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

    cin >> f >> c;
    for(int i = 1;i <= f;i++){
        for(int j = 1;j <= c;j++){
            cin >> matrix[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i = 1;i <= f;i++){
        for(int j = 1;j <= c;j++){
            if(i == 1 && j == 1) continue;
            if(matrix[i][j] != '#'){
                if(matrix[i-1][j] != '#'){
                    dp[i][j] = (dp[i][j]+dp[i-1][j])%MOD;
                }
                if(matrix[i][j-1] != '#'){
                    dp[i][j] = (dp[i][j]+dp[i][j-1])%MOD;
                }
            }
        }
    }

    cout<<dp[f][c];








    return 0;
}
/*
3 4
...#
.#..
....

5 2
..
#.
..
.#
..

5 5
..#..
.....
#...#
.....
..#..


20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................

*/


Measured memory_bytes: 5248
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;


int main(){
    cin>>sa>>sb;
    while(sa.size()!=0 or sb.size()!=0){
        if(sa.size()!=0){
            C sa[0];
            sa.erase(sa.begin());
        }
        
        if(sb.size()!=0){
            C sb[0];
            sb.erase(sb.begin());
        }
    }
    cout<<endl;


    
}

Measured memory_bytes: 256
#include <iostream>
//#include <algorithm>
//#include "math.h"

#define EPS 1.e-12

using namespace std;

int main(){
	int count;
	double xa,ya,ra,xb,yb,rb;
	cin >> count;
	for(int i=0;i<count;i++){
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		double dist2 = (xa-xb)*(xa-xb)+(ya-yb)*(ya-yb);
		//		double dist = (xa-xb)*(xa-xb)+(xa-xb)*(xa-xb);
		//cout << dist2 << " " << (ra+rb)*(ra+rb) << endl;
		//cout << ((dist2 -(ra+rb)*(ra+rb))>0) << endl;
		if(dist2>(ra+rb)*(ra+rb)+EPS){
			cout << 0 << endl;
		}
		else if(dist2 >= (ra - rb)*(ra - rb)){
			cout << 1 << endl;
		}
		else if(ra>rb){
			cout << 2 << endl;
		}
		else{
			cout << -2 << endl;
		}
	}
}		

Measured memory_bytes: 0
def okay_ornot(n):
    if n > 81:
        print("No")
        return
    else:
        for i in range(9):
            for j in range(9):
                if (i+1) * (j+1) == n:
                    print("Yes")
                    return
        print("No")
        return

n = int(input())
okay_ornot(n)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
// https://boostjp.github.io/tips/multiprec-int.html
// https://boostjp.github.io/tips/multiprec-float.html
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using namespace std;

#define ll long long
#define ld long double
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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

struct UnionFind {
    ll n;
    vector<ll> par,rank;

    UnionFind(ll N) : par(N) {
        n = N;
        REP(i,n) par[i] = i;
        rank.assign(n, 1);
    }

    ll root(ll x) {
        ll tmp = x;
        while(par[tmp] != tmp) {
            tmp = par[tmp];
        }
        return par[x] = tmp;
    }

    void unite(ll x, ll y) {
        ll rootX = root(x);
        ll rootY = root(y);
        if (rootX == rootY) return;
        rank[rootY] += rank[rootX];
        par[rootX] = rootY;
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll count(ll x) {
        return rank[root(x)];
    }
};

ll n,m,k;
int main() {
    INIT();

    cin >> n >> m;

    UnionFind unionFind(n);
    vector<ll> blocks(n, 1);
    REP(i,m) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        unionFind.unite(a,b);
    }
    unordered_map<ll, int> m;
    REP(i,n) {
        m[unionFind.root(i)]++;
    }
    cout << m.size() - 1;
}

Measured memory_bytes: 8728
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define ll long long int
using namespace std;

void Solve(  ){
    map<string, int> poll;
    int n;
    cin >> n;
    string s;
    int highest = 0;
    for(int i=0; i<n; i++)
    {
        cin >> s;
        poll[s]++;
        if(poll[s] > highest)
        {
            highest = poll[s];
        }
    }
    //cout << highest << '\n';
    map<string, int> :: iterator itr;
    for(itr = poll.begin(); itr != poll.end(); ++itr)
    {
        if( itr -> second == highest) cout << itr -> first << '\n';
    }
}
int main(){
   // int t;
   // cin >> t;
   // while(t--)
   {
        Solve( );
      //  cout << '\n';
   }
    return 0;
}


Measured memory_bytes: 19212
///*/////////////////////////////*///
/// IN THE NAME OF ALMIGHTY ALLAH ///
///*/////////////////////////////*///

///*////////////////////*///
/// Author : SAIFULLAH29 ///
///*////////////////////*///

///*//////////////////////////////////////////*///
/// "When you want something, all the universe ///
///  conspires in helping you to achieve it."  ///
///              - Paulo Coelho, The Alchemist ///
///*//////////////////////////////////////////*///

#include <bits/stdc++.h>

#define SS           " "
#define endl         "\n"
#define EPS          1e-9
#define gcd          __gcd
#define pb           push_back
#define pi           acos(-1.0)
#define Ars          greater<int>()
#define vi           vector<int>
#define vvi          vector<vector<int> >
#define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long              ll;
typedef double                 dbl;
typedef unsigned long long     ull;

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

void solve()
{
    ll n, m=0, x;
    cin>>n;
    x = n;

    while(x != 0)
    {
        m += x%10;
        x /= 10;
    }

    if(n%m == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

int main()
{
    wow

    int t=1;
    //cin>>t;

    while(t--)
        solve();

    return 0;
}

///*////////////////////////////////////////////*///
/// "There is only one thing that makes a dream  ///
/// impossible to achieve: the fear of failure." ///
///                - Paulo Coelho, The Alchemist ///
///*////////////////////////////////////////////*///


Measured memory_bytes: 3656
N,A,B=map(int,input().split())
MOD=10**9+7
ans=pow(2,N,MOD)-1

def nCr(n,r):
    res=1
    fac=1
    for i in range(r):
        res *= n-i
        res %= MOD
        fac *= i+1
        fac %= MOD
    return res*pow(fac, MOD-2, MOD)%MOD

ans -= nCr(N,A)
ans -= nCr(N,B)

print(ans%MOD)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
vector<int>v[maxn];
int dp[maxn];
bool mark;
bool marv[maxn];
int h[maxn];
void ok_h(int v1,int par){
	marv[v1]=true;
	for(int i=0;i<v[v1].size();i++){
		if(marv[v[v1][i]]==false){
			h[v[v1][i]]=h[v1]+1;
			ok_h(v[v1][i],v1);
		}
	}
}
void dfs(int v1,int par){
	int cnt=0;
	int cnv=0;
	marv[v1]=true;
	for(int i=0;i<v[v1].size();i++){
		if(marv[v[v1][i]]==false&&h[v[v1][i]]>h[v1]){
			dfs(v[v1][i],v1);
		}
		if(dp[v[v1][i]]==1&&h[v[v1][i]]>h[v1]){
			cnt++;
		}
		else if(h[v[v1][i]]>h[v1]){
			cnv++;
		}
	}
	if(v1==1){
		if(cnt>=1&&cnv==0){
			mark=true;
		}
	}
	if(cnv>=2){
		mark=true;
	}
	if(v[v1].size()==1&&v1!=1){
		dp[v1]=0;
	}
	else if(cnv==1){
		dp[v1]=1;
	}
	else{
		dp[v1]=0;
	}
//	cout<<v1<<" "<<dp[v1]<<" "<<cnv<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(false);cout.tie(false);
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a;
		int b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	h[1]=1;
	ok_h(1,-1);
	fill(marv,marv+maxn,0);
	dfs(1,-1);
	if(mark==true){
		cout<<"First";
	}
	else{
		cout<<"Second";
	}
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



// https://kimiyuki.net/writeup/algo/etc/icpc-2017-asia-c/
// interval 5, 5, 7, 7
// offset 0, 5, 8, 14


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    // ヒント 間隔hが一定
   
    int n, t;
    cin >> n >> t;
    
    ll offset = 0, interval = 0;
    rep(i, n) {
        int h;
        cin >> h;
        chmax(interval, h);
        ll ans = (t - offset) / interval;
        ans += ((t - offset) % interval >= h); // 下の2 20
        chmax(ans, 0LL);
        cout << ans + 1 << endl; // 必ず1以上
        offset += h;
    }
    
}


/*
 you may assume : may 許可, とみなして良い
 
 */

/*
 3 20
 5 7 3
 
 11111222223333344444
      111111122222223
             111    2
 
 5 3 2
 */

/*
 4 30
 5 3 7 2
 
 7 6 4 3
 */

/*
 
 2 20
 7 4
 
 11111112222222333333
        1111   2222
 */



Measured memory_bytes: 3212
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
x = [0 for i in range(N)]
x[0] = A[0]
ans = 0
for i in range(1,len(A)):
    x[i] = x[i-1]+A[i]
x.sort()
a = Counter(x)
for k,v in a.items():
    ans += v*(v-1)//2
    if k==0:
        ans += v
print(ans)


Measured memory_bytes: 112644
#include<stdio.h>
int main(void){
	int n;
	long long int sum=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		if((i+1)%3!=0&&(i+1)%5!=0){
			sum+=i+1;
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 1732
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    double w, h, area;
    int multi = 0;
    int x, y;
    int i;

    scanf("%lf%lf%d%d", &w, &h, &x, &y);
    area = w * h * 0.5;
    if (x == w * 0.5 && y == h * 0.5)
        multi = 1;

    printf("%f %d\n", area, multi);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
int a[maxn],dis[maxn];
map<int,int> mp;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%d",&a[i]);
		dis[i]=a[i];
		mp[a[i]]=i;
	}
	sort(dis,dis+n);
	int con=0;
	for(int i=0;i<n;++i)
	{
		if( (mp[dis[i]]&1) != (i&1) )++con;
	}
	printf("%d\n",con/2);
	return 0;
}



Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        String[] sousa = new String[n];
        String s1 = sc.next();
        for (int i=1;i<=n;i++) {
            String s2 = "";
            if (sc.hasNext()) {
                s2 = sc.next();
            }
            if (s1.equals("AB")) {
                if (a==0 && b==0) {
                    System.out.println("No");
                    return;
                } else {
                    if (a>b) {
                        a--;
                        b++;
                        sousa[i-1] = "B";
                    } else if (a==b && s2.equals("BC")) {
                        a--;
                        b++;
                        sousa[i-1] = "B";
                    } else {
                        a++;
                        b--;
                        sousa[i-1] = "A";
                    }
                }
            }
            if (s1.equals("AC")) {
                if (a==0 && c==0) {
                    System.out.println("No");
                    return;
                } else {
                    if (a>c) {
                        a--;
                        c++;
                        sousa[i-1] = "C";
                    } else if (a==c && s2.equals("BC")) {
                        a--;
                        c++;
                        sousa[i-1] = "C";
                    } else {
                        a++;
                        c--;
                        sousa[i-1] = "A";
                    }
                }
            }
            if (s1.equals("BC")) {
                if (b==0 && c==0) {
                    System.out.println("No");
                    return;
                } else {
                    if (b>c) {
                        b--;
                        c++;
                        sousa[i-1] = "C";
                    } else if (b==c && s2.equals("AC")) {
                        b--;
                        c++;
                        sousa[i-1] = "C";
                    } else {
                        b++;
                        c--;
                        sousa[i-1] = "B";
                    }
                }
            }
            s1 = s2;
        }
        System.out.println("Yes");
        for (int i=0;i<n;i++) {
            System.out.println(sousa[i]);
        }
    }
}


Measured memory_bytes: 59604
public class Main {
    public static void main(String[] args) {
        java.util.Scanner s=new java.util.Scanner(System.in);
        s.nextInt();
        long m[]=new long[26],a=1;
        for(char c:s.next().toCharArray())m[c-97]++;
        for(int i=0;i<26;i++)a=a*(m[i]+1)%1000000007;
        System.out.println(--a);
    }
}

Measured memory_bytes: 28068
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int sumDigits(int number) {
    int sum = 0;
    while (number > 0) {
        sum += number % 10;
        number /= 10;
    }
    return sum;
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int sum = 0;
    for (int i = 1; i <= N; i++) {
        if (A <= sumDigits(i) && sumDigits(i) <= B) {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n, m = map(int, input().split())

xy_dict = {}
for i in range(1,n+1):
    xy_dict[i] = []

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

dp = [-1]*(n+1)
dp[0] = 0

def get_longest(x):
    global dp

    if( dp[x] >= 0):
        return dp[x]
    else:
        y_list = xy_dict[x]
        temp_max = 0
        for y in y_list:
            temp_max = max(temp_max, get_longest(y)+1)

        dp[x] = temp_max
        return temp_max

ans = 0
for i in range(1,n+1):
    ans = max(ans, get_longest(i))

print(ans)

Measured memory_bytes: 67552
from heapq import heappush, heappop
inputs = lambda: map(int, raw_input().split())
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in xrange(q):
    a, v = inputs()
    data[a] += v
    T[a] = t

    heappush(que, (-data[a], a, t))
    while 1:
        v, k, p = heappop(que)
        if T[k] == p:
            print k, -v
            heappush(que, (v, k, p))
            break

Measured memory_bytes: 37896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    string s;
    cin >> s;
  	
  	int ans = 700;
    if(s[0] == 'o') ans += 100;
	if(s[1] == 'o') ans += 100;
  	if(s[2] == 'o') ans += 100;

  	cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
from heapq import nlargest
x,y,z,k=map(int,input().split())
A,B,C=[list(map(int,input().split()))for _ in[0]*3]
D=nlargest(k,(a+b for a in A for b in B))
E=nlargest(k,(d+c for d in D for c in C))
for i in E:
    print(i)

Measured memory_bytes: 4084
n = $stdin.gets.to_i
ary = []
result = 0
a = 0
b = 0
docchimo = 0
lk=false
n.times do |i|
  s = $stdin.gets
  ary[i] = s
  if s[0] == 'B'
    b += 1
  end
  if s[-2] == 'A'
    a += 1
  end
  if s[0] == 'B' && s[-2] == 'A'
    docchimo += 1
  end
  
  if s[0] != 'B' && s[-2] == 'A'
    lk=true
  end

  result += ary[i].scan("AB").size
end


if docchimo > 0 && a==b && !lk
  result -=1
end
puts result + [a,b].min

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

int main(){
    int H,W;
    cin >> H >> W;
    while (H!=0){
        for (int i=0; i < H;i++){
            for (int j=0; j<W; j++){
                cout << "#";
            }
            cout <<endl;
        }
        cout << endl;
        cin >> H >> W;
    }    
    return 0;
}


Measured memory_bytes: 3056
def func() :
    n,m=map(int,input().split())
    a={}
    for i in range(n) :
        s = input()
        for c in list(s):
            if c in a:
                a[c]+=1
            else :
                a[c] = 1
    c1=sum(map(lambda x : x%2 , a.values()))
    c2=sum(map(lambda x : x//4*4, a.values()))
    if c1 != n*m%2 or c2 < (n//2*2)*(m//2*2) :
        print('No')
    else :
        print('Yes')
func()

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

class TM{
public:
  int id, s, p;
  TM(){}
  TM(int id):id(id){ s = p = 0;}
  bool operator < ( const TM &t) const{
    if ( s == t.s ){
      if ( p == t.p ) return id > t.id;
      return p < t.p;
    } return s > t.s;
  }
};

int M, T, P, R;
bool S[51][11];
int X[51][11];

void solve(){
  int m, t, p, j;
  TM B[51];
  B[0] = TM(0); B[0].s = 100;
  for ( int i = 1; i <= T; i++ ) B[i] = TM(i);

  for ( int i = 0; i < R; i++ ){
    cin >> m >> t >> p >> j;
    if ( j == 0 ){
      B[t].s++;
      B[t].p += 20*X[t][p] + m;
    } else {
      X[t][p]++;
    }
  }
  sort(B, B+(T+1));

  for ( int i = 1; i <= T; i++ ) {
    if ( i> 1 ){
      if ( B[i].s == B[i-1].s && B[i].p == B[i-1].p ) cout << "=";
      else cout << ",";
    }
    cout << B[i].id;
  }
  cout << endl;

}

main(){
  while(1){
    cin >> M >> T >> P >> R;
    if ( M == 0 ) break;
    for ( int i = 1; i <= T; i++ ){
      for ( int j = 1; j <= P; j++ ){
	S[i][j] = false;
	X[i][j] = 0;
      }
    }
    solve();
  }
}

Measured memory_bytes: 1168
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
# include <stdio.h>
#include <bits/stdc++.h>

const int maxn = 3e5 + 111;

using namespace std;        

const int mod = 1e9 + 7;

int n;
long long cnt[5000], tmp[5000], dp[5000];

int main() {
    ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 2; i <= n; i++) {
	    int x = i;
	    for(int j = 2; j * j <= x; j++)
	        while(x % j == 0){
	            cnt[j]++;
	            x/=j;
	        }
	    if(x > 1) cnt[x]++;
	}
	for(int i= 0; i <= cnt[2]; i++) dp[i + 1] = 1;
	int last = 2;
	long long ans = 0;
	for(int i = 3; i <= n; i++) {
	    if(!cnt[i]) continue;
	    for(int j = 0; j <= 80; j++)
	    for(int k = 0; k <= cnt[i]; k++){
	        tmp[(j + 1) * (k + 1)] += dp[j + 1];
	    
	    }
	    for(int j = 0; j <= 80; j++)
	        dp[j] = tmp[j];
	   for(int j = 0; j <= 80; j++)
	        tmp[j] = 0;
	    
	}
	cout << dp[75];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

ll lcm( int m, int n )
{
	return ((ll)m / __gcd(m, n) * n);
}
 
 
int main()
{
  ll N,M;
  cin >> N >> M;
  string S;
  string T;
  cin >> S;
  cin >> T;
 
 
  int step = __gcd(N,M);
  ll L = lcm(N,M);

  // cout << step << endl;
  for(int i=0;i<step;i++){
    // printf("===== i %d\n",i);
    // cout << L/M <<endl;
    // cout <<"S:" << S[i*N/step] << endl;
    // cout << L/N <<endl;
    // cout <<"T:" << T[i*M/step] << endl;
    if(S[i*N/step] != T[i*M/step]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (ll) L << endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 1;
  while (1) {
    if ((a-1) * (cnt-1) + a >= b) break;
    cnt++;
  }
  if (b == 1) cout << 0 << endl;
  else cout << cnt << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int a[100001];
  for(int i = 1;i <= n;i++) cin >> a[i];

  bool check[100001] = {};
  for(int i = 1;i <= n;i++){
    if(a[i] == i) check[i] = true;
  }

  int ans = 0;
  for(int i = 1;i <= n;i++){
    if(check[i]){
      if(i != n && check[i+1]){
        check[i+1] = false;
      }
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define int long long

main()
{
    ios_base::sync_with_stdio(false);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k & 1){
        cout << (b + c) - (a + c) << endl;
    }
    else cout << a - b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char *argv[])
{
        int b, f, r, v;
        int n, i;
        int values[4][3][10];
        char buf[256];

        for (b = 0; b < 4; b++)
                for (f = 0; f < 3; f++)
                        for (r = 0; r < 10; r++)
                                values[b][f][r] = 0;

        fgets(buf, 256, stdin);
        sscanf(buf, "%d", &n);

        for (i = 0; i < n; i++) {
                fgets(buf, 256, stdin);
                sscanf(buf, "%d %d %d %d", &b, &f, &r, &v);
                values[b - 1][f - 1][r - 1] += v;
        }

        for (b = 0; b < 4; b++) {
                for (f = 0; f < 3; f++) {
                        for (r = 0; r < 10; r++)
                                printf(" %d", values[b][f][r]);
                        printf("\n");
                }
                if (b != 3) printf("####################\n");
        }
        return 0;
}

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


int main()
{
    string S;
    int flag = 0;

    cin >> S;

    for( int i = 0; i < S.length(); i++ )
    {
        if( S[i] == S[i+1] )
        {
            flag = 1;
            break;
        }
    }

    if( flag == 0 )
    {
        cout << "Good" << endl;
    }
    else
    {
        cout << "Bad" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;

bool AC(char b1, char b2)
{
	return (b1 == 'A' && b2 == 'C');
}

int main() {
	int N, Q;
	string S;
	cin >> N >> Q;
	cin >> S;
	vi ACsum(N + 1, 0);
	rep(i, N - 1) {
		ACsum[i + 2] = ACsum[i + 1];
		if (S[i] == 'A' && S[i + 1] == 'C')
			ACsum[i + 2]++;
	}
	rep(q, Q) {
		int l, r;
		cin >> l >> r;
		int ans = ACsum[r] - ACsum[l];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
n = gets.to_i
a = gets.split.map(&:to_i)

count = Array.new(10**5 + 1, 0)
a.each do |aa|
    count[aa] += 1
end
sum = a.inject(:+)
q = gets.to_i
q.times do
    b, c = gets.split.map(&:to_i)
    count[c] += count[b]
    sum += count[b] * (c - b)
    count[b] = 0
    puts sum
end

Measured memory_bytes: 21960
import sys


def read_heights():
    current = 0
    heights = [current]
    for c in sys.stdin.read().strip():
        current += {
            '/': 1,
            '\\': -1,
            '_': 0
        }[c]
        heights.append(current)
    return heights


heights = read_heights()

height_index = {}
for i, h in enumerate(heights):
    height_index.setdefault(h, []).append(i)

flooded = [False] * len(heights)
floods = []

# search from highest points
for h in sorted(height_index.keys(), reverse=True):
    indexes = height_index[h]
    for i in range(len(indexes) - 1):
        start = indexes[i]
        stop = indexes[i + 1]
        if start + 1 == stop or flooded[start] or flooded[stop]:
            continue
        if any(heights[j] >= h for j in range(start + 1, stop)):
            continue
        # flood in (start..stop)
        floods.append((start, stop))
        for j in range(start, stop):
            flooded[j] = True

floods.sort()

areas = []
for start, stop in floods:
    area = 0
    top = heights[start]
    for i in range(start + 1, stop + 1):
        h = heights[i]
        area += top - h + (heights[i - 1] - h) * 0.5
    areas.append(int(area))

print(sum(areas))
print(' '.join([str(v) for v in [len(areas)] + areas]))



Measured memory_bytes: 9768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	int k;
	scanf("%d", &k);
	if (k % 4 == 0 || k % 7 == 0) {
		printf("Yes");
	}
	else if (k < 3) {
		printf("No");
	}
	else {
		int i;
		double j;
		j = k / 4;
		for (i = 0; i < j; i++) {
			if ((k - 4 * i) % 7 == 0) {
				printf("Yes");
				return 0;
			}
		}
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import math
def is_prime(n):
    if n==1:
        return False
    for k in range(2,int(math.sqrt(n))+1):
        if n%k==0:
            return False
    return True
n=int(input())
m=0
c=0
while True:
    if m==n:
        break
    a=int(input())
    
    if is_prime(a)==True:
        c=c+1
 
    m=m+1
print(c)



Measured memory_bytes: 5672
N, K = map(int,input().split())

if K%2 == 1:
    count = 0
    for i in range(1,N+1):
        if i%K == 0:
            count += 1
            
    print(count**3)
    
else:
    c1 = 0
    c2 = 0
    for i in range(1,N+1):
        if i%K == 0:
            c1 += 1
            
        elif i%K == K//2:
            c2 += 1
            
    print(c1**3 + c2**3)
    

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

int main()
{
   long long int n,a,b;
    cin>>n>>a>>b;
    if(n==1  && a==b)
        cout<<1<<endl;
    else if(n==1  && a!=b)
        cout<<0<<endl;
    else if(b<a)
        cout<<0<<endl;
    else
        cout<<(b-a)*(n-2)+1<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<bool> P(N, false);
  for(int i = 0; i < K; i++){
    int d;
    cin >> d;
    for(int j = 0; j < d; j++){
      int a;
      cin >> a;
      P.at(a - 1) = true;
    }
  }
  int c = 0;
  for(int i = 0; i < N; i++){
    if(!P.at(i)) c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(a+b,min(a+c,b+c));
}

Measured memory_bytes: 3576
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	int si = s.size();
	if (si % 2 == 0) {
		cout << s << endl;
	} else {
		for (int i = 2; i >= 0; i--) {
			cout << s[i] ;
		}
		cout << "\n";
	}

	return 0;
	
}





Measured memory_bytes: 256
/**
*    created: 07.07.2020 21:45:51
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

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

    int a, b; cin >> a >> b;
    bool A = a == 4 || a == 9 || a == 6 || a == 11;
    bool B = b == 4 || b == 9 || b == 6 || b == 11;
    if (a == 2 || b == 2) cout << "No" << endl;
    else if (A && B) cout << "Yes" << endl;
    else if (!A && !B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b, c, d = na()

def gcd(a, b):
    while b > 0:
        c = a % b
        a = b
        b = c
    return a

def cou(b, c, d):
    g = gcd(c, d)
    return b - b//c - b//d + b//(c//g*d)

print(cou(b, c, d) - cou(a-1, c, d))


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)

MOD=10**9+7
n,k=map(int,input().split())

if k>=n-1:
  k=n-1

inv_table = [0]+[1]
for i in range(2,k+1):
  inv_table.append(-1*(MOD//i)*inv_table[MOD%i] %MOD)

comb_sum=1
fact=1
comb1=1
comb2=1
for i in range(1,k+1):
  comb1=(comb1*(n-i+1)*inv_table[i])%MOD
  comb2=(comb2*(n-i)*inv_table[i])%MOD
  comb=(comb1*comb2)%MOD
  comb_sum+=comb

print(comb_sum%MOD)

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

#define MAXN 3005

long long dp[MAXN][MAXN];
long long as [MAXN];

long long calc(int inicio, int fin, int p){
    if(dp[inicio][fin]!=-1){
        return dp[inicio][fin];
    }
    if(p==0){
        return dp[inicio][fin]=max(as[inicio]+calc(inicio+1,fin,1),as[fin]+calc(inicio,fin-1,1));
    }
    return dp[inicio][fin]=min(calc(inicio+1,fin,0),calc(inicio,fin-1,0));
}

int main(){
    int n;
    long long suma =0,X,rta;
    scanf("%d", &n);
    for(int i =0; i<MAXN; i++){
        for(int j =0; j<MAXN; j++){
            dp[i][j] =-1;
        }
    }
    for(int i=0; i<n; i++){
        scanf("%lld", &as[i]);
        suma+=as[i];
        if(n%2==1){
            dp[i][i]  = as[i];
        }
        else{
            dp[i][i] = 0;
        }
    }
    X = calc(0,n-1,0);
    rta = 2*X-suma;
    printf("%lld\n",rta );
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i<(n);i++)
using Graph = vector<vector<int>>;

void dfs(int v, int pre, int c, const Graph& G, vector<int>& d) {
    d[v] = c;
    for (auto nxt : G[v]) {
        if (nxt == pre) continue;
        dfs(nxt, v, c + 1, G, d);
    }
}

int argmax(const vector<int>& v) {
    int ma = -1;
    int arg = -1;
    rep(i, v.size()) {
        if (ma < v[i]) {
            ma = v[i];
            arg = i;
        }
    }
    assert(arg >= 0 && arg < v.size());
    return arg;
}

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

    int N;
    cin >> N;
    Graph G(N);
    rep(i, N - 1) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    vector<int> d(N);
    dfs(0, -1, 0, G, d);
    int v = argmax(d);

    dfs(v, -1, 0, G, d);
    int u = argmax(d);

    vector<int> d1(N), d2(N);
    dfs(v, -1, 0, G, d1);
    dfs(u, -1, 0, G, d2);

    rep(i, N) {
        cout << 2 * (N - 1) - max(d1[i], d2[i]) << endl;
    }
}

Measured memory_bytes: 17284
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	int h, w; cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];

	vector<vint> dp(h+5, vint(w+5, INF));
	if(s[0][0] == '#') dp[0][0] = 1;
	else dp[0][0] = 0;
	rep(i, h){
		rep(j, w){
			if(i != 0) dp[i][j] = min(dp[i][j], dp[i-1][j] + (s[i-1][j] == '.' && s[i][j] == '#'));
			if(j != 0) dp[i][j] = min(dp[i][j], dp[i][j-1] + (s[i][j-1] == '.' && s[i][j] == '#'));
		}
	}
	ans = dp[h-1][w-1];
	cout << ans << endl;
	return 0;
}

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


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
    fast();
    int a,b,c;cin>>a>>b>>c;
    int cnt=0;
    if(a!=b&&b!=c&&a!=c)cout<<3;
    else if((a==b&&b!=c)||(a==c&&a!=b)||(b==c&&a!=b))cout<<2;
    else cout<<1;




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a[i];
    vector<int> pnt(n);
    rep(i,n) pnt[i] = k -q;

    rep(i,q){
        pnt[a[i]-1]++;
    }
    rep(i,n){
        if(pnt[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
n,y=map(int, input().split())

for i in range(n + 1):
    for j in range(n - i + 1):
        if i *10000 + j * 5000 + (n-i-j) * 1000 == y:
            print(i, j, n-i-j)
            exit()
print("-1 -1 -1")

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

const int maxn = 3e5, mod = 1e9 + 7;
const int ch[10][2] = {{5, 1}, {3, 2}, {2, 2}, {4, 1}, {3, 3}, {7, 6}, {5, 1}, {5, 5}};
int n, dp[maxn + 3][10];
char s[maxn + 3];

void upd(int &x, int y) {
	x += y, x < mod ? 0 : x -= mod;
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		if (s[i] != '1') {
			for (int j = 0; j < 8; j++) {
				upd(dp[i][ch[j][0]], dp[i - 1][j]);
			}
		}
		if (s[i] != '0') {
			for (int j = 0; j < 8; j++) {
				upd(dp[i][ch[j][1]], dp[i - 1][j]);
			}
		}
	}
	printf("%d\n", (dp[n][1] + dp[n][2]) % mod);
	return 0;
}

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

using namespace std;

int price[51][4];

int main(){
        int N;
        while(cin>>N,N){
                int ans=INT_MAX;
                for (int i = 0; i*500 <= N; i++) {
                        for (int j = 0; i*500+j*300 <= N; j++) {
                                if(!((N-i*500-j*300)%200)){
                                        int k=(N-i*500-j*300)/200;
                                        int ans2=0;
                                        ans2+=(k%5)*380;
                                        ans2+=(k/5)*1520;
                                        ans2+=(j%4)*550;
                                        ans2+=(j/4)*1870;
                                        ans2+=(i%3)*850;
                                        ans2+=(i/3)*2244;
                                        ans=min(ans,ans2);
                                }
                        }
                }
                cout<<ans<<endl;
        }
        return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

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

ll n;
vector<ll> a;

int main() {
    cin >> n;
    a.resize(n);
    for (auto &e:a) cin >> e;
    sort(a.begin(), a.end());
    multiset<ll> pos, neg;
    for (ll i = 1; i < n - 1; i++) {
        if (a[i] >= 0) pos.insert(a[i]);
        else neg.insert(a[i]);
    }
    pos.insert(a[n - 1]);
    neg.insert(a[0]);
    vector<pair<ll, ll>> h;
    while (!neg.empty()) {
        ll p = *(pos.begin()), q = *(neg.begin());
        pos.erase(pos.begin());
        neg.erase(neg.begin());
        if (pos.size() <= neg.size()) {
            pos.insert(p - q);
            h.emplace_back(p, q);
        } else {
            neg.insert(q - p);
            h.emplace_back(q, p);
        }
    }
    cout << *(pos.begin()) << endl;
    for (auto e:h) {
        cout << e.first << ' ' << e.second << endl;
    }
}


Measured memory_bytes: 8956