akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9+7;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,d;
    cin >> n >> d;
    int cnt = 0;
    rep(i,n)
    {
        double a,b;
        cin >> a >> b;
        double tmpn = sqrt(a * a + b * b);
        if (tmpn<=d) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3800
i = 3
j = 3
arr = []
chosen_nums = []
i.times {
  arr.push(gets.chop.split.map(&:to_s))
}
n = gets.chop.to_i
n.times {
  chosen_nums.push(gets.chop.to_s)
}

result = []
for j in 0..2
  a = []
  for i in 0..2
    a.push(chosen_nums.include?(arr[j][i]))
    if a.size == 3
      result.push(a)
    end
  end
end
def judge(result)
  #横
  for i in 0..3-1
    return 'Yes' if result[i].count(true) == 3
  end
  #縦
  for j in 0..3-1
    return 'Yes' if [result[0][j], result[1][j], result[2][j]].count(true) == 3
  end
  #斜め
  return 'Yes' if [result[0][0], result[1][1], result[2][2]].count(true) == 3
  return 'Yes' if [result[0][2], result[1][1], result[2][0]].count(true) == 3
  return 'No'
end

print judge(result)

Measured memory_bytes: 1788
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

typedef pair<int, int> P;

int main()
{
    priority_queue<P, vector<P>, greater<P>> q;

    int N;
    cin >> N;

    REP(i, N)
    {
        int A, B;
        cin >> A >> B;
        q.emplace(make_pair(B, A));
    }

    ll right = 0, left = 0;
    bool ok = true;
    while (!q.empty())
    {
        pair<int, int> p = q.top();
        q.pop();
        int deadline = p.first;
        int time     = p.second;
        right = left + time;

        // cout << "(deadline, time): (" << deadline << ", " << time << ") | ";
        // cout << left << " to " << right << endl;

        if (right > deadline)
        {
            ok = false;
            break;
        }

        left = right;
    }

    if (ok)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> u(m*2);
  
  for(int i =0; i <m*2 ;i++){
    cin >> u.at(i);
  }
  for(int j =1; j <= n; j++) {
    int s = 0;
    for(int i =0; i <m*2 ;i++) {
      if(u.at(i) == j) s++;
    }
      cout << s << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int d, g;
vi p(10);
vi c(10);
int mn = 10 * 100 + 1;

void chk(int cnt, int pt, int ex, int i)
{
    if (i == d)
    {
        for (int j = 0; j < p[ex]; j++)
        {
            if (pt >= g)
            {
                break;
            }
            pt += (ex + 1) * 100;
            cnt++;
        }

        if (pt < g)
        {
            pt += c[ex];
        }

        if (pt >= g)
        {
            mn = min(mn, cnt);
        }
        else
        {
        }

        return;
    }

    if (ex != i)
    {
        chk(cnt + p[i], pt + (i + 1) * p[i] * 100 + c[i], ex, i + 1);
    }
    chk(cnt, pt, ex, i + 1);
}

int main()
{
    cin >> d >> g;
    for (int i = 0; i < d; i++)
    {
        cin >> p[i] >> c[i];
    }

    for (int i = 0; i < d; i++)
    {
        chk(0, 0, i, 0);
    }

    cout << mn << endl;

    return 0;
}


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

#define F first
#define S second

using namespace std;

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

const int N = 55, M = 110;

int n, m;
int x[N], y[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> x[i] >> y[i];
	
	LL res = 1LL << 62;
	for (int i = 0; i < n; i ++ )
		for (int j = 0; j < n; j ++ )
			for (int k = 0; k < n; k ++ )
				for (int l = 0; l < n; l ++ )
					if (x[i] <= x[j] && y[k] <= y[l])
					{
						int cnt = 0;
						for (int u = 0; u < n; u ++ )
							if (x[u] <= x[j] && x[u] >= x[i] && y[u] <= y[l] && y[u] >= y[k])
								cnt ++ ;
						if (cnt >= m) res = min(res, (LL)(x[j] - x[i]) * (y[l] - y[k]));
					}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,k;cin >> a >> b >> k;
  FORR(i,a,1){
      if(a%i == 0 && b%i==0){
          if(k==1){
              cout << i << endl;
              return 0;
          }
          k--;
      }
  }

}

Measured memory_bytes: 256
_, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).group_by { |e| e }

ans = 0
if k < a.keys.length
  ans = a.map { |_, v| v.length }.sort[0..(a.keys.length-k-1)].inject(:+)
end
puts ans


Measured memory_bytes: 46820
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int curGcd = A[0];
        for (int i = 1; i < N; i++) {
            curGcd = calcGcd(A[i], curGcd);
            if (curGcd == 1) {
                System.out.print(1);
                return;
            }
        }
        System.out.print(curGcd);
    }

    // 最大公約数を求める。
    int calcGcd(int m, int n) {
        if (m <= 0 || n <= 0) {
            throw new IllegalArgumentException("Arguments must be 1 and over.");
        }
        if(m < n) {
            int tmp = m;
            m = n;
            n = tmp;
        }
        int remainder = 0;
        while ((remainder = m % n) != 0) {
            m = n;
            n = remainder;
        }
        return n;
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 50140
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        float sumRevertA = 0;
        for (int i = 0; i < N; i++) {
            float a = Float.parseFloat(sc.next());
            sumRevertA += (1f / a);
        }

        System.out.println(1f / sumRevertA);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
#define INF 1e18

double dist(double x1,double y1,double x2,double y2){
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){
  double xs,ys,xt,yt;
  int n;
  cin>>xs>>ys>>xt>>yt>>n;
  vector<double> x(n),y(n),r(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>r[i];
  }
  x.pb(xs);  x.pb(xt);
  y.pb(ys);  y.pb(yt);
  r.pb(0);  r.pb(0);
  n=x.size();
  
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,n-2));
  double d[1111];
  fill_n(d,1111,INF);
  d[n-2]=0;

  while(que.size()){
    double cost=que.top().fi;
    int v=que.top().se;
    que.pop();
    if(cost>d[v])continue;
    for(int i=0;i<n;i++){
	 if(i==v)continue;
	 double tocost=max(0.0,dist(x[v],y[v],x[i],y[i])-r[v]-r[i]);
	 if(d[i]>d[v]+tocost){
	   d[i]=d[v]+tocost;
	   que.push(P(d[i],i));
	 }
    }
  }

  printf("%.10lf\n",d[n-1]);
  return 0;
}


