akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,k;cin>>n>>k;
    int cnt=0;
    while(n){
        n/=k;
        cnt++;
    }
    cout<<cnt<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1<<29;
int main(){
  
  //入力
  int H; int N;
  cin >> H >> N;
  int A[N]; int B[N];
  for(int i=0;i<N;i++) cin >> A[i] >> B[i];
  
  int DP[H+1]; //min{-i~に必要な魔力}
  DP[0]=0;
  for(int i=1;i<=H;i++){
    int minA=INF;
    for(int j=0;j<N;j++){
      if(i>A[j]){
        minA=min(minA,DP[i-A[j]]+B[j]);
      }
      else{
        minA=min(minA,DP[0]+B[j]);
      }
    }
    DP[i]=minA;
  }
  
  cout << DP[H] << endl;
  
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=100000 ;
///Power
ll  power(ll  i,ll  j)
{
    if(j==0)
    return 1 ;
    ll t=power(i,j/2)%maa ;
    if(j%2==0)
    return (t%maa*t%maa)%maa ;
    else
    return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
}
int main()
{
   fast ;
   ll a,b ;
   cin>>a>>b ;
   ll f=0 ;
   for(ll i=0;i<10;i++)
   {
       ll x=10*b+i ;
       if(((ll)((x*8)/100))==a)
       {
           f=1 ;
           cout<<x<<endl ;
           break ;
       }

   }
   if(f==0)
    cout<<"-1"<<endl ;


}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    int m,f,r;
    while(cin >> m >> f >> r && !(m==-1 && f==-1 && r==-1)){
        if(m==-1 || f==-1) cout << 'F' << endl;
        else if(m+f>=80) cout << 'A' << endl;
        else if(m+f>=65) cout << 'B' << endl;
        else if(m+f>=50) cout << 'C' << endl;
        else if(m+f>=30){
            if(r>=50) cout << 'C' << endl;
            else cout << 'D' << endl;
        }
        else cout << 'F' << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> box(n), seq(n);
  int cnt;
  int zerone;
  int m = 0;
  vector<int> ans;
  for(int i = 0; i < n; ++i) cin >> box[i];
  for(int i = n - 1; i >= 0; --i){
    cnt = 0;
    for(int j = 1; j * (i + 1) <= n; ++j){
      cnt ^= seq[j * (i + 1) - 1];
    }
    zerone = box[i] ^ cnt;
    if(zerone){
      m++;
      ans.push_back(i + 1);
    }
    seq[i] = zerone;
  }
  cout << m << endl;
  if(ans.empty()) return 0;
  for(int i = 0; i < ans.size(); ++i){
    cout << (i ? " " : "") << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;

int main() {
	int n, a, b, p,j=0,k=0,l=0,min;
	scanf("%d\n%d %d", &n, &a,&b);
	rep(i, n) {
		scanf("%d", &p);
		if (p <= a)j++;
		else if (p <= b)k++;
		else l++;
	}
	min = j;
	if (min > k)min = k;
	if (min > l)min = l;
	printf("%d\n", min);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,max_num = -1000001,min_num = 1000001,tmp;
    long long int sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        sum += tmp;
        max_num = max(max_num,tmp);
        min_num = min(min_num,tmp);
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
}


Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    ll k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    vector<int> s;
    vector<int> ord(n+1,-1);
    int c=1,l=0;
    {
        int v=1;
        while(ord[v]==-1){
            ord[v]=s.size();
            s.push_back(v);
            v=a[v-1];
        }
        c=s.size()-ord[v];
        l=ord[v];
    }

    if(k<l) cout<<s[k]<<endl;
    else{
        k-=l;
        k%=c;
        cout<<s[l+k]<<endl;
    }

}



Measured memory_bytes: 5784
package main

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

var sc = bufio.NewScanner(os.Stdin)

func rcv() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := rcv(), rcv()

	bucket := make([]int, n)
	for i := 0; i < m*2; i++ {
		bucket[rcv()-1]++
	}

	for i := 0; i < n; i++ {
		fmt.Println(bucket[i])
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long a,b,c,d,k;
    cin>>a>>b>>c>>d;
    k=max(a*c,b*d);
    k=max(k,a*d);
    k=max(k,b*c);
    cout<<k<<endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s,t;
  cin>>s>>t;
  vector<vector<int>> alp(27,vector<int> (0));
  int num=(int)s.length();
  rep(i,num){
    alp[s[i]-'a'].push_back(i);
  }
  int cnt=0;
  vector<vector<bool>> memo(30,vector<bool> (30,false));
  rep(i,num){
    if(s[i]!=t[i]){
      int c=s[i]-'a';
      int p=t[i]-'a';
      if(memo[c][p])break;
      memo[c][p]=true;
      int buf=alp[c].size();
      int buft=alp[p].size();
      rep(x,buft){
        s[alp[p][x]]=s[i];
      }
      rep(x,buf){
        s[alp[c][x]]=t[i];
      }
      swap(alp[c],alp[p]);
    }
  }
  //cout<<cnt<<endl;
  if(s==t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 1800
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define BUF_SIZE 15
#define PRIME_MAX 100000000

void setbit(char *bitmap, int bits) {
  bitmap[bits >> 3] |= (1 << (bits&7));
}

int getbit(char *bitmap, int bits) {
  return !!(bitmap[bits>>3] & (1 << (bits&7)));
}

void sieve(char *bitmap, int size) {
  int i, j;
  for(i = 2; i <= 10000;) {
    for(j = 2; i*j <= PRIME_MAX; j++) {
      setbit(bitmap, i*j);
    }
    // update i
    for(j = i+1;j <= 20000; j++) {
      if(!getbit(bitmap, j)) {
        i = j;
        break;
      }
    }
  }
}

int main(void) {
  FILE *fp = stdin;
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int queries;
  sscanf(line, "%d", &queries);

  static char bitmap[12500001];
  sieve(bitmap, 12500001);

  int i;
  int cnt = 0;
  for(i = 0; i < queries; i++) {
    if(!fgets(line, BUF_SIZE, fp)) return 0;
    int num;
    sscanf(line, "%d", &num);
    cnt += (!getbit(bitmap, num));
  }

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

  return 0;
}


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

int main(void){
    vector<string> S(3);
    cin>>S[0]>>S[1]>>S[2];
    bool finish = false;
    int turn = 0;;
    while(!finish){
        if (S[turn].size()==0){
            finish = true;
        }
        else {
            int card = (S[turn][0] - 'a');
            S[turn].erase(S[turn].begin());
            turn = card;
        }
    }   
    char ans;
    switch(turn){
        case 0: ans='A'; break;
        case 1: ans='B'; break;
        case 2: ans='C'; break;
        default: break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#include<cmath>
#include<iomanip>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  map<ll, ll, greater<ll>> mp;
  rep(i, n) {
    ll v;
    cin >> v;
    mp[v]++;
  }
  vector<vl> c(52, vl(52, 0));
  rep(i, 52) c[i][0] = 1;
  rep2(i, 1, 52) rep2(j, 1, i + 1) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
  double sum = 0;
  ll cnt = a;
  for(auto v : mp) {
    ll k = v.first;
    ll m = v.second;
    if(cnt > m) {
      cnt -= m;
      sum += k * m;
    } else if(cnt == m) {
      sum += k * cnt;
      printf("%.6f\n", sum / double(a));
      cout << 1 << endl;
      return 0;
    } else if(sum == 0) {
      printf("%.6f\n", double(k));
      ll ans = 0;
      rep2(i, a, min(b + 1, m + 1)) ans += c[m][i];
      cout << ans << endl;
      return 0;
    } else {
      sum += k * cnt;
      printf("%.6f\n", sum / double(a));
      cout << c[m][cnt] << endl;
      return 0;
    }
  }
}

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

 int main() {
   int X, Y, A, B, C;
   cin >> X >> Y >> A >> B >> C;
   vector<int> p(A), q(B), r(C);
   vector<pair<int, int>> pqr;

   rep(i, 0, A) cin >> p.at(i);
   rep(i, 0, B) cin >> q.at(i);
   rep(i, 0, C) {
     cin >> r.at(i);
     pqr.push_back({r.at(i), 2});
   }

   sort(p.begin(), p.end(), greater<int>());
   sort(q.begin(), q.end(), greater<int>());

   rep(i, 0, X) pqr.push_back({p.at(i), 0});
   rep(i, 0, Y) pqr.push_back({q.at(i), 1});

   sort(pqr.begin(), pqr.end(), greater<pair<int, int>>());

   ll ans = 0;

   rep(i, 0, X + Y) ans += pqr.at(i).first;

   cout << ans << endl;
 }


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define ll long long

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<c&&c<b) cout<<"Yes"<<endl;
    else if(b<c&&c<a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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



class Program
{
    const int MOD = 1000000007;
    const int INF = 1 << 30;

    static void Main(string[] args)
    {
        Solve();
    }

    static long GCD(long x, long y)
    {
        if (x == 0) return y;
        if (y == 0) return x;
        return GCD(y, x % y);
    }


    static long LCM(long x, long y)
    {
        return x * y / GCD(x, y);
    }

    static void Solve()
    {
        Scaner sc = new Scaner();
        write wr = new write();

        var A = sc.IntArr;
        

        wr.wri(Math.Max(A[2]-A[0]+A[1],0));


    }
}





class Scaner
{
    public string Str => Console.ReadLine();

    public string[] StrArr => Str.Split(' ');

    public long[] LongArr => StrArr.Select(long.Parse).ToArray();
    public int[] IntArr => StrArr.Select(int.Parse).ToArray();
    public char[] CharArr => Str.ToArray();
    public long Long1 => LongArr[0];
    public int Int1 => IntArr[0];
    
}



class write
{
    public  void wri<T>(T x)
    {
        Console.WriteLine(x);
    }
}



Measured memory_bytes: 13268
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define M_PI 3.14159265358979323846


#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

void setup() {
	ios::sync_with_stdio(0);
	cin.tie(0);
}


int main() {
	setup();
	int r;
	cin >> r;
	cout << 2 * M_PI * r << endl;

}

Measured memory_bytes: 3252
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  long long int n,i;
  cin>>n;
  vector<int> V;
  while(n>0)
  {
    V.push_back(n%26);
    if(n%26==0)
      --n;
    n/=26;
  }
  string d;
  for(i=0;i<V.size();i++)
  {
    if(V[i]==0)
      V[i]=26;
    d+=V[i]+'a'-1;
  }
  reverse(d.begin(),d.end());
  cout<<d;
}
  

Measured memory_bytes: 3628
def main():
    string = input()
    index = int(input())
    for i in range(len(string)):
        if not string[i] == "1":
            if i > index - 1:
                print("1")
            else:
                print(string[i])
            break
    else:
        # string = "11111...111"のとき
        print("1")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <stdio.h>
#define N 100000

int main(void) {

    int i, n;
    int number[N];
    char ch;

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

    i = 0;
    while (1) {
        while (1) {
            scanf("%c", &ch);
            if (ch == '\n') {
                break;
            } else {
                number[i] += ch - 48;
            }
        }
        if (number[i] == 0) {
            break;
        } else {
            i++;
        }
    }
    n = i;

    for (i = 0; i < n; i++) {
        printf("%d\n", number[i]);
    }

    return 0;

}

Measured memory_bytes: 928
import java.util.Scanner;

public class Main {
  static int a, b;
  static char op;

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

    a = sc.nextInt();
    op = sc.next().charAt(0);
    b = sc.nextInt();

    int ans = 0;
    if(op == '+'){
      ans = a + b;
    }
    else{
      ans = a - b;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 9684
class UnionFind():
    # 負の値はルートで集合の個数
    # 正の値は次の要素を返す
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        while self.table[x] >= 0:
            # 根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x

    # 併合
    def union(self, x, y):
        s1 = self.find(x)  # 根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:  # 根が異なる場合
            if self.table[s1] != self.table[s2]:  # グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                # グラフの長さが同じ場合,どちらを根にしても変わらない
                # その際,グラフが1長くなることを考慮する
                self.table[s1] += -1
                self.table[s2] = s1
        return


h, w = [int(i) for i in input().split()]
s = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s[i] = list(input())

union = UnionFind(h * w)

for i in range(h):
    for j in range(w):
        if i > 0 and s[i][j] != s[i - 1][j]:
            union.union(w * i + j, w * (i - 1) + j)
        if j > 0 and s[i][j] != s[i][j - 1]:
            union.union(w * i + j, w * i + (j - 1))
out = [[0, 0] for _ in range(h * w)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            out[union.find(w * i + j)][0] += 1
        else:
            out[union.find(w * i + j)][1] += 1
count = 0
for _out in out:
    count += _out[0] * _out[1]
print(count)

Measured memory_bytes: 23688
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]


n = int(input())
s = [input() for _ in range(n)]


h = {}

for i in range(n):
    if (s[i] in h):
        h[s[i]] += 1
    else:
        h[s[i]] = 1


ans = []
highScore = max(h.values())

for k,v in h.items():
    if v== highScore:
        ans.append(k)

ans.sort()

for i in range(len(ans)):
    print(ans[i])




Measured memory_bytes: 38508
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-6-10 21:11:33
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, C;
ll D[40][40];
ll c[510][510];
ll total[3][40];

int main()
{
  cin >> N >> C;
  for (auto i = 0; i < C; i++)
  {
    for (auto j = 0; j < C; j++)
    {
      cin >> D[i][j];
    }
  }
  for (auto i = 0; i < N; i++)
  {
    for (auto j = 0; j < N; j++)
    {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  fill(&total[0][0], &total[0][0] + 3 * 40, 0);
  for (auto i = 0; i < C; i++)
  {
    for (auto x = 0; x < N; x++)
    {
      for (auto y = 0; y < N; y++)
      {
        total[(x + y) % 3][i] += D[c[x][y]][i];
      }
    }
  }
  ll ans = 100000009907;
  for (auto i = 0; i < C; i++)
  {
    for (auto j = 0; j < C; j++)
    {
      if (i == j)
        continue;
      for (auto k = 0; k < C; k++)
      {
        if (i == k || j == k)
          continue;
        ll sum = 0;
        sum = total[0][i] + total[1][j] + total[2][k];
        ans = min(ans, sum);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2304
import java.util.*;
class Main{
    public static void main(String[] args) {
        //入力
        Scanner scn=new Scanner(System.in);
        String tile=scn.next();
        //処理
        int[] cnt=new int[2];
        for(int i=0;i<2;i++){
            cnt[i]=0;
            for(int j=0;j<tile.length();j++){
                if(j%2==0&&Character.getNumericValue(tile.charAt(j))==i) cnt[i]++;
                
                if(j%2==1&Character.getNumericValue(tile.charAt(j))!=i) cnt[i]++;
                
            }
        }
       //出力
        System.out.println(Math.min(cnt[0],cnt[1]));
    }
}


Measured memory_bytes: 27220
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


// pn + r (n は非負整数) で表せる整数のうち、x 以上となる最小の整数
long long amari_lower_bound(long long p, long long r, long long x) {
    if (r >= x) return r;
    return (x - r + p-1) / p * p + r;
}



long long N, K;

// K 以上
long long solve() {
    long long res = 0;
    for (long long b = K+1; b <= N; ++b) {
        long long amari = N % b;
        long long q = N / b;
        long long tmp = 0;
        if (amari < K) tmp += q * (b-K);
        else tmp += q * (b-K) + (amari - K + 1);
        if (K == 0) --tmp;
        res += tmp;

        // cout << b << ": " << amari << ", " << q << ", " << tmp << endl;
    }
    return res;
}

int main() {
    while (cin >> N >> K) {
        cout << solve() << endl;
    }
}


Measured memory_bytes: 256
import java.io.*;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true)
		{
			String[] str = br.readLine().split(" ");
			int H = Integer.parseInt(str[0]);
			int W = Integer.parseInt(str[1]);
			if(H==0 && W==0)	break;
			char a = '#', b = '#', c = '.';
			for(int i=1; i<=H; i++)
			{
				if(i%2==1)
				{
					a = b;
				}else if(i%2==0)
				{
					a = c;
				}
				for(int j=1; j<=W; j++)
				{
					System.out.print(a);
					if(a==b)		a = c;
					else if(a==c)	a = b;
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("input.txt","w",stdout);

    int i,m,n,x;
    cin >> n >> m;
    PQ<int>pq;
    for(i=0; i<n; i++)
    {
        cin >> x;
        pq.PS(x);
    }
    while(m--)
    {
        x=pq.T;
        if(x == 0)
            break;
        pq.PP;
        pq.PS(x/2);
    }
    LL ans=0;
    while(!pq.EM)
    {
        ans+=pq.T;
        pq.PP;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 892
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define SIZE 200005

using namespace std;
typedef long long ll;

ll a[SIZE], n;

ll diff(ll m1, ll i, ll m2) {
	ll p, q, r, s;
	p = a[m1] - a[0];
	q = a[i] - a[m1];
	r = a[m2] - a[i];
	s = a[n] - a[m2];
	//cout << m1 << " " << i << " " << m2 << endl;
	//cout << i << ": " << p << " " << q << " " << r << " " << s << endl;
	return (max(max(p, q), max(r, s)) - min(min(p, q), min(r, s)));
}

int main() {
	ll ans = INF, l, r, x, y, m1, m2, dx, dy;

	a[0] = 0;

	cin >> n;
	REP(i, n) cin >> a[i + 1];

	for (int i = 1; i <= n; i++) a[i] += a[i - 1];

	for (int i = 2; i <= n - 1; i++) {
		// debug(i);
		l = 1;
		r = i - 1;
		x = (r + 2 * l) / 3;
		y = ((2 * r + l) + 2) / 3;
		m1 = l;
		while (y - x > 0) {
			// debug(l);
			// debug(r);
			dx = abs((a[x] - a[0]) - (a[i] - a[x]));
			dy = abs((a[y] - a[0]) - (a[i] - a[y]));
			// debug(dx);
			// debug(dy);
			//			if (d0>d) break;
			//			else d0 = d;

			m1 = (dx < dy) ? x : y;
			// debug(m1);
			if (dx >= dy) {
				if (l == x) x++;
				l = x;
			} else {
				if (r == y) y--;
				r = y;
			}
			x = (r + 2 * l) / 3;
			y = ((2 * r + l) + 2) / 3;
		}
		// debug(x);
		// debug(y);

		l = i + 1;
		r = n - 1;
		x = (r + 2 * l) / 3;
		y = ((2 * r + l) + 2) / 3;
		m2 = l;
		while (y - x > 0) {
			// debug(l);
			// debug(r);
			dx = abs((a[x] - a[i]) - (a[n] - a[x]));
			dy = abs((a[y] - a[i]) - (a[n] - a[y]));
			// debug(dx);
			// debug(dy);
			
			m2 = (dx < dy) ? x : y;
			// debug(m2);

			if (dx >= dy) {
				if (l == x) x++;
				l = x;
			} else {
				if (r == y) y--;
				r = y;
			}
			x = (r + 2 * l) / 3;
			y = ((2 * r + l) + 2) / 3;
		}
		// debug(x);
		// debug(y);
		// debug(diff(m1, i, m2));
		ans = min(ans, diff(m1, i, m2));
		// debug(ans);
		//cerr << "--------------------" << endl;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <array>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using lint = long long int;
using ldouble = long double;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T ndvec(T v) { return v; }

template <class T, class... Ts>
auto ndvec(size_t l, Ts... ts) {
    return std::vector<decltype(ndvec<T>(ts...))>(l, ndvec<T>(ts...));
}

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    int precision;
    explicit Fout(int precision) : precision(precision) {}
};

std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}

/* ----- Constants ----- */
// constexpr int INF = std::numeric_limits<int>::max() / 3;
// constexpr int MOD = 1000000007;
// const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    std::string s;
    std::cin >> s;
    int n = s.length() + 1;

    std::vector<lint> ans(n, -1);
    std::function<lint(int)> dfs =
        [&](int i) {
            if (ans[i] != -1) return ans[i];

            auto& ret = ans[i];
            ret = 0;
            if (i > 0 && s[i - 1] == '<') {
                ret = std::max(ret, dfs(i - 1) + 1);
            }
            if (i < n - 1 && s[i] == '>') {
                ret = std::max(ret, dfs(i + 1) + 1);
            }
            return ret;
        };

    lint sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += dfs(i);
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 51588
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 12
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextString(scanner)
	bb := strings.Split(b, ".")
	i, _ := strconv.ParseInt(bb[0], 10, 64)
	ans := a * i
	if len(bb) == 2 {
		ans += a * strtoi(bb[1]) / 100
	}

	fmt.Fprintln(writer, ans)
}

func strtoi(s string) int64 {
	a := int64(10)
	ans := int64(0)
	for i := 0; i < len(s); i++ {
		ans += a * int64(s[i]-'0')
		a /= 10
	}
	return ans
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    string s;
    cin >> n >> s;
    unordered_map<int, int> cnt;
    for(char c: s)
        cnt[c] += 1;
    ll mod = 1e9 + 7;
    ll ans = 1;
    for(auto p: cnt) {
        ans *= (p.second+1);
        ans %= mod;
    }
    ans = (ans - 1 + mod) % mod;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1100
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i,j;
    int n;
    int a, b;
    char* pat;
    int pass = 0, bcount = 1;

    scanf("%d %d %d", &n, &a, &b);

    pat = (char*)malloc(sizeof(char) * (n+1));
    scanf("%s", pat);

    for(i=0;i<n;i++){
        if(*(pat + i) == 'a'){
            if(pass < a+b){
                 printf("Yes\n");
                 pass++;
            }else{
                printf("No\n");
            }
        }else if(*(pat + i) == 'b'){
            if(pass < a+b && bcount <= b){
                printf("Yes\n");
                pass++;
                bcount++;
            }else{
                printf("No\n");
            }
        }else{
            printf("No\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>

int main(void)
{
    int data[11][11];
    int n;
    
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i <= n; i++){
            for (int j = 0; j <= n; j++){
                data[i][j] = 0;
            }
        }
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                scanf("%d", &data[i][j]);
                data[i][n] += data[i][j];
                data[n][j] += data[i][j];
                data[n][n] += data[i][j];
            }
        }
        
        for (int i = 0; i <= n; i++){
            for (int j = 0; j <= n; j++){
                printf("%5d", data[i][j]);
            }
            printf("\n");
        }
        
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;

int n;

int main(){
	cin >> n;
	int h,m,s;
	h = n/3600;
	m = (n - h * 3600) / 60;
	s = n%60;
	cout << h << ":" << m << ":" << s << endl;

	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    int A[n];
    float sum = 0;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        sum += A[i];
    }
    int counter = 0;
    for(int i = 0; i < n; i++){
        if(A[i] >= sum / (4 * m)){
            counter += 1;
        }
    }
    if(counter >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = s()
N = len(S)
ans = 0
for i in range(1,N-1,2):
    a = S[:i+1]
    if a[:(i+1)//2] == a[(i+1)//2:]:
        ans = i+1
print(ans)

Measured memory_bytes: 9972
from collections import deque

class Graph():  #directed
    def __init__(self, n, edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.rev = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]].append(e[1])
            self.rev[e[1]].append(e[0])
            self.deg[e[1]] += 1

    def strongry_connected(self):
        group = [None for _ in range(self.n)]
        used = [0 for _ in range(self.n)]
        order = []
        for s in range(self.n):
            if not used[s]:
                stack = [s]
                used[s] = 1
                while stack:
                    node = stack.pop()
                    movable = False
                    for adj in self.graph[node]:
                        if not used[adj]:
                            movable = True
                            used[adj] = 1
                            stack.append(node)
                            stack.append(adj)
                            break
                    if not movable:
                        order.append(node)
        used = [0 for _ in range(self.n)]
        count = 0
        for s in order[::-1]:
            if not used[s]:
                stack = [s]
                group[s] = count
                while stack:
                    node = stack.pop()
                    used[node] = 1
                    for adj in self.rev[node]:
                        if not used[adj]:
                            group[adj] = count
                            stack.append(adj)
                count += 1
        return group, count

    def topological_sort(self):
        res = [i for i in range(self.n) if self.deg[i] == 0]
        queue = deque(res)
        while queue:
            node = queue.popleft()
            for adj in self.graph[node]:
                self.deg[adj] -= 1
                if self.deg[adj] == 0:
                    queue.append(adj)
                    res.append(adj)
        return res

def simplify(edge):
    res = []
    for e in edge:
        if e[0] == e[1]:
            continue
        res.append(e)
    return tuple(set(res))

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(M)]

edge = simplify(edge)

g = Graph(N, edge)
group, count = g.strongry_connected() #node_to_group
group_to_node = [[] for _ in range(count)]

for i in range(N):
    group_to_node[group[i]].append(i)

new_edge = []

for a, b in edge:
    new_edge.append((group[a], group[b]))

new_edge = simplify(new_edge)

new_g = Graph(count, new_edge)
ts = new_g.topological_sort()

res = [[] for _ in range(count)]

for i in range(count):
    res[i].append(len(group_to_node[ts[i]]))
    res[i].extend(group_to_node[ts[i]])

print(count)
print('\n'.join(map(lambda x: ' '.join(map(str, x)), res)))

Measured memory_bytes: 531976
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    cout << b*(t/a) << endl;
    return 0;
}


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

#define mp              make_pair
#define pb              push_back
#define ff              first
#define ss              second
#define inc(A,B)        A=(A+(B))%MOD
#define mul(A,B)        (ll(A)*ll(B)%ll(MOD))
#define sub(a,b)        (((a)-(b)+MOD)%MOD)

typedef pair < int ,int > pii;
typedef long long ll;
typedef complex < ll > pt;

const int MAX_N = 100005;
const int MOD = 1e9 + 7;

int n, maxi;
int arr[MAX_N];

bool can ( int val ) {
  bool passOne = false;
  int firstVal = val;
  for ( int i = 0; i < n; ++i ) {
    if ( arr[i] == firstVal and !passOne ) {
      passOne = true;
      continue;
    }
    if ( arr[i] <= 2*val )
      val += arr[i];
    if ( 2*val >= maxi )
      return true;
  }
  return false;
}

int binSearch () {
  int fr = 0, to = n-1, mid;
  while ( fr < to ) {
    mid = (fr+to) / 2;
    if ( can ( arr[mid] ) )
      to = mid;
    else
      fr = mid+1;
  }
  return fr;
}

int main() {

//  freopen ( "in.txt" , "r" , stdin );
//  freopen ( "out.txt" , "w" , stdout );

  scanf ( "%d", &n );
  for ( int i = 0; i < n; ++i )
    scanf ( "%d", arr+i );

  sort ( arr, arr+n );
  maxi = arr[n-1];

  printf ( "%d\n", n-binSearch () );

  return 0;

}


Measured memory_bytes: 640
def discomfort(p):
    if p%q == 0:
        ans.append(str(p/q))
        print ''.join(ans[1:])
    else:
        ans.append(str(p/q))
        r = str(p-q*(p/q))
        if not r in r_lis:
            r_lis.append(r)
            if discomfort(int(r+'0')): return True
        else:
            i = 0
            for index, v in enumerate(r_lis):
                if r == v:
                    i = index
            print ''.join(ans[1:])
            print ' '*len(ans[1:i+1])+'^'*(len(ans[i+1:]))
            return True

while True:
    try:
        p, q = map(int, raw_input().split(' '))
        ans = []
        r_lis = []
        discomfort(p)
    except EOFError:
        break

Measured memory_bytes: 4276
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    v = [tuple() for _ in range(N + 1)]
    v[N] = (A[N], A[N])

    if A[0] != 0:
        if A[0] == 1 and N == 0:
            print(1)
            exit()
        else:
            print(-1)
            exit()
    if N == 0:
        print(1)
        exit()

    for i in range(N - 1, -1, -1):
        low, up = v[i + 1][0], v[i + 1][1]
        up = min(2 ** i, up + A[i])
        if low % 2 == 0:
            low = low // 2 + A[i]
        else:
            low = low // 2 + A[i] + 1
        v[i] = (low, up)

    # print(v)
    for i in range(N):
        low, up = v[i][0], v[i][1]
        low = max(v[i + 1][0], low - A[i])
        up = min(v[i + 1][1], (up - A[i]) * 2)
        v[i + 1] = (low, up)

    ans = 0
    for i in range(N + 1):
        if v[i][0] > v[i][1]:
            print('-1')
            exit()
        ans += v[i][1]

    # print(v)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 671980
#define    ll           long long
#define    dn           double
#define    mp           make_pair
#define    pb           push_back
#define    se           second
#define    fi           first
#define    mod          1000000007
#define    sob(v)       v.begin(),v.end()
#define    sobr(v)      v.rbegin(),v.rend()
#define    fr(i,a,b)    for(int i=a;i<=b;++i)
#define    frr(i,a,b)   for(int i=a;i>=b;--i)
#define    pi           acos(-1.00)
#define    check        cout<<"*"<<endl
#define    ffix(x)      cout<<fixed<<setprecision(x)
#define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#include<bits/stdc++.h>
#include<string.h>
using namespace std;

typedef vector<int> vi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<int,vi> pp;

int dr[8]= {0,0,-1,1,-1,-1,+1,+1};
int dc[8]= {-1,1,0,0,-1,+1,-1,+1};

const int N=1000005;

inline void normal(ll &a){if(a>mod) a%=mod; (a<0) && (a+=mod);}
inline ll mod_mul(ll a,ll b){normal(a),normal(b); return (a*b)%mod;}
inline ll mod_add(ll a,ll b){normal(a),normal(b); return (a+b)%mod;}
inline ll mod_sub(ll a,ll b){normal(a),normal(b); a-=b; normal(a); return a;}
inline ll mod_pow(ll a,ll b){ll r=1; while(b>0){if(b&1)r=mod_mul(r,a); a=mod_mul(a,a); b>>=1;} return r;}
inline ll mod_inverse(ll a){return mod_pow(a,mod-2);}
inline ll mod_div(ll a,ll b){return mod_mul(a,mod_inverse(b));}

int main()
{
    string s,t;
    cin>>s>>t;
    int n1=s.size();
    int n2=t.size();
    int mini=200000;
    fr(i,0,n1-n2)
    {
        int cnt=0;
        fr(j,0,n2-1)
        {
            if(s[i+j]!=t[j])cnt++;
        }
        mini=min(mini,cnt);
    }
    cout<<mini<<endl;
}


Measured memory_bytes: 3620
import java.util.*;
import static java.lang.System.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if((a + b == c) || (a + c == b) ){
             out.println("Yes");
        }else if(b + c == a){
            out.println("Yes");
        }else{
            out.println("No");
        }

    }
}

Measured memory_bytes: 35312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, M;
    cin >> N >> M;
    if ((N >= 2) && (M >= 2))
        cout << (N - 2) * (M - 2) << endl;
    else if (N * M > 1)
    {
        cout << N * M - 2 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 384
A,V = map(int, input().split())

B,W = map(int, input().split())

T=int(input())

kyori=abs(B-A)
idousa=V-W

if idousa>0:
  if T>=kyori/idousa:
    print("YES")
  else:
    print("NO")
else:
  print("NO")


Measured memory_bytes: 9116
import sys
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

NUM = 20005

table = [""]*NUM


while True:

    T = str(input())
    if T == '-':
        break

    left = 0
    right = 0
    #長い配列にパターン文字列を転記
    for i in range(len(T)):
        # print(T[right])
        table[left+right] = T[right]
        right += 1

    num_suffle = int(input())

    for loop in range(num_suffle):
        pick_num = int(input())
        #先頭からpick_num文字を末尾に転記し、論理削除
        for i in range(pick_num):
            table[right+i] = table[left+i]
        left += pick_num
        right += pick_num

    for i in range(left,right):
        print("%s"%(table[i]),end = "")
    print()


Measured memory_bytes: 5740
from itertools import permutations

n = int(input())
s = input()

out = 0
ans = s.count("R")*s.count("G")*s.count("B")

combi = list(permutations(["R","G","B"],3))

for i in range(1,n):
    for j in range(n-i*2):
        if (s[j], s[j+i], s[j+i*2]) in combi:
            ans -= 1

print(ans)

Measured memory_bytes: 8940
n, k = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)
used = Hash.new(false)
res = - 10 ** 22

n.times do |cur|
  if used[cur]
    next
  end

  cyc = []
  while !used[cur]
    used[cur] = true
    cyc << c[cur]
    cur = p[cur] - 1
  end

  l = cyc.size
  dp = [0]
  ct = Array.new(l, 0)

  l.times do |w|
    ctm = - 10 ** 22
    l.times do |i|
      ct[i] += cyc[(i + w) % l]
      ctm = ct[i] if ct[i] > ctm
    end
    dp << ctm
  end

  if k <= l
    resm = dp[1..k].max
  elsif dp[-1] <= 0
    resm = dp[1..l].max
  else
    resm = dp[-1] * ((k - 1) / l) + dp[1..((k - 1) % l + 1)].max
  end
  res = resm if resm > res
end
puts res

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
	cin >> n;
	vector<vector<int> > p(n, vector<int>(n, -1));
	rep (i, n) {
	  int a;
	  cin >> a;
	  rep (j, a) {
		int x, y;
		cin >> x >> y;
		p[i][x - 1] = y;
	  }
	}
	int res = 0;
	rep (bit, 1 << n) {
	  vector<int> honest(n);
	  int cnt = 0;
	  rep (i, n) {
		if (bit & (1 << i)) {
		  honest[i] = 1;
		  cnt++;
		}
	  }
	  bool ok = true;
	  rep (i, n) {
		if (!honest[i]) continue;
		rep (j, n) {
		  if ((honest[j] && p[i][j] == 0) || (!honest[j] && p[i][j] == 1)) ok = false;
		}
	  }
	  if (ok) res = max(res, cnt);
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3644