akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


//4, 3
LL K, A, B;
int main() {
  cin >> K >> A >> B;
  //cout << K << endl;
  K += 1;
  if (B > A + 2 && K >= A) {
    K -= A;
    cout << K % 2 + (B - A) * (K / 2) + A << endl;
    //cout << (K / (A + 2)) * B + K % (A + 2);
  } else {
    cout << K << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
SS, res = [], []
for _ in range(N):
    SS.append(input().rstrip())
SS += ["#"]
for i in range(N):
    S = SS[i]
    if S=="AB":
        if A==B==1:
            if SS[i+1]=="BC": A, B = A-1, B+1; res.append("B")
            else: A, B = A+1, B-1; res.append("A")
        elif A>B: A, B = A-1, B+1; res.append("B")
        else: A, B = A+1, B-1; res.append("A")
    if S=="AC":
        if A==C==1:
            if SS[i+1]=="BC": A, C = A-1, C+1; res.append("C")
            else: A, C = A+1, C-1; res.append("A")
        elif A>C: A, C = A-1, C+1; res.append("C")
        else: A, C = A+1, C-1; res.append("A")
    if S=="BC":
        if B==C==1:
            if SS[i+1]=="AC": B, C = B-1, C+1; res.append("C")
            else: B, C = B+1, C-1; res.append("B")
        elif B>C: B, C = B-1, C+1; res.append("C")
        else: B, C = B+1, C-1; res.append("B")
    if A<0 or B<0 or C<0:
        print("No")
        exit()
print("Yes")
print(*res, sep="\n")



Measured memory_bytes: 95096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int f=0;
  while(a>0 && c>0)
  {
    if(f==0)
    {c-=b;
     f=1;
    }
    else
    {
      a-=d;
      f=0;
    }
  }
  if(a<=0)
    cout<<"No";
  else
    cout<<"Yes";
  
}

Measured memory_bytes: 3636
A, B, C, X, Y = list(map(int, input().split()))

result = float('inf')
for i in range(0, max(X, Y)+1):
    tmp = C*2*i + max(0, X-i) * A + max(0, Y-i) * B
    if tmp < result:
        result = tmp
print(result)


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  int x;
  if(a>=b) {
    x = a;
    a--;
  }
  else{
    x = b;
    b--;
  }
  if(a>=b) {
    x += a;
  }
  else x+=b;
  cout << x <<"\n";
  return 0;
}


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

object Main {
  case class Rotation(run: Dice => Dice){
    def apply(d: Dice): Dice = run(d)
    def compose(other: Rotation) = Rotation(run compose other.run)
  }

  object Rotation {
    def id = Rotation(d => d)
    def north = Rotation(d => Dice(List(1,5,2,3,0,4).map(d.pip)))
    def east = Rotation(d => Dice(List(3,1,0,5,4,2).map(d.pip)))
    def ccw = Rotation(d => Dice(List(0,3,1,4,2,5).map(d.pip)))

    final def axial(rot: Rotation): Seq[Rotation] =
      for(i <- 0 to 3) yield List.fill(i)(rot).fold(id)(_ compose _)

    def enumerateTop: Seq[Rotation] =
      for(i <- 1 to 6) yield ((0 to i).map(j => if(j % 2 == 0) north else east)).fold(id)(_ compose _)

    def enumerate: Seq[Rotation] = enumerateTop.flatMap(e => axial(ccw).map(e compose _))
  }

  case class Dice(pip: List[Int]){
    lazy val all: Seq[Dice] = Rotation.enumerate.map(_.run(Dice(pip)))
    def ===(that: Dice): Boolean = pip.corresponds(that.pip)(_ == _)
    def ==(that: Dice): Boolean = all.exists(_ === that)
  }

  def main(args: Array[String]): Unit = {
    val Array(n,_*) = readLine.split(" ").map(_.toInt)
    val dices = for(i <- 1 to n) yield Dice(readLine.split(" ").map(_.toInt).toList)

    val res = for{
      i <- 0 until n
      j <- i+1 until n
    } yield dices(i) == dices(j)

    println( if(res.forall(_ == false)) "Yes" else "No")
  }
}

