akhauriyash/Code-Regression huggingface dataset:
/*


*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main()
{
	int a,b,c,d;
	int count=0,cnt=0;
	int n[1000];
	int i=0;
	while(1){
		int ret;
		ret=scanf("%d",&n[i]);
		if(ret==EOF){
			break;
		}
		if(n[i]>50){
			i--;
		}
		i++;
	}
	cnt=i;
	for(i=0; i<cnt; i++){
		for(a=0; a<=9; a++){
			for(b=0; b<=9; b++){
				for(c=0; c<=9; c++){
					for(d=0; d<=9; d++){
						if(a+b+c+d==n[i]){
							count++;
						}
					}
				}
			}
		}
		printf("%d\n",count);
		count=0;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1000000007

using namespace std;

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

  rep(i, s.size() - 1) {
    if (s[i] == s[i + 1]){
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }

  rep(i, s.size() - 2) {
    if (s[i] == s[i + 2]){
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 9999999
int dijkstra(int x,int y);
int D[128][128];/*Adjacency matrix*/
int n;
int main(){
	int m;
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)break;
		memset(D,0,sizeof(D));
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(i == j)continue;
				D[i][j] = INF;
			}
		}
		
		for(int i = 0; i < m; i++){
			int x;
			scanf("%d",&x);
			if(x == 0){
				int a,b;
				scanf("%d%d",&a,&b);
				printf("%d\n",dijkstra(a,b));
			}
			else{
				int c,d,e;
				scanf("%d%d%d",&c,&d,&e);
				D[c][d] = min(D[c][d],e);
				D[d][c] = min(D[d][c],e);
			}
		}
	}
	return 0;
}
int dijkstra(int x,int y){
	int dist[128];
	bool done[128]={false};
	for(int i = 1; i <= n; i++){
		dist[i] = INF;
	}
	
	dist[x] = 0;
	int cost = 0;
	while(1){
		int e = -1;
		for(int i = 1; i <= n; i++){
			if(done[i] == false && (e == -1 || dist[i] < dist[e])){
				e = i;
			}
		}
		if(e == -1)break;
		done[e] = true;
		if(e == y){
			cost = dist[e];
			break;
		}
		
		for(int i = 1; i <= n; i++){
			dist[i] = min(dist[i],dist[e]+D[e][i]);
		}
		
	}
	
	if(cost == INF)return -1;
	else return cost;
}

Measured memory_bytes: 1100
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
h = [int(i) for i in input().split()]

dp = [0 for _ in range(n)]
for i in range(1,n):
    if(i == 1):
        dp[i] = abs(h[i] - h[i-1])
    else:
        dp[i] = min(abs(h[i] - h[i-1])+dp[i-1],abs(h[i] - h[i-2])+dp[i-2])

print(dp[n-1])

Measured memory_bytes: 15248
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t Q, H, S, D;
	uint64_t N;
	uint64_t maaya, sumipe;
	if (scanf("%" SCNu64 "%" SCNu64 "%" SCNu64 "%" SCNu64, &Q, &H, &S, &D) != 4) return 1;
	if (scanf("%" SCNu64, &N) != 1) return 1;

	sumipe = S;
	if (H * 2 < sumipe) sumipe = H * 2;
	if (Q * 4 < sumipe) sumipe = Q * 4;

	maaya = D;
	if (sumipe * 2 < maaya) maaya = sumipe * 2;

	printf("%" PRIu64 "\n", maaya * (N / 2) + sumipe * (N % 2));

	return 0;
}


Measured memory_bytes: 1700
import math
a,b,x=map(int,input().split())
if a*a*b>=x*2:
    c=x*2/(b*a)
    print(math.degrees(math.atan(b/c)))
else:
    d=2*(b-x/a/a)
    print(math.degrees(math.atan(d/a)))

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

