akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>
using namespace std;
#define int long long int
vector<int> edge[100005];
int n, m;
int dp[100005] = {};
int solve(int src)
{
	if (dp[src] != -1)
		return dp[src];
	bool leaf = 1;
	int maxlen = 0;
	for (auto x : edge[src])
	{
		leaf = 0;
		maxlen = max(solve(x), maxlen);
	}
	return dp[src] = (leaf) ? 0 : (1 + maxlen);
}
int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	memset(dp, -1, sizeof(dp));
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int x, y; cin >> x >> y;
		edge[x].push_back(y);//1 based indexing
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(ans, solve(i));
	}
	cout << ans;
	return 0;
}
// 4 5
// 1 2
// 1 3
// 3 2
// 2 4
// 3 4

Measured memory_bytes: 8576
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a <= b:
   x = 1
else:
   x = -1

ag = a + x * v * t
bg = b + x * w * t

if x == 1:
   if ag >= bg:
      print('YES')
   else:
      print('NO')
else:
   if ag <= bg:
      print('YES')
   else:
      print('NO')


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll K, A, B;
  cin >> K >> A >> B;

  ll ans= 1 + K;

  {
    ll tmp = A;
    if ((K - A + 1) % 2 == 0) {
      tmp += (B - A) * ((K - A + 1) / 2);
    } else {
      tmp += (B - A) * ((K - A + 1) / 2) + 1;
    }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll x){ cout << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

ll INF = 1e9+7;

ll modinv(ll a, ll m){
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=m;
    if(u<0){ u+=m; }
    return u;
}

ll modpow(ll a, ll n, ll m){
    ll ret=1;
    while(n>0){
        if(n&1){ ret=ret*a%m; }
        a=a*a%m;
        n>>=1;
    }
    return ret;
}

ll modC(ll n, ll k){
    const ll L=1e6;
    static ll fact[L], rfact[L];
    if(k==0) return 1;
    if(fact[0]==0){
        fact[0]=1;
        REP(i,1,L){                                                     
            fact[i]=(i*fact[i-1])%INF;
        }
    }
    return ((fact[n]*modinv(fact[n-k],INF))%INF*modinv(fact[k],INF))%INF;
}

ll modH(ll n, ll k){
    return modC(n+k-1,n-1);
}

int main(){
    ll N, K;
    ii(N), ii(K);
    ll ans=0;
    REP(i,0,min(N,K+1)){
        ans+=modC(N,i)*modH(N-i,i);
        ans%=INF;
    }
    oie(ans);

    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
char d[1000010];
int w,h,dd[1000010],p[1000010]={0};
void u(int i,int j){
  int a,b,k,x,y;
  int X[]={0,1,0,-1};
  int Y[]={1,0,-1,0};
  for(k=0;k<4;k++){
    y=i+Y[k];
    x=j+X[k];
    if(y<0||x<0||w==x||h==y||d[y*1000+x]=='#')continue;
    for(a=i*1000+j+1;p[a];a=p[a]);
    for(b=y*1000+x+1;p[b];b=p[b]);
    if(a-b){
      if(dd[a]< dd[b]) p[a]=b;
      if(dd[a]>=dd[b]) p[b]=a;
      if(dd[a]==dd[b])dd[b]++;
    }
  }
}
int main(){
  int a,b,c,n,i,j,k,mi,mj;
  scanf("%d %d",&w,&h);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf(" %c",&d[i*1000+j]);
      if(d[i*1000+j]=='t')d[mi=i*1000+j]='.';
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(d[i*1000+j]=='#')continue;
      u(i,j);
    }
  }
  scanf("%d",&n);
  for(c=0;c<=n;c++){
    for(a=1;p[a];a=p[a]);
    for(mj=mi+1;p[mj];mj=p[mj]);
    if(mj==a){
      printf("%d\n",c);
      break;
    }
    if(c==n){
      printf("-1\n");
      break;
    }
    scanf("%d %d",&j,&i);
    if(d[i*1000+j]=='.')continue;
    d[i*1000+j]='.';
    u(i,j);
  }
  while(c++<n)scanf("%*d %*d");
  return 0;
}
   

Measured memory_bytes: 9388
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++) 
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++) 
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;
//const ll INF = mod * mod;
//const double pi = 3.14159265358979;

