akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main(){
    long long N,C,K; cin >> N >> C >> K;
    vector<long long> v(N);
    for(int i=0;i<N;i++)cin>>v[i];
    sort(v.begin(),v.end());
    long long next = v[0]+K;
    int n_bus=0;
    int count=0;
    while(true){
        int n_pas = 0;
        for(int i=0;i<v.size();i++){
            if(v[i]<=next) n_pas++;
            else break;
        }
        if(n_pas>C){
            n_bus += n_pas/C;
            v.erase(v.begin(), v.begin()+n_pas-n_pas%C);
        }else{
            n_bus++;
            v.erase(v.begin(), v.begin()+n_pas);
        }
        if(v.size() == 0) break;

        next = v[0]+K;
    }
    cout << n_bus << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 998244353
//#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=3050;
//↑templete
signed main(){

    int N;
    cin>>N;
    string S;
    cin>>S;
    ll ans=0;

    ll B=0;
    for(int i=0;i<N;i++)
        if(S[i]=='B')
            B++;

    for(int i=0;i<N;i++){
        if(S[i]!='R')
            continue;
        for(int j=0;j<N;j++){
            if(S[j]!='G')
                continue;

            //cout<<S[i]<<" "<<S[j]<<endl;

            ans+=B;

            ll x=min(i, j), y=max(i, j);
            ll a=x-y+x, b=(x+y)/2, c=y+y-x;
            if(a<N && 0<=a && S[a]=='B')
                ans--;
            if(b<N && 0<=b && (x+y)%2==0 && S[b]=='B')
                ans--;
            if(c<N && 0<=c && S[c]=='B')
                ans--;
            
        }
    }

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


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define P 1000000007
#define N 100005
#define M 200005
using namespace std;
int i,j,k,l,s,n,m,s1,tot,last[N],to[M],Next[M],val[N],b[N],q[N],fa[N],dis[N],ans;
long long sum,x;
struct node {
	int x,y,z,v;
}a[N];
inline bool cmp(node x,node y) {
	return x.z<y.z;
}
inline int get(int x) {
	if (fa[x]==x) return x;
	return fa[x]=get(fa[x]);
}
inline void add(int x,int y,int z) {
	Next[++tot]=last[x]; last[x]=tot; to[tot]=y; val[tot]=z;
}
inline void build(int x) {
	int l=0,r=1; dis[q[1]=x]=1;
	while (l<r) {
		int k=q[++l];
		for (int i=last[k];i;i=Next[i]) {
			if (fa[k]==to[i]) continue;
			fa[q[++r]=to[i]]=k;
			b[to[i]]=val[i];
			dis[to[i]]=dis[k]+1;
		}
	}
}
inline int ask(int x,int y) {
	int ans=0;
	while (x!=y) {
		if (dis[x]>dis[y]) ans=max(ans,b[x]),x=fa[x];
		else ans=max(ans,b[y]),y=fa[y];
	}
	return ans;
}
inline int quick(int x,int y) {
	int s=1;
	while (y) {
		if (y&1) s=1ll*s*x%P;
		x=1ll*x*x%P;
		y>>=1;
	}
	return s;
}
int main() {
	scanf("%d%d%lld",&n,&m,&x);
	for (i=1;i<=n;i++) fa[i]=i;
	for (i=1;i<=m;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
	sort(a+1,a+1+m,cmp);
	for (i=1;i<=m;i++) {
		if (get(a[i].x)==get(a[i].y)) a[i].v=1;
		else add(a[i].x,a[i].y,a[i].z),add(a[i].y,a[i].x,a[i].z),fa[get(a[i].x)]=get(a[i].y),sum+=a[i].z;
	}
	if (sum>x) return puts("0"),0;
	for (i=1;i<=n;i++) fa[i]=0;
	build(1);
	for (i=1;i<=m;i++) {
		if (!a[i].v) a[i].v=-1;
		else a[i].v=a[i].z-ask(a[i].x,a[i].y);
	}
	if (sum==x) {
		for (i=1;i<=m;i++) if (!a[i].v) s++;
		ans=1ll*(quick(2,n-1)-2)*quick(2,m-(n-1))%P;
		ans=(ans+2ll*(quick(2,s)-1)*quick(2,m-(n-1)-s)%P)%P;
		ans=(ans+P)%P;
	}
	else {
		for (i=1;i<=m;i++) if (a[i].v==x-sum) s++;
		else if (a[i].v>x-sum) s1++;
		ans=1ll*2*(quick(2,s)-1)*quick(2,s1)%P;
	}
	printf("%d\n",ans);
} 

Measured memory_bytes: 2304
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		int min;

		for(int i = 0; i < n; i++){
			min = i;
			for(int j = i; j < n; j++){
				if(a[j] < a[min]){
					min = j;
				}
			}
			if(a[i] != a[min]){
				swap = a[i];
				a[i] = a[min];
				a[min] = swap;
				count++;
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	}
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int (i)=0;(i)<(int)(n);(i)++)

const int M = 2000, N = 10'000;
bool ab[2 * N], ac[2 * N], bc[2 * N];

bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    int A = a.size(), B = b.size(), C = c.size();

    REP(i, A) REP(j, B) if (!match(a[i], b[j])) ab[i - j + N] = 1;
    REP(i, A) REP(j, C) if (!match(a[i], c[j])) ac[i - j + N] = 1;
    REP(i, B) REP(j, C) if (!match(b[i], c[j])) bc[i - j + N] = 1;

    int ans = 3 * M;
    for (int i = -2 * M; i <= 2 * M; i++) {
        for (int j = -2 * M; j <= 2 * M; j++) {
            if (!ab[i + N] && !ac[j + N] && !bc[j - i + N]) {
                int l = min(0, min(i, j));
                int r = max(A, max(i + B, j + C));
                ans = min(ans, r - l);
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextInt();
        long b=sc.nextInt();
        long c=sc.nextInt();
        if(a+b>=c){
            System.out.println("No");
        }else if(4*a*b>=(c-a-b)*(c-a-b)){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        
        
        
        
 
    }



}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------

void _main() {
	string c;
	cin >> c;

	if (c == (string)"A") {
		cout << "T" << endl;
	}
	if (c == (string)"T") {
		cout<< "A" <<endl;
	}
	if (c == (string)"C") {
		cout<< "G" <<endl;
	}
	if (c == (string)"G") {
		cout<< "C" <<endl;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
INF = 10**9

n, m = map(int, input().split())
pqc = []

seen = set()
for i in range(n):
    seen.add((i, 0))
for _ in range(m):
    p, q, c = map(int, input().split())
    p -= 1; q -= 1
    pqc.append((p, q, c))
    seen.add((p, c))
    seen.add((q, c))
comp = dict()
for i, node in enumerate(seen):
    comp[node] = i

edge = [[] for _ in range(len(comp))]
for key in comp.keys():
    v, c = key
    if c != 0:
        frm = comp[(v, c)]
        too = comp[(v, 0)]
        edge[frm].append((too, 0))
        edge[too].append((frm, 1))

for p, q, c in pqc:
    frm = comp[(p, c)]
    too = comp[(q, c)]
    edge[frm].append((too, 0))
    edge[too].append((frm, 0))

class BFS:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = deque()

    def calc(self, start):
        self.dist[start] = 0
        self.q.append((0, start))
        while len(self.q) != 0:
            prov_cost, src = self.q.popleft()
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    if cost == 1:
                        self.q.append((self.dist[dest], dest))
                    else:
                        self.q.appendleft((self.dist[dest], dest))
        return self.dist

bfs = BFS(edge)
bfs.calc(comp[(0, 0)])
ans = bfs.dist[comp[(n-1, 0)]]
if ans == INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 213124
#include <stdio.h>
#include <bitset>
using namespace std;
int main(){
    bitset<64> b;
    int q,k,pos;
    unsigned long long int temp,now;
    bool f;
    b.reset();
    scanf("%d",&q);
    while(q--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d",&pos);
            if(b[pos])printf("1\n");
            else printf("0\n");
        }
        else if(k==1){
            scanf("%d",&pos);
            b[pos]=true;
        }
        else if(k==3){
            scanf("%d",&pos);
            b[pos]=!b[pos];
        }
        else if(k==2){
            scanf("%d",&pos);
            b[pos]=false;
        }
        else if(k==4){
            f=true;
            for(int i=0;i<64;i++)if(!b[i]){
                f=false;
                break;
            }
            if(f)printf("1\n");
            else printf("0\n");
        }
        else if(k==5){
            f=false;
            for(int i=0;i<64;i++)if(b[i]){
                f=true;
                break;
            }
            if(f)printf("1\n");
            else printf("0\n");
        }
        else if(k==6){
            f=true;
            for(int i=0;i<64;i++)if(b[i]){
                f=false;
                break;
            }
            if(f)printf("1\n");
            else printf("0\n");
        }
        else if(k==7){
            pos=0;
            for(int i=0;i<64;i++)if(b[i])pos++;
            printf("%d\n",pos);
        }
        else{
            temp=0;
            now=1;
            for(int i=0;i<64;i++){
                if(b[i])temp|=now;
                now<<=1;
            }
            printf("%llu\n",temp);
        }
    }
}


Measured memory_bytes: 2720
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

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

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
DSU = atcoder.dsu.DSU

# from atcoder.dsu import DSU
def solve():
    N,M = map(int,input().split())
    uf = DSU(N)

    for _ in range(M):
        a, b = map(int,input().split())
        a -= 1
        b -= 1
        uf.merge(a,b)
    
    print(len(uf.groups())-1)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 97548
#include <cstdio>
#include <map>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using P = std::pair<int, int>;

int A[3][3];
int N;
bool fl[3][3];

int main()
{
  rep( i, 3 ) rep( j, 3 )
    scanf( "%d", &A[i][j] );

  scanf( "%d", &N );

  rep( i, N )
  {
    int b;
    scanf( "%d", &b );

    rep( j, 3 ) rep( k, 3 )
    {
      if( A[j][k] == b )
        fl[j][k] = true;
    }
  }

  rep( i, 3 )
  {
    bool flg = true, flg2 = true;

    rep( j, 3 )
    {
      flg &= fl[i][j];
      flg2 &= fl[j][i];
    }

    if( flg || flg2 )
    {
      puts("Yes");

      return 0;
    }
  }

  if( (fl[0][0]&fl[1][1]&fl[2][2]) || (fl[0][2]&fl[1][1]&fl[2][0]) )
    puts( "Yes" );
  else
    puts( "No" );

  return 0;
}

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

//素数判定
bool isPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
      if (num % i == 0) {
        // 素数ではない
        return false;
      }
    }
    // 素数である
    return true;
}

int main() {
  int q;
  cin >> q;
  vector<int> res(100001, 0);
  for (int i = 3; i <= 100000; i+=2){
    if(isPrime(i) && isPrime((i + 1)/ 2)){
      res[i] = 1;
    }else {
      res[i] = 0;
    }
  }
  rep(i, 100000){
    res[i] += res[i-1];
  }
  rep(i, q){
    int l, r;
    cin >> l >> r;
    cout << res[r] - res[l - 1] << endl;
  }
}

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

#define read                   freopen("in.txt","rt",stdin)
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}


using namespace std;
int main()
{
    string str;
    cin>>str;
    int x=0;
    if(str[0]=='+')x++;
    else x--;
    if(str[1]=='+')x++;
    else x--;
    if(str[2]=='+')x++;
    else x--;
    if(str[3]=='+')x++;
    else x--;
    cout<<x<<endl;
}


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

const int maxn = 5e5 + 10;
vector<int>edge[maxn];
bool vis[maxn];
int deg[maxn][2];
char s[maxn];

IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f;	
}
int main() {
#ifdef Edgration 
	freopen("1.in", "r", stdin); 
#endif
	int n = read(), m = read();
	scanf("%s", s + 1);
	for (int i = 1; i <= m; ++i) {
		int x = read(), y = read();
		edge[x].push_back(y); edge[y].push_back(x);
		deg[x][s[y] == 'A']++; deg[y][s[x] == 'A']++;
	}
	queue<int>q;
	for (int i = 1; i <= n; ++i) if (deg[i][0] == 0 || deg[i][1] == 0) q.push(i), vis[i] = 1;
	while (!q.empty()) {
		int u = q.front(); q.pop(); 
		for (int i = 0; i < edge[u].size(); ++i) {
			int v = edge[u][i];
			deg[v][s[u] == 'A']--;
			if (!vis[v] && deg[v][s[u] == 'A'] == 0) {
				vis[v] = 1; q.push(v);
			}
		}
	}
	for (int i = 1; i <= n; ++i) if (!vis[i]) {
		puts("Yes"); return 0;	
	}
	puts("No");
	return 0;	
}

Measured memory_bytes: 20224
"use strict";

main(require("fs").readFileSync("/dev/stdin", "UTF-8")); // 3 5
// .....
// .#.#.
// .....

function main(input) {
  var height = 0;
  var width = 0;
  input.split("\n")[0].split(" ").map(function (value, index) {
    switch (index) {
      case 0:
        height = parseInt(value);
        break;

      case 1:
        width = parseInt(value);
        break;

      default:
        console.log("入力の１行目を判断出来ません。");
    }
  });
  var mass = new Array(height); // 各マスの状態
  // 2次元配列の生成

  for (var i = 0; i < mass.length; i++) {
    mass[i] = new Array(width);
  } // 2次元配列に値を格納


  for (var h = 0; h < height; h++) {
    mass[h] = input.split("\n")[h + 1].split("").slice();
  }

  var result = mass.slice();

  for (var _h = 0; _h < height; _h++) {
    for (var w = 0; w < mass[_h].length; w++) {
      if (mass[_h][w] !== "#") {
        (function () {
          var relationMass = [];
          var atomic_count = 0;

          if (_h - 1 >= 0) {
            if (w - 1 >= 0) {
              relationMass.push(mass[_h - 1][w - 1]);
            }

            if (w + 1 <= width) {
              relationMass.push(mass[_h - 1][w + 1]);
            }

            relationMass.push(mass[_h - 1][w]);
          }

          if (w - 1 >= 0) {
            relationMass.push(mass[_h][w - 1]);
          }

          if (w + 1 <= width) {
            relationMass.push(mass[_h][w + 1]);
          }

          if (_h + 1 < height) {
            if (w - 1 >= 0) {
              relationMass.push(mass[_h + 1][w - 1]);
            }

            if (w + 1 <= width) {
              relationMass.push(mass[_h + 1][w + 1]);
            }

            relationMass.push(mass[_h + 1][w]);
          }

          relationMass.forEach(function (e) {
            if (e === "#") {
              atomic_count++;
            }
          });
          result[_h][w] = atomic_count;
        })();
      }
    }
  }

  console.log(result = result.map(function (a) {
    return a.join("");
  }).join("\n"));
}

Measured memory_bytes: 21064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<(n);++i)
typedef long long int ll;

class CTravelingSalesmanAroundLake {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll k,n;
        in >> k >> n;

        vector<ll> a(n);
        rep(i,n){
            in >> a[i];
        }
        ll d=a[0]+k-a.back();
        for(int i=0;i<n-1;i++){
            d = max(d,a[i+1]-a[i]);
        }
        out << k-d << endl;
	}
};


