akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 vector<ll>l;
 ll a;
 rep(i,0,n){
  sc(a);push(l,a);
 }
 sort(l);
 ll sum=0;
 rep(i,0,n-1){
  sum+=l[i];
  //cout<<sum<<" "<<l[i]<<" "<<l[n-1]<<endl;
 }
 if(sum>l[n-1])py;
 else pn;
return 0;}

Measured memory_bytes: 3624
H, W = map(int, input().split())
A = []
for i in range(H):
  a = [i for i in str(input())]
  A.append(a)
  
def meiro(A, h, w):
  global H
  global W
  if ('#' in A[h][:w]) or (A[h][w] != '#'):
    return False
  while A[h][w] == '#':
    w += 1
    if w == W:
      break
  if h==H-1 and w==W:
    return True
  elif h == H-1:
    return False
  elif A[h][w-1:].count('#')==1:
    return meiro(A, h+1, w-1)
  
if meiro(A, 0, 0):
  print('Possible')
else:
  print('Impossible')

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

int main()
{
    int n;
    cin >> n;
    map<long long, long long> a;
    long long sum  = 0;
    for (int i = 0; i < n; i++)
    {
        long long aa;
        cin >> aa;
        if(a.count(aa))
        {
            a[aa]++;
        }
        else
        {
            a[aa] = 1;
        }
        sum += aa;
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        long long b,c;
        cin >> b >> c;
        if(!a.count(c))
        {
            a[c] = 0;
        }
        a[c] += a[b];
        sum -= b * a[b];
        sum += c * a[b];
        a[b] = 0;

        cout << sum << endl;
    }
    
}


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

/**
|||||||||||||       |||||     |||||    ||||||||||
||||||||||||||      |||||     |||||  |||||
|||||     |||||     |||||     |||||  |||||
||||||||||||||||    |||||||||||||||    ||||||||||
|||||||||||||||||   |||||||||||||||           |||||
|||||        |||||  |||||     |||||           |||||
|||||         ||||| |||||     |||||    ||||||||||
AHMED;HASSAN;SAEED;
*/

using namespace std;

int main()
{
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int> v(n+1,0);
    for(int i=0;i<n;i++){
        if(i!=0)
            v[i]=v[i-1];
        if(i!=0&&s[i]=='C'&&s[i-1]=='A'){
            v[i+1]++;
            v[i]++;
        }
    }
    v[n]=v[n-1];
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<v[r-1]-v[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
using System;

class Tester
{
    static void Main(string[] args)
    {
        string x = Console.ReadLine();
        int a = int.Parse(x);
        int hour, minute, second;

            minute = a / 60;
            hour = minute / 60;
            minute = minute % 60;
            second = a % 60;

        Console.WriteLine("{0}:{1}:{2}", hour, minute, second);
    }
}


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

using namespace std;
typedef long long ll;

bool check(int n){
    for(int i=1;;i++){
        if(i*i==n)return true;
        else if(i*i>n)return false;
    }
    return false;
}

int main(){
    int a,b;
    cin >> a >>b;
    int temp;
    if(b<10) temp = 10*a + b;
    else if(b<100) temp = 100*a + b;
    else  temp = 1000*a + b;
    if(check(temp))cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   int n,x;
   string ans="No";
   cin>>n;

   while(n>0)
   {
   int x=n%10;
   if(x==7)
   {
      ans="Yes";
      
   }
   n/=10;
   }
   cout<<ans;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(r) (r).begin(), (r).end()

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; }
const long long INF = 1LL<<60;

const int64_t MAX_N = 100010;
int64_t N, M, x, y, R = 0;
vector<int64_t> G[MAX_N];
int64_t dp[MAX_N];

int64_t solve(int x) {
    if (dp[x] != -1) return dp[x];
    int64_t r = 0;
    for (const auto& i : G[x]) {
        chmax(r, solve(i)+1);
    }
    return dp[x] = r;
}

int main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }
    rep(i, N) dp[i] = -1;

    rep(i, N) chmax(R, solve(i));
    cout << R << endl;
}


Measured memory_bytes: 11832
#include<bits/stdc++.h>
using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
    vector<char*> v({token});
    while(token = strtok(NULL,", ")) v.push_back(token);
    return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
    debug() << " [" << args.back() << ": " << H << "] ";
    args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    int n,i;
    cin>>n;
    vi a(n),b(n);
    REP(i,0,n-1) cin>>a[i];
    REP(i,0,n-1) cin>>b[i];
    reverse(all(b));
    int j,k;
    j=0,k=n-1;
    REP(i,0,n-1){
        if(a[i]==b[i]){
            if(b[i]!=b[j]&&a[j]!=b[i]) swap(b[i],b[j]),j++;
            else if(b[i]!=b[k]&&a[k]!=b[i]) swap(b[i],b[k]),k--;
            else {
                cout<<"No";
                return 0;
            }
        }
        dbg(b);
    }
    cout<<"Yes\n";
    REP(i,0,n-1) cout<<b[i]<<" ";
    return 0;
}