int main() {
    int n,m;
    cin >> n >> m;
    vii s(m);
    rep(i,m) {
        int k;
        cin >> k;
        s[i].resize(k);
        rep(j,k) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vi p(m);
    rep(i,m) cin >> p[i];
    int ans = 0;
    for(int i = 0; i < (1 << n); i++) {
        bool ok = true;
        rep(j,m) {
            int c = 0;
            for(auto x : s[j]) {
                if((i >> x) & 1) c++;
            }
            c %= 2;
            if(c != p[j]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << "\n";
}

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

int main() {
  string S;
  cin >> S;
  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < S.size(); i++) {
    if ((S[i] == '1' && i % 2 == 0) || (S[i] == '0' && i % 2 == 1)) ans1++;
    if ((S[i] == '0' && i % 2 == 0) || (S[i] == '1' && i % 2 == 1)) ans2++;
  }
  cout << min(ans1, ans2) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
typedef long long ll;
const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;

using namespace std;
    
int swith[100];
bool a[12][20];
int p[20];
int n,m;
int cnt = 0;
void solve(int i)
{

if(i == n)
	 {
	 	int check = 0;
	 	for(int j = 0 ; j < m ; j++)
	 	{    int tmp = 0;
	 		for(int k = 0 ; k < n ; k++)
	 		{
	 			if(a[j][k] and swith[k])
	 				  ++tmp;
	 		}
	 		check+=((tmp % 2) == p[j]);
	 	}

	 	if(check == m)
	 		  ++cnt;

	    return ;
	 }


solve(i + 1);
swith[i] = 1;
solve(i + 1);
swith[i] = 0;


}

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

for(int i = 0 ; i < m ; i++)
{
	int k;
	cin >> k;
	while(k--)
	{
		int x;
		cin >> x;
		a[i][x - 1] = 1;
	}
}
for(int i = 0 ; i < m ; i++)
 cin >> p[i];
solve(0);

cout << cnt ;


}


Measured memory_bytes: 384
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

len_hour_hand, len_minute_hand, hour, minute = map(int, input().split())

d_short = hour / 12 + (minute / 60) / 12
d_long = minute / 60
# print(f'd_long = {d_long}, d_short: {d_short}')

degrees = 360 * abs(d_long - d_short)
degrees = min(degrees, 360 - degrees)
radians = math.radians(degrees)

res = len_minute_hand ** 2 + len_hour_hand ** 2 - 2 * len_minute_hand * len_hour_hand * math.cos(radians)
print(math.sqrt(res))


Measured memory_bytes: 69004
require 'prime'

def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end

def divisors(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

def main
  n = gets.to_i
  list = divisors(n)
  while list.size > 2
    list.delete_at 0
    list.delete_at -1
  end
  puts list[-1].to_s.size
end

main



Measured memory_bytes: 14244
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	char a;
	int c[26] = {};
	while (cin>>a) {
		a=tolower(a);
		if (isalpha(a)) {
			c[a - 'a'] ++;
		}
	}
	for (int i = 0; i < 26; i++)
	{
		printf("%c : %d\n", i + 'a', c[i]);
	}
}

Measured memory_bytes: 3132
count = 0
s = ""
array =[]
while True:
    count += 1
    if count == 1:
        s = input()
    n = input()
    if n == "END_OF_TEXT":
        break
    array.append(n)
count = 0
for i in range(len(array)):
    for i2 in array[i].split():
        if s.upper() == i2.upper() or s.lower() == i2.lower():
            count += 1
print(count)

Measured memory_bytes: 7492
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}


//小さい順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//変換(文字から整数)
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

//要素数
int HM(char a[]){
    int cnt=0;
    while(a[cnt]!=0){
        cnt++;
    }
    return cnt;
}

int main(void){
    char stp[100];
    scanf("%s",stp);
    int size=0;
    size=HM(stp);
    for(int i=0;i<size;i+=2){
        if(stp[i]!='R'&&stp[i]!='U'&&stp[i]!='D'){
            printf("No");
            return 0;
        }
    }
    for(int i=1;i<size;i+=2){
        if(stp[i]!='L'&&stp[i]!='U'&&stp[i]!='D'){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    
    
}

    




Measured memory_bytes: 128
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//#undef _GLIBCXX_DEBUG //(compiler options)
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using namespace std;
using ll = long long; using ull = unsigned ll; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>;
template<typename T> T mind(T &x, const T &y) {if (y < x) {T d = y-x; x = y; return d;} else return 0;} //RETURNS A NON-POSITIVE VALUE
template<typename T> T maxd(T &x, const T &y) {if (y > x) {T d = y-x; x = y; return d;} else return 0;}
const int mod = 1e9+7, mod9 = 1e9+9, infi = 1e9+100; const ll infl = 1e18L+1000, modl = 1e18L+3; const ld infd = INFINITY;

#define x(a) real(a)
#define y(a) imag(a)
using G = ll; using point = complex<G>;
istream& operator>>(istream &is, point &p){G x, y; is >> x >> y; p = {x, y}; return is;}
ostream& operator<<(ostream &os, const point &p){os << p.x() << ' ' << p.y(); return os;}
G dot(const point &a, const point &b) {return (conj(a)*b).x();}
G crs(const point &a, const point &b) {return (conj(a)*b).y();}
G ori(const point &a, const point &b, const point &c) {return crs(b-a, c-b);};
bool cmpyx(const point &a, const point &b) {return a.y()<b.y() || (a.y()==b.y()&&a.x()<b.x());};

int32_t main()
{
    #ifndef LOCAL
    //ifstream cin("hull.in"); ofstream cout("hull.out");
    #endif // LOCAL
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(15);
    string s; cin >> s;
    int n = sz(s);
    int c = s[n/2];
    int i = n/2;
    while(i < n && s[i] == c && s[n-1-i] == c) ++i;
    cout << i;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main(void)
{
  char a[10001]={}; 
  while(scanf("%s",a)!=EOF){
    int j=0,i=0;
    int n,l;
    l=strlen(a);
    for(n=0;n<l-2;n++){
      if(a[n]=='J'&&a[n+1]=='O'&&a[n+2]=='I')
	j++;
      if(a[n]=='I'&&a[n+1]=='O'&&a[n+2]=='I')
	i++;
    }
    printf("%d\n%d\n",j,i);
  }

  return 0;
}

Measured memory_bytes: 560
import sys
import math

if __name__ == "__main__":
    A,B = map(float, input().split())
    for i in range(1, 2001):
        n1 = math.floor(i * 0.08)
        n2 = math.floor(i * 0.1)
        if n1 == A and n2 == B:
            print(i)
            exit()
    print(-1)




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

int main(){
	vector<int> a,b;
	int n,m;
	cin>>n;
	lp(i,n){
		int hoge;
		cin>>hoge;
		a.push_back(hoge);
	}
	cin>>m;
	lp(i,m){
		int hoge;
		cin>>hoge;
		b.push_back(hoge);
	}
	vector<int> ans;
	set_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(ans,ans.end()));
	for_each(ans.begin(),ans.end(),[](int hoge){ cout<<hoge<<endl;});
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll h,w,n;
set<vl> s;
ll l[e5];
ll ans;

int main(){
  cin >> w >> h >> n;
  for(ll i = 0;i < n;i++){
    vl p(2);
    cin >> p[1] >> p[0];
    s.insert(p);
  }
  for(ll i = 1;i <= h;i++){
    s.insert(vl({i,w+1}));
  }
  ans = w;
  l[1] = 1;
  for(ll i = 2,j = 1;i <= w;i++){
    if(s.count(vl({j+1,i})) == 0) j++;
    l[j] = i;

  }
  for(ll i = 1;i <= h;i++){
    if(l[i] == 0) break;
    vl p = *s.lower_bound(vl({i,l[i]}));
    // cerr << i << " " << l[i] << " " << p[0] << " " << p[1] << endl;
    ans = min(ans,p[1]-1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 39040
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	a := make(map[int]int)
	
	tmp := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		a[tmp]++
	}
	
	cnt := 0
	for _,v := range a {
		if v % 2 != 0 {
			cnt++
		}
	}
	//fmt.Println(a)
	fmt.Println(cnt)
}

Measured memory_bytes: 9668
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            int[] jousi= ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] buka = Enumerable.Repeat(0,N).ToArray();
            foreach(int i in jousi)
            {
                buka[i - 1] += 1;
            }
            foreach(int i in buka)
            {
                WriteLine(i);
            }
        }
    }
}

Measured memory_bytes: 40112
#include<bits/stdc++.h>
int R,C,n,ip=0;
int get(int x,int y){
	if(!y)return x;
	if(x==R)return R+y;
	if(y==C)return R+C+R-x;
	if(!x)return R+C+R+C-y;
	return -1;
}
struct edge{
	int x,t,id;
	bool operator<(const edge&w)const{return x<w.x;}
}e[200007];
int ss[100007],sp=0,ep=0;
int main(){
	scanf("%d%d%d",&R,&C,&n);
	for(int i=1,x1,y1,x2,y2;i<=n;++i){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int a=get(x1,y1),b=get(x2,y2);
		if(a>=0&&b>=0){
			if(a>b)std::swap(a,b);
			e[ep++]=(edge){a,1,i};
			e[ep++]=(edge){b,-1,i};
		}
	}
	std::sort(e,e+ep);
	ss[0]=-1;
	for(int i=0;i<ep;++i){
		if(e[i].t>0)ss[++sp]=e[i].id;
		else if(ss[sp--]!=e[i].id)return puts("NO"),0;
	}
	return puts("YES"),0;
}

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

int ar[1005];

int main(){
	int n,k,ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>ar[i];
	sort(ar,ar+n);
	for(int i=0;i<k;i++)
		ans+=ar[i];
	cout<<ans;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>

using namespace std;

#define _C

#ifdef _C

int main(void)
{
	int A, B, C, D, E, F;
	int maxw = 0, maxs  = 0;
	float rat = -1;
	cin >> A >> B >> C >> D >> E >> F;
	//set<int> xarr,yarr;
	//for (size_t a = 0; 100 * a*A <= F; a++)
	//	for (size_t b = 0; 100 * a*A + 100 * b*B <= F; b++)
	//	{
	//		xarr.insert(100 * a*A + 100 * b*B);
	//	}
	//for (size_t c = 0; c*C   <= F; c++)
	//	for (size_t d = 0; d*D + c*C <= F; d++)
	//	{
	//		yarr.insert(d*D + c*C);
	//	}



	for (size_t a = 0; 100*a*A  <= F; a++)
		for (size_t b = 0; 100*a*A + 100*b*B <= F; b++)
			for (size_t c = 0; 100 * a*A + 100 * b*B + c*C <= F; c++)
				for (size_t d = 0; 100 * a*A + 100 * b*B + c*C + d*D <= F; d++)
				{
					//if (c + d == 0) continue;
					if (a + b == 0) continue;

					int sum_wa = (a*A + b*B)*100;
					int sum_sug = c*C + d*D;
					int sum = sum_wa + sum_sug;
					float crat = (float)(c*C + d*D) / sum;



					if (sum_sug > E*(a*A + b*B))break;
					if (rat > crat) continue;

					rat = crat;


					maxw = sum;
					maxs = sum_sug;
				}

	cout << maxw << " " << maxs << endl;

	return 0;
}


#endif // C

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    ll a,b;
    cin >> a >> b;
    ll c,d;
    cin >> c >> d;
    ll Max =  a*c;
    Max = max(Max , a*d);
    Max = max(Max , b*d);
    Max = max(Max , b*c);
    cout << Max << endl;
}

Measured memory_bytes: 3588
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		ArrayList<Integer> n = new ArrayList<Integer>();
		for (int i = 0; i < 3; ++i) {
			n.add(s.nextInt());
		}
		Collections.sort(n);
		System.out.printf("%d %d %d\n", n.get(0), n.get(1), n.get(2));
	}
}

