akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int n;

    cin >> n;

    if (n < 1200) {
        cout << "ABC";
    } else if (n < 2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] ab = new int[N];
		for(int i = 0; i < N; i++) ab[i] = i+1;
		for(int i = 0; i < W; i++) {
			int a, b, tmp = 0;
			String[] s = sc.next().split(",");
			a = Integer.parseInt(s[0]) - 1;
			b = Integer.parseInt(s[1]) - 1;
			tmp = ab[a]; ab[a] = ab[b]; ab[b] = tmp;
		}
		for(int i = 0; i < N; i++) {
			System.out.println(ab[i]);
		}
	}
}

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

int main() {
    long long N;
    cin>>N;
    
    long long dddd = 0;

    for (long long i=1; i<=sqrt(N); i++) {
        if (N%i==0) dddd = max(dddd, i);
    }
    cout << (N/dddd) + dddd -2 << endl;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	a := nextInt()
	s := nextString()

	if a < 3200 {
		_, _ = fmt.Fprint(writer, "red")
	} else {
		_, _ = fmt.Fprintf(writer, "%s", s)
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
c={'N':"152304",'E':"310542",'W':"215043",'S':"402351",'R':"024135",'L':"031425"}
while 1:
 n=int(input())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[int(e)]for e in c[input()[0]]]
  a+=int(s[0])
 print(a)


Measured memory_bytes: 5656
#include <iostream>
#include <cmath>
#include <algorithm>
#define INF 1e19
#define MAX_V 1010
#define double long double
using namespace std;

double cost[MAX_V][MAX_V];
double d[MAX_V];
bool used[MAX_V];
int V;

void dijkstra(int s){
	fill (d,d+V,INF);
	fill (used,used+V,false);
	d[s] = 0;
	while(true){
		int v = -1;
		for(int u=0;u<V;u++){
			if(used[u]!=true && (v==-1 || d[u]<d[v])){
				v = u;
			}
		}
		
		if(v==-1){
			break;
		}
		used[v] = true;
		for(int u = 0; u<V;u++){
			d[u] = min(d[u],d[v]+cost[v][u]);
		}
	}
}

double x[1010],y[1010],r[1010],a,b;
int main(){
	cout.precision(30);
	int i,j,n;
	cin >> x[0] >> y[0] >> a >> b;
	cin >> n;
	x[n+1] = a; y[n+1] = b;
	r[0] = 0; r[n+1] = 0;
	for(i=1;i<=n;i++){
		cin >> x[i] >> y[i] >> r[i];
	}
	for(i=0;i<=n+1;i++){
		for(j=0;j<=n+1;j++){
			if(i==j){
				cost[i][j] = INF;
			}else{
				cost[i][j] = max(sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-r[i]-r[j],(double)0);
			}
		}
	}
	V = n+2;
	dijkstra(0);
	cout << d[n+1] << endl;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> a(h, vector<int>(w));

  for (int i = 0; i < h; i++) {
    int cur = 0;
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cur = 0;
      } else {
        cur++;
      }
      a[i][j] = cur;
    }
  }
  vector<vector<int>> b(h, vector<int>(w));
  for (int i = 0; i < w; i++) {
    int cur = 0;
    for (int j = 0; j < h; j++) {
      if (s[j][i] == '#') {
        cur = 0;
      } else {
        cur++;
      }
      b[j][i] = cur;
    }
  }
  vector<vector<int>> c(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    int cur = 0;
    for (int j = w - 1; j >= 0; j--) {
      if (s[i][j] == '#') {
        cur = 0;
      } else {
        cur++;
      }
      c[i][j] = cur;
    }
  }
  vector<vector<int>> d(h, vector<int>(w));
  for (int i = 0; i < w; i++) {
    int cur = 0;
    for (int j = h - 1; j >= 0; j--) {
      if (s[j][i] == '#') {
        cur = 0;
      } else {
        cur++;
      }
      d[j][i] = cur;
    }
  }
  int res = 0;
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '#') continue;

      res = max(res, a[i][j] + b[i][j] + c[i][j] + d[i][j] - 3);
    }
  }
  cout << res << endl;
}

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

#define forn(i,n) for (int i = 0; i < int(n); i++)

using namespace std;

typedef long long ll;
typedef vector<ll> vl;

template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}

int n,ga,sa,ba,gb,sb,bb;