Measured memory_bytes: 6264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

int main(){	
	long long Y;
	long long K;
	long long Z;
	long long X;
	scanf("%lld",&X);
	vector<long long> A(X-1+1);
	scanf("%lld",&Y);
	vector<long long> B(Y-1+1);
	scanf("%lld",&Z);
	vector<long long> C(Z-1+1);
	scanf("%lld",&K);
	for(int i = 0 ; i <= X-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= Y-1 ; i++){
		scanf("%lld",&B[i]);
	}
	for(int i = 0 ; i <= Z-1 ; i++){
		scanf("%lld",&C[i]);
	}
	vector<long long> AB;
	rep(i,X) {
		rep(j,Y) {
			AB.push_back(A[i]+B[j]);
		}
	}
	sort(AB.begin(),AB.end(),std::greater<ll>());
	priority_queue<ll> que;
	rep(i,min(K,X*Y)) {
		rep(j,Z) {
			que.push(AB[i]+C[j]);
		}
	}
	rep(i,K) {
		cout << que.top() << endl;
		que.pop();
	}
	return 0;
}



Measured memory_bytes: 43240
n =int(input())
if 400<=n<=599:
    print('8')
elif 600<=n<=799:
    print('7')
elif 800<=n<=999:
    print('6')
elif 1000<=n<=1199:
    print('5')
elif 1200<=n<=1399:
    print('4')
elif 1400<=n<=1599:
    print('3')
elif 1600<=n<=1799:
    print('2')
elif 1800<=n<=1999:
    print('1')

Measured memory_bytes: 9196
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    vector<int> cnt(26);
    for (int i = 0; i < 4; i++)
    {
        cnt[s[i] - '0' - 17]++;
    }

    int num = 0;
    for (int i = 0; i < 26; i++)
    {
        if (cnt[i] == 2)
        {
            num++;
        }
    }

    if (num == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    // cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x=0;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int max=0;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x++;
            if(max<x){
                max=x;
            }
        }
        else{
            x--;
        }
    }
    cout<<max<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