int main() {
	CTravelingSalesmanAroundLake solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

long long int n, i, j, k, s, a, b, r, c, a1;

int main()
{
    cin >> n;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++)
        {
            a = i;
            b = j;
            if(a < b)
                swap(a, b);
            while(b != 0)
            {
                r = a % b;
                a = b;
                b = r;
            }
            a1 = a;
            for(k = 1; k <= n; k++)
            {
                c++;
                b = k;
                a = a1;
                if(a < b)
                    swap(a, b);
                while(b != 0)
                {
                    r = a % b;
                    a = b;
                    b = r;
                }
                s += a;
            }
        }
    cout << s;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
   int a,b,c,sum=0;
   cin>>a>>b>>c;
   if(a==b&&b==c)
    {
        cout<<sum+1<<endl;
    }
    else if(a==b||b==c||c==a)
    {
        cout<<sum+2<<endl;
    }
    else
    {
        cout<<sum+3<<endl;
    }


    return 0;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2175
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int C[100] = { 0 };
	for (int i = 2; i <= 9;i++) C[i + '0'] = i;
	C['T'] = 10; C['J'] = 11; C['Q'] = 12; C['K'] = 13; C['A'] = 14;
	char c;
	int leader = 0;
	while (cin >> c) {
		if (c == '#')break;
		vector<vector<string>> Card(4, vector<string>(13));
		for (int i = 0; i < 4;i++) {
			for (int j = 0; j < 13;j++) {
				cin >> Card[i][j];
			}
		}
		
		int teamEW = 0, teamNS = 0;
		leader = 0;
		for (int i = 0; i < 13;i++) {
			int tokuten[4] = { 0 };
			int at = leader;
			int tokutenmax = 0;
			char suit = Card[leader][i][1];
			for (int j = 0; j < 4;j++) {

				if (Card[j][i][1] == c) {
					tokuten[j] = 15 + C[Card[j][i][0]];
				}
				else if (Card[j][i][1] == suit) {
					tokuten[j] = C[Card[j][i][0]];
				}
				if (tokutenmax < tokuten[j]) {
					tokutenmax = tokuten[j];
					at = j;
				}
			}
			if (at == 0 || at == 2) {
				teamNS++;
			}
			else {
				teamEW++;
			}
			leader = at;
			//cout << leader << endl;
		}
		if (teamNS > teamEW) {
			cout << "NS " << teamNS - 6 << endl;
		}
		else {
			cout << "EW " << teamEW - 6 << endl;
		}
	}
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, m; cin >> n >> m;

  vpi st(n), check(m);
  rep(i, n) cin >> st[i].fi >> st[i].se;
  rep(i, m) cin >> check[i].fi >> check[i].se;

  rep(i, n) {
    int idx = 0;

    rep(j, m) {
      int diff = abs(st[i].fi - check[j].fi) + abs(st[i].se - check[j].se);
      if (diff < abs(st[i].fi - check[idx].fi) + abs(st[i].se - check[idx].se)) idx = j;
    }

    cout << idx+1 << endl;
  }
  
  return (0);
}

