akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll x;
    cin>>x;
    if(x%11==0){
        cout<<(x/11)*2<<endl;
    }
    else if(x%11<=6){
        x-=x%11;
        cout<<(x/11)*2+1<<endl;
    }
    else{
        x+=x%11;
        cout<<(x/11)*2<<endl;
    }

    //cout<<(x/11)*2+2<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int a[3];
  cin >> a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int cnt=1;
  for(int i=0;i<2;i++){
    if(a[i]==a[i+1]) cnt++;
  }
  cout << 3-cnt+1<<endl;
}


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

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    swap(a,b),swap(a,c);
    printf("%d %d %d",a,b,c);
    return 0;
}

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


int main(){
  int k,n; cin >> k >> n;
  vector<int> A(n);
  for (auto &&i : A)
  {
    cin >> i;
  }
  vector<long long> len(n);
  for (int i = 0; i < n; i++)
  {
    if (i + 1 < n)
    {
      len.at(i) = A.at(i + 1) - A.at(i);
    }
    else
    {
      len.at(i) = (k -  A.at(n - 1)) + A.at(0);
    }
    
  }
  
  sort(len.begin(), len.end());
  cout << k - len.at(n - 1) << endl;
  
  
}

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

int64_t cnt_x;
int64_t cnt_y;
const int vn = 100000;
vector<vector<int>> to(vn * 2);
vector<bool> visited(vn * 2, false);

void dfs(int v)
{
  if (visited[v]) return;
  visited[v] = true;
  if (v < vn) {
    cnt_x++;
  } else {
    cnt_y++;
  }
  for (auto&& nv : to[v]) {
    dfs(nv);
  }
}

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

  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    y += vn;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  int64_t ans = 0;
  for (int i = 0; i < vn * 2; i++) {
    if (visited[i]) continue;
    cnt_x = 0;
    cnt_y = 0;
    dfs(i);
    ans += cnt_x * cnt_y;
  }
  cout << ans - n << endl;
}


Measured memory_bytes: 9984
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  to(tn()**2)
}
main()

Measured memory_bytes: 7372
#include<stdio.h>
#include<string.h>
#include<ctype.h>

char *StrToLower(char *s);

int main(){


	int a;
	int cnt = 0;
	char moji[200];
	char word[200];


	scanf("%s",&word);

	StrToLower(word);

	while(1)
	{
		scanf("%s",&moji);
		if(strcmp(moji,"END_OF_TEXT") == 0){
			break;
		}
		else
		{
			StrToLower(moji);
			if(strcmp(moji, word) == 0){
				cnt++;
			}
		}
	}
	printf("%d\n", cnt);
	scanf("%d",&a);
 return 0;
}

char *StrToLower(char *s)
{
char *p;

for(p=s;*p;p++)
*p=tolower(*p);
return (s);
}

Measured memory_bytes: 552
from itertools import accumulate

n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
acc = [0] + list(accumulate(v))
for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        minus = sorted(v[:l] + v[n - r:])
        bag = acc[l] - acc[0] + acc[n] - acc[n - r]
        bag -= sum(vi for vi in minus[:k - l - r] if vi < 0)
        ans = max(ans, bag)
print(ans)


Measured memory_bytes: 74376
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=min(c,a+b+1);
	ans+=b;
	cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    double X, Y;
    double a, b;

    scanf("%lf %lf", &X, &Y);
    a = (Y-2*X)/2;
    b = (4*X-Y)/2;

    if((int)a==a && (int)b==b && a>=0 && b>=0){
        printf("Yes");
    }else{
        printf("No");
    }


    return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    long long n,W,w[200000],v[200000],dp[101][100001]={0},ans=0;
    cin>>n>>W;
    rep(i,n) cin>>w[i]>>v[i];
    rep(i,n)rep(j,1000*n+1) dp[i][j]=10000000000;
    dp[0][0]=0;
    rep(i,n)rep(j,n*1000+1){
        if(j>=v[i]) dp[i+1][j]=min(dp[i][j-v[i]]+w[i],dp[i][j]);
        else dp[i+1][j]=dp[i][j];
    }
    rep(i,n*1000+1) if(dp[n][i]<=W&&i>ans) ans=i;
    cout<<ans<<endl;
}