int main()
{
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    char ans[2*n + 1];
    for(int i=0; i<n;  i++)
        ans[2*i]=s[i];
    for(int i=0; i<n; i++)
        ans[2*i + 1]=t[i];
    ans[2*n]='\0';
    cout<<ans<<endl;
    return 0;
}


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

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

    int i;
    for(i=0;i<4;i++){
        cout << s.at(i);
    }
    cout << " ";
    for(i=4;i<s.size();i++){
        cout << s.at(i);
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 256
def bfs_longest(x,y):
    queuex = [x]
    queuey = [y]
    queuedis = [0]
    looked = [[x,y]]
    ans = [0]
    while(len(queuex)):
        nowx = queuex.pop(0)
        nowy = queuey.pop(0)
        nowdis = queuedis.pop(0)
        search = [[nowx+1,nowy],[nowx-1,nowy],[nowx,nowy+1],[nowx,nowy-1]]
        for i in range(len(search)):
            if not (search[i] in looked):
                if maze[search[i][0]][search[i][1]] == ".":
                    queuex.append(search[i][0])
                    queuey.append(search[i][1])
                    queuedis.append(nowdis+1)
                    ans.append(nowdis+1)
                    looked.append([search[i][0],search[i][1]])
    return ans[-1]

h,w = map(int,input().split())
maze = [["#" for _ in range(w+2)]for p in range(h+2)]
anchor = []
for i in range(h):
    data = str(input())
    for j in range(w):
        maze[i+1][j+1] = data[j]
        if data[j] == ".":
            anchor.append([i+1,j+1])

answer = 0
if (len(anchor)) == (h*w):
    print(h+w-2)
    exit()
for i in range(len(anchor)):
    answer = max(bfs_longest(anchor[i][0],anchor[i][1]),answer)
print(answer)

Measured memory_bytes: 3188
n,m = map(int,input().split())
h = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        p[b-1] = -1
    if h[a-1] <= h[b-1]:
        p[a-1] = -1
print(p.count(0))

Measured memory_bytes: 20116
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////
int N, Q, K;
vector<pair<int,ll>>G[100100];
int main() {
	cin >> N;
	for (int i = 0; i < N-1; ++i) {
		int a, b; ll c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
	}
	cin >> Q >> K;
	K--;
	vector<ll>d(N + 1,-1);
	d[K] = 0;
	queue<int>q;
	q.push(K);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto p : G[v]) {
			int sv;
			ll c;
			sv = p.first;
			c = p.second;
			if (d[sv] < 0) {
				d[sv] = d[v] + c;
				q.push(sv);
			}
		}
	}
	for (int i = 0; i < Q; ++i) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int a[11];
