akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int s[] = new int[n];
            int sum = 0;
            for(int i=0;i<n;i++){
                s[i] = sc.nextInt();
                sum = sum+s[i];
            }
            double ave = (double)sum/n;
            double a2 = 0;
            for(int i=0;i<n;i++){
                a2 = a2+(s[i]-ave)*(s[i]-ave);
            }
            a2 = a2/n;
            double a = Math.pow(a2, 0.5);
            System.out.println(a);
        }
        sc.close();
    }
}


Measured memory_bytes: 31140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << max (max (a *10 + b + c, a + b * 10 + c), a + b + c * 10) << endl;
}


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

map<ll,ll> sosuu;

void bunkai(ll &N){
  if(N%2==0){
    sosuu[2]++;
    N=N/2;
    return ;
  }
  for(ll i=3;i<=sqrt(N);i+=2){
    if(N%i==0){
      sosuu[i]++;
      N=N/i;
      return ;
    }
  }
  sosuu[N]++;
  N=1;
  return ;
}

int main(){
  ll N;
  cin >> N;
  while(N!=1){
    bunkai(N);
  }
  ll ans=0;
  for(pair<ll,ll> p:sosuu){
    ans+=floor((-1+sqrt(1+8*p.second))/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int a[201];
int b[201];
int c[201];
int main()
{
	int i,j,l,n,sum=0;
	cin>>n>>l;
	for(i=1;i<=n;i++)
	{
		a[i]=l+i-1;
		sum+=a[i];
	}

	for(i=1;i<=n;i++)
	{
		b[i]=abs(a[i]);
	
	}
	for(i=1;i<=n-1;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(b[j]>b[j+1])
			{
				swap(b[j],b[j+1]);
				swap(a[j],a[j+1]);
			}
				
		}
	}
	
	cout<<sum-a[1];
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl                endl

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, int y) {                                                             //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
struct trio {
  T first{};
  T second{};
  T third{};
};
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class ECountMedian {
public:
  static void solve(istream &cin, ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) {
      cin >> A[i] >> B[i];
    }
    sort(ALL(A));
    sort(ALL(B));
    if (N % 2) {
      cout << B[N / 2] - A[N / 2] + 1 << endl;
    } else {
      cout << (B[N / 2] + B[N / 2 - 1]) - (A[N / 2] + A[N / 2 - 1]) + 1 << endl;
    }
  }
};


signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ECountMedian solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
ll r=1;
a=a%m;
while(b>0)
{
if(b&1)
r=(r*a)%m;
b=b/2;
a=(a*a)%m;
}
return r%m;
}

vi bit;//1-based indexing

void bit_update(ll x,ll n,ll val)
{
    while(x<n)
    {
        bit[x]+=val;
        x+=(x&(~x+1));
    }
}

ll bit_sum(ll x)
{
    ll sum=0;
    while(x>0)
    {
        sum+=bit[x];
        x-=(x&(~x+1));
    }
    return sum;
}



int main(){
    IOS
    ll n;
    cin>>n;
    vi h(n);
    rep(i,0,n)cin>>h[i];
    vi dp(n,1);
    ll a=1;
    repr(i,n-2,-1)
    {
        if(h[i]>=h[i+1])dp[i]+=dp[i+1];
        a=max(a,dp[i]);
    }
    cout<<a-1;



    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for ( int i = 1; i * i <= m; ++i ) {
        if ( m % i == 0 ) {
            if ( m / i >= n ) {
                ans = max(ans, i);
            }
            if ( i >= n ) {
                ans = max(ans, m / i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N, A, B;
    cin >> N >> A >> B;
    vector<LL> v(N);
    REP(i, N) {
        cin >> v[i];
    }
    LL s = v[0];
    REP(i, N) {
        v[i] -= s;
    }
    LL res = 0;
    FOR(i, 1, N) {
        res += min(B, A*(v[i] - v[i - 1]));
    }
    cout << res << endl;
    return 0;
}



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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int a, b; cin>>a>>b;
  vi p1, p2;
  rep(i,0,b) {
    p1.pb(a);
  }
  rep(i,0,a) {
    p2.pb(b);
  }
  if(p1<p2) {
    rep(i,0,SZ(p1)) cout<<p1[i];
  }
  else rep(i,0,SZ(p2)) cout<<p2[i];
  cout<<endl;
}



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

int main(void){
  long long n, now=0, ans[2]={};
  bool flag;
  scanf("%ld", &n);
  long long a[n];

  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }

  for (int j = 0; j < 2; j++) {
    now = 0;
    if (j==0) {
      flag = true;
    }else{
      flag = false;
    }

    for (int i = 0; i < n; i++) {
      now += a[i];
      if (flag) {
        if (now >= 0) {
          ans[j] += now + 1;
          now = -1;
        }
        flag = false;
      }else{
        if (now <= 0) {
          ans[j] += 1 - now;
          now = 1;
        }
        flag = true;
      }
    }
  }
  if (ans[0]>ans[1]) {
    printf("%ld", ans[1]);
  }else{
    printf("%ld", ans[0]);
  }
  return 0;
}


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

#define ll long long
#define N 200010
#define INFLL 0x3f3f3f3f3f3f3f3f
int n, m;
ll d;
struct node
{
	int id; ll v;
	void scan(int id)
	{
		this->id = id;
		scanf("%lld", &v);
	}
	bool operator < (const node &other) const { return v < other.v; }
}a[N];
struct Edge
{
	int u, v; ll w;
	Edge () {}
	Edge (int u, int v, ll w) : u(u), v(v), w(w) {}
	bool operator < (const Edge &other) const { return w < other.w; }
}edge[N << 2];

struct SEG
{
	struct node
	{
		ll Min; int pos;
		node () {}
		node (ll Min, int pos) : Min(Min), pos(pos) {}
		void init() { Min = INFLL, pos = -1; }
		node operator + (const node &other) const
		{
			node res; res.init();
			if (Min < other.Min)
			{
				res.Min = Min;
				res.pos = pos;
			}
			else
			{
				res.Min = other.Min;
				res.pos = other.pos;
			}
			return res;
		}
	}a[N << 2], res;
	void build(int id, int l, int r)
	{
		a[id].init(); 
		if (l == r) return;
		int mid = (l + r) >> 1;
		build(id << 1, l, mid);
		build(id << 1 | 1, mid + 1, r);
	}
	void update(int id, int l, int r, int pos, ll v)
	{
		if (l == r) 
		{
			a[id] = node(v, pos);
			return;
		}
		int mid = (l + r) >> 1;
		if (pos <= mid) update(id << 1, l, mid, pos, v);
		else update(id << 1 | 1, mid + 1, r, pos, v);
		a[id] = a[id << 1] + a[id << 1 | 1];
	}
	void query(int id, int l, int r, int ql, int qr)
	{
		if (qr < ql) return;
		if (l >= ql && r <= qr)
		{
			res = res + a[id];
			return;
		}
		int mid = (l + r) >> 1;
		if (ql <= mid) query(id << 1, l, mid, ql, qr);
		if (qr > mid) query(id << 1 | 1, mid + 1, r, ql, qr);
	}
}seg[2];

int pre[N];
int find(int x) { return pre[x] == 0 ? x : pre[x] = find(pre[x]); }
ll Kruskal()
{
	memset(pre, 0, sizeof pre);
	sort(edge + 1, edge + 1 + m);
	int cnt = 1;
	ll res = 0;
	for (int i = 1; i <= m; ++i)
	{
		int u = edge[i].u, v = edge[i].v; ll w = edge[i].w;
		int fu = find(u), fv = find(v);
		if (fu == fv) continue;
		pre[fu] = fv;
		++cnt;
		res += w;
		if (cnt == n) return res;
	}
	return res;
}

int main()
{
	while (scanf("%d%lld", &n, &d) != EOF)
	{	
		m = 0;
		for (int i = 1; i <= n; ++i) a[i].scan(i);
		for (int i = 0; i < 2; ++i) seg[i].build(1, 1, n);
		sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n; ++i)
		{
			int u = a[i].id, v;
			for (int j = 0; j < 2; ++j)
				seg[j].res.init();
			seg[0].query(1, 1, n, 1, u - 1);
			seg[1].query(1, 1, n, u + 1, n);
			for (int j = 0; j < 2; ++j) if (seg[j].res.pos != -1)
			{
				v = seg[j].res.pos;
				edge[++m] = Edge(u, v, a[i].v + 1ll * (j ? -1 : 1) * d * u + seg[j].res.Min);
			}
			seg[0].update(1, 1, n, u, a[i].v - d * u);
			seg[1].update(1, 1, n, u, a[i].v + d * u);
		}
		printf("%lld\n", Kruskal());
	}
	return 0;
}


Measured memory_bytes: 33408
n = int(input())
eight_cnt = 0

for i in range(1, n + 1, 2):
    j = 1
    cnt = 0
    
    while j*j <= i :
        if i % j == 0 :
            if j*j == i :
                cnt += 1
                
            else:
                cnt += 2
                
        j += 1
        
    if cnt == 8 :
        eight_cnt += 1
        
print(eight_cnt)  

Measured memory_bytes: 9096
# -*- coding: utf-8 -*-

n = gets.to_i
# 一回目

strings = Array.new
n.times do
  string_h = Hash.new
  gets.chomp.split('').each do |t|
    string_h[t] ||= 0
    string_h[t] += 1
  end
  strings.push(string_h)
end
# puts strings
# puts '--'

common = Hash.new
# 1回目
strings[0].each do |k, v|
  common[k] = v
end


exsit = Array.new
for i in 0...n do
  common.each_key { |k| exsit.push(k) }

  exsit.each do |k|
    if common.has_key?(k) && strings[i].has_key?(k)
      common[k] = common[k] < strings[i][k] ? common[k]:strings[i][k]
    else
      common.delete(k)
    end
  end
end
# puts exsit

result = Array.new
common.each do |k, v|
  result.push(k*v)
end

puts result.sort.join('')


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

vector<vector<pil>> Graph(100010);

int main(){
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b;
    long c;
    cin >> a >> b >> c;
    Graph.at(a-1).push_back(pil(b-1,c));
    Graph.at(b-1).push_back(pil(a-1,c));
  }
  int q,k;
  cin >> q >> k;
  queue<int> que;
  que.push(k-1);
  vector<long> distance(n,-1);
  distance.at(k-1) = 0;
  while(que.size()){
    int v = que.front();
    que.pop();
    for(pil nP : Graph.at(v)){
      int nv = nP.first;
      if(distance.at(nv) != -1) continue; 
      long cost = nP.second;
      distance.at(nv) = distance.at(v) + cost;
      que.push(nv);
    }
  }
  rep(i,q){
    int x,y;
    cin >> x >> y;
    cout << distance.at(x-1) + distance.at(y-1) << endl;
  }
}


Measured memory_bytes: 9984
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#define INF (1<<30)
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int D, N; cin >> D >> N;
	vector<int> T(D), A(N), B(N), C(N);
	for (int i = 0; i < D;i++) cin >> T[i];
	for (int i = 0; i < N;i++)cin >> A[i] >> B[i] >> C[i];
	vector<vector<pair<int, int>>> dp(D, vector<pair<int, int>>(N, { 0,-1 }));

	int ans = 0;
	for (int i = 0; i < N;i++) {
		if (T[0] >= A[i] && T[0] <= B[i]) {
			dp[0][i] = { 0,C[i] };
		}
	}

	for (int i = 1; i < D;i++) {
		for (int j = 0; j < N;j++) {
			if (T[i] >= A[j] && T[i] <= B[j]) {
				for (int k = 0; k < N;k++) {
					if (dp[i - 1][k].second != -1) {
						if (dp[i][j].first <= dp[i - 1][k].first + abs(C[j] - dp[i - 1][k].second)) {
							dp[i][j].first = dp[i - 1][k].first + abs(C[j] - dp[i - 1][k].second);
							dp[i][j].second = C[j];
						}
					}
				}

			}
		}
	}
	for (int i = 0; i < N;i++) {
		ans = max(ans, dp[D - 1][i].first);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3260
a, b = map(int, input().split())

ans_a = 0
ans_b = 0
ans = []
for i in range(b):
    ans_a = ans_a + a*10**i

for i in range(a):
    ans_b = ans_b + b*10**i

ans_a = str(ans_a)
ans_b = str(ans_b)

ans = [ans_a,ans_b]
answer = sorted(ans)
c = answer[0]
print(answer[0])

Measured memory_bytes: 3064
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=a+b+c;
	int n=max(a,(max(b,c)));
	int m=n;
	rep(i,k) n*=2;
	ans=ans+n-m;
	cout<<ans;
    rt0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        vector<int> a(5);
        vector<int> b(4);
        for(int i=0; i<5; ++i){
            cin >> a[i];
            if(a[i] == 0)
                return 0;
            ++ b[a[i]];
        }

        if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] > 0 && b[2] > 0 && b[3] > 0)){
            a.assign(5, 3);
        }else{
            if(b[1] == 0){
                replace(a.begin(), a.end(), 2, 1);
                replace(a.begin(), a.end(), 3, 2);
            }else if(b[2] == 0){
                replace(a.begin(), a.end(), 1, 2);
                replace(a.begin(), a.end(), 3, 1);
            }
        }

        for(int i=0; i<5; ++i)
            cout << a[i] << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define MAX 100005
