akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStreamReader; 
import java.io.BufferedReader;
import java.io.IOException;

class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader bf = new BufferedReader(is);
		while (true) {
			String[] strAry = bf.readLine().split(" ");
			int h = Integer.parseInt(strAry[0]);
			int w = Integer.parseInt(strAry[1]);
			if (h == 0 && w == 0) {
				break;
			}
			for (int i = 1; i <= h; i++) {
				if (i % 2 != 0) {
					for (int j = 1; j <= w; j++) {
						if (j % 2 != 0) System.out.print("#");
						else  if (j % 2 == 0) System.out.print(".");	
						}
					} else if (i % 2 == 0) {
						for (int k = 1; k <= w; k++) {
						if (k % 2 != 0) System.out.print(".");
						else if (k % 2 == 0) System.out.print("#");
						}
					}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 30868
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n;
  cin >> n;
  cout << (n+1)/2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N, cnt = 1;
	
	scanf("%d", &N);
	int *d;
	d = (int*)malloc(sizeof(int) * N);

	for(int i = 0; i < N; i++){
		scanf("%d", &d[i]);
		for(int j = 0; j < i; j++){
			if(d[j] == d[i])	break;
			if(j == i - 1)	cnt++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
from itertools import chain, combinations
import sys

def all_subsets(ss):
    return chain(*map(lambda x: combinations(ss, x), range(0, len(ss) + 1)))

array=raw_input()

for subset in all_subsets([0,1,2]):
    suma=sum(map(int,str(array)))
    signs=list("+++")

    for ind in subset:
        suma=suma-2*int(array[ind+1])
        signs[ind]='-'

    if suma == 7:
        print array[0],
        for i in range(0,3):
            sys.stdout.write(signs[i])
            sys.stdout.write(array[i+1])
        break

sys.stdout.write("=7")







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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    for(int i = 0; i < n+1; i++) cin >> a.at(i);
    for(int i = 0; i < n; i++) cin >> b.at(i);
    long int max = 0;
    for(int i = 0; i < n; i++){
        if(b.at(i) > a.at(i)){
            max += a.at(i);
            b.at(i) = b.at(i) - a.at(i);
            if(b.at(i) > a.at(i+1)){
                max += a.at(i+1);
                a.at(i+1) = 0;
            }else{
                max += b.at(i);
                a.at(i+1) -= b.at(i);
            }
        }else{
            max += b.at(i);
            a.at(i) -= b.at(i);
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void B_task();

int main()
{
	B_task();
	fflush(stdout);
	return 0;
}

static void B_task()
{
	int a, b;
	get2int(a, b);
	int targ = a;
	int cnt = b;
	if (a > b) {
		targ = b;
		cnt = a;
	}
	
	char szTmp[10] = { 0 };
	for (int i = 0; i < cnt; i++) {
		szTmp[i] = '0' + targ;
	}

	printf("%s\n", szTmp);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
const int inf = 100100100;


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

  dsu d(n);
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    d.merge(a,b);
  }

  int ans = d.groups().size()-1;
  cout << ans << endl;
}


Measured memory_bytes: 8948
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n;
int a[1048];
LL dp[1048];Pair del[1048];
int cnt;
vector<int> ans;

inline void getans(int cur)
{
	if (del[cur].x==1)
	{
		for (int i=1;i<=cur-1;i++) ans.pb(1);
		cnt=cur-1;
		return;
	}
	getans(del[cur].x-1);
	int len=del[cur].y-del[cur].x+1;
	for (int i=len/2+1;i>=1;i--)
		ans.pb(del[cur].x-cnt+i-1);
	cnt+=len+1;
}

int main ()
{
	int i,j;
	n=getint();
	for (i=1;i<=n;i++) a[i]=getint();
	for (i=1;i<=n;i++)
	{
		dp[i]=a[i];del[i]=mp(1,i-1);
		for (j=2;i-j>=1;j+=2)
			if (dp[i-j]+a[i]>dp[i])
			{
				dp[i]=dp[i-j]+a[i];
				del[i]=mp(i-j+1,i-1);
			}
	}
	LL maxn=-INF;int pos;
	for (i=1;i<=n;i++)
		if (dp[i]>maxn) maxn=dp[i],pos=i;
	printf("%lld\n",maxn);
	getans(pos);
	for (i=n;i>=pos+1;i--) ans.pb(n-cnt),cnt++;
	printf("%d\n",int(ans.size()));
	for (i=0;i<int(ans.size());i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 256
# youtubeの解説で紹介されていたダブリングを使って実装してみる
import math

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

# aのindexと街番号をあわせる
a.insert(0,0)

# ダブリングのテーブル作成
db = [a]
logk = math.ceil(math.log(k, 2)) # 底を2にする。底のデフォルトがeになっているため
#print(logk)

for i in range(1, logk+1):
  d = [0] * (n+1)
  prev = db[i-1]
  for j in range(1, n+1):
    d[j] = prev[prev[j]]
  db.append(d)
#print(bin(k))
#print(len(bin(k)))
#print(db)

v = 1
for i in range(logk, -1, -1):
  bit = 1 << i
  if k & bit:
    v = db[i][v]
print(v)

Measured memory_bytes: 174308
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m,k;
string s,t;

int main() {
  cin >> n;
  int a[201010];
  rep(i,n) cin >> a[i];
  int ans=1e9,g;
  rep(i,n-1) chmin(ans,__gcd(a[i],a[i+1]));
  cout << ans << endl;
}

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

int main(void) {
	int N, K, Y, X, ans = 0;
	cin >> N;
	cin >> K;
	cin >> X;
	cin >> Y;
	for (int i = 1; i <= K; i++) {
		if(i > N) break;
		ans += X;
	}
	for (int i = K + 1; ; i++) {
		if(i > N) break;
		ans += Y;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S,T;cin>>S>>T;
  int c=0;
  if(S[0]==T[0])c++;
  if(S[1]==T[1])c++;
  if(S[2]==T[2])c++;
  cout<<c<<endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

int N, K;
int D[10];
/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  cin >> N >> K;
  rep(i, K){
    int tmp;
    cin >> tmp;
    D[tmp]=1;
  }

  for(int i=N;i<=10*N;i++){
    bool isOK = true;
    string S = to_string(i);
    for(int j=0;j<S.size();j++){
      int a = S[j] - '0';
      isOK = isOK and (D[a]!=1);
    }
    if(isOK){
      cout << i;
      return 0;
    }
  }
  
  return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = 1;
		while(sc.hasNext()) {
			int W = sc.nextInt();
			if(W == 0) break;
			int N = sc.nextInt();
			int[] dp = new int[W + 1];
			int[] v = new int[N];
			int[] w = new int[N];
			Arrays.fill(dp, -1);
			dp[0] = 0;
			for(int i = 0; i < N; i++) {
				String[] s = sc.next().split(",");
				v[i] = Integer.parseInt(s[0]);
				w[i] = Integer.parseInt(s[1]);
			}
			for(int i = 0; i < N; i++) {
				for(int j = W; j >= 0; j--) {
					if(dp[j] != -1 && j + w[i] <= W) {
						int t = w[i] + j;
						dp[t] = Math.max(dp[t], dp[j] + v[i]);
					}
				}
			}
			int wei = 0;
			int val = 0;
			for(int i = 0; i <= W; i++) {
				if(val < dp[i]) {
					wei = i;
					val = dp[i];
				}
			}
			System.out.printf("Case %d:\n", cnt);
			System.out.println(val);
			System.out.println(wei);
			cnt++;
		}
		sc.close();
	}
}


Measured memory_bytes: 32076
pepole = int(input())

boss = list(map(int, input().split()))

workerList = {}

for single in range(pepole):
  workerList[single + 1] = 0

for single in range(len(boss)):
  workerList[boss[single]] += 1

for single in range(len(workerList)):
  print(workerList[single + 1])

Measured memory_bytes: 38788
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   char s[110];
   scanf("%s",s+1);
   int n=strlen(s+1);
   int a=1,b=(n-1)/2,c=(n+3)/2,d=n;
   bool p1=1,p2=1,p3=1;
   for(int i=1;i<=n;i++){
       if(s[i]!=s[n-i+1]){
           p1=0;
           break;
       }
   }
   for(int i=1;i<=b;i++){
       if(s[i]!=s[b-i+1]){
           p2=0;
           break;
       }
   }
   int temp=d-c;
   for(int i=c;i<(c+d)/2;i++){
       if(s[i]!=s[i+temp]){
           p3=0;
           break;
       }
       temp-=2;
   }
   if(p1&&p2&&p3)cout<<"Yes";
   else cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> PII;
typedef pair <int, int> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef pair <ld, ld> PLD;
typedef pair <PLD, ld> PLDD;
typedef pair <PLL, ll> PLLL;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
const ll MOD = 1e9+696969;
const long long INF = (ll)1e18+3;
int n, m, k, a, b, c, DL = 0, CC = 0, T;
#define maxn 1000100
int t[maxn];
int ile[maxn];

int main() {
	boost;
	cin >> n;
	FOR(i, 1, n) {
		cin >> t[i];
		ile[t[i]]++;
	}
	
	sort(t + 1, t + n + 1);
	if (t[n] != t[n-1]) OUT("Impossible");
	//czy da sie stworzyc srednice. 
	if (t[n] == 1) {
		if (n != 2) OUT("Impossible");
		OUT("Possible");
	}
	
	int MIN = inf;
	FOR(i, 1, t[n] - 1) {
		int dl = max(i, t[n] - i);
		MIN = min(MIN, dl);
		if (ile[dl] == 0) OUT("Impossible");
		ile[dl]--;
	}

	FOR(i, 1, n)
	  if (t[i] < MIN) OUT("Impossible");
	int cnt = 0;
	FOR(i, 1, n)
	  if (t[i] == MIN) cnt++;
	  
	if (t[n] % 2 == 0) {
		if (cnt > 1) OUT("Impossible");
	}
	else {
		if (cnt > 2) OUT("Impossible");
	}
	OUT("Possible");
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            String a = Console.ReadLine();

            // スペース区切りの整数の入力
            int b = int.Parse(a.Split(' ')[0]);
            int c = int.Parse(a.Split(' ')[1]);

            String result = (b > 8 || c > 8) ? ":(" : "Yay!";

            //出力
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N, T;
    cin >> N >> T;

    vector<int> c(N);
    vector<int> t(N);
    for (int i = 0; i < N; i++) {
        cin >> c[i] >> t[i];
    }

    int ans = 1001;
    for (int i = 0; i < N; i++) {
        if (T < t[i]) {
            continue;
        }
        else {
            ans = min(ans, c[i]);
        }
    }

    if (ans > 1000) {
        cout << "TLE" << endl;
    }
    else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<utility>
using namespace std;
typedef pair<int, int> P;

struct edge {
    P p;
    int cost;
};

const int MAX_N = 1e5;
int n;
P x[MAX_N], y[MAX_N];
edge e[MAX_N * 2 - 2];

int r[MAX_N], par[MAX_N];

void init(int x) {
    for (int i = 0; i < x; i++) par[i] = i;
}

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (r[x] < r[y]) par[x] = y;
    else {
        if (r[x] == r[y]) r[x]++;
        par[y] = x;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x[i].first, &y[i].first);
        x[i].second = i;
        y[i].second = i;
    }
    sort(x, x + n);
    sort(y, y + n);
    for (int i = 0; i < n - 1; i++) {
        e[i].p = P(x[i].second, x[i + 1].second);
        e[i].cost = x[i + 1].first - x[i].first;
    }
    for (int i = 0; i < n - 1; i++) {
        e[i + n - 1].p = P(y[i].second, y[i + 1].second);
        e[i + n - 1].cost = y[i + 1].first - y[i].first;
    }
    sort(e, e + 2 * n - 2, [](const edge &e1, const edge &e2)->bool {
        return e1.cost < e2.cost;
    });
    init(n);
    int ans = 0;
    for (int i = 0; i < 2 * n - 2; i++) {
        if (!same(e[i].p.first, e[i].p.second)) {
            ans += e[i].cost;
            unite(e[i].p.first, e[i].p.second);
        }
    }

    printf("%d\n", ans);
    return 0;
}


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

int main(){
    string str;
    cin >> str;
    bool f=true;
    

    if(str[0]!='A'){
        f=false;
    }

    if(f){
        int sum=0;
        for(int i=2;i<=str.length()-2;i++){
            if(str[i]=='C'){
                sum++;
                if(sum>1)
                    break;
            }
        }
        if(sum!=1)
            f=false;
    }

    if(f){
        for(int i=1;i<str.length();i++){
            if(str[i]!='C'&&(str[i]<'a'||str[i]>'z')){
                f=false;
                break;
            }
        }
    }

    if(f)
        cout << "AC" << endl ;
    else
        cout << "WA" << endl;

    return 0;
}

Measured memory_bytes: 256
function main(lines) {
  const a = +lines[0];

  const res = a + a**2 + a**3;
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 29688
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
 
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;
 
 
//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
 
template<typename T>
void vecvecprint(vector<vector<T>> v) {
    for(auto x :v) {
        REP(i, x.size()-1) {
            cerr << x[i] << " ";
        }
        cerr << x[x.size()-1] <<endl;
    }
}
 
template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}
 
int main(void) {
    int a, b;
    cin >> a >> b;
    if(a < 10 && b < 10) cout << a*b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
import math

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

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

p = 998244353
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0
for i in range(k + 1):
	ans = ans + m * cmb(n - 1, i, p) * pow(m - 1, n - i - 1, p)
print(ans % p)

Measured memory_bytes: 33064
#include <stdio.h>
#include <math.h>

int primecheck(int n){
    int i;
    
    if(n==0||n==1)return 0;

    for(i=2;i<=sqrt(n);i++){
        if(n%i==0)return 0;
    }
    return 1;
}

int main(void){
    int i,n,cnt,sum;
    
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        
        for(i=sum=cnt=0;cnt<n;i++){
            if(primecheck(i)==1){
                cnt++;
                sum+=i;
            }
        }
        printf("%d\n",sum);
    }
    
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	vector<int> cnt(4,0);
	rep(i,n){
		if(s[i]=='N') cnt[0]++;
		else if(s[i]=='S') cnt[1]++;
		else if(s[i]=='W') cnt[2]++;
		else cnt[3]++;
	}
	if((cnt[0] && !cnt[1]) || (!cnt[0] && cnt[1]) || (cnt[2] && !cnt[3]) || (!cnt[2] && cnt[3])){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 3648
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())
    S = readline().strip()
    
    if S.count('-') != 1:
        print('No')
        return
    
    if S.index('-') == A:
        print('Yes')
    else:
        print('No')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi; 
typedef pair<pair<double, double >, double > pii; 

int main(){

    ll N, C;
    cin >> N >> C;

    //入力　チャンネルごと
    vector<priority_queue<pi, vector<pi>, greater<pi > > > input(C);
    for(ll i = 0; i < N; i++){
        ll S, T, C; cin >> S >> T >> C;
        input[C-1].push(make_pair(S-1, T-1));
    }

    //連続して録画できる映像をまとめる
    vector<vector<ll > > memo(C, vector<ll >(100010, 0));
    for(ll i = 0; i < C; i++){
        ll t_1 = 0;
        while(!input[i].empty()){
            ll s = input[i].top().first;
            ll t = input[i].top().second;
            //cout << s << " " << t << endl;
            input[i].pop();
            memo[i][t+1]--;

            if(s <= t_1){
                memo[i][t_1 + 1]++;
            }else{
                memo[i][s]++;
            }

            t_1 = t;
        }
    }


    vector<ll > t_ans(100010, 0);
    for(ll i = 1; i < 100010; i++){
        ll sum = 0;
        for(ll j = 0; j < C; j++){
            sum += memo[j][i];
        }
        sum += t_ans[i-1];
        t_ans[i] = sum;
    }

    //重なりが一番多いところを探す
    ll mx = 0;
    for(ll i = 1; i <100010; i++){
        mx = max(mx, t_ans[i]);
    }

    cout << mx << endl;

}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

  int n;
  cin>>n;
  vi a(n), b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];

  ll c = 0;
  priority_queue<pii> pq;
  rep(i,0,n) pq.push({b[i], i});

  bool good=true;
  while (!pq.empty()) {
    int wtf = pq.top().fst;
    int m = pq.top().snd;
    pq.pop();
    if (b[m] != wtf) continue;
    if (b[m] == a[m]) continue;

    int y=max(a[m],max(b[(m-1+n)%n], b[(m+1)%n]));
    int sum = b[(m-1+n)%n] + b[(m+1)%n];
    int k = ((b[m] - y + sum - 1) / sum);
    b[m] -= k * sum;
    c += k;

    if (b[m] != a[m])
      pq.push({b[m],m});

    //cerr << m << " " << b[m] << endl;
    
    if (b[m] < a[m]) goto fail;
  }

  rep(i,0,n) {
      if (a[i]!=b[i]) {
        good=false;
        if (b[i] < a[i]) goto fail;
      }
    }
  if (good)cout<<c<<endl;
  else cout<<-1<<endl;

  if(good)return 0;
fail:
  cout<<-1<<endl;

}





Measured memory_bytes: 9456
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign


signed main()
{
    Int(n);
    while (n) {
        int ret = 0;
        for (int a = 1; a*a <= n; a++) {
            if (n - a*a == 0) {
                ret++;
            } else {
                for (int b = a; a*a + b*b <= n; b++) {
                    if (n - a*a - b*b == 0) {
                        ret++;
                    } else {
                        for (int c = b; a*a + b*b + c*c <= n; c++) {
                            if (n - a*a - b*b - c*c == 0) {
                                ret++;
                            } else {
                                for (int d = c; a*a + b*b + c*c + d*d <= n; d++) {
                            if (n - a*a - b*b - c*c - d*d == 0) {
                                ret++;
                            }
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << ret << endl;
        cin >> n;
    }

    return 0;
}

Measured memory_bytes: 3116
N = int( input() )
cities = []
for i in range(1, N+1):
    a,b = input().split() 
    b = int(b)
    cities.append([i,a,b])
    
cities = sorted(cities,key = lambda x: x[2])
cities.reverse()
cities = sorted(cities,key = lambda x: x[1])
for i in cities:
    print(i[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, ans = 0;
  string s;
  cin >> n >> s;
  for (int i = '0'; i <= '9'; ++i) {
    for (int j = '0'; j <= '9'; ++j) {
      for (int k = '0'; k <= '9'; ++k) {
        char c = i;
        int flag = 0;
        for (; flag < n; ++flag) {
          if (s[flag] == c) {
            c = j;
            flag++;
            break;
          }
        }
        for (; flag < n; ++flag) {
          if (s[flag] == c) {
            c = k;
            flag++;
            break;
          }
        }
        for (; flag < n; ++flag) {
          if (s[flag] == c) {
            ans++;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)

int main(){
    
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int>::iterator iter;
    rep(i, n) cin >> a[i];

    iter = max_element(a.begin(), a.end());
    size_t index = distance(a.begin(), iter);
    int max = a[index];

    vector<int> a_copy(a);
    a_copy.erase(a_copy.begin() + index);
    int second_max = *max_element(a_copy.begin(), a_copy.end());

    rep(i, n){
        if(i == index){
            cout << second_max << endl;;
        }else{
            cout << max << endl;
        }
    }

    return 0;
}

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

int  main()
{
	int n;
	cin >> n;
	vector<int> s(n);
	int sum = 0;
	int ans;
	rep(i, n)
	{
		cin >> s[i];
		sum += s[i];
	}
	if (sum % 10)
		ans = sum;
	else
	{
		sort(s.begin(), s.end());
		rep(i, n)
		{
			if (s[i] % 10)
			{
				ans = sum - s[i];
				break;
			}
		}
		if (!ans)
			ans = 0;
	}
	cout << ans << endl;
	return (0);
}


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

int main(){
  long long N,sum=1;
  cin >> N;
  vector<long long> A(N);
  for(long long i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  if(A[0]==0){
    cout << 0 << endl;
    return 0;
  }
  for(long long i=N-1;i>=0;i--){
    if(A[i]<=1000000000000000000/sum){
      sum = sum*A[i];
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4032
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int w = 0, a = 0, b = 0;
	std::cin >> w >> a >> b;
	if (std::abs(a-b)<=w) {
		std::cout << 0 << std::endl;
	}
	else {
		std::cout << std::abs(a - b) - w << std::endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
const int mod=1e9;
int main() {
    long long s;
    std::cin>>s;
    if(s%mod==0) {
        printf("0 0 0 %d %lld 0",mod,s/mod);
    }
    else {
        long long t=(s/mod+1)*mod;
        long long r=t-s;
        printf("0 0 %lld %lld %lld %d",t/mod,1LL,r,mod);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(i, c) ((c).find(i) != (c).end())
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define foreach(i, c) for(auto i : c)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watchc(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)

//=========================

#define PI 3.141592653589793

void run_test() {
	double a, b, h, m;
    cin >> a >> b >> h >> m;
    double ah = (h / 12.0 + m / 60. / 12.) * 2 * PI;
    double xh = a * cos(ah);
    double yh = a * sin(ah);
    double am = m / 60.0 * 2 * PI;
    double xm = b * cos(am);
    double ym = b * sin(am);
    cout << fixed << setprecision(10) << sqrt((xh-xm)*(xh-xm)+(yh-ym)*(yh-ym)) << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t;
	//while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	infile = ifstream("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl;
	cerr << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	if(infile.good()) infile.close();
}


Measured memory_bytes: 4164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

bool used[11];
int a[52];
int b[52];
int c[52];
int d[52];
int N,M,Q; 
int ans = 0;
void dfs(int t, vi &perm) {
  if (t == N) {
    int sum = 0;
    rep (i,Q) {
      if (perm[b[i]] - perm[a[i]] == c[i]) sum += d[i];
    } 
    ans = max(ans, sum);
    return ;
  }
  for (int i=perm[t-1]; i<=M; i++) {
    perm[t] = i;
    dfs(t+1, perm);
    perm[t] = INF;
  }
}

int main() {
  cin >>N>>M>>Q;
  rep(i,Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  vi perm(N, INF);
  for (int i=1; i<=M;i++) {
    perm[0] = i;
    dfs(1,perm);
    perm[0] = INF;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    int ans=0;
    rep(i,N){
        if((i+1) % 2 && a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int l = Integer.valueOf(arr01[0]);

        double temp = (double) l / 3;
        double maxdata = Math.pow(temp, 3);

        System.out.println(maxdata);

    }

}


Measured memory_bytes: 21076
#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;
    cin >> n;
    vector <ll> y(n);
    rep(i,n){
        cin >> y[i];
    }
    sort(y.begin(),y.end());
    ll ans=0;

    if(n<=2){
        cout << 0 << endl;
    }
    else{
        rep(i,n){
            rep(j,n){
                rep(k,n){
                    if(i<j and j<k){
                        if(y[k]<(y[i]+y[j])){
                            if(y[k]!=y[i] and y[k]!=y[j] and y[i]!=y[j])
                            ++ans;
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
    

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll K, X;
    cin >> K >> X;
    ll lb = max(-1000000ll, X-K+1);
    ll ub = min(1000000ll, X+K-1);
    for(int i=lb;i<=ub;i++) cout << i << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#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>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
  int n,ans;
  rep(i,5){
    cin >> n;
    if (n==0) ans = i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}



int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1;i<=n;i++) {
        ll y = n/i;
        ans += y*(y+1)*i/2;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
using namespace std;
const int INF = 11111111;
int main(void){
  int n,a,b,c,cost[50][50];
  int t,s,ans;

  for(;;){
    cin >> n;
    if(!n) break;
    int f[15] = {0};
    ans = INF;

    for(int i = 0;i <= 10;i++){
      for(int j = 0;j <= 10;j++){
	if(i == j) cost[i][j] = 0;
	else cost[i][j] = INF;
      }
    }

    for(int i = 0;i < n;i++){
      cin >> a >> b >> c;
      f[a] = f[b] = 1;
      cost[a][b] = cost[b][a] = c;
    }

    for(int i = 0;i <= 10;i++){
      for(int j = 0;j <= 10;j++){
	for(int k = 0;k <= 10;k++){
	  cost[j][k] = min(cost[j][k],cost[j][i] + cost[i][k]);
	}
      }
    }

    for(int i = 0;i <= 10;i++){
      s = 0;
      if(!f[i]) continue;
      for(int j = 0;j <= 10;j++){
	if(!f[j]) continue;
	s += cost[i][j];
      }
      if(s < ans){
	ans = s;
	t = i;
      }
    }

    cout << t << " " << ans << endl;

  }
}


Measured memory_bytes: 1168
package main

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

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	bs := make([]int, m)
	for i := range bs {
		sc.Scan()
		bs[i], _ = strconv.Atoi(sc.Text())
	}

	sbs := make([]int, m+1)
	for i := range bs {
		sbs[i+1] += sbs[i] + bs[i]
	}

	var mi, mc int
	for i := 0; i <= n; i++ {
		ri := k - mi
		if ri < 0 {
			break
		}

		l := 0
		r := m + 1
		for r-l > 1 {
			mid := (l + r) / 2
			if sbs[mid] <= ri {
				l = mid
			} else {
				r = mid
			}
		}
		cnt := i + l
		mc = max(mc, cnt)
		if i < n {
			mi += as[i]
		}
	}
	fmt.Println(mc)
}

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

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

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


Measured memory_bytes: 9600
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 4e5+5;
string s;
int dp[maxn];
int pre[maxn]; 
int num[maxn];
vector<int> v;
int n,k,c;
void dfs(int pos,int dep){
	//cout<<pos<<"  12"<<endl;
	int flag = 0;
	for(int i=0;i<c;i++){
		//cout<<dp[pos-i]<<"  dp"<<endl;
		if(pos-i>0&&s[pos-i-1]=='o'&&pre[pos-i]==0&&pre[pos+1]<=1&&dp[pos-i]==dep){
		//	cout<<pre[pos+1+c]<<endl;
		//	cout<<pos-i<<endl;
			v.push_back(pos-i);
			dfs(pos-i-c-1,dep-1);
			return;
		}
	}
	for(int i=pos;i>=1;i--){
		if(s[i-1]=='o'){
			if(pre[i]==0&&pre[i+c+1]<=1) v.push_back(i);
			int flag = 0;
			for(int j=1;j<=c;j++){
				if((i-j-1)>=0&&s[i-j-1]=='o'&&dp[i-j]==dep){
					break;
				}
				if((i-j-1)>=0&&s[i-j-1]=='o'&&dp[i-j]==dep-1){
					flag = 1;
					break;
				}
			}
			//if(dep==n&&num[dep]!=1) flag=0;
			//cout<<i<<endl;
			//cout<<1111<<endl;
			if(flag&&(v.size()==0||v[v.size()-1]!=i)) v.push_back(i);
			dfs(i-c-1,dep-1);
			return;
		} 
	}
}
int main() {
	
	while(cin>>n>>k>>c){
		memset(dp,0,sizeof(dp));
		memset(pre,0,sizeof(pre));
		memset(num,0,sizeof(num));
		v.clear();
		cin>>s;
	for(int i=1;i<=c;i++){
		if(s[i-1]=='o') {
			dp[i] = 1,num[dp[i]]++;
		//	cout<<num[dp[i]]<<" ";
		}
		else dp[i] = dp[i-1];
		
	}
	
	//cout<<endl;
	for(int i=c+1;i<=n;i++){
		if(s[i-1]=='o')
			dp[i] = dp[i-c-1]+1,num[dp[i]]++;
		else dp[i] = dp[i-1];
		
	} 
	for(int i=1;i<=n+1;i++){
		if(i>1)
			pre[i] = pre[i-1]+(s[i-2]=='o'?1:0);
		if(i>c+1){
			pre[i] = pre[i]-(s[i-c-2]=='o'?1:0);
		}
	}
	for(int i=2;i<=c+10;i++){
		pre[i+n] = pre[i+n-1];
	}
//	for(int i=1;i<=n+c;i++)
//		cout<<pre[i]<<" ";
	if(dp[n]!=k){
		return 0;
		//cout<<11111<<endl;
		//cout<<0<<endl;
		//continue;
	}
	else {
		dfs(n,k);
	}
	if(v.size()==0) {
		return 0;
		//cout<<v.size()<<endl;
		//continue;
	}
	//cout<<1111<<endl;
	sort(v.begin(),v.end());
	//cout<<v.size()<<endl; 
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<"\n";
	}
//break;
	}
	
	return 0;
}



Measured memory_bytes: 26104
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	_ = readLine()
	s := strings.Split(readLine(), "")
	k, _ := strconv.Atoi(readLine())

	match := s[k-1]

	for i := 0; i < len(s); i++ {
		if s[i] != match {
			fmt.Print("*")
		} else {
			fmt.Print(s[i])
		}
	}

	fmt.Println()
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	vi a(n);
	vi b(n);
	zip(i, 0, n) cin >> a[i];
	zip(i, 0, n)  cin >> b[i];
	int ext = 0;
	//map<int, int>m;
	vii v;
	int cnt = 0;
	zip(i, 0, n)
	{
		if (a[i] > b[i])
		{
			ext += (a[i] - b[i]);
			v.pb({a[i] - b[i], i});
			//m[i] = (a[i] - b[i]);
			a[i] = b[i];
			cnt++;
		}
	}
	//int cnt = 0;
	zip(i, 0, n)
	{
		if (a[i] < b[i] && ext >= b[i] - a[i])
		{

			ext -= (b[i] - a[i]);
			a[i] = b[i];
			cnt++;
		}
		else if (a[i] < b[i] && ext < b[i] - a[i])
		{
			cout << -1 << en;
			return 0;
		}
	}
	sort(all(v));
	zip(i, 0, v.size())
	{
		if (ext >= v[i].ff)
		{
			cnt--;
			ext -= v[i].ff;
		}
		else
		{
			break;
		}

	}
	// if (ext > 0)
	// 	cnt++;
	cout << cnt << en;





	return 0;
}



Measured memory_bytes: 2936