akhauriyash/Code-Regression huggingface dataset:
sx, sy, tx, ty = map(int, input().split())
diff_x = tx - sx
diff_y = ty - sy
for _ in range(diff_x):
    print("R", end="")
for _ in range(diff_y):
    print("U", end="")
for _ in range(diff_x):
    print("L", end="")
for _ in range(diff_y):
    print("D", end="")
print("D", end="")
for _ in range(diff_x+1):
    print("R", end="")
for _ in range(diff_y+1):
    print("U", end="")
print("L", end="")
print("U", end="")
for _ in range(diff_x+1):
    print("L", end="")
for _ in range(diff_y+1):
    print("D", end="")
print("R")


Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int t;
  cin >> t;
  rep(i,t){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a<b){
      cout << "No" << endl;
      continue;
    }
    if(b>d){
      cout << "No" << endl;
      continue;
    }
    if(c>=b-1){
      cout << "Yes" << endl;
      continue;
    }
    a=a%b;
    d=d%b;
    if(d==0){
      if(a<=c)cout << "Yes" << endl;
      else cout << "No" << endl;
      continue;
    }
    ll k=gcd(b,d);
    if(b-1-(b-1-a)%k<=c){
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
}  


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    for(auto&& i : A)cin >> i;
    if(accumulate(begin(A), end(A), 0UL, gcd<unsigned long, unsigned long>) != 1)return 0 & puts("not coprime");
    A.erase(remove(begin(A), end(A), 1UL), end(A));
    unsigned long M{*max_element(begin(A), end(A)) + 1};
    vector<unsigned long> memo(M), sieve(M, 1);
    for(const auto& i : A)if((memo[i] += 1) > 1)return 0 & puts("setwise coprime");
    for(unsigned long i{2}; i < M; ++i)if(sieve[i])for(unsigned long j{2}; i * j < M; ++j){
        sieve[i * j] = 0;
        if((memo[j] += memo[i * j]) > 1)return 0 & puts("setwise coprime");
    }
    puts("pairwise coprime");
    return 0;
}

Measured memory_bytes: 26672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x, y, a;
    int tmp1, tmp2, tmp3;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp1 >> tmp2 >> tmp3;
        x.push_back(tmp1);
        y.push_back(tmp2);
        a.push_back(tmp3);
    }
    int x0 = 0, y0 = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 1)
        {
            x0 = max(x0, x[i]);
        }
        if (a[i] == 2)
        {
            w = min(w, x[i]);
        }
        if (a[i] == 3)
        {
            y0 = max(y0, y[i]);
        }
        if (a[i] == 4)
        {
            h = min(h, y[i]);
        }
    }
    if (h - y0 < 0 || w - x0 < 0)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << max(0, (h - y0) * (w - x0)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main(){
	fast;	
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && a==c && b==c) cout<<1;
	else if(a==b && b!=c) cout<<2;
	else if(a==c && b!=c) cout<<2;
	else if(b==c && a!=b) cout<<2;
	else if(a!=b && b!=c && a!=c) cout<<3; 
}
	


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

typedef long long int ll;

ll n,k;
ll arr[100005];


ll dp[100005];

ll solve(ll i){
	
	if(i>=n)return INT_MAX;
	
	if(i==n-1)return 0;
	
	if(dp[i]==-1){
		
		ll x = INT_MAX;
		ll y = INT_MAX;
		/*
		if(i+2<n){
			
			x = solve(i+2)+abs(arr[i+2]-arr[i]);
			
		}
		if(i+1<n){
			y = solve(i+1)+abs(arr[i+1]-arr[i]);
		}
		*/
		vector <ll> ans; 
		ans.push_back(INT_MAX);
		for(ll w=1;w<=k;w++){
			if(i+w>=n)break;
			ans.push_back(solve(i+w)+abs(arr[i+w]-arr[i]));
		}
		
		dp[i] = *min_element(ans.begin(),ans.end());
		
	}
	return dp[i];
	
	
}

int main(){

	memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    
    for(ll i=0;i<n;i++)cin>>arr[i];
	
	cout<<solve(0);
	
}

Measured memory_bytes: 12800
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

void bubble_sort(int* p, int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[j], &p[j + 1]);
		}
	}
}