Measured memory_bytes: 3628
H,W=map(int,input().split())
CH,CW=map(lambda x:int(x)-1,input().split())
DH,DW=map(lambda x:int(x)-1,input().split())
maze=[input() for i in range(H)]
di=[[-1 for _ in range(W)] for _ in range(H)]
adj=[]
for i in range(-1,2):
  for j in range(-1,2):
    if i==0 or j==0:
      adj.append((i,j))
warp=[]
for i in range(-2,3):
  for j in range(-2,3):
    if (i,j) not  in adj:
      warp.append((i,j))
adj.remove((0,0))
from collections import deque
dq=deque([(CH,CW,0)])
while dq:
  h,w,d=dq.popleft()
  if 0<=h<H and 0<=w<W and di[h][w]<0 and maze[h][w]=='.':
    di[h][w]=d
  else:
    continue
  for i in range(len(adj)):
    dq.appendleft((h+adj[i][0],w+adj[i][1],d))
  for i in range(len(warp)):
    dq.append((h+warp[i][0],w+warp[i][1],d+1))
print(di[DH][DW])
  

Measured memory_bytes: 232216
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100050
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,k,a[128],dp[128][N];

void sum(int &a, int b){ a += b; if(a > MOD) a -= MOD; }
void res(int &a, int b){ a -= b; if(a < 0) a += MOD; }