Measured memory_bytes: 4800
N=int(input())
n=len(str(N))
ans=0
if n%2==1:
  if n==1:
    print(N)
  else:
    for i in range(1,n):
      if i%2==1:
        ans+=9*(10**(i-1))
    ans+=N-10**(n-1)+1
    print(ans)
else:
  for i in range(1,n):
    if i%2==1:
      ans+=9*(10**(i-1))
  print(ans)


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

int main()
{
    int n;
    cin >> n;
    string s[n];
    int t[n];
    int all_t = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
        all_t += t[i];
    }
    string x;
    cin >> x;



    for (int i = 0; i < n; i++)
    {
        all_t -= t[i];
        if (s[i] == x) 
        {
            break;
        }
    }

    cout << all_t << endl;

    return 0;
}

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

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string S, T; cin >> S >> T;
	int L = S.size();
	int cnt = 0;
	for (int i = 0; i < L; i++) {
		if (S[i] != T[i])cnt++;
	}
	cout << cnt << endl;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end

template<typename M,typename O=M>
struct LazySegmentTree{
    using F=function<M(M,M)>; using G=function<M(M,O)>; using H=function<O(O,O)>;
    int sz,height; vector<M> data; vector<O> lazy;
    const F f;const G g; const H h; const M m1; const O o1;
    LazySegmentTree(int n,const F f,const G g,const H h,const M &m1,const O o1):f(f),g(g),h(h),m1(m1),o1(o1){
        sz=1,height=0; while(sz<n)sz<<=1,height++;
        data.assign(2*sz,m1); lazy.assign(2*sz,o1);
    }
    void set(int k,M x){data[k+sz]=x;}
    void build(){rrep(k,sz-1,0)data[k]=f(data[2*k],data[2*k+1]);}
    M ref(int k){return lazy[k]==o1?data[k]:g(data[k],lazy[k]);}
    void recalc(int k){while(k>>=1)data[k]=f(ref(2*k),ref(2*k+1));}
    void thrust(int k){rrep(i,height,0)eval(k>>i);}
    void eval(int k){
        if(lazy[k]!=o1){
            lazy[2*k]=h(lazy[2*k],lazy[k]); lazy[2*k+1]=h(lazy[2*k+1],lazy[k]);
            data[k]=ref(k); lazy[k]=o1;
        }
    }
    void update(int a,int b,O x){
        thrust(a+=sz); thrust(b+=sz-1);
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1)lazy[l]=h(lazy[l],x),++l;
            if(r&1)--r,lazy[r]=h(lazy[r],x);
        }
        recalc(a); recalc(b);
    }
    M query(int a,int b){
        thrust(a+=sz); thrust(b+=sz-1);
        M L=m1,R=m1;
        for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
            if(l&1)L=f(L,ref(l++)); if(r&1)R=f(ref(--r),R);
        } return f(L,R);
    }
};