int array_max(int* p, int n)
{
	int max = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] > max)
			max = p[i];
	}
	return max;
}

int binary_search(int* p, int key, int n)
{
	int low = 0, high = n - 1;
	int middle;

	while (low <= high)
	{
		middle = (low + high) / 2;

		if (key == p[middle])
			return key;
		else if (key < p[middle])
			high = middle - 1;
		else if (key > p[middle])
			low = middle + 1;
	}
	return -1;
}

int main()
{
	int N;
	int M;
	int K;
	//int a[100000];
	int ans = 0;
	int conut = 0;
	char a;

	scanf("%c", &a);


	/*
	for (int i = 0; i < N; i++)
	{
		scanf("%d",&a[i]);
	}
	*/
	char b;
	b = a + 1;

	printf("%c\n", b);

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S;
  cin >> S;
  if(S.size()==1){
    cout << S << endl;
    return 0;
  }
  Rep(i,1,S.size()){
    if(S[i]!='9'){
      cout << ctoi(S[0])-1+9*(S.size()-1) << endl;
      return 0;
    }
  }
  cout << ctoi(S[0])+9*(S.size()-1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld  double
#define ll long long 
#define pp push
#define pb push_back
#define pf push_front
#define mp make_pair
#define inf 1e9
#define f first
#define s second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define mod 1000000007
using namespace std; 
int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++)cin>>h[i];
    ll dp[n];
    memset(dp,mod,sizeof(dp));
    dp[0]=0;
    for(ll i=1;i<n;i++)
    {
        
        for(ll j=i-1;j>=i-k&&j>=0;j--)dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int D = scan.nextInt();
        long[][] original = new long[H*W+1][2];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int A = scan.nextInt();
                original[A][0] = i;
                original[A][1] = j;
            }
        }
        long[] s = new long[H*W+1];
        for (int i = 1; i <= H * W - D; i++) {
            s[i+D] = s[i]
                    + Math.abs(original[i+D][0]-original[i][0])
                    + Math.abs(original[i+D][1]-original[i][1]);
        }
        int Q = scan.nextInt();
        for (int i = 0; i < Q; i++) {
            int L = scan.nextInt();
            int R = scan.nextInt();
            System.out.println(s[R]-s[L]);
        }
    }
}


Measured memory_bytes: 102228
import math


S = input()
N = len(S)
stays = [0] * N

def parse_head(s, start=0):
    assert s[start] == 'R'
    for i in range(start, N):
        if s[i] == 'L':
            split = i
            for j in range(split, N):
                if s[j] == 'R':
                    end = j
                    return start, split, end
            end = N
            return start, split, end

def gather(s, start, split, end):
    split_R = split - 1
    split_L = split
    end = end - 1

    count_split_R = 0
    count_split_L = 0

    count = (split_R - start + 1) / 2
    # print(count)
    count_split_R += math.ceil(count)
    count_split_L += math.floor(count)

    count = (end - split_L + 1) / 2
    # print(count)
    count_split_L += math.ceil(count)
    count_split_R += math.floor(count)

    return count_split_R, count_split_L


idx = 0
while idx < N:
    start, split, end = parse_head(S, start=idx)
    count_split_R, count_split_L = gather(S, start, split, end)
    stays[split-1] += count_split_R
    stays[split] += count_split_L
    # print(S[start:end], stays)
    idx = end

print(' '.join([str(stay) for stay in stays]))

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
const int INF = 1001001001;
 
