akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<string> s, ans;
int h, w;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i, h)
    {
        string temp;
        cin >> temp;
        bool c = false;
        rep(j, w)
        {
            if (temp[j] == '#')
            {
                c = true;
            }
        }
        if (c)
        {
            s.push_back(temp);
        }
    }
    map<int,bool>m;
    rep(j, w)
    {
        bool c=false;
        rep(i, s.size())
        {
            if (s[i][j] == '#')
            {
                c = true;
            }
        }
        if(c)
        m[j]=true;
    }
    rep(i,s.size()){
        rep(j,w){
            if(m[j]){
                cout<<s[i][j];
            }
        }
        cout<<"\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int a[200005];
map<int, int>m;// [200005];//就相当于是int m[200005];
vector<int> g[200005];
int vis[200005]={0};
int maxn = 0;
int dfs(int i, int ans) {
	if(vis[i]!=0)return ans;
	for (int j = 0; j<g[i].size(); j++)
	{
		//if(!vis[i])
		ans = max(dfs(g[i][j], ans) + 1, ans);
	}
	vis[i]=ans;
	return ans;
}
int main() {
	int n; cin >> n;
	int x;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		m[x] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (m[i]<m[i + 1])
			//如果 i+1的下标比i要大, 就是在他后面
			g[i].push_back(i + 1);
	}
	//建图完毕
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dfs(i, 1));
	}
	cout << (n-ans)<<endl;//(最长的)
	return 0;
}


Measured memory_bytes: 31360
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^
 
void solve() {
  string s; cin >> s;
  const ll n = s.size();
  ll cnt = 0, ans = 0;
  rep(i, n) {
    if (s[i] == 'W') {
      ans += i - cnt;
      ++cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
import sys
from math import sqrt
from itertools import permutations
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A =[[int(_) for _ in input().split()] for i in range(n)]
    a_list=list(permutations(A))
    a_len=len(a_list)
    ans_all=0
    for i in range(a_len):
        keiro = a_list[i]
        ans=0
        x0=keiro[0][0]
        y0=keiro[0][1]
        for x1,y1 in keiro[1:]:
            ans+=sqrt((x1-x0)**2+(y1-y0)**2)
        ans_all+=ans
    print(ans_all/a_len)
if __name__=='__main__':
    main()

Measured memory_bytes: 8052
#pragma GCC optimize ("Ofast")

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING

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


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

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	vector<int> v(3);
	for (auto& c : v)
		cin >> c;

	sort(v.begin(), v.end());
	if (v[0] == 5 && v[1] == 5 && v[2] == 7)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}

Measured memory_bytes: 3604
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll h, w, k;
  cin >> h >> w >> k;

  ll xs, ys, xg, yg;
  cin >> xs >> ys >> xg >> yg;
  xs--, ys--, xg--, yg--;

  vector<string> mp(h);
  rep(i, h) cin >> mp[i];

  using Q = tuple<ll, ll, ll, ll>;
  priority_queue<Q, vector<Q>, greater<Q>> pque;
  vector<vvll> dist(h, vvll(w, vll(5, INF)));

  pque.emplace(0, xs, ys, 4);
  dist[xs][ys][4] = 0;
  while (!pque.empty()) {
    ll du, x, y, d;
    tie(du, x, y, d) = pque.top();
    pque.pop();
    if (dist[x][y][d] < du) continue;
    rep(i, 4) {
      ll nx = x + dx[i], ny = y + dy[i];
      bool ok = 0 <= nx && nx < h && 0 <= ny && ny < w && mp[nx][ny] != '@';
      if (!ok) continue;
      ll dv;
      if (d == i) {
        dv = du + 1;
      } else {
        dv = k * (du / k) + k;
      }
      if (dist[nx][ny][i] > dv) {
        dist[nx][ny][i] = dv;
        pque.emplace(dv, nx, ny, i);
      }
    }
  }

  ll ans = INF;
  rep(i, 4) if (dist[xg][yg][i] != INF) chmin(ans, dist[xg][yg][i] / k);
  if(ans == INF) ans = -1;

  cout << ans << endl;

  return 0;
}


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

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




Measured memory_bytes: 3092
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

int main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  rep(i,n){
    rep(j,i){
      if((a[j]-a[i])%(n-1)==0){
	cout<<a[i]<<" "<<a[j]<<endl;
	return 0;
      }
    }
  }
}



Measured memory_bytes: 3092
import java.io.*;
class Main
{
    public static void main(String[] args) 
    {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line=null;
	try {
	    line = br.readLine();
	} catch (IOException e){
	    System.out.println(e);
	}

	int x = Integer.parseInt(line);
	int y = x * x * x;
	System.out.println(y);
    }
}

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

