akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        
        if(a >= k){
            System.out.println(a-k + " " + b);
        }else{
            System.out.println(0 + " " + Math.max((b - (k-a)), 0));
        }
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( v.begin(), v.end() );
#define LAST(v) v[sz(v)-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) long long int a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)


int MOD=1000000007;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
//Im ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    IIN(n)
    map<int, int> mp;
    int ans=0 ;

    bool eratos[101];
    for(int i = 0;i<101;i++){
      eratos[i] = true;
    }

    eratos[0]=eratos[1]=false;
    for(int i=2;i*i<=100;i++){
      if(eratos[i]){
        for(int j=0;i*(j+2)<=100;j++){
          eratos[i*(j+2)]=false;
        }
      }
    }


    for(int i = 2 ;i <= n; i++ ){
      int val = i;
      for(int j = 2; j <= n; j++ ){
        if(eratos[j]){
          if( val % j == 0 ){
            while( val % j == 0 ){
              mp[j]++;
              val /= j;
            }
          }
        }
      }
    }
    //75
    if( mp[2] >= 74 ) ans++;

    //25*3
    for( auto itr = mp.begin(); itr != mp.end(); itr++ ){
      if( itr->second >= 24){
        for( auto itr2 = mp.begin(); itr2 != mp.end(); itr2++ ){
          if( itr->first != itr2->first && itr2->second >= 2 ) ans++;

        }
      }
    }

    //15*5
    for( auto itr = mp.begin(); itr != mp.end(); itr++ ){
        if( itr->second >= 14){
          for( auto itr2 = mp.begin(); itr2 != mp.end(); itr2++ ){
            if( itr->first != itr2->first && itr2->second >= 4 ) ans++;
        }
      }
    }

    //5*5*3
    for( auto itr = mp.begin(); itr != mp.end(); itr++ ){
        if( itr->second >= 2){
          int four = 0;
          for( auto itr2 = mp.begin(); itr2 != mp.end(); itr2++ ){
            if( itr->first != itr2->first && itr2->second >= 4 ) four++;
          }
          ans += four * (four-1) / 2;
        }
      }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<string, vector<int>>> v(n);
    for (int i = 0; i < n; i++) {
        string s;
        int a;
        cin >> s >> a;
        v[i] = pair<string, vector<int>>(s, {100 - a, i + 1});
    }

    sort(v.begin(), v.end());
    for (auto x:v) {
        cout << x.second[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
struct Node{
  int key;
  struct Node *right,*left,*parent;
};
   
struct Node *root,*NIL;
   
void insert(int k){
  struct Node *x=root;
  struct Node *y=NIL;
  struct Node *z;
   
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while( x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
   
void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
   
void preorder(struct Node *u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
   
int main(){
  int n,i,x;
  int a=0,b=0;
  char com[10];
   
  scanf("%d",&n);
   
  for(i=0;i<n;i++){
    scanf("%s",com);
       
    a = strcmp(com,"insert");
    if(a==0){
      scanf("%d",&x);
      insert(x);
    }
   
    b = strcmp(com,"print");
    if(b==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
   
  return 0;
}

Measured memory_bytes: 24040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
    }

    void Solve()
    {
        Scanner cin = new Scanner();
        int n = cin.NextInt();

        Console.WriteLine(180 * (n - 2));
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string Next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public char[] ArrayChar()
    {
        return Next().ToCharArray();
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextInt() + add;
        }
        return Array;
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextLong() + add;
        }
        return Array;
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = NextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
n = int(input())

a = []
flag = 0
for i in range(n):
    b = input()
    if i == 0 or b[0] == en:
        if b in a:
            flag = 1
        else:
            a.append(b)
    else:
        flag = 1

    en = b[len(b)-1]

print(['Yes','No'][flag])


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll t[2]; cin >> t[0] >> t[1];
    ll a[2]; cin >> a[0] >> a[1];
    ll b[2]; cin >> b[0] >> b[1];

    ll mid = t[0] * (a[0] - b[0]);
    ll last = t[0] * (a[0] - b[0]) + t[1] * (a[1] - b[1]);

    if (last == 0) { // t1 + t2 秒後の距離が同じなら無限に出会う
        cout << "infinity" << endl;
        return 0;
    }
    if (((mid > 0) ^ (last > 0)) == 0) { // t1 + t2 秒経っても追いつけない
        cout << 0 << endl;
        return 0;
    }

    mid = abs(mid), last = abs(last);

    ll ans = (mid / last) * 2LL + 1;
    if (mid % last == 0) ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[]D = new int[K];
		for(int i = 0; i < K; i++) {
			D[i] = sc.nextInt();
		}
		sc.close();
		int t = N;
		while(true) {
			String n = Integer.toString(t);
			boolean flag = true;
			loop: for(int i = 0; i < n.length(); i++) {
				for(int j = 0; j < K; j++) {
					if((int)n.charAt(i) - '0' == D[j]) {
						flag = false;
						break loop;
					}
				}
			}
			if(flag) {
				break;
			}
			t++;
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 25656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char L = 'L', R = 'R';
		boolean r = false;
		for(int i = 0; i < s.length; i++) {
			if(((i + 1) % 2 == 0 && s[i] == R) 
			|| ((i + 1) % 2 != 0 && s[i] == L))
				r = true;
		}
		sc.close();
		System.out.println(r ? "No" : "Yes");
	}
}


Measured memory_bytes: 23636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();

		List<int> primeList = sieve(N);
		int[] numExponent = new int[N+1];
		for(int i = 2; i <= N; i++)
		{
			int tmp = i;
			foreach (int prime in primeList)
			{
				while(tmp % prime == 0)
				{
					tmp /= prime;
					numExponent[prime]++;
				}
				if(tmp == 1)
					break;
			}
		}

		int geq74 = numExponent.Where(x => (x >= 74)).Count();
		int geq24 = numExponent.Where(x => (x >= 24)).Count();
		int geq14 = numExponent.Where(x => (x >= 14)).Count();
		int geq4 = numExponent.Where(x => (x >= 4)).Count();
		int geq2 = numExponent.Where(x => (x >= 2)).Count();
		int ans = 
			geq74 + 
			geq24 * (geq2 - 1) + 
			geq14 * (geq4 - 1) + 
			(geq4 * (geq4 - 1) * (geq2 - 2))/2;
		Console.WriteLine(ans);
	}

	private static List<int> sieve(int N)
	{
		List<int> primeList = new List<int>();
		bool[] isPrime = new bool[N+1];
		for(int i = 2; i <= N; i++)
			isPrime[i] = true;

		for(int i = 2; i <= N; i++)
		{
			if(isPrime[i])
			{
				primeList.Add(i);
				for(int j = 2 * i; j <= N; j += i)
					isPrime[j] = false;
			}
		}

		return primeList;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 13396
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long countA = a ==0 ? 0 : (a-1)/x+1;
        long countB = b/x+1;
        System.out.println(countB-countA);

    }
}


Measured memory_bytes: 35892
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))
cost = [0] * n
cost[1] = abs(a[1]-a[0])
mi = sys.maxsize
for i in range(1,n):
    for j in range(max(0,i-k),i):
        mi = min(mi,cost[j]+abs(a[i]-a[j]))
        #print(j,mi)
    
    cost[i] = mi
    mi = sys.maxsize
#print(cost)
print(cost[n-1])

Measured memory_bytes: 84824
/*It’s going to be hard,
but hard does not mean impossible.*/

#include <bits/stdc++.h>

// definitions
#define __Imperial_Lord__ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define acc(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
#define p2(a, b) cout << a << " " << b << "\n"
#define p3(a, b, c) cout << a << " " << b << " " << c <<"\n"
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<"\n"
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<"\n"
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF = LONG_LONG_MAX;

template <class ...Args>
istream &read_args(Args &...args) {return (cin >> ... >> args);}
#define read(...)   __VA_ARGS__; read_args(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v)
        is >> i;
    return is;
}
template<typename T>    ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v)
        os << i << ' ';
    return os;
}