int main(){
    int n,k; scanf("%d%d",&n,&k);
    vector<ll> a(n),b(n+1,0),idx(n+1);
    rep(i,0,n)scanf("%lld",&a[i]),a[i]-=k;
    rep(i,0,n)b[i+1]=b[i]+a[i];
    vector<ll> val;
    rep(i,0,n+1)val.push_back(b[i]);
    sort(ALL(val)); val.erase(unique(ALL(val)),val.end());
    rep(i,0,n+1)idx[i]=lower_bound(ALL(val),b[i])-val.begin();
    LazySegmentTree<ll> seg(200010,[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;},0,0);
    seg.build();
    ll ans=0;
    rep(i,0,n+1){
        ans+=seg.query(0,idx[i]+1);
        seg.update(idx[i],idx[i]+1,1);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 14832
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    }
    println!("{}",
             if a<1200 {"ABC" }
             else if a<2800 {"ARC" }
             else {"AGC" }
    )
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int n = s.size();
    vector<int> acc(n + 1, 0);
    int hoge = 1;
    for (int i = 0; i < n; ++i) {
        acc[i + 1] = (acc[i] + (s[i] - '0') * hoge % 2019) % 2019;
        hoge = hoge * 10 % 2019;
    }

    ll ans = 0;
    vector<int> cnt(2019, 0);
    ++cnt[acc[n]];
    for (int i = n - 1; i >= 0; --i) {
        ans += cnt[acc[i]]++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4388
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=303;
const ull base=(ull)1e8+7;

char a[N][N];
ull hsa[N][N],hsb[N][N],pw[N];
int n,ans;

int main(){
	pw[0]=1;
	rep(i,1,N-1) pw[i]=pw[i-1]*base;
//	fileio("test");
	scanf("%d",&n);
	rep(i,1,n) scanf("%s",a[i]+1);
	rep(i,1,n){
		rep(j,1,n){
			hsa[i][j]=hsa[i][j-1]*base+a[i][j];
			hsb[i][j]=hsb[i-1][j]*base+a[i][j];
		}
	}
	rep0(v1,n){
		rep0(v2,n){
			bool flag=true;
			rep(i,1,n){
				int ni=(i+v1-1)%n+1,nj=(i+v2-1)%n+1;
				ull val1=(hsa[ni][n]-hsa[ni][v2]*pw[n-v2])*pw[v2]+hsa[ni][v2];
				ull val2=(hsb[n][nj]-hsb[v1][nj]*pw[n-v1])*pw[v1]+hsb[v1][nj];
			//	if(!v1) assert(val2==hsb[n][nj]);
			//	if(!v2) assert(val1==hsa[ni][n]);
			//	cerr<<i<<" "<<ni<<" "<<nj<<" "<<val1<<" "<<val2<<endl;
				if(val1!=val2){
					flag=false;
					break;
				}
			}
			ans+=flag;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
n,y = (int(x) for x in input().split())
sol = False
for i in range(n+1):
    bb = (y - 10000*i) - 1000*(n-i)
    a = i
    if bb % 4000 == 0 and bb >= 0:
        b = bb // 4000
        c = n - i - b
        if c >= 0:
            sol = True
            break
if not sol:
    print('-1 -1 -1')
else:
    print(a,b,c)

Measured memory_bytes: 38768
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a;
    cin>>a;
    bool flag=false;
    rep(i,26) {
        int sum=0;
        if(sum==a){
            flag=true;
        }
        sum+=4*i;
        if(sum==a){
            flag=true;
        }
        rep(j,16){
            if(sum==a){
                flag=true;
            }
            sum+=7*j;
            if(sum==a){
                flag=true;
            }
        }   
    } 
    if(flag){
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,j) for(int i = 0; i < (int)(j); i++)
#define repeat(i,k,j) for(int i = k; i < (int)(j); i++)

int main(){
  int N;
  cin >> N;
  vector<int> S(N);
  rep(i, N) cin >> S[i];
  int ans = 1;
  repeat(t, 1, N+1){
    if(N % t != 0) continue;
    bool flg = true;
    rep(i, N){
      if(S[i] != S[i%t]){
	flg = false;
	break;
      }
    }
    if(flg){
      ans = max(ans, N / t);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3612
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

int d[31][31];
int c[510][510];
int cnt[4][31];

int main(){
  itn n,C; cin >> n >> C;
  rep(i,C)rep(j,C) cin >> d[i][j];
  rep(i,n)rep(j,n){
    cin >> c[i][j];
    c[i][j]--;
  }
  rep(i,n)rep(j,n){
    cnt[(i+j)%3][c[i][j]]++;
  }
  ll ans=lnf;
  rep(i,C)rep(j,C)rep(k,C)if(i!=j&&j!=k&&k!=i){
    ll sum=0;
    rep(x,C){
      sum+=d[x][i]*cnt[0][x];
      sum+=d[x][j]*cnt[1][x];
      sum+=d[x][k]*cnt[2][x];
    }
    chmin(ans,sum);
  }
  cout << ans << endl;
}

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


int dp[11][300001];


int main(){
    int d,g;
    cin >> d >> g;
    g/=100;
    int p[d],c[d];
    for(int i=0;i<d;i++){
        cin >> p[i] >> c[i];
        c[i]/=100;
    }
    for(int i=0;i<11;i++){
        for(int j=0;j<300001;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<d;i++){
        for(int j=0;j<=p[i];j++){
            for(int k=0;k<200001;k++){
                if(j==p[i]) dp[i+1][k+(i+1)*j+c[i]]=min(dp[i+1][k+(i+1)*j+c[i]],dp[i][k]+j);
                else dp[i+1][k+(i+1)*j]=min(dp[i+1][k+(i+1)*j],dp[i][k]+j);
            }
        }
    }
    int ans=INF;
    for(int i=g;i<300001;i++){
        ans=min(ans,dp[d][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13184
/*" بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ -In the name of Allah."
   Never stop chasing!-MD.SOURAV.

   ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
   ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
   ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
   [███████████████████].░░░░░░░░░░░░░░
   ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░
*/

#include <bits/stdc++.h>


#define endl           "\n"
#define MAX            32000
#define F              first
#define S              second
#define sz(x)          x.size()
#define li             long int
#define gcd(a,b)       _gcd(a,b)
#define pb             push_back
#define asrt(a,n)      sort(a,a+n)
#define MOD 	       1000000007
#define ll             long long int
#define lcd(a,b)       (a*b)/gcd(a,b)
#define mp(x,y)        make_pair(x,y)
#define no             cout<<"NO"<<endl
#define yes            cout<<"YES"<<endl
#define f(i, a, n)     for(int i=a;i<n;i++)
#define test           int t;cin>>t;while(t--)
#define srt(v)         sort(v.begin() , v.end())
#define basrt(a,n)     sort(a,a+n, greater<int>())
#define deb(x)         cout << #x<< ": "<< x<< endl;
#define sumof(x)       accumulate(x.begin(),x.end(),0);
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ignore         cin.ignore (std::numeric_limits<std::streamsize>::max(),'\n');



using namespace std;

double pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 ;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<ll,ll> mllll;
typedef map<char,ll> mchll;
typedef map<string,ll> msll;
typedef vector<pair<ll,ll>> vpllll;
typedef vector<pair<int,int>> vpiiii;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}


void solve()
{

    int n;
    cin>>n;
    vll  v;
    enter(v,n);
    ll ans=0;
    ll sum=0;
    for(int i=0;i<n;i++)
	{
		ans+=v[i]*sum;
		ans%=MOD;
		sum+=v[i];
		sum%=MOD;
	}
	cout << ans;





}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll test_case=1;
    //cin>>test_case;
    while(test_case--)
	{
		solve();
	}

	return 0;
}

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

template<typename T>
struct E{
  int from,to;
  T cost;
};

template<typename T>
vector<T>bellman_ford(vector<E<T>>&g,int s,int sz){
  T inf=numeric_limits<T>::max();
  vector<T>d(sz,inf);
  d[s]=0;
  for(int i=0;i<sz-1;i++)for(auto e:g)if(d[e.from]!=inf)d[e.to]=min(d[e.to],d[e.from]+e.cost);
  for(auto e:g)if(d[e.from]!=inf&&d[e.from]+e.cost<d[e.to])return vector<T>();
  return d;
}

int main(){
  int N,M,S;
  cin>>N>>M>>S;
  vector<E<int>>G(M);
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    G[i]={a,b,c};
  }
  vector<int>ans=bellman_ford<int>(G,S,N);
  if(ans==vector<int>())cout<<"NEGATIVE CYCLE"<<endl;
  else for(auto it:ans){
    if(it==numeric_limits<int>::max())cout<<"INF"<<endl;
    else cout<<it<<endl;
  }
}



Measured memory_bytes: 3100
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e2 + 5;
int N,W, w[maxn], v[maxn], dp[maxn][maxn][300+5];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>N>>W;
    
    for (int i = 1; i <= N; i++)cin>>w[i]>>v[i];
    
    for (int i = 1; i <= N; i++){
        for (int j = 0; j <= i; j++){
            for (int k = 0; k < 3*j+1; k++){
                dp[i][j][k] = dp[i-1][j][k];
                if (k-(w[i] - w[1]) >=0 && j-1>=0)
                    dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-1][k-(w[i] - w[1])] + v[i]);
            }
        }
    }
    
    int ans = 0;
    for (int j = 0; j <= N; j++){
        for (int k = 0; k < 3*j+1; k++){
            if ((long long)j*w[1] + k <= W)ans = max(ans, dp[N][j][k]);
        }
    }

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



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

int main(){
    int n,a,b,ans=0;
    cin >> n;
    cin >> a >> b;

    vector<int> p(n);

    for(int i = 0;i<n;i++){
        cin >> p[i];
    }

    int case1,case2,case3 = 0;

    for(int i = 0;i<p.size();i++){
        if(p[i]<=a){
            case1++;
        } else if(p[i]>=a+1 && p[i]<=b){
            case2++;
        }else if(p[i]>=b+1){
            case3++;
        }
    }
    ans = case1;
    if(ans>case2){
        ans = case2;
    }
    if(ans>case3){
        ans = case3;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int mp[111][111];
int main(){
	// int t;
	// while(){
	scanf("%d",&n);
	char s[33];
	int mx1=0, mx2=0;
	vector<pair<int, int>> v;
	for(int i=0; i<n; ++i){
		scanf("%s",s);
		int sz=strlen(s);
		ll tmp=0, cnt=33;
		for(int j=0; j<sz; ++j){
			if(s[j]=='.'){
				cnt=0;
				continue;
			}
			++cnt;
			tmp*=10;
			tmp+=s[j]-'0';
		}
		if(cnt>=33){
			cnt=0;
		}
		while(cnt<9){
			tmp*=10;
			++cnt;
		}
		// cout<<"*"<<tmp<<endl;
		int cnt1=0, cnt2=0;
		while(tmp%2==0){
			++cnt1;
			tmp/=2;
		}
		while(tmp%5==0){
			++cnt2;
			tmp/=5;
		}
		v.push_back(mk(cnt1, cnt2));
		mx1=max(mx1, cnt1);
		mx2=max(mx2, cnt2);
	}
	ll ans=0;
	for(auto it:v){
		int tmp1=max(0, 18-it.fs);
		int tmp2=max(0, 18-it.sc);
		for(int j=tmp1; j<=mx1; ++j){
			for(int k=tmp2; k<=mx2; ++k){
				ans+=mp[j][k];
			}
		}
		++mp[it.fs][it.sc];
	}
	cout<<ans<<endl;
	// }
}

Measured memory_bytes: 5380
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>


using namespace std;

typedef pair<long, long> P;

int main() {
    long n;
    cin >> n;
    vector<P> ab;
    long a[3], b[3];
    for (auto &ai:a) cin >> ai;
    for (auto &bi:b) cin >> bi;
    for (long i=0; i<3; i++) {
        ab.push_back({a[i], b[i]});
    }
    long dp[5010] = {0}, best=0;
    for (long i=0; i<=n; i++) {
        dp[i+1] = max(dp[i], dp[i+1]);
        for (auto abi:ab) {
            if (i + abi.first <= n)
                dp[i + abi.first] = max(dp[i + abi.first], dp[i] + abi.second);
        }
        best = max(best, dp[i] + n - i);
    }
    n = best;
    best=0;
    vector<long> dp2(n+1, 0);
    for (long i=0; i<=n; i++) {
        for (auto abi:ab) {
            if (i + abi.second <= n)
                dp2[i + abi.second] = max(dp2[i + abi.second], dp2[i] + abi.first);
        }
        best = max(best, dp2[i] + n - i);
    }
    cout << best << '\n';
    return 0;
}


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

int N;

int main() {
  cin>>N;
  int x[N+1][3];
  x[0][0]=0;
  x[0][1]=0;
  x[0][2]=0;
  for (int i=0;i<N;i++){
  cin>>x[i+1][0]>>x[i+1][1]>>x[i+1][2];
  }
  bool can = true;
  for (int i=0;i<N;i++){
    int dist = abs(x[i+1][1]-x[i][1])+abs(x[i+1][2]-x[i][2]);
    int time = x[i+1][0]-x[i][0];
    if(dist>time){
    can = false;
    break;}
    else{
      if((time-dist)%2==1){
        can = false;
        break;
    }
    }
  
  }
  
  if (can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
int pre[MAXN];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> v;
    v.resize(n+2);
    
    for(int i = 1 ; i <= n ; i++)
    cin >> v[i];
    for(int i = 0;  i <= n ; i++)
      pre[i] = 1e9;
    
    for(int i = 1 ; i <= n ; i++)
       pre[i] = min(pre[i - 1] , v[i]);
    int ans = 1;
    for(int i = 2 ; i <= n ; i++)
      {
          if(v[i] <= pre[i - 1])
            {
                ++ans;
            }
      }
      cout << ans ;
    
    
    return 0;
} 

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int N = in.nextInt();

            int max = Integer.MIN_VALUE;

            int a[] = new int[N];

            for (int i = 1; i <= N; i++) {
                int c = in.nextInt();
                a[i - 1] = c;
                if (c > max) {
                    max = c;
                }
            }

            int count[] = new int[max + 2];

            for (int i = 0; i < N; i++) {
                if (a[i] == 0) {
                    count[a[i]]++;
                    count[a[i] + 1]++;
                } else {
                    count[a[i] - 1]++;
                    count[a[i]]++;
                    count[a[i] + 1]++;
                }
            }

            int ans = Integer.MIN_VALUE;

            for (int i = 0; i < max + 2; i++) {
                if (count[i] > ans) {
                    ans = count[i];
                }
            }

            out.println(ans);

//        int n = in.nextInt();
//        int[] a = in.nextIntArray(n);
//        int[] ct = new int[100001];
//        for (int i = 0; i < n; ++i) {
//            ct[a[i]]++;
//        }
//        n = ct.length;
//        int max = 0;
//        for (int i = 0; i < n; ++i) {
//            int value = ct[i];
//            if (i - 1 >= 0) value += ct[i - 1];
//            if (i + 1 < n) value += ct[i + 1];
//            max = Math.max(max, value);
//        }
//        out.println(max);
        }

    }
}



Measured memory_bytes: 50428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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;
}

// const int MAX = 1010;

int main()
{
    string s;
    cin >> s;
    int left = 0;
    int right = s.size() - 1;
    int cnt = 0;
    while (left != right)
    {
        // cout << "left:" << left << ' ';
        // cout << "right:" << right << endl;
        if (s[left] == s[right])
        {
            if (right - left == 1)
            {
                break;
            }
            ++left;
            --right;
            continue;
        }
        else if (s[left] == 'x')
        {
            ++cnt;
            ++left;
        }
        else if (s[right] == 'x')
        {
            ++cnt;
            --right;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>

int main()
{
	int A,B;
	scanf("%d",&A);
	scanf("%d",&B);
	
	if(A%2==0){
		printf("No");
	}
	else if(B%2==0){
		printf("No");
	}
	else if(A%2==1){
		printf("Yes");
	}
	else if(A%2==1){
		printf("Yes");
	}
	
	return 0;
}


Measured memory_bytes: 128
def gcd(n,m):
  a=min(n,m)
  b=max(n,m)
  while a!=0:
    b,a=a,b%a
  return b
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
for i in range(1,n):
  ans=gcd(ans,l[i])
print(ans)

Measured memory_bytes: 14252
#include<stdio.h>


int is_prime( int n )
{
	if( n < 4 )
	{
		return 1 ;
	}

	if( n % 2 == 0 || n % 3 == 0 )
	{
		return 0 ;
	}

	int i ;
	for( i = 5 ; i < n ; i += 2 )
	{
		if( n % i == 0 )
		{
			return 0 ;
		}
	}

	return 1 ;
}

int main()
{
	int n ;

	while( 1 )
	{
		scanf( "%d" ,&n ) ;

		if( n == 0 )
		{
			return 0 ;
		}
		else if( n < 4 )
		{
			continue ;
		}

		if( n % 2 == 0 )
		{
			n-- ;
		}

		while( n > 4 )
		{
			while( is_prime( n ) == 0 )
			{
				n -= 2 ;
			}

			if( is_prime( n - 2 ) == 1 )
			{
				printf( "%d %d\n" ,n - 2 ,n ) ;

				break ;
			}
			else
			{
				n -= 2 ;
			}
		}

	}
}

Measured memory_bytes: 600
caseN = 0
while True:
    caseN += 1
    W = int(input())
    if W == 0: break
    N = int(input())
    tr = [list(map(int, input().split(','))) for _ in range(N)]
    dp = [0 for x in range(W+1)]
    for x in range(N):
        for y in range(W,tr[x][1]-1,-1):
            dp[y] = max(dp[y], dp[y-tr[x][1]] + tr[x][0])
    sum_weight = 0
    sum_value = 0
    ind = N%2
    for x in range(W+1):
        if dp[x] > sum_value:
            sum_weight = x
            sum_value = dp[x]
    print("Case ", caseN, ":", sep='')
    print(sum_value)
    print(sum_weight)


Measured memory_bytes: 5720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  int a, b; cin >> a >> b;
  cout << b*2-a << endl;
  system("pause");
}

Measured memory_bytes: 504
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
// const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int x;
    cin >> x;
    if(x < 1200){
        cout << "ABC" << endl;
    }
    else {
        cout << "ARC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int par[200001],ran[200001];
int init(int n){
    rep(i,n+1) par[i]=i,ran[i]=0;
}
int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}
int unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return 0;
    if(ran[x]<ran[y]) par[x]=y;
    else{
        par[y]=x;
        if(ran[x]==ran[y]) ran[x]++;
    }
}
int same(int x,int y){
    return find(x)==find(y);
}
int main(){
    int n,m;
    cin>>n>>m;
    init(n);
    vec a(n);
    rep(i,n) cin>>a[i];
    int x,y;
    rep(i,m) cin>>x>>y,unite(x,y);
    vec root[200001];
    rep(i,n) root[find(i)].push_back(a[i]);
    rep(i,n) sort(all(root[i]));
    if(n/2<n-1-m){
        cout<<"Impossible\n";
        return 0;
    }
    ll ans=0,b=0;
    vec A;
    rep(i,n)if(root[i].size()) ans+=root[i][0],b++;
    if(b==1){
        cout<<0<<"\n";
        return 0;
    }
    rep(i,n)if(root[i].size()>1)rep(j,root[i].size()-1) A.push_back(root[i][j+1]);
    sort(all(A));
    rep(i,2*(n-1-m)-b) ans+=A[i];
    cout<<ans<<"\n";
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll n;
vector<ll> a(100010);

bool check(ll x) {
  ll now = a[x];
  REP(i, n) {
    if (i == x) continue;
    if (a[i] <= 2 * now) {
      now += a[i];
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  cin >> n;

  REP(i, n) cin >> a[i];
  a.resize(n);
  sort(ALL(a));

  ll lb = -1, ub = n;
  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2;
    if (check(mid))
      ub = mid;
    else
      lb = mid;
  }

  cout << n - 1 - lb << endl;
  return 0;
}

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

int main() {
  // string s;
  // cin >> s;
  // scanf("%c", &c);

  // char c = s[0];

  // cin >> s;
  char c;
  scanf("%c", &c);
  if (isupper(c))
    cout << "A" << endl;
  else
    cout << "a" << endl;
  return 0;
}


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

long long int M=1e+9+7;
const int N=1e+5+5;
long long int power(long long int x, long long int n)
{
    if (n == 0)
        return (long long)1;
    else if (n % 2 == 0) //n is even
        return power((x * x) % M, n / 2);
    else //n is odd
        return (x * power((x * x) % M, (n - 1) / 2)) % M;
}
long long int cans(long long int p, long long int q)
{
    return ((p * power(q, M - 2)) % M + M) % M;
}
long long int fact[N],facti[N];

int main()
{
    int n, k;
    cin >> n >> k;
    facti[0]=fact[0]=1;
    long long int a[n + 1], ans = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        fact[i]=(fact[i-1]*i)%M;
        facti[i]=cans(1,fact[i]);
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
    {
        if (i >= k)
        {
            long long int g=(fact[i-1]*facti[k-1])%M;
            g=(g*facti[i-k])%M;
            ans=(ans+(a[i]*g)%M)%M;
        }
        if (n - i >= k-1)
        {
            long long int j=n-i;
            long long int g=(fact[j]*facti[k-1])%M;
            g=(g*facti[j-k+1])%M;
            ans=(ans-(a[i]*g)%M)%M;
            ans=(ans+M)%M;
        }
    }
    cout << ans;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    abc085d()
}

private data class Sword(val swing: Long, val throwing: Long)

fun abc085d() {
    val (n, hp) = readLine()!!.split(" ").map { it.toLong() }
    val swords = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }
        .map { Sword(it[0], it[1]) }

    // 最大振り攻撃ダメージより大きい刀は最後に確定で投げるようにする
    val maxSwingDamage = swords.maxBy { it.swing }!!.swing
    val throwingAttacks = swords.filter { it.throwing >= maxSwingDamage }
        .sortedByDescending { it.throwing }

    var hpLeft = hp
    var attackCount = 0L
    for (throwingAttack in throwingAttacks) {
        if (hpLeft <= 0) break
        attackCount++
        hpLeft -= throwingAttack.throwing
    }

    // 最大振り攻撃ダメージの刀で残りを削る
    if (hpLeft > 0) attackCount += Math.ceil(hpLeft.toDouble() / maxSwingDamage.toDouble()).toLong()

    println(attackCount)
}


Measured memory_bytes: 85540
# 入力は以下の形式で標準入力から与えられる。
# N
# T A
# H1 H2... HN
n = gets.chomp.to_i
t, a = gets.chomp.split(" ").map(&:to_i)
a_h = gets.chomp.split(" ").map(&:to_i)

# ある国で、宮殿を作ることになりました。
# この国では、標高が x メートルの地点での平均気温は T − x × 0.006 度です。
# 宮殿を建設する地点の候補は N 個あり、地点 i の標高は Hi メートルです。

# これらの中から平均気温が
# A 度に最も近い地点を選んで
# 宮殿を建設すべき地点の番号を出力せよ。
a_h.map! { |h| t-(h*0.006) }
a_h.map! { |h| (h-a).abs  }
# p a_h

check = 0
a_h.each do |v|
  check = v if check < v
end
# p check

h_pos = 0
a_h.each_index do |idx|
  if a_h[idx] < check
    check = a_h[idx]
    h_pos = idx+1
  end
end

p h_pos

Measured memory_bytes: 1788
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Data.List

main = do
    [_,c,k] <- map read . words <$> getLine
    ts <- map (fst . fromJust . BC.readInt) . BC.lines <$> BC.getContents
    print $ solve c k ts

solve :: Int -> Int -> [Int] -> Int
solve c k = f 0 . sort
    where
        c' = c-1 -- first passanger always inside
        f :: Int -> [Int] -> Int
        f !acc [] = acc
        f !acc (t:ts) = let packAsMany = dropWhileNoLonger c' (<= t+k)
                            in f (acc+1) (packAsMany ts)

dropWhileNoLonger :: Int -> (a -> Bool) -> [a] -> [a]
dropWhileNoLonger _ _ [] = []
dropWhileNoLonger !l f list@(x:xs)
    | l <= 0    = list
    | otherwise = if f x then dropWhileNoLonger (pred l) f xs
                         else list

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

int main(void){
    char line1[51],line2[51];
    int sum=0,i,o,len;
    for(;o=0,memset(line2,0,sizeof(line2)),scanf("%s",line1)!=EOF;){
        len=strlen(line1);
        for(i=len-1;i>=0;i--)
            line2[o++]=line1[i];
        if(strcmp(line1,line2)==0)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}

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

using namespace std;

int main()
{
    int R;
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
    }else if(R<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
    return 0;
}



Measured memory_bytes: 764
n = int(input())
D = map(int, input().split())
cnt = [0]*13
for d in D:
    cnt[d] += 1

if any(2 < x for x in cnt[1:12]) or cnt[0] != 0 or cnt[12] == 2:
    print(0)
else:
    world = [0]*24
    world[0] = 1
    flag = 1
    for i, c in enumerate(cnt[1:], 1):
        if c == 0:
            continue
        if c == 2:
            world[i] = 1
            world[-i] = 1
        elif c == 1:
            if flag:
                world[i] = 1
            else:
                world[-i] = 1
            flag ^= 1
    print(
        min(map(lambda x: len(x)+1, (''.join(map(str, world[1:])).split('1')))))


Measured memory_bytes: 9180
N,M=map(int,input().split())
if M==0:
  print('0 0')
  exit()
AC=[0]*(N+1)
WA=[0]*(N+1)
for i in range(M):
  p,s=map(str,input().split())
  if s=='AC':
    key=int(p)
    AC[key]+=1
  elif s=='WA' and AC[int(p)]==0:
    WA[int(p)]+=1
for i in range(N+1):
  if AC[i]==0:
    WA[i]=0
ansc=AC.count(0)
ANSC=len(AC)-ansc
ANSW=sum(WA)
print(ANSC,ANSW)

Measured memory_bytes: 10264
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 2005;
const ll M = 1e9 + 7;
ll dp[N];
ll n;

ll f(ll cur) {
  if (cur < 0) return 0;
  if (cur == 0) return 1;
  ll &sol = dp[cur];
  if (sol != -1) return sol;
  sol = 0;
  for (ll i = 3 ; i <= cur ; i++) {
    (sol += f(cur - i)) %= M;
  }
  return sol;
}

int main() {
  in(n);
  memset (dp , -1 , sizeof dp);
  printf("%lld\n" , f(n));
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string str;
	for(;getline(cin,str),str!="END OF INPUT";){
		int len=str.size();
		int n=0,i;
		for(i=0;i<len;i++){
			if(str[i]==' '){
				cout<<n;
				n=0;
			}else n++;
		}
		cout<<n<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

int main()
{
    int n, m;
    cin>>n>>m;
    int matA[n][m], b[m], c[n];



    for (int i = 0; i < n; i++)
    {
        c[i]=0;
        for (int j = 0; j < m; j++)
        {
            cin>>matA[i][j];
        }
    }
    for (int j = 0; j < m; j++)
    {
        cin>>b[j];
    }

   // cout<<endl;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            c[i] += matA[i][j]*b[j];
        }
        cout<<c[i]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
  ll n;
  cin >> n;
  string ans = "";
  while (n > 0) {
    int res = n % 26;
    n = n / 26;
    if (res == 0) {
      ans = 'z' + ans;
      n -= 1;
    } else {
      char c = 'a' + res - 1;
      ans = c + ans;
    } 
  } 
  cout << ans << endl;
} 


Measured memory_bytes: 3608
ina = input()
inb = input()
N, X = ina.split()
N = int(N)
X = int(X)

L = inb.split()

sums = [0]
for i in range(N):
  sums += [sums[-1]+int(L[i])]

i = 0
for j in (sums):
  if j <= X:
    i += 1
print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	map<char,int> ls;
	int n;	cin>>n;
	string s;	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]!='+')	ls[s[i]]++;
	}
	map<int,int> kind;
	for(auto it:ls)	kind[it.second]++;
	int sum=(int)kind.size()-1;
	for(auto it:kind){
		if(it.first==1){
			if(it.second==1)	sum++;
			else 	sum+=-1+2*it.second;
		}
		else{
			if(it.second==1)	sum+=3;
			else 	sum+=3+2*it.second;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3200
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)



Measured memory_bytes: 28940
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
 cin >>N;
  int a1=N/100000000 ;
  int a2= N/10000000-a1*10;
  int a3=N/1000000-a1*100-a2*10;
  int a4=N/100000-a1*1000-a2*100-a3*10 ;
  int a5= N/10000-a1*10000-a2*1000-a3*100-a4*10;
  int a6= N/1000-a1*100000-a2*10000-a3*1000-a4*100-a5*10;
  int a7= N/100-a1*1000000-a2*100000-a3*10000-a4*1000-a5*100-a6*10;
  int a8= N/10-a1*10000000-a2*1000000-a3*100000-a4*10000-a5*1000-a6*100-a7*10;
  int a9=N-a1*100000000-a2*10000000-a3*1000000-a4*100000-a5*10000-a6*1000-a7*100-a8*10;
  
  int sum=a1+a2+a3+a4+a5+a6+a7+a8+a9;
  if(N%sum==0) {
cout<< "Yes"<< endl;
  }
  else {
    cout<<"No"<< endl;
  }
}
  
 

Measured memory_bytes: 256