akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct SuffixArray {
  vector< int > SA;
  const string s;

  SuffixArray(const string &str) : s(str) {
    SA.resize(s.size());
    iota(begin(SA), end(SA), 0);
    sort(begin(SA), end(SA), [&](int a, int b) {
      return s[a] == s[b] ? a > b : s[a] < s[b];
    });
    vector< int > classes(s.size()), c(s.begin(), s.end()), cnt(s.size());
    for(int len = 1; len < s.size(); len <<= 1) {
      for(int i = 0; i < s.size(); i++) {
        if(i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() && c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {
          classes[SA[i]] = classes[SA[i - 1]];
        } else {
          classes[SA[i]] = i;
        }
      }
      iota(begin(cnt), end(cnt), 0);
      copy(begin(SA), end(SA), begin(c));
      for(int i = 0; i < s.size(); i++) {
        int s1 = c[i] - len;
        if(s1 >= 0) SA[cnt[classes[s1]]++] = s1;
      }
      classes.swap(c);
    }
  }

  int operator[](int k) const {
    return SA[k];
  }

  size_t size() const {
    return s.size();
  }

  bool lt_substr(const string &t, int si = 0, int ti = 0) {
    int sn = (int) s.size(), tn = (int) t.size();
    while(si < sn && ti < tn) {
      if(s[si] < t[ti]) return true;
      if(s[si] > t[ti]) return false;
      ++si, ++ti;
    }
    return si >= sn && ti < tn;
  }

  int lower_bound(const string &t) {
    int low = -1, high = (int) SA.size();
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(lt_substr(t, SA[mid])) low = mid;
      else high = mid;
    }
    return high;
  }

  pair< int, int > lower_upper_bound(string &t) {
    int idx = lower_bound(t);
    int low = idx - 1, high = (int) SA.size();
    t.back()++;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(lt_substr(t, SA[mid])) low = mid;
      else high = mid;
    }
    t.back()--;
    return {idx, high};
  }

  void output() {
    for(int i = 0; i < size(); i++) {
      cout << i << ": " << s.substr(SA[i]) << endl;
    }
  }
};


struct LongestCommonPrefixArray {
  const SuffixArray &SA;
  vector< int > LCP, rank;

  LongestCommonPrefixArray(const SuffixArray &SA) : SA(SA), LCP(SA.size()) {
    rank.resize(SA.size());
    for(int i = 0; i < SA.size(); i++) {
      rank[SA[i]] = i;
    }
    for(int i = 0, h = 0; i < SA.size(); i++) {
      if(rank[i] + 1 < SA.size()) {
        for(int j = SA[rank[i] + 1]; max(i, j) + h < SA.size() && SA.s[i + h] == SA.s[j + h]; ++h);
        LCP[rank[i] + 1] = h;
        if(h > 0) --h;
      }
    }
  }

  int operator[](int k) const {
    return LCP[k];
  }

  size_t size() const {
    return LCP.size();
  }

  void output() {
    for(int i = 0; i < size(); i++) {
      cout << i << ": " << LCP[i] << " " << SA.s.substr(SA[i]) << endl;
    }
  }
};

int main() {
  string S;
  int Q;

  cin >> S;
  SuffixArray sa(S);
  cin >> Q;
  while(Q--) {
    string T;
    cin >> T;
    auto range = sa.lower_upper_bound(T);
    cout << (range.first != range.second) << endl;
  }
}


Measured memory_bytes: 19528
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const LL M=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int x,y;