Measured memory_bytes: 56432
#include <cstdio>
#define MOD 1000000007
typedef long long ll;
ll dp[405][405][405];
int a[405], b[405], appa[405], appb[405], app[405][405];
int main()
{
	// freopen("CF17-QC-F.in", "r", stdin);
	int n; 
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", a + i);
		appa[a[i]] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", b + i);
		appb[b[i]] = i;
	}
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
				app[i][j] += appa[k] <= i || appb[k] <= j;
		}
	}
	dp[0][0][0] = 1;
	for (int i = 1; i <= n / 3; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				dp[i][j][k] = (dp[i][j - 1][k] + dp[i][j][k - 1] - dp[i][j - 1][k - 1]) % MOD;
				if (appa[b[k]] > j && appb[a[j]] > k)
					(dp[i][j][k] += dp[i - 1][j - 1][k - 1] * (3 * i - app[j][k])) %= MOD; 
			}
		}
	}
	ll ans = (dp[n / 3][n][n] + MOD) % MOD;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3)
			ans = ans * i % MOD; 
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	long long a, b, c;
	cin >> a >> b >> c;
	long long x = a * b * (c % 2), y = b * c * (a % 2), z = c * a * ( b % 2);
	cout << min(x, min(y, z)) << endl;
	return 0;	
}


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

constexpr ll mod = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    if (abs(n - m) > 1)
    {
        cout << 0 << endl;
        return 0;
    }

    ll ans;
    if (abs(n - m) == 1)
        ans = max(n, m);
    else
        ans = 2;

    const int t = min(n, m);
    for (int i = 2; i <= t; ++i)
        ans = ans * i % mod, ans = ans * i % mod;

    cout << ans << endl;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  char c;
  std::cin >> c;

  std::cout << static_cast<char>(c + 1) << std::endl;
  return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int sum = a + b + c;
  int mx = max({a, b, c});
  int res = mx * 3 - sum;
  if (res % 2 == 0) {
    cout << res / 2 << endl;
  } else {
    cout << (res + 3) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 9999999999
lists = []
if n == 0:
    print(x)
    exit()
for i in range(-1000, 1000):
    if not i in p:
        lists.append(i)
for i in lists:
    if ans > abs(x - i):
        ans = abs(x-i)
        m = i
print(m)

Measured memory_bytes: 8936
import sys
input = sys.stdin.readline
from heapq import heappush, heappop

N = int(input())
A = [int(x) for x in input().split()]
a_to_i = {a:i for i,a in enumerate(A)}

# sparse table を使ってRMQ
# parityの同じところだけを見るようにしておく

U = len(A).bit_length()
sp = [None,A]
for i in range(2,U):
    L = 1 << (i-1)
    sp.append([x if x < y else y for x,y in zip(sp[-1][:-L], sp[-1][L:])])

def RMQ(x,y):
    # x番目から偶数番目だけ見て[x,y]での最小値を返す
    d = y - x
    if d <= 1:
        return A[x]
    n = d.bit_length()
    return min(sp[n-1][x], sp[n-1][y+2-(1<<(n-1))])

def F(x,y):
    # 辞書式で最小の2つ組をとる
    # そのあと、今後調べないといけない区間の一覧を返す
    x1 = RMQ(x,y-1)
    i1 = a_to_i[x1]
    x2 = RMQ(i1+1,y)
    i2 = a_to_i[x2]
    task = ((x,y) for x,y in ((x,i1-1), (i1+1,i2-1), (i2+1,y)) if y > x)
    return x1,x2,task

q = [(None,None,((0,N-1),))]
answer = []
while q:
    x,y,task = heappop(q)
    answer.append(x)
    answer.append(y)
    for left,right in task:
        heappush(q,F(left,right))

print(' '.join(map(str,answer[2:])))

Measured memory_bytes: 108108
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0;
  cin >> n;
  long long a[3*n];
  for(int i=0;i<3*n;i++){
    cin >> a[i];
  }
  sort(a,a+3*n);
  int x=0;
  for(int i=n;i<3*n;i++){
    if(x%2==0){
      ans+=a[i];
    }
    x++;
  }
  cout << ans << endl;
  return 0;
}


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

s = input()
n = len(s)
dp = [-1 for i in range(n)]
def count(i):
    if dp[i] != -1:
        return dp[i]
    elif i+2 >= n:
        dp[i] = 0
    elif s[i+1] == 'B' and s[i+2] == 'C':
        dp[i] = count(i+2)+1
    elif s[i+1] == 'A':
        dp[i] = count(i+1)
    else:
        dp[i] = 0
    return dp[i]
ans = 0
for i in range(n):
    if s[i] == 'A':
        ans += count(i)

print(ans)

Measured memory_bytes: 170572
#include<stdio.h>
#include<string.h>
#define L 100005

typedef struct pp{
  char name[100];
  int t;
}A;

A deq();
void enq(A x);
A Q[L];
int t,h, n;

int min(int a,int b){ return a<b ? a : b;}

