akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int solve(const vi& a,map<vi,int>& memo)
{
	if(a.size()==0)
		return 0;
	iter(memo) it=memo.find(a);
	if(it!=memo.end())
		return it->second;
	
	int di[]={0,1,1,1},dj[]={1,-1,0,1};
	int res=a.size();
	rep(i,5) rep(j,4){
		int p=i*4+j;
		if(p>=a.size())
			continue;
		rep(k,4){
			int ii=i+di[k],jj=j+dj[k],pp=ii*4+jj;
			if(ii<0 || 5<=ii || jj<0 || 4<=jj || pp>=a.size() || a[p]!=a[pp])
				continue;
			vi b;
			rep(l,a.size())
				if(l!=p && l!=pp)
					b.push_back(a[l]);
			res=min(res,solve(b,memo));
		}
	}
	return memo[a]=res;
}

int main()
{
	int n; cin>>n;
	while(n--){
		vi a(20);
		rep(i,20)
			cin>>a[i];
		map<vi,int> memo;
		cout<<solve(a,memo)<<endl;
	}
	
	return 0;
}

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


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;

	int n ,m ; 
	cin >> n >> m ; 
	string final(n , '#') ; 
	bool ans = true ; 
	for(int i =0 ; i< m ; ++i)
	{
		int u  ;
		char c ;
		cin >> u >> c ;
		--u ; 
		if(u <n && final[u] == '#')
		{
			final[u] = c;
				
		}
		if(u < n && final[u] != '#')
		{
   			if(final[u] != c)
   				ans= false ; 

		}
		
	}
	
	if(ans == false )
	{
		cout << -1  ; 
		return 0 ; 
	}

	if(n> 1 && final[0] == '0')
	{
		cout << -1 ; 
		return 0 ; 
	}
	if(n > 1 && final[0] == '#')
		final[0] = '1' ; 
	if(n ==1 && final[0] == '#')
		final[0] = '0' ; 
	for(int i = 1; i < n ; ++i)
	{
		if(final[i] == '#')
			final[i] = '0' ;  
	}
	cout << final;	
	

}


Measured memory_bytes: 3584
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
    
    // double input seems slow on CF
    void re(double& x) { string t; cin >> t; x = stod(t); } 
    void re(ld& x) { string t; cin >> t; x = stold(t); }
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) { re(first); re(rest...); }
    
    // pair
    template<class T1, class T2> istream& operator>>(istream& is, pair<T1,T2>& p) {
        is >> p.f >> p.s;
        return is;
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}';
        return os;
    }
    
    // vector
    template<class T> istream& operator>>(istream& is, vector<T>& a) {
        int sz; is >> sz; a.resize(sz);
        F0R(i,sz) is >> a[i];
        return is;
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        os << "{";
        F0R(i,sz(a)) {
            if (i) os << ", ";
            os << a[i];
        }
        os << "}";
        return os;
    }
}

using namespace io;

int n, co[2][MX];

int main() {
    setIO(); re(n);
    F0R(i,n) {
        int x; re(x);
        co[i&1][x] ++;
    }
    
    vpi v[2];
    F0R(i,2) F0R(j,MX) v[i].pb({co[i][j],j});
    sort(all(v[0])), sort(all(v[1]));
    reverse(all(v[0])), reverse(all(v[1]));
    
    int ret = 0;
    if (v[0][0].s != v[1][0].s) ret = v[0][0].f+v[1][0].f;
    else ret = max(v[0][1].f+v[1][0].f,v[0][0].f+v[1][1].f);
    
    cout << n-ret;
}
/* 
* (Actually read this pls)
    * Rlly bad errors: int overflow, array bounds
    * Less bad errors: special cases (n=1?), set tle
    * Common sense: do smth instead of nothing
*/

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



