akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    from collections import deque
    n,x,y = map(int,input().split())
    ans = [0]*(n)
    E = [[] for i in range(n)]
    E[0].append(1)
    E[n-1].append(n-2)
    for i in range(1,n-1):
        E[i].append(i-1)
        E[i].append(i+1)
    E[x-1].append(y-1)
    E[y-1].append(x-1)
    ans = [0]*(n)
    d = [[float("INF")]*n for i in range(n)]
    def search(x):
        d[x][x] = 0
        q = deque([])
        q.append((x,0))
        while q:
            bef,l = q.pop()

            for nex in E[bef]:
                if d[x][nex] > l+1:
                    d[x][nex] = l+1
                    q.append((nex,l+1))
        
        
    for i in range(n-1):
        search(i)
    for i in range(n-1):
        for j in range(i+1,n):
            if d[i][j] != float("INF"):
                ans[d[i][j]] += 1

    for i in ans[1:]:
        print(i)
if __name__ == "__main__":
    main()



Measured memory_bytes: 135560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

ll mypow(ll x, ll n) {
    if (n == 0) return 1;
    if (n%2 == 0) return mypow(((x%mod)*(x%mod))%mod, n/2);
    else return ((x%mod) * mypow(((x%mod)*(x%mod))%mod, (n-1)/2))%mod;
}

int main(){
    double R;
    cin >> R;
    cout << fixed << setprecision(16);
    cout << 2.0*R*M_PI << endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }



void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
	ll sum = 0;
	ll pre = -999;
	REP(i, N) {
		ll an = A[i]-1;
		sum += B[an];
		if (an-pre==1) {
			sum += C[pre];
		}
		pre = an;
	}
	cout << sum << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


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