Measured memory_bytes: 17244
#include <iostream>
#include <cstdio>

#define F(i, a, b) for (LL i = a; i <= b; i ++)
#define G(i, a, b) for (LL i = a; i >= b; i --)
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define mem(a, b) memset(a, b, sizeof a)
#define mn(a, b) ((a) = min(a, b))
#define mx(a, b) ((a) = max(a, b))
#define sf scanf
#define pf printf
#define bb puts("")

typedef long long LL;

using namespace std;

const LL N = 1e5 + 10;

LL n, m, Ans, Max;
LL a[N], S[N], T[N];

LL Doit(LL x, LL y) {
	return y >= x ? y - x : y + m - x;
}

int main() {
	sf("%lld %lld", &n, &m);
	F(i, 1, n) sf("%lld", &a[i]);
	F(i, 1, n - 1) {
		LL w = Doit(a[i], a[i + 1]);
		if (a[i + 1] > a[i]) {
			LL v = w - (a[i + 1] /* - T */ + 1);
			S[a[i] + 1] += v, S[a[i + 1] + 1] -= v;
			T[a[i] + 1] += 1, T[a[i + 1] + 1] -= 1;
		}
		else
		{
			LL v = w - (a[i + 1] + m + 1);
			// a[i] + 1 .. m
			S[a[i] + 1] += v, S[m + 1] -= v;
			T[a[i] + 1] += 1, T[m + 1] -= 1;

			// 0.. a[i + 1]
			v = w - (a[i + 1] + 1);
			S[0] += v, S[a[i + 1] + 1] -= v;
			T[0] += 1, T[a[i + 1] + 1] -= 1;
		}
		Ans += w;
	}
	F(i, 0, m) {
		S[i] += S[i - 1], T[i] += T[i - 1];
		mx(Max, S[i] + T[i] * i);
	}
	pf("%lld\n", Ans - Max);
}