#define ALPHA 26
char S[MAX];
int main()
{
    int K,i,N;
    scanf("%d ",&K);
    char c;
    for(i=0;;i++)
    {
        scanf("%c",&c);
        if(!(c>='a'&&c<='z')) break;
        S[i]=c;
    }
    N=i;
    for(i=0;i<N&&i<K;i++)
    {
        printf("%c",S[i]);
    }
    if(i<N) printf("...");
    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int cnt1[26] = {0}, cnt2[26] = {0};
    for (int i = 0; i < n; ++i)
        cnt1[s[i]-'a']++;
    int maxx = 0;
    for (int i = 0; i < n; i++)
    {

        ++cnt2[s[i]-'a'];
        int temp = 0;
        for (int k = 0; k < 26; k++)
        {
            if (cnt2[k] && (cnt1[k] - cnt2[k] > 0))
                ++temp;//, cout << 'a'+k << endl;
        }
        if (temp > maxx) maxx = temp;
    }
    cout << maxx << endl;
    return 0;
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int K, N;

int main(void)
{
    cin >> K >> N;
    vector<int> A(N);

    rep(i, N) {
        cin >> A[i];
    }

    ll ans = min(K - (A[0] + (K - A[N - 1])), K - (A[1] - A[0]));
    for(int i = 0; i < N - 1; ++i) {
        ll t = min(K - (A[i] - A[i - 1]), K - (A[i + 1] - A[i]));
        ans = min(t, ans);
    }

    ll t = min(K - (A[N - 1] - A[N - 2]), K - (K - A[N - 1] + A[0]));
    ans = min(t, ans);

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin >> n;
	for(register long long a = 1; a <= 3500; ++a)
	{
		for(register long long b = 1; b <=3500; ++b)
		{
			long long x = a * b * n;
			long long y = 4 * a * b - n * b - n * a;
			if(y > 0 && x % y == 0)
			{
				cout << a << " " << b << " " << x / y << endl;
				return 0;
			}
		}
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end());
    ll ans = INF;
    rep(i, N - K + 1) {
        ans = min(ans, abs(H[i + K - 1] - H[i]));
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);

		@SuppressWarnings("unchecked")
		Stack<Integer>[] stackArray = new Stack[n];
		for(int i = 0; i < n; i++){
			stackArray[i] = new Stack<Integer>();
		}

		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");

			//push
			if(tmpArray[0].equals("0")){
				int t = Integer.parseInt(tmpArray[1]);
				int x = Integer.parseInt(tmpArray[2]);

				stackArray[t].push(x);
			}
			//top
			else if(tmpArray[0].equals("1")){
				int t = Integer.parseInt(tmpArray[1]);

				if(!stackArray[t].isEmpty()){
					System.out.println(stackArray[t].peek());
				}
			}
			//pop
			else {
				int t = Integer.parseInt(tmpArray[1]);

				if(!stackArray[t].isEmpty()){
					stackArray[t].pop();
				}
			}
		}

	}
}