ll N;
double dp[310][310][310];

double rec(ll i, ll j, ll k){
  if(dp[i][j][k]>=0)return dp[i][j][k];
  if(i==0&&j==0&&k==0){
    //cout<<"0 0 0 "<<0.0<<endl;
	return 0.0;
  }
  double res=0.0;
  if(i>0)res+=rec(i-1, j, k)*i;
  if(j>0)res+=rec(i+1, j-1, k)*j;
  if(k>0)res+=rec(i, j+1, k-1)*k;
  res+=N;
  //cout<<res<<endl;
  res*=1.0/(i+j+k);
  //cout<<i<<" "<<j<<" "<<k<<" "<<res<<endl;
  return dp[i][j][k]=res;
}

int main(){
  cin>>N;
  vector<ll> A(N);
  ll one, two, three;
  one=0;two=0; three=0;
  rep(i, N){
    cin>>A[i];
    if(A[i]==1)one++;
    else if(A[i]==2)two++;
    else three++;
  }
  memset(dp, -1, sizeof(dp));

cout<<fixed<<setprecision(10)<<rec(one, two, three)<<endl;

}

Measured memory_bytes: 236516
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main() {

	int n;
	
	float s = 0;

	cin >> n;

	vector<int> a(100);

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

	for (int i = 0; i < n; i++) {
		s = s + 1/(float)a[i];
	}

	cout << 1 / s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;cin>>n;
int a[3];
for(int i=0;i<n;i++)
{
for(int j=0;j<3;j++)cin>>a[j];
sort(a,a+3);
if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}

Measured memory_bytes: 3048
#include <iostream>

using namespace std;

int main()
{
long long a[15000],x,y,i,ii,input,temp,sum=0,sum1=0,b=0,c;
cin >> x >> y;
c=y;
for(ii=1;ii<=x;ii++)
{
for(i=b;i<c;i++)
{
    cin >> input;
    a[i]=input;
    sum=sum+input;
    cout << input << " ";
}
b=b+y;
c=c+y;
cout << sum << endl;
sum=0;
}
for(ii=0;ii<y;ii++)
{
for(i=ii;i<x*y;i=i+y)
{
    sum=sum+a[i];
}
cout << sum << " ";
sum1=sum1+sum;
sum=0;
}
cout << sum1 << endl;
}



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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n;
    cin >> n;
    if(!n)
        return false;
    vector<pair<int,int>> v;
    for(int i = 0; i < n; ++i){
        int r, w;
        cin >> r >> w;
        v.emplace_back(r, w);
    }
    sort(v.begin(), v.end());
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        a[i] = v[i].first;
        b[i] = v[i].second;
    }
    if(2 * a.back() > accumulate(a.begin(), a.end(), 0LL)){
        int w = 2 * a.back() - accumulate(a.begin(), a.end(), 0LL);
        bitset<2007> dp;
        dp.set(0);
        for(int i = 0; i < n - 1; ++i)
            dp |= (dp << b[i]);
        int val = 0;
        for(int i = 0; i <= w; ++i)
            if(dp[i])
                val = i;
        int ans = 2 * a.back() - val + accumulate(b.begin(), b.end(), 0LL);
        cout << ans << endl;
    }
    else{
        cout << accumulate(a.begin(), a.end(), 0LL) + accumulate(b.begin(), b.end(), 0LL) << endl;
    }


    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3116
n , k, q = list(map(int, input().split()))
ans = [int(input()) for i in range(q)]
points = [k for i in range(n)]
for i in ans:
    points[i - 1] += 1
new_points = list(map(lambda x:x - q, points))

for i in new_points:
    if i <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 14428
N = int(input())
A = list(map(int, input().split()))

ans = 0
while True:
    if all(map(lambda x: x < N, A)):
        break

    temp = 0
    num = [0] * N

    for i in range(N):
        temp += A[i] // N
        num[i] = A[i] // N
        A[i] %= N

    ans += temp
    A = [a + temp - n for a, n in zip(A, num)]

print(ans)


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