int main(void){
  int n, y;
  cin >> n >> y;

  for(int i = 0; i <= n; i ++){
    for(int j = 0; j <= n-i; j ++){
      int k = n-j-i;
      if(10000*i + 5000*j + 1000*k == y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}

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

int main()
{
	int x,y;
	int t = 0;
	while(1){
		cin >> x >> y;
		if(x == 0 && y == 0) break;
		
		if(x > y){
			t = x;
			x = y;
			y = t;
		}
		
		cout << x << " " << y << endl;
	}
	
	return 0;
			
}

Measured memory_bytes: 2992
feneck = input().split()
H = input().split()
H_i = [int(h) for h in H]

N = int(feneck[0])
K = int(feneck[1])

list.sort(H_i, reverse=True)

if K < len(H_i):
  sum = 0
  H_i = H_i[K:]
  for hp in H_i:
    hp = int(hp)
    sum += hp
  print(sum)
else:
  print(0)

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

int N;
int M;
int d[100000];
int par[100000];
int outdeg[100000];
std::vector<int> g[100000];

int dfs(int cur){
  if(d[cur]!=-1)return d[cur];
  for(int dst:g[cur]){
    d[cur]=std::max(d[cur],dfs(dst)+1);
  }
  return d[cur];
}

int main(){
  std::cin>>N>>M;
  for(int i=0;i<N;++i)d[i]=-1;
  for(int i=0;i<N;++i)par[i]=-1;
  long long ans=0;
  for(int i=0;i<N+M-1;++i){
    int a,b;
    std::cin>>a>>b;
    --a;
    --b;
    g[b].push_back(a);
    ++outdeg[b];
  }
  for(int i=0;i<N;++i)if(outdeg[i]==0)d[i]=0;
  for(int i=0;i<N;++i){
    dfs(i);
  }
  for(int i=0;i<N;++i){
    for(int dst:g[i]){
      if(d[i]==d[dst]+1){
	par[i]=dst;
      }
    }
  }
  for(int i=0;i<N;++i){
    std::cout<<(par[i]+1)<<std::endl;
  }
  return 0;
}


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

int main() {
  int h,w;
  char a;
  cin >> h >> w;
  
  for(int i=0; i<h+2; i++){
    for(int j=0; j<w+2; j++){
      if(i==0 || j==0 || i==h+1 || j==w+1) cout << '#';
      else{
        cin >> a;
        cout << a;
      }
    }
    cout << endl;
  }
  
}




Measured memory_bytes: 256
N = int(input())
S = []
A = []
for i in range(N):
    s = int(input())
    if s % 10 == 0:
        A.append(s)
    else:
        S.append(s)
ans = sum(S) + sum(A)
if ans % 10 == 0 and len(S) != 0:
    ans = ans - min(S)
elif ans % 10 == 0:
    ans = 0

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{

	int n,h[20],i,max,m;

	max=0;
	m=0;

	scanf("%d",&n);

	for(i=0; i<n; i++) scanf("%d",&h[i]);

	for(i=0; i<n; i++)
	{
		if(h[i]>=max)
		{
			max=h[i];
			m=m+1;
		}
	}

	printf("%d\n",m);

	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
#define MOD (int)1e9+7
int dx4[]={1,0,-1,0};
int dy4[]={0,-1,0,1};
typedef long long int ll;
typedef unsigned long long int ull;
ll gcd(ll x,ll y){if(!y)return x;return gcd(y,x%y);}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void swap(ll *x,ll *y){ll tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){ll x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
typedef struct pair_{
    int x;
    int y;
}pair_t;

int main(){
    int k,s;scanf("%d %d",&k,&s);
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int x=s-(i+j);
            if(!(0<=x&&x<=k))continue;
            ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
N,*A=map(int,open(0).read().split())
l=[]
s=0
for a in reversed(A):
    s+=a
    l.append(s)
l.reverse()
m=1000000000+7
ans=0
for i in range(N-1):
    ans+=A[i]*l[i+1]
    ans%=m
print(ans)


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

const int MAX_N = 1000, MAX_M = 1000;
int dp[MAX_N + 1][MAX_M + 1];

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

	for (int i = 0;i < q;i++) {
		string x, y; cin >> x >> y;

		for (int i = 0;i <= x.size();i++)
			for (int j = 0;j <= y.size();j++) dp[i][j] = 0;

		for (int i = x.size() - 1;0 <= i;i--) {
			for (int j = y.size() - 1;0 <= j;j--) {
				if (x[i] == y[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
				else dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
		cout << dp[0][0] << endl;
	}
    return 0;
}




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

#define int long long
int a,b,x,y,c;

inline int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

inline void exgcd(int a,int b,int &x,int &y){
	if(b)exgcd(b,a%b,y,x),y-=a/b*x;
	else x=1,y=0;
}

inline int inv(int x,int p){//gcd(a,b)=0;
	int a,b;exgcd(x,p,a,b);
	if(a<0)a+=p;
	return a;
}

vector<int> s, t;

inline int gety(int x,int step){
	if(x==0)return c;
	return (c-1ll*x*step%c)%c;
}

inline int lowdiv(int x,int y){
	return x/y-(x%y&&(x^y)<0);
}

void Main(){
	int ans=0;
	cin >> a >> x >> b >> y >> c;
	int g=gcd(a,b);a/=g,b/=g;
	c/=gcd(c,g);
	for(int _=1;_<=2;_++){
		g=gcd(a,c);
		c/=g,a/=g;int h=gcd(b,g);
		b/=h,y/=g/h;

		swap(a,b),swap(x,y);
	}
	// cerr << a << " " << x << " " << b << " " << y << " " << c << endl;
	if(c==1){
		printf("%lld\n",x+y);return ;
	}
	int step=1ll*inv(b,c)*a%c;
	vector<int> pos, cnt;
		int z=inv(step, c), h=step, w=c, cur=0;
		while(w){
			int p=w/h;
			pos.push_back(1ll*cur*z%c);
			cnt.push_back(p);
			cur+=p*h;
			w%=h;
			if(w==0)break;
			h%=w;
			if(h==0)h=w;
		}
		pos.push_back(c);
	// for(size_t i=0;i<pos.size();i++)cout << pos[i] << " " ;puts("");
	// for(size_t i=0;i<cnt.size();i++)cout << cnt[i] << " ";puts("");
	// cerr << "????" << endl;
	for(size_t i=0;i<cnt.size();i++){
		int lx=pos[i], ly=gety(lx, step);
		int rx=pos[i+1], ry=gety(rx, step);
		
		// cerr << lx << " " << ly << " " << rx << " " << ry << endl;
		// cerr << cnt[i] << "??" << endl;
		int dx=(rx-lx)/cnt[i];
		int dy=(ly-ry)/cnt[i];
		// cerr << dx << " " << dy << endl;
		int lw=0,up=x+y+1;
		// cerr << "st" << endl;
		while(up-lw>1){
			int mid=(lw+up)>>1;
			int p=lowdiv(x-lx*mid,dx);
			int q=lowdiv(y-ry*mid,dy);
			if(p>=0&&q>=0&&p+q>=cnt[i]*mid)
				lw=mid;
			else
				up=mid;
		}
		// cerr << "ed" << endl;
		ans=max(ans, lw);
	}
	printf("%lld\n",ans);
}
#undef int

int main(){int T;cin >> T;while(T--)Main();}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

int main()
{
	ll n; cin >> n;
	int p = 0;
	ll a = 2;
	while (true)
	{
		if (a > n)break;
		p++;
		a *= 5;
	}
	ll ans = 0;
	if (n % 2 == 0)
	{
		reps(i, p)
		{
			ans += n / (ll)(2 * pow(5, i));
		}
	}
	co(ans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
   int a,b,d,r;
   
   double f;
   
   scanf("%d %d", &a, &b);
   
   d = a / b;
   
   r = a % b;
   
   f = ((double)a / (double)b);
   
   printf("%d %d %lf\n", d, r, f);
	return 0;
}



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

	long maxa,mina=1000,a,n,k,c,ans,b[200005];

int main()
{ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(!b[a])
		{
			c++;
			if(a>maxa)maxa=a;
			if(a<mina)mina=a;
		}
		b[a]++;
	}
	sort(b+mina,b+maxa+1);
	int j=1;
	while(!b[j])
	{
		j++;
	}
	for(int i=j;i<c-k+j;i++)
	{
		ans+=b[i];
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	string n;
	cin >> n;
	rep(i, n.size()) {
		if (n[i] == '7') {
			print("Yes");
			break;
		}
		if (i == n.size() - 1)
			print("No");
	}
}

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

long long int GCL(long long int a, long long int b){
  if (b == 0) return a;
  return GCL(b, a % b);
}

int main(){
  long long int a, b;
  cin >> a >> b;

  long long int g = GCL(a, b);

  int ans = 1;
  for (int i = 2; i <= sqrt(g); i++){
    if (g % i == 0){
      ans++;
      while (g % i == 0){
        g /= i;
      }
    }
  }
  if (g > 1) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int digit(ll n){
    int res=0;
    while(n){
        n /= 10;
        res++;
    }
    return res;
}

int F(ll A, ll B){
    return max(digit(A), digit(B));
}

int main(void){

    ll N;
    cin >> N;

    int ans = 100;
    for(ll i=floor(sqrt(N)); i>0; i--){
        if(N%i == 0){
            ll A = N/i;
            chmin(ans, F(A, i));
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/08/10 13:13:56
*******************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int maxn=1e6+10;
int n,pos,ans,l,r;
int q[maxn];
string s,t;
int main()
{
        //freopen("a.in","r",stdin);
        //freopen("a.out","w",stdout);
        cin>>n>>s>>t;
        s="#"+s;
        t="#"+t;
        if(s==t){cout<<0<<endl;return 0;}
        pos=n;l=1,r=0;
        for(int i=n;i>=1;i--)
        {
            if(t[i]==t[i-1])continue;
            pos=min(pos,i);
            while(pos and t[i]!=s[pos])pos--;
            if(pos==0){cout<<-1<<endl;return 0;}
            while(l<=r)
            {
                if(q[l]-(r-l+1)+1>i)l++;
                else 
                    break;
            }
            q[++r]=pos;
            if(i!=pos)ans=max(ans,r-l+1);
        }
        cout<<ans+1<<endl;
        return 0;
}


Measured memory_bytes: 6112
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define link(x) for(edge *j=h[x];j;j=j->next)
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
const int MAXN=3e5+10;
const double eps=1e-8;
const int mod=1e9+9;
#define ll long long
using namespace std;
struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}


typedef struct node{
    int l,del,vul;
}node;

vector<node>vec[MAXN];
int n,m,q;
int st[MAXN],tot;
int ans=0;
void dfs(int x,int y,int key){
    if(y==n){
	ans=max(ans,key);
	return ;
    }
    inc(i,x,m){
	st[++tot]=i;int sum=key;
	for(int j=0;j<vec[y+1].size();j++){
	    int t1=vec[y+1][j].l;int t2=vec[y+1][j].del;int t3=vec[y+1][j].vul;
	    if(i-st[t1]==t2)sum+=t3;
	}
	dfs(i,y+1,sum);
	tot--;
    }
}

int main(){
    n=read();m=read();q=read();
    int t1,t2,t3,t4;
    inc(i,1,q)t1=read(),t2=read(),t3=read(),t4=read(),vec[t2].pb((node){t1,t3,t4});
    dfs(1,0,0);
    printf("%d\n",ans);
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int X, Y;
  cin >> X >> Y;
  int ans = 0;

  switch (X) {
  case 3:
    ans += 100000;
    break;
  case 2:
    ans += 200000;
    break;
  case 1:
    ans += 300000;
    break;
  default:
    break;
  }

  switch (Y) {
  case 3:
    ans += 100000;
    break;
  case 2:
    ans += 200000;
    break;
  case 1:
    ans += 300000;
    break;
  default:
    break;
  }

  if (X == 1 && Y == 1) {
    ans += 400000;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] sh = s.split(" ");
		int n = Integer.parseInt(sh[0]);
		int x = Integer.parseInt(sh[1]);

		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			int m = Integer.parseInt(sc.next());
			list.add(m);
			x -= m;
		}
		Collections.sort(list);

		System.out.println(n + (int) (x / list.get(0)));

		sc.close();
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#include<set>
#define ll long long
#define inf 0x7fffffff;
#define maxn 1000005
using namespace std;
string s;
int read()
{
    int l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
} 
int main(){
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
	printf("Yes");
	else
	printf("No");
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)


Measured memory_bytes: 80084
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	int n, x;
	int count = 0;
	cin >> n >> x;
	while (n != 0 || x != 0){
		rep(i, n - 2){
			for (int j = i + 1; j < n - 1; j++){
				for (int k = j + 1; k < n; k++){
					if (x == i + j + k + 3){
						count++;
					}
				}
			}
		}
		cout << count << '\n';//output
		count = 0;//initialize
		cin >> n >> x;
	}

	return 0;
}


Measured memory_bytes: 3140
use proconio::{input,fastout};

fn main() {
    input! {
        n: i32,
    }

    let mut acs = 0;
    let mut was = 0;
    let mut tles = 0;
    let mut res = 0;

    for _m in 0..n {
        input! {
            s: String,
        }
        if s == "AC" {
            acs += 1;
        }
        if s == "WA" {
            was += 1;
        }
        if s == "TLE" {
            tles += 1;
        }
        if s == "RE" {
            res += 1;
        }
    }
    println!("AC x {}",acs);
    println!("WA x {}",was);
    println!("TLE x {}",tles);
    println!("RE x {}",res);
}


Measured memory_bytes: 2532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    String[][] inputArray;
    int[][] ansArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        inputArray = new String[H+2][W+2];
        ansArray = new int[H+2][W+2];

        for(int i=0; i<=H+1; i++){
            if(i == 0 || i == H+1){
                for(int j=0; j<=W+1; j++){
                    inputArray[i][j] = "w";
                }
            } else {
                char[] input = sc.next().toCharArray();
                for(int j=0; j<=W+1; j++){
                    if(j == 0 || j == W+1){
                        inputArray[i][j] = "w";
                    }
                    else {
                        inputArray[i][j] = String.valueOf(input[j-1]);
                    }
                }
            }
        }


        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                int count = -1;
                if(inputArray[i][j].equals(".")){
                    count = checkNbOfBomb(i, j);
                }
                if(count == -1){
                    if(j == W){
                        System.out.println("#");
                    } else {
                        System.out.print("#");
                    }
                } else {
                    if(j == W){
                        System.out.println(count);
                    } else {
                        System.out.print(count);
                    }
                }
            }
        }
    }

    int checkNbOfBomb(int i, int j) {
        int count = 0;
        if (inputArray[i+1][j].equals("#")) {
            count++;
        }

        if(inputArray[i+1][j+1].equals("#")){
            count++;
        }

        if(inputArray[i][j+1].equals("#")){
            count++;
        }

        if(inputArray[i-1][j+1].equals("#")){
            count++;
        }

        if(inputArray[i-1][j].equals("#")){
            count++;
        }

        if(inputArray[i-1][j-1].equals("#")){
            count++;
        }

        if(inputArray[i][j-1].equals("#")){
            count++;
        }

        if(inputArray[i+1][j-1].equals("#")){
            count++;
        }

        return count;
    }
}

Measured memory_bytes: 22228
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int N;
	cin >> N;
	int ans = 0;

	vector<int>d(N);
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
<?php
/**
 * ABC122
 * D - We Like AGC
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));
$mod = 1000000007;
fscanf(STDIN, "%d", $n);
$bases = ['A', 'G', 'C', 'T'];
$ng_pattern = ['AGC', 'ACG', 'GAC'];

foreach ($bases as $base1) {
    foreach ($bases as $base2) {
        foreach ($bases as $base3) {
            $key = $base1 . $base2 . $base3;
            $dp[0][$key] = 0;
            $dp[1][$key] = 0;
            $dp[2][$key] = 0;
            $dp[3][$key] = in_array($key, $ng_pattern) ? 0 : 1;
        }
    }
}

for ($i = 4; $i <= $n; $i++) {
    foreach ($bases as $base1) {
        foreach ($bases as $base2) {
            foreach ($bases as $base3) {
                $key = $base1 . $base2 . $base3;
                $dp[$i][$key] = 0;
                foreach ($bases as $base) {
                    if (in_array($key, $ng_pattern)) continue;
                    if ($base . $base1 . $base3 === 'AGC') continue;
                    if ($base . $base2 . $base3 === 'AGC') continue;
                    $dp[$i][$key] += $dp[$i - 1][$base . $base1 . $base2];
                    $dp[$i][$key] %= $mod;
                }
            }
        }
    }
}

echo array_sum($dp[$n]) % $mod, PHP_EOL;


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1) a = 14;
  if (b == 1) b = 14;
  if (a == b) cout << "Draw" << endl;
  else if (a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a,max,min,i;
  scanf("%d", &n);
  scanf("%d",&a);
  max=a;
  min=a;
  for(i=1;i<n;i++){
    scanf("%d",&a);
    if(max<a)max=a;
    if(min>a)min=a;
  }
  printf("%d\n",max-min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout << "a < b" <<endl;
    }else if(a==b){
        cout << "a == b" <<endl;
    }else{
        cout << "a > b" <<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
X=int(input())
if 400<=X<=599:
    print(8)
elif 600<=X<=799:
    print(7)
elif 800<=X<=999:
    print(6)
elif 1000<=X<=1199:
    print(5)
elif 1200<=X<=1399:
    print(4)
elif 1400<=X<=1599:
    print(3)
elif 1600<=X<=1799:
    print(2)
elif 1800<=X<=1999:
    print(1)

Measured memory_bytes: 9184
#!/usr/bin/env ruby

while line = gets
  x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p = line.chomp!.split(" ").map(&:to_f)

  a = (x_1 - x_3) * (y_p - y_3) - (y_1 - y_3) * (x_p - x_3)
  b = (x_2 - x_1) * (y_p - y_1) - (y_2 - y_1) * (x_p - x_1)
  c = (x_3 - x_2) * (y_p - y_2) - (y_3 - y_2) * (x_p - x_2)

  puts ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0)) ? "YES" : "NO"
end

Measured memory_bytes: 8644
N,M=map(int,input().split())
H=input().split()
good=[1]*N
for i in range(M):
  A,B=map(int,input().split())
  if int(H[A-1])>=int(H[B-1]):
    good[B-1]=0
  if int(H[A-1])<=int(H[B-1]):
    good[A-1]=0
print(good.count(1))



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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int x;
        cin>>x;
        if(x<600)
            cout<<8;
        else if(x<800)
            cout<<7;
        else if(x<1000)
            cout<<6;
        else if(x<1200)
            cout<<5;
        else if(x<1400)
            cout<<4;
        else if(x<1600)
            cout<<3;
        else if(x<1800)
            cout<<2;
        else cout<<1;
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second


void run(){
    int n; cin >> n;
    cout << (1000 - (n % 1000)) % 1000;
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3644
function main(input){
  const A=input.split(' ')[0];
  const B=input.split(' ')[1];
  const C=input.split(' ')[2];
  if(B>=A*C){
    console.log(C);
  }else{
    console.log(Math.floor(B/A));
  }

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7492
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

K,A,B = Is()
if B-A <= 2:
    print(K+1)
    exit()
else:
    ans = A-1
    if (K-ans)%2 == 0:
        ans += (K-ans)//2*(B-A)
    else:
        ans += (K-ans-1)//2*(B-A) + 1
    print(ans+1)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int b = sc.nextInt();
			if(b == 0){
				//System.out.println("break");
				break;
			}
			int[] a = new int[b];
			int left,right,searchvalue;
			for(int i=0; i < a.length; i++){
				a[i] = sc.nextInt();
			}
			searchvalue = sc.nextInt();
			left = 0; right = a.length-1;
			System.out.println(solve(left, right, searchvalue, a));
		}
	}

	int solve(int left, int right,int sv,int[] a){
		int mid = (left + right) / 2;
		if(a[mid] == sv){
			return 1;
		}else if(left > right){
			return 0;
		}else if(a[mid] < sv){
			return 1 + solve(++mid, right, sv, a);
		}else if(a[mid] > sv){
			return 1 + solve(left, --mid, sv, a);			
		}
		return 0;
	}
}

Measured memory_bytes: 18452
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l = s.size();
  int a, z;
  for(int i = 1; i <= l; i++){
    if(s[l-i] == 'A') a = l-i;
  }
  
  for(int i = 0; i < l; i++){
    if(s[i] == 'Z') z = i;
  }
  cout << z - a  + 1 << endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

void main_sub(void) {
    int a, b;
    cin >> a >> b;
    rep(i, 5000000) {
        int x = (int)(i * 0.08);
        int y = (int)(i * 0.10);
        if (x == a && b == y) {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
    return;
}

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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  ll l, r;
  cin >> l >> r;
  ll ans = 1e12;
  map<ll, ll>mp;
  for (ll i = l; i <= min (l + 2018, r); i++) {
    mp[i % 2019]++;
  }
  if (l + 2018 + 2018 <= r) {
    for (auto i : mp) {
      mp[i.first]++;
    }
  } else  {
    for (ll i = l + 2019; i <= r; i++) {
      mp[i % 2019]++;
    }
  }
  for (auto i : mp) {
    for (auto j : mp) {
      if (i.first == j.first && i.second == 1) {
        continue;
      }
      ans = min (ans, i.first * j.first % 2019);
    }
  }
  cout << ans << '\n';
  return 0;

}


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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int AB = A * B;
  int CD = C * D;

  if(AB > CD)
    cout << AB << endl;
  else
    cout << CD << endl;
}

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

int main()
{
	int a, b, c,i=1,sum=0;
	cin >> a >> b >> c;
	while(i<=b){
		if (((a*i) % b) == c) {
			cout << "YES" << endl;
			break;
		}
		else {
			i++;
			continue;
		}
	}
	if (i > b) cout << "NO" << endl;
}



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

#define MAX_N 1000000000

int main()
{
  while(1){
    int n;
    cin >> n;
    if(n == 0) break;
    long long int a[n];
    for(int i = 0; i < n; i++){
      string s;
      cin >> s;
      a[i] = s == "x" ? MAX_N+1 : atoi(s.c_str());
    } 
    long long int l = -MAX_N-3, u = MAX_N+3;
    bool flag = false;
    for(int i = 0; i < n-1; i++){
      if(a[i] == MAX_N+1){
        if(a[i+1] == MAX_N+1){
          flag = true;
          break;
        }else{
          if((i+1) & 1){
            u = min(u,a[i+1]);
          }else{
            l = max(l,a[i+1]);
          }
        }
      }else{
        if(a[i+1] == MAX_N+1){
          if((i+1) & 1){
            l = max(l,a[i]);
          }else{
            u = min(u,a[i]);
          }
        }else{
          if((i+1) & 1){
            if(a[i] >= a[i+1]){
              flag = true;
              break;
            }
          }else{
            if(a[i] <= a[i+1]){
              flag = true;
              break;
            }
          }
        }
      }
    }
    if(flag){
      cout << "none" << endl;
      continue;
    }
    if(u - l - 1 > 1)
      cout << "ambiguous" << endl;
    else if(u - l - 1 <= 0)
      cout << "none" << endl;
    else
      cout << (u+l)/2 << endl;
  }
}

Measured memory_bytes: 1224
local read = io.read

local n = read("n")

local count = 0
local paper_t = {}
for i = 1, n do
	local a_i = read("n")
	if paper_t[a_i] then
		count = count - 1
		paper_t[a_i] = nil
	else
		count = count + 1
		paper_t[a_i] = true
	end
end

print(count)


Measured memory_bytes: 8452
n = int(input())

factors = []

rem = 1
while n%2 == 0:
    n //= 2
    rem *=2
    if not rem in factors:
        factors.append(rem)
        rem = 1

for f in range(3, int(n**0.5)+ 1, 2):
    rem = 1
    while n%f == 0:
        n //= f
        rem *= f
        if not rem in factors:
            factors.append(rem)
            rem = 1

if n != 1:
    factors.append(n)

print(len(factors))


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

int main(){
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> pic(H + 2, vector<char>(W + 2));
  for (int i = 0; i < H + 2; i++){
    for (int j = 0; j < W + 2; j++){
      if (i == 0 || i == H + 1 || j == 0 || j == W + 1){
        pic.at(i).at(j) = '#';
      }
      
     else{
       cin >> pic.at(i).at(j);
     }
    }
  }
  
  for (int i = 0; i < H + 2; i++){
    for (int j = 0; j < W + 2; j++){
      cout << pic.at(i).at(j);
      if (j == W + 1){
        cout << endl;
      }
    }
  }
}

Measured memory_bytes: 256
from collections import defaultdict

h,w=map(int,input().split())
dd = defaultdict(int)
for _ in range(h):
    s = list(input())
    for c in s:
        dd[c]+=1
rr=[0,0,0,0]
for k in dd.keys():
    rr[dd[k]%4]+=1

if h%2+w%2==0:  # even even
    if rr[1]>0 or rr[2]>0 or rr[3]>0:
        print('No')
    else:
        print('Yes')
elif h%2+w%2==1:  # even odd
    if rr[1]>0 or rr[3]>0:
        print('No')
    elif h%2==0:
        if rr[2]<=h//2:
            print('Yes')
        else:
            print('No')
    elif w%2==0:
        if rr[2]<=w//2:
            print('Yes')
        else:
            print('No')
else:  # odd odd
    if rr[1]+rr[3]!=1:
        print('No')
    elif rr[1]==1:
        if rr[2]<=(h+w-2)//2:
            print('Yes')
        else:
            print('No')
    elif rr[3]==1:
        if rr[2]+1<=(h+w-2)//2:
            print('Yes')
        else:
            print('No')



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)      //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++)    //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);
    
    int n; cin >> n;
    vi a(n+1); rep1(i,n) cin >> a[i];
    
    int ans=0;
    int num = 1;
    int crash = 0;
    while(1) {
        if(num+crash >= n+1) break; 
        if(a[num+crash]==num) num++;
        else crash++;
    }
    cout << (crash!=n ? crash : -1) << '\n';
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	long long int N,K,tmp,ans=0;
	scanf("%lld%lld",&N,&K);
	
	if(K%2==0){
		tmp=(N+(K/2))/K;
		ans+=tmp*tmp*tmp;
	}
	
	tmp=N/K;
	ans+=tmp*tmp*tmp;
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import 'dart:io';

void main(List<String> args) {
  final line = stdin.readLineSync();
  final intLine = int.parse(line);
  final first = intLine % 10;
  if (first == 3) {
    print('bon');
  } else if (first == 0 || first == 1 || first == 6 || first == 8) {
    print('pon');
  } else {
    print('hon');
  }
}


Measured memory_bytes: 13144
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 1e9+5;
 
vector<int> col;
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    col.clear();
    int len = s.size();
    int num = 1;
    char c = s[0];
    int sum = 0;
    for(int i=1;i<len;i++)
    {
        if(s[i]==c)
            num++;
        else
        {
            col.push_back(num);
            sum += num/2;
            num = 1;
            c = s[i];
        }
    }
    col.push_back(num);
    int siz = col.size();
    if(siz==1)
    {
        cout << (ll)(len)*(ll)(k)/2LL << "\n";
    }
    else if(s[0]==s[len-1])
    {
        sum -= col[0]/2;
        cout << (ll)(sum)*(ll)(k) + (ll)(col[0]/2) + (ll)(col[siz-1]/2) + (ll)((col[0]+col[siz-1])/2) * (ll)(k-1);
    }
    else
    {
        sum += col[siz-1]/2;
        cout << (ll)(sum)*(ll)(k) << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int map[10][10];
int h, w;

void floyd(){
    int i, j, k;
    for(k = 0; k<10; k++){
        for(i = 0; i<10; i++){
            for(j = 0; j<10; j++){
                map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
            }
        }
    }
}

int main(){
    int i, j, a;
    while(~scanf("%d%d",&h, &w)){
        for(i = 0; i<10; i++){
            for(j = 0; j<10; j++){
                scanf("%d",&map[i][j]);
            }
        }
        floyd();
        int ans = 0;
        for(i = 0; i<h; i++){
            for(j = 0; j<w; j++){
                scanf("%d",&a);
                if(a!=-1 && a!=1){
                    ans += map[a][1];
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define all(in) in.begin(),in.end()
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
  int i,j;
  int n;
  cin>>n;
  vi r(n),s(n),p(n),c(n);
  int v[105][3];
  int ans,t;

  rep(i,n)cin>>r[i];
  rep(i,n)
    cin>>v[i][0]>>v[i][1]>>v[i][2];

  rep(ans,100)rep(t,3){
    rep(i,n){
      s[i]=v[i][0];
      p[i]=v[i][1];
      c[i]=v[i][2];
    }

    if(t==0)
      s[0]=min(s[0]+ans,100);
    else if(t==1)
      p[0]=min(p[0]+ans,100);
    else 
      c[0]=min(c[0]+ans,100);

    sort(all(s));
    sort(all(p));
    sort(all(c));
    
    pii ord[105]={};


    int num;
    if(t==0){
      num=s.end()-upper_bound(all(s),min(100,v[0][0]+ans));
      ord[0].first+=r[num];
    }else{
      num=s.end()-upper_bound(all(s),v[0][0]);
      ord[0].first+=r[num];
    }
    if(t==1){
      num=p.end()-upper_bound(all(p),min(100,v[0][1]+ans));
      ord[0].first+=r[num];
    }else{
      num=p.end()-upper_bound(all(p),v[0][1]);
      ord[0].first+=r[num];
    }
    if(t==2){
      num=c.end()-upper_bound(all(c),min(100,v[0][2]+ans));
      ord[0].first+=r[num];
    }else{
      num=c.end()-upper_bound(all(c),v[0][2]);
      ord[0].first+=r[num];
    }
    ord[0].second=0;

    for(i=1;i<n;i++){
      num=s.end()-upper_bound(all(s),v[i][0]);
      ord[i].first+=r[num];
      
      num=p.end()-upper_bound(all(p),v[i][1]);
      ord[i].first+=r[num];
      
      num=c.end()-upper_bound(all(c),v[i][2]);
      ord[i].first+=r[num];
      
      ord[i].second=i;
    }
    sort(ord,ord+n);
    /*
    cout<<"ans"<<ans<<endl;
    rep(i,n)
      cout<<i<<" "<<ord[i].first<<" "<<ord[i].second<<endl;
    */

    int z; 
    rep(z,n)
      if(ord[z].second==0){
	if(ord[n-8].first<=ord[z].first){
	  cout<<ans<<endl;
	  return 0;
	}
      }

  }
  cout<<"Saiko"<<endl;
}

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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }

};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
  int n,k;
  cin>>n>>k;
  mint sum =0;

  mint nmin =0;
  mint nmax =0;
  for(int j=0;j<k;j++){
    nmin+=j;
    nmax+=n-j;
  }
  sum+=(nmax-nmin+1);
  //cout<<"nmin="<<nmin<<" nmax="<<nmax<<endl;

  //何個の数を足して計算するかを決める
  for(int i=k+1;i<=n+1;i++){
  //  cout<<"roop is "<<i<<endl;
  nmin +=(i-1);
  nmax +=(n-i+1);
  //cout<<"nmin="<<nmin<<" nmax="<<nmax<<endl;

    //取れる値の最大値-最小値がその個数の取れる数

//    cout<<"nmin="<<nmin<<" nmax="<<nmax<<endl;
    sum+=(nmax-nmin+1);
//    cout <<sum<<endl;
  }
  cout<<sum<<endl;

}


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

int main() {
	// your code goes here
	long int n;
	cin>>n;
	
	long long int ans=1;
	
	for(int x=2; x<=n; x++){
	    
	    ans = (ans*x)%(1000000007);
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    int main(){
        string S;
        cin >> S;

        if(S=="Sunny"){
            cout << "Cloudy" << endl;
        }else if(S=="Cloudy"){
            cout << "Rainy" << endl;
        }else if(S=="Rainy"){
            cout << "Sunny" << endl;
        }
    }

Measured memory_bytes: 256
# 2019/08/09

n=int(input())
h=[0]+list(map(int,input().split()))+[0]
n+=2
cnt=0
btm=0
for i in range(n-1):
    if h[i]==h[i+1]:continue
    
    if h[i]<h[i+1]:
        btm=min(h[i],btm)
    else:
        cnt+=h[i]-btm
        btm=h[i+1]
print(cnt)

Measured memory_bytes: 3064
n,m = gets.split.map {|n| n.to_i}
mat = Array.new(n).map {Array.new(m)}
vec = Array.new(m)
for i in 1..n
  a = gets.split.map {|s| s.to_i}
  mat[i-1] = a
end
for i in 1..m
  j = gets.to_i
  vec[i-1] = j
end
for i in 1..n
  s = 0
  for j in 1..m
    s += mat[i-1][j-1] * vec[j-1]
  end
  puts s
end

Measured memory_bytes: 6216