const int D = 365;
vector<int> C(26), ans(D, 0), last(26,-1);
vector<vector<int>> S(D, vector<int>(26));

void debug1()
{
    //rep(i,26) cout << C[i] << " "; cout << endl;
    rep(i,D){
        rep(j,26)cout << S[i][j] << " ";
        cout << endl;
    }
}
void rand_init()
{
    rep(i,26) C[i] = rand() % 100;
    rep(i,D) rep(j,26) S[i][j] = rand() % 20000;
}
void input()
{
    int tmp;
    cin >> tmp;
    if(tmp == 0)
    {
      rand_init();
      return;
    }
    rep(i,26) cin >> C[i];
    rep(i,D)rep(j,26) cin >> S[i][j];
    rep(i,D) cin >> ans[i]; rep(i,D) ans[i]--; //B,C問題用
}
void output()
{
    for(auto x : ans)
        cout << x+1 << "\n";
}
int calc(vector<int> &vec)
{
    int score = 0;
    rep(i,D)
    {
        int cur = vec[i];
        score += S[i][cur];
        last[cur] = i;
        rep(j,26)
        {
            score -= C[j] * (i - last[j]);
        }
        cout << score << endl;
    }
    return score;
}
void greedy()
{
    rep(i,D)
        rep(j,26)
            if(S[i][j] > S[i][ans[i]])
                ans[i] = j;
}
void incremental()
{
    rep(t, 10000)
    {
        int d = rand() % D, q = rand() % 26;
        vector<int> old = ans;
        ans[d] = q;
        if(calc(ans) < calc(old))
            ans = old;
    }
}
void solve()
{
  greedy();
  incremental();
}
void rand_test(int r)
{
    rep(q,r)
    {
        rand_init();
        //debug1();
        solve();
        cout << 1000000 - calc(ans) << endl;
    }
}
int main()
{
    input();
    calc(ans);
    //rand_test(10);
    //solve();
    //output();
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll tx; cin>>tx; while(tx--)
typedef long long int ll;
int main() {
    FIO;
    //test
    {
       ll a,b,c,k,ans=0;
       cin>>a>>b>>c>>k;
       if(a<=k){
           ans+=a;
           k-=a;
       }
       else{
           ans+=k;
           k=0;
       }
       if(b<=k){
           k-=b;
       }
       else{
           k=0;
       }
       if(c<=k){
           ans-=c;
           k-=c;
       }
       else{
           ans-=k;
           k=0;
       }
       cout<<ans;
    }
	return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i=0; i<n; i++){
		cin >> a.at(i);
	}

	if(n%2==0){
		for(int i=n-1; i>=0; i-=2){
			cout << a.at(i) << " ";
		}
		for(int i=0; i<=n-1; i+=2){
			cout << a.at(i) << " ";
		}
	}else{
		for(int i=n-1; i>=0; i-=2){
			cout << a.at(i)<< " ";
		}
		for(int i=1; i<=n-2; i+=2){
			cout << a.at(i) << " ";
		}
	}
	cout << endl;
	return 0;
}


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

int main(){
	int N;
	string S;
	cin>>N;
	cin>>S;
	int kuro=0,shiro=0;
	for(long i=0;i<N;++i){
		if(S[i]=='.')shiro++;
		else kuro++;
	}
	int ans=shiro;
	int realans=ans;
	for(int i=0;i<N;++i){
		if(S[i]=='.'){
			ans--;
			shiro--;
			if(realans>ans)realans=ans;
		}
		else{
			ans++;
			kuro--;
		}
	}
	cout<<realans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
 
    // Your code here!
   string s;
   cin >> s;
   int count = 0;
   if(s[0] == s[1]){
       count = count + 1;
   }
    if(s[1] == s[2]){
       count = count +2;
   }
    if(s[2] == s[3]){
       count = count + 1;
   }
   count >= 3 ? cout << "Yes": cout << "No" << endl; 
}

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

static vector<int> stepList;
static vector<long> retList;

int main() {
  // 入力受け取り
  int N, K;
  cin >> N >> K;
  stepList.resize(N);
  retList.resize(N);
  for (int i=0; i<N; i++) cin >> stepList.at(i);
  
  // dp
  retList[0]=0;
  retList[1]=abs(stepList[1]-stepList[0]);
  for(int i=2; i <N; i++) {
    retList[i]=retList[i-1]+abs(stepList[i]-stepList[i-1]);
    for (int j =2; j <K+1; j++) {
      if (i-j <0) break;
      retList[i] = min(retList[i],retList[i-j]+abs(stepList[i]-stepList[i-j]));
    }
  }
  cout << retList[N-1] << endl;
}


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

