akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
	map<ll,ll>rect;
	ll n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		rect[a]++;
	}
	ll fir=0,sec=0;
	for(auto itr:rect){
		if(itr.second>=4){
			if(itr.first>fir){
				sec=itr.first;
				fir=itr.first;
			}
			else if(itr.first>sec){
				sec=itr.first;
			}
		}
		else if(itr.second>=2){
			if(itr.first>fir){
				sec=fir;
				fir=itr.first;
			}
			else if(itr.first>sec){
				sec=itr.first;
			}
		}
	}
	cout<<fir*sec<<endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	char a, b;
	cin >> a >> b;
	if (a == 'H')
		if (b == 'H')
			cout << "H" << "\n";
		else
			cout << "D" << "\n";
	else
		if (b == 'H')
			cout << "D" << "\n";
		else
			cout << "H" << "\n";
}

Measured memory_bytes: 3536
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1000000007;
constexpr ll mod = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

// Binary indexed Tree(BIT)
template <typename T>
struct BIT{
    private:
    vector<T> array;
    const int n;

    public:
    // 初期化
    BIT(int _n) : array(_n+1,0),n(_n) {}

    // 1番目からi番目までの累積和を求める
    T sum(int i){
        T s = 0;
        while(i > 0){
            s += array[i];
            // LSB減算
            i -= i & -i;
        }
        return s;
    }
    
    // [i,j]の要素の総和
    T sum(int i,int j){
        // 1番目からi-1番目までの総和
        T ret_i = sum(i-1);
        // 1番目からj番目までの総和
        T ret_j = sum(j);
        // i番目からj番目までの総和
        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i,T x){
        while(i <= n){
            array[i] += x;
            // LSB加算
            i += i & -i;
        }
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<ll> S(N+1,0);
    for(int i=0; i<N; i++){
        S[i+1] = S[i] + A[i];
    }
    set<pair<ll,ll>> se;
    for(int i=0; i<=N; i++){
        ll now = S[i] - i*K;
        se.insert(pair<ll,ll>(now,i));
    }
    vector<int> c(N+1);
    ll now = -INF;
    int id = 0;
    for(auto s: se){
        if(now == s.first){
            c[s.second] = id;
        }else{
            id++;
            now = s.first;
            c[s.second] = id;
        }
    }
    BIT<int> bit(N+1);
    ll ans = 0;
    for(int i=0; i<=N; i++){
        ans += bit.sum(c[i]);
        bit.add(c[i],1);
    }
    cout << ans << "\n";
    // for(int i=0; i<=N; i++){
    //     cout << S[i]-i*K << " " << c[i] << "\n";
    // }
    return 0;
}


Measured memory_bytes: 17536
import itertools
n = int(input())

array = []
dict = {}
dict["M"] = dict["A"] = dict["R"] = dict["C"] = dict["H"] = 0
for i in range(n):
    tmp = input()
    dict[tmp[0]] = dict.get(tmp[0], 0) + 1

m = dict["M"]
a = dict["A"]
r = dict["R"]
c = dict["C"]
h = dict["H"]
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+
      a*r*c+a*r*h+a*c*h+r*c*h)


Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val K = readLine()!!.toInt()
    val (A, B) = readLine()!!.split(" ").map(String::toInt)
    (A..B).map { it % K == 0 }.any { it }.let { if(it) {"OK"} else { "NG" } }.run(::println)   
}

Measured memory_bytes: 36416
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

void
find(vector<ll> & values, ll index, vector<vector<ll>> & prev) {
  if (values[index] >= 0) return;
  if (prev[index].size() == 0) {
    values[index] = 0;
    return;
  }

  ll best = 0;
  for (auto p : prev[index]) {
    find(values, p, prev);
    best = max(best, values[p]);
  }

  values[index] = best + 1;
}

void
solve() {
  ll n, m;
  cin>>n>>m;

  ll x, y;
  vector<vector<ll>> prev(n + 1, vector<ll>());
  vector<ll> next(n + 1, 0);
  for (ll i=0; i<m; i++) {
    cin>>x>>y;
    prev[y].push_back(x);
    next[x]++;
  }

  ll ans = 0;
  vector<ll> values(n + 1, -1);
  for (ll i=1; i<=n; i++) {
    if (next[i] == 0 && values[i] == -1) {
      find(values, i, prev);
      ans = max(ans, values[i]);
    }
  }
  cout<<ans<<endl;
}

int
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 19376
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string card = Console.ReadLine();
                if (card.CompareTo("-") == 0)
                    break;

                int shuffle_count = int.Parse(Console.ReadLine());
                for (int i = 0; i < shuffle_count; i++)
                {
                    int h = int.Parse(Console.ReadLine());
                    card = card.Substring(h) + card.Substring(0, h);
                }
                Console.WriteLine(card);
            }
        }
    }
}

Measured memory_bytes: 9864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (C>A+B)cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

using ll = long long;

