akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

vll pr;
set<ll> pri;

ll eratosthenes(ll x){
    vbo isprime(x+1,true);
    isprime[0]=false;
    isprime[1]=false;
    ll p=0;
    for(ll i=2;i<=x;i++){
        if(isprime[i]){
            p++;
            pr.push_back(i);
            pri.insert(i);
            for(ll j=2*i;j<=x;j+=i)isprime[j]=false;
        }
    }
    return p;
}

vbo prime(1e6+10,false);

bool factorization(ll x){
    for(int i=0;pr[i]*pr[i]<=x;i++){
        if(x%pr[i]==0){
            if(prime[pr[i]])return false;
            prime[pr[i]]=true;
            while(x%pr[i]==0)x/=pr[i];
        }
    }
    if(x!=1){
        if(prime[x])return false;
        prime[x]=true;
    }
    return true;
}

int main(){
    eratosthenes(1e6+10);
    int n;cin>>n;
    ll p=(ll)0;
    vll a(n);
    rep(i,n){
        cin>>a[i];
        p=__gcd(p,a[i]);
    }
    if(p!=1)cout<<"not coprime"<<endl;
    else{
        rep(i,n){
            if(!factorization(a[i])){
                cout<<"setwise coprime"<<endl;
                return 0;
            }
        }
        cout<<"pairwise coprime"<<endl;
    }
    //cout<<pr.size()<<endl;
}

Measured memory_bytes: 15624
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    int at = 0;
    int top = 0;
    int ans = 0;
    if(a.equals("H")) {
      at = 1;
    } else {
      at = -1;
    }
    if(b.equals("H")) {
      top = 1;
    } else {
      top = -1;
    }
    ans = at * top;
    String s = "H";
    if(ans == -1) s = "D";
    System.out.println(s);
  }
}

Measured memory_bytes: 20948
N, M = gets.split.map(&:to_i)

current = []
point = []

N.times do
  current << gets.split.map(&:to_i)
end

M.times do
  point << gets.split.map(&:to_i)
end


N.times do |i|
  c = current[i]
  data = []
  M.times do |j|
    cp = point[j]
    data << (c[0] - cp[0]).abs + (c[1] - cp[1]).abs
  end

  p data.index(data.min) + 1
end


Measured memory_bytes: 1788
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll h(n); REP(i, n) cin >> h[i];
    ll ans=0, tmp=0;
    rep(i, 1, n) {
        if (h[i-1] >= h[i]) tmp++;
        else {
            chmax(ans, tmp);
            tmp=0;
        }
    }
    chmax(ans, tmp);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a, b, c, d, x, g, l, m, n, o, y, z;
    cin>>a>>b>>c>>d;
    y = c;
    z = d;
    while(d!=0)
        {
            x = d;
            d = c%d;
            c = x;
        }
        g = c;
    l = y * z / g;
    if(a % y == 0)
    {
		m = b/y - a/y +1;
	}
	else
    {
		m = b/y - a/y;
	}
	if(a % z == 0)
    {
		n = b/z - a/z + 1;
	}
	else
    {
		n = b/z - a/z;
	}
	if( a % l == 0)
	{
		o = b/l - a/l +1;
	}
	else
    {
		o = b/l - a/l;
	}
	cout<<b-a+1-m-n+o<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		//compareTo(str) ?????????????????????str ??¨???????????????????????????????????§????????????????????????
		//str ??????????????§?????????????????????????????????????????? 0???????°???????????????£????????????????????????

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int taro = 0;
		int hana = 0;

		for(int i = 0; i < n; i++){
			String str1 = sc.next();
			String str2 = sc.next();;
			if (str1.compareToIgnoreCase(str2) == 0){
				taro += 1;
				hana += 1;
			}else if(str1.compareToIgnoreCase(str2) < 0){
				hana += 3;
			}else{
				taro += 3;
			}
		}
		System.out.println(taro + " " + hana);
		sc.close();
	}
}

Measured memory_bytes: 29820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define up(i,j,n) for( int i=j;i<=n;i++)
#define down(i,j,n) for( int i=j;i>=n;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define FILE "dealing"
#define ull unsigned int
int read(){
	int x=0,ch=getchar(),f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}