int main() {
    int n, k, ret = 0, x, y;
    char c;
    std::cin >> n >> k;
    std::vector<std::vector<int>> b(2 * k, std::vector<int>(k));
    for (auto i = 0; i < n; i++) {
        std::cin >> x >> y >> c;
        if (c == 'B') x += k;
        x %= 2 * k;
        y %= 2 * k;
        if (y >= k) {
            y -= k;
            x = (x + k) % (2 * k);
        }
        if (x < k) {
            b[0][0]++;
            b[x][0]--;
            b[0][y]--;
            b[x][y] += 2;
            b[x + k][y] -= 2;
            b[x + k][0]++;
        } else {
            b[x][y] += 2;
            b[x][0]--;
            b[x - k][0]++;
            b[x - k][y] -= 2;
            b[0][y]++;
        }
    }

    for (auto i = 0; i < 2 * k; i++) for (auto j = 1; j < k; j++) b[i][j] += b[i][j - 1];
    for (auto i = 1; i < 2 * k; i++) for (auto j = 0; j < k; j++) b[i][j] += b[i - 1][j];
    for (auto i = 0; i < 2 * k; i++) for (auto j = 0; j < k; j++) ret = std::max(ret, b[i][j]);
    
    printf("%d\n", ret);

    return 0;
}

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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    lint n;
    cin >> n;
    lint ans = 0, sum = 0;
    rep(i, n){
        lint a;
        cin >> a;
        if(a == 0){
            ans += sum/2;
            sum = 0;
        }else{
            sum += a;
        }
    }
    ans += sum/2;
    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(), d = sc.nextInt(), x = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < n; ++i) {
			int a = sc.nextInt();
			ans += (d - 1) / a + 1;
		}
		sc.close();
		ans += x;
		System.out.println(ans);
	}

}


Measured memory_bytes: 21076
from fractions import gcd

P = int(1e9)+7
n = int(input())

def lcm(p,q):
    return p*q//gcd(p,q)

a = list(map(int, input().split()))
x = a[0]
for i in range(1,n):
    x = lcm(x,a[i])
ans = 0
for i in range(n):
    ans += x//a[i]
ans = ans%P
print(ans)

Measured memory_bytes: 6112
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N,M;
  ll K;
  cin>>N>>M>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];
  vector<ll> B(M);
  rep(i,M) cin>>B[i];

  vector<ll> sum(M+1,0);
  rep(i,M) sum[i+1]=sum[i]+B[i];

  int ans=0;
  ll sa=0;
  for(int i=0;i<=N;i++){
    if(i>0) sa+=A[i-1];
    if(sa>K) break;

    int ok=0,ng=M+1;
    while(abs(ok-ng)>1){
      int mid=(ok+ng)/2;
      if(sa+sum[mid]<=K) ok=mid;
      else ng=mid;
    }
    chmax(ans,i+ok);
  }

  cout<<ans<<endl;



  return 0;
}


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

using namespace std;
using ll = long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

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

  ll k, sum = 0;
  cin >> k;
  FOR(a, 1, k + 1) FOR(b, 1, k + 1) FOR(c, 1, k + 1) {
    sum += gcd(gcd(a, b), c);
  }
  OUT(sum);

  return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 1 << 30;
const int MAX_PRIME = 1000010;
bool is_prime[MAX_PRIME + 10];
vector<int> primes;

void init_primes() {
    fill(is_prime, is_prime + MAX_PRIME + 10, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=0; i<=MAX_PRIME; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int k=i+i; k<=MAX_PRIME; k+=i) {
                is_prime[k] = false;
            }
        }
    }
}

int main() {
    init_primes();
    primes.push_back(INF);

    int N;
    while(scanf("%d", &N) != EOF) {
        printf("%zu\n", upper_bound(primes.begin(), primes.end(), N) - primes.begin());
    }
    return 0;
}


