akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

using ll = long long;

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

	ll money = 100;
	ll count = 0;
	while (money < X)
	{
		money = money * 1.01;
		count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3636
import math
import itertools

INF = 10**9+7
n = 0
def main():
	n,m = map(int,input().split())
	ans = 0
	if(n*2<m):
		ans += n
		m -= 2*n
	else:
		print(int(m/2))
		return
	ans += int(m/4)
	print(ans)

main()


Measured memory_bytes: 3064
s = input()
flag = True

for i in range(1, len(s) + 1):
    
    if i % 2 == 1:
        if s[i-1] == 'L':
            flag = False
            
    else:
        if s[i-1] == 'R':
            flag = False

if flag:
    print('Yes')
else:
    print('No')

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

#define int long double
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
    cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

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

    priority_queue<int,vector<int>,std::greater<int>> pq;

    for(int i=0;i<n;i++){
        int x; cin >> x;
        pq.push(x);
    }

   
    

    while(pq.size()>1){
        int a = pq.top();
        pq.pop();
        int b = pq.top();
        pq.pop();
        int ans = (a+b)/2.0;
        pq.push(ans);
    }

    cout << pq.top() << '\n';
 
 
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int N,X;
    cin >> N >> X;
    vector<int>m(N);
    int sum=0;
    for(int i=0;i<N;i++){cin >> m.at(i);
        sum+=m.at(i);}
        sort(m.begin(),m.end());
        cout << N+(X-sum)/m.at(0) << endl;

}


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

int main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	m1 += 60 * h1;
	m2 += 60 * h2;

	cout << (m2 - k - m1) << endl;

	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.function.DoubleToIntFunction;

public class Main {
    public static boolean debug = true;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        double[] input = new double[n];

        double temp =0;
        for(int i =0; i<n ; i++){
            input[i] = sc.nextDouble();

            temp = temp + (1/input[i]);
        }

        System.out.println(1/temp);


    }
    public static void d(String message){
        if(debug){
            System.out.println(message);
        }
    }
}


Measured memory_bytes: 25172
#include <stdio.h>
#include <stdlib.h>
int main(){
       int n,m,a,b,sta[200010]={0},flag=0;
       scanf("%d%d",&n,&m);
       for(int i=0;i<m;i++){
              scanf("%d%d",&a,&b);
              if(a==1){
                     sta[b]++;
                     if(sta[b]==2) flag=1;
              }
              if(b==n){
                     sta[a]++;
                     if(sta[a]==2) flag=1;
              }
       }
       if(flag) printf("POSSIBLE");
       else printf("IMPOSSIBLE");
       return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{ vector <int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin>>n;
  cout<<a[n-1];
}

Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef pair<int,int> P;

vector<vector<int>> G;
vector<int> c;
vector<int> w;

int main(int argc, char const *argv[]) {
  int n,m;cin>>n>>m;
  G=vector<vector<int>>(n);
  for(int i=0;i<m;i++){
    int u,v;cin>>u>>v;u--;v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  c=vector<int>(n);
  w=vector<int>(n);
  int q;cin>>q;
  vector<int> vs(q),ds(q),ccs(q);
  for(int i=0;i<q;i++){
    // int v,d,cc;cin>>v>>d>>cc;
    cin>>vs[i]>>ds[i]>>ccs[i];
  }
  for(int i=q-1;i>-1;--i){
    int v=vs[i],d=ds[i],cc=ccs[i];
    v--;
    queue<int> que;
    map<int,int> dist;
    dist[v]=0;
    if(w[v]<d+1-dist[v]){
      w[v]=d+1-dist[v];
      que.push(v);
    }
    if(c[v]==0)c[v]=cc;
    int t=0;
    while(que.size()){
      int u=que.front();que.pop();
      t++;
      if(dist[u]<=d&&c[u]==0)c[u]=cc;
      for(int uu:G[u]){
        if(dist.find(uu)==dist.end()){
          if(dist[u]<=d){
            // que.push(uu);
            dist[uu] = dist[u]+1;
            if(w[uu]<d+1-dist[uu]){
              w[uu]=d+1-dist[uu];
              que.push(uu);
            }
          }
        }
      }
    }
  }
  for(int i=0;i<n;++i)cout<<c[i]<<endl;
  // cout<<endl;
  return 0;
}


Measured memory_bytes: 13560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  string ans=s.substr(0,3);
  
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    char a;
    cin >> a;
    if (a == 'Y') ok = true;
  }
  if (ok) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,j,H,W;

  for(scanf("%d%d",&H,&W);H!=0||W!=0;scanf("%d%d",&H,&W)){
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        putchar((i+j)%2?'.':'#');
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 1000
from itertools import product

n = int(input())
i = 3
ans = 61
dpm = {
    "".join(k): 1
    for k in product("ACGT", repeat=3)
}
for k in ("AGC", "ACG", "GAC"):
    dpm[k] = 0

MOD = 1000000007

while i < n:
    ndpm = {k: 0 for k in dpm}
    for k in dpm:
        for c in "ACGT":
            ns = k + c
            if ns[-3:] in ("AGC", "ACG", "GAC") or \
                    (ns[0] == "A" and ns[-2:] == "GC") or \
                    (ns[0:2] == "AG" and ns[-1] == "C"):
                continue
            ndpm[ns[-3:]] += dpm[k] % MOD
    dpm = ndpm
    i += 1

print(sum(dpm.values()) % MOD)


Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))
H[0]-=1
for i in range(N-1):
    if H[i+1] - H[i] > 0:
        H[i+1]-=1
    if H[i] - H[i+1] > 0:
        print('No')
        exit()
