akhauriyash/Code-Regression huggingface dataset:
///                                                     ببِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define vec  vector
#define gcd  __gcd
#define pi   acos( -1 )
#define ll   long long
#define ld   long double
#define N    2256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define rep( a, b, c, d )  for( int a = b; a <= c; a += d )
#define rvv( a, b, c, d )  for( int a = b; a >= c; a -= d )
#define en                 printf( "\n" )
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() )
#define numcounts          __builtin_popcount
#define mxn( x, y, z )     max( x, min( y, z ) )
#define mnx( x, y, z )     min( x, max( y, z ) )
const int dx[ ] = { 1, -1, 0, 0 };
const int dy[ ] = { 0, 0, -1, 1 };
using namespace std;
ll ttt = 1;
ll n, a[20], x[20][20], y[20][20], ans;
bool ok;
void solve()
{
    cin >> n;
    for( ll i = 0; i < n; i ++ )
    {
        cin >> a[i];
        for( ll j = 0; j < a[i]; j ++ )
        {
            cin >> x[i][j] >> y[i][j];
            x[i][j] --;
        }
    }
    for( ll i = 1; i < 1<<n; i ++ )
    {
        ok = 1;
        for( ll j = 0; j < n; j ++ )
        {
            if( (i >> j) & 1 )
            {
                for( ll k = 0; k < a[j]; k ++ )
                    if( ((i >> x[j][k]) & 1) != y[j][k] )ok = 0;
            }
        }
        if( ok )ans = max( ans, numcounts(i) * 1LL );
    }
    cout << ans;
}
int main()
{
    //sc( "%I64d", &ttt );
    for( int i = 0; i < ttt; i ++ )
        solve();
}


Measured memory_bytes: 256
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PAIR pair<int, int>
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
//

int req[10] = { 0,2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10010];
signed main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int N, M;
  cin >> N >> M;
  int A[M];
  REP(i, M) cin >> A[i];
  fill(dp, dp + N, (int)-1e9);
  dp[0] = 0;
  REP(i, N)
  {
    REP(j, M)
    {
      if (i + 1 - req[A[j]] >= 0)
      {
        chmax(dp[i+1], dp[i + 1 - req[A[j]]] + 1);
      }
    }
  }
  sort(A,A+M,greater<int>());
  string ans{""};
  int n = N;
  REP(i,dp[N])
  {
    REP(j,M)
    {
      if(n >= req[A[j]] && dp[n] == dp[n-req[A[j]]] + 1)
      {
        ans.push_back(A[j]+'0'); 
        n -= req[A[j]];
        break; 
      }
    }
    
  }
  assert(n==0);
  cout << ans << endl;
}

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;

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

        if(tmp=="AC"){
            ac++;
        }else if(tmp=="WA"){
            wa++;
        }else if(tmp=="TLE"){
            tle++;
        }else if(tmp=="RE"){
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll A,B,C;
	ll sum = 0;
	cin >> A >> B >> C;
	if (B >= A * C) {
		cout << C;
	}
	else {
		cout << B / A;
	}

	return 0;
}

Measured memory_bytes: 256
//I Guds namn
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	if(b < a)
	{
		cout << 0 << '\n';
		return 0;
	}
	if(n == 1)
	{
		if(a == b)
			cout << 1;
		else
			cout << 0;
		cout << '\n';
		return 0;
	}
	ll sum = 0;
	for(int i = 2;i < n;i++)
		sum += a;
	ll mSum = 0;
	for(int i = 2;i < n;i++)
		mSum += b;
	cout << 1 + mSum - sum << '\n';
	return 0;
}
//KAG

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int ans(ll f){
	int res = 0;
	for(ll i = 2;i * i <= f; ++i){
		int cnt = 0;
		while(f%i == 0){
			++cnt;		
			f/=i;
		}
		int j = 1;
		while(cnt >= j * (j+1)/2){
			++res;
			++j;
		}
	}
	if(f != 1)++res;
	return res;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll n;
	cin >> n;
	cout << ans(n) << '\n';
}