int main() {
    REP(i,0,4){
        int b;
        cin>>b;
        a[b]++;
    }
    if(a[1]==a[4]&&a[4]==a[7]&&a[7]==a[9]&&a[9]==1){
        p("YES");
    }else{
        p("NO");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
set<int>st;
main(){
    string s;
    cin>>s;
    if(s[0]==s[1]){
        cout<<"1 2"<<endl;
        return 0;
    }
    r(i,s.size()-2){
        st.clear();
        r(j,3)st.insert(s[i+j]);
        if(st.size()<3){
            cout<<i+1<<' '<<i+3<<endl;
            return 0;
        }
    }
    cout<<"-1 -1"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int mod = 924844033;
int n,k,f[2][2010][2010][2];
ll ans[2010],g[2010],fac[2010];
void upd(int &a,int b){a+=b;if(a>=mod) a-=mod;}
int main(){
	read(n);read(k);
	f[0][0][0][1]=1;f[1][0][0][0]=1;
	for(int p:{0,1})
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++){
			upd(f[p][i][j][0],f[p][i-1][j][0]);
			upd(f[p][i][j][0],f[p][i-1][j][1]);
			if(j) upd(f[p][i][j][0],f[p][i-1][j-1][0]),
				upd(f[p][i][j][1],f[p][i-1][j-1][0]),
				upd(f[p][i][j][1],f[p][i-1][j-1][1]);
		}
	ans[0]=1;
	int sum=0;
	for(int i=1;i<=2*k&&i<=n;i++){
		int len=(n-i)/k/2+1,tag=i>k;
		memset(g,0,sizeof(g));
		if(i+(len-1)*2*k+k>n)
		for(int p1=0;p1<=len;p1++)
			for(int p2=0;p2<=sum;p2++)
				g[p1+p2]=(g[p1+p2]+ans[p2]*f[tag][len][p1][0])%mod;
		else
		for(int p1=0;p1<=len;p1++)
			for(int p2=0;p2<=sum;p2++)
				g[p1+p2]=(g[p1+p2]+ans[p2]*(f[tag][len][p1][1]+f[tag][len][p1][0]))%mod;
		memcpy(ans,g,sizeof(g));
		sum+=len;
	}
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	ll S=0;
	for(int i=0;i<=sum;i++)
		S=(S+(i&1?-1:1)*ans[i]*fac[n-i])%mod;
	cout<<(S+mod)%mod<<'\n';
	return 0;
}

Measured memory_bytes: 61824
#include<stdio.h>
using namespace std;

int main() {
	for (int _____ = 1; _____ <= 9; _____++) {
		for (int ____ = 1; ____ <= 9; ____++) {
			printf("%dx%d=%d\n", _____, ____, _____*____);
		}
	}
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

bool isSq(ll x) {
	return roundl(sqrtl(x))*roundl(sqrtl(x)) == x;
}

int solvable(ll a, ll b, ll c) {
	ll disc = b*b-4*a*c;
	if (disc < 0) return 0;
	if (!isSq(disc)) return 0;
	if (((ll)(-b+sqrtl(disc)))%2) return 0;
	return b!=sqrtl(disc);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n;
	cin >> n;
	
	for (ll t = 1; t <= n; t++){
		ll ans = 0;
		for (ll x = 1; x*x<t; x++) {
			for (ll y = 1; x*x+y*y+x*y<t; y++) {
				ll a = 1;
				ll b = x+y;
				ll c = x*x+y*y+x*y-t;
				ans+=solvable(a,b,c);
			}
		}
		cout << ans << "\n";
	}

}


Measured memory_bytes: 3620
N = int(input())
x = list()
u = list()

for a in range(0, N):
    X, U = input().split()
    x.append(float(X))
    u.append(U)

sm = 0

for a, b in zip(x, u):
    if b == 'BTC':
        sm += a*380000
    else:
        sm += a

print(sm)


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

int main() {
  int a,b;
  std::cin >> a >> b;
  if (a < b) {
    std::cout << "a < b" << '\n';
  } else if (a > b) {
    std::cout << "a > b" << '\n';
  } else {
    std::cout << "a == b" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3048
#include <stdio.h>

int main(void)
{
	int N;
	int T[100];
	int M;
	int P[100];
	int X[100];
	int i, j;
	int time;
	
	scanf("%d", &N);
	
	for (i = 0; i < N; i++){
		if (scanf("%d", &T[i]) == 1);
	}
	
	scanf("%d", &M);
	for (i = 0; i < M; i++){
		scanf("%d %d", &P[i], &X[i]);
	}
	
	
	for (i = 0; i < M; i++){
		time = 0;
		for (j = 0; j < N; j++){
			if ((P[i] - 1) == j){
				time += X[i];
			} else {
				time += T[j];
			}
		}
		printf("%d\n", time);
	}
	
	return (0);
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[a-1].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  rep(i,m) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    char c;
    cin >> c;
    if(c == 'A') cout << 'T' << endl;
    if(c == 'G') cout << 'C' << endl;
    if(c == 'C') cout << 'G' << endl;
    if(c == 'T') cout << 'A' << endl;

    return 0;
}

Measured memory_bytes: 768
s = input()
q = int(input())

hanten = 0
sen = ""
mat = ""
for i in range(q):
    x = input()
    if x == "1":
        if hanten == 0:
            hanten = 1
        else:
            hanten = 0
    else:
        if x[2] == "1":
            if hanten == 0:
                sen += x[4]
            else:
                mat += x[4]
        else:
            if hanten == 0:
                mat += x[4]
            else:
                sen += x[4]

if hanten == 0:
    print(sen[::-1] + s + mat)
else:
    print(mat[::-1] + s[::-1] + sen)

Measured memory_bytes: 4468
#include <iostream>
//#include <math.h>


using namespace std;

int main(void){
    int N,M;
    cin >> N >> M;
    int A[N+1]={},count=0,tot=0;

    for (int i = 1; i < N+1; i++)
    {
        cin >> A[i];
        tot += A[i];
        
    }
    for (int i = 1; i < N+1; i++)
    {
        if(A[i]*4*M>=tot) count++;
    }
    
    if(count>=M) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#coding=UTF-8
N=int(input())

mozir=input()
hyo=mozir.split(' ')
A=[int(mono) for mono in hyo]


subseq_nth=0
subseq_mae=None
subseq_muki=None

for mono in A:
    if subseq_mae==None:
        subseq_nth+=1
        subseq_mae=mono
#        print('case 1')
    else:
        if subseq_muki==None:
            if subseq_mae==mono:
                subseq_mae=mono
#                print('case 2')
            elif subseq_mae>mono:
                #減少パターン
                subseq_muki=-1
                subseq_mae=mono
#                print('case 3')
            else:
                subseq_muki=1
                subseq_mae=mono
#                print('case 4')
                
        elif (mono - subseq_mae) * subseq_muki >= 0:
            #増加減少の向きが合うとき
            #ここでは横這いのときもok
            subseq_mae=mono
#            print('case 5')
        else:
            #そうで無ければ仕切り直し
            subseq_mae=mono
            subseq_nth+=1
            subseq_muki=None
#            print('case 6')

#後処理
pass

print(subseq_nth)


Measured memory_bytes: 15192
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<map>
#include<functional>
#include<algorithm>
using namespace std;


#define MAX_N 1000000
bool is_prime[MAX_N+1];
void sieve(int n){
	memset(is_prime,true,sizeof(is_prime));
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
		}
	}
}

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

map<pair<int,int>,int> num;

pair<int,int> create(int m,int n){
	pair<int,int> res;
	int p=1,x=0,y=0;
	num.clear();
	for(int i=0;p<=m;i++){
		for(int j=0;j<i/2+1&&p<=m;j++){
			if(p==n)res=make_pair(x,y);
			num[make_pair(x,y)]=p++;
			x+=dx[i%4];
			y+=dy[i%4];
		}
	}
	return res;
}

int main(){
	sieve(MAX_N);
	int m,n;
	while(cin>>m>>n,m||n){
		map<pair<int,int>,pair<int,int> > cur,next;
		map<pair<int,int>,pair<int,int> >::iterator it;
		pair<int,int> s=create(m,n);
		pair<int,int> ans;
		if(is_prime[n])cur[s]=make_pair(1,n);
		else cur[s]=make_pair(0,0);
		ans=cur[s];
		while(!cur.empty()){
			for(it=cur.begin();it!=cur.end();++it){
				s=it->first;
				for(int i=-1;i<=1;i++){
					pair<int,int> t=make_pair(s.first+i,s.second+1);
					if(num.find(t)==num.end())continue;
					pair<int,int> val=it->second;
					if(is_prime[num[t]]){
						val.first++;
						val.second=num[t];
					}
					next[t]=max(next[t],val);
					ans=max(ans,val);
				}
			}
			cur.swap(next);
			next.clear();
		}
		cout<<ans.first<<' '<<ans.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 64788
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (int)(1e9+7)
#define INF (int)(1e9)
#define LLINF (int)(4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion



int main() {
    int N, M; input(N,M);
    vector<vector<int>> G(N);
    vector<int> dist(N, INF);
    vector<vector<bool>> visited(3, vector<bool>(N, false));
    REP(i, M) {
        int u, v; input(u,v);
        u--; v--;
        G[u].push_back(v);
    }
    int S, T; input(S,T);
    S--; T--;
    queue<PII> que;
    que.push({S,0});
    while (!que.empty()) {
        PII p = que.front(); que.pop();
        int v = p.first;
        if (visited[p.second % 3][v]) continue;
        visited[p.second % 3][v] = true;
        if (p.second % 3 == 0 && dist[v] != INF) continue;
        if (p.second % 3 == 0) {
            dist[v] = p.second / 3;
            if (v == T) {
                cout << dist[T] << endl;
                return 0;
            }
        }
        for (int to : G[v]) {
            que.push({to,p.second + 1});
        }
    }
    cout << -1 << endl;
    getchar(); getchar();
}

Measured memory_bytes: 6144
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
        sc.Scan()
        i, e := strconv.Atoi(sc.Text())
        if e != nil {
                panic(e)
        }
        return i
}

func main() {
        sc.Split(bufio.ScanWords)
        a := nextInt()
        b := nextInt()

        fmt.Println(a*b, (a+b)*2)
}


Measured memory_bytes: 1068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (auto &i : S) cin >> i;
    sort(S.begin(), S.end());
    for (auto i: S) cout << i;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int A[100][100] = {0}, B[100] = {0}, C[100] = {0};
  int i, j, n, m;

  scanf("%d %d", &n, &m);

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

  for (i = 0; i < m; i++)
    scanf("%d", &B[i]);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      C[i] += A[i][j] * B[j];
    }
  }

  for (i = 0; i < n; i++)
    printf("%d\n", C[i]);

  return 0;
}

Measured memory_bytes: 1076
from operator import itemgetter

dic = []
for i in range(int(input())):
  dic.append(input().split())
  dic[i][1] = int(dic[i][1])
  dic[i].append(i)

dic.sort(key=itemgetter(1), reverse=True)
dic.sort(key=itemgetter(0))
for listd in dic:
  print(listd[2]+1)

Measured memory_bytes: 38256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<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; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const double INF = 1LL<<60;
double dp[100000][15];

string str;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (getline(cin, str)) {
        istringstream sin(str);
        int L; sin >> L;
        double d;
        vector<double> vec;
        while (sin >> d) vec.PB(d);

        int n = vec.size();
        for (int i = 0; i < (1<<n); ++i) for (int j = 0; j < n; ++j) dp[i][j] = INF;
        for (int i = 0; i < n; ++i) dp[(1<<i)][i] = vec[i];
        for (int bit = 0; bit < (1<<n); ++bit) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    int nbit = bit | (1<<j);
                    
                    chmin(dp[nbit][j], dp[bit][i] + 2.0*sqrt( vec[i] * vec[j] ) );
                }
            }
        }
        double res = INF;
        for (int i = 0; i < n; ++i) chmin(res, dp[(1<<n)-1][i] + vec[i]);
        
        if (res <= L) puts("OK");
        else puts("NA");
    }
    return 0;
}


