akhauriyash/Code-Regression huggingface dataset:
io = STDIN
n,m,k=io.gets.split.map(&:to_i)
ar=io.gets.split.map(&:to_i)
br=io.gets.split.map(&:to_i)
cuma=Array.new(n+1,0)
cumb=Array.new(m+1,0)
n.times do |i|
  cuma[i+1]+=cuma[i]+ar[i]
end
m.times do |j|
  cumb[j+1]+=cumb[j]+br[j]
end
ans=0
(n+1).times do |i|
  next if cuma[i]>k
  j=cumb.bsearch_index{|cumbj|cuma[i]+cumbj>k} #より大きいものを求める
  if j  #jの1つ手前がmaxのindex
    ans = [ans,i+j-1].max
  else   #大きなものがない⇒itemのmaxでも範囲内
    ans = [ans,i+m].max
  end
end 
puts ans 


Measured memory_bytes: 45096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }

    UnionFind tree(N);

    rep(i,M){
        int x,y; cin >> x >> y;
        tree.unite(x-1,y-1);
    }
    int cnt = 0;

    rep(i,N){
        if(tree.same(i,P.at(i) - 1)) cnt++;
    }
    cout << cnt << endl;

    return 0;   
}


Measured memory_bytes: 1024
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;
#define REP(i, n) for(int i=0;i<(int)n;i++)
const int INF = (1<<29);

int n, m;

template<typename T>
struct Serializer{
	map<T, int> enc;
	vector<T> dec;
	int operator()(const T &t){
		auto it = enc.find(t);
		if(it != enc.end()) return it->second;
		dec.push_back(t);
		return enc[t] = dec.size() - 1;
	}
	size_t size(){
		return dec.size();
	}
};

int g[201][201], g2[201][201];