int main(){

  int elaps=0, c;
  int i, q;
  A u;

  scanf("%d %d", &n, &q);

  for(i=1;i<=n;i++){
    
    scanf("%s",Q[i].name);

    scanf("%d",&Q[i].t);

  }
  
  h=1; t=n+1;

  while(h !=t){

    u=deq();
    c=min(q, u.t);
    u.t -=c;
    elaps+=c;
    if(u.t>0) enq(u);
    else{
      printf("%s %d\n",u.name, elaps);
    }
  }

  return 0;
}



A deq(){
  A x =Q[h];
  h = (h+1)%L;
  return x;
}

void enq(A x){
  Q[t]=x;
  t=(t+1)%L;
}



Measured memory_bytes: 11984
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
 int n,m;
 cin>>n>>m;
 priority_queue<long long int>pq;
 for(int i=0;i<n;i++)
 {
     long long int temp;
     cin>>temp;
     pq.push(temp);
 }
 for(int i=0;i<m;i++)
 {
     ll temp=pq.top();
     pq.pop();
     pq.push(temp/2);

 }
 ll ans=0;
 while(!pq.empty())
 {

     ll temp=pq.top();
     pq.pop();
     ans+=temp;
 }
 cout<<ans;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
//usingを使ってlong long intをlliで省略できるようにする。(必須ではない)
using lli = long long int;

int main() {
	int N;
	cin >> N;
	vector<lli> v(N);
	map<lli, lli> m;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		//v[i]の長さの棒の本数を増やす
		m[v[i]]++;
	}
	sort(v.rbegin(), v.rend());
	lli ansA = 0, ansB = 0;
	for (int i = 0; i < N; i++) {
		//v[i]の長さの棒が2本以上あるか判定
		if (m[v[i]] >= 2) {
			if (ansA == 0) {
				ansA = v[i];
				//棒を使ったので2本減らす
				m[v[i]] -= 2;
			}
			else {
				//2つ目のペアがそろったらループから抜ける
				ansB = v[i];
				break;
			}
		}
	}
	cout << ansA * ansB << endl;
}

Measured memory_bytes: 7296
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
#include<stdio.h>
#include<string>
#include<malloc.h>
#include<string.h>
#include<stack>
#include<algorithm>
#include<map>
#include<utility>//pair
#define MAX 0x3f3f3f3f
int solve(int n, int m)
{
	return (n - 1)*(m - 1);
}

int main()
{
	int n, m;
	while (cin >> n >> m) {
		cout << solve(n, m) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N,M = map(int,input().split())
fr = [[0]*2 for _ in range(M)]
for i in range(M):
    fr[i][:] = list(map(int,input().split()))
    fr[i][0] -= 1
    fr[i][1] -= 1

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i in range(self.n) if self.parents[i] < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())

d = UnionFind(N)

for i in range(M):
    a,b = map(int,fr[i])
    d.union(a,b)

M = 0
for i in range(N):
    M = max(M,-d.size(i))
print(M)









Measured memory_bytes: 96336
def abc170_c():
    def solve():
        x, n = map(int, input().split(' '))
        if n == 0:
            return x

        p = list(map(int, input().split(' ')))

        search_range_min = min(min(p), x) - 1
        search_range_max = max(max(p), x) + 1
        search_values = [i for i in range(search_range_min, search_range_max + 1) if i not in p]

        check_dict = {}

        for i in search_values:
            # 絶対値が小さいものを調べるので差の絶対値を格納
            check_dict[i] = abs(x - i)

        return min(check_dict, key=check_dict.get)
    print(solve())

if __name__ == '__main__':
    abc170_c()

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

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

        while( (line = br.readLine()) != null){
            int a = Integer.parseInt(line);
            int count = 0;

            if(a > 36){
                System.out.println(count);
                continue;
            }

            for(int i = 9; i >= 0; i--){
                for(int j = 9; j >= 0; j--){
                    for(int k = 9; k>= 0; k--){
                        for(int l = 9; l >= 0; l--){
                            if(i+j+k+l == a) count++;
                        }
                    }
                }
            }

            System.out.println(count);
        }

    }
}

Measured memory_bytes: 24660
N=int(input())
al=input().split()
mc = 0
tt = 0
min = abs(int(al[0]))

for i in range(N):
    if int(al[i]) < 0:
        mc += 1
    tt += abs(int(al[i]))

    if min > abs(int(al[i])):
       min = abs(int(al[i]))

if (mc % 2):
    print(tt-2*min)
else:
    print(tt)


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

const int N = 600;
const double INF = 1e9;

int n,m;
int dis = 0;

vector<int> adj[605];

double memo[605];

