akhauriyash/Code-Regression huggingface dataset:
void main() {
  auto n = ri;
  writeln(n/3);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
  return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
  return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    res[i] = readAs!(T[]);
  }
  return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
  auto res = new T[][](height, width);
  foreach(i; 0..height) {
    auto s = rs;
    foreach(j; 0..width) res[i][j] = s[j].to!T;
  }
  return res;
}

int ri() {
  return readAs!int;
}

long rl() {
  return readAs!long;
}

double rd() {
  return readAs!double;
}

string rs() {
  return readln.chomp;
}

Measured memory_bytes: 2732
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String ar = sc.nextLine();

        int cnt = 0;

        for(int i = 0 ; i < ar.length() ; i++) {

            for(int j = i ; j <= ar.length() ; j++) {
                String str =ar.substring(i, j);
                if(str.matches("([ATCG])+")) {
                    if(cnt<str.length()) {
                        cnt = str.length();
                    }
                }
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 25172
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int N;
ll D[100010];
vector<pair<int,int>> ans;
vector<vector<int>> v(100010);
ll dist[100010] = {0},inf = 1e18;

void dfs(int n){
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(dist[s]==inf){
			dist[s] = dist[n]+1;
			dfs(s);
		}
	}
}

int main(){
	cin >> N;
	map<ll,int> m,num;
	priority_queue<ll> Q;
	for(int i=1;i<=N;i++){
		cin >> D[i];
		m[D[i]] = i;
		num[D[i]] = 1;
		Q.push(D[i]);
		dist[i] = inf;
	}
	int count = 0;
	while(count<N-1 && !Q.empty()){
		ll s = Q.top();
		Q.pop();
		ll t = s-(N-2*num[s]);
//		cout << s << " " << t << endl;
		if(t<=0) continue;
		if(m.count(t)){
			ans.push_back({m[s],m[t]});
			v[m[s]].push_back(m[t]);
			v[m[t]].push_back(m[s]);
			count++;
			num[t] += num[s];
		}
	}
	dist[1] = 0;
	dfs(1);
	ll sum = 0;
//	cout << ans.size() << endl;
	for(int i=2;i<=N;i++) sum += dist[i];
	if(count!=N-1 || sum!=D[1]) cout << -1 << endl;
	else{
		for(int i=0;i<N-1;i++){
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
}

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

int main(){
    int n,a,i=0,max=-1000000,min=1000000;
    long int sum=0;
    cin >> n;
    while(n!=i){
        cin >> a;
        if(a<min) min=a;
        if(max<a) max=a;       
        sum+=a; 
        i++;
    }
    cout << min << ' ' << max  <<  ' ' << sum << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

char maze[1005][1005];
int visited[1005][1005];

bool is_in_field(int h, int w, pll now){
    if(now.first < 0 || now.first >= h){return false;}
    if(now.second < 0 || now.second >= w){return false;}
    return true;
}

int bfs(int h, int w, int ch, int cw, int dh, int dw){
    queue<pll> q;
    queue<pll> q2;
    pll start = {ch, cw};
    pll goal = {dh, dw};
    pll d[4] = {{1,0},{-1,0},{0,1},{0,-1}};

    visited[start.first][start.second] = 0;

    q2.push(start);
    while(!q2.empty()){
        vector<pll> check;
        while(!q2.empty()){
            pll t = q2.front();
            q.push(t);
            check.push_back(t);
            q2.pop();
        }
        while(!q.empty()){
            pll now = q.front();
            q.pop();
            if(now == goal){
                return visited[dh][dw];
            }

            for(int i = 0; i < 4; i++){
                pll next = {now.first + d[i].first, now.second + d[i].second};
                if(is_in_field(h, w, next)){
                    char state = maze[next.first][next.second];
                    if(state == '.'){
                        if(visited[next.first][next.second] == -1){
                            q.push(next);
                            check.push_back(next);
                            visited[next.first][next.second] = visited[now.first][now.second];
                        }
                    }
                }
            }
        }
        for(int i = 0; i < check.size(); i++){
            pll now2 = check[i];
            for(int j = -2; j <= 2; j++){
                for(int k = -2; k <= 2; k++){
                    pll next2 = {now2.first + j, now2.second + k};
                    if(is_in_field(h, w, next2)){
                        char state2 = maze[next2.first][next2.second];
                        if(state2 == '.'){
                            if(visited[next2.first][next2.second] == -1){
                                q2.push(next2);
                                visited[next2.first][next2.second] = visited[now2.first][now2.second] + 1;
                            }
                        }
                    }
                }
            }
        }
    }

    return -1;
}

int main() {
    int h, w, cnt = 0;
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw;
    cin >> dh >> dw;
    ch--; cw--; dh--; dw--;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> maze[i][j];
            visited[i][j] = -1;
        }
    }
    int distance = 0;
    distance = bfs(h, w, ch, cw, dh, dw);
    cout << distance << endl;
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    getline(cin, s);

    rep(i, s.length())
    {
        if (s[i] >= 'a' && s[i] <= 'z')
        {
            cout << char(s[i] + 'A' - 'a');
        }
        else if (s[i] >= 'A' && s[i] <= 'Z')
        {
            cout << char(s[i] - 'A' + 'a');
        }
        else
        {
            cout << s[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3108
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline


    n = int(input().rstrip())
    a1_list = [int(x) for x in input().rstrip().split(" ")]
    a2_list = [int(x) for x in input().rstrip().split(" ")]


    upper_sum = a1_list[0]
    lower_sum = sum(a2_list)
    ans = upper_sum + lower_sum
    for i in range(1, n):
        upper_sum += a1_list[i]
        lower_sum -= a2_list[i-1]
        candy = upper_sum + lower_sum
        if candy > ans:
            ans = candy
    print(ans)




if __name__ == "__main__":
    resolve()


Measured memory_bytes: 62032
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T=1, n;
    while (T--){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll ans = -1e18;
        ans = max({ans, d*b, d*a, c*a,c*b});
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
const long long mod = pow(10,9)+7;

int main(){
    int n; //ボール全ての数
    int k; //青いボールの数

    //input
    cin >> n >> k;

    //パスカルの三角形を作る
    vector<vector<long>> dp(n+1,vector<long>(n+1)); //パスカルの三角形を表す配列
    dp[0][0] = 1; //三角形の一番上の部分

    for(int i=1; i<=n; i++){
        dp[i][0] = dp[i-1][0];
        for(int j=1; j<=i; j++){
            dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%mod;
        }
    }

    for(int i=1; i<=k; i++){
        cout << (dp[n-k+1][i]*dp[k-1][i-1])%mod << endl;
    }
}

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

long long  n, s, x[101000], p[101000], ans;

void out(long long x){
  cout<<x; exit(0);
}

int main(){
  cin>>n>>s;
  for (int i=1;i<=n;++i) cin>>x[i]>>p[i];
  int l=1, r=n;
  for (;l<=r;){
    if (s<=x[l]) out(ans+x[r]-s);
    if (s>=x[r]) out(ans+s-x[l]);
    ans+=x[r]-x[l];
    if (p[l]>=p[r]){
      for (;l<r&&p[l]>=p[r];) p[l]+=p[r--];
    }else{
      for (;l<r&&p[l]< p[r];) p[r]+=p[l++];
    }
  }
  out(ans);
}


Measured memory_bytes: 1792
//解説視聴後
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;
 
int main(){
  int n, count=0;
  vector<int> a;
  cin >> n;
  rep(i,n){
    int b;
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(), a.end());
  
  bool dp[a[n-1]];
  rep(i,a[n-1]) dp[i]=true;
  rep(i,n){
    if(dp[a[i]-1]==true){
      for(int j=2*a[i]-1;j<a[n-1];j+=a[i]) dp[j]=false;
    }
    if(a[i]==a[i+1] && i<n-1) dp[a[i]-1]=false;
  }
  rep(i,n){
    if(dp[a[i]-1]==true) count++;
  }
  
 
  cout << count << endl;
 
  
}

Measured memory_bytes: 5100
// AOJ 1060: No Story
// 2017.10.7 bal4u@uu
// 2017.12.15

#include <stdio.h>
#include <math.h>

#define MAX 48624			// ptbl[0] = 3, ptbl[5000] = 48623
int power[100], sz;
char tbl[MAX+2];

int psz;
int ptbl[50012] = {			// ptbl[166] = 997
         3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997 };

void sieve()
{
	int i, j, k;

	for (i = 0; i < 167; i++) {
		k = ptbl[i];
		for (j = k*k; j < MAX; j += k) tbl[j] = 1;
	}
	for (psz = 166, i = 997; i <= MAX; i += 2) if (!tbl[i]) ptbl[psz++] = i;
}

void prime_factor(long long n)
{
    int i, a, k;
    int *pp;

    sz = 0;
    if (!(n & 1)) {
        power[sz] = 0;
        do n >>= 1, power[sz]++;
        while (!(n & 1));
        sz++;
    }
	if (n <= 1) return;
	if (n <= MAX && !tbl[n]) { power[sz++] = 1; return; }
    k = (int)sqrt((double)n);
	for (pp = ptbl; n > 1 && *pp; pp++) {
        if (*pp > k || n <= MAX && !tbl[n]) { power[sz++] = 1; return; }
		if (n % *pp) continue;
		a = *pp, power[sz] = 0;
		do n /= a, power[sz]++;
	    while (n % a == 0);
		sz++;
	}
	if (n <= 1) return;
	for (i = 48623; n > 1; i+=2) {
        if (i > k) { power[sz++] = 1; break; }
        if (n % i == 0) {
            power[sz] = 0;
            do n /= i, power[sz]++;
            while (n % i == 0);
            sz++;
        }
    }
}

int main()
{
	long long n, ans;
	int i;

	sieve();
	while (scanf("%lld", &n) && n > 0) {
		if (n == 1) { puts("1"); continue; }
		if (n <= MAX && (n & 1) && !tbl[n]) { puts("2"); continue; }
        prime_factor(n);
		for (ans = 1, i = 0; i < sz; i++) ans = ans * (1 + (power[i] << 1));
        printf("%lld\n", (ans+1)>>1);
	}
	return 0;
}

Measured memory_bytes: 1908
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	string str; cin >> str;
	int m = 0;
	int tmp = 0;
	rep(i, str.length()) {
		if (str[i] == 'A' || str[i] == 'T' || str[i] == 'C' || str[i] == 'G')
			tmp++;
		else
			tmp = 0;
		m = std::max(tmp, m);
	}
	cout << m << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

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

  int N;
  cin >> N;
  int ans = 0;
  rrep(i,360) {
    if ((N*i)%360==0) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3632
import itertools
import math
ans = 0
l = []

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

for i in itertools.permutations(xy, n):
    l.append(i)
    for j in range(n - 1):
        ans += math.sqrt((i[j + 1][0] - i[j][0]) ** 2 +\
        (i[j + 1][1] - i[j][1]) ** 2)

ans /= len(l)
print(ans)


Measured memory_bytes: 45020
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
const int N=2e5+5;
const int mod=1e9+7;

int main(){
    int x;
    cin>>x;
    printf("%.3f",x*4*asin(1));

return 0;
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

ll dg[60];
const ll MOD = ll(1e9)+7;

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

    ll N;
    cin >> N;

    FILL0(dg);

    rep(i, N)
    {
        ll a;
        cin >> a;

        rep(i, 60)
        {
            if(a&(1LL<<i))
            {
                dg[i]++;
            }
        }
    }
    
    ll ans=0;
    rep(i, 60)
    {
        ans += ((dg[i]*(N-dg[i]))%MOD)*((1LL<<i)%MOD)%MOD;
        ans %= MOD;
    }    

    cout << ans << endl;

 

 

    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<string>
#include<string.h>
#include<map>
#include<math.h>

#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;s[i];++i){
        if(s[i]=='R'){
            int tmp=0;
            while(s[i]=='R'){
                i++;
                tmp++;
            }
            ans=max(ans,tmp);
        }
    }
    cout<<ans<<endl;
}


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

const long long int MOD = 1000000007;
const int MAX_K = 404040;

int N, K;

long long int fac[MAX_K], finv[MAX_K], inv[MAX_K];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_K; 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 int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  cin >> N >> K;
  COMinit();
  long long int res;
  if(K >= N - 1){
    res = COM(N * 2 - 1, N);
  }else{
    res = 0;
    for(int i = 0; i <= K; i++){
      long long int sum = COM(N, i);
      sum *= COM(N - 1, N - i - 1);
      res += sum % MOD;
      res %= MOD;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main() {
  int n; 
  cin >> n;
  int count = 0, a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i+1]) {
      count++;
      a[i+1] = 10;
    }
  }
  cout << count << endl;
  return 0;
}
 

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

#ifdef USE_PYTHON_LIKE_PRINT
#include "print.h"
#else
template<char SEP = ' ', char END = '\n'> inline void print(...){}
template<char SEP = ' ', char END = '\n'> inline void printe(...){}
template<char SEP = ' ', char END = '\n'> inline void printo(...){}
#define define_print(...)
#define define_print_with_names(...)
#define define_to_tuple(...)
#endif

using namespace std;

const int MAX = 200000;
const int NEVER_T = (MAX + 1) * 10;

typedef vector<tuple<int, char>> group;

int search(const group& group, const char U1, const char U2, int minT, int t){
	int last = -1;
	for(auto& plane : group){
		const auto U = get<1>(plane);
		if(U == U1){
			last = get<0>(plane);
		}else if(U == U2){
			if(last >= 0){
				const int T = (get<0>(plane) - last) * t;
				if(minT > T){
					minT = T;
				}
			}
		}
	}
	return minT;
}

int main(void){
	int N;
	cin >> N;
//	vector<tuple<int, int, char>> planes;
	vector<group> planesH(MAX + 1);
	vector<group> planesV(MAX + 1);
	vector<group> planes45(MAX * 2 + 1);
	vector<group> planes135(MAX * 2 + 1);
	for(int i = 0; i < N; i ++){
		int X, Y;
		char U;
		cin >> X;
		cin >> Y;
		cin >> U;
		planes45[MAX + X - Y].push_back(make_tuple(X, U));
		planes135[X + Y].push_back(make_tuple(X, U));
		if(U == 'U' || U == 'D'){
			planesV[X].push_back(make_tuple(Y, U));
		}else{
			planesH[Y].push_back(make_tuple(X, U));
		}
	}
	
	int minT = NEVER_T;
	for(auto& group : planes45){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'U', 'L', minT, 10);
			minT = search(group, 'R', 'D', minT, 10);
		}
	}
	for(auto& group : planes135){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'D', 'L', minT, 10);
			minT = search(group, 'R', 'U', minT, 10);
		}
	}
	for(auto& group : planesH){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'R', 'L', minT, 5);
		}
	}
	for(auto& group : planesV){
		if(group.size() > 0){
			sort(group.begin(), group.end(), [](const auto& a, const auto& b){ return get<0>(b) > get<0>(a); });
			minT = search(group, 'U', 'D', minT, 5);
		}
	}
	
	if(minT < NEVER_T){
		cout << minT << endl;
	}else{
		cout << "SAFE" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 49612
#include <stdio.h>

int main(){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		int i=10,ans=1;
		while((a+b)/i!=0){
			i*=10;
			ans+=1;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int S=scan.nextInt();
		int m,s,h;
		s=S%60;
		m=(S/60)%60;
		h=(S/3600)%24;
		System.out.println(h+":"+m+":"+s);
		scan.close();
	}
	
}


Measured memory_bytes: 26244
//#include <stdio.h>
//#include <algorithm>
//
//using namespace std;
//
//typedef long long ll;
//
//int main() {
//    ll n, m;
//    while (scanf("%lld%lld", &n, &m) != EOF) {
//        if (m % n == 0) { printf("%lld\n", m / n); continue; }
//        else {
//            ll l = 1, r = 1; r << 34;
//            while (l < r) {
//                ll mid = (l + r) / 2;
//                ll k = m - n * mid;
//                if (k < 0) r = mid;
//                else if (k == 0) l = mid;
//                else if (__gcd(k, mid) == mid) l = mid;
//                else r = mid;
//            }
//            printf("%lld\n", l);
//        }
//    }
//    return 0;
//}
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

#define N 110

typedef long long ll;

int x[N], y[N];
ll h[N];

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        int a, b, d;
        ll c;
        for (int i = 0; i < n; ++i) {
            scanf("%d%d%lld", &x[i], &y[i], &h[i]);
            if (h[i] != 0) d = i;
        }
        for (a = 0; a <= 100; ++a) {
            int flag;
            for (b = 0; b <= 100; ++b) {
                flag = 1;
                c = h[d] + abs(a - x[d]) + abs(b - y[d]);
                for (int i = 0; i < n; ++i) {
                    if (h[i] != max(c - abs(a - x[i]) - abs(b - y[i]), (ll)0)) { flag = 0; break; }
                }
                if (flag) break;
            }
            if (flag) break;
        }
        printf("%d %d %lld\n", a, b, c);
    }
    return 0;
}


