akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
using namespace std;

#define N 100000
#define EPS 1e-9
#define PI 3.14159265358979323846264338327950

int h[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, m, u, v, ans;
	cin >> n >> m;
	vector<vector<int>> adj(n);
	for (int i = 0; i < n; ++i) cin >> h[i];
	for (int i = 0; i < m; ++i) {
		cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}
	
	ans = 0;
	for (int i = 0; i < n; ++i) {
		if (adj[i].size() == 0){
			++ans;
		} else {
			bool ok = true;
			for (int j = 0; j < adj[i].size(); ++j)
				ok = ok && h[i] > h[adj[i][j]];
			ans += ok;
		}
	}
	cout << ans << '\n';
}


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

int saiki( long long int m, long long int n, vector< long long int > v ) {

  for ( long long int i = min( m, n ); i >= 1; i-- ) {
    v.push_back( i );
    if ( i == n ) {
      for ( long long int j = 0; j < v.size(); j++ ) {
	if ( j > 0 ) cout << " ";
	cout << v[j];
      }
      cout << endl;
    }else {
      saiki( i, n - i, v );
    }
    v.pop_back();
  }

  return 0;

}

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    vector< long long int > v;

    saiki( n, n, v );

  }

  return 0;

}

Measured memory_bytes: 1224
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import qualified Data.Map as M

main :: IO ()
main = mapM_ printIndex . solve =<< getc words

solve :: [[String]] -> [(String,[String])]
solve xs = M.assocs $ foldl f M.empty xs
  where
    f m [s,n] = M.insertWith (++) s [n] m

printIndex :: (String,[String]) -> IO ()
printIndex (s,ss) = do
  putStrLn s
  putStrLn . unwords . sortBy (\x y -> (toInt x) `compare` (toInt y)) $ ss
  
toInt :: String -> Int
toInt s = read s

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

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

int main() {
 long long n;
  cin>>n;
  long long a[n];
  map<int,long long> freq;
  for(long long i=0;i<n;i++)
  {
    cin>>a[i];
    freq[a[i]]++;
    
  }

  long long answer=0;
  for(auto i=freq.begin();i!=freq.end();++i)
  {
    long long count = i->second;
      answer+=(count*(count-1))/2;
  }
  for(long long i=0;i<n;i++)
  {

      cout<<answer-freq[a[i]]+1<<endl;
  
  }
  
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  double a, b;
  cin >> a >> b;
  int ans = 0;
  int curr = 1;
  while (curr < b) {
    curr -= 1;
    curr += a;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
            decimal sumAs = As.Sum();
            decimal ret = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (i == N - 2)
                {
                    ret = (ret + As[i] * As[i + 1] % COMDIV) % COMDIV;
                    break;
                }
                sumAs -= As[i];
                ret = (ret + As[i] * sumAs % COMDIV ) % COMDIV;
            }

            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 49156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
//#include<set>
//#include<iostream>
using namespace std;

int n;
int main()
{
	scanf("%d",&n);
	if (n/100==n%10) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
from math import atan, degrees


def main():
    a, b, x = map(int, input().split())

    full = a * a * b
    half = full * 0.5

    if x <= half:
        s = x / a
        ans = 90 - degrees(atan(2 * s / b ** 2))

    else:
        s = (full - x) / a
        if s != 0:
            ans = 90 - degrees(atan(a ** 2 / (2 * s)))
        else:
            ans = 0

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
s = gets.chomp
res = 'AC'

def lower?(c)
  if 'a' <= c
    return true
  end

  return false
end

if s[0] != 'A' || !lower?(s[1]) || !lower?(s[s.length-1])
  res = 'WA'
end

cnt = 0
c = ''

(2..s.length-2).each do |i|
  if !lower?(s[i])
    cnt += 1
    c = s[i]
  end
end

if cnt != 1 || c != 'C'
  res = 'WA'
end

puts res


Measured memory_bytes: 3836
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define per(a,b,c) for (int a=b;a>=c;a--)
#define go(u) for (int o=ft[u],v;v=E[o].t;o=E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> par;
const int P=1000000007,N=420;
LL f[N][N][N/3],g[N][N][N/3];
int n,a[N],b[N],s[N][N],toa[N],tob[N];
void upd(LL &x,LL y){x=(x+y)%P;}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),toa[a[i]]=i;
	rep(i,1,n) scanf("%d",b+i),tob[b[i]]=i;
	toa[0]=tob[0]=n+3;
	f[0][0][0]=1;
	rep(i,1,n) s[0][i]=i;
	rep(i,1,n) rep(j,0,n) s[i][j]=s[i-1][j]+(tob[a[i]]>j);//a[i]|b[1~j];
	rep(i,0,n) rep(j,0,n) rep(k,0,n/3){
		if (s[i][j]>3*k||s[i][j]<2*k||i<k||j<k) continue;
		LL res_c=3*k-s[i][j],res_2=n-3*k-1/*s[i][j]*/;
		LL fn=f[i][j][k];
		rep(_,0,0){// upd f
			if (tob[a[i+1]]<=j/*a[i+1]|b[1~j]*/){
				upd(f[i+1][j][k],fn);
				break;
			}
			upd(g[i][j][k],fn);
			upd(f[i+1][j][k],fn*res_c);
			if (toa[b[j+1]]<=i/*b[j+1]|a[1~i]*/) break;
		}
		LL gn=g[i][j][k];
		rep(_,0,0){// upd g
			if (tob[a[i+1]]<=j/*a[i+1]|b[1~j]*/) break;
			if (toa[b[j+1]]<=i/*b[j+1]|a[1~i]*/){
				upd(g[i][j+1][k],gn);
				break;
			}
			upd(g[i][j+1][k],gn*res_c);
			if (a[i+1]==b[j+1]) break;
			upd(f[i+1][j+1][k+1],gn*((res_2-1)*(res_2-0)));
		}
	}
	printf("%lld\n",g[n][n][n/3]);
	return 0;
}