double dp(int x){
	if(x == n) return 0.0;
	double &ret = memo[x];
	if(ret>=0.0) return ret;
	ret = 0;
	for(int i=0;i<adj[x].size();i++){
		int cur = adj[x][i];
		ret += dp(cur);
	}
	ret = ret/(double)adj[x].size();
	if(x == dis && adj[x].size() > 1){
		double lol2;
		double lala = 0.0;
		for(int i=0;i<adj[x].size();i++){
			int cur = adj[x][i];
			lala += dp(cur);
		}
		lol2 = lala;
		for(int i=0;i<adj[x].size();i++){
			int cur = adj[x][i];
			double now = lala - dp(cur);
			lol2 = min(lol2,now);
		}
		lol2/=(double)(adj[x].size()-1);
		ret = min(ret,lol2);
	}
	ret = ret+1.0;
	return ret;
}

void reset(){
	for(int i=0;i<=601;i++){
		memo[i] = -1.0;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
	}
	double ans = INF;
	for(int i=1;i<=n;i++){
		dis = i;
		reset();
		ans = min(ans,dp(1));
	}
	printf("%.9lf\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	ll n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;			 

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int N;
    cin >> N;
    ll ans=0;
    for (int i=1;i<=N;i++){
        if(i%3 == 0 || i%5==0){
            continue;
        }
        ans += i;

    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))

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

template<class T> void dump(const vector<T> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

template<class T> void dump(int w, int h, const vector<T> &v)
{
	REP(j, h){
		REP(i, w-1){ cout << v[j * w + i] << " "; }
		cout << v[j * w + w-1] << endl;
	}
}

template<class T> struct Matrix
{
	T w, h;
	vector<T> A;
	Matrix(T w_, T h_) : w(w_), h(h_), A(w * h) {}
	T get(T x, T y) const { return A[y * w + x]; }
};

template<class T> void input(Matrix<T> &m)
{
	REP(j, m.h){
		REP(i, m.w){
			cin >> m.A[j * m.w + i];
		}
	}
}

template<class T> Matrix<T> prod(const Matrix<T> &a, const Matrix<T> &b)
{
	Matrix<T> m(b.w, a.h);

	REP(j, m.h){
		REP(i, m.w){
			ll c = 0;
			REP(k, a.w){
				c += a.A[j * a.w + k] * b.A[k * b.w + i];
			}
			m.A[j * m.w + i] = c;
		}
	}

	return m;
}

void dump(const Matrix<ll> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%lld ", m.A[j * m.w + i]); }
		printf("%lld\n", m.A[j * m.w + m.w-1]);
	}
}

void dump(const Matrix<double> &m)
{
	REP(j, m.h){
		REP(i, m.w-1){ printf("%f ", m.A[j * m.w + i]); }
		printf("%f\n", m.A[j * m.w + m.w-1]);
	}
}

string &to_upper(string &s)
{
	REP(i, s.length()){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] -= 32;
		}
	}

	return s;
}

int main()
{
	string W;

	cin >> W;

	to_upper(W);

	int cnt = 0;

	for(;;){
		string T;
		cin >> T;

		if(T == "END_OF_TEXT")
			break;
		
		to_upper(T);

		if(T == W)
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>

int prim(int **, int);

int main(){

  int i, j;
  int n;
  int **a;

  scanf("%d", &n);

  a = (int **)malloc(sizeof(int *) * n);

  for(i = 0; i < n; i++){
    a[i] = (int *)malloc(sizeof(int) * n);
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &a[i][j]);

    }

  }

  printf("%d\n", prim(a, n));

  return 0;
}

int prim(int **a, int n){

  int i;
  int *d;
  int *pi;
  int *color;
  int min, u, ans = 0;
  
  d = (int *)malloc(sizeof(int) * n);
  pi = (int *)malloc(sizeof(int) * n);
  color = (int *)malloc(sizeof(int) * n);
  
  for(i = 0; i < n; i++){
    d[i] = 10000;
    pi[i] = -1;
    color[i] = 0;
  }

  d[0] = 0;

  while(1){

    min = 10000;

    for(i = 0; i < n; i++){
      if(color[i] != 1 && d[i] < min){
	min = d[i];
	u = i;

      }

    }

    if(min == 10000) break;

    color[u] = 1;

    for(i = 0; i < n; i++)
      if(a[u][i] != -1){
	if(color[i] != 1 && a[u][i] < d[i]){
	  pi[i] = u;
	  d[i] = a[u][i];
	}

      }

  }

  for(i = 0; i < n; i++){
    ans += d[i];
    }

  return ans;
}

Measured memory_bytes: 640
// 解き直し.
// https://img.atcoder.jp/data/arc/056/editorial.pdf
// テストケース(1_12.txt) などで, TLE版となったため, ロジック修正.
// AtCoder Beginner Contest 051 (D - Candidates of No Shortest Paths) で 実装した ダイクストラ法 を 一部流用.
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
double cost[1010][1010];          // 頂点(i, j) の 最小コスト を 保存.
double x[1010], y[1010], r[1010]; // バリア情報.
double b[1010][1010];             // バリア i, j の 中心を結ぶ辺のコスト.