print('Yes')

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

typedef long long ll;

int n, k;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    int res = 0;
    while (n) {
        n = n / k;
        ++res;
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

string solution(string input)
{
	string res(input);
	for(int i = 0; i < (int)input.length(); i++) {
		if(input[i] == '?'){
			if(i > 0) {
				if(input[i-1] == 'P') {
					input[i] = 'D';
					continue;
				}
			}
			if(i <= (int) input.length() - 2) {
				if(input[i+1] == '?' || input[i+1] == 'D') {
					input[i] = 'P';
				} else
					input[i] = 'D';
			} else { 
				input[i] = 'D';
			}
		}
	}
	return input;
}

int main()
{
	string input;
	cin >> input;
	string res = solution(input);
	cout << res << endl;
	return 0;
}


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

 int main() {
        double n,a,b;
        scanf("%lf %lf",&a,&b);
        n = (a+b)/2.0;
        if(floor(n)==ceil(n))
        printf("%.0lf\n",n);
        else
        printf("IMPOSSIBLE\n");
        
     
        
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n;
    cin >> n;
    string a[n], b[n], esc;
    bool ch = false;
    
    //input
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        b[i] = a[i];
    }
    
    //bubble
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(a[j][1] < a[j-1][1]){
                esc = a[j];
                a[j] = a[j-1];
                a[j-1] = esc;
            }
        }
    }
    
    //selection
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(b[j][1] < b[minj][1]){
                minj = j;
            }
        }
        esc = b[i];
        b[i] = b[minj];
        b[minj] = esc;
    }
    
    //stable check
    for(int i=0;i<n;i++){
        if(a[i]!=b[i]){
            ch = true;
            break;
        }
    }
    
    //output
    for(int i=0;i<n;i++){
        cout << a[i];
        if(i!=n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    cout << "Stable" << endl;
    
    for(int i=0;i<n;i++){
        cout << b[i];
        if(i!=n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    
    if(ch == false){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *　Lesson2B　３つの整数 a 、b 、c  を読み込み、
 *a  から b  までの整数の中に、c  の約数がいくつあるかを求めるプログラム
 * @author 前島佑介
 * @version 2014/12/1
 */
class Main {

	// プログラムのエントリポイント
	public static void main(String[] args) {

		//入力値1つ目
		int intNum1 = 0;

		//入力値2つ目
		int intNum2 = 0;

		//入力値3つ目
		int intNum3 = 0;

		int intAnswer = 0;

		try{
			//キーボードからの入力準備
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			//キーボードからの入力をString型で受け取る
			String strLine = br.readLine();

			//文字列の分割:入力値を" "で分ける
			//分けた文字列はstrLineAry[0]とstrLineAry[1]とstrLineAry[2]に分けられる
			String[] strLineAry = strLine.split(" ");

			//入力値の１つ目の値
			intNum1 = Integer.parseInt(strLineAry[0]);

			//２つ目の値
			intNum2 = Integer.parseInt(strLineAry[1]);

			//３つ目の値
			intNum3 = Integer.parseInt(strLineAry[2]);

			//aからｂの値でループ
			for(int i = intNum1; i <= intNum2; i++) {

				//aからbの値がintNum3の剰余0ならカウントする
				if(intNum3 % i == 0) {

					//約数があるのでカウント
					intAnswer++;
				}
			}

			//結果を出力
			System.out.println(intAnswer);





			//例外処理
			}catch(IOException e) {

				//例外時の出力
				System.out.println(e);

			}catch(NumberFormatException e) {

				//数値以外の入力値で出力
				System.out.println("数値で入力して下さい");
			}
	}
}

Measured memory_bytes: 17028
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string a,b;
	cin>>a>>b;
	for(int i=0;i<b.size();i++){
		cout<<a[i]<<b[i];
	}
	if(a.size()!=b.size()){
		cout<<a[b.size()];
	}
	cout<<endl;
}

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


double w, h;
bool BMI() {
	if (w / (h * h) >= 25) {
		return true;
	}
	else {
		return false;
	}

}

int main() {
	int s;
	char a, b;
	while (cin >> s >> a >> w >> b >> h ) {
		if (BMI()) {
			cout << s << endl;
		}
	}
}


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

int main(){
    int a[5], k;

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

    cin >> k;

    for (int i=0;i<5;i++) for (int j=i+1;j < 5;j++) {
        if (k < abs(a[i] - a[j])) {
            cout << ":(" << endl;
            return 0;
        }
    }

    cout << "Yay!" << endl;
    return 0;
}

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

int main() {
	int N, X; cin >> N >> X;
	vector<int> L(N);
	for (int i = 0; i < N; i++) cin >> L[i];

	long long int ans = 1;
	long long int d = 0;

	for (int i = 0; i < N; i++) {
		d += L[i];
		if (d <= X) ans++;
	}
	
	cout << ans << endl;
}

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

int main(){
  int n, m, s, t;
  cin >> n >> m;
  vector<int> vec(n);
  for(int i = 0; i < n; i++)
    vec.at(i) = 0;
  for(int i = 0; i < m; i++){
    cin >> s >> t;
    if(s != t){
      for(int j = 0; j < n;j++){
        if(s == j + 1)
          vec.at(j)++;
        if(t == j + 1)
          vec.at(j)++;
      }
    }
  }
  for(int i = 0; i < n; i++)
    cout << vec.at(i) << endl;
}

Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

max_x = max(max(x), X)
min_y = min(min(y), Y)

if max_x < min_y:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var target = Console.ReadLine().Split(' ').Select(int.Parse).Distinct();
            Console.ReadLine();
            var from = Console.ReadLine().Split(' ').Select(int.Parse);
            Console.WriteLine(from.Select(e => target.Count(f => f == e)).Sum());
        }
    }
}


Measured memory_bytes: 30392
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]