ll calc(int n, int g1, int g2, int s1, int s2, int b1, int b2) {
  vl dp(n+1);
  forn(i,dp.size()) dp[i] = i;

  for (int i = 0; i <= n; i++) {
    if (i+g1 <= n) chmax(dp[i+g1],dp[i]+g2);
    if (i+s1 <= n) chmax(dp[i+s1],dp[i]+s2);
    if (i+b1 <= n) chmax(dp[i+b1],dp[i]+b2);
  }

  return dp[n];
}

int main()
{
  cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;

  ll m = calc(n,ga,gb,sa,sb,ba,bb);

  cout << calc((int)m,gb,ga,sb,sa,bb,ba) << endl;

  return 0;
}


Measured memory_bytes: 195584
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<int>edge[200005];
P dfs(int v,int u,int d){
	P ret = mp(d,v);
	for(int i=0;i<edge[v].size();i++){
		if(edge[v][i]==u) continue;
		ret = max(ret,dfs(edge[v][i],v,d+1));
	}
	return ret;
}
int main(){
	scanf("%d",&n);
	rep(i,n-1){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].pb(b);
		edge[b].pb(a);
	}
	P p = dfs(1,-1,0);
	P q = dfs(p.sc,-1,0);
	//cout << q.fi << " " q.sc << endl;
	if(q.fi%3 == 1) puts("Second");
	else puts("First");
}


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << ((h2 - h1) * 60 + (m2 - m1) - k);
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{   int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(b>=c&&c>=a&&b<=d)
        printf("%d\n",b-c);
    else if(d>=a&&a>=c&&b>=d)
        printf("%d\n",d-a);
    else if(c>=a&&b>=d)
        printf("%d\n",d-c);
    else if(a>=c&&d>=b)
        printf("%d\n",b-a);
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 128
N,M,Q=list(map(int,input().split()))
M=[i for i in range(1,M+1)]
import itertools
A=list(itertools.combinations_with_replacement(M, N))
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
  a[i],b[i],c[i],d[i]=list(map(int,input().split()))
s=[]
ans=0
for j in range(len(A)):
  for k in range(Q):
    if A[j][b[k]-1]-A[j][a[k]-1]==c[k]:
      ans=ans+d[k]
  s.append(ans)
  ans=0
print(max(s))
   



Measured memory_bytes: 25164
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { 1, -1, 0, 0 };
int h, w;
int m[1005][1005];
int memo[1005][1005];
using P = pair<int, int>;
P p[1005 * 1005];

bool checkRange(int x, int y)
{
	return (0 <= x && x < w) && (0 <= y && y < h);
}

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

	for (int y = 0; y < h; y++)
	{
		for (int x = 0; x < w; x++)
		{
			cin >> m[x][y];
			p[m[x][y]] = P(x, y);
		}
	}

	for (int i = 1; i <= h * w; i++)
	{
		int x = p[i].first;
		int y = p[i].second;
		memo[x][y] = m[x][y];
		for (int j = 0; j < 4; j++)
		{
			int X = x + dx[j];
			int Y = y + dy[j];
			if (checkRange(X, Y) && m[x][y] > m[X][Y])
			{
				if (memo[X][Y] == -1)
				{
					memo[x][y] = -1;
					break;
				}
				if (memo[x][y] == m[x][y])
				{
					memo[x][y] = memo[X][Y];
				}
				else if (memo[x][y] != memo[X][Y])
				{
					memo[x][y] = -1;
					break;
				}
			}
		}
	}

	int ans = 0;
	for (int y = 0; y < h; y++)
	{
		for (int x = 0; x < w; x++)
		{
			if (memo[x][y] == -1) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

namespace AtCorder
{
	public class Program
	{
		const int MOD = 1000000007;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			string s = cin.Next();
			int n = s.Length;
			int[,] dp = new int[100005, 13];
			dp[0,0] = 1;
			for (int i = 0; i < n; i++) {
				if (s[i] == '?') {
					for (int j = 0; j < 10; j++) {
						for (int k = 0; k < 13; k++) {
							dp[i + 1, (k * 10 + j) % 13] += dp[i, k];
							dp[i + 1, (k * 10 + j) % 13] %= MOD;
						}
					}
				} else {
					int j = s[i] - '0';
					for (int k = 0; k < 13; k++) {
						dp[i + 1, (k * 10 + j) % 13] += dp[i, k];
						dp[i + 1, (k * 10 + j) % 13] %= MOD;
					}
				}
			}

			long ans = dp[n, 5];
			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

string s[5];
int sz[5];

int solve(){
	FOR(i,3) sz[i] = 0;
	int now = 0, nxt;
	while(1){
		if(sz[now] == (int)s[now].length()) return now;
		nxt = s[now][sz[now]] - 'a';
		sz[now]++;
		now = nxt;
	}
	return 0;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	FOR(i,3) cin >> s[i];
	int win = solve();
	cout << (char)(win + 'A') << endl;
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 2e5 + 5;

int a[maxn], N, M;
ll sum1[maxn], sum2[maxn], sum3[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N >> M;
  for(int i = 1; i <= N; ++i)
    cin >> a[i];
  auto inc1 = [&](int l, int r, int val)
  {
    sum1[l] += val;
    sum1[r + 1] -= val;
  };
  auto inc2 = [&](int l, int r)
  {
    sum2[l]++; sum2[r + 1]--;
    sum3[l] += l - 1; sum3[r + 1] -= l - 1;
  };
  auto dbg = [&](void)
  {
    int d = 0;
    vector<int> p1(M + 5), p2(M + 5);
    for(int i = 1; i <= M; ++i){
      p1[i] = sum2[i];
      p2[i] = sum3[i];
      p1[i] += p1[i - 1];
      p2[i] += p2[i - 1];
    }
    for(int i = 1; i <= M; ++i){
      d += sum1[i];
      cerr << d - (i * p1[i] - p2[i]) << ' ' ;
      //cerr << d + sum[i] << ' ' << sum[i] << '\n';
    }
    cerr << '\n';
  };
  for(int i = 1; i < N; ++i){
    if(a[i] < a[i + 1]){
      int l = a[i], r = a[i + 1];
      inc1(1, l, r - l);
      inc1(r + 1, M, r - l);
      inc1(l + 1, r, 1 + r - l);
      inc2(l + 1, r);
    }
    else if(a[i + 1] < a[i]){
      int l = a[i + 1], r = a[i], dis = M - r + l;
      inc1(l + 1, r, dis);
      inc1(r + 1, M, 1 + l + M - r);
      inc2(r + 1, M);
      inc1(1, l, l + 1);
      inc2(1, l);
      //cerr << dis << '\n';
    }
    //dbg();
  }
  for(int i = 1; i <= M; ++i){
    sum1[i] += sum1[i - 1];
    sum2[i] += sum2[i - 1];
  }
  ll res = 1e18;
  for(int i = 1; i <= M; ++i){
    sum3[i] += sum3[i - 1];
    #ifdef LOCAL
      cerr << i << ' ' << -(sum2[i] * i - sum3[i]) + sum1[i] << '\n';
    #endif // LOCAL
    res = min(res, -(sum2[i] * i - sum3[i]) + sum1[i]);
  }
  cout << res;
}


Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();

            bool flug = true;
            for (int i = 1; i <= s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (s[i-1] == 'R')
                    {
                        flug = false;
                        break;
                    }
                }
                else
                {
                    if (s[i-1] == 'L')
                    {
                        flug = false;
                        break;
                    }
                }
            }
            WriteLine(
                flug ? "Yes" :"No"
                );
        }
    }
}



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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  int i;
  for (i = 0; i < q; i++) {
    cin >> a[i];
  }
  vector<int> m(n, k - q);
  for (i = 0; i < q; i++) {
    m[a[i] - 1]++;
  }
  for (i = 0; i < m.size(); i++) {
    if (m[i] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) throws Exception{
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    HashSet<String> map = new HashSet<>();
    int res = 0;
    for(int i = 0; i < n; ++i) {
      String cur = sc.next();
      if(!map.contains(cur)) {
        res++;
        map.add(cur);
      }
    }
    System.out.println(res);
  }
}

class FastScanner {
  private final InputStream in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  public FastScanner(InputStream source) {
    in = source;
  }

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) return buffer[ptr++];
    else return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext()) throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
      throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 61068
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    long a[n];
    long b[n];
    int i;
    long max = 0;
    long s;
    for (i = 0; i < n; i++) {
        scanf("%ld %ld", &a[i], &b[i]);
        if (max < a[i]) {
            max = a[i];
            s = b[i];
        }
    }
    printf("%ld\n", max + s);

    return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static List<List<Integer>> ptnList = new ArrayList<List<Integer>>();

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();

		int a = 0;

		switch(x) {
		case 1:
			a += 300000;
			break;
		case 2:
			a += 200000;
			break;
		case 3:
			a += 100000;
			break;
		}

		switch(y) {
		case 1:
			a += 300000;
			break;
		case 2:
			a += 200000;
			break;
		case 3:
			a += 100000;
			break;
		}

		if(x == 1 && y ==1) {
			a += 400000;
		}


		System.out.println(a);

		sc.close();
	}


}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  vector<int> a(n, 0);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  cout << a.back()-a[0] << endl;
}