Measured memory_bytes: 3852
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 400005
#define LL long long
const double PI=3.1415926535897932384626;
struct cp{
	double r,i;
	cp(){}
	cp(double x,double y){r=x;i=y;}
	cp operator + (const cp &t)const{return cp(r+t.r,i+t.i);}
	cp operator - (const cp &t)const{return cp(r-t.r,i-t.i);}
	cp operator * (const cp &t)const{return cp(r*t.r-i*t.i,r*t.i+i*t.r);}
}a[N],b[N],w,wn;
void change(cp a[],int len)
{
	int i,j,k;
	for(i=1,j=len/2;i<len-1;i++){
		if(i<j) swap(a[i],a[j]);
		for(k=len/2;j>=k;j-=k,k>>=1);
		j+=k;
	}
}
void fft(cp a[],int len,int flg)
{
	int i,j,k;
	for(i=2;i<=len;i<<=1){
		wn=cp(cos(flg*2*PI/i),sin(flg*2*PI/i));
		for(j=0;j<len;j+=i){
			w=cp(1,0);
			for(k=j;k<j+i/2;k++){
				cp t=a[k];
				cp u=a[k+i/2]*w;
				a[k]=t+u;
				a[k+i/2]=t-u;
				w=w*wn;
			}
		}
	}
	if(flg==-1)
		for(i=0;i<len;i++)
			a[i].r/=len;
}
LL ans[N];
inline int getint()
{
	char c;int num=0,flag=1;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}
	return num*flag;
}
int c[N],cd[N];
int main()
{
	memset(c,0,sizeof(c));
	int m,i;	
	m=getint();
	for(i=1;i<=m;i++){
		cd[i]=getint();
		c[cd[i]]++;
	}
	sort(cd+1,cd+m+1);
	
	int lena,lenb,len,n;
	lena=lenb=cd[m]+1;
	len=lena+lenb;n=1;
	while(n<len)n<<=1;
	
	for(i=0;i<lena;i++)b[i]=a[i]=cp((double)c[i],0);
	for(i=lena;i<n;i++)b[i]=a[i]=cp(0,0);
	
	change(a,n);change(b,n);
	fft(a,n,1);fft(b,n,1);
	for(i=0;i<n;i++) b[i]=a[i]*b[i];
	change(b,n);fft(b,n,-1);
	for(i=0;i<len-1;i++) ans[i]=(LL)(b[i].r+0.5);
	
	len--;
	for(i=1;i<=m;i++)ans[cd[i]*2]--;
	for(i=0;i<len;i++)ans[i]>>=1;
	for(i=1;i<len;i++)ans[i]=1ll*ans[i]+1ll*ans[i-1];
	LL cnt=0;
	for(i=1;i<=m;i++){
		cnt=1ll*cnt+1ll*ans[len-1]-1ll*ans[cd[i]];
		cnt=1ll*cnt-1ll*(m-1);
		cnt=1ll*cnt-1ll*(m-i)*(m-i-1)/2;
		cnt=1ll*cnt-1ll*(m-i)*(i-1);
	}
	printf("%lld",cnt);
}

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

int main(){
  int x;
  cin >> x;
  
  //while (1)とかwhile (true)は無限ループのこと
  while (1){
    bool ok=true;
    for (int i=2;i<x;++i){
      if (x%i==0) {
        ok=false;
        break;
      }
    }
    if (ok) break;
      ++x;
  }
      cout << x << endl;
      return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long
//vector<int> g1;
//g1.push_back(i);

using namespace std;

int main()
{
	int shift;
	cin >> shift;
	string inp;
	cin >> inp;
	for (int i=0;i<inp.length();i++)
	{
		inp[i] = (inp[i]-'A'+shift)%26+'A';
	}
	cout << inp;
	return 0;
}



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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  int n;cn(n)
  vector<pair<int,int>> d(n);
  rep(i,n){
    cin >> d[i].first >> d[i].second;
  }
  double ans = 0;
  rep(i,n){
    rep(j,n){
      ans += sqrt( ( d[i].first - d[j].first )*( d[i].first - d[j].first ) + ( d[i].second - d[j].second )*( d[i].second - d[j].second ) );
    }
  }
  cout << setprecision(10) << ans/n << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    for (int i = 1; i < n; i++) {
        if (A[i-1] == A[i]) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll n,m;
    cin >> n >> m;
    if (n>m) swap(n,m);
    if (n==1){
        if (m==1){
            cout << 1 << endl;
        }else{
            cout << m-2 << endl;
        }
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



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

    unsigned long long q=N;
    string s;
    do {
        q--;
        char c='a'+q%26;
        s+=c;
        q/=26;
    } while (q>0);

    reverse(all(s));
    cout << s << endl;
    return 0;
}


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

namespace ABC_066_A_ringring
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] word = Console.ReadLine().Split(' ');
			int a = int.Parse(word[0]);
			int b = int.Parse(word[1]);
			int c = int.Parse(word[2]);


			int d = a + b;
			int e = a + c;
			int f = b + c;
			int x = 0;

			if (d <= e && d <= f)
				x = d;
			else if (e <= d && e <= f)
				x = e;
			else
				x = f;

			Console.WriteLine(x);
        }
	}
}