Measured memory_bytes: 1748
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

cnt = 0
cnt = sum([a_list[i] > a_list[j] for i in range(N) for j in range(i, N)])
second_cnt = sum([a_list[i] > a_list[j] for i in range(N) for j in range(i)])
if K > 1:
    second_cnt *= (K * (K - 1)) // 2
cnt = cnt * ((K * (K + 1)) // 2)
print((cnt + second_cnt) % (10 ** 9 + 7))


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n=0,x=-1;
    while(x!=0){
        cin >> x;
        if(x==0)break;
        n++;
        printf("Case %d: %d\n",n,x);
    }
}


Measured memory_bytes: 3068
<?php
$n=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
$ans=0;
$a=$p[0];
$b=$p[1];
$i=2;
while($i<$n){
  if($a<$b&&$b<$p[$i]){
    ++$ans;
  }elseif($a>$b&&$b>$p[$i]){
    ++$ans;
  }
  $a=$b;
  $b=$p[$i];
  ++$i;
}
echo $ans;

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

#define INF 1e10
#define ABS(a) ((a)>=0?(a):-(a))
#define MAX 32768

int s[16], d[16], v[16];
double dp[16][MAX];
int w[16][MAX];
short prev[16][MAX][2];
int ord[16];

int main()
{
	int n, i, j, k, t, ii, lim;
	double x, y;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d%d%d", &s[i], &d[i], &v[i]);

	memset(prev, -1, sizeof(prev));
	for (ii = 1, i = 0; i < n; ++i, ii <<= 1)
		w[i][ii] = v[i];

	lim = 1 << n;
	for (k = 0; k < lim; ++k)
	{
		for (ii = 1, i = 0; i < n; ++i, ii <<= 1)
		{
			if (k & ii)
				continue;

			t = k | ii;
			for (j = 0; j < n; ++j)
			{
				if (i == j || w[j][k] == 0)
					continue;

				int dd = d[i] - d[j];
				if (dd < 0)
					dd = -dd;

				x = dp[j][k] + (dd * (7 + 2 * w[j][k])) / 200.0;
				if (dp[i][t] == 0 || x < dp[i][t])
				{
					dp[i][t] = x, w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	for (x = INF, ii = 0, i = 0; i < n; ++i)
	{
		y = dp[i][lim-1];
		if (y == 0)
			continue;

		if (y < x)
			x = y, ii = i;
	}

	for (ord[0] = ii, i = ii, j = lim-1, k = 1; k < n; ++k)
	{
		ord[k] = prev[i][j][0];
		j = prev[i][j][1];
		i = ord[k];
	}

	printf("%d", s[ord[n-1]]);
	for (i = 1; i < n; ++i)
		printf(" %d", s[ord[n-i-1]]);

	putchar('\n');
	return 0;
}

Measured memory_bytes: 8836
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,X,sum=0;
    cin >> N >> X;
    vector<int>m(N);
    for(int i=0;i<N;i++){
        cin >> m.at(i);
        sum+=m.at(i);//すべてのドーナツ一個分の和を求める
    }
    sum=X-sum;//最低限のドーナツ代を引いた残りの材料
    sort(m.begin(),m.end());
    cout << sum/m.at(0)+N;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner in = new Scanner(System.in);

		int x = in.nextInt();
		int y = in.nextInt();


		System.out.println((x*y) + " " + ((2*x)+(2*y)));
		//System.out.println((2*x)+(2*y));
	}

}



Measured memory_bytes: 26140
#include<stdio.h>

int main(void){
	
	int n,m;
	int t[100],h[100];
	int buff;
	int i,j,k,l;
	int tadd,hadd;
	int cadd,cadmin;
	int changet,changeh;
	int changed[3];
	int btadd,bhadd;
	
	while(1){
		
		changed[2] = 9999;
		
		scanf(" %d %d",&n,&m);
		
		if(m==0 && n==0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf("%d",&t[i]);
			tadd += t[i];
		}
		
		for(i=0;i<m;i++){
			scanf("%d",&h[i]);
			hadd += h[i];
		}
		
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				
				btadd = 0;
				bhadd = 0;
				
				changet = t[i];
				changeh = h[j];
				
				for(k=0;k<n;k++){
					if(k==i){
						continue;
					}
					btadd += t[k];
				}
		
				for(l=0;l<m;l++){
					if(l==j){
						continue;
					}
					bhadd += h[l];
				}
				
				btadd += changeh;
				bhadd += changet;
				
				if(btadd == bhadd && (changet + changeh) < changed[2]){
					changed[0] = changet;
					changed[1] = changeh;
					changed[2] = changet + changeh;
				}
			}
		}
		
		if(changed[2] != 9999){
			printf("%d %d\n",changed[0],changed[1]);
		}else{
			printf("-1\n");
		}
		
		tadd = 0;
		hadd = 0;
		
	}
	
	return(0);
	
}

