akhauriyash/Code-Regression huggingface dataset:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

H,W = imn()
a = [input() for _ in range(H)]

dp = [[0 for _ in range(W)] for _ in range(H)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if i+1 < H and a[i+1][j] == '.': dp[i+1][j] = m_add(dp[i+1][j], dp[i][j])
        if j+1 < W and a[i][j+1] == '.': dp[i][j+1] = m_add(dp[i][j+1], dp[i][j])
print(dp[H-1][W-1])

Measured memory_bytes: 82008
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

int H, W;
string S[55];
int d[55][55];

bool inside(int y, int x)
{
	return 0 <= y and y < H and 0 <= x and x < W; 
}

signed main()
{
	cin >> H >> W;
	rep(i, H) cin >> S[i];

	rep(i, H) rep(j, W) d[i][j] = 1e9;

	queue<pii> q;
	q.push(pii(0, 0));
	d[0][0] = 0;

	while (q.size()) {
		pii p = q.front(); q.pop();

		rep(i, 4) {
			int ny = p.fst + dy[i], nx = p.scd + dx[i];

			if (inside(ny, nx)) {
				if (S[ny][nx] == '#' or d[ny][nx] != 1e9) continue;
				d[ny][nx] = d[p.fst][p.scd] + 1;
				q.push(pii(ny,nx));
			}
		}
	}

	if (d[H - 1][W - 1] == 1e9) {
		cout << -1 << endl;
		return 0;
	}

	int bcnt = 0;
	rep(i, H) rep(j, W) bcnt += S[i][j] == '#';

	//printf("bcnt %lld\n",bcnt);

	int ans = H * W - 2 - bcnt - d[H-1][W-1] + 1;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int d;
int q;
 
typedef struct {
  char name[100];
  int t;
}Process;
 
Process Q[10000000];
int n;
int head=0, tail=0;
 
 
void enqueue(Process x){
  Q[head]=x;
  head++;
}
 
Process dequeue(){
  tail++;
  return Q[tail-1];
}
 
int main(void){
  int i,j;
  int count;
  int time=0;
  Process x;
  scanf("%d %d", &n, &q);
   
  for ( i = 0; i < n; i++){
    scanf("%s", x.name);
    scanf("%d", &x.t);
    enqueue(x);
  }
   
  while(1){
    x=dequeue();
    if(x.t<=q){
      time+=x.t;
      printf("%s %d\n", x.name, time);
    }
    else{
      x.t-=q;
      time+=q;
      enqueue(x);
    }
    if(head-tail==0)break;
  }
  return 0;
}

Measured memory_bytes: 21076
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    // the a_i's are not necessarily distinct, so if it's possible to reach state 2, it'll be possible to reach it within N steps
    // otherwise there's a cycle (pigeonhole principle)
    int N;
    cin >> N;
    vector <int> a(N + 1);
    for(int i = 1 ; i <= N ; ++i){
        cin >> a[i];
    }
    int current = 1;
    int moves = 0;
    for(int i = 1 ; i <= N && current != 2 ; ++i, ++moves){
        current = a[current];
    }
    cout << (current == 2 ? moves : -1) << '\n';
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        vec.pb(b);
    }
    LL ans = 0;
    REP(a,N){
        ans += vec.at(a)-1;
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

ll dp[MAX][13];

int main(){
  string s;cin>>s;
  ll x = s.length();

  dp[0][0] = 1;
  rep(i,x){
    char c = s[i];
    ll tmp;
    if(c=='?') tmp = -1;
    else tmp = c-'0';
    rep(j,10){
      if(tmp != -1 and tmp != j) continue;
      rep(k,13){
        dp[i+1][(k*10+j) %13] += dp[i][k];
      }
    }
    rep(j,13) dp[i+1][j] %= MOD;
  }
  /*
  rep(i,x){
    rep(j,13){
      cout<<dp[i][j];
    }
    cout<<endl;
  }
  */
  cout<<dp[x][5]<<endl;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define int             long long
#define ld              long double
#define rep0(i,n)       for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rep(i,x,y)      for(int i=x;i<=y;i++)
#define reprev1(i,n)    for(int i=n;i>0;i--)
#define reprev0(i,n)    for(int i=n-1;i>=0;i--)
#define reprev(i,x,y)   for(int i=x;i>=y;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcount(x)
#define zerobits(x)     __builtin_ctz(x)
#define in(a,n)         vi a(n);rep0(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);rep1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define endl            '\n'
#define mod             1000000007
#define M               (int)1e6+6
#define inf             1e18
using namespace std;

int n,m,k,x,y,z,a1,b,c,d,i,j;





void sol()
{   
    cin>>n;
    in(a,n);
    c=0;
    int mx=0;

    rep1(i,n-1)
    {
      if(a[i]<=a[i-1])c++;
      mx=max(mx,c);
      if(a[i]>a[i-1])c=0;
      
    }
    
    
    cout<< mx <<endl;
}





int32_t main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // w(t)
    sol();
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<LP> pos0(n),pos1(n);
    rep(i,n) {
        ll x,y; cin >> x >> y;
        ll x1 = x-y, x2 = x+y;
        pos0[i] = LP(x1,x2);
        pos1[i] = LP(x2,x1);
    }
    sort(all(pos0)); sort(all(pos1));
    ll ans = max((pos0[n-1].first-pos0[0].first),(pos1[n-1].first-pos1[0].first));
    cout << ans << endl;

    // vector<ll> dist(n);
    // rep(i,n) {
    //     ll x,y; cin >> x >> y;
    //     dist[i] = x+y;
    // }
    // sort(all(dist));
    // cout << dist[n-1]-dist[0] << endl;
}

Measured memory_bytes: 9588
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> s;
int n, m;
int solve(int i, int m){
    if (m == 0)
        return 1;
    if (i >= n)
        return 0;
    int res = solve(i + 1, m)||solve(i + 1, m - s[i]);
    return res;
}
int main()
{
    vector<int> t;
    cin >> n;
    int temp;
    for (int i = 0; i < n; i++){
        cin >> temp;
        s.push_back(temp);
    }
    cin >> m;
    for (int i = 0; i < m; i++){
        cin >> temp;
        t.push_back(temp);
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < m; i++){
        if(solve(0, t[i]))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}



Measured memory_bytes: 3168
from collections import deque
t,*g=open(0)
h,w=map(int,t.split())
vis=[[1e9]*w for _ in range(h)]
vis[0][0]=int(g[0][0]=="#")
q=deque([(0,0,vis[0][0])])
while q:
	cy,cx,c=q.popleft()
	for ny,nx in ((cy+1,cx),(cy,cx+1)):
		cc=c
		if not (0<=ny<h and 0<=nx<w):
			continue
		if g[cy][cx]=="." and g[ny][nx]=="#":
			cc+=1
		if cc<vis[ny][nx]:
			vis[ny][nx]=cc
			q.append((ny,nx,cc))
#print(vis)
print(vis[-1][-1])

Measured memory_bytes: 3572
# 二分探索, 累積和
from bisect import bisect_right

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for x in [A, B, C]:
    x.sort()

t = [0] * (N + 1)  # 中部のパーツのサイズが Bi 以上のときの B と C の組み合わせの数
for i in range(N):
    t[i] = N - bisect_right(C, B[i])
for i in range(N - 1, -1, -1):
    t[i] += t[i + 1]

result = 0
for a in A:
    result += t[bisect_right(B, a)]
print(result)


Measured memory_bytes: 23360
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if(n+1 >= 2*k) System.out.println("YES");
		else System.out.println("NO");
	}

}


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


signed main() {
  int N;
  int p[50];
  cin >> N;
  for(int i=0; i<N; i++) cin >> p[i];

  auto get = [&](int i, int j, int k) {
    if(k==i) return p[j];
    if(k==j) return p[i];
    return p[k];
  };

  bool ok=true;
  for(int k=1; k<N; k++) if(p[k-1] > p[k]) { ok=false; break; }
  if(ok) { puts("YES"); return 0; }

  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) {
    bool ok=true;
    for(int k=1; k<N; k++) if(get(i,j,k-1) > get(i,j,k)) { ok=false; break; }
    if(ok) { puts("YES"); return 0; }
  }
  puts("NO");
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val (a,b,c,d) = readLine()!!.split(" ").map { it.toInt() }
    val frm = Math.max(a,c)
    val to = Math.min(b,d)
    val ans = Math.max(0, to-frm)
    println(ans)
}


