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

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

    vector<string> vs;
    vector<int> vi;

    int sh, sm, eh, em;
    char c;
    string st, sr;

    cin >> sh >> c >> sm >> st >> eh >> c >> em >> sr;

    for (int i = 1; i < N; i++) {
        int times = eh * 60 + em;
        cin >> sh >> c >> sm >> st >> eh >> c >> em >> sr;
        int timee = sh * 60 + sm;

        if (timee - times >= T) {
            vs.push_back(st);
            vi.push_back(timee - times);
        }
    }

    cout << vs.size() << endl;
    for (int i = 0; i < (int)vs.size(); i++) {
        cout << vs[i] << " " << vi[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

typedef struct edge{ll s,g,c;}E;
 
ll n,m;
E e[400010];
ll vnow[100010];
ll epre[400010];
 
ll d[100010];
ll que[200010];
void bfs(int k){
	ll qcnt=1;
	que[0]=k;
	rep(i,0,qcnt){
		ll v=que[i];
		for(ll t=vnow[v];t!=-1;t=epre[t]){
			if(!d[e[t].g]){
				que[qcnt++]=e[t].g;
				d[e[t].g]=d[v]+e[t].c;
			}else if(d[e[t].g]!=d[v]+e[t].c){
				puts("No");
				exit(0);
			}
		}
	}
}

int main(){
	scanf("%lld%lld",&n,&m);
	rep(i,0,n)vnow[i]=-1;
	
	rep(i,0,m){
		ll a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		a--;b--;
		e[2*i].s=a;
		e[2*i].g=b;
		e[2*i].c=c;
		epre[2*i]=vnow[a];
		vnow[a]=2*i;
		
		e[2*i+1].s=b;
		e[2*i+1].g=a;
		e[2*i+1].c=-c;
		epre[2*i+1]=vnow[b];
		vnow[b]=2*i+1;
	}
	ll cnt=0;
	rep(i,0,n)if(!d[i]){
		d[i]=++cnt<<32;
		bfs(i);
	}
	puts("Yes");
	return 0;
}

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

int main(){
  string str;
  
  //空白も含めて1行まるごとを文字列として受け取るためにはgetline関数を使う
  getline(cin,str);

  for(int i=0;i<(int)str.size();i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]=str[i]-'a'+'A';
    }else if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]-'A'+'a';
    }
  }
  cout<<str<<endl;
  return 0;
}



Measured memory_bytes: 3124
n=int(input())

ac,wa,tle,re=0,0,0,0

for _ in range(n):
    aaa=input()
    if aaa=='AC':
        ac+=1
    elif aaa=='WA':
        wa+=1
    elif aaa=='TLE':
        tle+=1
    elif aaa=='RE':
        re+=1


print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))



Measured memory_bytes: 9196
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N):
    d = [1] * (N + 1)
    for n in range(2, N + 1):
        for i in range(n, N + 1, n):
            d[i] += 1
    print(sum(d[i] * i for i in range(1, N + 1)))

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    main(N)


Measured memory_bytes: 151816
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<int> L(2*N);
  for (int i = 0; i < 2*N; i++) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());

  int meat = 0;
  for (int i = 0; i < 2*N; i+=2) {
    meat += L[i];
  }

  cout << meat << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    LL(n,k);
    if(k==1){
        out(intpow(n,3));
    }else if(k==2){
        out(intpow(n/2,3)+intpow((n+1)/2,3));
    }else if(k%2==1){
        out(intpow((n/k),3));
    }else if(k%2==0){
        out(intpow(n/k,3)+intpow(n/(k/2)-n/k,3));
    }
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

LL k, n, t[51];

LL suf(LL a, LL b)
{
    if(a % b == 0) return a / b;
    return a / b + 1;
}

bool check(LL x)
{
    // t[i] - y * n + (x - y) <= n - 1
    // - y * (n + 1) <= n - 1 - x - t[i]
    // y >= (-n + 1 + x + t[i]) / (n + 1)
    LL sm = 0;
    for(int i = 0; i < n; i++)
    {
        LL y = 0;
        if(t[i] + x + 1 - n > 0)
            y = suf(t[i] + x + 1 - n, n + 1);
        sm += y;
    }
    return sm <= x;
}