int main() {
    int N,K,Q;
    cin>>N>>K>>Q;
    vector<int> point(N);
    rep(i,Q){
        int a;
        cin>>a;
        --a;
        point.at(a)++;
    }
    rep(i,N){
        if(Q-point.at(i)<K){cout<<"Yes"<<endl;}
        else{cout<<"No"<<endl;}
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,min=1e6,tmp1,tmp2,sum1,sum2;
    cin >> n;
    for(int i=1;i<n;i++){
        int j = n-i;
        tmp1=i;
        sum1=0;
        sum2=0;
        while(tmp1>0){
            sum1+=tmp1%10;
            tmp1/=10;
        }
        while(j>0){
            sum2+=j%10;
            j/=10;
        }
        if(sum1+sum2<min)
            min = sum1+sum2;
    }
    cout << min << endl;
}


Measured memory_bytes: 256
import sys
n, k = map(int, input().split())
p = list(map(int, input().split()))
# 下の同値の場合を除外しないとrange(k,k)=[]となりfor文が回らない
if n == k:
    print((sum(p) + k) / 2)
    sys.exit(0)
saveSum = sum(p[0:k])
M = 0
for i in range(k, len(p)):
    saveSum = saveSum + p[i] - p[i - k]
    if saveSum > M:
        M = saveSum
print((k+M)/2)


Measured memory_bytes: 71792
a,b,c = map(int,input().split())
acnt = 0
bcnt = 0
ccnt = 0
cnt = 0
if a == b and a== c and a%2 == 0:
    print(-1)
    exit()
while a%2 == 0 and b%2 == 0 and c%2 == 0:
    cnt += 1
    acnt = (b+c)//2
    bcnt = (a+c)//2
    ccnt = (a+b)//2
    a = acnt
    b = bcnt 
    c = ccnt
print(cnt)


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> d;
    d.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> d[i];
    }
    vector<int> d_sum;
    d_sum.resize(N - 1);
    // d に関する部分和は、最後の要素一つのものから順に計算していく
    d_sum[0] = d[N - 1];
    for (int i = 1; i < N - 1; ++i) {
        d_sum[i] = d_sum[i - 1] + d[N - i - 1];
    }
    // d_sum = {
    //    d[N - 1]
    //    d[N - 1] + d[N - 2]
    //    ...
    //    d[N - 1] + d[N - 2] + ... + d[1]
    // }

    uint64_t ans = 0;
    for (int i = 0; i < N - 1; ++i) {
        ans += d[i] * d_sum[N - i - 2];
    }
    // ans =
    //    d[0] * (d[N - 1] + d[N - 2] + ... + d[1])
    //    + ...
    //    + d[N - 3] * (d[N - 1] + d[N - 2])
    //    + d[N - 2] * d[N - 1]
    // }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));
	
	int tmp = -1, count = 0;
	for(int i = 0; i < n; i++) {
		if(tmp == a[i]) {
			count++;
			continue;
		}
		
		if(count == n / 2) {
			printf("%d\n", a[i] - a[i - 1]);
			return 0;
		}
		tmp = a[i];
		count++;
	}
	printf("0\n");
	return 0;
}


Measured memory_bytes: 640
from collections import deque, defaultdict
import sys
sys.setrecursionlimit(2**20)
class LowLink:
    """
    与えられたグラフの関節点と橋を求める
    Attributes:
    size: グラフの頂点数
    pre: preorderでの訪問順
    low: ### 1. prenum[u]
        ### 2. GのBackEdge(u,v)が存在する場合は、prenum[v]
        ### 3. uの全ての子childに対してlowest[child]
    articulations<list>: 関節点のリスト
    bridges<list>: 橋のリスト

    """
    def __init__(self, v):
        self.size = len(v) + 1
        self.v = v
        self.pre = [None]*self.size
        self.low = [None]*self.size
        self.articulations = []
        self.bridges = []
        for x in range(self.size):
            if self.pre[x] is None:
                self.cnt = 0
                self.dfs(x, None)
    
    def dfs(self, x, prev):
        """
        DFSにより橋と関節点を求める
        x: 現在訪れているノード
        prev: ひとつ前のノード
        """
        self.pre[x] = self.low[x] = self.cnt # 初期化
        self.cnt += 1 # 
        is_articulation = False
        n = 0 # xから出ている子の個数
        for y in self.v[x]:
            if self.pre[y] is None: #yが未訪問なら
                n += 1 # xから出ている子の個数
                low_y = self.dfs(y, x) # 再帰呼び出し
                if low_y < self.low[x]:
                    # 最小値を更新できるなら
                    self.low[x] = low_y
                if self.pre[x] <= low_y:
                    if self.pre[x]: 
                        is_articulation = True
                    if self.pre[x] < low_y:
                        self.bridges.append(
                            (min(x,y), max(x,y))
                        )
            else:
                if y != prev and self.pre[y] < self.low[x]:
                    # yが以前訪れた物ではなくて、
                    # pre[y] < low[x]なら
                    self.low[x] = self.pre[y]
        
        if prev is None and n > 1:
            # prev is None == xが根 and
            # n > 1: 根xから子が2個以上出てるなら
            is_articulation = True
        
        if is_articulation:
            self.articulations.append(x)
        
        return self.low[x]

