akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a,b,c) max(a,max(b,c))
#define mod 1000000007
const ll INF = 1 << 30;
#define mod 1000000007
typedef pair<double, double  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<double,payar  > > vpp;
vector < payar >  vp;
string  num;
ll a, b, d, k;
ll DP[10005][105][2];

ll call(ll pos, ll sum, int flag )
{


    if(pos==num.size())
    {

        ll p = sum%d;
        if(p%d==0)
            return 1;

        else
            return 0;
    }

    if(DP[pos][sum][flag] !=-1 )
    {
        return DP[pos][sum][flag] ;
    }

    ll res = 0 ;

    ll lim;

    if(flag==0)
    {
        lim = num[pos]-48;
    }
    else
    {
        lim = 9;
    }
    for(int dgt = 0 ; dgt <=lim ; dgt++)
    {
        ll nf=flag ;
        ll cn=sum%d;
        if(flag==0 and dgt<lim)
            nf=1;
        cn+=dgt;
        cn=cn%d;


        res= (res%mod+call(pos+1,cn,nf))%mod;

    }
    return DP[pos][sum][flag] = res;

}



ll solve()
{

    memset(DP, -1, sizeof(DP));
    ll res = call(0, 0, 0);
    return res;
}

int main ()
{
    getline(cin, num);
    cin>>d;
    ll res = solve();

    cout << (res-1+mod)%mod << endl;


    return 0;
}


Measured memory_bytes: 17664
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int r,d,x;

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

  cin >> r >> d >> x;
  for(int i = 1;i<=10;i++){
     x = r*x - d;
     cout << x << endl;
  }

return 0;
}
///....


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>A, B;
int n, sum;
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &a);
		sum += abs(a);
		if (a > 0) {
			A.push_back(a);
		}
		else {
			B.push_back(a);
		}
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	if (B.empty()) {
		printf("%d\n", sum - A[0] * 2);
		for (i = 1; i+1 < A.size(); i++) {
			printf("%d %d\n", A[0], A[i]);
			A[0] -= A[i];
		}
		printf("%d %d\n", A.back(), A[0]);
		return 0;
	}
	if(A.empty()) {
		printf("%d\n", sum - abs(B.back()) * 2);
		int sz = B.size();
		for (i = 0; i + 1 < sz; i++) {
			printf("%d %d\n", B[sz - 1], B[i]);
			B[sz - 1] -= B[i];
		}
		return 0;
	}
	printf("%d\n", sum);
	for (i = 1; i < A.size(); i++) {
		printf("%d %d\n", B[0], A[i]);
		B[0] -= A[i];
	}
	printf("%d %d\n", A[0], B[0]);
	A[0] -= B[0];
	for (i = 1; i < B.size(); i++) {
		printf("%d %d\n", A[0], B[i]);
		A[0] -= B[i];
	}
}

Measured memory_bytes: 2424
import sys
from collections import deque
input = sys.stdin.readline

def belman(egdes, N, start, end):
    INF = int(1e10)
    cost = [INF] * N
    cost[start] = 0
    fin = False
    count = 0
    while True:
        no_change = True
        for edge in egdes:
            from_, to_, d = edge
            tmp = cost[from_] + d
            if cost[to_] > tmp:
                no_change = False
                cost[to_] = tmp
        count += 1
        if no_change:
            fin = True
            break
        elif count > N+1:
            break
    
    if fin:
        return max(0, -cost[end])
    else:
        return -1

def bfs(link, N, start):
    q = deque()
    check = [False] * N
    q.append(start)
    check[start] = True
    used = {start}
    while len(q) > 0:
        node = q.popleft()
        for next_ in link[node]:
            if not check[next_]:
                check[next_] = True
                q.append(next_)
                used.add(next_)
    return used
        

def main():
    N, M, P = map(int, input().split())

    link = [[] for i in range(N)]
    rlink = [[] for i in range(N)]
    edges = []

    for i in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        link[a].append(b)
        rlink[b].append(a)
        edges.append((a, b, -(c-P)))
    
    use_nodes = bfs(link, N, 0) & bfs(rlink, N, N-1)
    use_edges = [(a, b, c) for a, b, c in edges if a in use_nodes and b in use_nodes]
    print(belman(use_edges, N, 0, N-1))

if __name__ == "__main__":
    main()

Measured memory_bytes: 5408
var nodeList = Array<Treee?>(100000) { null }

fun main(args: Array<String>) {

    val nodeCount = readLine()!!.toLong()

    for (i in 1..nodeCount) {

        var inputs = readLine()!!.split(" ")
        val left = inputs[1].toInt()
        val right = inputs[2].toInt()
        val id = inputs[0].toInt()

        // 自身を作る
        if (nodeList[id] == null) {
            nodeList[id] = Treee(id, -1)
        }

        // 子供を記録
        if (left != -1) {
            val childLeftNode = nodeList[left] ?: Treee(left)
            childLeftNode.parent = id
            nodeList[left] = childLeftNode

            nodeList[id]!!.left = left
        }

        if (right != -1) {
            val childRightNode = nodeList[right] ?: Treee(right)
            childRightNode.parent = id
            nodeList[right] = childRightNode

            nodeList[id]!!.right = right
        }
    }

    var rootNode = nodeList.filter {
        it?.parent == -1
    }[0]

    setDepth(rootNode!!.id, 0)

    getHeight(rootNode.id)

    nodeList.filterNotNull().forEach { it.print() }
}

