akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;

/**
 * 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);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int[] A = CPUtils.readIntArray(N, in);
            Set<Integer> set = new HashSet<>(N);
            Arrays.stream(A).forEach(el -> set.add(el));
            if (set.size() == N)
            {
                out.print("YES");
            } else
            {
                out.print("NO");
            }
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

    }
}



Measured memory_bytes: 72752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N, 0), ans(N, 0);
    rep(i, 0, N)
    {
        cin >> A.at(i);
    }
    rep(i, 0, N)
    {
        if (i == 0)
        {
            rep(j, 0, N)
            {
                if (j % 2 == 0)
                {
                    ans.at(i) += A.at(j);
                }
                else
                {
                    ans.at(i) -= A.at(j);
                }
            }
        }
        else
        {
            ans.at(i) = -ans.at(i - 1) + 2 * A.at(i - 1);
        }
        cout << ans.at(i) << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define For(i,x,y) for(int i=x;i<=y;i++)
#define Rep(i,x,y) for(int i=x;i>=y;i--)
#define mp make_pair
#define pa pair<ll,int>
using namespace std;
inline int read(){
    int x=0,f=0;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;
    for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;
    return f?-x:x;
}
int n,h,in[405],ou[405],fa[405];
bool flag[405];
inline int find(int x){return (fa[x]==x)?x:fa[x]=find(fa[x]);}
int main(){
    n=read();h=read();
    For(i,1,h*2) fa[i]=i;
    For(i,1,n){
        int a=read(),b=read(),c=read(),d=read();
        int l=(c==0)?h+a:c;
        int r=(d==0)?b:h+d;
        in[r]++;ou[l]++;
        fa[find(l)]=find(r);
    }
    For(i,1,h) if(ou[i]>in[i]){puts("NO");return 0;}
    For(i,h+1,h*2) if(ou[i]<in[i]){puts("NO");return 0;}
    For(i,1,h*2) if(in[i]!=ou[i]) flag[find(i)]=1;
    For(i,1,h*2) if(find(i)==i&&!flag[i]&&in[i]+ou[i]!=0){puts("NO");return 0;}
    puts("YES");
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l=INT_MAX,r=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        if(m<=l)
        {
            l=m;
            r++;
        }
    }
    cout<<r<<"\n";
    return 0;
}



Measured memory_bytes: 3640
import java.util.ArrayList;
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());
		String s = sc.next();
		
		if(n >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
		

	}
}


Measured memory_bytes: 22736
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, T;
	cin >> N >> T;
	vector<int> A(N);
	set<int> exist;
	rep(i,N){
		cin >> A[i];
		exist.insert(A[i]);
	}
	map<int, int> ans;
	rep(i,N-1){
		exist.erase(A[i]);
		int nax = *exist.rbegin();
		++ans[nax - A[i]];
	}
	cout << (*ans.rbegin()).second << endl;
	return 0;
}

Measured memory_bytes: 8308
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
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;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


// [0, N-1]ではなく[1, N], 1-indexed
struct BIT {
  int N;
  int MAX_N = 200000;
  vector<ll> bit; // bit[1]...bit[N]を使用

  BIT(int n) : N(n), bit(MAX_N+1) {}

  ll sum(int a){          // 1～a (1-indexed)の和を求める
    ll ret=0;
    for (int i=a; i>0; i -= i & -i) ret += bit[i];
    return ret;
  }

  void add(int a, ll x){  // a番目(1-indexed)に x を加える
    for (int i=a; i<=MAX_N; i += i & -i) bit[i] += x;
  }
};


void compress(vector<int> &a){
  vector<int> com(a.size());
  rep(i, a.size()) com[i] = a[i];
  sort(all(com));
  com.erase(unique(all(com)), com.end());
  rep(i, a.size()) a[i] = lower_bound(all(com), a[i]) - com.begin() + 1;
}

int main() {
  int N; cin >>N;
  vector<int> A(N); rep(i, N) cin >>A[i];
  compress(A);
  // 座標圧縮しておく。ただし1-indexed
  // 各aiについて、既に見たものの中で自分未満のもののうち最大のものを自分に置き換える
  BIT bit(N);
  rep(i, N){
    int a = A[i];
    if (a == 1){
      bit.add(a, 1);
    }else if (bit.sum(a-1) == 0){
      bit.add(a, 1);
    }else{
      // 自分未満のやつがいた！
      int x = bit.sum(a-1);
      // 具体的にはbit.sum(i) = x となる最小のやつを見つける
      int ok = a-1, ng = 0;
      while (abs(ok-ng) > 1){
        int mid = (ok+ng)/2;
        if (bit.sum(mid) == x) ok = mid;
        else ng = mid;
      }
      bit.add(ok, -1);
      bit.add(a, 1);
    }
  }
  int res = bit.sum(N);
  cout <<res <<endl;
}

Measured memory_bytes: 2208
inf = 1000 * 1000 + 10

n, m = map(int, input().split())

g = tuple([inf] * n for _ in range(n))
e = set()
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c
    e.add((a, b, c))
    e.add((b, a, c))

for i in range(n):
    g[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

res = 0
for a, b, c in e:
    for s in range(n):
        if g[s][b] == g[s][a] + c:
            res += 1
            break

print(m - res // 2)


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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin>>N;
  int L[2*N];
  for (int i=0; i<2*N; i++) {
    cin>>L[i];
  }
  sort(L,L+2*N);
  int ans=0;
  for (int i=1; i<2*N; i+=2) {
    ans+=min(L[i-1],L[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  	cout<<fixed<<setprecision(15);
    
    double t,x; cin >> t >> x;
    OUT(t / x);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define all(a) a.begin(), a.end()
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

//pdf見て解答

ll mod = 1e9+7;

ll f(ll x, ll n){
    ll r = x;
    for(long long i = 1; i < n; i++){
        r = r * x % mod;
    }
    return r;
}

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

    ll ans = 0;
    ans = f(10,n) - f(9,n) - f(9,n) + f(8,n);
    ans %= mod;
    ans = (ans + mod) % mod; //NANIKORE
    put(ans);
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  long long int a[n], b[n], aa, bb, min = 100, cnt;
  for(int i = 0;i < n;i++){
    scanf("%lld %lld",&a[i],&b[i]);
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(i != j){
        aa = a[i] - a[j];
        bb = b[i] - b[j];
        cnt = 1;
        for(int s = 0;s < n;s++){
          for(int t = 0;t < n;t++){
            if((i != t || j != s) && (i != s || j != t) && s != t){
              if(aa == a[s] - a[t] && bb == b[s] - b[t])cnt++;
              //printf("%d : %d %d\n",s,t,cnt);
            }
          }
        }
        cnt = n - cnt;
        if(min > cnt)min = cnt;
        //printf("%d %d %d %lld %lld\n",i ,j ,cnt ,aa ,bb);
      }
    }
  }
  if(n == 1)min = 1;
  printf("%lld\n",min);
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 6e5 + 5;
int t;
const double p = 3.1415926;

int main()
{
	int n;
	while (cin >> n)
	{
		int x;
		map<int, int> mp;
		f(i, 1, n - 1) { scanf("%d", &x);mp[x]++; }
		f(i, 1, n)cout << mp[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 13068
// “Incredible change happens in your life when you decide to take control of what
// you do have power over instead of craving control over what you don't.

// Dear online judge:
//  I've read the problem, and tried to solve it.
//  Even if you don't accept my solution, you should respect my effort.
//  I hope my code compiles and gets accepted.

#include <bits/stdc++.h>
typedef long long ll;
#define forn(i, start, end) for (ll i = start; i < ll(end); i++)
#define input(arr, n) forn(i, 0, n) cin >> arr[i];
#define input2d(arr, n, m) forn(i, 0, n) forn(j, 0, m) cin >> arr[i][j];
#define MOD 1000000007
#define pb push_back
#define ppb pop_back
#define mk make_pair
#define f first
#define s second
#define tc    \
    ll T;     \
    cin >> T; \
    while (T--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;

int32_t main()
{
    FAST;
    //tc
    {
        ll a,b,c,k;
        cin >> a >> b >> c >> k;
        ll ans=0;
        if(k<=a){
            ans = k;
        }
        else if(k<=a+b){
            ans = a;
        }
        else if(k<=a+b+c){
            ans += a;
            k -= a;
            if(k>b){
                ans -= (k-b);
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int n;
long long he[2000010],xo[2000010];
int x;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		he[i]=he[i-1]+x;
		xo[i]=xo[i-1]^x;
	}
	int l=1;
	long long res=0;
	for(int r=1;r<=n;r++){
		while((he[r]-he[l-1])!=(xo[r]^xo[l-1]))
			l++;
		res+=(r-l+1);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 5888
H,W,A,B = map(int,input().split())
P=10**9+7
fac=[1]*(H+W)
inv=[1]*(H+W)
finv=[1]*(H+W)
for n in range(2,H+W):
    fac[n]=fac[n-1]*n%P
    inv[n]=(-inv[P%n]*(P//n))%P
    finv[n]=finv[n-1]*inv[n]%P
def comb(n,k):return ((fac[n]*finv[k]%P)*finv[n-k])%P
ans=0
for i in range(1,min(W-B+1,H-A+1)):
    w=B+i-1
    h=H-A-i
    ans=(ans+comb(w+h,w)*comb(W+H-w-h-2,W-w-1))%P
print(ans)

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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int X, Y;
  X = tx - sx;
  Y = ty - sy;
  for (int i = 0; i < X; i++) cout << "R";
  for (int i = 0; i < Y; i++) cout << "U";
  for (int i = 0; i < X; i++) cout << "L";
  for (int i = 0; i < Y + 1; i++) cout << "D";
  for (int i = 0; i < X + 1; i++) cout << "R";
  for (int i = 0; i < Y + 1; i++) cout << "U";
  cout << "L" << "U";
  for (int i = 0; i < X + 1; i++) cout << "L";
  for (int i = 0; i < Y + 1; i++) cout << "D";
  cout << "R" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vvi x(N), y(N);
    REP(i, N) {
        cin >> A;
        vi xx(A), yy(A);
        REP(a, A) {
            cin >> xx[a] >> yy[a];
            xx[a]--;
        }
        x[i] = xx;
        y[i] = yy;
    }
    vi p(N);
    for (int bit = 0; bit < BIT(N); bit++) {
        bool flag = 1;
        REP(i, N)
        p[i] = (bit >> i) & 1;
        REP(i, N) {
            if (p[i] == 1) {
                REP(j, x[i].size()) {
                    if (p[x[i][j]] != y[i][j]) {
                        flag = 0;
                        break;
                    }
                }
            }
            if (!flag)
                break;
        }
        if (flag) {
            dump(p);
            ans = max(ans, accumulate(ALL(p), 0LL));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2010, mod = 1e9+7;
int n,k,a[N];

inline int calc(int n){
	return 1ll*(n+1)*n/2%mod;
}

int main(){
	n=read(),k=read();
	For(i,1,n) a[i]=read();
	int ans=0;
	For(i,1,n){
		FOR(j,1,i) if (a[i]>a[j]) ans=(ans+calc(k-1))%mod;
		For(j,i+1,n) if (a[i]>a[j]) ans=(ans+calc(k))%mod;
	}
	printf("%d\n",ans);
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if((A == B && B != C && A != C)
    || (A == C && B != C && A != B)
    || (A != B && A != C && C == B))
    {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int X;
  cin >> X;
  if(X == 7 || X == 5 || X == 3)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(void);
void visit(int );

int G[N][N],d[N],f[N],color[N];
int time,n;


int main(){

  int u,v,k,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      G[i][j] =0;

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){ 
      scanf("%d", &v);
      G[u-1][v-1]++;
    }
  }


  dfs();

  for(i=0;i<n;i++){
      printf("%d %d %d",i+1, d[i], f[i]);
    
    printf("\n");
  }

  return 0;
}

void dfs(){

  int i;

  for(i=0;i<n;i++){
    color[i] = WHITE;
    time = 0;

  }
  for(i=0;i<n;i++)
    if(color[i] == WHITE)
      visit(i);
}

void visit(int u){

  int i;

  color[u] = GRAY;
  time++;
  d[u] = time;

  for(i=0;i<n;i++)
    if(G[u][i]==1)
      if(color[i] == WHITE)
	visit(i);

  color[u] = BLACK;
  time++;
  f[u] = time;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll s[100002], t[100002];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, q;
    cin >> a >> b >> q;
    for (int i = 1; i <= a; ++i)
        cin >> s[i];
    for (int i = 1; i <= b; ++i)
        cin >> t[i];

    s[0] = -1e15;
    t[0] = -1e15;
    s[a + 1] = 1e15;
    t[b + 1] = 1e15;
    a += 2;
    b += 2;
    while (q--)
    {
        ll x;
        cin >> x;
        ll sol = 1e15;
        {
            int p1 = lower_bound(s, s + a, x) - s;
            int p2 = p1 - 1;
            int k1 = lower_bound(t, t + b, s[p1]) - t;
            int k2 = k1 - 1;
            int r1 = lower_bound(t, t + b, s[p2]) - t;
            int r2 = r1 - 1;

            sol = min(sol, abs(s[p1] - x) + abs(s[p1] - t[k1]));
            sol = min(sol, abs(s[p1] - x) + abs(s[p1] - t[k2]));
            sol = min(sol, abs(s[p2] - x) + abs(s[p2] - t[r1])); //
            sol = min(sol, abs(s[p2] - x) + abs(s[p2] - t[r2]));
        }
        {
            int p1 = lower_bound(t, t + b, x) - t;
            int p2 = p1 - 1;
            int k1 = lower_bound(s, s + a, t[p1]) - s;
            int k2 = k1 - 1;
            int r1 = lower_bound(s, s + a, t[p2]) - s;
            int r2 = r1 - 1;

            sol = min(sol, abs(t[p1] - x) + abs(t[p1] - s[k1]));
            sol = min(sol, abs(t[p1] - x) + abs(t[p1] - s[k2]));
            sol = min(sol, abs(t[p2] - x) + abs(t[p2] - s[r1]));
            sol = min(sol, abs(t[p2] - x) + abs(t[p2] - s[r2]));
        }
        cout << sol << '\n';
    }
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
using namespace std;
int main() {
	int ans=9999;
	string S;
	cin >> S;
	for (int i = 0; i < S.size()-2; i++) {
		int num = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + (S[i + 2] - '0');
		ans = min(ans, abs(753-num));
	} 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC056
{
    class C
    {
        static void Main(string[] args)
        {
            long X = long.Parse(Console.ReadLine());

            long sum = 0;
            int t = 0;
            for (int i = 1; ; i++)
            {
                t = i;
                sum += i;
                if (X <= sum) break;
            }

            Console.WriteLine(t);
        }
    }
}


Measured memory_bytes: 11092
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        s: chars,
    }
    let mut count_array = vec![0; s.len()];

    let mut i = 0;
    let mut flag = false;
    
    while i < s.len() {
        let mut start = i;
        while s[i] == 'R' {
            i = i + 1;
        }
        //ここでs[i] == 'L'
        for j in start..i+1 {
            if (i - j) % 2 == 0 {
                count_array[i] = count_array[i] + 1;
            } else {
                count_array[i-1] = count_array[i-1] + 1;
            }
        }
        start = i;
        while s[i] == 'L' {
            if i == s.len() - 1 {
               flag = true;
               break;
            }
            i = i + 1;
        }
        if flag {
            i = i + 1;
        }
        for j in start+1..i {
            if (j - start) % 2 == 0 {
                count_array[start] = count_array[start] + 1;
            } else {
                count_array[start-1] = count_array[start-1] + 1;
            }
        }
        if flag {
            break;
        }
    }

    for ans in count_array.iter() {
        print!("{} ", ans);
    }
    println!("");
}
    


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

bool cmp(pair<int, int> x, pair<int, int> y) {
    return x.second < y.second;
}

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

    vector<pair<int, int>> vp(m);
    rep(i, 0, m) cin >> vp[i].first >> vp[i].second;
    
    sort(vp.begin(), vp.end(), cmp);

    int cur = -1, ans = 0;
    rep(i, 0, m) {
        if (cur <= vp[i].first) {
            cur = vp[i].second;
            ans++;
        }
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int P=1e9+7;
int n,a[107],f[107][107][107],ans=0;
void inc(int&a,int b){
	a+=b-P;
	a+=a>>31&P;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n*2;++i)scanf("%d",a+i);
	std::sort(a+1,a+n*2);
	a[0]=a[1],a[n*2]=a[n*2-1];
	f[n][a[n-1]!=a[n]][a[n+1]!=a[n]]=1;
	for(int i=n,d=1;i>1;--i,++d){
		int al=a[n-d-1]!=a[n-d],ar=a[n+d+1]!=a[n+d];
		for(int l=0;l<=n*2-1;++l)
		for(int r=0,x;r<=n*2-1;++r)if(x=f[i][l][r]){
			for(int a=0;a<l;++a)inc(f[i-1][a+al][r+ar+1],x);
			inc(f[i-1][l+al][r+ar],x);
			for(int a=0;a<r;++a)inc(f[i-1][l+al+1][a+ar],x);
		}
	}
	for(int l=0;l<=n*2-1;++l)
	for(int r=0;r<=n*2-1;++r)inc(ans,f[1][l][r]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int A,B,m;
    cin>>A>>B>>m;
    int a[A],b[B];
    for(int i=0;i<A;i++)
    cin>>a[i];
    for(int i=0;i<B;i++)
    cin>>b[i];
    int x[m],y[m],c[m];
    for(int i=0;i<m;i++)
    cin>>x[i]>>y[i]>>c[i];
    int amin=a[0],bmin=b[0],total=0,ans=0;
    for(int i=1;i<A;i++){
        amin=min(amin,a[i]);
    }
    for(int i=1;i<B;i++){
        bmin=min(bmin,b[i]);
    }
    ans=amin+bmin;
    for(int i=0;i<m;i++){
        int d=x[i],e=y[i];
        total=a[d-1]+b[e-1]-c[i];
        ans=min(ans,total);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <stdlib.h>

#define LEN 1000000

typedef struct {
    char name[100];
    int time;
} Job;

Job Array[LEN+1];
int head, tail;
 
void enqueue(Job*);
void dequeue();

int main() {
    int elaps = 0, n;
    int i, q;

    Job u;

    scanf("%d %d", &n, &q);

    for ( i = 1; i <= n+1; ++i){
        scanf("%s", Array[i].name);
        scanf("%d", &Array[i].time);
    }
    head = 1;
    tail = n+1;

    while(head != tail)
    {
        dequeue();
        u = Array[0];
        if(u.time > q) {
            u.time -= q;
            enqueue(&u);
            elaps += q;
        }else{
            elaps += u.time;
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}

void enqueue(Job *job) {
    Array[tail] = *job;
    ++tail;
}

void dequeue() {
    Array[0] = Array[head];
    ++head;
}


Measured memory_bytes: 21080
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;
using ll = long long;

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

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

    cout << n*n-a << endl;
    
    
    return 0;
}


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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main() {
  int h,w;
  cin>>h>>w;
  int ans=0;
  vector<string> field(h);
  int vec[h][w];
  for(int i=0;i<h;i++){
    cin>>field[i];
    for(int j=0;j<w;j++){
      if(field[i][j]=='.'){
        vec[i][j]=3000;
      }
      else{
        vec[i][j]=0;
      }
    }
  }
  for(int a=0;a<5;a++){
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        for(int k=0;k<4;k++){
          int m=i+dx[k];
          int n=j+dy[k];
          if(m<0||m>=h||n<0||n>=w)continue;
          vec[i][j]=min(vec[i][j],vec[m][n]+1);
        }
      }
    }
    for(int i=0;i<h;i++){
      for(int j=w-1;j>=0;j--){
        for(int k=0;k<4;k++){
          int m=i+dx[k];
          int n=j+dy[k];
          if(m<0||m>=h||n<0||n>=w)continue;
          vec[i][j]=min(vec[i][j],vec[m][n]+1);
        }
      }
    }
    for(int i=h-1;i>=0;i--){
      for(int j=0;j<w;j++){
        for(int k=0;k<4;k++){
          int m=i+dx[k];
          int n=j+dy[k];
          if(m<0||m>=h||n<0||n>=w)continue;
          vec[i][j]=min(vec[i][j],vec[m][n]+1);
        }
      }
    }
    for(int i=h-1;i>=0;i--){
      for(int j=w-1;j>=0;j--){
        for(int k=0;k<4;k++){
          int m=i+dx[k];
          int n=j+dy[k];
          if(m<0||m>=h||n<0||n>=w)continue;
          vec[i][j]=min(vec[i][j],vec[m][n]+1);
        }
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans=max(vec[i][j],ans);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5248
function main(input) {
    var args = input.trim();
    var result = {};
    for(var i = 0; args.length > i; i++) {
        result[args[i]] = result[args[i]] ? result[args[i]] + 1 : 1;
    }

    if (Object.keys(result).length !== 2) {
        console.log("No");
        return;
    }

    console.log(result[Object.keys(result)[0]] === 2 ? "Yes" : "No");
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main() {
  ll N, S;
  cin >> N;
  int tmp = N;
  S = 0;
  rep(i,log10(tmp) + 1) {
    S += (N % 10);
    N /= 10;
  }
  if((tmp % S) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3900
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int D = cin.nextInt();
        int[] t = new int[N];
        int[] F = new int[N];

        for (int i = 0; i < N; i++)
        {
            t[i] = cin.nextInt();
            F[i] = cin.nextInt();
        }

        int now = 1;
        int cnt = 0;
        int nowtime = 0;
        long ans = 0;

        for (int i = 0; i < N; i++)
        {
            if(nowtime + (now - 1) + (F[i] - 1) <= t[i])
            {
                ans += cnt * (now - 1L);
                nowtime += (now - 1);
                now = 1;
                cnt = 0;
            }

            int move = Math.Abs(now - F[i]);
            if (nowtime + move > t[i])
            {
                Console.WriteLine(-1);
                return;
            }
            ans += (long)cnt * (t[i] - nowtime);
            cnt++;
            if(cnt > D)
            {
                Console.WriteLine(-1);
                return;
            }
            now = F[i];
            nowtime = t[i];
        }
        ans += (long)cnt * (now - 1);

        Console.WriteLine(ans);
    }
}


class Scanner
{
    string[] s;
    int i;

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

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

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

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

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

    public double nextDouble()
    {
        return double.Parse(next());
    }


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

Measured memory_bytes: 10416
#include <iostream>
#include <string>
#include <algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int serch(int A[],int n,int key){
    A[n]=key;
    int i = 0;
    while(A[i]!= key) i++;
    if(i==n) return 0;
    return i;
}

int main(){
    int N;
    int A[100000];
    cin >> N;
    rep(i,N) cin >> A[i];
    for(int i=1;i<=N;i++){
        cout << serch(A,N,i) + 1<< ' ';
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1000000007;

int main(){
    int n,m;  cin >> n >> m;
    vector<int>dp(n+1);
    dp[0] = 1;
    dp[1] = 1;
    rep(i, m){
        int a;  cin >> a; 
        dp[a] = -1;
    }
    if(n >= 2){
        for(int i = 2; i <= n; i++){
            if(dp[i] == -1) continue;
            for(int j = 1; j <= 2; j++){
                if(dp[i-j] != -1){
                    dp[i] += dp[i-j];
                    dp[i] %= mod;
                }   
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int x = n / 10 / 10;
    if(n > x * 100 + x * 10 + x) cout << (x+1) * 100 + (x+1) * 10 + x+1 << endl;
    else cout << x * 100 + x * 10 + x  << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  string str,ref;
  cin>>str>>ref;
  map<char,int> pos;
  int N = str.size();
  vector<int> next (26,-1);
  vector<vector<int> > mat (26,vector<int>(N,-1));
  
  for (int i = N-1; i >= 0; i--) 
  {
    char c = str[i];
    for (int j = 0; j < 26; j++)
    {
      mat[j][i] = next[j];
    }
    next[(int)(c-'a')] = i;
  }
  for (int i = N-1; i >= 0; i--) 
  {
    char c = str[i];
    for (int j = 0; j < 26; j++)
    {
      if(mat[j][i] == -1)
      mat[j][i] = next[j];
    }
    next[(int)(c-'a')] = i;
    // DEBUG(next);
  }
  // DEBUG(next);
  // DEBUG(mat);
  int index = 0;
  int lcnt = 0;
  int flg = 0;
  for (int i = 0; i < ref.size(); i++)
  {
    int ni = mat[(int)(ref[i]-'a')][index];
    if(i == 0)
    {
      ni = next[(int)(ref[i]-'a')];
      if(ni == -1)
      {
        cout<<-1<<endl;
        return;
      }
      index = ni;
      continue;
    }
    if(ni == -1)
    {
      cout<<-1<<endl;
      return;
    }
    if(ni <= index && i != 0)lcnt++;
    index = ni;
    // DEBUG(index,ni,"\n");
  }

  cout<<lcnt*N + index + 1 - flg<<endl;
  

  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 22976
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	string st;
	int a;
	cin >> a;
	cout << int(pow(a, 3)) << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

int main(){
    int card[3][3];
    rep(i,3)rep(j,3) cin >> card[i][j];
    int n; cin >> n;
    rep(k,n){
        int num; cin >> num;
        rep(i,3)rep(j,3) if(card[i][j]==num) card[i][j] = 0;
    }
    
    int is_not_bingo = 0;
    
    rep(i,3){
        is_not_bingo = 0;
        rep(j,3){
            is_not_bingo += card[i][j];
        }
        if(!is_not_bingo){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    rep(i,3){
        is_not_bingo = 0;
        rep(j,3){
            is_not_bingo += card[j][i];
        }
        if(!is_not_bingo){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    is_not_bingo = 0;
    rep(i,3){
        is_not_bingo += card[i][i];
    }
    if(!is_not_bingo){
        cout << "Yes" << endl;
        return 0;
    }
    
    is_not_bingo = card[2][0] + card[1][1] + card[0][2];
    if(!is_not_bingo){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    
    return 0;
}

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

int main()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if(A1 + A2 + A3 >= 22){
        cout << "bust" << endl;
    }else {
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, w = list(map(int, readline().split()))
    wv = [list(map(int, readline().split())) for _ in range(n)]
    dp = [0] * (w + 1)
    for ww, vv in wv:
        for i in range(w-ww+1, -1, -1):
            if i + ww <= w:
                dp[i+ww] = max(dp[i+ww], dp[i] + vv)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 39664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong h, w, k;
char s[305][305];
llong ans[305][305];

bool check(llong x, llong y) {
    for (int i = y; i < h; i++) {
        if (s[i][x] == '#') return true;
    }

    return false;
}

int main() {
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s[i][j];
        }
    }

    llong id = 1;
    for (int j = 0; j < w; j++) {
        if (!check(j, 0)) continue;

        for (int i = 0; i < h; i++) {
            ans[i][j] = id;
            if (s[i][j] == '#' && check(j, i + 1)) id++;
        }
        id++;
    }

    for (int j = w - 1; j >= 0; j--) {
        if (ans[0][j] != 0) continue;
        
        for (int i = 0; i < h; i++) {
            ans[i][j] = ans[i][j + 1];
        }
    }
    for (int j = 0; j < w; j++) {
        if (ans[0][j] != 0) continue;
        
        for (int i = 0; i < h; i++) {
            ans[i][j] = ans[i][j - 1];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
	long long int a, b, c;
	scanf("%lld%lld%lld", &a, &b, &c);
	if(c<=a+b+1)
	{
		printf("%lld\n", b+c);
	}
	else
	{
		printf("%lld\n", a+2*b+1);
	}
}

Measured memory_bytes: 128
object Main extends App {

  val age = io.StdIn.readLine.toInt

  val out = age match {
    case 1 => "Hello World"
    case 2 => {
      val A = io.StdIn.readLine.toInt
      val B = io.StdIn.readLine.toInt
      (A + B).toString
    }
  }

  println(out)
}


Measured memory_bytes: 27320
import math
n=int(input())
while n != 0 :
	sums = 0.0
	s = list(map(float,input().split()))
	m = sum(s)/n
	for i in range(n):
		sums += ((s[i]-m)**2)/n
	print(math.sqrt(sums))
	n = int(input())


Measured memory_bytes: 5776
n = int(input())
d_l = list(map(int, input().split()))
d_l = sorted(d_l)
if len(d_l) %2 != 0:
    print(0)
else:
    idx = int(len(d_l)/2)
    abc = d_l[idx-1]
    agc = d_l[idx]
    print(agc-abc)

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

int main(){
	int a,b;
  	
  	cin >> a >> b;
  
  	if((a+b)%2 == 0)	cout << (a+b)/2 << endl;
  	else				cout << (a+b+1)/2 << endl;
  
  	return 0;
}

Measured memory_bytes: 256
def RunLengthEncoding(S):
    res = []
    N = len(S)
    i = 0
    while i < N:
        cnt = 1
        while i < N - 1 and S[i] == S[i + 1]:
            cnt += 1
            i += 1
        res.append((S[i], cnt))
        i += 1
    return res


S = input()
rle = RunLengthEncoding(S)
ans = 0
for k, v in rle:
    if k == "R":
        ans = max(ans, v)

print(ans)

Measured memory_bytes: 9132
# pythonの場合、ライブラリ関数でgcdがある？ただし、配列まとめてというわけではない模様
from math import gcd

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

	pc = True
	maxA = max(A)

	cnts = [ 0 for _ in range(maxA+1) ]
	for a in A:
		cnts[a] += 1
	for i in range(2,maxA):
		if pc:
			# 素因数ごとに、A内での登場回数を数える
			# 2つあったらその2つのcommon dividerとして、1以外にそれがあることが確定する
			cnt = 0
			for j in range(i,maxA+1,i):
				cnt += cnts[j]
				if 1 < cnt:
					# Aの素因数で重複があれば、pcでない
					pc = False
					break

	sc = False

	if pc == False:
		gcdResult = 0
		for a in A:
			# 配列全要素に対してgcdを呼んでるが、結果的に、それが1になればsc、ならなければnot sc
			gcdResult=gcd(gcdResult,a)
		if gcdResult == 1:
			sc = True

	if pc:
		print("pairwise coprime")
	elif sc:
		print("setwise coprime")
	else:
		print("not coprime")






if __name__ == "__main__":
	main()



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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define present(t, x) (t.find(x) != t.end())
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

void solve(){
	int n,d;
	cin>>n>>d;
	int cnt=0;
	FOR(i,0,n){
		int x,y;cin>>x>>y;
		if(1LL*x*x+1LL*y*y<=1LL*d*d){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}
int main(){
	solve();
	return 0;
}

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> hv, hc;
	hv.reserve(n);
	int input = 0;
	for (int i = 0; i < n; i++) {
		cin >> input;
		hv.push_back(input);
		hc.push_back(INT_MAX);
	}

	hc[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j < 0)
				break;
			hc[i] = min(hc[i], hc[i - j] + abs(hv[i] - hv[i - j]));
		}
	}
	cout << hc[n - 1];
}


Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ll long long int
#define inf 1450000090
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define nax 100010
#define mp make_pair
#define pi pair <int , int>
#define pii pair < int , pair <int ,int > >
#define MOD 1000000007
using namespace std;
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ll x,y;
  sdl(x);
  sdl(y);
  ll a,b,c;
  ll ans = 100010*1ll*100000;
  for(int i=1;i<x;i++) // y*i
  {
      ll done = y*1ll*i;
      ll left = x*y-done; // Y*(X-I)
      if(y%2 == 0)
        ans = min(ans,abs(done-left/2));
      else
        ans = min(ans,max(done,max((y/2+1)*(x-i),(y/2)*(x-i)))- min(done,min((y/2+1)*(x-i),(y/2)*(x-i))));
      if((x-i)%2 == 0)
        ans = min(ans,abs(done-left/2));
      else
        ans = min(ans,max(done,max(((x-i)/2)*(y),((x-i)/2+1)*(y)))- min(done,min(((x-i)/2)*(y),((x-i)/2+1)*(y))));
  }
  for(int i=1;i<y;i++) // x*i
  {
    ll done = x*1ll*i;
    ll left = x*y-done;
    if(x%2 == 0)
        ans = min(ans,abs(done-left/2));
      else
        ans = min(ans,max(done,max((x/2+1)*(y-i),(x/2)*(y-i)))- min(done,min((x/2+1)*(y-i),(x/2)*(y-i))));
      if((y-i)%2 == 0)
        ans = min(ans,abs(done-left/2));
      else
        ans = min(ans,max(done,max(((y-i)/2)*(x),((y-i)/2+1)*(x)))- min(done,min(((y-i)/2)*(x),((y-i)/2+1)*(x))));
  }
  printf("%lld\n",ans);
  return 0;
}  

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int n, k, r, s, p;
string t;

int point(char x)
{
	if (x == 'r')
		return p;
	else if (x == 's')
		return r;
	else if (x == 'p')
		return s;
	return 0;
}

int main()
{
	cin >> n >> k >> r >> s >> p >> t;

	int score = 0;

	for (int i = 0; i < n; i++) {
		if (t[i] == '0') {
			continue;
		}
		else if (i + k < n && t[i] == t[i + k]) {
			score += point(t[i]);
			t[i + k] = '0';
		}
		else {
			score += point(t[i]);
		}
	}
	cout << score << endl;
}

Measured memory_bytes: 512