def solve():
    V, E = map(int, input().split())
    G = defaultdict(lambda: [])
    for _ in range(E):
        s, t= map(int, input().split())
        G[s].append(t)
        G[t].append(s)
    
    #initialize
    lowlink = LowLink(G)
    #bridges
    bridges = lowlink.bridges
    print(len(bridges))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 65624
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

void solve() {
	int k;
	cin>>k;
	
	string s[MAX];
	for(int i=1;i<=9;i++) {
		s[i] = s[i] + (char) (i + '0'); 
	}
	int i = 1, j=10;
	while(j<=k) {
		int last = s[i].length()-1;
		if(s[i][last] != '0') s[j++] = s[i] + (char) (s[i][last] - 1);
		s[j++] = s[i] + s[i][last]; 
		if(s[i][last] != '9') s[j++] = s[i] + (char) (s[i][last] + 1);
		i++;
	}
	cout<<s[k]<<endl;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


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

int main(){
    int n,x;
    while(true){
    cin>>n>>x;
    int ans=0;
    if(n==0 && x==0)break;
    for(int i=1;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n+1;k++){
                int sum=i+j+k;
                if(sum==x)ans+=1;
            }
        }
    }
    cout<<ans<<endl;
    }
    return 0;
}


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

namespace AtCoder {
	class Program {
		static void Main(string[] args) {
			string s1 = Console.ReadLine();
			string s2 = Console.ReadLine();
			if (s1.Length > s2.Length) {
				Console.WriteLine("GREATER");
			} else if (s1.Length < s2.Length) {
				Console.WriteLine("LESS");
			} else {
				var c2 = s1.CompareTo(s2);
				if (c2 > 0) {
					Console.WriteLine("GREATER");
				} else if (c2 < 0) {
					Console.WriteLine("LESS");
				} else {
					Console.WriteLine("EQUAL");
				}
			}
		}
	}
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
  int N; cin >>N;
  string s; cin>>s; 
  int a = 0;
  REP(i,N){
    if( s[i]=='('){ ++a;}
    else if( a>0 ){ --a;}
  }
  int b = 0;
  REPR(i,N-1){
    if( s[i]==')'){ ++b;}
    else if( b>0 ){ --b;}
  }
  cout << string(b,'(') << s << string(a,')') <<"\n";
}





Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = parseInt(readline())
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
    if n == 1
      print(a[1]+b[1])
    else
	  	aa = Array{Int}(n)
	  	aa[1] = a[1]
		bb = Array{Int}(n)
		bb[n] = b[n]
		sum = Array{Int}(n)
		for i in 2:n
			aa[i] = aa[i-1]+a[i]
			bb[n+1-i] = bb[n+2-i] + b[n+1-i]
		end
		for i in 1:n
			sum[i] = aa[i]+bb[i]
		end
		print(maximum(sum))
	end
end

main()

Measured memory_bytes: 111612
import numpy

N, D = map(int, input().split())
points = []
for i in range(N):
	temp = numpy.array([int(x) for x in input().split()])
	points.append(temp)

count = 0
for i in range(N-1):
	for j in range(1, N):
		d = numpy.sqrt(numpy.sum((points[i] - points[j])**2))
		if(d.is_integer() and i<j):
			count+=1

print(count)

Measured memory_bytes: 12484
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
int main(){
	int n;
	cin>>n;
	string s;cin>>s;
	int out=0;
	int x=0;
	rep(i,n){
		if(s[i]=='I')x++;
		else x--;
		out=max(out,x);
	}
	cout<<out<<endl;
}
















Measured memory_bytes: 384
while 1:
    h,w=map(int, input().split())
    key=0
    a="\n \n"
    if h==0 and w==0:
        break
    if w%2==1:
        for i in range(h):
            for j in range(w):
                if key==0 or key%2==0:
                    key=key+1
                    print("#", end="")
                else:
                    key=key+1
                    print(".", end="")
            print()
        print()
    else:
         for i in range(h):
            for j in range(w):
                if i==0 or i%2==0:
                    if j==0 or j%2==0:
                        print("#", end="")
                    else:
                        print(".", end="")
                else:
                    if j==1 or j%2==1:
                        print("#", end="")
                    else:
                        print(".",end="")
            print()    
         print()


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

using namespace std;