Measured memory_bytes: 69472
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
before = 0
ans = 0
for num in a:
    if num == before:
        if ans == 0:
            ans = num
            before = 0
        else:
            print(ans * num)
            exit()
    else:
        before = num
print(0)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n, x;
    cin >> n;

    for (int i=1;i<=n;i++) {
        x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        } else {
            while (x!=0) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;    
            }
        }
    }
    cout << endl;
    return 0;
}



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

int main(){
	int n, q;
	cin >> n >> q;
    vector<set<int>> mat(n+1);
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        mat[a].insert(b);
        mat[b].insert(a);
    }
    vector<int> cnt(n+1, 0);
    for(int i=0; i<q; i++){
        int p, x;
        cin >> p >> x;
        cnt[p] += x;
    }

    queue<int> qu;
    qu.push(1);
    while(!qu.empty()){
        int v=qu.front();
        qu.pop();
        
        for(int i: mat[v]){
            qu.push(i);
            cnt[i] += cnt[v];
            mat[i].erase(v);
        }
    }

    for(int i=1; i<n+1; i++){
        cout << cnt[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 32000
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')

def main():
	n,m,k=MI()
	mod=998244353
	
	f=[1]
	for i in range(1,2*10**5+100):
		f.append((f[-1]*i)%mod)
	finv=[]
	for i in f:
		finv.append(pow(i,mod-2,mod))
	
	mp=[1]
	for i in range(1,2*10**5+100):
		mp.append((mp[-1]*(m-1))%mod)
		
	
	ans=0
	for kk in range(k+1):
		cnt=f[n-1]*finv[kk]*finv[n-1-kk]
		cnt%=mod
		cnt*=m*mp[n-kk-1]
		cnt%=mod
		ans+=cnt
	print(ans%mod)













if __name__=="__main__":
	main()


Measured memory_bytes: 32804
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.lang.*; 
import java.util.*;

public class Main 
{ 
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
		
	}
public static void main(String[] args) 
	{ 
		FastReader ob=new FastReader(); 
		String s = ob.next();
		int count=0,n=s.length();
		for (int i=0;i<n/2 ;i++ ) {
		    if(s.charAt(i)!=s.charAt(s.length()-1-i)){
		        count++;
		    }
		}
		System.out.println(count);
	}
		
	
} 	

Measured memory_bytes: 21204
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define debug(x) cout<<x<<"DE"<<endl;

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll l1[6],x=0,s=0;
    for(int i=1;i<=5;i++){
        cin>>l1[i];
        s+=l1[i]+((l1[i]%10)!=0?10-(l1[i]%10):0);
        if((l1[i]%10)!=0)x=max(x,(ll)(10-(l1[i]%10)));
    }
    cout<<s-x<<endl;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    /// <summary>
    /// https://atcoder.jp/contests/abc172/tasks/abc172_b
    /// </summary>
    class A_171_αlphabet
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string a = Console.ReadLine();

            if (Regex.IsMatch(a, "[A-Z]"))
            {
                a = "A";
            }
            else
            {
                a = "a";
            }



            string result = a;

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 26676
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
vector<pair<int, int>> vertexs[800];
int broken[800] = {};
int cost[800] = {};
void dfs(int now, int back) {
	for (int q = 0; q < vertexs[now].size(); ++q) {
		if (vertexs[now][q].first != back) {
			cost[vertexs[now][q].first] = cost[now] + vertexs[now][q].second;
			dfs(vertexs[now][q].first, now);
		}
	}
	return;
}
int main() {
	iostream::sync_with_stdio(false);
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		vector<tuple<int, int, int>> edges;
		REP(i, n-1) {
			int a;
			cin >> a;
			a--;
			edges.push_back(make_tuple(a, i + 1, 0));
		}
		long long ans = 0;
		REP(i, n - 1) {
			cin >> get<2>(edges[i]);
			ans += get<2>(edges[i]) * 3LL;
		}
		REP(i, n) {
			vertexs[i].clear();
			broken[i] = 0;
		}
		int cnt[800] = {};
		REP(i, edges.size()) {
			cnt[get<0>(edges[i])]++;
			cnt[get<1>(edges[i])]++;
		}
		REP(i, edges.size()) {
			if (cnt[get<0>(edges[i])] == 1 || cnt[get<1>(edges[i])] == 1) {
				ans -= 2LL * get<2>(edges[i]);
				if (cnt[get<0>(edges[i])] == 1) {
					broken[get<0>(edges[i])] = 1;
				}
				else {
					broken[get<1>(edges[i])] = 1;
				}
			}
			else {
				vertexs[get<0>(edges[i])].push_back(make_pair(get<1>(edges[i]), get<2>(edges[i])));
				vertexs[get<1>(edges[i])].push_back(make_pair(get<0>(edges[i]), get<2>(edges[i])));
			}
		}
		REP(i, n) {
			cost[i] = -1;
		}
		for (int i = 0; i < n; ++i) {
			if (broken[i] == 0) {
				cost[i] = 0;
				dfs(i, -1);
				break;
			}
		}
		long long now_itr = 0;
		REP(i, n) {
			if (cost[now_itr] < cost[i]) {
				now_itr = i;
			}
		}
		cost[now_itr] = 0;
		dfs(now_itr, -1);
		now_itr = 0;
		REP(i, n) {
			if (cost[now_itr] < cost[i]) {
				now_itr = i;
			}
		}
		cout << ans-cost[now_itr] << endl;
	}
}