int main(){
	while(cin >> n, n){
		Serializer<string> se;
		REP(i, 200)REP(j, 200)
			g[i][j] = g2[i][j] = i == j ? 0 : INF;
		REP(i, n){
			string s;
			cin >> s;
			int p = s.find('-');
			int u = se(s.substr(0, p));
			int v = se(s.substr(p+1));
			g[u][v] = 1;
		}
		n = se.size();
		REP(i, n)REP(j, n)if(g[i][j] == INF){
			int f = 0;
			REP(k, n){
				if(g[i][k] == 1 && g[k][j] == 1 || g[j][k] == 1 && g[k][i] == 1){
					f = 0; break;
				}
				if(g[i][k] == 1 && g[j][k] == 1 || g[k][i] == 1 && g[k][j] == 1)
					f = 1;
			}
			if(f) g[i][j] = 0;
		}
		REP(k, n)REP(i, n)REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		cout << n << endl;
		cin >> m;
		REP(i, m){
			string s;
			cin >> s;
			int p = s.find('-');
			int u = se(s.substr(0, p));
			int v = se(s.substr(p+1));
			if(g[u][v] & 1) puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

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

typedef long long ll;
const int mxn = 5005;
const int mxm = 1005;
const int inf = 0x3f3f3f3f;
const ll mod= 1e9+7;

#define ms(x,y) memset(x,y,sizeof(x))
int n,m,dp[mxn][mxn],dpp[mxn][mxn],a[mxn],b[mxn];
int main()
{
	ms(dp,0);ms(dpp,0); 
	scanf("%d%d",&n,&m);
	for(int i = 1;i<=n;i++)scanf("%d%d",a+i,b+i);
	for(int i = 1;i<=n;i++)
	{
		for(int j = 0;j<=m;j++)
		{
			dp[i][j] = dp[i-1][j];
		}
		for(int j = a[i];j<=m;j++)
		{
			dp[i][j] = max(dp[i][j] , dp[i-1][j-a[i]] + b[i]);
		}
	}
	for(int i = n;i>=1;i--)
	{
		for(int j = 0;j<=m;j++)
		{
			dpp[i][j] = dpp[i+1][j];
		}
		for(int j = a[i];j<=m;j++)
		{
			dpp[i][j] = max(dpp[i][j] , dpp[i+1][j-a[i]] + b[i]);
		}
	}
	int ans = 0;
	for(int i = 1;i<=n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			ans = max(ans,dp[i-1][j] + dpp[i+1][m-1-j] + b[i]);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 195968
a1,b1 = map(int,input().split())
a2,b2 = map(int,input().split())
a3,b3 = map(int,input().split())
cnt = [0,0,0,0]
cnt[a1-1] += 1
cnt[a2-1] += 1
cnt[a3-1] += 1
cnt[b1-1] += 1
cnt[b2-1] += 1
cnt[b3-1] += 1
print("YES" if max(cnt) < 3 else "NO")

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++)
 
const int m = 1000001;
 
int dp[2][1000001];
 
int main() {
 
    rep(i, 2)rep(j, m)dp[i][j] = j;
 
    for(int i=1,a;a=i*(i+1)*(i+2)/6,a<m;i++)
        rep(k, m-a) {
            if(dp[0][k]< dp[0][k+a])dp[0][k+a] = dp[0][k] + 1;
            if(a%2 && dp[1][k] < dp[1][k+a])dp[1][k+a] = dp[1][k] + 1;
        }
 
    for(int n;cin>>n,n;)cout<<dp[0][n]<<' '<<dp[1][n]<<endl;
 
    return 0;
}


Measured memory_bytes: 10796
#include<stdio.h>
int main(void)
{
	int hour, minute, second;
	scanf("%d",&second);
	if(0 <= second <= 86400)
	{
		minute = second / 60;
		hour = minute / 60;
		minute = minute - (60*hour);
		second = second - ((3600*hour) + (60*minute));
		printf("%d:%d:%d\n",hour, minute, second);
	}
return 0;
}

Measured memory_bytes: 592
function Main(input){
    input = input.split("\n");
    var k = 0;
    while(1){
        input[k] = input[k].split(" ");
        var n = parseInt(input[k][0],10);
        var a = parseInt(input[k][1],10);
        var b = parseInt(input[k][2],10);
        var c = parseInt(input[k][3],10);
        var x = parseInt(input[k++][4],10);

        if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
            break;
        input[k] = input[k].split(" ");
        var y = [];
        for(var i = 0;i < n;i++)
            y[i] = parseInt(input[k][i],10);
        k++;

        var frame = 0,flag = true,now = 0;

        while(frame <= 10000){
            if(x === y[now]){
                now++;
                if(now == n){
                    console.log(frame);
                    flag = false;
                    break;
                }
            }
            x = (a * x + b) % c;
            frame++;
        }
        if(flag)
            console.log("-1");
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

int main(){
    LL k, a, b;
    cin >> k >> a >> b;
    LL ans = 0;
    if(b-a <= 2 || k <= a-1){
        ans = 1+k;
    }else{
        k -= a-1;
        ans = a+(k/2)*(b-a)+(k&1);
    }
    cout << ans << endl;
}

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

int main(){
  int n,m; cin>>n>>m;
  //優先度付きキュー
   priority_queue<long long int> que; //元々コンテナアダプタなので使える
  for(int i=0;i<n;i++){
    long long int a; cin>>a;
    que.push(a);
  }
 int i=m; //残りの枚数

 while (i!=0) {
       int q=que.top(); //このタイミングでque内部のソートが起こる
       que.pop();
       
       que.push(q/2);
        i--;
    }
 
 long long int ans=0;
 while(!que.empty()){
  ans+=que.top();
   que.pop();
 }
cout<<ans<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 600, md = 1e9 + 7;
int dp[N + 1][N + 1][N + 1], x[N + 1];

inline void ad(int &x, int y) { if ((x += y)>= md)x -= md; }

int main(){
	int n;
	scanf("%d", &n);
	int fr = 0;
	f(i, 0, n){
		int a, b;
		scanf("%d%d", &a, &b);
		if (a == -1)swap(a, b);
		if (a == -1) { ++fr; continue; }
		if (b == -1)x[a] = 1;
		else x[a] = x[b] = -1;
	}
	n <<= 1;
	
	dp[0][0][0] = 1;
	int r;
	f(i, 1, n + 1)f(j, 0, n + 1)f(k, 0, n + 1)if (r = dp[i - 1][j][k]){
		if (x[i] == 0){
			if (j < n)ad(dp[i][j + 1][k], r);
			if (k)ad(dp[i][j][k - 1], r);
			if (k < n)ad(dp[i][j][k + 1], r);
		}else if (x[i] == 1){
			if (j)ad(dp[i][j - 1][k], (ll)r * j % md);
			if (k < n)ad(dp[i][j][k + 1], r);
		}else ad(dp[i][j][k], r);
	}
	
	int fc = 1;
	f(i, 2, fr + 1)fc = (ll)fc * i % md;
	
	int an = (ll)dp[n][0][0] * fc % md;
	printf("%d\n", an);
}

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

const int N=1e7+10,mod=1e9+7;

ll n,f[N],ans;

void init(){
	for(ll i=1;i*i<=n;i++){
		for(ll j=i;j*i<=n;j++){
			f[i*j]++;
			if(i!=j) f[i*j]++;
		}
	}
}
int main(){
	cin>>n;
	init();
	for(ll i=1;i<=n;i++)
		ans+=i*f[i];
	cout<<ans<<endl; 
	return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    bool dir = 0;

    vector<vector<int>> m(H, vector<int>(W));
    vector<vector<int>> stack(H * W, vector<int>(4));
    int count = 0;

    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> m.at(i).at(j);

    //右端に奇数を寄せる
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W - 1; j++) {
            if(m.at(i).at(j) % 2 == 1) {
                m.at(i).at(j)--;
                m.at(i).at(j + 1)++;
                stack.at(count++) = {i + 1, j + 1, i + 1, j + 2};
            }
        }
    }
    //右端の奇数を下に寄せる
    for(int i = 0; i < H - 1; i++) {
        if(m.at(i).at(W - 1) % 2 == 1) {
            m.at(i).at(W - 1)--;
            m.at(i + 1).at(W - 1)++;
            stack.at(count++) = {i + 1, W, i + 2, W};
        }
    }
    cout << count << endl;
    for(int i = 0; i < count; i++) {
        cout << stack.at(i).at(0) << " " << stack.at(i).at(1) << " "
             << stack.at(i).at(2) << " " << stack.at(i).at(3) << endl;
    }

    return 0;
}


Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    string s;
    cin>>n>>s;
    x=s.size();
   
    if(n>=x)
        {
            cout<<s<<endl;
        }
    else
    {
        cout<<s.substr(0,n)<<"...";

    }


   return 0;
}



Measured memory_bytes: 3596
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans_l = [0]*n

def min_dist(a,b):
    return min(b-a, abs(x-a)+1+abs(y-b), abs(x-b)+1+abs(y-a))
for i in range(n):
    for j in range(i, n):
        ans_l[min_dist(i,j)] += 1
for ans in ans_l[1:]:
    print(ans)

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

int main() {
  int a,b,c;

  
  cin >> a  >>b >>c ;

int j=0 ;

int i = 0;
 
 
  while (i <a) {
    j +=c ;
    i+=b ;
  }



  cout << j << endl;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n],dp[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k && j<n;j++)
            dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using P = pair<int, int>;

int main(){
  int n;
  cin >> n;
  map<string, vector<P>> mp;
  rep(i, n){
    string s;
    int p;
    cin >> s >> p;
    if (mp.find(s) != mp.end()){
      mp[s].push_back(P(p, i+1));
    }
    else{
      mp[s] = vector<P>{P(p, i+1)};
    }
  }
  
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    sort(mp[itr->first].rbegin(), mp[itr->first].rend());
    for (P x : mp[itr->first]){
      cout << x.second << endl;
    }
  }
  
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  int sum = 0;
  vector<int> A(N);
  for (auto&& e : A) {
    cin >> e;
    sum += e;
  }
  vector<int> divisor;
  for (int i = 1; i * i < sum + 1; i++) {
    if (sum % i == 0) {
      divisor.emplace_back(i);
      divisor.emplace_back(sum / i);
    }
  }
  int res = 0;
  for (auto d : divisor) {
    vector<int64_t> R(N);
    for (int i = 0; i < N; i++) {
      R[i] = A[i] % d;
    }
    sort(R.begin(), R.end());
    vector<int64_t> ACC = {0}, BCC = {0};
    for (auto r : R) {
      ACC.emplace_back(ACC.back() + r);
      BCC.emplace_back(BCC.back() + ((2 * d - r) % d));
    }
    for (int i = 0; i < (int)ACC.size(); i++) {
      if (BCC.back() - BCC[i] == ACC[i] && ACC[i] <= K) {
        res = max(res, d);
      }
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string S, T;

int main(void){

    cin >> S >> T;

    int Slen = S.length();
    char Sch[Slen + 10];
    char Tch[Slen + 10];

    for (int i = 1;i <= Slen;i++) {
        Sch[i] = S[i - 1];
        Tch[i] = T[i - 1];
    }

    int dif = 0;

    for (int i = 1;i <= Slen;i++){
        if (Sch[i] != Tch[i]) dif++;
    }
    
    cout << dif << endl;

    return 0;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  string s,t;
  cin >> s >> t;
  string ans = "No";
  for(int i = 0; i < s.size(); i++){
    if(s == t) ans = "Yes";
    s = s.back() + s.substr(0,s.size()-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
P = 10**9+7
fa = [1]
for i in range(1, 202020):
    fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, 202020)[::-1]:
    fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]

calc = lambda a, b: fa[a+b] * fainv[a] * fainv[b] % P

ans = 0
for i in range(H-A):
    ans = (ans + calc(B-1, i) * calc(H-1-i, W-B-1) )% P

print(ans)

Measured memory_bytes: 57200
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228


ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin >> n;
	double res = 0;
	for (int i = 0; i < n; ++i) {
		double a;
		cin >> a;
		res += 1.0 / a;
	}
	res = 1.0 / res;
	cout << setprecision(15) << res << '\n';
    return 0;
} // kek ;
// Ого! Кажетсья это $#@!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	string s, t;
	cin >> s >> t;
	char buf;
	for (int i = 0; i < s.size(); i++) {
		if (s == t) {
			cout << "Yes";
			return 0;
		}
		else {
			buf = s[0];
			s.erase(s.begin());
			s += buf;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>

int main(){
  
  std::string S;
  std::cin >> S;
  if(S == "MON"){
    std::cout << 6;
  }
  else if(S == "TUE"){
    std::cout << 5;
  }
  else if(S == "WED"){
    std::cout << 4;
  }
  else if(S == "THU"){
    std::cout << 3;
  }
  else if(S == "FRI"){
    std::cout << 2;
  }
  else if(S == "SAT"){
    std::cout << 1;
  }
  else if(S == "SUN"){
    std::cout << 7;
  }
  std::cout << std::endl;
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int (i)=0; (i)<(n); i++)
using veci = vector<int>;
using ll = long long;
int load(veci l, int q, ll p,  int n){//qはトラックの要素数、pは与えた上限、nは荷物の数
    vector<int> b(q, 0);
    int i=0;
    int j=0;
    rep(i, q){//全部載せられて、かつ最後のトラックまで載せられていたらその値を返す
    //全部のせられたらその値を返し、探索範囲を下に広げる
    //載せられなかったら探索範囲を上に広げる
        while (b[i] + l[j] <= p){
            b[i] += l[j];
            j++;
            if (j == n) {
                return p;//全部のせられた
                rep(i, q) cout << b[i] << " ";
                cout << endl;
            }
        }
    }
    return -1;//載せられなかった
}
ll binarysearch(vector<int> l, int q, int n){//二分探索
    ll right = 10000000000;
    ll left = 1;
    ll mid;
    ll a;
    while (right - left){
        mid = (right + left)/2;
        a = load(l, q, mid, n);
        if (a == -1) left = mid+1;
        if (a != -1) right = mid;
    }
    while (a == -1){
        mid++;
        a=load(l, q, mid, n);
        }
    return a;
}
int main(){
    int n, k;
    cin >> n >> k;
    veci luggage(n);
    int d;
    rep(i, n){
        cin >> luggage[i];
    }
    ll ans = binarysearch(luggage, k, n);
    cout << ans << endl;
}


Measured memory_bytes: 4388
k = int(input())
if k % 7 == 0:
    l = 9*k // 7
else:
    l = 9*k
if l % 2 == 0 or l % 5 == 0:
    print(-1)
else:
    pmo = 1
    for i in range(1, l + 1):
        mo = (pmo * 10) % l
        if mo == 1:
            print(i)
            break
        else:
            pmo = mo

Measured memory_bytes: 63220
S = input()
RL, ans = [], []

RorL, temp = S[0], 1
for s in S[1:]:
    if s == RorL:
        temp += 1
    else:
        RL.append(temp)
        RorL = s
        temp = 1
RL.append(temp)

for i in range(len(RL)//2):
    Rlen, Llen = RL[2*i], RL[2*i+1]
    RLlen = Rlen + Llen
    temp = [0]*RLlen
    if RLlen % 2 == 0:
        temp[Rlen - 1] = RLlen//2
        temp[Rlen] = RLlen//2
    else:
        reverse = False
        if (RLlen + abs(Rlen - Llen) - 1) // 2 % 2 != 0:
            reverse = True
        if (Rlen > Llen) ^ reverse: # 右側の数が大きくなる
            temp[Rlen - 1] = RLlen//2 + 1
            temp[Rlen] = RLlen//2
        else:                       # 左側の数が大きくなる
            temp[Rlen - 1] = RLlen//2
            temp[Rlen] = RLlen//2 + 1
    ans += temp

print(' '.join(list(map(str, ans))))

Measured memory_bytes: 11272
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<queue>
#include<iomanip>
using namespace std;
int main() {
	int N;
	cin >> N;
	bool flag = true;
	vector<long long int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] == 0) flag = false;
	}
	long long int ans = 1;
	if (flag) {
		for (int i = 0; i < N; i++) {
			int count=0;
			long long int tmp1, tmp2;
			tmp1 = ans;
			tmp2 = A[i];
			for (int j = 0; j < 18;j++) {
				tmp1 = tmp1 / 10;
				tmp2 = tmp2 / 10;
				if (tmp1 != 0) {
					count++;
				}
				if (tmp2 != 0) {
					count++;
				}
				if (tmp1 < 10 && tmp2 < 10 && tmp1 * tmp2>10)count++;
			}
			if (count >= 18 && ans * A[i] != 1000000000000000000)  {
				ans = -1;
				break;
			}
			else if (ans * A[i] > 1000000000000000000) {
				ans = -1;
			}
			else ans = ans * A[i];
		}
	}
	else ans = 0;

	cout << ans;
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) {
        ans += a[i] - 1;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int a,b;
    int cc=1;
    while(std::cin>>a>>b){
    
    if(a>=0&&b<=1000000){
    int e=a+b;
    int d=1;
    int f;
    
    for(int c=1;c<8;c++){
    	if(e/d>=1){
    		f=c;
		}
    	d=d*10;
	}
	std::cout<<f<<std::endl;
          
cc++;
if(cc==200){
	return 0;
}
	
}
}
return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
using namespace std;
int main() {
    string s;
    cin>>s;
    for (int i=0; i<s.size(); i++){
        if(s[i]=='?')s[i]='D';
    }
    cout<<s<<endl;
    return 0;
}

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


#define MAX_WH 21


int main( void )
{
	char top_down[ MAX_WH +1 ] ;
	char center[ MAX_WH +1 ] ;
	char other[ MAX_WH +1 ] ;

	int W ,H ;
	char initial ;
	scanf( "%d %d%*c%c" ,&W ,&H ,&initial ) ;

	int centerW = W / 2 ;
	int centerH = H / 2 ;

	memset( top_down ,'-' ,W ) ;
	memset( other ,'.' ,W ) ;

	top_down[ W - 1 ] = top_down[ 0 ] = '+' ;
	other[ W - 1 ] = other[ 0 ] = '|' ;
	other[ W ] = top_down[ W ] = '\0' ;

	sprintf( center ,"%s" ,other ) ;
	center[ centerW ] = initial ;

	int i ;
	for( i = 0 ; i < H ; ++i )
	{
		char *output ;
		if( i == 0 || i == H - 1 )
		{
			output = top_down ;
		}

		else if( i == centerH )
		{
			output = center ;
		}

		else
		{
			output = other ;
		}

		printf( "%s\n" ,output ) ;
	}

	return 0 ;
}


Measured memory_bytes: 2148
#include <bits/stdc++.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 fi first
#define se second
#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 int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll a;
	string b;
	cin >> a >> b;
	ll p = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
	a *= p;
	cout << a / 100 << endl;
	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ForBlue.ABC_059
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long x = long.Parse(input[0]);
            long y = long.Parse(input[1]);

            if (Math.Abs(x - y) <= 1)
            {
                Console.WriteLine("Brown");
            }
            else
            {
                Console.WriteLine("Alice");
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

int main() {
	string S;
	cin >> S;
	int ret = 0;
	for (char c : S) {
		if (c == 'C') ret = 1;
		if (ret == 1 && c == 'F') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(list(input()))
a=[[0]]
for i in range(1,h):
    t=a[i-1][0]
    if s[i][0]!=s[i-1][0]:
        a.append([t+1])
    else:
        a.append([t])

for j in range(1,w):
    t=a[0][j-1]
    if s[0][j]!=s[0][j-1]:
        a[0].append(t+1)
    else:
        a[0].append(t)

for i in range(1,h):
    for j in range(1,w):
        up=a[i-1][j]
        left=a[i][j-1]
        if s[i][j]!=s[i-1][j]:
            up += 1
        if s[i][j]!=s[i][j-1]:
            left += 1
        mn=min(up,left)
        a[i].append(mn)
num=a[h-1][w-1]
ans=(num+1)//2
if s[0][0]=='#' and num%2==0:
    ans += 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if(s == "Rainy") {
    cout << "Sunny" << endl;
  }
  else {
    cout << "Rainy" << endl;
  }
}
  

Measured memory_bytes: 256
if __file__.startswith('/tmp/'):
	import sys; sys.stdin = open('input.txt')

ctr = [0] * 4

for c in raw_input().strip():
	ctr['NSWE'.index(c)] = 1

if ctr[0] == ctr[1] and ctr[2] == ctr[3]:
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 2568
<?php
fscanf(STDIN, "%s", $s);
$s= strrev($s);
$array = array("dream","dreamer","erase","eraser");
foreach($array as $k => $v){
  $array[$k] = strrev($v);
}
$ans = true;
for($i=0;$i<strlen($s);){
  $ansz = false;
  foreach($array as $v){
    if(strpos($s,$v,$i)===$i){
      $i += strlen($v);
      $ansz = true;
    }
  }
  if($ansz == false){
    $ans = false;
    break;
  }
}
  if($ans == true){
    echo "YES";
  }else{
    echo "NO";}
  
?>

Measured memory_bytes: 16424
#include<stdio.h>
#include<math.h>

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int n;
  int i;
  int A[250];

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

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) >= 1)printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n)printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n)printf("right key = %d, ",A[right(i)]);
    puts("");
  }

  return 0;
}

Measured memory_bytes: 608
import java.math.BigDecimal;
import java.util.Scanner;

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

                String A = scan.next();
                String B = scan.next();
                
                BigDecimal bigA = new BigDecimal(A);
                BigDecimal bigB = new BigDecimal(B);
                
                BigDecimal seki = bigA.multiply(bigB);
                BigDecimal outputmoto = seki.setScale(0, BigDecimal.ROUND_DOWN);
                long output = outputmoto.longValue()
;
                System.out.println(output);

        }

}

Measured memory_bytes: 35968
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func uniqIntSlice(a []int) []int {
	m := make(map[int]struct{})
	for _, v := range a {
		m[v] = struct{}{}
	}
	u := []int{}
	for k := range m {
		u = append(u, k)
	}
	return u
}
func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

//a:old b:new a>b -> a=b (update) more small
func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

//a:old b:new a<b -> a=b (update) more large
func chmax(a *int, b int) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

func main() {
	n := nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	dp := make([]int, n)
	for i:=range dp{
		dp[i]= 100000000000
	}
	dp[0]=0

	for i := 1; i < n; i++ {
		chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		if i > 1 {
			chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
		}
	}
	fmt.Println(dp[n-1])
}

Measured memory_bytes: 2688
import java.util.*;

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

        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if (m == -1 && f == -1 && r == -1)
                break;

            System.out.println(grade(m, f, r));
        }
    }
    private static char grade(int m, int f, int r) {
        if (m == -1 || f == -1) {
            return 'F';
        } else if (m + f >= 80) {
            return 'A';
        } else if (m + f >= 65){
            return 'B';
        } else if (m + f >= 50) {
            return 'C';
        } else if (m + f >= 30) {
            return (r >= 50) ? 'C' : 'D';
        }
        return 'F';
    }
}