Measured memory_bytes: 2560
from collections import *
N = int(input())
G = [[] for n in range(N)]
for n in range(N-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

color = N*[0]
color[0] = 1
color[N-1] = -1
q = deque([])
q.append(0)
q.append(N-1)

while q:
  node = q.popleft()
  c = color[node]
  for to in G[node]:
    if color[to]==0:
      color[to] = c
      q.append(to)

b = color.count(1)
w = color.count(-1)

if w<b:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 26856
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  if(a > b)cout << 0 << endl;
  else if(n == 1 && (a != b))cout << 0 << endl;
  else if(n == 1)cout << 1 << endl;
  else cout << (n - 2) * (b - a) + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	    scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int l=1,r=0;
	int ans=0;
//	for(int i=1;i<=n;++i) 
//	   cout<<a[i]<<" ";
//	  cout<<endl; 
	while(r!=n)
	{
		++r;
		if(a[r] != a[l] || r==n)
		{
			int t=r-l;
			//cout<<r<<" "<<l<<" "<<t<<" "<<a[l]<<endl;
			if(r==n) ++t;
			if(t >= a[l])  ans+=t-a[l];
			else ans+=t;
			//cout<<ans<<endl;
			l=r;
		}
	}   
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4196
import java.util.Scanner;
public class Main {
  
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long n = stdIn.nextLong();
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		
		long c = a + b;
		
		long cnt = n / c;
		
		long ans = (n/(a+b))*a;
		
		long rem = n % (a+b);
		
		System.out.println(ans+Math.min(a,rem));
		
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, h;
    int ans = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int numOfCards = stdIn.nextInt();
  
        boolean[] spadeCardsExitsance = new boolean[13];
        boolean[] hartCardsExitsance = new boolean[13];
        boolean[] clubCardsExitsance = new boolean[13];
        boolean[] diamondCardsExitsance = new boolean[13];
  
        for(int i = 0; i < numOfCards; i++) {
            String suit = stdIn.next();
            int rank = stdIn.nextInt();
              
            switch(suit) {
            case "S":
                spadeCardsExitsance[rank - 1] = true;
                break;
            case "H":
                hartCardsExitsance [rank - 1] = true;
                break;
            case "C":
                clubCardsExitsance [rank - 1] = true;
                break;
            case "D":
                diamondCardsExitsance [rank - 1] = true;
                break;
            default:
                break;
            }
        }
  
        for(int i = 0; i < 13; i++) {
            if(!spadeCardsExitsance[i]) {
                System.out.println("S " + (i + 1));
            }
        }
        for(int i = 0; i < 13; i++) {
            if(!hartCardsExitsance[i]) {
                System.out.println("H " + (i + 1));
            }
        }
        for(int i = 0; i < 13; i++) {
            if(!clubCardsExitsance[i]) {
                System.out.println("C " + (i + 1));
            }
        }
        for(int i = 0; i < 13; i++) {
            if(!diamondCardsExitsance[i]) {
                System.out.println("D " + (i + 1));
            }
        }
    }
}

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