template<class T> bool cmin(T& a,T b){return a>b?a=b,true:false;}
template<class T> bool cmax(T& a,T b){return a<b?a=b,true:false;}
template<class T> T squ(T a){return a*a;}
const int maxn=305000,inf=1000000000,limit=100000,mod=1e9+7;
int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
int sub(int a,int b){return (a-=b)<   0?a+mod:a;}
int mul(int a,int b){return 1LL*a*b%mod;}

int n,m,a[maxn];
ll ans,val[maxn];
int l[maxn],r[maxn];
vector<int> E[maxn],V[maxn],L[maxn],R[maxn];
int main(){
	//freopen(FILE".in","r",stdin);freopen(FILE".out","w",stdout);
	n=read(),m=read();
	up(i,1,n)a[i]=read();
	up(i,2,n)l[i-1]=a[i-1],r[i-1]=a[i];
	ll ans=0,sum=0;
	up(i,1,n-1){
		if(l[i]<r[i])E[l[i]].pb(i),V[r[i]].pb(i);
		else {
			L[r[i]].pb(i),R[l[i]].pb(i),ans+=m+1-l[i];sum++;
		}
	}
	ll Max=-1e15,p=0;
	up(i,1,m){
		//printf("%lld %lld\n",ans,sum);
		cmax(Max,ans-sum);
		for(int j=0;j<E[i].size();j++){
			int x=E[i][j];
			sum++;
		}
		for(int j=0;j<V[i].size();j++){
			int x=V[i][j];
			ans-=r[x]-l[x];
			sum--;
		}
		for(int j=0;j<L[i].size();j++){
			int x=L[i][j];
			ans-=m+1-l[x]+r[x]-1;
			sum--;
		}
		for(int j=0;j<R[i].size();j++){
			int x=R[i][j];
			sum++;
		}
		ans+=sum;
	}
	up(i,2,n)Max-=(a[i]-a[i-1]+m)%m;
	Max=-Max;
	cout<<Max<<endl;
	return 0;
}





Measured memory_bytes: 36096
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

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

    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    long long A,B,C,K;
    cin>>A>>B>>C>>K;
    if(K <= A) cout<<K;
    else if (K-A <= B) cout<<A;
    else cout<<A - (K-A-B);
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        int check=0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='R' && i%2!=0){
                check++;
                break;
            }else if(s.charAt(i)=='L' && i%2==0){
                check++;
                break;
            }
        }
        if(check==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35788
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#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 mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll x; cin >> x;
    ll n = 360;
    while(n % x > 0){
        n += 360;
    }
    prt(n/x);
}






Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N;
    cin >> N;
    if(N%2==1) {
        cout << 0 << '\n';
        return 0;
    }

    ll ans = 0;
    for(ll i=10;i<(ll)1e18+7;i*=5){
        ans+=(N/i);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3500
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll a[200001],pos[200001];
	set<ll> st,mst;
	scan(N);
	rep(i,N){
		scan(a[i]);
		a[i]--;
		pos[a[i]]=i;
	}
	ll ans=0;
	rep(k,N){
		auto itr=st.lower_bound(pos[k]);
		ll migi,hidari;
		if(itr!=st.end()){
			migi=(*itr)-pos[k]-1;
		}
		else{
			migi=N-pos[k]-1;
		}
		auto mitr=mst.lower_bound(-pos[k]);
		if(mitr!=mst.end()){
			hidari=(*mitr)+pos[k]-1;
		}
		else{
			hidari=pos[k];
		}
		ans+=(k+1)*(hidari+1)*(migi+1);
		st.insert(pos[k]);
		mst.insert(-pos[k]);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 22144
import java.util.Arrays;
import java.util.Scanner;

class A implements Comparable<A>{
	int a;
	int b;
	public A(int a, int b) {
		this.a = a;
		this.b = b;
	}
	@Override
	public int compareTo(A o) {
		if(this.a < o.a) {
			return -1;
		}else if(this.a > o.a) {
			return 1;
		}else {
			return 0;			
		}
	}
	
}


public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		long k = stdIn.nextLong();
		A []c = new A[n];
		
		long cnt = 0;
		for(int i = 0; i < n; i++) {
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			c[i] = new A(a,b);
			
			}
			
		Arrays.sort(c);
		
		for(int i = 0; i < n; i++) {
			
			cnt += c[i].b;
			if(cnt >= k) {
				System.out.println(c[i].a);
				return;
			}
			
			
		
		
		
			
		}
		
		
	}

}