int main() {
	string a, b;
	cin>>a>>b;
	int m = a.length(), n = b.length();
	
	vector<vector<int>> dp(m+1, vector<int>(n+1,0));
	
	for(int  i = 1;i<=m;i++) {
		for(int j = 1; j <=n; j++) {
			if(a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
		}	
	}
	/*for(auto d : dp) {
		for(auto i : d) cout<<i<<" ";
		cout<<'\n';
	}
	*/
	//return 0;
	int i = m, j= n;
	string str = "";
	while( i > 0 && j > 0) {
		if(a[i-1] == b[j-1]) {
			str = a[i-1] + str;
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1]) {
			i--;
		}
		else{
			j--;
		}
	}
	cout<<str<<'\n';
	//cout<<0;
	return 0;

}


Measured memory_bytes: 35584
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    map<int, int> mp;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]] = i;
    }
    int h = 1;
    for(P x:mp) {
        a[x.second] = h++;
    }

    vi bit(n+1);
    auto add = [&](int i, int x) {
        while(i <= n) {
            bit[i] += x;
            i += i&-i;
        }
    };
    auto sum = [&](int i) {
        int res = 0;
        while(i) {
            res += bit[i];
            i &= i-1;
        }
        return res;
    };

    ll ans = 0;
    rep(i, n) {
        ans += i - sum(a[i]);
        add(a[i], 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 13860
#include<iostream>
#include <string>
using namespace std;
 
int main() {
	long long n, a, b;
	long long ta[100000];
	long long hirou = 0;
	string str;
	cin >> n >> a >> b;
	for (long long i = 0; i < n; i++) {
		cin >> ta[i];
	}
	for (long long i = 0; i < n - 1; i++) {
		if ((ta[i + 1] - ta[i])*a < b) {
			hirou = hirou + (ta[i + 1] - ta[i])*a;
		}
		else
		{
			hirou = hirou + b;
		}
	}
	cout << hirou << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, X, Y;
int A[2000][2000];
int RES[2001];
int main(void){
    cin >> N >> X >> Y;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++) A[i][j] = A[i][j-1] + 1;
    A[X-1][Y-1] = 1;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++) A[i][j] = min(A[i][j], A[i][j-1] + 1);
        for(int j=N-2;j>=i+1;j--) A[i][j] = min(A[i][j], A[i][j+1] + 1);
    }

    for(int j=0;j<N;j++){
        for(int i=1;i<N;i++) A[i][j] = min(A[i][j], A[i-1][j] + 1);
        for(int i=N-2;i>=0;i--) A[i][j] = min(A[i][j], A[i+1][j] + 1);
    }

    REP(i,N) REP(j,N) RES[A[i][j]] += 1;

    for(int i=1;i<N;i++) cout << RES[i] << endl;

    return 0;
}



Measured memory_bytes: 15872
#include <cmath>
#include <iostream>

const int MAX_N = 50;

int N, M;
long long int a[MAX_N][2], b[MAX_N][2];

int main(){

  std::cin >> N >> M;
  for(int i = 0; i < N;i++)
    std::cin >> a[i][0] >> a[i][1];

  for(int i = 0; i < M; i++)
    std::cin >> b[i][0] >> b[i][1];

  for(int i = 0; i < N; i++){
    int stop = 0, dis_min = 300000000;
    for(int j = 0; j < M; j++){
      int dis = std::abs(a[i][0] - b[j][0])
                + std::abs(a[i][1] -b[j][1]);

      if( dis < dis_min){
        dis_min = dis;
        stop = j;
      }

    }

    std::cout << stop + 1 << '\n';

  }

  return 0;

}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
d,t,s = readInts()
print('Yes' if d/s <= t else 'No')


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

int main(){
  int N;
  cin >> N;
  vector<int> num(N);
  long long C=0;
  for(int i=0;i<N;i++)
    cin >> num.at(i);
  priority_queue<long long , vector<long long>, greater<long long>> Q;
  for(int X=-100;X<101;X++){
    for(int j=0;j<N;j++)
      C+=(X-num.at(j))*(X-num.at(j));
    Q.push(C);
    C=0;
  }
  cout << Q.top() << endl;
}
  


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
before=sum(A)
for i in range(len(B)):
    while B[i]>0:
        if A[i]>=B[i]:
            A[i]-=B[i]
            B[i]=0
        else:
            B[i]-=A[i]
            A[i]=0
            if A[i+1]>=B[i]:
                A[i+1]-=B[i]
            else:
                A[i+1]=0
            B[i]=0