count = 0
for i in range(H):
    count_row = 0
    for j in range(W):
        if s[i][j] == "#":
            count_row += 1
            count += 1
        ans[i][j] = max(count_row, 1) + count-count_row
    if count_row==0:
        if count != 0:
            ans[i] = ans[i-1]
    if count != 0 and count==count_row:
        for ii in range(i):
            ans[ii] = ans[i]
for an in ans:
    print(*an)

Measured memory_bytes: 7588
#coding :utf-8
A,B,C,K=map(int,input().split())
cnt=0
if K-A > 0:
  cnt=A
  if K-A-B >0:
    cnt=cnt-(K-A-B)
    print(cnt)
  else:
    print(cnt)
else:
  print(K)
  

Measured memory_bytes: 9176
l = input()
while l != '0 0 0':
    l_split = l.split(' ')
    athletes = int(l_split[0])
    winner = int(l_split[1])
    percent = int(l_split[2])
    total_ticket = 0
    win_ticket = 0
    for i in range(athletes):
        tickets = int(input())
        total_ticket += tickets
        if i + 1 == winner and tickets > 0:
            win_ticket = tickets
    if win_ticket > 0:
        total_money = total_ticket*(100 - percent)
        print(str(total_money//win_ticket))
    else:
        print('0')
    l = input()


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

int main() {
	int hp, number;
	cin >> hp >> number;

	int damege[number];
	int result = 0;
	for (int i = 0; i < number; i++) {
		cin >> damege[i];
		result = result + damege[i];
	}
	if((hp - result) > 0) {
		cout << "No" << '\n';
	} else {
		cout << "Yes" << '\n';
	}

	return 0;
}


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

int twice(int a){
  if(a%4==0) return 2;
  else if(a%2==0 && a!=4) return 1;
  else return 0;
}

int main() {
  int N; cin>>N;
  vector<int> A(N);
  bool ikeru=1;
  int count0=0;
  int count1=0;
  int count2=0;
  for(int i=0; i<N; i++){
    int a; cin>>a;
    A[i]=twice(a);
    if(A[i]==0){
      ikeru=0;
      count0++;
    }
    if(A[i]==1) count1++;
    if(A[i]==2) count2++;
  }
  if(ikeru) cout<<"Yes"<<endl;
  else{
    if(count2>=count0) cout<<"Yes"<<endl;
    if(count0-count2==1 && count1==0) cout<<"Yes"<<endl;
    else if(count2<count0) cout<<"No"<<endl;
  }
}

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

int main() {
char C;
cin >> C;
string s = "abcdefghijklmnopqrstuvwxyz";
for (int i = 0; i < s.size(); i++) {
  if (C == s.at(i)) {
		cout << s.at(i + 1) << endl;
  }
}
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private int N;
    private int K;
    private long[] a;
 
    private void solve(Scanner sc, PrintWriter out) {
        N = sc.nextInt();
        K = sc.nextInt();
        a = new long[N];
        long max = 0;
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextLong();
            max += Math.max(a[i], 0);
        }
        long add = 0;
        long sub = 0;
        for (int i = 0; i < K; ++i) {
            add += Math.max(a[i], 0);
            sub += Math.min(a[i], 0);
        }
        long min = Math.min(add, -sub);
        for (int i = K; i < N; ++i) {
            add += Math.max(a[i], 0) - Math.max(a[i - K], 0);
            sub += Math.min(a[i], 0) - Math.min(a[i - K], 0);
            min = Math.min(min, Math.min(add, -sub));
        }
 
        out.println((max - min));
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 50484
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, y, i, j, k;
	bool found = false;
	cin >> n >> y;
	for (i = 0; i <= n; i++) {
		for (j = 0; i + j <= n; j++) {
			if (found) break;
			k = n - i - j;
			if (10000 * i + 5000 * j + 1000 * k == y) {
				found = true;
				cout << i << " " << j << " " << k << "\n";
			}
		}
	}


	if (!found) cout << "-1 -1 -1\n";

	return 0;
}



Measured memory_bytes: 256
S = input()
if S == "SUN":
    N = 7
if S == "MON":
    N = 6
if S == "TUE":
    N = 5
if S == "WED":
    N = 4
if S == "THU":
    N = 3
if S == "FRI":
    N = 2
if S == "SAT":
    N = 1
print(N)

Measured memory_bytes: 2940
//ABC174_B3
#include <stdio.h>
int main(){
	long int n,d;
	long int x,y;
	long int z=0;
	int cnt=0;
	
	scanf("%ld %ld",&n,&d);
	for(int i=0;i<n;i++){
		scanf("%ld %ld",&x,&y);
		z = x*x + y*y;
		if(z<=d*d)	cnt++;
	}
	
	printf("%d",cnt);
	
	return 0;
}


Measured memory_bytes: 1716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void solve()
    {

        var A = cin.scanlong;
        long cnt = 0;

        if (A[0] > 0 && A[3] > 0 && A[4] > 0)
        {
            cnt = Math.Min((A[0] % 2 + A[3] % 2 + A[4] % 2), ((A[0] - 1) % 2 + (A[3] - 1) % 2 + (A[4] - 1) % 2));
        }
        else
        {
            cnt = A[0] % 2 + A[3] % 2 + A[4] % 2;
        }

       
        WriteLine(Math.Max(0, A.Sum() - A[2] - A[5] - A[6] - cnt));
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 2776
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf') for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    for j in range(1, K+1):
        if i < N - j:
            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i] - h[i+j]))