Measured memory_bytes: 27536
import sys

S = input()
for i in range(len(S)):
    if i % 2 == 0:
        if not (S[i] == 'R' or S[i] == 'U' or S[i] == 'D'):
            print("No")
            sys.exit()
    else:
        if not (S[i] == 'L' or S[i] == 'U' or S[i] == 'D'):
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<int>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=1000005;
ll ans;
int a[N];
char ch[N];
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	Rep(i,n,1)if(ch[i]=='>')a[i]=a[i+1]+1; else a[i]=0;
	int dq=0;
	For(i,1,n+1){
		ans+=max(dq,a[i]);
		if(ch[i]=='<')dq++; else dq=0;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,j=1,i,count=0,y=-1;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		if(a[i]!=j)
		count++;
		else
		j++;	
	}
	if(count!=n)
	cout<<count;
	else
	cout<<y;
	return 0;
	
	
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

template<typename T>
vector<T> dijkstra(const vector<vector<pair<int, T>>> &graph, int root) {
  using P = pair<T, int>;
  vector<T> dists(graph.size(), numeric_limits<T>::max());
  priority_queue<P, vector<P>, greater<P>> que;
  dists[root] = 0;
  que.emplace(dists[root], root);
  while (!que.empty()) {
    P x = que.top(); que.pop();
    if (dists[x.second] < x.first) continue;
    for (auto e : graph[x.second]) {
      if (dists[e.first] > dists[x.second] + e.second) {
        dists[e.first] = dists[x.second] + e.second;
        que.emplace(dists[e.first], e.first);
      }
    }
  }
  return dists;
}