int main()
{
  solve();
  return 0;
}


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

using namespace std;

string lcsStringDPDP(string x, string y){
    int x1, y1;
    x1 = x.size(); 
    y1 = y.size();
    
    vector<vector<int>> f(x1 + 1, vector<int> (y1 + 1, 0));
    
    for(int j = 0; j<=y1; j++){
        f[x1][j] = 0;
    }
    for(int i = 0; i<=x1; i++){
        f[i][y1] = 0;
    }
    for(int i = x1-1; i>=0; i--){
        for(int j = y1-1; j>=0; j--){
            if(x[i] == y[j]){
                f[i][j] = 1 + f[i+1][j+1];
            }
            else{
                f[i][j] = max(f[i+1][j], f[i][j+1]);
            }
        }
    }
    
    string ans = "";
    // cout << x << " " << y << endl;
    int i, j; i = j = 0;
    // cout << x[i] << " " <<y[j] << endl;
    while(i < x1 && j < y1){
        if(x[i] == y[j]){
            // i++; j++;
            ans.push_back(x[i]);
            i ++; j ++;
            // cout << ans << endl;
        }
        else if(f[i][j+1] > f[i+1][j]){
            j++;
        }else i++;
    }
    
  //  reverse(ans.begin(), ans.end());
    return ans;
}

