akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

      int n = sc.nextInt();

      String[] s = new String[n];

      for(int i=0;i<n;i++){
        s[i] = sc.next();
      }

      char[][] c = new char[n][10];
      for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
          c[i][j] = s[i].charAt(j);
        }
      }

      for(int i=0;i<n;i++){
        Arrays.sort(c[i]);
      }

      String[] fin = new String[n];

      for(int i=0;i<n;i++){
        fin[i] = "";
        for(int j=0;j<10;j++){
            fin[i] += c[i][j];
        }
      }

      Arrays.sort(fin);

/*      for(int i=0;i<n;i++){
        System.out.println("fin[i]="+fin[i]);
      }*/
//////////////////////////////////////////////

      long cnt = 1;
      long ans = 0;

      for(int i=0;i<n-1;i++){
        if(fin[i].equals(fin[i+1])){
          cnt++;
        }
        else if(i!=n-2){
          ans += cnt*(cnt-1)/2;
          cnt = 1;
        }
        if(i==n-2){
          ans += cnt*(cnt-1)/2;
        }
      }

/*
      for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          if(fin[i].equals("-")){
            break;
          }
          else{
            if(fin[i].equals(fin[j])){
              fin[j] = "-";
              cnt++;
            }
          }
        }
        fin[i] = "-";
        ans += cnt*(cnt-1)/2;
        cnt = 1;
      }
*/
      System.out.println(ans);

      /*for(int i=0;i<n;i++){
        System.out.println("fin[i]="+fin[i]);
      }*/

    }
}


Measured memory_bytes: 105768
import sys
from io import StringIO
import unittest

import math

def resolve():
    n, m = map(int, input().split())
    div = 10**9 + 7

    # n! * m! * 2
    if abs(n - m) > 1:
        print(0)
    elif n == m:
        print((math.factorial(n) * math.factorial(m) * 2) % div)
    else:
        print((math.factorial(n) * math.factorial(m)) % div)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 2"""
        output = """8"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 2"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1 8"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """100000 100000"""
        output = """530123477"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 66668
#include <iostream>
#include <array>
#include <algorithm>
using namespace std;