after=sum(A)
print(before-after)


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

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

      BufferedReader br = new BufferedReader(
        new InputStreamReader(System.in));
      String[] input = br.readLine().split(" ");
      String a = input[0];
      String b = input[1];

      if(a.equals("H")){
        System.out.println(b);
      }else if(b.equals("H")){
        System.out.println("D");
      }else{
        System.out.println("H");
      }
      br.close();
  }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((c >= a and c <= b) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, long long R){
  if(N >= 10){
    cout << R << endl;
  }else{
    cout << R+(100*(10-N)) << endl;
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long R;
    scanf("%lld",&R);
    solve(N, R);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
ll power(ll a,ll b)
{ll result=1;
while(b>0)
{if(b%2==1)
 result*=a;
 a*=a;
 b/=2;
}
return result;
}
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int n,x,t;
 cin>>n>>x>>t;
 if(n%x==0)
 cout<<t*(n/x);
 else
  cout<<t*(n/x)+t;
}


Measured memory_bytes: 3656
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL a, b, k;

int main(){
    cin >> a >> b >> k;
    REP(t, k){

        if(t%2 == 0){
            a /= 2;
            b += a;
        }else{
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b << endl;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a-b >= c) cout << 0 << endl;
    else  cout << c - a + b << endl;
}

Measured memory_bytes: 3548
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 3e3 + 33, P = 1e9 + 7, div2 = (P + 1) / 2;

int n, m, x, y, a[N], b[N], dp[N][N], tmp[N][N], ans, pw2 = 1;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", a + i), b[i] = a[i];
	std::sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i++) a[i] = std::lower_bound(b + 1, b + n + 1, a[i]) - b;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) dp[i][j] = a[i] > a[j];
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		for (int j = 1, u, v; j <= n; j++)
			if (j != x && j != y) {
				u = 1ll * (dp[j][x] + dp[j][y]) * div2 % P;
				v = 1ll * (dp[y][j] + dp[x][j]) * div2 % P;
				dp[j][x] = u, dp[j][y] = u;
				dp[x][j] = v, dp[y][j] = v;
			}
		int u = 1ll * (dp[x][y] + dp[y][x]) * div2 % P;
		dp[x][y] = dp[y][x] = u;
		pw2 = pw2 * 2 % P;
	}
	for (int i = 1; i < n; i++)
		for (int j = i + 1; j <= n; j++) ans = (ans + dp[i][j]) % P;
	printf("%lld", 1ll * ans * pw2 % P);
}

Measured memory_bytes: 36992
#include<iostream>
#include<iterator>
#include<string>
#include<algorithm>
#include<functional>
#include<cctype>
using namespace std;
struct IsAlpha:unary_function<char, bool>
{bool operator()(char c)const{return isalpha(c)||c=='\'';}};
int main()
{
	string s;
	getline(cin, s);
	string::iterator i1=s.begin(),i2;
	ostream_iterator<char>o(cout);
	int f=0;
	for(;;)
	{
		i2 = find_if(i1,s.end(),not1(IsAlpha()));
		if(i2==s.end()){*o='\n';break;}
		if(i2-i1>2&&i2-i1<7)
			(f++?(*o=' ',f):f),
			copy(i1,i2,o);
		i1=i2+1;
	}
	return 0;
}

Measured memory_bytes: 0
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (0 ++^ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv
let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv
let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let between n x m = n <= x && x < m


(* ===== MAIN ===== *)

let x, y = scan "%d %d" (fun x y -> x, y)

let check i = y = i*2 + (x-i)*4

let rec loop i =
  if i > x then Printf.printf "No\n"
  else if check i then Printf.printf "Yes\n"
  else loop (i+1)

let () = loop 0


Measured memory_bytes: 5324
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
    	Scanner file = new Scanner(System.in);
      	int k = file.nextInt();
      	file.close();
      	int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      	System.out.println(a[k-1]);
      //	return 0;
    }
}


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


using namespace std;


int main(){
    int N,D;
    cin >> N >> D;
    int ans = 0;

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

    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            double sum = 0;
            for(int k = 0; k < D; k++){
                sum += pow(abs(x[i][k]-x[j][k]),2);        
            }
            
            sum = sqrt(sum);
            if(sum - (int)sum  == 0.0){
                ans++;
            }
            
        }
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}

