akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


#include <stdio.h>

#include<stdio.h>

int main(void)
{
	int  s,w;
	

	i_cin2(s,w);
	
	if (s <= w) { S_RTN("unsafe"); }
	S_RTN("safe");
	
//	return 0;
}



Measured memory_bytes: 1664
import java.io.IOException;
import java.util.Scanner;

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

		String s = sc.next();
		String t = sc.next();

		String ans = "No";
		for (int i = 0; i < s.length(); i++) {
			s = s.substring(s.length() - 1) + s.substring(0, s.length() - 1);
			if (s.equals(t)) {
				ans = "Yes";
				break;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23892
#include<iostream>
#include <string>

using namespace std;

int main() {
        string boxA,boxB;

	cin >> boxA >> boxB;

	for(int n = 0;n < boxA.size();n++) {
		if(boxA == boxB) {
		cout << "Yes" << "\n";
		return 0;
		}
		boxA = boxA[boxA.size()-1] + boxA.substr(0,boxA.size()-1);
	}
		cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  ans = LINF;
  rep(i, Size(s) - 2) {
    cnt = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
    ans = min(ans, abs(cnt - 753));
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let input = readLine()!.split(" ")
let A = input[0]
let B = input[1]
let C = input[2]

if A+B >= C {
    print(B+C)
} else {
    print(A+B+1+B)
}

Measured memory_bytes: 7400
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    string s; cin>>s;
    int K; cin>>K;

    set<string> st;
    for(char c='a';c<='z';c++){
        REP(i,s.size()){
            if(s[i]==c){
                for(int j=1;j<=5;j++){
                    st.insert(s.substr(i,j));
                }
            }
        }
        if(st.size()>=K){
            auto itr=st.begin();
            REP(i,K-1) itr++;
            cout<<*itr<<endl;
            return 0;
        }
    }
}


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

#define hey(x) cerr << #x << " : " << x << "\n";
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int, int> >
#define vvpi vector<vector<pair<int, int> > >
#define all(v) (v).begin(), (v).end()   
#define rall(v) (v).rbegin(), (v).rend()
#define pii pair<int, int>
#define pb push_back
#define SZ(x) (int)(x).size()
#define inf 1e12
#define F first
#define S second
#define fill(v, val) memset((v), val, sizeof(v))
#define PI 3.1415926535897932384626
#define out cout << fixed << setprecision(12)
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define hey2(x, y) cerr << #x << " : " << x << "," << #y << " : " << y << '\n';

const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const double pi = acos(-1);

void read(vi &a) {
    for(int &i : a)
        cin >> i;
}
void print(vi &a) {
    for(int i : a)
        cerr << i << ' ';
    cerr << '\n';
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi h(n);
    read(h);
    vi dp(n + 1, inf);
    dp[0] = 0;
    for(int i = 1; i < n; ++i) {
        for(int j = max(0LL, i - k); j < i; ++j) {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 4688
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, q;
    scanf("%d", &n);
    vector<int> S(n);
    for(auto it=S.begin(); it!=S.end(); it++){
        scanf("%d", &(*it));
    }
    sort(S.begin(), S.end());

    scanf("%d", &q);
    int sum=0;
    for(int i=0; i<q; i++){
        int qq;
        scanf("%d", &qq);
        sum+=binary_search(S.begin(), S.end(), qq);
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 2748
S = input()
N = len(S)
X = [[i-1 if S[i] == "L" else i+1 for i in range(N)] if j == 0 else [0]*N for j in range(20)]
for k in range(1, 20):
    for i in range(N):
        X[k][i] = X[k-1][X[k-1][i]]
A = [0]*N
for i in range(N):
    A[X[-1][i]] += 1
print(*A)

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        char[] c = n.toCharArray();
        int x = 0;
        for(int i=0; i<3; i++){
            if(c[i] == '1'){
                x++;
            }
        }
        System.out.println(x);
    }
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	int n;
	cin >> n;
	
	int ans = 0;
	
	rep(i , n){
		int l , r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m, c;
  cin >> n >> m >> c;
  vl b(m);
  rep(i, m) cin >> b[i];
  ll ans = 0;
  rep(i, n) {
    ll now = 0;
    rep(j, m) {
      ll a;
      cin >> a;
      now += a * b[j];
    }
    if(now + c > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

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

    int a;
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a % 2)cnt++;
    }
    if (cnt % 2)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
}


Measured memory_bytes: 256
A,B= gets.split.map(&:to_i)
S = gets.chomp


char_array = S.chars

check = true
char_array.each_with_index{|value,index|
  if index == A
      check = false if value!='-'
  else
    check = false unless (value =~  /[0-9]/)
  end
}

if check
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<stdio.h>

void selectionSort(int A[],int);

int main(){
  int A[1000];
  int i,N;

  scanf("%d",&N);
   if(N <= 0 && N >= 100)return 0;

  for( i = 0 ;i < N ; i++ ){
    scanf("%d",&A[i]);
  }
  selectionSort(A,N);

  
  return 0;
}

void selectionSort(int A[],int N){
  int i,j,ex,count=0,minj;

  for( i = 0 ; i < N - 1 ; i++ ){
    minj = i;
    for( j = i ; j < N ; j++ ){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    ex = A[i];
    A[i] = A[minj];
    A[minj] = ex;
    if(i != minj)count++;
  }
  for( i = 0 ; i < N ; i++ ){
    if( i > 0 )printf(" ");
    printf("%d",A[i]);
  }

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

  



Measured memory_bytes: 2100
using System;

class Program {
    static void Main( string[] args )
    {
        while ( true ) {
            string[] data = Console.ReadLine().Split( ' ' );
            int n = int.Parse( data[ 0 ] );
            int x = int.Parse( data[ 1 ] );

            if ( n == 0 && x == 0 ) {
                break;
            }

            int count = 0;
            int m = x / 3;

            for ( int a = 1; a < m; ++a ) {
                for ( int b = a + 1; b < n; ++b ) {
                    if ( x < a + b * 2 + 1 ) {
                        continue;

                    } else if ( x > a + b + n ) {
                        continue;
                    }

                    count += 1;
                }
            }

            Console.WriteLine( count );
        }
    }
}

Measured memory_bytes: 9156
#include <iostream>
#include <string>
using namespace std;
int main () {
	string output = "Good";
	char prev = '@';
	char curr;
	for(int i = 0; i < 4; i++) {
		cin >> curr;		
		if(curr == prev) {
			output = "Bad";
			break;
		}
		prev = curr;
	}
	cout << output << endl;
	return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 300010
const int DAT_SIZE = (1 << 18) - 1;
vl dat(DAT_SIZE), datb(DAT_SIZE);

void add(int a, int b, ll x, int v, int l, int r) {
	if (a <= l && r <= b) {
		dat[v] += x;
	}
	else if (l < b && a < r) {
		datb[v] += (min(b, r) - max(a, l))*x;
		add(a, b, x, v * 2 + 1, l, (l + r) / 2);
		add(a, b, x, v * 2 + 2, (l + r) / 2, r);
	}
}

ll sum(int a, int b, int v, int l, int r) {
	if (r <= a || b <= l) {
		return 0;
	}
	else if (a <= l && r <= b) {
		return dat[v] * (r - l) + datb[v];
	}
	else {
		ll res = (min(b, r) - max(a, l)) * dat[v];
		res += sum(a, b, v * 2 + 1, l, (l + r) / 2);
		res += sum(a, b, v * 2 + 2, (l + r) / 2, r);
		return res;
	}
}


int main() {
	int n, m, i, j;
	cin >> n >> m;
	vi l(n), r(n);
	vii d(m + 3, vi());
	for (i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
		d[r[i] - l[i] + 2].push_back(i);
	}
	int safe = n;
	for (int k = 1; k <= m; k++) {
		int res = 0;
		safe -= d[k].size();
		res += safe;
		for (i = 0; i < d[k].size(); i++) {
			add(l[d[k][i]], r[d[k][i]] + 1, 1, 0, 0, m + 1);
		}
		for (i = 1; k*i <= m; i++) {
			res = res + sum(k*i, k*i + 1, 0, 0, m + 1);
		}
		printf("%d\n", res);
			
	}
}

Measured memory_bytes: 12928
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

double dist(pair<double, double> a, pair<double, double>b) {
	return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

pair<double, double> calc_c(pair<double, double> a, pair<double, double>b, pair<double, double>c, double & r) {
	pair<double, double> e, f, g;
	e.first = (a.first + b.first) / 2;
	e.second = (a.second + b.second) / 2;
	f.first = (b.first + c.first) / 2;
	f.second = (b.second + c.second) / 2;
	double tan_a, tan_b;
	tan_a = tan(atan((b.second - a.second) / (b.first - a.first)) + PI / 2);
	tan_b = tan(atan((c.second - b.second) / (c.first - b.first)) + PI / 2);
	g.first = (e.second - f.second - e.first * tan_a + f.first * tan_b) / (tan_b - tan_a);
	g.second = e.second - (e.first - g.first) * tan_a;
	r = dist(a, g);
	return g;
}

pair<double, double> calc_c(pair<double, double> a, pair<double, double>b,double &r) {
	pair<double, double> g;
	g.first = (a.first + b.first) / 2;
	g.second = (a.second + b.second) / 2;
	r = dist(a, g);
	return g;
}

bool is_inner(pair<double, double> c, pair<double, double>p, double r) {
	return dist(c, p) <= (r + 1e-5);
}

int main() {
	io_init;
	int N;
	cin >> N;
	vector<pair<double, double>> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i].first >> a[i].second;
	}
	double ans = INF;
	if (N != 2) {
		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++) {
					//cout << i << " " << j << " " << k << endl;
					double r;
					auto c = calc_c(a[i], a[j], a[k], r);
					bool f = false;
					for (int s = 0; s < N; s++) {
						if (!is_inner(c, a[s], r))f = true;
					}
					if (!f)ans = min(ans, r);
				}
			}
		}
	}
	for (int i = 0; i < N-1; i++) {
		for (int j = i+1; j < N; j++) {
			if (i == j) continue;
			double r;
			auto c = calc_c(a[i], a[j], r);
			bool f = false;
			for (int k = 0; k < N; k++) {
				if (!is_inner(c, a[k], r))f = true;
			}
			if (!f)ans = min(ans, r);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long N, M;
    cin >> N >> M;

    vector<long long> vecA(M);
    for (long long i = 0; i < M; i++)
    {
        cin >> vecA.at(i);
    }
    
    long long sum = 0;
    for (long long i = 0; i < M; i++)
    {
        sum = sum + vecA.at(i);
    }
    
    long long max = N - sum;
    if (max < 0)
    {
        max = -1;
    }
    else
    {
        max = N - sum;
    }
    
    cout << max << endl;
    
}

Measured memory_bytes: 3708
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{ 
  int s,w;
  cin >> s >> w;
  if(w>=s)
    cout << "unsafe\n";
  else
   cout << "safe\n";
   return;
}

signed main()
{
  FAST
  int T=1;
  //  cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}

int main()
{
  int n;cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  ll sum=0,ans=0;
  REP(i,n) sum+=a[i];
  ll t=(ll)round(sum*1.0/n);
  REP(i,n) ans+=(t-a[i])*(t-a[i]);
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

#define INF (1<<29)


int N,M,R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];


void  dfs(int c,int las ,int  dist){if(c==R+1){if(res >dist)res=dist;return;}for(int i=1;i<=R;i++)if(!used[i]){used[i]=true;if(las==-1)dfs(c+1,i,0);else  dfs(c+1,i,dist+d[r[las]][r[i]]);used[i]=false;}}int  main(){scanf("%d%d%d",&N,&M,&R);for(int i=1;i<=N;i++) for(int j=1;j<=N;j++)if(i!=j)d[i][j]=INF;for(int i=1;i<=R;i++) scanf("%d",&r[i]);for(int i=1;i<=M;i++){scanf("%d%d%d",&A,&B,&C);if(d[A][B]>C)d[A][B]=d[B][A]=C;}for(int k=1;k<=N;k++)for(int i=1;i<=N;i++)for(int j=1;j<=N;j++)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];res=INF;dfs(1,-1,0);printf("%d\n",res);}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{int a[200];
int n;
cin>>n;
for(int i=0;i<n;i++)
    cin>>a[i];
long long ans=0;
for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    ans+=1ll*a[i]*a[j];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u)
    cout << a - 1 << " " << b << endl;
  else {
    cout << a << " " << b - 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> a(3);
	rep(i, 3) cin >> a[i];
	bool elf = true;
	rep(i, 3) if (a[i] % 2 != 0) elf = false;
	if (!elf) {
		cout << 0 << endl;
		return 0;
	}
	if (a[0] == a[1] && a[1] == a[2]) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 1;
	rep(ri, 1000000) {
		int b = (a[1] + a[2]) / 2;
		int c = (a[0] + a[2]) / 2;
		int d = (a[0] + a[1]) / 2;
		bool ok = true;
		a[0] = b, a[1] = c, a[2] = d;
		rep(i, 3) if (a[i] % 2 != 0) ok = false;
		if (!ok) break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

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

    int ans;
    if (D <= A)
    {
        ans=0;
    }
    else if (C <= A && D <= B)
    {
        ans = D-A;
    }
    else if (C<=A && B<=D)
    {
        ans = B-A;
    }
    else if (D <= B)
    {
        ans = D-C;
    }
    else if (C <=B && B <= D)
    {
        ans = B-C;
    }
    else if (B <= C)
    {
        ans = 0;
    }
    
    
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <stack>
#include <cstdlib>
#include <vector>
#define N 4
#define N2 16
#define MAX_DEPTH 45 
using namespace std;

class game{
  public:
  int board[N2];
  int w;
  int last_move;
  int depth;
  int mnh;
};
game start;

vector<int> move_list[N2];
int dist[N2][N2];

void print(game &g){
  for(int i=0;i<N2;i++){
    printf(" %d",g.board[i]);
  }
  cout<<" mnh: "<<g.mnh<<endl;
}


bool dfs(int depth){
  stack<game> s;
  s.push(start);
  
  game g;
  while(!s.empty()){
    g=s.top();s.pop();
    if(g.mnh==0) return true;
    if(g.depth==depth) continue;
    if(g.depth+g.mnh>depth) continue;

    for(int move:move_list[g.w]){
      if(g.last_move==-move) continue;
      game h=g;
      int to=h.w+move;
      h.mnh -= dist[to][h.board[to]-1];
      h.mnh += dist[h.w][h.board[to]-1];
      swap(h.board[h.w],h.board[to]);
      h.w = to;
      h.depth++;
      h.last_move=move;
      s.push(h);
    }
  }
  return false;
}

void initialize(){
  for(int i=0;i<N2;i++){
    if(i%N<N-1) move_list[i].push_back(1);
    if(i%N>0  ) move_list[i].push_back(-1);
    if(i/N<N-1) move_list[i].push_back(N);
    if(i/N>0  ) move_list[i].push_back(-N);
  }

  //i=board,j=piece-1
  for(int i=0;i<N2;i++){
    for(int j=0;j<N2;j++){
      dist[i][j] = abs(j%N-i%N) + abs(j/N-i/N);
    }
  }

  start.mnh=0;
  for(int i=0;i<N2;i++){
    if(i==start.w) continue;
    start.mnh += dist[i][start.board[i]-1];
  }
}

int solve(){
  initialize();
  for(int i=start.mnh;i<=MAX_DEPTH;i++){
    if(dfs(i)){
      return i;
    }
  }
  return -1;
}

int main(){
  for(int i=0;i<N2;i++){
    int tmp; cin>>tmp;
    if(tmp==0){
      start.board[i]=N2;
      start.w=i;
    }else{
      start.board[i]=tmp;
    }
  }
  start.depth=0;
  start.last_move=0;

  cout<<solve()<<endl;
}

Measured memory_bytes: 3140
N, M = map(int, input().split())
penalty = 0
AC = [0]*N
WA = [0]*N
for i in range(M):
    p, S = input().split()
    if S == 'AC':
        AC[int(p)-1]=1
    else:
        if AC[int(p)-1]==0:
            WA[int(p)-1] += 1
penalty = [a*b for a, b in zip(AC, WA)]
print(sum(AC), sum(penalty))

Measured memory_bytes: 5528
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N, A, B, C, D = LI_()
    S = SI().strip()

    if C < D:  # AがBを追い越さないとき
        if B < C:  # ABCDの並びのとき
            # A-Dに2つ以上連続の#がなければOK
            previous = '.'
            for i in range(A, D+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'
            print('Yes')
            return

        elif C < B:  # ACBDの並びのとき
            # A-C, B-D に2つ以上連続の#がなければOK
            previous = '.'
            for i in range(A, C+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'

            previous = '.'
            for i in range(B, D+1):
                if S[i] == '#':
                    if previous == '#':
                        print('No')
                        return
                    else:
                        previous = '#'
                else:
                    previous = '.'

            print('Yes')
            return

    elif D < C:  # AがBを追い越すとき: ABDCの並びしかない。
        # A-C に2つ以上連続の#がない かつ B-D に避難場所（3つ以上連続する . ）がある。
        count_continuous_dots = 0
        can_evac = False
        previous = '.'
        for i in range(A, C+1):
            if S[i] == '#':
                if previous == '#':
                    print('No')
                    return
                else:
                    previous = '#'
                    count_continuous_dots = 0
            else:
                previous = '.'
            if B-1 <= i <= D+1:
                if S[i] == '.':
                    count_continuous_dots += 1
                    if count_continuous_dots >= 3:
                        can_evac = True
        if can_evac:
            print('Yes')
        else:
            print('No')
        return


main()

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  vll t(n);
  for (ll i = 0; i < n; i++) cin >> t[i];

  ll ans = tt * n;
  for (ll i = 0; i < n - 1; i++) {
    if (t[i + 1] - t[i] < tt) ans -= tt - (t[i + 1] - t[i]);
  }

  cout << ans << endl;
}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  vector<int> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);

  bool check=true;

  for(int i=0;i<N;i++){
    if(A.at(i)%2==0){
      if(A.at(i)%3!=0 && A.at(i)%5!=0){
        //cout<<A.at(i)<<endl;
        check = false;
      }
    }
  }
  cout<< (check ? "APPROVED" : "DENIED") <<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll x; cin >> x; ll year = 0; ll mon = 100;
  
  while(mon < x){
    mon += mon/100;
    year++;
  }
  
  cout << year << endl;
}
  
  


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

int main() {
	// your code goes here
	long long n;
	cin >> n;
	vector<long long> a;
	for(int i=0; i<n; i++){
		long long b;
		cin >> b;
		a.push_back(b);
	}
	
	long long num = 0;
	long long money = 1000;
	decltype(a)::iterator result = std::unique(a.begin(), a.end());

	
    // [v.begin(), result)の範囲に、重複を除いた結果が入っている。
    // 不要になった要素を削除
    a.erase(result, a.end());
    
    if(a.size() == 1){
    	cout << money << endl;
    	return 0;
    }
	
	//折り返し地点を探す
	string turn[a.size()];
	for(int i=1; i<a.size()-1; i++){
		if(a.at(i-1) < a.at(i) && a.at(i) > a.at(i+1)){
			turn[i] = "down";
		}
		else if(a.at(i-1) > a.at(i) && a.at(i) < a.at(i+1)){
			turn[i] = "up";
		}
		else{
			turn[i] = "keep";
		}
	}
	
	if(a.at(0) < a.at(1)){
		num += money / a.at(0);
		money %= a.at(0);
	}
	
	for(int i=0; i<a.size()-1; i++){
		if(turn[i] == "down"){
			money += a.at(i) * num;
			num = 0;
		}
		else if(turn[i] == "up"){
			num += money / a.at(i);
			money %= a.at(i);
		}
	}
	
	if(a.at(a.size()-2) < a.at(a.size()-1)){
		money += a.at(a.size()-1) * num;
		num = 0;
	}
	
	cout << money << endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,s=0,mn=INT_MAX,f=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
      s+=a[i];
      if(a[i]%10!=0 &&mn>a[i])
      {
        mn=a[i];
        f=1;
      }
    }
    if(s%10==0&&f==0)
      cout<<0<<endl;
   else  if(s%10==0)
    {
      cout<<s-mn<<endl;
    }
    else
    {
      cout<<s<<endl;
    }
}
return 0;
}

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

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> k(M);
    for (int i = 0; i < M;i++){
        int size;
        cin >> size;
        k[i].resize(size);
        for (int j = 0; j < size;j++){
            int a;
            cin >> a;
            a--;
            k[i][j] = a;
        }
    }

    vector<int> p(M);
    for (int i = 0; i < M;i++)
        cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1 << N);bit++){
        bool ok = true;
        for (int m = 0;m < M;m++){
            int c = 0;
            for(auto v: k[m]){
                if(bit & (1 << v))
                    c++;
            }
            if(c % 2 != p[m])
                ok = false;
        }
        if(ok)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

struct Edge
{
    int u, v;

    Edge(){}
};

LL choose_2(LL n)
{
    return (n*(n - 1))/2;
}

struct DSU
{
    vector <int> parent;
    vector <LL> component_size;

    DSU(int n)
    {
        parent.resize(n + 1);
        component_size.resize(n + 1);

        for(int i = 1; i <= n; i++)
        {
            parent[i] = i;
            component_size[i] = 1;
        }
    }

    int get_parent(int x)
    {
        while(x != parent[x])
        {
            int grandparent = get_parent(parent[x]);

            parent[x] = grandparent;

            x = parent[x];
        }

        return x;
    }

    void unite(int u, int v)
    {
        int parent_u = get_parent(u), parent_v = get_parent(v);

        if(parent_u == parent_v)
            return;

        if(component_size[parent_u] > component_size[parent_v])
            swap(parent_u, parent_v);

        component_size[parent_v] += component_size[parent_u];
        component_size[parent_u] = 0;

        parent[parent_u] = parent[parent_v];
    }
};

int main()
{
    int no_of_vertices, no_of_edges;
    cin >> no_of_vertices >> no_of_edges;

    vector <Edge> edge(no_of_edges + 1);
    for(int i = 1; i <= no_of_edges; i++)
        cin >> edge[i].u >> edge[i].v;

    LL no_of_pairs = choose_2(no_of_vertices);
    vector <LL> connected_pairs(no_of_edges + 2, 0);

    DSU dsu(no_of_vertices);

    for(int i = no_of_edges; i >= 1; i--)
    {
        connected_pairs[i] = connected_pairs[i + 1];

        int parent_u = dsu.get_parent(edge[i].u), parent_v = dsu.get_parent(edge[i].v);
        //cout << "P " << edge[i].u << " = " << parent_u << " P " << edge[i].v << " = " << parent_v << endl;
        //cout << "Connected pairs = " << connected_pairs[i] << endl;
        if(parent_u == parent_v)
            continue;

        LL component_u = dsu.component_size[parent_u], component_v = dsu.component_size[parent_v];
        //cout << "C S " << edge[i].u << " =  " << component_u << " C S " << edge[i].v << " = " << component_v << endl;

        connected_pairs[i] += component_u*component_v; //cout << "After combining, size = " << connected_pairs[i] << endl;

        dsu.unite(edge[i].u, edge[i].v);
    }

    vector <LL> disconnected_pairs(no_of_edges + 1);
    for(int i = 1; i <= no_of_edges; i++)
        disconnected_pairs[i] = no_of_pairs - connected_pairs[i + 1];

    for(int i = 1; i <= no_of_edges; i++)
        cout << disconnected_pairs[i] << endl;

    return 0;
}


Measured memory_bytes: 4864
<?php

list($n, $k) = explode(' ', trim(fgets(STDIN)));
$h_list = explode(' ', trim(fgets(STDIN)));
rsort($h_list);

$count = 0;
foreach ($h_list as $index => $h) {
    if ($index < $k) {
        continue;
    }

    $count += $h;
}

echo $count;


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

#define MPI         (3.141592653589793)
#define STR_SIZE    (2)
#define SUCCESS     (0)
#define FAILURE     (-1)
#define rad(x)      (x * MPI / 180.0)

typedef enum
{
    LINE_FEED,
    BLANK,
    DELIMITER_ERROR
}DELIMITER_INFO;

typedef struct 
{
    double x;
    double y;
}POINT;

void Print_Kock_Curve(int n, POINT p1, POINT p2);
DELIMITER_INFO get_int(int *num, int min, int max);
DELIMITER_INFO get_str(char *p_str, int min, int max);
int judge_constraint(int test_num, int min, int max);


int main(void)
{
    int num;
    POINT p1 = {0,0}, p2 = {100,0};
    
    if(get_int(&num, 0, 6) != LINE_FEED)
    {
        return FAILURE;
    }
    
    printf("%.8lf %.8lf\n", p1.x, p1.y);
    Print_Kock_Curve(num, p1, p2);
    printf("%.8lf %.8lf\n", p2.x, p2.y);
    
    return SUCCESS;
}

void Print_Kock_Curve(int n, POINT p1, POINT p2)
{
    POINT s, t, u;
    
    if(n == 0)
    {
        return;
    }
    
    
    
    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
    u.x = (t.x - s.x) * cos(rad(60)) - (t.y - s.y) * sin(rad(60)) + s.x;
    u.y = (t.x - s.x) * sin(rad(60)) + (t.y - s.y) * cos(rad(60)) + s.y;
    

    Print_Kock_Curve(n - 1, p1, s);
    printf("%.8lf %.8lf\n", s.x, s.y);
    Print_Kock_Curve(n - 1, s, u);
    printf("%.8lf %.8lf\n", u.x, u.y);
    Print_Kock_Curve(n - 1, u, t);
    printf("%.8lf %.8lf\n", t.x, t.y);
    Print_Kock_Curve(n - 1, t, p2);
    
    return;
}

DELIMITER_INFO get_int(int *num, int min, int max)
{
    char str[STR_SIZE];
    DELIMITER_INFO delimiter;
    unsigned int i;
    
    delimiter = get_str(str, min, max);
    
    for(i = 0; i < STR_SIZE; i++)
    {
        if(str[i] == '\0')
    {
            break;
        }
        if(!isdigit(str[i]))
        {
            return DELIMITER_ERROR;
        }
    }
    
    *num = atoi(str);
    
    if(judge_constraint(*num, min, max) == -1)
    {
        return DELIMITER_ERROR;
    }    
    
    return delimiter;
}

DELIMITER_INFO get_str(char *p_str, int min, int max)
{
    unsigned int cnt = 0;
    int ch;
    
    while((ch = getchar()) != -1)
    {
        if(ch == ' ' || ch == '\n')
        {
            p_str[cnt] = '\0';
            if(ch == ' ')
            {
                return BLANK;
            }
            else
            {
                return LINE_FEED;
            }
        }
                        
        p_str[cnt] = ch;
        cnt++;
        
        if(judge_constraint(cnt + 1, min, max) == -1)
        {
            break;
        }
    }
    
    return DELIMITER_ERROR;
}

int judge_constraint(int test_num, int min, int max)
{
    if(test_num < min || test_num > max)
    {
        return FAILURE;
    }
    
    return SUCCESS;
}


Measured memory_bytes: 2100
#include <iostream>
#include <string>
#include <algorithm>
using namespace std; 
int n,hp,s[100010],t[100010],ans;  
int main()  
{ 
    cin>>n>>hp;
    for(int i=0;i<n;i++)cin>>s[i]>>t[i];
    sort(s,s+n,greater<int>());
    int max=s[0];
    sort(t,t+n,greater<int>());
    for(int i=0;i<n;i++)if(t[i]>max&&hp>0){hp-=t[i];ans++;}
    if(hp>0)ans+=(hp+max-1)/max;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
# メモ化+非再帰を用いた場合
case_no = 1
while True:
    W = int(input())
    if W == 0:
        break
    N = int(input())
    treasures = [tuple(map(int, input().split(','))) for _ in range(N)]
    
    V = [[0 for w in range(W+1)] for i in range(N+1)]
    weight = [[0 for w in range(W+1)] for i in range(N+1)]
    for i in range(1, N+1):
        for w in range(W+1):
            vi = treasures[i-1][0]
            wi = treasures[i-1][1]
            if wi <= w and vi != 0:
                l = V[i-1][w-wi] + vi
                r = V[i-1][w]
                if l > r:
                    V[i][w] = l
                    weight[i][w] = weight[i-1][w-wi] + wi
                else:
                    V[i][w] = r
                    weight[i][w] = weight[i-1][w]
            else:
                V[i][w] = V[i-1][w]
                weight[i][w] = weight[i-1][w]
    
    sum_value = 0
    sum_weight = 1e100
    for i in range(1, N+1):
        for j in range(W+1):
            if V[i][j] > sum_value or (V[i][j] == sum_value and weight[i][j] < sum_weight):
                sum_value = V[i][j]
                sum_weight = weight[i][j]
    
    print('Case {}:'.format(case_no))
    print(sum_value)
    print(sum_weight if sum_weight != 1e100 else 0)
    case_no += 1



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

int main (){
    char x, y;
    cin>>x>>y;
    if(x>y){
        cout<<">"<<endl;
    }
    else if(x<y){
        cout<<"<"<<endl;
    }
    else{
        cout<<"="<<endl;
    }
}

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

const ll mod=1e9+7;

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

/*-------------------------------------------*/

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

    ll n,m,x=-1,G=0,a;
    cin>>n>>m;
    rep(i,n){
        cin>>a;
        a/=2;
        if(!G)G=a;
        else G=G*a/__gcd(G,a);
        int y=0;
        while(a%2==0){
            y++;
            a/=2;
        }
        if(x==-1)x=y;
        else if(x!=y){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<(m/G+1)/2<<endl;
}

Measured memory_bytes: 256
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def intmax(a,b) return (a>b)? a:b end
n,t = inp
tt= na2(n,2)
a = na(n)
b = na(n)
n.times do |i|
  tt[i] = inp
end
tt.sort_by!{|u|u[0]}
n.times do |i|
  a[i],b[i] = tt[i]
end
ans = 0
dp = na(t+1)
l = dp.size-1
n.times do |i|
  ans = [ans,dp[-2]+b[i]].max
  next if(a[i] > t)
  l.downto(a[i]) do |j|
    dp[j] = intmax(dp[j-a[i]]+b[i],dp[j])
  end
end
p ans

Measured memory_bytes: 2296
n,m,x = gets.chomp.split(" ").map(&:to_i)
arr = []
n.times do |i|
  arr[i] = []
  gets.chomp.split(" ").each_with_index do |a, j|
    arr[i][j] = a.to_i
  end
end

min = 9999999999999

(2 ** n).times do |t|
  tmp = []
  m.times do |i|
    tmp[i] = 0
  end
  coin = 0
  ("%0#{n}d" % t.to_s(2)).split("").each_with_index do |flag, i|
    next if flag == "0"
    coin += arr[i][0]
    arr[i][1..-1].each_with_index do |a, j|
      tmp[j] += a
    end
  end
  if tmp.all?{|a| a >= x}
    min = coin if coin < min
  end
end
if min == 9999999999999
  puts "-1"
else
  puts min
end


Measured memory_bytes: 14316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int i;
	String N = br.readLine();
	int Num = Integer.parseInt(N);
	long sum = 0;

	for (i = 1; i <= Num; i++ ) {
		if (i % 3 != 0 && i % 5 != 0) sum = sum + i;
	}

	System.out.println(sum);
	}
}

Measured memory_bytes: 25620
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")


N,M = map(int,input().split())
Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    Adj_list[a-1].add((b-1, c))
    Adj_list[b-1].add((a-1, -c))
visited =[None]*(N)
ok = True
stack = []
for x in range(N):
   if visited[x] is not None:continue
   visited[x] = 0
   stack = [x]
   while stack:
       v = stack.pop()
       for to,d in Adj_list[v]:
           if visited[to] is None:
               visited[to] = visited[v] + d
               stack.append(to)
           else:
               if visited[to] != visited[v]+d:
                   ok = False
                   break
   if ok == False:
        break
print("Yes" if ok else "No")

Measured memory_bytes: 111744
n = int(input())
d = {}

for i in range(1, n+1):
    s, p = input().split()
    p = int(p)
    d[i] = (s, p)

d = sorted(d.items(), key=lambda x:x[1][1], reverse=True)
d = sorted(d, key=lambda x:x[1][0])

for e in d:
    print(e[0])

Measured memory_bytes: 62900
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader: reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_as_vec<T: FromStr>(&mut self) -> Vec<T> {
    self.iter.clone().map(|v| v.parse().ok().unwrap()).collect()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  let mut ans = 0;
  let mut t = Vec::with_capacity(5);
  for _ in 0..5 {
    sc.new_line();
    t.push(scan!(sc; i32));
  }
  for &i in t.iter() {
    if i % 10 == 0 {
      ans += i;
    }
  }
  let mut t = t.iter()
    .filter(|x| *x % 10 != 0)
    .map(|&x| x)
    .collect::<Vec<i32>>();
  t.sort_by(|a, b| (b % 10).cmp(&(a % 10)));
  let mut tmp = 0;
  for &v in t.iter() {
    ans += v;
    tmp = 10 - (ans % 10);
    ans += tmp;
  }
  ans -= tmp;
  println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int S, W;
  cin >> S >> W;
  if (S<=W) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3624