Measured memory_bytes: 3644
#include<iostream>
#include<bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <map>
typedef long long ll;
using namespace std;
int main()
{
	
	int n;
	cin>>n;
	int flag = 0;
	while(n--)
	{
		
		int x;
		cin>>x;
		if(x%2==0)
		{
			if(!(x%3==0||x%5==0))
			{
				flag = 1;
			}
		}
	}
	if(flag == 0) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return 0;
}

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

using namespace std;

constexpr unsigned int MAX_N { 5000005 };

long long p[MAX_N];

int main()
{
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.length() + 1;

    p[n] = s[n - 1] == '>' ? p[n - 1] + 1 : 0;
    for (int i = n - 1; i >= 0; --i)
    {
        p[i] = s[i] == '>' ? p[i + 1] + 1 : 0;
    }

    long long count = 0, sum = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        if ((s[i] == '<' && p[i] < p[i + 1]) ||
            (s[i] == '>' && p[i] > p[i + 1]))
        {
            continue;
        }

        if (s[i] == '<') p[i + 1] = p[i] + 1; 
    }

    for (int i = 0; i < n; ++i)
    {
            sum += p[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define repi(i,x,n) for(int i = x; i < n; i++)
#define rep(i,n) repi(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;

#define int long long

#define f first
#define s second

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

    cout<<fixed<<setprecision(10);

    int N;
    vector<pair<int,pair<pair<int,int>,pair<int,int>>>> t;
    vector<pair<int,int>> a, b;

    cin>>N;

    t.resize(N);

    for(int i = 0; i < N; i++){
        cin>>t[i].f>>t[i].s.f.f>>t[i].s.f.s>>t[i].s.s.f>>t[i].s.s.s;
    }


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

    for(int i = 0; i < N; i++){
        if(i && t[i-1].s.f.s == t[i].s.f.s && t[i].s.f.f != t[i-1].s.f.f){
            if(t[i].s.f.s == 0){
                a.push_back(make_pair((t[i-1].s.s.s - t[i].s.s.s)*(t[i-1].s.s.s - t[i].s.s.s) + (t[i-1].s.s.f - t[i].s.s.f)*(t[i-1].s.s.f - t[i].s.s.f), t[i].f - t[i-1].f));
                a[a.size()-1].f *= -1;
            } else {
                
                b.push_back(make_pair((t[i-1].s.s.s - t[i].s.s.s)*(t[i-1].s.s.s - t[i].s.s.s) + (t[i-1].s.s.f - t[i].s.s.f)*(t[i-1].s.s.f - t[i].s.s.f), t[i].f - t[i-1].f));
                 b[b.size()-1].f *= -1; 
            }
        }
    }

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

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

    if(a.size() == 0) cout<<-1<<" "<<-1<<endl;
    else cout<<sqrt(-a[0].first)<<" "<<(double)a[0].second/60<<endl;;

    
    if(b.size() == 0) cout<<-1<<" "<<-1<<endl;
    else cout<<sqrt(-b[0].first)<<" "<<(double)b[0].second/60<<endl;;


    
    return 0;
}




Measured memory_bytes: 3352
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[]t=new long[N];
		long max=0;
		for(int i=0;i<N;i++){
			t[i]=sc.nextLong();
			if(t[i]>max)max=t[i];
		}
		long ans=max;
		for(int i=0;i<N;i++){
			if(ans%t[i]!=0){
				ans=gcd(ans,t[i]);
			}
		}
		System.out.println(ans);
	}
	
	long gcd(long a, long b){
		long tempa=a;
		long tempb=b;
		long r=a%b;
		while(r!=0){
			a=b;
			b=r;
			r=a%b;
		}
		return (tempb/b)*tempa;
	}
}

Measured memory_bytes: 23764
while(True):
    n = int(input())
    if n==0: break
    d = {}
    c = 0
    l = list()
    for _ in range(n):
        id_,p,q = map(int,input().split())
        if id_ in d:
            d[id_] += p*q
        else:
            d[id_] = p*q
            l.append(id_)
    for i in l:
        if d[i] >= 1000000:
            print(i)
            c += 1
    if c == 0:
        print('NA')

Measured memory_bytes: 7776
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007

