akhauriyash/Code-Regression huggingface dataset:
<?php
$in = explode(' ', trim(fgets(STDIN)));
$a = $in[0];
$b = $in[1];
$k = $in[2];
$result = [];
for($i = 1; $i <= 100; $i++) {
    if($a % $i == 0 && $b % $i == 0) {
        $result[] = $i;
    }
}
rsort($result);
echo $result[$k - 1], PHP_EOL;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll x){ cout << x << " "; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

int main(){
    ll H,W;
    ii(H);
    ii(W);
    string S[H];
    REP(i,0,H){
        is(S[i]);
    }
    ll d[100][100];
    REP(x,0,W) REP(y,0,H) d[y][x]=1000; 

    if(S[0][0]=='#'){
        d[0][0]=1;
    }else{
        d[0][0]=0;
    }
    REP(y,0,H){
        REP(x,0,W){
            if(x>0){
                d[y][x]=d[y][x-1]+(ll)(S[y][x]=='#'&&S[y][x-1]=='.');
            }
            if(y>0){
                d[y][x]=min(d[y][x], d[y-1][x]+(ll)(S[y][x]=='#'&&S[y-1][x]=='.'));
            }
        }
    }

    oie(d[H-1][W-1]);
    return 0;
}


Measured memory_bytes: 384
from math import gcd
MAX = 10**6

sieve = [i for i in range(MAX+1)]

p = 2
while p * p <= MAX:
    if sieve[p] == p:
        for i in range(p*2, MAX+1, p):
            if sieve[i] == i:
                sieve[i] = p
    p += 1


N = int(input())
A = list(map(int, input().split()))
pf = []

for a in A:
    tmp = set()
    b = a
    while b != 1:
        tmp.add(sieve[b])
        b //= sieve[b]
    pf.append(tmp)


soin = [0] * (10 ** 6 + 1)
for f in pf:
    for n in f:
        soin[n] += 1

if max(soin[2:]) <= 1:
    print('pairwise coprime')
    exit()


setwise = A[0]

for a in A:
    setwise = gcd(setwise, a)
    
if setwise == 1:
    print('setwise coprime')
else:
    print('not coprime')

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

int main(void){
	int X,Y;
	int sum;
	int counter=0;

	cin >> Y >> X;

	int field[X][Y];

	for(int i=0;i<Y;i++){
		for(int j=0;j<X;j++){
			cin >> field[j][i];
		}
	}

	for(int start=0;start<Y-1;start++){
		for(int i=start+1;i<Y;i++){
			sum=0;
			
			for(int j=0;j<X;j++){
				sum+=pow(abs(field[j][start]-field[j][i]),2);
			}
			
			if(floor(sqrt(sum))==sqrt(sum)){
				counter++;
			}
		}
	}
	
	cout << counter << endl;

	return 0;
}


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

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

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

  int x; cin >> x;
  cout << (x < 1200 ? "ABC" : "ARC") << '\n';
  return 0;
}


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

int main(){
  int A, B, K; cin >> A >> B >> K;
  int k=0;
  for (int i=min(A,B);i>0;i--){
    if(A%i==0 && B%i==0) k++;
    if(k==K){
      cout << i << endl;
      break;
    }
  }
}




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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int sum=0,ma=0;
	rep(i,n){
		int a;cin >> a;
		sum+=a;
		ma=max(ma,a);
	}
	cout << sum-ma/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll                  long long
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
fast;
ll q=1,t;
while(q--)
{
    ll n,m,k,i,j,l,r,a,b,c=0,g,counter=0,u,v,d,e,w,p,x,y,flag=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n  >> x >> y;
    vector<ll> V(n);
    for(i=1;i<=n-1;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            V[min({j-i,abs(x-i)+1+abs(y-j)})]++;
        }
    }
    for(i=1;i<=n-1;i++) cout << V[i] << endl;
}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 5005;