int main(){

	fastio;
	fill(dp,0);
	cin >> n >> k;
	FER(i,1,n+1) cin >> a[i];

	dp[0][0] = 1;
	for(int i = 1; i <= n; ++i){
		int x = 0;
		for(int j = 0; j <= k; ++j){
			sum(x,dp[i-1][j]);
			if(j - a[i] - 1 >= 0) res(x,dp[i-1][j-a[i]-1]);
			dp[i][j] = x;
		}
	}
	cout << dp[n][k] << endl;
	return 0;
}


Measured memory_bytes: 50304
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
int H,W,dir,x,y;//dir 0->U 1->D 2->L 3->R
char cmap[30][30],tank[4] = {'^','v','<','>'};
string op;
int dx[4] = {0,0,-1,1};// U D L R
int dy[4] = {-1,1,0,0};

void op_U(){
  dir = 0;
  if( 0 <= y-1 && cmap[y-1][x] == '.'){
    cmap[y][x] = '.';
    y--; 
  } 
  cmap[y][x] = tank[dir];
}

void op_D(){
  dir = 1;
  if(y+1<H && cmap[y+1][x] == '.'){
    cmap[y][x] = '.';
    y++;
  }
  cmap[y][x] = tank[dir];
}

void op_L(){
  dir = 2;
  if(0<=x-1 && cmap[y][x-1] == '.'){
    cmap[y][x] = '.';
    x--;
  }
  cmap[y][x] = tank[dir];
}