LL qpow(LL a, LL b ,LL mod)
{
    LL res=1;
    while(b!=0)
    {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

bool arr[maxn+1]={false}; 
vector<int> produce_prim_number() 
{ 
        vector<int> prim; 
        prim.push_back(2); 
        int i,j; 
        for(i=3;i*i<=maxn;i+=2) 
        { 
                if(!arr[i]) 
                { 
                        prim.push_back(i); 
                        for(j=i*i;j<=maxn;j+=i) 
                                arr[j]=true; 
                } 
        } 
        while(i<maxn) 
        { 
                if(!arr[i]) 
                        prim.push_back(i); 
                i+=2; 
        } 
        return prim; 
} 
//计算n!中素数因子p的指数  
int cal(int x,int p) 
{ 
        int ans=0; 
        long long rec=p; 
        while(x>=rec) 
        { 
                ans+=x/rec; 
                rec*=p; 
        } 
        return ans; 
} 
//计算n的k次方对m取模，二分法  
int pow(long long n,int k,int M) 
{ 
        long long ans=1; 
        while(k) 
        { 
                if(k&1) 
                { 
                        ans=(ans*n)%M; 
                } 
                n=(n*n)%M; 
                k>>=1; 
        } 
        return ans; 
} 
//计算C（n，m）  
int combination(int n,int m) 
{ 
        //const int M=10007; 
        vector<int> prim=produce_prim_number(); 
        long long ans=1; 
        int num; 
        for(int i=0;i<prim.size()&&prim[i]<=n;++i) 
        { 
                num=cal(n,prim[i])-cal(m,prim[i])-cal(n-m,prim[i]); 
                ans=(ans*pow(prim[i],num,M))%M; 
        } 
        return ans; 
} 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>x>>y;
    if((x+y)%3!=0)
    {
        cout<<0;
        return 0;
    }
    int res=(x+y)/3;
    int n=x-res;
    int m=y-res;
    if(n<0||m<0)
    {
        cout<<0;
        return 0;
    }
    if(n<m)
        swap(n,m);
    cout<<combination(m+n,m)<<endl;
    return 0;
}

Measured memory_bytes: 1916
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);
    long a = input.nextLong();
    long b = input.nextLong();
    System.out.println(lcm(a,b));
  }



static long gcd(long a, long b) 
    { 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
    } 
      
    // method to return LCM of two numbers 
    static long lcm(long a, long b) 
    { 
        return (a*b)/gcd(a, b); 
    } 
}


Measured memory_bytes: 23636
//
// Created by Hideaki Imamura on 2020-03-28.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

void print_vec(vector<ll> v) {
    for (auto x : v) cout << x << " ";
    cout << endl;
}
# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

ll K, N;
vector<ll> A;