int main() {
    string a, b;
    cin >> a >> b;

    cout << lcsStringDPDP(a, b) << endl;
    // cout << a << " " << b << endl;
}
    
    
    
    


Measured memory_bytes: 35584
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;
    vector<string> mat(h);
    for (int i = 0; i < h; ++i) {
        cin >> mat[i];
    }

    vector<vector<bool>> visited(h, vector<bool>(w, false));
    vector<int> X{-1, 1, 0, 0};
    vector<int> Y{0, 0, -1, 1};

    auto inside = [&](int x, int y) {
        return x >= 0 && x < h && y >= 0 && y < w;
    };

    auto bfs = [&](int sx, int sy) {
        vector<int> cnts(2, 0);
        queue<pair<int,int>> que;
        que.emplace(sx, sy);
        visited[sx][sy] = true;

        int clr = mat[sx][sy];

        while (!que.empty()) {
            int x = que.front().first;
            int y = que.front().second;
            cnts[clr == mat[x][y]] += 1;
            que.pop();
            
            for (int i = 0; i < X.size(); ++i) {
                int nx = x + X[i], ny = y + Y[i];
                if (inside(nx, ny) && !visited[nx][ny] && mat[nx][ny] != mat[x][y]) {
                    visited[nx][ny] = true;
                    que.emplace(nx, ny);
                }
            }
        }

        return cnts[0] * 1LL * cnts[1];
    };

    long long res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (!visited[i][j]) {
                res += bfs(i, j);
            }
        }
    }
    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 512
n = int(input())
d = [int(i) for i in input().split()]
suff = [0 for i in range(n)]
for j in range(n-2, -1, -1):
    suff[j] = suff[j+1] + d[j+1]
print(sum([d[j]*suff[j] for j in range(n)]))

Measured memory_bytes: 3060
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (k+a+b >= 22)
            System.out.println("bust");
        else
            System.out.println("win");

    }
}


Measured memory_bytes: 35396
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int a,b;cin>>a>>b;
	cout<<a*b<<endl;

	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

long long qexp(long long b,long long p){
    long long res=1;
    while (p){
        if (p&1) res=(res*b);
        b=(b*b);
        p>>=1;
    }
    return res;
}

int calc_oppo(int i){
	int pow=1;
	int res=0;
	
	while (i){
		if (i%3==1){
			res+=pow*2;
		}
		else if (i%3==2){
			res+=pow;
		}
		
		i/=3;
		pow*=3;
	}
	
	return res;
}

int n;
string s;
deque<int> id;
int last_swap[1000];
deque<int> dq[1000];

int oppo[1000];

