akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

    int nV, nE, cap;
    cin >> nV >> nE >> cap;
    vector<vector<pair<int, int>>> edges(nV + 1); // to, cost
    for (int i = 0; i < nE; ++i) {
        int u, v, cost;
        cin >> u >> v >> cost;
        edges[u].emplace_back(v, cost);
        edges[v].emplace_back(u, cost);
    }
    const int INF = 1e6;
    vector<vector<int>> dist(nV + 1, vector<int>(nV + 1, INF));

    auto dijkstra = [&](int source) {
        long long inf = LONG_LONG_MAX;
        vector<bool> used(nV + 1);
        vector<long long> d(nV + 1, inf);
        d[source] = 0;
        long long minDist = 0;
        int cur = source;
        while (minDist < inf) {
            used[cur] = true;
            for (const auto& to : edges[cur]) {
                int v = to.first;
                int weight = to.second;
                if (d[cur] + weight < d[v]) {
                    d[v] = d[cur] + weight;
                }
            }
            minDist = inf;
            for (int v = 1; v <= nV; ++v) {
                if (!used[v] && d[v] < minDist) {
                    minDist = d[v];
                    cur = v;
                }
            }
        }
        for (int v = 1; v <= nV; ++v) {
            if (d[v] <= cap) {
                dist[source][v] = 1;
            }
        }
    };

    for (int v = 1; v <= nV; ++v) {
        dijkstra(v);
    }
    for (int k = 1; k <= nV; ++k) {
        for (int i = 1; i <= nV; ++i) {
            for (int j = 1; j <= nV; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int nQ;
    cin >> nQ;
    for (int q = 0; q < nQ; ++q) {
        int from, to;
        cin >> from >> to;
        int d = dist[from][to] == INF ? -1 : dist[from][to] - 1;
        cout << d << '\n';
    }

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

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

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

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

    int max_p = 2e5+5;
    int ans = 0;
    rep(i, n){
        int p; cin >> p;
        if(max_p >= p) {
            max_p = p;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
main(){
  int n;
  scanf("%d",&n);
  char taro[1000]={0},hanako[1000]={0};
  int i,j;
  int t_code=0,h_code=0;
  int t_point=0,h_point=0;
  for(i=0;i<n;i++){
    scanf("%999s%999s",taro,hanako);
    if(strcmp(taro,hanako)==0){
      t_point++;
      h_point++;
    }   
    j=0;                                                                                  
    while(taro[j]!='\0'|| hanako[j]!='\0'){
      t_code=taro[j]-'a';
      h_code=hanako[j]-'a';
      if(t_code>h_code){
        t_point=t_point+3;
        break;
      }
      else if(t_code<h_code){
        h_point=h_point+3;
        break;
      }
      j++;
    }                                                         
  }
  printf("%d %d\n",t_point,h_point);
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

const int N_MAX = 100;
int N;

int memo[210][210];

inline int acs(int n)
{
    return n + 100;
}

int main()
{

    for (int x = -100; x <= 100; x++)
    {
        for(int y = -100;y <= 100;y++)
        {
            memo[(acs(x))][acs(y)] = (x - y) * (x - y);
        }
    }

    int N;
    cin >> N;
    vector<int> a(N);

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

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

    int start = a[0];
    int end = a[a.size() - 1];

    int result = 100000000;

    for(int i = start;i <= end;i++)
    {
        int sum_ = 0;
        for(int j = 0;j < a.size();j++)
        {
            //cout << i << ":" << j << "=" << memo[acs(a[j])][acs(i)] << endl;
            sum_ += memo[acs(a[j])][acs(i)];
        }
        //cout << sum_ << endl;
        result = min(result,sum_);
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#define PI 3.14159265359
using namespace std;
int main(){
	int n,s;
	int *p;
	double avg,sg;
	
	while(cin>>n,n){
		avg=0;
		sg=0;
		p = new int[n];
		for(int i=0;i<n;++i){
			cin>>s;
			p[i]=s;
			avg+=s;
		}
		avg/=n;
		
		for(int i=0;i<n;++i){
			sg += ((p[i]-avg)*(p[i]-avg));
		}
		sg/=n;
		delete[]p;
		
		cout<<setprecision(20)<<sqrt(sg)<<endl;
	}
}

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

a1 = as.first
an = as.last
ans = 10**6 - 1

dd = Array.new(n, 0)

(n - 1).times do |i|
  dd[i] = as[i + 1] - as[i]
end
dd[-1] = k - an + a1

sum = dd.inject(:+)

dd.each do |d|
  ans = sum - d if sum - d <= ans
end

puts ans


Measured memory_bytes: 18948
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine() ;
		for(int i = 0 ; i < Integer.parseInt(n); i++){
			String str = sc.nextLine();
			String[] stra = str.split("");
 			Arrays.sort(stra);
 			String buff = new String();
 			for(int j = 0 ; j < stra.length ; j++){
 				if(!("0".equals(stra[j]))){
 					buff += stra[j];
 				}
 			}
 			
 			if(buff.length() == 0) buff = "0";
 			
 			int min = Integer.parseInt(buff);
 			String[] strb = str.split("");
 			buff = new String();
 			Arrays.sort(strb,Collections.reverseOrder());
 			for(int k = 0 ; k < strb.length ; k++){
 				buff += strb[k];
 			}
 			int max = Integer.parseInt(buff);
 			System.out.println(max - min);
		}
		sc.close();
	}
}

Measured memory_bytes: 15328
while True:
    name,typ = input().split()
    if typ=="X": break
    ans = []
    
    if "_" in name:
        ans = name.split("_")
    else:
        j = 0
        for i in range(1,len(name)):
            if name[i].isupper():
                ans.append(name[j:i])
                j = i
        ans.append(name[j:])
                
    if typ=="D":
        ans = map(str.lower, ans)
        print(*ans,sep="_")
        
    else:
        ans = "".join(map(str.capitalize, ans))
        if typ=="L":
            ans = ans[0].lower() + ans[1:]
        print(ans)
            
      


Measured memory_bytes: 5564
object Main {

  import java.util.Scanner

  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    var str = scanner.next()
    var ref = 0
    val a = str.toInt
    str = scanner.next()
    val b = str.toInt
    str = scanner.next()
    val c = str.toInt

    if(a == b && b == c)
      println(1)
    else if (a == b || b == c || a == c)
      println(2)
    else
      println(3)
  }
}


Measured memory_bytes: 25388
#counter 2次元リスト
def counter_list(A):
 def counter_dic(A): #counter 辞書
  dic = {}
  for a in A:
   dic[a] = dic.get(a,0) + 1
  return dic

 dic_ = counter_dic(A)
 B = []
 for k in dic_:
  B.append([dic_[k], k])
 B.sort(reverse=True) 
 return B

N = int(input())
S = []

for i in range(N):
 s = input()
 S.append(s)
  
ans = []
cnt = counter_list(S)
for i in range(len(cnt)):
  if(cnt[i][0] == cnt[0][0]):
    ans.append(cnt[i][1])
  else:
    break
    
ans.sort()
for i in range(len(ans)):
  print(ans[i])
  

Measured memory_bytes: 50444
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[100010], b, q, l;



int32_t main(){
INIT
cin>>n;
int cp=1;

for(int i=1; i<=n; i++){
    cin>>a[i];
}

for(int i=1; i<=n; i++){
    if(a[i]==0){cout<<0; return 0;}
}

for(int i=1; i<=n; i++){
    if(cp>(( (ll) 1000000000000000000 )/a[i]) ){cout<<-1; return 0;}
    cp*=a[i];
}





cout<<cp;
return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
int N, A, B;
	cin >> N >> A >> B;
	fyg(B+1,A) {
		if (y%N==0) {
			ce("OK");
			return 0;
		}
	}
	ce("NG")
    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
// =======================
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long int
#define ull unsigned long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ss second
#define setbits(x) _builtin_popcount(x)
#define parity(x) _builtin_parity(x)
#define leadzero(x) __builtin_clz(x)
#define trailzero(x) __builtin_ctz(x)
#define endl "\n"
#define elif else if
// =======================
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef map<int, int> mii;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}
int mpow(int base, int exp);
void yes() { cout << "YES\n"; }
void no() { cout << "NO\n"; }

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
// =======================
void solve()
{
    string s;
    cin >> s;
    int ans = 0;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') ans = 3;
    else if(s[0]=='R' && s[1]=='R' && s[2]!='R') ans = 2;
    else if(s[0]!='R' && s[1]=='R' && s[2]=='R') ans = 2;
    else if(s[0]!='R' && s[1]!='R' && s[2]!='R') ans = 0;
    else ans = 1;
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}


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

int main()
{
  string s;
  cin >> s;
  int i;
  for(i = 0; i < s.size(); i++)
  {
    if(s.at(i) == 'A')
    {
      break;
    }
  }
  int a = i;
  for(i = s.size()-1; i >= 0; i--)
  {
    if(s.at(i) == 'Z')
    {
      break;
    }
  }
  int z = i;
  cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int n,cnt[26];
string s;
ll ans=1;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	for (int i=0;i<n;++i) cnt[s[i]-'a']++;
	for (int i=0;i<26;++i) ans=(ans*(cnt[i]+1))%mod;
	cout<<(ans-1+mod)%mod;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int c=0;
	int l=s.length();
	for(int i=0;i<l/2;i++)
	{
		if(s[i]!=s[l-1-i])
		c++;
	}
	cout<<c<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

signed main() {
  int n;
  cin >> n;
  vector<int> w(n), s(n + 1, 0);
  for (auto&& u : w) cin >> u;
  rep(i, n) s[i + 1] = s[i] + w[i];
  int t = abs(s[n]);
  rep(i, n) t = min(t, abs(s[n] - 2 * s[i]));
  cout << t << endl;
}

Measured memory_bytes: 256
n=int(input())
ab = []
for _ in range(n):
    a=int(input())
    ab.append(a)

ans = 0

for i in range(n):
    ans += ab[i]//2
    if i == n-1:
        break
    elif ab[i]%2 == 1 and ab[i+1] > 0:
        ans += 1
        ab[i+1] -= 1
print(ans)

Measured memory_bytes: 51672
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,s;
    cin>>n>>s;
    ll size[n];
    ll value[n];
    for(ll i=0;i<n;i++)
        cin>>size[i]>>value[i];
    ll dp[n+1][s+1];
    for(ll i=0;i<n+1;i++)
    {
        for(ll j=0;j<s+1;j++)
        {
            if(i==0 || j==0)
                dp[i][j]=0;
        }
    }
    for(ll i=1;i<n+1;i++)
    {
        for(ll j=1;j<s+1;j++)
        {
            if(size[i-1]<=j)
            {
                //cout<<value[i-1]<<" value "<< dp[i-1][j-size[i-1]]<<endl;
                //cout<<value[i-1]+dp[i-1][j-value[i-1]]<<" val "<<dp[i-1][j]<<endl;
                dp[i][j]=max( value[i-1]+dp[i-1][j-size[i-1]], dp[i-1][j]);
            }
            else
                dp[i][j]=dp[i-1][j];
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    /*for(ll i=0;i<n+1;i++)
    {
        for(ll j=0;j<s+1;j++)
        {
            cout<<dp[i][j]<<" "<<;
        }
        cout<<endl;
    }*/
    cout<<dp[n][s];
    return 0;
}


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

int main() {
 int a, b, c, d, e, k;
 cin >> a >> b >> c >> d >> e >> k;
 if(e - a <= k){
    cout << "Yay!" << endl;
 }
 else {
    cout << ":(" << endl;
 }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void){

  int q;
  while( cin >> q ){
    if( q == -1 )break;
    if( q == 1 ){
      printf("1.000000");
      cout << endl;
      continue;
    }
    double x =  q / 2;
    while(1){
      if( abs(x*x*x - q) < 0.00001*q )break;
      x = x - ( x*x*x - q ) / ( 3*x*x );
    }
    printf("%.6f", x);
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
import scala.io.StdIn._
object Main extends App {
  val d = readInt
  val singleMark = readInt match {
    case 0 ⇒ Nil
    case x ⇒
      Array.tabulate(x) { _ ⇒
        val Array(a, p) = readLine.trim.split(' ')
        a → p.toInt
      }.filter(_._1 == "D").map(_._2).sorted(Ordering.Int.reverse).toList
  }
  val doubleMark = readInt match {
    case 0 ⇒ Nil
    case y ⇒
      Array.tabulate(y) { _ ⇒
        val Array(bc, p) = readLine.trim.split(' ')
        bc → p.toInt
      }.filter {_._1 == "DD"}.map(_._2).sorted(Ordering.Int.reverse).toList
  }
  println(
    solve(singleMark, doubleMark, d)
  )

  def solve(single: List[Int], double: List[Int], count: Int): Int = {
    (single, double) match {
      case (a::as, b::bs) if count > 1 ⇒
        math.max(solve(as, double, count - 1) + a, solve(single, bs, count - 2) + b)
      case (a::as, _) if count > 0 ⇒
        solve(as, double, count - 1) + a
      case (Nil, b::bs) if count > 1 ⇒
        solve(single, bs, count - 2) + b
      case _ ⇒ 0
    }
  }
}



Measured memory_bytes: 44140
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int LMAX=16;

int Damerau_Levenshtein(const char *s,const char *t,int INS=1,int DEL=1,int RPL=1,int SWP=1){
	int m=strlen(s),n=strlen(t);
	static int dp[LMAX+1][LMAX+1];

	rep(i,m+1) dp[i][0]=i*DEL;
	rep(j,n+1) dp[0][j]=j*INS;

	int s_last[128],t_last[128];
	memset(s_last,-1,sizeof s_last);
	rep(i,m){
		memset(t_last,-1,sizeof t_last);
		rep(j,n){
			int i1=s_last[t[j]],j1=t_last[s[i]];

			dp[i+1][j+1]=min(dp[i+1][j]+INS,dp[i][j+1]+DEL);
			dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(s[i]==t[j]?0:RPL));
			if(i1>=0 && j1>=0){
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i1][j1]+(i-i1-1)*DEL+SWP+(j-j1-1)*INS);
			}

			t_last[t[j]]=j;
		}
		s_last[s[i]]=i;
	}

	return dp[m][n];
}

int main(){
	for(int n,d;scanf("%d%d",&n,&d),n;){
		char s[200][20];
		rep(i,n) scanf("%s",s[i]);

		vector< pair<string,string> > ans;
		rep(i,n) rep(j,i) if(Damerau_Levenshtein(s[i],s[j])<=d) {
			if((string)s[i]<s[j]) ans.push_back(make_pair(s[i],s[j]));
			else                  ans.push_back(make_pair(s[j],s[i]));
		}
		sort(ans.begin(),ans.end());

		rep(i,ans.size()) printf("%s,%s\n",ans[i].first.c_str(),ans[i].second.c_str());
		printf("%d\n",ans.size());
	}

	return 0;
}

Measured memory_bytes: 1108
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
  char a[200],b[200];
    int fa[1000],fb[1000];
    cin>>a>>b;
    for(int i=0;i<strlen(a);i++)
    {
        fa[i]=a[i]-'a';
    }
    for(int i=0;i<strlen(b);i++)
    {
        fb[i]=b[i]-'a';
    }
    sort(fa,fa+strlen(a));
    sort(fb,fb+strlen(b));
    for(int i=0;i<strlen(a);i++)
    {
        a[i]=fa[i]+'a';
    }
    a[strlen(a)]='\0';
    for(int i=strlen(b)-1;i>=0;i--)
    {
        b[strlen(b)-i-1]=fb[i]+'a';
    }
    b[strlen(b)]='\0';

    if(strcmp(a,b)<0)cout<<"Yes\n";
    else cout<<"No\n";
   return 0;
}


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


public class Main{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;
        Main sol = new Main();
        while(t -- > 0)
        {
           double r = sc.nextDouble();
            out.println(2 * r * Math.PI);
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();
    }
    public String solve(String N){

        char [] c= N.toCharArray();
        int n = c.length;
        char [] c1 = new char[n], c2 = new char[n];
        for(int i = 0; i < n; i++)
        {
            c1[i] = (char)(c[i] - 1);
            if(c[i] == '4') {
                c2[i] = '1';
            }
            else c1[i]++;
        }
        boolean met = false;
        for(int i = 0; i < n; i++)
        {
            if(met) {
                if (c2[i] < '0')
                    c2[i] = '0';
            }
            else if(c2[i] > '0')
                met = true;
        }
        return new String(c1) + new String(c2).trim();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 33452
while True:
    count = 0
    n,x = map(int, input().split())
    if n == x == 0:
        break
    for i in range(1,n-1):
        for j in range(i+1,n):
            if ((x-i-j) > j) and (x-i-j) <= n:
                count += 1
    print(count)


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

int main() {
    ll k,n,i;//q;
    cin>>k>>n;
    ll a[n], d[n],s=0;
    for( i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for( i=0; i<n-1; i++)
    {
        d[i]=a[i+1]-a[i];
    }
    d[n-1]=a[0]+(k-a[n-1]);
    //cout<<a[n-1]<<d[n-1]<<endl;
     ll max=0;  
    for( i=0; i<n; i++)
    {
      if(d[i]>=max)
      max=d[i];
      s+=d[i];
    }
    cout<<s-max<<endl;
    
	return 0;
}


Measured memory_bytes: 3328
mod = pow(10, 9) + 7
def factorial(n):
    return fact[n]

N = pow(10, 5)  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    #inv.append((-inv[mod % i] * (mod // i)) % mod)
    #factinv.append((factinv[-1] * inv[-1]) % mod)

n = int(input())
print(factorial(n))


Measured memory_bytes: 7060
// V > Wだったら捕まえられる。
// V <= Wのとき、
// A == Bなら捕まえられる
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    if (V <= W) {
        cout << "NO" << endl;
        return 0;
    }

    if (abs(A - B) <= T * abs(V - W)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    LL n;
    cin >> n;
    if (n & 1) {
        cout << 0;
        return 0;
    }

    LL result = 0;
    for (LL x = 5; x <= n; x *= 5) {
        result += (n / x) / 2;
        if ((__int128) x * 5 > n) break;
    }
    cout << result << endl;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;

int N,Q;
struct node{
	int sz;
	bool ex;
	node *next [26];
};
node root;
int rel [100000] [26] [26];
int pref [100000];

void add(string& s)
{
	node *p = &root;
	FOR(i,0,s.size()){
		int key = s [i] - 'a';
		if(p->next [key] == nullptr){
			p->next [key] = new node();
		}
		p = p->next [key];
		p->sz++;
	}
	p->ex = true;
}

void pre_calc(string& s,int idx)
{
	node *p = &root;
	FOR(i,0,s.size()){
		int key = s [i] - 'a';
		if(p->ex) pref [idx]++;
		FOR(j,0,26){
			if(j == key) continue;
			if(p->next [j] != nullptr){
				rel [idx] [j] [key] += p->next [j]->sz;
			}
		}
		p = p->next [key];
	}
}

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

	cin >> N;
	vector<string> S(N);
	FOR(i,0,N){
		cin >> S [i];
		add(S [i]);
	}
	FOR(i,0,N){
		pre_calc(S [i],i);
	}

	cin >> Q;
	FOR(i,0,Q){
		int K;
		string T;
		cin >> K >> T;
		K--;
		int ans = pref [K] + 1;
		FOR(j,0,26){
			FOR(k,j + 1,26){
				ans += rel [K] [T [j] - 'a'] [T [k] - 'a'];
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 296192
inp = list(map(str, input().split()))
S = inp[0]
T = inp[1]
inp = list(map(int, input().split()))
A = inp[0]
B = inp[1]
U = str(input())

if S == U:
    A = A-1
else:
    B = B-1

print(str(A) + " " + str(B))


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()
	hlist := make([]int, n)
	num := 0
	for i := 0; i < n; i++ {
		hlist[i] = nextInt()
		if hlist[i] >= k {
			num++
		}
	}

	fmt.Println(num)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2864
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ld ans=0.000000;
	rep(i,1,n+1){
		ll val=i,cnt=0;
		while(val<k)cnt++,val=2*val;
		ans+=(ld)((ld)(1.000))/((ld)pow(2,cnt));
	}
	cout<<setprecision(20)<<ans/(ld)n;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
	int a, b, c, n, i;
	long long int d;
	b = -1000000;
	c = 1000000;
	d = 0;
	scanf("%d", &n);

	for (i = 1; i <= n; i = i + 1) 
	{
		scanf("%d", &a);

		if (c > a)
		{
			c = a;
		}
		if (b < a) 
		{ 
			b = a; 
		}

		d = d + a;
	}
	printf("%d %d %ld\n", c, b, d);
	return 0;
}


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



int main (void){
    int n;

    cin >> n;
    
    vector <int> p(n),q(n),c(n);

    rep(i,n){
        cin >>p[i];
    }

    rep(i,n){
        cin >>q[i];
    }
    rep(i,n){
        c[i]=i+1;
    }

    map<vector<int>,int> mp;

    do{
        mp[c]=mp.size();
    }
    while(next_permutation(c.begin(),c.end()));

    cout << abs(mp[p]-mp[q]) << endl;

    return 0;
}

Measured memory_bytes: 5248
import sys
from itertools import accumulate
MOD = 10 ** 9 + 7


n, k = map(int, sys.stdin.readline().split())

def main():
    a = range(n + 1)
    sl = list(accumulate(a))
    sr = list(accumulate(a[::-1]))

    res = 0
    for i in range(k, n + 2):
        res += sr[i-1] - sl[i-1] + 1
        res %= MOD
    print(res)



    
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 30420
#include<stdio.h>
int main()
{
	int a,b,c,d,n,kosuu=0;
	while(scanf("%d",&n)!=EOF)
	{
		kosuu=0;
		for(a=0; a<=9; a++)
		{
			for(b=0; b<=9; b++)
			{
				for(c=0; c<=9; c++)
				{
					for(d=0; d<=9; d++)
					{
						if(a+b+c+d==n)
							kosuu++;
					}
				}
			}
		}
		printf("%d\n",kosuu);
	}
	return 0;
}

Measured memory_bytes: 596
from operator import itemgetter

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

num = [''] * n

if m == 0:
    for i in range(n):
        num[i] = '0'
    if n != 1:
        num[0] = '1'
    print(''.join(num))
    exit()

sc = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))

last = sc[0][0]
num[last-1] = str(sc[0][1])
number = True

if last != 1:
    num[0] = '1'

for i in range(m):
    if n != 1 and sc[i][0] == 1 and sc[i][1] == 0:
        number = False
    if sc[i][0] == last and num[last-1] != '':
        if num[last-1] != str(sc[i][1]):
            number = False
    last = sc[i][0]
    num[last-1] = str(sc[i][1])

for i in range(n):
    if num[i] == '':
        num[i] = '0'

if number:
    print(''.join(num))
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for(int i = 0; i < h; i++)
        cin >> v[i];

    vector<bool> row(h, false);
    vector<bool> col(w, false);

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(v[i][j] == '#'){
                row[i] = true;
                col[j] = true;
            }
        }
    }
    for(int i = 0; i < h; i++){
        if(row[i]){
            for(int j = 0; j < w; j++){
                if(col[j])
                    cout << v[i][j];
            }
            cout << '\n';
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++ )
using namespace std;
int main() {
    long long n,m;
    cin >> n >> m;
    vector<long long> a(m);
    rep(i,m) cin >> a.at(i);
    rep(i,m){
        n -= a.at(i);
        if(n < 0){
            n = -1;
            break;
        }
    }
    cout << n << endl;

}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int P[N], res = 1e+6, pos = 0;
    REP(i, N){
        cin >> P[i];
        if (res >= P[i]){
            pos++;
        }
        res = min(res, P[i]);
    }

    cout << pos << endl;
}

Measured memory_bytes: 4396
my ($N,$M) = split(/\s+/,<>);
my @H = (0,split(/\s+/,<>));
my @flag;
for(my $i=0;$i<$M;$i++){
    my @dat = split(/ /,<>);
    if( $H[$dat[0]] >= $H[$dat[1]]  ){
        $flag[$dat[1]] = 1;
    }
    if( $H[$dat[1]] >= $H[$dat[0]]  ){
        $flag[$dat[0]] = 1;
    }
}
my $count =$N;
for(my $i=1;$i<=$N;$i++){
    if($flag[$i] == 1){
        $count--;
    }
}
print "$count";

Measured memory_bytes: 20080
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

def isOk(T):
    ret = 0
    for a, f in zip(A, F):
        ret += max(0, a - T // f)
    return ret <= K

ok = max(a * f for a, f in zip(A, F))
ng = -1
while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)


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

typedef long long ll;
typedef vector<int> vi;

#define PB push_back
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int arr[100000][3];
int n;
int dp[100000][3];
int rec(int row, int col)
{
    if(row == n-1)  return arr[n-1][col];
    if(dp[row][col]>0)
        return dp[row][col];
    else if(col==0)
        return dp[row][col]=arr[row][col]+max(rec(row+1,1),rec(row+1,2));
    else if(col==1)
        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,2));
    else if(col==2)
        return dp[row][col]=arr[row][col]+max(rec(row+1,0),rec(row+1,1));
}

int main()
{
    optimize();

    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    int x=max(rec(0,0),max(rec(0,1),rec(0,2)));
    cout<<x;
    return 0;
}


Measured memory_bytes: 10612
#include<stdio.h>

int main(void)
{
	char s;
	scanf("%c",&s);
	
	if(s=='A')
		printf("T");
	if(s=='T')
		printf("A");
	if(s=='G')
		printf("C");
	if(s=='C')
		printf("G");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>

#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX

typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;

const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;

using namespace std;

void solve()
{    
    int n ;
    cin>>n ;
    ll a[n] ;
    rep(i , n)cin>>a[i] ;   
    ll ans = 0 ; 
    ll pre = a[0] ;
    repu(i  ,1 , n-1){
        ans += max(pre - a[i] , 0LL) ;
        pre = max(pre , a[i]) ;
    }
    cout<<ans<<endl;
}
 
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
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    //  cin>>t;

    while(t--)
    {
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

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

int main() {
    int N,K;
    cin >> N >> K;
    int result = 0;
    
    for(int i = 0; i < N; i++)
    {
        int buf;
        cin >> buf;
        
        result += min(buf * 2,abs(buf - K) * 2);
    }
    
    cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

vector<vector<int>> sips(200009);

int main() {
    int N, M;
    cin >> N >> M;
    
    rep(i,M){
        int a, b; scnd2(a,b);
        sips[a].push_back(b);
        sips[b].push_back(a);
    }
    
    bool ans=false;
    queue<int> q;
    rep(i,sips[1].size()){
        if(sips[1][i]==N) ans=true;
        q.push(sips[1][i]);
    }
    
    if(!ans){
        rep(i,q.size()){
            int u = q.front(); q.pop(); q.push(0);
            rep(j,sips[u].size()){
                if(sips[u][j]==N) ans=true;
            }
        }
    }
    
    if(ans){
        cout1("POSSIBLE");
    }else{
        cout1("IMPOSSIBLE");
    }
}


Measured memory_bytes: 12400
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	char bun[25] = {};
	int len;
	cin >> bun;
	len=strlen(bun);
	for(int i=len-1;i>=0;i--){
		cout<<bun[i];
	}
	cout<<endl;
	return 0;
}



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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

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

  int ac=0,wa=0,tle=0,re=0;

  char tmp[100001][5];
  for(int i = 0; i < n; ++i){
    scanf("%s",tmp+i);
    if(strcmp(tmp[i],"AC") == 0)ac ++;
    else if(strcmp(tmp[i],"WA") == 0)wa ++;
    else if(strcmp(tmp[i],"TLE") == 0)tle ++;
    else if(strcmp(tmp[i],"RE") == 0)re ++;
  }

  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);

  return 0;
}


Measured memory_bytes: 2216
/* AtCoder Beginner Contest abc130
 * Problem E
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

const long long int p = 1000000007;

long long int f[2001][2001];

int main(void) {
	int n, m;
	cin >> n >> m;
	vector <int> s(n), t(m);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> t[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			f[i][j] = (f[i][j - 1] + f[i - 1][j] + (s[i - 1] == t[j - 1] ? 1 : -f[i - 1][j - 1]) + p) % p;
		}
	}
	cout << (1 + f[n][m]) % p << endl;
	return 0;
}



Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <algorithm>
using namespace	std;
int main(){

  int n,m;
  string s[100];
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>s[i];
  sort(s,s+n);
  for(int i=0;i<n;i++) cout<<s[i];
  cout<<endl;
  return 0;

}






Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int INF = 100000000;
struct Vec{
	int ind;
	int val;
};

bool valDesc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val> right.val: left.val > right.val;
}

bool valAsc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val <  right.val: left.val < right.val;
}
long gcd(long x, long y)
{
    long r;

    while((r = x % y) != (long)0)
    {
        x = y;
        y = r;
    }
    return y;
}

long lcm(long x, long y)
{
    return (x * y / gcd(x, y));
}

int main(void){
	long N,M,ans=long(-1);
	string S,T;
	cin >> N >> M;
	cin >> S;
	cin >> T;
	long l = lcm(N,M);
	int i = 0;
	for(i=0;i< int(N/(l/M));i++){
		if(S[i*(l/M)] != T[i*(l/N)]){
			printf("%ld\n",ans);
			fflush(stdout);
			return 0;
		}
	}
	ans = l;
	printf("%ld\n",ans);
	fflush(stdout);
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	if ((N / 100) % 10 == (N / 10) % 10 && ((N / 1000) % 10 == (N / 100) % 10 || (N / 10) % 10 == N % 10)) cout << "Yes";
	else cout << "No";
	return 0;
}

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

int N,K;
long long int a[100005];

long long int L[100005], R[100005], S[100005];

int main(void) {
	cin >> N >> K;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= N; i++) {
		S[i] = a[i] + S[i - 1];
	}

	for (int i = 1; i <= N; i++) {
		if (a[i] >= 0) { L[i] = a[i] + L[i - 1]; }
		else { L[i] = L[i - 1]; }
	}

	for (int i = N; i >= 1; i--) {
		if (a[i] >= 0) { R[i] = a[i] + R[i + 1]; }
		else { R[i] = R[i + 1]; }
	}

	long long int ans = -2000000000000000;

	for (int i = 1; i <= N - K + 1; i++) { //black
		long long int tmp;
		tmp = L[i - 1] + S[i + K-1] - S[i - 1] + R[i + K];
		ans = max(ans, tmp);
	}
	for (int i = 1; i <= N - K + 1; i++) {//white
		long long int tmp;
		tmp = L[i - 1]  + R[i + K];
		ans = max(ans, tmp);
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int N;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    cout<<N/3<<endl;
    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;

	long long dp[200090];

int main(){

	memset(dp,63,sizeof dp);
	long long deff = dp[0];

	int n; cin >> n;
	long long w; cin >> w;
	
	for(int i = 0; i < n; i++){
		int val;
		long long wei; cin >> wei >> val;
		for(int i = 100090; i >= 0; i--){
			if(dp[i] == deff) continue;
			else dp[i + val] = min(dp[i] + wei , dp[i + val]);
		//	cout << i + val << " " << dp[i + val] << endl; system("pause");
		}
		dp[val] = min(wei,dp[val]);
	}
	
	int sol = 0;
	for(int i = 0; i < 100090; i++){
		if(dp[i] <= w) sol = max(i ,sol);
	} cout << sol;
	



	return 0;
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

inline bool is_in_one_to_nine(const int n) {
    return 1 <= n && n <= 9;
}

int main() {
    int n;
    cin >> n;
    int sq_n = sqrt(n) + 1;
    str ans = "No";
    FOR(i, 1, 10) {
        if(n % i == 0 && is_in_one_to_nine(n / i)) {
            ans = "Yes";
            break;
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>

using namespace std;

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

int n,d[100000];
P p[100000];
set<int> c,g;
set<P> s;
ll yen=0;
priority_queue<P, vector<P>, greater<P> > q;


int dist(int a, int b){
    return min(abs(p[a].first-p[b].first), abs(p[a].second-p[b].second));
}

void f(int z){
    g.insert(z); //
    c.erase(z);
    if(z-1>=0&&z-1<n){
        if(g.find(z-1)==g.end()){
            c.insert(z-1);
            d[z-1]=min(d[z-1], dist(z-1, z));
            q.push(P(d[z-1], z-1));
        }
    }
    if(z+1>=0&&z+1<n){
        if(g.find(z+1)==g.end()){
            c.insert(z+1);
            d[z+1]=min(d[z+1], dist(z+1, z));
            q.push(P(d[z+1], z+1));
        }
    }
    auto itrZ=s.find(P(p[z].second, z));
    if(itrZ!=s.end()){
        auto itrP=itrZ;
        itrP++;
        if(itrP!=s.end()){
            int zp=(*itrP).second;
            if(g.find(zp)==g.end()){
                c.insert(zp);
                d[zp]=min(d[zp], dist(zp, z));
                q.push(P(d[zp], zp));
            }
        }
        if(itrZ!=s.begin()){
            itrZ--;
            int zp=(*itrZ).second;
            if(g.find(zp)==g.end()){
                c.insert(zp);
                d[zp]=min(d[zp], dist(zp, z));
                q.push(P(d[zp], zp));
            }
        }
    }
}

int main(void){
    cin>>n;

    fill(d, d+n,1e9+7);
    for(int i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p, p+n);
    for(int i=0;i<n;i++){
        s.insert(P(p[i].second, i));
    }
    f(0);

    while(!c.empty()&&!q.empty()){
        P can=q.top();
        q.pop();
        int ind=can.second,cost=can.first;
        if(g.find(ind)==g.end()){
            f(ind);
            yen+=(ll)cost;
            //cout<<"---("<<ind<<")+"<<cost<<endl;
        }

        //break;
    }

    cout<<yen<<endl;
}


Measured memory_bytes: 11508
#include<bits/stdc++.h>
/*
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<ctime> 
*/
#define ll long long
using namespace std;
const int N=1e5 + 100;
const double eps=1e-10;
ll cnt[N],a[N];
int main(){
	int n;
	memset(cnt,0,sizeof(cnt));
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		ans+=a[i];
		cnt[a[i]]++;
	}
	int q;
	scanf("%d",&q);
	ll x,y;
	for(int i=1;i<=q;i++){
		scanf("%lld%lld",&x,&y);
		cnt[y]+=cnt[x];
		ans+=(y-x) * cnt[x];
		cnt[x]=0;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 5392