Measured memory_bytes: 612
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(o) (o).begin(), (o).end()
using namespace std;
typedef int_fast64_t ll;

size_t i, j;
ll N, K, S = 0;
ll cnt, buff, tmp;
ll A[500], B[500];
ll x, y;
vector<ll> cand;

inline bool solve(ll m) {
    for(i = 0; i < N; i++) B[i] = A[i] % m;
    sort(B, B + N);
    cnt = 0, buff = 0, tmp;
    for(i = 0, j = N - 1; i <= j; i++) {
        if(B[i] == 0 || B[i] == m) continue;
        buff = B[i];
        cnt += B[i];
        B[i] = 0;
        if(cnt > K) return false;
        while(buff && j >= i) {
            if(B[j] == 0 || B[j] == m) {
                j--;
                continue;
            }
            tmp = m - B[j];
            if(tmp > buff) {
                B[j] += buff;
                break;
            } else {
                buff -= tmp;
                j--;
            }
        }
    } 
    return true;
}

int main() {
    scanf("%lld %lld", &N, &K);
    REP(i, N) {
        scanf("%lld", A + i);
        S += A[i];
    }
    x = 1, y;
    while(x * x <= S) {
        if(S % x == 0) {
            y = S / x;
            if(solve(y)) {
                printf("%lld\n", y);
                return 0;
            }
            cand.push_back(x);
        }
        x++;
    }
    reverse(ALL(cand));
    for(auto& c : cand) if(solve(c)) {
        printf("%lld\n", c);
        break;
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] array = new int[a];
		int count = 0;
		for(int i = 0; i < a; i++) {
			array[i] = sc.nextInt();
		}
		for(int i = 1; i < array.length - 1; i++) {
			if(array[i -1] < array[i] && array[i] < array[i + 1]) {
				count++;
			}else if(array[i + 1] < array[i] && array[i] < array[i - 1]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<sstream>
#define INF 0x9f9f9f9f

using namespace std;
const int maxn=200+10; 
int a[maxn];
int ccc[20];
typedef long long ll;
ll map1[maxn][maxn];
int main(){



	ll n,m;
	cin>>n>>m;

	for(ll i=0;i<n;i++)
		for(ll j=0;j<n;j++)
			if(i==j)map1[i][j]=0;
			else
				map1[i][j]=INF;

	int a,b,c;

	for(ll i=0;i<m;i++){
		cin>>a>>b>>c;
		map1[a][b]=c;
	}


	for(ll k=0;k<n;k++){
		for(ll i=0;i<n;i++){
			for(ll j=0;j<n;j++){
				if(!(map1[i][k]==INF||map1[k][j]==INF)&&map1[i][j]>map1[i][k]+map1[k][j])
					map1[i][j]=map1[i][k]+map1[k][j];
			}
		}
	}

	ll judge=1;
	for(ll i=0;i<n;i++){
		if(map1[i][i]!=0){
			judge=0;
			break;
		}
	}



	if(judge==1){
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){

			if(map1[i][j]==INF)
				{
					if(j==n-1)printf("INF");
					else printf("INF ");
			}
			else
				{
					if(j==n-1)printf("%lld",map1[i][j]);
					else
						printf("%lld ",map1[i][j]);
			}
		}
		printf("\n");
	}
	}
	else
		puts("NEGATIVE CYCLE");



	//cout<<INF<<endl;


	return 0;
}


Measured memory_bytes: 3352
n=int(input())
t=list(map(int,input().split()))
m=int(input())
d=[]
for _ in range(m):
  d.append(list(map(int,input().split())))
  
ans=[sum(t)-t[x[0]-1]+x[1] for x in d]
for x in ans:
  print(x)

Measured memory_bytes: 9112
from math import ceil, log10
from itertools import product


def solve(string):
    n = int(string)
    ans = 0
    for i in range(2, ceil(log10(n))):
        tmp = [
            int("".join(x))
            for x in product("753", repeat=i + 1)
            if "7" in x and "5" in x and "3" in x
        ]
        ans += len([x for x in tmp if x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 4280
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input().strip())
    if n == 2:
        print(1)
        return

    result = 2
    for x in range(2, int(n ** 0.5) + 1):
        if n % x == 1:
            result += 1 if x ** 2 == n - 1 else 2
            continue
        a = n
        while a % x == 0:
            a //= x
        result += a % x == 1
    print(result)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 39152
N = int(input())

# 証言者ごとに整理する
testimony_list = []
for i in range(N):
    array = [-1] * N
    testimony_list.append(array)
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        # iさんの、xさんへの証言
        testimony_list[i][x - 1] = y

max_count = 0
for i in range(2 ** N):
    failed = False
    for j in range(N):
        if not (i >> j & 1):
            continue
        array = testimony_list[j]
        for k in range(N):
            if array[k] == -1:
                continue
            if (i >> k & 1) != array[k]:  # 正直者に対して不親切 or 不親切に対して正直者と証言
                failed = True
                break
    if not failed:
        # 「0b010110」の「0b」を除外して1の数をカウント
        max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)


Measured memory_bytes: 44140
#line 1 "../lib/template.hpp"

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

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

  int n;
  cin >> n;
  int INF = 1e9 + 1;
  vi a(n), dp(n, INF);
  REP(i, n) { cin >> a[i]; }

  REP(i, n) {
    auto itr = lower_bound(ALL(dp), a[i]);
    *itr = a[i];
  }

  REP(i, n) {
    if (dp[i] == INF) {
      cout << i << endl;
      return 0;
    }
  }
  cout << n << endl;

  return 0;
}



