akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    int a[22];
    int b[22];
    int c[22];
    int ans = 0;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    for (int i = 0; i < (n - 1); i++) {
        cin >> c[i];
    }
    
    for (int i = 0; i < n; i++) {
        ans += b[a[i] - 1];
        
        if ((a[i] > 1) && (i > 0) && ((a[i - 1] + 1) == a[i])) {
            ans += c[a[i - 1] - 1];
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

int main()
{
    long long int N;
    long long int K;
    
    cin >> N;
    cin >> K;
    
    vector<long long int> A(N);
    vector<long long int> F(N);
    
    for(long long int i=0; i<N; i++){
        long long int a;
        cin >> a;
        A[i] = a;
    }
    for(long long int i=0; i<N; i++){
        long long int f;
        cin >> f;
        F[i] = f;
    }
    sort(A.begin(), A.begin()+N);
    sort(F.rbegin(), F.rend());
    
    long long int start = -1, end = 1e12+1;
    long long int now;
//    long long int MIN=1000000000;
    
    while (abs(start - end) > 1) {
        now = (start + end)/2;
        long long int S = 0;
        for(long long int i=0; i<N; i++){
            if(A[i]*F[i] > now){
                S += A[i]-now/F[i];
            }
        }
//        cout << "S:" << S << endl;
//        cout << "K:" << K << endl;
//        cout << "start:" << start << endl;
//        cout << "now:" << now << endl;
//        cout << "end:" << end << endl;
//        cout << "***************" << endl;
        if(S > K){
            start = now;
        }
        else{
            end = now;
        }
    }
        
    cout << end << endl;
    return 0;
}


Measured memory_bytes: 3328
from sys import stdin
import math

[N, K] = list(map(int, stdin.readline().rstrip().split()))
l = list(map(int, stdin.readline().rstrip().split()))
l_sorted = sorted(l, reverse=True)

total_length=0
for i in range(K):
    total_length += l_sorted[i]

print(total_length)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    while(1){
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++) cout << "#";
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3104
def main():
    N = int(input())
    A = list(map(int, input().split()))

    cnt_2 = 0
    cnt_4 = 0
    others = 0
    for ai in A:
        if ai % 4 == 0:
            cnt_4 += 1
        elif ai % 2 == 0:
            cnt_2 += 1
        else:
            others += 1

    # print(cnt_2, cnt_4, others)

    ans = ''
    if cnt_4 > 0:
        if cnt_4 * 2 + 1 >= N:
            ans = 'Yes'
        elif cnt_4 * 2 + cnt_2 >= N:
            ans = 'Yes'
        else:
            ans = 'No'
    elif cnt_4 + cnt_2 >= N:
        ans = 'Yes'
    else:
        ans = "No"
        

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
import scala.io.StdIn
object Main extends App {
  var numList = StdIn.readLine.split(" ")
  var a = numList(0).toInt
  var b = numList(1).toInt
  var isEven = (a * b) % 2 == 0

  if (isEven) {
    print("Even")
  } else {
    print("Odd")
  }
}

Measured memory_bytes: 27208
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

int a[100];
int main(void){
	int a1, b1, c1;
	cin >> a1 >> b1 >> c1;
	int a2, b2, c2;
	cin >> a2 >> b2 >> c2;
	int a3, b3, c3;
	cin >> a3 >> b3 >> c3;
	if(
		a1 - a2 == b1 - b2 &&
		a1 - a2 == c1 - c2 &&
		a1 - a3 == b1 - b3 &&
		a1 - a3 == c1 - c3
		){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7


def combination(n: int, r: int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


x, y = map(int, read().split())

if ((x + y) % 3 != 0):
    print("0")
else:
    a = (2*y - x) // 3
    b = (x - a) // 2

    if a < 0 or b < 0:
        print(0)
    else:
        print(combination(a+b, a))


Measured memory_bytes: 3064
class Solver
  def initialize

    loop do
      h, w = gets.chomp.split(' ').map(&:to_i)

      break if h.zero? && w.zero?

      first = ('#.' * w)[0..w-1]
      second = ('.#' * w)[0..w-1]

      h.times do |i|
        puts i.even? ? first : second
      end

      puts 
    end
  end
end

Solver.new

Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m,array[100000+10],ans=0,sum1=0,sum2=0,sum3=0,sum=0,cnt=0,cnt1=0,cnt2=0,cnt3=0,flag=0,flag1,flag2;
    int i,j;
    string s[100],p;
    char ch;
    cin>>m>>n;
    if(m==n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
    //3のつく数字か、n以下の3の倍数
bool has3(int x){
        while(x){
            if(x % 10 == 3)
                return true;
            x /= 10;
        }
        return false;
    }
void call(int n){
    for(int x =1; x<=n; x++){
        if(x%3 == 0 or has3(x)){
            cout<<" "<<x;
        }
    }
    cout<<endl;
}
int main() {
    int n;
    cin>>n;
    call(n);
    return 0;
}

Measured memory_bytes: 3088
/*
AizuOnline A2198
title Moonlight Farm
WA
*/
#include <stdio.h>
#include <stdlib.h>
#define NOOFPLANT 50
int N;
struct Pl_st 
{ char L[21];   //name
  int  P;       //price
  int  A;
  int  B;
  int  C;
  int  D;
  int  E;
  int  F;
  int  S;
  int  M;
} 
plant[NOOFPLANT];
//
extern double shuuritu(struct Pl_st *);
int compare(void * x,void * y)
{
  double dif=(shuuritu((struct Pl_st *)y)-
	   shuuritu((struct Pl_st *)x));
  if(dif!=0.0)
    return((dif > 0.0)-(dif < 0.0));
  else
    return(strcmp(((struct Pl_st *)x)->L,
		  ((struct Pl_st *)y)->L));
}
double shuuritu(struct Pl_st * pp)
{
  double time;
  double income;
  double mergin;

  time=pp->A+pp->B+pp->C+(pp->D+pp->E)*pp->M;
  income=pp->F*pp->S*pp->M;
  mergin =income-pp->P;
  return(mergin/time);
}
main()
{
  int i;
  struct Pl_st *pp;

  while(EOF!=scanf("%d ",&N) && N)
    {
      for(i=0;i<N;i++)
	{
	  pp=&plant[i];
	  scanf("%s ",(char *)&(pp->L));
	  scanf("%d ",&(pp->P));
	  scanf("%d ",&(pp->A));
	  scanf("%d ",&(pp->B));
	  scanf("%d ",&(pp->C));
	  scanf("%d ",&(pp->D));
	  scanf("%d ",&(pp->E));
	  scanf("%d ",&(pp->F));
	  scanf("%d ",&(pp->S));
	  scanf("%d ",&(pp->M));
	}
      qsort(plant,N,sizeof(struct Pl_st),(__compar_fn_t)compare);

      for(i=0;i<N;i++)
	printf("%s\n",plant[i].L);
      printf("#\n");
    }
return(0);
}

Measured memory_bytes: 604
($n,$m)=glob<>;
for(1..$m){
    ($a,$b)=glob<>;
    push(@L,$b) if($a==1);
    push(@L,$a) if($b==$n);
}
for(@L){
        $f=1,last if($c{$_}++);
}
print+$f?"":"IM","POSSIBLE";

Measured memory_bytes: 41216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];

    vector<int> sum(n);
    rep(i, n) sum[i] = 0;

    rep(i, m) {
        sum[a[i]-1]++;
        sum[b[i]-1]++;
    }

    rep(i, n) {
        cout << sum[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
N = int(input())
a = list(map(int,input().split()))
pos_max = max(a)
neg_max = min(a)
res = []
if abs(pos_max) >= abs(neg_max):
    # pos_max を 全要素に足す
    pos = a.index(pos_max) + 1
    for i in range(N):
        a[i] += pos_max
        res.append([pos, i + 1])
    # 全要素が正
    for i in range(N-1):
        a[i+1] += a[i]
        res.append([i + 1, i + 2])
else:
    # neg_max を 全要素に足す
    pos = a.index(neg_max) + 1
    for i in range(N):
        a[i] += neg_max
        res.append([pos, i + 1])
    # 全要素が負
    for i in range(N-2,-1,-1):
        a[i] += a[i+1]
        res.append([i + 2, i + 1])

# print(*a)
print(len(res))
for l in res:
    print(*l)


Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<vector<int>> edges;
vector<int> visited; // 0: not completed, 1: visiting, 2: completed

// Return true if cycle is found
bool solve(vector<int> &acc, const int cur, const int prev, const int N) {
    acc.push_back(cur);

    if (visited[cur] == 1) {
        return true;
    }
    if (visited[cur] == 2) {
        return false;
    }

    visited[cur] = 1;

    for (auto &next : edges[cur]) {
        if (next == prev) continue;
        if (visited[next] == 2) continue;
        if (solve(acc, next, cur, N)) return true;
    }

    visited[cur] = 2;
    int x = acc.back();
    assert(x == cur);
    acc.pop_back();
    return false;
}

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

    edges.resize(N);
    for (int i = 0; i < N; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    visited.resize(N, 0);

    vector<int> acc;
    for (int i = 0; i < N; i++) {
        assert(visited[i] == 0);
        // if (visited[i] == 2) continue;
        if (solve(acc, i, -1, N)) {
            break;
        }
        acc.clear();
    }

    set<int> cycle;
    if (!acc.empty()) {
        int x = acc.back();
        int i;
        bool flag = false;
        for (i = 0; i < (int) acc.size(); i++) {
            if (flag) {
                cycle.insert(acc[i]);
            }
            if (acc[i] == x) {
                flag = true;
            }
        }
    }

    // printf("cycle: ");
    // for (auto v : cycle) {
    //     cout << v << " ";
    // }
    // cout << endl;

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (cycle.find(a) != cycle.end() && cycle.find(b) != cycle.end()) {
            cout << "2" << endl;
        } else {
            cout << "1" << endl;
        }
    }

    return 0;
}



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

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0
#define LIM 1000000007

bool compare(const pair<lli,lli> &a,const pair<lli,lli> &b){
	return a.first < b.first;
}

int main(){

	lli n,m;
	cin>>n>>m;
	vector<pair<lli,lli>> s;
	REP(i,n){
		lli tmpA,tmpB;
		cin>>tmpA>>tmpB;
		s.push_back(make_pair(tmpA,tmpB));
	}
	sort(s.begin(),s.end(),compare);

	lli nowNum = 0;
	lli nowCost= 0;

	REP(i,n){
		if(nowNum +s[i].second >= m){
			lli buy = m - nowNum;
			nowCost += buy*s[i].first;
			break;
		}
		else{
			lli buy = s[i].second;
			nowCost += buy*s[i].first;
			nowNum += buy;
		}
	}
	cout<<nowCost<<endl;

	return 0;
}

Measured memory_bytes: 2420
n = gets.to_i
a = gets.split.map(&:to_i)
cash = 1000
stock = 0
0.upto(n-2){|i|
  if a[i] < a[i+1] && stock == 0
    stock = cash/a[i]
    cash -= stock*a[i]
  end
  if a[i] > a[i+1]
    cash += stock*a[i]
    stock = 0
  end
}
if stock!=0
  cash += stock*a[n-1]
  stock = 0
end
p cash


Measured memory_bytes: 14232
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main(){
    int n, a, b, ans=0;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        int sum=0, now=i;
        while(now){
            sum += now%10;
            now /= 10;
        }
        if( a <= sum && sum <= b)ans += i;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = (l); i <= (r); i++)
#define LOG(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;

int r = 0; 
int main() {
	int n; cin >> n;
	string s; cin >> s;
	if (n % 2) return puts("No"), 0;
	for (int i = 0; i < n / 2; i++) if (s[i] != s[i + n / 2]) return puts("No"), 0;
	puts("Yes");
	return 0;
}


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

using namespace std;
using ll = long long;

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

  int n;
  ll m;
  cin >> n >> m;

  vector<ll> d;
  for (ll i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      d.push_back(i);
      if (i * i != m) {
        d.push_back(m / i);
      }
    }
  }
  sort(d.begin(), d.end(), greater<ll>());

  for (auto dd : d) {
    if (m / dd >= n) {
      cout << dd << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
vector <char> v;
vector<int> num;
string s ;

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

  for (i = 0; i < N;i++){
    int Z;
    cin >> Z;
    num.push_back(Z);
  }
  sort(num.begin(),num.end(),greater<int>());
  i = 0;

  while(i < (int)num.size()){
    if(i%2 == 0){
      ans += num[i];
    }else{
      ans -= num[i];
    }
    i++;
  }
  cout << ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<set>
using namespace std;
set<int> remainders;
int main()
{
    int k;
    scanf("%d",&k);
    int last=0;
    for(int i=1;;i++)
    {
        int cur=(last*10+7)%k;
        if(cur==0)
        {
            printf("%d\n",i);
            return 0;
        }
        if(remainders.count(cur))
        {
            puts("-1");
            return 0;
        }
        remainders.insert(cur);
        last=cur;
    }
    return 0;
}


Measured memory_bytes: 50584
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll n;
  scanf("%lld", &n);

  if (n % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll count = 0;
  for (ll i = 1;; i++) {
    ll plus = n / 2;

    for (ll j = 0; j < i; j++) {
      plus /= 5;
    }
    if (plus <= 0) {
      break;
    }

    count += plus;
  }

  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include "bits/stdc++.h"
 
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a*b*c == 5*5*7){
    printf("YES\n");
  }
  else printf("NO\n");
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
     int i, x, a;
     long int max=-1000000, min=1000000, sum=0;
 
    scanf("%d", &i);
 
    for(x=0;x<i;x++){
        scanf("%d", &a);
     
        if(a > max){ max = a;}
        if(a < min){ min = a;}
         
        sum += a;
    }
 
    printf("%ld %ld %ld\n", min, max, sum);
    return 0;
}  

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}

int main(){
    int A,P;
    cin >> A >> P;
    int ans,count;
    count = A * 3 + P;
    ans = count /2;
    cout << ans << endl;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (((a == 5) && (b == 5) && (c == 7)) || ((a == 5) && (b == 7) && (c == 5)) || ((a == 7) && (b == 5) && (c == 5))) {


		cout << "YES" << endl;

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

	}
}


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

vector<pair<int ,int> > a[51][51];
char s[50][51];
int n ,m ,b[51][51] ,dis[51][51] ,vis[51][51];
queue<pair<int ,int> >q;

int main(){

	scanf("%d %d" ,&n ,&m);
	int black = 0;
	for(int i = 0 ; i < n ; i++){
		scanf(" %s" ,s[i]);
		for(int j = 0 ; j < m ; j++){
			if(s[i][j] == '#'){	black++;	continue;	}
			if(i > 0 && s[i - 1][j] != '#')	a[i][j].push_back(make_pair(i - 1 ,j));
			if(j > 0 && s[i][j - 1] != '#')	a[i][j].push_back(make_pair(i ,j - 1));
			if(i < n - 1 && s[i + 1][j] != '#')	a[i][j].push_back(make_pair(i + 1 ,j));
			if(j < m - 1 && s[i][j + 1] != '#')	a[i][j].push_back(make_pair(i ,j + 1));
		}
	}	
	
	for(int i = 0 ; i < n ; i++)	for(int j = 0 ; j < m ; j++)	dis[i][j] = INT_MAX;
	
	dis[0][0] = 0;
	q.push(make_pair(0 ,0));
	while(!q.empty()){
		pair<int ,int> p = q.front();
		q.pop();
		vis[p.first][p.second] = 2;
		for(int i = 0 ; i < a[p.first][p.second].size() ; i++){
			pair<int ,int> jj = a[p.first][p.second][i];
			dis[jj.first][jj.second] = min(dis[jj.first][jj.second] ,1 + dis[p.first][p.second]);
			if(!vis[jj.first][jj.second]){
				vis[jj.first][jj.second] = 1;
				q.push(jj);
			}
		}
	}
	if(dis[n - 1][m - 1] == INT_MAX)	printf("-1");
	else{
		int t = n*m - 1;
		//printf("%d %d %d" ,t ,black ,dis[n - 1][m - 1]);
		t -= black;
		t -= dis[n - 1][m - 1];
		printf("%d" ,t);
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int m[100][100];

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> c;
    rep(i, n) rep(j, a[i]) c.push_back(i + 1);

    int k = 0;
    rep(i, h)
    {
        bool flag = (i % 2 == 0 ? 0 : 1);
        int j = (flag == 0 ? 0 : w - 1);
        for (int cnt = 0; cnt < w; cnt++)
        {
            m[i][j] = c[k];
            k++;
            flag == 0 ? j++ : j--;
        }
    }

    rep(i, h) rep(j, w) j != w - 1 ? cout << m[i][j] << " " : OP(m[i][j]);

    return 0;
}

Measured memory_bytes: 512
program judge
 implicit none
 integer :: a, b
 
 read(*,*)a, b
 
 if (a==b) then
  write(*,*)"Draw"
 else if (a==1) then
  write(*,*)"Alice"
 else if (b==1) then
  write(*,*)"Bob"
 else if (a>b) then
  write(*,*)"Alice"
 else 
  write(*,*)"Bob"
 end if
 
end program judge

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

import fractions
gcd = fractions.gcd(a, b)

#print(gcd)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if gcd == 1:
  print(1)
else:
  primes = factorization(gcd)
  print(len(primes)+1)


Measured memory_bytes: 5176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
ll dp[10000003];
bool searched[10000003];

bool is_prime[10000001+1];
vector<int> prime;

void sieve(int n){
  for (int i=0; i <= n; i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for (int i = 2; i <= n; i++){
    if (is_prime[i]){
      for (int j=2*i; j <= n; j+=i) is_prime[j] = false;
    }
  }
  rep(i, n+1) {
    if (is_prime[i]) prime.push_back(i);
  }
}

bool calc(ll a, ll key) { // keyは素因数
  if (key*a>N) return true;
  if (searched[key*a]) return false;
  ll _a = a;
  ll cnt=1;
  while(_a%key==0) {
    _a/=key;
    cnt++;
  }
  dp[key*a] = dp[a]*key*(cnt+1)/cnt;
  searched[key*a] = true;
  return false;
}

int main() {
  INCANT;
  cin >> N;
  sieve(N);
  dp[1] = 1ll;
  for (int i=1; i<=N; i++) {    
    for (auto p: prime) {
      if (calc(i, p)) break;
    }
    searched[i] = true;
  }
  ll sum=0ll;
  for (int i=1ll; i<=N; i++) sum+=dp[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 103428
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer, Integer> a = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                int x = sc.nextInt();
                if (!a.containsKey(x)) {
                    a.put(x, 0);
                }
                a.put(x, a.get(x) + 1);
            }
        }
        int ans = 0;
        for (Integer key : a.keySet()) {
            if (a.get(key) == n) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

const ll INF = (ll)1e9;
const int maxN = (int)1e6;

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c -= b;
    if (c <= 0) {
      cout << "Yes";
      break;
    }
    a -= d;
    if (a <= 0) {
      cout << "No";
      break;
    }
  }
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(){
  int a, b, c, t;

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

  if(b < a)
  {
    t = b;
    b = a;
    a = t;
  }

  if(c < b)
  {
    t = c;
    c = b;
    b = t;

    if(a > b)
    {
      printf("%d %d %d\n", b, a, c);
    }else{
      printf("%d %d %d\n", a, b, c);
    }

  }else{
    printf("%d %d %d\n", a, b, c);
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e7 + 5, mod = 1e9 + 7;

ll ans[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    fill(ans, ans + n + 5, 2);
    for(ll i = 2; i  <= n; i++){
        for(ll j = i + i; j <= n; j += i)
            ans[j]++;
    }
    ans[1] = 1;
    // for(int i = 1; i <= n; i++) cout << ans[i] << ' ';
    ll res = 0;
    for(int i = 1; i <= n; i++) res += (ans[i] * i);
    cout << res;




    return 0;
}



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

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

using namespace std;

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

  sort(s.begin(), s.end());
  bool ok = true;
  rep(i, s.size() - 1) {
    if (s[i] == s[i + 1]) {
      ok = false;
    }
  }

  std::cout << (ok ? "yes" : "no") << std::endl;
  return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[][] numbers = new int[3][3];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				numbers[i][j] = sc.nextInt();
			}
		}

		if (
				((numbers[0][0] - numbers[0][1]) == (numbers[1][0] - numbers[1][1])) && ((numbers[0][0] - numbers[0][1]) == (numbers[2][0] - numbers[2][1])) &&
				((numbers[0][1] - numbers[0][2]) == (numbers[1][1] - numbers[1][2])) && ((numbers[0][1] - numbers[0][2]) == (numbers[2][1] - numbers[2][2])) &&
				((numbers[1][0] - numbers[1][1]) == (numbers[1][0] - numbers[1][1]) && (numbers[1][0] - numbers[1][1]) == (numbers[2][0] - numbers[2][1])) &&
				((numbers[1][1] - numbers[1][2]) == (numbers[1][1] - numbers[1][2]) && (numbers[1][1] - numbers[1][2]) == (numbers[2][1] - numbers[2][2]))
			) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
ll a[50];
int n;
int check(ll k){
	int i;
	ll cnt=0;
	FOR(i,0,n){
		if(a[i]+k>=n){
			cnt+=(a[i]+k+1)/(n+1);
		}
	}
	return cnt==k;
}
int main(void)
{
	int i;
	ll sum=0,k;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	FOR(k,MAX(0,sum-(n-1)*n),sum+1){
		if(check(k)){
			printf("%lld\n",k);
			return 0;
		}
	}
	return 0;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int

using namespace std;

int main() {

    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<int> b(M);
    vector<int> city(N, 0);


    for (int i = 0; i < M; ++i) {
        cin >> a[i];
        cin >> b[i];
    }

    for (int i = 0; i < M; ++i) {
        city[a[i] - 1]++;
        city[b[i] - 1]++;
    }

    for (int i = 0; i < N; ++i) {
        cout << city[i] << endl;
    }
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 1};
int dy[] = {1, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

const int K = 80 * 80 * 4 + 5;
int dp[80][80][K], A[80][80], B[80][80];
int main() {
    int H, W; cin >> H >> W;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> A[i][j];
        }
    }
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> B[i][j];
        }
    }

    int O = 80 * 80 * 2 + 2;
    int z = abs(A[0][0] - B[0][0]);
    dp[0][0][O+z] = dp[0][0][O-z] = true;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            for(int k=0; k<K; k++) {
                if(!dp[i][j][k]) continue;
                for(int x=0; x<2; x++) {
                    int ni = i + dx[x], nj = j + dy[x];
                    if(ni >= H or nj >= W) continue;
                    int a = k + A[ni][nj] - B[ni][nj];
                    int b = k - A[ni][nj] + B[ni][nj];
                    dp[ni][nj][a] = true;
                    dp[ni][nj][b] = true;
                }
            }
        }
    }

    int ans = INF;
    for(int i=H-1; i<H; i++) {
        for(int j=W-1; j<W; j++) {
            for(int k=0; k<K; k++) {
                int v = abs(k - O);
                if(dp[i][j][k]) {
                    chmin(ans, v);
                }
            }
        }
    }

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


Measured memory_bytes: 638592
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}
ll dp[100001][3];
int main() {
	string S;
	get(S);
  ll pat=1;
  FORIN(i,1,(int)S.size()+1){
    dp[i][0]=dp[i-1][0];
    dp[i][1]=dp[i-1][1];
    dp[i][2]=dp[i-1][2];
    if(S[i-1]=='A'){
      dp[i][0]+=pat;
    }else if(S[i-1]=='B'){
      dp[i][1]+=dp[i-1][0];
    }else if(S[i-1]=='C'){
      dp[i][2]+=dp[i-1][1];
    }else{
      dp[i][0]+=pat;
      dp[i][1]+=dp[i-1][0];
      dp[i][2]+=dp[i-1][1];
      dp[i][0]+=dp[i-1][0]*2;
      dp[i][1]+=dp[i-1][1]*2;
      dp[i][2]+=dp[i-1][2]*2;
      pat=pat*3%MOD;
    }
    dp[i][0]%=MOD;
    dp[i][1]%=MOD;
    dp[i][2]%=MOD;
  }
  print(dp[S.size()][2]);
  return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;

const int MAX_N = 2 * 1e5 + 2;
const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;

int C[MAX_N];
ll dp[MAX_N];

int main() {
    int N;
    cin >> N;
    C[0] = INF;
    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }
    map<int, ll> cnt;
    dp[0] = 1;
    for (int i = 1; i <= N; i++) {
        dp[i] = (dp[i] + cnt[C[i]]) % MOD;
        if (C[i] != C[i - 1]) {
            dp[i] = (dp[i] + dp[i - 1]) % MOD;
            cnt[C[i]] = (cnt[C[i]] + dp[i - 1]) % MOD;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

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

// グラフを隣接行列で管理する //pathがあるかどうかだけが今回の関心事項だから
bool G[10][10];

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

    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a][b] = G[b][a] = true;
    }

    //順列
    vector<int> ord(N);
    for(int i = 0; i < N; i++) ord[i] = i;

    //順列を全部試す
    int res = 0; //pathの数を記録する
    do{
        if(ord[0] != 0) break; //本問題では頂点1(i = 0)からスタートしなければならないから

        bool ok = true;
        for(int i = 0; i +1 < N; i++){
            int from = ord[i]; //先程のif文チェックを通過しているから, ord[0] = 0;
            int to = ord[i+1]; //次の移動先頂点
            if(!G[from][to]) ok = false; //G[from][to] = falseという場合, from-to上の辺が存在しない（移動不可）
        }
        if(ok) ++res; //ok = trueは, 頂点1からラスの頂点まで到達するpathの存在を意味する

    }while(next_permutation(ord.begin(), ord.end())); //順列を考えることで, すべての点を一回だけ通ることが保証される

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

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

template<long long MOD = 1000000007>
struct Mint {
private:
  long long val;

public:
  constexpr Mint(const long long x = 0) noexcept : val(x < 0 ? x % MOD + MOD : x >= MOD ? x % MOD : x) {}
  constexpr Mint &operator+=(const Mint rhs) noexcept {
    if ((val += rhs.val) >= MOD) val -= MOD;
    return *this;
  }
  constexpr Mint &operator-=(const Mint rhs) noexcept {
    if ((val -= rhs.val) < 0) val += MOD;
    return *this;
  }
  constexpr Mint &operator*=(const Mint rhs) noexcept {
    val = val * rhs.val % MOD;
    return *this;
  }
  constexpr Mint &operator/=(Mint rhs) noexcept {
    val = val * rhs.inv().val % MOD;
    return *this;
  }
  constexpr Mint operator+(const Mint& rhs) const noexcept { return Mint(*this) += rhs; }
  constexpr Mint operator-(const Mint& rhs) const noexcept { return Mint(*this) -= rhs; }
  constexpr Mint operator*(const Mint& rhs) const noexcept { return Mint(*this) *= rhs; }
  constexpr Mint operator/(const Mint& rhs) const noexcept { return Mint(*this) /= rhs; }
  constexpr Mint inv() const noexcept { return pow(MOD-2); }
  constexpr Mint pow(long long n) const noexcept {
    Mint ret(1), mul(val);
    while (n) {
      if (n % 2) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  constexpr bool operator==(const Mint& rhs) const noexcept { return val == rhs.val; }
  constexpr bool operator!=(const Mint& rhs) const noexcept { return val != rhs.val; }
  friend ostream &operator<<(ostream &os, const Mint<MOD> &x) { return os << x.val; }
  friend istream &operator>>(istream &is, Mint<MOD> &x) {
    long long t;
    is >> t;
    x.val = t % MOD;
    return is;
  }
};

int main() {
  int n; cin>>n;
  vector<long long> t(n), a(n);
  for (int i = 0; i < n; i++) cin>>t[i];
  for (int i = 0; i < n; i++) cin>>a[i];

  vector<long long> ma(n, 1e9), mi(n, 1);
  ma[0] = mi[0] = t[0];
  for (int i = 1; i < n; i++) {
    if (t[i] != t[i-1]) {
      ma[i] = mi[i] = t[i];
    } else {
      ma[i] = t[i];
    }
  }
  if (not (mi[n-1] <= a[n-1] and a[n-1] <= ma[n-1])) {
    cout << 0 << endl;
    return 0;
  }
  ma[n-1] = mi[n-1] = a[n-1];
  for (int i = n-2; i >= 0; i--) {
    if (a[i] != a[i+1]) {
      if (not (mi[i] <= a[i] and a[i] <= ma[i])) {
        cout << 0 << endl;
        return 0;
      }
      ma[i] = mi[i] = a[i];
    } else {
      ma[i] = min(ma[i], a[i]);
    }
  }

  Mint<> ans = 1;
  for (int i = 0; i < n; i++) {
    int d = ma[i] - mi[i] + 1;
    if (d <= 0) {
      cout << 0 << endl;
      return 0;
    }
    ans *= d;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main()

{
    int a,b,c,d,e;
    scanf("%d%d%d",&a,&b,&c);

    if(a==b && a==c )
        printf("1");

    else if(a==b && a!=c)
        printf("2");

    else if(a==c && a!=b)
        printf("2");

    else if(b==c && b!=a)
        printf("2");

    else if(a!=b && a!=c)
        printf("3");

    return 0;

}

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

ans = 0

for i in reversed(range(n)):
    if a[i+1] - b[i] >= 0:
        a[i+1] -= b[i]
        ans += b[i]
    else:
        b[i] -= a[i+1]
        ans += a[i+1]
        if a[i] - b[i] >= 0:
            a[i] -= b[i]
            ans += b[i]
        else:
            ans += a[i]
            a[i] = 0
print(ans)
        

Measured memory_bytes: 18476
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(10**9)
#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]


for w in range(1, N + 1):
    for l in range(N - w + 1):
        r = w + l
        dp[l][r] = A[l] - dp[l + 1][r]
        if r > 0:
            dp[l][r] = max(dp[l][r], A[r - 1] - dp[l][r - 1])

print(dp[0][N])



Measured memory_bytes: 135240
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr double BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;

ll N, M, Q;
vector<ll> a;
vector<ll> b;
vector<ll> c;
vector<ll> d;
ll mx = 0;
//
void check(std::vector<ll> A)
{
    ll score = 0;
    rep(i, Q) if (A[b[i] - 1] - A[a[i] - 1] == c[i]) score += d[i];
    chmax(mx, score);
}
void dfs(std::vector<ll> A)
{
    if (A.size() == N)
    {
        check(A);
        return;
    }
    A.push_back(A.back());
    while (A.back() != M)
    {
        dfs(A);
        ++A.back();
    }
    dfs(A);
}
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    cin >> N >> M >> Q;
    a = b = c = d = vector<ll>(Q);
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    //
    dfs({1});
    cout << mx;
    return 0;
}

Measured memory_bytes: 3620
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

while(True):
    a1,m1,a2,m2,a3,m3 = map(int, input().split())
    if a1 == 0: break
    p = 1
    nx = 0
    while(True):
        nx += 1
        p = a1*p%m1
        if not p-1: break
    p = 1
    ny = 0
    while(True):
        ny += 1
        p = a2*p%m2
        if not p-1: break
    p = 1
    nz = 0
    while(True):
        nz += 1
        p = a3*p%m3
        if not p-1: break
    print(lcm(nx,ny,nz))



Measured memory_bytes: 6348
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());

            if ((b - a + 1 <= k) || (b - a + 1 <= k * 2)) {
                for (int i = 0; i < b - a + 1; i++) {
                    out.println(a + i);
                }
                return;
            }

            for (int i = 0; i < k; i++) {
                out.println(a + i);
            }
            for (int i = 0; i < k; i++) {
                out.println(b - k + 1 + i);
            }

        }

    }
}



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

int n,m,x,y;
int mmp[100005];
map<int,int> mp;
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++) mmp[i]=1;
  mp[1]++;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    mmp[x]--;
    mmp[y]++;
    map<int,int>::iterator it=mp.find(x);
    if(it!=mp.end()){
      if(mmp[x]==0) mp.erase(it);
      mp[y]++;
    }
  }
  int ans=0;
  for(map<int,int>::iterator i=mp.begin();i!=mp.end();i++) if(mmp[i->first] != 0){
      // cout<<i->first<<" "<<mmp[i->first]<<endl;
      ans++;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5376
n,q = map(int, input().split())
cs = list(map(int, input().split()))

prevs = [-1] * (n+1)
# 左端
sts = [-1] * n
for i,c in enumerate(cs):
    c -= 1
    if prevs[c] != -1:
        sts[prevs[c]] = i
    prevs[c] = i

qs = [[] for i in range(n)] 
for i in range(q):
    l,r = map(int, input().split())
    l -= 1
    r -= 1
    qs[l].append((r,i))

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n+10)

    def add(self, x, w):
        while x <= self.n:
            self.bit[x] += w
            x += x&-x

    def sum(self, x):
        cnt = 0
        while x > 0:
            cnt += self.bit[x]
            x -= x&-x
        return cnt

bit = BIT(n)
ans = [0] * q
for l in range(n-1,-1,-1):
    # 矢印を追加
    if sts[l] != -1:
        bit.add(sts[l], 1)
    for r,i in qs[l]:
        cnt = bit.sum(r)
        ans[i] = r - l + 1 - cnt

print(*ans, sep="\n")

Measured memory_bytes: 210660
n, m, q = gets.split.map(&:to_i)

a = Array.new(n+2) {Array.new(n+2, 0)}
m.times do
    l, r = gets.split.map(&:to_i)
    a[l][r] += 1
end

n.downto(1) do |i|
    i.upto(n) do |j|
        a[i][j+1] += a[i][j]
        a[i][j] += a[i+1][j]
    end
end

q.times {p a.dig(*gets.split.map(&:to_i))}

Measured memory_bytes: 4988
import sys,bisect
input=sys.stdin.readline
n=int(input())

a=[int(input()) for _ in range(n)]
a.reverse()

dp=[float("inf")]*(n+1)
for b in a:
    idx=bisect.bisect_right(dp,b)
    dp[idx]=b

ans=bisect.bisect_left(dp,float("inf"))

print(ans)


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


int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h)
    cin >> s[i];
  vector<vector<int>> c(h, vector<int>(w, -1));
  rep(i, h)
    rep(j, w)
    {
      if (s[i][j] == '#')
        continue;
      int last = j + 1;
      while (last < w && s[i][last] == '.')
        last++;
      for (int k=j; k<last; k++)
        c[i][k] += last - j;
      j = last - 1;
    }
  rep(j, w)
    rep(i, h)
    {
      if (s[i][j] == '#')
        continue;
      int last = i + 1;
      while (last < h && s[last][j] == '.')
        last++;
      for (int k=i; k<last; k++)
        c[k][j] += last - i;
      i = last - 1;
    }
  int ans = 0;
  rep(i, h)
    rep(j, w)
      ans = max(ans, c[i][j]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 22144
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>
#include <fstream>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REM(i,a,n) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 1e-11
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
const double PI = 3.1415926535897932;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator >> (istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
//sum, 累積和
// 負のときの割り算に注意
#if 1
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Suffix_Array.h"
#include "Matrix.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator >> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

LL N, A, B, C, D;

int main() {
	cin >> N >> A >> B >> C >> D;
	LL diff = abs(A - B);
	
	bool ok = 0;
	REP(i, 0, N) {
		LL j = N - 1 - i;
		LL l1 = C * i, r1 = D * i;
		LL l2 = C * j + diff, r2 = D * j + diff;
		if (r2 >= l1 && l2 <= r1) ok = true;
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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[] ballInfo = new int[n];
		for(int i = 0;i < n;i++) {
			ballInfo[i] = sc.nextInt();
		}
		Arrays.sort(ballInfo);
		int ballTypeCount = 0;
		int ballCount = 0;
		List<Integer> ballTypeCountInfo = new ArrayList<Integer>();
		for(int i =0;i <n;i++) {
			if(i ==0) {
				ballCount++;
				continue;
			}
			if(ballInfo[i] == ballInfo[i-1]) {
				ballCount++;
			}else {
				ballTypeCountInfo.add(ballCount);
				ballCount =1;
				ballTypeCount++;
			}
			if(i == n -1) {
				ballTypeCountInfo.add(ballCount);
				ballTypeCount++;
			}
		}
		Collections.sort(ballTypeCountInfo);
		int answer = 0;
		int i = 0;
		while(ballTypeCount > k) {
			answer += ballTypeCountInfo.get(i);
			ballTypeCount--;
			i++;
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 70924