print(dp[-1])           

Measured memory_bytes: 56928
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    a = abs(a-b);
    v = v-w;
    if (a <= v*t) PRINT("YES");
    else PRINT("NO");
}


Measured memory_bytes: 3688
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W, K = MAP()
c = [input() for _ in range(H)]

ans = 0

total_black = 0
for i in range(H):
	for j in range(W):
		if c[i][j] == "#":
			total_black += 1

ans = 0
for ny in range(H+1):
	for nx in range(W+1):
		for y in combinations(range(H), ny):
			for x in combinations(range(W), nx):
				black = 0
				for yy in y:
					for i in range(W):
						if c[yy][i] == "#":
							black += 1
				for xx in x:
					for i in range(H):
						if c[i][xx] == "#":
							black += 1

				for xx in x:
					for yy in y:
						if c[yy][xx] == "#":
							black -= 1

				if black == total_black - K:
					ans += 1

print(ans)	


Measured memory_bytes: 10432
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
#define debug(x) cout << #x << " = " << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){

    //条件の言い換え: どの要素も総和と互いに素でなく、かつ全ての要素の最大公約数は1
    //3の倍数出ない2の倍数と2の倍数でない3の倍数を混在させつつ、総和を6の倍数に保つことができれば良い
    //2または3の倍数: 20000個, 総和は6の倍数なので要素数は足りる

    int N; cin >> N;
    if(N == 3){ cout << 2 << ' ' << 5 << ' ' << 63 << endl; return 0; }
    if(N == 4){ cout << 2 << ' ' << 5 << ' ' << 20 << ' ' << 63 << endl; return 0; }

    vector<int> two(9998), three(4998), six(5000);
    rep(i, 4999){
        six[i] = (i + 1) * 6;
        three[i] = six[i] + 9;
        two[i * 2] = six[i] + 2;
        two[i * 2 + 1] = six[i] + 4;
    }
    six[4999] = 30000;

    deque<int> ans = { 4, 2, 3, 9 };
    auto answer = [&](){
        rep(i, ans.size()){
            if(i > 0)cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    };
    #define judge if(ans.size() == N){ answer(); return 0; }

    //4 ~ 5004
    rep(i, 5000){
        ans.push_back(six[i]);
        judge;
    }

    //5004 ~ 10003
    rep(i, 4999){
        ans.pop_back();
        ans.push_front(two[i * 2]);
        ans.push_front(two[i * 2 + 1]);
        judge;
    }

    //10003 ~ 15002
    rep(i, 4999){
        ans.push_back(six[i + 1]);
        judge;
    }

    //15002 ~ 17501
    rep(i, 2499){
        ans.pop_back();
        ans.push_front(three[i * 2]);
        ans.push_front(three[i * 2 + 1]);
        judge;
    }

    //17501 ~ 20000
    rep(i, 2499){
        ans.push_back(six[i + 2501]);
        judge;
    }

}

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