using namespace std;


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

    if (n % 2 == 0) {
        string s;
        cin >> s;

        vector<string> vec(n);

        for (int i = 0; i < s.length(); ++i) {
            vec[i] = s[i];
        }

        string temp1, temp2;
        for (int i = 0; i < vec.size() / 2; ++i) {
            temp1 += vec[i];
        }
        reverse(vec.begin(), vec.end());
        for (int i = 0; i < vec.size() / 2; ++i) {
            temp2 += vec[i];
        }

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

        if (temp1 == temp2) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

	int A = scan.nextInt();
	int B = scan.nextInt();
	int C = scan.nextInt();

	int r = A % B;
	String ans = "NO";
	for(int i=0; i<B; i++) {
	    if(i*r % B == C) {
		ans = "YES";
		break;
	    }
	}
	System.out.println(ans);
	scan.close();
    }
}


Measured memory_bytes: 22992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const ll mod=1e9+7;
ll n,k;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
ll F[N],I[N];
void init(){
    F[0]=1;
    for(ll i=1;i<=N;i++){
        F[i]=F[i-1]*i%mod;
    }
    I[N]=power(F[N],mod-2);
    for(ll i=N;i--;){
        I[i]=I[i+1]*(i+1)%mod;
    }
}

ll C(ll n, ll k){
    return F[n]*I[n-k]%mod*I[k]%mod;
}

int main(){
    init();
    cin>>n>>k;
    ll sum=0;
    for(ll i=0;i<n&&i<=k;i++){
       sum=(sum+C(n,i)*C(n-1,i))%mod;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    sort(d.begin(),d.end());
    int left = d[n/2-1];
    int right = d[n/2];
    int ans = 0;

    for(int i = left+1;i<=right;i++) {
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', chunk => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const lake = Number(inputs[0].split(' ')[0]);
  const house = inputs[1].split(' ').map(Number);
  let max = 0;

  for (let i = 0; i < house.length; i++) {
    let span;
    if (!house[i + 1]) {
      span = lake - house[i] + house[0];
    } else {
      span = house[i + 1] - house[i];
    }
    max = Math.max(max, span);
  }

  console.log(lake - max);
}


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

int main(){
  string s;
  cin >> s;
  string sv = s;
  reverse(sv.begin(), sv.end());
  int count = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) != sv.at(i)) count++;
  }
  cout << count / 2;
}


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

int main(){
  double q,x,d;
  while(cin>>q&&q!=-1){
    d=0.00001*q;
    x=q/2;
    while(1){
      x=x-(x*x*x-q)/(3*x*x);
      if(fabs(x*x*x-q)<d) break;
    }
    cout<<fixed<<setprecision(6)<<x<<endl;
  }
  return 0;
}

Measured memory_bytes: 1276
N=int(input())
P= list(map(float,input().split()))
ans=[[0 for e in range(2*N+3)] for f in range(N+1)]
ans[0][N+1]=1
for n in range(1,N+1):
 for i in range(N+1-n,N+2+n):
  ans[n][i]=ans[n-1][i-1]*P[n-1]+ans[n-1][i+1]*(1-P[n-1])
t=0
for i in range(N+1,2*N+3):
 t+=ans[N][i]
print(t)


Measured memory_bytes: 482696
import Control.Applicative
import Data.Foldable

gcdmul :: [Int]->Int
gcdmul (x:[]) = x
gcdmul (x:xs) = foldl' gcd x xs

solver :: Int->[Int]->Bool
solver k as
    |k > (maximum as) = False
    |otherwise = k `rem` (gcdmul as) == 0
    
myshow True = "POSSIBLE"
myshow False = "IMPOSSIBLE"
 
main :: IO ()
main = do
    [_, k] <- map read . words <$> getLine
    as <- map read . words <$> getLine
    putStrLn $ myshow $ solver k as