int main() {
  int n; cin>>n;
  vector<vector<pair<int, long long>>> g(n);
  rep(i, n-1) {
    int a, b, c; scanf("%d%d%d",&a,&b,&c);
    --a; --b;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  int q, k; cin>>q>>k;
  --k;
  auto dists = dijkstra(g, k);
  rep(i, q) {
    int x, y; scanf("%d%d",&x,&y);
    --x; --y;
    print(dists[x]+dists[y]);
  }

  return 0;
}

Measured memory_bytes: 11120
import java.io.*;
import java.util.*;

/******************************\
 * The solution is at the top *
 *                            *
 *   Created by : azhar556    *
\******************************/

public class Main {
	static class Pair {
		int a, b;
		Pair (int a, int b) {
			this.a = a;
			this.b = b;
		}
	}
    static void solve() {
		int N = ni();
		Pair[] arr = new Pair[N];
		for (int i = 0; i < N; i++) {
			arr[i] = new Pair(ni(), ni());
		}
		Arrays.sort(arr, new Comparator<Pair>() {
			public int compare (Pair a, Pair b) {
				return a.b - b.b;
			}
		});
		long work = 0L;
		for (int i = 0; i < N; i++) {
			work += arr[i].a;
			if (work > arr[i].b) {
				out.println("No"); return;
			}
		}
		out.println("Yes");
    }    

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        int t;// = ni();
        t = 1;
        while (t-- > 0) solve(); 
        err.println("Time elapsed : " + (System.currentTimeMillis() - time) / 1000F + " s.");
        err.close(); out.close();
    }

	static int[] radixSort(int[] f){ return radixSort(f, f.length); }
	static int[] radixSort(int[] f, int n)
	{
		int[] to = new int[n];
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		return f;
	}

    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static PrintWriter err = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer token;
    
    static boolean hasMoreTokens () {
        String sample = null;
		try {
			sample = br.readLine();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return sample == null ? false : true;
    }

    static String ns() {
        while (token == null || !token.hasMoreTokens()) {
            try {
                token = new StringTokenizer(br.readLine());
            }
            catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return token.nextToken();
    }
    static char nc() {
        return Character.valueOf(ns().charAt(0));
    }
    static int ni() {
        return Integer.parseInt(ns());
    }
    static double nd() {
        return Double.parseDouble(ns());
    }
    static long nl() {
        return Long.parseLong(ns());
    }
}
// Collections Arrays Math
// Vector HashSet TreeSet HashMap TreeMap ArrayDeque 

Measured memory_bytes: 53036
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	int m_module = 1000000007;
	vector<struct Memo> memo;
public:
	int calculate(int, int);
	Combination1(int, int);
};
int Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, int module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Weather_Prediction(void) {

	string S; cin >> S;

	string weather[3] = { "Sunny","Cloudy","Rainy" };
	for (int loop = 0; loop < 3; loop++) {
		if (S == weather[loop]) {
			cout << weather[(loop + 1) % 3] << flush;
			break;
		}
	}
	return;
}

int main(void) {

	A_Weather_Prediction();
	return 0;
}


Measured memory_bytes: 256
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    H,W,N = iRaw(),iRaw(),iRaw()
    Z = max(H,W)
    return (N+Z-1)//Z

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    ll N;
  cin >>N;
ll dp,count;
  count=1;
  cin>>dp;
  
  ll a;
  for(ll i=0;i<N-1;i++){
  cin>>a;
    if(dp>a){dp=a;count=count+1;}
  }
  
 cout<<count<<endl;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
s = [input() for _ in range(h)]

def check():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                continue

            def ok(x,y):
                return x>=0 and x<h and y>=0 and y<w and s[x][y]=='#'

            if all([not ok(x,y) for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) :
                return False
    return True


print("Yes" if check() else "No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    ll a;
    map<ll, ll> mp;
    REP(i, n) {
        cin >> a;
        mp[a]++;
        if (mp[a] == 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int Maxn = 110;
const int Maxw = 100010;
const int INF = (int) 1e9;

ll dp[Maxn][Maxw], w[Maxn], v[Maxn];

int main() {
    int n, x;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            dp[i + 1][j] = dp[i][j];
            if (j - w[i] >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
        }
    }

    cout << dp[n][x] << endl;

    return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

    int n;
    cin >> n;

    bool ans = false;

    rep(i,26){
        int cakecost = i * 4;

        if(cakecost <= n && (n - cakecost) % 7 == 0){
            ans = true;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
gets.to_i
num = gets.split.map(&:to_i)
if num.include?(0)
    puts(0)
else
    ans = 1
    flag = true
    num.map do |n|
        ans *= n
        if ans > (10 ** 18)
            flag = false
            break
        end
    end
    flag ? puts(ans) : puts(-1)
end

Measured memory_bytes: 21580
l,r = map(int,input().split())
mod = 2019
 
for i in range(l,r+1):
  for j in range(i+1,r+1):
    mod = min(mod,(i*j)%2019)
    if mod == 0:
      break
  if mod == 0:
    break
      
print(mod)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std; 
int main() {
int R,D,X,ans;
cin >> R >> D >> X;
ans = R*X-D;
cout << ans << endl;
for(int i = 1; i < 10; i++){
ans = ans * R - D;
cout << ans << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int power(int a, int b, int c){
    int ans = 1;
    while(b){
        if(b&1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

int f[N];

signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n, m, k;
    cin >> n >> m >> k;
    f[0] = 1;
    for(int i = 1; i < N; i++)
        f[i] = (f[i-1]*i) % mod;
    int ans = (m*n * (m*n - 1) * (m + n)) % mod;
    ans = (ans * f[m*n - 2]) % mod;
    ans = (ans * power(f[k-2], mod-2, mod)) % mod;
    ans = (ans * power(f[n*m - k], mod - 2, mod)) % mod;   
    ans = (ans * power(6, mod-2, mod)) % mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int N;
	cin >> N;
	long long ans = 0;
	int hoge;
	vector<int> a(N+1), b(N);
	for (int i = 0; i < N + 1; i++){
		cin >> a[i];
	
	}

	for (int i = 0; i < N; i++){
		cin >> b[i];
	}
	for (int i = 0; i < N; i++){
		/*if (a[i]<=b[i]){
			ans += min(a[i], b[i]);
			hoge = min(b[i] - a[i], a[i + 1]);
			a[i + 1] -= hoge;
			ans += hoge;
		}
		else {
			ans += b[i];
		}*/
		int d = min(a[i], b[i]);
		ans += d; a[i] -= d; b[i] -= d;
		d = min(a[i+1], b[i]);
		ans += d; a[i + 1] -= d;
	}
	cout << ans << endl;
	return 0;			

}

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

using namespace std;

int main()
{
  vector<pair<string,int>> com;
  string s;
  int a,count;
  string m;

  count = 0;

  while(cin>>s>>a){
    com.push_back(make_pair(s,a));
    ++count;
  }

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

  for(int i = 0;i<count;++i){
    pair<string,int> p = com[i];
    if(i == 0){
      cout<<p.first<<endl;
      cout<<p.second;
      m = p.first;
    }
    else{
      if(m == p.first){
        cout<<" "<<p.second;
      } 
      else{
        cout<<endl;
        cout<<p.first<<endl;
        cout<<p.second;
        m = p.first;
      }
    }
  }

  cout<<endl;

  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(x, n) for(int i=x; i<=n; ++i)
#define MOD 1000000007

vvi AL;
vi dfs_num;
int ans = 0;
int counter;

void dfs(int u) {

    dfs_num[u] = 1;
    counter++;

    for(auto v: AL[u]) {
        if(!dfs_num[v]) {
            dfs(v);
        }
    }
}

int main() {

    int n, m;
    sc("%d %d", &n, &m);

    AL.assign(n+5, vi());
    dfs_num.assign(n+5, 0);

    FOR(1, m) {
        int a, b;
        sc("%d %d", &a, &b);

        AL[a].pb(b);
        AL[b].pb(a);
    }

    FOR(1, n) {

        if(!dfs_num[i]) {
            counter = 0;
            dfs(i);
            ans = max(ans, counter);
        }
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 21196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 set<string> st;
	 while(n--)
	 {
	 	string s;
	 	cin>>s;
		st.insert(s);
	 }
	 cout<<st.size();
	 
	 return 0;
}

Measured memory_bytes: 19280
n = int(input())
d = []
left = []
right = []
for i in range(n):
    x,l = map(int, input().split())
    # num , left , right
    d.append([x-l,x+l])

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] < p:
        ans -= 1
        p = min(p,d[i][1])
    else:
        p = d[i][1]
print(ans)


Measured memory_bytes: 20104
#include<iostream>
#include<vector>
#include<assert.h>
#include<algorithm>

using namespace std;

int main(void) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = min(b,d) - max(a,c);
    if (ans > 0) {
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define INF 1000000007

using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

ll combination(ll a, ll b) {
    ll aa = 1;
    ll bb = 1;
    for (int i = 0; i < b; i++) {
        aa *= (a - i);
        bb *= (i + 1);
    }
    return aa / bb;
}

int main()
{
    int N, D;
    cin >> N >> D;
    vector<vector <int> > v(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> v[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            }
            double rt = sqrt(sum);
            // cout << rt << endl;
            if (ceil(rt) == floor(rt)) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// Problem: Q - Flowers
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_q
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

const int N = 800080;
long long lc[N], rc[N], t[N];
long long h[N], a[N];
int n;
#define ls (p << 1)
#define rs (p << 1 | 1)
void pushup(int p) {
    t[p] = max(max(t[p], t[ls]), t[rs]);
}
void build(int p, int l, int r) {
    lc[p] = l; rc[p] = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(ls, l, mid);
    build(rs, mid + 1, r);
//    pushup(p);
}
long long query(int p, int l, int r) {
    if (l <= lc[p] && rc[p] <= r) return t[p];
    if (l > rc[p] || r < lc[p]) return 0LL;
    return max(query(ls, l, r), query(rs, l, r));
}
void modify(int p, int x, long long v) {
    if (x == lc[p] && x == rc[p]) {
        t[p] = v;
        return;
    }
    if (x > rc[p] || x < lc[p]) return;
    modify(ls, x, v); modify(rs, x, v);
    pushup(p);
}
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> h[i];
    for (int i = 1; i <= n; i++) cin >> a[i];
    build(1, 0, n);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        long long cur;
        cur = query(1, 0, h[i] - 1) + a[i];
        ans = max(ans, cur);
        modify(1, h[i], cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 19032