Measured memory_bytes: 128
n=int(input())
s=list(input())
a={}
mod=10**9+7
for i in range(n):
    if s[i] not in a:
        a[s[i]]=1
    else:
        a[s[i]]+=1
ans=1
for i in a:
    ans=ans*(a[i]+1)%mod
print(ans-1)
        


Measured memory_bytes: 3956
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
const int maxn = 2000;
char s[maxn];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    scanf("%s",s+1);
    s[k] = tolower(s[k]);
    printf("%s",s+1);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC125
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long[] lgcd = new long[N + 1];
            long[] rgcd = new long[N + 1];

            for (int i = 0; i < N; i++)
            {
                lgcd[i + 1] = CalcGCD(lgcd[i], A[i]);
                rgcd[N - i - 1] = CalcGCD(rgcd[N - i], A[N - 1 - i]);
            }

            long res = 0;
            for (int i = 0; i < N; i++)
            {
                res = Math.Max(res, CalcGCD(lgcd[i], rgcd[i + 1]));
            }
            Console.WriteLine(res);

        }
        public static long CalcGCD(long a, long b)
        {
            if (b == 0) { return a; }
            return CalcGCD(b, a % b);
        }
    }
}


Measured memory_bytes: 29916
import sys
sys.setrecursionlimit(100000)


