akhauriyash/Code-Regression huggingface dataset:
s = input()
if (s == "keyence"):
    print("YES")
elif (s[0:7] == "keyence" or s[len(s) - 7:] == "keyence"):
    print("YES")
else:
    if (s[0:6] == "keyenc" and s[-1] == "e"):
        print("YES")
    elif (s[0:5] == "keyen" and s[len(s) - 2:] == "ce"):
        print("YES")
    elif (s[0:4] == "keye" and s[len(s) - 3:] == "nce"):
        print("YES")
    elif (s[0:3] == "key" and s[len(s) - 4:] == "ence"):
        print("YES")
    elif (s[0:2] == "ke" and s[len(s) - 5:] == "yence"):
        print("YES")
    elif (s[0:1] == "k" and s[len(s) - 6:] == "eyence"):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3064
# include <bits/stdc++.h>
# define int long long
# define fi first
# define se second

using namespace std ;

const int N = 1001, mod = 1e9 + 7 ;
char grid[N][N];
int dp[N][N] ;

int32_t main() {
    //freopen("haybales.in", "r", stdin ) ;
    //freopen("haybales.out", "w", stdout ) ;
    int n, w ;
    cin >> n >> w ;
    for( int i =1 ; i <= n ; i ++ ) {
        for( int j = 1 ; j <= w;  j ++ ) {
            cin >> grid[i][j] ;
        }
    }
    dp[1][1] = 1 ;
    for( int i = 1 ; i <= n ; i ++ ) {
        for( int j = 1 ; j <= w ; j ++ ) {
            if( grid[i][j] == '#' ) continue ;
            dp[i][j] += dp[i-1][j] + dp[i][j-1] ;
            dp[i][j] %= mod ;
        }
    }
    cout << dp[n][w] ;
}


Measured memory_bytes: 12340
import Data.Map ((!))
import qualified Data.Map as M
import Control.Monad

main = readLn >>= print.solve

solve :: Int -> Int
solve = M.foldr (+%) 0.(ans!!)
  where
  ans = M.empty : M.empty : M.empty
        : (M.fromList.(`zip`repeat 1).filter correct.replicateM 3) "AGCT"
        : map f (drop 3 ans)
  f pMap = foldr g M.empty correctStrs4
    where g head4 = M.insertWith (+%) (init head4) (pMap!tail head4)
  correctStrs4 = filter correct $ replicateM 4 "ACGT"
  correct ('A':'G':'C': _ ) = False
  correct [ _ ,'A','G','C'] = False
  correct ('A':'C':'G': _ ) = False
  correct [ _ ,'A','C','G'] = False
  correct ('G':'A':'C': _ ) = False
  correct [ _ ,'G','A','C'] = False
  correct ['A', _ ,'G','C'] = False
  correct ['A','G', _ ,'C'] = False
  correct _ = True

infixl 6 +%
a +% b = (a+b)`mod`1000000007

Measured memory_bytes: 3324
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
   //  String[] O=sc.nextLine().split(" ");
     String[] E=sc.nextLine().split("");

//int n=Integer.parseInt(nyuA);

//int H=Integer.parseInt(O[0]);
//int W=Integer.parseInt(O[1]);

HashSet<String> list=new HashSet<>();

for(int i=0;i<E.length;i++){
list.add(E[i]);
}

if(list.size()==E.length)
System.out.println("yes");
else
System.out.println("no");



//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;


int main() {
	int n; cin >> n;
	vector<int> t(n + 2);
	vector<double> v(n + 2), va;
	for (int i = 1; i <= n; i++) cin >> t[i];
	for (int i = 1; i <= n; i++) cin >> v[i];
	for (int i = 1; i <= n; i++) t[i] += t[i - 1];
	for (int i = 0; i <= n; i++) t[i] *= 2;
	for (int i = 0; i <= t[n]; i++) {
		double s = i/2.;
		for (int j = 1; j <= n; j++) {
			if (t[j - 1] <= i && i <= t[j]) s = min(s, v[j]);
			else if (i < t[j - 1]) s = min(s, v[j] + abs(t[j - 1] - i)/2.);
			else if (t[j] < i) s = min(s, v[j] + abs(t[j] - i)/2.);
		}
		s = min(s, abs(t[n] - i) / 2.);
		va.push_back(s);
	}

	double ans = 0;
	for (int i = 0; i < (int)va.size() - 1; i++) {
		ans += 0.5*(va[i + 1] + va[i]) / 2.;
	}
	cout << fixed << setprecision(10000000) << ans << endl;
	return 0;
}

