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

using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
const int N = 2e5+5;
char a[N],b[N];

vector<int>y[30];
int vis[30];
int main()
{
    scanf("%s%s",a,b);
    for(int i=0;i<26;i++)y[i].pb(0);
    int len=strlen(a);
    for(int i=0;i<len;i++){
        y[b[i]-'a'].pb(i);
        y[b[i]-'a'][0]++;
    }
    int flag=1;
    for(int i=0;i<26;i++){
        if(!y[i][0])continue;
        char x=a[y[i][1]];
        if(vis[x-'a'])flag=0;
        vis[x-'a']=1;
        for(int j=2;j<=y[i][0];j++){
            if(a[y[i][j]]!=x)flag=0;
        }
    }
    printf("%s\n",flag?"Yes":"No" );
    return 0;
}

Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

int main() {//s N c M
	ll N, M;
	cin >> N >> M;
	if (N * 2 >= M) cout << M / 2 << endl;
	else cout << (N * 2 + M) / 4 << endl;
}

Measured memory_bytes: 256
import bisect
import heapq
import sys
import queue


input = sys.stdin.readline
sys.setrecursionlimit(100000)


class V:
    def __init__(self, f):
        self.f = f
        self.v = None

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if self.v is None:
            self.v = n
        else:
            self.v = self.f(self.v, n)

    def get(self):
        return self.v


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    X, Y = read_values()
    if X % Y == 0:
        print(-1)
    else:
        print(X * (Y + 1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3952
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x : x[0])
ans = 0
for AB in AB:
    if M <= AB[1]:
        ans += M * AB[0]
        break
    else:
        ans += AB[0] * AB[1]
        M -= AB[1]
print(ans)

Measured memory_bytes: 28560
#include<stdio.h>

int masu[100][100];
int n,m;
int ans,max;

void func(int x,int y){
	masu[x][y] = 0;
	ans++;
	if(max < ans) max = ans;
	if(masu[x][y+1] == 1 && y+1<100){
		func(x,y+1);
		masu[x][y+1] = 1;
	}
	if(masu[x][y-1] == 1 && y-1>-1){
		func(x,y-1);
		masu[x][y-1] = 1;
	}
	if(masu[x+1][y] == 1 && x+1<100){
		func(x+1,y);
		masu[x+1][y] = 1;
	}
	if(masu[x-1][y] == 1 && x-1>-1){
		func(x-1,y);
		masu[x-1][y] = 1;
	}
	masu[x][y] = 1;
	ans--;
}


int main(void){
	while(scanf("%d%d",&m,&n) && n && m){
		for(int i = 0 ; i < n; i++){
			for(int j = 0; j < m ;j++){
				scanf("%d",&masu[i][j]);
			}
		}
		
		for(int i = 0 ; i < n; i++){
			for(int j = 0; j < m ;j++){
				if(masu[i][j] == 1){
					ans=0;
					func(i,j);
				}
			}
		}
		
		printf("%d\n",max);
		max = 0;
		for(int i = 0 ; i < n; i++){
			for(int j = 0; j < m ;j++){
				masu[i][j]=0;
			}
		}
	}
	return 0;
}

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

int n;
cin>> n;
int a[2][n];
rep(i,2)rep(j,n) cin >> a[i][j];
vector<int> vec(n);
rep(j,n){
    int cnt=0;
    for(int k=0; k<=j; k++) cnt+=a[0][k];
    for(int l=j; l<n; l++) cnt+=a[1][l];
    vec[j]=cnt;
}
sort(vec.begin(), vec.end(), greater<int>());
cout << vec[0] << endl;

}

Measured memory_bytes: 256
s = input()
c = 0
ans = 0
for i in range(len(s)):
    if (s[i]=="A" or s[i]=="C" or s[i]=="G" or s[i]=="T"):
        c += 1
        if (ans < c):
            ans = c
    else:
        c = 0
print(ans)

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#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;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = pow(10, 5) + 1;//+1しないとREになる(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

int main(void) {
	double H, N;
	cin >> H >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	std::sort(A.begin(), A.end(), std::greater<int>());
	//for (int i = 0; i < N; i++) cout << A[i] << endl;

	int sum = 0;
	for (int i = 0; i < N; i++) sum += A[i];

	if (sum >= H) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        string n=s;
        int minn=0,maxx=0;
        for(int i=1;i<s.size();i++)
        {
            if(s[i]==s[i-1])
            {
                if(s[i]=='0') s[i]='1';
                else s[i]='0';
                minn++;
            }
        }
//        cout<<minn<<endl;
        for(int i=n.size()-1;i>=1;i--)
        {
            if(n[i]==n[i-1])
            {
                maxx++;
                if(n[i-1]=='0') n[i-1]='1';
                else n[i-1]='0';
            }
        }
//        cout<<n<<endl;
        cout<<min(maxx,minn)<<endl;
    }
}