int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
 
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
 
  cout << "Yes" << endl;
  rep(i, n) {
    if (i == 0) continue;
    cout << pre[i] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 10656
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){cout<<endl;}template<class H,class...T>void put(string d,H&&h,T&&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

template<class T>string bitstr(T x){return typeid(T)==typeid(int)?bitset<32>(x).to_string('_','#'):bitset<64>(x).to_string();}
template<class T>int bitcnt(T x){return typeid(T)==typeid(int)?__builtin_popcount(x):__builtin_popcountll(x);}
template<class T>int bitdig(T x){return x?typeid(T)==typeid(int)?32-__builtin_clz(x):64-__builtin_clzll(x):0;}
template<class T>int bitpow(T x){return x?typeid(T)==typeid(int)?__builtin_ctz(x):__builtin_ctzll(x):0;}


int main(){
    dcl(h,w);
    vvi s(h+2,vi(w+2,-1));
    rep(i,h)rep(j,w){
        dclt(char,c);
        s[i+1][j+1]=(c=='#'?-1:0);
    }
    s[1][1]=1;
    
    queue<pii> q;
    q.emplace(1,1);
    while(!q.empty()){
        pii cur=q.front();
        q.pop();
        int v[]={-1,0,1,0,-1};
        rep(i,4){
            if(s[cur.fs+v[i]][cur.sc+v[i+1]]==0){
                s[cur.fs+v[i]][cur.sc+v[i+1]]=s[cur.fs][cur.sc]+1;
                q.emplace(cur.fs+v[i],cur.sc+v[i+1]);
            }
        }
    }
    if(s[h][w]==0){
        cout<<-1<<endl;
        return 0;
    }
    q.emplace(h,w);
    while(!q.empty()){
        pii cur=q.front();
        q.pop();
        int v[]={-1,0,1,0,-1};
        rep(i,4){
            if(s[cur.fs+v[i]][cur.sc+v[i+1]]==s[cur.fs][cur.sc]-1){
                s[cur.fs][cur.sc]=-1;
                q.emplace(cur.fs+v[i],cur.sc+v[i+1]);
                break;
            }
        }
    }
    s[1][1]=-1;
    int ans=0;
    rep(i,h+2)rep(j,w+2)if(s[i][j]>=0)ans++;
    cout<<ans<<endl;

}



Measured memory_bytes: 256
use std::collections::HashMap;

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    line = String::new();
    std::io::stdin().read_line(&mut line);
    let a: Vec<i64> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
    let n = a.len();
    let mut count: HashMap<i64, i64> = HashMap::new();
    for &ai in &a {
        let c = count.entry(ai).or_insert(0);
        *c += 1;
    }
    let mut ret = 0;
    for (_, value) in &count {
        ret += value * (value - 1) / 2;
    }
    for &ai in &a {
        let m = count.get(&ai).unwrap();
        println!("{}", ret - m * (m - 1) / 2 + (m - 1) * (m - 2) / 2);

    }
}


Measured memory_bytes: 18380
n,*aa = map(int, open(0).read().split())
from collections import Counter
l_cnt = Counter()
r_cnt = Counter()

for i,a in enumerate(aa):
    l_cnt[i+a] += 1

for i,a in enumerate(aa):
    if i-a in l_cnt:
        r_cnt[i-a] += 1

ans = 0
for key in r_cnt:
    ans += l_cnt[key] * r_cnt[key]
print(ans)

Measured memory_bytes: 124528
#include <bits/stdc++.h>
const int MAX=3e5+10;
const int modn=1e9+7;
typedef long long ll ;
#define int ll
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
int h,w,m;
int x,y;
map<int,int>cntx,cnty;
map<int,int>::iterator it;
int maxx,maxy;
int ansx[MAX],ansy[MAX];
map<pair<int,int>,int>mp;
vector<int>flagx,flagy;
void solve(){
    cin>>h>>w>>m;
    for(int i=1;i<=m;i++){
        cin>>x>>y;
        cntx[x]++;
        cnty[y]++;
        mp[pair<int,int>(x,y)]++;
    }
    for(it=cntx.begin();it!=cntx.end();it++){
        maxx=max(maxx,it->second);
    }
    for(it=cnty.begin();it!=cnty.end();it++){
        maxy=max(maxy,it->second);
    }
    for(it=cntx.begin();it!=cntx.end();it++){
        if(it->second==maxx)
            flagx.push_back(it->first);
    }
    for(it=cnty.begin();it!=cnty.end();it++){
        if(it->second==maxy)
            flagy.push_back(it->first);
    }
    int maxn=0;
    for(int i=0;i<flagx.size();i++){
        int xx=flagx[i];
        for(int j=0;j<flagy.size();j++){
            int cnt=0;
            int yy=flagy[j];
            if(mp[pair<int,int>(xx,yy)]==0){
                cout<<maxx+maxy;
                return;
            }
        }
    }
    cout<<maxx+maxy-1;
}
signed main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //cwk;
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 67876
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  dic = {}
  for i in range(n):
    a = int(input())
    if a in dic:
      if dic[a] == 1:
        dic[a] = 0
      elif dic[a] == 0:
        dic[a] = 1
    else:
      dic[a] = 1
  cnt = 0
  for k,v in dic.items():
    cnt += v
  print(cnt)