long dp[41][1<<17][2];

int main(){
  int n,x,y,z;
  cin>>n>>x>>y>>z;
  const int MASK = (1<<(x+y+z))-1;

  fill(dp[0][0], dp[n+1][0], 0);
  dp[0][0][0] = 1;

  const int XYZ = (1<<(x+y+z-1))+(1<<(y+z-1))+(1<<(z-1));
  rep(i,n) rep(mask, 1<<(x+y+z)){
     rep(k,2) if(dp[i][mask][k]>0){
      repl(j,1,11){
        int nmask = ((mask<<j) + (1<<(j-1)))&MASK;
        if(k==0 && (nmask&XYZ)==XYZ){//dbg(bitset<17>(nmask));
          (dp[i+1][nmask][1] += dp[i][mask][0])%=MOD;
        }
        else {
          (dp[i+1][nmask][k] += dp[i][mask][k])%=MOD;
        }
      }
    }
  }

  long ans = 0;
  rep(mask, 1<<(x+y+z)) ans += dp[n][mask][1];

  cout << ans%MOD << endl;

  return 0;
}


Measured memory_bytes: 84224
#include <iostream>

int main(int argc, char const* argv[])
{
    uint32_t n, a, b;
    std::cin >> n >> a >> b;

    uint32_t result = 0;
    for (int i=1; i <= n; i++) {
        uint32_t tmp = i;
        uint32_t digitSum = 0;
        while (tmp != 0) {
            digitSum += tmp % 10;
            tmp /= 10;
        }
        if (a <= digitSum && digitSum <= b) {
            result += i;
        }
    }
    std::cout << result << std::endl;
    return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    string ans="";
    for (int i = 0; i < 3; ++i) {
        string s;cin >>s;
        ans+=s[i];
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t,u;
  cin>>s>>t;
  long long a,b;
  cin>>a>>b;
  cin>>u;
  if(u==s)
 
  {
    a--;
  }
  else
    b--;
  cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
s = 0
while high - low >= 0:
    for j in range(n):
        X += max(0, math.ceil((h[j] - t * b) / (a - b)))
        #Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))
    if X == t:
        print(t)
        exit()
    elif X < t:
        high = t - 1
        """for j in range(n):
            Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))"""
    elif X > t:
        low = t + 1
    s = t
    t = (low + high) // 2
    X = 0
    Y = 0
for j in range(n):
  if math.ceil((h[j] - s * b) / (a - b)) > 0:
            Y += math.ceil((h[j] - s * b) / (a - b))
if Y <= s:
  print(s)
else:
  print(s + 1)


Measured memory_bytes: 14264
n, q = gets.split.map(&:to_i)
queue = []
n.times do
  name, rest = gets.chomp.split
  queue << [name, rest.to_i]
end
time = 0
until queue.empty?
  name, rest = queue.shift
  if rest <= q
    time += rest
    puts "#{name} #{time}"
  else
    time += q
    queue << [name, rest - q]
  end
end


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int N;
vector<pair<int,int> > px;
vector<pair<int,int> > py;

vector<tuple<int,int,int> > edge;//辺の重み，始点，終点
class UnionFind{
  public:
  //親の番号を格納する 親だった場合-1*集合のサイズ
  vector<int> Parent;

  //コンストラクタ 初めはバラバラの状態
  UnionFind(int N){
    Parent = vector<int>(N,-1);//要素数N,要素の値-1で初期化
  }

  //Ａがどのグループに属しているか調べる
  int root(int A){
    if(Parent[A] < 0)return A;//Aが親だったらA自身を返す
    return Parent[A] = root(Parent[A]);//親に繋ぎなおす
  }

  //頂点数を調べる
  int size(int A){
    return -Parent[root(A)];//Aの根×-1=集合のサイズ
  }

  //AとBをくっつける
  bool connect(int A, int B){
    //Aの根とBの根をくっつける
    A = root(A);
    B = root(B);
    if(A==B)return false;//既に同じグループならそのままでfalseを返す

    //Aのサイズ>=Bのサイズとする  
    if(size(A)<size(B))swap(A,B);

    Parent[A] += Parent[B];//AのサイズにBのサイズを足す
    Parent[B] = A;//Bの親をAに変更する
    return true;
  }

  //AとBが同じグループかどうか調べる
  bool same(int A,int B){
    if(root(A)==root(B))return true;
    else return false;
  }

};

int kruskal(){//最小全域木を作り、コストの総和を返す
  UnionFind Uni(100010);
  int cost=0;
  sort(all(edge));
  rep(i,edge.size()){
    int a = get<1>(edge[i]),b = get<2>(edge[i]);
    if(!Uni.same(a,b)){//閉路が出来ないなら
      cost += get<0>(edge[i]);
      Uni.connect(a,b);
    }
  }

  return cost;
}

int main(){
  cin >> N;
  map <pair<int,int>,int > M;
  rep(i,N){
    int x,y;
    cin >> x >> y;
    px.push_back(make_pair(x,y));
    py.push_back(make_pair(y,x));
    M[make_pair(x,y)]=i;
  }
  
  sort(all(px));
  sort(all(py));

  rep(i,N-1){
    int x1,y1,x2,y2;
    x1 = px[i].first;
    x2 = px[i+1].first;
    y1 = px[i].second;
    y2 = px[i+1].second;
    edge.push_back(make_tuple(abs(x2-x1),M[make_pair(x1,y1)],M[make_pair(x2,y2)]));
    y1 = py[i].first;
    y2 = py[i+1].first;
    x1 = py[i].second;
    x2 = py[i+1].second;
    edge.push_back(make_tuple(abs(y2-y1),M[make_pair(x1,y1)],M[make_pair(x2,y2)]));
  }
  
  cout << kruskal() << endl;
}

Measured memory_bytes: 13412
#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(){
  int n, m, q;
  cin >> n >> m >> q;

  vector<vector<int> > train(n + 1, vector<int>(n + 1, 0));
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    train[l][r]++;
  }

  vector<vector<int> > cum(n + 1, vector<int>(n + 1, 0));
  for(int i = 1; i <= n; i++) cum[i][i] = train[i][i];

  for(int i = 1; i <= n - 1; i++) {
    for(int j = 1; j <= n - i; j++) {
      cum[j][j + i] = train[j][j + i] + cum[j + 1][j + i] + cum[j][j + i - 1] - cum[j + 1][j + i - 1];
    }
  }

  rep(i, q) {
    int p, q;
    cin >> p >> q;
    cout << cum[p][q] << endl;
  }
  return 0;		 
}

Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vl vector <long>
#define vll vector < ll >
#define pll pair < ll , ll >
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MODCONST 1000000007
//#define v[i] abs(v[i])