Measured memory_bytes: 3280
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e3 + 10;
int row[N * N], col[N * N];

int main() {
  int n, m, x;
  scanf("%d%d", &n, &m);
  memset(row, 255, sizeof(row));
  memset(col, 255, sizeof(col));
  bool conflict = false;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    if (row[x] >= 0) conflict = true;
    row[x] = i;
  }
  for (int j = 0; j < m; ++j) {
    scanf("%d", &x);
    if (col[x] >= 0) conflict = true;
    col[x] = j;
  }
  if (conflict) {
    puts("0");
    return 0;
  }
  int k, row_cnt = 0, col_cnt = 0;
  int64 ret = 1;
  for (k = n * m; k >= 1; --k) {
    if (row[k] >= 0 && col[k] >= 0) {
      if (row_cnt + 1 > n || col_cnt + 1 > m) break;
      row_cnt += 1;
      col_cnt += 1;
    } else if (row[k] >= 0) {
      if (row_cnt + 1 > n) break;
      row_cnt += 1;
      ret = ret * col_cnt % MOD;
    } else if (col[k] >= 0) {
      if (col_cnt + 1 > m) break;
      col_cnt += 1;
      ret = ret * row_cnt % MOD;
    } else {
      int cur = row_cnt * col_cnt - (n * m - k);
      ret = ret * cur % MOD;
    }
  }
  if (k > 1) ret = 0;
  printf("%lld\n", ret);
  return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;