using namespace std;

int frog1(int N, int a[])
{
    int dp[N+1];
    dp[0] = 0;
    dp[1] = a[0];
    dp[2] = abs(a[1] - a[0]);
    dp[3] = min(dp[2] + abs(a[2]-a[1]) , abs(a[2]-a[0]));
    for( int i = 3; i < N; i++)
    {
        dp[i+1] = min(dp[i] + abs(a[i]-a[i-1]), dp[i-1] + abs(a[i]-a[i-2]));
    }
    return dp[N];
}

int frog2(int N, int a[], int k)
{
    int dp[N+1];
    dp[0] = 0;
    dp[1] = a[0];
    dp[2] = abs(a[1] - a[0]);
    for( int i = 3; i <= N; i++)
    {
        dp[i] = INT_MAX;
        for(int j = 1 ; j <= k; j++)
            if(i-j-1>=0)
            {
                if(i-j-1 == 0)
                    dp[i] = min(dp[i], abs(a[i-1] - a[i-j-1]));
                else
                    dp[i] = min(dp[i], dp[i-j] + abs(a[i-1]-a[i-j-1]));
            }  
    }

    return dp[N];
}


int main()
{
    int N, k;
    cin>>N>>k;
    int a[N];
    for(int i = 0; i < N; i++) cin>>a[i];
    cout << frog2(N,a,k);
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int a, b, c; cin >> a >> b >> c;
	if (a < b && b < c) puts("Yes");
	else puts("No");
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n*2);
    rep(i,n)cin>>a[i];
    rep(i,n*2){
        a[i]=a[i%n];
    }
    vector<ll>len(n);
    vector<ll>nxt(2*1e5+1);
    for(int i=n*2-1;i>=n;i--){
        nxt[a[i]]=i;
    }
    for(int i=n-1;i>=0;i--){
        len[i]=nxt[a[i]]-i;
        nxt[a[i]]=i;
    }
    vector<ll>d(n,-1);
    ll now=0;
    ll cnt=0;
    ll cnt1;
    while(1){
        if(d[now]>=0){
            cnt1=d[now];
            break;
        }
        d[now]=cnt;
        cnt+=len[now]+1;
        now=(now+len[now]+1)%n;
    }
    stack<ll>st;
    k*=n;
    k-=cnt1;
    k%=cnt;
    while(len[now]+1<=k){
        k-=(len[now]+1);
        now=(now+len[now]+1)%n;
    }
    set<ll>s;
    REP(i,now,n){
        if(s.find(a[i])!=s.end()){
            while(s.find(a[i])!=s.end()){
                ll k=st.top();
                st.pop();
                s.erase(k);
            }
        }else{
            s.insert(a[i]);
            st.push(a[i]);
        }
    }
    vector<ll>b(0);
    while(!st.empty()){
        ll k=st.top();
        st.pop();
        b.pb(k);
    }
    reverse(all(b));
    for(auto e:b){
        cout<<e<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 22000
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;
typedef pair<int, int> pii;

int main(){
    int H, W;
    cin >> H >> W;
    vector<int> cnts(26);

    rep(i, H){
        rep(j, W){
            char c;
            cin >> c;
            cnts[c - 'a'] ++;
        }
    }

    vector<int> modF(4);
    rep(i, cnts.size()){
        int index = cnts[i] % 4;
        modF[index] ++;
    }

    if(H % 2 == 0 && W % 2 == 0){
        if(modF[1] + modF[2] + modF[3] == 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }

    if(H % 2 == 1 && W % 2 == 1){
        if(modF[1] + modF[3] == 1 && modF[2] + modF[3] <= H / 2 + W / 2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }

    if(W % 2 == 1){
        swap(H, W);
    }

    if(modF[1] + modF[3] == 0 && modF[2] <= W / 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


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

#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using namespace std; 

using ll = long long;
using ii = pair<int,int>;

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

  int n; cin >> n;
  vector<vector<int>> v(n, vector<int>(3));
  for (auto &i : v) for (auto &j : i) cin >> j;

  ll a = 0, b = 0, c = 0, aa, bb, cc;
  for (int i = n - 1; i >= 0; --i) {
    aa = max(b + v[i][1], c + v[i][2]);
    bb = max(a + v[i][0], c + v[i][2]);
    cc = max(a + v[i][0], b + v[i][1]);
    a = aa, b = bb, c = cc;
  }

  cout << max({a, b, c}) << ende;
  return 0;
}


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

using namespace std;

int main(){
  long long a,b,c,d; cin >> a >> b >> c >> d;
  long long  e=max(c,d);
  long long  f=min(c,d);
  long long r = e % f;
  while(r!=0){
    e = f;
    f = r;
    r = e % f;
  }
  long long s=c*d/f;
  cout << fixed << setprecision(20);
  cout << b-a+1-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/s-(a-1)/s) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N, H, W;
  cin >> N >> H >> W;
  vector<vector<long long>> vec(N,vector<long long>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  int ans = 0;
  for(int k=0; k<N; k++){
    if((vec.at(k).at(0) >= H) && (vec.at(k).at(1) >= W)){
     ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 2720: Identity Function
// 2017.10.9 bal4u@uu

#include <stdio.h>
#include <math.h>

#define INF 0x7fffffff
#define SIZE  25
int size;
int factor[SIZE];

int ptbl[] = {
         3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997, 0 };

void prime_factor(int n)
{
  int i, d, sw;
  int *pp;

  size = 0;
  if ((n & 1) == 0) {
    factor[size++] = 2;
    do n >>= 1LL;
    while ((n & 1) == 0);
  }
  for (pp = ptbl; n > 1 && *pp > 0; pp++) {
    if (n % *pp) continue;
    d = *pp;
    factor[size++] = d;
    do n /= d;
    while (n % d == 0);
  }
  if (n > 1) {
    int b = (int)sqrt((double)n);
    for (i = 1009, sw = 0; n > 1; ) {
      if (i > b) {
        factor[size++] = (int)n;
        break;
      }
      if (n % i == 0) {
        factor[size++] = i;
        do n /= i;
        while (n % i == 0);
      }
      if (sw) { i += 2, sw = 0; }
      else    { i += 4, sw = 1; }
    }
  }
}

int gcd(int a, int b)
{
	int r;
	while (b != 0) r = a % b, a = b, b = r;
	return a;
}

int lcm(int a, int b)
{
	return a/gcd(a, b)*b;
}

int big_mod(int b, int p, int m)
{
   long long s = 1;
   long long d;

   d = b % m;
   while (p > 0) {
      if (p & 1) s = (s * d) % m;
      p >>= 1;
      d = (d * d) % m;
   }
   return (int)s;
}

int main()
{
	int n, i, t, ans;
	int L, a, k;

	scanf("%d", &n);
	ans = -1;
	for (i = 2; ; i++) {
		if ((t = i*i) > n) break;
		if (n % t == 0) goto Done;
	}

	prime_factor(n);
	L = factor[0]-1;
	for (i = 1; i < size; i++) L = lcm(L, factor[i]-1);
	if (L == 1) { ans = 1; goto Done; }
	if (gcd(n, L) != 1) goto Done;

	prime_factor(L);
	for (a = L, i = 0; i < size; i++) a = a/factor[i]*(factor[i]-1);

	ans = INF; i = (int)sqrt(a);
	for (k = 1; k <= i; k++) {
		if (a % k == 0) {
			if (big_mod(n, k, L) == 1) { ans = k; goto Done; }
			t = a/k; if (big_mod(n, t, L) == 1 && t < ans) ans = t;
		}
	}
	if (ans == INF) ans = -1;
Done:printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1828
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll a,b;
    cin>>a>>b;
    ll ans=0;
    if(a<b){
        rep(i,b) ans += a * pow(10,i);
    }else{
        rep(i,a) ans += b * pow(10,i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define P 998244353 
using namespace std;
int sum,n,x,ans;
int f[2200*2200],a[2200],q[2200*2200],tail;
int add(int x,int a){
    for(int i=tail;i>=1;i--)
    	for(int j=1;j<=a;j++)
        if(f[q[i]+x*j]==0)q[++tail]=q[i]+x*j,f[q[i]+x*j]=1;
}
int main(){
    scanf("%d",&n);
    f[0]=1;
    tail=1;
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int tot=1;
    for(int i=1;i<=n;i++){
    	if(a[i]==a[i+1]){
    		tot++;
    		continue;
		}
        x=a[i]; 
        add(x,tot);
        sum+=x*tot;
        tot=1;
    }
    for(int i=0;i<=sum;i++)if(f[i])ans++;
    ans/=2;
    for(int i=1;i<=sum;i++){
        if(f[i])ans--;
        if(ans==0){
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 24832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int len = (int)Math.Sqrt(n);

            StringBuilder sb = new StringBuilder();
            sb.Append(n + ":");

            if (n < 2) sb.Append(" " + n);

            while (n % 2 == 0)
            {
                n /= 2;
                sb.Append(" " + 2);
            }

            for (int i = 3; i <= len; i += 2)
            {
                while (n % i == 0)
                {
                    n /= i;
                    sb.Append(" " + i);
                }
            }

            if (n > 1) sb.Append(" " + n);

            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 9236
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

int q;
int main(){

  cin>>q;
  ll lp,rp;
  lp=rp=0;
  for(int i=0;i<q;i++){
    int p,n;
    char c;
    cin>>p>>c>>n;
    if(c=='(')lp+=n;
    else rp+=n;
    if(lp==rp)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }

  return 0;
}

Measured memory_bytes: 856
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int n, m, s, t;
vector<vector<int> > G(100010);
vector<vector<int> > Ga(100010);
vector<vector<int> > Gb(100010);
long long v1[100010], v2[100010];
long long M = 1000000000ll * 1000000000;
queue<int> q;
long long num[100010];
int idx[100010];
long long Y = 1000000000ll*1000000;

bool cmp(int aa, int bb)
{
	return v1[aa]+v2[aa] < v1[bb]+v2[bb];
}

void solve()
{
	int i;
	for(i=0; i<n; i++)
		v1[i] = v2[i] = M;
	v1[s] = 0;
	int u, v;
	q.push(s);
	while(!q.empty() ){
		u = q.front();
		q.pop();
		for(i=0; i<G[u].size(); i++){
			v = G[u][i];
			if(v1[u]+Ga[u][i] < v1[v]){
				v1[v] = v1[u]+Ga[u][i];
				q.push(v);
			}
		}
	}
	v2[t] = 0;
	q.push(t);
	while(!q.empty() ){
		u = q.front();
		q.pop();
		for(i=0; i<G[u].size(); i++){
			v = G[u][i];
			if(v2[u]+Gb[u][i] < v2[v]){
				v2[v] = v2[u]+Gb[u][i];
				q.push(v);
			}
		}
	}
	
	int cur = -1;
	for(i=0; i<n; i++)
		idx[i] = i;
	sort(idx, idx+n, cmp);
	for(i=0; i<n; i++)
		num[i] = -1;
	for(i=0; i<n; i++){
		int i2 = idx[i];
		if(i2 > cur){
			num[i2] = Y - v1[i2] - v2[i2];
			cur = i2;
		}
	}
	for(i=n-1; i>=0; i--){
		if(num[i] == -1){
			num[i] = num[i+1];
		}
	}
	for(i=0; i<n; i++)
		printf("%lld\n", num[i]);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i;
	int u, v, a, b;
	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--, t--;
	for(i=0; i<m; i++){
		scanf("%d%d%d%d", &u, &v, &a, &b);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
		Ga[u].push_back(a);
		Gb[u].push_back(b);
		Ga[v].push_back(a);
		Gb[v].push_back(b);
	}
	solve();
	return 0;
}

Measured memory_bytes: 21120
#include <iostream>
 #include <cmath>
 #include <string>
 #include <cstring>
 #include <utility>
 #include <vector>
 #include <set>
 #include <map>
 #include <stack>
 #include <queue>
 #include <bitset>
 #include <algorithm>
 #include <functional>
 #include <numeric>
 #define debug(x) cerr << #x << ':' << x << endl
 #define rep(i,n) for(int i=0;i<(int)n;++i)
 #define ALL(c) (c).begin(), (c).end()
 using namespace std;
 typedef long long ll;
 const ll MOD=1000000007;
 int main(){
    ll n,m;
    cin >> n >> m;
    if(abs(n-m)>1){
        cout << 0 << endl;
        return 0;
    }
    else if (abs(n-m)==1){
        // n>=mで考える
        if(m>n){
            ll tmp=n;
            n=m, m=tmp;
        }
        ll fact_n=1, fact_m=1;
        while(n!=1){
            fact_n = ((fact_n%MOD) * (n%MOD))%MOD;
            n--;
        }
        while(m!=1){
            fact_m = ((fact_m%MOD) * (m%MOD))%MOD;
            m--;
        }
        ll ans = (fact_n*fact_m)%MOD;
        cout << ans << endl;
    }
    else{
        if(m>n){
            ll tmp=n;
            n=m, m=tmp;
        }
        ll fact_n=1, fact_m=1;
        while(n!=1){
            fact_n = ((fact_n%MOD) * (n%MOD))%MOD;
            n--;
        }
        while(m!=1){
            fact_m = ((fact_m%MOD) * (m%MOD))%MOD;
            m--;
        }
        ll ans = (2*fact_n*fact_m)%MOD;
        cout << ans << endl;
    }
    return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>

using namespace std;

string expr(int x, int y) {
    stringstream ss;
    ss << x << "x" << y << "=" << x*y;
    return ss.str();
}

int main() {
    set<string> c;
    for (int i=1e3; i; --i) {
        c.insert(expr(rand() % 9 + 1, rand() % 9 + 1));
    }
    for (auto it=c.begin(); it!=c.end(); ++it) {
        cout << *it << endl;
    }
    return 0;
}

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

int main() {
    int X;
    cin >> X;

    int A,B;
    for (int i=0;i<1000;i++) {
        for (int j=-1000;j<1000;j++) {
            if (pow(i,5)-pow(j,5)==X) {
                A=i;
                B=j;
            }
        }
    }
    cout << A << " " << B << endl;
}

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

int main(){
    int64_t n, k;
    cin >> n >> k;
    n = n%k;
    int64_t a = n;
    int i;
    n = n - k;
    int64_t b = abs(n);
    if(b >= a){
        cout << a << endl;
    }
    else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
    int N, M;
    cin >> N >> M;

    int constraint[3] = {0};
    int equal[3];
    int s[5], c[5];
    for (int i=0; i<M; i++) {
        cin >> s[i] >> c[i];
    }
    
    for (int i=0; i<M; i++) {
        if (constraint[s[i]-1] != 0 && c[i] != equal[s[i]-1]) {
            cout << -1 << endl;
            return 0;
        }
        constraint[s[i]-1] = 1;
        equal[s[i]-1] = c[i];
    }

    if (N == 1) {
        if (constraint[0]) cout << equal[0] << endl;
        else cout << 0 << endl;
        return 0;
    }
    if (constraint[0]) {
        if (equal[0] == 0) {
            cout << -1 << endl;
        }
        else {
            for (int i=0; i<N; i++) {
                if (constraint[i] == 0) equal[i] = 0;
            }
            for (int i=0; i<N; i++) cout << equal[i];
            cout << endl;
        }
    } else {
        equal[0] = 1; constraint[0] = 1;
        for (int i=0; i<N; i++) {
            if (constraint[i] == 0) equal[i] = 0;
        }
        for (int i=0; i<N; i++) cout << equal[i];
        cout << endl;
    }
        
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  string a;
  cin >> a;
  if (a[6] <= '4' and a[5] == '0') {
    cout << "Heisei";
  } else {
    cout << "TBD";
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define INF (1<<24)
int n;
int r[101][101];
main(){
  scanf("%d",&n);
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++) r[i][j]=INF;
  for(int i=0;i<n;i++){
    int rr,k;
    scanf("%d %d",&rr,&k);
    for(int j=0;j<k;j++){
      int t;
      scanf("%d",&t);
      r[rr][t]=1;
    }
  }
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      for(int l=1;l<=n;l++)
	r[j][l]=min(r[j][l],r[j][i]+r[i][l]);
  int p;
  scanf("%d",&p);
  for(int i=0;i<p;i++){
    int s,d,v;
    scanf("%d %d %d",&s,&d,&v);
    int res=r[s][d]+1;
    if(res>v) printf("NA\n");
    else printf("%d\n",res);
  }
}

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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<long>;
using vll = vector<ll>;
using vb  = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vector<int> >;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

int main()
{
    FASTIO;
    char c; cin >> c;
    cout << (c >= 'a' ? 'a' : 'A') << nl;
    return 0;
}


Measured memory_bytes: 3652
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    D={}
    ans=0
    for i,a in enumerate(A):
        if i-a in D:
            ans += D[i-a]
        if i+a in D:
            D[i+a] += 1
        else:
            D[i+a] = 1
    print(ans)

main()


Measured memory_bytes: 40344
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

const int maxn=1e5+5;
vector<int> g[maxn];
struct Node
{
    int u,d;
    Node(int uu,int dd){
        u=uu; d=dd;
    }
    bool operator <(const Node& x) const
    {
        return d>x.d;
    }
};
priority_queue<Node>pq;
int dis[maxn],pre[maxn];


int main()
{
    int n,m; scanf("%d%d",&n,&m);
    for(int i=1;i<=m;++i){
        int u,v; scanf("%d%d",&u,&v);
        g[u].push_back(v); g[v].push_back(u);
    }
    for(int i=1;i<=n;++i) dis[i]=1e9;
    dis[1]=0;
    pq.push(Node{1,0});
    while(!pq.empty()){
        Node now=pq.top(); pq.pop();
        int u=now.u;
        for(auto v:g[u]){
            if(dis[v]>dis[u]+1){
                dis[v]=dis[u]+1;
                pre[v]=u;
                pq.push(Node(v,dis[v]));
            }
        }
    }
    puts("Yes");
    for(int i=2;i<=n;++i) printf("%d\n",pre[i]);
    return 0;
}

Measured memory_bytes: 11268
/**
*    author:  Dooloper
*    created: 12.04.2020 20:51:07
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
typedef unsigned long ll;

ll GCD(int a, int b, int c){
    return __gcd(__gcd(a,b),c);
    // else return __gcd(__gc?d(a,b),c)*k;
}

int main() {
   cin.tie(0);
   int K;cin>>K;

   ll sum = 0;

    // sum += 1;
   int a = 1;
   int b = 1;
   int c = 1;


   for(; a != K || b != K || c != K ;){
    //    sum += __gcd(__gcd(a,b),c);
    // cout<<111111<<endl;
    //    cout<<a<<" "<<b<<" "<<c<<endl; 
        sum += GCD(a,b,c);
       c++;
       if(c > K) {
           c = 1;
           b ++;
           if( b > K){
               b = 1;
               a++;
           }
       }
   }
//    cout<<a<<" "<<b<<" "<<c<<endl;
    sum += GCD(K,K,K);
   cout<<sum <<endl;
   return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define re register
using namespace std;
int n,a[100002],b,head[10002],cnt,ans,m;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re int i=1;i<=n;++i){
		for(re int j=i;j<=n;++j){
			while(a[i]==a[j])++j;
			if(j>n)break;
			for(re int k=j;k<=n;++k){
				while(a[j]==a[k])++k;
				if(k>n)break;
				if(a[i]+a[j]>a[k])++ans;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 3772
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int N;cin>>N;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<N;i++){
    cout<<s[i]<<t[i];
  }
  cout<<endl;

}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%f %f', $zei8, $zei10);
for ($i=1; $i <= 1009; $i++) { 
    $tmp8 = floor($i * 0.08);
    $tmp10 = floor($i * 0.10);
    if ($tmp8 === $zei8 && $tmp10 === $zei10) {
        echo $i;
        echo "\n";
        exit;
    }
}
echo -1;
echo "\n";

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

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

	int K;
	cin >> K;

	int h[N];
	for (int i = 0; i < N; i++)
		cin >> h[i];

	int count = 0;

	for (int i = 0; i < N; i++) {
		if (h[i] >= K)
			count++;
	}

	cout << count << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < C; i++) for (int j = 0; j < C; j++) scanf("%d", &D[i][j]);
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
        scanf("%d", &A[i][j]); A[i][j]--;
    }

    vector<vector<int>> v(3, vector<int>(C));
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) v[(i+j)%3][A[i][j]]++;
    int minD = INF;
    for (int c1 = 0; c1 < C; c1++) {
        for (int c2 = 0; c2 < C; c2++) {
            if (c1 == c2) continue;
            for (int c3 = 0; c3 < C; c3++) {
                if (c2 == c3 || c1 == c3) continue;
                int cur = 0;
                for (int j = 0; j < C; j++) {
                    cur += D[j][c1] * v[0][j];
                    cur += D[j][c2] * v[1][j];
                    cur += D[j][c3] * v[2][j];
                }
                minD = min(minD, cur);
            }
        }
    }

    cout << minD << '\n';
}


Measured memory_bytes: 4696
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  int ans=0;
  rep(i,0,4){
    char x;cin>>x;
    if(x=='+'){ans++;}
    else{ans--;}
  }
  cout<<ans<<endl;
}



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

const int MAX_N = 100 * 1000 + 10;
int cnt[MAX_N], red[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	fill(cnt, cnt + n, 1);
	red[0] = true;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cnt[x]--;
		cnt[y]++;
		red[y] |= red[x];
		red[x] &= (cnt[x] > 0);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += red[i];
	cout << ans;
}

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

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

	int n;
	cin >> n;

	for(int i = 0;; ++i) {
		if(n == 1) {
			cout << i << endl;
			break;
		}
		n = (n + 2) / 3;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1196
N, M = [int(n) for n in input().split()]
K = [list(map(int, input().split())) for i in range(M)]
P = [int(n) for n in input().split()]


case_cnt = 0
for i in range(2**N):
  bulbs = []
  ons = []
  #N個のswitchがON/OFFの入力ケース作成
  for j in range(N):
    if (i >> j) & 1:
      ons.append(j)
  #print("case#{0} switch : {1}".format(i, ons))    
  #入力ケースに対するして、各電球ごとのSwithがONとなる数をカウント
  for k in range(M):
    cnt = 0
    for s in K[k][1:]:
      if s-1 in ons:
        cnt += 1
    #bulbsに電球が光ればTrue, 光らなければFalse
    if P[k] == cnt % 2 :
      bulbs.append(True)
    else:
      bulbs.append(False)
  #全電球が光っているのであれば、カウント
  if all(bulbs):
    case_cnt += 1
print(case_cnt)

Measured memory_bytes: 3064
#include <stdio.h>
#define LEN 1000000
 
int main(){
    int i, j, n;
    int prime[LEN];
    for(i = 2; i < LEN; ++i){
        prime[i] = 1;
    }
 
    for(i = 2; i <= 1000;){
        for(j = i * 2; j < LEN; j += i){
            prime[j] = 0;
        }
        for(j = i + 1; ; ++j){
            if(prime[j]){
                i = j;
                break;
            }
        }
    }
 
    while(scanf("%d", &n) != EOF){
        int counter = 0;
        for(i = 2; i <= n; ++i){
            if(prime[i]){
                ++counter;
            }
        }
        printf("%d\n", counter);
    }
    return 0;
}

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

#define ll long long
#define pb push_back

int main(){

	int N;
	int arr1[100005], arr2[100005];
	for(int i = 0; i < 100005; i ++){
		arr1[i] = 0;
		arr2[i] = 0;
	}
	cin >> N;
	if(N == 2){
		int a, b;
		cin >> a >> b;
		if(a == b)cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	for(int i = 0; i < N; i ++){
		int v;
		cin >> v;
		if(i % 2 == 0){
			arr1[v] ++;
		}
		else{
			arr2[v] ++;
		}
	}
	vector<pair<int, int>> P1, P2;
	for(int i = 0; i < 100005; i ++){
		P1.pb(make_pair(arr1[i], i));
		P2.pb(make_pair(arr2[i], i));
	}
	sort(P1.begin(), P1.end());
	sort(P2.begin(), P2.end());
	if(P1[P1.size() - 1].second != P2[P2.size() - 1].second){
		cout << N - P1[P1.size() - 1].first - P2[P2.size() - 1].first << endl;
	}
	else{
		int ans1, ans2;//ans1は1そのまま2変更
		ans1 = N - P1[P1.size() - 1].first - P2[P2.size() - 2].first;
		ans2 = N - P2[P2.size() - 1].first - P1[P1.size() - 2].first;
		cout << min(ans1, ans2) << endl;
	}

	return 0;
}

Measured memory_bytes: 2804
#include<stdio.h>

int main(void){
    
    int a,b,c;
    
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    
    if((a < b) && (b < c))
        printf("Yes\n");
    else
        printf("No\n");
        
    return 0;
}


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

#define sysp system("pause")

int a,b,c,d,e,f;
string s,t,u;

int main(){
	int a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	cout<<abs(a[0]-a[1])+abs(a[1]-a[2])<<endl;
	sysp;
} 

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int H;
    cin >> H;
    long long int W;
    cin >> W;
    if((H == 1)||(W == 1)){
        cout << 1;
    }
    else if((H%2 == 0)&&(W%2 == 0)){
        cout << H*W/2;
    }
    else if((H%2 == 0)&&(W%2 == 1)){
        cout << H*W/2;
    }
    else if((H%2 == 1)&&(W%2 == 0)){
        cout << H*W/2;
    }
    else{
        cout << (H*W+1)/2;
    }
}

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

long long x, y;

int main() {
  cin >> x >> y;
  if (x == 0)
    cout << abs(y) + (y < 0) << endl;
  else if (y == 0)
    cout << abs(x) + (x > 0) << endl;
  else if (x * y < 0)
    cout << 1 + abs(x + y) << endl;
  else if (x < y)
    cout << y - x << endl;
  else
    cout << 2 + x - y << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        System.out.println(Math.max(A*B,C*D));
    }
}

Measured memory_bytes: 10320
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int main(){

    ll n;
    cin>>n;
    vector<pair<ll,ll>> ku;
    vector<ll> s;
    for(int i=0;i<n-1;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        ku.push_back(make_pair(b,a));
        s.push_back(c);
    }
  /*  rep(i,n-1){
        cout<<ku[i].first<<ku[i].second<<endl;
    }*/
    for(int i=0;i<n-1;i++){
        ll time=0;
        for(int j=i;j<n-1;j++){
            if(time<ku[j].first){
                time+=ku[j].first-time;
            }else{
                if(time%s[j]!=0){
                    time+=s[j]-(time%s[j]);
                }
            }
            time+=ku[j].second;
        }
        
        cout<<time<<endl;
    }
    cout<<0<<endl;
    
    return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize, l: usize, vs : [chars; n]);
    vs.sort();
    let mut v = vs.iter().fold(vec![], |acc, second| [&acc[..], &second[..]].concat());
    for ch in v.iter() {
        print!("{}", ch);
    }
}


Measured memory_bytes: 4352
N = int(input())
P = [int(s) - 1 for s in input().split()]
ans = 0
i = 0
while i < len(P) - 1:
    if P[i] == i:
        P[i], P[i+1] = P[i+1], P[i]
        ans += 1
        i += 2
    else:
        i += 1
if P[N - 1] == N - 1:
    ans += 1
print(ans)


Measured memory_bytes: 13880