int main()
{
    int q, t, f;
    array<int, 6> d;
    array<string, 3> tbl = {"12431", "03520", "01540"};
    auto idx=[&](int x){return distance(d.begin(), find(d.begin(), d.end(), x));};
    auto half=[](int x){return x < 3 ? x : 5 - x;};

    for (int &x: d)
        cin >> x;

    cin >> q;
    while (q-- && cin >> t >> f) {
        int ti = idx(t), fi = idx(f), r = 3 - half(ti) - half(fi);
        cout << d[tbl[r].find(to_string(ti) + to_string(fi)) != string::npos ? r : 5 - r]
            << endl;
    }

    return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int N,K;  cin>>N>>K;
  vector<int> p(N);
  rep(i,0,N) cin>>p[i];
  sort(all(p));
  ll sum=0;
  rep(i,0,K){
    sum += p[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
	int x, y;
	while (cin >> x >> y, !(x == 0 && y == 0)) {
		if (x <= y)cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(10 ** 5)

class UniteFind:
    def __init__(self, N):
        self.par = [i for i in range(N)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return
        self.par[ry] = rx

    def same(self, x, y):
        if (self.root(x) == self.root(y)):
            return True
        return False


N, M = map(int, input().split())
rf = UniteFind(N)

for _ in range(M):
    x, y, _ = map(int, input().split())
    rf.unite(x-1, y-1)

m = {i: -1 for i in range(N)}
ans = 0

for i in range(N):
    if m[rf.root(i)] == -1:
        m[rf.root(i)] = 1
        ans += 1

print(ans)


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

int main(){
  int N ;
  cin >> N;
  string k;
  set<string> S;
  for(int i =0;i<N;i++){
    cin >> k;
    S.insert(k);
  }
  cout << S.size() << endl;
  
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

struct UnionFind{
	vi rank,par;
	void Init(int n){
		rank.assign(n,0);
		par.assign(n,-1);
	}
	int Find(int i){
		return par[i]==-1?i:(par[i]=Find(par[i]));
	}
	bool Same(int a,int b){
		return Find(a)==Find(b);
	}
	bool Unite(int a,int b){
		a=Find(a);
		b=Find(b);
		if(a==b)
			return false;
		if(rank[a]<rank[b])
			swap(a,b);
		par[b]=a;
		if(rank[a]==rank[b])
			rank[a]++;
		return true;
	}
} uf;

int main(){
	int n=read(),q=read();
	map<int,vector<pii>> edges;
	int minCost=INT_MAX;
	REP(_,q){
		int a=read(),b=read(),c=read();
		chmin(minCost,c);
		edges[c].PB(MP(a,b));
		edges[c+1].PB(MP((a+1)%n,b));
	}
	int curCost=minCost,cmp=n;
	uf.Init(n);
	ll ans=0;
	while(cmp>1){
		for(auto e:edges[curCost])
			if(!uf.Same(e.first,e.second)){
				cmp--;
				ans+=curCost;
				uf.Unite(e.first,e.second);
				edges[curCost+2].PB(MP((e.first+1)%n,(e.second+1)%n));
			}
		curCost++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 55936
import java.util.*;
public class Main {
  
    public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      int b = sc.nextInt();
      
      //積を表示
      int c = a * b;
      if (c % 2 == 0) {
          System.out.println("Even");
      } else {
          System.out.println("Odd");
      }
      sc.close();
    }
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

ll N, A, B, ans;

void solve() {
    cin >> N >> A >> B;
    ll times = N / (A + B);
    ans += A * times;
    ans += min(A, N % (A + B));
    cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main{
	def main(args: Array[String])={
		val x = readLine().split(" ").map(_.toInt)
		val(a,b,c)=(x(0),x(1),x(2))
		if(a < b && b < c){
			println("Yes")
		}else{
			println("No")
		}
	}
}

Measured memory_bytes: 43468
import sys
from io import StringIO
import unittest

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

def resolve():
    int1 = lambda x: int(x) - 1
    readline=sys.stdin.readline

    n,m,k=map(int, readline().strip().split())

    uf = UnionFind(n)

    exc=[0]*n

    for i in range(m):
        a,b=map(int1, readline().strip().split())
        uf.Unite(a,b)
        exc[a]+=1
        exc[b]+=1
    
    for i in range(k):
        a,b=map(int1, readline().strip().split())
        if uf.isSameGroup(a,b):
            exc[a]+=1
            exc[b]+=1
    
    rescnt=[]

    for i in range(n):
        ri=uf.Count(i)-1-exc[i]
        rescnt.append(str(ri))
    
    print(" ".join(rescnt))

resolve()

Measured memory_bytes: 17096
n, q = map(int, input().split())
s_list = list(input())
l_r_list = [list(map(int, input().split())) for _ in range(q)]
c_sum = [0]
su = 0
for i in range(n - 1):
    if s_list[i] == "A" and s_list[i + 1] == "C":
        su += 1
    c_sum.append(su)
for l, r in l_r_list:
    print(c_sum[r - 1] - c_sum[l - 1])

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

using namespace std;

int mod = 1e9 + 7;

int find(int a, vector<int>& group) {
    if (a == group[a]) return a;
    return find(group[a], group);
}

void unite(int group_a, int group_b, vector<int>& group, vector<int>& rank) {
    if (rank[group_a] < rank[group_b]) swap(group_a, group_b);
    group[group_b] = group_a;
    rank[group_a] += rank[group_b];
    return;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // N-1 -(built edges)
    int N, M, a, b;
    cin >> N >> M;
    vector<int> group(N + 1);
    for (int i = 0; i <= N; i++) {
        group[i] = i;
    }
    vector<int> rank(N + 1, 0);
    int cnt = 0;
    for (int j = 0; j < M; j++) {
        cin >> a >> b;
        int group_a = find(a, group), group_b = find(b, group);
        if (group_a != group_b) {
            cnt++;
            unite(group_a, group_b, group, rank);
        }
    }
    cout << N - 1 - cnt;

    return 0;
}

Measured memory_bytes: 3876
#include <iostream>
#include <vector>
#include <string>
#include <climits>


using namespace std;


using ll = long long;


class node {
    public:
        node();
        ll k;
        node *l, *r, *p;
};


node::node()
    : l{nullptr}, r{nullptr}, p{nullptr}
{
}



node *root = nullptr;


void insert(node *n)
{
    node *parent, *now;
    now = root;
    while (now != nullptr) {
        parent = now;
        if (now->k <= n->k)
            now = now->r;
        else
            now = now->l;
    }

    if (root == nullptr)
        root = n;
    else if (parent->k <= n->k)
        parent->r = n;
    else
        parent->l = n;
}


void inorder(node *now, vector<ll> &log)
{
    if (now->l != nullptr)
        inorder(now->l, log);

    log.push_back(now->k);

    if (now->r != nullptr)
        inorder(now->r, log);
}


void preorder(node *now, vector<ll> &log)
{
    log.push_back(now->k);

    if (now->l != nullptr)
        preorder(now->l, log);

    if (now->r != nullptr)
        preorder(now->r, log);
}


bool find(ll k)
{
    node *now = root;
    while (now != nullptr && now->k != k) {
        if (now->k <= k)
            now = now->r;
        else
            now = now->l;
    }

    if (now == nullptr)
        return false;
    else
        return true;
}


void print_log(vector<ll> &log)
{
    for (auto it = log.begin(); it != log.end(); ++it) {
        cout << " " << *it;
    }
    cout << endl;
}


int main()
{
    ll N;
    cin >> N;
    for (ll i = 0; i < N; i++) {
        vector<ll> log;
        vector<node *> nodes;
        string cmd;
        node *n;
        ll k;

        cin >> cmd;
        switch(cmd[0]) {
            case 'i':
                cin >> k;
                n = new node;
                n->k = k;
                insert(n);
                break;
            case 'p':
                inorder(root, log);
                print_log(log);
                log.clear();

                preorder(root, log);
                print_log(log);
                log.clear();
                break;
            case 'f':
                cin >> k;
                if (find(k)) {
                    cout << "yes" << endl;
                } else {
                    cout << "no" << endl;
                }
                break;
        }
    }
}



Measured memory_bytes: 25888
#include <cstdio>

int a[(int)1e4 + 10];

int main() {
	int n;
	while (~scanf("%d", &n) && n) {
		int sum = 0;
		int average;
		for (int i = 0; i < n; i++) 
			scanf("%d", &a[i]), sum += a[i];
		average = sum / n;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] <= average) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2612
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <set>
#include <map>

using namespace std;



int main() {
	ios::sync_with_stdio(false);

	string filename = "date";

	//ifstream cin(filename + ".in");
	//ofstream cout(filename + ".out");

	int n;
	cin >> n;

	vector<int> vec(n + 1);
	int totalCost = 0;

	for (int i = 0; i < n; ++i) {
		cin >> vec[i];
		if (i > 0) totalCost += abs(vec[i] - vec[i - 1]);
		else totalCost += abs(vec[i]);
	}
	totalCost += abs(vec[n - 1]);

	cout << totalCost - abs(vec[0] - vec[1]) - abs(vec[0]) + abs(vec[1]) << "\n";
	for (int i = 1; i < n; ++i) {
		int ans = totalCost - abs(vec[i] - vec[i - 1]) - abs(vec[i + 1] - vec[i]) + abs(vec[i + 1] - vec[i - 1]);
		cout << ans << "\n";
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

void drawChessboard(int height, int width);

int main(void) {

    int height;
    int width;

    while(1) {
        scanf("%d %d", &height, &width);

        if(height == 0 && width == 0) {
            break;
        }

        drawChessboard(height, width);

        printf("\n");
    }
    
    return 0;
}

void drawChessboard(int height, int width) {

    int i;
    int j;

    for(i = 0; i < height; i++) {
        for(j = 0; j < width; j++) {
            if((i + j) % 2 == 0) {
                 putchar('#');
            }
            else {
                 putchar('.');
            }
        }
        
        printf("\n");
    }

    return;
}

Measured memory_bytes: 576
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;
int dp[N][2][2][2];
int d[N];
int dfs(int pos, bool limit1 = true, bool limit2 = true, bool carry = false)
{
	if (pos == -1)
	{
		return carry ? 0 : 1;
	}
	if (dp[pos][limit1][limit2][carry] != -1) return dp[pos][limit1][limit2][carry];
	int& ret = dp[pos][limit1][limit2][carry] = 0;
	int up1 = limit1 ? d[pos] : 1;
	int up2 = limit2 ? d[pos] : 1;
	vector<tuple<int, int, int>> vp;
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			int sum = i + j;
			if (carry && sum < 1) continue;
			for (int o = 0; o < 2; o++)
			{
				int tot = sum + o;
				if (carry && tot < 2) continue;
				if (!carry && i + j + o >= 2) continue;
				if ((i ^ j ^ o) > up1) continue;
				if ((i ^ j) > up2) continue;
				vp.emplace_back(i ^ j ^ o, i ^ j, o);
			}
		}
	}
	sort(vp.begin(), vp.end());
	vp.resize(unique(vp.begin(), vp.end()) - vp.begin());
	for (auto& p : vp)
	{
		int a, b, c;
		tie(a, b, c) = p;
		ret += dfs(pos - 1, limit1 && a == d[pos], limit2 && b == d[pos], c);
		if (ret >= INF) ret -= INF;
	}
	return ret;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	MEM(dp, -1);
	LL n;
	int len = 0;
	cin >> n;
	while (n)
	{
		d[len++] = n % 2;
		n /= 2;
	}
	cout << dfs(len - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
p=[x-1 for x in p]
mi=set(range(n))
g={}
# g[id]=[ary]
while mi:
  x0=mi.pop()
  ary=[c[x0]]
  x=x0
  while p[x]!=x0:
    x=p[x]
    mi.discard(x)
    ary.append(c[x])
  cnt=len(ary)
  tmp=0
  ary*=2
  cary=[tmp]
  for x in ary:
    tmp+=x
    cary.append(tmp)
  g[x0]=[cnt,cary]
ans=-float('inf')
for cnt,cary in g.values():
  x,y=divmod(k,cnt)
  tmp1=max(0,cary[cnt]*x)
  tmp2=-float('inf')
  for i in range(cnt):
    for j in range(y):
      tmp2=max(tmp2,cary[i+j+1]-cary[i])
  ans=max(ans,tmp1+tmp2)
  if x:
    tmp1=max(0,cary[cnt]*(x-1))
    tmp2=-float('inf')
    for i in range(cnt):
      for j in range(cnt):
        tmp2=max(tmp2,cary[i+j+1]-cary[i])
    ans=max(ans,tmp1+tmp2)
  

print(ans)


Measured memory_bytes: 75112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int n = sc.nextInt();
    		int a = sc.nextInt();
    		int b = sc.nextInt();
    		int c = sc.nextInt();
    		int x = sc.nextInt();
    		if(n+a+b+c+x == 0) break;
    		
    		int[] slot = new int[n];
    		for(int i=0;i<n;i++) {
    			slot[i] = sc.nextInt();
    		}
    		
    		int count = 0;
    		boolean flag = false; 
    		loop: for(int i=0;i<n;i++) {
    			while(x!=slot[i]) {
    				x = (a*x + b)%c;
    				count++;
    				if(count>10000) {
    					flag = true;
    					break loop;
    				}
    			}
    			x = (a*x + b)%c;
    			count++;
    		}
    		if(flag) System.out.println("-1");
    		else System.out.println(count-1);
    	}
    }
}



Measured memory_bytes: 41364
#include<bits/stdc++.h>
using namespace std;
int n,a[22];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	int ans=0;
	for(int i=2;i<n;i++)
	{
		if(a[i-1]>a[i]&&a[i]>a[i+1]||a[i-1]<a[i]&&a[i]<a[i+1])ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 384
// 長方形の中に円が含まれるかを判定するプログラムを作成してください。
// 次のように、長方形は左下の頂点を原点とし、右上の頂点の座標 (W,H)が与えられます。
// また、円はその中心の座標 (x,y)と半径 rで与えられます。
// 【入力】
// ５つの整数 W、H、x、y、rが空白区切りで１行に与えられます。
// 【出力】
// 円が長方形の内部に含まれるなら Yes と、
// 一部でもはみ出るならば No と１行に出力してください。
// 【制約】
// −100≤x,y≤100
// 0<W,H,r≤100
// 【例】
// 入力：5 4 2 2 1、出力：Yes
// 入力：5 4 2 4 1、出力：No
#include <stdio.h>

int main( void) {
  int W, H;
  int x, y, r;

  scanf( "%d %d %d %d %d", &W, &H, &x, &y, &r);

  if ( x - r < 0 || x + r > W) printf( "No\n");
  else if ( y - r < 0 || y + r > H) printf( "No\n");
  else printf( "Yes\n");

  return 0;
}



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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a((size_t) n);
    vector<ll> sum((size_t) n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }

    ll mind = numeric_limits<ll>::max();
    for (int i = 0; i < n - 1; ++i) {
        mind = min(mind, abs(sum[i + 1] - (sum[n] - sum[i + 1])));
    }

    cout << mind << endl;
}

Measured memory_bytes: 3328
import math
import itertools

N = int(input())
x_y_list = [list(map(int,input().split()))for _ in range(N)]
distance_list = []
for i in range(N):
  for j in range(i+1,N,1):
    distance = math.sqrt((x_y_list[i][0]-x_y_list[j][0])**2 + 
                         (x_y_list[i][1]-x_y_list[j][1])**2)
    distance_list.append(distance)
ans = 0
c = list(itertools.combinations(distance_list,N-1))
for i in range(len(c)):
  ans += sum(c[i])
ans = ans/len(c)
print(ans)


Measured memory_bytes: 137008
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
signed main(){
	int n;
	cin>>n;
	if(n<1000)puts("ABC");
	else puts("ABD");
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);

$array = array();
$rar = array();
$result = 0;
$temp = 0;
for ($i=1; $i <= $N; $i++) { 
	 array_push($array, trim(fgets(STDIN)));
}
sort($array, SORT_NUMERIC );
if ($N % 2 == 0) {
	for ($j=0; $j < $N / 2; $j++) { 
		$rar[$j*2+1]=$array[$j];
		$rar[$j*2]=$array[$j+$N/2];
	}
}else{
	$center = $N/2;
	$rar[$center]=$array[0];
	for ($m=1; $m <= $N / 2; $m++) { 
		if ($m % 2==1) {
			$rar[$center-$m]=$array[$N-$m];
			$rar[$center+$m]=$array[$N-$m-1];
		}else{
			$rar[$center-$m]=$array[$m-1];
			$rar[$center+$m]=$array[$m];
		}
	}
	for ($k=0; $k < $N-1 ; $k++) { 
		$temp+=abs($rar[$k]-$rar[$k+1]);
	}
	$rar[$center]=$array[$N-1];
	for ($m=1; $m <= $N / 2; $m++) { 
		if ($m % 2==0) {
			$rar[$center-$m]=$array[$N-$m];
			$rar[$center+$m]=$array[$N-$m-1];
		}else{
			$rar[$center-$m]=$array[$m-1];
			$rar[$center+$m]=$array[$m];
		}
	}
}

for ($k=0; $k < $N-1 ; $k++) { 
	$result+=abs($rar[$k]-$rar[$k+1]);
}
echo ($result<$temp)?$temp:$result;

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

#define INF (1 << 29)
#define MAX_N 1000

int x[MAX_N];
int y[MAX_N];
int p;
int v[40];

int main()
{
	int n;

	cin >> n;
	for( int i = 0; i < n; i++ ) {
		cin >> x[i] >> y[i];
		int pp = abs(x[i] + y[i]) % 2;
		if( i == 0 ) {
			p = pp;
		}
		if( pp != p ) {
			cout << -1 << endl;
			return 0;
		}
	}

	int m = 31;
	for( int i = 0; i < m; i++ ){
		v[i] = 1 << (m - i - 1);
	}
	if( p == 0 ) {
		v[m] = 1;
		m++;
	}
	

	cout << m << endl;
	for( int i = 0; i < m; i++ ) {
		cout << v[i];
		if( i < m - 1 ) {
			cout << " ";
		}
	}
	cout << endl;

	for( int i = 0; i < n; i++ ) {
		int xx = x[i];
		int yy = y[i];
		for( int j = 0; j < m; j++ ) {
			if( abs(xx) >= abs(yy) ) {
				if( xx >= 0 ) {
					cout << "R";
					xx -= v[j];
				}
				else {
					cout << "L";
					xx += v[j];
				}
			}
			else {
				if( yy >= 0 ) {
					cout << "U";
					yy -= v[j];
				}
				else {
					cout << "D";
					yy += v[j];
				}
			}
		}
		cout << endl;
	}

	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++)
typedef long long ll;

int main(){
  int a, b, h, m;
  double l, pi=3.14159265359;
  cin >> a >> b >> h >> m;

  l=sqrt(a*a+b*b-2*a*b*cos(m*pi/30-(h*60+m)*pi/360));

  printf("%.10lf\n", l);

  return 0;
}

Measured memory_bytes: 4092
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


using ll=long long;

class mod_ll
{
public:
	ll m_v;
	static const ll m_m=1000000007; // prime value ex. 1000000009
	mod_ll(ll v=0) : m_v(v%m_m) {}
	mod_ll operator = (ll rhs)
	{
		m_v=rhs%m_m;
		return *this;
	}
	ll operator ()(){return m_v;}
	mod_ll operator = (mod_ll rhs)
	{
		m_v=rhs.m_v;
		return *this;
	}
	mod_ll operator += (ll rhs)
	{
		m_v=(m_v+rhs)%m_m;
		return *this;
	}
	mod_ll operator += (mod_ll rhs)
	{
		m_v=(m_v+rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator + (mod_ll rhs)
	{
		auto ret=*this;
		return ret+=rhs;
	}
	mod_ll operator -= (mod_ll rhs)
	{
		m_v=(m_v-rhs.m_v+m_m)%m_m;
		return *this;
	}
	mod_ll operator - (mod_ll rhs)
	{
		auto ret=*this;
		return ret-=rhs;
	}
	mod_ll operator *= (ll rhs)
	{
		rhs%=m_m;
		m_v=(m_v*rhs)%m_m;
		return *this;
	}
	mod_ll operator *= (mod_ll rhs)
	{
		m_v=(m_v*rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator * (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret*=rhs;
	}
	mod_ll operator ^ (ll rhs)
	{
		mod_ll t=*this;
		mod_ll ret(1LL);

		for(;rhs>0;rhs>>=1)
		{
			if(rhs&1) ret*=t;
			t*=t;
		}
		return ret;
	}
	mod_ll operator /= (mod_ll rhs)
	{
		return *this*=(rhs^(m_m-2));
	}
	mod_ll operator /= (ll rhs)
	{
		mod_ll t(rhs);
		return *this/=t;
	}
	mod_ll operator / (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret/=rhs;
	}
};


mod_ll mod_fact(int n)
{
	static vector<mod_ll> memo(1);

	if((int)memo.size()<=n)
	{
		if(memo.size()==1)
		{
			memo[0]=1;
		}
		for(int i=memo.size();i<=n;i++)
		{
			memo.push_back(memo.back()*i);
		}
	}
	return memo[n];
}


mod_ll mod_nCr(int n, int r)
{
	mod_ll bunsi=mod_fact(n);
	mod_ll bunbo=mod_fact(n-r)*mod_fact(r);
	return bunsi/bunbo;
}


mod_ll mod_nCr2(int n, int r)
{
	mod_ll bunsi(1);
	mod_ll bunbo(1);
	if(r*2>n) r=n-r;

	for(int i=0;i<r;i++)
	{
		bunsi*=(n-i);
		bunbo*=(i+1);
	}

	return bunsi/bunbo;
}


mod_ll mod_nPr(int n, int r)
{
	mod_ll ret(1);

	for(int i=0;i<r;i++)
	{
		ret*=(n-i);
	}
	return ret;
}


struct solve
{
	int n;
	solve(int n):n(n){}
	ll operator()(vll&a) {
		vll c(61, 0);
		for(int i=0;i<n;i++)
		{
			ll v=a[i];
			for(int j=0;j<c.size();j++)
			{
				if(v&1) c[j]++;
				v>>=1;
			}
		}

//for(int i=0;i<60;i++) cout << c[i] << " "; cout << "\n";

		mod_ll ans;
		mod_ll u(1);
		for(int i=0;i<c.size();i++)
		{
			mod_ll t(c[i]*(n-c[i]));
			ans+=u*t;
			u*=2;
		}
		return ans();
	}
};

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

	for(;;)
	{
		int n;

		cin >> n;
		if(cin.fail()) break;

		vll a(n);
		for(auto&m:a) cin >> m;

		cout << solve(n)(a) << "\n";
	}
	return 0;
}


Measured memory_bytes: 2560
#!/usr/bin/perl

my $s = scalar(<STDIN>);
$s =~ s/[\x00-\x20]+$//ios;

my $n = length($s);

my $d = 0;
my $dec = 1;
my %m = ('0'=>1);
for(my $i=$n-1;$i>=0;$i--){
  my $dd =  $d + $dec * ( substr($s,$i,1) - 0 );
  $dd = $dd % 2019;
  $m{$dd} ++;
  $d = $dd;
  $dec = ( $dec * 10 ) % 2019;
}

my $tt = 0;
foreach my $k (keys %m){
  my $v = $m{$k};
  $tt += $v * ( $v - 1 ) / 2;
}
print "$tt\n";


Measured memory_bytes: 5400
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  ll d[3];
  clr(d,0);
  rep(i,0,n){
    ll a;
    cin>>a;
    if(a%4==0)d[2]++;
    else if(a%2==0)d[1]++;
    else d[0]++;
  }
  if(d[2]>=d[0]){
    cout << "Yes" << endl;
  }
  else{
    if(d[2]==0){
      if(d[0]>0){
        cout << "No" << endl;
      }
      else{
        cout << "Yes" << endl;
      }
    }
    else if(d[2]+1==d[0]){
      if(d[1]>0){
        cout << "No" << endl;
      }
      else{
        cout << "Yes" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;
#define pb(x) push_back(x)
#define MOD 1000000007

using namespace std;

int main(){

    int a[3];

    cin >> a[0] >> a[1] >> a[2];

    sort(a,a+3);

    if(a[0] + a[1] == a[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

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

int main(){

	int N;
	cin >> N;
	int oddCnt = 0;
	ll a;
	for(int i = 0; i < N; i ++){
		cin >> a;
		if(a%2 == 1)oddCnt ++;
	}
	if(oddCnt%2 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;

struct Card{
    char suit;
    char value;
};

void bubble(Card A[], int N){
    rep(i,N) gnr(j,i+1,N)
        if(A[j].value < A[j-1].value)
            swap(A[j],A[j-1]);
}

void selection(Card A[], int N){
    rep(i,N){
        int minj = i;
        rng(j,i,N)
            if(A[j].value < A[minj].value) minj = j;
        swap(A[i],A[minj]);
    }
}

void print(Card A[], int N){
    rep(i,N){
        if(i>0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(Card c1[], Card c2[], int N){
    rep(i,N)
        if(c1[i].suit != c2[i].suit) return false;
    return true;
}

int main() {
    Card c1[100],c2[100];
    int N;
    char ch;

    cin >> N;
    rep(i,N){
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }

    bubble(c1,N);
    selection(c2,N);

    print(c1,N);
    cout << "Stable" << endl;
    print(c2,N);
    if(isStable(c1,c2,N)) {
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
int main(){
  vector<int> a(5);
  rep(i,5) cin >> a[i];
  rep(i,5){
    if(a[i] == 0){
      cout << i+1 << endl;
      return 0;
    }
  }
}

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


double calc(vector<double> x,vector<double> y,double X){
	int n = x.size();
	double answer = 0;
	for(int i = 0 ; i < n ; i++){
		double sub = y[i];
		for(int j = 0 ; j < n ; j++){
			if( i != j ){
				sub *= (X-x[j]);
				sub /= (x[i]-x[j]);
			}
		}
		answer += sub;
	}
	return answer;
}
int main(){
	int d;
	while(cin >> d && d){
		vector<double> v(d+3);
		for(int i = 0 ; i < v.size() ; i++) cin >> v[i];
		vector<int> vote(v.size(),0);
		for(int i = 0 ; i < v.size() ; i++){
			vector<double> x,y;
			for(int j = 0 ; j < v.size() ; j++){
				if( i != j ){
					x.push_back(j);
					y.push_back(v[j]);
				}
			}
			x.resize(d+1);
			y.resize(d+1);
			int ok = 1;
			for(int j = 0 ; j < v.size() ; j++){
				if( i != j && abs(calc(x,y,j)-v[j]) > 0.8 ) ok = 0;
			}
			if( ok ){
				cout << i << endl;
				break;
			}
		}

	}
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

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

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

void mod(ll &val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i).first >> vec.at(i).second;
    }
    vector<bool> zorome(N);
    for(int i = 0;i < N;i++) {
        if(vec.at(i).first == vec.at(i).second) {
            zorome.at(i) = true;
        }
    }
    int Max = 0;
    int cnt = 0;
    for(int i = 0;i < N;i++) {
        if(zorome.at(i) == true) {
            cnt++;
        }
        else {
            chmax(Max,cnt);
            cnt = 0;
        }
    }
    chmax(Max,cnt);
    if(Max >= 3) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
num = list(map(int, input().split()))
order = input()

for o in order:
    if o == 'N':
        next = '263415'
    elif o == 'W':
        next = '326154'
    elif o == 'S':
        next = '513462'
    else:
        next = '421653'

    temp = [0]*6
    for i,n in enumerate(next):
        temp[i] = num[int(n)-1]

    num = temp

print(num[0])



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

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

    if (x < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int x = n * 800;
	int y = (n / 15) * 200;
	cout << x - y << endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  r(i,n) cin>>v.at(i);
  int q;
  cin>>q;
  while(q--){
    int b, c;
    cin >> b >> c;
    reverse(v.begin()+b, v.begin()+c);
  }
  r(i,n){
    cout << v.at(i);
    if(i!=n-1) cout << " ";
    else cout << endl;
  }
  
}


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

int main(){
  int n,C;
  cin >> n >> C;
  vector<vector<int>> d(C,vector<int>(C));
  for(int i=0;i<C;++i){
    for(int j=0;j<C;++j) cin >> d[i][j];
  }

  vector<vector<int>> c(n,vector<int>(n));

  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      cin >> c[i][j];
      c[i][j]--;
    }
  }

  vector<vector<int>> cost(3,vector<int>(C,0));

  for(int k=0;k<C;++k){
    for(int i=0;i<n;++i){
      for(int j=0;j<n;++j){
        cost[(i+j)%3][k] += d[c[i][j]][k];
      }
    }
  }

  int cal=1<<30;
  int co[3];
  for(co[0]=0;co[0]<C;++co[0]){
    for(co[1]=0;co[1]<C;++co[1]){
      if(co[0]==co[1])continue;
      for(co[2]=0;co[2]<C;++co[2]){
        if(co[2]==co[0] || co[2]==co[1])continue;
        int tmp=0;
        for(int l=0;l<3;++l)tmp += cost[l][co[l]];

        cal=min(cal,tmp);
      }
    }
  }
  cout << cal << endl;
  return 0;
}


Measured memory_bytes: 4576
#include <stdio.h>
#include <string.h>
int main(void){
    
 char a[10002];
 for(;scanf("%s",a)+1;){
 
 
 int j=0,i=0,n=strlen(a),k;
 for(k=0;k<n;k++){
     if(a[k]=='O'){
         if(a[k-1]=='J'&&a[k+1]=='I')
         j++;
         
         if(a[k-1]=='I'&&a[k+1]=='I')
         i++;
     }
 }
 printf("%d\n%d\n",j,i);
 }
}

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

#define MAXC 1000000007

int n,k;
int h[100005];
int dp[100005];

int solve(int x){
    if (x >= n-1) return 0;
    else if (dp[x] != -1) return dp[x];
    else {
        int aux = MAXC;
        for (int i = 1; i <= k; i++){
            if (x+i < n){
                aux = min(aux,abs(h[x]-h[x+i])+solve(x+i));
            }
        }
        return dp[x] = aux;
    }
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    memset(&dp,-1,sizeof(dp));
    for (int i = 0; i < n; i++){
        cin >> h[i];
    }
    cout << solve(0) << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
main(){
    string s;
    int d[102][102]={},r=0;
    while(getline(cin,s)){
        int c=1,digit=0;
        string t;
        for(int i=0;i<s.size();++i)
            if(s[i]==',')
                d[r][c++]=atoi(t.c_str()),t="";
            else t+=s[i];
        d[r++][c]=atoi(t.c_str());
    }
    int m[102][102]={};
    m[0][1]=d[0][1];
    int n=r/2+1;
    for(int i=1;i<n;i++)for(int j=1;j<102;j++)
        m[i][j]=d[i][j]+max(m[i-1][j-1],m[i-1][j]);
    for(int i=n;i<r;i++)for(int j=1;j<101;j++)
        m[i][j]=d[i][j]+max(m[i-1][j],m[i-1][j+1]);
    cout<<m[r-1][1]<<endl;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll c[500005]={},o[500005]={};
int main() {

	string s;
	ll total=0;

	cin>>s;
	rep(i,s.size()){
		if(s[i]=='<'){
			c[i]++;
			c[i]+=c[i-1];
			if(s[i+1]!='>')total+=c[i];
		}
	}
	rrep(i,s.size()){
		if(s[i]=='>'&&s[i-1]!='<'){
			o[i]++;
			o[i]+=o[i+1];
			total+=o[i];
		}
		if(s[i]=='>'&&s[i-1]=='<'){
			o[i]++;
			o[i]+=o[i+1];
			total+=max(o[i],c[i-1]);
		}
	}
	cout<<total<<endl;
	return 0;

}


Measured memory_bytes: 8708
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const int intinf = 1 << 30;
const long long mod = 1e9 + 7;

int counts = 0;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
};

void merge(vector<int> &A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1 + 1);
    vector<int> R(n2 + 1);
    rep(i, n1) L[i] = A[left + i];
    L[n1] = intinf;
    rep(i, n2) R[i] = A[mid + i];
    R[n2] = intinf;
    int i = 0, j = 0;
    rep(k, left, right) {
        counts++;
        if(L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(vector<int> &A, int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

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

    mergeSort(A, 0, n);

    vecout(A);
    cout << counts << endl;
}



Measured memory_bytes: 6740
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local function tostringxx(o, depth) depth = depth or 0 if depth > 10 then return "<too deep!>" end if o == _G then return "<_G>" end local indent0 = (" "):rep((depth) * 2) local indent1 = (" "):rep((depth+1) * 2) local indent2= (" "):rep((depth+2) * 2) if type(o) == 'table' then local keys = {} local types = {} for k in pairs(o) do types[type(k)] = true table.insert(keys, k) end local types_count = 0 local lasttype for k in pairs(types) do types_count = types_count + 1 lasttype = k end if types_count == 1 and (lasttype == 'string' or lasttype == 'number') then table.sort(keys) end local inside = {} for i=1,#keys do local k = keys[i] local v = o[k] if type(k) == 'string' then k = string.format('%q', k) end table.insert(inside, indent1 .. '['..tostring(k)..'] = ' .. tostringxx(v, depth + 1)) end return '{\n' .. table.concat(inside, ',\n') .. '\n' .. indent0 .. '}' else if type(o) == 'string' then o = string.format('%q', o) end return tostring(o) end end
local function richtraceback() local x = 2 while true do local info = debug.getinfo(x) if not info then break end local fname = '<' .. info.short_src .. ":" .. info.linedefined .. ">" if info.name then fname = info.name end print(info.short_src .. ":" .. info.currentline .. ": in " .. ("%q"):format(fname)) print(" LOCALS:") local p = 1 while true do local name, val = debug.getlocal(x,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) p = p + 1 end print(" UPVALUES:") for p=1,info.nups do local name, val = debug.getupvalue(info.func,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) end x = x + 1 end end
local function myassert(b) if not b then richtraceback() error("assertion failed") end end 
-----------------------
local D = read.n()
for i=1,D do
    print(1)
end

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

int main() {
int x ,y ,p;
while(1){
	cin>>x>>y>>p;
if(x==0){
	break;
}
int sum=0,j,l,jmax,lmax;
for(int k=1;k<=p/2;k++){
	jmax=0;
	lmax=0;
	int amin=k*100/(100+x);
	int amax=(k+1)*100/(100+x);
	if((k*100)%(100+x)!=0){
	amin=amin+1;
	}
	if(((k+1)*100)%(100+x)==0){
	amax=amax-1;
	}
	for(int a=amin;a<=amax;a++){
		j=a*(100+y)/100;
		if(jmax<j){
			jmax=j;
		}
	}
	int bmin=(p-k)*100/(100+x);
	int bmax=(p-k+1)*100/(100+x);
	if(((p-k)*100)%(100+x)!=0){
	bmin=bmin+1;
	}
	if((((p-k)+1)*100)%(100+x)==0){
	bmax=bmax-1;
	}
	for(int b=bmin;b<=bmax;b++){
		l=b*(100+y)/100;
		if(lmax<l){
			lmax=l;
		}
	}
	if(sum<(jmax+lmax)){
		sum=jmax+lmax;
	}
}
cout<<sum<<endl;
}

	return 0;
}

Measured memory_bytes: 1160