int main(){
	int n;
	cin >> n;
	string s;

	map<string,int>mp;
	for(int i=0;i<n;i++){
		cin >> s;
		mp[s]+=1;
	}

	int max=0;
	for(auto x:mp){
		if(x.second > max){
			max = x.second;
		}
	}

	for(auto i=mp.begin();i!=mp.end();i++){
		if(i->second == max){
			cout << i->first << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 25216
using System;
using System.Linq;
using System.Collections.Generic;

public static class Hello{
    static Scanner sc = new Scanner();
    public static void Main(){
        var X = sc.NextInt();
        var Y = sc.NextInt();
        var Z = sc.NextInt();
        
        Console.WriteLine((int)((X - Z) / (Y + Z)));
    }
}
public class Scanner{
    private string line;
    private string[] token;
    private int cursole = 0;
    
    public string ReadLine(){
        line = Console.ReadLine();
        token = line.Split(' ');
        cursole = 0;
        return line;    
    }
    
    public string Next(){
        if(token == null) ReadLine();
        if(token.Length <= cursole) ReadLine();
        var ret = token[cursole];
        ++cursole;
        return ret;
    }

    public IEnumerable<double> NextDoubleList(){
        return NextList().Select(s => Double.Parse(s));
    }

    public int NextInt(){return Int32.Parse(Next());}
    
    public long NextLong(){return Int64.Parse(Next());}

    public double NextDouble(){return Double.Parse(Next());}

    public IEnumerable<string> NextList(){
        ReadLine();
        cursole = Int32.MaxValue;
        return token;
    }
    
    public IEnumerable<int> NextIntList(){
        return NextList().Select(s => Int32.Parse(s));
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <bits/stdc++.h>
#define MAX_SIZE 500010
#define INFTY 2000000000
using namespace std;

int n, A[MAX_SIZE];
long long cmp = 0;
void merge(int left, int mid, int right) {
    int i, j, k, n1 = mid - left, n2 = right - mid;
    int L[n1+1], R[n2+1];
    for (i=0; i < n1; i++) L[i] = A[left + i];
    for (i=0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;
    for (k=left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
            cmp += n1 - i;
        }
    }
    return;
}

void mergeSort(int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}


int main(){
    cin >> n;
    for (int i=0; i < n; i++) scanf("%d", &A[i]);
    mergeSort(0, n);
    cout << cmp << endl;
    // for (int i=0; i < n - 1; i++) printf("%d ", A[i]);
    // cout << A[n-1] << endl << cmp << endl;
    return 0;
} 


Measured memory_bytes: 4808
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int v[]=new int[n];
		for(int i=0;i<n;i++) {
			v[i]=sc.nextInt();
		}
		Arrays.sort(v);
		double ans=v[0];
		for(int i=1;i<n;i++) {
			ans=(v[i]+ans)/2.0;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N,K;
  cin>>N>>K;
  vector <long> num(N);
  for(int i = 0;i<N;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  long ans = num[K-1]-num[0];
  for(int i = 0;i<N-K+1;i++){
    ans = min(ans,num[i+K-1]-num[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int x,y,s,sum,max;

	while(cin >> x >> y >> s){
		if((x==0)&&(y==0)&&(s==0)){return 0;}

		max = 0;

		for(int i=1; i<s-1; i++){
			for(int j=s-1; j > 0 ; j--){

				sum =  (int)( (i*(100+x)) / 100) + (int)( (j*(100+x)) / 100);

				if(sum == s){
					sum =  (int)( (i*(100+y)) / 100) + (int)( (j*(100+y)) / 100);
					if(sum > max){ max = sum;}
				}
				if(sum < s){ break;}
				}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	vector<ll> arr(n);
	set<ll> ss;
	for(auto i=0;i<n;++i){cin>>arr[i]; ss.insert(arr[i]);}
	if(ss.size()==arr.size())cout<<"YES\n";
	else
		cout<<"NO\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 11264
#include <iostream>

using namespace std;

int main(void)
{
  int p,q,r;
  cin >> p >> q >> r;
  int pq,qr,rp;
  pq = p + q;
  qr = q + r;
  rp = r + p;
  int min = pq;
  if(min > qr)
    min = qr;
  if(min > rp)
    min = rp;
  cout << min;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		long A = nextLong();
		long B = nextLong();
		long C = nextLong();
		long K = nextLong();

		long ans = 0;
		if(K%2==0){
			ans=A-B;
		}else{
			ans=B-A;
		}
		System.out.println(ans);

	}




	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int main(){
  int N,M;
  cin>>N>>M;
  int low=1;
  int high=N;
  if(N%2==1){
    for(int i=0;i<M;i++){
      cout<<low<<" "<<high<<endl;
      low++;
      high--;
    }
  }else{
    vector<pair<int,int>> ans(M);
    int count=1;
    set<int> m;
    m.insert(N/2);
    for(int i=0;i<M;i++){
      ans.at(i).first=count;
      count++;
    }
    for(int i=M-1;i>=0;i--){
      int x=count-ans.at(i).first;
      x=min(x,N-x);
      while(m.count(x)==1){
        count++;
        x=count-ans.at(i).first;
        x=min(x,N-x);
      }
      ans.at(i).second=count;
      m.insert(x);
      count++;
    }
    for(int i=0;i<M;i++){
      cout<<ans.at(i).first<<" "<<ans.at(i).second<<endl;
    }
  }
}


Measured memory_bytes: 6796
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int H,W,N;

vector< vector<char> > tmp;

bool win(vector< vector<char> > field)
{
	rep(y,H){
		rep(x,W){
			if(field[y][x] != '.'){ return false; }
		}
	}
	return true;
}

int fall()
{
	int cnt = 0;
	for(int y=H-1; y>0; y--){
		for(int x=W-1; x>=0; x--){
			if(tmp[y][x] == '.' && tmp[y-1][x] != '.'){
				swap(tmp[y][x],tmp[y-1][x]);
				cnt++;
			}
		}
	}
	return cnt;
}

void erase()
{
	vector< vector<bool> > del(H,vector<bool>(W,false));
	rep(y,H)
	{
		rep(x,W)
		{
			char self = tmp[y][x];
			if(self == '.'){ continue; }

			//横の処理
			int cnt=0;
			REP( i, x, W ){
				if( self == tmp[y][i] ){ cnt++; }
				else{ break; }
			}
			if(cnt >= N){
				REP( i, x, W ){
					if( self == tmp[y][i] ){ del[y][i] = true; }
					else{ break; }
				}
			}

			//縦の処理
			cnt = 0;
			REP( i, y, H ){
				if( self == tmp[i][x] ){ cnt++; }
				else{ break; }
			}
			if(cnt >= N){
				REP( i, y, H ){
					if( self == tmp[i][x] ){ del[i][x] = true; }
					else{ break; }
				}
			}
		}
	}

	rep(y,H){
		rep(x,W){
			if(del[y][x]){ tmp[y][x] = '.'; }
		}
	}
}

void show()
{
	rep(i,H){
		DUMP(tmp[i]);
	}
	cout << "-------------------" << endl;
}

int main()
{
	cin >> H >> W >> N;
	vector< vector<char> > field(H,vector<char>(W,'.'));

	rep(y,H){
		rep(x,W){
			cin >> field[y][x];
		}
	}

	rep(y,H){
		rep(x,W-1)
		{
			tmp = field;
			swap(tmp[y][x],tmp[y][x+1]);
			int cnt=1;
			while(true)
			{
				while(cnt){ cnt = fall(); }
				erase();
				cnt = fall();
				if(!cnt){ break; }
			}

			if(win(tmp)){ //クリアー判定
				cout << "YES" << endl;
				goto end;
			}
		}
	}
	cout << "NO" << endl;
end:
	return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll dp[100005][2];
int main(){
  string s;
  cin>>s;
  ll n=sz(s);
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  rep(i,n){
    {//a+b==0
      if(s[i]=='0'){
        dp[i+1][0]+=dp[i][0];
        dp[i+1][1]+=dp[i][1];
        dp[i+1][0]%=MOD;
        dp[i+1][1]%=MOD;
      }
      else{
        dp[i+1][1]+=dp[i][0]+dp[i][1];
        dp[i+1][1]%=MOD;
      }
    }
    {
      if(s[i]=='0'){
        dp[i+1][1]+=dp[i][1]*2;
        dp[i+1][1]%=MOD;
      }
      else{
        dp[i+1][0]+=dp[i][0]*2;
        dp[i+1][1]+=dp[i][1]*2;
        dp[i+1][0]%=MOD;
        dp[i+1][1]%=MOD;
      }
    }
  }
  COUT((dp[n][0]+dp[n][1])%MOD);
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int x[10][10];
signed main(){
	int a,b;
	cin>>a>>b;
	f(i,max(a,b)){
		cout<<min(a,b);
	}
	cout<<endl;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)

for i in 0..n
  for j in 0..n-i
    if i * 10000 + j * 5000 + (n-i-j) * 1000 == k
      puts "#{i} #{j} #{n-i-j}"
      exit
    end
  end
end

puts "#{-1} #{-1} #{-1}"


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

using namespace std;

constexpr long long INF64 = 1e18;

using Weight=long long;

struct Edge{
    int src,dst,ds,belong,st,kaisuu;
    Weight weight;
    Edge(int src,int dst,int ds,Weight weight,int belong,int st,int kaisuu):
    src(src),dst(dst),ds(ds),weight(weight),belong(belong),st(st),kaisuu(kaisuu){}
};

auto operator < (const Edge &e,const Edge &f){
    if(e.weight!=f.weight)return e.weight>f.weight;
    else return e.kaisuu>f.kaisuu;
}

using Edges=vector<Edge>;
using Graph=vector<Edges>;

pair<Weight,int> dijkstra(const Graph &g,int s,int t,int N,int T){
    const int V=g.size();
	vector<Weight>dist(100001,INF64);
	vector<int>prev(100001,-1);
    priority_queue<Edge>q;
    /*for(int i=0;i<N;++i){
		dist[s][i]=0;
		prev[s][i]=-2;
	}*/
    for(q.emplace(-2,s,-1,-T,-1,-2,-1);!q.empty();){
        Edge e=q.top();q.pop();
        if(e.belong>=0){
			if(prev[e.ds]!=-1)continue;
			else prev[e.ds]=e.src;
		}
        if(e.dst==t)return make_pair(e.weight,e.kaisuu);
        for(auto ge:g[e.dst]){
			int plus=0;
			if(e.belong!=ge.belong || abs(e.st-ge.st)>1)plus=T;
            if(dist[ge.ds] > e.weight+ge.weight+plus){
                dist[ge.ds]=e.weight+ge.weight+plus;
				if(plus)plus=1;
                q.emplace(ge.src,ge.dst,ge.ds,dist[ge.ds],ge.belong,ge.st,e.kaisuu+plus);
            }
        }
    }
	return make_pair(-1,-1);
}


int main(){
	int N,T;
	cin>>N>>T;
	string A,B;
	cin>>A>>B;
	map<string,int>mp;
	int k=1,f=0;
	Graph g(100001);
	for(int i=0;i<N;++i){
		int a;
		cin>>a;
		int prev=-1;
		vector<int>station(a);
		for(int j=0;j<a;++j){
			string s;
			cin>>s;
			if(mp[s]==0)mp[s]=k++;
			station[j]=mp[s];
		}
		for(int j=0;j<a-1;++j){
			Weight t;
			cin>>t;
			g[station[j]].emplace_back(station[j],station[j+1],f+1,t,i,j+1,-1);
			g[station[j+1]].emplace_back(station[j+1],station[j],f,t,i,j+1,-1);
			f++;
		}
		f++;
	}
	pair<Weight,int>ans=dijkstra(g,mp[A],mp[B],N,T);
	if(ans.first==-1)cout<<"-1"<<endl;
	else cout<<ans.first<<" "<<ans.second<<endl;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e5+5;
vector < pair <ll, ll> > v[L];
vector <string> store(L);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll N, M;
    cin >> N >> M;

    for(ll i=1; i<=M; i++)
    {
        ll P, Y;
        cin >> P >> Y;
        v[P].pb(mp(Y, i));
    }

    for(ll i=1; i<=N; i++)
    {
        sort(v[i].begin(), v[i].end());

        ll t = i;

        string temp = "";
        ll cnt = 0;
        while(t)
        {
            temp+=(char)(t%10+48);
            t/=10;
            cnt++;
        }

        reverse(temp.begin(), temp.end());

        cnt = 6-cnt;
        while(cnt--)
        {
            temp = '0' + temp;
        }

        for(ll j=0; j<sz(v[i]); j++)
        {
            string tem = "";
            ll te = j+1;

            ll count = 0;

            while(te)
            {
                tem+=(char)(te%10+48);
                te/=10;
                count++;
            }

            reverse(tem.begin(), tem.end());

            count = 6-count;

            while(count--)
            {
                tem = '0' + tem;
            }

            store[v[i][j].ss] = temp + tem;
        }
    }

    for(ll i=1; i<=M; i++)
    {
        cout << store[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <vector>

using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;

int const nmax = 2000;
int dp[1 + nmax][1 + nmax];
int sz[1 + nmax], dp2[1 + nmax];
vector<int> g[1 + nmax];
int n, k;

int finalresult = nmax;

void dfs(int node, int parent){
  for(int h = 0; h < g[node].size(); h++){
    int to = g[node][h];
    if(to == parent)
      g[node].erase(g[node].begin() + h);
  }

  sz[node] = 1;
  dp[node][0] = 0;
  for(int i = 0; i <= nmax; i++)
    dp2[i] = nmax;

  for(int h = 0; h < g[node].size(); h++){
    int to = g[node][h];
    dfs(to, node);
    for(int i = 0; i <= sz[node]; i++)
      for(int j = 0; j <= sz[to]; j++)
        if(i + j <= k)
          dp2[max(i, j)] = min(dp2[max(i, j)], dp[node][i] + dp[to][j]);
    sz[node] += sz[to];
    for(int i = 0; i <= sz[node]; i++) {
      dp[node][i] = dp2[i];
      dp2[i] = nmax;
    }
  }

  for(int i = 0;i <= k; i++)
    finalresult = min(finalresult, dp[node][i] + n - (sz[node]));

  for(int i = sz[node]; 0 < i; i--)
    dp[node][i] = dp[node][i - 1];
  dp[node][0] = sz[node];
  if(node != 1)
    dp[node][k + 1] = sz[node];
}

int main()
{
  cin >> n >> k;
  for(int i = 1;i < n; i++){
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for(int i = 0;i <= n; i++)
    for(int j = 0;j <= n; j++)
      dp[i][j] = n;
  dfs(1, 0);

  cout << finalresult;
  return 0;
}


Measured memory_bytes: 16128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int z = 1 << 30, sum = 0;
		for (int i = 1; i <= n; i++) {
			int x = scan.nextInt();
			sum += x;
			if (x % 10 > 0)
				z = Math.min(z, x);
		}
		if (sum % 10 == 0)
			System.out.println(z == 1 << 30 ? 0 : sum - z);
		else
			System.out.println(sum);
		return;
	}
}

Measured memory_bytes: 22868
def main():
    a,b = map(int,input().split())
    for x in range(1,10001):
        x_a = int(x * 0.08)
        x_b = int(x * 0.1)
        if x_a == a and x_b == b:
            print(x)
            return
    print(-1)
if __name__=='__main__':
    main()


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

#define ll long long

using namespace std;

int n,k,r,s,p;
int res;
string t;
int prime(int x){
    for (int i=2; i<=sqrt(x); i++){
        if (x%i==0) return 0;
    }
    return 1;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k>>r>>s>>p;
    cin>>t;
    for (int i=0; i<k; i++){
        if (t[i]=='r') {
            res+=p;
            t[i]='p';
        }
        else if (t[i]=='s') {
            res+=r;
            t[i]='r';
        }
        else {
            res+=s;
            t[i]='s';
        }
    }
    for (int i=k; i<t.size(); i++){
        if (t[i]=='r'){
            if(t[i-k]!='p') {
                res+=p;
                t[i]='p';
            }
            else{
                if(t[i+k]=='s') t[i]='s';
            }
        }
        else if(t[i]=='s'){
            if(t[i-k]!='r') {
                res+=r;
                t[i]='r';
            }
            else{
                if (t[i+k]=='p') t[i]='p';
            }
        }
        else if(t[i]=='p'){
            if(t[i-k]!='s') {
                res+=s;
                t[i]='s';
            }
            else{
                if (t[i+k]=='r') t[i]='r';
            }
        }
    }
    
    cout<<res;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, ii>  iii;
typedef pair<double, double>  iidb;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 3200
#define offset 3000
#define ptr nodo*
const ll MOD=1e9+7;

using namespace std;
int A,B,C,D,E,F;
int dp[tam][tam];
ii maxx;
void cmp(ii &par1,ii par2)
{
	if (par1.second* par2.first<=par2.second*par1.first)
		par1=par2;

}
int f(int sugar,int water)
{
	if (water+sugar>F)
		return 0;
	//cout<<sugar<<' '<<water<<endl;
	if (dp[sugar][water]!=-1)
		return dp[sugar][water];
	dp[sugar][water]=1;
	if (sugar+water>0 && (water*E>=(sugar*100)))
	cmp(maxx,{sugar+water,sugar});
	f(sugar+C,water);
	f(sugar+D,water);
	f(sugar,water+100*A);
	f(sugar,water+100*B);
	return 0;
}
int main()
{	
	cin>>A>>B>>C>>D>>E>>F;
	maxx={0,0};
	memset(dp,-1,sizeof dp);
	f(0,0);
	cout<<maxx.first<<' '<<maxx.se<<endl;
}		

Measured memory_bytes: 43632
def tap_dance(s):

    ki = s[0::2]
    gu = s[1::2]
    ans = "Yes"

    if "L" in ki:
        ans = "No"
    if "R" in gu:
        ans = "No"

    return ans

def main():
    s = str(input())
    print(tap_dance(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
 
int N, K;
double x[60], y[60], c[60], r[60];
 
double dist(const pdd &a, const pdd &b) {
	double xx = a.X - b.X;
	double yy = a.Y - b.Y;
	return sqrt(xx * xx + yy * yy);
}
vector<pair<double, double>> inter(int a, int b) {
	vector<pair<double, double>> ret;
	double d = dist(pdd(x[a], y[a]), pdd(x[b], y[b]));
 
	if (r[a] + r[b] < d) return ret;
	if (x[a] == x[b] && y[a] == y[b] || d < abs(r[a] - r[b])) return { { x[a], y[a] } };
 
	double tmp = (r[a] * r[a] - r[b] * r[b] + d * d) / (2 * d);
	double h = sqrt(r[a] * r[a] - tmp * tmp);
 
	double xx = x[a] + tmp / d * (x[b] - x[a]);
	double yy = y[a] + tmp / d * (y[b] - y[a]);
 
	ret.emplace_back(xx + h * (y[b] - y[a]) / d, yy - h * (x[b] - x[a]) / d);
	ret.emplace_back(xx - h * (y[b] - y[a]) / d, yy + h * (x[b] - x[a]) / d);
 
	return ret;
}
int check(double t) {
	for (int i = 0; i < N; ++i) r[i] = t / c[i];
 
	int ret = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			auto pts = inter(i, j);
			for (auto &p : pts) {
				int cnt = 0;
				for (int k = 0; k < N; ++k)
					if (dist(p, pdd(x[k], y[k])) <= r[k] + 1e-9) ++cnt;
				ret = max(ret, cnt);
			}
		}
	}
 
	return ret;
}
int main() {
	fastio;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) cin >> x[i] >> y[i] >> c[i];
 
	double s = 0, e = 282850;
	while (s < e - 1e-9) {
		double m = (s + e) / 2.0;
		
		if (check(m) < K) s = m;
		else e = m;
	}
 
	cout << fixed << setprecision(9) << (s + e) / 2.0;
 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a, b, c, data;
    scanf("%d %d %d",&a, &b, &c);
    data = c-(a-b);
    if(data>=0) {
        printf("%d\n", data);
    }else{
        printf("0");
    }
    return 0;
}

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

int main(){
  string S;
  cin>>S;
  if(S.at(1)==S.at(2)&&(S.at(0)==S.at(1)||S.at(2)==S.at(3))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

using ll = long long;
#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 INF 1e9
// const ll INF = 1LL << 60;

int cal(int n){
  return n*(n+1)*(n+2)/6;
}
constexpr int maxd = 1e6+10;
int dp[maxd], dp2[maxd];
int main(){
  vector<int> P;
  int p;
  for(int i = 1; (p=cal(i)) <= 1e6; i++){
    P.push_back(p);
  }
  REP(i, maxd){
    dp[i] = dp2[i] = INF;
  }
  dp[0] = 0;
  dp2[0] = 0;
  REP(i, P.size()){
    int a = P[i];
    REP(j, 1e6){
      if(j+a > 1e6) continue;
      dp[j+a] = min(dp[j+a], dp[j]+1);
      if(a % 2){
        dp2[j+a] = min(dp2[j+a], dp2[j]+1); 
      }
    }
  }
  while(true){
    int n;
    cin >> n;
    if(n == 0) break;
    cout << dp[n] << " " << dp2[n] << endl;
  }
  return 0;
}



Measured memory_bytes: 10956
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int s[12];

long long int ans=0;
string x;
//先頭からi番目までの数字で,最後に＋を入れた後の数がwであるとする
//このvoidでの処理は、「自分(=i+1番目の数字)より前に＋を入れるかどうか」
void wf(int i,long long int ss,long long int w)
{
 //＋を入れたらssにwを足してwはs[i]で更新する
 //＋を入れなかったらssには何も足さずwを10*w+s[i]で更新する
 //もしiがx.size()に一致していたらwfには入れずにansにssを足してループを抜ける
 if((i+1)!=x.size())
	{
 	 wf(i+1,ss+w,s[i]); //＋を入れた処理
	 wf(i+1,ss,10*w+s[i]); //＋を入れない処理
	}
 if((i+1)==x.size())
	{
	 ans=ans+ss+w+s[i];//＋を入れた処理
	 ans=ans+ss+(10*w+s[i]);//＋を入れない処理
	}
}

int main()
{
 cin>>x;
 for(int i=0;i<x.size();i++)
 {
	s[i]=x[i]-'0';
 }
 //初期入力ではi=1,w=s[0]、x.size()==1なら除外してvoidには入れずにans=s[0]
 if(x.size()==1){ans=s[0];}
 else{wf(1,0,s[0]);}
 printf("%lld",ans);\
 
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main() {
    	int n, y;
    	scanf("%d %d", &n, &y);
    	int c1 = y / 10000;
    	int c2 = y / 5000;
    	for (int i = 0; i <= c1; i++) {
    		for (int j = 0; j <= c2; j++) {
    			int k = n - i - j;
    			if (k < 0)
    				break;
    			int cur = i * 10000 + j * 5000 + k * 1000;
    			if (cur == y) {
    				printf("%d %d %d\n", i, j, k);
    				return 0;
				}
    		}
    	}
    	printf(" -1 -1 -1\n");
    	return 0;
    }

Measured memory_bytes: 256
n = gets.to_i
h = {}
n.times do
  s = gets
  h[s.chomp] = 1
end

for m in ["S", "H", "C", "D"] do
  for i in 1..13 do
    puts "#{m} #{i}" if !h.has_key?(m+" "+i.to_s)
  end
end


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d.at(i);
  }

  if (n % 2 != 0) {
    cout << 0;
    return 0;
  }

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

  int arc_min = d.at(d.size() / 2);
  int abc_max = d.at((d.size() - 1) / 2);

  cout << arc_min - abc_max;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int x[MAXN], y[MAXN];
int idxx[MAXN], idxy[MAXN];
bool visit[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    vector<pii> candx, candy;
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &x[i], &y[i]);
        candx.push_back(make_pair(x[i], i));
        candy.push_back(make_pair(y[i], i));
    }
    sort(candx.begin(), candx.end());
    sort(candy.begin(), candy.end());
    for (int i = 0; i < N; i++) {
        idxx[candx[i].second] = i;
        idxy[candy[i].second] = i;
    }
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    LL ans = 0;
    pq.push(make_pair(0, candx[0].second));
    while (!pq.empty()) {
         auto tp = pq.top();
         pq.pop();
         int cur = tp.second;
         //printf("cur = %d w = %d\n", cur, tp.first);
         if (visit[cur]) continue;
         visit[cur] = 1;
         ans += tp.first;
         int cur_x = idxx[cur], cur_y = idxy[cur];
         if (cur_x - 1 >= 0)
             pq.push(make_pair(x[cur] - candx[cur_x - 1].first, candx[cur_x - 1].second));
         if (cur_y - 1 >= 0)
             pq.push(make_pair(y[cur] - candy[cur_y - 1].first, candy[cur_y - 1].second));
         if (cur_x + 1 < N)
             pq.push(make_pair(candx[cur_x + 1].first - x[cur], candx[cur_x + 1].second));
         if (cur_y + 1 < N)
             pq.push(make_pair(candy[cur_y + 1].first - y[cur], candy[cur_y + 1].second));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5740
h,w = map(int,input().split())

z = []
p = []
m = 10**9+7
for i in range(h):
    z.append(list(input()))
    p.append(list([0]*w))
p[0][0] = 1

for x in range(h):
    for y in range(w):
        if x != 0 or y != 0:
            if z[x][y] == "#":
                p[x][y] == 0
            else:
                p[x][y] += (p[x-1][y] + p[x][y-1])%m
               
                
print(p[h-1][w-1])

Measured memory_bytes: 52548
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char a;
    while(1){
        scanf("%c", &a);
        if(a == '\n') break;
        if(isalpha(a)){
            if(islower(a)) printf("%c", toupper(a));
            if(isupper(a)) printf("%c", tolower(a));
        }else{
            printf("%c", a);
        }
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 3144
S = input()

'''
357 375 537 573 735 753 
3357 3375 3537 3573 3735 3753 
5357 5375 5537 5573 5735 5753 
3357,3375,3537,

3けた　、4けた 5 ,6, 7, 8
6,18,54,162,486, 8
sum = [2 * 3,2 * 3 * 3,]
'''

N = len(S)
list375 =['3','5','7']
if N <  3:
    print(0)
    exit(0)

for i in range(N + 1):
    if i ==0:
        continue
    else:
        targetList = list375[:]
        for l in targetList:
            #print(l)
            list375.append(l + '3')
            list375.append(l + '5')
            list375.append(l + '7')

result = [i for i in list(set(list375)) if int(i) <= int(S) and (i.count('3') >0 and i.count('5') >0 and i.count('7') >0)]
#print(result)
print(len(result))


'''
def judge753():
    if keta[0] < 3:
        return 0
    if keta[0] < 5:
        if keta[1] < 3:
            return 0
        if keta[1] < 5:
            if keta[2] < 5:
                return 0
            if keta[2] < 7:
                return 1
            return 2
        if keta[1] < 7:
            
        return sum[len(S)-1]
    if keta[0] < 7:
        if keta[1] < 3:
            return sum[len(S)-1] + sum[len(S)-2]
        if keta[1] < 5:
            if keta[2] < 5:
        
        return sum[len(S)-1]
        
print(min(absList))
'''


Measured memory_bytes: 64360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		
		int ans = 0;
		if(K < N)
			ans = K * X + (N-K) * Y;
		else
			ans = N * X;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
bool check(int k)
{
	for(int i=2;i<=sqrt(k);i++)
		if(k%i==0)
			return false;
	return true;
}
int main()
{
	int n;	cin>>n;
	vector<int> v;
	for(int i=6;i<=55555;i+=5)
	{
		if(check(i)==true)
		{
			v.push_back(i);
			n--;
		}
		if(n==0)
			break;
	}
	for(int i=0;i<v.size()-1;i++)
		cout<<v[i]<<" ";
	cout<<v[v.size()-1]<<endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()

for i in range(len(s)):
    if i % 2 == 0 and s[i] == 'L':
        print('No')
        exit()
    if i % 2 == 1 and s[i] == 'R':
        print('No')
        exit()
    
print('Yes')

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




// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(10005);


//nPk
 mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}




//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }

mint dp[13][100005];
int main() {

string s;
cin>>s;
ll n=s.size();
vector<ll> a(0);
vector<ll> b(0);
vector<ll> ans(n,0);

a.push_back(0);
rep(i,n-1){
  if(s[i]==s[i+1])continue;
  if(s[i]=='L'){
    a.push_back(i+1);
  }
  else b.push_back(i+1);
}
a.push_back(n);
rep(i,b.size()){
// cout<<b[i]<<endl;
  ll t1=b[i]-a[i];
  ll t2=a[i+1]-b[i];
  ans[b[i]-1]+=t1/2;
  ans[b[i]-1]+=t2/2;
  ans[b[i]]+=t1/2;
  ans[b[i]]+=t2/2;
if (t1%2==1)ans[b[i]-1]++;
if (t2%2==1)ans[b[i]]++;

}
rep(i,n)cout<<ans[i]<<' ';
}


Measured memory_bytes: 15428
from itertools import accumulate
from operator import add, mul
n,m,q=map(int,input().split())

a=[]
b=[]
for i in range(n):
    a.append([0]*(n))
    b.append([0]*(n))

#import numpy as np
#b=np.array(b)
#print(a)
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    #a[(r-1):n,0:l]+=1
    for j in range(r-1,n):
        for k in range(l):
            a[j][k]+=1
'''
for i in range(m):
    l,r=map(int,input().split())
    #print(a[(r-1):n,0:l])
    a[l-1][r-1]+=1

#print(a)

for i in range(n):
    a[i]=list(accumulate(a[i]))

#print(a)

for i in range(n):
    for j in range(n-i-1):
        a[n-i-j-2][n-i-1]+=a[n-i-j-1][n-i-1]
        #print(a)

#print(a)

'''
for l in range(n):
    for r in range(l,n):
        temp=a[r][l]
        for i in range(r,n):
            for j in range(0,l+1):
                b[i][j]+=temp
        #b[r:n,0:l+1]+=temp
'''
#print(a)
#print(b)

for i in range(q):
    P,Q=map(int,input().split())
    print(a[(P-1)][(Q-1)])
'''
for i in range(que):
    p,q=MI()
    if p==1:
        ans=lis[q-1][q-1]
    else:
        ans=lis[q-1][q-1]-lis[p-2][q-1]
    print(ans)
'''

Measured memory_bytes: 19076
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
	int n;
	cin>>n;

	int arr[3];
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			{
				arr[0]=i;
				arr[1]=j;
				arr[2]=k;
				sort(arr,arr+3);

				sum+=__gcd(arr[0],__gcd(arr[1],arr[2]));
			}
		}
	}
	cout<<sum<<endl;
	
	
}

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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    string s[n];
    map<string, int> mp;
    int mx = 0;
    rep(i, n) {
        cin >> s[i];
        mp[s[i]]++;
        chmax(mx, mp[s[i]]);
    }
    sort(s, s + n);
    rep(i, n) {
        if(mp[s[i]] == mx) {
            cout << s[i] << endl;
            i += mx - 1;
        }
    }
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int c[n],s[n],f[n];
  REP(i,n-1) cin >> c[i] >> s[i] >> f[i];
  REP(i,n) {
    int t=0;
    for (int j = i; j < n-1; j++) {
      if (t<s[j]){
        t=s[j];
      } else if (t%f[j] != 0) {
        t=t+f[j]-t%f[j];
      }
      t+=c[j];
    }
    COUT(t);
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
 
const int INF = 100000000;
#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)

using namespace std;

int main()
{
	ll N;
	cin >> N;
	ll ans=0;
	for (int i = 1; i <= N; i++) {
		ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-10,110)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    print(iii[idx])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27204
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const int MOD = 1000000007;

int main(){
  string s; cin >> s;
  int n = s.size();
  
  int mul = 1;
  vector<vector<int>> dp(n+1,vector<int>(13,0));
  dp[0][0] = 1;
  int deep = 1;
  for(int i = n-1;i >= 0;i--){
    if (s[i] == '?'){
      for(int j=0; j<10;j++){
        int move = j * mul % 13;
        for(int k = 0; k < 13; k++){
          dp[deep][(k+move)%13] += dp[deep-1][k];
          dp[deep][(k+move)%13] %= MOD;
        }
      }
    }else{
      int k = s[i] - '0';
      int move = k * mul % 13; //スライドさせる距離
      for(int j = 0; j < 13;j++){
        dp[deep][(j+move)%13] += dp[deep-1][j];
        dp[deep][(j+move)%13] %= MOD;
      }
    }
    deep++;
    mul *= 10;
    mul %= 13;
  }
  
  cout << dp[n][5];
  return 0;
  
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n;
    cin >> n;
    ll zmin = 2e9, zmax = -2e+9, wmin = 2e9, wmax = -2e+9;
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        zmin = min(zmin, x + y);
        zmax = max(zmax, x + y);
        wmin = min(wmin, x - y);
        wmax = max(wmax, x - y);
    }
    cout << max(zmax - zmin, wmax - wmin) << endl;
    return 0;
}


Measured memory_bytes: 3544
s = input()

dict = {}
for i in range(4):
    if s[i] in dict:
      dict[s[i]] = dict[s[i]] +1 
    else:
      dict[s[i]] = 1

count = 0
for i in dict:
  if 2 == dict[i]:
    count = count +1

if count == 2:
  print('Yes')
else:
  print("No")

Measured memory_bytes: 3064