akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(int i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main() {
    int n; cin>>n;
    vector<int> s(n); REP(i,n) cin>>s[i];
    int q; cin>>q;
    vector<int> t(q); REP(i,q) cin>>t[i];

    int cnt=0;
    REP(i,q){
        int ng = -1;
        int ok = (int)s.size();

        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (s[mid]>=t[i]) ok = mid;
            else ng = mid;
        }
        if(s[ok]==t[i]) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll T, X;
  cin >> T >> X;

  cout << fixed << setprecision(10) << (double)T / (double)X << "\n";
  
  return 0;
}


Measured memory_bytes: 3792
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
H, W = map(int, input().split())
S = []
for h in range(H):
    Sh = list(input())
    S.append(Sh)
G = [[0 for _ in range(H*W)] for _ in range(H*W)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            if h > 0 and S[h-1][w] == '.':
                G[h * W + w][(h - 1) * W + w] = 1
                G[(h - 1) * W + w][h * W + w] = 1
            if w > 0 and S[h][w-1] == '.':
                G[h * W + w][h * W + (w - 1)] = 1
                G[h * W + (w - 1)][h * W + w] = 1
            if h < H - 1 and S[h+1][w] == '.':
                G[h * W + w][(h + 1) * W + w] = 1
                G[(h + 1) * W + w][h * W + w] = 1
            if w < W - 1 and S[h][w+1] == '.':
                G[h * W + w][h * W + (w + 1)] = 1
                G[h * W + (w + 1)][h * W + w] = 1
graph = csr_matrix(G)
dist_matrix = floyd_warshall(csgraph=graph, directed=False)
max_dist = 0
for i in range(H * W):
    for j in range(H * W):
        d = dist_matrix[i][j]
        if d != np.inf and d > max_dist:
            max_dist = d
print(int(max_dist))


Measured memory_bytes: 20008
#include<bits/stdc++.h>
using namespace std;
long long a,b,ans;
void dfs(long long n)
{
	if(n<=a)
	{
		long long x=n,a3=0,a5=0,a7=0;
		while(x)
		{
			if(x%10==3)a3=1;
			if(x%10==5)a5=1;
			if(x%10==7)a7=1;
			x/=10;
		}
		if(a3&&a5&&a7)ans++;
	}
	else return;
	dfs(n*10+3);
	dfs(n*10+5);
	dfs(n*10+7);
}
int main()
{
	cin>>a;
	dfs(3);dfs(7);dfs(5);
	cout<<ans<<endl;
}

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


int main()
{

    long long int n;
    cin>>n;
    long long int arr[n],ans=0,b,t;

    for(t=0;t<n;t++){
        cin>>arr[t];
        arr[t]=arr[t]-t-1;
    }


    sort(arr,arr+n);

    b= arr[n/2];

    //cout<<b;

    for(t=0;t<n;t++){
        ans+=abs(arr[t]-b);
    }

    cout<<ans;





    return 0;
}


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

int main(void)
{
    int A, B;
    cin >> A >> B;
    int x = 1;
    int i = 0;
    while(x < B){
        x = x - 1 + A;
        i++ ;
    }
    printf("%d\n", i);

}

Measured memory_bytes: 3668
// a

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    // 単発入力
    string S;
    string T;
    string U;
    int A,B;

    cin >> S;
    cin >> T;
    cin >> A >> B;
    cin >> U;

    // cout << S << endl;
    // cout << T << endl;
    // cout << A << endl;
    // cout << B << endl;
    // cout << U << endl;

    int a = A;
    if (!S.compare(U)) A--;

    if (!T.compare(U)) B--;

    cout << A << ' ' << B << endl;

    return 0;
}



Measured memory_bytes: 256
while data = gets
  a, b, c, d, e, f = data.split.map(&:to_f)
  x = (c*e - f*b)/(a*e - b*d)
  y = (f*a - c*d)/(a*e - b*d)
  puts sprintf("%.3f %.3f", x + 0.0, y + 0.0)
end

Measured memory_bytes: 8612
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	long long a, b, k;

	scanf("%lld %lld %lld", &a, &b, &k);

	long long subt;
	subt = a < k ? a : k;
	a -= subt;
	k -= subt;
	subt = b < k ? b : k;
	b -= subt;
	k -= subt;

	printf("%lld %lld\n", a, b);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
#define ULL unsigned long long
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;

int main()
{
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if ((int)(log10(i)) % 2 == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int x;
  cin >> x;

  if(x == 1){cout << 1 << endl;return 0;}

  for(int i = x;x > 0 ;i--)
  {
    // i がべき乗数か調べる
    for(int j = 2;j < sqrt(i) + 1;j++)
    {
      // iを割れるやつがあったら、割りまくってみる
      if(i % j == 0)
      {
        int b = i;
        bool chk = true;
        for(int k = 1;k <= 10;k++)
        {
          // 割まくれるか？
          if(b == j)
          {
            break;
          }
          else if(b % j != 0)
          {
            chk = false;
            break;
          }
          else
          {
            b /= j;
          }
        }
        if(chk)
        {
          cout << i << endl;
          return 0;
        }
      }
    }
  }


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
M=10**9+7
V="AGC"
Swap=[[0,1,2,3],[1,0,2,3],[0,2,1,3],[0,1,3,2]]

n=gets.to_i
dp=Hash.new(0)
[?A,?G,?C,?D].repeated_permutation(2){|perm|
  dp[?.+perm.join]=1
}

(n-2).times{
  _dp=Hash.new(0)
  [?A,?G,?C,?D].each{|c|
    dp.each{|k,v|
      str=k+c
      key=str[1..3]
      strs=Swap.map{|perm|perm.map{|i|str[i]}.join}
      unless strs.any?{|s|s.index V}
        _dp[key]=(_dp[key]+v)%M
      end
    }
  }
  dp=_dp
}

puts dp.values.inject(:+)%M

Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long dfs(int K,const vector<vector<int>> &g, int now,int from){
    int num;
    if (from == -1) num = K-1;
    else num = K-2;

    if (K < g[now].size()) return 0;

    long long cnt = 1;
    for (auto i : g[now]){
        if (i == from) continue;
        cnt *= num;
        num--;
        cnt %= MOD;
    }
    for (auto i : g[now]){
        if (i == from) continue;
        cnt *= dfs(K,g,i,now);
        cnt %= MOD;
    }
    return cnt;
}

int main(){
    int N,K; cin >> N >> K;
    vector<vector<int> > g(N);
    
    for (int i = 0; i < N-1; i++){
        int a,b; cin >> a >> b; a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << K*dfs(K,g,0,-1)%MOD << endl;
}

Measured memory_bytes: 11520
#include <cstdio>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int Ans[100016];
int Now[100016];

int main() {
    int N;
    scanf("%d", &N);
    vector<pair<int, int> > A, B;
    for(int n=0; n<N; ++n) {
        int a;
        scanf("%d", &a);
        A.emplace_back(a, n);
    }
    for(int n=0; n<N; ++n) {
        int b;
        scanf("%d", &b);
        B.emplace_back(b, n);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int n=0; n<N; ++n) {
        if(B[n].first<A[n].first) {
            printf("No\n");
            return 0;
        }
    }
    for(int n=1; n<N; ++n) {
        if(A[n].first<=B[n-1].first) {
            printf("Yes\n");
            return 0;
        }
    }
    for(int n=0; n<N; ++n) {
        Now[n] = n;
        Ans[B[n].second] = A[n].second;
    }
    for(int n=0; n<N-1; ++n) {
        if(Now[n]==Ans[n]) {
            printf("Yes\n");
            return 0;
        }
        int ans = Ans[n];
        int * Now2 = Now + n;
        for(int i=N-1-n; i; --i) {
            if(ans==Now2[i]) {
                Now2[i] = Now2[0];
                break;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2676
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int a,b;
	cin >> a >> b;
	if(a <= 0 and 0 <= b){
		cout << "Zero" << endl;
	}else if(0 < a and 0 < b){
		cout << "Positive" << endl;
	}else{
		if((b-a+1)%2 == 1){
			cout << "Negative" << endl;
		}else{
			cout << "Positive" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int l; cin >> l;
    cout << (ld)pow((ld)l / 3.0, 3.0) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 640
// Candy Distribution Again
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int N, x;
    int a[110];
    int count = 0;
    cin >> N >> x;
    for (int i = 0; i < N; ++i) cin >> a[i];
    sort(a, a+N);
    for (int i = 0; i < N; ++i) {
        if (x >= a[i]){
            x -= a[i];
            count++;
        } else {
            break;
        }
        if (i == N-1 && x != 0) count -= 1;
    }
    cout << count << endl;
}

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

using ll=long long;

int main(){

int N;
cin>>N;

for(int i=1;i<=9;++i){
for(int j=1;j<=9;++j){
if(i*j==N){
cout<<"Yes"<<endl; goto xyz;
}
}
}

cout<<"No"<<endl;

xyz:;
}

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

int main()
{
	int line,i=0,stack[10] = {0};

	while(cin >> line)
	{
		if(line == 0)
		{
			i--;
			cout << stack[i] << endl;
		}
		else
		{
			stack[i] = line;
			i++;
		}
	}

	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    rep(i, N) {
        cin >> S[i];
    }
    set<char> s(S.begin(), S.end());
    if (s.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        long[] A = new long[N];
        long sum = 0;
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
            sum += A[i];
        }
        long x = (long)N * (N + 1) / 2;
        if (sum % x != 0) {
            _out.println("NO");
            return;
        }

        long K = sum / x;
        for (int i = 0; i < N; ++i) {
            long d = A[(i + 1) % N] - A[i];
            if ((d - K) % N != 0 || d - K > 0) {
                _out.println("NO");
                return;
            }
        }
        _out.println("YES");
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){
    ll n,m;
    cin>>n>>m;
    ll a[n+1][m+1];
    memset(a,0,sizeof a);
    for(ll i=1;i<n+1;i++){
        for(ll j=1;j<m+1;j++){
            char ch;
            cin>>ch;
            if(ch=='#')
                a[i][j] = 1;
        }
    }
    ll dp[n+1][m+1];
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(i==1 and j==1){
                dp[i][j] = a[i][j];
            }
            else if(i==1){
                dp[i][j] = dp[i][j-1] + (a[i][j] == 1 ? (a[i][j-1]== 0 ? 1 : 0) : 0);
            }
            else if(j==1){
                dp[i][j] = dp[i-1][j] + (a[i][j] == 1 ? a[i-1][j]==0 ? 1 : 0 : 0); 
            }
            else{
                dp[i][j] = dp[i-1][j] + (a[i][j] == 1 ? a[i-1][j]==0 ? 1 : 0 : 0);  
                dp[i][j] = min(dp[i][j] , dp[i][j-1] + (a[i][j]== 1 ? a[i][j-1] == 0 ? 1ll : 0ll : 0ll) );
            }
        }
    }
    // for(ll i=1;i<n+1;i++){
    //     for(ll j=1;j<m+1;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[n][m] << endl;
}

int main(){
    #ifdef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<P> d(m); 
    rep(i, 0, m){
        cin >> d[i].first >> d[i].second;
        d[i].second--;
    }
    sort(all(d));
    vector<P> ans(n);
    rep(i, 0, n){
        ans[i] = {i, i};
    }
    rep(i, 0, m){
        int id = d[i].second;
        int l = min(ans[id].first, ans[id + 1].first);
        int r = max(ans[id].second, ans[id + 1].second);
        ans[id] = ans[id + 1] = {l, r};
    }
    for(int ii = 0; ii < ans.size(); ii++){
        if(ii) cout << ' ';
        cout << ans[ii].second - ans[ii].first + 1;
    }
    cout << endl;
}


Measured memory_bytes: 7568
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(x) cout<<x<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,A,B,ans;
  cin>>A>>B;
  if(A<=8&&B<=8)print("Yay!");
  else print(":(");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 100050;
int N;
long long a[MAX_N];

std::vector<int> belong[MAX_N];
long long belong_ac[MAX_N];
long long ret[MAX_N] = {};

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> a[i];
    }
    a[0] = 0;

    std::vector<int> cand_idx;
    cand_idx.push_back(0);
    long long tmp_max = 0;
    belong[0].push_back(0);

    for (int i = 1; i <= N; i++) {
        if (tmp_max < a[i]) {
            cand_idx.push_back(i);
            tmp_max = a[i];
            belong[cand_idx.size() - 1].push_back(i);
        } else {
            int lb = 0;
            int ub = cand_idx.size() - 1;
            while(lb + 1 < ub) {
                int mid = (lb + ub) / 2;
                if (a[i] <= a[cand_idx[mid]]) {
                    ub = mid;
                } else {
                    lb = mid;
                }
            }
            belong[ub].push_back(i);
        }
    }

    /*
    for (int i = 0; i < cand_idx.size(); i++) {
        std::cout << "cand:" << cand_idx[i] << ":";
        for (auto b : belong[i]) {
            std::cout << b << " ";
        }
        std::cout << std::endl;
    }
    */

    belong_ac[cand_idx.size()] = 0;

    for (int i = cand_idx.size() - 1; 0 <= i; i--) {
        belong_ac[i] = belong_ac[i+1] + belong[i].size();
    }

    for (int i = cand_idx.size() - 1; 1 <= i; i--) {
        for (auto b : belong[i]) {
            ret[cand_idx[i]] += a[b] - a[cand_idx[i-1]];
        }
        ret[cand_idx[i]] += (a[cand_idx[i]] - a[cand_idx[i-1]]) * belong_ac[i+1];
    }

    for (int i = 1; i <= N; i++) {
        std::cout << ret[i] << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define print(x) for(auto it:x) cout << it << " "; cout << "\n";
#define wi(x) cerr << #x << " is " << x << nl
const double eps = 1e-6;
const int mod = 1e9 + 7;

ll rec_power(ll a, ll b){ // assuming a != 0
	if(b == 0) return 1;
	ll tmp = rec_power(a,b/2);
	ll res = tmp * tmp;
	if(b&1) res *= a;
	return res;
}

ll power(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res = (res * a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}

void solve(){
	string s; cin >> s;
	int n = s.length();
	ll ans = 0;
	rep(i,0,n-1) ans += s[i] - '0';
	if(ans%9 == 0) cout << "Yes";
	else cout << "No";
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();
	
	return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

int A[33][33];
pair<int, int> dp[33][33][33][33];
int u[33][33];
int visit[33][33][33][33];
int s;

int sum(int x, int y){
  if(x < 0 || y < 0){
    return 0;
  }
  else{
    return A[x][y];
  }
}

int sum(int x1, int y1, int x2, int y2){
  return sum(x2 - 1, y2 - 1) - sum(x1 - 1, y2 - 1) - sum(x2 - 1, y1 - 1) + sum(x1 - 1, y1 - 1);
}

pair<int, int> solve(int x1, int y1, int x2, int y2){
//  printf("solve(%d, %d, %d, %d)\n", x1, y1, x2, y2);
  if(visit[x1][y1][x2][y2] == 1){
    return dp[x1][y1][x2][y2];
  }
  visit[x1][y1][x2][y2] = 1;
  int i, j;
  pair<int, int> ans(-1, inf), res1, res2;
  if(sum(x1, y1, x2, y2) >= s){
    ans = pair<int, int>(1, sum(x1, y1, x2, y2));
  }
//  printf("ini_ans = (%d, %d)\n", ans.first, ans.second);
  for(i = x1 + 1; i < x2; i++){
    res1 = solve(x1, y1, i, y2);
    res2 = solve(i, y1, x2, y2);
    if(res1.first < 0 || res2.first < 0){
      continue;
    }
    if(ans.first < res1.first + res2.first){
      ans = pair<int, int>(res1.first + res2.first, min(res1.second, res2.second));
    }
    else if(ans.first == res1.first + res2.first){
      ans.second = max(ans.second, min(res1.second, res2.second));
    }
  }
  for(j = y1 + 1; j < y2; j++){
    res1 = solve(x1, y1, x2, j);
    res2 = solve(x1, j, x2, y2);
    if(res1.first < 0 || res2.first < 0){
      continue;
    }
    if(ans.first < res1.first + res2.first){
      ans = pair<int, int>(res1.first + res2.first, min(res1.second, res2.second));
    }
    else if(ans.first == res1.first + res2.first){
      ans.second = max(ans.second, min(res1.second, res2.second));
    }
  }
  dp[x1][y1][x2][y2] = ans;
//  printf("dp[%d][%d][%d][%d] = (%d, %d)\n", x1, y1, x2, y2, ans.first, ans.second);
  return ans;
}

int main(){
  while(1){
    int H, W, i, j, k, l;
    scanf("%d%d%d", &H, &W, &s);
    if(H == 0){
      return 0;
    }
    s = -s;
    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        scanf("%d", &u[i][j]);
        s += u[i][j];
      }
    }
//    printf("s = %d\n", s);
    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        if(i == 0 && j == 0){
          A[i][j] = u[i][j];
        }
        else if(i == 0){
          A[i][j] = A[i][j - 1] + u[i][j];
        }
        else if(j == 0){
          A[i][j] = A[i - 1][j] + u[i][j];
        }
        else{
          A[i][j] = A[i - 1][j] + A[i][j - 1] - A[i - 1][j - 1] + u[i][j];
        }
      }
    }
    for(i = 0; i <= H; i++){
      for(j = 0; j <= W; j++){
        for(k = 0; k <= H; k++){
          for(l = 0; l <= W; l++){
            dp[i][j][k][l] = pair<int, int>(-1, inf);
            visit[i][j][k][l] = 0;
          }
        }
      }
    }
    pair<int, int> ans = solve(0, 0, H, W);
    printf("%d %d\n", ans.first, ans.second - s);
  }
}



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

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 2 != 0) cnt++;
	}

	cout << cnt / (double)n << endl;

	return 0;
}

Measured memory_bytes: 256
def str_selection_sort(a,n):
    m=0
    for i in range(0,n):
        minj=i
        for j in range(i,n):
            if(int(a[minj][1:]) > int(a[j][1:])):
                minj=j
        if(minj!=i):
            m+=1
            a[minj],a[i] = a[i],a[minj]
        
    print(" ".join(a))
    return a

def str_bubble_sort(a,n):
    m=0
    flag=True
    while(flag):
        flag=False
        for i in range(n-1,0,-1):
            if(a[i-1][1:] > a[i][1:]):
                tmp=a[i-1]
                a[i-1]=a[i]
                m+=1
                a[i]=tmp
                flag=True
                
    print(" ".join(a))
    return a

def is_stable(a,b,n):
    for i in range(1,n):
        if(b[i-1][1:]!=b[i][1:]):
            continue
        flag=False
        for j in a:
            if(j[:1]==b[i-1][:1] and (not flag)):
                flag=True
                continue
            if(j[:1]==b[i][:1]):
                if(not flag):
                    return False
                else:
                    return True
        
        if(flag):
            return False
    return True

a=[]
n=int(input())
s=input()
a=s.split()
b=str_bubble_sort(list(a),n)
print("Stable")
c=str_selection_sort(list(a),n)
if(b==c):
    print("Stable")
else:
    print("Not stable")

Measured memory_bytes: 7736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
#define pll pair<long long, long long>
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll dx[] = {1,-1,0,0};
ll dy[] = {0,0,1,-1};
const ll sz = 3e5+5,mod = 998244353;
ll t,n,m,k;
vector<ll> p(sz),sp(sz),fac(sz);

const ll lim = 1e18;
const ll inf = 1e15;

ll Power(ll a, ll b)
{
    if(a==0)
        return 0;
    if(b==0)
        return 1;
    ll ans=Power((a*a)%mod,b/2);
    if(b&1)
        return (a*ans)%mod;
    return ans%mod;
}
ll Inv(ll a)
{
    return Power(a,mod-2);
}


int main()
{
    FIO
    cin>>n;
    ll ans = n/500*1000;
    ll x = n%500;
    ans += x/5*5;
    cout<<ans;
}


Measured memory_bytes: 7316
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;

    int t1 = H1 * 60 + M1;
    int t2 = H2 * 60 + M2;
    cout << (t2 - t1) - K << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int H, W;
	cin >> H >> W;
	vector<vector<char>> A(H, vector<char>(W));
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> A[i][j];
		}
	}
	vector<vector<char>> R = A;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (i == 0 && 0 < j && j < W - 1){
				R[i][j] = '#';
			}
			if (0 < i && i < H - 1 && 0 < j && j < W - 1 && j % 2 == 0){
				R[i][j] = '#';
			}
		}
	}
	vector<vector<char>> B = A;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			if (i == H - 1 && 0 < j && j < W - 1){
				B[i][j] = '#';
			}
			if (0 < i && i < H - 1 && 0 < j && j < W - 1 && j % 2 == 1){
				B[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cout << R[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cout << B[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 4428
n=int(input())
if n<=2:
    print(0);exit()
if n in [3,4,5]:
    print(1);exit()
def C(n, r ,mod=10**9+7):
    if n-r<r: r=n-r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) %mod

    return result % mod
ans=0
mod=10**9+7
for k in range(1,n//3+1):
    now= n-3*k
    ans+= C(now+k-1,k-1)
    ans%=mod
print(ans%mod)

Measured memory_bytes: 74708
N,M = map(int, input().split())

if M == 0:
    print(0,0)
    exit()

pS = [list(input().split()) for _ in range(M)]
ACed = [0] * (N+1)
pena_memo = [0] * (N+1)
n_pena = [0] * (N+1)

for i in range(M):
    if ACed[int(pS[i][0])] == 0:
        if pS[i][1] == "AC":
            ACed[int(pS[i][0])] = 1
            n_pena[int(pS[i][0])] = pena_memo[int(pS[i][0])]
        else:
            pena_memo[int(pS[i][0])] += 1

print(sum(ACed), sum(n_pena))

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

int main(){
    string s; cin >> s;
    int ans = 1000;
    for(int i = 0; i <= s.size()-3; ++i){
        int x = (s[i]-'0') * 100 + (s[i+1] - '0') * 10 + (s[i+2]-'0');
        ans = min(ans, abs(x-753));
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  // int a, b, c;
  // cin >> a >> b >> c;
  // cout << a + b + c << endl;
  // 入力は文字列として与えられているので上記は利用不可


  // string s;
  // int cnr;
  // cin >> s;

  // if (s[1] == '1')
  //   cnr++;
  // if (s[2] == '1')
  //   cnr++;
  // if (s[3] == '1')
  //   cnr++;
    
  // cout << cnr << endl;
  // 初期化不足と、配列間違い

  string s;
  int cnr = 0;
  cin >> s;

  if (s[0] == '1')
    cnr++;
  if (s[1] == '1')
    cnr++;
  if (s[2] == '1')
    cnr++;
    
  cout << cnr << endl;
}

Measured memory_bytes: 256
/*input
4
1 4 2
2
1 1 -8
2
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 gen;
struct node;
using pnode = node*;
int sz(pnode a);
ll dd(pnode a);
struct node
{
	node *l = NULL, *r = NULL;
	int w;
	int val;
	int dyd = 1;
	ll dyd1;
	node(int val): val(val)
	{
		w = gen();
		dyd1 = val;
	}
	void fixS()
	{
		dyd = 1 + sz(l) + sz(r);
		dyd1 = val + dd(l) + dd(r);
	}
};
int sz(pnode a)
{
	if (a)
		return a->dyd;
	return 0;
}
ll dd(pnode a)
{
	if (a)
		return a->dyd1;
	return 0;
}
pnode merge(pnode a, pnode b)
{
	if (a == NULL)
		return b;
	if (b == NULL)
		return a;
	if (a->w < b->w)
	{
		a->r = merge(a->r, b);
		a->fixS();
		return a;
	}
	else
	{
		b->l = merge(a, b->l);
		b->fixS();
		return b;
	}
}
pnode merge(pnode a, pnode b, pnode c)
{
	return merge(merge(a, b), c);
}
void split(pnode a, int v, pnode &x, pnode &y)
{	// (x <= v), (y > v)
	if (a == NULL)
	{
		x = NULL;
		y = NULL;
		return;
	}
	if (a->val <= v)
	{
		split(a->r, v, a->r, y);
		x = a;
	}
	else
	{
		split(a->l, v, x, a->l);
		y = a;
	}
	a->fixS();
}
void split_(pnode a, int k, pnode &x, pnode &y)
{	// (x->sz = min(a->sz, k))
	if (a == NULL)
	{
		x = NULL;
		y = NULL;
	}
	else
	{
		if (k <= 0)
		{
			x = NULL;
			y = a;
		}
		else if (a->dyd < k)
		{
			x = a;
			y = NULL;
		}
		else
		{
			if (sz(a->l) + 1 <= k)
			{
				split_(a->r, k - 1 - sz(a->l), a->r, y);
				x = a;
			}
			else
			{
				split_(a->l, k, x, a->l);
				y = a;
			}
			a->fixS();
		}
	}
}
void print(pnode a, char g = '\n')
{
	if (a == NULL)
	{
		if (g != ' ')
			cout << g;
		return;
	}
	print(a->l, ' ');
	cout << a->val << ' ';
	print(a->r, g);
}

int main()
{
	ios_base::sync_with_stdio(false);
	ll sumb = 0;
	pnode x = NULL;
	int Q;
	cin >> Q;
	int kiek = 0;
	while (Q--)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			kiek++;
			ll a, b;
			cin >> a >> b;
			sumb += b;
			pnode l, r;
			split(x, a, l, r);
			x = merge(l, new node(a), r);
		}
		else
		{
			pnode a, b, c;
			ll k = (kiek - 1) / 2;
			split_(x, k, a, b);
			split_(b, 1, b, c);
			ll X = b->val;
			ll Y = sumb;
			Y += dd(c);
			Y -= dd(a);
			Y += X * (sz(a) - sz(c));
			cout << X << " " << Y << "\n";
			x = merge(a, b, c);
		}
		//cout << "x: ";
		//print(x);
	}
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int maxn = 6e5 +10;
string s;
int n , l, r, mn[maxn];
void mnd( int a ){
	string s;
	cout<< a << endl ; 
	cin >> s;
	if( s == "Male")
		mn[a]=0;
	else if( s== "Female")
		mn[a]=1;
	else
		exit(0);
}
void bs(int l , int r){
	int mid= (l+r)/2;
	mnd(mid);
	if( ( mid %2 == l%2 && mn[mid] != mn[l]) || (  mid %2 != l%2 && mn[mid] == mn[l]))
		bs(l, mid);
	else 
		bs(mid, r);

}
int main()
{
	cin>>n;
	mnd(0);
	mnd(n-1);
	bs(0,n-1);
	
}

Measured memory_bytes: 852
w,h,n = gets.chomp.split(' ').map(&:to_i)
list = []
n.times do
  list << gets.chomp.split(' ').map(&:to_i)
end
p_list = [0,w,0,h]
list.each do |arr|
  if arr[2] == 1
    if p_list[0] < arr[0]
      p_list[0] = arr[0]
    end
  elsif arr[2] == 2
    if p_list[1] > arr[0]
      p_list[1] = arr[0]
    end
  elsif arr[2] == 3
    if p_list[2] < arr[1]
      p_list[2] = arr[1]
    end
  else
    if p_list[3] > arr[1]
      p_list[3] = arr[1]
    end
  end
end
puts [p_list[1]-p_list[0],0].max * [p_list[3]-p_list[2],0].max


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

//#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(vec) (vec).begin(),(vec).end()
#define vint vector<int>
#define pint pair<int,int>
#define vpint vector<pint>

int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}

int n,c;
int dd[32][32];
int cc[502][502];
vector<int> col[3];
vector<int> cost[3];

signed main(){
    cin>>n>>c;
    REP(i,c)REP(j,c)cin>>dd[i][j];
    REP(i,n)REP(j,n)cin>>cc[i][j];
    
    REP(i,n)REP(j,n){
        col[(i+j)%3].push_back(cc[i][j]);
    }
    
    REP(to,c){
        int sum=0;
        REP(from,col[0].size())sum+=dd[col[0][from]-1][to];
        cost[0].push_back(sum);
        sum=0;
        REP(from,col[1].size())sum+=dd[col[1][from]-1][to];
        cost[1].push_back(sum);
        sum=0;
        REP(from,col[2].size())sum+=dd[col[2][from]-1][to];
        cost[2].push_back(sum);
    }
    
    int ans=1000000000;
    REP(x,cost[0].size()){
        REP(y,cost[1].size()){
            if(x==y)continue;
            REP(z,cost[2].size()){
                if(x==z||y==z)continue;
                ans=min(ans,cost[0][x]+cost[1][y]+cost[2][z]);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2416
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
    double a, b, c, d, e, f;

    cin >> a >> b >> c >> d >> e >> f;

    double ans1 = 0, ans2 = 0;
    for(double i = 0; i <= 30.0; i += 1.0){
        for(double j = 0; j <= 30.0; j += 1.0){
            for(double k = 0; k <= 100.0; k += 1.0){
                for(double l = 0; l <= 100.0; l += 1.0){
                    if(c * k + d * l <= e * (a * i + b * j)){
                        if((a * i + b * j) * 100.0 + c * k + d * l <= f){
                            if(ans1 == 0 && ans2 == 0){
                                ans1 = (a * i + b * j) * 100.0 + c * k + d * l;
                                ans2 = c * k + d * l;
                            }
                            else{
                                if(100.0 * ans2 / ans1 <= 100.0 * (c * k + d * l) / ((a * i + b * j) * 100 + c * k + d * l)){
                                    ans1 = (a * i + b * j) * 100.0 + c * k + d * l;
                                    ans2 = c * k + d * l;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    printf("%.0lf %.0lf\n", ans1, ans2);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
    char * deck = malloc(sizeof(char) * 201);
    char * deck2 = malloc(sizeof(char) * 201);
    char stop = '-';
    char * point = &stop;
    int m, h;
    int i;

    while(1){
        scanf("%s", deck);
        if(deck[0] == stop) break;;
        //fgets(deck, sizeof(char) * 201, stdin);
        scanf(" %d", &m);

        for(i = 0; i < m; i++){
            scanf(" %d", &h);
            strncpy(deck2, &deck[h], strlen(deck) - h);
            //puts(deck2);
            strncat(deck2, deck, h);
            //puts(deck2);
            memset(deck, 0, sizeof(char) * 201);
            strncpy(deck, deck2, strlen(deck2));
            //puts(deck);
            memset(deck2, 0, sizeof(char) * 201);
        }
        printf("%s\n", deck);
    }
    free(deck);
    free(deck2);
    return(0);
}


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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N;
	map<int, int> mp[2];
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		mp[i % 2][a]++;
	}
	vector<pair<int, int>> vecs[2];
	for (int p = 0; p < 2; p++) {
		mp[p].emplace(0, 0);
		for (auto it : mp[p]) {
			vecs[p].emplace_back(it.second, it.first);
		}
		sort(vecs[p].rbegin(), vecs[p].rend());
	}
	int ma = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (vecs[0][i].second != vecs[1][j].second) {
				ma = max(ma, vecs[0][i].first + vecs[1][j].first);
			}
		}
	}
	int ans = N - ma;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 6140
def inp():
    return(int(input()))


def invr():
    return(map(str, input().split()))


N = inp()
pos = [0] * 101
SP = dict()
for i in range(1, N+1):
    key, val = invr()
    val = int(val)
    if key in SP:
        temparr = SP[key]
        temparr.append(val)
        SP[key] = temparr
    else:
        SP[key] = [val]
    pos[val] = i

names = sorted(SP)

for key in names:
    values = SP[key]
    values = sorted(values, reverse=True)
    for i in values:

        print(pos[i])


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

int main() {
    int n, b;
    long long ans = 0;
    cin >> n >> b;
    ans += b/2;
    b = b%2;
    for(int i=1;i<n;i++){
        int a;
        cin >> a;
        ans += (a + b) / 2;
        b = (a + b) % 2;
        if(a == 0)b = 0;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import numpy as np


def main():
    H, W = map(int, input().split())
    s_x = 1
    s_y = 1
    g_x = H
    g_y = W
    dp = - np.ones((H+2, W+2))
    black = 0
    for i in range(1, H+1):
        line = input()
        for j in range(1, W+1):
            if line[j - 1] == '.':
                dp[i][j] = 0
            else:
                black += 1
    queue = deque()
    queue.append((s_x, s_y))
    dp[s_x][s_y] = 1
    while len(queue) != 0:
        now_x, now_y = queue.popleft()
        for x in range(-1, 2):
            for y in range(-1, 2):
                if (x + y) % 2 == 0:
                    continue
                next_x = now_x + x
                next_y = now_y + y
                if dp[next_x][next_y] == 0:
                    dp[next_x][next_y] = dp[now_x][now_y] + 1
                    queue.append((next_x, next_y))
    if dp[g_x][g_y] == -1 or dp[g_x][g_y] == 0:
        print(-1)
    else:
        print(int(H * W - black - dp[g_x][g_y]))




if __name__ == '__main__':
    main()


Measured memory_bytes: 13668
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();

        while (A <= B) {
            if (A % K == 0) {
                System.out.println("OK");
                return;
            }
            A++;
        }
        System.out.println("NG");
    }
}


Measured memory_bytes: 35724
#include<iostream>
#include<string>

using namespace std;

int main(){
	int ans[26] = {};

	while(true){
		string s;
		getline(cin,s);
		int n = s.length();

		if(s.length() == 0)
			break;

		for(int i= 0; i< n ;i++){
			if((s[i] >= 'a')&&(s[i] <= 'z')){
				ans[(int)s[i]- 'a']++;
			}else if((s[i] >= 'A')&&(s[i] <= 'Z')){
				int num = (int)s[i] -'A';
				ans[num]++;
			}
		}
	}

	for(int i=0;i<26;i++){
		cout << (char)(i + 'a') << " : " << ans[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3204
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

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

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

func nextStrs(n int) []string {
	res := make([]string, n)
	for i := range res {
		res[i] = nextStr()
	}
	return res
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	//くじ引きを1回だけ行った場合
	if n == 1 {
		fmt.Println(n)
		return
	}
	//くじ引きを2回以上行った場合
	gifts := nextStrs(n)
	sort.Strings(gifts)
	count := 1
	for i := 0; i < n-1; i++ {
		if gifts[i] != gifts[i+1] {
			count++
		}
	}
	fmt.Println(count)
}


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

int main(){
  int a[3], cost = 0;
  cin >> a[0] >> a[1] >> a[2];

  for(int i = 0; i < 3; i++){
    if(i == 0){
      cost = abs(a[0]-a[1]) + abs(a[0]-a[2]);
    }
    else{
      cost = cost < abs(a[i]-a[0]) + abs(a[i]-a[1]) + abs(a[i]-a[2]) ? cost : abs(a[i]-a[0]) + abs(a[i]-a[1]) + abs(a[i]-a[2]);
    }
  }
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 256