int main(){//C
    int N;cin>>N;
    vector<int> H(N);
    rep(i,0,N) cin>>H.at(i);
    int c=0;
    int max=0;
    int j=N-1;
    while(j>max&&j!=0){
        rep(i,N-(j+1),N-1) {
        if(H.at(i)>=H.at(i+1)) c++;
        else {
            j--;
            break;
        }}
        if(c>=max) max=c;
        c=0;
    }
    cout<<max<<endl;
    return 0;
}

/*int main(){//D
    int N;cin>>N;
    long long j=0;
    rep(i,0,N) j+=i;
    cout<<j<<endl;
    return 0;
}*/

/*int main(){//A
    string S,T;
    cin>>S>>T;
    int c=0;
    for(int i=0;i<S.size();i++){
        if(S.at(i)==T.at(i)) c++;
    }
    cout<<c<<endl;
    return 0;
}*/

/*int main() {//B
    int A,B;
    cin>>A>>B;
    int c=1;
    int a=A;
    if(B==1) c=0;
    else{
        while(A<B){
            A+=a-1;
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}*/

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

while 1:
  try:
    n, m = map(int, input().split())
    if n == 0:
      break
    p = sorted(list(map(int, input().split())))
    p.reverse()
    for i in range(m - 1, n, m):
      p[i] = 0
    print(sum(p))
  except:
    break



Measured memory_bytes: 5720
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int n, a[200020], b[200020];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }

    sort(a, a + n, greater<int>());

    for (int i = 0; i < n; i++) {
        if (a[0] == b[i]) cout << a[1] << endl;
        else cout << a[0] << endl;
    }
}

/*
g++ -std=c++14 abc134/f.cpp
 */

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int grid[3][3];
    rep(i,3) rep(j,3) cin >> grid[i][j];
    bool ok = 1;
    int a = grid[1][0]-grid[0][0];
    int b = grid[2][0]-grid[0][0];
    rep(i,3){
        if (grid[0][i]+a != grid[1][i]) ok = 0;
        if (grid[0][i]+b != grid[2][i]) ok = 0;
    }
    if (ok) PRINT("Yes");
    else PRINT("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 2019
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  if(M/mod!=N/mod)Out(0);
  else{
    M%=mod;
    N%=mod;
    sum=INF;
    rep(i,N,M)rep(j,i+1,M+1)chmin(sum,(i*j)%mod);
    Out(sum);
  }
}


