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

int main() {
  string S;
  cin >> S;
  int n = S.size();
  ll ans = 0;
  for (int i=0; i<(1<<(n-1)); i++) {
    ll a = 0;
    for (int j=0; j<n-1; j++) {
      a += S[j] - '0';
      if (i & (1<<j)) {
        ans += a;
        a = 0;
      }
      a *= 10;
    }
    ans += a + S[n-1] - '0';
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int digitSum(int n){
    int ans=0;

    for(;;){
        ans += n%10;
        n=n/10;
        if(n==0) break;
    }

    return ans ;


}

int main(){
   int N;
   cin>>N;
   int ans = 999999999;

   for(int i=1;i<N;i++){
       int pre = digitSum(i) + digitSum(N-i);
       ans = min(ans,pre);
   }

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

 



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

int main() {
    int a[3000], n;
    cin >> n;
    vector<vector<long>> dp (n+1, vector<long> (n+1));
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int L = n-1; L >= 0; L--) {
        for (int R = L; R < n; R++) {
            dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
        }
    }
    cout << dp[0][n-1];
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> g[MAXV];
int id[MAXN][MAXN];
int getid(int i, int j){
    if(i > j) swap(i,j);
    return id[i][j];
}
bool visited[MAXV];
bool calced[MAXV];
int dp[MAXV];

int dfs(int v){
    if(visited[v]){
        if(!calced[v]) return -1;
        return dp[v];
    }
    visited[v] = true;
    dp[v] = 1;
    for(int u : g[v]){
        int res = dfs(u);
        if(res == -1) return -1;
        dp[v] = max(dp[v], res+1);
    }
    calced[v] = true;
    return dp[v];
}

int main(){
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n){
        rep(j,n-1){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int v = 0;
    rep(i,n){
        rep(j,n){
            if(i < j) id[i][j] = v++;
        }
    }
    rep(i,n){
        rep(j,n-1){
            a[i][j] = getid(i, a[i][j]);
        }
        rep(j,n-2){
            g[a[i][j+1]].push_back(a[i][j]);
        }
    }
    int ans = 0;
    rep(i,v){
        int res = dfs(i);
        if(res == -1){
            puts("-1");
            return 0;
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
}


Measured memory_bytes: 38528
W, H, N  = map(int,input().split()) 
l = 0; r = W; u = H; d = 0 

for i in range(N):
    x, y, a = map(int,input().split()) 
    if a == 1:
        l = max(l,x) 
    elif a == 2:
        r = min(r,x) 
    elif a == 3:
        d = max(d,y) 
    else:
        u = min(u,y) 

print(max(0,(r-l))*max(u-d, 0)) 

Measured memory_bytes: 9208
import sys
n = int(input())
s = [int(input()) for i in range(n)]
s = sorted(s)
if sum(s) % 10 != 0:
  print(sum(s))
  sys.exit()
elif all([ss % 10 == 0 for ss in s]):
  print(0)
  sys.exit()
else:
  for i in s:
    if (sum(s) - i) % 10 != 0:
      print(sum(s) - i)
      sys.exit()


Measured memory_bytes: 63216
N = int(input())
A = list(map(int,input().split()))
if N > 0 and A[0] > 0:
	print(-1)
	exit()
if N == 0:
	if A[0] == 1:
		print(1)
	else:
		print(-1)
	exit()

mid_node = [(0,0) for i in range(N+1)]
for i in range(N-1, -1, -1):
	m,M = mid_node[i+1]
	child_leaf = A[i+1]
	mid_node[i] = ((child_leaf + m + 1)//2, child_leaf + M)

def between(n,a,b):
	return a <= n and n <= b
ans = [0 for i in range(N+1)]
if not between(1, mid_node[0][0], mid_node[0][1]):
	print(-1)
	exit()

ans[0] = (1, 0)
for i in range(1, N+1):
	b_m = ans[i-1][0]
	node_min, node_max = mid_node[i][0] + A[i], mid_node[i][1] + A[i]
	candidate_min, candidate_max = b_m, b_m*2
	if candidate_min > node_max or candidate_max < node_min:
		print(-1)
		exit()
	node = min(candidate_max, node_max)
	ans[i] = (node - A[i], A[i])
print(sum([a+b for a,b in ans]))

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

int main(){
  int n;
  cin >> n;
  int x[n],y[n];
  for(int i=0;i<n;i++) cin >> x[i] >> y[i];
  if(n==1) cout << 1 << endl;
  else{
    int ans=n;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        int count=n;
        if(i!=j){
          int a=x[i]-x[j];
          int b=y[i]-y[j];
          for(int k=0;k<n;k++){
            for(int l=0;l<n;l++){
              if(x[k]-a==x[l]&&y[k]-b==y[l]){
                count--;
              }
            }
          }
          ans=min(ans,count);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = 0

    for i in range(N):
        for j in range(i+1,N):
            if L[i] == L[j]:
                continue
            for k in range(j+1,N):
                if (L[j] == L[k]) | (L[k] == L[i]):
                    continue
                temp = [L[i], L[j], L[k]]
                temp = sorted(temp)
                if temp[0] + temp[1] > temp[2]:
                    res += 1

    print(res)



main()


Measured memory_bytes: 9200
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
string grid[2001];
int vert[2001][2001];
int hori[2001][2001];

int main(){
    int h,w;

    cin >> h >> w;
    for(int i=0;i<h;i++){
        cin >> grid[i];
    }

    // vertical
    for(int x=0;x<w;x++){
        int range = 0;
        int light_begin = 0;
        for(int y=0;y<h;y++){
            if(grid[y][x]=='.'){
                range++;
                if(y==h-1){
                    for(int i=light_begin;i<=y;i++){
                        vert[i][x] = range;
                    }
                }
            } else {
                vert[y][x] = 0;
                for(int i=light_begin;i<y;i++){
                    vert[i][x] = range;
                }
                light_begin = y+1;
                range = 0;
            }
        }
    }

    // horizontal
    for(int y=0;y<h;y++){
        int range = 0;
        int light_begin = 0;
        for(int x=0;x<w;x++){
            if(grid[y][x]=='.'){
                range++;
                if(x==w-1){
                    for(int i=light_begin;i<=x;i++){
                        hori[y][i] = range;
                    }
                }
            } else {
                hori[y][x] = 0;
                for(int i=light_begin;i<x;i++){
                    hori[y][i] = range;
                }
                light_begin = x+1;
                range = 0;
            }
        }
    }

    int ans = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans = max(ans, vert[i][j]+hori[i][j]-1);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
double calc(ll x){
	ll y=10,len=1,sum=0,res=x;
	while (y<=x) y*=10,len++;
	while (len--){
		y/=10;
		sum+=x/y;
		x%=y;
	}
	return res*1.0/sum*1.0;
}
bool ck(ll a){
	ll now=1;
	while (now<=a){
		if (calc(now+a)<calc(a)) return 0;
		now*=10;
	}
	return 1;
}
int main(){
	int k;
	scanf("%d",&k); 
	ll now=0;
	while (k--){
		ll a=1;
		while (1){
			if (ck(now+a)){now+=a; break;}
			a*=10;
		}
		printf("%lld\n",now);
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
xyh = [tuple(map(int, input().split())) for _ in range(N)]

for cx in range(100 + 1):
    for cy in range(100 + 1):
        # すべての中心候補に対して
        H = -1
        for x, y, h in xyh:
            if h > 0:
                t = h + abs(x - cx) + abs(y - cy)
                if H == -1:
                    H = t
                else:
                    if H != t:
                        # 適切な中心を選んでいるときは、すべてのHが一致する
                        break
        else:
            for x, y, h in xyh:
                if h != max(H - abs(x - cx) - abs(y - cy), 0):
                    break
            else:
                if H >= 1:
                    print(cx, cy, H)
                    exit()


Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        sc.close();

        int one = M*1900 + (N-M)*100; //一回でかかる時間

        System.out.println((int)(one * Math.pow(2, M)));
    }
}

Measured memory_bytes: 23892
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var alist = System.Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        foreach(var a in alist)
        {
            if(a % 2 == 0)
            {
                if(a % 3 ==0 || a%5 == 0)
                {
                    continue;
                }
                else
                {
                    System.Console.WriteLine("DENIED");
                    return;
                }
            }
        }

        System.Console.WriteLine("APPROVED");
    }


}



Measured memory_bytes: 13396
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a; 
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	set<ll> ag;
	ag.insert(a);
	ag.insert(b);
	ag.insert(c);
	if (ag.size() == 2)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        char ans[10], c;
        int cursor=0;
        while((c = getchar())!='\n'){
                if(c=='B') cursor--;
                else ans[cursor++] = c;
                if(cursor<0) cursor++;
        }
        for(int i=0; i<cursor; i++) putchar(ans[i]);
        puts("");
        return 0;
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 210, M = 10, INF = 0x3f3f3f3f;

int n, m, k;
int f[N][N];
int r[M];

int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < k; i ++ ) cin >> r[i];
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			if (i == j) f[i][j] = 0;
			else f[i][j] = INF;
	
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		cin >> a >> b >> c;
		f[a][b] = f[b][a] = min(f[a][b], c);
	}
	
	for (int k = 1; k <= n; k ++ )
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
	
	int res = INF;
	sort(r, r + k);
	do
	{
		int t = 0;
		for (int i = 0; i < k - 1; i ++ ) t += f[r[i]][r[i + 1]];
		res = min(res, t);
	}while (next_permutation(r, r + k));
	
	cout << res << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n, k;
	cin >> n >> k;

	ll x[n];
	ll zmcnt = 0;

	rep(i, n){
		cin >> x[i];
		if(x[i] <= 0) zmcnt++;
	}

	if(zmcnt == 0){
		cout << x[k-1]<< endl;
		return 0;
	}

	ll plcnt = n - zmcnt;
	ll pl[plcnt+1];
	ll zm[zmcnt+1];

	pl[0] = 0;
	zm[0] = 0;
	for(ll i = 0; i < zmcnt; i++) zm[i+1] = -x[zmcnt- i - 1];
	for(ll i = 0; i < plcnt; i++) pl[i+1] = x[i + zmcnt];

	/*
	for(ll i = 0; i < zmcnt; i++) cout << zm[i+1] << ",";
	cout << endl;
	for(ll i = 0; i < plcnt; i++) cout << pl[i+1] << ",";
	cout << endl;
	*/

	ll ans = 1e12;
	for(int i = 0; i <= k; i++){
		if(i <= plcnt && k-i <= zmcnt) {
			// cout << i << "," << pl[i] << "," << zm[k-i] << endl;
			ans = min(ans, pl[i] + zm[k-i] * 2);
			ans = min(ans, pl[i] * 2 + zm[k-i]);
		}
	}

	cout << ans << endl;	
}

Measured memory_bytes: 1792
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on July 27, 2018, 9:30 AM
 */

#include <stdio.h>
#include <stdlib.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

/*
 * 
 */

int M[MAX][MAX], d[MAX], f[MAX], color[MAX];
int n, u, k, v, time;

void makeGraph(int size);
void dfs();
void visit(int r);

int main(int argc, char** argv) {
    scanf("%d", &n);
    
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) M[i][j] = 0;
    
    makeGraph(n);
    
    dfs();
    
    for (int ix = 0; ix < n; ++ix) printf("%d %d %d\n", ix+1, d[ix], f[ix]);
    
    return (EXIT_SUCCESS);
}

void makeGraph(int size)
{
    for (int i = 0; i < size; ++i)
    {
        scanf("%d %d", &u, &k);
        u--;
        for (int ix = 0; ix < k; ++ix)
        {
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
}

void dfs()
{
    for (int i = 0; i < n; ++i) color[i] = WHITE;
    time = 0;
    for (int i = 0; i < n; ++i) if (color[i] == WHITE) visit(i);
}

void visit(int r)
{
    color[r] = GRAY;
    d[r] = ++time;
    for (int i = 0; i < n; ++i) if (M[r][i] == 1) if (color[i] == WHITE) visit(i);
    color[r] = BLACK;
    f[r] = ++time;
}


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

int main(){
  int n,m;cin>>n>>m;
  vector<pair<ll,ll>>pa;
  for(ll i=0;i<n;i++){
      ll a; cin>>a;
      pa.push_back({a,1});

  }
  for(ll i=0;i<m;i++){
      ll b,c; cin>>b>>c;
      pa.push_back({c,b});
  }
  sort(pa.rbegin(),pa.rend());
  ll ans=0;
  ll cnt=0;
  for(ll i=0;i<pa.size();i++){
      if(cnt+pa[i].second<=n){
          ans+=pa[i].second*pa[i].first;
          cnt+=pa[i].second;
      }
      else{
          if(cnt<=n){
              ans+=(n-cnt)*pa[i].first;
              cnt=n;
          }
      }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7444
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	char a;
	cin>>a;
	if(a>='A' and a<='Z')
		cout<<'A';
	else
		cout<<'a';
	
	return 0; 	
}

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

int main() {
	vector<char> t={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  	string s;cin>>s;
  	
  	for(int i=0;i<26;i++){
      bool a=false;
     	 for (int j=0;j<s.size();j++){
    		if(s.at(j)==t.at(i)){
            	a=true;
            }     	
         }
      if(a==false){
      	cout<<t.at(i)<<endl;
        return 0;
      }
    }
      	cout<<"None"<<endl;
}
  	


Measured memory_bytes: 512
n, m = gets.split.map(&:to_i)
students = n.times.map{gets.split.map(&:to_i)}
checks = m.times.map{|i| gets.split.map(&:to_i) << i+1}
students.each{|p|
	puts checks.min_by{|q| p.zip(q).map{|d| d.reduce(:-).abs}.reduce(:+)}[2]
}

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	
   	int n;
   	cin >> n;
   	int res = 0;
   	fi(1, n + 1) {
   		int d = n / i;
   		res += i * (d + 1) * d  / 2;
    } 
   	cout << res << '\n';
}

Measured memory_bytes: 3640
#include<stdio.h>

int main(){
  int W, H, x, y, r;

  scanf("%d %d %d %d %d",&W, &H, &x, &y, &r);

  if ( x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
    printf("Yes\n");
  else
    printf("No\n");


  return 0;
}

Measured memory_bytes: 584
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l[] = new int[n];
        long ans =0;

        for(int i=0;i<n;i++)l[i]=sc.nextInt();

        Arrays.sort(l);

        for(int i=0;i<n-2;i++)for(int j=i+1;j<n-1;j++){
            int max = l[i]+l[j];

            int max_index = Arrays.binarySearch(l,max);
            if(max_index<0)max_index = -(max_index+2);
            else{
                while(true){
                    max_index--;
                    if(l[max_index]!=max)break;
                }
            }

            int min_index = j+1;
            int tri = max_index-min_index+1;
            //System.out.println(l[i]+" "+l[j]+" "+min_index+" "+max_index);
            ans += tri;
        }
        System.out.println(ans);



    }
}


Measured memory_bytes: 26380
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct SCC{
  vector<vector<int> > G,R,T,C;
  vector<int> vs,used,blg;
  SCC(){}
  SCC(int n):G(n),R(n),used(n),blg(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(int v){
    used[v]=1;
    for(int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(int v,int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  int build(){
    int n=G.size();
    for(int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }
    for(int v=0;v<n;v++)
      for(int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
  int operator[](int k) const{return blg[k];};
};

struct TwoSat{
  int n;
  SCC scc;
  TwoSat(int n):n(n),scc(n*2){}
  int negate(int v){return (n+v)%(n*2);}
  void add_if(int u,int v){
    // u -> v <=> !v -> !u
    scc.add_edge(u,v);
    scc.add_edge(negate(v),negate(u));
  }
  void add_or(int u,int v){
    // u or v <=> !u -> v
    add_if(negate(u),v);
  }
  void add_nand(int u,int v){
    // u nand v <=> u -> !v
    add_if(u,negate(v));
  }
  void set_true(int v){
    //  v <=> !v ->  v
    scc.add_edge(negate(v),v);
  }
  void set_false(int v){
    // !v <=>  v -> !v
    scc.add_edge(v,negate(v));
  }
  vector<int> build(){
    scc.build();
    vector<int> res(n);
    for(int i=0;i<n;i++){
      if(scc[i]==scc[n+i]) return {};
      res[i]=scc[i]>scc[n+i];
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;

  TwoSat G(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.add_if(a,b);
  }
  G.build();

  for(int i=0;i<n;i++){
    int flg=0;
    for(int j=0;j<n;j++){
      if(G.scc.blg[i]!=G.scc.blg[j]) continue;
      if(flg) cout<<" ";
      flg=1;
      cout<<j+1;
    }
    cout<<endl;
  }

  return 0;
}



Measured memory_bytes: 5588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

int main(void) {
  int a, b;
  cin >> a >> b;
  puts(a+b == 15 ? "+" : a*b == 15 ? "*" : "x");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, ma, mb;
int a[45], b[45], c[45];
int dp[45][405][405];

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

  cin >> n >> ma >> mb;
  REP(i, n) {
    cin >> a[i + 1] >> b[i + 1] >> c[i + 1];
  }
  REP(i, n + 1) {
    REP(j, 401) {
      REP(k, 401) {
        dp[i][j][k] = INF;
      }
    }
  }
  REP(i, n + 1) {
    dp[i][0][0] = 0;
  }
  FOR(i, 1, n + 1) {
    FOR(j, 0, 401) {
      FOR(k, 0, 401) {
        if(j - a[i] >= 0 && k - b[i] >= 0) {
          dp[i][j][k] = min(dp[i - 1][j - a[i]][k - b[i]] + c[i], dp[i - 1][j][k]);
        } else {
          dp[i][j][k] = dp[i - 1][j][k];
        }
      }
    }
  }

  int ans = INF;
  int i = ma, j = mb;
  while(i <= 400 && j <= 400) {
    ans = min(ans, dp[n][i][j]);
    i += ma;
    j += mb;
  }

  cout << (ans == INF ? -1 : ans) << endl;
}


Measured memory_bytes: 26880
# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

from itertools import count

X = int(input())

for x in count(X):
    if len(tuple(prime_factors(x))) == 1:
        print(x)
        break

Measured memory_bytes: 62560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
  int N;
  int K;
  int i = 1;

  scanf("%d %d", &N, &K);
  while (pow(K, i) <= N) i++;
  printf("%d\n", i);

  return (0);
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n;

	cin >> n;

	vector<pair<ll, pair<ll, ll>>> v(n);

	REP(i, n) {
		ll t, x, y;
		cin >> t >> x >> y;
		v[i] = make_pair(t, make_pair(x, y));
	}

	pair<ll, ll> now = make_pair(0, 0);
	ll nowt = 0;

	REP(i, n) {
		ll a = abs(v[i].second.first - now.first) + abs(v[i].second.second - now.second);
		if ((v[i].first - nowt) < a || (v[i].first - nowt) % a % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}

		now = v[i].second;
		nowt = v[i].first;
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 2560
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
int main()
{
  string s;
  cin >> s;

  s[3] = '8';

  cout << s << endl;
  
  return 0;
}


Measured memory_bytes: 256
input = gets.to_i
count = 1
if input == 4 or input == 1 or input == 2 then
  count = 1
else
until input==4 do
if input%2==0 then
    input = input/2
    count +=1
else
    input = input*3+1
    count +=1
end
end
end
puts count+3

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if (0<=y-r && y+r<=H && 0<=x-r && x+r<=W){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
 return 0;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG


void solve(std::string s){
    if(s.size() == 2){
        if(s.at(0) == s.at(1)){
            printf("1 2\n");
        }else{
            printf("-1 -1\n");
        }
        return;
    }

    for(int i=0; i + 3 <= s.size(); i++){
        // check s[i:i+3]
        if(s.at(i) == s.at(i+1) || s.at(i+1) == s.at(i+2) || s.at(i+2) == s.at(i)){
            printf("%d %d\n", i+1, i+3);
            return;
        }
    }

    printf("-1 -1\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(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, mn = INT_MAX, no, cnt = 0;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> no;
        mn = min(no, mn);
        if(mn >= no) {
            cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,m;
  cin>>n>>m;
  vpl s(m);
  REP(i,m)cin>>s[i].FI>>s[i].SE;
  REP(i,m)s[i].FI--;

  ll i;
  if(n==1)
    i=0;
  else
    i=pow(10,n-1);

  for(i; i<pow(10,n); i++){
    string a = to_string(i);
    bool flag = true;
    REP(j,m){
      if(a[s[j].FI]-'0' != s[j].SE)
        flag = false;
    }

    if(flag){
      cout<<i<<endl;
      return 0;
    }
  }

  cout<<-1<<endl;

}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();

		long[] a = new long[5];
		for (int i = 0; i < 5; i++) a[i] = sc.nextLong();
		Arrays.sort(a);

		System.out.println(N % a[0] == 0 ? (N / a[0]) + 4 : N / a[0] + 5);
	}

}

Measured memory_bytes: 22740
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l[] = new int [n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    int answer =0;
    Arrays.sort(l);
    for(int i=2;i<n;i++){ //長い方を止め
      for(int j=0;j<i-1;j++){ //短い方を止め
        //長い方と短い方の間の流さでOKな組み合わせの数を、にぶたんで検索する
        answer = answer + okNum(l,j,i);
      }
    }
    System.out.println(answer);
    
  }
  
  //配列、短い方の添字、長い方の添字から、OKな組み合わせを検索する
  public static int okNum(int length[],int lowerInd,int upperInd){
    int upperLen = length[upperInd];
    int keepSup = upperInd;
    int lowerLen = length[lowerInd];
  //長辺の長さ<短辺の長さ+中辺の長さとなる中辺の数を返却したい  
    //⇔長辺-短辺<中辺となる中辺の数
    int target = upperLen - lowerLen;
    int cnt =0;
    int tmpLen=0;
    int tmpInd=0;
    boolean flg = true;
    while(flg){
      tmpLen=length[(upperInd+lowerInd)/2];
      tmpInd=(upperInd+lowerInd)/2;
      if(target<tmpLen){
        upperInd=tmpInd;
      }else{
        lowerInd=tmpInd;
      }
      if(upperInd-lowerInd<2){
        flg=false;
        tmpInd=upperInd;
      }
    }
    return keepSup-tmpInd;
  }
  
}


Measured memory_bytes: 28264
n,k = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]

ind =1
dind = a[ind-1]
aset = set([1,])
arr = [1,]

while dind not in aset:
    ind = dind
    dind = a[ind-1]
    arr.append(ind)
    aset.add(ind)


# print(arr, dind)
ui = arr.index(dind)
offset = ui+1
unit = arr[ui:]
# print(unit,offset)
if k<offset:
    print(arr[k])
else:
    k-=offset
    k=k%len(unit)
    if k==len(unit)-1:
        k=0
    else:
        k+=1
    print(unit[k])

    

Measured memory_bytes: 124972
import java.util.*;

public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String str = sc.nextLine();
                sc.close();
        //int N = Integer.parseInt(str);

                int count=0;

        for(int i = 0; i < str.length(); i++){
            count += str.charAt(i) - '0';
        }


                System.out.println((count%9 == 0) ? "Yes" : "No");
        }
}



Measured memory_bytes: 41288
object Main extends App {
  import scala.collection.mutable.{Set => mSet}
  val Array(n,k) = readLine.split(" ").map{_.toInt}
  val d:mSet[Int] = mSet()
  readLine.split(" ").map{_.toInt}.toList.foreach{d += _}
  var payment:mSet[Int] = mSet()
  for (x <- n.toString.map{_.asDigit}) payment += x
  var ans = n
  while(!(d & payment).isEmpty) {
    ans += 1
    payment = mSet()
    for (x <- ans.toString.map{_.asDigit}) payment += x
  }
  println(ans)
}

Measured memory_bytes: 47372
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import fractions
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**21


def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
        cost, cur = heapq.heappop(h)
        if costs[cur] != INF:
            continue
        costs[cur] = cost
        for edge in graph[cur]:
            ecost, tgt = edge
            if costs[tgt] == INF:
                heapq.heappush(h, (cost + ecost, tgt))

    return costs


def main():
    money = 10 ** 15
    n, m, s, t = getlist()
    s -= 1; t -= 1

    yengraph = [[] for _ in range(n)]
    snuukgraph = [[] for _ in range(n)]
    for i in range(m):
        a, b, c, d = getlist()
        a -= 1; b -= 1
        yengraph[a].append([c, b])
        yengraph[b].append([c, a])
        snuukgraph[a].append([d, b])
        snuukgraph[b].append([d, a])

    ycost = dijkstra(yengraph, s, n)
    scost = dijkstra(snuukgraph, t, n)

    sumcost = []
    idx = 1
    for y, s in zip(ycost, scost):
        sumcost.append((y+s, idx))
        idx += 1
    sumcost.sort()
    idx = 0
    for i in range(n):
        while True:
            ans, cid = sumcost[idx]
            if cid > i:
                print(money - ans)
                break
            else:
                idx += 1
    # print(ycost)
    # print(scost)
    # print(sumcost)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 105652
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define MAXN 100000
using namespace std;
int main(){
       ll n;cin>>n;
	string strings;
	cin>>strings;
	ll right=0,gets=0,burys=0;
	for(ll i=0;i<n;i++){
		if(strings[i]=='R')right++;
		else if(strings[i]=='G')gets++;
		else burys++;
	}
	ll anss=right*gets*burys;
	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			if(strings[i]==strings[j])continue;
			ll k=j+(j-i);
			if(k>=n)continue;
			if(strings[k]==strings[i] || strings[k]==strings[j])continue;
			anss--;
		}
	}
	cout<<anss;
 
    return 0;
}


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

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".")
      break;
    vector<int> stack;
    int sz = 0;
    int now = 0;
    int n = s.size();
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (s[i] == '(') {
        stack.push_back(')');
      } else if (s[i] == '[') {
        stack.push_back(']');
      } else if (s[i] == ')' || s[i] == ']') {
        if (stack.size() == 0) {
          ok = false;
          break;
        } else {
          if (stack[stack.size() - 1] == s[i]) {
            stack.pop_back();
          } else {
            ok = false;
            break;
          }
        }
      }
    }
    if (stack.size() > 0)
      ok = false;
    if (ok) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 2992
#include<bits/stdc++.h>
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define Rep(i,n)        for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

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


    LL sum=0;


    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                sum+=GCD(GCD(i,j),k);
            }
        }
    }
    cout<<sum;

   return 0;
}


Measured memory_bytes: 3532
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int total = A * X + B * Y;
		if (X > Y) {
			for (int i = 0; i <= 2 *X ;  i += 2) {

				if (total > A * Math.max(0, X - 0.5 * i) + B * Math.max(0, Y - 0.5 * i) + C * i) {
					total = (int) (A * Math.max(0, X - 0.5 * i)+ B * Math.max(0, Y - 0.5 * i) + C * i);
				}
			}
		} else {
			for (int i = 0; i <=  2 *Y; i += 2) {
				if (total > A * Math.max(0, X - 0.5 * i) + B * Math.max(0, Y - 0.5 * i) + C * i) {
					total = (int) (A * Math.max(0, X - 0.5 * i) + B * Math.max(0, Y - 0.5 * i) + C * i);
				}
			}
		}
		System.out.println(total);

	}
}


Measured memory_bytes: 23252
l = sorted(list(map(int,input().split())))
C,B,A = l[0],l[1],l[2]
cnt = 0
while A != B or B != C or C != A:
	if A == B:
		if C < A:
			C += 2
			cnt += 1
		elif C > A:
			A += 1
			B += 1
			cnt += 1
	else:
		B += 1
		C += 1
		cnt += 1
print(cnt)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!

N = int(input())
res = 0

for i in range(N):
    inp = input().split(' ')
    xi = float(inp[0])
    ui = inp[1]
    
    if ui == 'JPY':
        res += xi
    else:
        res += xi * 380000

print(res)


Measured memory_bytes: 2940
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <deque>
#include <map>
#include <bits/stdc++.h>
using namespace std;

double rad_to_deg(double rad){
    return 360*rad / (2*M_PI);
}

int main(void){
    
    double a,b,x;
    
    cin >> a >> b >> x;

    double maxV = a*a*b;
    double tan_;
    if(maxV > 2*x){
        double tmp = a*b*b;
        double tmp_ = 2*x;
        tan_ = tmp / tmp_;
        }
    else if(maxV < 2*x){
        double tmp_ = b/a;
        double tmp = x/pow(a,3);
        tan_ = 2*(tmp_ - tmp);
        tan_ = 2*(maxV - x) / pow(a,3);
    }
    else{
        tan_ = b/a;
    }

    double rad_theta = atan(tan_);
    double deg_theta = rad_to_deg(rad_theta);

    cout << fixed;
    cout << setprecision(10) << deg_theta << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll dp[n];
    for (ll i = 0; i < n; i++) {
        dp[i] = INT_MAX;
    }
    // for (ll i = 0; i < n; i++) {
    //     cout << a[i] << " " << dp[i] << endl;
    // }
    dp[0] = 0;
    for (ll i = 1; i < n; i++) {
        for (ll j = 1; j <= k; j++) {
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

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

typedef struct{
  int num;
  int point;
} Data;


Data segTree[2100000];
int segSize;

void reSize(int n){
  segSize = 1;
  while(segSize < n){
    segSize *= 2;
  }
}


void init(int n){
  for(int i = 0;i < segSize;i++){
    if(i < n){
      segTree[i+segSize-1].point = 0;
      segTree[i+segSize-1].num = i;
    }
    else segTree[i+segSize-1].point = INT_MIN;
  }

  for(int i = segSize-2;i >= 0;i--){
    segTree[i] = segTree[i*2+1];
  }

}


void update(int i,int val){
  i = segSize-1+i;
  segTree[i].point += val;
  while(i > 0){
    i = (i-1) / 2;
    if(segTree[i*2+1].point >= segTree[i*2+2].point){
      segTree[i] = segTree[i*2+1];
    }else{
      segTree[i] = segTree[i*2+2];
    }
  }

  return;
}

int main(){
  int n,r,l;
  cin >> n >> r >> l;

  reSize(n);
  init(n);
  int d,t,x;


  int times[100000] = {};

  int mae = 0;
  for(int z = 0;z < r;z++){
    cin >> d >> t >> x;

    if(mae != 0) times[segTree[0].num] += t-mae;

    update(d-1,x);

    mae = t;
  }

  times[segTree[0].num] += l-mae;

  Data max;
  max.point = 0;
  for(int i = 0;i < n;i++){
    if(max.point < times[i]){
      max.point = times[i];
      max.num = i+1;
    }
  }
  cout << max.num << endl;

  return 0;
}







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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    ll n, m;
    map<int, int> mp;
    cin >> n;
    m = n;
    for (ll i = 2; i * i <= m; ++i) {
        while (n % i == 0) {
            n /= i;
            mp[i]++;
        }
    }
    if (n > 1) {
        mp[n]++;
    }
    int ans = 0;
    for (auto t : mp) {
        int cnt = t.second;
        int k = 1;
        while (k <= cnt) {
            ans++;
            cnt -= k;
            k++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> s;
    int dema=0, demc=0, posc;
    int leng=s.size();
    s=' '+s;
    rep(i, 1, leng) {
        dema+=s[i]=='A';
        if(s[i]=='C') {
            ++demc;
            posc=i;
        }
        if(s[i]!='A'&&s[i]!='C'&&s[i]>'A'&&s[i]<='Z') return cout << "WA", 0;
    }
    if(dema!=1||demc!=1) return cout << "WA", 0;
    if(posc<3||posc==leng) return cout << "WA", 0;
    cout << "AC";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
def query(q):
    print('?', end = ' ')
    for i in q[:-1]:
        print(i+1, end = ' ')
    print(q[-1]+1)
back = []
q = list(range(0, N))
query(q)
T = input()
ok = 0
ng = N
c = T
while ng-ok>1:
    mid = (ok+ng)//2
    query(list(range(mid, mid+N)))
    T = input()
    if T == c:
        ok = mid
    else:
        ng = mid
eq1 = list(range(ng, ng+N-1))
eq2 = list(range(ng-1))+list(range(ng+N, N*2))
a = ng

ans = ['n']*(N*2)
for i in range(N*2):
    if a<=i<a+N-1:
        query(eq2+[i])
        T = input()
        if T == '-1':
            a = 1/0
        if T == 'Red':
            ans[i] = 'R'
        else:
            ans[i] = 'B'
    else:
        query(eq1+[i])
        T = input()
        if T == '-1':
            a = 1/0
        if T == 'Red':
            ans[i] = 'R'
        else:
            ans[i] = 'B'
print('!', end = ' ')
print(*ans, sep = '')





Measured memory_bytes: 44740
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl v(n+1);  // v[i] : 問題iをACしたら1。していなければ0
    set<ll> st;
    vl cnt(n+1);
    rep(i, m) {
        ll p;
        string s;
        cin >> p >> s;
        if(s == "AC") {
            st.insert(p);
            v[p] = 1;
        }
        if(s == "WA" && v[p] == 0) {
            cnt[p]++;
        }
    }

    ll ans = 0;
    rep(i, n+1) {
        if(v[i]) {
            ans += cnt[i];
        }
    }

    cout << st.size() << " " << ans << endl;
    re0;
}

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


int main(){
	long long n;
	cin>>n;
	long long v[n];
	long long wt[n];
	long long W;
	cin>>W;
	for(long long i=0;i<n;i++){
		cin>>wt[i];

		cin>>v[i];
	}

	long long dp[n+1][W+1]={0};


	for(long long i=0;i<=n;i++){
		for(long long j=0;j<=W;j++){
			if(i==0||j==0)
				dp[i][j]=0;
			else if(wt[i-1]>j)
				dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
			}
		}
	}

	/*for(long long i=0;i<n;i++){
		for(long long j=0;j<W;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/

	cout<<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    if(n==m){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  set<string> SET;
  int N;cin>>N;
  FOR(i,0,N) {
    string s;
    cin >> s;
    SET.insert(s);
  }
  int M;cin>>M;
  bool open = false;
  FOR(i,0,M) {
    string s;
    cin >> s;
    if(SET.count(s)) {
      if(!open) {
        cout << "Opened by " << s << endl;
        open = true;
      } else {
        cout << "Closed by " << s << endl;
        open = false;
      }
    } else {
      cout << "Unknown " << s << endl;
    }
  }
  return 0;
}

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

int main() {
	// your code goes here
    int x,y,m=0;
    cin >> x >> y;
    if(x<=3) m+=(4-x)*100000;
    if(y<=3) m+=(4-y)*100000;
    if(x==1&&y==1) m+=400000;
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256