Measured memory_bytes: 59320
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,l,x,y,di,num;
int d1[101][101],d2[101][101],d[101][101];
int main(){
  while(cin>>n>>m>>l,n){
    memset(d1,0,sizeof(d1));
    memset(d2,0,sizeof(d2));
    r(i,n)r(j,101)d[i][j]=1e8;
    r(i,m){
      cin>>x>>y>>di>>num;x--;y--;
      d1[y][x]=d1[x][y]=di;
      d2[y][x]=d2[x][y]=num;
    }
    d[0][l]=0;
    r(o,n)r(i,n)r(j,n)if(d1[i][j])r(k,l+1)if(d[i][k]!=1e8){
      if(d1[i][j]<=k)d[j][k-d1[i][j]]=min(d[j][k-d1[i][j]],d[i][k]);
      d[j][k]=min(d[j][k],d[i][k]+d2[i][j]);
    }
    int ans=1e9;
    r(i,l+1)ans=min(ans,d[n-1][i]);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<stack>

using namespace std;
int a[200];
int main(){
    int n, count=0;
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    int flag = 1;
    while(flag){
        flag = 0;
        for(int i=n-1;i>0;i--){
            if(a[i]<a[i-1]){
                int tmp = a[i];
                a[i] = a[i-1];
                a[i-1] = tmp;
                flag = 1;
                count++;
            }
        
        }
    }
    for(int i=0;i<n;i++){
        if(i!=0) cout << " ";
        cout << a[i];
    }
    cout << "\n" << count << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  ll H;
  cin >> H;
  
  ll cnt = 1;
  int r = 1;
  
  ll X = H;
  while (X > 1) {
    cnt += 1LL<<r;
    X /= 2;
    ++r;
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#define zero(n)(fabs(n)<.01)
main(n,a,b,c,d,p,q,r,D,f){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d);//fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;   //won't lose generality
		p=3*a,q=2*b,r=c,D=q*q-4*p*r;  //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)&&y1*y2>0)goto one;
			puts(
				zero(x1)?(
					d==0?"1 0":"2 1"
				):zero(x2)?(
					d==0?"0 1":"1 2"
				):x1>0?(
					d>0?"2 1":d<0?"3 0":"2 0"
				):x2<0?(
					d>0?"0 3":d<0?"1 2":"0 2"
				):(
					d>0?"2 1":d<0?"1 2":"1 1"
				)
			);
		}else if(D==0)
			puts(d>0?"0 1":d<0?"1 0":"0 0");
		else{one:
			puts(d>0?"0 1":d<0?"1 0":"0 0");
		}
	}
	exit(0);
}

Measured memory_bytes: 580
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main () {
	
	int N;
	scanf("%d",&N);
	
	int ans[N+1];
	for(int i=0;i<N+1;i++){
		ans[i] = 0;
	}
	
	int A[N+1];
	for(int i=2;i<=N;i++){
		scanf("%d",&A[i]);
		ans[A[i]]++;
	}
	
	for(int i=1;i<=N;i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gya(ll n,ll p,ll m){
	ll b=1;
	while (p>0) {
		if(p%2)b=(b*n)%m;
		n=(n*n)%m;
		p/=2;
	}
	return b;
}
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[214514];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	ll ans=0,mod=1e9+7;
	ll x=1,y=1;
	for(int i=1;i<k;i++){
		x*=n+1-i;
		x%=mod;
		y*=i;
		y%=mod;
	}
	x=x*gya(y,mod-2,mod);
	x%=mod;
	//cout<<x<<endl;
	for(int i=n;i>=k;i--){
		x*=i-k+1;
		x%=mod;
		x*=gya(i,mod-2,mod);
		x%=mod;
		//cout<<x<<endl;
		ans+=(3*mod+a[i-1]-a[n-i])*x;
		ans%=mod;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4344
#include <bits/stdc++.h>
#include <vector>
using namespace std;
vector<int64_t> A(100);
int64_t luc(int n){
if(n==0){return A.at(0)=2;}
if(n==1){return A.at(1)=1;}
else if(A.at(n)!=0){return A.at(n);}
else return A.at(n)=luc(n-1)+luc(n-2);}

int main(){
int N;
cin>>N;
cout<<luc(N)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct ball
{
    int num;
    string s;
};
int main()
{
    ball a,b;
    string u;
    cin>>a.s>>b.s>>a.num>>b.num>>u;
    if(u==a.s)
        a.num--;
    else
        b.num--;
    cout<<a.num<<" "<<b.num<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int n, k, q;
    cin>>n>>k>>q;
    vector<int> ten(n);
    rep(i, n) ten[i] = k;
    int index;
    rep(i, q){
        cin >> index;
        ten[index-1]+=1;
    }

    rep(i, n){
        if(ten[i]-q<=0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N, c[1000], w[1000], sum[1000];

int s(int l, int r){
	return (r-1 < 0 ? 0 : sum[r-1]) - (l-1 < 0 ? 0 : sum[l-1]);
}

int memo2[1000][1001];
bool sol(int l, int r){ //[l,r)
	if(r-l == 1) return true;
	if(memo2[l][r] != INT_MIN) return memo2[l][r];
	bool ret = false;
	if(c[l] >= s(l+1, r) && sol(l+1, r)) ret = true;
	if(c[r-1] >= s(l, r-1) && sol(l, r-1)) ret = true;
	return memo2[l][r] = ret;
}

int memo[1000];
int solve(int l){
	if(l == N) return 0;
	if(memo[l] != INT_MIN) return memo[l];
	int ret = INT_MAX;
	for(int i=l+1; i<=N; i++){
		if(sol(l, i)) ret = min(ret, solve(i)+1);
	}
	return memo[l] = ret;
}

signed main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> c[i] >> w[i];
		sum[i] = (i == 0 ? 0 : sum[i-1]) + w[i];
		memo[i] = INT_MIN;
		for(int j=0; j<N; j++) memo2[i][j+1] = INT_MIN;
	}
	cout << solve(0) << endl;
}


Measured memory_bytes: 7088
#include<iostream>
#include<list>
using namespace std;
class Graph{
public:
  int V;
  list<int> *adj;
  Graph(int v){
    V=v;
    adj=new list<int>[v+1];
  }
  void addEdge(int a,int b){
    adj[a].push_back(b);
  }
};
int Ldis(int x,Graph g,int *dp){
  if(g.adj[x].size()==0){
    dp[x]=0;
  }
  if(dp[x]!=-1){
    return dp[x];
  }
  else{
    int maxd=0;
    for(int j:g.adj[x]){
      if(Ldis(j,g,dp)>maxd) maxd=Ldis(j,g,dp);
    }
    dp[x]=1+maxd;
    return dp[x];
  }
  
}

int main(){
  int n,m;
  cin>>n>>m;
  Graph g(n);
  while(m--){
    int x,y;
    cin>>x>>y;
    g.addEdge(x,y);
  }
  int dp[100005];
  for(int i=0;i<100005;i++){
    dp[i]=-1;
  }
  int l=0;
  for(int i=0;i<=n;i++){
    if(l<Ldis(i,g,dp)) l=Ldis(i,g,dp);
  }
  cout<<l<<endl;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define repvin(n) vint a(n);r(i,n)cin>>a[i];
#define int long long
#define str string
#define vint vector<signed>
#define pint pair<signed,signed>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define mx 60

int n,m;
vint a(mx),b(mx);
bool visited[mx],graph[mx][mx];

void dfs(int s){
  visited[s]=true;
  for(int node=0;node<n;++node){
    if(graph[s][node]&&!visited[node])dfs(node);
  }
}

signed main(){
  cin>>n>>m;
  repi(m)cin>>a[i]>>b[i];
  repi(m)a[i]--,b[i]--;
  repi(m){
    graph[a[i]][b[i]]=true;
    graph[b[i]][a[i]]=true;
  }
  int res=0;
  repi(m){
    graph[a[i]][b[i]]=false;
    graph[b[i]][a[i]]=false;
    rep(j,n)visited[j]=false;
    dfs(0);
    bool bridge=false;
    rep(j,n)if(!visited[j])bridge=true;
    if(bridge)res++;
    graph[a[i]][b[i]]=true;
    graph[b[i]][a[i]]=true;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<string,int> hashh;
int n,ans;
char s[23];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if (hashh.find(s)==hashh.end())
		{
			hashh.insert(pair<string, int>(s,1));
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

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

int solve(string s, string t){
	int ans = 0;
	for(int i=0 ; i < s.size() ; i++ ){
		string s_ = s.substr(i);
		int len = min( s_.size() , t.size() );
		int a[4001] = {0};
		
		for(int j=0 ; j < len ; j++ ){
			if( s_[j] == t[j] ) a[j] = 1;
		}
		
		int sum=0;
		for(int j=1 ; j < len ; j++ ){
			if( a[j-1] > 0 && a[j] > 0 ){
				a[j] = a[j-1] + 1;
				sum = max( sum , a[j-1] + 1 );
			}
		}
		ans = max( ans , sum );
	}
	return ans;
}

int main(){
	string s,t;
	while( cin >> s >> t ){
		int ans = max( solve(s,t) , solve(t,s) );
		cout << ans << endl;
	}
}

Measured memory_bytes: 960
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, M = NMI()
    uf = UnionFind(N)
    for i in range(M):
        x, y, z = NMI()
        uf.unite(x-1, y-1)
    gc = uf.group_count()
    print(gc)


class UnionFind:
    def __init__(self, n):
        #親要素のノード番号を格納　xが根のとき-(サイズ)を格納
        self.par = [-1 for i in range(n)]
        self.n = n

    def find(self, x):
        #根ならその番号を返す
        if self.par[x] < 0:
            return x
        else:
            #親の親は親
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def is_same(self, x, y):
        #根が同じならTrue
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return

        #木のサイズを比較し、小さいほうから大きいほうへつなぐ
        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


if __name__ == "__main__":
    main()

Measured memory_bytes: 8244
#include <stdio.h>

int main(){
  int N,c=0;
  scanf("%d",&N);
  for(int i=1;i<=9;i++){
    if(N%i==0 && N/i<=9) c=1;
  }
  if(c) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) { cout << "Yes"; }
	else if (s[3] == s[2] && s[1] == s[2]) { cout << "Yes"; }
	else  { cout << "No"; }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e5 + 5;

int N;
int W[maxn];
vector<ii> G[maxn];
int child[maxn], par[maxn];
int spEdge = 0, spVert = 0;
ll ans = 0;

void dfs(int v, int pE) {
	child[v] = 1;
	int mx_child = 0;
	for (auto &e : G[v]) {
		int w, u; tie(w, u) = e;
		if (u == par[v]) continue;
		par[u] = v;
		dfs(u, w);
		child[v] += child[u]; mx_child = max(mx_child, child[u]);
	}
	if (child[v] * 2 == N) spEdge = pE;
	if (max(mx_child, N - child[v]) <= N / 2) spVert = v;
	ans += 2LL * W[pE] * min(child[v], N - child[v]);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> N;
	for (int i = 1; i < N; ++i) {
		int u, v; cin >> u >> v >> W[i];
		G[u].push_back(ii(i, v));
		G[v].push_back(ii(i, u));
	}
	dfs(1, 0);
	if (spEdge) {
		cout << ans - W[spEdge] << endl;
	} else {
		int mn = 1e9;
		for (auto &e: G[spVert]) mn = min(mn, W[e.first]);
		cout << ans -  mn << endl;
	}
}

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

long long n;
string s;

int main() {
  cin >> n >> s;
  for(int i = 0; i < s.size(); ++i)
    s[i] = ((s[i] - 'A') + n) % 26 + 'A';

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int n;
cin >> n;
cout << n*n*n << endl;


return 0;
}

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

int main()
{
        double x1, x2, y1, y2;

        cin >> x1 >> y1 >> x2 >> y2;

        cout.setf(ios::fixed, ios::floatfield);
        cout << sqrt(pow((x2-x1),2) + pow((y2-y1),2)) << endl;

        return 0;
}


Measured memory_bytes: 3284
n=int(input())
l=[]
for _ in range(n):
    a=int(input())
    ll=[]
    for i in range(a):
        x,y=map(int,input().split())
        x-=1
        ll.append((x,y))
    l.append(ll)
ans=0
for k in range(2**n):
    f=1
    c=0
    for i in range(n):
        if ((k>>i)&1)==0:
            continue
        for x,y in l[i]:
            if ((k>>x)&1)!=y:
                f=0
                break
    if f:
        for i in range(n):
            c+=((k>>i)&1)

        ans=max(ans,c)
print(ans)


Measured memory_bytes: 43372
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

int main() {
  size_t N, numc;

  std::cin >> N;
  std::cin >> numc;

  std::vector<std::vector<unsigned int>>
    D(numc, std::vector<unsigned int>(numc));

  for (size_t y=0; y<numc; y++) {
    for (size_t x=0; x<numc; x++) {
      std::cin >> D[x][y];
    }
  }

  std::vector<std::vector<unsigned int>>
    cmap(3, std::vector<unsigned int>(numc, 0));

  for (size_t y=0; y<N; y++) {
    for (size_t x=0; x<N; x++) {
      unsigned int c;
      std::cin >> c;
      c--;
      size_t g = (x + y) % 3;
      cmap[g][c]++;
    }
  }

  unsigned int ans =
    std::numeric_limits<decltype(ans)>::max();

  for (size_t x=0; x<numc; x++) {
    for (size_t y=0; y<numc; y++) {
      if (x==y) continue;
      for (size_t z=0; z<numc; z++) {
        if (x==z) continue;
        if (y==z) continue;
        unsigned int cost = 0;
        for (size_t c=0; c<numc; c++) {
          cost += cmap[0][c] * D[x][c];
          cost += cmap[1][c] * D[y][c];
          cost += cmap[2][c] * D[z][c];
        }

        ans = std::min(ans, cost);
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n % m == 0){
				System.out.println(0);
			}
			else{
				System.out.println(1);
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 21844
package main

import (
	"fmt"
)

const mod = int(1e9 + 7)

var ifac, fac []int

var n, m int

func main() {
	const cmax = int(5e5 + 1)
	fac = make([]int, cmax)
	ifac = make([]int, cmax)
	inv := make([]int, cmax)
	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[0], inv[1] = 1, 1
	for i := 2; i < cmax; i++ {
		fac[i] = (fac[i-1] * i) % mod
		inv[i] = (mod - inv[mod%i]*(mod/i)) % mod
		if inv[i] < 0 {
			inv[i] += mod
		}
		ifac[i] = (ifac[i-1] * inv[i]) % mod
	}

	fmt.Scan(&n, &m)

	var pt int
	for fx := 0; fx <= n; fx++ {
		b := comb(n, fx) * perm(m-fx, n-fx)
		if fx%2 == 0 {
			pt += b
		} else {
			pt -= b
		}
		pt %= mod
	}
	if pt < 0 {
		pt += mod
	}

	fmt.Println(perm(m, n) * pt % mod)
}

func comb(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 || r == n {
		return 1
	}
	t := (ifac[n-r] * ifac[r]) % mod
	return (t * fac[n]) % mod
}

func perm(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 {
		return 1
	}
	return (fac[n] * ifac[n-r]) % mod
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 14016
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void start(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("input.txt","r")){
        freopen ("input.txt" , "r" , stdin);
        freopen ("output.txt" , "w" , stdout);
    }
    #endif
}
signed main(){
    start();

    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    int count = 0;
        for(int i=1;i<=a;i++){
            ans++;
            count++;
            if(count == k){
                cout<<ans;
                return 0;
            };
        }
        for(int i=1;i<=b;i++){
            count++;
            if(count == k){
                cout<<ans;
                return 0;
            };
        }
        for(int i=1;i<=c;i++){
            ans--;
            count++;
            if(count == k){
                cout<<ans;
                return 0;
            };
        }
    
    //cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
struct edge{int to,cost;};
vector<edge>v[100010];
int color[100010];
bool used[100010];
void dfs(int x){
    used[x]=true;
    for(edge e:v[x]){
        if(!used[e.to]){
            if(e.cost%2==0)color[e.to]=color[x];
            else color[e.to]=1-color[x];
            dfs(e.to);
        }
    }
}
signed main(){
    cin>>n;
    rep(i,n-1){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        v[a].pb({b,c});
        v[b].pb({a,c});
    }
    color[0]=0;
    dfs(0);
    rep(i,n)cout<<color[i]<<endl;
    return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, l; cin >> n >> l;
    vector<string> s(n);
    rep(i, n){
        string tmp;
        cin >> tmp;
        //sort(tmp.begin(), tmp.end());
        s.at(i) = tmp;
    }
    sort(s.begin(), s.end());
    string ans;
    rep(i, n){
        ans += s.at(i);
    }

    cout << ans << endl;
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str= sc.nextLine();
		int min = 999;
		for (int i = 0; i < str.length() - 2; i++) {
			int temp = Integer.parseInt(str.substring(i, i + 3));
			temp = Math.abs(753 - temp);
			min = min > temp ? temp : min;
		}
		System.out.println(min);
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	ll X;
	cin >> X;

	cout << (X/500)*1000 + (X%500)/5*5 << endl;

	return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

void solve(){
	int n; cin >> n;
	vector<int> k(n);
	vector<ll> l(n), r(n);
	for(int i=0; i<n; i++){
		cin >> k[i] >> l[i] >> r[i];
	}

	ll ans = 0;
	vector<pair<int, ll>> ls, rs;
	for(int i=0; i<n; i++){
		if(l[i]<r[i]){
			ans += l[i];
			rs.push_back({n-k[i], r[i]-l[i]});
		}else if(r[i]<l[i]){
			ans += r[i];
			ls.push_back({k[i], l[i]-r[i]});
		}else{
			ans += l[i];
		}
	}

	sort(ls.rbegin(), ls.rend());
	sort(rs.rbegin(), rs.rend());

	priority_queue<ll> lque;
	int j=0;
	for(int i=ls.size()-1; i>=0; i--){
		while(j<ls.size()&&i<ls[j].first){
			dbg(i, j, ls[j].first, ls[j].second);
			lque.push(ls[j].second);
			j++;
		}
		if(lque.size()){
			dbg("l", lque.top());
			ans += lque.top();
			lque.pop();
		}
	}

	j=0;
	priority_queue<ll> rque;
	for(int i=rs.size()-1; i>=0; i--){
		while(j<rs.size()&&i<rs[j].first){
			dbg(i, j, rs[j].first, rs[j].second);
			rque.push(rs[j].second);
			j++;
		}
		if(rque.size()){
			dbg("r", rque.top());
			ans += rque.top();
			rque.pop();
		}
	}

	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int t; cin >> t;
	for(int i=0; i<t; i++) solve();
	return 0;
}


Measured memory_bytes: 11992
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using  namespace std;

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << endl;

using db = long double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define scl1(a)             scanf(“%I64d", &a)
#define scl2(a, b)          scanf("%lld %lld", &a, &b)

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;
const int inf = 0x3f3f3f3f;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){

	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k,n;
string s;
cin>>s;
	n=s.size();
	ll a[n+1];			rep(i,0,n+1,1)	a[i]=-1;
	// k=1,j=0,x=1;
	// ce(n)
	if(s[0]=='<')	a[0]=0;
	if(s[n-1]=='>')		a[n]=0;

	rep(i,0,n+1,1){
		if(s[i]=='>'&& s[i+1]=='<'){
			a[i+1]=0;
		}
	}
	rep(i,0,n+1,1){
		if(a[i]==0){
			x=1;	i++;
			while(i<=n && a[i]==-1  && s[i-1]=='<'){	//
				a[i]=x++;
				i++;
			}
			i--;
		}
	}
	// rep(i,0,n+1,1){	cout<<a[i]<<" "; } ce("")
	for(i=n;i>=0;i--){
		if(a[i]==0){
			i--;
			while(i>=0  && s[i]=='>'){	// && a[i]==-1
				a[i]=a[i+1]+1;
				i--;
			}
			i++;
		}
	}
	rep(i,0,n,1){
		if(s[i]=='<'){
			if(!(a[i]<a[i+1]))	a[i+1]=a[i]+1;
		}
	}
	ll sum=0;
	rep(i,0,n+1,1){
		sum+=a[i];
		// cout<<a[i]<<" "; 
	}
	// ce("")
	ce(sum)
}
/*
0<1>0>-1>-2<-1<0>-1<0<1<2<3<4>3>2>1<2
2<3>2>1>0<1<2>1<2<3<4<5<6>5>4>3<4
0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1
*/

Measured memory_bytes: 4764
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  int s[100]={0};
  REP(i,N){
    int k=i+1;
    FOR(j,2,k+1){
      while(k%j==0){
        k/=j;
        s[j]++;
      }
    }
  }
  // REP(i,10)cerr<<s[i]<<endl;
  int ans=0;
  REP(i,100)if(s[i]>=74)ans++;
  REP(i,100)REP(j,100){
    if(i==j)continue;
    if(s[i]>=2 and s[j]>=24)ans++;
    if(s[i]>=4 and s[j]>=14)ans++;
  }
  REP(i,100)REP(j,100)REP(k,j){
    if(i==j or i==k)continue;
    if(s[i]>=2 and s[j]>=4 and s[k]>=4)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    int sum=0,sum2=0;
    cin>>n>>m;
   // vector<int>v;

    int arr[n+1][m+1];
  for(int i=0;i<n;i++){

  for(int j=0;j<m;j++){
  cin>>arr[i][j];
    sum+=arr[i][j];
  }
//cout<<i<<m<<endl;
arr[i][m]=sum;
sum=0;


  }
  for(int j=0;j<=m;j++){
   for(int i=0;i<n;i++){
    sum2+=arr[i][j];
   }
   arr[n][j]=sum2;
   sum2=0;
  }
int k;
for(int i=0;i<=n;i++){
  for(int j=0;j<m;j++){
cout<<arr[i][j]<<" ";
 k=j;
  }
  cout<<arr[i][m];
cout<<endl;
  }
}



Measured memory_bytes: 3136
#include<stdio.h>
int main(void){
    int n;
    int flag = 0;
    scanf("%d",&n);
    if(n > 81){
        flag=0;
    }
    else{
        for(int i=1;i<=9;i++){
            if(n%i == 0 && n/i <= 9){
                flag=1;
                break;
            }
        }
    }
    if(flag==1){
        printf("Yes");
    }
    else{
        printf("No");
    }

}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    lint a,b,n; cin>>a>>b>>n;

    lint rn = min(b-1, n);
    cout<< a*rn/b;
}


Measured memory_bytes: 3640
n = gets.to_i
c = []
s = []
f = []
(1..n - 1).each do |i|
  c[i], s[i], f[i] = gets.split.map(&:to_i)
end

(1..n - 1).each do |i|
  total = 0
  (i..n - 1).each do |j|
    total = s[j] if total < s[j]
    total = ((total - 1) / f[j] + 1) * f[j]
    total += c[j]
  end
  puts total
end
puts 0


Measured memory_bytes: 3836
time = [int(input()) for i in range(5)]
lst = []
for i in time:
  lst.append(i%10)
lst.sort()
while 0 in lst:
  lst.remove(0)
times = []
for i in lst[1:]:
  times.append(10-i)
total = sum(time) + sum(times)
print(total)

Measured memory_bytes: 3060
#include <stdio.h>
 
int main() {
  int n, m, x, ans = 1e9+7, i, j, k, a[20][20], b[20], c[20], s;
  scanf("%d %d %d",&n, &m, &x);
  
  for(i = 0; i < n; i++) {
      scanf("%d",&c[i]);
      for(j = 0; j < m; j++)
      scanf("%d",&a[i][j]);
    }
    for(i = 0; i < (1 << n); i++) { /*full search by shift operation*/
        for(j = 0; j < m; j++)
        b[j] = 0; /*b means the sum of improvement on the "j" condition*/
        for(j = s = 0; j < n; j++) {
            if((i & (1 << j)) == 0)
            continue;
            s += c[j];
            for(k = 0; k < m; k++)
            b[k] += a[j][k];
        }
        for(j = 0; j < m; j++) {
            if(b[j] < x) /*if skill level is less than x*/
            goto NEXT;
        }
        if(ans > s)
        ans=s; /*record minimum*/
        NEXT:; /*not update*/
    }
    printf("%d\n",ans>1e9?-1:ans);
    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1, dy = y2 - y1;
  cout << x2 - dy << ' ' << y2 + dx << ' ' << x1 - dy << ' ' << y1 + dx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);
string S;
  cin>>S;
  

    if(S=="AAA"||S=="BBB"){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int a[500];
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= 2 * n; i++)
        cin >> a[i];
    sort(a + 1, a + 2 * n + 1);
    int ans = 0;
    for(int i = 2 * n - 1; i >= 1; i -= 2)
    {
        ans += a[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
	int N;	cin >> N;
	long long ans=0,b,a;
	vector<long long> A(N);
	for (long long i = 0; i < N; i++) {
		cin >> a; A[i] = a - i-1;
	}
	sort(A.begin(), A.end());
	if (N % 2 == 1) b = A[N / 2];
	else b = (A[(N - 1) / 2] + A[N / 2]) / 2;
	for (int i = 0; i < N; i++) {
		ans += abs(A[i] - b);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
N=int(input())
st=[]
a=0
b=0
for i in range(N):
    st.append(list(map(str,input().split())))
X=str(input())
for i in range(N):
    if st[i][0]==X:
        a=i
for i in range(a+1,N):
    b+=int(st[i][1])
print(b)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long int res = 1;
    vector<long long int> v;
    for (int i = 0; i < n; i++) {
        long long int t;
        cin >> t;
        v.push_back(t);
        if (t == 0) res = 0;
    }
    for (int i = 0; i < n; i++) {
        if ((v[i] > 0 && res * v[i] < res) || res * v[i] > (long long int)1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
        res *= v[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 4256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll t,n,d;
int main()
{
	SPEED;
	cin>>t;
	while(t--)
	{
		cin>>n>>d;
		n--;
		ll ans=0;
		if(n%2==0)
			ans=(n)*127+d;
		else
			ans=(n)*127+(d^127);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>  // is_any_of
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;


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

    int N = S.size();
    int M = N - 1;

    ll ans = 0;
    for (int bit = 0; bit < (1 << M); bit++) {
        string s = S;
        for (int i = 0; i < M; i++) {
            if (bit & (1 << i)) {
                s.insert(M - i, "+");
            }
        }
        vector<string> T;
        boost::algorithm::split(T, s, boost::is_any_of("+"));
        for (auto t : T) {
            ans += stoll(t);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3644
#ika tako
import sys
n, q = map(int, input().split())
lines = sys.stdin.readlines()
links = [set() for _ in range(n)]
for line in lines[:n - 1]:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
adds = [0] * n
for line in lines[n - 1:]:
    p, x = map(int, line.split())
    p -= 1
    adds[p] += x
ans = [-1] * n
q = [(0, 0)]
while q:
    v, a = q.pop()
    a += adds[v]
    ans[v] = a
    for u in links[v]:
        if ans[u] == -1:
            q.append((u, a))
print(*ans)

Measured memory_bytes: 118628
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll h, w, n;
    cin>>h>>w>>n;
    ll sr, sc;
    cin>>sr>>sc; sr--; sc--;
    string s, t;
    cin>>s>>t;

    int cur = sr;
    rep(i, n) {
        if (s[i] == 'U') cur--;
        if (cur < 0) {
            cout<<"NO"<<endl;
            return 0;
        }
        if (t[i] == 'D' && cur < h - 1) cur++;
    }
    cur = sr;
    rep(i, n) {
        if (s[i] == 'D') cur++;
        if (cur >= h) {
            cout<<"NO"<<endl;
            return 0;
        }
        if (t[i] == 'U' && cur > 0) cur--;
    }
    cur = sc;
    rep(i, n) {
        if (s[i] == 'L') cur--;
        if (cur < 0) {
            cout<<"NO"<<endl;
            return 0;
        }
        if (t[i] == 'R' && cur < w - 1) cur++;
    }
    cur = sc;
    rep(i, n) {
        if (s[i] == 'R') cur++;
        if (cur >= w) {
            cout<<"NO"<<endl;
            return 0;
        }
        if (t[i] == 'L' && cur > 0) cur--;
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 920
import java.util.*;
 
public class Main {
	
    public static void main( String args[] ) {
        Scanner scan	= new Scanner( System.in );

		while( true ) {
			// 文字列入力
			String	n		= scan.next();
			if ( n.equals("-") ) {
				break;
			}

			// 処理
			int	m = scan.nextInt();
			for( int i = 0; i < m; i++ ) {
				int h = scan.nextInt();
				n = n.substring( h, n.length() ) + n.substring( 0, h );

			}

			// 出力
			System.out.println( n );
		}
		
		scan.close();
	}
}

Measured memory_bytes: 18284
#include <bits/stdc++.h>
using namespace std;
  
/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */
  
int main()
{
    double  a, b, c;
          
    cin >> a >> b >> c;
              
    double q = M_PI * c / 180;
                  
    printf("%f\n", a * b / 2 * sin(q));
    printf("%f\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(q)));
    printf("%f\n", b * sin(q));

    return (0);
}

Measured memory_bytes: 3616
#include <stdio.h>
#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define BLACK 2
#define GRAY 1

int n, M[MAX][MAX];

int prim(){
    int u,minv;
    int d[MAX],p[MAX],color[MAX];
    
    for(int i=0; i<n; i++){
        d[i]=INFTY;
        p[i]=-1;
        color[i]=WHITE;
    }
    
    d[0]=0;
    
    while (1) {
        minv=INFTY;
        u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u=i;
                minv=d[i];
            }
        }
        
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > M[u][v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    
    int sum =0;
    for(int i=0; i<n; i++){
        if(p[i] != -1) sum+= M[i][p[i]];
    }
    return sum;
}

int main(){
    scanf("%d",&n);
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            int e;
            scanf("%d",&e);
            M[i][j] = (e == -1) ? INFTY:e;
            
        }
    }
    printf("%d\n", prim());
    return 0;
}



Measured memory_bytes: 2800
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (int c = 0;; c++) {
			int n = sc.nextInt();
			int t = sc.nextInt();
			if (n + t == 0) {
				break;
			}
			int m[] = new int[n];
			int l[] = new int[n];
			int k[] = new int[n];

			for (int i = 0; i < n; i++) {
				m[i] = sc.nextInt();
				l[i] = sc.nextInt();
				k[i] = sc.nextInt();
			}

			for (int z = 1;; z++) {
				boolean ok = false;
				int f = 0;
				int m2[] = new int[n];
				int st[] = new int[n]; // l,m , k
				int ope = z;
				int map[] = new int[n];
			
				for (int i = 0; i < n; i++) {
					m2[i] = l[i];
					map[i] = i;
				}
				
				for (int a = 0;;) {
	/*				System.out.println(a+":");
					for(int i = 0 ; i < n ; i++){
					System.out.println(" "+st[i]+" "+m2[i]);
					}*/
					if (f == n) {
						ok = true;
						break;
					}
					if (a >= t + 1) {

						break;
					}
					int mini = t + 1;
					int mini2 = t + 1;

					int j = 0;
					int n2 = n-f;
					
					for (int ii = 0; ii < n2; ii++ , j++) {
						int i = map[ii];
						if (st[i] == 1) {
							if (m2[i] <= a) {
								f++;
								if(n==f){
									break;
									
								}
								st[i] = 3;
								ope++;
								j--;
								continue;
							} else {
								mini = Math.min(m2[i], mini);
							}
						}
						if (st[i] == 0) {
							int za = a % (l[i] + k[i]);
							if (za <= l[i]) {
								if (ope > 0) {
									ope--;
									st[i] = 1;
									m2[i] = m[i] + a;
									mini = Math.min(mini, m2[i]);
								}
							} else {
								m2[i] =l[i]+k[i] - za + a;
								mini2 = Math.min(mini2, m2[i]);
							}
						}
						map[j] = i;
					}
					if (f == n) {
						ok = true;
						break;
					}

					if (ope > 0) {
						mini = Math.min(mini2, mini);
					}

					a = mini;

				}
				if (ok) {
					System.out.println( z);
					break;
				}
			}
		}
	}

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

	}

}

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

string ilham, bojos;
int ndaru;
int main(){
	cin >> ilham;
	ndaru = ilham.length();
	for(int i = ndaru-1; i >= 0; i--){
		bojos = bojos + ilham[i];
	}
	cout << bojos << "\n";
	
	return 0;
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n;
int a[200010];
int l[200010], r[200010];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		if (i == 0) continue;
		l[i] = max(a[i - 1], l[i - 1]);
	}
	Rep(i, n) {
		if (i == n - 1) continue;
		r[i] = max(a[i + 1], r[i + 1]);
	}
	rep(i, n) {
		cout << max(l[i], r[i]) << endl;
	}
}


Measured memory_bytes: 6272
using System;
using System.Collections.Generic;


public class Contest
{
	public static void Main()
	{
		int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));

//		int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] c = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
//		int[] d = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
/*
		int n = a[0];
		int[][] e = new int[n][];
		for(int i=0; i<n; i++) e[i] = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string,int>(s => int.Parse(s)));
*/




		string ans = ((a[0]==3)||(a[0]==5)||(a[0]==7))?"YES":"NO";

		Console.WriteLine(ans);
	}
	
	private static int calc_main(int[] a,int[] b,int[] c,int[] d) {



		return 0;
	}




}


Measured memory_bytes: 11092