// code beigns in main
int main()
{
    __Imperial_Lord__
    ll t = 1;
    // cin >> t;

    while(t--)
    {
        ll read(x);
        if(x>=30) p1("Yes");
        else p1("No");
    }
    exec;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    ll m;
    cin>>m;
    cout<<m*(m-1)/2;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sez(a) a.size()
const int maxn=2e5+1;
const int INF=1e9+7;
ll dp[maxn];
int cnt[maxn];
int nt[26];
int main(){
    #ifdef kolya
        freopen("input.txt","r",stdin);
    #else
     //   freopen("tree.in","r",stdin);
     //    freopen("tree.out","w",stdout);
    #endif // kolya
  //  ios_base::sync_with_stdio(0);u
  //  cin.tie(0);
  //  cout.tie(0);
    string s;
    cin>>s;
    ll ans=1;
    for(int i=0; i<s.size(); ++i){
        ans+=nt[s[i]-'a'];
        for(int c=0; c<26; ++c){
            if (c+'a'!=s[i])
                nt[c]++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 640
open System

let N,K = stdin.ReadLine().Split()|>fun c -> int c.[0],int64 c.[1]
let A = stdin.ReadLine().Split()|>Array.map int64|>Array.sort
let F = stdin.ReadLine().Split()|>Array.map int64|>Array.sort
[<EntryPoint>]
let main argv =
    let t = [|for i in [0..N-1] do yield A.[N-1-i]*F.[i]|]
    let mutable l = -(1L)
    let mutable r=1e13|>int64

    while r-l>1L do
        let c = ((r+l)/2L)
        let mutable sum =0L
        for i in [0..N-1] do
            sum <- (if t.[i]>c then ((t.[i] - c + F.[i] - (1L))/F.[i]) else 0L) + sum 

        match sum<=K with
        |true -> r<-c
        |false -> l<-c

    printfn "%d" r
    0


Measured memory_bytes: 81520
from collections import deque

n, q = map(int, input().split())
t = 0
queue = deque([])
for _ in range(n):
    name, time = input().split()
    time = int(time)
    queue.append([name, time])
while len(queue):
    if queue[0][1] > q:
        queue[0][1] -= q
        t += q
        queue.rotate(-1)
    else:
        t += queue[0][1]
        queue[0][1] = t
        print(" ".join(list(map(str, queue.popleft()))))

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    ll n;
    cin >> n;

    set<ll> div, ndiv;

    ll m = n - 1;
    for(ll i = 2; i * i <= m; i++){
        if(m % i == 0){
            div.insert(i);
            if(m / i != i) div.insert(m/i);
        }
    }

    div.insert(m);
    div.erase(1);

    for(ll i = 2; i * i <= n; i++){
        if(n % i == 0){
            ndiv.insert(i);
            if(n / i != i) ndiv.insert(n/i);
        }
    }

    ndiv.insert(n);
    ndiv.erase(1);

    int ans = div.size();

    for(ll k : ndiv){
        if(k == 1) continue;
        ll nn = n;
        while(nn % k == 0) nn /= k;
        if(nn % k == 1) ans++;
    }

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




Measured memory_bytes: 512
N = int(input())
S = input()

cnt = 0
left = 0
for i in range(N):
	if S[i] == '(':
		cnt += 1
	else:
		if cnt == 0:
			left += 1
		else:
			cnt -= 1

ans = ("("*left) + S + ")"*cnt
print(ans)


Measured memory_bytes: 2940
x=[]
y=[]
n,m=map(int,input().split())

for i in range(n):
    a=list(map(int,input().split()))
    x.append(a)
    
for j in range(m):
    b=int(input())
    y.append(b)

#print(x)
#print(y)


for k in range(n):
    z=0
    for l in range(m):
        z+=y[l]*x[k][l]

    print(z)       


Measured memory_bytes: 6012
import math

def isPrime(A):
    cnt=0
    for i in A:
        if i==2:
            cnt=cnt+1
        k=int(math.sqrt(i))
        for j in range(2,k+2):
           # print(j)
            if i%2==0:
                break
            if i%j==0:
                break
            if j>=k:
                cnt=cnt+1
                break
    return cnt
n=int(input())
A=list()
for i in range(n):
    A.append(int(input()))
print(isPrime(A))


Measured memory_bytes: 6008
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
all_point = [K - Q]*N
x = 0
for a in A:
    all_point[a-1] += 1

for b in all_point:
    if b <= 0:
        all_point[x] = "No"
    else:
        all_point[x] = "Yes"
    x += 1

for c in all_point:
    print(c)

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

/*
 * 最小費用流
 * O(FVE)
 */
struct MinCostFlow{
    const int inf = std::numeric_limits<int>::max()/3;
    struct edge{
        int to,cap,cost,rev;
        edge(){}
        edge(int t,int ca,int co,int r) : to(t),cap(ca),cost(co),rev(r){}
    };

    int V;  // # of node 
    vector<vector<edge>> G;
    MinCostFlow(){}
    MinCostFlow(int V_){ init(V_); }

    void init(int V_){
        V = V_;
        G.resize(V);
    }

    void add_edge(int from,int to,int cap,int cost){
        G[from].emplace_back(to,cap,cost,G[to].size());
        G[to].emplace_back(from,0,-cost,G[from].size()-1);
    }

    // s->tに向かって流量f流すときの最小費用
    // もしs->tに向かってf流せない場合は-1
    int min_cost_flow(int s,int t,int f){
        int res=0;
        vector<int> dist(V,inf);
        vector<int> prevv(V),preve(V);
        while(f>0){
            dist.assign(V,inf);
            dist[s] = 0;
            bool update=true;
            while(update){
                update=false;
                for(int v=0;v<V;v++){
                    if(dist[v]==inf) continue;
                    for(int i=0;i<(int)G[v].size();i++){
                        edge &e = G[v][i];
                        if(e.cap>0 and dist[e.to] > dist[v]+e.cost){
                            dist[e.to] = dist[v] + e.cost;
                            prevv[e.to] = v;
                            preve[e.to] = i;
                            update = true;
                        }
                    }
                }
            }

            if(dist[t] == inf) return -1;   // 流量fを流すことは不可能

            int d = f;
            for(int v=t;v!=s;v=prevv[v]) d = min(d,G[prevv[v]][preve[v]].cap);
            f -= d;
            res += d * dist[t];
            for(int v=t;v!=s;v=prevv[v]){
                edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

int main(){
    int V,E,F; cin >> V >> E >> F;
    MinCostFlow graph(V);
    for(int i=0;i<E;i++){
        int u,v,c,d;
        cin >> u >> v >> c >> d;
        graph.add_edge(u,v,c,d);
    }

    cout << graph.min_cost_flow(0,V-1,F) << endl;
}



Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int a[200000];
int b[200000];

int main()
{
	int n;
	int k;
	int index=0;
	int ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(n%2==0)
		k=n-1;
	else
		k=n-2;
	
	while(k>0)
	{
		b[index]=a[k];
		k-=2;
		index++;
	}
	for(int i=0;i<n;i+=2)
	{
		b[index]=a[i];
		index++;
	}

	if(n%2!=0)
	{
		//cerr<<"rev"<<endl;
		reverse(b,b+n);
	}
	for(int i=0;i<n;i++)
		cout<<b[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;

int main() {
	ll n, k, a[2010], front[2010] = { 0 }, back[2010] = { 0 }, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			if (a[j] < a[i]) {
				if (i > j)front[i]++;
				else back[i]++;
			}
		}
	}
	ll fhoge = (((k - 1) * k )/ 2) % mod;
	ll bhoge = (((k + 1) * k )/ 2) % mod;
	for (int i = 0; i < n; i++) {
		//count
		ll hoge = (front[i] * fhoge) % mod;
		ll piyo = (back[i] * bhoge) % mod;

		ans += (hoge + piyo) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val x = sc.nextInt
    val y = sc.nextInt
    val z = sc.nextInt

    println(go(x, y, z, 0, z))
  }

  def go(x: Int, y: Int, z: Int, count: Int, now: Int): Int = {
    if (now == x) count
    else if (now > x) count - 1
    else go(x, y, z, count+1, now + y + z)
  }
}



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

using namespace std;

const int N = 51;

pair <long long, long long> p[N];

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

	set <pair<long long, long long> > mp;
	for (int i = 0; i < n; ++i) {
		cin >> p[i].first >> p[i].second;
		mp.insert(make_pair(p[i].first, p[i].second));
	} 
	if(n == 1) {
		puts("1");
		return 0;
	}
	int mx = 100;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			long long nxt_x = p[j].first - p[i].first;
			long long nxt_y = p[j].second - p[i].second;
			int tot = 0;
			for (int k = 0; k < n; ++k) {
				tot++;
				if(mp.count(make_pair(p[k].first+nxt_x, p[k].second+nxt_y))) tot--;
			}
			mx = min(mx, tot);
		}
	}
	cout << mx << endl;

}

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

#define ll long long int

typedef pair<ll,ll> pii;

#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vvl vector<vector<ll,ll> >
#define vvs vector<vector<string> >
#define pb push_back
#define mk make_pair
#define sbit(a)  __builtin_popcount(a)
#define f(i,a,n) for(i=a;i<n;i++)
#define fb(i,a,n) for(i=a;i>=n;i--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define nextp(s) next_permutation(s.begin(), s.end()); 
#define ignor cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define bsearch(a,x) binary_search(a.begin(),a.end(),x)
#define ini ll i,j,k,l,m,n,x,y,sm=0,cnt=0
const ll mod=1e9+7;
const double pi=acos(-1);


bool prime[1000000];
void sieve(ll n) 
{ 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*2; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 



ll bs(ll arr[], ll l, ll r, ll x)
{
   if (r >= l)
   {
        ll mid = l + (r - l)/2;
        if (arr[mid] == x)  
            return mid;
        if (arr[mid] > x) 
            return bs(arr, l, mid-1, x);
        return bs(arr, mid+1, r, x);
   }
   return -1;
}




ll moex(ll x,ll n,ll mod)

{
    
	if(n==0)
        
       		return 1;
    
	else if(n%2 == 0)   
        	
		return moex((x*x)%mod,n/2,mod);
    
	else 
              return (x*moex((x*x)%mod,(n-1)/2,mod))%mod;

}


ll modi(ll a, ll m) 
{ 
      	ll k=moex(a, m-2, m); 
	return k;
} 
const ll maximum=99999;
void subString(string s, int n) 
{
    for (int i = 0; i < n; i++) 
        for (int len = 1; len <= n - i; len++)
            cout << s.substr(i, len) << endl;
}


int main(){
    	fast;
       ll n,k;
       cin>>n>>k;
       if(k==1)
       cout<<0;
       else
       cout <<n-k;
    return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  
  int ans = 0;
  for (int i = 0; i < K+1; i++){
    for(int j = 0; j < K+1; j++){
      int k = S - i - j;
      if (i + j + k == S && k >= 0 && k <= K)ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int r, g;
    cin >> r >> g;
    cout << g + (g - r) << endl;
    return 0;
}



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

int main() {
	int a, b;
	cin >> a >> b;
	int w[16] = { 16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
	if (w[a - 1] > w[b - 1])cout << "Alice" << endl;
	else if (w[a - 1] < w[b - 1])cout << "Bob" << endl;
	else cout << "Draw" << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

template <typename T>
void dijkstra(int s,vector<vector<pair<int,T>>>& edges,vector<T>& dist) {
    priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> que;
    dist[s] = 0;
    que.push(make_pair(0,s));
    while (!que.empty()) {
        pair<ll,int> p = que.top();
        que.pop();
        int v =  p.second;
        if (dist[v] < p.first) continue;
        for (pair<int,T>& e : edges[v]) {
            if (dist[e.first] > dist[v]+e.second) {
                dist[e.first] = dist[v]+e.second;
                que.push(make_pair(dist[e.first],e.first));
            }
        }
    }
}

int main() {
    int n,m,s,t = 2510;
    cin >> n >> m >> s;
    s = min(s,2500);
    vector<vector<pair<int,ll>>> edges(n*t);
    vector<ll> dist(n*t,1e18);
    for (int i = 0;i < m;++i) {
        int u,v,a,b;
        scanf("%d%d%d%d",&u,&v,&a,&b);
        u--;v--;
        for (int j = a;j < t;++j) {
            edges[u*t+j].push_back(make_pair(v*t+j-a,b));
            edges[v*t+j].push_back(make_pair(u*t+j-a,b));
        }
    }
    for (int i = 0;i < n;++i) {
        int c,d;cin >> c >> d;
        for (int j = c;j < t;++j) edges[i*t+j-c].push_back(make_pair(i*t+j,d));
    }
    dijkstra<ll>(s,edges,dist);
    vector<ll> ans(n);
    for (int i = 0;i < n;++i) ans[i] = *min_element(dist.begin()+i*t,dist.begin()+(i+1)*t);
    for (int i = 1;i < n;++i) cout << ans[i] << newl;
}

Measured memory_bytes: 23940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vll A(N);
	REP(i, N) {
		cin >> A[i];
	}
	bool isTaro = (N % 2 == 1);
	auto dp = make_v<ll>(N, N);
	REP(cnt, N) {
		REP(l, N) {
			int r = l + cnt;
			if (r >= N)break;
			if (cnt == 0) {
				if (isTaro) {
					dp[l][r] = A[l];
				}
				else {
					dp[l][r] = -A[l];
				}
			}
			else {
				if (isTaro) {
					dp[l][r] = max(dp[l][r - 1]+ A[r], dp[l + 1][r]+ A[l]);
				}
				else {
					dp[l][r] = min(dp[l][r - 1] - A[r], dp[l + 1][r] - A[l]);
				}
			}
		}
		isTaro = !isTaro;
	}
	cout << dp[0][N - 1] << endl;
	return 0;
}


Measured memory_bytes: 70784
n=int(input())
s=[str(input()) for i in range(n)]
#print(s)
ans=0
x=0
y=0
z=0
for i in range(n):
    ans+=s[i].count('AB')
    if s[i][0]=='B' and s[i][-1]=='A':
        x+=1
        y+=1
        z+=1
    elif s[i][-1]=='A':
        x+=1
        z+=1
    elif s[i][0]=='B':
        y+=1
        z+=1
p=(x-1 if x==y==z>0 else min(x,y))
print(ans+p)

Measured memory_bytes: 44632
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 1e18
#define MOD 1000000007
#define PI 4*atan(1.0)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=1005;
//int arr[SIZE]={};
//ここまでテンプレ
typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
 
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
int main(){
	cout<<setprecision(20);
	int sx,sy,gx,gy;
	cin>>sx>>sy>>gx>>gy;
	int N;
	cin>>N;
	int x[SIZE]={},y[SIZE]={},r[SIZE]={};
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i]>>r[i];
	}
	x[N]=sx,y[N]=sy,r[N]=0;
	x[N+1]=gx,y[N+1]=gy,r[N+1]=0;
	Graph G;
	for(int i=0;i<N+2;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<N+2;i++)for(int j=0;j<N+2;j++){
		double cost=max(0.0,sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2))-(double)(r[i]+r[j]));
		G[i].push_back(Edge(i,j,cost));
	}
	vector<Weight> dis;
	vector<int> prev;
 
	shortestPath(G,N,dis,prev);
	cout<<dis[N+1]<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll MOD = 1e9 + 7;
	ll n;
	cin >> n;

	ll all = 1ll, a = 1ll, b = 1ll;
	rep(i, n){
		all *= 10;
		all %= MOD;
		a *= 9;
		a %= MOD;
		b *= 8;
		b %= MOD;
	}

	ll ans = all;
	ans += MOD - a;
	ans %= MOD;
	ans += MOD - a;
	ans %= MOD;
	ans += b;
	ans %= MOD;

	cout << ans << endl;

}


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

int main(){
    int a,b;

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

    return 0;
}


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

int main() {
	std::string str;
	std::cin >> str;
	int w;
	std::cin >> w;
	
	std::string ans("");
	for (int i=0; i<str.size(); i+=w) {
		ans += str[i];
	}
	std::cout << ans << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		long mod = 1000000007;

		int N = Int32.Parse(Console.ReadLine());
		string s = Console.ReadLine();

		long[] num = new long[26];
		for(int i = 0; i < N; i++)
			num[(int)(s[i] - 'a')]++;
		
		long ans = 1;
		for(int i = 0; i < 26; i++)
			ans = (ans * (num[i] + 1)) % mod;
		ans--;

		Console.WriteLine(ans);
	}
}





Measured memory_bytes: 11360
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("sleepy.in","r", stdin);
    freopen("sleepy.out","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 405;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;

int n;
ll sum[N], dp[N][N];

int main()
{
    //TxtRead();
    TheTime();
		
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		ll a;
		scanf("%lld", &a);
		sum[i]=sum[i-1]+a;
	}
	
  	memset(dp, '?', sizeof(dp));
	for(int l=n; l>=1; l--){
		for(int r=l; r<=n; r++){
			if(l==r) dp[l][r]=0;
			if(l+1==r) dp[l][r]=sum[r]-sum[l-1];
			else for(int i=l; i<r; i++){
				dp[l][r]=min(dp[l][r], dp[l][i]+dp[i+1][r]
										  +sum[r]-sum[l-1]);
			}
		}
	}
  
	printf("%lld", dp[1][n]);
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n%2==1) {
    cout << "No" << endl;
    return 0;
  }
  
  string s1=s.substr(0,n/2), s2=s.substr(n/2);
  if(s1==s2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

if b < a:
    print(0)
elif n == 1:
    if a == b:
        print(1)
    else:
        print(0)
else:
    small = a * (n - 2)
    big = b * (n - 2)
    num = big - small + 1
    print(num)

Measured memory_bytes: 3060
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> Option<T> {
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).ok();
    b.trim().parse().ok()
}

/// # Examples
/// ```
/// let mtx = (0..2).map(|_| read_v().unwrap()).collect();
/// ```
#[allow(dead_code)]
fn read_v<T: std::str::FromStr>() -> Option<Vec<T>> {
    read::<String>()
        .unwrap()
        .split_whitespace()
        .map(|e| e.parse().ok())
        .collect()
}

fn main() {
    let xs: Vec<i32> = read_v().unwrap();
    let (x, y, z) = (xs[0], xs[1], xs[2]);

    println!("{} {} {}", z, x, y);
}

#[cfg(test)]
mod tests {
    #[allow(unused_imports)]
    use super::*;

    #[test]
    fn parse() {
        assert_eq!(1, 1);
    }
}


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

const int maxn(3005);
const int mod(1e9 + 7);
const int inv2(500000004);

inline int Add(int x, int y) {
	return x + y >= mod ? x + y - mod : x + y;
}

int f[maxn][maxn], a[maxn], n, q, p = 1;

struct Data {
	int a, b, c;
};

vector <Data> trs;

int main() {
	register int i, j, x, y, ans;
	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (i = 1; i <= n; ++i)
		for (j = 1; j <= n; ++j) f[i][j] = a[i] < a[j];
	while (q) {
		p = p * 2 % mod, --q;
		scanf("%d%d", &x, &y);
		if (x > y) swap(x, y);
		trs.clear();
		for (i = 1; i <= n; ++i) {
			trs.push_back((Data){x, i, (ll)inv2 * Add(f[x][i], f[y][i]) % mod});
			trs.push_back((Data){i, x, (ll)inv2 * Add(f[i][x], f[i][y]) % mod});
			trs.push_back((Data){y, i, (ll)inv2 * Add(f[x][i], f[y][i]) % mod});
			trs.push_back((Data){i, y, (ll)inv2 * Add(f[i][x], f[i][y]) % mod});
		}
		trs.push_back((Data){x, y, (ll)inv2 * Add(f[x][y], f[y][x]) % mod});
		trs.push_back((Data){y, x, (ll)inv2 * Add(f[x][y], f[y][x]) % mod});
		for (auto t : trs) f[t.a][t.b] = t.c;
	}
	for (ans = 0, i = 1; i <= n; ++i)
		for (j = i + 1; j <= n; ++j) ans = Add(ans, f[j][i]);
	ans = (ll)ans * p % mod, printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

int main(){
	string s; cin >> s;
	cout << s;
	if(s[s.size()-1]=='s')
		cout << "es" << endl;
	else
		cout << "s" << endl;
	return 0;
}

Measured memory_bytes: 3624
# ダミーノード'0'を設定 ※※※
# AtCoder Beginner Contest 168
# https://atcoder.jp/contests/abc168/tasks/abc168_d

import sys
input = sys.stdin.readline

n, m =  map(int, input().split()) # nは頂点の数、mは辺の数
pic = [[] for _ in range(n+1)] # 隣接リスト_初期化 ※※※

for _ in range(m): # 隣接リスト_取り込み
    a, b = map(int, input().split())
    pic[a].append(b) # ※※※
    pic[b].append(a) # ※※※
#print(pic)

from collections import deque

def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数_dis → 親ノードを探索して'ans'に記録
    queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ
    dis = [None] * (n+1) # uからの距離を全ノード分初期化 ※※※
    dis[u] = 0 # 開始位置'u'の距離は'0'
    ans = [-1] * (n+1) # 親ノードを記録する
    while queue:
        v = queue.popleft() # 'v'に探索候補のノードを popleft
        for i in pic[v]: # pic[v]: 探索候補のノードに隣接するノードのリスト
            if ans[i] == -1: # 親ノードを記録
                ans[i] = v
            if dis[i] is None:
                dis[i] = dis[v] + 1 # 'u'からの距離を記録
                queue.append(i)
    #print(ans)
    #print(dis)
    return ans

print('Yes')

tmp = BFS(1) # ここは開始位置'1'

for j in tmp[2:]:
    print(j) # ※※※


Measured memory_bytes: 34564
n, ma, mb = map(int,input().split())
INF = 1000000
abmax = 10
nmax = 40
medi = []
sumb = 0
suma = 0
for i in range(n):
    a, b, c = map(int,input().split())
    suma += a
    sumb += b
    medi.append([a,b,c])
dp = [[[INF for k in range(nmax*abmax+1)] for j in range(nmax*abmax+1)] for i in range(nmax+1)]
dp[0][0][0] = 0
for i in range(n):
    a, b, c = medi[i]
    for x in range(suma+1 - a):
        for y in range(sumb+1 - b):
            if dp[i][x][y] == INF:
                continue
            dp[i + 1][x][y] = min(dp[i + 1][x][y], dp[i][x][y])
            dp[i + 1][x + a][y + b] = min(dp[i][x][y] + c, dp[i + 1][x + a][y + b])

t = 1
ok = False
ans = INF
for ca in range(1,nmax*abmax+1):
    for cb in range(1,nmax*abmax+1):
        if ma*cb == mb*ca:
            ans = min(ans, dp[n][ca][cb])
    
print(ans if ans != INF else -1)

Measured memory_bytes: 60016
import sys
input = sys.stdin.readline
from fractions import gcd
def prime_factorize(n):
    res = []
    for i in range(2, int(n**0.5)+1):
        if n % i != 0:continue
        ex = 0
        while n % i == 0:
            ex += 1
            n = n//i
        res.append((i, ex))
    if n != 1:res.append((n, 1))
    return res
def main():
    A, B = map(int, input().split())
    g = gcd(A, B)
    res = prime_factorize(g)
    ans = len(res) + 1
    print(ans)
if __name__ == "__main__":
    main()

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

using namespace std;

int main(){

    int x;
    long long int ans[87];
    cin>>x;
    ans[0]=2;ans[1]=1;
    for(int i=2;i<=x;i++)ans[i]=ans[i-1]+ans[i-2];
    cout<<ans[x]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> data(25);
  
  int mounum = 0;
  int result = 1;
  int flag = 0;

  
    cin >> mounum;
    
  for (int r = 0; r < mounum; r++) {
    cin >> data.at(r);
  }
  
  
  for (int i = 1; i < mounum; i++) {
    for (int k = 0; k < i; k++) {
      if(data.at(k)>data.at(i)){
        flag = 3;
      }
    }
    if(flag==3){
      flag=0;
    }
    else if(flag==0){
      result++;
      flag = 0;
    }
  }
  
    cout << result << endl;
}


Measured memory_bytes: 256
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  while (a >= b)
  {
    if (k == 0)
    {
      Yes(0);
      return;
    }
    k--;
    b *= 2;
  }
  while (b >= c)
  {
    if (k == 0)
    {
      Yes(0);
      return;
    }
    k--;
    c *= 2;
  }
  Yes(1);
}

int main()
{
  init_main();
  solve();
}

Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {
Scanner sc = new Scanner(System.in);
    int go;
    public void solve(){
        int shu=sc.nextInt();
        int kaz=sc.nextInt();
        switch(shu) {
            case 1:
            go=6000*kaz;
            break;
            case 2:
            go=4000*kaz;
            break;
            case 3:
            go=3000*kaz;
            break;
            case 4:
            go=2000*kaz;
            break;
        }
    }
    public void out(){
        System.out.println(go);
    }
    public static void main(String[] args){
        Main obj=new Main();
        for(int a=1;a<=4;a++){
            obj.solve();
            obj.out();
    }
}
}
    

Measured memory_bytes: 17364