akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict

n = int(sys.stdin.readline().rstrip())
sp = [sys.stdin.readline().split() for _ in range(n)]

def main():
    res = defaultdict(list)
    for i in range(n):
        s, p = sp[i]
        res[s].append((int(p), i+1))
    
    for s, l in sorted(res.items()):
        for p, i in sorted(l, reverse=True):
            yield i

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 3316
def queue(nm,tm,q):
    total=0
    while nm:
        name=nm.pop(0)
        time=tm.pop(0)
        if q<time:
            time-=q
            total+=q
            nm.append(name)
            tm.append(time)

        else:
            total+=time
            print("{} {}".format(name, total))
    
    
def main():
    n,q=map(int,input().split())
    name=[]
    time=[]
    for i in range(n):
        nm,tm=input().split()
        name.append(nm)
        time.append(int(tm))

    queue( name, time, q)
    

if __name__=='__main__':
    main()



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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  for (ll i = 0; i < N; ++i) {
    cin >> H.at(i);
  }
  vector<vector<ll>> G(N);
  for (ll i = 0; i < M; ++i) {
    ll ai, bi;
    cin >> ai >> bi;
    G.at(ai - 1).push_back(bi - 1);
    G.at(bi - 1).push_back(ai - 1);
  }
  ll cnt = 0;
  for (ll i = 0; i < N; ++i) {
    ll hi = H.at(i);
    bool flg = true;
    for (ll j = 0; j < G.at(i).size(); ++j) {
      ll hj = H.at(G.at(i).at(j));
      if (hj >= hi) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ++cnt;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

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

using vi = vector<int>;
using ii = pair<int, int>;

const int MOD = 1e9 + 7;

using ll = long long;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(NULL);

  int n;

  cin >> n;

  vi v(n), p(n + 1);

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

  p[n] = 0;
  for (int i = n - 1; i >= 0; i--)
    p[i] = (0LL + p[i + 1] + v[i]) % MOD;

  ll ans = 0;
  for (int i = 0; i < n - 1; i++)
    ans = (ans + 1LL * v[i] * p[i + 1]) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4768
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, yen) = in.readLine.split(" ").map(_.toInt)
  val ans = {
    var isFind = false
    var res = Array(0,0,0)
    for {
      x <- 0 to n
      y <- 0 to n - x
      if !isFind
    } {
      val z = n - x - y
      if((10000 * x) + (5000 * y) + (1000 * z) == yen) {
        res = Array(x, y, z)
        isFind = true
      }
    }
    if(res.forall(_ == 0)) Array(-1,-1,-1) else res
  }

  println(ans.mkString(" "))
}

