akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

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

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1},dy[]={0,1,0};

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

struct State{
	int x,y,d,o,s;
	State(int a,int b,int h,int e,int g):x(b),y(a),d(h),o(e),s(g){}
	bool operator>(const State& s)const{
		return d>s.d;
	}
};

int W,H,f,m,o,c[10][10],d[10][10][51][1<<10],ans;

void Solve(){
	fill_n((int*)d,10*10*51*(1<<10),INF);
	ans=INF;
	priority_queue<State,vector<State>,greater<State>> que;
	REP(x,0,W){
		int cost=0,oxy=o-1;
		if(oxy<=0) continue;
		if(c[0][x]<0) cost=-c[0][x];
		else oxy=min(m,oxy+c[0][x]);
		if(cost>f||oxy<=0) continue;
		d[0][x][oxy][1<<x]=cost;
		que.push(State(0,x,cost,oxy,1<<x));
	}
	while(!que.empty()){
		State v=que.top();
		que.pop();
		int vy=v.y,vx=v.x,vd=v.d,vo=v.o,vs=v.s;
		if(vy==H-1) ans=min(ans,d[vy][vx][vo][vs]);
		if(d[vy][vx][vo][vs]<vd||vo<=1) continue;
		REP(i,0,3){
			int ny=vy+dy[i],nx=vx+dx[i];
			if(ny<0||H<=ny||nx<0||W<=nx) continue;
			int cost=0,no=vo-1,ns=vs|(1<<nx);
			if(ny!=vy||((vs>>nx)&1)==0){
				if(c[ny][nx]<0) cost=-c[ny][nx];
				else no=min(m,no+c[ny][nx]);
			}
			if(ny!=vy) ns=1<<nx;
			if(vd+cost<d[ny][nx][no][ns]&&vd+cost<=f){
				d[ny][nx][no][ns]=vd+cost;
				que.push(State(ny,nx,d[ny][nx][no][ns],no,ns));
			}
		}
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while(true){
		cin >> W >> H;
		if(W==0&&H==0) break;
		cin >> f >> m >> o;
		REP(y,0,H) REP(x,0,W) cin >> c[y][x];
		Solve();
		if(ans==INF) cout << "NA";
		else cout << ans;
		cout << endl;
	}
	return 0;
}

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

#define what_is(x) cerr << #x << " is " << x << endl;

const ll MAX = (1LL<<61);

const int N = 1e5+1;

int n, m;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// cout.precision(2); cout << fixed;
	cin >> n >> m;
	int ans = 1;
	for (int i = 1; i*i <= m; i++) {
		if (m%i == 0) {
			if (m / i >= n) {
				ans = max(ans,i);
			}
			if (i >= n) {
				ans = max(ans, m/i);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
Data = list(map(int,input().split()))
Ans  = [0]*N
Ans2 = [0]*N

for n in range(N,0,-1):
    Ans[n-1] = Data[n-1]
    k = 2
    while k*n <= N:
        Ans[n-1] -= Ans[k*n-1]
        if Ans[n-1] < 0:
            Ans[n-1] = 1
        k+=1

cnt = 0
for i in range(N):
    if Ans[i] == 1:
        Ans2[cnt] = i+1 
        cnt += 1

print(cnt)
if cnt > 0:
    for i in range(cnt):
        print( Ans2[i], end = ' ')
    print()


Measured memory_bytes: 12468
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using ll = long long int;

int main(void){
    int N,M;cin>>N>>M;
    int sum;
    if(N>0&&M>0){
        sum = N*(N-1)/2+M*(M-1)/2;
    }else if(N==0){
        sum = M*(M-1)/2;
    }else{
        sum = N*(N-1)/2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    int n;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        string temp;
        cin>>temp;
        mp[temp]+=1;
    }
    int m;
    cin>>m;
      rep(i,m){
        string temp;
        cin>>temp;
        mp[temp]-=1;
    }
    int pmax=0;
       for(auto itr = mp.begin(); itr != mp.end(); ++itr) {          // キーを表示
        if(pmax<itr->second )
                      pmax=itr->second ;
    }
    cout<< max(pmax,0)<< endl;
    return 0;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const llint INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n, l; cin >> n >> l;
    vint a(n);
    for (int i = 0; i < n; i++) {
        a[i] = l + i;
    }
    int s = 0;
    for (int i = 0; i < n; i++) {
        s += a[i];
    }
    int ans = INF;
    for (int i = 0; i < n; i++) {
        int t = s - a[i];
        if (abs(t - s) < abs(ans - s)) ans = t;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 147483600
#define EPS 1e-9

// solve Ax=b
vector<double> gaussJordan(const vector<vector<double>> &A, const vector<double> &b){
  int n=A.size();
  vector<vector<double>> B(n, vector<double>(n+1));
  rep(i,n) rep(j,n) B[i][j] = A[i][j];
  rep(i,n) B[i][n] = b[i];

  rep(i,n){
    int pivot=i;
    repl(j,i,n) if(abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    swap(B[i], B[pivot]);

    if(abs(B[i][i]) < EPS) return vector<double>();

    repl(j,i+1,n+1) B[i][j] /= B[i][i];
    rep(j,n) if(i!=j) repl(k,i+1,n+1) B[j][k] -= B[j][i] * B[i][k];
  }
  vector<double> x(n);
  rep(i,n) x[i] = B[i][n];
  return x;
}

int main(){
  int n,s,t;
  while(cin>>n>>s>>t, n){
    s--;t--;
    vector<int> q(n);
    rep(i,n) cin>>q[i];
    vector<vector<int>> a(n,vector<int>(n));
    rep(i,n) rep(j,n) cin>>a[i][j];

    vector<vector<int>> d(n, vector<int>(n,INF));
    rep(i,n) rep(j,n) if(a[i][j]>0) d[i][j]=a[i][j];
    rep(i,n) d[i][i]=0;
    rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    // mat * x = vec
    vector<vector<double>> mat(n,vector<double>(n,0));
    vector<double> vec(n,0);
    rep(i,n){
      if(i==t){
        mat[i][i]=1;
      } else if(q[i]==0){
        int cnt=0;
        rep(j,n) if(a[i][j]>0) cnt++;
        rep(j,n) if(a[i][j]>0){
          mat[i][j] = -1.0/cnt;
          vec[i] += (double)a[i][j]/cnt;
        }
        mat[i][i] = 1;
      } else {
        vector<int> cand;
        int best = INF;
        rep(j,n) if(a[i][j]>0){
          int l = a[i][j] + d[j][t];
          if(l < best){
            best = l;
            cand = vector<int>(1,j);
          } else if(l==best){
            cand.pb(j);
          }
        }
        for(auto j : cand){
          mat[i][j] = -1.0/cand.size();
          vec[i] += (double)a[i][j]/cand.size();
        }
        mat[i][i] = 1;
      }
    }

    vector<double> ret = gaussJordan(mat, vec);
    if(ret.size()==0) cout<<"impossible"<<endl;
    else printf("%.8f\n", ret[s]);
  }

  return 0;
}

Measured memory_bytes: 3336
#include "bits/stdc++.h"

using namespace std;

static const int maxn = 1e5 + 5;

int tnode, tedge;
vector <int> graph[maxn];

int dp[maxn];
bool memoize[maxn];

inline int longestPath(int u)
{
	int &ret = dp[u];
	bool &mem = memoize[u];
	if (mem) return ret;
	mem = 1;
	int maxi = 0;
	for (int v : graph[u])
	{
		int go = 1 + longestPath(v);
		if (go > maxi) maxi = go;
	}
	return ret = maxi;
}

int main()
{
	scanf("%d %d", &tnode, &tedge);
	for (int e = 1; e <= tedge; e++)
	{
		int u, v;
		scanf("%d %d", &u, &v);
		graph[u].emplace_back(v);
	}
	int maxi = 0;
	for (int i = 1; i <= tnode; i++)
	{
		if (longestPath(i) > maxi) maxi = longestPath(i);
	}
	printf("%d", maxi);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

int N = 110000;
bool is_prime[110000];

void set_prime() {
    rep(i, N) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    REP(i, 2, sqrt(N)) {
        if(is_prime[i]) {
            for(int j=0; i*(j+2)<N; j++) {
                is_prime[i*(j+2)] = false;
            }
        }
    }
}

int main() {
    set_prime();
    int n, p;
    while(cin>>n>>p, n+p>0) {
        vint v;
        for(int i=n+1, j=0; j<100; i++) {
            if(is_prime[i]) j++, v.pb(i);
        }
        vint w;
        rep(i, v.size()) REP(j, i, v.size()) {
            w.pb(v[i]+v[j]);
        }
        sort(w.begin(), w.end());
        cout << w[p-1] << endl;
    }
}


Measured memory_bytes: 3316
def main():

    N, M, Q = map(int, input().split())
    train = [[0 for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        l, r = map(int, input().split())
        train[l-1][r-1] += 1

    accum = [[0 for _ in range(N+1)]]
    for i in range(N):
        temp = [0]
        v = 0
        for j in range(N):
            v += train[i][j]
            temp.append(accum[-1][j+1]+v)
        accum.append(temp)
        # print(temp)

    for _ in range(Q):
        p, q = map(int, input().split())
        v = accum[q][q] - accum[p-1][q] - accum[q][p-1] + accum[p-1][p-1]
        print(v)

if __name__ == '__main__':
    main()

Measured memory_bytes: 60760
N_list = sorted([int(elem) for elem in input().split()])
if N_list[0] != 1:
    print("NO")
elif N_list[1] != 4:
    print("NO")
elif N_list[2] != 7:
    print("NO")
elif N_list[3] != 9:
    print("NO")
else:
    print("YES")


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

int main() {
  int N, S = 0;
  cin >> N;

  for (int i =0; i < N; i++) {
    int start, end;
    cin >> start >> end;
    S += end - start + 1;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

N, M, Q = map(int, input().split())
A = []
for i in range(Q):
    A.append(list(map(int, input().split())))

# for i in range(Q):
#     print(A[i])

numbers = []
count = 0
def dfs(num_list):
    last = num_list[-1]
    if len(num_list) == N:
        numbers.append(num_list)
    else:
        for i in range(last, M+1):
            tmp = num_list[:]
            tmp.append(i)
            dfs(tmp)

for i in range(1, M+1):
    dfs([i])

_max = 0
for number in numbers:
    _sum = 0
    for i in range(Q):
        if number[A[i][1] - 1] - number[A[i][0] - 1] == A[i][2]:
            _sum += A[i][3]
    if _max < _sum:
        _max = _sum
print(_max)


Measured memory_bytes: 93900
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;

int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll mn = min(b-1,n);
	cout<<((a*mn)/b) - a*(mn/b)<<endl;
}


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

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

    int n;
    cin >> n;
    cout << n / 2 + (n % 2 == 1) << endl;
}

Measured memory_bytes: 256
package main

import (
        //"bufio"
        "fmt"
        //"os"
        //"strconv"
        //"strings"
)

func main() {
        var k, s int64
        num := 0
        fmt.Scan(&k, &s)
        var x, y, z int64
        for x = 0; x <= k; x++ {
                for y = x; y <= k; y++ {
                        for z = y; z <= k; z++ {
                                if x+y+z == s {
                                        num += getNum(x, y, z)
                                }
                        }
                }
        }

        fmt.Println(num)

}

func getNum(x, y, z int64) int {
        num := 0
        if x == y && y == z {
                num = 1
        } else if (x == y && x != z) || (x == z && x != y) || (y == z && x != y) {
                num = 3
        } else {
                num = 6
        }
        return num
}

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

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

	ll N;
	cin>>N;

	vector<ll>V,temp;

	for(ll i = 0;i<N;i++)
	{
		ll inp;
		cin>>inp;
		V.pb(inp);
		temp.pb(inp);
	}

	ll max = *max_element(V.begin(),V.end());

	sort(temp.begin(),temp.end());

	ll max2 = temp[N-2];

	// cout<<max<<endl;
	// cout<<max2<<endl;

	ll count = 0; 	//count frequency of largest

	for(ll i = 0;i<N;i++)
	{
		if(V[i] == max)
			count++;
	}

	if(count > 1)
	{
		for(ll i = 0;i<N;i++)
			cout<<max<<endl;
	}

	else
	{
		for(ll i = 0;i<N;i++)
		{
			if(V[i] != max)
				cout<<max<<endl;
			else
				cout<<max2<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 5220
import fractions
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A,B = map(int,input().split())
ans = fractions.gcd(A,B)
lists = []
cnt = 0
ansr = prime_factorize(ans)
print(len(set(ansr))+1)


Measured memory_bytes: 5048
#include <iostream>
using namespace std;
static const int N = 100;

int main(){
    int M[N][N];
    int n, u, k, v;

    cin >> n;

    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            M[i][j] = 0;
        }
    }

    for (int i=0; i<n; i++){
        cin >> u >> k;
        u--;
        for (int j=0; j<k; j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            if(j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1196
import java.nio.CharBuffer;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int SX = sc.nextInt();
		int SY = sc.nextInt();
		int TX = sc.nextInt();
		int TY = sc.nextInt();
		int w = Math.abs(TX - SX);
		int h = Math.abs(TY - SY);
		CharBuffer cb = CharBuffer.allocate(8 + w * 4 + h * 4);
		cb.append('D');
		for (int i = 0; i < w; i++) {
			cb.append('R');
		}
		cb.append('R');
		cb.append('U');
		for (int i = 0; i < h; i++) {
			cb.append('U');
		}
		cb.append('L');
		for (int i = 0; i < w; i++) {
			cb.append('L');
		}
		for (int i = 0; i < h; i++) {
			cb.append('D');
		}
		cb.append('L');
		for (int i = 0; i < h; i++) {
			cb.append('U');
		}
		cb.append('U');
		cb.append('R');
		for (int i = 0; i < w; i++) {
			cb.append('R');
		}
		cb.append('D');
		for (int i = 0; i < h; i++) {
			cb.append('D');
		}
		for (int i = 0; i < w; i++) {
			cb.append('L');
		}
		cb.flip();
		System.out.println(cb.toString());
	}

}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 22996
from sys import exit

N = int(input())
S = input()


def get_count():
    count = 1

    m = {}

    for s in S:
        if s in m.keys():
            m[s] += 1
        else:
            m[s] = 1

    for k in m:
        count *= m[k] + 1

    count -= 1

    return count


ans = get_count() % (10 ** 9 + 7)

print(ans)


Measured memory_bytes: 3188
from collections import defaultdict

n = int(input()) 
counter = defaultdict(int)

for s in map(str, range(1, n+1)):
    head = s[0]
    tail = s[-1]
    counter[(head, tail)] += 1
    
ans = 0
items = list(counter.items())
for (head, tail), cnt in items:
    ans += cnt*counter[(tail, head)]
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  ll ans=0;
  vector<pair<ll,char>> vec;
  pair<ll,char> tmp{1,s[0]};
  for (int i = 1; i < s.size(); ++i)
  {
    if(s[i]==tmp.second) tmp.first++;
    else {
      vec.push_back(tmp);
      tmp={1,s[i]};
    }
  }
  vec.push_back(tmp);
  if (vec[0].second=='>') {
    ans += (vec[0].first+1)*vec[0].first/2;
    vec.erase(vec.begin());
  }
  if (vec.back().second=='<') {
    ll e=vec.back().first;
    ans += e*(e+1)/2;
    vec.pop_back();
  }

  for (int i = 0; i < vec.size(); i+=2)
  {
    ll x=vec[i].first,y=vec[i+1].first;
    ll z=max(x,y), w=min(x,y);
    ans+=z*(z+1)/2+w*(w-1)/2;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 8188
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;
int main()
{
    int N;
    vector<int> Hs;
    
    cin >> N;
    Hs.resize(N);
    for(int i = 0; i < N; ++i){
        cin >> Hs[i];
    }
    
    string ans = "Yes";
    Hs[0]--;
    for(int i = 1; i < N; ++i){
        if(Hs[i-1] > Hs[i]){
            ans = "No";
            break;
        }
        if(Hs[i-1] < Hs[i]){
            Hs[i]--;
        }
    }
    
    
    cout << ans << endl;
}


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

//整数を選択

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool can = false;

  for(int i = 1; i <= A * B; ++i){
    if (A * i % B == C){
      cout << "YES" << endl;
      can = true;
      break;
    } 
  }
  if (can == false){
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 3616
// Volume0 - 0071: Bombs Chain
#include <iostream>
#include <deque>
#include <string>
using namespace std;
 
class Solver {
private:
    static const int SIZE = 8;
    deque< deque<bool> > dd;
    void explode(int x, int y);
public:
    Solver() { dd.assign(SIZE, deque<bool>(SIZE,false)); }
    void input();
    void output();
};
void Solver::input() {
    string str;
    for(unsigned int i=0; i<dd.size(); ++i) {
        cin >> str;
        for(unsigned int j=0; j<str.size(); ++j) {
            dd[i][j] = (str[j] == '1');
        }
    }
    int x, y;
    cin >> x >> y;
    explode(x-1, y-1);
}
void Solver::explode(int x, int y) {
    if(0 <= x && x < SIZE && 0 <= y && y < SIZE && dd[y][x]) {
        dd[y][x] = false;
        for(int i=1; i<=3; ++i) {
            explode(x-i, y);
            explode(x+i, y);
            explode(x, y-i);
            explode(x, y+i);
        }
    }
}
void Solver::output() {
    for(unsigned int i=0; i<dd.size(); ++i) {
        for(unsigned int j=0; j<dd[i].size(); ++j) {
            cout << (dd[i][j] ? 1 : 0);
        }
        cout << endl;
    }
}
 
int main(int argc, char** argv) {
    int n;
    if(!(cin >> n)) return 0;
    Solver solver;
    for(int i=0; i<n; ++i) {
        solver.input();
        cout << "Data " << i+1 << ":" << endl;
        solver.output();
    }
    return 0;
}

Measured memory_bytes: 3260
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    A, B = map(int, input().split())
    print(lcm(A, B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

    int N; cin >> N;
    vector<int> L(N);
    for(int i=0; i<N; i++)cin >> L[i];
    long res=0;

    sort(L.begin(), L.end(), greater<int>());

    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(L[i]+L[j]>L[k]&&L[k]+L[j]>L[i]&&L[i]+L[k]>L[j]) res++;
                else break;
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
xs = list(map(int, input().split()))
cand = []
for l, r in zip(xs, xs[k-1:]):
  ds = sorted([abs(l), abs(r)])
  if(l * r > 0):
    cand.append(ds[1])
  else:
    cand.append(ds[0] * 2 + ds[1])
print(min(cand))
    

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

typedef pair<int, int> ii;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<int> vi;

#define end '\n'
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<=b;i++)

#define L(x) (x<<1)
#define R(x) ((x<<1)+1)

const int maxN = 200010;
int v[maxN];

int main() {
	//fast input/output c++
	ios_base::sync_with_stdio(0), cin.tie(NULL);

	int k, n;
	cin >> k >> n;

	for(int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	ll ans = 0LL;
	int maior = v[1];
	for(int i = 1; i <= n; i++) {
		ans += v[i]-v[i-1];
		maior = max(maior, v[i]-v[i-1]);
	}

	maior = max(maior, k-v[n]+v[1]);
	ans += k-v[n]+v[0];

	cout << ans - maior << endl;

	return 0;
}


Measured memory_bytes: 1024
def main():
    n, k = map(int, input().split())
    hs = sorted([int(input()) for _ in range(n)])
    ans = float("inf")
    for i in range(n-k+1):
        ans = min(ans, hs[i+k-1]-hs[i])
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int H,W,M;
    cin>>H>>W>>M;
    map<int,int> h,w;
    map<pii,int> c;
    set<int>x,y;
    rep(i,M){
        int a,b;
        cin>>a>>b;
        h[a]++;w[b]++;
        x.insert(a);
        y.insert(b);
        c[MP(a,b)]++;
    }
    int mh=0;
    for(auto a:x){
        mh=max(h[a],mh);
    }
    int mw=0;
    for(auto a:y){
        mw=max(w[a],mw);
    }
    vi X,Y;
    for(auto a:x){
        if(h[a]==mh){
            X.PB(a);
        }
    }
    for(auto a:y){
        if(w[a]==mw){
            Y.PB(a);
        }
    }
    bool r=false;
    int hs=X.size(),ws=Y.size();
    rep(i,hs){
        rep(j,ws){
            if(c[MP(X[i],Y[j])]==0){
                r=true;
                break;
            }
        }
    }
    if(r){
        cout<<mh+mw<<endl;
    }
    else cout<<mh+mw-1<<endl;
}

Measured memory_bytes: 99396
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,M,Pe;
double p;
vector<P> edges;
int num[1<<15];
double dp[1<<15];
double pow(int x)
{
    double res = 1.0;
    double r = p;
    while(x)
    {
        if(x&1)res*=r;
        r=r*r;
        x>>=1;
    }
    return res;
}
double rec(int S)
{
    if(dp[S]!=-1.0)return dp[S];
    if(S==0)return 0.0;
    double ret = 1.0;
    vector<int> v;
    for(int i=0;i<N;i++)if(S&(1<<i))v.pb(i);
    int sz = v.size();
    for(int i=1;i<(1<<sz);i++)
    {
        int T = S;
        for(int j=0;j<sz;j++)if(i&(1<<j))T-=(1<<v[j]);
        if(!(T&1))continue;
        ret -= rec(T)*pow((num[T]+num[S-T]-num[(1<<N)-1-S])/2);
        //if(S==(1<<N)-1)cout << T << endl;
    }
    return dp[S]=ret;
}
int main()
{
    scanf("%d %d %d",&N,&M,&Pe);
    for(int i=0;i<M;i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        u--;v--;
        edges.pb(P(u,v));
    }
    for(int i=0;i<(1<<N);i++)
    {
        for(int j=0;j<M;j++)
        {
            int u = edges[j].fi;
            int v = edges[j].sec;
            if(i&(1<<u) && !(i&(1<<v)))num[i]++;
            if(i&(1<<v) && !(i&(1<<u)))num[i]++;
        }
    }
    p = Pe/100.0;
    for(int i=0;i<(1<<N);i++)dp[i]=-1.0;
    //for(int i=1;i<(1<<N);i++)printf("%.12f\n",rec(i));
    printf("%.12f\n",rec((1<<N)-1));
    return 0;
}

Measured memory_bytes: 1444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N;
    string S;
    cin >> N >> S;
    set<int> d1, d2, d3;
    for(int i = 0; i < N; ++i) {
        int num = S[i] - '0';
        for(auto i : d2)
            d3.insert(num * 100 + i);
        for(auto i : d1)
            d2.insert(num * 10 + i);
        d1.insert(num);
    }
    cout << d3.size() << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    long long a = 2;
    long long b = 1;
    for (size_t i = 1; i < n; i++)
    {
        long long c = a + b;
        a = b;
        b = c;
    }
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    val (n, m, q) = readLine()!!.split(' ').map { it.toInt() }
    val t = Array(n + 1) { IntArray(n + 1) }
    repeat(m) {
        val (l, r) = readLine()!!.split(' ').map { it.toInt() }
        t[l][r]++
    }

    for (i in 1..n) {
        for (j in 1..n) {
            t[i][j] += t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1]
        }
    }

    val pw = PrintWriter(System.out)
    repeat(q) {
        val (l, r) = readLine()!!.split(' ').map { it.toInt() }
        pw.println(t[r][r] - t[l - 1][r] - t[r][l - 1] + t[l - 1][l - 1])
    }
    pw.flush()
}


Measured memory_bytes: 78620
s = input()
length = len(s)
ans = 0
bef = ''
i = 0

while i < length:
    if s[i] == bef:
        try:
            bef = s[i] + s[i+1]
        except IndexError:
            ans -= 1
        i += 1
    else:
        bef = s[i]
    i += 1
    ans += 1
print(ans)

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

#define   ll    long long int

int main( )
{
    ll a, b, k, d, e, f;
    cin >> a >> b >> k;
    d = min(a, k);
    a -= d;
    k -= d;
    d = min(b, k);
    b -= d;
    k -= d;
    cout << a << ' ' << b << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main() {
    int N,K;

    cin >> N >> K;
    vector<int> A(N,0);

    for(int i = 0; i < K; i++){
        int d;
        cin >> d;

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

            A[a-1] = 1;
        }
    }

    int sum = 0;

    for(int i = 0; i < N; i++){
        if(A[i] == 0){
            sum++;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n;
int i,j;


int x;
int count=0;
int cnt[10];
int tmp=0;
char *comi = "insert";
char *comp = "print";


struct Node{
  int k;

  
  struct Node *r;
  struct Node *l;
  struct Node *p;
};

struct Node *root;
struct Node *NIL;






void insert(int key){

  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node*)malloc(sizeof(struct Node));

  z->k=key;
  z->l=NIL;
  z->r=NIL;

  while(x!=NIL){
    y = x;
    if(z->k<x->k)x=x->l;
    else x = x->r;
  }
  z->p=y;
  if(y==NIL)root=z;
  else{
    if(z->k<y->k)y->l=z;
    else y->r=z;
  }
}



void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d", u->k);
  preorder(u->l);
  preorder(u->r);
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->l);
  printf(" %d", u->k);
 
  inorder(u->r);
}



struct Node *find(struct Node *u, int key){
  while (u != NIL && key != u->k){
    if(key < u->k) u = u->l;
    else u = u->r;
  }
  return u;
}


int main(){



  struct Node *t;
  char *com;


  com = (char*)malloc(7*sizeof(char));  

  scanf("%d", &n);



  
  for(i=0; i<n; i++){
    scanf("%s", com);
    if(com[0] == 'f'){
      scanf("%d", &x);
      t = find(root, x);

      
      if(t != NIL){
	printf("yes\n");
      }

      
      else{
	printf("no\n");
      }
    }




    
      else if(strncmp(com,comi,6)==0){
	scanf("%d",&x);
	insert(x);
      }
      else if(strncmp(com,comp,5)==0){

	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      }
    }

    return 0;
  }



Measured memory_bytes: 20496
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using Tu = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    //A,G,C,T
    ll dp[101][4][4][4];

    for(ll i=0;i<4;i++){
        for(ll j=0;j<4;j++){
            for(ll k=0;k<4;k++){
                dp[3][i][j][k]=1;
            }
        ;}
    ;}
    dp[3][0][1][2]=0;
    dp[3][1][0][2]=0;
    dp[3][0][2][1]=0;
    for(ll i=4;i<=N;i++){
        for(ll l=0;l<4;l++){
          for(ll j=0;j<4;j++){
              ll sum=0;
            for(ll k=0;k<4;k++){
                sum+=dp[i-1][k][l][j];
                sum%=MOD;
            }
            for(ll k=0;k<4;k++){
                dp[i][l][j][k]=sum;
            ;}
          ;}
        ;}
        for(ll j=0;j<4;j++){
            dp[i][j][1][2]+=MOD-dp[i-1][0][j][1];
            dp[i][j][1][2]%=MOD;
        ;}
        for(ll j=0;j<4;j++){
            if(j==1)continue;
            dp[i][1][j][2]+=MOD-dp[i-1][0][1][j];
            dp[i][1][j][2]%=MOD;
        ;}
        dp[i][0][1][2]=0;
        dp[i][1][0][2]=0;
        dp[i][0][2][1]=0;

    ;}
    ll ans=0;
    for(ll i=0;i<4;i++){
        for(ll j=0;j<4;j++){
            for(ll k=0;k<4;k++){
                ans+=dp[N][i][j][k];
            }
        ;}
    ;}
    cout<<ans%MOD<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s,t;
    cin >> s >> t;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])ans++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s;
    int A, B;
    cin >> A >> B >> s;

    if (!(1 <= A <= 5) || !(1 <= B <= 5)) {
        cout << "No" << endl;
        return 0;
    }
    
    for (int i = 0; i < A; i++) {
        if (!('0' <= s[i] && s[i] <= '9')){
            cout << "No" << endl;
            return 0;
        }
    }

    if (s[A] != '-') {
         cout << "No" << endl;
         return 0;
    }

    for (int i = 1; i < B; i++) {
        if (!('0' <= s[A + i] && s[A + i] <= '9')) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 256
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


const int MAX = 100 * 1000 + 47;

void no()
{
    cout << "No" << endl;
    exit(0);
}

int A[MAX][3];
int B[MAX], U[MAX];
int X[2], I[2];


int main()
{
    int n;
    scanf("%d", &n);
    FOR(i, 0, 3)
        FOR(j, 0, n)
            scanf("%d", &A[j][i]);
    FOR(i, 0, n)
    {
        if (A[i][1] % 3 != 2)no();
        if (abs(A[i][0] - A[i][1]) != 1 || abs(A[i][1] - A[i][2]) != 1 || A[i][0] == A[i][2])no();
        B[i] = min(A[i][0], A[i][2]) / 3;
        if ((B[i] - i) & 1)no();
        if (A[i][0] > A[i][2])
            X[i & 1] ^= 1;
    }
    FOR(i, 0, n)
        if (!U[i])
        {
            int cur = B[i];
            while(cur != i)
            {
                U[cur] = 1;
                cur = B[cur];
                I[i&1] ^= 1;
            }
        }
    
    if (I[0] != X[1] || I[1] != X[0])no();
    
    cout << "Yes" << endl;

}



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

int main(){
    int d[100],n,num=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(d[j]<d[j-1]){
                swap(d[j],d[j-1]);
                num++;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<(i==0?"":" ")<<d[i];
    }
    cout<<endl<<num<<endl;
    
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}


int main(void){
    int n;
    cin >> n;
    if(n % 10 == 3){
        cout << "bon" << endl;
    }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3632
import math
a,b=map(int,input().split())
A=math.factorial(a)
B=math.factorial(b)
m=10**9+7
if abs(a-b)<=1:
    if a==b:
        print(2*A*B%m)
    else:
        print(A*B%m)
else:
    print(0)

Measured memory_bytes: 5320
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

int main(){
    vector<int> x(3, 0);
    for(int i = 0; i < 3; i++) cin >> x[i];

    sort(x.begin(), x. end());

    if(x[0] == 5 && x[1] == 5 && x[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))

(defparameter param (input-to-list (read-line)))
(defparameter str (read-line))
(format t "~a" (string-downcase str :start (1- (cadr param)) :end (cadr param)))


Measured memory_bytes: 4192
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        int res = 0;
        int padL = 0;
        int padR = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(')
            {
                res--;
            }
            else
            {
                res++;
                if (res > 0)
                {
                    padL += res;
                    res = 0;
                }
            }
        }
        padR = -res;
        Console.Write(string.Join("", Enumerable.Repeat('(', padL).ToArray()));
        Console.Write(s);
        Console.Write(string.Join("", Enumerable.Repeat(')', padR).ToArray()));
        Console.WriteLine();
    }
}

Measured memory_bytes: 13268
# 解説 AC

# 参考1: https://twitter.com/rickytheta/status/1175412019006074880
# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038

mod = 998244353
max_A = 10**6
N = int(input())
A = list(map(int, input().split()))

# nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
def make_prime_checker(n):
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

primes = [p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime]  # max_A 以下の素数のリスト

g = [0] * (max_A+1)
for a in A:
    g[a] += a
for p in primes:
    # 倍数集合の高速ゼータ変換みたいなやつ  O((max_A)loglog(max_A))
    # 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
    # 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう？（みんぷろ 2018 本戦 A - Uncommon など）
    for k in range(max_A//p, 0, -1):
        g[k] += g[k*p]

# この時点で g[d] = Σ_{d|a} a  (A の要素のうち d の倍数であるものの総和)

g = [v * v % mod for v in g]

# この時点で
# g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
#      = Σ_{(d|a)∧(d|b)} ab
#      = Σ_{d | gcd(a,b)} ab

# この式変形天才すぎないか？（これを使った一連の操作を gcd 畳み込み というらしい？）

for p in primes:
    # 倍数集合の高速メビウス変換みたいなやつ  O((max_A)loglog(max_A))

    # for k in range(1, max_A//p+1):
    #     g[k] -= g[k*p]  # 包除原理ヤバい

    for k, g_kp in enumerate(g[p::p], 1):  # 高速化（ゼータ変換の方は途中で g が変化するので高速化できない）
        g[k] -= g_kp  # 包除原理ヤバい

# この時点で g[d] = Σ_{gcd(a,b)=d} ab

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

modinv_list = make_modinv_list(max_A, mod)
ans = sum((gg % mod * minv % mod for gg, minv in zip(g, modinv_list)))
ans %= mod

# この時点で
# ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
#     = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
#     = Σ_a Σ_b lcm(a,b)

ans -= sum(A)
ans *= modinv_list[2]
ans %= mod

# この時点で ans = Σ_{i<j} lcm(a,b)

print(ans)


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

using namespace std;

using ll = long long;

int main(){

    ll n; cin >> n;
    ll arr[n];
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    ll ans = 0;
    for(ll i = 1; i < n; ++i){
        if(arr[i] < arr[i - 1]){
            ans += (arr[i - 1] - arr[i]);
            arr[i] = arr[i - 1];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5200
# cook your dish here
s=list(input())
c = 0
if s[0] == 'A':
    c += 1
if s[2:len(s)-1:].count('C') == 1:
    c += 1

    s.remove('C')
if 'A' in s:
    s.remove('A')
a = 'a'
for i in range(len(s)):
    a += s[i]
if a.islower():
    c += 1
 
if c == 3:
    print('AC')
else:
    print('WA')

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

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

  bool valid = true;

  int x = 0;
  int y = 0;
  int t = 0;

  for (int i = 0; i < N; i++) {
    int T, X, Y;
    cin >> T >> X >> Y;

    for (int j = 0; j < T - t; j++) {
      if (x != X) {
        x > X ? x-- : x++;
      }
      else {
        y > Y ? y--: y++;
      }
    }

    t = T;

    if (x == X && y == Y) continue;
    valid = false;
  }

  cout << (valid ? "Yes" : "No") << endl;
}


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

using namespace std;
#define ll long long int 
#define tezz std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() {
            string s[3] = { "Sunny","Cloudy","Rainy"};
            string p;
            cin>>p;
            
            int i,t,q;
            i=0;
            int l=3;
            while(l--){
            
                if(s[i]==p){
                    t=i;
                    break;
                }
                i++;
                
                
            }
            
            
            q = (t+1)%3;
            
            cout<<s[q];
                
}

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

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    int count = 0, targ = 1;
    vector<bool> NumJdg(N);
    for (int i = 0; i < N; i++) {
        NumJdg.at(i) = false;
    }
    
    for (int i = 0; i < N; i++) {
        if (a.at(i) == targ && NumJdg.at(targ - 1) == false) {
            NumJdg.at(targ - 1) = true;
            targ++;
        }
        else {
            count++;
        }
    }
    if (count == N) {
        count = -1;
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
vector<int> a(1000000, 0);
int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= 100; i++)
    {
        for (int j = 1; j <= 100; j++)
        {
            for (int k = 1; k <= 100; k++)
            {
                int tmp = i*i+j*j+k*k+i*j+j*k+k*i;
                a[tmp]++; 
            }
            
        }
        
    }
    
    for (int i = 1; i <= N; i++)
    {
        cout << a[i] << endl;
    }
    
}

Measured memory_bytes: 7052
def main():
    A, B, C, X, Y = (int(i) for i in input().split())
    ans1 = A * X + B * Y
    ans2 = 0
    ans3 = 0
    if X < Y:
        ans2 += 2 * C * X
        ans2 += B * (Y-X)
        ans3 += 2 * C * Y
    else:
        ans2 += 2 * C * Y
        ans2 += A * (X-Y)
        ans3 += 2 * C * X

    print(min(ans1,ans2,ans3))

if __name__ == '__main__':
    main()

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

long gcd(long a, long b){
    if(a==0) return b;
    return b==0 ? a : gcd(b, a%b);
}

int main(void){
    long n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    long g=gcd(n,m);
    long lcm=n*m/gcd(n,m);
    /*
    string x(lcm, ' ');
    string y(lcm, ' ');
    string z(lcm, ' ');
    */
    for(long i=0; i<lcm; i+=lcm/g){
        //cout << s[i/(m/g)] << " " << t[i/(n/g)] << endl;
        if(s[i/(m/g)] != t[i/(n/g)]){
            cout << "-1" << endl;
            return 0;
        }
    }
    /*
    for(long i=0; i<n; i++){
        x[i*m/g] = s[i];
        y[i*m/g] = 'b';
    }
    for(long i=0; i<m; i++){
        x[i*n/g] = t[i];
        z[i*n/g] = 'c';
    }
    cout << x << endl;
    cout << y << endl;
    cout << z << endl;
    */
    cout << lcm << endl;
    return 0;
}


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

int main(){
	int m,a[7],b[7],g,n;
	while(cin >> m,m){
		for(int i = 0;i < m;i++) cin >> a[i] >> b[i];
		int dp[8][1001] = {};
		dp[0][0] = 1;
		for(int i = 1;i <= m;i++){
			for(int j = 0;j <= 1000;j++){
				for(int k = 0;k <= b[i - 1];k++){
					if(j - k * a[i - 1] < 0) break;
					dp[i][j] += dp[i - 1][j - k * a[i - 1]];
				}
			}
		}
		cin >> g;
		for(int i = 0;i < g;i++){
			cin >> n;
			cout << dp[m][n] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2968
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   bool b = 0;
   ll res = 0;
   TESTS {
      wez(x);
      if (b && (x > 0)) {
         --x;
         ++res;
      }
      res += x/2;
      b = x % 2;
   }
   cout << res;
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n; cin >> n;

  lint n0=n, ans=0;
  map<lint,lint> mp;
  set<lint> st;

  for(lint i=2;i*i<=n;i++) {
    while(n0%i == 0) {
      n0 /= i;
      mp[i]++;
      st.insert(i);
    }
  }

  if(n0 > 1) {
    mp[n0]++;
    st.insert(n0);
  }

  for(set<lint>::iterator itr=st.begin();itr!=st.end();itr++) {
    lint num=0;
    for(num=0;;num++) {
      if(num*(num+1)/2 > mp[*itr]) { break; }
    }
    ans += num-1;
  }

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

Measured memory_bytes: 3600
i=62,y,m,s,f[];main(c){for(;s?++f[y*12+*f+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",f,&y,&s)?s=s*4+1:++i<180?i%12>1?m=fmax(m,y=f[i]),y||++c:1:!printf("%d\n%d\n",c,m););}

Measured memory_bytes: 0