akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const int MAX = 200;
const long long INF = (1LL<<32);
int V, E, s, t, d;
long long G[MAX][MAX];

void floyd()
{
    for(int k=0; k<V; k++)
    {
        for(int i=0; i<V; i++)
        {
            if(G[i][k]==INF) continue;
            for(int j=0; j<V; j++)
            {
                if(G[k][j]==INF) continue;
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
}
bool negative()
{
    for(int i=0; i<V; i++)
    {
        if(G[i][i]<0)
            return 1;
    }
    return 0;
}
int main()
{
    cin >> V >> E;
    for(int i=0; i<V; i++)
    {
        for(int j=0; j<V; j++)
        {
            if(i==j) G[i][j] = 0;
            else G[i][j] = INF;
        }
    }
    for(int i=0; i<E; i++)
    {
        cin >> s >> t >> d;
        G[s][t] = d;
    }
    floyd();
    if(negative())
        cout << "NEGATIVE CYCLE" << endl;
    else
    {
        for(int i=0; i<V; i++)
        {
            for(int j=0; j<V; j++)
            {
                if(j) cout << " ";
                if(G[i][j]!=INF)
                    cout << G[i][j];
                else
                    cout << "INF";
            }
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3264
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main()
{
  int n,t,i,j,res=0;
  vector<int> v[26];
  string s;
  cin >> n >> s;
  for(i=0;i<n;i++)
    v[(int)(s[i]-'a')].push_back(i);
  for(i=0;i<n;i++){
    t=0;
    for(j=0;j<26;j++)
      if(v[j].size()>0&&v[j][0]<=i&&v[j][v[j].size()-1]>i)
        t++;
    res=max(res,t);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int N=1e5+5;
int n,a[N],dp[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    if(a[1]!=0) printf("0\n");
    else
    {
        sort(a+1,a+1+n);
        ll ans=1;dp[0]=1;
        for(int i=2;i<=n;i++)
        {
            if(a[i]==0) {ans=0;break;}
            ans=ans*dp[a[i]-1]%mod;
            dp[a[i]]++;
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 1024
# https://abc113.contest.atcoder.jp/tasks/abc113_b

candidate_count = gets.chomp.to_i
temp = gets.chomp.split(" ").map{|x| x.to_i}
average_temperature = temp[0]
comparison_temperature = temp[1]
abs_temperature = gets.chomp.split(" ").map{|x| ((average_temperature - x.to_i * 0.006)-comparison_temperature).abs}

min = Float::INFINITY

remenber_min_candidate = 0

(abs_temperature.length).times do |i| 
    if abs_temperature[i] < min
        min = abs_temperature[i]
        remenber_min_candidate = i+1
    end
end

puts remenber_min_candidate

Measured memory_bytes: 1788
'use strict'
function main(input) {
  input = input.split('\n')
  const value = input[1].split(' ')
  const cost = input[2].split(' ')
  let result = 0
  value.forEach((val, i) => {
    const temp = Number(val) - Number(cost[i])
    if (temp > 0) result += temp
  })
  console.log(result)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	private static final int BIG_NUM  = 2000000000;
	private static final int MOD  = 1000000007;

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input_str[] = new String[2];
		Deque<String> list = new ArrayDeque<String>();
		StringBuilder ans = new StringBuilder();

		try {
			int N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				input_str = br.readLine().split("\\s+");

				if(input_str[0].equals("insert")){
					list.addFirst(input_str[1]);
				}else if(input_str[0].equals("delete")){
					list.remove(input_str[1]);
				}else if(input_str[0].equals("deleteFirst")){
					list.removeFirst();
				}else if(input_str[0].equals("deleteLast")){
					list.removeLast();
				}
			}

			if(!list.isEmpty()){
				ans.append(list.getFirst());
				list.removeFirst();
			}
			while(!list.isEmpty()){
				ans.append(" ").append(list.getFirst());
				list.removeFirst();
			}

			System.out.println(ans.toString());

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var H = HW[0];
            var W = HW[1];
            var maps = new char[H][];
            var memo = new int[H][];
            for (var i=0;i<H;i++)
            {
                maps[i] = Console.ReadLine().ToCharArray();
                memo[i] = maps[i].Select(c=>int.MaxValue).ToArray();
            }
            Console.WriteLine(Search(maps, H, W, 0, 0, 0,memo,'.'));

        }

        static int Search(char [][] maps, int H, int W, int y,int x, int cnt,int[][] memo,char prev)
        {
            if (prev == '.' && maps[y][x] == '#') cnt++;
            if(memo[y][x]<=cnt)
            {
                return int.MaxValue;
            }
            memo[y][x] = cnt;
            if (H==y+1&&W==x+1)
            {
                return cnt;
            }
            var cnt1 = int.MaxValue;
            var cnt2 = int.MaxValue;
            if (y + 1 < H)
            {
                cnt1 = Search(maps, H, W, y + 1, x, cnt,memo, maps[y][x]);
            }
            if (x + 1 < W)
            {
                cnt2 = Search(maps, H, W, y, x+1, cnt, memo, maps[y][x]);
            }
            return Math.Min(cnt1,cnt2);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

typedef long long ll;

const ll INF=1000000000000000LL;
class Dinic{
private:
  static const int MAX_V=1001;
  class edge{
  public:
    int to,rev;
    ll cap;
    edge(int to_,ll cap_,int rev_){
      to=to_;
      cap=cap_;
      rev=rev_;
    }
  };
public:
  vector<edge> G[MAX_V];
  // sからの距離
  int level[MAX_V];
  // どこまで調べ終わったか
  int iter[MAX_V];
  void add_edge(int from,int to,ll cap){
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  void init(){
    for(int i=0;i<MAX_V;i++)G[i].clear();
  }
private:
  // sからの最短距離を求める
  void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.push(e.to);
        }
      }
    }
  }
  // 増加パスをdfsで探す
  ll dfs(int v,int t,ll f){
    if(v==t)return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        ll d=dfs(e.to,t,min(f,e.cap));
        if(d>0){
          e.cap-=d;
          G[e.to][e.rev].cap+=d;
          return d;
        }
      }
    }
    return 0;
  }
public:
  // sからtへの最大流を求める
  ll max_flow(int s,int t){
    ll flow=0;
    while(1){
      bfs(s);
      if(level[t]<0)return flow;
      memset(iter,0,sizeof(iter));
      ll f;
      while((f=dfs(s,t,INF))>0)flow+=f;
    }
  }
};


#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N;
int A[101];

int main(){

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

    Dinic d; d.init();
    const int S = N;
    const int T = N + 1;
    ll sum = 0;
    for(int i = 0; i < N; i++) sum += max(0, A[i]);
    for(int i = 0; i < N; i++) {
        if(A[i] <= 0){
            d.add_edge(S, i, abs(A[i]));
        }
        else{
            d.add_edge(i, T, abs(A[i]));
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 2*(i + 1); j <= N ; j += (i + 1)){
            int a = j - 1;
            d.add_edge(i, a, INF);
        }
    }

    cout << sum - d.max_flow(S, T) << endl;
    
    

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <cstring>

#define test(t) while(t--)

#define ll  long long int

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);



using namespace std;

void solve()
{ll k;
  in k;
  string s;
  in s;
  if(s.size()>k){
  for(ll i=s.size();i>k;i--){
    s.pop_back();
  }
  string p="...";
  out s+p<<en;}
  else
    out s<<en;
}

int main(){ fast()
             //freopen("input.txt","r",stdin);
             //freopen("output.txt","w",stdout);
             ll t=1;
            //cin>>t;
            test(t){
            solve();
            }
return 0;}


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

using namespace std;

int main(void){
    string s,t;
    cin>>s>>t;
    int count=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]) count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int K, S;
    int x, y, z;
    int cnt = 0;

    cin >> K >> S;

    for (x = 0; x <= K; ++x){
      for (y = 0; y <= K; ++y){
          if (S - x - y <= K && S - x - y >= 0) cnt++;
      }
    }
    cout << cnt << endl;
}

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

void solve(int n, vector<int>h){
  vector<int>dp(n);
  dp[0] = 0;
  dp[1] = abs( h[0] - h[1] );
  for (int i=2; i<n; i++){
    dp[i] = min(
      (dp[i-2] + abs( h[i-2] - h[i] )),
      (dp[i-1] + abs( h[i-1] - h[i] ))
    );
  }
  cout << dp[n-1];
}

int main(){
  int n; cin>>n;
  vector<int>h(n); rep(i,n) cin>>h[i];
  solve(n,h);
}

Measured memory_bytes: 4584
#include <bits/stdc++.h>
#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 REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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;}

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

  cout << (N-1)*N/2 << endl;
}

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

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

	for (int i = 1; i <= n; i++)
	{
		int x = i;
		if (x % 3 == 0)
		{
			cout << " " << i;
		}else
		{
			for (; x; x /= 10)
			{
				if (x % 10 == 3){
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;
}
	

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
char ar[ MX +2], br [MX+2];
int main(){

    int n;
    I(n);
    if(n < 1200)PC("ABC");
    else if(n < 2800)PC("ARC");
    else PC("AGC");
    return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > v;
	v.resize(N+1);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	bool flag = false;
	for (int i = 0; i < (int)v[1].size(); i++) {
		int next = v[1][i];
		for (int j = 0; j < (int)v[next].size(); j++) {
			if (v[next][j] == N) {
				flag = true;
				break;
			}
		}
		if (flag) break;
	}

	if (flag) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}


Measured memory_bytes: 8576
N, Q = map(int, input().strip().split())
S = input().strip()
queries = [map(int, input().split()) for _ in range(Q)]

countl = [0]
for i in range(1, N+1):
    if S[:i].endswith("AC"):
        countl.append(countl[-1] + 1)
    else:
        countl.append(countl[-1])

for l, r in queries:
    print(countl[r] - countl[l])

Measured memory_bytes: 52108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
        return 0;
    }
    ll res=0;
    ll tmp=5;
    while(n>=tmp){
        res+=(n/tmp)/2;
        tmp*=5;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 384
#include<cstdio>
int H,W;
char a[555][555];
int main(){
	scanf("%d%d",&H,&W);
	for(int i=0;i<H;i++)scanf("%s",a[i]);
	for(int t=0;t<2;t++?1:puts(""))
		for(int i=0;i<H;i++,puts(""))
			for(int j=0;j<W;j++)putchar(".#"[a[i][j]=='#'||(j==W-1||j&&i%2==1)==t]);
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include "cmath"
#include <cstdlib>
#include <string>
#include <utility>

using namespace std;
typedef long long ll;


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

    int n;
    cin >> n;

    cout << 180 * (n - 2) << endl;

    return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long

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

    string s;
    cin >> s;
    for (char c : s) {
        if (c == '7') {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  bool flag=true;
  for(int i=0;i<S.size();i++){
    if((i+1)%2!=0){
      if(S.at(i)=='L'){
        flag=false;
        break;
      }
    }
    else{
      if(S.at(i)=='R'){
        flag=false;
        break;
      }
    }
  }
  if(flag==true){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n,m;
	pair<int,int> p[10010];
	while(cin>>n>>m,n|m){
		set<int> st1,st2;
		st1.insert(1);
		rep(i,m){
			cin >> p[i].first >> p[i].second;
			if( p[i].first==1 || p[i].second==1 ){
				st1.insert( p[i].first );
				st1.insert( p[i].second );
			}
		}
		rep(i,m){
			if( st1.find(p[i].first)!=st1.end() && st1.find(p[i].second)==st1.end() ){
				st2.insert( p[i].second );
			}
			if( st1.find(p[i].second)!=st1.end() && st1.find(p[i].first)==st1.end() ){
				st2.insert( p[i].first );
			}
		}
		
		cout << (st1.size()-1)+(st2.size()) << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int N,A,odd=0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        odd += A%2;
    }

    if(odd%2==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dfs(ll h){
  if(h==1){
    return 1;
  }
  return dfs(h/2)*2+1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll h;
  cin>>h;
  cout<<dfs(h)<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  ll n,d=1000000;
  while(cin >> n && n)  {
    map<ll,ll> m,m2,m3;
    set<ll> se;
    m.clear();
    m2.clear();
    m3.clear();
    se.clear();
    rep(i,n) {
      ll x,y,z;
      cin >> x >> y >> z;
      if(se.count(x)) {
	m2[m[x]]+=y*z;
      } else {
	m[x]=m.size()+1;
	m3[m[x]]=x;
	se.insert(x);
	m2[m[x]]=y*z;
      }
    }
    bool ck=true;
    tr(it,m2) {
      iter(m3) it2=m3.find(it->F);
      if(it->S>=d) {
	cout <<it2->S << endl;
	ck=false;
      }
    }
    if(ck) pr("NA");
  }
  return 0;
}


Measured memory_bytes: 1424
#include<stdio.h>
int main()
{
	int n,m,i,t=1;
	char a[100];
	scanf("%d%d",&n,&m);
	scanf("%s",a);
	for(i=0;i<n;i++)if(a[i]<'0'||a[i]>'9')t=0;
	if(a[n]!='-')t=0;
	for(i=n+1;i<n+1+m;i++)if(a[i]<'0'||a[i]>'9')t=0;
	if(t==0)printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b, c; cin>>a>>b>>c;
	int k; cin>>k;
	for(int i=0; i<=k; i++){
		for(int j=0; i+j<=k; j++){
			for(int l=0; i+j+l<=k; l++){
				if(a*(1<<i)<b*(1<<j) && b*(1<<j)<c*(1<<l)){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3536
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort()
B.sort()
C.sort()

lenC = len(C)

cnt = 0

for b in B:
    ind_a = bisect.bisect_left(A, b)
    ind_c = bisect.bisect_right(C, b)
    cnt += ind_a * (lenC - ind_c)

print(cnt)

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  
  int ans = n/x;
  if(n%x != 0)
    ans++;
  ans *= t;
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
int main(){
    int n, q;
    sc(n), sc(q);
    string s; cin >> s;
    vector<int> ac(n,0);
    for (int i = 1; i < n; i++){
        if (s[i-1]=='A' && s[i]=='C') ac[i]=ac[i-1]+1;
        else ac[i] = ac[i-1];
    }
    int l, r;
    for (int i = 0; i < q; i++){
        sc(l), sc(r);
        l--; r--;
        cout << ac[r] - ac[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for(auto &x: A) cin >> x;

	sort(A.begin(), A.end());

	int a = A[(N - 1) / 2], b = A[N / 2];
	cout << b - a << endl;
}


Measured memory_bytes: 640
def c_write_and_erase(N, A):
    from collections import Counter
    # 奇数回言われた数字だけが最後に残る
    return len([1 for v in Counter(A).values() if v % 2 == 1])

N = int(input())
A = [int(input()) for i in range(N)]
print(c_write_and_erase(N, A))

Measured memory_bytes: 16660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

void a(){
	cout << "NA" << endl;
	return;
}

int main(){
	int n;
	vector<string> sample;
	string aaa;

	cin >> n;
	for(int i=0;i<n;i++){
		cin >> aaa;
		sample.push_back(aaa);
	}

	for(unsigned int i=0;i<sample.size();i++){
		string snake = sample[i];
		string::size_type aruyon;

		if((aruyon = snake.find(">'"))==0){
			int equal=0;
			int j;
			for(j=2;snake.at(j)=='=';j++) equal++;
			if(equal > 0)
				if(snake.at(j) == '#'){
					j++;
					for(;snake.at(j)=='=';j++) equal--;
					if(equal == 0){
						if(snake.at(j)=='~' && j+1 == snake.size()) cout << 'A' << endl;
						else a();
					}
					else a();
				}
				else a();
			else a();
		}
		else if((aruyon = snake.find(">^"))==0){
			int j;
			bool dou = false;
			aruyon = snake.find("~~");
			if(aruyon == snake.size() -2){
				if(aruyon%2==0){
					for(j=2;j<aruyon;j++){
						dou = false;
						if(snake.at(j) == 'Q') j++;
						else break;	
						if(snake.at(j) == '=') dou = true;
						else break;
					}
					if(dou) cout << 'B' << endl;
					else a();
				}
				else a();
			}
			else a();
				
		}
		else
			a();
	}

  return 0;
}

Measured memory_bytes: 1444
fetchStrNum = input()

strLength = len(fetchStrNum)

constStrLength = 3

favoriteNum = 753

ans = abs(favoriteNum - int(fetchStrNum))

length = strLength - constStrLength

tempNum = 1000
for i in range(length + 1):
    ans = abs(favoriteNum - int(fetchStrNum[i:3 + i]))

    if ans == 0:
        tempNum = 0
        break

    if tempNum > ans:
        tempNum = ans

print(tempNum)


Measured memory_bytes: 3316
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        var p = 0;
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var q = int.Parse(line[0]);
            if (q == 0)
            {
                var q2 = int.Parse(line[1]);
                a[p++] = q2;
            }
            else if (q == 1)
            {
                var q2 = int.Parse(line[1]);
                Console.WriteLine(a[q2]);
            }
            else p--;
        }
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: 001_apc_c / Link: https://apc001.contest.atcoder.jp/tasks/apc001_c?lang=en  ----- */
/* ------問題------

N を 3 以上の奇数とします。
N 個の席が円状に並んでいます。 席には 0 から N−1 まで番号が振られています。 各 i (0≤i≤N−2) について、席 i と席 i+1 は隣り合っています。 また、席 N−1 と席 0 は隣り合っています。
各席の状態は「空席」「男性が座っている」「女性が座っている」のどれかです。 ただし、同性どうしが隣り合う席に座っていることはありません。 N が 3 以上の奇数の場合、空席が少なくとも 1 つは存在することが示せます。
あなたには N のみが与えられ、各席の状態は与えられません。 あなたの目標は、どれか 1 つの空席の番号を当てることです。 そのために、あなたは次のクエリを繰り返し送ることができます。
整数 i (0≤i≤N−1) を選ぶ。 席 i が空席ならば、正答となる。 そうでなければ、席 i に座っている人の性別が知らされる。
クエリを高々 20 回まで送ることで、どれか 1 つの空席の番号を当ててください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

bool react(int x) {
	cout << x << endl;
	string ret;
	cin >> ret;
	if (ret == "Vacant") exit(0);
	return (ret == "Male");
}

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

	cin >> N;
	bool start = react(0);
	react(N - 1);
	int low = 1, high = N;

	while (1) {
		const int mid = (low + high) / 2;
		bool cur = react(mid);
		if (mid % 2 == (start != cur)) {
			low = mid + 1;
		}
		else {
			high = mid;
		}
	}

	return 0;
}


Measured memory_bytes: 852
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()
	n := len(s)
	if n == 1 {
		fmt.Println(1)
		return
	}

	dp := make([][2]int, n+1)
	// dp[i][j]  i文字目で最大値
	// j=0 直前は1文字
	// j=1 直前は2文字
	dp[1][0] = 1
	if s[0] == s[1] {
		dp[2][0] = 1
	} else {
		dp[2][0] = 2
	}
	for i := 3; i < n+1; i++ {
		if s[i-1] != s[i-2] {
			dp[i][0] = dp[i-1][0] + 1
		}

		dp[i][0] = max(dp[i][0], dp[i-1][1]+1)
		dp[i][1] = max(dp[i][1], dp[i-2][0]+1)
	}

	//	fmt.Println(dp)
	fmt.Println(max(dp[n][0], dp[n][1]))
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	//	sc.Split(bufio.ScanWords)
	sc.Split(bufio.ScanLines)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5396
module Main where
import Control.Applicative((<$>))
import Data.List(sort)


main :: IO ()
main = do
  (a:b:c:_) <- (map show) <$> sort <$> (map atoi ) <$> words <$> getLine
  putStrLn $ a ++ " " ++ b ++ " " ++ c
  where
    atoi x = read x :: Int

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>

using namespace std;

const double EPS=1e-10;
bool EQ(double a,double b){
	return abs(a-b)<EPS;
}

int n;
int xs[101];
int ys[101];
int rs[101];
int cs[101];
char dp[1<<24];
bool isNoCross(int a,int b){
	double sumR=rs[a]+rs[b];
	double dist=sqrt(1.0*(xs[a]-xs[b])*(xs[a]-xs[b])+(ys[a]-ys[b])*(ys[a]-ys[b]));
	if(EQ(sumR,dist)||sumR<dist)return true;
	return false;
}

bool isOver(int a,int b){
	if(isNoCross(a,b))return true;
	return a<b;
}

int dfs(int mask){
	if(dp[mask]>=0)return dp[mask];
	if(mask==(1<<n)-1)return 0;
	int res=0;
	int lt[30];
	int sz=0;
	for(int i=0;i<n;i++){
		bool ok=true;
		if((mask>>i)&1)continue;
		for(int j=0;j<n;j++){
			if(i==j)continue;
			if((mask>>j)&1)continue;
			if(!isOver(i,j)){
				ok=false;
				break;
			}
		}
		if(ok)
			lt[sz++]=i;
	}
	for(int i=0;i<sz;i++){
		for(int j=i+1;j<sz;j++){
			int a=lt[i];
			int b=lt[j];
			if(cs[a]==cs[b]){
				int nmask=mask;
				nmask|=(1<<a);
				nmask|=(1<<b);
				res=max(res,dfs(nmask)+2);
			}
		}
	}
	return dp[mask]=res;
}

void solve(){

	while(cin>>n&&n){
		memset(dp,-1,sizeof(dp));
		for(int i=0;i<n;i++)
			cin>>xs[i]>>ys[i]>>rs[i]>>cs[i];
		int res=dfs(0);
		cout<<res<<endl;
	}
}
int main(){

	solve();

	return 0;
}

Measured memory_bytes: 16000
def selection(X, A, B, C):
    if X == 'a':
        if len(A) == 0:
            print('A')
            return
        else:
            Y = A.pop(0)
    if X == 'b':
        if len(B) == 0:
            print('B')
            return
        else:
            Y = B.pop(0)
    if X == 'c':
        if len(C) == 0:
            print('C')
            return
        else:
            Y = C.pop(0)
    selection(Y, A, B, C)

def main():
    Sa = list(input())
    Sb = list(input())
    Sc = list(input())
    selection('a', Sa, Sb, Sc)

main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int a,b;
    cin >> a >> b;

    rep(i,1000000){
		int x=0.08*i;
      	int y=0.1*i;
        if(x==a && y==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int a, b;

  while ( scanf ( "%d %d", &a, &b ) == 2 )
  {
    int x = a + b;
    int res = 0;

    while ( x )
    {
      x /= 10;
      ++res;
    }
    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;
using posteriority_queue = priority_queue<int, vi, greater<int>>;
 
//DP template
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;} 
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
vll dp(1000000, INF);

//mod template
const ll MOD = 1000000007;

//input var
int N;

int main() {
    //input
    cin >> N;
    // for (int i = 0; i < N; i++) cin >> a.at(i);
     
    //IC
    dp.at(0) = 0;


    //loop
    for (int i = 0; i <= N; i++) {
        int tmp;
        // case 1
        chmin(dp.at(i+1), dp.at(i)+1);
        
        // case 6
        tmp = 6;
        while(i+tmp <= N){
            chmin(dp.at(i+tmp), dp.at(i)+1);
            tmp*=6;
        }

        // case 9
        tmp = 9;
        while(i+tmp <= N){
            chmin(dp.at(i+tmp), dp.at(i)+1);
            tmp*=9;
        }
    }

    //output
    cout << dp.at(N) << endl;

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int D, G;
vector<int> p, c;
vector<tuple<int, int, string>> solved;

void calc(int n, int scr, int cst, string sol) {
	if (n == D) {
		solved.push_back(make_tuple(scr, cst, sol));
		// printf("%s, %d, %d\n", sol.c_str(), cst, scr);
		return;
	}
	calc(n + 1, scr, cst, sol + '0');
	calc(n + 1, scr + 100*(n+1)*p[n] + c[n], cst + p[n], sol + '1');
}

int main () {
	cin >> D >> G;
	p.resize(D), c.resize(D);
	rep(i, D) cin >> p[i] >> c[i];

	calc(0, 0, 0, "");
	// sort(all(solved));
	int ans = INF;
	rep(i, solved.size()) {
		int scr = get<0>(solved[i]), cst = get<1>(solved[i]);
		string sol = get<2>(solved[i]);
		if (scr < G) {
			for (int j = sol.size() - 1; j >= 0; --j) {
				if (sol[j] == '0') {
					double d = G - scr;
					scr += 100*(j+1)*p[j];
					cst += min(p[j], (int)ceil(d / (100*(j+1))));
					break;
				}
			}
		}
		// printf("%s, %d, %d\n", sol.c_str(), cst, scr);
		if (scr >= G) ans = min(ans, cst);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>> v;
long long vb[53][53], cb[53];

long long dfs(int parent, int cur, int dest) {
	long long ret = 0;
	for(int c: v[cur]) {
		if (parent == c) continue;
		if (c == dest) return vb[cur][c];
		ret = dfs(cur, c, dest);
		if (ret) {
			ret |= vb[cur][c];
			break;
		}
	}
	return ret;
}

std::vector<std::vector<int>> iig(int vn, int en) {
	std::vector<std::vector<int>> res(vn);
        for(int i = 0; i < en; i++) {
                int s, t;
                std::cin >> s >> t;
                s--; t--;
                res[s].push_back(t);
                res[t].push_back(s);
		vb[s][t] = vb[t][s] = 1LL << i;
        }
        return res;
}

int main() {
	cin >> n;
	v = iig(n, n - 1);
	cin >> m;
	for(int i = 0; i < m; i++) {
		int ui, vi;
		cin >> ui >> vi;
		ui--; vi--;
		cb[i] = dfs(-1, ui, vi);
	}
	int f = 1;
	long long res = 0;
	for(int i = 1; i <= m; i++) {
		vector<bool> bitmask(m - i, false);
		bitmask.resize(m, true);
		do {
			long long bits = 0;
			for(int i = 0; i < m; i++) {
				if (bitmask[i]) bits |= cb[i];
			}
			int count_ones = __builtin_popcountll(bits);
			int count_zeros = n - 1 - count_ones;
			if (f) {
				res += 1LL << count_zeros;
			} else {
				res -= 1LL << count_zeros;
			}
		} while(next_permutation(bitmask.begin(), bitmask.end()));
		f ^= 1;
	}
	cout << (1LL << (n - 1)) - res << endl;
}








Measured memory_bytes: 256
#include <stdio.h>
int main(){

	int a, h, m;
	scanf("%d", &a);
	h = a / 3600;
	a = a - ( h*3600 );
	m = a / 60;
	a = a - ( m * 60);
	printf("%d:%d:%d\n", h, m, a);

return 0;
}


Measured memory_bytes: 2140
#include <iostream>
//#include <bits/stdc++.h>
// a&1 check odd or not and a>>=1 halfs a
// (n-1-i)%i previous in circle (i+n-1)%n next one
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
using namespace std;

string s;
void solve(){
	cin>>s;
	int sum=0;
	for(int i=0;i<int(s.size());i++){
		if(s[i]=='g'){
			sum++;
		}
		else{
			sum--;
		}
	}
	if(sum>0){
		cout<<sum/2<<endl;
	}
	else{
		cout<<sum<<endl;
	}
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	solve();


	return 0;
}



Measured memory_bytes: 512
package main

import "fmt"

const N = 1e5+5

type Vertex struct {
  indegree int
  maxlen int
  adj []*Vertex
}

func (v *Vertex) add(u *Vertex) {
  v.adj = append(v.adj, u)
}

func (v *Vertex) incIndegree() {
  v.indegree++
}

func (v *Vertex) decIndegree() {
  v.indegree--
}

func umax(current *int, val int) {
  if val > *current {
    *current = val
  }
}

type Queue []*Vertex

func (q *Queue) Push(v *Vertex) {
  *q = append(*q, v)
}

func (q *Queue) Pop() *Vertex {
  old := *q
  *q = old[1:]
  return old[0]
}

func (q Queue) Empty() bool {
  return len(q) == 0
}

func main() {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)
  vs := make([]*Vertex, n)
  for i := 0; i < n; i++ {
    vs[i] = &Vertex{
      indegree: 0,
      maxlen: -1,
    }
  }
  for i := 0; i < m; i++ {
    var x, y int
    fmt.Scanf("%d %d", &x, &y)
    x--
    y--
    vs[x].add(vs[y])
    vs[y].incIndegree()
  }
  q := make(Queue, 0)
  for i := 0; i < n; i++ {
    if vs[i].indegree == 0 {
      q.Push(vs[i])
    }
  }
  maxlen := 0
  for !q.Empty() {
    current := q.Pop()
    for i := 0; i < len(current.adj); i++ {
      next := current.adj[i]
      umax(&next.maxlen, current.maxlen + 1)
      umax(&maxlen, next.maxlen)
      next.decIndegree()
      if next.indegree == 0 {
        q.Push(next)
      }
    }
  }
  fmt.Println(maxlen+1)
}

Measured memory_bytes: 16384
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, C, opt = INF, per[5], cst[35][35];
bool used[35];
int grp[5][35];

int main(){
  FAST_IO

  cin >> N >> C;

  for(int r = 1; r <= C; ++r){
    for(int c = 1; c <= C; ++c){
      cin >> cst[r][c];
    }
  }

  for(int r = 1; r <= N; ++r){
    for(int c = 1, x; c <= N; ++c){
      cin >> x;
      grp[(r + c) % 3][x]++;
    }
  }

  for(int o = 1; o <= C; ++o){
    for(int t = o + 1; t <= C; ++t){
      for(int th = t + 1, cost; th <= C; ++th){
        per[0] = o, per[1] = t, per[2] = th;
        do{
          cost = 0;
          for(int g = 0; g < 3; ++g){
            for(int c = 1; c <= C; ++c){
              cost += grp[g][c] * cst[c][per[g]];
            }
          }

          min_self(opt, cost);
        }while(next_permutation(per, per + 3));
      }
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n,k;
ll mn=1000000000000000000;
cin>>n>>k;
if(k>=n)
{
cout<<min(n,k-n)<<endl;
}
else
{
cout<<min(n%k,k-n%k)<<endl;
}
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)

def eat(level, X):
    if X == 0:
        return 0
    if level == 0:
        return X
    if (X-1) <= T_array[level-1]:
        return eat(level-1, X-1)
    else:
        return P_array[level-1] + 1 + eat(level-1, min(X-T_array[level-1]-2, T_array[level-1]))


N, X = map(int, input().split())

P_array = [0] * 51
B_array = [0] * 51
T_array = [0] * 51
P_array[0] = 1
B_array[0] = 0
T_array[0] = 1

for i in range(1, 51):
    P_array[i] = P_array[i-1]*2 + 1
    B_array[i] = B_array[i-1]*2 + 2
    T_array[i] = P_array[i] + B_array[i]

print(eat(N,X))

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
int64_t mod;
class ModInt {
private:
	int64_t integer_;

public:
	ModInt(const int64_t initial_number = 0)
		: integer_(initial_number) {}
	
	// 四則演算
	ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod)
			ret.integer_ -= mod;
		return ret;
	}
	ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod;
		return ret;
	}
	ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod};
	}
	// 代入
	ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	operator int64_t() { return integer_; }
};

using Mint = ModInt;
using vi = std::vector<Mint>;
void output(std::vector<vi>& mat)
{
	for (auto& e: mat)
	{
		for (auto& f: e)
			std::cout << f << ' ';
		std::cout << std::endl;
	}
	std::cout << std::endl;
}

int main()
{
	int p;
	scanf("%d", &p);
	mod = p;
	std::vector<Mint> inv(p), a(p);
	inv[0] = inv[1] = Mint(1ll);
	for (int i{2}; i < p; i++)
		inv[i] = (Mint(0ll) - inv[p % i]) * Mint(p / i);
	for (auto& e: a) scanf("%d", &e);
	for (int row{}; row < p - 1; row++)
		for (int other_row{row + 1}; other_row < p; other_row++)
		{
			a[other_row] -= a[row];
			a[other_row] *= inv[other_row - row];
		}
	for (int col{p - 2}; col >= 0; col--)
		for (int row{col}; row < p - 1; row++)
			a[row] -= a[row + 1] * Mint(col);
	
	for (int i{}; i < p; i++)
		std::cout << a[i] << (i == p - 1? '\n': ' ');
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
 int n;
 cin >> n;
 vector<int> p(n);
 vector<int> q(n);
 rep(i,n) cin >> p.at(i);
 rep(i,n) cin >> q.at(i);
 vector<int> x(n);
 rep(i,n) x.at(i) = i+1;
 int cnta,cntb,cnt = 1;
 do{
   if(x == p)cnta = cnt;
   if(x == q)cntb = cnt;
   cnt++;
 }while(next_permutation(x.begin(),x.end()));
 cout <<abs(cnta-cntb) << endl;

 
}

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

using namespace std;
int main()
{

long int a,b,i,c=0,ans;
cin>>a>>b;
if(a<b)
{
for(i=a;i<=b;i++)
{
  if(abs(a-i)==abs(b-i))  
        {
        c++;
ans=i;
           break; 
        
    }
    

}
if(c==0)
cout<<"IMPOSSIBLE"<<endl;
else

cout<<i<<endl;
}

else 
{

for(i=b;i<=a;i++)
{
  if(abs(a-i)==abs(b-i))  
        {
        c++;
ans=i;
           break; 
        
    }
    

}
if(c==0)
cout<<"IMPOSSIBLE"<<endl;
else

cout<<i<<endl;

}






return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c;
    if(a<=c&&c<=b)Cout("Yes");
    else Cout("No");
    return 0;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	double n;
	cin >> n;
	int x;
	for (int i = 1; i <= n; i++) {
		if (n == floor(i * 1.08)) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Vector2 {
	public Vector2(double x, double y) {
		this.x = x;
		this.y = y;
	}
	public static Vector2 sub(Vector2 a, Vector2 b) {
		return new Vector2(a.x - b.x, a.y - b.y);
	}
	public static double cross(Vector2 a, Vector2 b) {
		return a.x * b.y - a.y * b.x;
	}
	public double x, y;
}

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			Vector2 a = new Vector2(scanner.nextDouble(), scanner.nextDouble());
			Vector2 b = new Vector2(scanner.nextDouble(), scanner.nextDouble());
			Vector2 c = new Vector2(scanner.nextDouble(), scanner.nextDouble());
			Vector2 p = new Vector2(scanner.nextDouble(), scanner.nextDouble());
			Vector2 ab = Vector2.sub(b, a);
			Vector2 bp = Vector2.sub(p, b);
			Vector2 bc = Vector2.sub(c, b);
			Vector2 cp = Vector2.sub(p, c);
			Vector2 ca = Vector2.sub(a, c);
			Vector2 ap = Vector2.sub(p, a);
			double c0 = Vector2.cross(ab, bp);
			double c1 = Vector2.cross(bc, cp);
			double c2 = Vector2.cross(ca, ap);
			if ((c0 > 0 && c1 > 0 && c2 > 0) || (c0 < 0 && c1 < 0 && c2 < 0)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 29;
 
int main() {
	ll n;
	cin >> n;
	bool all9 = true;
	int cnt = 0;
	while (n >= 10)
	{
		if (n % 10 != 9) all9 = false;
		n /= 10;
		cnt++;
	}
	int ans = n + cnt * 9;
	if (all9) cout << ans << endl;
	else cout << ans -1 << endl;
}

Measured memory_bytes: 256