fun setDepth(currentIndex: Int, currentDepth: Int) {
    // 左から巡回

    if (nodeList[currentIndex]!!.left != -1) {
        setDepth(nodeList[currentIndex]!!.left, currentDepth + 1)
    }

    // 保存
    nodeList[currentIndex]!!.depth = currentDepth

    if (nodeList[currentIndex]!!.right != -1) {
        setDepth(nodeList[currentIndex]!!.right, currentDepth + 1)
    }
}

fun getHeight(currentIndex: Int): Int {


    // 左から巡回
    val heights = arrayListOf<Int>()

    // 左右なければ高さ0にするので
    heights.add(0)
    if (nodeList[currentIndex]!!.left != -1) {
        heights.add(getHeight(nodeList[currentIndex]!!.left) + 1)
    }

    if (nodeList[currentIndex]!!.right != -1) {
        heights.add(getHeight(nodeList[currentIndex]!!.right) + 1)
    }

    // 保存
    nodeList[currentIndex]!!.height = heights.max()!!
    return heights.max()!!
}

class Treee(
    var id: Int,
    var parent: Int = -1,
    var left: Int = -1,
    var right: Int = -1,
    var depth: Int? = null,
    var height: Int? = null
) {

    fun print() {
        println("node $id: parent = $parent, sibling = ${getSibling()}, degree = ${getDegree()}, depth = $depth, height = $height, ${type()}")
    }

    fun type(): String {
        if (parent == -1) {
            return "root"
        }

        if (left == -1 && right == -1) {
            return "leaf"
        }

        return "internal node"
    }

    fun getSibling(): Int {
        if (parent == -1) {
            return -1
        }
        if (nodeList[parent]!!.right != id) {
            return nodeList[parent]!!.right
        }
        if (nodeList[parent]!!.left != id) {
            return nodeList[parent]!!.left
        }
        return -1
    }

    fun getDegree(): Int {
        var count = 0
        if (right != -1) {
            count++
        }
        if (left != -1) {
            count++
        }

        return count
    }
}


Measured memory_bytes: 32760
s = input()
n = len(s)
front = (n-1) // 2
rear = (n+2) // 2
sf = s[:front]
sr = s[rear:]
srev = s[::-1]
sfrev = sf[::-1]
srrev = sr[::-1]
if sfrev == sf and srrev == sr and srev == s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9128
import sys
from itertools import permutations

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


def main():
    N = int(readline())
    print(N * (N - 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int d,n,a[1010][1010],p[1010],w[1010],vis[1010],ans,h;
bool no=false;
void dfs(int x)
{
	int l,r,k=a[x][p[x]];
	if(vis[x]!=0 || vis[k]!=0)
		return ;
	vis[x]++;
	if(x==a[k][p[k]])
	{
		w[x] = w[k] = max(w[x],w[k])+1;
	//	cout<<x<<" "<<k<<" "<<p[x]<<" "<<p[k]<<endl;
		p[k]++;
		if(p[k]==n)
			ans++;
		else	
			dfs(a[k][p[k]]);
		p[x]++;
		if(p[x]==n)
			ans++;
		else	
			dfs(a[x][p[x]]);		
		h++;	
	}
	return ;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int o=1;o<n;o++)
			cin>>a[i][o];
		p[i]=1;	
	}
	while(ans!=n)
	{
		h=0;
		for(int i=1;i<=n;i++)
			vis[i]=0;
		for(int i=1;i<=n;i++)
			if(vis[i]==0)
				dfs(i);
		if(h==0)
		{
			no=true;
			break;
		}		
	}
//	cout<<ans<<endl;
	if(no==true)
		cout<<-1<<endl;
	else
	{
		for(int i=1;i<=n;i++)
			d=max(d,w[i]);
		cout<<d<<endl;	
	}			
}

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

int N;
int A[110];
int maxA = 0;
int minA = 10000000000;

int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    maxA = max(maxA, A[i]);
    minA = min(minA, A[i]);
  }
  int ans = maxA - minA;
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int b=1, cnt=0;
  
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  
  for(int i=0; i<N; i++){
    b = a.at(b-1);
    cnt++;
    if(b==2) break;
  }
  
  if(b==2) cout << cnt << endl;
  else cout << -1 << endl;
  
}

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

const int N = 55;
const int INF = 19191919;
int n,d;
int p[N][N];

int dp[N][N][N];
int par[N][N][N];
int ok[N][N][N] = {};