if __name__ == '__main__':
  main()

Measured memory_bytes: 15068
#include <stdio.h>
int fib(int);
int fibo[45];
int main(){
  int n,i;
  for(i=0;i<45;i++)fibo[i]=-1;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}
int fib(int n){
  if(n==0 || n==1)return fibo[n]=1;
  if(fibo[n]!=-1)return fibo[n];
  return fibo[n]=fib(n-1)+fib(n-2);
}



Measured memory_bytes: 2752
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque

n,u,v=nii()
u-=1
v-=1

tree=[[] for i in range(n)]
for i in range(n-1):
  a,b=nii()
  a-=1
  b-=1
  tree[a].append(b)
  tree[b].append(a)

def BFS(s):
  dist=[-1 for i in range(n)]
  dist[s]=0

  que=deque()
  que.append(s)

  while que:
    x=que.popleft()
    for i in tree[x]:
      if dist[i]==-1:
        que.append(i)
        dist[i]=dist[x]+1
  return dist

dist_t=BFS(u)
dist_a=BFS(v)

ans=0
for i in range(n):
  if dist_a[i]>dist_t[i]:
    ans=max(ans,dist_a[i]-1)

print(ans)

Measured memory_bytes: 33820
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll N;
    cin >> N;
    ll M = (N % 2 == 0) ? N : (N + 1);
    auto ans = make_vec_nd((ll)0, M, M);
    rep(i,0,M) {
        rep(j,i+1,M) {
            ll level = 1;
            ll k = j - i;
            while (k % 2 == 0) {
                k /= 2;
                level++;
            }
            ans[i][j] = level;
        }
    }
    rep(i,0,N-1) {
        rep(j,i+1,N) {
            cout << ans[i][j];
            if (j != N-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int n,K,Q,a[2005],w[2005],s[2005],temp[2005];
int main(){
	scanf("%d%d%d",&n,&K,&Q);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),w[i]=a[i];
	sort(w+1,w+n+1);
	int ans=2e9;
	for(int i=1;i<=n;i++){
		int top=0;
		for(int p=1,j;p<=n;){
			if(a[p]<w[i]){
				p++;continue;
			}
			for(j=p;a[j]>=w[i]&&j<=n;j++) temp[j-p+1]=a[j];
			sort(temp+1,temp+j-p+1);
			for(int k=1;k<=j-p-K+1;k++) s[++top]=temp[k];
			p=j;
		}
		sort(s+1,s+top+1);
		if(top>=Q) ans=min(ans,s[Q]-s[1]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ct = 0
flg = 0
for i in range(N):
    s,g = map(int,input().split())
    if s == g:
        ct += 1
    else:
        ct = 0
    if ct == 3:
        flg = 1

print(("No","Yes")[flg == 1])

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

struct Edge{
  int to,cost;
  bool operator<(const Edge&a)const{
    return cost>a.cost;
  }
};
struct Graph{
  Graph(int n):E(n),T(n),N(n){}
  vector<vector<Edge>>E,T;
  int N;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
    E[b].push_back({a,c});
  }
  void prim(int s){
    bool visited[N];
    priority_queue<pair<Edge,int>>Q;
    memset(visited,0,N);
    Q.push({{s,0},-1});
    while(!Q.empty()){
      Edge e=Q.top().first;
      int from=Q.top().second;Q.pop();
      if(visited[e.to])continue;
      visited[e.to]=1;
      if(from+1)T[from].push_back(e),T[e.to].push_back({from,e.cost});
      for(auto&a:E[e.to])
      if(!visited[a.to])Q.push({a,e.to});
    }
  }
  int get_cost(){
    int ret=0;
    for(auto&a:T)for(auto&b:a)ret+=b.cost;
    return ret/2;
  }
  vector<Edge>* get_MST(){
    return T.data();
  }
};

main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    Graph G(N);
    for(int i=0;i<N;++i)
        for(int j=0;j<N;++j){
            int a;
            cin>>a;
            if(~a) G.add_edge(i,j,a);
        }
    G.prim(0);
    cout<<G.get_cost()<<endl;
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

ULL MOD;

struct Matrix {
	ULL M[3][3] = { {1,0,0}, {0,1,0}, {0,0,1} };
	Matrix operator*(const Matrix &r) const {
		Matrix t;
		rep(x, 3) rep(y, 3) {
			t.M[x][y] = 0;
			rep(i, 3) {
				t.M[x][y] += M[i][y] * r.M[x][i];
				t.M[x][y] %= MOD;
			}
		}
		return t;
	}
};

Matrix Pow(const Matrix &a, ULL p) {
	if (p == 0) return Matrix();
	if (p == 1) return a;
	Matrix tmp = Pow(a, p / 2);
	tmp = tmp * tmp;
	if (p % 2 == 1) tmp = tmp * a;
	return tmp;
}
ULL Pow(const ULL &a, ULL p) {
	if (p == 1) return a;
	ULL tmp = Pow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2 == 1) tmp = tmp * a % MOD;
	return tmp;
}

struct Problem {

	ULL ans = 0;

	void Solve2(ULL Len, ULL A, ULL B, ULL P) {
		Matrix Mx;
		Mx.M[0][0] = P % MOD; Mx.M[1][0] = 0; Mx.M[2][0] = 0;
		Mx.M[0][1] = 1; Mx.M[1][1] = 1; Mx.M[2][1] = 0;
		Mx.M[0][2] = 0; Mx.M[1][2] = B % MOD; Mx.M[2][2] = 1;
		Mx = Pow(Mx, Len);
		ans = ans * Mx.M[0][0] + A % MOD * Mx.M[0][1] + Mx.M[0][2];
		ans %= MOD;
	}

	void Solve() {
		ULL Len, A, B; cin >> Len >> A >> B >> MOD;
		ULL R = A + B * Len;
		rep(i, 18) {
			ULL P = 1; rep(j, i) P *= 10;
			ULL Lb = P, Rb = P * 10;
			if (R <= Lb) continue;
			if (A >= Rb) continue;
			Lb = max(Lb, A);
			Rb = min(Rb, R);
			Lb = (Lb + B - 1 - A) / B * B + A;
			Rb = (Rb + B - 1 - A) / B * B + A;
			Solve2((Rb - Lb) / B, Lb, B, P * 10);
		}
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
tiles = [[0 for _ in range(W)] for _ in range(H)]
index = 0
rest_a = A[0]
for h in range(H):
  for w in range(W):
    if rest_a == 0:
      index += 1
      rest_a = A[index]-1
    else:
      rest_a -= 1
    if h%2 == 0:
      tiles[h][w] = index+1
    else:
      tiles[h][W-w-1] = index+1
for h in range(H):
  print(' '.join(map(str, tiles[h])))

Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int num = 0;
  vector<bool> exist(4);
  string color = "PWGY";
  char si;
  cin >> N;
  for(int n=0; n<N; n++){
    cin >> si;
    for(int i=0; i<4; i++){
        if(!exist.at(i)){
            if(color.at(i) == si){
                exist.at(i) = true;
                num += 1;
            }
        }
    }
  }
  if (num == 3)
    cout << "Three" << endl;
  if (num == 4)
    cout << "Four" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int n;cin>>n;
    string s;
    int p;
    set<pair<pair<string,int>,int> > st;
    for(int i=0;i<n;i++){
        cin>>s>>p;
        st.insert(make_pair(make_pair(s,-1*p),i+1));
    }
    for(auto it=st.begin();it!=st.end();it++){
        cout<<it->second<<endl;
    }
    return 0;
}

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

int main()
{
    void solution();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solution();

    return 0;
}

void solution()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, b * d), max(a * d, b * c));
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	ll k;
	cin >> k;
	if (k == 1) {
		cout << 1 << "\n";
		return;
	}
	vector <ll> x;
	ll tmp = 7 % k;
	x.pb(tmp);
	map <int, int> g;
	g[tmp] = 1;
	for (ll i = 1; ;i++) {
		tmp = (tmp * 10 + 7) % k;
		if (g.find(tmp) != g.end()) break;
		x.pb(tmp);
		g[tmp] = 1;
	}
	for (ll i = 0; i < x.size(); i++) {
		if (x[i] % k == 0) {
			cout << i + 1 << "\n";
			return;
		}
	}
	//cout << x.size() << "\n";
	cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

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

using namespace std;

static long long MOD = 1e9 + 7;

/*
 * 素因数とその個数の map を返す
 */
static map<long long, long long> calc_prime_factor (long long n) {
    map<long long, long long> prime_factor;
    for ( long long i = 2; i * i <= n; i++ ) {
        while ( n % i == 0 ) {
            prime_factor[i]++;
            n /= i;
        }
    }
    if ( n != 1 )
        prime_factor[n]++;
    return prime_factor;
}

int main (void) {
    int N;
    cin >> N;

    map<long long, long long> prime_factor;
    vector<long long> n_factor(N+1, 0);
    for ( int i = 2; i <= N; i++ ) {
        prime_factor = calc_prime_factor(i);
        for ( auto itr : prime_factor )
            n_factor[itr.first] += itr.second;
    }

    long long ans = 1;
    for ( int i = 2; i <= N; i++ ) {
        ans *= n_factor[i] + 1;
        ans %= MOD;
    }

    cout << ans << 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;

#define int long long

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	vector<int> f(n);
	{
		vector<int> st;
		for (int i = 0; i < n; i++) {
			while (!st.empty() && a[st.back()] >= a[i]) {
				st.pop_back();
			}
			f[i] = -1;
			if (!st.empty()) f[i] = st.back();
			st.push_back(i);
		}
	}
	vector<int> s(n);
	{
		vector<int> st;
		for (int i = n - 1; i >= 0; i--) {
			while (!st.empty() && a[st.back()] > a[i]) {
				st.pop_back();
			}
			s[i] = n;
			if (!st.empty()) s[i] = st.back();
			st.push_back(i);
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int l = (i - f[i]);
		int r = (s[i] - i);
		// cerr << i << ' ' << l << ' ' << r << endl;
		ans += (a[i] * l * r);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7156
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int x,n,p;
std::set<int> st;
int main(){
	std::cin>>x>>n;
	rep(i,n){
		std::cin>>p;
		st.insert(p);
	}
	int ans=0;
	rep(i,300){
		if(st.find(i)==st.end()&&std::abs(ans-x)>std::abs(i-x)){
			ans=i;
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}


Measured memory_bytes: 3644
# include <iostream>
# include <algorithm>

const int MAX_N = 1000;
const int MAX_m = 1000;

struct X {
	int number;
	int count = 0;
	bool operator<(const X& _x) {
		return count<_x.count;
	}
};

int n, m;

int a[MAX_N], b;
X x[MAX_N];

int main() {
	std::cin >> n >> m;
	for (int i = 0; i<n; ++i)
		std::cin >> a[i];
	for (int i = 0; i<m; ++i) {
		std::cin >> b;
		for (int j = 0; j<n; ++j) {
			if (a[j] <= b) {
				++x[j].count;
				break;
			}
		}
	}
	for (int i = 0; i<n; ++i)
		x[i].number = i;
	X *p = std::max_element(x, x + n);
	std::cout << (*p).number+1 << std::endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int solve(string x, string y) {
    int n = x.length();
    int m = y.length();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (x[i - 1] == y[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
           else {
               dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[n][m];
}

int main() {
    int n;
    cin >> n;
    string x, y;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        cout << solve(x, y) << endl;
    }
    return 0;
}



Measured memory_bytes: 6808
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define endl '\n'
const ll N=2e5+5,mod=1000000007,bit=60;
signed main()
{
    fast;
    ll pro=1,temp,t,i,j,l,r,n,m,mid,z,k,x,y,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,next,sum=0,flag=1,i1=-1,i2=-1,u,v;
    cin>>x>>y;
    n=__gcd(x,y);
    for(i=2;i<=sqrt(n);i++)
    {
    	if(n%i==0)
    	{
    		ans++;
    		while(n%i==0)
    		{
    			n/=i;
    		}
    	}
    }
    if(n>=2)
    {
    	ans++;
    }
    ans++;
    cout<<ans<<endl;
	return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

string s,ans;
int main(){
	cin >> s;
	
	bool al[26];

	rep(i,0,26){
		al[i] = false;
	}

	rep(i,0,s.size()){
		al[s[i]-'a'] = true;
	}
	rep(i,0,26){
		if(al[i] == false){
			printf("%c\n",(char)(i+'a'));
			return 0;
		}
	}
	printf("None\n");
	return 0;
}


Measured memory_bytes: 512
str=input()
N=len(str)
a=[0]*N
a[0]=int(str[N-1])
base=10
for i in range(N-1):
    a[i+1]=(int(str[N-i-2])*base+a[i])%2019
    base*=10
    base%=2019
b=[0]*2019
b[0]=1
for i in range(N):
    b[int(a[i])]+=1
ans=0
for i in range(2019):
    if b[i]>1:
        ans+=(b[i]*(b[i]-1))/2
print(int(ans))

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



int main()
{
    int a, b;
    cin >> a >> b;
    ll gcd = __gcd(a, b);
    ll lcm;
    lcm = a  / gcd * b;
    cout << lcm << endl;
    return 0;
}


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

using namespace std;

int main(void) {
    int N, no = 0;

    cin >> N;

    vector<int> A(N,0);

    for (int i = 1; i < N; i++) {
        cin >> no;
        A.at(no - 1)++;
    }

    for (int i = 0; i < N; i++) {
        cout << A.at(i) << endl;
    }

    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int K; cin >> K;
    ll out=0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            int tmp=gcd(i,j);
            for(int k=1;k<=K;k++){
                out += gcd(tmp,k);
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    int pt1 = p+q;
    int pt2 = p+r;
    int pt3 = r+q;
    if(pt1<=pt2){
      if(pt1<=pt3){
        System.out.println(pt1);
      }else{
        System.out.println(pt3);
      }
    }else{
      if(pt2<=pt3){
        System.out.println(pt2);
      }else{
        System.out.println(pt3);
      }
    }  
  }
}

Measured memory_bytes: 21844
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
//#include <intrin.h>
#include <ctime>
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
using namespace::std;

void solve(){
	vector< vector<int> > A(3,vector<int>(3));
	for(int r=0;r<3;++r){
		for(int c=0;c<3;++c){
			cin >> A[r][c];
		}
	}
	int X = A[0][0];
	int Y = A[1][0];
	int Z = A[2][0];
	int B1 = A[0][1]-X;
	int B2 = A[1][1]-Y;
	int B3 = A[2][1]-Z;
	if( B1!=B2 || B2 != B3 ){
		cout << "No" << endl;
		return;
	}
	int C1 = A[0][2]-X;
	int C2 = A[1][2]-Y;
	int C3 = A[2][2]-Z;
	if( C1!=C2 || C2 != C3 ){
		cout << "No" << endl;
		return;
	}
	cout << "Yes" << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#![allow(non_snake_case)]
use std::collections::VecDeque;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:usize = sc.read();
    let mut E:Vec<Vec<(usize, usize)>> = vec![vec![];N];
    for i in 0..(N-1){
        let mut a: usize = sc.read();
        let mut b: usize = sc.read();
        a -= 1;
        b -= 1;
        E[a].push((b,i));
        E[b].push((a,i));    
    }
    let mut d:VecDeque<usize> = VecDeque::new();
    let mut Ans:Vec<usize> = vec![0;N];
    
    d.push_back(0);
    while let Some(v) = d.pop_front(){
        let mut num:usize = 1;
        let mut before:usize = 0;
        for i in 0..(E[v].len()){
            if Ans[E[v][i].1] > 0{
                before = Ans[E[v][i].1];
                break
            }
        }
//        println!("{}", v);
        for i in 0..(E[v].len()){
            if num == before{
                num += 1;
            }
            if Ans[E[v][i].1] == 0{
                Ans[E[v][i].1] = num;
//                println!("hoge {}", E[v][i].0);
                d.push_back(E[v][i].0);
                num += 1;
            }
        }
    }
    let mut ans:usize = 1;
    for i in 0..(N-1){
        if Ans[i] > ans{
            ans = Ans[i];
        }
    }
    println!("{}", ans);
    for i in 0..(N-1){
        println!("{}", Ans[i]);
    }
    

}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 14716
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn inv(a: usize) -> usize {
    let m = M as i64;
    let mut a = a as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    let mut tmp;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        tmp = a;
        a = b;
        b = tmp;
        u -= t * v;
        tmp = u;
        u = v;
        v = tmp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u as usize;
}

fn main() {
    input! {
        k: usize,
        s: Chars,
    }
    let n = s.len();
    let m = n + k;
    let mut f = vec![1; m + 1];
    let mut g = vec![1; m + 1];
    let mut p = vec![1; m + 1];
    let mut q = vec![1; m + 1];
    for i in 1..=m {
        f[i] = f[i - 1] * i % M;
        g[i] = inv(f[i]);
        p[i] = p[i - 1] * 26 % M;
        q[i] = q[i - 1] * 25 % M;
    }
    let mut result = 0;
    for i in n..=m {
        let l = m - i;
        let mut s = q[i - n] * p[l] % M;
        s = s * f[i - 1] % M * g[n - 1] % M * g[i - n] % M;
        result = (result + s) % M;
    }
    println!("{}", result);
}


Measured memory_bytes: 69544
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;
use std::mem::swap;
use std::time::Instant;
use rand::random;
use std::cmp::min;

const MIN: i64 = std::i64::MIN;

fn score(t: &Vec<usize>, c: &Vec<i64>, s: &Vec<Vec<i64>>) -> i64 {
    let mut last = vec![0; 26];
    let mut score = 0;
    for i in 0..t.len() {
        score += s[i][t[i]] - (0..26).fold(0, |acc, x| acc + (i as i64 + 1 - last[x]) * c[x]);
        last[t[i]] = i as i64;
    }
    score
}

#[fastout]
fn main() {
    input! {
    d: usize,
    c: [i64; 26],
    s: [[i64; 26]; d]
    }
    let start = Instant::now();
    let mut dp = vec![vec![vec![vec![]; 27]; 26]; d + 1];
    for i in 0..=d {
        for j in 0..26 {
            for k in 0..27 {
                dp[i][j][k].push(MIN)
            }
        }
    }
    for i in 0..26 {
        for j in 0..27 {
            dp[0][i][j][0] = 0;
        }
    }
    for i in 0..d {
        for j in 0..26 {
            for k in 0..26 {
                let t = dp[i][k][0][0] - (1..27)
                    .fold(0, |acc, x| acc + if j != x - 1 { (i as i64 + 1 - dp[i][k][x][dp[i][k][x].len() - 1]) * c[x - 1] } else { 0 }) + s[i][j];
                if t > dp[i + 1][j][0][0] {
                    dp[i + 1][j][0][0] = t;
                    for l in 1..27 {
                        dp[i + 1][j][l] = dp[i][k][l].clone();
                        if j == l - 1 {
                            dp[i + 1][j][l].push(i as i64 + 1);
                        }
                    }
                }
            }
        }
    }
    let mut ans = vec![vec![]; 26];
    ans[0].push(MIN);
    for i in 0..26 {
        if ans[0][0] < dp[d][i][0][0] { swap(&mut ans, &mut dp[d][i]) }
    }
    let mut t = vec![0; d];
    for i in 1..27 {
        for j in 0..ans[i].len() {
            if ans[i][j] == 0 { continue; }
            t[ans[i][j] as usize - 1] = i - 1;
        }
    }
    let mut end = start.elapsed();
    let mut cur_s = score(&t, &c, &s);
    let try_count = 10;
    while end.as_nanos() < 1_860_000_000 {
        let k = (0..try_count).map(|_|random::<usize>() % d).collect::<Vec<usize>>();
        let prev_k = (0..try_count).map(|x| t[k[x]]).collect::<Vec<_>>();
        for i in 0..try_count {
            t[k[i]] = random::<usize>() % 26;
        }
        let next_s = score(&t, &c, &s);
        if cur_s > next_s {
            for i in 0..try_count {
                t[k[i]] = prev_k[i];
            }
        } else {
            cur_s = next_s;
        }
        end = start.elapsed();
    }
    for i in 0..d {
        println!("{}",t[i] + 1);
    }
}



Measured memory_bytes: 29260
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a,b,c,d;
cin >> a>>b>> c>>d;
if(a+b==c+d) cout <<"Balanced"<<endl;
else if((a+b)>(c+d)) cout <<"Left"<<endl;
else cout << "Right"<<endl;
}


Measured memory_bytes: 256