Measured memory_bytes: 3612
import sys

input = sys.stdin.readline
import fractions



def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    MOD = 10 ** 9 + 7

    x = 1
    for a in A:
        x = (a * x) // fractions.gcd(a, x)

    ans = 0
    for a in A:
        ans += x // a

    print(ans % MOD)



    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 6112
#include <iostream>

using namespace std;


int main(){

	char c, ans;
	bool p[10][11];



	while (1){
		ans = '-';

		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 11; j++){
				p[i][j] = 0;
			}
		}

		for (int i = 0; i < 8; i++){
			for (int j = 0; j < 8; j++){
				cin >> c;
				p[i][j + 1] = c - '0';
			}
		}

		if (cin.eof())break;


		for (int i = 0; i < 8; i++){
			for (int j = 0; j < 8; j++){
				if (p[i][j + 1] == 1){
					if (p[i][j + 3] == 1) ans = 'C';
					else if (p[i + 2][j + 1] == 1) ans = 'B';
					else if (p[i + 2][j] == 1) ans = 'D';
					else if (p[i + 1][j + 3] == 1) ans = 'E';
					else if (p[i + 2][j + 2] == 1) ans = 'F';
					else if (p[i + 1][j] == 1) ans = 'G';
					else if (p[i + 1][j + 2] == 1) ans = 'A';
				}
				if (ans != '-')break;
			}
			if (ans != '-')break;
		}

		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1132