int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int N;
    int cak=4,dor=7;

    cin >> N;
    while(N >=0){
        if(N%4 == 0){
            cout << "Yes" << endl; 
            return 0;
        }
        N-=7;
    }
    if(N==0)
        cout << "Yes" << endl;
    else
        cout<< "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_166
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();
            if (s[1] == 'B')
            {
                WriteLine("ARC");
            }
            else
            {
                WriteLine("ABC");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main()
{
  int N, A, B;
  int res=0;
  cin >> N >> A>> B;

  res = min(A*N, B);

  
  cout << res << endl;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
costs = list(map(int, input().split()))

if k > n:
    k == n

if n == 2:
    print(abs(costs[-1] - costs[-2]))
else:
    dp = [float("inf") for i in range(n)]
    dp[-1] = 0

    for i in range(1, k + 1):
        curr_min = float("inf")
        for j in range(i):
            curr_min = min(abs(costs[n - i - 1] - costs[n - j - 1]) + dp[n - j - 1], curr_min)
        dp[n - i - 1] = curr_min    

    for i in range(n - k - 2, -1, -1):
        curr_min = float("inf")
        for j in range(1, k + 1):
            curr_min = min(curr_min, abs(costs[i] - costs[i + j]) + dp[i + j]) 
        dp[i] = curr_min

    print(dp[0])


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  int cnt = 0;
  for(int i = 0; i < n-1; ++i){
    if(v[i] == i){
      swap(v[i],v[i+1]);
      cnt++;
    }
  }
  cnt += v[n-1] == n-1;
  cout << cnt << endl;
}



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

array = []
dict_array = {}
for i in range(1, n+1):
  name, p = input().split()
  array.append([name, int(p)])
  dict_array[str(name)+str(p)] = i

sort_array = sorted(array, key=lambda x:(x[0], -x[1]))

for i in range(0, len(sort_array)):
  print(dict_array[str(sort_array[i][0])+str(sort_array[i][1])])

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    string check;

    for(int i = 0; i < n - 2; i++){
        check = s.substr(i, 3);
        if(check == "ABC"){
            count++;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1;
    for (size_t i = 0; i < size; ++i) {
        vec1.push_back(cin2var<T>());
    }
    return vec1;
}

int main()
{
    const int       N(cin2var<int>());
    const int       C(cin2var<int>());
    const vec1<int> P(cin2vec<int>(C));
    const int       sum = accumulate(P.cbegin(), P.cend(), 0);
    const int       N1  = N + 1;
    int result = sum / N1;
    if (sum % N1 > 0) {
        ++result;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3140
using System;
using System.Collections.Generic;

namespace AIsing20200711
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            if( N < 6 )
            {
                for (var i = 0; i< N; i++)
                {
                    Console.WriteLine(0);
                }
                return;
            }

            for(var i = 1; i <= N; i++)
            {
                int cnt = 0;
                for (var x = 1; x<= N; x++)
                {
                    if(x*x>=i)
                    {
                        break;
                    }
                    for( var y = 1; y<= N; y++)
                    {
                        if(x*x + y*y + x*y > i)
                        {
                            break;
                        }
                       for( var z = 1;z<=N;z++)
                        {
                            int rlt = x * x + y * y + z * z + x * y + y * z + z * x;
                            if(rlt == i)
                            {
                                cnt++;
                                continue;
                            }
                            else if(rlt > i)
                            {
                                break;
                            }
                        }
                    }
                }
                Console.WriteLine(cnt);
            }
        }
    }
}


Measured memory_bytes: 27536
#C - 755 解3
Set753 = {7, 5, 3}
List753 = [7, 5, 3]

N = int(input())

def getDigitList(n):
    list = []
    while n>0:
        list.append(n%10)
        n //= 10
    list.reverse()
    if list==[]: list = [0]
    return list

def gen(n):
    if n>N: return []
    else:
        d = getDigitList(n)
        #print(d) #
        if set(d)==Set753: 
            result = [n]
        else:
            result = []
        for a in List753:  result += gen(n*10+a)
        return result
                
result = gen(0)
#print(result) #
print(len(result)) 

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

f = False
for i in range(n):
    t, x, y = list(map(int, input().split()))
    if f:
        continue
    if t < x + y:
        print('No')
        f = True
    if t % 2 == 0 and (x + y) % 2 == 1:
        print('No')
        f = True
    if t % 2 == 1 and (x + y) % 2 == 0:
        print('No')
        f = True
if not f:
    print('Yes')


Measured memory_bytes: 44120
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a, b, c;
    cin>>a>>b>>c;
    if(a == b + c or b == a + c or c == a + b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 4648
#A
inf = float("inf")
N,M = map(int,input().split())
C = list(map(int,input().split()))
C.sort()

dp = [inf for i in range(N+1)]
dp[0] = 0
for c in C:
    for p in range(c,N+1):
        dp[p] = min(dp[p],dp[p-c]+1)
        
print(dp[N])





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

signed main(){
	lint n; cin >> n;
	vector<lint> a(n);
	for(lint i = 0; i < n; i++) cin >> a[i];
	lint ans1 = 0, ans2 = 0, sum1 = 0,sum2 = 0;
	for(lint i = 0; i < n; i++){
		sum1 += a[i];
		if(i % 2 == 0 && sum1 <= 0) ans1 += (1 - sum1), sum1 = 1;
		if(i % 2 == 1 && sum1 >= 0) ans1 += (sum1 + 1), sum1 = -1;  
	}
	for(lint i = 0; i < n; i++){
		sum2 += a[i];
		if(i % 2 == 1 && sum2 <= 0) ans2 += (1 - sum2), sum2 = 1;
		if(i % 2 == 0 && sum2 >= 0) ans2 += (sum2 + 1), sum2 = -1;  
	}
	cout << min(ans1, ans2) << endl;
}
	


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_159TheNumberofEvenPairs
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long N = inputLongArray[0];
            long M = inputLongArray[1];

            long result = (N * (N - 1) / 2) + (M * (M - 1) / 2);

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
#define double long double
const int MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    int arr[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        sum -= arr[i];
        // int temp = ((sum % MOD) * arr[i]) % MOD;
        // sum = ((sum % MOD) + (temp));
        ans += (sum % MOD) * arr[i];
        ans %= MOD;
    }
    cout << ans << endl;
}

int32_t main()
{
    IOS;
#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    solve();

}

Measured memory_bytes: 5196
def main():
    a, v = list(map(int, input().split()))
    b, w = list(map(int, input().split()))
    t = int(input())

    if v * t >= w * t + abs(b - a):
        return 'YES'
    else:
        return 'NO'

if __name__ == '__main__':
    result = main()
    print(result)


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

int bubbleSort(vector<int> &A, int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int sw = bubbleSort(A, N);
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << A[i] << endl;
    } else {
      cout << A[i] << ' ';
    }
  }
  cout << sw << endl;
};



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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)

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