def process():
    for data in get_dataset():
        H = len(data)
        W = len(data[0])
        field = create_field(H, W)
        print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(raw_input().rstrip())
        dataset.append(data)
    return dataset

process()

Measured memory_bytes: 15884
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

int check[100000];

int main()
{
    // input
    int N, M;
    int H[100000];
    int A[100000];
    int B[100000];
    int a,b;
    scanf( "%d %d", &N, &M );
    for ( int i=0; i<N; i++ ) {
        scanf( " %d", H+i );
    }
    for ( int i=0; i<M; i++ ) {
        scanf( " %d %d", &a, &b );
        if ( H[a-1] <= H[b-1] ) {
            check[a-1] = -1;
        }
        if ( H[b-1] <= H[a-1] ) {
            check[b-1] = -1;
        }
    }

    // process
    int ret = 0;
    for ( int i=0; i<N; i++ ) {
        if ( check[i] == 0 ) {
            ret++;
        }
    }

    // output
    printf( "%d\n", ret );

    return 0;
}


Measured memory_bytes: 2468
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int N;
vector<ld> x,y;

ld calc(ld X,ld Y){
  ld ans=0;
  for(int i=0;i<N;i++){
    ld tmpx=abs(X-x.at(i));
    ld tmpy=abs(Y-y.at(i));
    chmax(ans,sqrt(tmpx*tmpx + tmpy*tmpy));
  }
  return ans;
}