Measured memory_bytes: 26228
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;
 
int main() 
{
	fast;
	ll a,b,c; cin>>a>>b>>c;
	cout << c << " " << a << " " << b << endl;
	return 0;
}

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

vector<int> _753;

void generate_753() {
  for (int d = 3; d <= 9; ++d) {
    rep(bit, pow(3, d)) {
      int b = bit;
      bool _7 = false, _5 = false, _3 = false;
      int x = 0;
      rep(i, d) {
        x *= 10;
        switch (b % 3) {
          case 0:
            x += 7;
            _7 = true;
            break;
          case 1:
            x += 5;
            _5 = true;
            break;
          case 2:
            x += 3;
            _3 = true;
            break;
          default: break;
        }
        b /= 3;
      }
      if (_7 && _5 && _3) _753.push_back(x);
    }
  }
  sort(_753.begin(), _753.end());
  return;
}

int main() {
  generate_753();
  int n;
  cin >> n;
  int ans = upper_bound(_753.begin(), _753.end(), n) - _753.begin();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4216
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000
typedef pair<int,int> P;
struct edge{ int to,cap,cost,rev; };
 
int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
 
void add_edge(int from,int to,int cap,int cost){
   
  G[from].push_back( (edge){to,cap,cost,(int)G[to].size()} );
  G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f){
   
  int INF=1e9;
  int res=0;
  fill(h,h+V,0);
  while(f>0){
 
    priority_queue< P , vector<P> , greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
     
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }
 
    if(dist[t]==INF)return -1;
 
    for(int v=0;v<V;v++)h[v]+=dist[v];
    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,(int)G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
 
  return res;
}
 
int N,M,K;
int a[100];
int b[100][100];
int T[100];
 
int main(){
 
  cin>>N>>M>>K;
  for(int i=0;i<N;i++)cin>>a[i];    
 
  for(int i=0;i<M;i++)
    for(int j=0;j<N;j++)
      cin>>b[i][j];
 
  for(int i=0;i<M;i++)
    cin>>T[i];
 
 
  V=2+M+N+2;
  int si=V-2;
  int ti=V-1;
  //  cout<<si<<' '<<ti<<endl;
   
  int X=1000000;
   
  add_edge(si,0,N,0);
  add_edge(si,1,N-K,0);
 
  for(int i=0;i<N;i++){
    add_edge(0,2+i,1,X-a[i]);
    add_edge(2+i,ti,1,0);
  }
 
  for(int i=0;i<M;i++){
    add_edge(1,2+N+i,T[i],0);
  }
 
  for(int i=0;i<M;i++){
    for(int j=0;j<N;j++){
      add_edge(2+N+i,2+j,1,X-b[i][j]);
    }
  }
 
  int ans=min_cost_flow(si,ti,N);
  ans-= X*N;
  ans=-ans;
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3520
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
struct data{
	int x,y;
	data(){}
	data(int x,int y):x(x),y(y){}
};
int main() {
	int n;
	while(scanf("%d",&n) ,n){
		int m;
		vector<data> star;
		vector<data> map;
		for(int i = 0; i < n; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			star.push_back(data(x,y));
		}
		scanf("%d",&m);
		for(int i = 0; i < m; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			map.push_back(data(x,y));
		}
		for(int i = 0; i < m; i++){
			int dx = map[i].x - star[0].x,dy = map[i].y - star[0].y;
			int cnt = 0;
			for(int j = 0 ; j < n; j++){
				for(int k = 0; k < m; k++){
					if(star[j].x + dx == map[k].x && star[j].y + dy == map[k].y){
						cnt++;
					}
				}
			}
			if(cnt == n){
				printf("%d %d\n",dx,dy);
				break;
			}
		}
	}
    return 0;
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

const int MAXN = 1000010;
const int MOD = 924844033;

int n;
int head[MAXN], data[MAXN << 1], nxt[MAXN << 1], cnt;

void add(int x, int y)
{
	nxt[cnt] = head[x]; data[cnt] = y; head[x] = cnt++;
	nxt[cnt] = head[y]; data[cnt] = x; head[y] = cnt++;
}

int sz[MAXN], F[MAXN];

void dfs(int now, int pa)
{
	sz[now] = 1;
	for (int i = head[now]; i != -1; i = nxt[i]) {
		if (data[i] == pa) continue;
		dfs(data[i], now);
		sz[now] += sz[data[i]];
		F[n - sz[data[i]]]++;
	}
	F[sz[now]]++;
}

int power(int x, int y)
{
	int ret = 1;
	while (y) {
		if (y & 1) ret = 1ll * ret * x % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return ret;
}

int fac[MAXN], inv[MAXN], bot[MAXN], ans[MAXN];
int rev[MAXN];

const int GG = 5;

void FFT(int *num, int N, int tp)
{
	int L = -1;
	for (int m = 1; m < N; m <<= 1) L++;
	FOR(i, 1, N - 1) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << L);

	FOR(i, 0, N - 1) if (i < rev[i]) std::swap(num[i], num[rev[i]]);

	for (int i = 1; i < N; i <<= 1) {
		int wn = power(GG, (MOD - 1) / (i << 1));
		if (tp == -1) wn = power(wn, MOD - 2);
		for (int j = 0, p = i << 1; j < N; j += p) {
			int w = 1;
			for (int k = 0; k < i; k++, w = 1ll * w * wn % MOD) {
				int x = num[j + k], y = 1ll * num[j + k + i] * w % MOD;
				num[j + k] = (x + y) % MOD;
				num[j + k + i] = (x - y + MOD) % MOD;
			}
		}
	}

	if (tp == -1) {
		int invN = power(N, MOD - 2);
		FOR(i, 0, N - 1) num[i] = 1ll * num[i] * invN % MOD;
	}
}

int main()
{
	in(n);
	memset(head, -1, sizeof head);

	FOR(i, 1, n - 1) {
		int x, y; in(x); in(y); add(x, y);
	}

	dfs(1, 0);

	fac[0] = 1;
	FOR(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % MOD;

	inv[n] = power(fac[n], MOD - 2);
	DNF(i, n - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
	
	FOR(i, 0, n) F[i] = 1ll * F[i] * fac[n - i] % MOD;

	FOR(i, 0, n) bot[i] = inv[i];

	int N;
	for (N = 1; N <= n + n; N <<= 1);

	FFT(F, N, 1); FFT(bot, N, 1);
	FOR(i, 0, N - 1) F[i] = 1ll * bot[i] * F[i] % MOD;
	FFT(F, N, -1);

	FOR(i, 1, n) ans[n - i] = 1ll * F[i] * inv[n - i] % MOD;

	DNF(i, n, 1) {
		ans[i] = (1ll * n * fac[n] % MOD * inv[i] % MOD * inv[n - i] % MOD - ans[i] + MOD) % MOD;
	}

	FOR(i, 1, n) printf("%d\n", ans[i]);
		
	return 0;
}


Measured memory_bytes: 46720
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int money, n, msum = 0, nsum = 0, cnt = 0, result;
  double ave;
  char c;

  while(cin >> money >> c >> n) {
    msum += money * n;
    nsum += n;
    cnt++;
  }
  ave = (double)nsum / cnt;
  if((int)(ave*10)%10 >= 5) result = (int)ave +1;
  else result = (int)ave;
  cout << msum << endl;
  cout << result << endl;
}

Measured memory_bytes: 1160
N,M=map(int,input().split())

s=[[0 for i in range(N)] for j in range(M)]

for i in range(M):
    tmp=list(map(int,input().split()))

    k=tmp[0]
    for j in range(k):
        s[i][tmp[j+1]-1]=1

p=list(map(int,input().split()))

out=0

for i in range(2**N):
    b=list(map(int,list(bin(i))[2:]))
    b=[0 for j in range((N-len(b)))]+b
    ss=1
    for j in range(M):
        t=0
        for k in range(N):
            if b[k]==1 and s[j][k]==1:
                t+=1
        if t%2!=p[j]:
            ss=0
    if ss==1:
        out+=1

print(out)
       

Measured memory_bytes: 3064
# C - management

n = int(input())
al = list(map(int,input().split()))

s = [0]*n
level = 1
al.sort()
for i in range(len(al)):
    if al[i] == level:
        s[level-1] += 1
    elif al[i] >= level:
        level = al[i]
        s[level-1] += 1

for j in s:
    print(j)


Measured memory_bytes: 32360
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

static void AGC033_B();
#if 1
int main()
{
	AGC033_B();
	
	fflush(stdout);
	return 0;
}
#endif


static const int AGC033_BMax = 200000;

static void AGC033_B()
{
	int H, W, N, Sr, Sc;
	static char szS[AGC033_BMax + 4] = { 0 };
	static char szT[AGC033_BMax + 4] = { 0 };

	scanf(" %d %d %d %d %d", &H, &W, &N, &Sr, &Sc);
	scanf(" %s %s", szS, szT);



	int tkLeft = 0, tkRight = 0, tkUp = 0, tkDown = 0;
	int aoLeft = 0, aoRight = 0, aoUp = 0, aoDown = 0;

	for (int i = 0; i < N; i++) {
		switch (szS[i]) {
		case 'L':
			tkLeft++;
			break;
		case 'R':
			tkRight++;
			break;
		case 'U':
			tkUp++;
			break;
		case 'D':
			tkDown++;
			break;
		}
#if 0
		switch (szT[i]) {
		case 'L':
			aoLeft++;
			break;
		case 'R':
			aoRight++;
			break;
		case 'U':
			aoUp++;
			break;
		case 'D':
			aoDown++;
			break;
		}
#endif
	}

	const char* ans = "YES\n";
#if 0
	if (((Sr == 1) && (szS[0] == 'D')) ||
		((Sr == H) && (szS[0] == 'U')) ||
		((Sc == 1) && (szS[0] == 'L')) ||
		((Sc == W) && (szS[0] == 'R'))){
		ans = "NO\n";
	}
	tkLeft = ((tkLeft - aoRight) > 0) ? (tkLeft - aoRight) : 0;
	tkRight = ((tkRight - aoLeft) > 0) ? (tkRight - aoLeft) : 0;
	tkUp = ((tkUp - aoDown) > 0) ? (tkUp - aoDown) : 0;
	tkDown = ((tkDown - aoUp) > 0) ? (tkDown - aoUp) : 0;
#endif



	if ((Sr - tkUp) < 1) {
		int s = Sr;
		for (int i = 0; i < N; i++) {
			if (szS[i] == 'U') {
				s--;
			}

			if (s < 1) {
				printf("NO\n");
				return;
			}

			if ((szT[i] == 'D') && (s < H)) {
				s++;
			}
		}
	}
	if ((Sr + tkDown) > H) {
		int s = Sr;
		for (int i = 0; i < N; i++) {
			if (szS[i] == 'D') {
				s++;
			}

			if (s > H) {
				printf("NO\n");
				return;
			}

			if ((szT[i] == 'U') && (s > 1)) {
				s--;
			}
		}

	}
	if ((Sc - tkLeft) < 1) {
		int s = Sc;
		for (int i = 0; i < N; i++) {
			if (szS[i] == 'L') {
				s--;
			}

			if (s < 1) {
				printf("NO\n");
				return;
			}

			if ((szT[i] == 'R') && (s < W)) {
				s++;
			}
		}
	}
	if ((Sc + tkRight) > W) {
		int s = Sc;
		for (int i = 0; i < N; i++) {
			if (szS[i] == 'R') {
				s++;
			}

			if (s > W) {
				printf("NO\n");
				return;
			}

			if ((szT[i] == 'L') && (s > 1)) {
				s--;
			}
		}
	}
	printf(ans);
}



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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans = v.back() - v.front();
  for (int i = 0; i < n - k + 1; i++) {
    int hmin = v[i];
    int hmax = v[i + k - 1];
    ans = min(ans, hmax - hmin);
  }
  cout << ans << endl;
  return 0;
}


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

string format(char s[], int l)
{
    char temp[105];

    for(int i=0; i<l; i++)
    {
        temp[i] = s[l-i-1];
    }
    string ar(temp);

    //cout<<ar<<endl;

    return ar;
}

main()
{
    //string s;

    char s[105], t[105];

    cin>>s>>t;

    int n = strlen(s);
    int m = strlen(t);

    sort(s, s+n);
    sort(t, t+m);

    string a = format(t,m);

    string b(s);

    if(a>b && strcmp(s,t)!=0) cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int x;
	cin >> x;
	
	int i = 1;
	while(true) {
		if((i * (i + 1)) / 2 >= x) {
			cout << i << endl;
			return 0;
		}
		i++;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int n, h, w;
	cin >> n >> h >> w;

	int count = 0;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;

		if (h <= a && w <= b) {
			count++;
		}
	}

	COUT(count);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int a;
    cin >> a;
    string s;
    cin >> s;

    if (a >= 3200) {
        print(s);
    } else {
        print("red")
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())

    num = str(N)
    ans = "No"
    if num[0] == num[1] == num[2]:
        ans = "Yes"
    if num[1] == num[2] == num[3]:
        ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b)	for(i=a;i<b;i++)
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define M 1000000007                          
int main()                                  
{                                             
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    cin>>a>>b;
    if(a>b)
    {
        for(ll i=0;i<a;i++) cout<<b;
    }
    else if(a<b)
    {
        for(ll i=0;i<b;i++) cout<<a;
    }
    else if(a==b)
    {
        for(ll i=0;i<a;i++) cout<<a;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
const int MAX_N = 305;
bool dp[10000025][2];//dp[i][j]代表还剩i个石头，当前为k进行操作时会输还是会赢，0代表第一个人first，1代表第二个人second 
int arr[MAX_N],n;
bool dfs(int k,int t)
{
	//初始条件为dp[0][0]=0,dp[0][1]=0 
    if(dp[k][t]>0)
	  return dp[k][t];
    bool ans=0;
    for(int i=1;i<=n;++i)//遍历n个可以移除石子的数量 
      if(k>=arr[i])//只要当前剩余石子数量大于可以移除石子的数量 
	    ans|=!dfs(k-arr[i],!t);//若上一状态对手赢(1)，则当前状态自己输(0)，上一状态对手输(0)则当前状态自己赢(1)
        //这里用或运算，因为只要有能赢的情况就会选择能赢的情况 
	return dp[k][t]=ans;
}
int main()
{
    int k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=n;++i)
	  scanf("%d",&arr[i]);
    if(dfs(k,0)==false)
	  printf("Second\n");
    else printf("First\n");
    return 0;
}

Measured memory_bytes: 8416