Measured memory_bytes: 512
N,K = list(map(int, input().split()))
H_1 = list(map(int, input().split()))
H_2 = sorted(H_1,reverse = True)
S=sum(H_2)
if N>K:
    for i in range(K):
        S -= H_2[i]
    print(S)
else:
    print(0)


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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var s = new string[N];
        int c1, c2, c3;
        c1 = c2 = c3 = 0;
        int ans = 0;
        var subStr = new System.Text.StringBuilder();
        for (int i = 0; i < N; i++)
        {
            var value = Console.ReadLine();
            s[i] = value;

            var startB = value.StartsWith("B");
            var endA = value.EndsWith("A");
            if (startB && endA)
            {
                c1++;
            }
            else if (startB && !endA)
            {
                c2++;
            }
            else if (!startB && endA)
            {
                c3++;
            }

            for (int j = 0; j < value.Length - 1; j++)
            {
                subStr.Clear();
                subStr.Append(value[j]).Append(value[j + 1]);
                if (subStr.ToString() == "AB") ans++;
            }
        }


        if (c1 == 0)
        {
            ans += Math.Min(c2, c3);
        }
        else if (c2 + c3 == 0)
        {
            ans += c1 - 1;
        }
        else
        {
            ans += c1 + Math.Min(c2, c3);
        }

        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 13468
#include <iostream>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main(){
	string s, t, po, ans;
	bool ok;

	cin >> s >> t;
	ok = true;
	ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
		
	REP(i,s.length()-t.length()+1){
		po = s;
		ok = true;
		REP(k,s.length()){
			if (i<=k && k<i+t.length()){
				po[k] = t[k-i];
			}else if (po[k]=='?'){
				po[k] = 'a';
			}
		}
		//debug(po);
		REP(k,s.length()){
			if (s[k]!=po[k] && s[k]!='?'){
				ok = false;
				break;
			}
		}
		if (po<ans && ok) ans = po;
	}
	
	if (ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"){
		cout << "UNRESTORABLE" << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}


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

using namespace std;

int main(void){

  int N;
  cin >> N;

  int a;
  set<int> paper;
  
  for(int i = 0; i < N; ++i){
    cin >> a;

    if(!paper.erase(a)){
      paper.insert(a);
    }
  }
  
  cout << paper.size() << endl;
  
  return 0;
}


Measured memory_bytes: 4864
from collections import defaultdict

def main():
    N = int(input())
    strs = defaultdict(int)
    for _ in range(N):
        str = list(input().rstrip())
        strs[''.join(sorted(str))] += 1

    ans = 0
    for freq in strs.values():
        if freq > 1:
            ans += (freq * (freq - 1)) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 101644
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Alice = []
Bob = []
for i in range(N):
  if i%2 == 0:
    Alice.append(A[i])
  else:
    Bob.append(A[i])

print(sum(Alice) - sum(Bob))

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

int main() {
  long N, cnt = 0, ans = 0;
  cin >> N;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (i%j == 0 && i%2 == 1) cnt++;
    }
    if (cnt == 8) ans++;
    cnt = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>
#define bufsize 1<<21
char ibuf[bufsize];
char *ptr=ibuf;

void readint(int *i)
{
    *i=0;
    while(*ptr>='0')
    {
        *i=*i*10+*ptr-'0';
        ++ptr;
    }
    ++ptr;
}