Measured memory_bytes: 36220
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<i64> = vec![0; n + 1];
    for i in 0..n {
        let x: i64 = sc.cin();
        xs[i + 1] = xs[i] + x;
    }
    xs.sort();
    let mut ans: u64 = 0;
    {
        let mut last = xs[0];
        let mut count: u64 = 1;
        for i in 1..n+1 {
            if last == xs[i] {
                count += 1;
            } else {
                ans += count * (count - 1) / 2;
                count = 1;
                last = xs[i];
            }
        }
        ans += count * (count - 1) / 2;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 18056
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	auto temp = 2 * D + 1;
	auto result = N / temp;
	if (N % temp > 0)
	{
		++result;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
ma = 0
str1 = {}
ans=[]
for i in range(n):
	s = str(input())
	try:
		str1[s]+=1
	except:
		str1[s]=1
	if ma < str1[s]:
		ma=str1[s]
sorted(str1.items(),key=lambda x: x[1],reverse=True)
for item,val in str1.items():
	if ma==val:
		ans.append(item)
for i in sorted(ans):
	print(i)


Measured memory_bytes: 43228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);

        var dist = Enumerable.Repeat(long.MaxValue, n).ToList(); // 開始点からの距離dist

        if (Bellman_ford(n, 0, m, dist)) Console.WriteLine("inf");
        else Console.WriteLine(-dist[n - 1]);
    }

    static bool Bellman_ford(int n, int s, int m, List<long> dist)
    {
        // グラフの受け取りはこっちでやる
        // a→b(コストc)
        string[] cin;
        int[] a = new int[m];
        int[] b = new int[m];
        long[] c = new long[m];
        for (long i = 0; i < m; i++)
        {
            cin = Console.ReadLine().Split();
            a[i] = int.Parse(cin[0]) - 1;
            b[i] = int.Parse(cin[1]) - 1;
            c[i] = -long.Parse(cin[2]);
        }

        dist[s] = 0;

        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
                    dist[b[j]] = dist[a[j]] + c[j];
            }
        }

        var dist2 = new List<long>(dist);

        bool[] negative = new bool[n];

        for (int j = 0; j < m; j++)
        {
            if (dist2[a[j]] != long.MaxValue && dist2[b[j]] > dist2[a[j]] + c[j])
            {
                dist2[b[j]] = dist2[a[j]] + c[j];
                negative[b[j]] = true;
            }
            if (negative[a[j]]) negative[b[j]] = true;
        }

        if (negative[n - 1]) return true;
        else return false;
    }
}


