akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(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; }


int main(){
    vector<string> hand(3);
    rep(i, 3) cin >> hand[i];

    int turn = 0;
    while(true){
        if(hand[turn].size() == 0)break;
        char card = hand[turn][0]; hand[turn].erase(0, 1);
        turn = card - 'a';
    }
    if(turn==0)cout << 'A' << ln;
    else if(turn==1)cout << 'B' << ln;
    else cout << 'C' << ln;
}

Measured memory_bytes: 3624
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp.array;
  auto k = readln.chomp.to!long;

  if (s.uniq.array.length == 1) {
    writeln(s.length * k /2);
  } else {
    long tmp;
    long cnt = 1;
    foreach (i; 1..s.length) {
      if (s[i-1] == s[i]) {
        cnt++;
      } else {
        tmp += cnt / 2;
        cnt = 1;
      }
    }
    
    tmp += cnt / 2;
    tmp *= k;

    if (s[0] != s[$-1]) {
      tmp.writeln;
    } else {
      long a=1, b=1;
      foreach (i; 1..s.length) {
        if (s[i-1] == s[i]) a++;
        else break;
      }
      foreach_reverse (i; 0..s.length-1) {
        if (s[i+1] == s[i]) b++;
        else break;
      }
      tmp -= (k-1) * (a/2 + b/2 - (a+b)/2);
      tmp.writeln;
    } 
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 200005;
int N;
int S[MAX_N],T[MAX_N];
struct node
{
    int st,ed;
}itv[MAX_N];
bool cmp(node x,node y)
{
     return x.ed<y.ed;
}
int main()
{
    cin>>N;
    for(int i=0;i<N;i++) cin>>S[i]>>T[i];
    for (int i=0;i<N;i++){
        itv[i].st=S[i];
        itv[i].ed=T[i];
    }
    cout<<endl;
    sort(itv,itv+N,cmp);
    //for(int i=0;i<N;i++) cout<<itv[i].st<<" "<<itv[i].ed<<endl;
    int ans=0,t=0;
    for (int i=0;i<N;i++){
        if (t+itv[i].st<=itv[i].ed){
            ans++;
            t+=itv[i].st;
        }
    }
    //cout<<ans<<endl;
    if(ans==N) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3328
def slide(c):
    c = ord(c) + 1
    if c > ord('z'):
        c = ord('a')
    return chr(c)
    
while 1:
    try:
        s = input()
        ans = ""
        while 1:
            if "the" in s or "this" in s or "that" in s:
                print(s)
                break
            for i in range(0,len(s)):
                if ord(s[i]) >= ord('a') and ord(s[i]) <= ord('z'):
                    ans += slide(s[i])
                else:
                    ans += s[i]
            s = ans
            ans = ""
    except:
        break



Measured memory_bytes: 5556
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
    int n;
    int d, min, max;
    long long sum;
    
    scanf("%d%d", &n, &d);
    sum = min = max = d;
    while (--n > 0) {
        scanf("%d", &d);
        if (d < min) min = d;
        if (d > max) max = d;
        sum += d;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2096
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	s := getString()

	switch s {
	case "Sunny":
		out("Cloudy")
	case "Cloudy":
		out("Rainy")
	case "Rainy":
		out("Sunny")
	}
}


Measured memory_bytes: 640
N,A,B = map(int,input().split())
if A + B > N + 1 or A * B < N:
	print(-1)
	exit()
swap = False
if A < B:
	B,A = A,B
	swap = True

base = [i for i in range(1,A+1)]
rest = N - A
roop = (N + A - 1) // A
if roop == B:
	a = A + 1
	pre = []
	while a <= N:
		pre = [i for i in range(a, min(N+1, a+A))] + pre
		a += A
else:
	pre = [i for i in range(A+B-1, A, -1)]
	r = []
	a = A+B
	while a <= N:
	  r = [i for i in range(a, min(N+1, a+A-1))] + r
	  a += A-1
	pre = pre + r
ans = pre + base
if swap:
	ans = [N-i+1 for i in ans]
print(" ".join(map(str, ans)))

Measured memory_bytes: 49908
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5;
ll N,A,B,C,D;
string S;
bool ismv(ll x,ll y){
	return (S[x+1]=='.'&&x+1!=A&&x+1!=B&&x+1<=y)||(S[x+2]=='.'&&x+2!=A&&x+2!=B&&x+2<=y);
}
void mv(ll &x){
	if(S[x+1]=='.'&&x+1!=A&&x+1!=B){
		x++;
	}else{
		x+=2;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>A>>B>>C>>D>>S;
	A--;
	B--;
	C--;
	D--;
	S.push_back('#');
	S.push_back('#');
	while(1){
		if(A==C&&B==D){
			break;
		}else{
			bool af=ismv(A,C),bf=ismv(B,D);
			if(A==C){
				if(bf){
					mv(B);
				}else{
					break;
				}
			}else if(B==D){
				if(af){
					mv(A);
				}else{
					break;
				}
			}else if(C<=D){
				if(bf){
					mv(B);
				}else if(af){
					mv(A);
				}else{
					break;
				}
			}else{
				if(af){
					mv(A);
				}else if(bf){
					mv(B);
				}else{
					break;
				}
			}
		}
	}
	cout<<((A==C&&B==D)?"Yes":"No")<<endl;
			
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    char a[21];
    cin>>a;
    for(int i=0;i<3;i++){
        cout<<a[i];
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
  int main(){
  lint n;
  cin >>n; vector<lint> a(n);
  lint g=1000000000000000000;
  lint ans=1;
  bool x=false;
  rep(i,n){cin >> a[i];
    if(a[i]==0)x=true;
          }
          if(x){
              cout<<0<<endl;
              return 0;
          }
          rep(i,n){
              if(g/a[i]<ans){
                  cout<<-1<<endl;
                  return 0;
              }
              ans*=a[i];
          }
   cout<<ans<<endl;  
  }
      
      
    

  
          
  

Measured memory_bytes: 4056
#include<stdio.h>
int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(n*a<b)
	{
		printf("%d\n",n*a);
	} 
	else
	{
		printf("%d\n",b);
	}
	return 0;
}

Measured memory_bytes: 128
// date: 07.06.20
// author: FlyingSpirit

#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll a,b;
int b1;
char ch;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b>>ch>>b1;
    b=b*100+b1;
    cout<<a*b/100;
    return 0;
}


Measured memory_bytes: 3580
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(; sc.hasNext();){
			int[] c={4, 1, 4, 1, 2, 1, 2, 1};
			int[] p=new int[8];
			for(int i=0; i<8; i++)
				p[i]=sc.nextInt();
			int min=Integer.MAX_VALUE;
			LinkedList<String> list=new LinkedList<String>();
			for(int j=0; j<8; j++){
				int sum=0;
				for(int i=0; i<8; i++)
					sum+=max(c[(i+j)%8]-p[i], 0);
				if(sum<=min){
					if(sum<min)
						list.clear();
					String s="";
					for(int i=0; i<7; i++)
						s+=c[(i+j)%8]+" ";
					s+=c[(7+j)%8];
					list.add(s);
					min=sum;
				}
//				println(sum+"");
			}
//			println("");
			String[] ss=list.toArray(new String[0]);
			sort(ss);
			println(ss[0]);
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001
#define PLUS 0
#define MINUS 1

using namespace std;

bool start[31][NCONS];
bool endt[31][NCONS];
int arr[NCONS];

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N, C; cin >> N >> C;
	for (int i = 0; i < N; i++)
	{
		int s, t, c; cin >> s >> t >> c;
		start[c][s] = true;
		endt[c][t] = true;
	}

	for (int i = 1; i <= C; i++)
	{
		int write = 0;
		for (int j = 0; j < NCONS; j++)
		{
			if (start[i][j]) write = 1;
			arr[j] += write;
			if (endt[i][j] && !start[i][j]) write = 0;
		}
	}



	int ret = 0;
	for (int i = 0; i < NCONS; i++)
		ret = max(ret, arr[i]);
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 6656
function Main(input){
    input = input.split("\n");
    var n = parseInt(input[0],10);

    var aa = 0;flag = true;
    for(var i = 1;i <= n;i++){
        if(input[i] == "A")
            aa++;
        else{
            if(aa == 0){
                flag = false
                break;
            }
            aa--;
        }
   }
   if(flag && aa == 0)
       console.log("YES");
   else
       console.log("NO");
 
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 15492
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	std::string line;	// 文字列の入力行
	std::getline(std::cin, line);
//	if (std::stoi(line.length) != 4)
//		return 1;

	//std::cout << "Line length: " << line.length() << "  String: " << line << "\n";

	//std::cout << line[0] << endl;
	//std::cout << line[1] << endl;
	//std::cout << line[2] << endl;
	//std::cout << line[3] << endl;

	if ((line[0] == line[1]) && (line[1] == line[2]) && (line[2] == line[3])){
		std::cout << "No" << endl;
	}else if ((line[0] == line[1])&&(line[2] == line[3])){
		std::cout << "Yes" << endl;
	}else if((line[0] == line[2]) && (line[1] == line[3])){
		std::cout << "Yes" << endl;
	}else if ((line[0] == line[3]) && (line[1] == line[2])){
		std::cout << "Yes" << endl;
	}else{
		std::cout << "No" << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    int n;
    string ans;
    cin >> n;
    vector<string> s(n);
    vector<vector<int>> num_list(n, vector<int>(26, 0));
    vector<int> ans_list(26);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<s[i].size(); j++){
            int tmp = s[i][j] - 'a';
            num_list[i][tmp]++;
        }
    }

    for(int i=0; i<26; i++){
        int tmp=num_list[0][i];
        for(int j=1; j<n; j++){
            tmp=min(tmp, num_list[j][i]);
        }
        ans_list[i]=tmp;
    }

    for(int i=0; i<26; i++){
        while(ans_list[i]>0){
            char tmp = 'a'+i;
            cout << tmp;
            ans_list[i]--;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
const ll INF = 1LL << 60;

int n;
double dp[3005][3005];
double p[3005];

int main(){
  cin >> n;
  rep(i,n) cin >> p[i];
  
  dp[0][0] = 1.0;
  
  rep(i,n){
    for(int j=0;j <=i;j++){
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1.0-p[i]);
    }
  }
  
  double ans = 0.0;
  for(int i = (n+1)/2; i <= n;i++) ans += dp[n][i];
  
  printf("%.10f",ans);
  return 0;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
int count(vector<int> &a){
  int N = a.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (a[i] == 1){
      ans++;
    }
  }
  return ans;
}
int solve(vector<int> a, vector<int> b){
  int N = a.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (a[i] != b[i]){
      int p = i;
      while (a[i] != b[p]){
        p++;
      }
      for (int j = p - 1; j >= i; j--){
        swap(b[j], b[j + 1]);
        ans++;
      }
    }
  }
  return ans;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b[i];
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++){
    cin >> p[i];
  }
  vector<int> c;
  for (int i = 0; i < M; i++){
    for (int j = 0; j < p[i]; j++){
      c.push_back(i % 2);
    }
  }
  int ans = INF;
  if (count(b) == count(c)){
    ans = min(ans, solve(b, c));
  }
  for (int i = 0; i < N; i++){
    c[i] = 1 - c[i];
  }
  if (count(b) == count(c)){
    ans = min(ans, solve(b, c));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3160
import fractions

A, B, C, D = map(int, input().split())
A -= 1
lcd = C * D // fractions.gcd(C, D)
div_a = A - (A // C + A // D - A // lcd)
div_b = B - (B // C + B // D - B // lcd)
print(div_b - div_a)


Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

i64 partition_count(int n, int m, i64 mod) {
    // divide n (undistinguished) items into m (undistinguished) groups, groups can have 0 items
    vvi dp(m + 1, vi(n + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (j - i >= 0) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % mod;
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    return dp[m][n];
}

int main() {
    int n, k;
    cin >> n >> k;
    cout << partition_count(n, k, MOD) << endl;
}


Measured memory_bytes: 10736
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main
{
    static class Node{
        int b = 0;
        int w = 0;
        List<Integer> child;
    }
    static int subsetSum(int[] arr, int target){
        int n = arr.length;
        int m = target + 1;
        boolean[][] dp = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            if (arr[i] > target) continue;
            dp[i][arr[i]] = true;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (dp[i-1][j]){
                    dp[i][j] = true;
                    if (j + arr[i] <= target){
                        dp[i][j+arr[i]] = true;
                    }
                }
            }
        }
        for (int i = m-1; i >= 0;i--) {
            if (dp[n-1][i]){
                return i;
            }
        }
        return 0;
    }

    static Node[] nodes;
    static int[] X;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc= new Scanner(System.in);
        int N = sc.nextInt();
        nodes = new Node[N];
        X = new int[N];
        for (int i = 0; i < N; i++) {
            nodes[i] = new Node();
            nodes[i].child = new ArrayList<>();
        }
        for (int i = 1; i < N; i++) {
            int par = sc.nextInt();
            nodes[par - 1].child.add(i);
        }
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        System.out.println(recur(0) ? "POSSIBLE": "IMPOSSIBLE");
    }

    public static boolean recur(int nodeIdx){
        Node cur = nodes[nodeIdx];
        if (cur.child == null || cur.child.size() == 0){
            cur.b = 0; cur.w = X[nodeIdx];
            return true;
        }
        for (int i = 0; i < cur.child.size(); i++) {
            if (!recur(cur.child.get(i))) {
                return false;
            }
        }
        int b = 0, w = 0;
        int[] swap = new int[cur.child.size()];
        for (int i = 0; i < cur.child.size(); i++) {
            int black = nodes[cur.child.get(i)].b;
            int white = nodes[cur.child.get(i)].w;
            b += Math.min(white, black);
            w += Math.max(white, black);
            swap[i] = Math.max(white, black) - Math.min(white, black);
        }
        if (b > X[nodeIdx]) {
            return false;
        }
        int sww = subsetSum(swap, X[nodeIdx] - b);
        cur.b = X[nodeIdx];
        cur.w = w - sww;
        return true;
    }

}

Measured memory_bytes: 29564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int r,s,p;
int add(char c){
    if(c == 'r') return p;
    else if(c == 's') return r;
    else return s;
}

int main(){
    int n,k; cin >> n >> k;
    cin >> r >> s >> p;
    string t; cin >> t;
    vector<vector<char>> v(k);
    rep(i,n){
        v[i%k].push_back(t[i]);
    }
    int ans = 0;
    rep(i,k){
        if(v[i].empty()) continue;
        int q = v[i].size();
        int j = 0;
        while(j < q-1){
            if(v[i][j+1] != v[i][j]){
                ans += add(v[i][j]);
                j++;
            }else{
                ans += add(v[i][j]);
                j += 2;
            }
        }
        if(j == q-1) ans += add(v[i][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
h,w = map(int,input().split())
dp=[list(map(int,input().split())) for i in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k])
ans = 0
for i in range(h):
    a = list(map(int,input().split()))
    for j in a:
        if j >= 0:
            ans +=dp[j][1]
print(ans)


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


def solve(D: int, G: int, p: "List[int]", c: "List[int]"):
    ans = 1e9
    for bit in range(2 ** D):
        sum = 0
        rest_max = -1
        num = 0

        for i in range(D):
            if bit & 1 << i:
                sum += (i + 1) * 100 * p[i] + c[i]
                num += p[i]
            else:
                rest_max = i
        
        if sum < G:
            # remain = G - sum
            # need = int(remain / (100 * (rest_max + 1)))
            s1 = 100 * (rest_max + 1)
            need = int((G - sum + s1 - 1) / s1)
            if need >= p[rest_max]:
                continue
            num += need
        ans = min(ans, num)

    print(ans)
    return


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

if __name__ == '__main__':
    main()


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

int n;
long long ans;
string s;
map < pair < string, string >, long long > m;

signed main () {
	cin >> n >> s;
	for (int i = 0; i < (1 << n); ++i) {
		string red, blue;
		for (int j = 0; j < n; ++j) {
			if (i & (1 << j)) 
				red += s[j];
			else 
				blue += s[j];
		}
		reverse(blue.begin(), blue.end());
		++m[make_pair(red, blue)];
	}
	for (int i = 0; i < (1 << n); ++i) {
		string red, blue;
		for (int j = 0; j < n; ++j) {
			if (i & (1 << j)) 
				red += s[n + j];
			else 
				blue += s[n + j];
		}
		reverse(blue.begin(), blue.end());
		ans += m[make_pair(blue, red)];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 60916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String[] strarray = br.readLine().split(" ");
			int n = Integer.parseInt(strarray[0]);
			int m = Integer.parseInt(strarray[1]);

			if(n == 0 && m == 0){
				break;
			}
			
			int current = n - 1;
			
			boolean[] available = new boolean[n];
			Arrays.fill(available, true);
			
			int turn = 0;
			while(turn < n){
				
				int send = 0;
				while(true){
					current = (current + 1)%n;
					if(available[current]){
						send++;
						if(send == m){
							//System.out.println("now "+current);
							available[current] = false;
							turn++;
							break;
						}
					}

				}
			}
			
			System.out.println(current + 1);
		}
	}

}

Measured memory_bytes: 25328
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}

signed main(){
    int n;
    cin>>n;
    init_fact(20000010);
    int Comb=comb(n,n/2);
    int ans=modpow(3,n);
    int beki[20000002];
    beki[0]=1;
    for(int i=1;i<=n+1;i++){
        beki[i]=beki[i-1]*2%mod;
    }
    for(int i=n/2+1;i<=n;i++){
        ans-=comb(n,i)*beki[n-i+1]%mod;
        ans+=mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 236160
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
typedef priority_queue<int> Pque;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

string s, t;
char a[50], b[50];
int n, m;
vector<string> v;

int main(){
    cin >> s;
    cin >> t;

    n = s.size();
    m = t.size();

    for(int k=n-m;k>=0;--k){
        REP(i, n) a[i] = s[i];
        REP(i, m) b[i] = t[i];
        
        for(int l=k;l<(k+m);++l){

            if(a[l] == '?'){
                a[l] = b[l-k];
            } else if (a[l] != b[l-k]){
                break;
            }

            if(l == (k+m-1)){
                REP(i, n){
                    char ans = a[i] != '?' ? a[i] : 'a';
                    cout << ans;
                }
                cout << endl;
                return 0;
            }
        }
    }

    cout << "UNRESTORABLE" << endl;

	return 0;
}

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

int main(void)
{
    int a,b;
    char ch;
    cin>>a>>ch>>b;
    if(ch=='+')
    {
        cout << a+b<<endl;
    }
    else
    {
        cout <<a-b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   int i,j,k=0,m=0,n=0,t,l,e,f,h,q,p,r;

    string s,c,b,a;
    cin>>s;
    t=s.size();

    for(j=s.size()-1,i=0;i<s.size();i++,j--)
    {
        if(s[j]!=s[i])
        {

            cout<<"No"<<endl;
            return 0;
        }
        else
        {

            k++;
        }
    }
        if(k==s.size())
        {

           l=(t-1)/2;

           for(f=l-1,e=0;e<l;e++,f--)
           {
               if(s[f]==s[e])
               {
                   m++;

               }
               else
               {
                   cout<<"No"<<endl;
                   return 0;
               }
           }
        }
               if(m==l)
               {
                   h=(t+3)/2;
                   r=t-h+1;

                   for(q=t-1,p=h-1;p<t;p++,q--)
                   {
                      if(s[q]==s[p])
                          {
                              n++;
                          }
                          else
                            {
                                cout<<"No"<<endl;
                                return 0;
                            }
                   }


                   }

                   if(n==r)
                    {
                        cout<<"Yes"<<endl;
                    }


           }





Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
if n%2==1:
    print(0)
    quit()
tmp=n
waru=10
li=[]
while tmp//waru>0:
    li.append(tmp//waru)
    waru*=5
ans=0
# for i in range(len(li)):
#     ans+=li[i]
print(sum(li))
# print(li)

Measured memory_bytes: 38256
from fractions import gcd

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

if n == 1:
    ans = 1000000000
elif n == 2:
    ans = max(a)
else:
    l = [a[0]]
    for i in range(1, n):
        l.append(gcd(l[-1], a[i]))
    r = [a[-1]]
    for i in range(n - 1, -1, -1):
        r.append(gcd(r[-1], a[i]))
    r = list(reversed(r))
    ans = max(l[-2], r[1])
    for i in range(1, n - 1):
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)

Measured memory_bytes: 93024
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main() 
{
	int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if ((abs(a - c) <= d) || ((abs(a - b) <= d) && (abs(b - c) <= d)))
			printf("Yes");
		else
			printf("No"); 
		return 0; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

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

	ll h, w;
	cin >> h >> w;
	ll a[h + 2][w + 2] , l[h + 2][w + 2]  , u[h + 2][w + 2] , r[h + 2][w + 2] , d[h + 2][w + 2] ;
	for (ll i = 0; i <= h + 1; i++)
	{
		for (ll j = 0; j <= w + 1; j++)
		{
			a[i][j] = 0;
			l[i][j] = 0;
			u[i][j] = 0;
			r[i][j] = 0;
			d[i][j] = 0;
		}
	}
	for (ll i = 1; i <= h; i++)
	{
		string s;
		cin >> s;
		for (ll j = 1; j <= w; j++)
		{
			if (s[j - 1] == '.')
			{
				l[i][j] = l[i][j - 1] + 1;
				u[i][j] = u[i - 1][j] + 1;
			}
			else
				a[i][j] = 1;
		}
	}
	for (ll i = h; i >= 1; i--)
	{
		for (ll j = w; j >= 1; j--)
		{
			if (a[i][j] == 0)
			{
				r[i][j] = r[i][j + 1] + 1;
				d[i][j] = d[i + 1][j] + 1;
			}
		}
	}
	ll ans = 0, mx = 0;
	for (ll i = 1; i <= h; i++)
	{
		for (ll j = 1; j <= w; j++)
		{
			ans = 0;
			if (!a[i][j])
			{
				ans = l[i][j - 1] + r[i][j + 1] + u[i - 1][j] + d[i + 1][j] + 1;
			}
			mx = max(mx, ans);

		}
	}
	cout << mx << endl;
}

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

int SQ(int x) {
  int sq = sqrt(x);
  if (sq * sq == x) {
    return 1;
  }
  else {
    return 0;
  }
}

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      int d2 = 0;
      for (int k = 0; k < D; k++) {
        d2 += (X.at(i).at(k) - X.at(j).at(k)) *  (X.at(i).at(k) - X.at(j).at(k));
      }
      ans += SQ(d2);
    }
  }
  cout << ans << endl;
}


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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 301;

double dp[2][N][N];

void solve()
{
  int n;
    cin >> n;
    
  int a[n];
   f(i,n) cin >> a[i];
    
 dp[0][0][0] = 0;
 
 for(int i=0;i<=n;i++)
     for(int j=0;j<=n;j++)
        for(int k=0;k<=n;k++)
 {
    if(i+j+k>n) continue;
    if(i==0 && j==0 && k==0) continue;
     
    dp[i%2][j][k] = n; 
     
    if(i>0) dp[i%2][j][k]+=(i*dp[(i-1)%2][j+1][k]); 
    if(j>0) dp[i%2][j][k]+=(j*dp[i%2][j-1][k+1]);
    if(k>0) dp[i%2][j][k]+=(k*dp[i%2][j][k-1]); 
    
    dp[i%2][j][k] /=(i+j+k); 
 }
 
 int p[4] = {0};
 
 f(i,n) p[a[i]]++;
    
 cout << fixed << setprecision(9) << dp[p[3]&1][p[2]][p[1]] << '\n';
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	fast;
	int k, x;
	cin>>k>>x;
	for(int i=x-k+1;i<x+k;i++)
		cout<<i<<' ';
	return 0;
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	friend modnum inv(const modnum& m) { return m.inv(); }
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
	friend modnum neg(const modnum& m) { return m.neg(); }

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}

using num = modnum<int(1e9) + 7>;

vector<num> fact, ifact;

void init(){
	int N = 2100000;
	fact = {1};
	for(int i = 1; i < N; i++) fact.push_back(i * fact[i-1]);
	ifact.resize(N);
	ifact.back() = 1 / fact.back();
	for(int i = N - 1; i > 0; i--) ifact[i-1] = i * ifact[i];
}

num ncr(int n, int k){
	if(k < 0 || k > n) return 0;
	return fact[n] * ifact[k] * ifact[n-k];
}

num solve(int a, int b){
	return ncr(a+b+2, a+1) - 1;
}

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	init();
	int r1, r2, c1, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	num ans = solve(r2, c2) - solve(r1-1, c2) - solve(r2, c1-1) + solve(r1-1, c1-1);
	cout << ans << '\n';
}


Measured memory_bytes: 18664
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll ans = INF;
    rep(bit, (1<<n)){
        if(__builtin_popcount(bit)<k) continue;
        ll cnt = 0;
        ll cost = 0;
        ll h_max = -1;
        rep(i,n){
            if(bit & (1<<i)){
                if(a[i]>h_max){
                    h_max = a[i];
                }else{
                    h_max++;
                    cost += (h_max - a[i]);
                }
                cnt++;
            }else{
                h_max = max(h_max, a[i]);
            }

            if(cnt>=k) break;
        }

        ans = min(ans, cost);
    }

    cout << ans << endl;

}
/********  Main() Ends Here *************/


Measured memory_bytes: 3588
n = int(input())
tbl = [[0]*10 for _ in [0]*10]
k = 10
for i in range(1, n+1):
    if i // k: k *= 10
    l = i*10//k
    r = i%10
    tbl[l][r] += 1
    
ans = 0
for l, _t in enumerate(tbl):
    for r, t in enumerate(_t):
        if l == r:
            ans += t*t
        else:
            ans += t*tbl[r][l]
print(ans)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> x(n);
    vector<int> y(n);
    rep(i,n) {
        int t;cin>>t;
        x[i] = t;
        y[i] = t;
    }
    sort(all(y));
    // n/2-1, n/2
    int m1 = y[n/2-1], m2 = y[n/2];
    rep(i,n){
        if(x[i]<=y[n/2-1]){
            cout<<m2<<endl;
        }else{
            cout<<m1<<endl;
        }
    }

}

Measured memory_bytes: 3840
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp0 = input[0].split(" ");
   // tmp1 = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var n = parseInt(tmp0[0], 10);

    var W=[];
    for(i=1;i<=n;i++){tmp = input[i].trim().split("　");
                     //tmp = input[i].split(" ");
                     r=tmp[0];
                    W[i]=r;}
                    W.splice( 0, 1 );
                  var b3 = Array.from(new Set(W));
                   
      if(b3.length!==W.length){console.log('No');
                                      }
       else{
           for(i=1;i<n;i++){ tmp1 = input[i].split(" ");
                       var w1 = tmp1[0];
                       tmp2 = input[i+1].split(" ");
                       var w2 = tmp2[0];
                       if(w1.substr(-1)==w2.substr(0,1)){continue;}
                        else{console.log('No');
                                      break;}
                       // if(i==n-1){console.log('Yes');}
                      }
                      if(i==n){console.log('Yes');}
                    } 
               }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int dp[1005][1005];
int W;
int n;
int v[1005], w[1005];
int now = 1;

int main()
{
	while( 1 ){
		scanf( "%d", &W );
		if( !W ) break;
		scanf( "%d", &n );
		for( int i = 0; i < n; i++ ){
			scanf( "%d,%d",  &v[i], &w[i] );
		}
		
		memset( dp, 0, sizeof( dp ) );
		
		for( int i = 0; i < n; i++ ){
		 	for( int j = 0; j <= W; j++ ){
				if( j < w[i] ){
				 	dp[i+1][j] = dp[i][j];
				}
				else{
				 	dp[i+1][j] = std::max( dp[i][j], dp[i][j-w[i]] + v[i] );
				}
			}
		}
		
		int res = W;
		for( int i = W; i >= 0; i-- ){
			if( dp[n][i] == dp[n][W] ) res = std::min( res, i );
			else break;
		}
		
		printf( "Case %d:\n", now );
		printf( "%d\n", dp[n][W] );
		printf( "%d\n", res );
		
		now++;	
	}
	

 	return 0;
}

Measured memory_bytes: 5148
package main

import(
    "fmt"
)



func main() {
    var c string
    fmt.Scan(&c)
    var ans string
    if c=="a" || c=="i" || c=="u" || c=="e" || c=="o"{
        ans = "vowel"
    } else {
        ans = "consonant"
    }
    fmt.Println(ans)
}





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

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

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<utility>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,m,a[N],dp[N];
bool notok[N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
		cin>>a[i],notok[a[i]]=true;
	dp[0]=dp[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(!notok[i-1])
			dp[i]+=dp[i-1],dp[i]%=1000000007;
		if(!notok[i-2])
			dp[i]+=dp[i-2],dp[i]%=1000000007;
	}
	cout<<dp[n]%1000000007;
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int D;
const int T = 26;      // type no kazu
vector<ll> c(T + 1);   // penalty 1-indexed
vector<vector<ll>> s;  // 1-indexed
vector<set<ll>> days(T + 1);
vector<ll> ans;
ll maxScore = 0;

void readInput() {
  cin >> D;
  REP(i, T) { cin >> c[i + 1]; }
  s = vector<vector<ll>>(D + 1, vector<ll>(T + 1));
  REP(i, D) REP(j, T) { cin >> s[i + 1][j + 1]; }
}

ll calcInitScore(const vector<ll>& t) {
  FOR(i, 1, T + 1) {
    days[i].insert(D + 1);
    days[i].insert(0);
  }

  ll beforeScore = 0;
  FOR(i, 1, D + 1) {
    days[t[i]].insert(i);
    // score gain
    ll afterScore = beforeScore + s[i][t[i]];
    // penalty
    FOR(j, 1, T + 1) { afterScore -= c[j] * (i - *(++days[j].rbegin())); }
    beforeScore = afterScore;
  }
  return beforeScore;
}

int main() {
  readInput();

  vector<ll> sum(T + 1, 0);
  REP(i, T) { sum[i + 1] = sum[i] + c[i + 1]; }

  ans = vector<ll>(D + 1);

  random_device seed_gen;
  mt19937_64 rnd(seed_gen());
  uniform_int_distribution<int> dist_t(1, sum[T]);
  uniform_int_distribution<int> dist_u(1, T);

  vector<ll> t(D + 1);
  // DUMP(sum[T]);
  FOR(i, 1, D + 1) {
    ll num = dist_t(rnd);
    // DUMP(num);
    FOR(j, 1, T + 1) {
      if (j < T && num > sum[j]) {
        continue;
      }
      t[i] = j;
      break;
    }
  }

  ans = t;
  // maxScore = calcInitScore(ans);

  REP(i, D) { cout << ans[i + 1] << endl; }
}

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

int main() {
    string s[110], t[110];
    int N, M;

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

    cin >> M;
    for(int i = 0; i < M; i++) {
        cin >> t[i];
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int score = 0;
        for(int j = 0; j < N; j++) {
            if(s[j] == s[i]) score++;
        }
        for(int j = 0; j < M; j++) {
            if(t[j] == s[i]) score--;
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        int taro_point = 0;
        int hanako_point = 0;
        int card_num = 0;
        int result_comp;

        String[] taro_card,hanako_card;

        Scanner sc= new Scanner( System.in );

        card_num = sc.nextInt();

        taro_card = new String[card_num];
        hanako_card = new String[card_num];

        for ( int i = 0 ; i < card_num ; i++ ) {
            taro_card[i] = sc.next();
            hanako_card[i] = sc.next();
        }

        for ( int i = 0 ; i < card_num ; i++ ) {
            result_comp = 0;
            result_comp = taro_card[i].compareTo(hanako_card[i]);

            if ( result_comp < 0 ) {
                hanako_point += 3;
            }else if ( result_comp == 0 ) {
                taro_point ++;
                hanako_point ++;
            }else if ( result_comp > 0 ) {
                taro_point += 3;
            }

        }
        System.out.println( taro_point + " " + hanako_point );
        sc.close();
    }
}


Measured memory_bytes: 29656
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] array = {"a", "e", "i", "o", "u"};
        List<String> list = Arrays.asList(array);
        String input = sc.next();
        if(list.contains(input)){
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    using P = pair<int, int>;
    vector<vector<P>> to(n);
    rep(i,n-1) {
        int u,v,w;
        cin >>u >> v >> w;
        u--;v--;
        to[u].emplace_back(v,w);
        to[v].emplace_back(u,w);
    }
    vector<bool> seen(n,false);
    vector<bool> w(n,false);
    w[0] = true;
    queue<int> q;
    q.emplace(0);
    while(!q.empty()) {
        int v = q.front();
        seen[v] = true;
        q.pop();
        for(auto next: to[v]) {
            int nv = next.first;
            int dist = next.second;
            if(seen[nv])continue;
            if(w[v] && dist%2 == 0 || !w[v] && dist%2 == 1) {
                w[nv] = true;
            } else {
                w[nv] = false;
            }
            q.emplace(nv);
        }
    }
    rep(i,n) {
        if(w[i]) cout << 0 << endl;
        else cout << 1 << endl;
    }
}


Measured memory_bytes: 9120