main()
{
    fread(ibuf,1,bufsize,stdin);

    int h,w,k,sx,sy,tx,ty;
    readint(&h);
    readint(&w);
    readint(&k);
    readint(&sx);
    readint(&sy);
    readint(&tx);
    readint(&ty);
    sx--,sy--,tx--,ty--;

    struct po {int x,y;};
    struct po qu[1<<20];
    struct po *beg=qu,*end=qu+1;
    beg->x=sx,beg->y=sy;
    unsigned int dist[1<<20];
    memset(dist,-1,sizeof(dist));
    dist[sx*w+sy]=0;
    while(beg!=end)
    {
        int x=beg->x,y=beg->y;
        unsigned int d=dist[x*w+y];
        ++beg;
        char *pt=ptr+x*(w+1)+y;
        char *const pcp=pt;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a++,z+=w;
            pt+=w+1;
            if(a==h||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b++,z++;
            pt++;
            if(b==w||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            a--,z-=w;
            pt-=w+1;
            if(a<0||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
        pt=pcp;
        for(int i=1,a=x,b=y,z=a*w+y; i<=k; i++)
        {
            b--,z--;
            pt--;
            if(b<0||*pt=='@'||dist[z]<=d) break;
            if(a==tx && b==ty)
            {
                printf("%u\n",d+1);
                return 0;
            }
            if(dist[z]!=d+1)
            {
                end->x=a,end->y=b;
                dist[z]=d+1;
                ++end;
            }
        }
    }
    puts("-1");
}


Measured memory_bytes: 11312
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[105];
int main(void)
{
	int i,n,ans=0,num=1;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=2;i<=n;++i)
	{
		if(a[i]==a[i-1])++num;
		else ans+=num/2,num=1;
	}
	ans+=num/2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
# D - Lucky PIN
N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            a = S.find(str(i))
            if a == -1:
                continue
            # i が含まれるとき
            b = S.find(str(j),a+1)
            if not(a < b):
                continue
            # j の index が a以降のとき
            c = S.find(str(k),b+1)
            if not(b < c):
                continue
            # k の index が b　以降のとき
            ans += 1
print(ans)

Measured memory_bytes: 63968
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI3(N, A, B);
  print(min(N * A, B));
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  ll N,S;
  cin>>N>>S;
  VL A(N);
  rep(i,N) cin>>A[i];
  ll mod=998244353;
  ll dp[3001][3001][3]={};
  dp[0][0][0]=1;
  rep(i,N){
    rep(j,3001){
      (dp[i+1][j][0]+=dp[i][j][0])%=mod;
      
      (dp[i+1][j][1]+=dp[i][j][0]+dp[i][j][1])%=mod;
      if(j+A[i]<=S) (dp[i+1][j+A[i]][1]+=dp[i][j][0]+dp[i][j][1])%=mod;
      
      (dp[i+1][j][2]+=dp[i][j][0]+dp[i][j][1]+dp[i][j][2])%=mod;
      if(j+A[i]<=S) (dp[i+1][j+A[i]][2]+=dp[i][j][0]+dp[i][j][1])%=mod;
    }
  }
  cout<<dp[N][S][2]<<endl;
}

Measured memory_bytes: 211456
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; i ++) {
    	ll x;
    	cin >> x;
    	ans   += (x & 1);
	}
	cout << (ans & 1 ? "NO" : "YES");
    return (0);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;


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

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n =  s.nextInt();
		int[] ar = new int[n];
		double sum=0;
		for(int i=0;i<n;i++) {
			ar[i]=s.nextInt();
			sum+=(double)1/ar[i];
		}
		System.out.println(1/sum);
		
		
	}
	
}


Measured memory_bytes: 33340
s=input()
l=['A','C','G','T']
len_s=[]
count=0
for i in range(len(s)):
    if s[i] in l and i!=len(s)-1:
        count+=1
    elif s[i] not in l:
        len_s+=[count]
        count=0
    else:
        count+=1
        len_s+=[count]
print(max(len_s))

Measured memory_bytes: 3064
#ifndef chafen
#define chafen