int32_t main(){
    string s; cin >> s;
    if(s[0] != s[1] || s[0] != s[2] || s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#define NUM 100001

int parent(int a){
  return a/2;
}

int left(int a){
  return 2*a;
}

int right(int a){
  return 2*a+1;
}

int main(){
  int n,i,A[NUM];

  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) > 0)
      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)]);

    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 608
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;
int arr[maxn];
int ps[maxn];
int main(){
	migmig;
	int n;
	cin>>n;
	int an=inf;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	ps[0]=arr[0];
	for(int i=1;i<n;i++){
		ps[i]=ps[i-1]+arr[i];
	}
	for(int i=0;i<n-1;i++){
		int l=ps[i];
		int r=ps[n-1]-ps[i];
		int x=abs(l-r);
		an=min(an,x);
	}
	cout<<an;
}



Measured memory_bytes: 256
function main(input) {
  var map = {};
  input[0].split("").forEach(w=>{map[w]=true});
  var tx = "abcdefghijklmnopqrstuvwxyz";
  var ans = "None";
  for(var i=0;i<tx.length;i++){
    if(!map[tx[i]]) {console.log(tx[i]); return;}
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  ll A[N], B[M], sumA[N+1], sumB[M+1];
  sumA[0] = 0;
  sumB[0] = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sumA[i+1] = sumA[i] + A[i];
  }
  for (int i=0; i<M; i++) {
    cin >> B[i];
    sumB[i+1] = sumB[i] + B[i];
  }
  int ans = 0, a = 0, b = M;
  while (a <= N) {
    while (b != 0 && sumB[b] > K-sumA[a])
      b--;
    if (sumA[a]+sumB[b] <= K)
      ans = max(ans, a+b);
    a++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9764
import java.util.*;
import java.math.*;
public class Main {
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();//肥料の種類
			int m = stdIn.nextInt();//肥料を与える回数
			if(n == 0 && m == 0) break;

			double[][] table = new double[n][n];
			for(int r = 0; r < n; r++) {
				for(int c = 0; c < n; c++) {
					table[r][c] = stdIn.nextDouble();
				}
			}
			double[][] dp = new double[m][n];
			Arrays.fill(dp[0], 1);//最初は効果がない
			for(int k = 1; k < m; k++) {
				for(int r = 0; r < n; r++) {
					for(int c = 0; c < n; c++) {
						dp[k][c] = Math.max(dp[k][c], dp[k - 1][r] * table[r][c]);
					}
				}
			}
			double ans = -1;
			for(int r = 0; r < n; r++) {
				ans = Math.max(ans, dp[dp.length - 1][r]);
			}
//			BigDecimal bi = new BigDecimal(String.valueOf(ans));
//			double k2 = bi.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
			System.out.printf("%.2f\n", ans);
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b || b==c || a==c){
        if(a!=b || b!=c || a!=c){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256