Measured memory_bytes: 11416
#include<stdio.h>
int main(void){
   int x,i = 1,g;
   while(1)
   {
       scanf("%d",&x);
       if(x == 0)
       {
           break;
       }
       printf("Case %d: %d\n",i,x);
       i++;
   }

    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

bool kaibun(string s) {
  string a = s.substr(0, s.size()/2);
  string b = s.substr((s.size()+1)/2);
  reverse(b.begin(), b.end());
  return a == b;
}

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

  if (kaibun(s)) {
    if (kaibun(s.substr(0, s.size()/2)) && kaibun(s.substr((s.size()+1)/2))) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

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

inline int gcd(int a,int b)
{
	if(a)
		return gcd(b%a,a);
	else
		return b;	
} 

int main()
{
	int K,ans=0;
	cin >> K;
	for(int i=1;i <= K;i++)
		for(int j=1;j <= K;j++)
			for(int k=1;k <= K;k++)
				ans += gcd(gcd(i,j),k);
	cout << ans << endl;
	return 0;	
} 

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define mod 1000000007
#define N 10001
#define D 100
int dp[N][D][2];
using namespace std; 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string k;
    int d;
    cin>>k>>d;
    reverse(k.begin(),k.end());
    memset(dp,0,(k.size()+1)*d*sizeof(dp[0][0]));
    dp[0][0][0] = 1;
    dp[0][0][1] = 1;
    for(int i=1;i<=k.size();i++){
        for(int j=0;j<d;j++){
            for(int m=0;m<2;m++){
                int lim = (m==0)?9:(k[i-1]-'0');
                for(int l=0;l<=lim;l++){
                    int prevm = m;
                    if(l<(k[i-1]-'0'))prevm=0;
                    dp[i][j][m] = (dp[i][j][m]+dp[i-1][(j+l)%d][prevm])%mod;
                }
            }
        }
    }
    int ans = (dp[k.size()][0][1]-1+mod)%mod;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,n,s) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void printpair(vector<pair<ll, ll>> vp)
{
  cout<<'['<<endl;
  rep(i,0,vp.size())
  {
    pair<ll, ll> p=vp[i];
    cout<<'{'<<p.first<<','<<p.second<<'}'<<endl;
  }
  cout<<'}'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
const long long INF = 1e12;
//------------------------------------------------------------
ll N,M;
void solve()
{
    cin >> N;
    map<string, ll> map;

    rep(i,0,N)
    {
      string s;
      cin >>s;
      
      if(!map.count(s)) map[s] = 0;
      map[s] = map[s]+1;
    }

    cin >>M;

    rep(i,0,M)
    {
      string s;
      cin >>s;
      
      if(!map.count(s)) map[s] = 0;
      map[s]=map[s]-1;
    }

    ll ans =0;

    for(const auto x : map)
    {
      ans = max(ans,x.second);
    }

    print(ans);

    return;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define Pr pair<LL,bool>
using namespace std;

const LL maxn = 212345*2;

vector<LL>edge[maxn];

void Link(LL st,LL ed){
    edge[st].push_back(ed);
    edge[ed].push_back(st);
}

LL dis[2][maxn];
int pos[maxn];
bool vis[2][maxn];
deque<Pr> Q;

void spfa(LL st){
    memset(dis,-1,sizeof(dis));
    memset(vis,dis[0][st] = 0,sizeof(vis));
    vis[0][st] = true;
    Q.push_front(Pr(st,0));
    bool f;
    Pr p;
    while(!Q.empty()){
        p = Q.front();
        Q.pop_front();

        st = p.first;
        f = p.second;
       // printf("%d:\n",pos[st]);

        vis[f][st] = false;
        for(auto it : edge[st]){
            LL ed = it;
            LL v = (f&&pos[ed] == pos[st]);

           //printf("%d->%d %d\n",pos[st],pos[ed],v);

            if(pos[ed] == pos[st])
            {
                if(dis[0][ed] == -1 || dis[f][st] + v < dis[0][ed]){
                    dis[0][ed] = dis[f][st] + v;
                    if(vis[0][ed] == false){
                        vis[0][ed] = true;
                        if(Q.empty() || dis[Q.front().second][Q.front().first] >= dis[0][ed])
                            Q.push_front(Pr(ed,0));
                        else
                            Q.push_back(Pr(ed,0));
                    }
                }
            }
            else
            {
                if(dis[1][ed] == -1 || dis[f][st] + v < dis[1][ed]){
                    dis[1][ed] = dis[f][st] + v;
                    if(vis[1][ed] == false){
                        vis[1][ed] = true;
                        if(Q.empty() || dis[Q.front().second][Q.front().first] >= dis[1][ed])
                            Q.push_front(Pr(ed,1));
                        else
                            Q.push_back(Pr(ed,1));
                    }
                }
            }
        }
    }
}

vector<LL> user[maxn],id[maxn];
LL locate(LL k,LL tpy){

	int l = 0,r = user[k].size();

	while(l <= r)
	{
		int mid = (l+r)>>1;
		if(user[k][mid] == tpy) return id[k][mid];
		if(user[k][mid] < tpy) l = mid+1;
		else r = mid-1;
	}
}

LL st[maxn],ed[maxn],c[maxn],t[maxn];


int main(){
    LL n,m;
    scanf("%lld %lld",&n,&m);

        for(LL i=0;i<m;i++){
            scanf("%lld %lld %lld",&st[i],&ed[i],&c[i]);
            user[st[i]].push_back(c[i]);
            user[ed[i]].push_back(c[i]);
        }
        for(LL i=1;i<=n;i++){
            sort(user[i].begin(),user[i].end());
            user[i].erase(unique(user[i].begin(),user[i].end()),user[i].end());
        }
        LL len = 0;
        pos[0] = 1;
        for(LL k = 1;k<=n;k++){
            for(LL i = 0;i<user[k].size();i++){
                id[k].push_back(++len);
                pos[len] = k;
                if(i) Link(len,len-1);
            }
        }
        for(LL i=0;i<m;i++){
            Link(locate(st[i],c[i]),locate(ed[i],c[i]));
        }
        len++;
        pos[len] = n;
        for(auto x : id[1]) Link(0,x);
        for(auto x : id[n]) Link(len,x);

        spfa(0);
        printf("%lld\n",dis[0][len]);

    return 0;
}


Measured memory_bytes: 76032
def convert(c):
    if c == 'A':
        return 'a'
    elif c == 'B':
        return 'b'
    return 'c'

nk = input()
nk = nk.split(' ')
nk = [int(a) for a in nk]

k = nk[1]
s = input()

result = s[:k-1]
result += convert(s[k - 1])
result += s[k:]
print(result)


Measured memory_bytes: 3060
#include<stdio.h>
 
int main(void)
{
    char x[1001];
    int sum[10000];
    int number;
    int i, j;
    int last = 0;
     
    for(i = 0; last != 1; i++)
    {
        scanf("%s", x);
        for(j = 0; x[j] != '\0'; j++)
        {
            if(j == 0)
            {
                sum[i] = (int)(x[j] - '0');
            }
            else
            {
                sum[i] += (int)(x[j] - '0');
            }
 
        }
        if(x[0] == '0' && x[1] == '\0')
        {
            last = 1;
            number = i;
        }
    }
     
    for(i = 0; i < number; i++)
    {
        printf("%d\n", sum[i]);
    }
    return 0;
}
   
 



 

Measured memory_bytes: 544
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn fact(n: usize) -> usize {
    let modulo = 1_000_000_007;
    let mut res = 1;
    for i in 1..n+1 {
        res *= i;
        res %= modulo;
    }
    res
}

fn solve() {
    let n = get!(usize);
    let mut s = get!(String).chars().map(|c| c == 'W').collect::<Vec<_>>();

    for i in 0..2*n {
        if i%2 == 0 {
            s[i] = !s[i];
        }
    }
    if s.iter().filter(|&&t| t).count() != n {
        println!("0");
        return;
    }
    
    let mut count = 1usize;
    let modulo = 1_000_000_007;

    let mut lnum = 0;
    for i in 0..2*n {
        if s[i] {
            lnum += 1;
        } else {
            if lnum == 0 {
                println!("0");
                return;
            }
            count *= lnum;
            count %= modulo;
            lnum -= 1;
        }
    }
    println!("{}", count * fact(n) % modulo);
}


Measured memory_bytes: 8572
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}

const int N = 1e7 + 10;
int n, w[N], Size, MX, rt, siz[N], fa[N];
int cnt, from[N], to[N << 1], dis[N << 1], nxt[N << 1];
bool vis[N];
inline void addEdge(int u, int v, int w) {
	to[++cnt] = v, dis[cnt] = w, nxt[cnt] = from[u], from[u] = cnt;
}
struct Edge { int u, v; ll w; } e[N]; int m;
inline bool operator < (const Edge &a, const Edge &b) { return a.w < b.w; }

void getrt(int u, int fa) {
	int maxpart = 0; siz[u] = 1;
	for(int i = from[u]; i; i = nxt[i]) {
		int v = to[i]; if(vis[v] || v == fa) continue;
		getrt(v, u), siz[u] += siz[v];
		maxpart = max(maxpart, siz[v]);
	} maxpart = max(maxpart, Size - siz[u]);
	if(maxpart < MX) MX = maxpart, rt = u;
}
int P; ll val, ans;

void dfs(int u, int fa, ll dep) {
	if(dep + w[u] < val) val = dep + w[u], P = u;
	for(int i = from[u]; i; i = nxt[i])
		if(!vis[to[i]] && to[i] != fa)
			dfs(to[i], u, dep + dis[i]);
}

void Link(int u, int fa, ll dep) {
	e[++m] = (Edge){u, P, val + dep + w[u]};
	for(int i = from[u]; i; i = nxt[i])
		if(!vis[to[i]] && to[i] != fa)
			Link(to[i], u, dep + dis[i]);
}

void doit(int u) {
	vis[u] = 1, val = 1e18, P = 0;
	dfs(u, 0, 0), Link(u, 0, 0);
	for(int i = from[u]; i; i = nxt[i]) {
		int v = to[i]; if(vis[v]) continue;
		Size = MX = siz[v], getrt(v, u), doit(rt);
	}
}

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main () {
#ifdef OFFLINE_JUDGE
	freopen("233.in", "r", stdin);
	freopen("233.out", "w", stdout);
#endif
	read(n);
	for(int i = 1; i <= n; ++i) read(w[i]);
	for(int i = 1, u, v, w; i < n; ++i) {
		read(u), read(v), read(w);
		addEdge(u, v, w), addEdge(v, u, w);
	}
	Size = MX = n; getrt(1, 0), doit(rt);
	sort(e + 1, e + m + 1); int blo = n;
	for(int i = 1; i <= n; ++i) fa[i] = i;
	for(int i = 1; i <= m && blo > 1; ++i) {
		int u = find(e[i].u), v = find(e[i].v);
		if(u != v) ans += e[i].w, fa[u] = v, --blo;
	} printf("%lld\n", ans);
	return 0;
} 


Measured memory_bytes: 88448
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char s[100];
	cin>>s;
	int S=strlen(s);
	int cnt=0;
	if(s[0]=='A') 
		if(s[1]<='z' && s[1]>='a'){
			for(int i=2;i<S-1;i++){
				if((s[i]>'z' || s[i]<'a')){
					if(s[i]!='C'){
						cout<<"WA"<<endl;return 0;
					}
					else{
						cnt++;
						if(cnt>1){
							cout<<"WA"<<endl;return 0;
						}
					}
				}
			}
		}
		else{
			cout<<"WA"<<endl;return 0;
		}
	else{
		cout<<"WA"<<endl;return 0;
	}
	if(cnt!=1){
		cout<<"WA"<<endl;return 0;
	}
	if(s[S-1]<'a' || s[S-1]>'z'){
		cout<<"WA"<<endl;return 0;
	}
	cout<<"AC"<<endl;return 0;
}

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

typedef long long ll;
ll k, c1, c2;
string s;
int main()
{
	ll i;
	cin >> s >> k;
	if (k % 2) {
		for (i = 1; i < s.size(); i++) {
			if (s[i] == s[i - 1]) c1++, i++;
		}
		if (i == s.size() && s[s.size() - 1] == s[0]) c1++, i = 2;
		else i = 1;
	} else {
		i = 1;
	}
	s += s;
	for (; i < s.size(); i++) {
		if (s[i] == s[i - 1]) c2++, i++;
	}
	c2 *= k / 2;
	if (i == s.size() && s[s.size() - 1] == s[0]) c2 += k / 2 - 1;
	cout << c1 + c2 << endl;
    return 0;
}


Measured memory_bytes: 256