akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
    int A,B,C,X,Y,maxim,minim,rem,ans;
    cin >> A >> B >> C >> X >> Y;
    if(A+B<C*2){
        cout << A*X + B*Y << endl;
    }else{
        maxim = max(X,Y);
        if(X==maxim){
            rem = A;
        }else{
            rem = B;
        }
        minim = min(X,Y);
        ans = min(C*2*maxim,C*2*minim+rem*(maxim-minim));
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
s1 = s[:2]
s2 = s[2:]
if (int(s1) <= 12 and int(s1) >= 1) and (int(s2) <= 12 and int(s2) >= 1):
  print('AMBIGUOUS')
elif ((int(s1) == 0) or int(s1) > 12) and (int(s2) <= 12 and int(s2) >= 1):
  print('YYMM')
elif ((int(s2) == 0) or (int(s2) > 12)) and (int(s1) <= 12 and int(s1) >= 1):
  print('MMYY')
else:
  print('NA')


Measured memory_bytes: 3064
import math
K=int(input())
ans=0
for a in range(1,K+1):
	for b in range(a,K+1):
		for c in range(b,K+1):
			A=math.gcd(math.gcd(a,b),c)
			if a==b and b==c:
				ans+=A
			elif a==b or b==c:
				ans+=(A*3)
			else:
				ans+=(A*6)
print(ans)



Measured memory_bytes: 9132
#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <=N; ++i) {
		if (i*i == N) {
			cout << i * i << endl;
			return 0;
		}
		else if (i*i>N) {
			cout << (i - 1)*(i - 1) << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int countt = 0;
		int counth = 0;
		
		for(int i = 0; i < n; i++) {
			String taro = sc.next();
			String hanako = sc.next();
			boolean draw = true;
			
			for(int x = 0; x < Math.min(taro.length(), hanako.length()); x++) {
				if(taro.charAt(x) > hanako.charAt(x)) {
					countt += 3;
					draw = false;
					break;
				}else if(taro.charAt(x) < hanako.charAt(x)) {
					counth += 3;
					draw = false;
					break;
				}
			}
			
			if(draw) {
				if(taro.length() > hanako.length()) {
					countt += 3;
				}else if(taro.length() < hanako.length()) {
					counth += 3;
				}else {
					countt++;
					counth++;
				}
			}
		}
		
		System.out.println(countt + " " + counth);
	}
}


Measured memory_bytes: 29496
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <set>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */
void printAns(bool can);

/* main */
int main(){

    int n, q, k;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> k;
        auto it = lower_bound(a.begin(), a.end(), k);
        int dist = distance(a.begin(), it);
        cout << dist << '\n';
    }
}




Measured memory_bytes: 3108
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class ProgramC
    {
        static void Main(string[] args)
        {

            //入力
            string s = Console.ReadLine();
            long ans = 0;
            long temp = 0;
            int[] sum = new int[2019];
            sum[0]++;
            
            for (int i = s.Length - 1;i >= 0; i--)
            {
                
                temp += (s[i] - '0') * modpow(10, s.Length - 1 - i, 2019);
                temp %= 2019;

                sum[temp]++;

            }

            for (int i = 0; i < 2019; i++)
                ans += sum[i] * (sum[i] - 1) / 2;
            

            Console.WriteLine(ans);
            
        }

        //繰り返し二乗法で求める
        static long modpow(long a, long n, long MOD)
        {
            if (n == 0)
                return 1;
            if (n % 2 == 0)
            {
                long temp = modpow(a, n / 2, MOD);
                return temp * temp % MOD;
            }

            return a * modpow(a, n - 1, MOD) % MOD;
        }
    }

}


Measured memory_bytes: 26516
n,m = map(int,input().split())

li2=[input() for i in range(m)]
ab = []
for i in range(m):
    ab.append( [int(x.strip()) for x in li2[i].split()])

ab = sorted(ab,key=lambda x:x[1])

ans_last = ab[0][1]
ans = 1

for i in range(1,m):
    a = ab[i][0]
    b = ab[i][1]
    if b > ans_last and a >= ans_last:
        ans_last = b
        ans += 1

print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