Measured memory_bytes: 371584
#include <stdio.h>

#define maxArraySize 1000

void output(int a[],int n){
	int c;
	for(c=0;c<n;c++){
		printf("%d",a[c]);
		if(c != n-1)printf(" ");
	}
	printf("\n");
}

void insersionSort(int A[],int N){
	int i,j,v;
	for(i=1;i<N;i++){
		v = A[i];
		j = i - 1;
		while(j>=0 && A[j]>v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		output(A,N);
	}
}

int main(void){
	int a[maxArraySize],n,c;
	scanf("%d",&n);
	for(c=0;c<n;c++){
		scanf("%d",&a[c]);
	}
	output(a,n);
	insersionSort(a,n);
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
          
          #define F first
          #define S second
          #define N 222222
          #define M 1000000007
          #define pb push_back
          #define cend(s) return cout << s, 0
          using namespace std;
          typedef long long ll;
	ll arr[23232];
          typedef vector<int> vi;
          
          int main()
          {
            int n, r = 0, w, r1 = 0, w1 = 0;
            string s, ss;
            cin >> n >> s;
            for(int i = 0; i < n; i++)
              r += (s[i] == 'R');
            w = n - r;
            if(!w || !r)  
              cend(0);    
            for(int i = 0; i < n; i++)
            {
              w1 += (s[i] == 'W');
              r1 += (s[i] == 'R');
              if(w1 == r-r1 || w1 == w)
                cend(w1);
            }
          }

Measured memory_bytes: 3708
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
M=a[n-1]
for i in range(n-1):
    b.append(M-a[i])
c=a+b
c.sort()

import bisect
index=bisect.bisect_right(c,M//2)-1

if c[index] in a:
    print(M,c[index])
else:
    print(M,M-c[index])

Measured memory_bytes: 14428
#include<bits/stdc++.h>
#define MAXN 205
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
char str[MAXN][MAXN];
int color[MAXN];
int d[MAXN][MAXN];
bool dfs(int v,int c)
{
    color[v]=c;
    for(int i=1;i<=n;i++)
    {
        if(str[v][i]!='1') continue;
        if(color[i]==c) return false;
        if(!color[i]&&!dfs(i,-c)) return false;
    }
    return true;
}
void floyd_warshall()
{
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
          for(int j=1;j<=n;j++)
            d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
    memset(color,0,sizeof(color));
    bool f=true;
    for(int i=1;i<=n;i++) if(color[i]==0&&!dfs(i,1)) f=false;
    if(!f)
    {
        puts("-1");
        return 0;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j) d[i][j]=0;
            else d[i][j]=(str[i][j]=='1'?1:INF);
        }
    floyd_warshall();
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(d[i][j]!=INF) ans=max(ans,d[i][j]+1);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();
        System.out.println(new Main().f(s, t));
    }

    public String f(String s, String t) {
        int m = s.length();
        int n = t.length();
        int[][] dp = new int[m+1][n+1];
        for(int i = 1; i <= m; i++){
            for(int j = 1; j <= n; j++){
                if(s.charAt(i-1) == t.charAt(j-1)){
                    dp[i][j] = dp[i-1][j-1] + 1;
                }else{
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        int i = m, j = n;
        while(i > 0 && j > 0){
            if(s.charAt(i-1) == t.charAt(j-1)){
                sb.append(s.charAt(i-1));
                i--;
                j--;
            }else{
                if(dp[i-1][j] >= dp[i][j-1]){
                    i--;
                }else{
                    j--;
                }
            }
        }
        return sb.reverse().toString();
    }
}


Measured memory_bytes: 82772
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
string s;
int k;
int main()
{
	cin>>s;
	cin>>k;
	for(int i=0;i<s.size();i+=k)
	{
		cout<<s[i];
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
ans = 1
# index: 同じ帽子をかぶっている人数
# value: 色の数
cnt = [3 if i == 0 else 0 for i in range(N+1)]

for a in A:
    ans = ans * cnt[a] % mod
    if ans == 0:
        break
    cnt[a] -= 1
    cnt[a+1] += 1

print(ans)



Measured memory_bytes: 56108
n = int(input())
a = list(map(int, input().split()))
num = [0 for i in range(max(a)+3)]
for i in a:
    num[i] += 1
ans = 0
for i in range(max(a)+1):
    temp = num[i] + num[i+1] + num[i+2]
    ans = max(temp, ans)
print(ans)

Measured memory_bytes: 13964
import java.util.*;
import java.math.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long[N];
    for (int i=0; i<N; i++) {
      A[i] = sc.nextLong();
    }
    long maxhu = -1_000_000_001;
    long minsei = 1_000_000_001;
    int counthu = 0;
    long out = 0;
    for (int i=0; i<N; i++) {
      if(A[i] < 0){
        counthu++;
      }
      if(A[i] < 0 && maxhu < A[i]){
        maxhu = A[i];
      } else if (A[i] >= 0 && minsei > A[i]){
        minsei = A[i];
      }
    }
    for (int i=0; i<N; i++) {
      if(A[i] < 0){
        out -= A[i];
      } else {
        out += A[i];
      }
    }
    if(counthu%2 == 1){
      out -= 2*Math.min(-maxhu, minsei);
    }
    System.out.println(out);
  }
}



Measured memory_bytes: 50396
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<int> a = { 1, 14, 32, 51, 51, 51, 243, 419, 750, 910 };
ll kai(vector<ll> A, ll key) {
	ll an = 0;
	rep(i, A.size()) {
		an += (A.at(i) - 1) / key;
	}
	return an;
}
// index が条件を満たすかどうか
bool isOK(int index,vector<ll> A, int K) {
	if (kai(A,index) <= K) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(ll MA,vector<ll> A,ll K) {
	int left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = MA; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, A,K)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}


int main() {
	ll N;
	cin >> N;
	if (N == 2) {
		cout << 1 << endl;
		return 0;
	}
	ll an = 1;
	for (ll i = 2; i * i <= N - 1; i++) {
		if ((N - 1) % i == 0) {
			an += 2;
			if (i * i == N-1) {
				an--;
			}
		}
	}
	
	for (ll i = 2; i * i <= N; i++) {
		if (i * i == N) {
			an++;
			continue;
		}
		if (N % i == 0) {
			ll k = i;
			ll M = N;
			while (M %k == 0) {
				M /= k;
			}
			if ((M - 1) % k == 0)an++;
		}
		if (i * i != N) {
			ll k = N/i;
			ll M = N;
			while (M % k == 0) {
				M /= k;
			}
			if (M - 1 % k == 0)an++;
		}
	}
	cout << an + 1 << endl;

}


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

int main(){

	int n, q, m, h, d, data[100];
	
	while(cin >> n >> q){
		if(n == 0 && q == 0) break;
		fill(data, data+100, 0);
		h = 0;
		
		for(int i=0; i<n; i++){
			cin >> m;
			for(int j=0; j<m; j++){
				cin >> d;
				data[d]++;
			}
		}
		
		for(int i=0; i<100; i++){
			if(h < data[i]){
				h = data[i];
				d = i;
			}
		}
		
		if(h >= q) cout << d << endl;
		else cout << '0' << endl;
	}

	return 0;

}

Measured memory_bytes: 1160
using System;
class Program
{
	static void Main()
	{
	int n = int.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    int[] nums = new int[n];
   	 for(int i = 0; i<n; i++)
   	 {
		nums[i] = int.Parse(Console.ReadLine());
   	 }
    Array.Sort(nums);//小さい順に並び替え
    int cal = 1;//求める個数
    	for(int i = 0; i<n-1; i++)
   	 {
   	  if(nums[i]<nums[i+1])cal++; 
   	 }
	//出力
	Console.WriteLine(cal);//WriteLineをWriteとすると、改行なしで出力。
	}
}

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

int main(int argc, char** argv){
  ll N, K;
  cin >> N >> K;
  // 0<=K<=1e12 -> 1e12 = (10^3)^4 < (2^10)^4 = 40bit
  ll A[N];
  for(int cnt0=0; cnt0<N; cnt0++) cin >> A[cnt0];

  ll X = 0;
  for(int i=40; i>=0; i--){
    ll shft = 1LL << i;
    if(shft > K - X) continue;

    // A1~ANの先頭からiビット目の1の数を数える
    // int cntOne: iビット目の1の数
    int cntOne = 0;
    for(int j=0; j<N; j++) if(A[j] & shft) cntOne++;
    if(cntOne <= N/2) X += shft;
  }
  
//  cout << X << endl;
  // Xが求まったのでfを求める
  ll ans = 0;
  for(int j=0; j<N; j++) ans += A[j] ^ X;

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


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	int n,m;
	cin >> n >> m;
	ll a[n],b[n],c[m],d[m];
	for (int i=0;i<n;i++) cin >> a[i] >> b[i];
	for (int i=0;i<m;i++) cin >> c[i] >> d[i];
	for (int i=0;i<n;i++) {
		int f=1;
		int e=abs(a[i]-c[0])+abs(b[i]-d[0]);
		for (int j=1;j<m;j++) {
			if (abs(a[i]-c[j])+abs(b[i]-d[j])<e) e=abs(a[i]-c[j])+abs(b[i]-d[j]),f=j+1;
		}
		cout << f << endl;
	}
}

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

int H, W;

int main() {
  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    for(int i = 0; i < H; i++){
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3088
#include <iostream>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
// long long -> lint
using lint = long long;
// fast cin and cout from hitonanode-san's code
// w/o 71 ms -> w/ 18 ms (tested on ABC148-D with C++14(GCC 5.4.1))
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;


int main(){
    // input
    int N, M;
    cin >> N >> M;
    vector<int> AC(N);
    vector<int> WA(N);
    for( int i=0; i<N; i++ ){
        AC[i]=0;
        WA[i]=0;
    }

    // cal
    int p;
    string S;
    for( int i=0; i<M; i++ ){
        cin >> p >> S;
        // not correct yet
        if( AC[p-1] != 1 ){
            if( S == "AC" ){
                // correct case
                AC[p-1] = 1;
            }else{
                // incorrect case
                WA[p-1]++;
            }
        }
    }
    int num_ac = 0, num_wa = 0;
    for( int i=0; i<N; i++ ){
        if( AC[i]==1 ){
            num_ac++;
            num_wa += WA[i];
        }
    }

    // out
    cout << num_ac << " " << num_wa << endl;
} 

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

int main()
{
    string s;   cin >> s;
    int len = s.size();
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < len; i++)
    {
        if (i % 2)//奇数
        {
            if (s[i] == '1')  ans1++;
            else    ans2++;
        }
        else
        {
            if (s[i] == '1')   ans2++;
            else    ans1++;
        }
    }
    cout << min(ans1, ans2);
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
//#define INF 1e6+5
#define ll long long


#define ar array
#define wt(x) int x;cin>>x;while(x--)
typedef unsigned long long int ull;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

 void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
 
}
ll power(ll a,ll b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    ll res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
//dfs tree and bridges
 //forward ->parent to child
 //back->child to parent
 
 
 long long A, B, C, D;
long long INF = 5e18;
 
void min_self(long long& a, long long b) {
    a = min(a, b);
}
 
map<long long, long long> mapka;
 
long long f(long long goal) {
    if(goal == 0) {
        return 0;
    }
    if(goal == 1) {
        return D;
    }
    if(mapka.count(goal)) {
        return mapka[goal];
    }
    long long best = INF;
    if(D < INF / goal) {
        min_self(best, D * goal);
    }
    for(int i = 0; i < 3; ++i) {
        int mul = vector<int>{2,3,5}[i];
        long long cost = vector<long long>{A,B,C}[i];
        if(goal % mul == 0) {
            min_self(best, cost + f(goal / mul));
        }
        else {
            long long down = goal / mul * mul;
            min_self(best, cost + D * (goal - down) + f(goal / mul));
            long long up = down + mul;
            min_self(best, cost + D * (up - goal) + f(goal / mul + 1));
        }
    }
    return mapka[goal] = best;
}
 
void test_case() {
    long long N;
    cin >> N;
    cin >> A >> B >> C >> D;
    cout << f(N) << endl;
    mapka.clear();
}
 
int main() {
    c_p_c();
    int T;
    cin >> T;
    while(T--) {
        test_case();
    }
}

 
 

Measured memory_bytes: 4456
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let arr:Vec<(char, char)> = (0..n).map(|_| {
        let s: String = read();
        let mut it = s.chars();
        let c = it.next().unwrap();
        let k = it.next().unwrap();
        (c, k)
    }).collect();
    let b = bubble_sort(arr.clone(), n);
    println!("{}", b.iter().map(|&(c, k)| format!("{}{}", c, k)).collect::<Vec<String>>().join(" "));
    println!("Stable");
    let s = selection_sort(arr.clone(), n);
    println!("{}", s.iter().map(|&(c, k)| format!("{}{}", c, k)).collect::<Vec<String>>().join(" "));
    if is_stable(&b, &s, n) {
        println!("Stable");
    } else {
        println!("Not stable");
    }
}

fn bubble_sort(mut a:Vec<(char, char)>, n:usize) -> Vec<(char, char)> {
    let mut flag = true;
    while flag {
        flag = false;
        for i in 1..n {
            if a[i].1 < a[i-1].1 {
                a.swap(i, i-1);
                flag = true;
            }
        }
    }
    a
}

fn insert_sort(mut a:Vec<String>, n: usize) -> Vec<String> {
    for i in 1..n {
        let mut j = i;
        while j > 0  && a[j-1] > a[j] {
            a.swap(i, i-1);
            j -= 1;
        }
    }
    println!(
        "{}",
        a.clone()
            .into_iter()
            .map(|x| x.to_string().chars().rev().collect::<String>())
            .collect::<Vec<String>>()
            .join(" ")
    );
    println!("Stable");
    return a.into_iter().map(|x| x.to_string().chars().rev().collect::<String>()).collect::<Vec<String>>()
}

fn selection_sort(mut a:Vec<(char, char)>, n:usize) -> Vec<(char, char)> {
    for i in 0..n {
        let mut min = i;
        for j in i..n {
            if a[j].1 < a[min].1 {
                min = j;
            }
        }
        if a[i] != a[min] {
            a.swap(i, min);
        }
    }
    a
}

fn is_stable(v1: &Vec<(char, char)>, v2: &Vec<(char, char)>, n:usize) -> bool{
    for i in 0..n {
        if v1[i] != v2[i] {
            return false;
        }
    }
    true
}


Measured memory_bytes: 5028
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,h,w,n);
  VEC(int,a,n);

  int now = 0;
  vector< vector<int> > ans(h, vector<int>(w,0));
  REP(hi,h){
    REP(wi,w){
      int w_real = ((hi&1)?wi:w-wi-1);
      ans[hi][w_real] = now;
      if (--a[now]==0) ++now;
    }
  }

  REP(hi,h){
    REP(wi,w){
      if (wi!=0) SP;
      OUT(ans[hi][wi]+1);
    }
    BR;
  }
  
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int H, W;
    int height, width;
    for(;;){
        scanf("%d %d", &height, &width);
        if(height == 0&& width ==0) break;
        for(H = 1; H <= height; H++){
            for(W = 1; W <= width; W++)
                putchar('#');
            putchar('\n');
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2040
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  int n,ans=0;
  cin >> n;
  VVI d(n,VI(2));
  
  for(int a=1; a<=n+1; a++){
    for(int b=1; a*b<n; b++){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 89316
#include <iostream>
#include <queue>
#define INF 100000;
#define P pair < int , pair < int , pair < int , int > > > 
#define dis first
#define dir second.first
#define x second.second.first
#define y second.second.second
using namespace std;
int w,h;
int mp[31][31];
int c[4];
//> v < ^
//0 1 2 3

int mk(int dr,int i) {
  if(dr==0) return (0+i)%4;
  else if(dr==3) return (1+i)%4;
  else if(dr==2) return (2+i)%4; 
  else if(dr==1) return (3+i)%4;

  return -1;
}

int dijkstra() {
  priority_queue <P> Q;
  int dx[] = {1,0,-1,0};
  int dy[] = {0,1,0,-1};
  bool visited[4][31][31] = {};
  int d[4][31][31];
  for(int i=0;i<4;i++)
    for(int j=0;j<h;j++)
      for(int k=0;k<w;k++) 
	d[i][j][k] = -INF;

  P t;
  t.dis = 0,   t.dir = 0,   t.x = 0,   t.y = 0;
  d[0][0][0] = 0;
  Q.push(t);

  while(!Q.empty()){
    t = Q.top() , Q.pop();
    if(visited[t.dir][t.y][t.x] == 1) continue;
    visited[t.dir][t.y][t.x] = 1;

    // if(mp[t.y][t.x] == 4) continue;

    for(int i=0;i<4;i++) {
      int nx = t.x+dx[i],ny = t.y+dy[i];
      if(nx<0 ||ny<0 ||w<=nx ||h<=ny) continue;
      int ii = mk(t.dir,i);
      int cost = c[ii];
      if(mp[t.y][t.x] == ii) cost = 0;

      if(d[i][ny][nx] < d[t.dir][t.y][t.x]-cost) {
	d[i][ny][nx] = d[t.dir][t.y][t.x]-cost;
	P tt;
	tt.x = nx,  tt.y = ny,  tt.dir = i,  tt.dis = d[i][ny][nx];
	Q.push(tt);
      }
    }
  }

  int ans = -INF;
  for(int i=0;i<4;i++) ans = max(ans,d[i][h-1][w-1]);
  return ans;
}

int main() {

  while(1) {
  cin >> w >> h;
  if(w == 0 && h == 0) break;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mp[i][j];
    }
  }
   
  for(int i=0;i<4;i++) cin >> c[i];

  cout << -dijkstra() <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    cout << 2 * 3.14 * n << "\n";
}




Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const int mod = 1e9+7;

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < (1<<3); i++){
    bitset<3> b(i);
    vector<char> op(3);
    int tmp = s[0] - '0';
    REP(j,3+1){
      int a = s[j] - '0';
      if(b.test(j-1)) {
        tmp += a;
        op[j-1] = '+';
      }
      else{
        tmp -= a;
        op[j-1] = '-';
      }
    }
    if(tmp == 7){
      rep(i,3) cout << s[i] << op[i];
      cout << s[3] << '=' << 7 << endl;
      return 0;
    }
  }
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  ll n, m;
  cin >> n >> m;
  ll tmp1 = n/2;
  ll tmp2 = (n/2) + 1;
  bool flag = (n % 2 == 0);
  map<int, bool> mp;
  rep(i, m){
    cout << tmp1 << ' ' << tmp2 << endl;
    tmp1 -= 1;
    tmp2 += 1;
    if(flag){
      if(n/2 == tmp2 - tmp1 || mp[n - (tmp2 - tmp1)]){
        tmp2 += 1;
      }
      mp[tmp2 - tmp1] = true;
    }
  }
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val nums = readLine()?.split(" ")
    nums ?: return
    val n = nums[0].toInt()
    val a = nums[1].toInt()
    val b = nums[2].toInt()

    val result = (1..n).filter { sum(it) in a..b }.sum()
    println(result)
}

private fun sum(num: Int): Int {
    var sum = num % 10
    var n = num / 10
    while (n >= 1) {
        sum += (n % 10)
        n /= 10
    }
    return sum
}

Measured memory_bytes: 35952
S = input()
N = len(S)

all_error = 0
for i in range(0, N-1):
  if S[i] == S[N-1-i]:
    pass
  else:
    all_error = 1

before_error = 0
for j in range(0, int((N-1-1)/2)):
  if S[j] == S[int((N-1-1)/2)-j]:
    pass
  else:
    before_error = 1

after_error = 0
for k in range(0, (N-1) - (int((N+3)/2)-1) - 1):
  if S[int((N+3)/2)-1+k] == S[N-1-k]:
    pass
  else:
    after_error = 1

if int(all_error) + int(before_error) + int(after_error) == 0:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    A, _ := strconv.Atoi(arr[0])
    P, _ := strconv.Atoi(arr[1])
    retval := (A * 3 + P) / 2
    fmt.Println(retval)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define pb push_back
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

int a[maxn];



int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    int n,k; cin >> n >>k;
    int r = 1e9;
    k--;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i >= k) {
            r = min(r, min(abs(a[i - k]), abs(a[i])) + a[i] - a[i - k]);
        }
    }
    cout << r <<endl;
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	ll n,k;
	cin >> n >> k;
	
	const ll zero = n / k;
	ll ans = 1LL * zero * zero * zero;

	if(k % 2 == 0){
		const ll half = max(0LL, n + k/2) / k;
		ans += 1LL * half  * half * half;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N,M = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for _ in range(N):
    A,B = list(map(int, input().split()))
    a.append(A)
    b.append(B)
for _ in range(M):
    C,D = list(map(int, input().split()))
    c.append(C)
    d.append(D)
inf = float('inf')

for i in range(N):
    ans = 0
    l = inf
    for j in range(M):
        if l > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            l = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
    print(ans)


Measured memory_bytes: 3064
n=int(input())
N=10**4+20;M=103
a=[0 for _ in range(N)]
for x in range(1,M):
    for y in range(1,M):
        for z in range(1,M):
            res=x*x+y*y+z*z+x*y+y*z+z*x;
            if res<N:a[res]+=1
for i in range(n):
    print(a[i+1])

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum;

int main()
{
	fast;
	cin>>n;
	fs(ar,n-1);
	sum+=ar[1]+ar[n-1];
	fo(i,2,n-1)
		sum+=min(ar[i],ar[i-1]);
	
	cout<<sum;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int mxn=1e5+10;
ll n,arr[mxn],dp[mxn];
ll func(ll i,ll idx)
{
    if(idx>=n-1)
        return 0;
    if(dp[idx]!=-1)
        return dp[idx];
    ll p=0,q=INT64_MAX;
    p=func(1,idx+1)+abs(arr[idx+1]-arr[idx]);
    if(idx+2<n)
        q=func(2,idx+2)+abs(arr[idx+2]-arr[idx]);
    return dp[idx]=min(p,q);
}
int main()
{   
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    memset(dp,-1,sizeof dp);
    cout<<func(0,0)<<endl;
    return 0;
}

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

using namespace std;

int a[200000], b[200000];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, i;
	int sol = 0;
	vector<int> vec;
	int lo1, hi1, lo2, hi2;
	int k;
	
	cin>>n;
	
	for (i = 0; i < n; ++i)
		cin>>a[i];
	for (i = 0; i < n; ++i)
		cin>>b[i];
	
	for (int l = 0; l < 29; ++l)
	{
		int mask = (1<<(l+1))-1;
		vec.clear();
		for (i = 0; i < n; ++i)
			vec.push_back(a[i] & mask);
		sort(vec.begin(), vec.end());
		
		k = 0;
		for (i = 0; i < n; ++i)
		{
			lo1 = (1<<l) - (b[i] & mask);
			hi1 = (2<<l) - (b[i] & mask);
			lo2 = (3<<l) - (b[i] & mask);
			hi2 = (4<<l) - (b[i] & mask);
			
			k += lower_bound(vec.begin(), vec.end(), hi1) - lower_bound(vec.begin(), vec.end(), lo1);
			k += lower_bound(vec.begin(), vec.end(), hi2) - lower_bound(vec.begin(), vec.end(), lo2);
		}
		
//		cout<<k<<'\n';
		
		if (k & 1)
			sol |= 1<<l;
	}
	
	cout<<sol<<'\n';
}


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

int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N > K) {
    cout << X * K + Y * (N-K) << endl;
  }
  else {
    cout << X * N << endl;
  }
}

Measured memory_bytes: 256
//Volume5-0513
import java.util.Scanner;

class Main {

	private static int   n,len;
	private static int[] card;

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		n    = sc.nextInt();
		len  = n*2;
		card = new int[len];
		init();
		int m=sc.nextInt();
		int k;
		while(m-- > 0){
			k = sc.nextInt();
			if   (k==0){riffle();}
			else       {cut(k)  ;}
		}
		for(int i:card){System.out.println(i);}
	}

	private static void init(){
		for(int i=0;i<card.length;i++){
			card[i] = i+1;
		}
	}

	private static void cut(int k){
		int[] tmp = new int[card.length];
		int i=0;
		for(int j=k;j<card.length;i++,j++){
			tmp[i] = card[j];
		}
		for(int j=0;j<k;i++,j++){
			tmp[i] = card[j];
		}
		card = tmp;
	}

	private static void riffle(){
		int[] tmp = new int[len];
		for(int i=0,j=0;j<n;i+=2,j++){
			tmp[i]   = card[j];
			tmp[i+1] = card[j+n];
		}
		card = tmp;
	}
}

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

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

	int same = 0;
	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] == S[0] ) same++;
	}

	if( S.size() == same ) {
		cout << S.size() * K / 2 << endl;
		return 0;
	}
	int cnt = 0;
	for( int i = 0; i < S.size() - 1; i++ ) {
		if( S[i] == S[i + 1] ) {
			cnt++;
			i++;
		}
	}
	string s = S + S;
	int cnt1 = 0;
	for( int i = 0; i < s.size() - 1; i++ ) {
		if( s[i] == s[i + 1] ) {
			cnt1++;
			i++;
		}
	}
	long long ans = (cnt1 - cnt) * (K - 1) + cnt;

	cout << ans << endl;
}


Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline

MAX  = 10 ** 15

N, M, s, t = map(int, input().split())

g1 = [[] for _ in range(N + 1)]
g2 = [[] for _ in range(N + 1)]
for _ in range(M):
    u, v, a, b = map(int, input().split())
    
    g1[u].append((a, v))
    g1[v].append((a, u))
    
    g2[u].append((b, v))
    g2[v].append((b, u))

d1 = [MAX] * (N + 1)
d2 = [MAX] * (N + 1)

d1[s] = 0 #始点の距離を0にする
pque = []
heapq.heappush(pque, [0, s]) #要素を[距離、頂点]として管理　最初の位置を入れる

while len(pque) != 0: #queの中に要素が残っている時
    p = heapq.heappop(pque) #最も距離が短いものを取り出す
    v = p[1] #距離が最も短い頂点
    if d1[v] < p[0]: #取り出した値より既に小さい値がdに入っているときは無視して次へ
        continue
    for i in range(len(g1[v])): #頂点vの隣接リストを走査
        e = g1[v][i]
        if d1[e[1]] > d1[v] + e[0]: #距離が更新できるかを検討
            d1[e[1]] = d1[v] + e[0]
            heapq.heappush(pque, [d1[e[1]], e[1]]) #更新できた場合、その値をpqueに入れる