LL bin_search(LL l, LL r)
{
    while(l + 1 < r)
    {
        LL m = (l + r) / 2;
        check(n * m) ? r = m : l = m;
    }
    return r;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> t[i];
    LL val = n * bin_search(-1, 1e17);
    for(int i = 1000 * n - 1; i >= 0; i--)
    {
        if(val - i < 0) continue;
        if(check(val - i))
        {
            cout << val - i << "\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int r, c, n; cin >> r >> c >> n;
	vector<pi> v;
	rep(i, n){
		auto dist = [&](int x, int y){
			if(x == 0) return y;
			if(x == r) return 2 * c + r - y;
			if(y == 0) return 2 * c + 2 * r - x;
			if(y == c) return c + x;
			return inf;
		};
		int a, b, x, y; cin >> a >> b >> x >> y;
		int da = dist(a, b), db = dist(x, y);
		if(da == inf || db == inf) continue;
		v.emplace_back(da, i);
		v.emplace_back(db, i);
	}
	sort(all(v));
	vi s;
	for(pi p : v){
		if(s.empty() || s.back() != p.second) s.pb(p.second);
		else s.pop_back();
	}
	cout << (s.empty() ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 2672
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

long long n;
int ans = 0;

void dfs(long long x,int a,int b,int c){
  if (x > n) return;
  else{
    if(a>=1 && b>=1 && c>=1) ans += 1;
    dfs(10*x+3,a+1,b,c);
    dfs(10*x+5,a,b+1,c);
    dfs(10*x+7,a,b,c+1);
  }
}

int main(){
  cin >> n;
  dfs(0,0,0,0);
  cout << ans << endl;
  return 0;
}


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

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

    int ans = 0;
    while (true) {
        bool flag = false;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if (h.at(i) > 0) {
                h.at(i)--;
                flag = true;
            } else {
                if (flag) ans++;
                flag = false;
                cnt++;
            }
        }
        if (cnt >= N) break;
        else {
            if (flag) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long
const double eps = 1e-9;

template<typename T>
struct Fenwick{
    vector<T> bit;
    T mod;
    Fenwick(int n){
        bit = vector<T>(n + 1);
        mod = 0;
    }
    void add(int i, T v){
        int n = bit.size();
        ++i;
        while(i < n){
            bit[i] += v;
            if(mod > eps) bit[i] %= mod;
            i += i & -i;
        }
    }
    T get(int i){
        T res = 0;
        ++i;
        while(i > 0){
            res += bit[i];
            if(mod > eps) bit[i] %= mod;
            i -= i & -i;
        }
        return res;
    }
};

bool judge(vector<long long> &a, long long c) {
    int N = a.size();
    vector<int> b(N + 1);
    for(int i = 0; i < N; ++i) {
        b[i + 1] = a[i] >= c ? 1: -1;
        b[i + 1] += b[i];
    }
    Fenwick<int> bit(2 * N + 10);
    const int OFFSET = N + 5;
    int cnt = 0;
    for(int i = 0; i <= N; ++i) {
        cnt += bit.get(b[i] + OFFSET);
        bit.add(b[i] + OFFSET, 1);
    }
    return cnt * 2 >= N * (N + 1) / 2;
}

void solve(long long N, std::vector<long long> a){
    int l = 0, u = (int)1e10;
    while(u - l > 1) {
        int c = (l + u) / 2;
        if (judge(a, c)) {
            l = c;
        } else {
            u = c;
        }
    }
    cout << l << endl;
}

signed main(){
	ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}

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

using namespace std;

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

    vector<int>v(n);

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

    for(int i = 0;i < n;i++)
        cout << v[i] << " ";

    cout << endl;

    return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
//#define int long long;
signed main() {
  int N;
  cin >> N;
  if (N < 105) {
    cout << 0;
  } else if (N < 135) {
    cout << 1;
  } else if (N < 165) {
    cout << 2;
  } else if (N < 189) {
    cout << 3;
  } else if (N < 195) {
    cout << 4;
  } else {
    cout << 5;
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の
string型配列と同じような感じ） map<int, string> mp; for (auto itr =mp.begin();
itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};

int main(){
     int h,w;cin >> h >> w;cin.ignore();
     //左上から右下へ幅有線探索（まず行けるかどうか）
     //,黒と白の枚数を数えて取れる最大値を出力
     int white,black;white = black = 0;
     char map[h][w];int num[h][w];
     for(int i = 0;i<h;i++){
             string s;getline(cin,s);
             for(int j = 0;j<w;j++){
                     if(s.at(j) == '.'){white +=1;}
                     map[i][j] = s.at(j);
                     num[i][j] = MOD;
             }
     }
     black = h*w - white;
     queue<pair<int,int>> que;
     pair<int,int> p = make_pair(0,0);
     que.push(p); if(map[0][0] == '.') num[0][0] = 1;
     while(que.size()){
             p = que.front();que.pop();
//             cout << p.first << " " << p.second << endl;
             for(int i = 0;i<4;i++){
                     int nx = p.first + dx[i];
                     int ny = p.second + dy[i];
                    if(nx >= 0 and ny >= 0 and nx < w and ny < h and num[ny][nx] == MOD and map[ny][nx] == '.'){
                            pair<int,int> a= make_pair(nx,ny);
                            que.push(a);// cout << "  " << a.first << " " << a.second << endl;
                            num[ny][nx] = num[p.second][p.first] +1;
                    }
             }
     }
     if(num[h-1][w-1] == MOD){
             cout << -1 << endl;
     }else{
             cout << white  - num[h-1][w-1] << endl;
     }/*
     for(int i = 0;i<h;i++){
          for(int j = 0;j<w;j++){
                  cout << num[i][j] << " ";
          }
          cout  << endl;
     }*/
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    int n;
    scanf("%d", &n);
    string s;
    cin >> s;
    int q;
    scanf("%d", &q);
    while(q--){
        int k;
        scanf("%d", &k);
        deque<int> d;
        deque<int> m;
        lint sum = 0;
        lint ans = 0;
        rep(i, n){
            while(!d.empty() && i-d[0] >= k){
                d.pop_front();
                sum -= (lint)m.size();
                while(!d.empty() && !m.empty() && m[0] < d[0]) m.pop_front();
            }
            if(s[i] == 'D') d.push_back(i);
            if(s[i] == 'M'){
                if(d.empty()) continue;
                m.push_back(i);
                sum += (lint)d.size();
            }
            if(s[i] == 'C') ans += sum;
        }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 5288
import java.util.Scanner;

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


	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int q=sc.nextInt();
		int lr[][] = new int[n][n];

		for(int i=0; i<m; i++) {
			int l=sc.nextInt();
			int r=sc.nextInt();
			l--;r--;
			lr[l][r]++;
		}

		int sum[][] = new int[n+1][n+1];
		sum[0][0]=0;
		for(int l=0; l<n; l++) {
			for(int r=0; r<n; r++) {
				sum[l+1][r+1] = sum[l+1][r] + sum[l][r+1] - sum[l][r] + lr[l][r];
			}
		}

		for(int i=0; i<q; i++) {
			int l=sc.nextInt();
			int r=sc.nextInt();
			int ans = sum[r][r] - sum[r][l-1] - sum[l-1][r] + sum[l-1][l-1];
			System.out.println(ans);
		}
		sc.close();
	}


}


Measured memory_bytes: 164932
import java.util.*;
public class Main {
 
         
        public static void main(String[] args) throws java.io.IOException{
            Scanner scan = new Scanner(System.in);
            while(true){
            	int n = scan.nextInt();
            	if(n==0)break;
            	int [] s = new int [n];
            	for(int i=0;i<n;i++)s[i]=scan.nextInt();
            	int st = 32;
            	while(st!=0){
            	for(int i=0;i<n;i++){
            		st -= (st-1)%5;
            		System.out.println(st);
            		st -=s[i];
            		if(st<=0){st=0;
            		System.out.println(st);
            		break;
            		}
            		System.out.println(st);
            	}
            	
            }
            
        }
        }
}

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

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;           /*******MOD***********超过long long 一点不要紧*****/

const int maxn = 123456;
typedef pair<int,int> pii;


char a[maxn], b[maxn];
int main(){

    int n ;
    string s;
    cin >> s;
    n = s.size();
    int sum = 0;
    if(s[0] != 'A' || s[1] == 'C' || s[n - 1] == 'C'){cout << "WA" << endl;
        return 0;}
    for (int i = 1; i < n; ++i) {
        if(s[i] == 'C')sum ++;
        else if(s[i] < 'a' || s[i] > 'z') {cout << "WA" << endl;
            return 0;}
    }
    if(sum > 1 || !sum)cout << "WA" << endl;
    else cout << "AC" << endl;
    return 0;
}

Measured memory_bytes: 256
L=input()
INF=10**9+7
N=len(L)
dp1=[0]*(N+1)
dp2=[1]*(N+1)
for i in range(N):
    if L[i]=="1":
        dp1[i+1]=(3*dp1[i]+dp2[i])%INF
        dp2[i+1]=(2*dp2[i])%INF
    else:
        dp1[i+1]=(3*dp1[i])%INF
        dp2[i+1]=dp2[i]

print((dp1[N]+dp2[N])%INF)


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

const int inf = 10000000;
int n, m, x;
int c[12], a[12][12];
int ans = inf;

int dm = 5;			//depth_max
int b = 2;			//branch
int ta[12] = { 0 };	//table
void dfs(int d, int s) {
	if (d == n) {
		//処理
		int d[12] = { 0 };
		int cost = 0;
		rep(i, n) {
			if (ta[i] == 1) {
				cost += c[i];
				rep(j, m) {
					d[j] += a[i][j];
				}
				int k;
				for (k = 0; k < m; k++) {
					if (d[k] < x) break;
				}
				if (k == m) {
					ans = min(ans, cost);
				}
			}
		}
		return;
	}

	for (int i = s; i < b; i++) {
		ta[d] = i;
		dfs(d + 1, 0);
	}
}

int main() {
	cin >> n >> m >> x;
	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	dfs(0, 0);
	if (ans == inf) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
def extended_euclid(a, b):
    x1, y1, m = 1, 0, a
    x2, y2, n = 0, 1, b
    while m % n != 0:
        q, r = divmod(m, n)
        x1, y1, m, x2, y2, n = x2, y2, n, x1 - q * x2, y1 - q * y2, r
    return (x2, y2, n)

a, b = map(int, input().split())
x, y, _ = extended_euclid(a, b)
print(x, y)


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

int main(){
    int n,ans=0,cnt=1;
    cin >> n;
    vector<int> h(n);
    for(int i = 0;i < n;i ++){
        cin >> h[i];
    }
    while(cnt != 0){
        cnt = 0;
        for(int i = 0;i < n;i ++){
            if(h[i]!=0){
                while(i<n && h[i]!=0){
                    h[i] --;
                    i ++;
                    cnt ++;
                }
                ans ++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K = li_input()

    x,y = 0, 0

    for i in range(1, N+1):
        if i % K == 0:
            x += 1
        if i % K == (K // 2):
            y += 1

    if K % 2 == 1:
        print(x ** 3)
    else:
        print(x ** 3 + y ** 3)





main()


Measured memory_bytes: 4916
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Candidates of No Shortest Paths
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_M = 1000;

const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Edge {
  int i, a, b, c;
  Edge() {}
  Edge(int _i, int _a, int _b, int _c): i(_i), a(_a), b(_b), c(_c) {}
};

/* global variables */

vpii nbrs[MAX_N];
Edge es[MAX_M];
bool used[MAX_N];
int dists[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    es[i] = Edge(i, a, b, c);
    nbrs[a].push_back(pii(b, i));
    nbrs[b].push_back(pii(a, i));
  }

  int cnt = 0;
  for (int i = 0; i < m; i++) {
    Edge &ei = es[i];
    for (int j = 0; j < n; j++) dists[j] = INF;
    dists[ei.a] = 0;

    priority_queue<pii> q;
    q.push(pii(0, ei.a));

    while (! q.empty()) {
      pii u = q.top(); q.pop();
      int ud = -u.first, ui = u.second;
      if (dists[ui] != ud) continue;
      if (ui == ei.b) break;

      vpii &nbru = nbrs[ui];
      for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int &vi = vit->first;
	Edge &ve = es[vit->second];
	int vd = ud + ve.c;
	if (i != ve.i && dists[vi] > vd) {
	  dists[vi] = vd;
	  q.push(pii(-vd, vi));
	}
      }
    }

    if (dists[ei.b] < ei.c) cnt++;
    //printf("%d(%d,%d): %d, %d\n", i, ei.a, ei.b, dists[ei.b], ei.c);
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==1) a=14;
	if(b==1) b=14;
	/*1478932871*/
	if(a>b) printf("Alice\n");
	else if(a<b) printf("Bob\n");
	else printf("Draw\n");
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A, B = ni()
    val P = na(N)
    val a = P.count(_ <= A)
    val b = P.count(x => A + 1 <= x && x <= B)
    val c = N - a - b
    val ans = min(a, min(b, c))
    out.println(ans)
  }


  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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

int main() {
    int n;
    vector<string> v;
    string s;
    int count = 0;
    long long result = 0;

    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> s;
        sort(s.begin(), s.end());
        v.push_back(s);
    }

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

    for (int i = 1; i < n; i++) {
        if (v[i] == v[i - 1]) {
            result += ++count;
        }
        else {
            count = 0;
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 5748
// ARC100C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = (1 << 18) + 200;

int n, ai[MAX_N], bit, ans[MAX_N], max_val[MAX_N][2];

int main()
{
    scanf("%d", &bit), n = 1 << bit;
    for (int i = 0; i < n; i++)
        scanf("%d", &ai[i]), max_val[i][0] = i, max_val[i][1] = n;
    for (int i = 0; i < n; i++)
    {
        for (int b = bit - 1; b >= 0; b--)
            if (!(i & (1 << b)))
            {
                int dst = i | (1 << b);
                if (ai[max_val[i][0]] > ai[max_val[dst][0]])
                    swap(max_val[dst][0], max_val[dst][1]), max_val[dst][0] = max_val[i][0];
                else if (ai[max_val[i][0]] > ai[max_val[dst][1]] && max_val[i][0] != max_val[dst][0])
                    max_val[dst][1] = max_val[i][0];
                if (ai[max_val[i][1]] > ai[max_val[dst][0]])
                    swap(max_val[dst][0], max_val[dst][1]), max_val[dst][0] = max_val[i][1];
                else if (ai[max_val[i][1]] > ai[max_val[dst][1]] && max_val[i][1] != max_val[dst][0])
                    max_val[dst][1] = max_val[i][1];
            }
        if (i != 0)
            printf("%d\n", ans[i] = max(ans[i - 1], ai[max_val[i][0]] + ai[max_val[i][1]]));
    }
    return 0;
}

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

int main()
{

    ll n;
    cin>>n;
    ll way[n+1];
    memset(way,0,sizeof(way));
    way[0]=1;
    ll coin[2001];
    int j=0;
    for(int i=3;i<=2000;i++)
        coin[j++]=i;
    int k=j;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<k;j++)
        {
           if(i>=coin[j])
            way[i]=(way[i]+way[i-coin[j]])%mod;
        }
    }
    cout<<way[n]<<"\n";
}




Measured memory_bytes: 3644
// In the name of God

#include <bits/stdc++.h>
using namespace std;
vector<int> nums;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	string s;
	cin >> s;
	int c = 1;
	for(int i=1;s[i];i++) {
		if(s[i]==s[i-1]) c++;
		else {
			nums.push_back(c);
			c=1;
		}
	}
	nums.push_back(c);
	int i = 0;
	long long ans = 0;
	while(i<nums.size()) {
		if(nums[i] % 3 == 0) {
			ans += (nums[i]/3)*2LL;
			i++;
		}
		else if(nums[i]%3==1) {
			ans += (nums[i]/3)*2LL;
			ans++;
			i++;
		}
		else {
			if(i!=nums.size()-1) {
				ans += (nums[i]/3)*2LL;
				ans+=2;
				nums[i+1]--;
				i++;
			}
			else {
				ans += (nums[i]/3)*2LL;
				ans++;
				i++;
			}
		}
	}
	cout << ans;
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


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

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

int n, m;
vector<vector<char> > gg;

bool check(int x, int y) {
    return (x >= 0 && y >= 0 && y < m && x < n);
}

vector<int> dx{0, 0, 1, -1}, dy{1, -1, 0, 0};

int bfs(int x, int y) {
    vector<vector<int> > d(n, vector<int> (m, -1));
    d[x][y] = 0;
    queue<pair<int,int> > q;
    q.push({x, y});
    int mx = 0;
    while (q.size()) {
        auto cur = q.front();
        q.pop();
        for (int i = 0;i < 4;i++) {
            int nx = cur.X + dx[i];
            int ny = cur.Y + dy[i];
            if (check(nx, ny)) {
                if (gg[nx][ny] == '.' && d[nx][ny] == -1) {
                    d[nx][ny] = d[cur.X][cur.Y] + 1;
                    chkmax(mx, d[nx][ny]);
                    q.push({nx, ny});
                }
            }
        }
    }
    return mx;
}



main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    cin >> n >> m;
    gg.resize(n, vector<char> (m));
    cin >> gg;
    int ans = 0;
    for (int i = 0;i < n;i++) {
        for (int j = 0;j < m;j++) {
            if (gg[i][j] == '.') {
                chkmax(ans, bfs(i, j));
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> pozo(N);
  for (auto& ar : pozo)
    cin >> ar;

  int min = pozo[0], max = pozo[0];

  for (auto ar : pozo) {
    if (min > ar)
      min = ar;
    if (max < ar)
      max = ar;
  }

  int Q;
  cin >> Q;
  vector<pair<int, int> > change(Q);
  for (auto& q: change) {
    cin >> q.first;
    cin >> q.second;
  }
  
  for (int i = 0; i <= change.size(); i++) {
    if (min == pozo[0] && max == pozo[N-1]) {
      int explr = 0;
      bool is_sorted = true;
      for (auto ar: pozo) {
        if (explr > ar) {
          is_sorted = false;
          break;
        } else
          explr = ar;
      }
      if (is_sorted) {
        cout << i << endl;
        return 0;
      }
    }
    if(i < change.size()){
    int tmp = pozo[change[i].first-1];
    pozo[change[i].first-1]  = pozo[change[i].second-1];
    pozo[change[i].second-1] = tmp;
    }
  }
  cout << -1 << endl;
}




Measured memory_bytes: 6268
# coding: utf-8

while True:
    m, f, r = map(int, input().split())
    
    if m + f + r == -3:
        exit()

    if m == -1 or f == -1 or (m + f < 30):
        print('F')
        
    elif m + f >= 80:
        print('A')
    
    elif 65 <= (m + f) < 80:
        print('B')
        
    elif 50 <= (m + f) < 65:
        print('C')
    
    elif 30 <= (m + f) < 50:
        if r >= 50:
            print('C')
        else:
            print('D')



Measured memory_bytes: 5600
ans_list = []

def solve():
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        return "end"
    a = list(map(int,input().split()))
    res = -float("inf")
    n = len(a)
    for i in range(n):
        for j in range(i+1,n):
            cand = a[i] + a[j]
            if res < cand <= m:
                res = cand
    if res == -float("inf"):
        res = "NONE"
    return res

while True:
    ans = solve()
    if ans == "end":
        break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5716
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    int cnt = 0;
    for(int i = 1;i <= n;i++){
        int now = 0;
        if(i%2!=0){
            for(int j=1;j<=n;j++){
                if(i%j==0) now++;
            }
            if(now==8) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  set<int> s;
  int q;
  cin >> q;
  int tmp, tmp2;
  rep_i(i, q){
    cin >> tmp >> tmp2;
    if(tmp == 0){
      s.insert(tmp2);
      say(s.size());
    }else{
      set<int>::iterator itr = s.find(tmp2);
      if(itr == s.end()){
        say(0);
      }else{
        say(1);
      }
    }
  }
}


Measured memory_bytes: 12480
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <climits>

using namespace std;
typedef long long ll;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int main()
{
    ll n, x;
    cin >> n >> x;
    
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    
    vector<ll> mi(n, LLONG_MAX);
    
    ll ans = LLONG_MAX;
    
    rep(t, n){
        ll sum = 0;
        rep(i, n){
            mi[i] = min(mi[i], a[(i-t+n)%n]);
            sum += mi[i];
        }
        
        ans = min(ans, sum + t*x);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
#define sf(n) scanf("%d",&n);
#define sfl(n) scanf("%lld",&n);
#define pf(n) printf("%d",n);
#define pfl(n) printf("%lld",n);
#define pr printf("\n");
#define LL long long
using namespace std;
set<int> S1,S2,S3;
set<int>::iterator it;

int main(){
    int N,m;
    scanf("%d%d",&N,&m);
    int flag=0;

    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(a==1){
            S1.insert(b);
            if(b==N)
                flag=1;
        }
        if(b==1){
            S1.insert(a);
            if(a==N)
                flag=1;
        }
        if(a==N){
            S2.insert(b);
            if(b==1)
                flag=1;
        }
        if(b==N){
            S2.insert(a);
            if(a==1)
                flag=1;
        }
    }

    for(it=S1.begin();it!=S1.end();it++){
        S3.insert(*it);
    }
    for(it=S2.begin();it!=S2.end();it++){
        S3.insert(*it);
    }

    if(flag){
        printf("POSSIBLE\n");
    }
    else{
        if(S3.size() != (S1.size()+S2.size()) ){
            printf("POSSIBLE\n");
        }
        else{
            printf("IMPOSSIBLE\n");
        }
    }

    return 0;
}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int mod = 998244353;
const int N = 333333;
long long fact[N];
long long inv[N];
long long invfact[N];

long long C(int n, int k) {
	return fact[n] * invfact[k] % mod * invfact[n - k] % mod;
}

int main() {
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; ++i) {
		inv[i] = (i == 1) ? 1 : mod - mod / i * inv[mod % i] % mod;
		fact[i] = fact[i - 1] * i % mod;
		invfact[i] = invfact[i - 1] * inv[i] % mod;
		assert(inv[i] * i % mod == 1);
	}

	int n = nxt(), a = nxt(), b = nxt();
	long long k;
	cin >> k;

	long long ans = 0;
	for (int i = 0; i <= n; ++i) {
		long long l = 1ll * i * a;
		if (k < l) {
			break;
		}
		long long kk = k - l;
		if (kk % b) {
			continue;
		}
		long long lb = kk / b;
		if (lb > n) {
			continue;
		}
		ans += 1ll * C(n, i) * C(n, lb) % mod;
	}
	cout << ans % mod << "\n";

	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N; cin>>N;
    if(N%2) cout << fixed << setprecision(10) << ((N/2)+1)/(1.0*N) << endl;
    else cout << fixed <<setprecision(10) << 1/2.0 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		int X = stdIn.nextInt();
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		
		if(B <= A)
		{
			System.out.println("delicious");
		}
		else if(B <= A+X)
		{
			System.out.println("safe");
		}
		else
		{
			System.out.println("dangerous");
		}
	}

}


Measured memory_bytes: 35756
#include <bits/stdc++.h>
using namespace std;
void cxxio() {
    ios::sync_with_stdio(false);
    cin.tie(0);
}

void print(bool ok) {
    cout<<(ok? "Yes\n":"No\n");
    exit(0);
}

int main() {
    cxxio();
    int n;
    cin>>n;
    map<int, int> m;
    for (int x; cin>>x; ++m[x]);
    int lo=m.begin()->first;
    int hi=m.rbegin()->first;
    if (lo==hi) print(2*hi<=n || hi==n-1);
    else print(lo==hi-1 && m[lo]<hi && 2*hi-m[lo]<=n);
}


Measured memory_bytes: 4992
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X = I()
    def solve(x):
        res = (-1+sqrt(1+8*x))/2
        return res + (int(res)!=res)
    print(int(solve(X)))
if __name__ == '__main__':
    main()

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
int h, w, k;
int sx,sy;
int fx, fy;
int dr[] = {1, -1, 0, 0};
int dc[] = {0, 0, 1, -1};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w >> k >> sx >> sy >> fx >> fy;
    vector<string> arr(h);
    for(int i=0; i<h; i++)
    {
        cin >> arr[i];
    }
    vector<vector<int>> dist(h, vector<int>(w, INF));
    sx--; sy--; fx--; fy--;
    queue<pair<int, pii>> q;
    q.push({0, {sx, sy}});
    dist[sx][sy] = 0;
    while(!q.empty())
    {
        pair<int, pii> t = q.front();
        q.pop();
        int cost = t.f;
        int y = t.s.s, x = t.s.f;
        for(int i=0; i<4; i++)
        {
            for(int a=1; a<=k; a++)
            {
                int newx = x + dr[i] * a;
                int newy = y + dc[i] * a;
                if(newx < 0 || newx >= h || newy < 0 || newy >= w)
                    break;
                int ncost = cost + 1;
                if(arr[newx][newy] == '@')
                    break;
                if(dist[newx][newy] > ncost)
                {
                    dist[newx][newy] = ncost;
                    q.push({ncost, {newx, newy}});
                }
                else if(dist[newx][newy] == ncost)
                    continue;
                else
                    break;
            }
        }
    }
    if(dist[fx][fy] == INF)
    {
        cout << -1;
    }
    else
    {
        cout << dist[fx][fy];
    }
    return 0;
}


Measured memory_bytes: 12140