bitset<N> pdp[N];
bitset<N> sdp[N];
int ps[N][N + 1];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	pdp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		pdp[i + 1] = pdp[i] | (pdp[i] << a[i]);
	}
	sdp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		sdp[i + 1] = sdp[i] | (sdp[i] << a[n - 1 - i]);
	}	
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < N; j++) {
			ps[i][j + 1] = ps[i][j] + sdp[i][j];
		}
	}	
	int c = n;
	for (int i = 0; i < n; i++) {
		int fu = 0;
		for (int p = 0; p < k; p++) {
			if (!pdp[i][p]) continue;
			int l = max(0, k - p - a[i]);
			int r = k - p;
			int any = (ps[n - 1 - i][r] > ps[n - 1 - i][l]);
			fu |= any;
		}
		c -= fu;
	}
	cout << c << endl;
}


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

int main() {
	int a, b, c;
	char op;
	cin >> a >> op >> b;
	while (op != 63) {
		if (op == 43) {
			c = a + b;
			cout << c << endl;
		}
		else if (op == 45) {
			c = a - b;
			cout << c << endl;
		}
		else if (op == 42) {
			c = a * b;
			cout << c << endl;
		}
		else if (op == 47) {
			c = a / b;
			cout << c << endl;
		}
		cin >> a >> op >> b;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	for(int i=0;i<a;++i)
	{
		int d;
		cin>>d;
		if(d<b||d>=c)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ll X,N;
     vector<ll>v(101,0);


     cin>>X>>N;
     for(ll i=0;i<N;i++){
        ll x;
        cin>>x;
        v[x]++;
     }

     if(v[X]==0)cout<<X<<endl;

     else {
               ll j=X,k=X;
                while(1){
        j--;
        if(v[j]==0&&j>=0){cout<<j<<endl;return 0;}
     else if(j<0){cout<<j<<endl;return 0;}
        k++;
         if(v[k]==0&&k<=100){cout<<k<<endl;return 0;}
         else if(k>100){cout<<k<<endl;return 0;}
                }
     }
     return 0;
}


Measured memory_bytes: 3624
import collections
N, M = [int(_) for _ in input().split()]
X = [int(_) for _ in input().split()]
rlist = [[0, collections.defaultdict(int), 0] for _ in range(M)]
for x in X:
    rlist[x % M][0] += 1
    rlist[x % M][2] += 1
    rlist[x % M][1][x] += 1
ans = rlist[0][0] // 2
if M % 2 == 0:
    ans += rlist[M // 2][0] // 2
    rlist[M // 2][0] %= 2
for i in range(1, (M + 1) // 2):
    x = min(rlist[i][0], rlist[M - i][0])
    rlist[i][0] -= x
    rlist[M - i][0] -= x
    ans += x
for i in range(1, M):
    if rlist[i][0] and 2 * i != M:
        c = res = 0
        for k in rlist[i][1].values():
            res += k % 2
            c += k // 2
        cut = rlist[i][2] - rlist[i][0] - res
        cut += cut % 2
        cut //= 2
        cut = max(0, cut)
        ans += c - cut
print(ans)


Measured memory_bytes: 48092
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================
vector<vector<pii>>G;
int n;

vi bfs(int start) {
	vi E(n, INF);

	queue<int> que;
	que.push(start);
	E[start] = 0;

	while (!que.empty()) {
		const int u = que.front(); que.pop();
		for (auto val : G[u]) {
			pii ne = val;

			int t = ne.first;
			int w = ne.second;

			if (E[t] != INF) continue;

			E[t] = E[u] + w;

			que.push(t);
		}
	}

	return E;
}

void solve() {
	vi D = bfs(0);

	int maxV = 0;
	int pos = 0;

	REP(i, n) {
		if (D[i] == INF) continue;
		if (maxV < D[i]) {
			maxV = D[i];
			pos = i;
		}
	}

	D = bfs(pos);

	maxV = 0;
	REP(i, n) {
		if (D[i] == INF) continue;
		maxV = max(maxV, D[i]);
	}

	cout << maxV << "\n";
}

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

	cin >> n;

	G.resize(n);

	int s, t, w;
	REP(i, n - 1) {
		cin >> s >> t >> w;

		G[s].push_back(make_pair(t, w));
		G[t].push_back(make_pair(s, w));
	}

	solve();
	return 0;
}

Measured memory_bytes: 9952
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // 最大公約数の取得			
    long gcd(long a, long b) {			
    	if (b == 0)		
    		return a;	
    	return gcd(b, a % b);		
    }			
    			
    // 最小公倍数の取得			
    long lcm(long a, long b) {			
    	return a / gcd(a, b)  * b;		
    }			

    // ==================================================================
    public void solve() {
    	char[] C1 = sc.next().toCharArray();
		char[] C2 = sc.next().toCharArray();
		Map<Integer, Integer> map1 = new HashMap<>();
		Map<Integer, Integer> map2 = new HashMap<>();
		int cnt1, cnt2;
		for (int i = 0; i < C1.length; i++) {
			cnt1 = (int)(C1[i] - '0');
			cnt2 = (int)(C2[i] - '0');
			if(map1.get(cnt1) == null) {
				map1.put(cnt1, cnt2);
			} else if(map1.get(cnt1) != cnt2) {
				out.println("No");	return;
			}
			if(map2.get(cnt2) == null) {
				map2.put(cnt2, cnt1);
			} else if(map2.get(cnt2) != cnt1) {
				out.println("No");	return;
			}
		}
		out.println("Yes");
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}

Measured memory_bytes: 28388
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

const long long MOD = 1000000007;
ll inv[100100];

void init_inv(){
  inv[1] = 1;
  FOR(i,2,100100){
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
  }
}

inline ll mod(ll a) {
    return (a % MOD + MOD) % MOD;
}

int main(){
  ll n;cin>>n;
  vector<ll> a(n+10);
  FOR(i,1,n+1)cin>>a[i];
  init_inv();
  
  vector<ll> inv_sum(n+10);
  inv_sum[0]=0;
  FOR(i,1,n+10)inv_sum[i]=mod(inv_sum[i-1]+inv[i]);
  
  ll n_e=1;
  FOR(i,1,n+1)n_e=mod(n_e*i);

  ll ans=0;
  FOR(i,1,n+1){
    ans=mod(ans+mod(mod(n_e*mod(inv_sum[i]+inv_sum[n-i+1]-1))*a[i]));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
n,k=map(int,input().split())
l=[0]*k
r=[0]*k
mod=998244353
for i in range(k):
    l[i],r[i]=map(int,input().split())
dp=[0]*n
sum_dp=[0]*n
dp[0]=1
sum_dp[0]=1
for i in range(1,n):
    for j in range(k):
        if (i-l[j]>=0):
            dp[i]+=sum_dp[i-l[j]]
            dp[i]%=mod
        if (i-r[j]-1>=0):
            dp[i]-=sum_dp[i-r[j]-1]
            dp[i]+=mod
            dp[i]%=mod
    sum_dp[i]=sum_dp[i-1]+dp[i]
    sum_dp[i]%=mod
print(dp[n-1])

Measured memory_bytes: 76908
/*input
5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=305;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn][maxn];
int tg[maxn][maxn];

int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,n) REP(j,n) cin>>a[i][j];

	REP(i,n) REP(j,n) REP(k,n){
		if(a[i][j]+a[j][k]<a[i][k]){
			cout<<-1;
			return 0;
		}
		if(a[i][j]+a[j][k]==a[i][k]){
			if(j!=i&&j!=k) tg[i][k]=1;
		}
	}
	ll ans=0;
	REP(i,n) for(int j=i+1;j<n;j++) if(!tg[i][j]){
		ans+=a[i][j];
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
typedef long long LL;

using namespace std;
struct point
{
	LL x;
	LL y;
}Point[60]; 

bool cmp(struct point a,struct point b)
{
	return a.x<b.x;
}
LL my_min(LL a,LL b)
{
	return a<b ? a:b; 
}
int main()
{
	LL min=7e18;
	int N,K;
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++)
		scanf("%lld %lld",&Point[i].x,&Point[i].y);
	sort(Point,Point+N,cmp);
	for(int i=0;i+K-1<N;i++)
	{
		LL dd[60];
		int len=0;
		for(int j=0;j<K-1;j++) 
			dd[len++]=Point[i+j].y;
		for(int l=K-1;i+l<N;l++)
		{
			dd[len++]=Point[i+l].y;
			sort(dd,dd+len);
			for(int q=0;q+K-1<len;q++)
				min=my_min(min,(Point[i+l].x-Point[i].x)*(dd[q+K-1]-dd[q]));
		}
	}
	printf("%lld\n",min);
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    string S;cin >> S;
    int n = S.size();
    vector<int> p;
    int a=0;
    for(int i=0;i<n;i++){
        if(i!=0){
            if(S[i]==S[i-1])a++;
            else{
                p.push_back(a);
                a=0;
            }
        }else a++;
    }
    cout << p.size() << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main() {
  ll n;
  string s;
  cin >> n;
  cin >> s;
  ll ans = 0;
  rep(i,n-2){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ans++;
    }
  }
  cout << ans << endl;
}


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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  std::string S;
  std::cin >> S;

  std::map<std::string, int> m;
  m["SUN"] = 7;
  m["MON"] = 6;
  m["TUE"] = 5;
  m["WED"] = 4;
  m["THU"] = 3;
  m["FRI"] = 2;
  m["SAT"] = 1;

  std::cout << m[S] << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる






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

  vector<vector<ll>> ans(n+1,vector<ll>(13,0));
  ans[0][0]=1;
  repo(i,13){
    ans[0][i]=0;
  }
  rep(i,n){
    if(s[i]=='?') {
      rep(j,13){
        rep(k,10){
          ans[i+1][(10*j+k)%13]+=ans[i][j];
          if(ans[i+1][(10*j+k)%13]>=mod) ans[i+1][(10*j+k)%13]%=mod;
        }
      }
    }
    else {
      rep(j,13){
        ans[i+1][(10*j+(s[i]-'0'))%13]+=ans[i][j];
        if(ans[i+1][(10*j+(s[i]-'0'))%13]>=mod) ans[i+1][(10*j+(s[i]-'0'))%13]%=mod;
      }
    }
  }

  cout << ans[n][5] << endl;

}

Measured memory_bytes: 13696
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			double xa1 = sc.nextDouble();
			double ya1 = sc.nextDouble();
			double xa2 = sc.nextDouble();
			double ya2 = sc.nextDouble();
			double xb1 = sc.nextDouble();
			double yb1 = sc.nextDouble();
			double xb2 = sc.nextDouble();
			double yb2 = sc.nextDouble();
			if(xb2 < xa1 || xa2 < xb1 || yb2 < ya1 || ya2 < yb1) {
				System.out.println("NO");
			}else {
				System.out.println("YES");
			}
		}
		sc.close();
	}
}


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

int main()
{
	char a, b;
  	cin >> a >> b;
  
  	if (a == 'H' && b == 'H') cout << "H" << endl;
  	if (a == 'H' && b == 'D') cout << "D" << endl;
  	if (a == 'D' && b == 'H') cout << "D" << endl;
  	if (a == 'D' && b == 'D') cout << "H" << endl;
  
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M; cin >> N >> M;
  vector<PII> xs(N);
  REP(i,N){
	cin >> xs[i];
  }
  vector<PII> ps(M);
  REP(i,M){
	cin >> ps[i];
  }
  
  REP(i,N){
	int res = 1e9, ix = 0;
	REP(j,M){
	  int tmp = abs(xs[i].FF - ps[j].FF) + abs(xs[i].SS - ps[j].SS);
	  if(tmp < res){
		res = tmp;
		ix = j;
	  }
	}
	cout << ix+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A

#B

#C
def dfs(n,k):
    if n == 0:
        li.append(k)
    else:
        for i in range(4):
            dfs(n-1,k+[i])
n,a,b,c = LI()
l = IR(n)
li = []
dfs(n,[])
ans = float("inf")
for k in li:
    d = [0,0,0]
    m = 0
    for i in range(n):
        if k[i] < 3:
            if d[k[i]] != 0:
                m += 10
            d[k[i]] += l[i]
    if d[0]*d[1]*d[2] == 0:continue
    m += abs(a-d[0])+abs(b-d[1])+abs(c-d[2])
    ans = min(ans, m)
print(ans)
#D
"""
a,b,q = LI()
s = IR(a)
t = IR(b)
for i in range(q):
    x = I()
    c = bisect.bisect_left(s,x)
    ans = float("inf")
    if c == a:
        k = abs(x-s[-1])
        y = s[-1]
        d = bisect.bisect_left(t,y)
        if d == b:
            k += abs(y-t[-1])
        else:
            if abs(y-t[d-1]) < abs(y-t[d]):
                k += abs(y-t[d-1])
            else:
                k += abs(y-t[d])
        ans = min(k,ans)
    else:
        k = abs(x-s[c-1])
        y = s[c-1]
        d = bisect.bisect_left(t,y)
        if d == b:
            k += abs(y-t[-1])
        else:
            if abs(y-t[d-1]) < abs(y-t[d]):
                k += abs(y-t[d-1])
            else:
                k += abs(y-t[d])
        ans = min(k,ans)
        k = abs(x-s[c])
        y = s[c]
        d = bisect.bisect_left(t,y)
        if d == b:
            k += abs(y-t[-1])
        else:
            if abs(y-t[d-1]) < abs(y-t[d]):
                k += abs(y-t[d-1])
            else:
                k += abs(y-t[d])
        ans = min(k,ans)
    c = bisect.bisect_left(t,x)
    if c == b:
        k = abs(x-t[-1])
        y = t[-1]
        d = bisect.bisect_left(s,y)
        if d == a:
            k += abs(y-s[-1])
        else:
            if abs(y-s[d-1]) < abs(y-s[d]):
                k += abs(y-s[d-1])
            else:
                k += abs(y-s[d])
        ans = min(k,ans)
    else:
        k = abs(x-t[c-1])
        y = t[c-1]
        d = bisect.bisect_left(s,y)
        if d == a:
            k += abs(y-s[-1])
        else:
            if abs(y-s[d-1]) < abs(y-s[d]):
                k += abs(y-s[d-1])
            else:
                k += abs(y-s[d])
        ans = min(k,ans)
        k = abs(x-t[c])
        y = t[c]
        d = bisect.bisect_left(s,y)
        if d == a:
            k += abs(y-s[-1])
        else:
            if abs(y-s[d-1]) < abs(y-s[d]):
                k += abs(y-s[d-1])
            else:
                k += abs(y-s[d])
        ans = min(k,ans)
    print(ans)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 60508
fun main(args: Array<String>) {
    val (N, L) = readLine()!!.split(" ").map { it.toInt() }
    val A = (1..N).map { it to L + it - 1 }
    val min = A.minBy { Math.abs(it.second) }
    println((N * (N + 1))/2 - min!!.first + (L - 1) * (N - 1))
}

Measured memory_bytes: 37868
from bisect import bisect_left


def solve(string):
    a, b, q, *stx = map(int, string.split())
    bignum = 3 * 10**10
    s = [-bignum] + stx[:a] + [bignum]
    t = [-bignum] + stx[a:a + b] + [bignum]
    ans = []
    for _x in stx[-q:]:
        i, j = bisect_left(s, _x), bisect_left(t, _x)
        ls, rs = _x - s[i - 1], s[i] - _x
        lt, rt = _x - t[j - 1], t[j] - _x
        ans.append(str(min(max(rs, rt), max(ls, lt), rt + ls + min(rt, ls),
                           rs + lt + min(rs, lt))))
    return "\n".join(ans)


if __name__ == '__main__':
    n, m, l = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, l) + '\n'.join([input() for _ in range(n + m + l)])))


Measured memory_bytes: 39512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  int k,s;
  cin>>k>>s;
  int ans=0;
  rep(x,k+1){
    rep(y,k+1){
      int z=s-x-y;
      if(0<=z&&z<=k)ans++;
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans;
char str[220000];
int main() {
	scanf("%d",&n);
	scanf("%s",&str);
	int l=0,r=n-1;
	while (l<r) {
		while (str[l]=='R')++l;
		while (str[r]=='W')--r;
		if (l<r){
			swap(str[l],str[r]);
			++ans;			
		}
		++l;--r;
	}
	for (l=0;l<n;++l) if (str[0]!=str[l]) break;
	for (r=n-1;r>=0;--r) if (str[n-1]!=str[r]) break;
	int tmp1=0,tmp2=0;
	for (int i=l;i<=r;++i) 
		if (str[i]=='W') tmp1++; else tmp2++;
	if (tmp1>tmp2) ans+=tmp2;else ans+=tmp1;
	printf("%d",ans);
	return 0;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int A,B; cin >> A >> B; cout << A*B << endl;
    
    return 0;
}


Measured memory_bytes: 3572
package main

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

func main() {
	n := readInt()

	ans, pre := 0, math.MaxInt64
	for i := 0; i < n-1; i++ {
		cur := readInt()
		ans += min(cur, pre)
		pre = cur
	}
	ans += pre

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  ll N, A, B; cin >> N >> A >> B;

  if(A > B || (N==1 && A!=B)){
    cout << 0 << endl;
    return 0;
  }

  ll ans = (B-A)*(N-2) + 1;
  cout << ans << endl;
}


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

using namespace std;

#define int long long
#define double long double

struct pt {
	double x, y;
	int it;
	double an = 0;
	pt(double x, double y, int it): x(x), y(y), it(it){}
};

bool cmp (pt a, pt b) {
	return a.x < b.x || a.x == b.x && a.y < b.y;
}

bool cw (pt a, pt b, pt c) {
	return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) < 0;
}

bool ccw (pt a, pt b, pt c) {
	return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) > 0;
}

void convex_hull (vector<pt> & a) {
	if (a.size() == 1)  return;
	sort (a.begin(), a.end(), &cmp);
	pt p1 = a[0],  p2 = a.back();
	vector<pt> up, down;
	up.push_back (p1);
	down.push_back (p1);
	for (size_t i=1; i<a.size(); ++i) {
		if (i==a.size()-1 || cw (p1, a[i], p2)) {
			while (up.size()>=2 && !cw (up[up.size()-2], up[up.size()-1], a[i]))
				up.pop_back();
			up.push_back (a[i]);
		}
		if (i==a.size()-1 || ccw (p1, a[i], p2)) {
			while (down.size()>=2 && !ccw (down[down.size()-2], down[down.size()-1], a[i]))
				down.pop_back();
			down.push_back (a[i]);
		}
	}
	a.clear();
	for (size_t i=0; i<up.size(); ++i)
		a.push_back (up[i]);
	for (size_t i=down.size()-2; i>0; --i)
		a.push_back (down[i]);
}

double getdist(pt a, pt b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double an[100];

main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<pt> a;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        a.push_back(pt(x, y, i));
    }
    convex_hull(a);
    const double pi = atan2(0, -1);
    int t = a.size();
    for(int i = 0; i < t; i++){
        int j, k;
        j = (i == 0) ? t - 1 : i - 1;
        k = (i == t - 1) ? 0 : i + 1;
        double sum = 0;
        double A = getdist(a[i], a[j]);
        double B = getdist(a[i], a[k]);
        double C = getdist(a[j], a[k]);
        sum = acos((A*A+B*B-C*C)/(2*A*B));
        an[a[i].it] = (pi - sum) / (2 * pi);
    }
    cout << fixed << setprecision(12);
    for(int i = 0; i < n; i++) cout << an[i] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007

typedef pair<int, int> pii;
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int x; cin>>x;
	ll ans = x / 500 * 1000;
	x %= 500;
	ans += x/5 * 5;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	int r;
	cin >> r;
	cout << 3*r*r << endl;
}


Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    int A,B;
    cin>>A>>B;

    if(500*A>=B){

        cout<<"Yes"<<endl;
    }
    else{

        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char c[2][3];

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

    if(c[0][0]==c[1][2]
        &&c[0][1]==c[1][1]
        &&c[0][2]==c[1][0])
            cout<<"YES"<<"\n";
    else
        cout<<"NO"<<"\n";

    return 0;
}

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

if __name__ == "__main__":
	N = int(input())
	m = 0
	a = 0
	r = 0
	c = 0
	h = 0
	for i in range(N):
		name = input()
		if name[0] == "M":
			m += 1
		elif name[0] == "A":
			a += 1
		elif name[0] == "R":
			r += 1
		elif name[0] == "C":
			c += 1
		elif name[0] == "H":
			h += 1
	# 3人を選ぶ方法を全探索する
	ans  = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h
	ans += a*r*c + a*r*h + a*c*h
	ans += r*c*h
	print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll k, a, b;
    cin >> k >> a >> b;

    cout << max(((k - a + 1) / 2) * (b - a) + a + ((k - a + 1) & 1), k + 1);

    return 0;
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;
int m[201][201];

ll gcd(ll a, ll b) {
	if(m[a][b] != 0) return m[a][b];
	if(m[b][a] != 0) return m[b][a];
	if (b == 0) return a;
	return m[b][a%b] = gcd(b, a%b);
}

int main() {
	ll n, ans = 0;
	cin >> n;
	int g1;

	REP(i,201) {
		REP(j,201) {
			m[i][j] = 0;
		}
	}

	FOR(i,1,n+1) {
		FOR(j,1,n+1) {
			g1 = gcd(i,j); 
			FOR(k,1,n+1) {
				ans += gcd(g1, k);
			}
		}
	}

	// REP(i,4) {
	// 	REP(j,4) {
	// 		cout << m[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << ans << endl;
	return 0;

}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct P{
  double x, y, z;
  P(double x_=0., double y_=0., double z_=0.):x(x_), y(y_), z(z_)
  {}
  double norm() const{
	return sqrt(x*x+y*y+z*z);
  }
  
  P operator+(const P& p2) const{
	return P(x+p2.x, y+p2.y, z+p2.z);
  }
  P operator-(const P& p2) const{
	return P(x-p2.x, y-p2.y, z-p2.z);
  }

  P operator*(double sc) const{
	return P(x*sc, y*sc, z*sc);
  }
};

double solve(const P& p1, const P& p2, const P& dv1, const P& dv2,
			 double r1, double r2, double dr1, double dr2, double ub){
  double lb = 0., md = 1e9;
  REP(i,100){
	double ts[2] = {(lb * 2 + ub) / 3., (lb + ub * 2) / 3.};
	double ys[2];
	REP(j,2){
	  P c1 = p1 + dv1 * ts[j];
	  P c2 = p2 + dv2 * ts[j];
	  double dist = (c1 - c2).norm();
	  double tr1 = r1 - dr1 * ts[j];
	  double tr2 = r2 - dr2 * ts[j];
	  ys[j] = dist - tr1 - tr2;
	  maxi(ys[j], 0.);
	}
	if(ys[0] <= ys[1]){
	  ub = ts[1];
	  md = ys[0];
	}
	else{
	  lb = ts[0];
	  md = ys[1];
	}
  }
  if(md > EPS) return 1e9;

  return lb;
}

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

  int N;
  while(cin>>N,N){
	vector<P> ps(N), dv(N);
	vector<double> rs(N), dr(N);
	REP(i,N){
	  cin >> ps[i].x >> ps[i].y >> ps[i].z
		  >> dv[i].x >> dv[i].y >> dv[i].z
		  >> rs[i] >> dr[i];
	}

	vector<double> ans(N);
	vector<bool> col(N);
	REP(i,N) ans[i] = rs[i] / dr[i];
	priority_queue<pair<double,PII>> pq;
	REP(i,N) REP(j,i){
	  double t = solve(ps[i], ps[j], dv[i], dv[j], rs[i], rs[j], dr[i], dr[j], min(ans[i], ans[j]));
	  pq.push(MP(-t,MP(i,j)));
	}

	while(!pq.empty()){
	  double at = -pq.top().FF;
	  PII p = pq.top().SS;
	  pq.pop();
	  if(col[p.FF] || col[p.SS]) continue;
	  col[p.FF] = col[p.SS] = true;
	  mini(ans[p.FF], at);
	  mini(ans[p.SS], at);
	}
	
	REP(i,N) cout << fixed << setprecision(9) << ans[i] << endl;
  }

  return 0;
}

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

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

    int ans = 0;
    for(int i=0; i<S.size()-1; i++){
        if(S[i] != S[i+1]) ans++;
    }
    cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1020
#include <stdio.h>
int main(void)
{
	int x,y,i;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x<=y){
			printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  char a, b;
  cin >> a >>b;
  if(a == b){
    cout << "H" << endl;
  }else{
    cout << "D" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int n,ans=0;
vector<Int> a(202),u(202,0);
Int tmp=0;
const Int BEET = 34;
void dfs(Int x){
  //cout<<x<<endl;
  if(x==BEET){
    Int res=tmp;
    //cout<<res<<":"<<endl;
    for(Int i=BEET;i<=n;i++){
      //cout<<"i "<<i;
      if(u[i]) continue;
      if((i&1)==0&&BEET<=i/2) continue;
      if(i*2<=n&&!u[i*2]){
	// rm i / rm i*2 / get
	res+=max({0LL,a[i],a[i]+a[i*2]});
      }else{
	// rm / get
	res+=max({0LL,a[i]});
      }
    }
    //cout<<endl;
    ans=max(ans,res);
    return;
  }
  
  if(u[x]){
    dfs(x+1);
    return;
  }

  // get x
  tmp+=a[x];
  dfs(x+1);
  tmp-=a[x];

  // rm x and its mul
  for(Int i=x;i<=101;i+=x) u[i]++;
  dfs(x+1);
  for(Int i=x;i<=101;i+=x) u[i]--;
}
signed main(){
  cin>>n;
  for(Int i=1;i<=n;i++) cin>>a[i];

  //assert(n<BEET);
  dfs(1);
  cout<<ans<<endl;
  return 0;
}


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

int main(){
	int N,Q,q;
	cin>>N>>Q;
	vector<int> c(N);
	rep(i,0,N) cin>>c[i];
	sort(all(c));
	rep(i,0,Q){
		cin>>q;
		int res=0;
		for(int j=1;(j-1)*q<1000000;j++){
			vector<int>::iterator it;
			it=lower_bound(all(c),j*q);
			if(it==c.begin()) continue;
			it--;
			res=max(res,(*it)%q);
		}
		cout<<res<<endl;
	}
}

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

using namespace std;
 
int main()
{
    string res;
    int n, cnt = 0, cntH = 0, point = 0;
 
    cin >> n;
    for (int i = 0; i < n;) {
	cin >> res;
     
	if (res == "OUT") {
	    cnt++;
	    if (cnt == 3) {
		i++;
		cnt = 0;
		cout << point << endl;
		point = 0;
		cntH = 0;
	    }
	} else if (res == "HIT") {
	    cntH++;
	    if (cntH == 4) {
		point++; cntH--;
	    }
	} else {
	    point += cntH+1;
	    cntH = 0;
	}
    }
    return 0;
}

Measured memory_bytes: 3000
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll n,a[100],ans,ans2,cnt=-1,all,L,R,dp[100][100];

int main()
{Tie
	setpre(10);
	cin>>n>>L>>R;
	dp[0][0]=1;
	for(int i=1;i<=50;i++)
		for(int j=0;j<=i;j++)
			if(j)
				dp[i][j]=dp[i-1][j]+dp[i-1][j-1];
			else
				dp[i][j]=1;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(i<L)
			ans+=a[i];
		if(!~cnt&&a[i]==a[L-1])
			cnt=L-i;
		if(a[i]==a[L-1])
			all++;
	}
	cout << (double)ans/L<<'\n';
	if(a[0]!=a[L-1])
		cout<<dp[all][cnt]<<'\n';
	else
	{
		ll tmp=0;
		for(int i=L;i<=min(R,all);i++)
			tmp+=dp[all][i];
		cout << tmp<<'\n';
	}
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * Created by fcdkbear on 15.10.16.
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        new Task().solve(in, out);
        out.close();
    }


    static class Task {

        public void solve(InputReader in, PrintWriter out) {

            int n = in.nextInt();
            int m = in.nextInt();
            String[] a = new String[n];
            int total = 0;
            for (int i = 0; i < n; ++i) {
                a[i] = in.next();
                for (int j = 0; j < m; ++j) {
                    if (a[i].charAt(j) == '#') {
                        total++;
                    }
                }
            }
            int x = 0;
            int y = 0;
            for (int i = 0; i < total; ++i) {
                if ((x >= n) || (y >= m) || (a[x].charAt(y) != '#')) {
                    out.println("Impossible");
                    return;
                }
                if ((x + 1 < n) && (a[x + 1].charAt(y) == '#')) {
                    x++;
                } else {
                    y++;
                }
            }
            out.println("Possible");

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }

}


Measured memory_bytes: 8528