Measured memory_bytes: 87296
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
     
    int main() {
    	#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
     
        float c;
        int r;

        cin>>r;

        c = float(3.14159 * 2 * r);
        cout<<c;
   
        return 0;
    }

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

int main(){
    int N; cin >> N;
    int x = 1000;
    int c = 0;
    while(1){
        c++;
        if(c*x >= N){
            cout << c*x-N << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long M = in.nextLong();
		if (N == 1 && M == 1) {
			System.out.println(1);
		} else if (N == 1 || M == 1) {
			System.out.println(N * M - 2);
		} else {
			System.out.println((N * (M - 2)) - (M - 2) * 2);
		}
		in.close();
	}
}


Measured memory_bytes: 23764
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

"""
if len(set(a)) == len(a):
    print("YES")
else:
    print("NO")
"""

flag = True
a.sort()
for i in range(n - 1):
    if a[i] == a[i + 1]:
        flag = False
if flag:
    print("YES")
else:
    print("NO")


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0;i<H;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<W+2;i++){
    cout << '#';
  }
  cout << endl;
  for(int i=0;i<H;i++){
    cout << '#' << A.at(i) << '#' << endl;
  }
  for(int i=0;i<W+2;i++){
    cout << '#';
  }
}


Measured memory_bytes: 256
/*
 * zyrch - Rupanshu Yadav
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

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

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

#define forn(i,a,b) for (int i = (a); i < ll(b); ++i)
#define fo(i,a) forn(i,0,ll(a))
#define rforn(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ro(i,a) rforn(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
ll mod = 1000000007;
inline int fast_expo(int base,int power,int modulo=mod){
    base%=modulo;
    if (base<0) base+=modulo;
    ll x=base,cnt=power,ans=1;
    while(cnt){
        if (cnt&1) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1;
    }
    return ans;
}

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int INF = (int)1e9;
//=========================CODE STARTS HERE=============================//

int main() {

	fast_cin();

	ll n;
	cin >> n;
	
	vl arr(n);
	
	fo(i, n) cin >> arr[i];
	
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	
	forn(i, 2, n) {
		if (dp[i - 1] + abs(arr[i - 1] - arr[i]) < dp[i - 2] + abs(arr[i - 2]  -arr[i])) {
			dp[i] = dp[i - 1] + abs(arr[i - 1] - arr[i]);
		}else {
			dp[i] = dp[i - 2] + abs(arr[i - 2] - arr[i]);
		}
	}
	
	cout << dp[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1792
s = gets.chomp.to_s
k = gets.chomp.to_i

r = [1]
s.each_char.with_index do |v, i|
  next if i == 0
  if v == s[i-1]
    r[-1] += 1
  else
    r.push 1
  end
end

if r.length == 1
  puts r[0] * k / 2
  exit
end

ans = r.map{|e| e / 2}.reduce(:+)
ans *= k

ans += k-1 if s[0] == s[-1] && r[0].odd? && r[-1].odd?

puts ans


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N, M, sum = 0; cin >> N >> M;
  vector<ll> A(N), D(N, 0);
  vector<pair<ll, ll>> CB(M);
  rep(i, 0, N) {
  	cin >> A[i];
  }
  vsort(A);
  rep(i, 0, M) {
  	ll B, C; cin >> B >> C;
    CB[i] = make_pair(C, B);
  }
  sort(CB.begin(), CB.end(), greater<pair<ll, ll>>());
  ll j = 0;
  rep(i, 0, N) {
    D[i] = CB[j].first;
    CB[j].second--;
    if (CB[j].second <= 0) {
    	j++;
    }
    if (CB[M - 1].second <= 0) break;
  }
  rep(i, 0, N) {
  	sum += max(A[i], D[i]);
  }
  cout << sum << endl;
}

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

int main( )
{
    int a, b, c, d, e, f;
    double x, y;
 
    while( cin >> a >>  b >> c >> d >> e >> f )
    {
        x = (double) ( e * c - b * f ) / ( a * e - b * d );
        y = (double) ( a * f - c * d ) / ( a * e - b * d );
	
	x += 0;
	y += 0;

        cout << fixed << setprecision(3) << x << " " << y << endl; 
    }
    return 0;
}

Measured memory_bytes: 3180
#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>;


int main() {
	int a;
	cin >> a;
	if (a >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

#ifndef __has_include
#define __has_include(x) (false)
#endif

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T, class BinaryOperation>
constexpr T fold(std::initializer_list<T> args, T init, BinaryOperation op)
{
    return std::accumulate(args.begin(), args.end(), init, op);
}

// numeric_low
namespace numeric
{
    template<class T>
    constexpr T gcd(const T x, const T y)
    {
        if (x < 0)return gcd(-x, y);
        if (y < 0)return gcd(x, -y);
        return (!y) ? x : gcd(y, x % y);
    }

    template<class T>
    constexpr T lcm(const T x, const T y)
    {
        if (x < 0)return lcm(-x, y);
        if (y < 0)return lcm(x, -y);
        return x * (y / gcd(x, y));
    }
}

template <class... Args>
std::size_t hash(Args... args)
{
    return fold({ static_cast<std::size_t>(args)... }, 0_sz,
        [](std::size_t seed, std::size_t x)
    {
        // uses magic number from boost
        return seed ^= x + 0x9e3779b9 + (seed << 6) + (seed >> 2);
    });
}

template <class Begin, class End>
void printAll(Begin beginIter, End endIter, std::string delimiter)
{
    for (auto iter{ beginIter }; iter != endIter; ++iter)
    {
        std::cout << *iter;
        if (std::distance(iter, endIter) != 1)
            std::cout << delimiter;
    }
}

template <class Container>
void printAll(const Container& c, std::string delimiter)
{
    printAll(std::cbegin(c), std::cend(c), delimiter);
}

template<class T>
void printAll(const std::initializer_list<T>& ini, std::string delimiter)
{
    printAll(ini.begin(), ini.end(), delimiter);
}

int main()
{
    using namespace std;
    
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    auto minL = numeric::lcm((ll)n, (ll)m);

    bool found = true;

    map<int, char> x;

    for (int i = 0; i < n; ++i)
    {
        auto index = i * minL / n + 1;
        x[index] = s[i];
    }

    for (int i = 0; i < m; ++i)
    {
        int index = i * minL / m + 1;
        if (x.count(index) == 0 || x[index] == t[i])
        {
            
        }
        else
        {
            found = false;
            break;
        }
    }

    if (found)
    {
        cout << minL << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

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

int main() {

	int n;
	cin >> n;
	string str;
	cin >> str;
	bool ans = false;
	for(int i=0; i<n/2; i++){
		if(str.at(i) != str.at(n/2+i)){
			ans = true;
			break;
		}
	}
	if(ans || n%2 == 1){
		cout << "No";
	}else{
		cout << "Yes";
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (n, d) = br.readLine().split(" ").map { it.toInt() }
  val x = (1..n).map { br.readLine().split(" ").map { it.toInt() }.toIntArray() }

  var cnt = 0
  for(i in 0 until n) {
    for(j in i+1 until n) {
      val v = x[i].zip(x[j]).map { z -> (z.first - z.second) * (z.first - z.second) }.sum()
      if((v % Math.sqrt(v.toDouble())) == 0.0) {
        cnt++
      }
    }
  }

  val ans = cnt
  println(ans)
}

Measured memory_bytes: 33868
#include<bits/stdc++.h>
using namespace std;
int main(){
  double a,b,c,d;
  cin>>a>>b>>c;
  c=c*M_PI/180;
  double x=a*b*sin(c)/2,y=sqrt(a*a+b*b-2*a*b*cos(c))+a+b,z=2*x/a;
  printf("%.5f\n%.5f\n%.5f\n",x,y,z);
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<string> s(n);
    REP(i, n) cin >> s[i];

    bool fa = false, fb = false;
    ll ret = 0, a = 0, b = 0;
    REP(i, n) {
        REP(j, s[i].size()-1) {
            if(s[i][j]=='A' && s[i][j+1]=='B') ret++;
        }
        if(s[i][0]=='B' && s[i].back()=='A') a++, b++;
        else if(s[i][0]=='B') b++, fb = true;
        else if(s[i].back()=='A') a++, fa = true;
    }
    // cout << ret << endl;
    if(!fb) a--;
    if(!fa) b--;
    ll tmp = max(0LL, min(a, b));
    // if(a == 1 && b == 1 && flag) tmp = 0;
    cout << ret + tmp << endl;

    return 0;
}


Measured memory_bytes: 768
A,B,C = map(int,input().split())

if(A==B):
    if(A!=C):
        print('Yes')
    else:
        print('No')
elif(A==C):
    if(A!=B):
        print('Yes')
    else:
        print('No')
elif(B==C):
    if(A!=B):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/



#define INF "#"
int N, A, S, G, X[401], Y[401]; string LAB[401];
string ans[401];
//---------------------------------------------------------------------------------------------------
void sol() {
    rep(i, 0, A) cin >> X[i] >> Y[i] >> LAB[i];

    vector<string> v;
    rep(i, 0, A) v.push_back(LAB[i]);

    rep(i, 0, N) ans[i] = INF;
    ans[G] = "";

    rep(i, 0, N * 6) rep(j, 0, A) {
        int a = X[j], b = Y[j];
        if (ans[b] == INF) continue;
        if (ans[a] == INF) ans[a] = LAB[j] + ans[b];
        else {
            string aa = ans[a], bb = LAB[j] + ans[b];
            if (bb < aa) {
                ans[a] = bb;
            }
        }
    }

    string pre = ans[S];

    rep(i, 0, N * 6) rep(j, 0, A) {
        int a = X[j], b = Y[j];
        if (ans[b] == INF) continue;
        if (ans[a] == INF) ans[a] = LAB[j] + ans[b];
        else {
            string aa = ans[a], bb = LAB[j] + ans[b];
            if (bb < aa) {
                ans[a] = bb;
            }
        }
    }

    if (ans[S] < pre || ans[S] == INF) {
        printf("NO\n");
        return;
    }

    printf("%s\n", ans[S].c_str());
}
//---------------------------------------------------------------------------------------------------
void _main() {
    int t = 1;
    while (cin >> N >> A >> S >> G) {
        if (N == 0) return;
        sol();
        //fprintf(stderr, "Finish : %d\n", t); t++;
    }
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

ll gangen[MAXN], pre[MAXN];
vector<LL> batas;
ll A[MAXN];
int n, q;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> q;
	FOR(i, 1, n) cin >> A[i];
	sort(A + 1, A + n + 1);
	ll sek = 0;
	FOR(i, 1, n) {
		pre[i] = pre[i - 1] + A[i];
		if (n % 2 == i % 2) {
			sek += A[i];
			gangen[i] = sek;
		}
	}
	int kiri = n - 2, kanan = n - 1;
	while(kiri >= 1) {
		int tengah = (A[kiri] + A[kanan]) >> 1;
		batas.pb(mp(tengah + 1, gangen[kiri] + pre[n] - pre[kanan]));
		//cout << batas[batas.size() - 1].f << ' ' << batas[batas.size() - 1].s << " EA\n";
		kiri -= 2, kanan -= 1;
	}
	batas.pb(mp(0, pre[n] - pre[n / 2]));
	reverse(batas.begin(), batas.end());
	while(q--) {
		int x;
		cin >> x;
		int kiri = 0, kanan = batas.size() - 1;
		int res = -1;
		while(kiri <= kanan) {
			int tengah = (kiri + kanan) >> 1;
			if (batas[tengah].f <= x) {
				res = tengah;
				kiri = tengah + 1;
			}
			else kanan = tengah - 1;
		}
		cout << batas[res].s << '\n';
	}
}

Measured memory_bytes: 4980
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        s: [Chars; n],
    }

    let mut map = HashMap::new();
    for s in s {
        *map.entry(s).or_insert(0) += 1i64;
    }
    let mut vec = map.iter().map(|(k, v)| (k, *v)).collect_vec();
    vec.sort_by_key(|&(k, v)| (Reverse(v), k));
    let most = vec[0].1;
    for (k, v) in vec {
        if v != most {
            break;
        }
        for c in k {
            print!("{}", c);
        }
        println!();
    }
}


Measured memory_bytes: 33236
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define Mo 1000000007

using namespace std;
int i,j,m,n,p,k,a[N],chun[N],deg[N],D[N],vis[N],Q[N],size[N],tot,ans,Qt[N];
int fac[N],inv[N];
vector<int>tree[N],v[N];
void work(int x)
{
		int i;
		Q[0]=0;
		for (i=x;!vis[x];x=a[x]) vis[x]=1,Q[++Q[0]]=x; 
		for (i=1;i<=Q[0];++i) if (size[Q[i]]) break;
		if (i<=Q[0]) 
		{
				++tot; 
				for (i=1;i<=Q[0];++i) tree[tot].pb(Q[i]);
		}
		else chun[Q[0]]++;
}
void jia(int &x,int y)
{
		x+=y; if (x>=Mo) x-=Mo;
}
int dp()
{
		int i,la=0,lb=0,fa=1;
		for (i=1;i<=Qt[0];++i)
			if (size[Qt[i]])
			{
					int na=i+size[Qt[i]]-1,nb=i+size[Qt[i]],ga=0;
					if (la<i) jia(ga,fa);
					if (lb&&lb<i) jia(ga,fa);
					fa=ga; la=na; lb=nb;
			}
		int now=0;
		if (la<=Qt[0]) jia(now,fa);
		if (lb<=Qt[0]) jia(now,fa);
		return now;
}
int power(int x,int y)
{
		int sum=1;
		for (;y;y>>=1)
		{
			if (y&1) sum=1ll*sum*x%Mo;
			x=1ll*x*x%Mo;
		}
		return sum;
}
int C(int x,int y)
{
		return 1ll*fac[x]*inv[y]%Mo*inv[x-y]%Mo;
}
void pre()
{
	fac[0]=inv[0]=1;
	for (i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%Mo,inv[i]=power(fac[i],Mo-2); 
}
int Count(int x)
{
		Q[0]=0;
		int i;
		for (i=0;i<(int)tree[x].size();++i) Q[++Q[0]]=tree[x][i];
		if (Q[0]==1)
		{
				if (size[Q[1]]==1) return 1;
				return 0;
		}
		for (i=1;i<=Q[0];++i) if (size[Q[i]]) break;
		Qt[0]=0;
		for (j=i;j>=1;--j) Qt[++Qt[0]]=Q[j];
		for (j=Q[0];j>i;--j) Qt[++Qt[0]]=Q[j]; 
		return dp();
}
int main()
{
	pre();
	scanf("%d",&n);
	for (i=1;i<=n;++i) scanf("%d",&a[i]),v[i].pb(a[i]),deg[a[i]]++;
	for (i=1;i<=n;++i) D[i]=deg[i];
	for (i=1;i<=n;++i) if (!deg[i]) Q[++Q[0]]=i;
	for (i=1;i<=n;++i) if (deg[i]>2)
	{
			puts("0");
			return 0;
	}
	int l;
	for (l=1;l<=Q[0];++l)
	{
			int p=Q[l]; vis[p]=1;
			size[p]++;
			for (i=0;i<(int)v[p].size();++i)
			{
					int k=v[p][i];
					deg[k]--; size[k]+=size[p];
					if (deg[k]==0) Q[++Q[0]]=k;
			}
	}
	for (i=1;i<=n;++i) if (vis[i]&&D[i]==2)
	{	
			puts("0");
			return 0;
	}
	for (i=1;i<=n;++i) if (!vis[i]) work(i);
	ans=1;
	for (i=1;i<=n;++i)
			if (chun[i])
			{
					int now=0;
					for (j=0;j<=chun[i];j+=2)
					jia(now,
					1ll*((i>1&&(i&1))?power(2,chun[i]-j):1)*C(chun[i],j)%Mo*C(j,j/2)%Mo*fac[j/2]%Mo*power(power(2,j/2),Mo-2)%Mo*power(i,j/2)%Mo);
					ans=1ll*ans*now%Mo;
			}
	for (i=1;i<=tot;++i) 
	{
		int now=Count(i);
		ans=1ll*ans*now%Mo;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 11768
num_shop, num_want = map(int, input().split())

shops = []

for i in range(num_shop):
  price, hold = list(map(int, input().split()))
  shops.append([price, hold])

shops = sorted(shops, key = lambda x:x[0])
  
num_bought = 0
total_price = 0

for shop in shops:
  if shop[1] + num_bought >= num_want:
    total_price += (num_want - num_bought) * shop[0]
    break
  else:
    total_price += shop[0] * shop[1]
    num_bought += shop[1]

print(total_price)

Measured memory_bytes: 63960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    ll n; cin >> n; 
    string s = "";
    while(n > 0){
        n--;
        char c = 'a' + n%26;
        s.pb(c);
        n = n/26;
    }
    reverse(all(s));
    cout << s << endl;
    return 0;
}  

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

int main(void){
    string O,E;
    cin>>O>>E;
    int N = O.size()+E.size();
    string ans(N,'a');
    for (int i=0;i<O.size();i++){
        ans[i*2] = O[i];
    }
    for (int i=0;i<E.size();i++){
        ans[i*2+1] = E[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  
  cout << (char)(a[0]-32) <<(char)(b[0]-32) << (char)(c[0]-32) << endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
	int x , a;
	cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	} else {
		cout << 10 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E17
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	string s;
	vi v;
	ll k;
	cin >> s >> k;
	int tgt = 1;
	rep(i, s.size()) {
		if (s[i]!='1'&&tgt == 1) {
			tgt = s[i]-'0';
		}
		v.push_back(tgt);
	}
	if (k > s.size())cout << tgt << endl;
	else cout << v[k-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int D;
int C[30];
int S[400][30];
int last[400][30];

ll score(vector<int>& t)
{
  ll s = 0LL;
  REP(i,t.size()){
    s += S[i][t[i]];
    REP(j,26) last[i+1][j] = last[i][j];
    last[i+1][t[i]] = i+1;
    REP(j,26){
      s -= C[j] * (i+1-last[i+1][j]);
    } 
  }
  return s;
}

ll score_2(vector<int>& t, ll before, int d, int old, int q)
{
  ll s = before;
  s += S[d][q] - S[d][old];
  FOR(i,d,D){
    if(t[i]==old) break;
    s += C[old] * ((i+1) - last[i+1][old]);
    s -= C[old] * ((i+1) - last[d][old]);
  }
  FOR(i,d,D){
    if(i!=d && t[i]==q) break;
    s += C[q] * ((i+1) - last[i+1][q]);
    s -= C[q] * ((i+1) - (d+1));
  }

  return s;
}

vector<int> init(void)
{
  vector<int> t;
  REP(d, D){
    ll max_sc = LLONG_MIN;
    int ind = 0;
    REP(i,26){
      t.push_back(i);
      ll sc = score(t);
      if(max_sc<sc){
        max_sc = sc;
        ind = i;
      }
      t.pop_back();
    }
    t.push_back(ind);
  }
  return t;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];

  auto T = init();
  ll max_score = score(T);
  
  int ti = clock();
  while(clock() - ti < 190 * CLOCKS_PER_SEC / 100){ 
    REP(loop,100){
      int d = rand365(mt);
      int q = rand26(mt);
      int old = T[d];
      T[d] = q;
      ll tmp = score_2(T, max_score, d, old, q);
      if(max_score<tmp){
        max_score = tmp;
        FOR(i,d,D){
          if(T[i]==old) break;
          last[i+1][old] = last[d][old];
        }
        FOR(i,d,D){
          if(i!=d && T[i]==q) break;
          last[i+1][q] = (d+1);
        }
      }else{
        T[d] = old;
      }
    }
  }
  REP(i,D) cout << T[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3740
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

x=gets.to_i
val_500=x/500
x%=500
val_5=x/5
puts val_500*1000+val_5*5

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S;

    cin >> S;

    ll sum = 0;
    REP(i, S.size() ){
        sum += ( S[i]-'0' );
    }
    if( sum % 9 == 0 ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3720
n = int(input())
pw = input()
wset = set()
wset.add(pw)
for _ in range(n - 1):
    w = input()
    if pw[-1] != w[0] or w in wset:
        print('No')
        exit()
    else:
        pw = w
        wset.add(w)
print('Yes')

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, q;
    string s;
    cin >> n >> q >> s;

    vector< pair<char, char> > queries(q);
    char t,d;
    for(int i=0;i<q;++i) {
        cin >> queries[i].second >> queries[i].first;
    }


    // ng までのゴーレムが左から落ちる
    int ng[2] = {-1, n}, ok[2] = {n, -1};
    for(int k=0;k<2;++k) {
        while(abs(ok[k]-ng[k]) > 1) {
            int mid = (ok[k]+ng[k])/2;
            int si = mid;
            for(int i=0;i<q&&si>=0&&si<n;++i) {
                if(queries[i].second == s[si]) {
                    if(queries[i].first == 'L') {
                        --si;
                    } else if(queries[i].first == 'R') {
                        ++si;
                    }
                }
            }
            if((k == 0 && si < 0) || (k == 1 && si >= n)) {
                ng[k] = mid;
            } else {
                ok[k] = mid;
            }
        }
    }
    cerr << ng[0] << " " << ng[1] << endl;

    cout << max(0, n-(ng[0]+1)-(n-ng[1])) << endl;

    
}


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

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 100003;
bool notPr[N_MAX];
int prime[N_MAX];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  map<long long, long long> sqr;
  int cntPr = 0;
  for (int i = 2; i < N_MAX; ++i) {
    if (!notPr[i])
      prime[++cntPr] = i, sqr[1ll * i * i] = i;
    for (int j = 1; j <= cntPr && i * prime[j] < N_MAX; ++j) {
      notPr[i * prime[j]] = 1;
      if (i % prime[j] == 0)
        break;
    }
  }
  
  int n;
  cin >> n;
  typedef vector<pair<long long, bool> > Factor;
  map<Factor, int> tub;
  map<Factor, Factor> inverse;
  int ans = 0, extra = 0;
  for (int i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    Factor f, g;
    long long temp = x;
    for (int j = 1; 1ll * prime[j] * prime[j] * prime[j] <= x; ++j)
      if (temp % prime[j] == 0) {
        int tms = 0;
        while (temp % prime[j] == 0)
          ++tms, temp /= prime[j];
        tms %= 3;
        if (tms != 0)
          f.push_back(make_pair(prime[j], tms != 1));
      }
    for (auto a : f)
      g.push_back(make_pair(a.first, !a.second));
    if (temp > 1) {
      if (sqr.find(temp) != sqr.end()) {
        temp = sqr[temp];
        f.push_back(make_pair(temp, 1));
        g.push_back(make_pair(temp, 0));
      }
      else {
        f.push_back(make_pair(temp, 0));
        g.push_back(make_pair(temp, 1));
      }
    }
    if (f.empty())
      extra = 1;
    else {
      ++tub[f];
      inverse[f] = g;
    }
  }
  
  for (auto t : tub) {
    if (tub.find(inverse[t.first]) == tub.end())
      ans += t.second;
    else {
      if (t.first[0].second == 0)
        ans += max(t.second, tub[inverse[t.first]]);
    }
  }
  cout << ans + extra << endl;
  return 0;
}


Measured memory_bytes: 37504
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      char c[2][3];
      rep(i,2){
       rep(j,3){
        cin >> c[i][j]; 
       }
      }
      bool flag=true;
      rep(i,3){
       if(c[0][i]!=c[1][2-i]) flag=false;
      }
      if(flag)cout << "YES" << endl;
      else cout << "NO" <<endl;
      return 0;}


Measured memory_bytes: 256
def main():
    K = int(input())
    if K % 2 == 0 or K % 5 == 0:
        print(-1)
        return
    cnt = 1
    tmp = 7
    while tmp % K != 0:
        tmp = tmp * 10 + 7
        tmp %= K
        cnt += 1

    print(cnt)

main()


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "No";
    if(c > a && b > c) ans = "Yes";
    if(c < a && b < c) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256