Measured memory_bytes: 38760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    map<ll,ll> mp;
    ll ans=0;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    reverse(ALL(a));
    REP(i,n){
        bool f=false;
        REPR(j,32){
            if((1LL<<j)<=a[i]){
                break;
            }
            if(mp[(1LL<<j)-a[i]]){
                ans++;
                mp[(1LL<<j)-a[i]]--;
                f=true;
                break;
            }
        }
        if(!f){
            mp[a[i]]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 55676
#include<string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	deque<int> nums;

	string str;
	cin>>str;

	for(int i = 0;i < str.size();i++){
		if(str[i] == '0'){
			nums.push_back(0);
		}else if(str[i] == '1'){
			nums.push_back(1);
		}else if(str[i] == 'B'){
			if(!nums.empty()){
				nums.pop_back();
			}
		}
	}

	for(auto& s:nums){
		cout<<s;
	}cout<<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N == 0) {
      System.out.println(0);
      return;
    }
    
    String ans = "";
    while (N != 0) {
      if (N % 2 != 0) {
        N--;
        ans = "1" + ans;
      } else {
        ans = "0" + ans;
      }
      N /= -2;
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

#include <cmath>
using namespace std;

int main() {
    
    string s;
    
    cin >> s;
    
    string out;
    
    for(auto a: s){
        
        if (a == '0' || a == '1'){
            out.push_back(a);
        }else{
            if (out.size() == 0) continue;
            out.pop_back();
        }
        
    }
    
    cout << out << endl;
    
    return 0;
    
}




Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  vector<bool> hoge(101, false);

  REP(i,n){
    int a;
    cin >> a;
    hoge[a] = true;
  }

  int sum = 0;

  REP(i,hoge.size()){
    if(hoge[i]){
      sum++;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;
 
typedef int Weight;
//typedef
//------------------------------------------
 
typedef int Weight;
//typedef
//------------------------------------------

int main(){
    string key="keyence";
    string S;
    cin>>S;
    REP(i,SZ(S))FOR(j,i,SZ(S)){
        string tmp=S.substr(0,i)+S.substr(j);
        if(tmp==key){
            cout<<"YES"<<endl;return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

mod = 10**9+7

def power(a, n, mod):
    bi=str(format(n,"b")) #2進数
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

X = [0]*(k+1)

ans = 0
for g in reversed(range(1, k+1)):
    temp = power(k//g, n, mod)
    j = g
    while j <= k:
        temp -= X[j]
        j += g
    ans += temp*g
    X[g] = temp
ans %= mod
print(ans)


Measured memory_bytes: 74696
program abc29
 implicit none
 integer(8)::N,D,i,ia,c=0
 integer(8),allocatable::a(:),b(:)
 read(*,*)N,D
 allocate(a(N),b(N))
 do i=1,N
  read(*,*)a(i),b(i)
 end do
 do ia=1,N
  if(a(ia)**2+b(ia)**2<=D**2)then
   c=c+1
  end if
 end do
 print'(i0)',c
 deallocate(a,b)
end program abc29

Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
const int MAXN=300010;
int n,a[MAXN],c[3][MAXN],inv[3];
void modify (int k,int x,int v) {
	for (int i=x;i<=n;i+=(i&(-i))) {c[k][i]+=v;}
	return;
}
int query (int k,int x) {
	int res=0;
	for (int i=x;i;i-=(i&(-i))) {res+=c[k][i];}
	return res;
}
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if ((i&1)!=(a[i]&1)) {printf("No\n");return 0;}
		inv[i&1]+=query(i&1,n)-query(i&1,a[i]);
		inv[2]+=query(2,n)-query(2,a[i]);
		modify(i&1,a[i],1),modify(2,a[i],1);
	}
	if (inv[2]==3*(inv[0]+inv[1])) {printf("Yes\n");}
	else {printf("No\n");}
	return 0;
}

Measured memory_bytes: 4992
## ABC 085C
## C - Otoshidama

import sys
n, y = (int(_) for _ in input().split())

for i in range(0,n+1):
    for j in range(0,n+1-i):
        if(10000*i+5000*j+1000*(n-i-j) == y):
            print(i,j,n-i-j)
            sys.exit()
                    
print('-1 -1 -1')

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

using namespace std;

int dp[210][210];

template <typename T>
T gcd(T a, T b) {
  if (dp[a][b] != -1) return dp[a][b];
  return dp[a][b] = (b ? gcd(b, a % b) : a);
}

int main() {
  int K;
  cin >> K;
  memset(dp, -1, sizeof(dp));
  int64_t sum = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        int d = gcd(b, c);
        int e = gcd(a, d);
        sum += e;
      }
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

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

using namespace std;

const long long MOD = 1000000007;

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

	int n;
	string s;
	cin >> n >> s;

	rep(i, s.length()) {
		s[i] = 'A' + (s[i] - 'A' + n) % 26;
	}

	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<cstring>
using namespace std;
int a[100005],c; 
int main()
{int n,k;
 cin>>n>>k;
 for(int i=0;i<n;i++){
 cin>>a[i];}
 if(n!=k && k!=1){
 for(int i=0;i<n;i++) 
 if(i%(k-1)==0)
 {c++;
 }
 c--;
 if((n+c-1)%k==0){
 int hans1=(n+c-1)/k;
 cout<<hans1<<endl;
}
 else if((n+c-1)%k!=0){
 int hans1=(n+c)/k;
 int hans2=1;
 cout<<hans1+hans2<<endl;
}
}
 else if(n==k)
 {cout<<n/k<<endl;
 }
 system("pause");
 return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

typedef vector<int> vi;
typedef priority_queue<int> pqi0;
typedef priority_queue<int, vi, greater<int> > pqi1;

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

    pqi0 q1;
    pqi1 q2;
    long long sq1 = 0, sq2 = 0;
    long long bs = 0;
    for (int i = 0; i < q; i++) {
        int c;
        cin >> c;
        if (c == 1) {
            int a, b;
            cin >> a >> b;
            if (q1.empty() || a <= q1.top()) {
                q1.push(a);
                sq1 += a;
            } else {
                q2.push(a);
                sq2 += a;
            }
            bs += b;

            if (q1.size() > q2.size() + 1) {
                int t = q1.top();
                sq2 += t;
                sq1 -= t;
                q2.push(t);
                q1.pop();
            }
            if (q2.size() > q1.size()) {
                int t = q2.top();
                sq2 -= t;
                sq1 += t;
                q1.push(t);
                q2.pop();
            }
        } else {
            long long ans = bs;
            int x = q1.top();
            ans += 1ll * q1.size() * x - sq1;
            ans += sq2 - 1ll * q2.size() * x;
            cout << x << " " << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3452
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
  b_temp, c_temp = map(int,input().split())
  B.append(b_temp)
  C.append(c_temp)
  
sum = 0
n_dic = {}
  
for i in range(N):
  sum += A[i]
  if A[i] not in n_dic.keys():
    n_dic[A[i]] = 1
  else:
  	n_dic[A[i]] += 1
  
for i in range(Q):
  #print(n_dic)
  #print(B[i], C[i])
  if B[i] not in n_dic.keys():
    print(sum)
  else:
    #print(B[i] * n_dic[B[i]], C[i] * n_dic[B[i]])
    sum = sum - (B[i] * n_dic[B[i]]) + (C[i] * n_dic[B[i]])
    print(sum)
    if C[i] not in n_dic.keys():
      n_dic[C[i]] = n_dic[B[i]]
      n_dic[B[i]] = 0
    else:
      n_dic[C[i]] += n_dic[B[i]]
      n_dic[B[i]] = 0

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;


int main(){
    int n, m;
    int ans = 0;
    cin >> n >> m;
    vector<int> edge[n];
    vector<int> junretu(n-1);
    REP(i, n-1) {
        junretu[i] = i+1;
    }
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    do {
        int now = 0;
        bool seikou = true, seikou2 = false;
        REP(i, n-1) {
            seikou2 = false;
            REP(j, edge[now].size()) {
                if(edge[now][j] == junretu[i]) seikou2 = true;
            }
            if(!seikou2) {
                seikou = false;
                break;
            }
            now = junretu[i];
        }
        if(seikou) ans++;
    } while (next_permutation(junretu.begin(), junretu.end()));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
      int n;cin >> n;
      cout << 180 * (n-2) << endl;
      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);
		
		String r = sc.next();
		String g = sc.next();
		String b = sc.next();
		
		int n = Integer.parseInt(r+g+b);
		
		if(n%4==0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
		
	}

}


Measured memory_bytes: 22996
n=int(input())
best=[int(s) for s in input().split()]
for i in range(n-1):
  a,b,c=map(int,input().split())
  aa=max(best[1]+a,best[2]+a)
  bb=max(best[0]+b,best[2]+b)
  cc=max(best[0]+c,best[1]+c)
  best=[aa,bb,cc]
print(max(best))

Measured memory_bytes: 47832
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

void chmin(Int& a, Int b) { if (a > b) { a = b; } };

int main() {
	const Int INF = 1e18;
	Int H, N;
	cin >> H >> N;
	vector<Int> a(N), b(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
	}

	vector<Int> dp(H + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= H; ++j) {
			if (dp[j] == INF) { continue; }
			chmin(dp[min(H, j + a[i])], dp[j] + b[i]);
		}
	}
	cout << dp[H] << endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    ll cnt=0;
    ll flag=0;
    rep(i,N){
        ll d1,d2;
        cin>>d1>>d2;
        if(d1==d2){
            cnt++;
        }else{
            cnt=0;
        }

        if(cnt>=3){
            flag=1;
        }
    }
    if(flag==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
   


    return 0;
    

}

Measured memory_bytes: 3628
n, q = map(int, input().split())

tree = [i for i in range(n)]
def root(x):
    pre = []
    while x != tree[x]:
        pre.append(x)
        x = tree[x]
    for node in pre:
        tree[node] = x
    return x
def unite(x, y):
    X, Y = root(x), root(y)
    if X != Y:
        tree[X] = Y
def same(x, y):
    if root(x) == root(y):
        return print(1)
    else:
        return print(0)

for _ in range(q):
    c, x, y = map(int, input().split())
    if c == 0:
        unite(x, y)
    else:
        same(x, y)



Measured memory_bytes: 5980
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main()
{
long long int a[3],k;
scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
scanf("%lld",&k);

sort(a,a+3);

long long int y,sum=0;
y=pow(2,k);
sum=sum+a[1]+a[0];
sum=sum+a[2]*y;
printf("%lld",sum);

return 0;
}


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

int main(){
    int n,m,m_cou=0,n_cou=0;
    char token[100]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(strtok(token, " "));m=atoi(strtok(NULL, " "));
    n_cou=(n-1)*n/2;
    m_cou=(m-1)*m/2;
    printf("%d",n_cou+m_cou);
    return 0;
}



Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    if(a>0){
        cout << "Positive" << endl;
    }else if(b<0){
        if((b-a)%2==1){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;
        }
    }else{
        cout << "Zero" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int N;
int A[200010];

int main() {
	cin >> N;
	int ma = 0;
	int ma2 = 0;
	int index = -1;
	REP(i, N) {
		cin >> A[i];
		
	}
	REP(i, N) {
		if (ma <= A[i]) {
			ma = A[i];
			ma2 = ma;
			index = i;
		}
	}
	sort(A, A + N);

	REP(i, N) {
		if (i == index) {
			cout << A[N - 2] << endl;
		}
		else {
			cout << ma << endl;
		}
	}

}

Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    const int SIZE = 300010;
    int H, W, M, h[SIZE], w[SIZE], x[SIZE], y[SIZE];
	cin >> H >> W >> M;
    for (int i = 1; i <= H; ++i){
        x[i] = 0;
    }
    for (int i = 1; i <= W; ++i){
        y[i] = 0;
    }
    for (int i = 0; i < M; ++i){
        cin >> h[i] >> w[i];
        x[h[i]]++;
        y[w[i]]++;
    }

    int x_max = 0;
    for (int i = 1; i <= H; ++i){
        x_max = max(x_max, x[i]);
    }

    int x_sum = 0;
    for (int i = 1; i <= H; ++i){
        if (x[i] == x_max) x_sum++;
    }

    int y_max = 0;
    for (int i = 1; i <= W; ++i){
        y_max = max(y_max, y[i]);
    }

    int y_sum = 0;
    for (int i = 1; i <= W; ++i){
        if (y[i] == y_max) y_sum++;
    }

    int m_sum = 0;
    for (int i = 0; i < M; ++i){
        if (x[h[i]] == x_max && y[w[i]] == y_max) m_sum++;
    }

    if (m_sum == x_sum * y_sum){
        cout << x_max + y_max -1 << endl;
    } else {
        cout << x_max + y_max << endl;
    }
	return 0;
}

Measured memory_bytes: 8296
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> b(n - 1);
    in_arr(int, b, n - 1);
    int ans = 0;
    rep(i, n) {
        if(i == 0) {
            ans += b[0];
        } else if(i == n - 1) {
            ans += b[n - 2];
        } else {
            ans += min(b[i], b[i - 1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int h = sc.nextInt();
		int w = sc.nextInt();
		for (int i = 0;i < h;i++) {
			String s = sc.next();
			System.out.println(s);
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 11560
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		StringBuffer sb = new StringBuffer();
		
		int k = 0;
		int n = 0;
		int i = 0;
		int j = 0;
		
		int A[],B[],C[];
		
		n = Integer.parseInt(as.next());
		
		A = new int[n];
		B = new int[n];
		
		for(i=0;i<n;i++){
			
			A[i] = Integer.parseInt(as.next());
			if(k < A[i]){
				
				k = A[i];
				
			}
			
		}
		
		k++;                         //0???????????°?????°????????????
		
		C = new int[k+1];
		
		for(i=0;i<k;i++){
			
			C[i] = 0;
			
		}
		
		for(j=0;j<n;j++){
			
			//System.out.println(A[j]);
			C[A[j]]++;
			
		}
		
		for(i=0;i<k;i++){
			
			C[i+1] = C[i+1] + C[i];
			
		}
		
		for(j=n-1;j>=0;j--){
			
			//System.out.println(C[A[j]]);
			B[C[A[j]]-1] = A[j];
			C[A[j]]--;
			
		}
		
		for(i=0;i<n;i++){
			
			if(i != n-1){
				
				sb.append(String.valueOf(B[i])).append(" ");
				
			}
			else{
				
				sb.append(String.valueOf(B[i]));
				
			}
			
		}
		
		System.out.println(sb);

	}

}

Measured memory_bytes: 290508
n,m = map(int,raw_input().split())

arr = map(int,raw_input().split())

ans = 0
for i in range(1,n):
	if arr[i] + arr[i-1] > m:
		t = min(arr[i],arr[i] + arr[i-1]-m)
		arr[i] -= t
		ans += t

	if arr[i] + arr[i-1] > m:
		t = min(arr[i-1],arr[i-1]-m)
		arr[i-1] -= t
		ans += t

print ans

Measured memory_bytes: 11340
// Strategy
//
//  - the function Array.indexOf is very high speed.
//  - in the case of T.length=max, P.length=max and
//    "high correlation", the speed of Array.indexOf is decreasing.
//  - therefore, we prepare the process for "high correlation" in first.

//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .split(config.newline, 2);

T = line[0];
P = line[1];
line = null;
P2 = P + P;
for (cor = 0; cor < P.length && P2.indexOf(P, cor) === cor; cor++) ;
cor--;

if (cor < 10) normal_search();
else search_with_correlation_check();

function normal_search() {
  var res, idx, j;
  res = new Array(T.length);
  idx = 0;
  j = 0;
  while ((idx = T.indexOf(P, idx)|0) !== -1) {
    res[j] = idx;
    idx = (idx + 1)|0;
    j = (j + 1)|0;
  }

  res.length = j;
  if (res.length !== 0) console.log(res.join('\n'));
}

function search_with_correlation_check() {
  var res, idx, j, k;
  res = new Array(T.length);
  idx = 0;
  j = 0;
  while ((idx = T.indexOf(P, idx)|0) !== -1) {
    if (T.indexOf(P2, idx) === idx) {
      for (k = 0; k <= cor; k = (k+1)|0) {
        res[j] = idx;
        idx = (idx + 1)|0;
        j = (j + 1)|0;
      }
    } else {
      res[j] = idx;
      idx = (idx + 1)|0;
      j = (j + 1)|0;
    }
  }

  res.length = j;
  if (res.length !== 0) console.log(res.join('\n'));
}

Measured memory_bytes: 116952
s=[int(input()) for i in range(5)]
list=[]
a=0
b=0
for j in range(5):
  if s[j]%10!=0:
    list.append(s[j]%10)
    a+=1
if 0<a:
  list.sort()
  for k in range(5):
    if s[k]%10==0:
      b+=s[k]
    else:
      c=s[k]%10
      b+=s[k]+10-c
  b=b-10+list[0]
  print(b)
else:
  for l in range(5):
    b+=s[l]
  print(b)

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: 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...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

int main(){
	string str; cin >> str;
	if(str == "ABC") cout << "ARC\n";
	else cout << "ABC\n";
}

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

using namespace std;

// int
// main(int argc, char* argv[]) {
//   int n, i, count;
//   long long binAnd, _a;
//
//   cin >> n;
//
//   binAnd = 1000000000;
//   for(i=0; i<n; i++) {
//     cin >> _a;
//     binAnd = binAnd | _a;
//   }
//   count = 0;
//   while (true) {
//     if (binAnd % 2 == 0) {
//       count++;
//       binAnd = binAnd / 2;
//     } else {
//       cout << count << endl;
//       return 0;
//     }
//   }
//   cout << count << endl;
//
//   return 0;
// }
int
main(void) {
  int n, i, count;
  bool divivable;

  cin >> n;
  int A[n];

  for(i=0; i<n; i++) {
    cin >> A[i];
  }
  count = 0;
  while (true) {
    divivable = true;
    for(i=0; i<n; i++) {
      if (A[i] % 2 == 0) {
        A[i] /= 2;
      } else {
        divivable = false;
        break;
      }
    }
    if (divivable) {
      count++;
    } else {
      cout << count << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int hcell,wcell,hpaint,wpaint,nblack,nwhite;
  //順にマス行、マス列、塗る行、塗る列、塗られたマス、白いマス
  scanf("%d %d",&hcell,&wcell);
  scanf("%d %d",&hpaint,&wpaint);
  nblack = (wcell*hpaint) + (hcell*wpaint) - (hpaint * wpaint);
  nwhite = (hcell*wcell) - nblack;
  printf("%d\n",nwhite);
  return 0;
}

Measured memory_bytes: 128
#! python3
# officeHouse.py - 4棟あるオフィスの入居者情報を管理します

# 入居棟を配列でモデル化する
four_buildings = [[[0]*10 for i in range(3)] for j in range(4)] # 1F 10 部屋、4棟

# 棟の間の仕切りを作る
partition = '#' * 20

# 入力される入居者情報の数を受け取る
n = int(input())

# 入居者情報の数分だけ、ループを回し、モデルに反映する
for info in range(n):
  regident_info = [int(i) for i in input().split()]
  b = regident_info[0] - 1 # ビル python の配列は 0 スタートのため
  f = regident_info[1] - 1 # 階
  r = regident_info[2] - 1 # 部屋
  v = regident_info[3] # 人数
  four_buildings[b][f][r] += v

# ここから出力
for i, building in enumerate(four_buildings):
  for floor in building:
    str_floor = list(map(str, floor))
    print(' ' + ' '.join(str_floor))
  if i != 3:
    print(partition)



Measured memory_bytes: 5604
#include<stdio.h>

int main(void)

{

   int a,b,d,r;

   double f;

   scanf("%d %d",&a,&b);

   d=a/b;

   r=a%b;

   f=(double)a/(double)b;

   printf("%d %d %lf\n",d,r,f);

   return 0;

}
 

Measured memory_bytes: 636
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N, K = readint()
  p = readint()
  p= sort!(p)

  s = 0
  for i in 1:K
    s += p[i]
  end
  println(s)
  
  
end

main()

Measured memory_bytes: 164304
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      if(n >= k){
      	System.out.println(x*k+(n-k)*y);
      }
      else System.out.println(x*n);
    }
}


Measured memory_bytes: 22612
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
aa = 0
b = 0
for i in range(n):
    aa += a[i] ** 2  
    b += a[i]
    #aa %= mod
    #b %= mod
print((b ** 2 - aa)//2%mod)


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

int main(){
  int n, k, q; cin >> n >> k >> q;
  vector<int> score(100000, k - q);
  for (int i = 0; i < q; i++){
    int a; cin >> a; a--;
    score.at(a)++;
  }
  for (int i = 0; i < n; i++){
    if (score.at(i) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 1024
N, A, B = gets.chomp.split(' ').map(&:to_i)

def sum(n)
  sum = 0
  while(n > 0)
    sum += n % 10
    n /= 10
  end
  sum
end

sum = 0
(1..N).each do |n|
  s = sum(n)
  sum += n if A <= s && s <= B
end

puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()


ll func1(ll x, ll val, vector <ll> &vec){
   while(x < 1e6+1){
         vec[x] = max(vec[x], val);
         x += (x&-x);
   }
}

ll func2(ll x, vector <ll> vec){
   ll ans = 0;
   while(x > 0){
         ans = max(ans, vec[x]);
         x -= (x&-x);
   }
   return ans;
}

ll arr[123];

int main()
{
   string s;
   cin >> s;
   for(int i = 0; i < s.size(); i++){
        arr[i] = s[i] - '0';
        //cout << arr[i] << " ";
   }
   //cout << endl;
   int ans1 = -1;
   for(int i = 0; i < 15; i++){
       int ans = arr[0];
       for(int j = 1; j < 4; j++){
           if(1<<j & i) ans += arr[j];
           else ans -= arr[j];
       }
       //cout << i <<  " " << ans << endl;
       if(ans == 7){
          ans1 = i; break;
       }
   }

   cout << arr[0];
   for(int i = 1; i < 4; i++){
       if(ans1 & 1<<i) cout << "+";
       else cout << "-";
       cout << arr[i];
   }
   cout << "=7";
}


Measured memory_bytes: 256
n=int(input())
arr=[int(i) for i in input().split()]
ans=[0]*(n+1)
ans[1]=0
ans[2]=abs(arr[1]-arr[0])
for i in range(3,n+1):
    ans[i]=min(ans[i-1]+abs(arr[i-2]-arr[i-1]),ans[i-2]+abs(arr[i-3]-arr[i-1]))
print(ans[n])


Measured memory_bytes: 13928
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//Hey u r far away to know this
#include <bits/stdc++.h>
using namespace std;
#define     ff                  first
#define     pb                  push_back
#define     ss                  second
#define     ll                  long long
#define     MAX                 5000
#define     mpi                 map<int, int>
#define     mpll                map<ll, ll>
#define     pll                 pair<ll, ll>
#define     plld                pair<ll, double>
#define     SKILLER             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     vi                  std::vector<int>
#define     vll                 std::vector<ll>
#define     vs                  std::vector<string>
#define     vvi                 std::vector<std::vector<int>>
#define     vvll                std::vector<std::vector<ll>>
#define     all(v)              v.begin(), v.end()
#define     allr(v)              v.rbegin(), v.rend()
#define     loop(i, a, b)     for(int i = a; i < b; i++)
#define       debug(x)         cout << x <<" " <<"\n";
#define       debug1(x, y)     cout << x << " " << y  << "\n";
#define       debug2(x, y, z)     cout << x << " " << y << " " << z<<"\n";
#define       int             ll
const   int N = 1e6+5, Mod = 1e9 + 7;
int32_t main(){
        SKILLER;
       
        int n, k; cin >> n >> k;
        vector<int> v(n);
        for(int i = 0; i < n; i++)
            cin >> v[i];
        int sum = 0;
        for(int i = k - 1; i < n - 1; i++){
            if(v[i - k + 1] < v[i + 1])
                cout << "Yes\n";
            else cout << "No\n";
        }
        return 0;
}

Measured memory_bytes: 4784
#include <stdio.h>
int main(){
	char ans[1000][20];
	int n,i,to,from,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&from,&to);
		if(from<to){
				for(j=from;j<to;j++){
					printf("%d ",j);
				}
				printf("%d\n",to);
		}else if(to==5){
			for(j=from;j<=9;j++){
				printf("%d ",j);
			}
			puts("5");
		}else if(from>to){
			if(from>=6&&from<=9&&to<=5){
				for(j=from;j<=9;j++){
					printf("%d ",j);
				}
				for(j=5;j>to;j--){
					printf("%d ",j);
				}
				printf("%d\n",to);
			}else if(from>=6&&from<=9&&to>=6&&from<=9){
				for(j=from;j<=9;j++){
					printf("%d ",j);
				}
				printf("5 4 3 2 1 0 1 2 3 4 5 ");
				for(j=6;j<to;j++){
					printf("%d ",j);
				}
				printf("%d\n",to);
			}else{
				for(j=from;j>to;j--){
				printf("%d ",j);
				}
				printf("%d\n",to);
			}
		}
	}
	
	return 0;
}

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

int main(void) {
	char s[101] = { 0 };
	char ans[5] = { 0 };
	int len, x, i = 1;

	scanf("%s", &s);
	len = strlen(s);
	x = len - 2;

	ans[0] = s[0];
	if (x >= 10) {
		ans[i] = '0' + (x / 10);
		x = x - (x / 10) * 10;
		i++;
	}
	if (x < 10) {
		ans[i] = '0' + x;
		i++;
	}
	ans[i] = s[len - 1];

	printf("%s\n",ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main()
{
    int X,Y,Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}

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

using namespace std;

class pos{
public:
  int x;
  int y;
};

double calsqrt(pos src, pos dst){
  double ret = sqrt(pow((src.x - dst.x), 2) + pow((src.y - dst.y), 2));
  return ret;
}

int main(){
	
  int n;
  cin >> n;
  
  vector<pos> p(n);
  
  for(int i=0; i<n; i++){
  	cin >> p[i].x >> p[i].y;
  }
  
  vector<int> id(n);
  for(int i=0; i<n; i++){
  	id[i] = i;
  }
 
  double sum = 0;
  
  do{
  	for(int i=0; i<n-1; i++) { sum += calsqrt(p[id[i]], p[id[i+1]]); }
  } while(next_permutation(id.begin(), id.end()));
  
  int fact = 1;
  for(int i=2; i<=n; i++){
  	fact *= i;
  }
  double ans = sum / fact;
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int i, j, k, M, N, a[10010], b[10010];
    scanf("%d", &N);
    M = N*(N-1)/2 - N/2;
    k = 0;
    for (i=1;i<=N;i++) for (j=i+1;j<=N;j++) {
        a[k] = i; b[k++] = j;
    }
    printf("%d\n", M);
    for (i=0;i<k;i++) {
        if ((N%2 && a[i]+b[i] == N) || (!(N%2) && a[i]+b[i] == N+1)) continue;
        printf("%d %d\n", a[i], b[i]);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define d first
#define t second
using namespace std;
typedef long l;
l N,K,i,n,p,s;
vector<pair<l,l> >v;
bool u[1<<17];
priority_queue<l,vector<l>,greater<l>>q;
main(){
  cin>>N>>K;
  v.resize(N);
  for(i=0;i<N;i++)cin>>v[i].t>>v[i].d;
  sort(v.rbegin(),v.rend());
  for(i=0;i<K;i++){
    s+=v[i].d;
    if(u[v[i].t])q.push(v[i].d);
    else u[v[i].t]=true,n++;
  }
  p=s+n*n;
  for(i=K;i<N;i++){
    if(!u[v[i].t]){
      if(!q.size())break;
      u[v[i].t]=true;
      s+=v[i].d;
      s-=q.top();q.pop();
      p=max(p,s+(++n)*n);
    }
  }
  cout<<p<<endl;
}


Measured memory_bytes: 2556
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a, b, c;

int main() {
	while(~scanf("%d %d %d", &a, &b, &c)) {
		if(a + b >= c) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

int main(void) {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
static const int mod = 1e9+7;
ll mpow(ll a, ll n){
    ll res = 1;
    while (n > 0){
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll x; scll(x);
    bool check = false;
    rep(i, 1, 120){
        rep(j, 0, 119){
            if ((mpow(i, 5)-mpow(j, 5)+mod)%mod == x){
                cout << i << " " << j << endl;
                check = true;
            }else if ((mpow(i, 5)+mpow(j, 5))%mod == x){
                cout << i << " " << -j << endl;
                check = true;
            }
            if (check) break;
        }
        if (check) break;
    }
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;

struct edge {
    i64 from, to, cost;
    edge(i64 from, i64 to) : from(from), to(to), cost(1) {}
    edge(i64 from, i64 to, i64 cost) : from(from), to(to), cost(cost) {}
};
using Graph = vector<vector<edge>>;

constexpr i64 SINF = std::numeric_limits<i64>::max() / 10;
const i64 MOD = 1000003;
const i64 dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
//const i64 dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//const i64 dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//const i64 dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    i64 a, b, c;
    cin >> a >> b >> c;
    cout << min({a + b, b + c, c + a}) << endl;
 }

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

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

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

int main(){
    int N;
    cin >> N;
    ll ans = 1LL;
    for(int i=0;i<N;i++){
        ll T;
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n,t;
    cin >> n >> t;
    ll a[n];
    vector<ll> b;
    ll memo1=0;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        if(a[memo1]<a[i]){
            b.push_back(a[i]-a[memo1]);
        }
        else if(a[memo1]>a[i]){
            memo1=i;
        }
    }
    sort(b.begin(),b.end(),greater<ll>());
    b.push_back(0);
    for(ll i=0;i<b.size();i++){
        if(b[i]!=b[0]){
            ll count=i;
            cout << count << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long ans = 0;
		for(int i = 1; i < n; i++) {
			ans += i;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
import os
import sys
from io import BytesIO, IOBase

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")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import bisect

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,k = Ri()

a = Ri()
b = Ri()

arr1 = [0]*n
arr2 = [0]*m

arr1[0] = a[0]
arr2[0] = b[0]

for i in range(1,n):
    arr1[i] = arr1[i-1]+a[i]

for i in range(1,m):
    arr2[i] = arr2[i-1]+b[i]

ans = 0
for i in range(n+1):
    # if k -arr1[i-1] > 
    if i == 0:
        ind = bisect.bisect_right(arr2, k)
        ind-=1
        ans=  max(ans, i+ind+1)
        # print(ans)
    else:
        if k -arr1[i-1] >= 0:
            ind = bisect.bisect_right(arr2, k-arr1[i-1])
            # print(ind)
            ind-=1
            ans=  max(ans, i+ind+1)
    # print(ans)

print(ans)


Measured memory_bytes: 123900
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

#define MOD 998244353

int main(){
  ll N;
  cin >> N;
  ll A[N];
  rep(i, N) cin >> A[i];

  ll sumA = 0;
  rep(i, N) sumA += A[i];
  ll dp[2][sumA + 1];
  ll dphalf[2][sumA + 1];
  rep(i, sumA+1){
    dp[0][i] = 0;
    dp[1][i] = 0;
    dphalf[0][i] = 0;
    dphalf[0][i] = 0;
  }
  dp[0][0] = 1;
  dphalf[0][0] = 1;
  ll all = 1;
  rep(i, N) all = all * 3 % MOD;

  rep(n, N){
    rep(i, sumA + 1){
      if(i >= A[n]){
        dp[(n+1)%2][i] = (dp[n%2][i-A[n]] + dp[n%2][i] * 2) % MOD;
        dphalf[(n+1)%2][i] = (dphalf[n%2][i-A[n]] + dphalf[n%2][i]) % MOD;
      }
      else{
        dp[(n+1)%2][i] = dp[n%2][i] * 2 % MOD;
        dphalf[(n+1)%2][i] = dphalf[n%2][i];
      }
    }
  }
  if(sumA % 2 == 0) dp[N%2][sumA / 2] -= dphalf[N%2][sumA / 2];
  ll ans = all;
  repi(i, (sumA+1)/2, sumA+1) ans = (ans - dp[N%2][i] * 3) % MOD;
  cout << (ans + MOD) % MOD << endl;
  return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    int col[9];
    REP(i, 9) col[i] = 0;
    int x;
    REP(i, N){
        cin >> x;
        if((x/400)>7){
            col[8]++;
        }else{
            col[x/400]++;
        }
    }
    int res = 0;
    REP(i, 8){
        if(col[i]>0) res++;
    }
    if(res==0){
        cout << 1 << " " << col[8] << endl;
    }else{
        cout << res << " " << res+col[8] << endl;
    }
    return 0;
}

Measured memory_bytes: 256