Measured memory_bytes: 82304
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{char c[101][101]={0,0};
 char a[101][101]={0,0};
 int n,m,s;
 cin>>n>>m;
 for(int i=1;i<=n;i++)
    {for(int j=1;j<=m;j++)
        cin>>c[i][j]; 
	}
 for(int i=1;i<=n;i++)
    {for(int j=1;j<=m;j++)
        {if(c[i][j]=='#')
           cout<<'#';
		 else
		   {s=0;
		    if(c[i-1][j-1]=='#')
              s++;
            if(c[i-1][j]=='#')
              s++;
            if(c[i-1][j+1]=='#')
              s++;
            if(c[i][j-1]=='#')
              s++;
            if(c[i][j+1]=='#')
              s++;
            if(c[i+1][j-1]=='#')
              s++;
            if(c[i+1][j]=='#')
              s++;
            if(c[i+1][j+1]=='#')
              s++;
            cout<<s;
           } 
		}
	 cout<<endl;
    }
 cout<<endl;
} 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    print(len(list(set(S))))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


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

int main(){
    long n,a,b;
    cin>>n>>a>>b;
    long c,d;
    c=n/(a+b);
    d=n-c*(a+b);
    if(d<=a){cout<<c*a+d;}
    else{cout<<c*a+a;}
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = 0ll;
	ans = ans + min(a,d);
	d = d - min(a,d);
	d = d - min(b,d);
	ans = ans - min(c,d);
	cout<<ans;
}

Measured memory_bytes: 3648
n,m = map(int,input().split())
tuuro = []
for i in range(m):
	a,b = map(int,input().split())
	tuuro.append((a-1,b-1))
#行ける部屋は.?
ikeru = [[] for _ in range(n)]
for i,j in tuuro:
	ikeru[i].append(j)
	ikeru[j].append(i)

fukasa = [0 for _ in range(n)]
fukasamoto = [0 for _ in range(n)]
kaisuu = 0
settansaku = set([])
listmada = [0]
setmada = set([0])

while len(setmada) != 0:
	kaisuu += 1
	for i in listmada[:]:
		settansaku.add(i)
		listmada.remove(i)
		setmada.remove(i)
		for k in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					listmada.append(k)
					setmada.add(k)
					fukasa[k] = kaisuu
					fukasamoto[k] = i+1

print("Yes")
for i in range(1, n):
	print(fukasamoto[i])

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int x, y, sum;
    cin >> x >> y;

    for(int i = 0; i <= x; i++) {
        int j = x - i;
        sum = i * 2 + j * 4;
        if(sum == y) {
            cout << "Yes" << endl;
            exit(0);
        }
    }

    cout << "No" << endl;

    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pll> vp;
typedef vector<ll> vll;