//#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rrep(i,a,b) for (int i = a; i >= b; i--)



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int te=1;
	//cin>>te;
	while(te--){
        int a,k,c,n;
        ll ans=0LL;
        cin>>n>>k;
        vi v;
        rep(i,1,n) {cin>>a; v.pb(a);}
        sort(v.begin(),v.end());
        rep(i,1,k){
        ans+= (ll)v[i-1];
        }
        cout<<  ans<<endl;

	}
	return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,l;
	cin >> n;
	vector<int> b(100000+3,0);
	for(int i = 0; i < n; i++) {
		cin >> l;
		if (l == 0){
			b[l]++;
			b[100000+2]++;
		}
		else{
			b[l] ++;
			b[l - 1] ++;
			b[l + 1] ++;
		}
	}

	int x = -1;
	for(int i = 0; i <= 100000+2; i++) {
		if (b[i] > x){
			x = b[i];
		}
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    char x;
    cin >> x;

    if(x == 'A' || x == 'T')
        x ^= 'A' ^ 'T';
    else
        x ^= 'C' ^ 'G';
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
n = int(input())
b = [int(input()) for _ in range(n)]

b1 = [0] * 3
b2 = [0] * 3
b3 = [0] * 3

for i in b:
    for j in range(3):
        if i == a1[j]:
            b1[j] = 1
for i in b:
    for j in range(3):
        if i == a2[j]:
            b2[j] = 1
for i in b:
    for j in range(3):
        if i == a3[j]:
            b3[j] = 1

if b1[0] == b2[0] == b3[0] ==1 or b1[1] == b2[1] == b3[1] == 1 or b1[2] == b2[2] == b3[2]==1:
    print("Yes")
    exit()
elif b1[0] == b2[1] == b3[2] == 1 or b1[2] == b2[1] == b3[0] ==1:
    print("Yes")
    exit()
elif b1[0] == b1[1] == b1[2] == 1 or b2[0] == b2[1] == b2[2] == 1 or b3[0] == b3[1] == b3[2] == 1:
    print("Yes")
    exit()

print("No")


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){

  int total_stores,last_time,firework_time;

  while(~scanf("%d %d %d",&total_stores,&last_time,&firework_time)){
    int dp[3001];
    memset(dp,0,sizeof(dp));

    int fun[3001];
    int cost[3001];
    for(int store_idx = 0; store_idx < total_stores; store_idx++){
      scanf("%d %d",fun + store_idx,cost + store_idx);
    }

    for(int store_idx = 0; store_idx < total_stores; store_idx++){
      for(int time=last_time;time>=0;time--){
        if(time + cost[store_idx] > last_time) continue;
        if(time < firework_time && firework_time < time + cost[store_idx]) continue;
        dp[time + cost[store_idx]]
          = max(dp[time + cost[store_idx]],dp[time] + fun[store_idx]);
      }
    }
    
    int res = 0;
    for(int time=0;time<=last_time;time++){
      res = max(res,dp[time]);
    }
    printf("%d\n",res);
  }
}

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

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int L = keyboard.nextInt();
		
		String[] SI = new String[N];
		
		for(int i = 0; i < N; i ++) {
			SI[i] = keyboard.next();
		}
		
		Arrays.sort(SI);
		
		for(int i = 0; i < N; i ++) {
			System.out.print(SI[i]);
		}
		keyboard.close();	
	}
}

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

#define N 200010
#define MAX 1000000000000000000

#include <stdio.h>

int main (void) {
    int n, m = 0, l[100], l_tmp, i, j, k, c = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &(l[i]));
    }

    for (i = 0; i < n; i++) {
        for (j = i + 1; j < n; j++) {
            if (l[i] == l[j]) continue;
            for (k = j + 1; k < n; k++) {
                if (l[i] == l[k] || l[j] == l[k]) continue;

                if ((l[i] + l[j] > l[k]) &&
                        (l[j] + l[k] > l[i]) &&
                        (l[k] + l[i] > l[j])){
                    c++;
                }
            }
        }
    }

    printf("%d", c);

    return 0;

}



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