ld f(ld X){
  ld l=0;
  ld r=1000;
  for(int i=0;i<100;i++){
    ld midl=(2*l+r)/3;
    ld midr=(l+2*r)/3;
    if(calc(X,midl)>calc(X,midr)) l=midl;
    else  r=midr;
  }
  return calc(X,l);
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> N;
  x.resize(N);
  y.resize(N);
  for(int i=0;i<N;i++)  cin >> x.at(i) >> y.at(i);

  ld l=0;
  ld r=1000;
  for(int i=0;i<100;i++){
    ld midl=(2*l+r)/3;
    ld midr=(l+2*r)/3;
    if(f(midl)>f(midr))  l=midl;
    else  r=midr;
  }
  cout << f(l) << endl;

  return 0;
}

Measured memory_bytes: 3888
#include<stdio.h>
#define MAX 100
int number[MAX] = {0};
void selectionSort(int *, int);

int main(){
    int n, i;

    scanf("%d\n", &n);

    scanf("%d", number);
    for(i = 1; i < n ; i++) {
        scanf(" %d", number + i);  
    }
    selectionSort(number, n);

}

void selectionSort(int *a, int n){
    int i, j;
    int minj;
    int t;
    int temp = 0;
    int flag;
    for(i = 0; i < n; i++){
        flag = 0;
        minj = i;
        for(j = i + 1; j < n; j++){
            if(a[j] < a[minj]){
                minj = j;
                flag = 1;
            }
        }
        if(flag == 1){
            t = a[i];
            a[i] = a[minj];
            a[minj] = t;
            temp++;
        }
    }

                
    for(i = 0; i < n - 1; i++){
        printf("%d ", *(a + i));
    }
    printf("%d\n", *(a + n - 1));
    printf("%d\n", temp);
}