# include <cstdio>
# include <iostream>
# include <cstring>
# include <queue>
# define N 300000
# define INF 0x7f7f7f7f //0x7fffffff
# define _cin std::ios::sync_with_stdio(false)
# define rg register
# define il inline
struct edge{
    int next;
    int to;
    int w;
}e[(N+1)<<1];
int head[N+1];
int book[N+1];
int vis[N+1];
int dis[N+1];
int n,m;
using namespace std;
//template <class A> il bool SPFA(A s);
bool SPFA(int s);
int main()
{
    _cin;
    rg int edge_sum=0;
    rg int u,v,w;
    cin>>n>>m;
    for(int i = 1;i<=m;i++){
        cin>>u>>v>>w;
        //edge_sum++;
        e[i].next=head[u];
        e[i].to=v;
        e[i].w=w;
        head[u]=i;
        
        //edge_sum++;
        e[i+m].next=head[v];
        e[i+m].to=u;
        e[i+m].w=-w;
        head[v]=i+m;
    }
    memset(dis,0x7f,sizeof(dis));
    memset(vis,0,sizeof(vis));
    memset(book,0,sizeof(book));
    for(int i = 1;i<=n;i++){
        if(vis[i] == false){
            vis[i]=1;
            if(SPFA(i) == false){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}
//template <class A> il bool SPFA(A s)
bool SPFA(int s)
{
    queue <int> q;
    dis[s]=0;
    q.push(s);book[s]=1;
    while(q.size()>0){
        int k=q.front();q.pop();
        book[k]=0;
        for(int i = head[k];i;i=e[i].next){
            int tt=e[i].to;
            if(dis[k]<INF && dis[tt]<INF && dis[tt]!=dis[k]+e[i].w) return false;
			else if(dis[k]<INF && dis[tt] == INF){
                dis[tt]=dis[k]+e[i].w;
                if(book[tt] == false) {q.push(tt);book[tt]=1;}
                vis[tt]=1;
            }
        }
    }
    return true;
}

#endif

Measured memory_bytes: 10880
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using lld = long long int ;
#define mod 1000000007; 

int main(){
    lld a,b,c,d;
    cin >> a>>b>>c>>d;
    lld ans[4];
    ans[0]=a*c;
    ans[1]=a*d;
    ans[2]=b*c;
    ans[3]=b*d;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            if(ans[i]<ans[j]){
                lld m=ans[i];
                ans[i]=ans[j];
                ans[j]=m;
            }
        }
    }
    cout << ans[0] << endl;
    return 0;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int last = scanner.nextInt();
        long ans = 0;
        for (int i = 1; i < n; i++) {
            int v = scanner.nextInt();
            if (last > v) {
                ans += last - v;
            }
            last = Math.max(last, v);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 60024
#include<iostream>

#include <vector>
#include <list>
#include<stack>
#include<queue>
#include<array>

#include <set>
#include<map>

#include<string>
#include<stdlib.h>

#include<algorithm>
#include <functional>
#include<math.h>

#include<fstream>
#include<iomanip>

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


//変数
ll N, K;
vector<ll> a;
vector<vector<ll>> children;





//サブ関数
//入力
void input()
{
	cin >> N >> K;
	REP(i, N) {
		ll tmp;
		cin >> tmp;
		tmp--;
		a.push_back(tmp);
	}
	children.resize(N);
	REP(i, N)children[a[i]].push_back(i);
}

bool isCapitalSafe()
{
	return (a[0] == 0);
}

void search_deeper(vector<ll>& deep, ll target)
{
	if (deep[target] == -1) {
		search_deeper(deep, a[target]);
		deep[target] = deep[a[target]] + 1;
	}
}

priority_queue<pair<ll, ll>> pq_deeper()
{
	vector<ll> deep(N, -1);
	deep[0] = 0;
	REP(i, N) search_deeper(deep, i);
	
	priority_queue<pair<ll, ll>> pq;
	REP(i, N)pq.push({ deep[i],i });
	return pq;
}

ll upper_node(pair<ll, ll> now, ll dist)
{
	ll p = now.second;
	REP(i, dist)p = a[p];
	return p;
}

void tree_cut(vector<bool>& searched, ll root)
{
	queue<ll> q;
	q.push(root);
	while (!q.empty()) {
		auto node = q.front(); q.pop();
		searched[node] = true;
		for (auto child : children[node]) {
			if (!searched[child]) {
				q.push(child);
			}
		}
	}
}

//計算
void calc()
{
	int res = 0;
	if (!isCapitalSafe())res++;
	a[0] = 0;

	auto pq = pq_deeper();
	vector<bool> searched(N, false);
	searched[0] = true;
	while (!pq.empty()) {
		auto now = pq.top(); pq.pop();
		if (now.first <= K)break;
		if (searched[now.second])continue;
		ll p = upper_node(now, K - 1);
		tree_cut(searched, p);
		res++;
	}
	cout << res << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 12532
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(N - 1):
    if i + 1 == p[i]:
        p[i + 1], p[i] = p[i], p[i + 1]
        ans += 1
print(ans if p[N - 1] != N else ans + 1)

Measured memory_bytes: 13880
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s; cin>>n>>s;
    int l=0,r=0;
    rep(i,0,n){
        if(s[i]=='(')r++;
        else{
            if(r==0)l++;
            else r--;
        }
    }
    rep(i,0,l)cout<<'(';
    cout<<s;
    rep(i,0,r)cout<<')';
    putchar(endl);
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long k = sc.nextLong();
		long d = sc.nextLong();

		long ax = Math.abs(x);
		long xk = ax/d;
		long xkk = Math.min(k, xk);
		
		ax = Math.abs(ax - d*xkk);;
		if( (k-xkk) % 2 == 1 ) {
			ax = Math.abs(ax - d);
		}
		
		System.out.println(ax);
	}
}


Measured memory_bytes: 35636
A, B = map(int, input().split())
S = input()


def is_digit(num):
    try:
        int(num)
        return True
    except ValueError:
        return False


a = S[:A]
x = S[A]
b = S[A+1:]

if x == "-":
    for num in [a, b]:
        if not is_digit(num):
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 0.00001

const int maxn=2003;
ll dp[maxn][maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;cin>>n>>m;
    vi s(n);
    vi t(m);
    rep(i,0,n-1)
    {
        cin>>s[i];
    }
    rep(i,0,m-1){cin>>t[i];}
    rep(i,1,n)
    {
        rep(j,1,m)
        {
            dp[i][j]=0;
        }
    }
    rep(i,1,n)
    {
        rep(j,1,m)
        {
            dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            dp[i][j]=(dp[i][j]+MOD)%MOD;
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=dp[i][j]+dp[i-1][j-1]+1;
                dp[i][j]%=MOD;
            }
        }
    }
    cout<<(dp[n][m]+1)%MOD<<"\n";

    return 0;

    //check for long long or int
}


Measured memory_bytes: 31616
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N,a[Nmax]={};
	cin >> N;
	REP(i,N) cin >> a[i+1];
	int mi=a[1];
	int cnt=1;
	bool flag=false;
	for(;;){
		if(mi==2){ flag=true; break; }
		if(cnt>100010) break;
		mi=a[mi];
		cnt++;
	}
	if(flag) cout << cnt << endl;
	else cout << -1 << endl;
	return 0;
}

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