int main(){
  cin >>n >>d;
  rep(i,n)rep(j,d) cin >>p[i][j];
  
  rep(i,N)rep(j,N)rep(k,N)
  {
    dp[i][j][k] = INF;
    par[i][j][k] = INF;
  }
  
  rep(i,n) dp[0][0][i] = 0;
  
  rep(i,d)rep(j,N-1)rep(k,n)
  {
    // next stay
    rep(l,n)
    {
      int nj = j+(k!=l);
      if(dp[i+1][nj][l] > dp[i][j][k]+p[l][i])
      {
        dp[i+1][nj][l] = dp[i][j][k]+p[l][i];
        par[i+1][nj][l] = k;
      }
      else if(dp[i+1][nj][l] == dp[i][j][k]+p[l][i])
      {
        par[i+1][nj][l] = min(par[i+1][nj][l], k);
      }
    }
  }
  
  int P = INF;
  int M = INF;
  rep(i,N)rep(j,n) P = min(P,dp[d][i][j]);
  rep(i,N)rep(j,n)if(dp[d][i][j] == P) M = min(M, i);
  rep(i,n)if(dp[d][M][i] == P) ok[d][M][i] = 1;
  
  for(int i=d; i>=1; --i)rep(j,N)rep(k,n)
  {
    if(!ok[i][j][k]) continue;
    
    // stayed before
    rep(l,n)
    {
      int bj = j - (k!=l);
      if(bj<0) continue;
      
      if(dp[i][j][k] - p[k][i-1] == dp[i-1][bj][l]) ok[i-1][bj][l] = 1;
    }
  }
  
  
  vector<int> ans(d,INF);
  rep(i,n)
  {
    if(!ok[0][0][i]) continue;
     
    vector<int> t(d);
    int now = i;
    int ct = 0;
    
    rep(j,d)
    {
      rep(k,n)
      {
        int nct = ct + (now!=k);
        if(ok[j+1][nct][k])
        {
          t[j] = k;
          ct = nct;
          now = k;
          break;
        }
      }
    }
    
    /*
    printf(" GO %d\n", i);    
    rep(j,d) cout << t[j]+1 << endl;
    */
    ans = min(ans,t);
  }

  cout << P << " " << M << endl;
  rep(i,d) cout << ans[i]+1 << endl;
  return 0;
}

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

int main() {
  int A,B,C;
  int goukei;
  int ans;
  cin >> A >> B >> C;
  goukei=B+C;
  if (A >= goukei) {
    cout << "0" << '\n';
  }else{
    ans = abs((B+C)-A);
    cout << ans << '\n';  
  }
}


Measured memory_bytes: 256
import math
n = int(input())

x = n
ans = []
i = 2
while i <= math.sqrt(n):
    if n % i == 0:
        n = n //i
        ans.append(str(i))
    else:
        i += 1
if n != 1:
    ans.append(str(n))
print(str(x) + ":" + " " + " ".join(ans))



Measured memory_bytes: 5664
#include <algorithm>
#include <cstdio>
#include <cstring>
#define w(i, j) (c[j] - c[(i)-1])

typedef long long L;
const int N = 6e2 + 26, P = 1e9 + 7;

struct mod_t {
	static int norm(int x) { return x + (x >> 31 & P); }
	static void norm2(int& x) { x += x >> 31 & P; }
	int x;
	mod_t() {}
	mod_t(int v) : x(v) {}
	mod_t(long long v) : x(v) {}
	mod_t(char v) : x(v) {}
	mod_t operator+(const mod_t& rhs) const { return norm(x + rhs.x - P); }
	mod_t operator-(const mod_t& rhs) const { return norm(x - rhs.x); }
	mod_t operator*(const mod_t& rhs) const { return (L)x * rhs.x % P; }
	void operator+=(const mod_t& rhs) { norm2(x += rhs.x - P); }
	void operator-=(const mod_t& rhs) { norm2(x -= rhs.x); }
	void operator*=(const mod_t& rhs) { x = (L)x * rhs.x % P; }
};

mod_t f[N][N], g[N], ans;
int p[N], c[N];
int n, k;
int h(int l, int r) { return (r - l + 1) - w(l, r); }
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1, x, y; i <= k; i++) {
		scanf("%d%d", &x, &y);
		x[p] = y, y[p] = x, x[c] = y[c] = 1;
	}

	g[0] = g[1] = 1;
	for (int i = 2; i <= 2 * n; i++) g[i] = g[i - 2] * (i - 1);
	for (int i = 1; i <= 2 * n; i++) c[i] += c[i - 1];

	for (int l = 1; l <= 2 * n; l++)
		for (int r = l + 1; r <= 2 * n; r++)
			if ((l ^ r) & 1) {
				for (int x = l; x <= r; x++)
					if (x[p] && (x[p] < l || x[p] > r)) goto end;
				f[l][r] = g[h(l, r)];
				for (int x = l + 1; x < r; x++) f[l][r] -= f[l][x] * g[h(x + 1, r)];
				ans += f[l][r] * g[(n << 1) - (r - l + 1) - ((k << 1) - w(l, r))];
			end:;
			}
	printf("%d", ans.x);
}