Measured memory_bytes: 2100
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	vector<vector<int>> vec(3, vector<int> (3));
	int N;
	rep(i, 3)
	{
		rep(j, 3)
		{
			cin >> vec[i][j];
		}
	}
	cin >> N;
	rep(i, N)
	{
		int temp;
		cin >> temp;
		rep(i, 3)
		{
			rep(j, 3)
			{
				if (vec[i][j] == temp)
					vec[i][j] = 0;
			}
		}
	}

	string ans;
	ans = "No";
	rep(i, 3)
	{
		if (vec[i][0] == 0 && vec[i][1] == 0 && vec[i][2] == 0)
		{
			ans = "Yes";
			break ;
		}
		if (vec[0][i] == 0 && vec[1][i] == 0 && vec[2][i] == 0)
		{
			ans = "Yes";
			break ;
		}
	}
	if (vec[0][0] == 0 && vec[1][1] == 0 && vec[2][2] == 0)
		ans = "Yes";
	if (vec[0][2] == 0 && vec[1][1] == 0 && vec[2][0] == 0)
		ans = "Yes";

	cout << ans << '\n';
	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int keta(ll A)
{
    int cnt = 0;
    while (A)
    {
        cnt++;
        A /= 10;
    }
    return cnt;
}

int main()
{
    int N, M;
    cin >> N >> M;

    cout << (M+N-3)/(N-1) << endl;

    return 0;
}


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