const ll MOD = 1e9+7;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  ll x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);
  ll ans = 0;
  if(x < d) {
    if(k % 2 == 0) {
      ans = x;
    }
    else {
      ans = abs(x-d);
    }
  }
  else {
    if(x/d > k) {
      ans = x - d*k;
    }
    else if(x/d == k) {
      ans = x%d;
    }
    else {
      ll divnum = x/d;
      ll tmp = k - divnum;
      if(tmp % 2 == 0) {
        ans = x % d;
      }
      else {
        ans = min(abs(x%d-d), abs(x%d+d));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	char s[52][52];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> s[i][j];
		}
	}
	bool can = true;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (s[i][j] == '#' && s[i - 1][j] != '#' && s[i][j - 1] != '#' && s[i + 1][j] != '#' && s[i][j + 1] != '#') can = false;
		}
	}
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
def adj(n): return [[] for _ in range(n)]

n,m = imap()
ab = np.array([iarr() for i in range(m)])
g = adj(n+1)
for i in range(m):
    aa,bb = ab[i][0],ab[i][1]
    g[aa].append(bb)
    g[bb].append(aa)

dep = iarr(n+1)
dep[1] = 1
q = col.deque([1])
route = iarr(n+1)
while q:
    now = q.popleft()
    for next in g[now]:
        if dep[next]: continue
        else:
            q.append(next)
            dep[next] = dep[now]+1
            route[next] = now

print("Yes")
for ans in route[2:]: print(ans)







Measured memory_bytes: 76864
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    int sum = 0;
    for (int e: a) {
        sum += e;
    }
    int avg = round((double)sum / n);

    int ans = 0;
    for (int e: a) {
        int diff = abs(e - avg);
        ans += diff * diff;
    }
    cout << ans << endl;
}


Measured memory_bytes: 504
MOVES = 'rsp'

def points(me, rival):
    if me == 'r' and rival == 's':
        return r
    if me == 's' and rival == 'p':
        return s
    if me == 'p' and rival == 'r':
        return p
    return 0

def pos(hand):
    return MOVES.index(hand)

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input().rstrip()
ret = 0
me = []
for i, rival in enumerate(t):
    if rival == 'r':
        if i - k >= 0 and me[i - k] == 'p':
            if i + k < n:
                if t[i + k] == 'p':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('s')
                elif t[i + k] == 'r':
                    me.append('s')
        else:
            me.append('p')
            ret += p
    elif rival == 's':
        if i - k >= 0 and me[i - k] == 'r':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('s')
                elif t[i + k] == 'p':
                    me.append('p')
                elif t[i + k] == 's':
                    me.append('s')
        else:
            me.append('r')
            ret += r
    elif rival == 'p':
        if i - k >= 0 and me[i - k] == 's':
            if i + k < n:
                if t[i + k] == 'r':
                    me.append('r')
                elif t[i + k] == 's':
                    me.append('p')
                elif t[i + k] == 'p':
                    me.append('r')
        else:
            me.append('s')
            ret += s
