akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int N=55,M=(1<<18)+5;
int n,m,k,s,t;
int a[N];
bool book[N];
long long C[N][N];
long long sum[N][N];
void init(int n=50)
{
	for(int i=0;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	for(int i=0;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum[i][j]=sum[i][j-1]+C[i][j];
	return;
}
int main()
{
	scanf("%d%d%d%d",&n,&k,&s,&t);
	init();
	m=18;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=m-1;i>=0;i--)
	{
		if((s&(1<<i))==1&&(t&(1<<i))==0)
		{
			printf("0");
			return 0;
		}
		if((s&(1<<i))==(t&(1<<i)))
		{
			for(int j=1;j<=n;j++)
				if((s&(1<<i))!=(a[j]&(1<<i))) book[j]=true;
		}
	}
	vector<int>v;
	for(int i=1;i<=n;i++)
		if(!book[i]) v.push_back(a[i]);
	n=0;
	for(int u:v)
		a[++n]=u;
	long long ans=0;
	for(int state=0;state<(1<<m);state++)
	{
		bool flag=false;
		for(int i=0;i<m;i++)
			if((state&(1<<i))&&(s&(1<<i))==(t&(1<<i)))
			{
				flag=true;
				break;
			}
		if(flag) continue;
		map<int,int>cnt;
		for(int i=1;i<=n;i++)
			cnt[a[i]&state]++;
		long long res=0;
		for(auto [val,num]:cnt)
			res+=sum[num][k];
		if(__builtin_popcount(state)&1) ans-=res;
		else ans+=res;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3848
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
   ll i,j,cc=0;
   cin>>j;
   string str;
   cin>>str;
   for(i=1;i<j;i++){
    if(str[i] != str[i-1])cc++;
   }
   cout<<cc+1<<endl;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		sc.close();
		int ans = b / a;
		if(c < ans) ans= c;
		System.out.println(ans);
	}

}


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

// #define int long long

signed main()
{
    int i=0, j=0, k=0, ans=0;
    int a[3][3]={0}, N, b[10]={0};
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    cin>>N;
    for(i=0;i<N;i++){
        cin>>b[i];
    }

    int A[3][3]={0};
    for(k=0;k<N;k++){
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                if(b[k]==a[i][j])
                    A[i][j]=1;
            }
        }
    }

    int v[3]={0}, h[3]={0}, acnt=0;
    for(i=0;i<3;i++){
        if(A[i][i])
            acnt++;
        for(j=0;j<3;j++){
            if(A[i][j]){
                h[i]++;
                v[j]++;
            }
        }
    }
    if(A[0][2]+A[1][1]+A[2][0]==3)
        acnt=3;
    if(acnt==3){
        cout<<"Yes"<<endl;
        return 0;
    }

    for(i=0;i<3;i++){
        if((h[i]==3)||(v[i]==3)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(v) begin(v), end(v)
#define rreps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)
#define rrep(i, n) rreps(i, 0, n)
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto&& i : n)
#define fill(x, y) memset(x,y,sizeof(x))
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
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; }
template <typename T> inline void print(const T& x) {cout << x << '\n';}

signed main()
{ 
  int n, m;
  while(cin>>n>>m, n||m)
  {
    vi t(n);
    vi h(m);
    each(v,t) cin>>v;
    each(v,h) cin>>v;
    int a=INF, b=INF;
    rep(i,n)
    {
      rep(j,m)
      {
        swap(t[i],h[j]);
        if(accumulate(ALL(t),0)==accumulate(ALL(h),0)) 
        {
          if((a+b)>(t[i]+h[j])) 
          {
            b=t[i], a=h[j];
          }
        }
        swap(t[i],h[j]);
      }
    }
    if(a==INF&&b==INF) print(-1);
    else cout<<a<<" "<<b<<endl;
  }

  return 0;
}