void op_R(){
  dir = 3;
  if(x+1<W && cmap[y][x+1] == '.'){
    cmap[y][x] = '.';
    x++;
  
  }
  cmap[y][x] = tank[dir];
}

void op_S(){
  int cnt=1;
  while(true){
    if(!( 0<=x+dx[dir]*cnt  && x+dx[dir]*cnt < W && 0<=y+dy[dir]*cnt && y+dy[dir]*cnt < H) )break;
    if(cmap[y+dy[dir]*cnt][x+dx[dir]*cnt] == '*'){
      cmap[y+dy[dir]*cnt][x+dx[dir]*cnt] = '.';
      break;
    }
    else if(cmap[y+dy[dir]*cnt][x+dx[dir]*cnt] == '#'){
      break;
    }
    cnt++;
  }
}

void display(){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << cmap[i][j];
    }
    cout << endl;
  }
}

void solve(){
  for(int i=0;i<op.length();i++){
    if(op[i] == 'U')op_U();
    else if(op[i] == 'D')op_D();
    else if(op[i] == 'L')op_L();
    else if(op[i] == 'R')op_R();
    else if(op[i] == 'S')op_S();
  }
  display();
}




int main(){
  int T,enu;
  cin >> T;
  while(T-- > 0){
    cin >> H >> W;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin >> cmap[i][j];
	if(cmap[i][j] == '^'){
	  dir = 0;
	  x = j; y = i;
	}
	else if(cmap[i][j] == 'v'){
	  dir = 1;
	  x = j; y = i;
	}
	else if(cmap[i][j] == '<'){
	  dir = 2;
	  x = j; y = i;
	}
	else if(cmap[i][j] == '>'){
	  dir = 3;
	  x = j; y = i;
	}
      }
    }
    cin >> enu;
    cin >> op;
    solve();
    if(T > 0)cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n;cin >> n;
        vll v(n);
        map<ll,ll> mp;
        rep(i,n){
             cin >> v[i];
            // a[v[i]]++;
             mp[v[i]]++;
        }
        ll f=0;
        for(auto it=mp.begin();it!=mp.end();it++){
            if(it->second>1){
                f=1; break;
            }
        }
        if(!f){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }

    }
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define maxn 15
char s[maxn];
int main()
{
    scanf("%s",s);
    int n=strlen(s);
    if(n>=4&&s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
        puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7

def solve():
  N = int(input())
  S = [s == 'W' for s in input()] # W: True, B: False
  if S[0] or S[2 * N - 1]: return 0

  ans = 1
  cnt = 1
  d = True # L: True, R: False
  for i in range(1, N * 2):
    if S[i] == S[i - 1]: d = not d
    if d: cnt += 1
    else:
      ans = (ans * cnt) % MOD
      cnt -= 1

  if cnt != 0: return 0

  for i in range(2, N + 1): ans = (ans * i) % MOD
  return ans

print(solve())

Measured memory_bytes: 5096
A, B = map(int, input().split())
A -= 1
if A % 2 == 1:
    if (A // 2 + 1) % 2 == 1:
        A = 1
    else:
        A = 0
else:
    if (A // 2) % 2 == 1:
        A = 1 ^ A
    else:
        A = 0 ^ A
if B % 2 == 1:
    if (B // 2 + 1) % 2 == 1:
        B = 1
    else:
        B = 0
else:
    if (B // 2) % 2 == 1:
        B = 1 ^ B
    else:
        B = 0 ^ B

print(A^B)
    

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  double a,b,x; cin >> a >> b >> x;
  double ans = 0;
  if (x <= b * a * a / 2.0) {
    ans = 90-atan(2 * x / a / b / b) / PI / 2 * 360;
  } else {
    double t = (2*x/a - a*b)/a;
    ans = 90-atan(a/(b-t)) / PI / 2 * 360;
  }
  cout << ans << endl;
}

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

int main(void)
{
    int a[5];
    for (int i = 0; i < 5; ++i)
        cin >> a[i];
    sort(a, a + 5);
    for (int i = 4; 0 <= i; --i)
        cout << ((i!=4)? " ": "") << a[i];
    cout << endl;
    return 0;
}






Measured memory_bytes: 3104
// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n")[0];
  const N = parseInt(input.split(' ')[0])
  const R = parseInt(input.split(' ')[1])
if(N >= 10){
  console.log(R)
}else{
  console.log(R + 100*(10 - N))
}
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22080
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

/*int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

struct BIT{
    vector<int> dat;
    int sz;
    BIT(int n){
        for(sz=1;sz<n;sz *= 2);
        dat.resize(++sz);
    }
    int q(int n){
        int ret = 0;
        for(int i=n;i>0;i-=i&-i)ret +=dat[i];//和の計算　iから最後の１のbit(i&-i 多分＆はビット積)を減算
        for(int i=n;i<sz;i+=i&-i) dat[i]++;//値の加算　iから最後mの１のbitを加算
        return ret;
    }
};

int main(){
    int n,k;
    cin >> n>> k;
    char s[n];
    cin >> s;
    s[k-1]=s[k-1]+0x20;
    cout<< s<<endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Text.Printf

main :: IO ()
main = do
  xs <- getc $ solve . toInt
  mapM_ printId xs

solve :: Int -> Int
solve x
  | r == 0 = 39
  | otherwise = r
  where
    r = x `mod` 39

printId :: Int -> IO ()
printId = printf "3C%02d\n"

toInt :: String -> Int
toInt s = read s

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

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

using namespace std;
typedef long long ll;

void solve();
int n, k;
string s;
int a[100];

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

void solve()
{
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] % 2 == 0 && (a[i] % 3 != 0 && a[i] % 5 != 0))
        {
            flag = 1;
            break;
        }
    }
    if (flag)
    {
        cout << "DENIED" << endl;
    }
    else
    {
        cout << "APPROVED" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }

void solve()
{
    ll a, b; cin >> a >> b;
    string s, t; cin >> s >> t;
    ll g = __gcd(a, b);
    string x, y;
    for(ll i = 0; i < a; i+= (a/g))  x += s[i]; //cout << x << " ";
    for(ll i = 0; i < b; i+= (b/g))  y += t[i]; //cout << y << " ";
    if(x != y) ANS(-1);
    ANS(lcm(a, b)); 
}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

//init:O(n).unite,find:(Ack^-1(n,n))
class union_find{
	private:
	vector<int> parent,rank,gs;
    int size;
	public:
    int count_group;
    union_find()=default;
    union_find(int n){ init(n); }

    void init(int n){
		size=n;
		count_group=n;
		parent.resize(size);
		rank.assign(size,0);
        gs.assign(size,1);
		for(int i=0; i<size; ++i) parent[i]=i;
	}

	int find(int x){
		if(parent[x]==x) return x;
		else return parent[x]=find(parent[x]);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			parent[x]=y;
            gs[y]+=gs[x];
		} else {
			parent[y]=x;
            gs[x]+=gs[y];
			if(rank[x]==rank[y]) ++rank[x];
		}
		--count_group;
	}

	bool is_same_group(int x,int y){
		return find(x)==find(y);
	}

    int group_size(int x){
        return gs[find(x)];
    };
};


void solve(int n,int m){
    static vector<int> t[1000001];
    rep(i,0,1000001) t[i].clear();
    rep(i,0,n){
        int h;
        cin >> h;
        t[h].push_back(i);
    }
    vector<tuple<int,int,int>> edges;
    rep(i,0,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a;
        --b;
        edges.push_back(make_tuple(c,a,b));
    }
    sort(edges.begin(),edges.end());

    int ans=0;
    union_find uf(n);
    vector<bool> f(n);
    for(int i=1000000; i>=1; --i){
        if(t[i].empty()) continue;

        rep(j,0,t[i].size()) f[t[i][j]]=true;
        for(const auto &edge:edges){
            const int a=get<1>(edge),b=get<2>(edge);
            if(uf.is_same_group(a,b)) continue;
            if(!f[a] or !f[b]) continue;
            uf.unite(a,b);
            ans+=get<0>(edge);
        }
        bool is_connected=true;
        rep(j,0,n){
            if(!f[j]) continue;
            rep(k,j+1,n){
                if(!f[k]) continue;
                if(uf.is_same_group(j,k)) continue;
                is_connected=false;
                break;
            }
        }
        if(!is_connected){
            ans=0;
            uf.init(n);
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n,m;
        cin >> n >> m;
        if(n==0 and m==0) break;
        solve(n,m);
    }
    return 0;
}

Measured memory_bytes: 26980
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int answer = 0;
  int seq = 0;
  rep(i, 3) {
    if (S[i] == 'S') {
      answer = max(seq, answer);
      seq = 0;
    } else {
      seq++;
    }
  }
  answer = max(seq, answer);
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    int r = a%b;
    if (r == 0) {
        return b;
    } else {
        return gcd(b, r);
    }
}

int main() {
    int k;
    cin >> k;
    int sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
struct edge { int to; ld cost; };
ld d[1002];
vector<edge> G[1002];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + 1002, (ld)INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < (int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
struct cir { ld x, y, r; };
ld dis(cir x, cir y) {
	ld d = sqrt(pow(y.x - x.x, 2) + pow(y.y - x.y, 2));
	ld res = d - x.r - y.r;
	if (res < 0)return 0;
	else return res;
}
int main() {
	cout << fixed << setprecision(10);
	ld xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int n; cin >> n;
	cir a[1002];
	rep(i, n) {
		ld x, y, r; cin >> x >> y >> r;
		a[i] = { x,y,r };
	}
	a[n] = { xs,ys,0 };
	a[n + 1] = { xt,yt,0 };
	rep(i, n + 2) {
		Rep(j, i + 1, n + 2) {
			ld d = dis(a[i], a[j]);
			G[i].push_back({ j,d });
			G[j].push_back({ i,d });
		}
	}
	dijkstra(n);
	cout << d[n + 1] << endl;
	return 0;
}

Measured memory_bytes: 34840
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int A=gi();
	    int B=gi();
	    int[] P=new int[N];
	    int s=0;
	    int m=0;
	    int l=0;
	    for (int i=0; i<N;i++) {
	    	P[i]=gi();
	    	if(P[i]<=A) {
	    		s++;
	    	} else if(P[i]<=B) {
	    		m++;
	    	} else {
	    		l++;
	    	}
	    }
	    

        System.out.println(Math.min(s, Math.min(m, l)));
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  ll sum=0;
  map<ll,ll> mp;
  ll ans=0;
  mp[0]=1;
  for(int i=0;i<n;i++){
    ll a;cin >> a;
    sum+=a;
    ans+=mp[sum%m];
    mp[sum%m]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main(void)
{
    int W, H, N, p;
    int out, in;
    int i;
    int n;
    
    scanf("%d%d", &W, &H);
    out = W * 2 + H - 2;
    in = (W - 1) * 2 + (H - 2) - 2;

//printf("<<%d %d>>", in, out);

    scanf("%d", &N);
    n = 0;
    for (i = 0; i < N; i++){
        scanf("%d", &p);
        if (p == 0){
            out--;
        }
        else {
            in--;
        }
//printf("<%d %d>", in, out);
        if (out <= W - 1 && in == out){
//printf("(A%d %d)", in, out);
            n++;
        }
        if (W + 1 <= out && out <= W + H - 2){
            if (out - 2 == in){
//printf("(B%d %d)", in, out);
                n++;
            }
        }
        if (W + H - 2 + 1 <= out){
            if (out - 4 == in){
//printf("(C%d %d)", in, out);
                n++;
            }
        }
    }
    printf("%d\n", n);
    
    return (0);
}



Measured memory_bytes: 2112
#include<iostream>

using namespace std;

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    int n,m;
    n=A*C;
    m=B/A;
    int ans;
    if(n<=B){
     ans=C;
    }
    else{
        ans=m;
    }
    cout<<ans;
    return 0;
}

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

//1番目の勇者は1番目の街のモンスターを全力でmin(A1,B1)体倒し、
//残った力で2番目の街のモンスターを全力でmin(A2,B1−min(A1,B1))体倒す
int main() {
  int N;
  cin >> N;
  ll A[N], B[N];
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  ll s = 0;//合計で倒せるモンスターの最大値
  for (int i = 0; i < N; i++) {//入力例1
    s += min(A[i], B[i]);//s+=min(3,4)->s=3
    B[i] -= min(A[i], B[i]);//B[1]-=min(3,4)->B[1]=1
    A[i] -= min(A[i], B[i]);//A[1]-=min(3,4)->A[1]=0
    s += min(A[i + 1], B[i]);//s+=min(5,1)->3+1=4
    A[i+1] -= min(A[i + 1], B[i]);//A[2]-=min(5,4)->5-4=1
  }
  cout << s << "\n";
  return 0;
}
//解説pdfによると最大流問題に帰着できるらしい...


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int q;
    int dp[1005][1005];
    dp[0][0]=0;
    cin>>q;
    rep(z,q){
	string a,b;
	cin>>a>>b;
	
	reps(i,a.size()){
	    reps(j,b.size()){
		if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	cout<<dp[a.size()][b.size()]<<'\n';
    }
				  
    return 0;
}



Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n){cin>>a[i];}
  sort(a.rbegin(),a.rend());
  int sum = accumulate(a.begin(),a.end(),0);
  if(a[0]<sum-a[0]){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 && i % 5) ans += i;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3652
using System;
class Program
{
    static void Main(string[] args)
    {
        //// 整数の入力
        //int a = int.Parse(Console.ReadLine());
        //// スペース区切りの整数の入力
        //string[] input = Console.ReadLine().Split(' ');
        //int b = int.Parse(input[0]);
        //int c = int.Parse(input[1]);
        //// 文字列の入力
        //string s = Console.ReadLine();
        ////出力
        //Console.WriteLine((a + b + c) + " " + s);

        int a = int.Parse(Console.ReadLine());

        float answer = 0;
        if ( a % 2 != 0)
        {
            answer = (a - a / 2) / (float)a;
        }
        else
        {
            answer = 0.5f;
        }

        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 11092