print(ret)


Measured memory_bytes: 4212
//https://atcoder.jp/contests/dp/tasks/dp_i
//I - Coins
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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 (b<a) { a=b; return 1; } return 0;}
int main() {
    ll N; cin>>N;
    vector<double> pn(N+1);
    FOR(i,0,N){
        cin>>pn.at(i);
    }    
    vector<vector<double>> dp(N+1,vector<double>(N+1,0)); //回数,表
    dp[0][0]=1;
    FOR(i,0,N){
        FOR(omote,0,N+1){
            dp[i+1][omote] += dp[i][omote]*(1.0-pn[i]);
            dp[i+1][omote+1] += dp[i][omote]*pn[i];
        }
    }
    double ans=0;
    FOR(omote,0,N+1){
        if(N-omote<omote) ans+=dp[N][omote];
    }
    cout<<fixed<<std::setprecision(10)<<ans<<endl;
}
int main_() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<double> pn(N+1);
    FOR(i,1,N+1){
        cin>>pn.at(i);
    }    
    vector<vector<double>> dp(N+1,vector<double>(N+1));
    dp[0][0]=1;
    auto dpij = [&](ll i,ll j)->double{
        if (i<0||i>N) return 0;
        if (j<0||j>N) return 0;
        return dp[i][j];
    };
    FOR(i,0,N+1){
        FOR(j,0,N+1){
            if(i==0&&j==0) continue;
            ll tm=i+j; //回目
            if(tm>=pn.size()) continue;
            dump(tm,i,j); //表、うら
            auto p=pn.at(tm);
            dp[i][j] = p*dpij(i-1,j) + (1.0f-p)*dpij(i,j-1);
        }
    }
    dump(dp);
    double ans=0;
    FOR(i,0,N+1){
        FOR(j,0,N+1){
            if(i+j==N&&i>j) ans+=dp[i][j];
        }
    }
    cout<<fixed<<std::setprecision(10)<<ans<<endl;
    return 0;
}

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