Measured memory_bytes: 4676
#include<stdio.h>
void call(int);

int main(){
  int n;

  scanf("%d",&n);

  call(n);
  

  return 0;
}

void call(int n){
  int i=1;
  int x;
  
  for(;i<=n;i++){
    x=i;
    if(x%3==0){
      printf(" %d",i);
      continue;
    }
    while(x){
      if(x%10==3){
	printf(" %d",i);
	break;
      }
      x/=10;
    }
  }
  printf("\n");
}
  

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

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        int c[n];
        for (int i = 0; i < n; i++) {
            cin >> c[i];
        }
        sort(c, c+n);
        long long int time = 0;
        for (int i = 0; i < n; i++) {
            time += c[i] * (n - 1 - i);
        }
        cout << time << endl;
    }
    return 0;
}

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

int main()
{
	lli n, m, ai, bi;
	
	cin >> n >> m;
	
	vector< pair<lli, lli> > v;
	
	lli sum = 0, mn;
	
	for(int i = 0; i < n; i++){
		cin >> ai >> bi;
		
		v.push_back(make_pair(ai, bi));
	}
	
	sort(v.begin(), v.end());
	
	for(int i = 0; i < n; i++){
		if(m == 0) break;
		
		ai = v[i].first; bi = v[i].second;
		
		mn = min(m, bi);
		sum += mn*ai;
		
		m -= mn;
	}
	
	cout << sum << "\n";
	
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
//#include <set>
#include <vector>
//#include <map>
#include <iomanip>
//#include <utility>

#define ii InputInteger()
#define il InputLong()
#define is InputString()
#define f for( int i=0; i<n; i++ )

const int Inf = 2147483647;
const char e = '\n';

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef double d;
typedef vector <int> vi;
typedef vector <string> vs;

int InputInteger()
{
    int n;
    cin >> n;
    return n;
}
ll InputLong()
{
	ll n;
	cin >> n;
	return n;
}
string InputString()
{
	string s;
	cin >> s;
	return s;
}
void Ia( int arr[], int n )
{
    f
    {
        cin >> arr[i];
    }
}
vi Iv( vi& p )
{
	for( int& x: p )
    {
		cin >> x;
	}
	return p;
}
void Pv( vi p )
{
	for( int x: p )
    {
		cout << x << e;
	}
}
void Pa( int arr[], int n )
{
    f
    {
        cout << arr[i] << e;
    }
}
void Sa( int p[], int n )
{
	sort( p, p + n );
}
void Sa( vi& p )
{
	sort( p.begin(), p.end() );
}
bool comdes( int a, int b )
{
	return a > b;
}
void Sd( int p[], int n )
{
	sort( p, p + n, comdes );
}
void Sd( vi& p )
{
	sort( p.begin(), p.end(), comdes );
}
void Ca( int arr[], int n )
{
    f
    {
        arr[ i ] = 0;
    }
}
int main()
{
    ios_base::sync_with_stdio( false );
    // cin.tie( NULL );
    //int t;
    //t = ii;
   // while( t-- )
    {
        double PI = acos(-1.0);
        double a = ii, b = ii, h = ii, m = ii;
        h = (h*60) + m;
        h = h/2;
        double angle = abs((h) - (m * 6));
        angle = (PI * angle)/180;
        double cosa = cos(angle);
        double len = (a * a) + (b * b) - (2 * a * b * cosa);
        len = sqrt(len);
        cout << std :: fixed;
        cout << setprecision(20) << len;
        cout << e;
    }
    return 0;
}
///Kafe's Grandmaster template




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

int main() {
int n = 0, a = 0;
cin >> n >> a;
if (n <= a)
  cout << "Yes" << endl;
else if (0 <= n%500 && n%500 <= a)
  cout << "Yes" << endl;
else 
  cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '9')
		{
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
	int F,T;
	bool f=true;
	char c;
	int Q;
	string s;
	cin>>s;
	cin>>Q;
	for(int i=0;i<Q;i++){
		cin>>F;
		if(F==1) f^=1;
		else{
			cin>>T>>c;
			if(T==1&&f||T==2&&!f)
				s.insert(s.begin(),c);
			if(T==1&&!f||T==2&&f)
				s.push_back(c);
		}
	}
	if(!f)reverse(s.begin(),s.end());
	cout<<s<<endl;
}

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

int selectionSort(int A[], int N) {
    int Count = 0;
    
    for (int i = 0; i < N; i++) {
        int minKey = i;
        for (int j = i + 1; j < N; j++) {
            if (A[minKey] > A[j]) {
                minKey = j;
            }
        }
        if (minKey != i) {
            swap(A[i], A[minKey]);
            Count++;
        }
    }
    
    return Count;
}

int main(void) {
    int N, Count;
    cin >> N;
    int* A = new int[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    Count = selectionSort(A, N);
    
    for (int i = 0; i < N; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    
    cout << endl;
    cout << Count << endl;
}


Measured memory_bytes: 3092
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
int main()
{
  scanf("%lld",&n);
  ll ans=1000000000000,m=trunc(sqrt(n));
  for (ll i=1;i<=m;i++)
  if (n%i==0)
  {
  	ans=min(ans,i-1+n/i-1);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    string line;
    while (cin >> line) {
        if (line.size() % 2 != 0) {
            cout << "NA" << endl;
            continue;
        }
        string result;
        while (line.empty() != true) {
            if (line[0] < '1' || '6' < line[0] || line[1] < '1' || '5' < line[1]) {
                result = "NA";
                break;
            }
            char ch[3], add;
            ch[0] = line[0];
            ch[1] = line[1];
            if (ch[0] != '6') {
                add = 'a' + (line[0] - '1') * 5 + (line[1] - '1');
            } else {
                switch (ch[1]) {
                case '1':
                    add = 'z';
                    break;
                case '2':
                    add = '.';
                    break;
                case '3':
                    add = '?';
                    break;
                case '4':
                    add = '!';
                    break;
                case '5':
                    add = ' ';
                    break;
                default:
                    break;
                }
            }
            result += add;
            line.erase(0, 2);
        }
        cout << result << endl;
    }
}

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

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

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    int check_num = 1;
    int break_count = 0;
    for(int i = 0; i < N; i++){
        if(a[i] == check_num){
            check_num++;
        }else{
            break_count++;
        }
    }
    if(break_count == N) cout << -1 << endl;
    else cout << break_count << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int func(int x)
{
	if(x<10)return x;
	else return x%10+func(x/10);
}

int main()
{
	int n,ans=1000000000;
	cin>>n;
	for(int i=1;i<=n/2;i++)
	{
		int a=i,b=n-i;
		ans=min(ans,func(a)+func(b));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    ll N,A,B,C;
    ll ans=0;
    cin>>N;
    int S[N],D[N];
    ans=(((N)*(N-1))/2);
    if(ans<0){
        ans=0;
        
    }

    Out(ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

int a,b,d,r ;

double f ;

scanf("%d %d",&a,&b) ;

d = a/b ;

r = a%b ;

f = (double)a/(double)b ;

printf("%d %d %lf\n",d,r,f) ;

return 0 ;

} 

Measured memory_bytes: 636
import sys

IMPOSSIBLE = 'Impossible'
POSSIBLE = 'Possible'

def solve():
    H, W = map(int, sys.stdin.readline().split())
    lines = list(map(lambda s: s.rstrip(), sys.stdin.readlines()))
    maxs = []
    mins = []
    for line in lines:
        m = -1
        for i, w in enumerate(line):
            if w == '#':
                m = i
        maxs.append(m)
        m = len(line)
        for i, w in reversed(list(enumerate(line))):
            if w == '#':
                m = i
        mins.append(m)

    for i, (min, max) in enumerate(zip(mins, maxs)):
        if '.' in lines[i][min:max+1]:
            return IMPOSSIBLE

    for min, max in zip(mins[1:], maxs):
        if min != max:
            return IMPOSSIBLE

    return POSSIBLE

print(solve())


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        int count = 0;
        for (int i = 0 ; i <= 3000 ; i++) {
            for (int j = 0 ; j <= 3000; j++) {
                int k = n - r * i - g * j;
                if (k >= 0 && k % b == 0) count++;
            }
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 22612
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N,K,Q;cin>>N>>K>>Q;
    vector<int> A(N);
    for(int i=0;i<Q;i++){
        int q;cin>>q;
        q--;
        A[q]++;
    }
    for(int i=0;i<N;i++){
        if(K-(Q-A[i])<=0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a,b;
    cin >> a >> b;
    if(a == b){
        print("=");
    }else if(a > b){
        print(">");
    }else{
        print("<");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int h, w, k;
int dp[114][19];
signed main() {
	cin >> h >> w >> k;
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, w) {
			dp[i][j] %= mod;
			rep(k, 1 << (w - 1)) {
				rep(l, w - 2) {
					if ((k >> l) & 1 && (k >> (l + 1) & 1))goto ng;
				}
				if (j && (k >> (j - 1)) & 1)dp[i + 1][j - 1] += dp[i][j];
				else if ((k >> j) & 1)dp[i + 1][j + 1] += dp[i][j];
				else dp[i + 1][j] += dp[i][j];
			ng:;
			}
		}
	}
	cout << dp[h][k - 1] % mod << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

perm :: [Int] -> [a] -> [a]
perm y x = [ x!!i | i <- y ]
hRoll = [0,2,4,1,3,5]
toTop = [[0,1,2,3,4,5]
        ,[1,5,2,3,0,4]
        ,[2,1,5,0,4,3]
        ,[3,1,0,5,4,2]
        ,[4,0,2,3,5,1]
        ,[5,1,3,2,4,0]]
hRotate :: [a] -> [[a]]
hRotate d = [d, h d, (h.h) d, (h.h.h) d] where h = (perm hRoll)

allRotate :: [a] -> [[a]]
allRotate d = concat[ hRotate x | x <- map(\ x -> perm x d) toTop]

-- TSEWNB
main = do
    l1 <- words <$> getLine
    l2 <- words <$> getLine
    let o = case elemIndex l1 (allRotate l2) of
              Nothing -> "No"
              _ -> "Yes"
    putStrLn $ o

Measured memory_bytes: 3508
n=int(input())
a=list(map(int,input().split()))
b=[]
ans=0
for i in range(n):
    if a[i]//400<8:
        b.append(a[i]//400)
    else:
        ans+=1
x=max(1,len(set(b)))
y=ans+len(set(b))
#if y>=8:
#    y=8
#else:
#    y=y


print(x,y)


Measured memory_bytes: 3316
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
Check_list = ["OK" for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    if H_list[A-1] > H_list[B-1]:
        Check_list[B-1] = "NG"
    elif H_list[A-1] < H_list[B-1]:
        Check_list[A-1] = "NG"
    elif H_list[A-1] == H_list[B-1]:
        Check_list[A-1] = "NG"
        Check_list[B-1] = "NG"
S = 0
for i in range(N):
    if Check_list[i] == "OK":
        S += 1
print(S)

Measured memory_bytes: 20068
#include <iostream>
#include <queue>
#include <vector>
#define INF 1<<30
#define WHITE 0
#define BLACK 1
using namespace std;

int main(int argc, char* argv[]) {
    int n, u, k, v, c;
    cin >> n;

    int color[n];
    int d[n];
    vector <pair<int, int>> Adj[n];
    priority_queue <pair<int, int>> que;
    pair<int, int> top;

    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            Adj[u].push_back(make_pair(v, c));
        }
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    que.push(make_pair(0, 0));

    while (!que.empty()){
        top = que.top();
        que.pop();
        c = (-1)*top.first;
        u = top.second;

        color[u] = BLACK;
        for (int j = 0; j < Adj[u].size(); j++){
            int v = Adj[u][j].first;
            int w = Adj[u][j].second;

            if (color[v]) continue;
            if (d[u] + w < d[v]){
                d[v] = d[u] + w;
                que.push(make_pair((-1)*d[v], v));
            }
        }
    }
    for (int i = 0; i < n; i++)
        cout << i << " " << (d[i] == INF? -1: d[i]) << endl;

    return 0;
}



Measured memory_bytes: 7812
#include <cstdio>
#include <string>

int main(void) {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);

	int sum = 0;
	if (A < B)
		sum = A;
	else
		sum = B;

	if (C < D)
		sum += C;
	else
		sum += D;

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = list(map(int, input().split()))
N = combinations_count(N, 2) if N >= 2 else 0
M = combinations_count(M, 2) if M >= 2 else 0

print(N + M)

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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_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 int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int n,k,c = 0;
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        if(k - x > x){
            c += x * 2;
        }else{
            c += (k - x) * 2;
        }
    }
    cout << c << endl;

}

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

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

int main(){
	int n,ans,x;
	cin>>n>>ans;
	for(int i=1;i<n;i++)	
		scanf("%d",&x),ans=gcd(ans,x);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import string
 
alphabets=list(string.ascii_lowercase)
 
s=input()
 
l=len(s)
 
hm = lambda a,string: sum([x==a for x in string])
 
for x in range(l-1):
  if s[x]==s[x+1]:
    print('{} {}'.format(x+1, x+2))
    sys.exit()
 
 
for n in range(l-3):
  for a in alphabets:
    if hm(a,s[n:n+3])> 1:
      print('{} {}'.format(n+1,n+3))
      sys.exit()
print('-1 -1')

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

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

  string ans = "Three";
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      ans = "Four";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
ans=0
1.upto(N/2) do|i|
  ans+=(N/i*(N/i+1)/2)*i
end
ans+=N*(N+1)/2-(N/2)*(N/2+1)/2
puts ans

Measured memory_bytes: 14376
import itertools

def main():
    N = int(input())
    if N < 100:
        print(0)
        exit()
    ans = 0
    for rep in range(3, len(str(N))+1):
        for comb in itertools.product(["3", "5", "7"], repeat=rep):
            if len(set(comb)) != 3:
                continue
            if int("".join(comb)) <= N:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <queue>

using namespace std;

struct Point
{
	int x, y, i;
};

bool cmpX(Point& p1, Point& p2)
{
    return p1.x < p2.x;
}

bool cmpY(Point& p1, Point& p2)
{
	return p1.y < p2.y;
}

vector<int> visited;
vector<Point> points, points2;
vector< vector< pair<int, int> > > graph;
priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;

int main()
{
    int N;
    cin >> N;
	points.resize(N);
	visited.assign(N, 0);
	graph.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> points[i].x >> points[i].y;
        points[i].i = i;
    }

    points2 = points;
    sort(points2.begin(), points2.end(), cmpX);
    for (int i = 1; i < points2.size(); ++i) {
		int dist = points2[i].x - points2[i-1].x;
		graph[ points2[i].i ].push_back(make_pair(dist, points2[i-1].i));
		graph[ points2[i-1].i ].push_back(make_pair(dist, points2[i].i));
    }

    points2 = points;
    sort(points2.begin(), points2.end(), cmpY);
    for (int i = 1; i < points2.size(); ++i) {
		int dist = points2[i].y - points2[i-1].y;
		graph[ points2[i].i ].push_back(make_pair(dist, points2[i-1].i));
		graph[ points2[i-1].i ].push_back(make_pair(dist, points2[i].i));
    }

    long long ans = 0;
    pq.push(make_pair(0, 0));
    while (!pq.empty()) {
        pair<int, int> edge = pq.top();
//        cout << edge.first << ' ' << edge.second << endl;
        pq.pop();


		int u = edge.second;
		if (visited[u]) continue;
		visited[u] = 1;
        ans += edge.first;


		for (int i = 0; i < graph[u].size(); ++i) {
			pair<int, int> p = graph[u][i];
            pq.push(p);
		}
    }

    cout << ans << endl;
}


Measured memory_bytes: 13172
#include<cstdio>
using namespace std;
int n,m;
char a[55][55],b[55][55];
bool check(int x,int y)
{
	for(int k=x;k<=x+m-1;k++)
	for(int r=y;r<=y+m-1;r++)
	{
		if(a[k][r]!=b[k+1-x][r+1-y])return false;
	}
	return true;
}
int main()
{
	char h[55];
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",h);
		for(int j=1;j<=n;j++)
		a[i][j]=h[j-1];
    }
    for(int i=1;i<=m;i++)
	{
		scanf("%s",h);
		for(int j=1;j<=m;j++)
		b[i][j]=h[j-1];
    }
    for(int i=1;i<=n-m+1;i++)
    {
    	for(int j=1;j<=n-m+1;j++)
    	{
    		if(check(i,j))
    		{
    			printf("Yes");
    			return 0;
    		}
    	}
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	
		public static void main(String[] args) {
			int a[]=new int[26];
			for(int j=0;j<26;j++) {
				a[j]=100;
			}
			int b=scan.nextInt();
			for(int i=0;i<b;i++) {
				String str=scan.next();
				int z[]=new int[26];
				for(int j=0;j<str.length();j++) {
					char ch=str.charAt(j);
					z[ch-'a']++;
				}
				for(int j=0;j<26;j++) {
					a[j]=min(a[j],z[j]);
				}
				
			}
			for(int i=0;i<26;i++) {
				for(int j=0;j<a[i];j++) {
					char ch=(char)((char)'a'+i);
					System.out.print(ch);
				}
			}
			System.out.println();
		}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
int main(){
	ll a,b;
	cin>>a>>b;
	ll t=b/gcd(a,b);
	ll out=1;
	for(ll i=2;i*i<=t;i++){
		if(t%i==0){
			out*=i;
			while(t%i==0)t/=i;
		}
	}
	cout<<out*t<<endl;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <functional>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int f[501][501];
bool visited[501];
int main()
{
    int n, m;
    while(cin >> n >> m && n && m) {
        int a, b;
        memset(f, 0, sizeof(f));
        for(int i = 0; i < m; i++) {
            cin >> a >> b;
            f[a][b] = f[b][a] = 1;
        }
        
        queue<P> que;
        que.push(P(0, 1));
        memset(visited, 0, sizeof(visited));
        visited[1] = true;
        int ans = 0;

        while(!que.empty()) {
            P p = que.front(); que.pop();
            ans++;
            if(p.first == 2)
                continue;
            
            for(int j = 1; j <= n; j++) 
                if(f[p.second][j] == 1 && !visited[j]) {
                    que.push(P(p.first + 1, j));
                    visited[j] = true;
                }
        }
        cout << (ans - 1) << endl;
    }
}

Measured memory_bytes: 0
S = input()
T = input()
a = []
ans = 0
for i in range(len(S)-len(T)+1):
    C = S[i:i+len(T)]
    for j in range(len(T)):
        if C[j] == T[j]:
            ans+=1
    a.append(ans)
    ans=0
print(len(T)-max(a))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 1e6+10;
const ll INF = 1e17;

int N[MAX], D;
ll dp[MAX][2];

ll solve() {
    REP (i, D+2) REP (j, 2) dp[i][j] = INF;
    dp[0][0] = 0;
    REP (d, D+1) REP (k, 2) {
        int n = N[d] + k;
        // 繰り下がりが発生しないなら、bを0にする
        if (n < 10) CHMIN(dp[d+1][0], dp[d][k] + n);
        // 繰り下がりが発生するなら、aを0にする
        if (n > 0) CHMIN(dp[d+1][1], dp[d][k] + 10 - n);
    }
    return min(dp[D+1][0], dp[D+1][1]);
}

int main() {
    string S;
    cin >> S;
    D = S.size();
    REP (i, D) N[i] = S[D - i - 1] - '0';
    cout << solve() << endl;
}

Measured memory_bytes: 20868
#include<bits/stdc++.h>
using namespace std;
/**
vector<int>ar(3);
for(auto&e:ar){
    scanf("%d",&e);
        }
sort(ar.begin(),ar.end())
int sum=accumulate(ar.begin(),ar.end(),0);
**/
//memo kyuridenamida 1237852
int main(){
    double pai=3.141592653589;
    int N,d;
    cin >> N >> d;
    vector< array<int,3> > star;
    for(int i = 0 ; i < N ; i++){
        int x,y,b;
        cin >> x >> y >> b;
        star.push_back(array<int,3>{b,x,y});
    }   
    sort(star.begin(),star.end());
    int l = 0 , r = 0;
    multiset<int> X,Y;
    long long ans = 0;
    while( r != N){
        X.insert(star[r][1]);
        Y.insert(star[r][2]);
        r++;
        while( star[r-1][0] - star[l][0] > d ){
            X.erase(X.find(star[l][1]));
            Y.erase(Y.find(star[l][2]));
            l++;
        }
        ans = max((long long)((*X.rbegin())-(*X.begin())) * ((*Y.rbegin())-(*Y.begin())),ans);
        //cout << (*X.rbegin())-(*X.begin()) << " " << ((*Y.rbegin())-(*Y.begin())) << "|" << star[r-1][0] - star[l][0] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 23752
#include<iostream>
#include<algorithm>
#include<string>
#include<stdlib.h>
#define ll long long

using namespace std;

const ll mod = 1e9+7;
const ll N=5e5+5;

ll fac[N];
ll infac[N];
ll n,m;

ll qp(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        y>>=1;
    }
    return res;
}

void prepare(){
    fac[0]=fac[1]=1;
    infac[0]=infac[1]=1;
    for(ll i=2;i<N;++i)fac[i]=fac[i-1]*i%mod;
    infac[N-1]=qp(fac[N-1],mod-2);
    for(ll i=N-2;i>1;--i)infac[i]=infac[i+1]*(i+1)%mod;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>m;
    prepare();
    ll res=fac[m]*infac[m-n]%mod;
    ll tmp=res;
    ll mk=-1;
    for(ll i=1;i<=n;++i){
        tmp=(tmp+mk*(fac[n]*infac[i]%mod*infac[n-i]%mod)*(fac[m-i]*infac[m-n]%mod))%mod;
        mk=-mk;
    }
    res=res*tmp%mod;
    cout<<(res+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 11452
#include <iostream>

using namespace std;

int a, b, c, x, y, z;

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	cin >> a >> b >> c;
	x = c;
	y = a;
	z = b;
	cout << x << ' ' << y << ' ' << z << '\n';
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

int main(){
  vector<int> vec;
  int n,k,l;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>l;
    vec.push_back(l);
  }
  sort(vec.begin(),vec.end(),greater<int>() );
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=vec[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,num[100],i,j,plus,minus;
    long long int dp[100][21];
    scanf("%d",&n);
    for(i=0; i<n; i++){
        for(j=0; j<21; j++){
            dp[i][j]=0LL;
        }
        scanf("%d",&num[i]);
    }
    dp[0][num[0]]++;
    for(i=1; i<n-1; i++){
        for(j=0; j<21; j++){
            if(dp[i-1][j]!=0){
                plus = j+num[i];
                minus = j-num[i];
                if(plus>-1 && plus<21){
                    dp[i][plus]+=dp[i-1][j];
                }
                if(minus>-1 && minus<21){
                    dp[i][minus]+=dp[i-1][j];
                }
            }
        }
    }
    printf("%lld\n",dp[n-2][num[n-1]]);
    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    if(N >= M) cout << 0 << endl;
    else{
    vector<int> X(M);
    for(int i = 0; i < M; i++) cin >> X[i];
    sort(X.begin(),X.end());
    vector<int> Y(M-1);
    for(int i = 0; i < M-1; i++) Y[i] = abs(X[i+1] - X[i]);
    sort(Y.begin(),Y.end());
    reverse(Y.begin(),Y.end());
    vector<int> Z(N-1);
    for(int i = 0; i < N-1; i++){
        Z[i] = Y[i];
    }
    int S = abs(X[M-1] - X[0]);
    for(int i = 0; i < N-1; i++){
        S -= Z[i];
    }
    cout << S << endl;
    }  
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    cout << A[0];
    FOR(i, N, 1) {
        if (A[i] == A[i - 1])
            continue;
        cout << " " << A[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4000
import sys
input = sys.stdin.readline

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

A,B=map(int,input().split())

#print(gcd(A,B))

x=gcd(A,B)

import math

L=int(math.sqrt(x))

FACT=dict()

for i in range(2,L+2):
    while x%i==0:
        FACT[i]=FACT.get(i,0)+1
        x=x//i

if x!=1:
    FACT[x]=FACT.get(x,0)+1

print(len(FACT)+1)


Measured memory_bytes: 3188