using namespace std;

#define NMAX 50

typedef struct s{
	string L;
	double P,A,B,C,D,E,F,S,M;
} S;

bool operator<(S a,S b){
	double aa=(a.F*a.S*a.M-a.P)/((a.A+a.B+a.C+a.D+a.E)+(a.D+a.E)*(a.M-1));
	double bb=(b.F*b.S*b.M-b.P)/((b.A+b.B+b.C+b.D+b.E)+(b.D+b.E)*(b.M-1));
	return aa>bb||(aa==bb&&a.L<b.L);
}

int main(){

	int N;
	S data[NMAX];

	while(1){
		cin>>N;
		if(N==0) break;

		for(int i=0;i<N;i++){
			cin>>data[i].L>>data[i].P>>data[i].A>>data[i].B>>data[i].C>>data[i].D>>data[i].E>>data[i].F>>data[i].S>>data[i].M;
		}

		sort(data,data+N);

		for(int i=0;i<N;i++){
			cout<<data[i].L<<endl;
		}
		cout<<"#"<<endl;
	}

}

Measured memory_bytes: 1256
#include <stdio.h>

int main(void) {
	char arr[22];
	int i, len=0;
	
	scanf("%s", arr);
	
	while(arr[len]!=0){
		len++;
		
	}
	for(i=len-1;i>=0;i--)
	printf("%c", arr[i]);
	
	putchar('\n');

	return 0;
}

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

#define INF INT64_MAX
#define MAX 5

long long N;
long long a[MAX];