int main(){            
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(abs(x-a) < abs(x-b))  cout << "A" << endl;
	else cout << "B" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main(){
  int N,M;cin>>N>>M;
  string S;cin>>S;
  int now = N;
  vector<int> can;
  rep(i,N+1) {
    if(S[i]=='0') can.push_back(i);
  }
  vector<int> ans;
  while(1) {
    if(now-M<=0) {
      ans.push_back(now);
      break;
    } else {
      int plc = lower_bound(can.begin(),can.end(),now-M) - can.begin();
      if(can[plc]==now) {
	cout<<-1<<endl;
	return 0;
      } else {
	ans.push_back(now-can[plc]);
	now = can[plc];
      }
    }
  }
  rep(i,(int)ans.size()) cout<<ans[(int)ans.size()-1-i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
	int H, W;
	std::vector<int> h, w;
	
	int cnt = 0;
	while(1)
	{
		std::cin >> H >> W;
		
		if( H == 0 && W == 0 ) break;
		
		else 
		{
			h.push_back(H);
			w.push_back(W);
		}
		
		cnt++;
	}
		
	for(int i = 0; i < cnt; i++)
	{
		for(int j = 0; j < h[i]; j++)
		{
			for(int k = 0; k < w[i]; k++)
			{
				std::cout << "#";
			}
			
			std::cout << std::endl;
		}
		
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3152
// D - Maximum Average Sets
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using DBL = double;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(ll i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MAX 50

vvl nCr_table(MAX+1, vl(MAX+1, 1));

void nCr_table_create(ll N){
	rp(n,1,N+1) rp(r,1,N+1-n)
		nCr_table[n][r] = nCr_table[n-1][r] + nCr_table[n][r-1];
}

ll nCr(int n, int r){
	if(n < r) return 0;
	int i = n - r;
	int j = r;
	return nCr_table[i][j];
}

int main(){
	ll N,A,B; cin>>N>>A>>B;
	vl V(N); rpz(i, N) cin>>V[i];
	sort(allr(V));
	nCr_table_create(N);

	DBL maxave = 0.0;
	rpz(i, A) maxave += V[i];
	maxave /= A;

	int n = 0, r = 0;
	ll v = V[A-1];
	rpz(i, N){
		if(v == V[i]){
			n++;
			if(i < A) r++;
		}
	}

	ll maxcnt = 0;
	if(r == A) rp(r, A, B+1) maxcnt += nCr(n, r);
	else maxcnt = nCr(n, r);

	printf("%.6f\n", maxave);
	cout<< maxcnt <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int map[10 + 2][10 + 2];

int housecnt;
int ans;
int cathx, cathy;

int calc(int x, int y, int depth)
{
	int i;
	
	if (depth == housecnt && (cathx == x || cathy == y)){
		ans++;
		return (0);
	}
	
	map[x][y] = 0;
	i = 1;
	while (map[x + i][y] == 0) i++;
	if (map[x + i][y] == 1){
		calc(x + i, y, depth + 1);
	}
	i = 1;
	while (map[x - i][y] == 0) i++;
	if (map[x - i][y] == 1){
		calc(x - i, y, depth + 1);
	}
	i = 1;
	while (map[x][y + i] == 0) i++;
	if (map[x][y + i] == 1){
		calc(x, y + i, depth + 1);
	}
	i = 1;
	while (map[x][y - i] == 0) i++;
	if (map[x][y - i] == 1){
		calc(x, y - i, depth + 1);
	}
	map[x][y] = 1;
	
	return (0);
}

int main(void)
{
	int w, h;
	
	while (1){
		scanf("%d%d", &w, &h);
		
		if (w == 0 && h == 0){
			break;
		}
		
		memset(map, -1, sizeof(map));
		
		housecnt = ans = 0;
		
		for (int y = 1; y <= h; y++){
			for (int x = 1; x <= w; x++){
				scanf("%d", &map[x][y]);
				if (map[x][y] == 2){
					cathx = x;
					cathy = y;
					map[x][y] = 0;
				}
				if (map[x][y] == 1){
					housecnt++;
				}
			}
		}
		
		calc(cathx, cathy, 0);
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

int main()
{
    int n,k;
    cin>>n>>k;
    int flag[n]={0};
	int d[k];
	for(int i=0;i<k;i++)
	{
		cin>>d[i];
		int c[d[i]];
		for(int j=0;j<d[i];j++)
		{
			cin>>c[j];
			flag[c[j]-1]=1;
		}
	 }
	 int sum=0;
	 for(int i=0;i<n;i++)
	 {
	 	if(flag[i]==0)sum++;
	  } 
	  cout<<sum;
}


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

bool is_triangle(int a, int b, int c) {
  if (a == b || a == c || b == c) {
    return false;
  } 
  if ((a + b) > c && (b + c) > a && (c + a) > b) {
    return true;
  } 
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  
  int ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (is_triangle(L[i], L[j], L[k])) {
          ans++;
        }
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef 	long long 							ll;
#define		mod									1000000007
#define 	ppi 								pair<ll,ll>
#define 	all(v) 								v.begin(),v.end()
#define 	prq									priority_queue
#define 	vi 									vector<ll>
#define     vip									vector<ppi>
#define 	forn(i,a,b)  						for(i=a;i<b;i++)
#define 	ford(i,a,b)   						for(i=a;i>b;i--)
#define 	endl 								"\n";
#define 	p_b 								push_back
#define 	m_p 								make_pair
#define     umap								unordered_map<ll,ll>
#define     uset                                unordered_set<ll>
#define     Stack								stack<ll>
#define     Queue								queue<ll>
#define     F									first
#define     S 									second				
void print1D(vector<ll> &v)
{
	cout<<"Debug Array:  ";
	for(ll i=0;i<v.size();i++)
 	   cout<<v[i]<<" ";
	cout<<"-----------------------------\n"; 
}

void print2D(vector<vector<ll>> &v)
{
	cout<<"Debug2d: ";
	ll n = v.size(),m=v[0].size();
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			cout<<v[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"--------------------------------------\n";
}

void printS(string &s)
{
	ll l=s.length(),i;
	cout<<"String: ";
	for(i=0;i<l;i++)
	{
		cout<<s[i];
	}
	cout<<"\n---------------------------------------\n";
}

void vectorInput(vector<ll> &v)
{
	ll n=v.size();
	for(ll i=0;i<n;i++){
	   cin>>v[i];
   }
}

void pairInput(vector<ppi> &vp)
{
	ll n = vp.size(),i,j,k;
	for(i=0;i<n;i++)
	{
		cin>>vp[i].F>>vp[i].S;
	}
}

void swap(ll &a,ll &b)
{
	ll t=a;
	a=b;
	b=t;
}

void sol()
{
	
	ll i,j,k,n,m,ans=0,d;
	cin>>n;
	string s;
	cin>>s;
	i=0,j=n-1;
	while(i<j)
	{
		
		while(i<j && s[j]=='W')
		{
			j--;
		}
		while(i<j && s[i]=='R')
		{
			i++;
		}
		if(i<j)
		{
			ans++;
			i++;
			j--;
		}
	}
	cout<<ans;
}

/*<----------------------------------------------------------------------------------------------------------------------------------------------->*/

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
	ll test=1;
//	cin>>test;
	while(test--)
	{
		sol();
		
	}
}

Measured memory_bytes: 3756
a = list(map(int, input().split()))
if a[0] == a[1] and a[0] != a[2]:
  print("Yes")
elif a[0] != a[1] and a[1] == a[2]:
  print("Yes")
elif a[0] == a[2] and a[0] != a[1]:
  print("Yes")
else:
  print("No")


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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
    fastio;

    int n, m;
    cin >> n >> m;
    vector<bool> A;
    FOR(i, 0, n) {
        A.pb(false);
    }
    bool possible = false;
    FOR(i, 0, m) {
        int a, b;
        cin >> a >> b;
        if (a == 1) {
            if (A[b-1]) {
                possible = true;
            }
            A[b-1] = true;
        }
        if (b == n) {
            if (A[a-1]) {
                possible = true;
            }
            A[a-1] = true;
        }
    }
    (possible) ? cout << "POSSIBLE\n" : cout << "IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (a >= b)cout << "delicious" << endl;
    else if (a + x >= b)cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}


Measured memory_bytes: 256
def dfs(vum,v,d,f,t):
    # print('first')
    # print(vum,v,d,f,t)
    if f[v] >= 0:
        return d,f,t
    t += 1
    d[v] = t
    for u in vum[v]:
        # print(v, d[v], f[v], u, d[u], f[u])
        if d[u] >= 0:
            # print('skip', str(v), str(u))
            continue
        d,f,t = dfs(vum,u,d,f,t)
    t += 1
    f[v] = t
    # print(v, d[v], f[v])
    # print('last')
    # print(vum,v,d,f,t)
    return d,f,t

def main():
    n = int(input())
    rows = []
    for i in range(n):
        rows.append([int(x) for x in input().split()])

    vum = {}
    for v,row in enumerate(rows):
        u,k = row[0],row[1]
        ul = []
        if k > 0:
            for j in row[2:]:
                ul.append(j-1)
        vum.update({v:ul})

    # print(vum)
    d = [-1]*len(vum)
    f = [-1]*len(vum)
    t = 0
    for v in vum:
        d,f,t = dfs(vum,v,d,f,t)
    for i,(j,k) in enumerate(zip(d,f)):
        print(i+1,j,k)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5668
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

int main(int argc, char const *argv[]) {
  int n, k;
  string s;

  cin >> n >> k;

  cout << (k == 1 ? 0 : (n - k)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

#include <algorithm>
#include <complex>

#define X real()
#define Y imag()

typedef long double Real;
typedef complex<Real> Point;
struct Line{Point a, b;};

const Real EPS = 1e-8;

inline int sgn(Real a, Real b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
inline bool near(Point a, Point b) {return !sgn(abs(a - b));}
namespace std {
  inline bool operator<(Point a, Point b) {return sgn(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

inline Real dot(const Point &a, const Point &b) {return a.X * b.X + a.Y * b.Y;}
inline Real det(const Point &a, const Point &b) {return a.X * b.Y - a.Y * b.X;}

inline Point vec(const Line &a) {return a.b - a.a;}

enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, ON = 16};
inline int ccw(const Point &a, const Point &b, const Point &c) {
  if (near(a, c) || near(b, c)) return ON;
  int s = sgn(det(b - a, c - a));
  if (s) return s > 0 ? LEFT : RIGHT;
  return (a < b) == (b < c) ? FRONT : (c < a) == (a < b) ? BACK : ON;
}

inline bool iSS(const Line &a, const Line &b, bool strict = false) {
  int cwa = ccw(a.a, a.b, b.a) | ccw(a.a, a.b, b.b);
  int cwb = ccw(b.a, b.b, a.a) | ccw(b.a, b.b, a.b);
  if (strict) return (cwa & cwb) == (LEFT | RIGHT);
  return ((cwa | cwb) & ON) || ((cwa & cwb) == (LEFT | RIGHT));
}

inline Real dLP(const Line &l, const Point &p) {return abs(det(vec(l), p - l.a) / vec(l));}
inline Real dSP(const Line &s, const Point &p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}
inline Real dSS(const Line &a, const Line &b) {return iSS(a, b) ? 0 : min(min(dSP(a, b.a), dSP(a, b.b)), min(dSP(b, a.a), dSP(b, a.b)));}

int main() {
  int n1, n2;
  cin >> n1;
  Point vp1[n1 + 2];
  for (int i : range(1, n1 + 1)) {
    Real x, y;
    cin >> x >> y;
    vp1[i] = Point(x, y);
  }
  cin >> n2;
  Point vp2[n2 + 2];
  for (int i : range(1, n2 + 1)) {
    Real x, y;
    cin >> x >> y;
    vp2[i] = Point(x, y);
  }
  vp1[0] = Point(0, 0);
  vp1[n1 + 1] = Point(1000, 0);
  vp2[0] = Point(0, 1000);
  vp2[n2 + 1] = Point(1000, 1000);
  Real res = 1e9;
  for (int i : range(n1 + 1)) for (int j : range(n2 + 1)) {
    res = min(res, dSS((Line){vp1[i], vp1[i + 1]}, (Line){vp2[j], vp2[j + 1]}));
  }
  cout << fixed << setprecision(15) << res << endl;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.

int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	string s;
	cin>>s;
	int n = s.length();
	int d = INT_MAX;
	for(int i=0;i+2 < n;i++){
		int num = 100*(s[i] - '0') + 10*(s[i+1] - '0') + (s[i+2] - '0');
		int a = abs(753 - num);
		d = min(d, a);
	}
	cout<<d;
  	return 0;
}

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


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

bool SmallerFisrtToSecond(const tuple<string, int, int>& f, const tuple<string, int, int>& s){
	if (get<0>(f) == get<0>(s)){
		return get<1>(f) > get<1>(s);
	}
	else {
		return get<0>(f) < get<0>(s);
	}
}

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

	vector<tuple<string, int, int>> r(n);

	for (int i = 0; i < n; i++){
		string name;
		int score;
		cin >> name >> score;
		r[i] = make_tuple(name, score, i + 1);
	}

	sort(r.begin(), r.end(), SmallerFisrtToSecond);

	for (int i = 0; i < n; i++){
		cout << get<2>(r[i]) << endl;
	}
}


Measured memory_bytes: 256
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}


int main()
{
	fast
	int n;
	cin>>n;
	unordered_map <int,int> mp;
	FOR(i,1,101)
	{
		FOR(j,1,101)
		{
			FOR(k,1,101)
			{
				int ans = (i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(k*i);
				mp[ans]++;
			}
		}
	}
	FORE(i,1,n)
	{
		cout<<mp[i]<<endl;
	}
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int five = 0;
		int seven = 0;
		for (int i = 0; i < 3; i++) {
			int num = sc.nextInt();
			if(num == 5) {
				five++;
			}else if(num == 7) {
				seven++;
			}
		}
		if(five == 2 && seven == 1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		sc.close();
	}

}

Measured memory_bytes: 35732
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = []

for i in range(a + 1):
  total = 0
  for j in range(b + 1):
    for k in range(c + 1):
      total = 500 * i + 100 * j + 50 * k
      if x == total:
        ans.append((i, j, k))
print(len(ans))

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

typedef complex<double>Point;

struct Segment{
    Point p1,p2;
    Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){}
};

struct Circle{
    Point p;
    double r;
    Circle(const Point &p=Point(),double r=0.0):p(p),r(r){}
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point>Polygon;

const double PI=acos(-1);
const double EPS=1e-8;
const double INF=1e16;

inline double square(double a){return a*a;}
inline double norm(const Point &a){return square(a.real())+square(a.imag());}
inline double dot(const Point &a,const Point &b){return (conj(a)*b).real();}
inline double cross(const Point &a,const Point &b){return (conj(a)*b).imag();}
inline double toDeg(double t){return t/PI*180.0;}
inline double toRad(double t){return t/180.0*t;}
#define equals(a,b) (fabs((a)-(b))<EPS)

bool isOrthogonal(Vector a,Vector b){
    return equals(dot(a,b),0.0);
}

bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
    return isOrthogonal(a1-a2,b1-b2);
}

bool isOrthogonal(Segment s1,Segment s2){
    return isOrthogonal(s1.p1-s1.p2,s2.p1-s2.p2);
}

bool isParallel(Vector a,Vector b){
    return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
    return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
    return isParallel(s1.p1-s1.p2,s2.p1-s2.p2);
}


void getPoint(Point &p){
    double x,y;
    scanf("%lf%lf",&x,&y);
    p=Point(x,y);
}

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

    while(n--){
        Point a1,a2,b1,b2;
        getPoint(a1);
        getPoint(a2);
        getPoint(b1);
        getPoint(b2);
        if(isParallel(a1,a2,b1,b2))puts("2");
        else if(isOrthogonal(a1,a2,b1,b2))puts("1");
        else puts("0");
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	long long ans=1;
	for (int i=1;i<=n;i++){
		ans*=i;
		if (ans>1000000007){
			ans=ans%1000000007;
		}
	}
	cout << (long long)ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath> 
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric> 
#include <iomanip>
#include <map> 
#include <stack>
#include <sstream>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAX = 1e6;
long long max(long long a, long long b) { if (a > b)return a; else return b; }
long long min(long long a, long long b) { if (a < b)return a; else return b; }
const int MAXN = 1000000 + 30;
int a[MAXN];


  		     		    	   				   	

int main()
{
	
		ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
		ll  n, k;
		cin >> n >> k;
		if (n % k == 0)
		{
			cout << 0;
			return 0;
		}
		if (n <= k)
		{
			ll d = abs(n - k);
			if (d <= n)
			{
				cout << d;
			}
			else
			{
				cout << n;
			}
			
		}
		else if (n > k)
		{
			
				ll d = n / k;
				n -= (d * k);
				cout << min(n, abs(n - k));
		}
		
		return 0;
	
}

Measured memory_bytes: 3164
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>

//#define int ll
//#define double long double
//#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.14159265358979

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 3e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T>
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

signed main()
{
    Start();
    int n, t;
    cin >> n >> t;
    vector <int> a(n), b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i] >> b[i];
    int t0 = t + 3;
    int dp[n + 1][t0];
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < t0; ++j)
        {
            dp[i][j] = dp[i - 1][j];
            if (j)
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            if (j - a[i - 1] < t && j - a[i - 1] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i - 1]] + b[i - 1]);
        }
    }
    int fp[n + 1][t0];
    memset(fp, 0, sizeof fp);
    for (int i = n - 1; i >= 0; --i)
    {
        for (int j = 0; j < t0; ++j)
        {
            fp[i][j] = fp[i + 1][j];
            if (j)
                fp[i][j] = max(fp[i][j], fp[i][j - 1]);
            if (j - a[i] < t && j - a[i] >= 0)
                fp[i][j] = max(fp[i][j], fp[i + 1][j - a[i]] + b[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < t; ++j)
        {
            ans = max(ans, dp[i][j] + fp[i + 1][t - j - 1] + b[i]);
        }
    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 70656
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

uf_t = numba.types.UniTuple(i8[:], 2)


@njit((uf_t, i8), cache=True)
def find_root(uf, x):
    root = uf[0]
    while root[x] != x:
        root[x] = root[root[x]]
        x = root[x]
    return x


@njit((uf_t, i8, i8), cache=True)
def merge(uf, x, y):
    root, size = uf
    x, y = find_root(uf, x), find_root(uf, y)
    if x == y:
        return False
    if size[x] < size[y]:
        x, y = y, x
    size[x] += size[y]
    root[y] = root[x]
    return True

@njit((i8, i8, i8[:]), cache=True)
def main(N, M, AB):
    ans = N - 1
    root = np.arange(N + 1, dtype=np.int64)
    size = np.ones_like(root)
    uf = (root, size)

    for i in range(0, len(AB), 2):
        a, b = AB[i:i + 2]
        if merge(uf, a, b):
            ans -= 1
    return ans

N, M = map(int, readline().split())
AB = np.array(read().split(), np.int64)

print(main(N, M, AB))

Measured memory_bytes: 120696
Ss = input()

ans1 = 0
for i, S in enumerate(Ss):
    if S != '01'[i%2]:
        ans1 += 1

ans2 = 0
for i, S in enumerate(Ss):
    if S != '10'[i%2]:
        ans2 += 1

print(min(ans1, ans2))


Measured memory_bytes: 3188
N,M=map(int,input().split(" "))
l=list(map(int,input().split(" ")))
sum_list=sum(l)
border=sum_list/(4*M)
c=0
for i in range(N):
  if l[i]>=border:
    c+=1
if c>=M:
  print("Yes")
else:
  print("No")
  

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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in(),k=in(),h[n],st[n];
    forin(h,n);
    for (int i=0;i<n;i++) st[i]=INT_MAX;
    st[0]=0;
    for (int i=0;i<n;i++){
        for (int i2=k;i2>0;i2--){
            if (i-i2<0) continue;
            st[i]=min(st[i],st[i-i2]+abs(h[i-i2]-h[i]));
        }
    }
    cout << st[n-1]<< endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  int min = L.at(0);
  int max = R.at(0);
  for(int i = 0; i < M; i++){
    if (min < L.at(i)) {
      min = L.at(i);
    }
    if (max > R.at(i)) {
      max = R.at(i);
    }
  }
  if(min > max){
    cout << 0 << endl;
  }
  else {
    cout << max - min + 1 << endl;
  }
}


Measured memory_bytes: 1024
<?php

$money = trim(fgets(STDIN));


$happy = 0;

while($money > 4){
	if($money > 499){
		$money -= 500;
		$happy += 1000;
	}elseif($money > 4){
		$money -= 5;
		$happy += 5;
	}
}

echo $happy;

Measured memory_bytes: 4468
n,k = map(int, input().split())
p = list(map(int, input().split()))

def s(n):
    return (n+1)/2

d = list(map(s, p) )

ans = m = sum(d[0:k])
ans_i = 0
# print(ans)
# print(ans/k)
# print(n-k)
for i in range(n-k):
    m -= d[i]
    m += d[i+k]
    # print(m)
    if ans < m:
        ans = m
        ans_i = i + 1

print(ans)
# for i in range(n-k):

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


int a, b, c, x, y;

int main()
{
    scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
    int ans = 2e9 + 10;

    int cl = max(x, y);
    for(int i = 0; i <= cl; i ++){
        ans = min(ans, i * 2 * c + (max(0, x - i)) * a + (max(0, y - i)) * b);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import sys
a=[1]*500000
for i in range(3,999,2):
 if a[i//2]:a[(i*i)//2::i]=[0]*len(a[(i*i)//2::i])
[print([e-1,sum(a[:(e+1)//2])][e>3])for e in map(int,sys.stdin)]


Measured memory_bytes: 15016
price_A, price_B, price_C, required_A_num, required_B_num = readlines.first.split(' ').map(&:to_i)

LIMIT = 10**5

answer = nil
(0..LIMIT).each do |i|
  total_price = 0  
  total_price += price_C * 2 * i 
  total_price += price_A * [0, required_A_num - i].max
  total_price += price_B * [0, required_B_num - i].max
  answer = answer.nil? ? total_price : [answer, total_price].min
end

puts answer

Measured memory_bytes: 14232
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] A = new int[n];
        int[] B = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(sc.next());
            B[i] = Integer.parseInt(sc.next());
        }
        final int INF = 1001001001;
        int dp[][] = new int[n+1][h+1];
        for(int i=0; i<n; i++) {
        	for(int j=0; j<=h; j++) {
        		dp[i][j]=INF;
        	}
        }
        for(int i=0; i<n; i++) {
        	dp[i][0]=0;
        }
        for(int i=0; i<n; i++) {
        	for(int j=0; j<=h; j++) {
        		if(A[i]<=j) {
        			dp[i+1][j] = Math.min(dp[i+1][j-A[i]]+B[i], dp[i][j]);
        		}else {
        			dp[i+1][j] = Math.min(B[i], dp[i][j]);
        		}
        	}
        }
        System.out.println(dp[n][h]);
		sc.close();
	}
}


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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    char a;
    cin >> a;

    if ('a' <= a && a <= 'z') prt("a");
    if ('A' <= a && a <= 'Z') prt("A");

    return 0;
}


Measured memory_bytes: 3584
N,Y = map(int,input().split())
t = int(Y/1000)
swich = 0
break_swich = 0

for i in range(t+1):
    x = i
    if break_swich == 1:
        break
    for n in range(int((t-10*i)/5)+1):
        y = n
        z = t - 10*i - 5*n
        if x+y+z == N:
            print(x,y,z)
            swich = 1
            break_swich = 1

if swich == 0:
    print(-1,-1,-1)


Measured memory_bytes: 3064
#include<stdio.h>
#define N 2000000
int a[N],b[N],c[N];
int main(){
  int i,j,k=0,n;
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    c[a[i]]++;
    
    if(k<a[i])k=a[i];
  }
  for(i=1;i<=k;i++){
    c[i]+=c[i-1];
  }

  for(i=0;i<n;i++){
    b[c[a[i]]-1]=a[i];
    c[a[i]]--;
  }
  for(i=0;i<n;i++){
    if(i!=n-1)
      printf("%d ",b[i]);
    else printf("%d\n",b[i]);
    
  }
  
  
  return 0;
}

Measured memory_bytes: 17892
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define INF 2000000000
#define ull unsigned long long

int main(){
    int i,k,num=0;
    char s[101]={},tmp;
    scanf("%d",&k);
    scanf("%s",s);
    while (s[num]!='\0') num++;
    if (num>k) {
        for (i=0; i<k; i++) {
            tmp=s[i];
            printf("%c",tmp);
        }
        printf("...");
    }else{
        printf("%s",s);
    }
    return 0;
}



Measured memory_bytes: 1732
N = int(input())
A=0
B=0
BA=0
ans=0
for i in range(N):
  s = input()
  last = len(s)-1
  ans += s.count('AB')
  if s[0]=='B' and s[last]=='A':
    A+=1
    B+=1
    BA+=1
  elif s[0]=='B':
    B+=1
  elif s[last]=='A':
    A+=1
ans += min(A,B)
if A==B and B==BA and A!=0:
  ans-=1
print(ans)

Measured memory_bytes: 3064
from collections import Counter
h, w, n = map(int, input().split())
c = []
for k in range(n):
    i, j = map(lambda x: int(x) - 1,input().split())
    for l in range(3):
        for m in range(3):
            p = i - l
            o = j - m 
            if p < 0 or p > h - 3: continue
            if o < 0 or o > w - 3: continue
            c.append((p, o))

c = Counter(Counter(c).values())
print((h - 2) * (w - 2) - sum(c.values()))
for i in range(1, 10):
    print(c[i])

Measured memory_bytes: 198520
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n=int(input())
s=str(n)
count=0
for i in s:
    count+=int(i)
print("Yes" if n%count==0 else "No")


Measured memory_bytes: 38256
#include <iostream>
#include <stdio.h>
#include <queue>

using namespace std;

typedef struct
{
	int x, y;
}P;

int w, h, n, dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
char s[1002][1002];
int d[1002][1002];
P a[10], p, q;

int bfs(P st, P ed)
{
	int i, j;
	for (i = 0; i < h; i++)
		for (j = 0; j < w; j++)
			d[i][j] = -1;
	queue<P>que;
	que.push(st);
	d[st.x][st.y] = 0;	
	while (!que.empty())
	{
		p = que.front();
		que.pop();
		if (p.x == ed.x && p.y == ed.y)
			break;	
		for (i = 0; i < 4; i++)
		{
			q.x = dir[i][0] + p.x;
			q.y = dir[i][1] + p.y;
			if (q.x >= 0 && q.x < h && q.y >= 0 && q.y < w && s[q.x][q.y] != 'X' && d[q.x][q.y] == -1)
			{				
				que.push(q);
				d[q.x][q.y] = d[p.x][p.y] + 1;
			}
		}
	}
	return d[p.x][p.y];
}

int main()
{
	int i, j, sum;
	scanf("%d%d%d", &h, &w, &n);
	for (i = 0; i < h; i++)
	{
		scanf("%s", s[i]);
		for (j = 0; j < w; j++)
			if (s[i][j] == 'S')
			{
				a[0].x = i;
				a[0].y = j;
			}
			else if (s[i][j] != '.')
			{
				sum = s[i][j] - '0';
				a[sum].x = i;
				a[sum].y = j;
			}
	}
	for (i = sum = 0; i < n; i++)
		sum += bfs(a[i], a[i + 1]);
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 6112
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 

class Program { 
     static void Main(string[] args) {
     //入力を受け取る
     var N = int.Parse(Console.ReadLine());
     var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
     
     
     var B = new int[N+1];
     B[0] = Math.Abs(A[0]);
     B[N] = Math.Abs(A[N-1]);
     for(int i = 1; i < N ; i++){
         B[i] = Math.Abs(A[i]-A[i-1]);
     }
     
     var dis = B.Sum();
    //Console.WriteLine(dis);
     for(int i = 0;i < N;i++){
         var ans = dis;
         if(i == N-1){
             ans = ans-(B[i]+B[i+1])+Math.Abs(A[i-1]);
         }else if(i == 0){
             ans = ans-(B[i]+B[i+1])+Math.Abs(A[i+1]);
         }else{
             ans = ans-(B[i]+B[i+1])+Math.Abs(A[i+1]-A[i-1]);
         }
        Console.WriteLine(ans);
     }
}
     
     
     
     static int distance(int min,int max){
         var amin = Math.Abs(min);
         var amax = Math.Abs(max);
         
         if(min*max >= 0){
             if(amin > amax){
                 return amin*2;
             }else{
                 return amax*2;
             }
         }else{
             return amax*2+amin*2;
         }
     }
     }


Measured memory_bytes: 28124
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}

ll modpow(ll x, ll n){
	ll r=1;
	while(n){
		if(n&1) r=r*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return r;
}
int main(){
  ll x;cin>>x;
  cout<<8-(x-400)/200<<endl;
}



Measured memory_bytes: 3628