int state=0; //how many swap have happened so far

int perm[600005];
int ans[600005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	rep(x,0,1000) oppo[x]=calc_oppo(x);
	//rep(x,0,10) cout<<x<<" "<<oppo[x]<<endl;
	
	cin>>n;
	cin>>s;
	
	int bn=(n+1)/2,tn=n-bn;
	bn=qexp(3,bn),tn=qexp(3,tn);
	
	rep(x,0,bn){
		id.push_back(x);
		
		rep(y,0,tn) dq[x].push_back(y);
	}
	
	rep(x,0,sz(s)){
		if (s[x]=='S'){
			rep(x,0,bn){
				if (x<oppo[x]) swap(id[x],id[oppo[x]]);
			}
			state++;
		}
		else{
			id.push_front(id.back());
			id.pop_back();
			
			int curr=id.front();
			
			if ((state-last_swap[curr])%2==1){ //swap inside id
				rep(y,0,tn){
					if (y<oppo[y]) swap(dq[curr][y],dq[curr][oppo[y]]);
				}
			}
			last_swap[curr]=state;
			
			dq[curr].push_front(dq[curr].back());
			dq[curr].pop_back();
		}
	}
	
	//rep(x,0,bn) cout<<id[x]<<" ";
	//cout<<endl;
	
	//rep(x,0,tn) cout<<dq[2][x]<<" ";
	//cout<<endl;
	
	rep(x,0,bn) if ((state-last_swap[x])%2==1){
		rep(y,0,tn){
			if (y<oppo[y]) swap(dq[x][y],dq[x][oppo[y]]);
		}
	}
	
	rep(x,0,bn){
		rep(y,0,tn) perm[x+y*bn]=id[x]+bn*dq[id[x]][y];
	}
	
	rep(x,0,bn*tn) ans[perm[x]]=x;
	
	//rep(x,0,bn*tn) cout<<perm[x]<<" ";
	//cout<<endl;
	
	rep(x,0,bn*tn) cout<<ans[x]<<" ";
}


Measured memory_bytes: 11424
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return (a * b) / gcd(a, b);
}

ll eval(string& exp) {
    ll ret = 0, cur = 0;
    for (int i = 0; i < (int)exp.size(); i++) {
        if (exp[i] == '+') {
            ret += cur;
            cur = 0;
        }
        else {
            cur = cur * 10 + (exp[i] - '0');
        }
    }
    ret += cur;
    return ret;
}

int main()
{
    string s; cin >> s;
    const int len = s.size();
    ll ans = 0;
    for (int mask = 0; mask < (1 << (len - 1)); mask++) {
        string tmp = "";
        for (int i = 0; i < len - 1; i++) {
            tmp += s[i];
            if (1 & (mask >> i)) {
                tmp += '+';
            }
        }
        tmp += s[len - 1];
        ans += eval(tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s[3];
    rep(i, 0, 3) cin >> s[i];
    cout << s[0][0] << s[1][1] << s[2][2] << endl;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int n;
cin>>n;
int a[100001];
int b[100001];
for(int i=1;i<=n;i++)
{cin>>a[i];}
int s=0;
for(int i=0;i<=n;i++)
s+=abs(a[i]-a[i+1]);
int ans=0;
for(int i=1;i<=n;i++)
{ans=s-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]);
 cout << ans << endl;}
system("pause");
return 0;
} 


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
using namespace std;

typedef pair<int,int> pi;
typedef pair<int,pi> ppi;
#define MK make_pair
#define F first
#define S second

struct SP{
    stack<pi> s;
};

SP o[1000];

ppi search(int s,int n){
    ppi p;
    int sum=0;
    int mx=0;
    int sub=0;
    int dis=0;
    while(!o[n].s.empty()){
        pi q=o[n].s.top();
        o[n].s.pop();
        if(q.F!=s){
            sum+=q.S;
            ppi x=search(n,q.F);
            if(x.S.F+q.S>mx){
                sub=mx;
                mx=x.S.F+q.S;
            }
            else if(x.S.F+q.S>sub){
                sub=x.S.F+q.S;
            }
            dis=max(dis,x.S.S);
            sum+=x.F;
        }
    }
    dis=max(dis,mx+sub);
    p=MK(sum,MK(mx,dis));
    //cout<<p.F<<" "<<p.S.F<<" "<<p.S.S<<endl;
    return p;
}