using namespace std;

void solve()
{
    string s;
    cin>>s;
    ll len = s.length();
    ll mid = len/2, a = 0, b = (len-3)/2;
    bool flag = true;
    while(a<=b){
        if((s[a]==s[b]) and (s[mid+1+a]==s[mid+1+b]) and (s[a]==s[mid+1+a])){
            a++; b--;
        }else{
            flag = false;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

int main()
{
    fastio ;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll tc=1;
    //cin>>tc; //for number of testcases
    //ll ts = tc;
    while(tc--){
        //cout<<"Case #"<<ts-tc<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int p[22];
int main(){
	cin>>n;
	REP(i,n)cin>>p[i];
	int ans=0;
	for(int i=1;i<n-1;i++){
		if((p[i-1]>p[i]&&p[i]>p[i+1])||(p[i-1]<p[i]&&p[i]<p[i+1])){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
t,a = inm()
for i in range(n-1):
    tt,aa = inm()
    k = max((t+tt-1)//tt, (a+aa-1)//aa)
    t = k*tt
    a = k*aa
print(t+a)


Measured memory_bytes: 38768
def main():
    n = int(input())
    m = [list(map(int, input().split())) for _ in range(n)]

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            d = m[i][j]
            for k in range(n):
                if k in (i, j):
                    continue
                t = m[i][k] + m[k][j]
                if t < d:
                    print(-1)
                    return
                if t == d:
                    break
            else:
                ans += d
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69212
#include<stdio.h>

int main() {
    int Dice[2][7]; //サイコロ２個、６面体
    //int side[5] = {2, 3, 5, 4, 2};
    //処理用
    int i, j, k;
    
    //入力
    for (i=0; i<2; i++) { //２回 0 ~ 1
        for (j=1; j<7; j++) {  //６面 1 ~ 6
            scanf("%d", &Dice[i][j]);
        }
    }
    
    //処理
    for (i=0; i<6; i++) {
        
        //1の１面　== ２の２面 の場合
        if (Dice[0][1] == Dice[1][1]) {
            for (j=0; j<4; j++) {
                
                //判定
                for (k=1; k<7; k++) {
                    if (Dice[0][k] != Dice[1][k]) {
                        break;
                    }
                }
                
                if (k == 7) { //kが最後まで回ったおk
                    printf("Yes\n");
                    return 0;
                }
                
                //回す
                Dice[1][0] = Dice[1][2];
                Dice[1][2] = Dice[1][3];
                Dice[1][3] = Dice[1][5];
                Dice[1][5] = Dice[1][4];
                Dice[1][4] = Dice[1][0];
                
            }
        }
        
        //回す
        Dice[1][0] = Dice[1][1];
        
        switch(i) { //iで判定
            case 2: //iが2の時だけこっち
                Dice[1][1] = Dice[1][3];
                Dice[1][3] = Dice[1][6];
                Dice[1][6] = Dice[1][4];
                Dice[1][4] = Dice[1][0];
                break;
            
            default: //その他
                Dice[1][1] = Dice[1][2];
                Dice[1][2] = Dice[1][6];
                Dice[1][6] = Dice[1][5];
                Dice[1][5] = Dice[1][0];
                break;
        }
    }
    
    //ここまできたらアウト
    printf("No\n");
    
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>

    using namespace std;


    int main(){
        string s;
        cin >> s;
        for(int i = 0; i < 3; i++){
            if(s[i] == '9'){
                s[i] = '1';
            }else if(s[i] == '1'){
                s[i] = '9';
            }
        }
        cout << s << '\n';
    }

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/******************************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/******************************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;

vector<vector<int> > g(nax);
vector<int> val(nax);

void dfs(int cur,int par,int v){
    v+=val[cur];
    val[cur] = v;
    for(auto it:g[cur]){
        if(it==par) continue;
        dfs(it,cur,v);    
    }
}



int main(){

    sync
   // file();
    
    int n,m;
    cin>>n>>m;


    forn(i,n-1){
        int x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    while(m--){
        int node,v;
        cin>>node>>v;
        val[node]+=v;
    }
    dfs(1,1,0);
    fore(i,1,n) cout<<val[i]<<" ";

  return 0;
}

Measured memory_bytes: 23552
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
struct SCC{
    vector<vector<int>> g, gr;
    int n, k;
    vector<int> cmp, vs;
    vector<bool> used;
    void dfs(int x){
        used[x]=1;
        for(auto y:g[x]){
            if(!used[y]) dfs(y);
        }
        vs.push_back(x);
    }
    void rdfs(int v, int k){
        used[v]=1;
        cmp[v]=k;
        for(auto y:gr[v]){
            if(!used[y]) rdfs(y, k);
        }
    }
    SCC(const vector<vector<int>> &g):g(g), n(g.size()), cmp(n), used(n){
        gr.resize(n);
        for(int x=0; x<n; x++) for(auto y:g[x]) gr[y].push_back(x);
        for(int i=0; i<n; i++){
            if(!used[i]) dfs(i);
        }
        fill(used.begin(), used.end(), 0);
        k=0;
        for(int i=vs.size()-1; i>=0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }
    }
};
int main()
{
    int n, m;
	scanf("%d %d", &n, &m);
	vector<vector<int>> g(n);
	for(int i=0; i<m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].push_back(b);
	}
	SCC scc(g);
	printf("%d\n", scc.k);
	vector<vector<int>> v(scc.k);
	for(int i=0; i<n; i++) v[scc.cmp[i]].push_back(i);
	for(auto w:v){
		printf("%d", w.size());
		for(auto x:w) printf(" %d", x);
		printf("\n");
	}
    return 0;
}


Measured memory_bytes: 101184
n=int(input())
s=list(input())
z=90
ans = []
# print(n,s)
# print([ord(i) for i in s])

for i in s:
    if ord(i)+n > z:
        ans.append(chr(ord("A") - (z-ord(i)-n)  -1))
    else:
        ans.append(chr(ord(i)+n))

# print([ord(i) for i in ans])
print("".join(ans))



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

int main(void){
  char x;
  cin >> x;
  if(x=='A'){
    cout << 'T' << endl;
  }else if(x=='T'){
    cout << 'A' << endl;
  }else if(x=='G'){
    cout << 'C' << endl;
  }else{
    cout << 'G' << endl;
  }
  return 0;
}

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

int main() {
  int64_t a, b, x;
  cin >> a >> b >> x;
  int64_t res = b / x + 1;
  if (a != 0) {
    res -= (a - 1) / x + 1;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int D;
    int T;
    int S;

    cin >> D >> T >> S;

    if (S*T >= D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main()
{
		int n,m,o,p,d,c;
		scanf("%d %d %d %d", &n,&m,&o,&p);
		{
		c=m+n;
				d=o+p;
		
if(c>d){
						printf("Left\n");
				}
				else if(c==d){
						printf("Balanced\n");
				}else{
						printf("Right\n");
				}
				}
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    // 処理
    if (abs(a - c) <= d) {
        cout << "Yes" << endl;
    } else if (abs(a - b) <= d && abs(b - c) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    // 出力

    return 0;
}


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

using namespace std;

int main()
{
	string N;
	int num= 0;

	cin >> N;

	for (int i = 0; i < N.length(); i++)
		num = num + (N[i] - 48);
	if (num % 9 == 0)
		cout << "Yes";
	else
		cout << "No";
	
	return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll, ll>
#define mii         map<pii, ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a + b + p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

void solve(){
    int n;
    vi A(3);
    cin>>n;
    rep(i, 0, 3) cin>>A[i];
    int p[n];
    rep(i, 0, n) cin>>p[i];
    sort(p, p+n);
    int ans = hell;
    do {
        rep(i, 0, n) {
            rep(j, i+1, n) {
                rep(k, j+1, n) {
                    int val, a, b, c;
                    val = a = b = c = 0;
                    int sum = 0;
                    rep(ind, 0, i+1) {
                        a += p[ind];
                        sum++;
                    }
                    rep(ind, i+1, j+1) {
                        b += p[ind];
                        sum++;
                    }
                    rep(ind, j+1, k+1) {
                        c += p[ind];
                        sum++;
                    }
                    val = abs(a-A[0]) + abs(b-A[1]) + abs(c-A[2]) + (sum - 3) * 10;
                    if(val < ans)
                        ans = val;
                }
            }
        }
    }
    while(next_permutation(p, p+n));
    cout<<ans<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;


int main()
{

  int A, B, C;
  cin >> A >> B >> C;
  int a = A, b = B, c = C;
 
  int cost = 0;
 
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int latte = a / 2;
    int malta = b / 2;
    int beet = c / 2;
    a = malta + beet;
    b = latte + beet;
    c = latte + malta;
 
    ++cost;
    if(A == a && b == B && c == C) {
      cout << -1 << endl;
      return (0);
    }
  }
 
  cout << cost << endl;
}


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

int main() {
  int N, i;
  cin >> N;
  std::vector<int> d(N);
  for (i=0; i<N; i++) cin >> d.at(i);
  std::sort(d.begin(), d.end());
  //for (i=0; i<N; i++) cout << i << ':' << d.at(i) << endl;////
  d.erase(unique(d.begin(), d.end()), d.end());
  cout << d.size() << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 75116
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Node[] nodes = new Node[N];
    for (int i = 0; i < N; i++) nodes[i] = new Node();
    for (int i = 0; i < N - 1; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      nodes[a].adjacent.add(nodes[b]);
      nodes[b].adjacent.add(nodes[a]);
    }
    int[] c = new int[N];
    long sum = 0;
    for (int i = 0; i < N; i++) {
      c[i] = scanner.nextInt();
      sum += c[i];
    }
    Arrays.sort(c);
    reverse(c);
    sum -= c[0];

    dfs(nodes[0], null, c, 0);
    System.out.println(sum);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < N; i++) {
      sb.append(nodes[i].value).append(' ');
    }
    sb.setLength(sb.length() - 1);
    System.out.println(sb.toString());
  }

  private static int dfs(Node node, Node from, int[] c, int cindex) {
    node.value = c[cindex++];
    for (Node a : node.adjacent) {
      if (a != from) {
        cindex = dfs(a, node, c, cindex);
      }
    }
    return cindex;
  }

  private static void reverse(int[] a) {
    int i = 0;
    int j = a.length - 1;
    while (i < j) {
      int tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++;
      j--;
    }
  }

  private static class Node {
    private final List<Node> adjacent = new ArrayList<>();
    private int value = -1;
  }
}


Measured memory_bytes: 46508
#include <iostream>
using namespace std;
int main (){
    int a, b, i;
    for(i=0; i<3000; i++){
    cin>>a>>b;
    if(a==0&&b==0){
    return 0;
    }
    else if(b>=a){
    cout<<a<<" "<<b<<endl;
    }
    else{
    cout<<b<<" "<<a<<endl;
    }
    }
    cout<<endl;
}


Measured memory_bytes: 3100
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class APassword {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            out.println(n * n * n);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();
        
        int x = x2 - x1;
        int y = y2 - y1;
        System.out.println(String.format("%d %d %d %d", x2-y, y2+x, x1-y, y1+x));
    }
}

Measured memory_bytes: 27020
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
bool a[5001][5001];
int main(){
  int i,j;
  int r,s,t,u,v,w,x[3000],y[3000],n;
  int mx;
  while(cin>>n&&n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      cin>>x[i]>>y[i];
      a[x[i]][y[i]]=1;
    }
    mx=0;
    for(i=0;i<n-1;i++){
      for(j=i+1;j<n;j++){
	v=x[i]-x[j];
	w=y[i]-y[j];
	if(((r=x[i]-w)>=0&&(s=y[i]+v)>=0&&(t=x[j]-w)>=0&&(u=y[j]+v)>=0&&r<=5000&&s<=5000&&t<=5000&&u<=5000&&a[r][s]&&a[t][u])||
	   ((r=x[i]+w)>=0&&(s=y[i]-v)>=0&&(t=x[j]+w)>=0&&(u=y[j]-v)>=0&&r<=5000&&s<=5000&&t<=5000&&u<=5000&&a[r][s]&&a[t][u]))
	  if(mx<v*v+w*w)
	    mx=v*v+w*w;
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
static const int MAX_N = 100000;

int N, T;
int A[MAX_N];
map<int, int> mpa;

int main(){
	cin >> N >> T;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		mpa[A[i]]++;
	}
	int max_benefit = 0;
	int min_a = A[0];
	for(int i = 1; i < N; i++){
		min_a = min(min_a, A[i - 1]);
		max_benefit = max(max_benefit, A[i] - min_a);
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(mpa[A[i] + max_benefit] > 0) ans++;
		mpa[A[i]]--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9984
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    ret = ''
    for i, c in enumerate(S):
        if i + 1 == K:
            ret += c.lower()
        else:
            ret += c
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

@njit('(i8,i8,i8[:])', cache=True)
def main(N, K, A):
    B = np.maximum(A, 0)
    Acum = np.zeros(len(A) + 1, np.int64)
    Bcum = np.zeros(len(A) + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    Bcum[1:] = np.cumsum(B)
    ret = -(10**18)
    for l in range(N - K + 1):
        r = l + K
        sum1 = Bcum[l]
        sum2 = Bcum[-1] - Bcum[r]
        sum3 = Acum[r] - Acum[l]
        x = sum1 + sum2 + max(sum3, 0)
        ret = max(ret, x)
    return ret

print(main(N, K, A))

Measured memory_bytes: 119600
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,ans;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=1;i*i<=n;++i){
		ans=i;
	}
	cout<<ans*ans;
	return cout<<endl,0;
}

Measured memory_bytes: 256
# %% constants
# ------------

# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))

    # handle IO and solve
    N, K = readnum()
    A = readnum()
    print_result.(solve(N, K, A))
end

print_result(r) = println(r ? "Yes" : "No")

@inbounds function solve(N, K, A)
    ret = zeros(Bool, N - K)
    for i in 1:(N-K)
        cur = A[i]
        next = A[K+i]
        ret[i] = next > cur
    end
    return ret
end

@static if @isdefined(Juno)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


Measured memory_bytes: 209356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());

            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}


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

const int N = 2e5 + 5;

vector<int> p[26];
bool vis[N];
int bit[N], num[26];

void add(int p, int v) {
  for (int i = p; i < N; i += i & -i) bit[i] += v;
}
int sum(int p) {
  int res = 0;
  for (int i = p; i > 0; i -= i & -i) res += bit[i];
  return res;
}

int main() {
  string s;
  cin >> s;
  int n = s.size(), cnt = 0;
  for (int i = 0; i < n; i++) {
    p[s[i] - 'a'].push_back(i + 1);
    num[s[i] - 'a']++;
  }
  int flag = 0;
  int z = -1;
  for (int i = 0; i < 26; i++) {
    if (p[i].size() % 2) flag++, z = i;
  }
  if (flag > 1) {
    return puts("-1"), 0;
  }
  for (int i = 1; i <= n; i++) add(i, 1);
  flag = 0;
  ll res = 0;
  for (int i = 1, cnt = 0; i <= n; i++) {
    int c = s[i - 1] - 'a';
    if (vis[i]) continue;
    num[c] -= 2;
    cnt++;
    int pos = p[c].back();
    vis[pos] = 1;
    p[c].pop_back();
    if (num[c] < 0) {
      flag = 1;
      continue;
    }
    if (flag) res++;
    int should = n - cnt + 1;
    int dif = sum(n) - sum(pos);
    res += dif;
    add(pos, -1);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = -1;
    ll sum = 0;
    REP(i,N){
        ll d, c;
        cin >> d >> c;
        sum += d * c;
        ans += c;
    }
    ans += (sum-1) / 9;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define ll	long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.141592653589793
 
int main() 
{	fastio;
	int testcases = 1;
	//cin>>testcases;
	while (testcases--) {
		int h1, m1, h2, m2, k;
		cin>>h1>>m1>>h2>>m2>>k;
		int ans = (h2-h1)*60 - m1 + m2 - k;
		cout<<ans;
		cout<<"\n";	
	}
    return 0; 
}


Measured memory_bytes: 3636
//http://drken1215.hatenablog.com/entry/2019/04/03/224800
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    int n; cin>>n;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    int sum = accumulate(all(a),0);
    bitset <4000003> dp;
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        dp |= (dp << a[i]);
    }
    
    long long res;
    for (res = (sum+1)/2; res < 4000003; ++res) {
        if (dp[res]) break;
    }
    cout << res << endl;
}


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

int main() {
    int N, ans;
    cin >> N; ans = 0;
    int V[N], C[N];
    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
n, x, y = map(int, input().split())
ans = [0] * (n - 1)

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        dist = min(abs(j - i), abs(x - i) + abs(y - j) + 1)
        ans[dist - 1] += 1

for v in ans:
    print(v)

Measured memory_bytes: 9324
N = int(input())

strs = []
dicts = {}
for i in range(N):
    s = input()
    if dicts.get(s) is not None:
        dicts[s] += 1
    else:
        dicts[s] = 1

dict_sorted = sorted(dicts.items(), key=lambda x:x[1], reverse=True)

i = 0
sts = []
for s in dict_sorted:
    if dicts[s[0]] == dicts[dict_sorted[0][0]]:
        sts.append(s[0])
    i = dicts[s[0]]

for s in sorted(sts):
    print(s)

Measured memory_bytes: 47324
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main(void)
{
    int A, P;
    cin >> A >> P;
    printf("%d\n", (A*3+P)/2);

    return 0;
}

Measured memory_bytes: 384