int main() {
    cin >> K >> N;
    A.assign(N + 1, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    A[N] = A[0] + K;

    vector<ll> interval(N, 0);
    for (int i = 0; i < N; ++i) interval[i] = A[i+1] - A[i];
    //print_vec(interval);
    cout << K - *max_element(interval.begin(), interval.end()) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(void){
  int h,w,i;
  char a[101][101];

  scanf("%d %d",&h,&w);

  for(i=0;i<h;i++){
    scanf("%s",&a[i][0]);
  }
  for(i=0;i<w+2;i++){
    printf("#");
  }
  printf("\n");

  for(i=0;i<h;i++){
    printf("#%s#\n",a[i]);
  }

  for(i=0;i<w+2;i++){
    printf("#");
  }
  printf("\n");
  return 0;
}


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

int main(void)
{
    char str[1001],tmp[1001],p[1001],command[10];
    int q,a,b,i,j;
 
    scanf("%s %d",str,&q);

    for(j=0;j<q;j++)
    {
        scanf("%s %d %d",command,&a,&b);
        if(!strcmp(command,"print"))
        {
            for(i=a;i<=b;i++)printf("%c",str[i]);
            printf("\n");
        }
        if(!strcmp(command,"reverse"))
        {
            strcpy(tmp,str);
            for(i=a;i<=b;i++)str[i]=tmp[b-(i-a)];
        }
        if(!strcmp(command,"replace"))
        {
            scanf("%s",p);
            for(i=a;i<=b;i++)str[i]=p[i-a];
        }
    }
    return 0;
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	string s, t;
	cin >> s >> t;
	cout << t << s << endl;



	return 0;
}


Measured memory_bytes: 3592
input()
a = input().rstrip().split()
a = [int(a_i) for a_i in a]

res = 1
if 0 in a:
    print(0)
else:
    for a_i in a:
        a_i = int(a_i)
        res = res * a_i
        if res > 1000000000000000000:
            print(-1)
            break
    else:
        print(res)


Measured memory_bytes: 21692
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <random>
#include <stack>
#include <ctime>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;
using VP = vector<P>;

int main() {
    long n, k;
    cin >> n >> k;
    VI as;
    long minind;
    REP(i,n) {
        long a;
        cin >> a;
        as.push_back(a);
        if (a == 1) minind = i;
    }
    long cnt = 0;
    long i = 0;
    while (1) {
        if (i <= minind && minind < i + k) {
            i += k;
            cnt++;
        } else {
            i += k - 1;
            cnt++;
        }
        if (i >= n) {
            cout << cnt << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 1400
N = int(input())
T, A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
h = [abs(A - (T - x * 0.006)) for x in H]

m = h[0]
ans = 1
for i in range(len(h)):
    if h[i] < m:
        m = h[i]
        ans = i + 1


print(ans)

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

using namespace std;
using Int = long long;

signed main(){
    Int n;
    cin >> n;
    vector<Int> a;
    for(Int i = 0; i < n; i++){
        Int tmp_a;
        cin >> tmp_a;
        a.push_back(tmp_a);
    }
    vector<Int> m;
    Int sum = 0;
    for(Int i = 0; i < n; i++){
        if(i % 2 == 0){
            sum += a[i] * 2;
        } else {
            sum -= a[i] * 2;
        }
    }
    m.push_back(sum / 2);
    for(Int i = 1; i < n; i++){
        m.push_back(2 * a[i - 1] - m[i - 1]);
    }

    for(Int i = 0; i < n - 1; i++){
        cout << m[i] << " ";
    }
    cout << m[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=998244353;
#define INF 2*1e9
#define N 210000
using namespace std;

main(){
    string s;
    cin>>s;
    if(s.size()==3){
        int t[3]={};
        rep(i,3){
            t[(int)(s[i]-'a')]++;
        }
        if(t[0]&&t[1]&&t[2]){cout<<3;return 0;}
    }
    rep(i,s.size()){
        if(s[0]!=s[i]) break;
        if(i==s.size()-1){
            cout<<1;return 0;
        }
    }
    ll sum=0,check=1;
    rep(i,s.size()){
        sum+=(s[i]-'a');
        sum%=3;
        if(i<s.size()-1&&s[i]==s[i+1]){
            check=0;
        }
    }
    ll dp[N][3][3][2]={};//何番目、最後の数、和、今までにあるか
    dp[0][0][0][0]=dp[0][1][1][0]=dp[0][2][2][0]=1;
    rep(i,s.size()-1){
        rep(j,3){
            rep(k,3){
                rep(l,2){
                    rep(m,3){
                        if(m!=j)
                            dp[i+1][m][(k+m)%3][l]
                            =(dp[i+1][m][(k+m)%3][l]+dp[i][j][k][l])%MOD;
                        else{
                            dp[i+1][m][(k+m)%3][1]
                            =(dp[i+1][m][(k+m)%3][1]+dp[i][j][k][l])%MOD;
                        }
                    }
                }
            }
        }
    }
    rep(i,3){
        check=(check+dp[s.size()-1][i][sum][1])%MOD;
    }
    cout<<check;
    return 0;
}

Measured memory_bytes: 30084
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.nextInt()
    val w = sc.nextInt()
    println(problem164a(s, w))
}

fun problem164a(s: Int, w: Int): String {
    return if (s <= w) "unsafe" else "safe"
}

Measured memory_bytes: 36584
def solve(n,S):
    Used=[False]*len(S)
    Cur=[]
    Cur.append(S[0])
    Used[0]=True
    for _ in range(n):
        idx=0
        num=len(Cur)
        for i,s in enumerate(S):
            if (not Used[i]) and s<Cur[idx]:
                Cur.append(s)
                idx+=1
                Used[i]=True
                if idx==num:
                    break
        else:
            return 'No'
        Cur.sort(reverse=True)
    return 'Yes'

n=int(input())
S=list(map(int,input().split()))
S.sort(reverse=True)
print(solve(n,S))

Measured memory_bytes: 119244
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
typedef pair<long long, long long> pll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//abc131_e
int main() {
    ll N,K;
    cin >> N >> K;

    //最短距離が2の組み合わせの最大値
    ll ma = (N-1)*(N-2)/2;
    if(ma < K)
    {
        cout << -1 << endl;
        return 0;
    }
    vector <pll> res;
    //Nとすべてを連結させる
    //Nを真ん中にする
    for(ll i = 1; i <= N-1; ++i)
    {
        res.push_back({i, N});
    }
    //距離1にしてしまう数
    ll rem = ma - K;
    //1,2から順に距離1にする
    ll ci = 1; 
    ll cj = 2;

    for(ll i = 0; i < rem; ++i)
    {
        res.push_back({ci,cj});
        
        ++cj;
        //頂点対を更新
        if(cj == N)
        {
            ++ci;
            cj = ci + 1;
        }
    }

    cout << res.size() << endl;

    for(auto v:res)
    {
        cout << v.first << " " << v.second << endl;
    }

    return 0;
    
}

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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n) cin >> v[i];
	vi ans(n);
	vi sum(n, 0);
	RREP(i, n) {

		ans[i] = (sum[i] % 2) ^ v[i];
		if (ans[i]) {
			int a = i + 1;
			set<int> st;
			for (int j = 2; j * j <= a; ++j) {
				if (a % j == 0) {
					st.insert(j);
					if (j * j != a) st.insert(a / j);
				}
			}
			st.insert(1);
			for (auto s : st) {
				sum[s - 1]++;
			}
		}
	}
	vi res;
	REP(i, n) {
		if (ans[i]) res.push_back(i + 1);
	}
	cout << res.size() << endl;

	REP(i, res.size()) cout << res[i] << " ";
	cout << endl;
}

Measured memory_bytes: 3832
import java.util.Scanner;

public class Main {


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

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();
		long num = 1;
		long mod= 1000_000_007;
		for(int i=1;i<=n;i++) {
			num = num * i % mod;
		}
		System.out.println(num);

	}

}


Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    ll count = 0;
    for (int i = 0; i < N; ++i) {
        ll tmp = 0;
        if(A[i] != B[i]){
            tmp++;
        }
        if(B[i] != C[i]){
            tmp++;
        }
        if(C[i] != A[i]){
            tmp++;
        }
        if(tmp == 2){
            count++;
        }
        if(tmp == 3){
            count+=2;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    long long int s; cin >> s;
    long long int x2, y2, x3;
    x3 = ceil(pow(s, 0.5));
    y2 = ceil(pow(s, 0.5));
    x2 = x3*y2 - s;
    cout << 0 <<" " <<  0 <<" "<< x2 << " " << y2 << " "<< x3 << " " << 1 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstring>

using namespace std;

int main(){
	int N, M;
	cin >> N >> M;
	int A[M];
	for (int i=0;i<M;i++){
		cin >> A[i];
	}
	sort(A,A+M);
	int NUM[10] = {0,2,5,5,4,5,6,3,7,6};
	int dp[N+1];
	memset(dp, -10000000, sizeof(dp));
	dp[0] = 0;
	for(int j=1;j<N+1;j++){
		for(int i=0;i<M;i++){
			if(j >= NUM[A[i]]){
				dp[j] = max(dp[j-NUM[A[i]]] + 1,dp[j]);
			}
		}
	}
	int zan = N;
	for(int i = dp[N];i >0;i--){
		for(int j = M-1;j>=0;j--){
			if(dp[zan-NUM[A[j]]] ==i -1 && zan >= NUM[A[j]]){
				cout << A[j];
				zan = zan - NUM[A[j]];
				break;
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let A = read![[i64]];
    let B = read![[i64]];

    if A.iter().sum::<i64>() < B.iter().sum::<i64>() {
        println!("-1");
        return;
    }

    let mut t = 0_i64;
    let mut k = 0;
    let mut y = vec![];

    for i in 0..N {
        if A[i] >= B[i] {
            y.push(A[i] - B[i]);
        } else {
            t += B[i] - A[i];
            k += 1;
        }
    }

    y.sort();
    y.reverse();
    for i in 0..y.len() {
        if t <= 0 {
            break;
        }
        t -= y[i];
        k += 1;
    }

    println!("{}", k);
}


Measured memory_bytes: 11512
#include <bits/stdc++.h>
using namespace std;
// int N が既に与えられているとする. 

int main(){
  int N; cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += max(V.at(i) - C.at(i), 0);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n;
	int a[20],v[20];
	int i,c;
	int b;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i], &v[i]);
	}
	b=0;
	
	for(c=1;c<n;c++){
		if(v[c]>v[b]){
			b=c;
		}
		else if(v[c]==v[b]){
			if(a[c]<a[b]){
				b=c;
			}
		}
	}
	printf("%d %d\n",a[b],v[b]);
	
	return(0);
}

Measured memory_bytes: 600
while true
    n = gets.to_i
    break if n == 0
    y = gets.to_i
    max = [0.0, 0]
    n.times{
        b, r, t = gets.chomp.split.map(&:to_i)
        x = 0
        case t
        when 1 then x = 1 + (r / 100.0) * y
        when 2 then x = (1 + r / 100.0) ** y
        end
        max = [x, b] if max[0] < x
    }
    puts max[1]
end


Measured memory_bytes: 6940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    string s,t;
    cin >> s >> t;
    For(i,0,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3916
#include <stdio.h>

main() {
  int array[100];
  int i, n;
  
  scanf("%d", &n);
  
  
  for (i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }
  for (i = n-1; i >= 0; i--) {
    printf("%d", array[i]);
    if (i != 0) {
      printf(" ");
    }
    
  }
  printf("\n");
  return 0; 
}

Measured memory_bytes: 600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int sum(vector<int> A){
    int res = 0;
    for (int a : A) res += a;
    return res;
}

class Range {
    public:
        int start;
        int step;
        int length;
        int operator[](int i){
            return start + step * i;
}
};
int sum(Range A){
    return (2 * A.start + (A.length - 1) * A.step) * A.length / 2;
}
template <typename T>
vector<T> slice_vector(vector<T> A,int start_idx,int fin_idx){
    vector<T> res(fin_idx - start_idx);
    for (int i = start_idx; i < fin_idx; i++)
    {
        res[i-start_idx] = A[i];
    }
    return res;
}
template <typename T>
void cout_vector(vector<T> A){
    for (int i=0;i<A.size();i++){
        cout << A[i] << " ";  
    }
    cout << endl;
}
template <typename T>
int minimum(vector<T> A){
    int m = 10^100;
    for (T a : A){
     if (a < m) m = a;
    }
    return m;
}

template <typename T>
int maximum(vector<T> A){
    int m = 10^-100;
    for (T a : A) {
        if (a > m) m = a;
    }
    return m;
}


int main(){
    int A,B,C,D,E,as,bs,cs,ds,es;
    vector<int> Times(5);
    vector<int> remTimes(5);
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    cin >> E;
    as = 10 - A % 10;
    bs = 10 - B % 10;
    cs = 10 - C % 10;
    ds = 10 - D % 10;
    es = 10 - E % 10;
    remTimes = {as,bs,cs,ds,es};
    Times = {A,B,C,D,E};
    rep(i,5) (remTimes[i] != 10) ? (Times[i] += remTimes[i]) : (remTimes[i] = 0);
    int ans = sum(Times) - maximum(remTimes);
    cout << ans << endl;
}

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

int main(){
  ll n; cin >> n;
  vector<ll> v(3*n);
  for(ll i = 0; i < 3*n; i++){
    cin >> v[i];
  }

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

  ll sum = 0;
  for(ll i = 3*n-2; i > n-1; i -= 2){
    sum += v[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
   
    int h, n;
    cin >> h >> n;
    int x = 0;
    vector<pair<int, int>>p(n);
    vector<long long int>d(h + 10003, 99999999999);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        d[p[i].first] = p[i].second;
        x = max(x, p[i].first);
    }
    d[0] = 0;
    for (int i = x; i > 0; i--) {
        d[i] = min(d[i + 1],d[i]);
    }

    for (int i = 0; i <= h; i++) {
        for (int j = 0; j < n; j++) {
            d[i + p[j].first] = min(d[i + p[j].first], d[i] + p[j].second);
        }
       
    }

    while(d[h] == 99999999999) {
    
        h++;

    }
    for (int i = h; i < d.size(); i++)d[h] = min(d[h], d[i]);

    cout << d[h] << endl;
    

    return 0;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int 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;
  cin >> n;
  string s;
  while(n > 0) {
    n--;
    s += char(n % 26 + 'a');
    n /= 26;
  }
  reverse(all(s));
  cout << s << endl;
}

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

struct UnionFind {
    vector<ll> par,rank,cnt; // par[i]:iの親の番号,rank[r]:rを根とする木の高さ,cnt[r]:rを根とする木の要素数

    UnionFind(ll N){ //全て根として初期化
        for(ll i = 0; i < N; i++) par.push_back(i);
        rank.assign(N,0);
        cnt.assign(N,1);
    }

    ll root(ll x){ // xの根を返す
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x,ll y){ // xの木とyの木を併合
        ll rx = root(x); 
        ll ry = root(y);
        if (rx == ry) return;
        
        if(rank[rx] < rank[ry]){
            par[rx] = ry;
            cnt[ry] += cnt[rx]; 
        }else{
            par[ry] = rx;
            cnt[rx] += cnt[ry];
            if(rank[x] == rank[y]) rank[rx] ++;
        }
    }

    ll tsize(ll x){ //　xの木の要素数を返す
        ll rx = root(x);
        return cnt[rx];
    }

    bool same(ll x,ll y){ // xとyが同一の木に存在するかを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m),ans(m);
    for(ll i = 0;i < m;i ++){
        cin >> a[i] >> b[i];
        a[i] --;b[i] --;
    }
    UnionFind tree(n);
    ans[m-1] = (n*(n-1))/2;
    for (ll i = m-1;i >= 1;i --){
        ll as = tree.tsize(a[i]),bs = tree.tsize(b[i]);
        bool isCom = tree.same(a[i],b[i]);
        tree.unite(a[i],b[i]);
        ll us = tree.tsize(a[i]);
        ans[i-1] = ans[i]-(isCom?0:(us*(us-1)-as*(as-1)-bs*(bs-1))/2);
    }
    for(ll i = 0;i < m;i ++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6132
#include<stdio.h>
#include<string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp{
    char name[100];
    int t;
}p;

p Q[LEN];
int head, tail, n;

void enqueue(p x){
    Q[tail] = x;
    tail = (tail+1) % LEN;
}

p dequeue(){
    p x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b ? a:b; }

int main(){
    int elaps = 0, c;
    int i, q;
    p u;
    scanf("%d %d", &n, &q);

    /* すべてのプロセスをキューに順番に追加する */
    for( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;

    /* シミュレーション */
    while( head != tail){
        u = dequeue();
        c = min(q, u.t);    /* qまたは必要な時間u.tだけ処理を行う */
        u.t -= c;   /* 残りの必要時間を計算 */
        elaps += c; /* 経過時間を加算 */
        if( u.t > 0 ) enqueue(u);   /* 処理が完了していなければuに移動 */
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}





Measured memory_bytes: 11924
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int a,b,w;
    cin>>w>>a>>b;
    int ans=0;
    if(a+w<b)ans=b-a-w;
    else if(b+w<a)ans=a-b-w;
    else ans=0;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
len=int(input())
list = input().split(" ")
msg="DENIED"
for i in range(len):
  if int(list[i])%2==0 and (int(list[i])%3==0 or int(list[i])%5==0):
    msg="APPROVED"
  elif int(list[i])%2==0:
    msg="DENIED"
    break
  else:
    msg="APPROVED"  
print(msg)

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

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

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

    ll ans=0;
    for(ll in=1;in<=n;in++) {
        if(in%3!=0&&in%5!=0) ans += in;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
arr=[1,2]
arr=arr+[0]*(n-2)
danger=[int(input()) for _ in range(m)]
if danger==[]:
  pass
elif danger[0]==1:
  arr[0]=0
  arr[1]=1
for i in range(m):
  arr[danger[i]-1]=-1
for i in range(n):
  if arr[i]==-1:
    arr[i]=0
  elif i==0 or i==1:
    continue 
  else:
    arr[i]=(arr[i-1]+arr[i-2])%(10**9+7)
print(arr[n-1]%(10**9+7))


Measured memory_bytes: 45004
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,x,y;
  cin >> n >> x >> y;

  long list[n+3] = {0};
  
  for(long i=1; i<n; i++){
    for(long j=i+1; j<n+1; j++){
      //cout << i << ' ' << j << endl;
      long dist = j-i;
      dist = min(dist,max(i-x,x-i)+1+max(j-y,y-j));
      //cout << dist << endl;
      list[dist]++;
    }
  }
  for(long i=1; i<n; i++){
    cout << list[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Data.Maybe

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    (ngs :: VUM.IOVector Bool) <- VUM.replicate (10^5+100) False
    (dp :: VUM.IOVector Int) <- VUM.replicate (10^5+100) 0

    replicateM_ m $ do
        i <- fst . fromJust . B.readInt <$> B.getLine
        VUM.modify ngs (||True) i

    VUM.write dp 0 1

    forM_ [0..10^5] $ \i -> do
        ng <- VUM.read ngs i
        curr <- VUM.read dp i
        unless ng $
            forM_ [i+1,i+2] $ \j -> do
                ng' <- VUM.read ngs j 
                dist <- VUM.read dp j
                unless ng' $ do
                    VUM.write dp j ((curr + dist) `mod` (10^9+7))

    VUM.read dp n >>= print

Measured memory_bytes: 1916
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = list(map(int,stdin.readline().rstrip().split()))
from itertools import permutations
lis = permutations(li)

liv = []

for i in lis:
    liv.append(list(i))
liv.sort()
a = liv.index(li)
b = liv.index(lin)

print(abs(a-b))

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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

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

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

    vi dp(W+1, 0);
    for(int i=0; i<=W; i++){
        for(int j=0; j<N; j++){
            if(w[j] <= i) chmax(dp[i], dp[i-w[j]]+v[j]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}


Measured memory_bytes: 3140
import java.util.*;

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

        int N = sc.nextInt();
        int[] X = new int[N];

        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }

        int minSum = 1000000000;
        int sum = 0;

        for (int P = 0; P <= 100; P++) {
            for (int i = 0; i < N; i++) {
                sum += Math.pow(X[i] - (P + 1), 2);
            }
            minSum = Math.min(minSum, sum);
            sum = 0;
        }

        System.out.println(minSum);

    }
}


Measured memory_bytes: 21716
import numpy
n=int(input())
l=list(map(int, input().split()))
res=0
mod=10**9+7
l.append(0)
l.reverse()
cum=numpy.cumsum(l)%mod
for i in range(n):
    res+=((l[n-i]%mod)*cum[n-i-1])%mod
print(res%mod)

Measured memory_bytes: 49820
Imports System

Module Program

	Public Function CountChar(ByVal s As String, ByVal c As Char) As Integer
		Return s.Length - s.Replace(c.ToString(), "").Length
	End Function

	Sub Main()

		Dim msg As String
		Dim s As String
		Dim parts As String()
		Dim cnt1, cnt2, cnt3, cnt4 As Integer

		s = Console.ReadLine()
		parts = Split(s, " ", -1, CompareMethod.Binary)


		s = ""

		For Each p As String In parts
			s += p
		Next

		cnt1 = CountChar(s, "1")
		cnt2 = CountChar(s, "9")
		cnt3 = CountChar(s, "7")
		cnt4 = CountChar(s, "4")

		If cnt1 = 1 And cnt2 = 1 And cnt2 = 1 And cnt4 = 1 Then
			msg = "YES"
		Else
			msg = "NO"
		End If

		Console.WriteLine(msg)
    End Sub
End Module


Measured memory_bytes: 13536
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String ans = "";

		if (n < 1200) {
			ans = "ABC";
		} else {
			ans = "ARC";
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
L,A,B,M=map(x->parse(Int,x),split(readline()))
ans=0
function f(a,b,c,d,u,s)
	X,Y=ans,s
	if u>0
		X,Y=f(a*a%M,b*(a+1)%M,(b*d%M+c*(a+1)%M)%M,2*d%M,div(u,2),s)
	end
	if u%2==1
		X=(a*X%M+b*Y%M+c)%M
		Y=(Y+d)%M
	end
	X,Y
end
pre=0
g=1
for d=1:18
	l=pre-1
	r=L
	g*=10
	while r-l>1
		m=div(r+l,2)
		if A+B*m<g
			l=m
		else
			r=m
		end
	end
	ans,_=f(g%M,1,0,B%M,r-pre,(A%M+B%M*pre%M)%M)
	pre=r
end
println(ans)

Measured memory_bytes: 172900
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
#define ll long long
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
using namespace std;
int a[1000];
int main() {
    ll n,k;
    cin >> n >> k;
    REP(i,k) {
        ll d;
        cin >> d;
        REP(j, d) {
            ll tmp;
            cin >> tmp;
            tmp--;
            a[tmp]++;
        }
    }
    ll cnt = 0;
    REP(i,n) {
        if(a[i] == 0) {
            cnt++;
        }
    }
    cout << fixed << cnt;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

int main()
{
    std :: ios_base :: sync_with_stdio(false);

    long long n , res{};
    std :: cin >> n;

    std :: map <std :: string , long long> m;

    for(int i = 0 ; i < n ; i++)
    {
        std :: string s;
        std :: cin >> s;
        std :: sort(s.begin() , s.end());

        m[s]++;
    }

    for(auto i : m)
        res += i.second * (i.second - 1) / 2;

    std :: cout << res << '\n';
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int n, ans = 0;
    cin >> n;
    vector <int> a(n+1);
    for (int i = 0; i < n; i++) cin >> a[i];
    a[n] = -1;

    for (int i = 0; i < n; i++) {
        if (a[i] == i+1 and a[i+1] == i+2) {
            ans++;
            i++;
        }
        else if (a[i] == i+1) ans++; 
    }

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

Measured memory_bytes: 640
n, a=gets.split.map(&:to_i)
xs=gets.split.map(&:to_i)

s=xs.inject(:+)
dp=Array.new(n+1){Array.new(s+1, 0)}
dp[0][0]=1
xs.each do |x|
  n.downto 0 do |i|
    s.downto 0 do |j|
      if j+x<=s and dp[i][j]>0
        dp[i+1][j+x]+=dp[i][j]
      end
    end
  end
end

ret=(1..n).reduce(0) do |res, i|
  res+(i*a>s ? 0 : dp[i][i*a])
end

puts ret


Measured memory_bytes: 2812
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

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

int main()
{
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if (k - a <= 0)
  {
    cout << k;
  }
  else if (k - a - b <= 0)
  {
    cout << a;
  }
  else
  {
    cout << a - (k - a - b);
  }

  return 0;
}

Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            String[] values = line.split(" ");
            if (values.length < 8) {
                break;
            }
            double x1 = Double.parseDouble(values[0]);
            double y1 = Double.parseDouble(values[1]);
            double x2 = Double.parseDouble(values[2]);
            double y2 = Double.parseDouble(values[3]);
            double x3 = Double.parseDouble(values[4]);
            double y3 = Double.parseDouble(values[5]);
            double xp = Double.parseDouble(values[6]);
            double yp = Double.parseDouble(values[7]);
            double area12 = area(xp, yp, x1, y1, x2, y2);
            double area23 = area(xp, yp, x2, y2, x3, y3);
            double area31 = area(xp, yp, x3, y3, x1, y1);
            double area123 = area(x1, y1, x2, y2, x3, y3);
            String result = area12 + area23 + area31 - area123 < 0.0001 ? "YES"
                    : "NO";
            out.println(result);
        }
    }

    static double area(double x1, double y1, double x2, double y2, double x3,
            double y3) {
        return 0.5 * Math.abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1));
    }
}

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

int main() {
  string S;
  string T;
  string S2;
  cin >> S >> T;
  S2="UNRESTORABLE";
  int s,t;
  s = S.size();
  t = T.size();
  int i,j,k;
  for(i=s-t;i>=0;i--) {
    int j=0;
    while(j<=t-1) {
	if (S[i+j]==T[j]||S[i+j]=='?') {
		j+=1;
	}
	else break;
    }
    if(j==t) {
	S2=S;
	for(k=i;k<i+t;k++) {
		S2[k]=T[k-i];
	}
	for(k=0;k<s;k++) {
		if(S2[k]=='?') S2[k]='a';
	}
	  cout << S2 << endl;
	  return 0;
    }
  }
  cout << S2 << endl;
  return 0;  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int X = stdIn.nextInt();
		int[] m = new int[N];
		m[0] = stdIn.nextInt();
		X -= m[0];
		int min = m[0];
		for(int i = 1; i < N; i++) {
			m[i] = stdIn.nextInt();
			X -= m[i];
			if(m[i] < min) {
				min = m[i];
			}
		}
		System.out.println(N+X/min);

	}

}

Measured memory_bytes: 21844
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:usize,b:usize}
    if a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;
double x[12];
string u[12];

int main(){
   int n;
   cin>>n;
   for(int i=0;i<n;i++){
      cin>>x[i]>>u[i];
   }
   double ans=0;
   for(int i=0;i<n;i++){
      if(u[i]=="JPY"){
         ans+=x[i];
      }
      else ans+=x[i]*380000.0;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
def main():

    H, N = map(int, input().split())

    ab = [tuple(map(int, input().split())) for _ in range(N)]

    INF = float("inf")
    dp = [[INF for _ in range(H+1)] for _ in range(N+1)]
    dp[0][0] = 0


    for i in range(1, N+1):
        for h in range(H+1):
            aaa = h-ab[i-1][0] if h-ab[i-1][0] >= 0 else 0
            tmp = dp[i][aaa] if dp[i][aaa] != INF else 0
            dp[i][h] = min(dp[i-1][h], tmp + ab[i-1][1])

    print(dp[-1][H])


if __name__ == "__main__":
    main()

Measured memory_bytes: 289288
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
l = abs(A-B)
U = V-W
if U < 0:
    print('NO')
elif U == 0 and l!=0:
    print('NO')
elif l == 0:
    print('YES')
elif l/U <= T:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

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

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a; cin>>a; COUT(a>999?"ABD":"ABC");
}













Measured memory_bytes: 256