struct edge {
    int u;    // 次の頂点.
    double d; // 距離.
    bool operator < (const edge &E) const { return d > E.d; }
};

vector<edge> G[1010];

// https://ja.wikipedia.org/wiki/ダイクストラ法
// グラフを最良優先探索する.
// ※dijkstraの動作確認用.
// @param s: 今回探索する頂点番号.
// @return: 特に無し.
void dijkstra(int s){
    
    // 1. 初期化.
    priority_queue<edge> pq;
    
    // 2. 始点設定.
    pq.push({s, 0.0});
    cost[s][s] = 0.0;
    
    // 3. キュー pq が 空になるまで, 探索.
    while(!pq.empty()){
        // 4. 探索を継続するために, 頂点を取得.
        int u = pq.top().u;    // 頂点番号.
        double d = pq.top().d; // コスト.
        pq.pop();
        
        // 5. より小さいコストが設定済みなら, Skip.
        if(cost[s][u] < d) continue;
        
        // 6. 各隣接する頂点について, コストを確認し, 最短コストを更新.
        rep(i, G[u].size()){
            int nu = G[u][i].u;
            double nd = d + G[u][i].d;
            // 最短コスト更新.
            if(cost[s][nu] > nd) cost[s][nu] = nd, pq.push({nu, nd});
        }
    }
}

int main(){
    
    // 1. 入力情報.
    double xs, ys, xt, yt;
    int N;
    scanf("%lf %lf %lf %lf %d", &xs, &ys, &xt, &yt, &N);
    rep(i, N) scanf("%lf %lf %lf", &x[i + 1], &y[i + 1], &r[i + 1]);
    x[0] = xs, y[0] = ys, x[N + 1] = xt, y[N + 1] = yt;
    
    // 2. 辺のコストを事前計算.
    rep(i, N + 1){
        repx(j, i + 1, N + 2){
            double w = max(0.0, hypot(x[i] - x[j], y[i] - y[j]) - (r[i] + r[j]));
            b[i][j] = w;
            b[j][i] = w;
        }
    }
    
    // 3. グラフ作成.
    // 頂点が, 0, 1, ... , N, N + 1 までの (N + 2)頂点あると見る.
    rep(i, N + 1){
        repx(j, i + 1, N + 2){
            G[i].pb({j, b[i][j]});
            G[j].pb({i, b[j][i]});
        }
    }
    
    // 4. ダイクストラ法.
    rep(i, 1010) rep(j, 1010) cost[i][j] = 202020202020202020.0;
    dijkstra(0);
    
    // 5. 出力.
    printf("%.10f\n", cost[0][N + 1]);
    return 0;
    
}