Measured memory_bytes: 256
N, W = map(int, input().split())
V = N * 1000
w, v = [0]*N, [0]*N
for i in range(N):
  w[i], v[i] = map(int, input().split())

dp = [[float("INF")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
  for v_sum in range(V+1):
    if v_sum >= v[i-1]:
      dp[i][v_sum] = min(dp[i-1][v_sum - v[i-1]] + w[i-1], dp[i-1][v_sum])
    else:
      dp[i][v_sum] = dp[i-1][v_sum]

ans = 0
for v_sum in range(V+1):
  if dp[N][v_sum] <= W:
    ans = v_sum
print(ans)

Measured memory_bytes: 311064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int c[105][105];
int main(){
    int h,w;
    int n;
    cin >> h >> w;
    int H=h;
    int W=w;
    cin >> n;
    vector<int>a(n+1);
    rep(i,n){
        cin >>a[i+1];
    }
    int now = 1;
    int kai = 0;
    while(1){
        rep(j,w-kai*2){
            c[0+kai][j+kai] = now;
            a[now]--;
            if(a[now]==0)now++;
        }
        
        if(now==n+1)break;
        rep(i,h-1-kai*2){
            c[i+1+kai][w-1-kai] = now;
            a[now]--;
            if(a[now]==0){
                now++;
            }
        }
        
        if(now==n+1)break;
        rep(j,w-1-kai*2){
            c[h-1-kai][w-j-2-kai] = now;
            a[now]--;
            if(a[now]==0){
                now++;
            }
        }
        
        if(now==n+1)break;
        rep(i,h-2-kai*2){
            c[h-i-2-kai][0+kai] = now;
            a[now]--;
            if(a[now]==0){
                now++;
            }
        }
        //h-=2;
        //w-=2;
        kai++;
        if(now==n+1)break;
    }
    rep(i,H){
        rep(j,W-1){
            cout << c[i][j] << " ";
        }
        cout << c[i][W-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=82,M=N*N;
bool f[N][N][N*N*2];
int a[N][N];
int n,m,ans=1<<30;
void dfs(int x,int y,int v){
	if (f[x][y][v+M]) return;f[x][y][v+M]=true;
	if (x==n&&y==m) {
		ans=min(ans,abs(v-a[x][y]));
		ans=min(ans,abs(v+a[x][y]));
		return;
	}
	if (x!=n) dfs(x+1,y,v+a[x][y]),dfs(x+1,y,v-a[x][y]);
	if (y!=m) dfs(x,y+1,v+a[x][y]),dfs(x,y+1,v-a[x][y]);
}
int main (){
	scanf ("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			scanf ("%d",&a[i][j]);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			int x;scanf ("%d",&x);
			a[i][j]=abs(a[i][j]-x);
		}
	dfs(1,1,0);
	printf ("%d",ans);
	return 0;
}

Measured memory_bytes: 86912
#include <cstdio>
#include <iostream>

using namespace std;

void swap(int *x, int *y){
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

int main(){
	int w, n, a, b, p[30];
	cin >> w >> n;
	
	for(int i=0; i<w; ++i)
		p[i]=i+1;
	
	for(int i=0; i<n; ++i){
		scanf(" %d,%d", &a, &b);
		swap(p[a-1], p[b-1]);
	}

	for(int i=0; i<w; ++i)
		printf("%d\n", p[i]);
		 
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll arr[105],dp[105][100005],n,k;

int main()
{
	ll i,j;
	boost
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>arr[i];
	dp[1][0]=1;
	if(n==1)
	{
		if(k<=arr[1])
			cout<<1;
		else
			cout<<0;
		return 0;
	}
	for(i=1;i<=arr[1];i++)
		dp[1][i]=dp[1][i-1]+1;
	for(i=arr[1]+1;i<=k;i++)
		dp[1][i]=dp[1][i-1];
	for(i=2;i<=n;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(j-arr[i]>0)
				dp[i][j]=(dp[i-1][j]-dp[i-1][j-arr[i]-1]+MOD)%MOD;
			else
				dp[i][j]=dp[i-1][j];
		}
		if(i!=n)
		{
			for(j=1;j<=k;j++)
				dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD;
		}
	}	
	cout<<dp[n][k];
	return 0;
}

Measured memory_bytes: 79360
int main(void) {
    int i, n, k;
    scanf("%d",&n);
    i = 100000;
    while (n > 0) {
        i = i * 1.05;
        if(!(i % 1000 == 0))
        {
            k = i % 1000;
            i = i + 1000 - k;
        }
    n--;
    }
    printf("%d\n", i);
    return 0;
}    

Measured memory_bytes: 592
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
#define  PI 3.141592
int main(void){
    long double x1, x2, x3, x4, y1, y2, y3, y4, tilt_a, tilt_b;
    int n;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        if(x1 == x2){
            if(x3 == x4) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
        else{
            tilt_a = (y2-y1)/(x2-x1);
            tilt_b = (y4-y3)/(x4-x3);
            if(tilt_a == tilt_b){
                cout << "YES" << endl;
            }
            else cout << "NO" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define N 3009
#define INF 1000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pf(x) printf("%d",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
int dp[N][N];
string s="",s1,s2;
void prin(int len,int n,int m){
    int i=n-1,j=m-1,k=len;
    while(len>0){
        if(s1[i]==s2[j]){
            s+=s1[i];
            i--;j--;len--;
        }
        else{
            if(dp[i-1][j]==dp[i][j]){i--;}
            else{j--;}
        }
    }
    for(i=0; i<k; i++){
        cout << s[k-i-1];
    }
}
int main(){
    int i,j,n,m,t,k,x,y;
    // string s1,s2;
    cin >> s1 >> s2;
    s1="#"+s1;
    s2="$"+s2;
    for(i=1; i<s1.length(); i++){
        for(j=1; j<s2.length(); j++){
            if(s1[i]==s2[j]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                dp[i][j]=max(dp[i][j],dp[i][j-1]);
                dp[i][j]=max(dp[i][j],dp[i-1][j]);
            }
            else{
                dp[i][j]=max(dp[i][j],dp[i][j-1]);
                dp[i][j]=max(dp[i][j],dp[i-1][j]);
            }
        }
    }
    prin(dp[s1.length()-1][s2.length()-1],s1.length(),s2.length());
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
int isK(int i)
{
  return (i % 2 != 0) ? 1 : 0;
}
int main(void)
{
  std::map<int, int> data;
  int n, t, ans;
  std::cin >> n;
  for(int i = 0; i != n; i++){
    std::cin >> t;
    data[t]++;
  }
  ans = 0;
  for(auto itr = data.begin(); itr != data.end(); itr++)
    ans += isK(itr->second);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4992
from itertools import permutations
N, C = map(int, input().split())
D, P = [], [[0]*C for _ in range(3)]
for i in range(C):
    D.append(list(map(int, input().split())))
for i in range(N):
    for j, c in enumerate(map(int, input().split())):
        P[(i+j)%3][c-1] += 1
res = float("inf")
for q in permutations(range(C),3):
    tmp = 0
    for k in range(3):
        c = q[k]
        for i, p in enumerate(P[k]):
            tmp += D[i][c]*p
    res = min(tmp, res)
print(res)

Measured memory_bytes: 69708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    x -= a;
    x %= b;
    cout << x << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

		int a = n % 100;
		int b = (n - a) / 100;

		boolean um = false;
		boolean sm = false;

		if(0 < a && a < 13) um = true;
		if(0 < b && b < 13) sm = true;

		if(um && sm) System.out.println("AMBIGUOUS");
		else if(um) System.out.println("YYMM");
		else if(sm) System.out.println("MMYY");
		else System.out.println("NA");

	}
}

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

using namespace std;

int main (void) {
    string s;
    cin >> s;
    int s_len = s.size();

    long long ans = 0;
    for ( int i = 0; i < s_len; i++ ) {
        int n = s.at(i) - '0';
        long long m = 1;
        for ( int j = 0; i + j < s_len - 1; j++ ) {
            long long p = (1LL<<i) * (1LL<<(s_len - i - j - 2));
            ans += p * m * n;
            m *= 10;
        }
        ans += (1LL<<i) * m * n;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define N 200005
#define SIZE 2000005
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;
int n,m;
int vis[N],ar[N];
vector< vector< int > > adj(N);
set< int > s;
int ans[N];
int place[N];
set < int > :: iterator it;

void dfs(int root){
    if(vis[root])return;
    vis[root] = 1;
    int val = -1;
    if(s.find(ar[root])==s.end()){
    s.insert(ar[root]);
    it = s.upper_bound(ar[root]);
    if(it != s.end()){
        val = *it;
        s.erase(it);
    }
    place[root] = 1;
    }
  //  cout<<root<<" "<<s.size()<<"\n";
    ans[root] = (int) s.size();
    for(auto ch : adj[root]){
        if(vis[ch])continue;
        dfs(ch);
    }
    if(val!=-1)s.insert(val);
   if(place[root]) s.erase(ar[root]);
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(0);
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    
    return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000009;
int mpow(int n,int m){
    n%=mod;
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}

int N,M;
int fact[3333333];
int inv[3333333];

int C(int n,int k){
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}

struct UnionFindTree{
    vector<int>par,sz;
    UnionFindTree(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool areSame(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

int table[3333333];

int calc(vpint A){
    vint xs;
    rep(i,A.size()){
        xs.pb(A[i].fi);
        xs.pb(A[i].se);
    }
    sort(all(xs));xs.erase(unique(all(xs)),xs.end());
    rep(i,A.size()){
        A[i].fi=lower_bound(all(xs),A[i].fi)-xs.begin();
        A[i].se=lower_bound(all(xs),A[i].se)-xs.begin();
    }

    UnionFindTree uf(xs.size());
    rep(i,A.size())uf.unite(A[i].fi,A[i].se);

    int cnt=0;
    rep(i,xs.size()){
        if(uf.find(i)!=i)continue;
        if(uf.sz[i]>3)return 0;
        if(uf.sz[i]==3)continue;
        cnt++;
    }

    int n=3*N-(int)xs.size();

    if(n<cnt)return 0;
    
    int ret=fact[n]*inv[n-cnt]%mod;
    ret=ret*table[n-cnt]%mod;
    return ret;
}

signed main(){
    fact[0]=1;
    for(int i=1;i<3333333;i++)fact[i]=fact[i-1]*i%mod;
    inv[3333333-1]=mpow(fact[3333333-1],mod-2);
    for(int i=3333333-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    table[0]=1;
    for(int i=3;i<3333333;i+=3){
        table[i]=table[i-3]*C(i-1,2)%mod;
    }


    cin>>N>>M;

    vpint A,B;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        if(c==0)A.pb({a,b});
        else B.pb({a,b});
    }

    int ans=0;

    int k=B.size();
    for(int i=1;i<(1<<k);i++){
        vpint AA=A;
        rep(j,k)if(i>>j&1)AA.pb(B[j]);

        int pc=0;
        rep(j,k)if(i>>j&1)pc++;
        if(pc%2==1)ans=(ans+calc(AA))%mod;
        else ans=(ans-calc(AA)+mod)%mod;
        
      //  assert(0<=calc(AA)&&calc(AA)<mod);
    }

    cout<<(calc(A)-ans+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 81304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  int A=0;
  int Ans=0;
  string S; cin>>S;
  for(int i=0; i<N; i++){
    if(S.at(i)=='I')
      A++;
      else A--;
    Ans=max(Ans,A);
  }
  cout<<Ans<<endl;
}
  


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, l; cin >> n >> l;
    vector<int> data(n);
    for (auto &v : data)
        cin >> v;
    int idx = -1;
    for (int i = 1 ; i < n ; i++) {
        if (data[i - 1] + data[i] >= l)
            idx = i;
    }
    if (idx == -1) {
        cout << "Impossible\n";
        exit(0);
    }
    cout << "Possible\n";
    for (int i = 1 ; i < idx ; i++)
        cout << i << '\n';
    for (int i = n - 1 ; i > idx ; i--)
        cout << i << '\n';
    cout << idx << '\n';

}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i,a,b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i,a,b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i,a,b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int INF = 1e9 + 3;
const int MOD = 1e9 + 7;

const int N = 2e5 + 3;

int n, m, cnt;
vi a[N];
int f[N];

void dfs(int u, int p) {
    for (int &v : a[u]) if (v != p) {
        f[v] += f[u];
        dfs(v, u);
    }
}

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
//        freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    fore(i, 1, n) {
        int u, v; cin >> u >> v;
        a[u].pb(v);
        a[v].pb(u);
    }
    while (m--) {
        int u, w;
        cin >> u >> w;
        f[u] += w;
    }
    dfs(1, -1);
    fort(i, 1, n) cout << f[i] << " \n"[i == n];
    return 0;
}



Measured memory_bytes: 23552