from fractions import gcd
a,b=map(int,input().split())
n=gcd(a,b)
ans={1}
for i in range(2,int(n**0.5)+1):
  while n%i==0:
    n//=i
    ans.add(i)
if n>1:
  ans.add(n)
print(len(ans))

Measured memory_bytes: 5048
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,ret;
vi a;

signed main(){
    I(n);
    a.resize(n);
    REP(i,n) I(a[i]);
    REP(i,n-1){
        ret += a[i]/2;
        a[i] %= 2;
        if (a[i] > 0 && a[i+1] > 0){
            a[i]--;
            a[i+1]--;
            ret++;
        }
    }
    cout << ret + a[n-1]/2 << endl;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
L = list(map(int,input().split()))

dp = [float("inf") for i in range(N)]
dp[0] = 0

for i in range(1,N) :
    for j in range(max(0,i-K),i) :
        dp[i] = min(dp[i], dp[j] + abs(L[j] - L[i]))

ans = dp[N-1]

print(ans)


Measured memory_bytes: 56672
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int r, ans;
    cin >> r;
    ans = pow(r, 2);
    cout << ans << endl;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	vector<pair<int, string>> liquid(n);
	rep(i, 0, n) cin >> liquid[i].second >> liquid[i].first;
	sort(all(liquid));

	//for (auto p : liquid)
		//cerr << p.first << " " << p.second << endl;

	int m; cin >> m;
	vector<string> color(m);
	rep(i, 0, m) cin >> color[i];
	reverse(all(color));
	rep(i, 0, m) {
		string target = color[i];
		//cerr << "Target: " << target << "; " << liquid.size() << endl;
		bool fulfilled = 0;
		int density;

		while (liquid.size()) {
			auto l = liquid.back(); liquid.pop_back();
			if (l.second == target) {
				//cerr << "Use: " << l.first << ", " << l.second << endl;
				density = l.first;
				fulfilled = 1;
				break;
			}
		}

		if (!fulfilled) {
			cout << "No" << endl;
			return 0;
		}

		while (liquid.size() && liquid.back().first == density) {
			//cerr << "Pop" << endl;
			liquid.pop_back();
		}
	}

	cout << "Yes" << endl;
}



Measured memory_bytes: 17720
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    int total = 0;
    int a[] = new int[n];
    int x[] = new int[n];
    int min = 0;
    for(int i=0 ; i<n ; i++){
      a[i] = i+l;
      total = total + a[i];
    }
    for(int i=0 ; i<n ; i++){
      if(Math.abs(a[i])<=Math.abs(a[min])){
        min = i;
      }
    }
    System.out.println(total-a[min]);
  }
}


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

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<cstdlib>

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<complex>
using namespace std;

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


//4-side
//int xx[] = {0,0,-1,1};
//int yy[] = {-1,1,0,0};
//6-side hexagonal
//int xx[] = {2,-2,1,1,-1,-1};
//int yy[] = {0,0,1,-1,1,-1};