# print (d1)

d2[t] = 0 #始点の距離を0にする
pque = []
heapq.heappush(pque, [0, t]) #要素を[距離、頂点]として管理　最初の位置を入れる

while len(pque) != 0: #queの中に要素が残っている時
    p = heapq.heappop(pque) #最も距離が短いものを取り出す
    v = p[1] #距離が最も短い頂点
    if d2[v] < p[0]: #取り出した値より既に小さい値がdに入っているときは無視して次へ
        continue
    for i in range(len(g2[v])): #頂点vの隣接リストを走査
        e = g2[v][i]
        if d2[e[1]] > d2[v] + e[0]: #距離が更新できるかを検討
            d2[e[1]] = d2[v] + e[0]
            heapq.heappush(pque, [d2[e[1]], e[1]]) #更新できた場合、その値をpqueに入れる

# print (d2)

tmp = MAX
ans = [MAX] * N
for i in range(N, 0, -1):
    tmp = min(tmp, d1[i] + d2[i])
    ans[i - 1] -= tmp

print (*ans, sep = '\n')

Measured memory_bytes: 118812
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		out.println(1-t);
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    vector<bool> used(110,false);
    for(int i=0;i<n;i++){
        cin>>p[i];
        used[p[i]] = true;
    }
    int tmp = 150, ans = 0;
    for(int i=0;i<=101;i++){
        // cout<<i<<" ";
        if(used[i]) continue;
        ans = (tmp > abs(x - i)) ? i : ans;
        tmp = min(tmp, abs(x-i));
        // cout<<abs(x - i)<<endl;
    }

    cout<<ans<<endl;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n);
    rep(i, n) a[i] = vector<int>(m);
    vector<int> b(m);
    vector<int> c(n);
    rep(i, n)
    {
        rep(j, m) cin >> a[i][j];
    }
    rep(j, m) cin >> b[j];
    rep(i, n)
    {
        rep(j, m)
        {
            c[i] += a[i][j] * b[j];
        }
    }
    rep(i, n)
    {
        cout << c[i] << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数　
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define INTINF 1000000000
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000  //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

#define N_MAX 100000
#define h_MAX 10000
#define K_MAX 100

int main()
{
    int N;
    int K;
    long dp[N_MAX + 1];
    long tmpdp;
    long mintmpdp;
    int h[N_MAX];

    memset(dp, -1, sizeof(dp));
    memset(h, -1, sizeof(h));

    cin >> N;
    cin >> K;
    REP(i, N)
    {
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < N; i++)
    {
        int jMax = min(i, K);
        mintmpdp = h_MAX * N_MAX;
        for (int j = 1; j <= jMax; j++)
        {
            tmpdp = dp[i - j] + abs(h[i] - h[i - j]);

            if (tmpdp < mintmpdp)
            {
                mintmpdp = tmpdp;
            }
        }
        dp[i] = mintmpdp;
    }
    cout << dp[N - 1];
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
  
  char S[3];
  
  scanf("%s", S);
  
  
  if(S[0] == S[1] && S[1] == S[2]){
    printf("No");
  }else{
    printf("Yes");
  }
  
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  string ans = "Yes";
  int T = 0, X = 0, Y = 0;

  for (int i = 0; i < N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    int a = t - T, b = abs(x - X) + abs(y - Y);
    if (a < b) ans = "No";
    if (a % 2 == 0 && b % 2 == 1) ans = "No";
    if (a % 2 == 1 && b % 2 == 0) ans = "No";
    T = t, X = x, Y = y;
  }

  cout << ans << "\n";
}

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

int main() {
    ll n,m;
    cin>>n>>m;
    if(n>=m){
        cout<<min(n,m/2);
    }else {
        ll com=m/2;
        ll ans=0;
        if(com>=n){
            ans+=n;
            com-=n;
            cout<<ans+(com)/2;
        }else{
            cout<<com;
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            
            if(N %2 == 0)
            {
                var Sh = S.Substring(0, N / 2);
                
                if(S == Sh + Sh)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }

            }
            else
            {
                Console.WriteLine("No");

            }
        }
        
    }

}


Measured memory_bytes: 13140