const int MAX_LEN = 1200;
int n;
char s[1000][MAX_LEN];

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

    while (cin >> n && n) {
        rep(i, n) rep(j, MAX_LEN) s[i][j] = '#';
        rep(i, n) {
            string t;
            cin >> t;
            rep(j, t.size()) s[i][j] = t[j];
        }

        // process row by row
        rep(j, MAX_LEN) {
            // make plus and space
            rep(i, n) {
                if (s[i][j] == '.' && s[i][j + 1] != '.') {
                    s[i][j] = '+';
                }
                if (s[i][j] == '.' && s[i][j + 1] == '.') {
                    s[i][j] = ' ';
                }
            }
            // make line
            rep(i, n) {
                if (s[i][j] == '+') {
                    int k = i + 1;
                    while (k < n && s[k][j] == ' ') k++;
                    if (k < n && s[k][j] == '+') {
                        rep2(l, i + 1, k) {
                            s[l][j] = '|';
                        }
                    }
                }
            }
        }

        rep(i, n) {
            rep(j, MAX_LEN) {
                if (s[i][j] == '#') break;
                cout << s[i][j];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 4384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			int m=in.nextInt();
			if((n|m)==0)
				return;
			ArrayList<Integer> L=new ArrayList<Integer>();
			int sum=0;
			int item=1;
			for(int i=0;i<n;i++)
				L.add(in.nextInt());
			Collections.sort(L);
			Collections.reverse(L);
			for(int i=0;i<n;i++)
			{
				sum+=L.get(i);
				if(item%m==0)
					sum-=L.get(i);
				item++;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <vector>
#include <string>

using ll = long long;

using namespace std;

void solve() {
    ll k, n;
    cin >> k >> n;
    if (n <= 1) {
        cout << "0\n";
        return;
    }
    std::vector<ll> vals(n);
    ll ans = k;
    for (int i = 0; i < n; ++i) {
        cin >> vals[i];
    }
    for (int i = 0; i < n; ++i) {
        ll prev = vals[(i + n - 1) % n];
        ll dist = prev - vals[i];
        if (dist < 0) {
            dist += k;
        }
        ans = min(ans, dist);
    }
    cout << ans << '\n';
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    solve();
}


Measured memory_bytes: 1920
package main

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

func main() {
	r := nextInt()
	g := nextInt()
	b := nextInt()
	if (r*100+g*10+b)%4 == 0 {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 640
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long X=sc.nextLong(), y=100;
    int z=0;
    while(y<X){
      y= y+ y/100;
      z++;
    }
    System.out.println(z);
  }
}

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

class Main{
  public static void main(String args[]){
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int k = in.nextInt();
    int a[] = new int[n];
    for(int i=0;i<n;i++)
      a[i] = in.nextInt();

    int dp[] = new int[n];
    dp[0] = 0;
    for(int i=1;i<n;i++){
      dp[i] = Integer.MAX_VALUE;
      int j = Math.max(0, i-k);
      for(;j<i;j++)
        dp[i] = Math.min(dp[i], Math.abs(a[i]-a[j]) + dp[j]);
    }
    System.out.println(dp[n-1]);
  }
}

Measured memory_bytes: 50228
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	cin >> N;



	cout << N / 500 * 1000 + N % 500 / 5 * 5 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N],s1[N],s2[N];
void revprint(char *s) {
	for (int i=strlen(s)-1;i>=0;i--)
		putchar(s[i]);
}
int main() {
//	ios::sync_with_stdio(false);
	int i,q,flag,t,f,cnt1=0,cnt2=0;
	char c;
	scanf("%s",s);
	scanf("%d",&q);
	flag=0;
	while (q--) {
		scanf("%d",&t);
		if (t==1) flag=1-flag;
		else {
			cin>>f>>c;
			if (f==1) {
				if (flag==0) s1[cnt1++]=c;
				else s2[cnt2++]=c;
			}
			else {
				if (flag==0) s2[cnt2++]=c;
				else s1[cnt1++]=c;
			}
		}
	}
	s1[cnt1]='\0'; s2[cnt2]='\0';
	if (flag==1) {
		revprint(s2); revprint(s);
		printf("%s\n",s1);
	}
	else {
		revprint(s1);
		printf("%s%s\n",s,s2);
	}
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	int timesum = h * 60 + m;
	double minute = (double)m / 5;
	double kakudo1 = (double)timesum * 0.5;
	double kakudo2 = (double)m * 6;
	double kakudosum = min(abs(kakudo1 - kakudo2), 360 - abs(kakudo1 - kakudo2));
	double pi = (double)2.0 * asin(1.0);
	double unit = (double)pi / 180.0;
	double deg_r =(double) kakudosum * unit;
	double ans = (double)cos(deg_r);
	double kai = (double)a*a + b*b - 2 * b * a * ans;
	cout <<fixed<<setprecision(22)<< sqrt(kai) << endl;
	return 0;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int A, B;
int D[15][15];
int f[105][105];

int main(){

  cin >> A >> B;
  rep(i,A){
    rep(j,B){
      cin >> D[i][j];
    }
  }

  rep(a,101){
    rep(b,101){
      rep(x,A){
        rep(y,B){
          f[a][b] = max(f[a][b], D[x][y] - (x+1)*a - (y+1)*b);
        }
      }
    }
  }

  rep(x,A){
    rep(y,B){
      int mn = 1000000000;
      rep(a,101){
        rep(b,101){
          mn = min(mn, (x+1)*a + f[a][b] + (y+1)*b);
        }
      }
      if(D[x][y] != mn){
        cout << "Impossible" << endl;
        return 0;
      }
    }
  }
  
  cout << "Possible" << endl;
  cout << 202 << " " << 200+101*101 << endl;
  rep(i,100){
    cout << i+1 << " " << i+2 << " X" << endl;
  }
  rep(i,100){
    cout << 102+i << " " << 102+i+1 << " Y" << endl;
  }
  rep(i,101){
    rep(j,101){
      cout << i+1 << " " << 202-j << " " << f[i][j] << endl;
    }
  }
  
  cout << 1 << " " << 202 << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count=0;
    string str;
    string str1;
    cin>>str;
    cin>>str1;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]!=str1[i])
        {
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 3896
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  let h = input[0].trim().split(' ').map(Number);
  let m = input[1].trim().split(' ').map(Number);
  let l = input[2].trim().split(' ').map(Number);

  let x = [m[0]-h[0], m[1]-h[1], m[2]-h[2]]
  let y = [l[0]-m[0], l[1]-m[1], l[2]-m[2]]

  if(x[0] === x[1] && x[1] === x[2]){
    if(y[0] === y[1] && y[1] === y[2]){
      console.log('Yes');
      return;
    }
  }
  console.log('No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
while 1:
    w = raw_input()
    if w=="0000": break
    if int(w)%1111==0:
        print "NA"
        continue
    ans = 0
    while(w!="6174"):
        w = ("".join(sorted(w))).zfill(4)
        w = str(int(w[::-1])-int(w))
        ans += 1
    print ans

Measured memory_bytes: 4212
#!/usr/bin/env python3
import numpy as np
from scipy.sparse.csgraph import shortest_path

H, W = list(map(int, input().split()))

c_table = []

for _ in range(10):
    c_table.append(list(map(int, input().split())))

a_table = []

for _ in range(H):
    a_table.append(list(map(int, input().split())))

c_table = np.array(c_table)
a_table = np.array(a_table)

d_matrix = shortest_path(c_table)
cost = 0

for h in range(H):
    a_list = a_table[h]
    for a in a_list:
        if a == -1:
            continue
        cost += d_matrix[a][1]

ans = int(cost)
print(ans)


Measured memory_bytes: 18152
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		LL n = -1, ans = 0;
		cin >> n;
		if (n <= 0) break;
		vector<LL> l(n);
		for (int i = 0; i < n; ++i) {
			cin >> l[i];
		}
		sort(l.begin(), l.end());
		l.push_back(1LL << 60);
		for (LL a = 0; a < n; ++a) {
			for (LL b = a + 1, c = a + 1; b < n; ++b) {
				while (l[c + 1] < l[a] + l[b]) {
					++c;
				}
				ans += c - b;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

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

    int n, x;
    cin >> n >> x;
    int d = 0;
    int i;
    for (i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (d + a <= x) {
            d += a;
        } else {
            break;
        }
    }
    cout << i + 1 << endl;
}

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

typedef long long LL;

const int INF = (1<<30);

int n;
double arr[3005];
double memo[3005][3005];

double dp(int idx,int head){
	if(idx==n&&head>=(n+1)/2) return 1;
	if(idx==n) return 0;
	if(memo[idx][head]!=-1.00) return memo[idx][head];
	
	double ret=0;
	ret=(dp(idx+1,head+1)*arr[idx])+(dp(idx+1,head)*(1-arr[idx]));
	return memo[idx][head]=ret;
}


int main(){
	for(int i=0;i<3005;i++){
		for(int j=0;j<3005;j++){
			memo[i][j]=-1.00;
		}
	}
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf",&arr[i]);
	}
	
	double ans=dp(0,0);
	printf("%.9lf\n",ans);
}

Measured memory_bytes: 71040
from itertools import accumulate

class BIT:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

N, K, *A = map(int, open(0).read().split())

B = [0] + list(accumulate(a - K for a in A))

memo = {n: i for i, n in enumerate(sorted(set(B)), 1)}
bit = BIT(N + 1)

ans = 0
for b in map(memo.get, B):
    ans += bit.sum(b)
    bit.add(b, 1)

print(ans)


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	int A, B; cin >> A >> B; swap(A, B);
	auto field = make_v<char>(100, 100);
	REP(i, 50) REP(j, 100) field[i][j] = '.';
	REP(i, 50) REP(j, 100) field[i + 50][j] = '#';

	int cnt = 1;
	for (int i = 0; i < 100; i += 2) {
		bool done = false;
		for (int j = 0; j < 100; j += 2) {
			if (cnt >= A) {
				done = true;
				break;
			}
			field[i][j] = '#';
			cnt++;
		}
		if (done) break;
	}

	cnt = 1;
	for (int i = 51; i < 100; i += 2) {
		bool done = false;
		for (int j = 0; j < 100; j += 2) {
			if (cnt >= B) {
				done = true;
				break;
			}
			field[i][j] = '.';
			cnt++;
		}
		if (done) break;
	}

	cout << 100 << " " << 100 << endl;
	REP(i, 100) {
		REP(j, 100) cout << field[i][j];
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(raw_input())
A = map(int,raw_input().split())
print " ".join(map(str,A))
for i in range(1,n) :
     v = A[i]
     j = i - 1
     while j >= 0 and A[j] > v:
       A[j+1] = A[j]
       j = j-1
     A[j+1] = v
     print " ".join(map(str,A))

Measured memory_bytes: 6372
import java.util.Scanner;

//Educational DP Contest / DP まとめコンテスト
//E	Knapsack 2
public class Main {

	static void chMin(long[][] dp, int i, int j, long v) {
		if (dp[i][j] > v) {
			dp[i][j] = v;
		}
	}

	static void chMax(long[][] dp, int i, int j, long v) {
		if (dp[i][j] < v) {
			dp[i][j] = v;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());

		final int DP_SIZE = 100 + 10;
		final int V_MAX = 101000;

		long[] wArr = new long[N];
		int[] vArr = new int[N];
		for (int i = 0; i < N; i++) {
			wArr[i] = Long.parseLong(sc.next());
			vArr[i] = Integer.parseInt(sc.next());
		}
		sc.close();

		long[][] dp = new long[DP_SIZE][V_MAX];

		// 初期化
		for (int i = 0; i < DP_SIZE; i++) {
			for (int sumV = 0; sumV < V_MAX; sumV++) {
				dp[i][sumV] = 1000000000000000000l;
			}
		}

		// 初期条件
		dp[0][0] = 0;

		// DPループ
		for (int i = 0; i < N; i++) {
			for (int sumV = 0; sumV < V_MAX; sumV++) {
				// 採用する場合
				if (sumV >= vArr[i]) {
					chMin(dp, i + 1, sumV, dp[i][sumV - vArr[i]] + wArr[i]);
				}

				// 採用しない場合
				chMin(dp, i + 1, sumV, dp[i][sumV]);
			}
		}

		long ans = 0;
		for (int i = 0; i < V_MAX; i++) {
			if (dp[N][i] <= W) {
				ans = i;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 129620
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
bool BinarySearch(int A[], int sz, int key)
{
    int left = -1, right = sz;
    while(right - left > 1)
    {
        int mid = (left + right) / 2;
        if(A[mid] == key) return true;
        else if(A[mid] < key) left = mid;
        else right = mid;
    }
    return false;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int S[n + 1];
    for(int i = 0; i < n; i++) cin >> S[i];
    int q; cin >> q;
    int T[q + 1];
    for(int i = 0; i < q; i++) cin >> T[i];
    int cnt = 0;
    for(int i = 0; i < q; i++)
    {
        if(BinarySearch(S, n, T[i])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3696
def rotate(p, comm):
    if comm==0:
        p[0],p[1],p[2], p[27],p[28],p[29] = p[27],p[28],p[29], p[0],p[1],p[2]
        p[14], p[15] = p[15], p[14]
        p[18], p[20] = p[20], p[18]
    elif comm==1:
        p[2],p[5],p[8], p[21],p[24],p[27] = p[21],p[24],p[27], p[2],p[5],p[8]
        p[11], p[18] = p[18], p[11]
        p[12], p[14] = p[14], p[12]
    elif comm==2:
        p[6],p[7],p[8], p[21],p[22],p[23] = p[21],p[22],p[23], p[6],p[7],p[8]
        p[12], p[17] = p[17], p[12]
        p[9], p[11] = p[11], p[9]
    elif comm==3:
        p[0],p[3],p[6], p[23],p[26],p[29] = p[23],p[26],p[29], p[0],p[3],p[6]
        p[9], p[20] = p[20], p[9]
        p[15], p[17] = p[17], p[15]
def all_eq(A, left, right):
    return all(A[i]==A[left] for i in xrange(left, right))
def is_correct(p):
    return all_eq(p, 9, 12) and all_eq(p, 12, 15) and all_eq(p, 15, 18) and all_eq(p, 18, 21) and all_eq(p, 0, 9) and all_eq(p, 21, 30)
def dfs(p, cnt, f):
    ret = 9
    if cnt==9:
        return 9
    if is_correct(p):
        return cnt
    for k in xrange(4):
        if k==f:
            continue
        rotate(p, k)
        ret = min(ret, dfs(p, cnt+1, k))
        rotate(p, k)
    return ret

n = input()
for _ in xrange(n):
    p = map(int, raw_input().split())
    print dfs(p, 0, -1)

Measured memory_bytes: 4424
/******************************************
* AUTHOR : cf/villazer *
******************************************/
#include <iostream>
#include<iomanip>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define lb(arr,n,x) lower_bound(arr,arr+n,x)-arr
#define ub(arr,n,x) upper_bound(arr,arr+n,x)-arr
#define endl "\n"
#define PI 3.14159265358979323846  /* pi */
#define sqr(x) (x)*(x)
#define all(v)  ((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.

typedef long long ll;
typedef long double ld;
//Calculation of (x^y)%mm
ll mod_exp(ll x,ll y,ll mm)
{
    if(y==0)
        return(1);
    else if(y%2==0)
        return(mod_exp((x*x)%mm,y/2,mm));
    else
        return((x*mod_exp((x*x)%mm,(y-1)/2,mm))%mm);
}


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





ll n;
cin>>n;
ll arr[n+1];
rep1(i,2,n+1)
{
	cin>>arr[i];
}
int brr[n+1];
for(int i=1;i<=n;i++)
	brr[i]=0;
for(int i=2;i<=n;i++)
{
	brr[arr[i]]++;
}
for(int i=1;i<=n;i++)
{
	cout<<brr[i]<<endl;
}



return 0;
}

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

int main() {
  int a,b;

  cin >> a >> b;

  int ma = max(a,b);
  int mi = min(a,b);

  rep(i,ma){
    cout << mi;

  }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<pair<long, long>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  sort(data.begin(), data.end());
  long count = 0, sub, a, b;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(i == j)continue;
      sub = 1;
      a = data.at(j).first - data.at(i).first;
      b = data.at(j).second - data.at(i).second;
      for(int k = 0; k < N; k++){
        if(k == i)continue;
        for(int l = 0; l < N; l++){
          if(l == j || k == l)continue;
         if(data.at(l).first - data.at(k).first == a && data.at(l).second - data.at(k).second == b){
           sub++;
         }
        } 
      }
      count = max(count, sub);
    }
  }
  if(N == 1)cout << 1 << endl;
  else cout << N - count << endl;
  return 0;
}


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

int main()
{
    char s[105];
    long long k;
    cin >> s >> k;
    int i = 0;
    while (s[i] == '1' && i < 105)
    {
        i++;
    }
    if (k <= i)
    {
        cout << '1' << "\n";
    }
    else
    {
        cout << s[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  if (b-a+1 >= 2*k) {
    for (int i=0; i<k; i++) cout << a+i <<endl;
    for (int i=1-k; i<=0; i++) cout << b+i << endl;
  }
  else {
    while (a <= b) {
      cout << a << endl;
      a++;
    }
  }
  return 0;
}

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

signed main()
{
	//ios::sync_with_stdio(false);
	int k,a,b;
	cin>>k>>a>>b;
	if(a>=b-2) cout<<k+1<<endl;
	else{
		cout<<max(a+(k-a+1)/2*(b-a)+(k-a+1)%2,k+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <queue>

#define rep(i,s,t) for(int i=s;i<t;i++)
#define mp(a,b) make_pair(a,b)

using namespace std;

int main(void){
	int n;
	int id,u,a,p;

	//降順でkeyにスコア，Valueに 昇順でkeyにペナルティ valueに 昇順でKeyにid番号 valueに所属を保持する3重map
	//これを用いてスコアをソートする
	map<int,map<int,map<int,int> > ,greater<int> > ranking;
	//それぞれのチームの数を保持する配列
	int team[1001];
	//選ばれたチームのチームIDを保持するキュー
	queue<int> select;

	while(cin >> n){
		//スコアリストをクリアする
		ranking.clear();
		if(n==0) break;

		//それぞのチームのスコアを3重mapに挿入していく
		rep(i,0,n){
			cin >> id >> u >> a >> p ;
			//登場する大学のidのみを初期化する
			team[u]=0;
			ranking[a][p][id]=u;
		}
		//スコア順に並べた3重mapを上位から順に処理する
		bool interupt=false;
		for(map<int,map<int,map<int,int> >,greater<int> >::iterator it=ranking.begin();it!=ranking.end() && !interupt;it++){
			for(map<int,map<int,int> >::iterator jt=(*it).second.begin();jt!=(*it).second.end() && !interupt;jt++){
				for(map<int,int>::iterator kt=(*jt).second.begin();kt!=(*jt).second.end() && !interupt;kt++){
					int tid=(*kt).first;
					int tsc=(*kt).second;
					//tema数が10未満の場合
					if(select.size()<10){
						if(team[tsc]<3){
							select.push(tid);
							team[tsc]++;
						}
					//tema数が20未満の場合
					}else if(select.size()<20){
						if(team[tsc]<2){
							select.push(tid);
							team[tsc]++;
						}
					//tema数が26未満の場合
					}else if(select.size()<26){
						if(team[tsc]<1){
							select.push(tid);
							team[tsc]++;
						}
					//tema数が26を超えた場合はカウントを打ち切る
					}else{
						interupt=true;
					}
				}
			}

		}
		//キューを先頭から出力していく
		while(!select.empty()){
			cout << select.front() << endl;
			select.pop();
		}

	}

	return 0;
}

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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;

vector<int> prime;
int p[maxn];

void init() {
	for (int i = 1; i < maxn; i++) p[i] = 1;
	p[0] = p[1] = 0;
	for (int i = 2; i < maxn; i++) {
		if (p[i]) {
			prime.push_back(i);
			for (int j = i * 2; j < maxn; j += i) p[j] = 0;
		}
	}
}

int main() {
	int x;
	init();
	cin >> x;
	int id = lower_bound(prime.begin(), prime.end(), x) - prime.begin();
	cout << prime[id] << endl;
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#define MAX 100
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL) return;
  D[u]=d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right, d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1:h2);
  
  /*式1 ? 式2 : 式3
    式1が真であれば → 式2を実行
    式1が偽であれば → 式3を実行
  */
}

int getSibling(int u){
  if(T[u].parent==NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg=0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0,i;
  scanf("%d",&n);

  for(i=0;i<n;i++) T[i].parent=NIL;

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL) T[l].parent=v;
    if(r!=NIL) T[r].parent=v;
  }

  for(i=0;i<n;i++){
    if(T[i].parent==NIL){
      root = i;
    }
  }
  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++) print(i);
  
  return 0;
}
  



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

int main(void) {
  string s;
  string t;
  cin>>s;
  cin>>t;
  int r = 0;
  if(s.compare(t) == 0) {
    cout << r << endl;
    return 0;
  }
  for(int i = 0; i < s.size(); i++ ) {
    if(s[i]!=t[i]){
      r++;
    }
  }
  cout << r << endl;
  return 0;
}

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

int main() {
  int N,count=0;
  cin >> N;
  string S;
  cin >> S;
  for(int i=0;i<N-2;i++){
      if(S.at(i)=='A'){
          if(S.at(i+1)=='B'){
              if(S.at(i+2)=='C'){
                  count++;
              }
          }
      }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
typedef struct
{
	int A;
	int B;
}omise;

int cmp(const void *p, const void *q) {
	return ((omise*)p)->A - ((omise*)q)->A;
}


int main()
{
	int N, M,i;
	omise list[MAX];

	unsigned long kingaku = 0;

	scanf("%d %d", &N, &M);
	for (i = 0;i < N;i++)
	{
		scanf("%d %d", &list[i].A, &list[i].B);
	}
	qsort(list, N, sizeof(omise), cmp);
	for (i = 0;M>0;i++)
	{
		if (M > list[i].B) {
			kingaku += (list[i].A*list[i].B);
		}else {
			kingaku += (list[i].A*M);
		}

		M -= list[i].B;
	}
	printf("%ld\n",kingaku);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;

int main()
{
    FAST

    ll n;

    cin>>n;

    map<string ,ll> m;

    for(ll i = 0;i<n;i++)
    {
        string s;
        cin>>s;

        m[s]++;
    }

    cout<<"AC x "<<m["AC"]<<endl;

    cout<<"WA x "<<m["WA"]<<endl;

    cout<<"TLE x "<<m["TLE"]<<endl;

    cout<<"RE x "<<m["RE"]<<endl;

    return 0;
}



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

ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }

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

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
from collections import deque
n,q = map(int,input().split())
que = deque([])
ans = []
t = 0
for i in range(n):
    name,time = input().split()
    que.append([name,int(time)])
while que:
    p = que.popleft()
    if p[1] > q:
        t += q
        p[1] -= q
        que.append(p)
    else:
        t += p[1]
        ans.append([p[0],t])

for namae,num in ans:
    print(namae,num)


Measured memory_bytes: 15096
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))


ans = 0
for i,ai in enumerate(a):
    
    ans += b[ai-1]
    if i ==0:
        continue
    if ai == a[i-1]+1:
        ans += c[ai-2]

print(ans)
    

Measured memory_bytes: 3060
s = input()
t = input()

sset = set(s)
tset = set(t)

if sset != tset:
    print('No')
    exit()

# for i in range(len(s)):
#     temp = ''
#     for j in range(i, i + len(s)):
#         if j > len(s) - 1:
#             j = j - i
#         temp = temp + s[j]
#     print(temp)

for _ in range(len(s)):
    s = s[len(s) - 1] + s[:len(s) - 1]
    if s == t:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 3060
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int X = sc.nextInt();
        int T = sc.nextInt();

        //試行回数
        int l;

        //割り切れるとき
        if(N % X == 0){
            l = N / X;
        }
        else{
            l = N / X + 1;
        }

        int a = l * T;
        System.out.println(a);
    }
}

Measured memory_bytes: 35692
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


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

    int n;
    cin>>n;
    map<int,int>mp;
    for (int i = 1; i <=100; i++)
    {
        for (int j = 1; j <=100; j++)
        {
            for (int k = 1; k <=100; k++)
            {
                int x=i*i+j*j+k*k+i*j+i*k+j*k;
                mp[x]++;
            }
            
        }
        
    }
    for (int i = 1; i <=n; i++)
    {
        cout<<mp[i]<<'\n';
    }
    
    
    
    return 0;
}

Measured memory_bytes: 6068
N, M = map(int, input().split())
s = []
for n in range(0, M):
  s.append(list(map(lambda x: int(x), input().split())))

answer = [-1] * N

for n in s:
  index = n[0] - 1
  if answer[index] == -1:
  	answer[index] = n[1]
  else:
    if answer[index] != n[1]:
      print("-1")
      exit()

if len(answer) == 1:
  if answer[0] == -1:
    print("0")
    exit()
  else:
    print(answer[0])
    exit()
if answer[0] == -1:
  answer[0] = 1
if answer[0] == 0:
  print("-1")
  exit()
      
for n in range(0, len(answer)):
  if answer[n] == -1:
    answer[n] = 0
      
ans_string = ""
for n in answer:
  ans_string += str(n)

print(ans_string)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////


int cnt(int k) {
	int res = 0;
	while (k != 0) {
		res++;
		k /= 10;
	}
	return res - 1;
}

int main() {
	int N;
	cin >> N;
	int key[10][10];
	REP(i, 10)REP(j, 10)key[i][j] = 0;
	//先頭がiで末尾がjの数
	for (int i = 1; i <= N; ++i) {
		key[i / int(pow(10, cnt(i)))][i % 10]++;
	}
	int ans = 0;
	bool m[10];
	REP(i, 10)m[i] = false;
	for (int i = 1; i <= 9; ++i) {
		for (int j = 1; j <= 9; ++j) {
			ans += key[i][j] * key[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (const T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int z = 0;
	while(a>0 and c>0)
	{
		if(z & 1)
			a -= d;
		else
			c -= b;
		z ^= 1;
	}
	cout << (z ? "Yes" : "No");
}


Measured memory_bytes: 3648
def main():
    n = int(input())
    df = []
    for _ in range(n):
        a, b = map(int, input().split(' '))
        df.append([a+b, a, b])
    df.sort(reverse = True)
    result = 0
    for i in range(n):
        if i%2 == 0:
            x = df.pop(0)
            result += x[1]
        else:
            x = df.pop(0)
            result -= x[2]
    print(result)
if __name__ == '__main__':
    main()

Measured memory_bytes: 23260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
int main(){
	int N;
	cin >> N;
	int a[100];
	rep(i,N)cin>>a[i];
	int ans = 100000000;
	for(int i=-100;i<=100;i++){
		int sum = 0;
		rep(j,N){
			sum += (i-a[j])*(i-a[j]);
		}
		ans = min(ans,sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int a[400000],b[400000];
signed main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    if(b[n-2]==b[n-1]){
        rep(i,n)cout<<b[n-1]<<endl;
    }
    else{
        rep(i,n){
            if(a[i]==b[n-1])cout<<b[n-2]<<endl;
            else cout<<b[n-1]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7296