#define popc(a) (__builtin_popcount(a))
//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

#define MX 100005
#define inf 100000000

const double pi = acos(-1.0);
const ll mod = 1000000007ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    scanf("%d", &n);
    printf("%d\n", n/3);
    return 0;
}



Measured memory_bytes: 256
from itertools import permutations

def check(queen):
    for r1, c1 in queen:
        if not all((r1 == r2 and c1 == c2) or (r1 + c1 != r2 + c2 and r1 - c1 != r2 - c2)
                   for r2, c2 in queen):
            return False
    return True

n = int(input())
row, col = list(range(8)), list(range(8)) #まだ置ける
queen = []
for _ in range(n):
    r, c = map(int, input().split())
    queen.append((r, c))
    row.remove(r) #もう置けない所を削除
    col.remove(c)
for l in permutations(col):
    queen_tmp = queen[:]
    for r, c in zip(row, l):
        queen_tmp.append((r, c))
    if check(queen_tmp):
        board = [''.join('Q' if (r, c) in queen_tmp else '.' for c in range(8)) for r in range(8)]
        print(*board, sep='\n')
        break


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int cnt[26];
int main() {
  string s;
  cin >> s;
  string t = s;
  int n = sz(s);
  rep(i,n){
    int c = s[i]-'a';
    cnt[c]++;
  }
  rep(i,26){
    if(cnt[i] == 0){
      char ch = 'a'+i;
      cout<<s+ch<<endl;
      return 0;
    }
  }

  int id = 0;
  bool ok = false;
    while(sz(s) && !ok){
      if(s[sz(s)-1] == 'z'){
        s.pop_back();
        cnt[t[n-1-id]-'a'] = 0;
        id++;
      }
      else
      {
        s[sz(s)-1]++;
        int c = s[sz(s)-1]-'a';
        if(cnt[c] == 0) ok=true;
        //cout<<s<<endl;
      }
    }
  if(sz(s)==0){
    cout<<-1<<endl;
    return 0;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
        int num;
        double w, h;
        char str[100], *tp;

        while ( scanf( "%s", str ) != EOF ) {
                tp = strtok( str, "," );
                num = atoi( tp );
                tp = strtok( NULL, "," );
                w = atof( tp );
                tp = strtok( NULL, "," );
                h = atof( tp );
                if ( w / (h*h) >= 25 ) { printf( "%d\n", num ); }
        }

        return 0;
}



Measured memory_bytes: 2036
import java.util.*;

public class Main {

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

		
		while(true){
			int max  = -1;
			int maxi;
			int min  = 1001;
			int mini;
			int sum = 0;
			
			num = scan.nextInt();
			if(num == 0)break;
			
			int[] scr = new int[num];
			
			for(int i = 0; i < num; i++){
				scr[i] = scan.nextInt();
				if(max < scr[i]){
					max = scr[i];
					maxi = i;
				} 
				if(min > scr[i]){
					min = scr[i];
					mini = i;
				}
				sum += scr[i];
			}
			
			sum -= (max + min);
			sum /= (num-2);
			
			System.out.println(sum);
		
		}
	}

}

Measured memory_bytes: 28832
n = gets.to_i
s = gets.chomp
t = gets.chomp

candidates = []
s.chars.each_with_index do |sch, si|
  str = ""
  t.chars.each_with_index do |tch, ti|
    if s[si+ti] == tch
      str += tch
    else
      break
    end
  end
  candidates << str
end

# p candidates

ans = ""
if candidates.empty?
  ans = s + t
else
  common = candidates.sort { |a, b| b.size - a.size }
  common.each do |c|
    if (s[0...s.rindex(c)] + t).size >= n
      puts (s[0...s.rindex(c)] + t).size
      exit
    end
  end

  ans =  s + t
end

puts ans.size


Measured memory_bytes: 1916
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        int n=sc.nextInt();
        int a;
        int b;
        String str2;
        StringBuilder sb;
        for(int i=0;i<n;i++){
            String order=sc.next();
            a=sc.nextInt();
            b=sc.nextInt();
            if(order.equals("print")){
                str2=str.substring(a,b+1);
                System.out.println(str2);
            }else if(order.equals("reverse")){
                str2=str.substring(a,b+1);
                sb=new StringBuilder(str2);
                str2=sb.reverse().toString();
                sb=new StringBuilder(str);
                str=sb.replace(a,b+1,str2).toString();
            }else if(order.equals("replace")){
                str2=sc.next();
                sb=new StringBuilder(str);
                str=sb.replace(a,b+1,str2).toString();
            }
        }
    }
}


Measured memory_bytes: 29784
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
typedef long long ll;
typedef long double ld;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
  ll n,m,k,i,j,result=0;
  int a[200010];
  string s;
  cin >> n;
  cout << (n>=30 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3628