int main(){
    while(1){
    
    
    
    
    
    
    
    int n;
    cin>>n;
    if(n==0){break;}
    int b[1000]={};
    int count[1000]={};
    int sum=0;
    
    for(int i=2;i<=n;i++){
        cin>>b[i];
        count[i]++;
        count[b[i]]++;
    }
    for(int i=2;i<=n;i++){
        int d;
        cin>>d;
        sum+=d;
        if(count[i]!=1 && count[b[i]]!=1){
            //cout<<i<<" "<<b[i]<<endl;
            pi p=MK(b[i],d);
            o[i].s.push(p);
            p=MK(i,d);
            o[b[i]].s.push(p);
        }
    }
    
    /*
    for(int i=1;i<=n;i++){
        cout<<count[i]<<" ";
    }
    cout<<endl;
     */
    
    ppi p;
    for(int i=1;i<=n;i++){
        if(count[i]!=1){
            p=search(0,i);
            break;
        }
    }
    
    //cout<<p.F*2<<" "<<p.S.S<<endl;
    cout<<sum+p.F*2-p.S.S<<endl;
    
        
        
    }
    
    return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
int n;
ld dp[301][301][301];
/*ld f(int p, int q,int r)
{
    if(p==0 && q==0 && r==0) return 0;
    ld x,val1=0,val2=0,val3=0;
    if(p>0)
    {
    x=(ld)(p)/(p+q+r);
    if(dp[p-1][q][r]==0) dp[p-1][q][r]=f(p-1,q,r);
    val1= (p==0?0:x*dp[p-1][q][r]);
    }
    if(q>0)
    {
    x=(ld)(q)/(p+q+r);
    if(dp[p+1][q-1][r]==0) dp[p+1][q-1][r]=f(p+1,q-1,r);
    val2= (q==0?0:x*dp[p+1][q-1][r]);
    }
    if(r>0)
    {
    x=(ld)(r)/(p+q+r);
     if(dp[p][q+1][r-1]==0) dp[p][q+1][r-1]=f(p,q+1,r-1);
    val3= (r==0?0:x*dp[p][q+1][r-1]);
    }
   // cout<<val1<<" "<<val2<<" "<<val3<<endl;
    ld ans=(ld)(n)/(p+q+r)+val1+val2+val3;
   // if(p==1) cout<<ans<<endl;
    return ans;
}*/
void solve()
{
  //code begins from here//
    cin>>n;
    int a[4]={0};
    lop (i,n)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    lop(k,a[3]+1)
    {
        lop(j,a[2]+1+a[3]-(k))
        {
            lop(i,a[1]+1+a[2]+a[3]-(k+j))
            {
                if(i==j && j==k && i==0) continue;
                dp[i][j][k]=(ld)(n)/(i+j+k);
                if(i) dp[i][j][k]+=((ld)(i)/(i+j+k))*dp[i-1][j][k];
                if(j) dp[i][j][k]+=((ld)(j)/(i+j+k))*dp[i+1][j-1][k];
                if(k) dp[i][j][k]+=((ld)(k)/(i+j+k))*dp[i][j+1][k-1];
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dp[a[1]][a[2]][a[3]]<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 212752
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 0; i < k; ++i) cout << s << ' ';
    for (int i = k; i < n; ++i) cout << (s == 1000000000 ? 1 : s + 1) << (i == n - 1 ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>




#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e18;
const ll SIZE = 1e5 + 10;  //are u sure?
const ll mod = 1e9+7;
ll dp[SIZE][32];
ll arr[SIZE][32];
unordered_map<string,int> id;
int pref[SIZE];

void solve(){
	int n; cin >> n;
	
	for(int i = 1; i <= n; i++){
		string s; int t; cin >> s >> t;
		id[s] = i;
		pref[i] = pref[i - 1] + t;
	}
	string s; cin >> s;
	cout << pref[n] - pref[id[s]] << endl;
}


int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a, b, c, d;
  d = n % 10;
  c = n % 100 / 10;
  b = n % 1000 / 100;
  a = n / 1000;
  if (b == c) {
    if (a == b || c == d) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
    int N;
    cin >>N;
    int num = N +(N+1)%2;
    int M = (N*(N-1))/2 -N/2;
    cout << M << endl;
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            if(i+j != num){
                cout << i << " "<<j<<endl;
            }
        }
    }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = list(int(s) - 1 for s in read().split())

    ans = 0
    x = 0
    lit = [False] * N
    lit[0] = True
    while True:
        x = A[x]
        ans += 1
        if lit[x] or x == 1:
            break
        lit[x] = True

    if x != 1:
        ans = -1

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 88304
#include<bits/stdc++.h>
#define gc getchar
#define re register
#define rep(i,u,z) for(re int i=u;i<=z;++i)
#define reb(i,u,z) for(re int i=u;i>=z;--i)
#define inf 0x7fffffff

using namespace std;
typedef long long ll;

int a[110],n;

inline int read(){
	int rt=0;
	char ch=gc();
	while(ch<'0'||ch>'9')ch=gc();
	while(ch>='0'&&ch<='9'){
		rt=(rt<<3)+(rt<<1)+(ch&15);
		ch=gc();
	}
	return rt;
}
int main(){
	int x;
	n=read(),x=read();
	a[0]=1;
	rep(i,1,n){
		a[++a[0]]=a[i]+read();
		if(a[a[0]]>x)break;
		else if(i==n)++a[0];
	}
	printf("%d",a[0]-1);
	return 0;
}

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

using namespace std;

int main() {
    int N, D, X;
    cin >> N >> D >> X;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        int day = 1;
        while ( (D - day) >= 0) {
            X++;
            day += a;
        }
    }
    cout << X << endl;

    return 0;
}


Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();

    match std::io::stdin().read_line(&mut line) {
        Ok(0) => return Err("eof".to_string()),
        Ok(_) => (),
        Err(err) => return Err(format!("{:?}", err)),
    }

    line.trim()
        .split_whitespace()
        .map(|x| x.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .map_err(|_| format!("{}", "parse error"))
}

fn main() {
    let wv = read_parameters::<String>().unwrap();
    let w = wv[0].to_lowercase();
    let mut counter = 0;
    loop {
        let pv = read_parameters::<String>().unwrap();
        if pv[0] == "END_OF_TEXT" {
            break;
        }

        for s in pv {
            let s = s.to_lowercase();
            if s == *w {
                counter += 1;
            }
        }
    }
    println!("{}", counter);
}



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define TTF template<typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline void Out(T&x){cout<<x;}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline int ubnd(T&v,ET(T)&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T)&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF inline void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF inline void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
#undef TT
#undef TTF
#undef ET

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

int main()
{
  int mat[128][128];
  int n = in();
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      mat[i][j] = in();
    }
  }
  ll tot = 0;
  for (int i = 0; i < n; i++){
    for (int j = i; j < n; j++){
      tot += min(mat[i][j], mat[j][i]);
    }
  }
  printf("%lld\n", tot);
  return (0);
}

// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

Measured memory_bytes: 1228
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		boolean bool = false;
		
		for(int i=a;i<=b;i++) {
			if(i % k == 0) {
				bool = true;
			}
		}
		
		if(bool) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}

	}

}