void solve() {	
	int n, k, s;
	cin >> n >> k >> s;
	if (s <= (int) 1e5) {
		for (int i = 0; i < k; ++i) {
			cout << s << ' ';
		}
		for (int i = 0; i < n - k; ++i) {
			cout << (int) 1e9 << ' ';
		}
		return;
	}
	else {
		for (int i = 0; i < k; ++i) {
			cout << s << ' ';
		}
		for (int i = 0; i < n - k; ++i) {
			cout << 1 << ' ';
		}
		return;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
int a[maxn];
int main(){
	int  k;
	scanf("%d %d", &n, &k);
	bool ok = false;
	for(int i = 0; i < n; i++){
		scanf("%d", a+i);
	}
	vector<int> ans;
	int lf, rg;
	for(int i = 0; i < n-1; i++){
		if(a[i] + a[i+1] >= k){
			ok = true;
			lf = i;
			rg = i+1;
			ans.push_back(i);
			break;
		}
	}
	if(!ok)printf("Impossible\n");
	else{
		while(lf != 0){
			ans.push_back(lf-1);
			lf--;
		}
		while(rg < n-1){
			ans.push_back(rg);
			rg++;
		}
		printf("Possible\n");
		for(int i = (int)ans.size()-1; i >=0; i--)printf("%d\n",1 +  ans[i]);
	}
}

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

using namespace std;

int main(){
  string S; cin>>S;
  int N=S.size();

  for(int i=0;i<N;i++){
    if(S[i]!=S[N-1-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> ab(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        ab[i] = {b, a};
    }
    sort(ab.begin(), ab.end());
    int r = ab[0].first;
    int ans = 1;
    for ( int i = 1; i < m; ++i ) {
//        cout << "r: " << r << "ab[i].second:  " << ab[i].second << endl;
        if ( ab[i].second >= r ) {
            ++ans;
            r = ab[i].first;
        }
//        cout << "test" << " " << i << " " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 1000005
ll arr[MAX+2];
bool check()
{
    for(int i=2;i<MAX;i++){
        if(arr[i]>1) return false;
    }
    for(int i=2;i<MAX;i++)
    {
        ll cnt=0;
        for(int j=i;j<MAX;j+=i){
            if(arr[j]==1) cnt++;
        }
        if(cnt>1) return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    ll gcd=0;
    for(int i=1;i<=n;i++) {
        ll a; cin>>a;
        gcd=__gcd(gcd,a);
        arr[a]++;
    }
    if(check())
    {
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    if(gcd==1){
        cout<<"setwise coprime"<<endl;
        return 0;
    }
    cout<<"not coprime"<<endl;
    
    
}

Measured memory_bytes: 11424
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  vector <ll> a;
  REP(i,n){
    ll b;
    cin >> b;
    a.pb(b);
  }
  ll sum = 0;
  //ll sum2 = a[0];
  ll num = 0;
  int f;
  f = 1;
  for(int i = 0;i < n;i++){
    if(f == 1){
      sum += a[i];
      if(sum > 0){
	ll u = -1-sum;
	sum += u;
	num += abs(u);
      }
      else if(sum == 0){
	sum--;
	num++;
      }
      f = 0;
    }
    else{
      
      sum += a[i];
      if(sum < 0){
	ll u = 1-sum;
	sum += u;
	num += abs(u);
      }
      else if(sum == 0){
	sum++;
	num++;
      }
      f = 1;
    }
    //cout << sum << endl;
  }

  f = 0;
  ll sum2 = 0;
  ll num2 = 0;
  for(int i = 0;i < n;i++){
    if(f == 1){
      sum2 += a[i];
      if(sum2 > 0){
	ll u = -1-sum2;
	sum2 += u;
	num2 += abs(u);
      }
      else if(sum2 == 0){
	sum2--;
	num2++;
      }
      f = 0;
    }
    else{
      
      sum2 += a[i];
      if(sum2 < 0){
	ll u = 1-sum2;
	sum2 += u;
	num2 += abs(u);
      }
      else if(sum2 == 0){
	sum2++;
	num2++;
      }
      f = 1;
    }
    //cout << sum << endl;
  }


  cout << min(num,num2) << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, d;
int t;
int main()
{
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		if (d < b)
		{
			printf("No\n");
			continue;
		}
		ll belowc = a;
		if (a > c)
		{
			ll diff = a-c;
			diff/=b;
			belowc -= diff*b;
			if (belowc > c) belowc-=b;
			assert(belowc <= c);
		}
		else belowc -= b;
		if (belowc < 0)
		{
			printf("No\n");
			continue;
		}
		if (d == b)
		{
			printf("Yes\n");
			continue;
		}
		belowc += d;
		// Only case, d > b
		// i.e. gain more than you lose
		ll delta = d-b;
		delta -= (delta/b)*b;
		if (delta == 0) 
		{
			printf("Yes\n");
			continue;
		}
		assert(delta >= 0);
		// 'delta' is how much is gained each time
		ll delta2 = delta-b;
	//	printf("delta delta2 %lld %lld\n", delta2, delta);
		// we go down delta2, or up by delta
		bool fails = 0;
		for (int j = 0; j < 10000; j++)
		{
			ll addam = c-belowc;
			addam /= delta;
			belowc += delta*addam;
			if (belowc <= c) belowc += delta;
			addam = belowc-c-1;
			addam/=-delta2;
			assert(belowc > c);
			belowc += addam * delta2;
			if (belowc + delta2 > c) belowc += delta2;
			assert(belowc > c);
			if (belowc - b < 0) { fails = 1; break; }
			belowc += delta2;
			assert(belowc <= c);
		}
		if (fails) 
		{
			printf("No\n"); 
			continue; 
		}
		else printf("Yes\n");
	}
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define endl '\n'
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
signed main(){
    int T1,T2,A1,A2,B1,B2;
    cin>>T1>>T2>>A1>>A2>>B1>>B2;
    if(A1*T1+A2*T2 == B1*T1+B2*T2) { puts("infinity");return 0; }
    A1*=T1; A2*=T2; B1*=T1; B2*=T2;
    if(A1+A2>B1+B2) { swap(A1,B1); swap(A2,B2); }
    if(A1>B1){
        int r = (A1-B1)/(B1+B2-A1-A2);
        int res = 2*r;
        if((A1-B1)%(B1+B2-A1-A2)) res++;
        cout<<res<<endl;
    }else puts("0");
    return 0;
}


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

int main(){
  int n,k,count=0,ans=0;
  cin >> n >> k;
  string s;
  cin >> s;
  r(0,i,n-1){
    if(s.at(i)!=s.at(i+1))count++;
  }
  ans=n-count-1;
  while(k--){
    if(count>=2){
      ans+=2; count-=2;
    }
    else if(count){
      ans++; count--;
    }
    else break;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, p, pt, sum = 1;
  cin >> n;
  cin >> pt;
  for (int i = 1; i < n; i++) {
    cin >> p;
    if (pt > p) {
      sum += 1;
      pt = p;
    }
  }
  cout << sum ;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
q = int(input())

s = [0]
t = [0]
v = 0
for c in S:
	v = (v + (ord(c) - ord("A") + 1)) % 3
	s.append(v)
v = 0
for c in T:
	v = (v + (ord(c) - ord("A") + 1)) % 3
	t.append(v)
for i in range(q):
	a,b,c,d = map(int, input().split())
	x = (3 + s[b] - s[a-1]) % 3
	y = (3 + t[d] - t[c-1]) % 3
	if x == y:
		print("YES")
	else:
		print("NO")


Measured memory_bytes: 5356
N, Q = map(int, input().split())
S = str(input())
TD = [list(map(str, input().split())) for i in range(Q)]


def disappear(index, place):
    if index == -1:
        return (False, False)
    else:
        left = False
        right = False
        for t, d in TD:
            cur_chara = place[index]
            if t == cur_chara:
                if d == 'R':
                    index += 1
                else:
                    index -= 1
                if index < 0:
                    left = True
                    break
                elif index > N-1:
                    right = True
                    break
        return (left, right)


def binarySearch(place, direction):
    """
    :param direction; left, right
    :return: 消失する位置
    """
    start, end = -1, N
    if direction == 'left':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[0]:
                start = t
            else:
                end = t
        return start
    elif direction == 'right':
        while end - start > 1:
            t = start + (end - start) // 2
            if disappear(t, place)[1]:
                end = t
            else:
                start = t
        return start


left = binarySearch(S, direction='left')
right = binarySearch(S, direction='right')
print(right - left)

Measured memory_bytes: 41264
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRILF(v, n) printf("%."#n"lf\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A& a, const B& b) { a = max(a, (A)b); };

ldb inf = 1e18;
ldb eps = 1e-18;
ldb distance(ldb x1, ldb y1, ldb x2, ldb y2, ldb r1, ldb r2) {
	ldb dx = x1 - x2;
	ldb dy = y1 - y2;
	ldb d = sqrtl(dx * dx + dy * dy);
	return max(d - r1 - r2, 0.0L);
}

int main() {
	ldb xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	ll N; cin >> N;
	vector<ldb> X(N), Y(N), R(N);
	REP(i, 0, N) cin >> X[i] >> Y[i] >> R[i];
	X.push_back(xs); Y.push_back(ys); R.push_back(0);
	X.push_back(xt); Y.push_back(yt); R.push_back(0);
	N += 2;
	vector<vector<ldb>> dist(N);
	REP(i, 0, N) {
		dist[i].resize(N);
		REP(j, 0, N)dist[i][j] = distance(X[i], Y[i], X[j], Y[j], R[i], R[j]);
	}
	vector<ldb> dmin(N);
	vector<bool> done(N);
	REP(i, 0, N) {
		dmin[i] = inf;
		done[i] = false;
	}
	dmin[N - 2] = 0;
	auto cmp = [](pair<int, ldb> a, pair<int, ldb> b) {return a.second > b.second + eps; };
	priority_queue<pair<int, ldb>, vector<pair<int, ldb>>, decltype(cmp)> q(cmp);
	q.push({ N - 2,0 });
	while (!q.empty()) {
		int ind = q.top().first;
		q.pop();

		if (done[ind])continue;

		done[ind] = true;
		REP(i, 0, N) {
			if (i == ind)continue;
			if (dmin[i] > dmin[ind] + dist[ind][i] + eps) {
				dmin[i] = dmin[ind] + dist[ind][i];
				q.push({ i, dmin[i] });
			}
		}
	}
	ldb ans = dmin[N - 1];
	PRIF((double)ans, 11);
	return 0;
}

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

/* constant */

#define MAX_R	(50000)
#define MAX_C	(50000)
#define MAX_Q	(50000)

/* typedef */

typedef struct _od_t {
  int a, b, o;
} od_t;

/* global variables */

static char rows[MAX_R], cols[MAX_C];
static od_t orders[MAX_Q];

/* main */

int main(int argc, char **argv) {
  int ai, bi, c, i, j, k, oi, q, r, tf;
  long count;
  od_t *odi;

  for (;;) {
    scanf("%d %d %d", &r, &c, &q);
    if ((r | c | q) == 0) break;

    bzero(rows, sizeof(rows));
    bzero(cols, sizeof(cols));

    for (i = 0; i < q; i++)
      scanf("%d %d %d", &(orders[i].a), &(orders[i].b), &(orders[i].o));

    count = 0;

    for (i = q - 1; i >= 0; i--) {
      odi = &(orders[i]);

      if (odi->a) {
	if (! rows[odi->b]) {
	  rows[odi->b] = 1;
	  if (odi->o) count += r;
	  c--;
	}
      }
      else {
	if (! cols[odi->b]) {
	  cols[odi->b] = 1;
	  if (odi->o) count += c;
	  r--;
	}
      }
    }

    printf("%ld\n", count);
  }

  return 0;
}

Measured memory_bytes: 1292
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

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

    #[行先, 距離]
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        l,r,d = map(int, input().split())
        adj[l-1].append([r-1, d])
        adj[r-1].append([l-1, -d])

    x = [inf]*n

    def dfs(v):
        if x[v]==inf:
            x[v] = 0
        d = deque([v])
        while d:
            v  = d.popleft()
            for nv, cost in adj[v]:
                if x[nv] == inf:
                    x[nv] = x[v] + cost
                    d.append(nv)
                else:
                    if x[nv] - x[v] != cost:
                        return False
        return True


    for v in range(n):
        if not dfs(v):
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()




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


int main(){
int K,N;
long long max;
int a[200000],b[200001];
cin >> K >>N;
for(int i=0;i<N;i++){cin >> a[i];}
b[0]=a[0]+K-a[N-1];
max=b[0];
for(int j=1;j<N;j++){
  b[j]=a[j]-a[j-1];
  if(b[j]>max){
    max=b[j];
  }
}
cout << K-max << endl;
return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
 
using namespace std;
 
#define lli long long
lli M=1e9;
 
#define MAXN  10000001 
 
int main()
{
    lli q=1;
    // cin>>q;
    time_t start, end;
    time(&start);
    for(lli tc=1;tc<=q;tc++)
    {
        char c;
        cin>>c;
        if(c<='Z'&&c>='A')
        cout<<'A';
        else if(c<='z'&&c>='a')
        cout<<'a';
        cout<<endl;
    }
    
    time(&end);
    // cout<<fixed<<double(end - start)<<setprecision(10)<<endl;
    return 0;
}

Measured memory_bytes: 3628
from sys import stdin
import collections
def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = collections.Counter(D)
    if(hash[0] != 1 or D[0] != 0):
        print(0)
        return
    count = hash[0]
    for i in range(1, max(D)+1):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 62004