Measured memory_bytes: 37948
import math 
import bisect
from collections import deque
n,k,q = map(int, input().split())
a = [0]*q
for i in range(q):
    a[i] = int(input())

judge = [k-q] * n
for i in range(len(a)):
    judge[a[i]-1] += 1

for i in range(n):
    if judge[i] > 0:print('Yes')
    else: print('No')



Measured memory_bytes: 10800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <climits>

typedef long long ll;

using namespace std;

void solve() {
    double r;
    cin >> r;
    printf("%08f %08f\n", r*r*M_PI, r*2*M_PI);
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
using namespace std;
int main(){
int N,a,b,c;
cin>>N;
for(int i=0;i<N;i++){
int ans=0;
cin>>a>>b>>c;
	if(a*a==b*b+c*c){
	ans=ans+1;}
		else if(b*b==a*a+c*c){
		ans=ans+1;}
		else if(c*c==a*a+b*b){
		ans=ans+1;}
	if(ans==1){
	cout<<"YES"<<endl;}
	if(ans!=1){
	cout<<"NO"<<endl;}
	}
return 0;
}

Measured memory_bytes: 1156
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {

    static int N;
    static int[] bit = new int[1000010];

    public static void add(int a, int w) {
        for (int i=a;i<=N;i+=i&(-i)) {
            bit[i]+=w;
        }
    }

    public static int sum(int a) {
        int ret = 0;
        for (int i=a;i>0;i-=i&(-i)) {
            ret+=bit[i];
        }
        return ret;
    }

    public static int get(int k) { // 0_indexed find
        ++k;
        int res = 0;
        int nn = 1; while (nn < (int)N) nn *= 2;
        for (int i = nn / 2; i > 0; i /= 2) {
            if (res + i < (int)N && bit[res + i] < k) {
                k = k - bit[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        N = in.nextInt();
        int K = in.nextInt();
        int[] P = new int[N];
        int sorted = 0;
        int cnt = 0;
        int before= -1;
        for (int i=0;i<N;i++) {
            P[i] = in.nextInt();
            if (P[i]>before) {
                cnt++;
                if (cnt==K) sorted++;
            } else {
                cnt=1;
            }
            before = P[i];
        }

        for (int i=0;i<K;i++) {
            add(P[i]+1, 1);
        }

        int ans = N-K+1;
        for (int i=K;i<N;i++) {
            int flag = 0;
            if (get(0)!=P[i-K]+1) flag=1;
            add(P[i-K]+1, -1);
            add(P[i]+1, 1);
            if (get(K-1)!=P[i]+1) flag=1;
            if (flag==0) ans--;

            // out.println(flag);
        // for (int j=0;j<K;j++) {
        //     if (j==K-1) out.println(get(j));
        //     else out.print(get(j)+" ");
        // }
        }
        if (sorted>=2) out.println(ans-sorted+1);
        else out.println(ans);
        // out.println(sorted);

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 49220
from collections import Counter
n_cards, n_change = map(int,input().split())
a_ls = list(map(int, input().split()))
c = Counter(a_ls)
for i in range(n_change):
    time, card = map(int,input().split())
    c[card] += time

d = sorted(c.items(),key=lambda x:x[0], reverse=True)
ans = 0
rest = n_cards
for v, times in d:
    if times <= rest:
        ans += v*times
        rest -= times
    else:
        ans += v*rest
        break
print(ans)

Measured memory_bytes: 121248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			double n = in.nextDouble();
			double m = in.nextDouble();
			double d = in.nextDouble();

			if (d == 0) {
				out.println(n*(m-1)/(n*n));
			} else {
				out.println(2*(n-d)*(m-1)/(n*n));
			}

		}


	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 22740
import scala.collection.mutable.PriorityQueue

object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n");
    println(solve(input).trim());
  }

  def solve(input:String):String={
    val Array(nm,aas)=input.split("\n");
    val Array(n,m)=nm.split(" ").map(_.toInt)
    val as=aas.split(" ").map(_.toLong)
    val pq = new PriorityQueue[Long]
    for(a <- as){
      pq.enqueue(a)
    }
    for(i <- 1 to m){
      pq.enqueue(pq.dequeue/2)
    }
    pq.toList.sum.toString
  }
}


Measured memory_bytes: 75812
#include <math.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

using namespace std;
using ll = long long;
using P = pair<int, int>;

ll solve(int temp, int end, vector<int> c, vector<int> p, int now) {
  vector<ll> ans;
  ll score = 0;

  while (temp >= end) {
    // cout << temp << endl;
    now = p.at(now);
    // cout << "now" << now << endl;
    score += c.at(now);
    ans.push_back(score);

    temp--;
  }
  // cout << "関数ない while終わり" << endl;
  ll maxS = ans.at(0);
  for (int i = 0; i < ans.size(); i++) {
    if (maxS < ans.at(i)) {
      maxS = ans.at(i);
    }
  }
  return maxS;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  vector<int> c(n);
  int pT;
  for (int i = 0; i < n; i++) {
    cin >> pT;
    p.at(i) = pT - 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> c.at(i);
  }

  int now;
  ll ans = -1e18;
  for (int i = 0; i < n; i++) {
    now = i;
    vector<int> temp;
    temp.push_back(now);
    ll score = c.at(now);
    for (int j = 0; j < k; j++) {
      now = p.at(now);
      if (now == i) {
        break;
      }
      score += c.at(now);
      temp.push_back(now);
    }

    ll tempS = 0;
    for (int j = 0; j < temp.size(); j++) {
      tempS += c.at(temp.at(j));
      if (j + 1 > k) break;
      ll tempT = tempS;
      if (score > 0) {
        ll loop = (k - j - 1) / temp.size();
        tempT += score * loop;
      }
      ans = max(ans, tempT);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3324
import itertools
n,m,x = list(map(int,input().split()))
a = []
f = True
res = []
p = 0

for i in range(n):
    a.append(list(map(int,input().split())))

for k in range(n):
    for i in itertools.combinations(a,k+1):

        f = True
        for l in range(m):
            if f == True:
                c = 0
                p = 0
                for j in range(k+1):
                    if len(i) == 1:
                        c += i[j][l+1]
                    else:
                        c += i[j][l+1]
                if c < x:
                    f = False
           
        if f == True:
            ressum = 0
            for o in range(k+1):
                ressum += i[o][0]
            res.append(ressum)

if res == []:
    print(-1)
else:
    print(min(res))               
               

Measured memory_bytes: 9252
#include <stdio.h>

int MAX_INT=2018;

int sum_Digit(int num){
  int dig;
  int sum=0;

  while(num){
    dig = num%10;
    sum = sum+dig;
    num = num/10;
  }
  return sum;
}

int main() {
  int N;
  scanf("%d", &N);

  int a, b, ans=MAX_INT;
  int tmp;
  if (N>10){
    for (int i=1; i<N/2+1; i++){
      a=i;
      b=N-a;
      if (b%10==0){
        tmp=sum_Digit(a)+sum_Digit(b);
        if (ans>tmp){
          ans=tmp;
        }
      }
    }
  }
  else{
    for (int i=1; i<N/2+1; i++){
      a=i;
      b=N-a;
      tmp=sum_Digit(a)+sum_Digit(b);
      if (ans>tmp){
        ans=tmp;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
  
using namespace std;

void SieveOfEratosthenes(int n, bool prime[], 
                         bool primesquare[], int a[]) 
{ 
    // Create a boolean array "prime[0..n]" and 
    // initialize all entries it as true. A value 
    // in prime[i] will finally be false if i is 
    // Not a prime, else true. 
    for (int i = 2; i <= n; i++) 
        prime[i] = true; 
  
    // Create a boolean array "primesquare[0..n*n+1]" 
    // and initialize all entries it as false. A value 
    // in squareprime[i] will finally be true if i is 
    // square of prime, else false. 
    for (int i = 0; i <= (n * n + 1); i++) 
        primesquare[i] = false; 
  
    // 1 is not a prime number 
    prime[1] = false; 
  
    for (int p = 2; p * p <= n; p++) { 
        // If prime[p] is not changed, then 
        // it is a prime 
        if (prime[p] == true) { 
            // Update all multiples of p 
            for (int i = p * 2; i <= n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    int j = 0; 
    for (int p = 2; p <= n; p++) { 
        if (prime[p]) { 
            // Storing primes in an array 
            a[j] = p; 
  
            // Update value in primesquare[p*p], 
            // if p is prime. 
            primesquare[p * p] = true; 
            j++; 
        } 
    } 
} 
  
// Function to count divisors 
int countDivisors(int n, bool prime[], 
                         bool primesquare[], int a[]) 
{ 
    // If number is 1, then it will have only 1 
    // as a factor. So, total factors will be 1. 
    if (n == 1) 
        return 1; 
  
    
  
    // ans will contain total number of distinct 
    // divisors 
    int ans = 1; 
  
    // Loop for counting factors of n 
    for (int i = 0;; i++) { 
        // a[i] is not less than cube root n 
        if (a[i] * a[i] * a[i] > n) 
            break; 
  
        // Calculating power of a[i] in n. 
        int cnt = 1; // cnt is power of prime a[i] in n. 
        while (n % a[i] == 0) // if a[i] is a factor of n 
        { 
            n = n / a[i]; 
            cnt = cnt + 1; // incrementing power 
        } 
  
        // Calculating the number of divisors 
        // If n = a^p * b^q then total divisors of n 
        // are (p+1)*(q+1) 
        ans = ans * cnt; 
    } 
  
    // if a[i] is greater than cube root of n 
  
    // First case 
    if (prime[n]) 
        ans = ans * 2; 
  
    // Second case 
    else if (primesquare[n]) 
        ans = ans * 3; 
  
    // Third case 
    else if (n != 1) 
        ans = ans * 4; 
  
    return ans; // Total divisors 
} 
  

signed main()
{

  std::ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
  int n;
    cin >> n;
    vector<vector<int>> divisors(n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            divisors[j].push_back(i);
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        cnt += divisors[n - i].size();
    }
    cout << cnt;
  return 0;
}

Measured memory_bytes: 184032
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> x, y;
vector< pair<int, int> > d;

using ll = long long;

ll solve1() {
  for(int i=0;i < n;i++)
    d.emplace_back(x[i], i),
    d.emplace_back(y[i], i);
  sort(begin(d), end(d));
  int rmin = d[0].first, bmax = d[n*2-1].first;
  int bmin = y[d[0].second], rmax = x[d[n*2-1].second];
  for(int i = 0; i < n ; i++) {
    if(i == d[0].second) continue;
    if(i == d[n*2-1].second) continue;
    rmax = max(rmax, x[i]);
    bmin = min(bmin, y[i]);
  }
  return ll (rmax - rmin) * (bmax - bmin);
}

ll solve2() {
  if(d[0].second == d[n*2-1].second) return (ll) 1e18;
  int rmin = d[0].first, rmax = d[n*2-1].first;
  ll res = 1e18;

  int bmax = y[d[0].second];
  for(int i = 1; i < 2*n-1 ; i++)
    if(d[i].second != d[0].second) bmax = max(bmax, x[d[i].second]);
  int ymin = y[d[0].second];

  set<int> st;
  for(int i = 1; i < 2*n-1 ; i++) {
    int j = d[i].second;
    if(j == d[0].second) continue;
    if(st.count(j)) continue;
    st.insert(j);
    int bmin = min(ymin, x[j]);
    
    res = min(res, ll (rmax - rmin) * (bmax - bmin));
    if(j == d[n*2-1].second) break;
    bmax = max(bmax, y[j]);
    ymin = min(ymin, y[j]);
  }
  return res;
}

int main() {
  cin >> n;
  x = vector<int>(n);
  y = vector<int>(n);
  for(int i=0;i < n;i++) {
    int s, t;
    cin >> s >> t;
    if(s > t) swap(s, t);
    x[i] = s; y[i] = t;
  }
  ll res = 1e18;
  res = min(res, solve1());
  res = min(res, solve2());
  cout << res << endl;
}


Measured memory_bytes: 14828
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.exception;

  long x, y; rd(x, y);

  if(x==y) writeln(-1);
  else if(x<y) writeln(x);
  else writeln(x%y==0 ? -1 : x);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

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

using namespace std;

int n;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i, printf("\n"))
    {
        for (int j = i + 1; j <= n; ++ j)
        {
            int val = i ^ j;
            for (int k = 0; ; ++ k)
                if (val & (1 << k))
            {
                printf("%d ", k + 1);
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y);
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int H = 105;
const int W = 105;
char field[H][W];

int m, n;

int a[4] = {1, 0, -1, 0};
int b[4] = {0, 1, 0, -1};

void dfs(int x, int y, char c)
{
    field[x][y] = '$';
    for(int i = 0; i < 4; i++)
    {
        int x1 = x + a[i];
        int y1 = y + b[i];
        if(0 <= x1 && x1 < m && 0 <= y1 && y1 < n && field[x1][y1] == c)
        {

            dfs(x1, y1, c);
        }
    }
    return ;
}
int main()
{
    while(~scanf("%d %d", &m, &n) && m && n)
    {

        int ans = 0;
        mset(field, '$');
        fori (i, 0, m){
            getchar();
            fori (j, 0, n)
            {
                scac(field[i][j]);
            }
        }

        fori (i, 0, m)
            fori (j, 0, n)
            {
                if(field[i][j] != '$')
                    {
                        ans++;
                        dfs(i, j, field[i][j]);
                    }
            }
            cout << ans << endl;
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <climits>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

long long int inf = 10000000000000000;

int main(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,r;
	cin>>n>>m>>r;
	int cit[r];
	for(int i = 0; i < r; i++){
		cin>>cit[i];
	}
	long long int a[n+1][n+1];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			a[i][j] = inf;
		}
	}
	for(int i = 1; i <= n; i++){
		a[i][i] = 0;
	}
	int u,v,w;
	for(int i = 1; i <= m; i++){
		cin>>u>>v>>w;
		a[u][v] = w;
		a[v][u] = w;
	}
	for(int k = 1; k <= n; k++){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}
	long long int dp[(1<<r)][r];
	for(int mask = 1; mask < (1<<r); mask++){
		for(int j = 0; j < r; j++){
			if(mask&(1<<j)){
				int otherMask = mask^(1<<j);
				if(otherMask == 0){
					dp[mask][j] = 0;
				}else{
					dp[mask][j] = inf;
					for(int k = 0; k < r; k++){
						if(otherMask&(1<<k)){
							dp[mask][j] = min(dp[mask][j], dp[otherMask][k] + a[cit[j]][cit[k]]);
						}
					}
				}
			}
		}
	}
	long long int ans = inf;
	for(int i = 0; i < r; i++){
		ans = min(ans, dp[(1<<r) - 1][i]);
	}
	cout<<ans<<endl;
}



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

int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    rep(i,n-1){
        if(p[i] == i+1) {
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    if(p[n-1] == n) ans++;
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int N, W_count = 0, R_count = 0;
  string S;
  
  cin >> N >> S;
  
  for (int i = 0; i < N; i++) {
    if (S[i] == 'W') {
      W_count++;
    }
    
    if (S[i] == 'R') {
      R_count++;
    }
  }
  
  if (R_count == 0 || W_count == 0) {
    cout << 0 << endl;
    
    return 0;
  }
  
  int ans = 0;
  for (int i = 0; i < R_count; i++) {
    if (S[i] == 'W') {
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main()
{
	long long N, W; // N：アイテム数、W：ナップザックの容量
	cin >> N >> W;
	vector<long long> iw(N + 1);	// 重さ
	vector<long long> iu(N + 1);	// 価値
	vector<vector<long long>> dp(N + 1, vector<long long>(W + 1)); // DPメモリ（アイテム、容量）
	iw[0] = iu[0] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> iw[i] >> iu[i];
	}

	for (int i = 0; i <= N; i++) {
		dp[i][0] = 0;
		dp[0][i] = 0;
	}

	// Item Loop
	for (int i = 1; i <= N; i++) {
		// Weight Loop
		for (int j = 1; j <= W; j++) {
			if (j - iw[i] >= 0) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - iw[i]] + iu[i]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	cout << dp[N][W];
}


Measured memory_bytes: 80256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

k, n, *lst = map(int, read().split())
lst.sort()
dis = k
for i in range(n):
    if i == 0:
        tmp=lst[-1] - lst[0]
    else:
        tmp=k - lst[i] + lst[i - 1]
    dis=min(dis, tmp)
print(dis)

Measured memory_bytes: 25124
//AtCoder ABC077 B - Around Square
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N;
    cin>>N;
    ll ans=0;
    for (ll i=1;i*i<=N;++i) {
        ans=max(ans,i*i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int N,a,count = 0;
  cin >> N;
  for(int i = 0;i < N;++i){
    cin >> a;
    while(a > 0){
      if(a%2 != 0)break;
      count++;
      a /= 2;
    }
  }

  cout << count << endl;
}

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

int main(){
	int N, M, Q;
	cin >> N >> M >> Q;
	int X[N][N], R[N][N];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			X[i][j] = 0;
		}
	}
	for(int i=0; i<M; i++){
		int L, R;
		cin >> L >> R;
		X[L-1][R-1]++;
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(i == 0 && j == 0){
				R[i][j] = X[0][0];
			}else if(i == 0){
				R[i][j] = R[i][j-1] + X[i][j];
			}else if(j == 0){
				R[i][j] = R[i-1][j] + X[i][j];
			}else{
				R[i][j] = R[i-1][j] + R[i][j-1] - R[i-1][j-1] + X[i][j];
			}		
		}
	}
	int p[Q], q[Q];
	for(int i=0; i<Q; i++){
		cin >> p[i] >> q[i];
	}
	for(int i=0; i<Q; i++){
		if(p[i] == 1){
			cout << R[q[i]-1][q[i]-1] << endl;
		}else{
			cout << R[q[i]-1][q[i]-1] - R[q[i]-1][p[i]-2] - R[p[i]-2][q[i]-1] + R[p[i]-2][p[i]-2] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<int,bool> Pair;

int main(){

  int ans = 0;
  int A,B;

  cin >> A;
  cin >> B;

  if(B == 1) cout << ans << endl;
  else{

    ans = 1;

    for(int i = A;i < B ; i+=A)
    {
      ans++;
      --i;
    }
    cout << ans << endl;
  }
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

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

    int i=1;
    vector<string> div;
    div.push_back(S.substr(0,1));
    while(i<S.length()-1){
        if(S.substr(i,1)==div.back()){
            div.push_back(S.substr(i,2));
            i+=2;
        }else{
            div.push_back(S.substr(i,1));
            i+=1;
        }
    }

    if(i==S.length()-1&&S.substr(i,1)!=div.back()){
        div.push_back(S.substr(i,1));
    }

    cout<<div.size()<<endl;

    return 0;
}


Measured memory_bytes: 10996
n,k=map(int,input().split())
hl=list(map(int,input().split()))
dp=[0]
for i in range(1,n):
    t=[]
    for j in range(1,min(i+1,k+1)):
        t.append(dp[i-j]+abs(hl[i-j]-hl[i]))
    dp.append(min(t))
print(dp[-1])

Measured memory_bytes: 57824
int main(){
	
int i,n,H,W;

while(1){

scanf("%d %d",&H,&W);
if(H==0 && W==0) break;

for(i=1;i<=H;i++){
	for(n=1;n<=W;n++){
		if(i==1 || i==H){
		printf("#");
		}
		else{
			if(n==1 || n==W){
				printf("#");
			}
			else{
				printf(".");
			}
		}
	}
printf("\n");

}

printf("\n");

}
return 0;

}

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

int main(){
  int N;
  cin >>N;
  
  int A;
  vector<int> ans(N);
  rep(i,0,N){
    cin >> A;
    ans[A-1] = i+1;
  }
  
  rep(i,0,N) cout<<ans[i]<<' ';
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[200009];
main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    ll s = a[n];
    int u = n-2;
    for(int i = n-1; i >=1; i--){

        if(u == 0) break;
        if(u > 1) s += 2*a[i], u -= 2;
        else s += a[i], u--;
    }
    cout<<s<<endl;
}


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

using namespace std;
const int N=5e5+5,mod=1e9+7;
#define ll long long
ll x[N],v[N];
ll best[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    ll c;
    cin>>n>>c;
    for(int i=0;i<n;i++)
        cin>>x[i]>>v[i];
    ll cur=0,ans=0;
    for(int i=n-1;i>=0;i--)
    {
        cur+=v[i];
        ans=max(ans,cur-(c-x[i]));
        best[i]=max(best[i+1],cur-(c-x[i]));
    }
    cur=0;
    for(int i=0;i<n;i++)
    {
        cur+=v[i];
        ans=max(ans,cur-x[i]);
        ans=max(ans,cur+best[i+1]-2*x[i]);
        best[i]=cur-x[i];
        if(i) best[i]=max(best[i],best[i-1]);
    }
    cur=0;
    for(int i=n-1;i>=0;i--)
    {
        cur+=v[i];
        ans=max(ans,cur+best[i-1]-2*(c-x[i]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi std::vector<int>
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
#define YES std::cout << "YES" << std::endl
#define NO std::cout << "NO" << std::endl
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T> void debug(const T& t);
constexpr ll mod10_9p7 = 1000000000 + 7;

/**************************************************************/
int main()
{
    stat();
    string s;cin>>s;
    int curb=0;
    ull ans=0;
    rep(i,s.size()){
if(s[i]=='B'){++curb;continue;}
ans+=curb;


    }
    cout<<ans<<endl;

    return 0;
}
/**************************************************************/
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}

unsigned long long modpow(int x__, int n__, long long mod__)
{
    long long ret__ = 1;
    for (long long i__ = 0; i__ < n__; ++i__) {
        ret__ = ret__ * x__ % mod__;
    }
    return ret__;
}

template <typename T> void debug(const T& t)
{
#ifdef local
    dbg(t);
#endif
}


Measured memory_bytes: 3732
dic = {'1':1, '2':3, '3':1, '4':2, '5':1, '6':2, '7':1, '8':1, '9':2, '10':1, '11':2, '12':1}
i = list(map(int, input().split()))
if dic[str(i[0])] == dic[str(i[1])]:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    ll N, K;
    string S;

    cin >> N >> K >> S;

    S[K - 1] += 32;

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

char s[10];

int main(void)
{
	scanf("%s",s+1);
	for(int i=1; i<=3; ++i)
	{
		if(s[i]=='7')
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for (int i=1;i<=n;i++)if (i%3!=0&&i%5!=0)ans+=i;
        System.out.println(ans);
    }

}


Measured memory_bytes: 35836
import random
D=int(input())
c=[int(i) for i in input().split()]
s=[[int(i) for i in input().split()] for i in range(D)]
for i in range(D):
    j=0
    for k in range(26):
        if s[i][k]>s[i][j]:
            j=k
    print(j+1)

Measured memory_bytes: 9888
n=int(input())
a=[int(n)for n in input().split()]
b=[int(n)for n in input().split()]
c=[int(n)for n in input().split()]
s=b[a[0]-1]
for i in range(1,len(a)):
    if a[i-1]+1==a[i]:
        s+=c[a[i-1]-1]
    s+=b[a[i]-1]
print(s)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll s;
  cin >> s;
  ll x1 = 0;
  ll y1 = 0;
  ll x2 = 1000000000;
  ll y2 = 1;
  ll y3 = s/1000000000 + 1;
  if (s % 1000000000 == 0) {
    y3--;
  }
  ll x3 = 1000000000*y3 - s;
  cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << ' ' << '\n';
}


Measured memory_bytes: 3668
#include<iostream>

using namespace std;

int main(void) {
	int A, B, C;
	cin >> A >> B >> C;

	if (A == B && B == C && C == A) {
		cout << "No" << endl;
	}
	else if (A != B && B != C && C != A) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}


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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//s.find(w[i])==string::npos
//findの使い方

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)

long long int n,cnt=0,ans=0,a,b,c,cmp[100000],data[100000],m,h;

string s;

int main(void){
      cin >> s;
      string w="abcdefghijklmnopqrstuvwxyz";
      for(int i=0;i<w.size();i++){
          if(s.find(w[i])==string::npos){
              cout << w[i] << endl;
              return 0;
          }
      }
      cout << "None" << endl;
return 0;
}


Measured memory_bytes: 512
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum = 0;
  int r = min(a, k);
  sum += r;
  k -= r;
  r = min(b, k);
  k -= r;
  r = min(c, k);
  sum -= r;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char SA[128], SB[128], SC[128];

    scanf("%s%s%s", SA, SB, SC);

    int lena, lenb, lenc;

    lena = strlen(SA);
    lenb = strlen(SB);
    lenc = strlen(SC);

    int ta, tb, tc;
    ta = 0, tb = 0, tc = 0;
    int t = 0;

    while(true){
        if(t == 0){
            if(ta == lena){
                printf("A\n");
                break;
            }else if(SA[ta] == 'b'){
                t = 1;
            }else if(SA[ta] == 'c'){
                t = 2;
            }
            ta++;
        }else if(t == 1){
            if(tb == lenb){
                printf("B\n");
                break;
            }else if(SB[tb] == 'a'){
                t = 0;
            }else if(SB[tb] == 'c'){
                t = 2;
            }
            tb++;
        }else{
            if(tc == lenc){
                printf("C\n");
                break;
            }else if(SC[tc] == 'a'){
                t = 0;
            }else if(SC[tc] == 'b'){
                t = 1;
            }
            tc++;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string s; cin >> s;

    int a_pos = -1, z_pos;
    for (int i = 0; i < s.size(); i++) {
        if (a_pos == -1 && s[i] == 'A') {
            a_pos = i;
        } 
        if (a_pos != -1 && s[i] == 'Z') {
            z_pos = i;
        }
    }

    cout << z_pos - a_pos + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

N = int(input())
V = list(map(int, input().split()))

# コーナーケースは先に終わらせる
# 全部同じ数の場合は、N/2が答え
if len(set(V)) == 1:
    print(N//2)
    exit()
# 2つしかない場合は1が答え
if N == 2:
    print(1)
    exit()

# 方針: 偶数番目と奇数番目は分けて考える
# 偶数番目、奇数番目はそれぞれの最頻値に合わせるのが低コスト
# 最頻値が同じ場合は「数列に現れる数はちょうど2種類」の制約を外れるので、2番目に多い数にあわせる
d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = V[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

if l_even[0][0] != l_odd[0][0]:
    print(N - l_even[0][1] - l_odd[0][1])
else:
    # どちらも試してコストの小さい方を採用する
    ans1 = N - l_even[0][1] - l_odd[1][1]
    ans2 = N - l_even[1][1] - l_odd[0][1]
    print(min(ans1, ans2))


Measured memory_bytes: 65384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        int max = 0; 
        int secondmax = 0;
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            if(max < A[i]){
                secondmax = max;
                max = A[i];
            } else if(secondmax < A[i]){
                secondmax = A[i];
            }
        }
        
        for(int i = 0; i < N; i++){
            if(max == A[i]){
                System.out.println(secondmax);
            } else{
                System.out.println(max);
            }
        }
    }
}


Measured memory_bytes: 94048