int main() {
	cin >> N;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	long long mi = INF;
	for( int i = 0; i < MAX; i++ ) {
		mi = min( mi, a[i] );
	}
	long long d = N / mi;
	if( N % mi ) {
		d++;
	}
	long long ans = 4 + d;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin>>N>>S;
    int b[N+1]{},w[N+1]{};
    b[0]=0;
    w[0]=0;
    rep(i,N){
        b[i+1]=b[i];
        w[i+1]=w[i];
        if(S[i]=='#') b[i+1]++;
        else w[i+1]++;
    }
    int ans=INF;
    rep(i,N+1){
        ans=min(ans,b[i]+(w[N]-w[i]));
    }
    cout << ans << endl;




}


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

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int H,W;
  cin >> H >> W;
  vector<vector<char>> C(H,vector<char>(W));
  rep(i,H)
  {
    rep(j,W)
    {
      cin >> C[i][j];
    }
  }
  rep(i,2*H)
  {
    rep(j,W)
    {
      if(j!=W-1)
      {
      cout << C[i/2][j];
      }
      if(j==W-1)
      {
        cout << C[i/2][j] << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys

N = int(input())
#Bs = list(map(int, input().split()))
Bs = [B - 1 for B in map(int, input().split())]

anss = []
for _ in range(N):
    iNow = -1
    for i in reversed(range(len(Bs))):
        if Bs[i] == i:
            iNow = i
            break
    else:
        print(-1)
        sys.exit()

    anss.append(iNow)

    Bs = Bs[:iNow] + Bs[iNow+1:]

print('\n'.join(map(str, [ans+1 for ans in anss[::-1]])))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
list<int>li[100005];
int n,m;
int dp[100005];

int solve(int i){
 
  if(dp[i]!=-1)
    return dp[i];
  
  int maxi = 0;
  
  for(auto e:li[i]){
  	maxi = max(solve(e)+1,maxi);
  }
  
  return dp[i] = maxi;
}
int main(){
	
  cin>>n>>m;
  memset(dp,-1,sizeof dp);
  
  for(int i=0;i<m;i++){
  	int a,b;
    cin>>a>>b;
    li[a].push_back(b);
  }
  
  int ans = 0;
  
  for(int i=1;i<=n;i++){
    if(dp[i] == -1)
  		ans = max(ans,solve(i));
  }
  
  cout<<ans;
}

Measured memory_bytes: 7424
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;


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

const ll INF=1e9+7;

int main(){
    ll x,y;
    cin >> x >> y;
    if(x<=y){
        if(x<0 && y>0 && abs(y)>=abs(x)){
            cout << 1+y+x << endl;
        }
        else if(x<0 && y>0 && abs(y)<abs(x)){
            cout << 1-y-x << endl;
        }
        else{
            cout << y-x << endl;
        }
    }
    else{
        if(x>0 && y>=0){
            cout << min(1LL+x+y,2LL+x-y) << endl;
        }
        else if(x>0 && y<0 && abs(x)>=abs(y)){
            cout << 1+x+y << endl;
        }
        else if(x>0 && y<0 && abs(x)<abs(y)){
            cout << 1-x-y << endl;
        }
        else if(x==0){
            cout << 1-y << endl;
        }
        else{
            cout << 2+x-y << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		String r = solve(s);
		System.out.println(r);
	}

	private static String solve(String s) {
		if (s.equals("ABC"))
			return "ARC";
		else
			return "ABC";
	}
}

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

int main(){
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      cin >> s[i][j];
    }
  }

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

  int cnt = 0;
  bool flag = true;

  for(int i=0; i<h; ++i){
    for(int j=0; j<w; ++j){
      if(s[i][j] == '#'){
       bool can = false;
        for(int k=0; k<4; ++k){
          const int ni = i + dy[k];
          const int nj = j + dx[k];
          if(ni<0 || h<=ni) continue;
          if(nj<0 || w<=nj) continue;
          if(s[ni][nj] == '#') can = true;
        }
        if(can == false) flag = false;
      }
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

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

const int LIMIT = 5001;

int main()
{
	int n;

	while( cin >> n && n )
	{
		bool map[ LIMIT ][ 5 ] = {0};
		int h[ 5 ] = {0};
		for( int i = 0; i < n; ++i ){
			int d, p, q;
			cin >> d >> p >> q;
			q -= 1;

			int w = ( d == 1 ? p : 1 );
			int hh = 0;
			for( int i = 0; i < w; ++i ){
				hh = max( hh, h[ q + i ] );
			}
			if( d == 1 ){
				for( int i = 0; i < w; ++i ){
					map[ hh ][ q + i ] = true;
					h[ q + i ] = hh + 1;
				}
			}else{
				for( int i = 0; i < p; ++i ){
					map[ hh + i ][ q ] = true;
				}
				h[ q ] = hh + p;
			}

			for( int i = 0; i < 5; ++i ){
				hh = max( hh, h[ i ] );
			}
			for( int i = 0; i < hh; ++i ){
				bool full = true;
				for( int j = 0; j < 5; ++j ){
					if( !map[ i ][ j ] ){
						full = false;
						break;
					}
				}
				if( full ){
					for( int j = i; j < hh; ++j ){
						for( int k = 0; k < 5; ++k ){
							map[ j ][ k ] = map[ j + 1 ][ k ];
						}
					}
					for( int j = 0; j < 5; ++j ){
						int p = hh;
						while( p >= 0 && !map[ p ][ j ] ){
							--p;
						}
						h[ j ] = p + 1;
					}
					--hh;
					--i;
				}
			}
		}
		int hh = 0;
		for( int i = 0; i < 5; ++i ){
			hh = max( hh, h[ i ] );
		}
		int ans = 0;
		for( int i = 0; i < hh; ++i ){
			for( int j = 0; j < 5; ++j ){
				if( map[ i ][ j ] ) ++ans;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);

#define debug(x) (#x " : " + to_string(x))
#define debug_cout(x) (cout << #x << " : " << to_string(x) << endl)
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair((a), (b));
using namespace std;
using ll = long long;
//#define int long long
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = (int)2e9;

/*****/

int main()
{
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n)	cin >> p[i];

	int cnt = 0;
	for (int i = 1; i < n - 1; i++)
	{
		int max = p[i - 1] > p[i + 1] ? p[i - 1] : p[i + 1];
		int min = p[i - 1] < p[i + 1] ? p[i - 1] : p[i + 1];

		if (min < p[i] && p[i] < max)
		{
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD= 1e9 + 7;
ll fast_power(ll base, ll power) {
    long long result = 1;
    while(power > 0)
    {
        if(power % 2 == 1)
        {
            result = (result%MOD * base%MOD) % MOD;
        }
        base=(base%MOD * base%MOD)%MOD;
        power/=2;
    }
    return result;
}
ll LCM( ll a , ll b)
{
    return ((a*b)/__gcd(a,b));
}
ll divideMOD ( ll a , ll b , ll m)
{
    return ((a%m)*(fast_power(b,m-2)%m))%MOD;
}
int main()
{
    ll x , y;
    cin >> x >> y;
    if( (x+y)%3 != 0 )
    {
        cout << 0 ;
        return 0;
    }
    ll m;
    ll ans=0 , part1 , part2 , subpart2;
    for(int n = 0 ; n <= x ; n++)
    {
        m= x-n ;
        m/=2;
        if( n + 2*m == x && m + 2*n == y)
        {
            part1=1;
            for(int i =1 ; i <= (n+m) ;i++ )
            {
                part1=part1%MOD * i%MOD ;
                part1%=MOD;
            }
            part2=1;
            subpart2= 1;
            for(int i = 1 ; i <= m ;i++ )
            {
                part2=part2%MOD * i%MOD ;
                part2%=MOD;
            }
            for(int i = 1 ; i<= n ; i++ )
            {
                subpart2=subpart2%MOD * i%MOD ;
                subpart2%=MOD;
            }
            part2= part2%MOD * subpart2%MOD ;
            part2%=MOD;
            ans+= (divideMOD( part1 , part2 , MOD )%MOD);
            ans%=MOD;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
from math import factorial

N, K = [int(_) for _ in input().split()]
# N = 10
MOD = 10 ** 9 + 7

kaijo = [0] * (N + 1)
kaijo[0] = kaijo[1] = 1
for i in range(2, N + 1):
    kaijo[i] = (kaijo[i - 1] * i) % MOD

gyaku = [0] * (N + 1)
gyaku[0] = gyaku[1] = 1

for i in range(2, N + 1):
    gyaku[i] = (gyaku[i - 1] * pow(i, MOD - 2, MOD)) % MOD
    # gyaku[i] = pow(kaijo[i], MOD - 2, MOD)


def calc(n, k):
    return (kaijo[n] * gyaku[n - k] * gyaku[k]) % MOD
    # return factorial(n) // (factorial(n - k) * factorial(k))


def solve():
    for i in range(1, K + 1):
        n = N - K + 1
        k = i
        if k <= n:
            print((calc(n, k) * calc(K - 1, i - 1)) % MOD)
        else:
            print(0)


solve()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];

int main() {
	int n;
	string s;
	cin>>n>>s;
	bool flg=true;
	if(n%2>0){
		flg=false;
	}else{
		rep(i,n/2){
			if(s[i]!=s[i+n/2])flg=false;
		}
	}
	if(flg){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (s[i] == '1') {
            s[i] = '9';
        } else if (s[i] == '9') {
            s[i] = '1';
        }
    }
    cout << s << nl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3604
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
L_c = 0
R_c = 0
for i in range(M):
    if A[i]<X:
        L_c+=1
    elif A[i]>X:
        R_c+=1
print(min(L_c,R_c))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int N, M; cin >> N >> M;
    vector<int> key(M, 0), a(M, 0);
    
    rep(i, M){
        cin >> a[i];
        int b; cin >> b;
        rep(j, b){
            int c; cin >> c; --c;
            key[i] += 1<<c;
        }
    }

    const int inf = 1<<30;
    vector<vector<int>> dp(M+1, vector<int>(1<<N, inf));
    dp[0][0] = 0;
    rep(i, M) rep(S, 1<<N) if(dp[i][S] != inf) {
        // use
        chmin(dp[i+1][S|key[i]], dp[i][S] + a[i]);
        // not use
        chmin(dp[i+1][S], dp[i][S]);
    }
    cout << (dp[M][(1<<N)-1] == inf? -1:dp[M][(1<<N)-1]) << endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	ll N, A, B;
	cin >> N >> A >> B;
	vector<ll>X(N);
	rep(i, N)cin >> X[i];
	ll ans = 0;
	rep(i, N - 1) {
		ans += min(A*(X[i + 1] - X[i]), B);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >>n;
  int ans=0;
  int x[n],y[n];
  rep(i,n)cin >> x[i];
  rep(i,n)cin >> y[i];
  rep(i,n){
    if(x[i]-y[i]>0)ans+=x[i]-y[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N = int(input())
    tree = {i:[] for i in range(N)}
    edges = []
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges.append((a, b))
        tree[a].append(b)

    ans = {}
    frontier = deque([(1,0)])
    while frontier:
        u, prev_color = frontier.pop()
        if tree.get(u) is None:
            continue
        for i, v in enumerate(tree[u], 1):
            color = i if i != prev_color else len(tree[u])+1
            ans[u, v] = color
            frontier.appendleft((v, color))

    print(max(ans.values()))
    for edge in edges:
        print(ans[edge])


    
main()

Measured memory_bytes: 53892