using namespace std;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    int lt = 0, lx = 0, ly = 0;
    for(int i = 0; i < n; i++) {
        cin >> t[i] >> x[i] >> y[i];
        if(true) {
            int dist = abs(x[i] - lx) + abs(y[i] - ly);
            if(!(dist <= t[i] - lt && dist % 2 == (t[i] - lt) % 2)) {
                cout << "No" << endl;
                return 0;
            }
            lt = t[i], lx = x[i], ly = y[i];
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3624
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))
(let* ((line (read-line nil nil))
	   (splited (mapcar #'parse-integer (splitat #\space line)))
	   (lst (loop for i from (cadr splited) to (1- (reduce #'+ splited)) collect (list (abs i) i)))
	   (removeat (reduce (lambda(acc x) (if (< (car acc) (car x)) acc x)) lst))
	   (reduced (reduce (lambda(acc x) (if (= (cadr removeat) (cadr x)) acc (+ acc (cadr x)))) lst :initial-value 0)))
  (format t "~A~%" reduced))

Measured memory_bytes: 15588
//#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <cmath>
#include <random>
#include <bitset>
#include <complex>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define mmin(a, b) a = min(a, (b))
#define mmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ALL(a) a.begin(),a.end()
#define sqr(x) (x) * (x)
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int & 
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

template<class T>
void show(const vector<T> &a) {
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int N = 4e3 + 9;
const int H = N >> 1;
const int oo = 1e9;
int n;
int a[N];
int black[N];
int fur[N][H];
int dp[H][H];
int kek[2][H];

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

	cin >> n;
	fori(i, (n << 1)) {
		string bl;
		cin >> bl >> a[i];
		black[i] = bl[0] == 'B';
		kek[black[i]][a[i]] = i;
	}
	int ans = 0;
	fori(i, (n << 1)) {
		for (int j = i + 1; j < (n << 1); ++j)
			if (black[i] != black[j])
				++fur[i][a[j]];
			else
				ans += a[i] > a[j];
		for (int j = 1; j <= n; ++j) 
			fur[i][j] += fur[i][j - 1];
		
	}
	//watch(ans);
	fori(i, n + 1) fori(j, n + 1)
		dp[i][j] = oo;
	dp[0][0] = 0;
	fori(i, n + 1) 
		fori(j, n + 1) if (dp[i][j] < oo) {
			if (i < n) mmin(dp[i + 1][j], dp[i][j] + fur[kek[0][i + 1]][j]);
			if (j < n) mmin(dp[i][j + 1], dp[i][j] + fur[kek[1][j + 1]][i]);
		}
	cout << dp[n][n] + ans;
}


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

int main() {
  int K;
  int N;
  cin >> K >> N;
  vector<int> ie(N);
    
  for(int i=0;i<N;i++){
    cin >> ie.at(i);
  }
  
  int max_dis = 0;
  
  for(int j=0;j<N-1;j++){
      max_dis = max(max_dis,ie.at(j+1) - ie.at(j));
  }
  
  cout <<  K - max(max_dis,K + ie.at(0) - ie.at(N-1));
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
A = []
B = []
flag = False
for i in range(N):
    A.append(input())
for k in range(M):
    B.append(input())
    
for i in range(N-M+1):   #リストAを縦に見る
    for k in range(N-M+1):   #リストAを横に見る
        S = []
        for j in range(i, i+M):   #リストAをMxMになるように抜き出してSに入れる
            S.append(A[j][k : k+M])
        if S == B:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main(){

int n,k;
cin>>n>>k;

vector<int>h(n);
for(int i=0;i<n;i++)
 cin>>h.at(i);

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

 int index = 0,ans = INT_MAX;

 for(int i=k-1;i<n;i++){

    int memo = h[i] - h[index];
    ans = min(ans,memo);
    index++;
 }

  cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 3696
/* 別解のダブリングというテクニックを使って解いてみる */
function main(input) {
  let [n, k] = input[0].trim().split(" ").map(i => BigInt(i));
  const a = input[1].trim().split(" ").map(i => parseInt(i-1));

  //2**?の深さを確かめる
  let max_depth = 0n;
  while(true){
    max_depth++;
    if(2n**max_depth>k){
      max_depth--;
      break;
    }
  }

  /* ダブリングによるマップを作る */
  let map = [];
  map[0] = a;
  for(let i=1;i<=max_depth;i++){
    map[i] = [];
    for(let j=0;j<n;j++){
      map[i][j]= map[i-1][map[i-1][j]];
    }
  }

  //k番目の要素までの経路を作成する
  let map_load = [];
  for(let i=max_depth;i>=0n;i--){
    let pow2 = 2n**i;
    if(k>=pow2){
      for(let j=0n;j<(k/pow2);j++){
        k-=pow2;
        map_load.push(i);
      }
    }
    if(k===0n){
      break;
    }
  }
  //経路通りに辿って答えを見つける
  let now = 0;
  for(let i of map_load){
    now=map[i][now];
  }

  console.log((now+1)+"");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 180284
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int n;
  string s;
  cin >> s;
  int a[26] = {};

  for(int i = 0; i < s.size(); i++) {
    a[s[i]-char(0x61)] += 1;
  }

  bool flag = true;
  for(int i = 0; i < s.size(); i++) {
    if(a[i] > 1) flag = false;
  }
  if(flag) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}

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

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

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

int main(){
	int S, a, b, c, d;
	cin >> S;
	a = S/60;
	b = S%60;//byou
	c = a/60;//jikan
	d = a%60;//hun
	cout << c << ":" << d << ":" << b << endl;

	return 0;
}

Measured memory_bytes: 1164
import java.lang.Math

fun main(args: Array<String>) {
    val (N, A, B) = readInputLine().split(" ").map { it.toLong() }

    println(N / (A + B) * A + Math.min(N - N / (A + B) * (A + B), A))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37760
#include <stdio.h>

struct dice {
	int up;
	int front;
	int right;
	int left;
	int back;
	int down;
};

void mov_order(struct dice *d, char order)
{
	int wk;
	
	switch(order){
		case 'N':
			wk       = d->up;
			d->up    = d->front;
			d->front = d->down;
			d->down  = d->back;
			d->back  = wk;
			break;
		case 'E':
			wk       = d->left;
			d->left  = d->down;
			d->down  = d->right;
			d->right = d->up;
			d->up    = wk;
			break;
		case 'W':
			wk       = d->right;
			d->right = d->down;
			d->down  = d->left;
			d->left  = d->up;
			d->up    = wk;
			break;
		case 'S':
			wk       = d->back;
			d->back  = d->down;
			d->down  = d->front;
			d->front = d->up;
			d->up    = wk;
			break;
	}
}

void set_up(struct dice *d1, struct dice *d2, char *order)
{
	d2->up    = d1->up;
	d2->front = d1->front;
	d2->right = d1->right;
	d2->left  = d1->left;
	d2->back  = d1->back;
	d2->down  = d1->down;
	
	while(*order != 0x00){
		mov_order(d2, *order);
		order++;
	}
}

int main(void)
{
	int i, q, up, front, wk;
	struct dice d1, d2;
	
	scanf("%d%d%d%d%d%d", &d1.up, &d1.front, &d1.right, &d1.left, &d1.back, &d1.down);
	scanf("%d", &q);
	for(i = 0; i < q; i++){
		scanf("%d%d", &up, &front);
		if(up == d1.up)         set_up(&d1, &d2, "");
		else if(up == d1.front) set_up(&d1, &d2, "N");
		else if(up == d1.right) set_up(&d1, &d2, "W");
		else if(up == d1.left)  set_up(&d1, &d2, "E");
		else if(up == d1.back)  set_up(&d1, &d2, "S");
		else if(up == d1.down)  set_up(&d1, &d2, "NN");
		while(front != d2.front){
			wk = d2.front;
			d2.front = d2.right;
			d2.right = d2.back;
			d2.back  = d2.left;
			d2.left  = wk;
		}
		printf("%d\n", d2.right);
	}
	
	return(0);
}



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


int main() {
  int i, j;
  
  for(i=1;i<10;i++){
    for(j=1;j<10;j++){
      cout<<i<<'x'<<j<<"="<<i*j;
      cout<<endl;
    }
  }
  
  return 0;
}

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

int main(){
    long double A,B,H,M;
    long double ans=0,rad,th;
    cin>>A>>B>>H>>M;
  
    th = abs(30*(H+(M/60))-6*M);
    if(th<=180){
        rad = (th * M_PI)/180;
    }else{
        rad =((360-th)*M_PI)/180;
    }
    ans = sqrt(A*A+B*B-2*A*B*cos(rad));
    cout<<setprecision(13)<<ans<<endl;
}

Measured memory_bytes: 4168
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define int long long

bool isIntersect(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy) {
	int ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
	int tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
	int tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
	int td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);

	return tc * td < 0 && ta * tb < 0;
}
double dst(int x1, int y1, int x2, int y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double solve(vector<int> &X, vector<int> &Y, int X1, int Y1, int X2, int Y2) {
	vector<double> dist0(X.size(), 1e15);
	vector<double> dist1(X.size(), 1e15);

	for (int i = 0; i < X.size(); i++) {
		if (i != 0 && !isIntersect(X[i], Y[i], X[0], Y[0], X1, Y1, X2, Y2)) {
			dist0[i] = dst(X[i], Y[i], X[0], Y[0]);
		}
		if (i != 1 && !isIntersect(X[i], Y[i], X[1], Y[1], X1, Y1, X2, Y2)) {
			dist1[i] = dst(X[i], Y[i], X[1], Y[1]);
		}
	}
	double res = 1e15;
	for (int i = 0; i < X.size(); i++) {
		res = min(res, dist0[i] + dist1[i]);
	}
	for (int i = 0; i < X.size(); i++) {
		for (int j = 0; j < X.size(); j++) {
			if (!isIntersect(X[i], Y[i], X[j], Y[j], X1, Y1, X2, Y2)) {
				res = min(res, dist0[i] + dist1[j] + dst(X[i], Y[i], X[j], Y[j]));
			}
		}
	}
	return res + dst(X1, Y1, X2, Y2);
}
signed main() {
	int A, B;
	cin >> A >> B;
	vector<int> XA(A), YA(A);
	vector<int> XB(B), YB(B);
	for (int i = 0; i < A; i++) {
		cin >> XA[i] >> YA[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> XB[i] >> YB[i];
	}
	double res = 0;
	if (isIntersect(XA[0], YA[0], XA[1], YA[1], XB[0], YB[0], XB[1], YB[1])) {
		res = solve(XA, YA, XB[0], YB[0], XB[1], YB[1]);
		res = min(res, solve(XB, YB, XA[0], YA[0], XA[1], YA[1]));
	}
	else {
		res = dst(XA[0], YA[0], XA[1], YA[1]) + dst(XB[0], YB[0], XB[1], YB[1]);
	}
	if (res > 1e14) {
		cout << -1 << endl;
	}
	else {
		cout << setprecision(15) << res << endl;
	}
}


Measured memory_bytes: 3320