Measured memory_bytes: 35820
#include<stdio.h>

int main(void) {
	//入力される数字の数
	int num;

	//入力された数字を格納する配列
	int array[200];

	int i;
	int count = 0;
	
	//偶奇判定のフラグ
	int flag = 0;
	

	//入力1　
	scanf("%d", &num);

	//入力2　数字を配列に格納
	for ( i = 0; i < num; i++)
	{
		scanf("%d", &array[i]);
	}

	//処理関数　
	while (1)
	{
		for (i = 0; i < num; i++)
		{
			if (array[i] % 2 != 0) flag = 1;
		}

		//奇数があれば終了
		if (flag) break;

		for ( i = 0; i < num; i++)
		{
			array[i] = array[i] / 2;
		}
		count++;
	}
	
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#create date: 2020-08-07 07:30

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a = na()
    print(sum(a) - max(a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using ll = long long;
int main() {
  int k;
  std::cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      ll m = std::gcd(i, j);
      for (int p = 1; p <= k; p++) {
        ans += std::gcd(m, p);
      }
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<ll,int,int,int,int,int,int,int>T;
#define PI 3.14159265358979
const int MAX = 510000;
const int MOD = 1000000007;
//この設定だとn<10^7が限界。maxの0を一個増やせば100msかかるが一桁増やせる。
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll N;
  cin>>N;
  ll dp[1000000];
  rep(i,1000000){dp[i]=1000000ll;}
  dp[0]=0ll;
  rep(i,N+1){
  	rep(j,6){
      ll p=i+(ll)pow(6,j+1);
      if(p<=N){dp[p]=min(dp[p],dp[i]+1ll);}
    }
    rep(j,5){
      ll q=i+(ll)pow(9,j+1);
      if(q<=N){dp[q]=min(dp[q],dp[i]+1ll);}
    }
    dp[i+1]=min(dp[i+1],dp[i]+1ll);
  }
  cout<<dp[N];
  
  
} 

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) cin >> A.at(i).at(j);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll tmp = 0;
        for (int j = 0; j < N; j++) {
            if (j < i) tmp += A.at(0).at(j);
            else if (j == i) tmp += A.at(0).at(j) + A.at(1).at(j);
            else tmp += A.at(1).at(j);
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int w, d;
    while(cin >> w >> d, w) {
        vector<int> h1(w), h2(d);
        vector<bool> used(w, false);
        for(int i=0; i<w; ++i) {
            cin >> h1[i];
        }
        for(int i=0; i<d; ++i) {
            cin >> h2[i];
        }
        int ret = accumulate(h1.begin(), h1.end(), 0);
        for(int i=0; i<h2.size(); ++i) {
            bool swapped = false;
            for(int j=0; j<h1.size(); ++j) {
                if(!used[j] && h1[j] == h2[i]) {
                    used[j] = true;
                    swapped = true;
                    break;
                }
            }
            if(!swapped) {
                ret += h2[i];
            }
        }
        cout << ret << endl;
    }
}


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

int main(){
    int X;
    cin >> X;
    int kazu = X / 100;
    bool ans = false;
    int dig2 = X - kazu * 100;
    int count = 0;
    while(dig2 > 4){
        dig2 -= 5;
        count++;
    }
    while(dig2 > 3){
        dig2-= 4;
        count++;
    }
    while (dig2 > 2)
    {
        dig2 -= 3;
        count++;
    }
    while (dig2 > 1)
    {
        dig2 -= 2;
        count++;
    }
    while (dig2> 0)
    {
        dig2 -= 1;
        count++;
    }
    if(count <= kazu){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int sum[5002][5002];
int x[5002];
int y[5002];
int X[5002];
int Y[5002];
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=0;i<a;i++){
        scanf("%d%d",x+i,y+i);
        X[i]=x[i];
        Y[i]=y[i];
    }
    X[a]=-1999999999;
    X[a+1]=1999999999;
    Y[a]=-1999999999;
    Y[a+1]=1999999999;
    std::sort(X,X+a+2);
    std::sort(Y,Y+a+2);
    for(int i=0;i<a;i++){
        x[i]=lower_bound(X,X+a+2,x[i])-X;
        y[i]=lower_bound(Y,Y+a+2,y[i])-Y;
        sum[x[i]][y[i]]++;
    }
    for(int i=0;i<a+2;i++){
        for(int j=1;j<a+2;j++){
            sum[i][j]+=sum[i][j-1];
        }
    }
    for(int i=0;i<a+2;i++){
        for(int j=1;j<a+2;j++){
            sum[j][i]+=sum[j-1][i];
        }
    }
    for(int i=0;i<b;i++){
        int p,q,r,s;
        scanf("%d%d%d%d",&p,&q,&r,&s);
        int P=lower_bound(X,X+a+2,p)-X-1;
        int Q=lower_bound(Y,Y+a+2,q)-Y-1;
        int R=upper_bound(X,X+a+2,r)-X-1;
        int S=upper_bound(Y,Y+a+2,s)-Y-1;
        printf("%d\n",sum[R][S]-sum[R][Q]-sum[P][S]+sum[P][Q]);
    }
}

Measured memory_bytes: 98856
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; string S; cin >> N >> S;
    char p = S[0]; int ans = 1;
    REP(i, 1, N) {
        if (S[i] == p) continue;
        p = S[i];
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

vector<int> sieve(int n) {
  vector<int> p(n);
  REP(i,2,n) p[i]=i;
  for(int i=2; i*i<n; i++) {
    if(p[i]) {
      for(int j=i*i; j<n; j+=i) p[j]=0;
    }
  }
  p.erase(remove(all(p),0),p.end());
  return p;
}

int main() {
  vector<int> p=sieve(10001);
  int n;
  cin >> n;
  int cnt=0;
  while(n--) {
    int x;
    cin >> x;
    bool f=true;
    rep(i,p.size()) {
      if(x<=p[i]) break;
      if(!(x%p[i])) f=false;
    }
    if(f) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1232