Measured memory_bytes: 3152
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int ans=0;
    for(int i=0;i<a.length();i++){
      if(a.charAt(i)!=b.charAt(i)){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 41144
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
using namespace std;

int main() {
	FIO;
	int arr[] = { 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;
	cout << arr[k - 1] << '\n';
	return 0;
}

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;
using P = pair<int, int>;

int main()
{
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;

    cout << n/(a+b)*a + min(n%(a+b), a) << endl;


    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
// #include <cctype>


using namespace std;


int main()
{


    string deck;
    int n;


    //method 1
    while (cin >> deck >> n)
    {
 //it is valid to use cin >> deck >> n instead
        int s;
        while (n--)
        {

            cin >> s;

            //method 1
            // deck += deck.substr(0, s);
            // deck.erase(0, s);

            //method 2
            // string::iterator it = deck.begin() + s;
            // rotate(deck.begin(), it, deck.end());

            //method 3
            deck = deck.substr(s) + deck.substr(0, s);
        }

        cout << deck << endl;
    }

}


Measured memory_bytes: 3172
import scala.io.StdIn
import scala.annotation.tailrec

object Main extends App {
  val n = StdIn.readInt
  val Array(a, b) = StdIn.readLine.split(" ").map(_.toInt)
  val p = StdIn.readLine.split(" ").map(_.toInt)

  val arr = Array.ofDim[Int](3)
  p.foreach(i => {
    if(i <= a) arr(0) += 1
    else if(i <= b) arr(1) += 1
    else arr(2) += 1
  })

  val ans = arr.min
  println(ans)
}

Measured memory_bytes: 27336
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

H = ii()
W = ii()
N = ii()

H, W = max(H, W), min(H, W)
if N % H:
    print(N // H + 1)
else:
    print(N // H)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    if (a == 0) cout << 1 << endl;
    if (b == 0) cout << 2 << endl;
    if (c == 0) cout << 3 << endl;
    if (d == 0) cout << 4 << endl;
    if (e == 0) cout << 5 << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	// 連想配列のmapを利用
	map<string, long> m;
	for (int i = 0; i < N; i++)
	{
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		m[s]++;
	}
	
	long answer = 0;
	for (map<string, long>::iterator it = m.begin(); it != m.end(); it++)
	{
		long n = it->second;
		// 各組の出現回数をnとすると、その組み合わせはnC2 = n(n - 1)/2
		answer += n * (n - 1) / 2;
	}
	
	cout << answer << endl;
	
	return 0;
}

Measured memory_bytes: 11136
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int t[5];
char s[100005];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		t[s[i]-'a'+1]++;
	}
	sort(t+1,t+4);
	if(t[3]-t[1]<=1){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
using namespace std;
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back


int n,m;
int dsu[100005];

int f( int u ){
	if ( dsu[u] != u ) return dsu[u] = f(dsu[u]);
	return u;
}

int main(){

	scanf("%d%d",&n,&m);
	for ( int i = 1; i <= n; i++ ){
		dsu[i] = i;
	}

	int cc = n;
	for ( int i = 0; i < m; i++ ){
		int u , v;
		scanf("%d%d",&u,&v);
		if ( f(u) == f(v) ) continue;
		cc--;
		if ( f(u) > f(v) ) swap(u,v); 
		dsu[f(u)] = f(v);
	}

	printf("%d\n",cc-1);
	return 0;
}

Measured memory_bytes: 4216
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main(){
    long long a;
    float b;
    cin>>a>>b;
    float fractional_part = fmod(b, 1.0);
    int tmp=(int)(round(fractional_part*100));

    long long ans1=a*(int)(b/1);
    long long ans2=(tmp*a)/100;
    long long ans=ans1+ans2;

    cout<<ans<<endl;
}

Measured memory_bytes: 3744
S = input()

Odd = ["R", "U", "D"]
Even = ["L", "U", "D"]
S_l = len(S)
result = "Yes"

for i in range(0, S_l):
    if i % 2 == 0:
        if not S[i] in Odd:
            result = "No"
            break
    if i % 2 != 0:
        if not S[i] in Even:
            result = "No"
            break

print(result)

Measured memory_bytes: 8916
#include <stdio.h>
#include <string.h>
 int main(void){
    int N,i;
    scanf("%d",&N);
    
    char s[N],a[N/2],b[N/2];
    
    if(N%2==0){
    for(i=0;i<N;i++){
      scanf("%s",&s[i]);
     }
      for(i=0;i<N;i++){
      if(i<N/2){
        a[i]=s[i];
      }
      else
        b[i-N/2]=s[i];
      }
      if(strncmp(a,b,N/2)==0)
        printf("Yes");
      else
        puts("No");
    }
     else    
    printf("No");
} 

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}


void solve() {
    ll n, k;
    cin >>n >>k;
    n %= k;
    cout << min(n, k - n) <<endl;
}

int main() {
	header();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int flag=-1;
	for(int i = 1; i <= n; ++i){
		int x;
		cin >> x;
		if(flag==0)continue;
		if(x%2==1)continue;
		if(x%2==0&&(x%3==0||x%5==0)){
		}
		else flag=0;//不成功 
	}
	if(flag==0)cout << "DENIED";
	else cout << "APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h> 
#include<algorithm> 
#include<stdio.h> 
#include<sstream>
#include<fstream>  
using namespace std; 
typedef long long ll; 
typedef long double ld; 

int ceil(int a, int m){
    // division of a and m
    if(a % m == 0){
        return a/m; 
    }
    else{
        return a/m + 1; 
    }
}

vector<int> sort(vector<int> arr){
    sort(arr.begin(), arr.end()); 
    return arr; 
}

int minInVector(vector<int> arr){
    int mins = 1e9; 
    for(int i = 0; i<arr.size(); i++){
        mins = min(mins, arr[i]); 
    }
    return mins; 
}

int maxInVector(vector<int> arr){
    int maxs = -1; 
    for(int i = 0; i<arr.size(); i++){
        maxs = max(maxs, arr[i]); 
    }
    return maxs; 
}

bool checkElement(vector<int> arr, int k){
    for(int i = 0; i<arr.size(); i++){
        if(arr[i] == k){
            return true; 
        }
    }
    return false; 
}



const int MOD = 1e9 + 7; 

int main(){

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

char nl = '\n'; 
char bl = ' ';
/*
For array arr use the following preamble to sort
int diff = sizeof(arr)/sizeof(arr[0]); 
sort(arr, arr + diff); 

*/

ll x,k,d; 
cin >> x >> k >> d; 

ll diff = abs(x)/d; 

if(diff <= k){
        int rem = k - diff; 
        if(rem % 2 == 0){
            cout << abs(x) - diff*d; 
        }
        else{
            if(abs(abs(x) - diff*d + d) < abs(abs(x) - diff*d + d)){
                cout << abs(abs(x) - diff*d + d); 
            }
            else{
                cout << abs(abs(x) - diff*d  - d); 
            }
        }
}
else{
    cout << abs(abs(x) - k*d); 
}
}



Measured memory_bytes: 3672
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int main()
{
	ll k, s;
	cin >> k >> s;

	ll cnt = 0;
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			ll z = s - (i + j);
			if (0 <= z && z <= k)
			{
				cnt++;
			}
		}
	}

	cout << cnt << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++) cin >> a[i];

  ll ans = 0;
  for(ll i = 0; i < n; i++){
    ll cnt = 0;
    for(ll j = i + 1; j < n; j++){
      if(a[i] > a[j]) cnt++;
    }
    cnt *= k % mod;
    ans += cnt % mod;
    ans %= mod;
  }

  for(ll i = 0; i < n; i++){
    ll cnt = 0;
    for(ll j = 0; j < n; j++){
      if(a[i] > a[j]) cnt++;
    }
    cnt *= (k * (k-1))/2 % mod;
    ans += cnt % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

bool ok(string s){
  if (s >= "01" && s <= "12") return true;
  else return false;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s; cin >> s;
  string t1 = s.substr(0, 2), t2 = s.substr(2, 2);
  if (ok(t1) && ok(t2)){
    print("AMBIGUOUS");
  } else if (ok(t1) && !ok(t2)){
    print("MMYY");
  } else if (!ok(t1) && ok(t2)){
    print("YYMM");
  } else {
    print("NA");
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int v[n];
    int c[n];
    int ans = 0;
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
    for(int i = 0;i < n;i++){
        cin >> c[i];
    }
    for(int i = 0;i < n;i++){
        ans += max(0,v[i]-c[i]);
    }
    cout << ans << endl;
}

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

int main()
{
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if ((x - r >= 0 && x + r <= W) && (y - r >= 0 && y + r <= H))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}


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

int main() {
  string S;
  int count = 0;
  cin >> S;
  for(int i = 0; i < 3; i++) {
    if(S.at(i) == '1') {
      count++;
    }
  }
  cout<<count<<endl;
}


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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

struct SL {
	priority_queue<ll> L;
	priority_queue<ll, vector<ll>, greater<ll>> R;
	ll ans, rBase, lBase;
	SL() : ans(0ll), rBase(0ll), lBase(0ll) {}
	void addR(int v) {
		rBase += v;
	}
	void addL(int v) {
		lBase += v;
	}
	void addSL(int x) {
		L.push(x-lBase); R.push(x-rBase);
		while(R.top()+rBase < L.top()+lBase) {
			ll l = L.top()+lBase, r = R.top()+rBase;
			ans += l-r;
			L.pop(); R.pop();
			L.push(r-lBase); R.push(l-rBase);
		}
	}
};
int N, Nr[MAX_N][2];
int main() {
	cin >> N;
	REP(i, N) REP(j, 2) scanf("%d", &Nr[i][j]);
	SL sl;
	REP(i, N) {
		sl.addR(Nr[i][1] - Nr[i][0]);
		sl.addSL(Nr[i][1]);
		sl.addL(-(Nr[i][1] - Nr[i][0]));
	}
	printf("%lld\n", sl.ans);
	return 0;
}

Measured memory_bytes: 2932
C = [list(map(int, input().split())) for i in range(3)]
N = 100
ok = 0
for a1 in range(N+1):
    b1 = C[0][0] - a1
    b2 = C[0][1] - a1
    b3 = C[0][2] - a1
    for a2 in range(N+1):
        if not (b1 == C[1][0] - a2) or not (b2 == C[1][1] - a2) or not (b3 == C[1][2] - a2):
            continue
        for a3 in range(N+1):
            if not (b1 == C[2][0] - a3) or not (b2 == C[2][1] - a3) or not (b3 == C[2][2] - a3):
                continue
            ok = 1
            break
        else:
            continue
        break
    else:
        continue
    break
print("Yes"*ok or "No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    int A,B,C;
    cin>>A>>B>>C;
    cout<<max(0,C-(A-B))<<endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():
    n = I()
    a = IR(n)
    ans = 0
    b = [0]*(n+1)
    for i in range(n):
        ans += (a[i]+b[i])>>1
        if (a[i]%2)^(b[i]%2) and a[i]:
            b[i+1] += 1
    print(ans)
    return

#C
def C():
    n = I()
    a = IR(n)
    b = [(a[i],i) for i in range(n)]
    b.sort()
    for i in range(n):
        a[b[i][1]] = i+1
    ans = 0
    for i in range(n):
        if a[i]&1 == i&1:
            ans += 1
    print(ans>>1)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 53596
from collections import defaultdict
from heapq import heappush, heappop
from collections import deque
n, x, y = list(map(int, input().split()))
G = [[]*n for _ in range(n)]

for i in range(n-1):
    G[i].append((i+1, 1))
    G[i+1].append((i, 1))
G[x-1].append((y-1, 1))
G[y-1].append((x-1, 1))
# print(G)
INF = 10**30
N = n


# s: 開始頂点
# N: 頂点数
# G: グラフ
# G[v][i] = (w, d): 辺v-wのコストは d (0 or 1)
dd = []
for i in range(n):
    s = i
    dist = [10**9] * N
    S = deque([s])
    T = deque()
    dist[s] = 0

    d = 0
    while S:
        while S:
            v = S.popleft()
            for w, c in G[v]:
                if d+c < dist[w]:
                    dist[w] = d+c
                    if c:
                        T.append(w)
                    else:
                        S.append(w)
        S, T = T, S
        d += 1
    dd.append(dist)

ans = defaultdict(lambda: 0)
for dist in dd:
    for t in dist:
        ans[t] += 1
for i in range(n-1):
    print(ans[i+1]//2)


Measured memory_bytes: 82908
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include <functional>

#define big ((long long)(1e9)+7)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
	string s;
	cin >> s;
	if(s.at(2) == s.at(3) && s.at(4) == s.at(5))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


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

using namespace std;

void rec(set<int>& visits, vector<long long>& rets, vector<long long>& op,
         vector<vector<int> >& connection, int cursor, int parent) {
  rets[cursor] += op[cursor];
  if (parent != -1)
    rets[cursor] += rets[parent];
  visits.insert(cursor);
  for (int i = 0; i < connection[cursor].size(); ++i) {
    int next = connection[cursor][i];
    if (visits.find(next) == visits.end())
      rec(visits, rets, op, connection, next, cursor);
  }
}

int main(int argc, char* argv[]) {
  int N, Q;
  cin >> N >> Q;

  int a[N - 1];
  int b[N - 1];
  vector<vector<int> > connection(N);
  for (int i = 0; i < N - 1; ++i) {
    cin >> a[i] >> b[i];
    connection[a[i] - 1].push_back(b[i] - 1);
    connection[b[i] - 1].push_back(a[i] - 1);
  }

  int p[Q];
  int x[Q];
  vector<long long> op(N);
  for (int i = 0; i < Q; ++i) {
    cin >> p[i] >> x[i];
    op[p[i] - 1] += x[i];
  }

  vector<long long> rets(N);
  set<int> visits;
  rec(visits, rets, op, connection, 0, -1);

  for (int i = 0; i < N; ++i) {
    if (i != 0)
      cout << " ";
    cout << rets[i];
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 44544
import sys

n, m = list(map(int, input().split()))
aaa = set(map(int, sys.stdin))
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1 if 1 not in aaa else 0
MOD = 10 ** 9 + 7

for i in range(2, n + 1):
    if i in aaa:
        continue
    dp[i] = (dp[i - 2] + dp[i - 1]) % MOD
print(dp[n])


Measured memory_bytes: 11884
s=input()
cnt=0
ans=0
for i in s:
    if i=="A" or i=="C" or i=="G" or i=="T":
        cnt += 1
        ans = max(ans, cnt)
    else:
        #ans = max(ans, cnt)ここに書くとすべてAVGTの時にansが更新されない
        cnt=0
print(ans)

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

int main()
{
    string codefes="CODEFESTIVAL2016";
    string str;
    int i=0;
    int cnt=0;
    cin>>str;
    for(i=0;i<16;i++){
        if(str[i]!=codefes[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;

}



Measured memory_bytes: 384
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

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

const int N = 1e6;
const ll inf = 998244353;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

int n;
int a[N];
vector <int> g[N];
ll ans[N], cnt[N], dp[N];
ll sz;

ll dfs(int v, int p = -1){
    dp[v] = 1;
    ll cur = cnt[a[v]];
    for(int i = 0;i < g[v].size();i ++){
        int to = g[v][i];
        if(to == p){
            continue;
        }
        ll pre = sz - cnt[a[v]];
        dp[v] += dfs(to, v);
        ll nxt = sz - cnt[a[v]];
        ans[a[v]] -= (nxt - pre) * (nxt - pre - 1) / 2;
    }
    cnt[a[v]] = cur + dp[v];
    sz ++;
    return dp[v];
}

int main(){
    Speedforce
    //fop("F.in", "F.out")
    //mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
    }
    for(int i = 1;i < n;i ++){
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i = 1;i <= n;i ++){
        ans[i] = (ll)n * (n - 1) / 2;
    }
    dfs(1);
    for(int i = 1;i <= n;i ++){
        ll nxt = n - cnt[i];
        ans[i] -= (nxt - 1) * nxt / 2;
    }
    for(int i = 1;i <= n;i ++){
        ans[a[i]]++;
    }
    for(int i = 1;i <= n;i ++){
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 57468
#include<stdio.h>
#include<stdlib.h>
//ST[1]は親はST[0]|は子の数
int *ST[100000];
int ST2[100000][2];
int main(){
  int n,i,j,NN,MN,free;
  scanf("%d",&n);
  for(i=0;i<n;i++)ST2[i][1]=-1;
  for(i=0;i<n;i++){
    scanf("%d%d",&NN,&MN);
    ST[NN]=malloc(MN*sizeof(int));
    ST2[NN][0]=MN;
    for(j=0;j<MN;j++){
      scanf("%d",&free);
      ST[NN][j]=free;
      ST2[free][1]=NN;
    }
  }
  for(i=0;i<n;i++){
    j=i;
    free=0;
    printf("node %d: parent = %d,",i,ST2[i][1]);
    while(ST2[j][1]!=-1){
      j=ST2[j][1];
      free++;
    }
    printf(" depth = %d, ",free);
    if(ST2[i][1]==-1)printf("root,");
    else{
      if(ST2[i][0]==0)printf("leaf,");
      else printf("internal node,");
    }printf(" [");
    for(free=0;free<ST2[i][0];free++){
      if(ST2[i][0]==1){printf("%d",ST[i][0]);break;}
      if(free==0) printf("%d,",ST[i][free]);
      else if(free!=ST2[i][0]-1)printf(" %d,",ST[i][free]);
      else printf(" %d",ST[i][free]);
    }
    printf("]");
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 6940
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

long long powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

long long fac[510000],finv[510000],inv[510000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<510000;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}
long long COM(int n,int k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
long long facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}

int main(void){
    COMinit();
    lint N,K;
    cin >> N >> K;
    if(K==1){
        cout << COM(N,2) << endl;
    }
    else if(N-1<=K){
        cout << COM(N+N-1,N) << endl;
    }
    else{
        lint ans=0;
        for(int i=0;i<=K;i++){
            lint place=N-i;
            ans=(ans+COM(N-1,place-1)*COM(N,place))%MOD;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 12160
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
A = LI()

s = sum(A)

divisor = []  # s の約数

for i in range(1,int(s**.5)+1):
    if s % i == 0:
        divisor.append(i)
        if i != s//i:
            divisor.append((s//i))

divisor.sort(reverse=True)

from itertools import accumulate

for d in divisor:
    B = []
    for a in A:
        if a % d == 0:
            continue
        else:
            B.append(a % d)
    B.sort()
    C = [0] + list(accumulate(B))
    D = [0] + list(accumulate([d-b for b in B]))
    r = 10**10  # 操作の回数
    for i in range(len(C)):
        r = min(r,max(C[i],D[-1]-D[i]))
    if r <= K:
        print(d)
        break


Measured memory_bytes: 74596
N = int(input())
restaurants = {}
for i in range(N):
    S, P = input().split()
    if S not in restaurants:
        restaurants[S] = [[int(P), i + 1]]
        continue
    restaurants[S] = restaurants[S] + [[int(P), i + 1]]

restaurants_sorted = sorted(restaurants.items(), key=lambda x:x[0])
for city in restaurants_sorted:
    city = list(city[1])
    city.sort(reverse=True)
    for restaurant in city:
        print(restaurant[1])

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	stack<int> s;
	for(int n;cin>>n;){
		if(n==0){
			cout<<s.top()<<endl;
			s.pop();
		}
		else
			s.push(n);
	}
	
	return 0;
}

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

#define sz(s) (int)s.size()
#define int long long
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define rinat puts("rinat");

using namespace std;

const int N = 1e5 + 5;
const int inf = 1e9 + 7;

int n, mx = -inf, cnt;

inline int check( int x )
{
    int res = 0;
    while( x > 0 )
    {
        res += x % 10;
        x /= 10;
    }
    return res;
}

main()
{
    cin >> n;

    int l = 1, m = n;

    while( l < n )
    {
        l *= 10;
        cnt++;
    }

    l /= 10;
    cnt--;

    n /= l;
    n *= l;

    cout << max ( check(n - 1), check(m) );
}









Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int A[MAX], B[MAX], C[MAX];

int main(){
  int n,  i, j, k = 0;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i + 1]);
    if(A[i + 1] > k)k = A[i + 1];
  }
  for(i = 0; i <= k; i++)C[i] = 0;
  for(j = 1; j <= n; j++)C[A[j]]++;
  for(i = 1; i <= k; i++)C[i] = C[i] + C[i-1];
  for(j = n; j >= 1; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i = 1; i <= n; i++){
    if(i > 1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 17428
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
#define int long long
int n;
signed main(){
    cin>>n;
    if(n%2==0){
        int ans=0;
        int i=5;
        while(n/2/i>0){
            ans+=n/2/i;
            i*=5;
        }
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
def solve(A):
    if(len(A) == 1):
        return A[0]
    return solve([abs(A[i]-A[i+1]) for i in range(0,len(A),2)])

n = int(input())
A = []
for i in range(2**n):
    A.append(int(input()))

print(solve(A))


Measured memory_bytes: 23840
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string n;
   cin>>n;
   bool pd=false;
   for(int i=0;i<n.size();i++)
   if(n[i]=='7')
   pd=true;
   if(pd)
   cout<<"Yes";
   else
   cout<<"No";
   return 0;	
} 

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=100000+10;
vector<int> va,vb;
int flag=1;
int main(){
   int a[26],b[26];
   memset(a,0,sizeof(a));
   memset(b,0,sizeof(b));
   string s1,s2;
   cin>>s1>>s2;
   for(int i=0;i<s1.size();i++){
        a[s1[i]-'a']++;
        b[s2[i]-'a']++;
   }
   for(int i=0;i<26;i++){
       va.push_back(a[i]);
       vb.push_back(b[i]);
   }
   sort(a,a+26);
   sort(b,b+26);
   for(int i=0;i<26;i++){
        if(a[i]!=b[i]){
                cout<<"No";
                flag=0;
                break;
        }
   }
   if(flag)
    cout<<"Yes";
   return 0;
}


Measured memory_bytes: 776
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;

ll gBinom[51][51];

void CalcBinom()
{
	gBinom[1][1] = 1;
	for (int i = 2; i <= 50; i++)
	{
		gBinom[i][1] = i;
		for (int j = 2; j <= i; j++)
		{
			gBinom[i][j] = gBinom[i - 1][j] + gBinom[i - 1][j - 1];
		}
	}
}

int main()
{
	CalcBinom();
	ll nums[52];

	int N, A, B;
	scanf("%d%d%d", &N, &A, &B);
	for (int i = 0; i < N; ++i)
	{
		scanf("%lld", &nums[i]);
	}
	sort(nums, nums + N, greater<ll>());

	double avg = 0.0;
	for (int i = 0; i < A; ++i)
		avg += nums[i];
	avg /= A;

	const ll val = nums[A - 1];
	int ccc[2] = { 0, 0 };
	for (int i = 0; i < N; ++i)
	{
		if (nums[i] == val)
			++ccc[i >= A];
	}
	int u = ccc[0] + ccc[1];
	ll cnt = 0;
	if (val == nums[0])
	{
		for (int i = A; i <= B; ++i)
			cnt += gBinom[u][i];
	}
	else
		cnt = gBinom[u][ ccc[0] ];
	printf("%.20lf\n", avg);
	printf("%lld\n", cnt);
	return 0;
}


Measured memory_bytes: 128
import math
import copy

n = int(input())
# k, x = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
# table = [list(input()) for n in range(h)]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
# s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

kotae = 0

for i in range(n) :
    kotae += b[a[i]-1]
    if(i < n-1) :
        if(a[i] + 1 == a[i+1]):
            kotae += c[a[i]-1]

print(kotae)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}


vector<vector<pii > > tree;
vector<bool> seen;
vi ans;

void dfs(int p,int color){
	seen[p]=true;
	ans[p]=color;
	for(auto elem:tree[p]){
		int next,w;
		tie(next,w)=elem;
		if(!seen[next]){
			if(w&1) dfs(next,1-color);
			else dfs(next,color);
		}
	}
}

//他の人の解答を参考.
int main(){
	int n;
	cin>>n;
	
	tree.resize(n);
	seen.assign(n,false);
	ans.resize(n);
	REP(i,n-1){
		int u,v,w;
		cin>>u>>v>>w;
		tree[u-1].push_back(pii(v-1,w));
		tree[v-1].push_back(pii(u-1,w));
	}
	
	dfs(0,0);
	
	line(ans);
}

Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int f[n];
    int b[n];
    for (int i = 0; i < n; i++){
        if (i % 2 == 0){
            f[i/2] = a[i];
        }else{
            b[i/2] = a[i];
        }
    }
    if (n % 2 == 0){
        for (int i = n / 2 - 1; i >= 0; i--){
            cout << b[i] << " ";
        }
        for (int i = 0; i < n / 2; i++){
            cout << f[i] << " ";
        }
    }else{
        for (int i = n / 2; i >= 0; i--){
            cout << f[i] << " ";
        }
        for (int i = 0; i < n / 2; i++){
            cout << b[i] << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 3712
import java.util.*;
 
public class Main{
    public static void main(String[] args){
 
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        double c = (double)a/b;
 
        System.out.println(c);
 
 
 
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------
const int N = 1E5 + 100;
const LL MOD = 1E9 + 7;

LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }

LL w[N], fac[N] = {1}, ls[N], rs[N], S[N];
int main() {
#ifdef zerol
    freopen("in", "r", stdin);
#endif
    FOR (i, 1, N) fac[i] = fac[i - 1] * i % MOD;
    int n; cin >> n;
    FOR (i, 1, n + 1) cin >> w[i];
    FOR (i, 1, n + 1) ls[i] = (ls[i - 1] + i * w[i]) % MOD;
    FORD (i, n, 0) rs[i] = (rs[i + 1] + (n - i + 1) * w[i]) % MOD;
    FOR (i, 1, n + 1) S[i] = (S[i - 1] + w[i]) % MOD;
    LL ans = 0;
    FOR (d, 1, n) {
        LL m = min(d, n + 1 - d);
        LL x = ls[m] + rs[n - m + 1] + m * (S[n - m] - S[m]) % MOD;
        LL y = S[d] + (S[n] - S[n - d]);
        x -= y;
        ans += 2 * fac[n] * get_inv(d + 1, MOD) % MOD * get_inv(d + 2, MOD) % MOD * x % MOD;
        ans += fac[n] * get_inv(d + 1, MOD) % MOD * y % MOD;
//        LL x = L[n - d + 1] - L[d - 1] + ls[d - 1] + rs[n - d + 2];
//        ans += fac[d] * fac[n - d] % MOD * x % MOD;
//        dbg(d, fac[d] * fac[n - d], x, S[n - m] - S[m]);
//        ans %= MOD;
        ans %= MOD;
    }
    ans += fac[n] * S[n];
    cout << (ans % MOD + MOD) % MOD << endl;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
signed main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==0 && b==0 && c==0){
    cout<<"Close\n";
  }
  if(a==0 && b==0 && c==1){
    cout<<"Open\n";
  }
  if(a==1 && b==1 && c==0){
    cout<<"Open\n";
  }
  if(a==0 && b==1 && c==0){
    cout<<"Close\n";
  }
  if(a==1 && b==0 && c==0){
    cout<<"Close\n";
  }
  return(0);
}



Measured memory_bytes: 3084
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int N;cin>>N;
	vector<int>hs(N);
	for(int i=0;i<N;++i)cin>>hs[i];
	vector<int>ds(N-1);
	for(int i=0;i<N-1;++i)ds[i]=hs[i+1]-hs[i];

	vector<int>nextds;
	bool flag=true;
	for (int i = 0; i < N - 1; ++i) {
		if(ds[i])nextds.push_back(ds[i]>0?1:-1);
		else {
			if (!flag) {

			}
			else {
				nextds.push_back(ds[i]);
			}
		}
		flag=ds[i];
	}
	vector<int>anss(5);
	for (int i = 0; i < int(nextds.size()) - 1; ++i) {
		if(nextds[i]==0)continue;
		else {
			if (nextds[i] < 0) {
				if (nextds[i + 1] == 0) {
					if(i+2==nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[2]++;
						}
						else {
							assert(nextds[i+2]>0);
							anss[1]++;
						}
					}

				}
				else {
					if(nextds[i+1]>0)anss[4]++;
				}
			}
			else {
				if (nextds[i + 1] == 0) {
					if (i + 2 == nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[0]++;
						}
						else {
							assert(nextds[i + 2]>0);
							anss[2]++;
						}
					}
				}
				else {
					if (nextds[i + 1]<0)anss[3]++;
				}
			}
		}
	}
	for (int i = 0; i < 5; ++i) {
		cout<<anss[i];
		if(i==4)cout<<endl;
		else cout<<" ";
	}
	return 0;
}


Measured memory_bytes: 4324
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Closeable;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADoubleHelix solver = new ADoubleHelix();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADoubleHelix {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String c = in.next();
            switch (c) {
                case "T":
                    out.println('A');
                    break;
                case "A":
                    out.println('T');
                    break;
                case "G":
                    out.println('C');
                    break;
                case "C":
                    out.println('G');
                    break;
            }
        }

    }

    static class FastScanner implements Closeable {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public void close() {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}



Measured memory_bytes: 21076