Measured memory_bytes: 39656
#include<stdio.h>
int main(void)
{
int a,b,d=0,r=0;
double f=0.0;
scanf("%d %d",&a,&b);
d=a/b;
r=a%b;
f=(double)a/b;
printf("%d %d %f\n",d,r,f);
return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<string.h>

int main(){
  char S[51];
  char T[51];
  int i,j,k,sl,tl,judge = 0;

  scanf("%s %s",S,T);

  sl = strlen(S);
  tl = strlen(T);

  for(i=sl - tl + 1;i>=0;i--){
    judge = 0;
    for(j=0;j<tl;j++){
      if(S[i+j] != T[j] && S[i+j] != '?')
        judge = 1;
    }
    if(judge == 0)break;
  }

  if(judge == 1){
    puts("UNRESTORABLE");
    return 0;
  }


  for(k=0;k<tl;k++)
    S[i+k] = T[k];

  for(i=0;i<sl;i++){
    if(S[i] == '?')
      S[i] = 'a';
  }

  printf("%s\n",S);

  return 0;
}


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

struct max_flow
{
    struct edge{ll to,cap,rev;};
    ll V;
    vector<vector<edge>> graph;
    vector<pair<ll,ll>> prev;
public:
    
    max_flow(ll n)
    {
        V=n;
        graph.resize(V,vector<edge>());
        prev.resize(V);
    }

    void add_edge(ll from,ll to, ll cap)
    {
        graph[from].push_back((edge){to,cap,(ll)graph[to].size()});
        graph[to].push_back((edge){from,0,(ll)graph[from].size()-1});
        return;
    }
    bool bfs(ll s,ll t)
    {
        vector<bool> visit(V,false);
        for (ll i=0;i<V;i++) prev[i]=make_pair(-1,-1);
        vector<ll> d(V,INF);
        visit[s]=true;prev[s].first=s;d[s]=0;
        queue<ll> que;
        que.push(s);
        ll v;
        while (!que.empty())
        {
            v=que.front();
            que.pop();
            for (ll i=0;i<graph[v].size();i++)
            {
                edge e=graph[v][i];
                if (!visit[e.to] && d[e.to]>d[v]+1 && e.cap>0)
                {
                    prev[e.to]=make_pair(v,i);
                    d[e.to]=d[v]+1;
                    visit[e.to]=true;
                    que.push(e.to);
                }
            }
        }
        return prev[t].first!=-1;
    }

    void update(ll from,ll to, ll f,ll edgenum)
    {
        edge e=graph[from][edgenum];
        graph[from][edgenum].cap-=f;
        graph[e.to][e.rev].cap+=f;
        return;
    }

    ll run(ll s,ll t)
    {
        ll from,to,f,ans=0;
        while(bfs(s,t))
        {
            from=-1;to=t;f=INF;
            while (from!=s)
            {
                from=prev[to].first;
                f=min(f,graph[from][prev[to].second].cap);
                to=from;
            }
            to=t;from=-1;
            while (from!=s)
            {
                from=prev[to].first;
                update(from,to,f,prev[to].second);
                to=from;
            }
            ans+=f;
        }
        return ans;
    }
};

int main()
{
    ll N;cin >> N;
    
    ll ans=0;
    max_flow solve(N+2);
    ll a;
    for (ll i=0;i<N;i++)
    {
        cin >> a;
        if (a<=0)
        {
            solve.add_edge(0,i+1,-a);
            for (ll j=2;j*(i+1)<=N;j++) 
            {
                solve.add_edge(i+1,j*(i+1),INF);
            }
        }
        else
        {
            ans+=a;
            solve.add_edge(i+1,N+1,a);
            for (ll j=2;j*(i+1)<=N;j++) 
            {
                solve.add_edge(i+1,j*(i+1),INF);
            }
        }
    }
    cout << ans-solve.run(0,N+1) << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


const double PI = acos(-1);
const int M = 1000005;

int main(){
    string s;
    cin>>s;
    
    vector<ll> cnt(2,0);
    
    for(ll i = 0; i<s.size(); i++){
        cnt[s[i] - '0']++;
    }
    ll ans = min({cnt[1], cnt[0]}) * 2;
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3736
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair<int, int> P;

vector <int> edge[100005];
bool visited[100005];

int dfs(int cur, int goal) {
    visited[cur] = true;
    if (cur == goal) return 1;

    int ret = 0;
    for (int x : edge[cur]) {
        if (!visited[x]) {
            ret += dfs(x, goal);
        }
    }

    return ret;
}

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int six = 0;
    int four = 0;
    vector <int> idx;
    for (int i = 0; i < n; i++) {
        if (edge[i].size() % 2 == 1) {
            cout << "No\n";
            return 0;
        } else if (edge[i].size() == 6) {
            six++;
        } else if (edge[i].size() == 4) {
            four++;
            idx.push_back(i);
        }
    }

    if (six > 0 || four > 2) {
        cout << "Yes\n";
        return 0;
    } else if (four < 2) {
        cout << "No\n";
        return 0;
    }

    int ans = 0;
    visited[idx[0]] = true;
    for (int i = 0; i < edge[idx[0]].size(); i++) {
        visited[idx[1]] = false;
        ans += dfs(edge[idx[0]][i], idx[1]);
    }

    if (ans == 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 7040
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop with position = 0
        for idx from offset below (length dest-vector)
        do (setf (values (aref dest-vector idx) position)
                 (parse-integer string :start position :junk-allowed t))
           (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (x (read))
         (xs (make-array n :element-type 'uint32)))
    (declare (uint32 n x))
    (split-ints-into-vector (read-line) xs)
    (println (reduce #'gcd xs :key (lambda (xi) (abs (- xi x)))))))

#-swank(main)


Measured memory_bytes: 18920
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main()
{
    int h,w;
  cin >> w >>h;

  vector< vector<char> > v;
  v = vector< vector<char> >(w+2,vector<char>(h+2,'#'));

  for (int i = 1; i < w+1; ++i)
  {
      for (int j = 1; j < h+1; ++j)
      {
          char k;
          cin >> k;
          v[i][j] = k;
      }
  }
    
  for (int i = 0; i < w+2; ++i)
  {
      for (int j = 0; j < h+2; ++j){
        cout << v[i][j];
      }
    cout <<endl;
  }

    
    return 0;
}






Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int A1,A2,A3,a1,a2,a3,cost=0;
    cin>>A1>>A2>>A3;
    if(A1<=A2&&A1<=A3&&A2<=A3)
    {
        a1=A1;
        a2=A2;
        a3=A3;
    }
    else if(A1<=A2&&A1<=A3&&A3<=A2)
    {
        a1=A1;
        a2=A3;
        a3=A2;
    }
    else if(A2<=A1&&A2<=A3&&A1<=A3)
    {
        a1=A2;
        a2=A1;
        a3=A3;
    }
    else if(A2<=A1&&A2<=A3&&A3<=A1)
    {
        a1=A2;
        a2=A3;
        a3=A1;
    }
    else if(A3<=A1&&A3<=A2&&A1<=A2)
    {
        a1=A3;
        a2=A1;
        a3=A2;
    }
    else if(A3<=A1&&A3<=A2&&A2<=A1)
    {
        a1=A3;
        a2=A2;
        a3=A1;
    }
    cout<<0+a2-a1+a3-a2<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef struct Cor {
	double x;
	double y;
} Cor;

int main() {
	int N;
	scanf("%d", &N);
	Cor city[N];
	for (int i = 0; i < N; i++) {
		scanf("%lf %lf", &city[i].x, &city[i].y);
	}
	double ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			ans += sqrt(pow(city[i].x - city[j].x, 2.0) + pow(city[i].y - city[j].y, 2.0));
		}
	}
	printf("%lf\n", (ans*2) / (double)N);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			if(!sc.hasNextInt()){
				break;
			}
			int n = sc.nextInt();
			int count = 0;
			for(int a = 0; a < 10; a++){
				for(int b = 0; b < 10; b++){
					for(int c = 0; c < 10; c++){
						for(int d = 0; d < 10; d++){
							if(a+b+c+d == n){
								count++;
							}
						}						
					}
				}
			}
			System.out.println(count);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
		
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, L;
ll MOD = 998244353; ll INF = 9999999999999; ll ans = 1;
vll flag, color; vll path; vl D; string S; vl P; vl W;
//***********//
ll battle(ll a, ll b) {
	ll big = max(a, b);
	ll small = min(a, b);
	if (W[abs(a - b) - 1] == 0) {
		return small;
	}
	else {
		return big;
	}
}
int main() {
	cin >> N;
	cin >> S;
	//cout << "hoge";
	ll L = S.length(); L++;
	W.resize(L-1);
	for (i = 0; i < L-1; i++) {
		W[i]=ctoi(S[i]);
	}
	//cout << L;
	for (i = 0; i < L; i++) {
		ll p;
		cin >> p;
		P.push_back(p);
	}
	//cout << "huga";
	vector<vll> list(N + 1);
	list[0].resize(1);
	list[0][0] = P;
	//k海戦目
	//ll size = L;
	for (k = 0; k < N; k++) {
		for (ll p = 0; p < list[k].size(); p++) {
			ll q = p * 2;
			list[k + 1].resize(list[k].size() * 2);
			ll size = list[k][p].size();
			for (ll i = 0; i < size - 1; i+=2) {
				//cout << i;
				//cout << list[k][p][i] << list[k][p][i + 1];
				//cout << battle(list[k][p][i], list[k][p][i + 1]);
				list[k + 1][q].push_back(battle(list[k][p][i], list[k][p][i + 1]));
				//cout << "aaa";
			}
			//cout << "hoge";
			//cout << "a-" << q;
			q++;
			for (ll i = 1; i < size-2; i+=2) {
				//cout << battle(list[k][p][i], list[k][p][i + 1]);
				list[k + 1][q].push_back(battle(list[k][p][i], list[k][p][i + 1]));
			}
			//cout << battle(list[k][p][size-1], list[k][p][0]);
			list[k + 1][q].push_back(battle(list[k][p][size-1], list[k][p][0]));
			//cout << "hoge";
			//cout << "a-" << q;
		}
		//size /= 2;
		//cout << "b" << endl;
	}
	for (i = 0; i < L; i++) {
		ll p = i;
		ll num = 0;
		//cout << p;
		ll P = L / 2;
		for (j = 0; j < N; j++) {
			if (p % 2 == 1) {
				num += P;
			}
			P /= 2;
			p /= 2;
		}
		//cout << num;
		cout << list[N][num][0] << endl;
	}
}


Measured memory_bytes: 68672
from sys import stdin
input = stdin.readline
def minus(n):
  return n-1
  
def main():
  num_list = list(map(int, input().split()))
  A = list(map(int, input().split()))
  N=num_list[0]
  K=num_list[1]
  A_i=0
  N_list=[0]*N
  A =list(map(minus, A))
  sFlag=True
  i=0
  while(sFlag):
    i=i+1
    pre=A_i
    N_list[A_i]+=1
    if(N_list[A_i]==3):
      sumA=N_list.count(int(2))
      sumA=sumA+N_list.count(int(3))
      K=(K-i)%sumA+1
      for j in range(K):
        pre=A_i
        te=A[A_i]
        A_i=te
      sFlag=False
      break
    te=A[A_i]
    A_i=te
    if(i>=K):
      sFlag=False
      break
  print(A_i+1)
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 100452
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
#define all(x) (x).begin(),(x).end()
using namespace std;
signed main(){
	int a;
	string s;
	cin>>a>>s;
	if(a<3200)puts("red");
	else cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;

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

    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));
    dp[0][0] = 0;
    for (int i=1; i<(int)s.size()+1; i++) {
        for (int j=1; j<(int)t.size()+1; j++) {
            if (s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int i=s.size(), j=t.size();
    string ans = "";
    while (i>0 && j>0) {
        if (s[i-1] == t[j-1]) {
            ans += s[i-1];
            i--; j--;
        } else if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }
    for (auto c=ans.rbegin(); c!=ans.rend(); c++)
        cout << *c;
    cout << "\n";
}


Measured memory_bytes: 38484
#include <bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, X, D;
	cin >> N >> X >> D;
	if (D == 0) {
		if (X == 0) {
			cout << 1 << endl;
		} else {
			cout << 1 + N << endl;
		}
		return 0;
	}
	if (D < 0) {
		X = -X;
		D = -D;
	}
	map<int, int> R;
	int mn = 0;
	int mx = 0;
	int res = 0;
	vector<pair<int, pair<int, int> > > vp;
	vp.emplace_back(0, make_pair(0, 0));
	for (int i = 1; i <= N; i++) {
		int sum = X * i;
		mn += i - 1;
		mx += N - i;
		int ll = sum / D;
		// if (D * ll > sum) {
		// 	ll--;
		// }
		int md = sum - D * ll;
		int l = ll + mn;
		int r = ll + mx;
		// dd(sum); dd(ll); dd(md); dd(l); de(r);
		vp.emplace_back(md, make_pair(l, r));
	}
	sort(vp.begin(), vp.end());
	for (int i = 0; i < vp.size(); i++) {
		//cerr << i << " " << l << " " << r << endl;
		int md = vp[i].first;
		int l = vp[i].second.first;
		int r = vp[i].second.second;
		int t;
		// dd(md);dd(l);de(r);
		if (R.count(md) == 0) {
			t = -((int)1 << 60);
		} else {
			t = R[md];
		}
		if (t >= l) {
			l = t + 1;
		}
		if (t < r) {
			res += r - l + 1;
			R[md] = r;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 18412
#include<stdio.h>
#define SWAP(a,b)({a ^= b; b ^= a; a ^= b;})
int main(){
    int a, b, c;
    while(scanf("%d %d %d", &a, &b, &c) == 3){
        if(a>b) SWAP(a, b);
        if(c<b) SWAP(b, c);
        if(a>b) SWAP(a, b);
        printf("%d %d %d\n", a, b, c);
    }
return 0;
}



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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	ret(n*n*n)	
	
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author phantom11
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            int i;
            for (i = 0; i < n; i++) {
                a[i] = in.nextInt() - 1;
            }
            int c = 0;
            for (i = 0; i < n; i++) {
                if (a[a[i]] == i) {
                    c++;
                }
            }
            out.printLine(c / 2);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22156
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    from collections import defaultdict

    d = defaultdict(list)

    for i in range(M):
        d[s[i]].append(c[i])
        d[s[i]] = list(set(d[s[i]]))

    if not all([len(v) == 1 for k, v in d.items()]):
        print('-1')
        exit()

    ans = []
    for i in range(1, N+1):
        if d[i]:
            ans.append(d[i][0])
        elif i == 1 and N >= 2:
            ans.append(1)
        else:
            ans.append(0)

    if len(str(int(''.join(map(str, ans))))) != N:
        print(-1)
    else:
        print(int(''.join(map(str, ans))))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    string S; cin >> S;
    int cnt = 0;
    int ans = 0;
    rep(i,S.length()) {
        if(S[i] == 'A' or S[i] == 'T' or S[i] == 'G' or S[i] == 'C') {
            cnt++;
            ans = max(ans, cnt);
        }
        else {
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int A[3][3];
  rep(i,3){
    rep(j,3){
      cin >> A[i][j];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n+10);
  rep(i,n) cin >> b[i];
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(b[i] == A[j][k]){
          A[j][k] = 0;
        }
      }
    }
  }
  bool flag = false;
  rep(i,3){
    if(A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) flag = true;
    else if(A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0) flag = true;
  }
  if(A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) flag = true;
  if(A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) flag = true;
  if(flag) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256