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

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

int main() {
    int a,b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
    return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    ll N;
    cin >> N;
    string Si;

    set<string> st;
    rep(i,N){
        cin >> Si;
        st.insert(Si);
    }
    cout << st.size();
}

Measured memory_bytes: 19232
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    char[] S = scn.nextLine().toCharArray();
    char[] T = scn.nextLine().toCharArray();
    int size = S.length;

    HashMap<Character, Character> map1 = new HashMap<>();
    HashMap<Character, Character> map2 = new HashMap<>();

    String ans = "Yes";
    for (int i = 0; i < size; i++) {
      if (!map1.containsKey(S[i])) {
        map1.put(S[i], T[i]);

      } else if (map1.get(S[i]) != T[i]) {
        ans = "No";
        break;
      }

      if (!map2.containsKey(T[i])) {
        map2.put(T[i], S[i]);
      } else if (map2.get(T[i]) != S[i]) {
        ans = "No";
        break;
      }
    }

    System.out.println(ans);
  }

}


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

int n, a[200010];
int cnt[1000010], ans;
inline void solve(int T) {
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    sort(a + 1, a + n + 1);
    rep(i, 1, n) {
        if(!cnt[a[i]]) {
            if(a[i] != a[i + 1]) ans++;
            while(a[i] == a[i + 1]) i++;
            for(int j = 2; j * a[i] <= 1000000; j++) cnt[j * a[i]] = 1;
        }
    }
    cout << ans << endl;
}   
int main()
{
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out2.txt", "w", stdout);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
}

Measured memory_bytes: 8288
#include <cstdio>
#include <cstring>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const double EPS = 1e-9;

#define MAXN 150004
int N;
VI adj[MAXN];

int par[MAXN];
int nchildren[MAXN];
double E_down[MAXN];
double sum_children_E[MAXN];
void dfs1(int u) {
   nchildren[u] = 0;
   sum_children_E[u] = 0.0;
   for (int v : adj[u]) {
      if (v != par[u]) {
         par[v] = u;
         nchildren[u]++;
         dfs1(v);
         sum_children_E[u] += E_down[v];
      }
   }
   if (nchildren[u] == 0)
      E_down[u] = 0.0;
   else
      E_down[u] = 1 + sum_children_E[u] / nchildren[u];
}

double E_up[MAXN];
double E[MAXN];
void dfs2(int u) {
   int p = par[u];
   if (p == -1) {
      E_up[u] = 0.0;
      E[u] = E_down[u];
   }
   else {
      if (E_up[p] > EPS)
         E_up[u] = 1 + (E_up[p] + (sum_children_E[p] - E_down[u]) + nchildren[p] - 1) / nchildren[p];
      else if (nchildren[p] > 1)
         E_up[u] = 1 + ((sum_children_E[p] - E_down[u]) + nchildren[p] - 1) / (nchildren[p]-1);
      else
         E_up[u] = 1;
      E[u] = E_up[u] / (nchildren[u]+1) + E_down[u] * nchildren[u] * 1.0 / (nchildren[u]+1);
   }
   for (int v : adj[u]) {
      if (v != p)
         dfs2(v);
   }
}

int main(int argc, char* argv[]) {
   scanf("%d", &N);
   REP(j, N-1) {
      int u, v;
      scanf("%d %d", &u, &v);
      --u, --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
   }

   par[0] = -1;
   dfs1(0);

   dfs2(0);

   REP(u, N) {
   // fprintf(stderr, "%d: Edown=%.05f  Eup=%.05f  E=%.05f\n", u+1, E_down[u], E_up[u], E[u]);
      printf("%.010f\n", E[u]);
   }

   return 0;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,K; cin >> N >> K;
    cout << (N-3+K)/(K-1) << endl; 

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: usize, b: usize) -> usize {
    if b > a {
        return gcd(b, a);
    }
    if a % b == 0 {
        return b;
    }
    gcd(b, a % b)
}

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }
    let mut div_count = 0;
    let mut t = a[0];
    while t % 2 == 0 {
        div_count += 1;
        t /= 2;
    }
    for i in 1..n {
        let mut ai = a[i];
        let mut div_count2 = 0;
        while ai % 2 == 0 {
            div_count2 += 1;
            ai /= 2;
        }
        if div_count != div_count2 {
            println!("0");
            return;
        }
    }
    let mut lcm = 1;
    for i in 0..n {
        let ai = a[i] / 2;
        lcm = lcm * ai / gcd(lcm, ai);
        if lcm > m {
            println!("0");
            return;
        }
    }
    println!("{}", (m - lcm) / (lcm * 2) + 1);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Discount Fare
            string line = Console.ReadLine();
            var array = line.Split(' ');
            
            int x = int.Parse(array[0]);
            int y = int.Parse(array[1]);
            
            Console.WriteLine(x + y / 2);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool Check(const vector<int> &index, const vector<vector<pair<int, int>>> &a)
{
    for (auto i : index)
    {
        for (const auto &j : a[i])
        {
            if (j.second == 1)
            {
                if (std::find(index.begin(), index.end(), j.first - 1) == index.end())
                {
                    return false;
                }
            }
            else
            {
                if (std::find(index.begin(), index.end(), j.first - 1) != index.end())
                {
                    return false;
                }
            }
        }
    }

    return true;
}

int main()
{
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> a(n);

    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        for (int j = 0; j < t; j++)
        {
            int x, y;
            cin >> x >> y;
            a[i].emplace_back(x, y);
        }
    }

    int max = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        vector<int> index;
        for (int j = 0; j < n; j++)
        {
            if (i & (1 << j))
            {
                index.push_back(j);
            }
        }
        if (Check(index, a))
        {
            max = max < index.size() ? index.size() : max;
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

map<ll, ll> mp;
ll a[200010];

int main(){
    int n;
    cin >> n;
    rep(i, n) {
        ll b;
        cin >> b;
        a[i] = b;
        mp[b]++;
    }
    ll res = 0;
    for(auto v : mp){
        ll num = v.second;
        res += num * (num-1) / 2;
    }

    rep(i, n){
        ll num = mp[a[i]];
        ll tmp = res;
        tmp -= num * (num-1) / 2;
        tmp += (num-1) * (num-2) / 2;
        cout << tmp << endl;
    }


    return 0;
}


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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;
constexpr int MOD = 998244353;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

constexpr int MAX_N = 100005;

int n, m, d[MAX_N];
vector<pii> G[MAX_N];
priority_queue<pii, vector<pii>, greater<>> q;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);
    cout << fixed;

    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int l, r, c;
        cin >> l >> r >> c;
        G[l].emplace_back(c, r);
    }
    for (int i = 2; i <= n; i++)
    {
        G[i].emplace_back(0, i - 1);
    }

    fill(d, d+MAX_N, INF);

    q.emplace(0, 1);
    while (!q.empty())
    {
        const auto p = q.top();
        q.pop();
        if (d[p.second] < p.first) continue;

        for (const auto e : G[p.second])
        {
            const int c = e.first, to = e.second;
            if (d[to] <= p.first + c) continue;

            d[to] = p.first + c;
            q.emplace(p.first + c, to);
        }
    }

    if (INF <= d[n]) {
        cout << -1 << endl;
    } else {
        cout << d[n] << endl;
    }
}


Measured memory_bytes: 9464
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(n) scanf("%s",n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof a)
#define mem(a,b,n) memset(a,b,n*sizeof(int))
#define uint unsigned int

const  int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int t,n,m;

int main()
{
	ll a,b;
	cin>>a>>b;
	if((a+b)%2==0)
		cout<<(a+b)/2<<endl;
	else
		puts("IMPOSSIBLE");
}



Measured memory_bytes: 256
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B = MI()
S = LS2()

for i in range(A+B+1):
    if i == A:
        if S[i] != '-':
            print('No')
            break
    else:
        if S[i] == '-':
            print('No')
            break
else:
    print('Yes')


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n)  ; i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , m ;
  cin >> n >> m ;
  vector<int> v(n) ;
  vector<int> ans(n) ;
  
  rep(i,n){
    int h ; 
    cin >> h ;
    v.at(i) = h ;
    ans.at(i) = 0;
  }
  
  rep(i,m){
    int a , b ;
    cin >> a >> b ; 
    a--; 
    b--;
    if(v.at(a) >= v.at(b)) {
      ans.at(b) --;
    }
    if(v.at(a) <= v.at(b)){
      ans.at(a) --;
    }
  }
  
  int ANS = 0;
  rep(i,n){
    if(ans.at(i) == 0) ANS ++ ;
  }
  
  cout <<ANS; 
    
    
  
  
}


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

int main(){
    //input
    string S;
    cin >> S;

    //calc
    long long ans=0;
    long long sub;
    long long i,bit;
    for(bit=0; bit<(1<<(S.length()-1)); bit++){
        sub=S[0]-'0';
        for(i=0; i<(S.length()-1);i++){
            if(bit&(1<<i)){
                ans += sub;
                sub = S[i+1]-'0';
            }else{
                sub = 10*sub + (S[i+1]-'0');
            }
        }
        ans += sub;
    }

    //answer
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
from collections import deque

def resolve():
    K = int(input())
    q = deque(range(1, 10))

    for i in range(K):
        x = q.popleft()
        r = x%10
        y = 10*x+r
        if r != 0:
            q.append(y-1)
        q.append(y)
        if r != 9:
            q.append(y+1)
    return print(x)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 11884
fun main(args: Array<String>) = shojin06e()

fun shojin06e() {
    val n = readLine()!!.toLong()

    if (n == 1L) return println(0)

    var answer = 0L

    for (i in 1..Math.sqrt(n.toDouble()).toLong()) {
        val m = (n - i) / i
        if (n / m == n % m) answer += m
    }

    println(answer)
}


Measured memory_bytes: 31732
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(void){
    int p[300] = {3};
    int cnt = 1, i, n = 5;
    
    while(cnt < 300){
        for(i = 0; i < cnt; i++){
            if(n % p[i] == 0){
                goto next;
            }
        }
        p[cnt] = n;
        cnt++;
        
        next: 
        n += 2;
    }
    
    cin >> n;
    
    cnt = 1;
    i = 0;
    while(cnt <= n){
        if(p[i] % 10 == 3){
            cout << p[i];
            if(cnt != n){
                cout << ' ';
            }
            cnt++;
        }
        i++;
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

int main()
{
    int res = 0;
    for (int i = 0; i < 4; i++) {
        char tmp;
        cin >> tmp;
        res += (tmp == '+') ? 1 : -1;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<ll> a(n);
	for( auto &k : a ) cin >> k;
	ll sum = 0;
	for( auto k : a ) sum ^= k;
	for( auto k : a ) cout << (sum ^ k) << endl;
}

Measured memory_bytes: 4660
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,M,C; cin>>N>>M>>C;
    vint b(M);
    REP(i,M) cin>>b[i];
    int ans=0;
    while(N--){
        vint a(M);
        REP(i,M) cin>>a[i];
        int sum=C;
        REP(i,M) sum+=a[i]*b[i];
        if(sum>0) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int n, k, q;
  cin >> n >> k >> q;
  vector<ll> a;
  rep(i, n){
    ll x;
    cin >> x;
    a.pb(x);
  }
  if(q == 1){
    cout << 0 << endl;
    return 0;
  }
  a.pb(-1);
  ll res = linf;
  rep(i, n){
    // max: a[i]
    vector<ll> cand;
    vector<ll> vtmp;
    rep(j, n + 1){
      if(a[j] < a[i]){
        if(vtmp.size() == 0)continue;
        sort(vtmp.begin(), vtmp.end());
        rep(m, int(vtmp.size()) - k + 1){
          cand.pb(vtmp[m]);
        }
        vtmp.clear();
      }else{
        vtmp.pb(a[j]);
      }
    }
    if(cand.size() < q)continue;
    sort(cand.begin(), cand.end());
    res = min(res, cand[q-1] - cand[0]);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define LAST(i,n) if(i==n-1)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    string S; cin >> S;

    lint w_count[N];
    lint e_count[N];

    REP(i, N) {
      if(i == 0) {
        w_count[0] = (S[0] == 'W' ? 1 : 0);
        e_count[N-1] = (S[N-1] == 'E' ? 1 : 0);
      }
      else {
        w_count[i] = w_count[i-1] + (S[i] == 'W' ? 1 : 0);
        e_count[N-1-i] = e_count[N-i] + (S[N-1-i] == 'E' ? 1 : 0);
      }
    }

    lint res = N;

    FOR(i, 1, N-1) {
      res = min(res, w_count[i-1] + e_count[i+1]);
    }
    res = min(res, e_count[1]);
    res = min(res, w_count[N-1]);
              
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 5396
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
 
int main(){
    double xa, ya, ra, xb, yb, rb;
    double d;
    int n, i;
 
    scanf("%d", &n);
    for( i=0; i<n; i++ ){
        scanf("%lf %lf %lf %lf %lf %lf",
                &xa, &ya, &ra, &xb, &yb, &rb);
        d = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
        if( ra+rb < d )
            printf("0\n");
        else if( fabs(ra-rb) <= d )
            printf("1\n");
        else if( ra-rb > d )
            printf("2\n");
        else
            printf("-2\n");
    }
 
    return 0;
}

Measured memory_bytes: 620
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}


void solv() {
	ll n, q;
	cin >> n >> q;
	queue<pair<string, ll>> qu;
	for (size_t i = 0; i < n; i++)
	{
		string s;
		int v;
		cin >> s >> v;
		qu.push(make_pair(s, v));
	}

	ll sum = 0;
	while (!qu.empty())
	{
		pair<string, ll> p = qu.front();
		qu.pop();
		sum += min(q, p.second);
		if (p.second <= q) {
			
			cout << p.first << " " << sum << endl;
			continue;
		}

		p.second -= q;
		qu.push(p);
	}
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN = 1e5 + 5;
LL x[MAXN], w[MAXN], ans[MAXN];
int main(){
	LL n, l, t, i, j = 1;
	scanf("%lld %lld %lld", &n, &l, &t);
	for(i = 1 ; i <= n ; ++i){
		scanf("%lld %lld", &x[i], &w[i]);
		ans[i] = x[i] + (w[i] == 1 ? t : -t);
		ans[i] = (ans[i] % l + l) % l;
	}
	for(i = 1 ; i <= n ; ++i){
		LL r = x[i] + (w[i] == 1 ? t : -t);
		j +=  r / l;
		r %= l;
		if(r < 0) --j;
	}
	sort(ans + 1, ans + 1 + n);
	j = (j % n + n) % n;
	if(j == 0) j = n;
	for(i = j ; i <= n ; ++i)
		printf("%lld\n", ans[i]);
	for(i = 1 ; i < j ; ++i)
		printf("%lld\n", ans[i]);
	return 0;
}

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

void solve()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i * i <= n; i++)
    {
        ans = i * i;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

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

#define endl '\n'

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

    char a, b;
    cin >> a >> b;
    if(a == b)
        cout << "=";
    else if(a < b)
        cout << "<";
    else
        cout << ">";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n=0,d,x,y,ans=0;
	scanf("%lld%lld",&n,&d);
	d*=d;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x,&y);
		ans+=(x*x+y*y<=d);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3828
### constant

MX = MY = 8
ITVL = 4
LX = MX * ITVL
LY = MY * ITVL

SLX = 3
SLY = 1
SDX = SDY = 1

### main

loop do
  n = gets.to_i
  break if n < 0

  xms = (MY + 1).times.map{MX.times.map{false}}
  yms = (MX + 1).times.map{MY.times.map{false}}

  n.times do
    di, xi, yi = gets.strip.split
    if di == 'x'
      xms[yi.to_i][xi.to_i] = true
    else
      yms[xi.to_i][yi.to_i] = true
    end
  end
  #p xms
  #p yms
  
  lx = SLX
  ly = SLY
  dx = SDX
  dy = SDY

  loop do
    lx += dx
    ly += dy

    break if lx == SLX && ly == SLY && dx == SDX && dy == SDY
    
    mx = lx / ITVL
    my = ly / ITVL

    reflect = false
    if ly % ITVL == 0 && xms[my][mx]
      dy = -dy
      reflect = true
    elsif lx % ITVL == 0 && yms[mx][my]
      dx = -dx
      reflect = true
    end

    break if ! reflect && (lx == 0 || lx == LX || ly == 0 || ly == LY)
  end

  puts [lx * 100 / ITVL, ly * 100 / ITVL].join(' ')
end

Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
#include<algorithm>
#define inf 1 << 21
#define MAX 100
using namespace std;

int m[MAX + 1][MAX + 1], p[MAX + 1],n;

void MCM(){
    
    for(int i = 1; i <= n; i++) m[i][i] = 0;
    
    for(int l = 2; l <= n; l++){
        for(int i = 1; i <= n - l + 1; i++){
            int j = i + l - 1;
            m[i][j] = inf;
            for(int k = i; k <= j-1; k++){
                m[i][j] = min(m[i][j],m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    printf("%d\n",m[1][n]);
}

int main(){
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d %d",&p[i-1],&p[i]);
    MCM();
    return 0;
}



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

ll MOD = 998244353;
long long fact[402020], frev[402020];

long long modpow(long long a, long long p = MOD - 2) {
	if (p == 0) return 1;
	long long tmp = modpow(a, p / 2);
	tmp = tmp * tmp % MOD;
	if (p % 2 == 1) tmp = tmp * a % MOD;
	return tmp;
}

long long C(int p, int q) {
	if (q < 0 || p < q) return 0;
	return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}


int main() {
	fact[0] = frev[0] = 1;
	for (int i = 1; i <= 400000; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		frev[i] = modpow(fact[i]);
	}

	ll N, A, B, K;
	cin >> N >> A >> B >> K;

	ll ans = 0;
	for(ll i=0;i<=N;i++) {
		ll rest = K - i * B;
		if(rest % A == 0) {
			ll a = rest / A;
			ll b = i;
			ans = (ans + (C(N, a) * C(N, b) % MOD)) % MOD;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6656
#include <stdio.h>

int main(){
  int N;
  long long int T,A[200002];
  scanf("%d",&N);
  A[0]=0LL;
  for(int i=1;i<=N;i++){
    scanf("%lld",&T);
    A[i]=A[i-1]+T;
  }
  
  long long int min=A[N]-A[1]*2LL;
  if(min<0LL) min*=-1LL;
  for(int i=2;i<N;i++){
    long long int Q=A[N]-A[i]*2LL;
    if(Q<0LL) Q*=-1LL;
    if(Q<min) min=Q;
  }
  printf("%lld\n",min);
  return 0;
}

Measured memory_bytes: 3300
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	const int MOD = 2019;
	int n=s.size();
	std::reverse(all(s));
	std::vector<int> dp(n+1,0);
	int xx=1;
	rep(i,n) {
		xx=(xx*10)%MOD;
		dp[i+1]=(dp[i]+(int)(s[i]-'0')*xx)%MOD;
	}
	std::map<int,int> map;
	rep(i,n+1) {
		map[dp[i]]++;
	}
	debug(dp);
	int count=0;
	for(auto x:map) {
		count+=x.second*(x.second-1)/2;
	}
	print(count);
	return 0;
}


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

#define vi vector<int>
#define vvi vector<vi>

const int INF = 1e9 + 5;

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

    int a,b,h,m;
    
    cin >> a >> b >> h >> m;
    double ang1 = h*5*6;
    ang1 += ((double)m/60)*5*6;
    // cout << fixed << ang1 << "\n";

    double angle = ang1 - m*6;
    // cout << fixed << ang1 << "\n";
    if(angle > 180){
        angle = 360 - angle;
    }
    // cout << fixed << angle << "\n";
    if(angle == 90){
        double ans = sqrt(a*a + b*b);
        cout.precision(20);
        cout <<fixed <<  ans;
    }else{
       
        double radians = (angle*M_PI/180);
        double c = pow(a,2)+ pow(b,2) - (2*a*b*cos(radians));
        c = sqrt(c);

        cout.precision(20);
        cout <<fixed <<  c;

    }


    return 0;
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;




int32_t main()
{








    int a,b;
    cin >> a >> b;

    cout << a*b;



    return 0;
}


Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;


    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = in.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        long ans = 0;
        // i - j = ai + aj  ai - i = -aj - j
        for (int i = 1; i <= n; i++) {
            int v = a[i] - i;
            ans += map.getOrDefault(v, 0);
            v = -a[i] - i;
            map.put(v, map.getOrDefault(v, 0) + 1);
        }
        out.println(ans);
    }



}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}


Measured memory_bytes: 55912
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int gcd(int a, int b){return b ? gcd(b, a%b) : a;}

int main(){
    ll h, w, ans;
    cin >> h >> w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    
    if(h%2 == 0) ans = h/2*w;
    else if(w%2 == 0) ans = w/2*h;
    else ans = (h+1)/2*w-w/2;

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

int main(void)
{
	using namespace std;
	int n;
	double D1, D2, D3, D4 = 0;
	cin >> n;
	int x[n], y[n], d[n];
	for(int i = 0; i < n; i++)
		cin >> x[i];
	for(int i = 0; i < n; i++)
		cin >> y[i];
	for(int i = 0; i < n; i++)
		d[i] = abs(x[i] - y[i]);
	for(int i = 0; i < n; i++)
		D1 += d[i];
	for(int i = 0; i < n; i++)
		D2 += d[i] * d[i];
	for(int i = 0; i < n; i++)
		D3 += d[i] * d[i] * d[i];
	for(int i = 0; i < n; i++)
	{
		if(D4 < d[i])
			D4 = d[i];
	}
	cout << fixed << setprecision(8) << D1 << endl << sqrt(D2) << endl << pow(D3, 1.0 / 3) << endl << D4 << endl;
}


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

queue<string> que;
int k;
string ans;
void bfs(string t, int i) {
  if (i == k) {
    ans = t;
    return;
  }
  int n = t.size();
  if (t.at(n - 1) == '9') {
    char mini = '8';
    char equ = '9';
    que.push(t + mini);
    que.push(t + equ);
  } else if (t.at(n - 1) == '0') {
    char equ = '0';
    char maxi = '1';
    que.push(t + equ);
    que.push(t + maxi);
  } else {
    char tar = t.at(n - 1);
    char mini = tar - 1;
    char maxi = tar + 1;
    que.push(t + mini);
    que.push(t + tar);
    que.push(t + maxi);
  }
  string next = que.front();
  que.pop();
  bfs(next, i + 1);
}
int main() {
  cin >> k;
  if (k <= 12) {
    cout << k << endl;
  } else {
    for (int i = 2; i <= 9; i++) {
      que.push(to_string(i));
    }
    bfs("1", 1);
    cout << ans << endl;
  }
}

Measured memory_bytes: 35200
a,b = map(int,input().split())
c="入力が間違っています。"
d="鶴が"
e="匹で、亀が"
f="匹です。"
 
k=b//2-a
t=2*a-b//2
if k<0 or t<0 or b%2!=0:
    print('No')
else:
    print('Yes')

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


int n;
int s[100000];

/*二分探索*/
int binarySearch(int key) {

    int left = 0;
    int right = n;
    int mid;
    while (left < right) {

        mid = (left + right) / 2;

        if (s[mid] == key) {
            return 1;
        }
        if (key < s[mid]) {
            right = mid;
        } else if (key > s[mid]) {
            left = mid + 1;
        }
    }

    return 0;   
}

int main() {

    cin >> n;

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

    int q;
    cin >> q;

    int t;
    int res = 0;

    for (int i = 0; i < q; i++) {
        cin >> t;
        if ( binarySearch(t) ) {
            res ++;
        }
    }
    
    cout << res << endl;

    return 0; 
    
}


Measured memory_bytes: 3392
import java.util.*;
import static java.lang.Math.*;

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

		// 入力
		int n = sc.nextInt();
		int[] a = new int[n]; 
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}

		// 計算
        double d = 0;
		for(int i = 0; i < n; i++){
			d += (double)1/a[i];
		}
		// 出力
		System.out.println(1/d);
	}

}


Measured memory_bytes: 23380
/*
 #pragma GCC target ("avx2")
 #pragma GCC optimize ("Ofast")
 #pragma GCC optimize ("unroll-loops")
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#define F first
#define S second
#define pb push_back
using namespace std;
  
// Return the maximum volume.
double maxvolume(double s)
{
    // finding length
    double length = s / 3;
  
    s -= length;
  
    // finding breadth
    double breadth = s / 2;
  
    // finding height
    double height = s - breadth;
  
    return length * breadth * height;
}
  
// Driven Program
int main()
{
    double s ;
    cin>>s;
    cout.precision(9);
    cout <<fixed<< maxvolume(s) << endl;
    return 0;
}


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


// Cの枚数を0 ~ max(X, Y) * 2で探索する
int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int tmp_max_price = A * X + B * Y;
  rep(i, max(X, Y) * 2 + 1) {
    int price = i * C;

    price += A * max((X - i / 2), 0);
    price += B * max((Y - i / 2), 0);

    tmp_max_price = min(tmp_max_price, price);
  }

  cout << tmp_max_price << endl;
}

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

#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define endl "\n"

#define for0(i, n) for (int i = 0; i < n; i++)
#define loop(i, a, b) for(int i = a;i <= b; i++)
#define forrev(i, n) for(int i = n; i >= 0; i--)
#define test_case(t) int t; cin >> t; while (t--)
#define debug(x) cout<< #x << "=" << x <<"\n";
#define debug(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n";

typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;

#define prec(n) fixed<<setprecision(n)
#define inf (int)(1e18)
#define MAX 1000002
#define MOD 1e9 + 7

long long int max(long long int a,long long int b){if(a>b) return a; else return b;}
long long int min(long long int a,long long int b){if(a<b) return a; else return b;}
bool isPrime(int N){
    for(int i=2;i*i<=N;++i){
        if(N%i==0) return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n,k;
    cin>>n>>k;

    vi p(n);

    for(int &x : p)
     cin>>x;

    sort(all(p));

    int sum = 0;

    for(int i = 0; i < k;i++)
     sum += p[i];

    cout<<sum<<endl;  

    return 0;
}
//g++ -std=c++17 -Wshadow -Wall -O2 -Wno-unused-result



Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define F first 
#define S second 
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

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

// template <typename T>
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;
  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo;
    exp >>= 1;
  }
  return result;
}

const int N = 3e3 + 2 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

lint dp[N][N][4] ;
int val[N][N] ;
// int idx[N][N] ;
int n, m, k ;

lint solve(int i, int j, int curRow) {
	if(i >= n) return 0;
	if(j >= m) return 0;
	if(dp[i][j][curRow] != -1) return dp[i][j][curRow] ; 
	lint ans = 0 ;
	
	// dont pick
	reMax(ans, max(solve(i, j+1, curRow), solve(i+1, j, 0)));

	// pick
	if(curRow < 3) {
		reMax(ans, solve(i, j+1, curRow + 1) + val[i][j]);
		reMax(ans, solve(i+1, j, 0) + val[i][j]); 
	}
	return dp[i][j][curRow] = ans ; 
}

int main()
{
    fastio; cin >> n >> m >> k ; int r, c, v ;
    // SET(index, -1);
    SET(val, 0);
    for(int i = 0; i < k; i++) {
    	cin >> r >> c >> v ;
    	r-- ; c-- ; 
    	// idx[r][c] = i ; 
    	val[r][c] = v ; 
    }
    SET(dp, -1); cout << solve(0, 0, 0); 
}


Measured memory_bytes: 320992
using System;

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

            var firstMax = 0;
            var secondMax = 0;
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                if (A[i] > firstMax)
                {
                    secondMax = firstMax;
                    firstMax = A[i];
                }
                else if (A[i] > secondMax)
                {
                    secondMax = A[i];
                }
            }

            for (int i = 0; i < N; i++)
            {
                if (A[i] == firstMax)
                {
                    Console.WriteLine(secondMax);
                }
                else
                {
                    Console.WriteLine(firstMax);
                }
            }
        }
    }
}


Measured memory_bytes: 17108
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;


public class Main {

	public static class pair implements Comparable<pair> {
		int id;
		int ans;

		pair(int x, int y) {

			id = x;
			ans = y;

		}

		public pair() {

		}

		public int compareTo(pair o) {
			// TODO Auto-generated method stub

			return this.id - o.id;
		}
	}

//	static int mod = (int) 998244353.;
	static int mod=(int)1e9+7;
	static ArrayList<Integer> gr[];
	static int[][] ar;
	static Scanner sc = new Scanner(System.in);
	static int pri[] = new int[(int) 1e6 + 5];
	static StringBuilder out = new StringBuilder();

	static long dp[][];

	public static void main(String[] args) throws IOException {
		int t =1;// sc.nextInt();
		
		while (t-- > 0) {
		
			int n=sc.nextInt();
			ar=new int[n][n];
			long sum=0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++)
				ar[i][j]=sc.nextInt();
				
			}
			dp=new long[n][(1<<n)];
			set=(1<<n)-1;
			
			for(int i=0;i<n;i++) {
				for(int j=0;j<dp[0].length;j++) {
					dp[i][j]=-1;
				}
			}
			long ans=solve(n-1,0);
			
			
			System.out.println(ans);
			
		}

		System.out.println(out);
	}
	static int set;
	static long solve(int i,int mask) {
		if(i==-1 && mask==set) {
			return 1L;
		}
		if(i<=-1)return 0;
		if(dp[i][mask]!=-1)return dp[i][mask];
	    long ans=0;
	    
	    for(int j=0;j<ar.length;j++) {
	    	if(ar[i][j]==1 && ((1<<j)&mask)==0)ans+=solve(i-1,(mask|(1<<j)));
	    	ans%=mod;
	    }
		return dp[i][mask]= ans%mod;
		
	}


}

Measured memory_bytes: 371796
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  int x[4];
  for (int i = 0; i < 4; i++) { x[i] = 0; }
  int a, b;
  for (int i = 0; i < 3; i++) {
    cin >> a >> b;
    x[a-1]++;
    x[b-1]++;
  }
  sort(x, x+4);
  int y[4] = {1, 1, 2, 2};
  int f = 1;
  for (int i = 0; i < 4; i++) {
    if (x[i] != y[i]) f = 0;
  }
  if (f == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans = 0;
    ll i = 0,j = b;
    bool flag;
    if(n<b){
        ans = floor(((double)a*n)/b)-a*floor((double)n/b);
        cout << ans << endl;
        return 0;
    }else{
        ans = floor(((double)a*(b-1))/b)-a*floor((double)(b-1)/b);
        cout << ans << endl;
        return 0;
    }

    
    
    return 0;
}

Measured memory_bytes: 3732
def dig(x):
    c=0 
    while x:
        c+=1 
        x//=10 
    return c 
n=int(input())
def div(x):
    if x==1:
        return [1] 
    d=[1,x]
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            d.append(i)
            if i!=x//i:
                d.append(x//i)
    return d 
d=div(n)
mini=10**9 
for i in d: 
    b=n//i 
    mini=min(mini,max(dig(b),dig(i)))
print(mini)
    

Measured memory_bytes: 3064
/* 164b.c */
#include <stdio.h>

int main(void){
    int a,b,c,d=0;
    int tak,aok=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    aok=c-b;
    tak=a-d;
    if(aok<=0){
        printf("Yes");
        return 0;
    }else if(tak<=0){
        printf("No");
        return 0;
    }
    for(int i=0; i<100;i++){
        aok=aok-b;
        tak=tak-d;
        if(aok<=0){
            printf("Yes");
            return 0;
        }else if(tak<=0){
            printf("No");
            return 0;
        }
    }
}

Measured memory_bytes: 1732
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const D EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> II;

/** Problem0082 : Flying Jenny **/
bool cmp(const II &a, const II &b)
{
	if (a.first == b.first) return a.second < b.second;
	else return a.first < b.first;
}

int main()
{
	int p[8];
	const int num[8] = {4, 1, 4, 1, 2, 1, 2, 1};
	while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4]>>p[5]>>p[6]>>p[7]) {

		//int ans=INF
		int tmp=INF, idx=0;
		vector<II> ans;
		
		rep(i, 8) {
			int tt=0;
			int nnum[8];
			rep(j, 8)
				nnum[j] = num[(i+j)%8];
			
			rep(j, 8) {
				tt+=max(0, p[j] - nnum[j]);
			}
			
			int tans=0;
			rep(j, 8) {
				tans*=10;
				tans+=nnum[j];
			}
			ans.push_back(II(tt, tans));
		}
		
		sort(ans.begin(), ans.end(), cmp);
		
		
		char sans[10];
		sprintf(sans, "%d", ans[0].second);
		
		cout << sans[0];
		REP(i, 1, 8) {
			cout << " " << sans[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll N, M;
ll sum;
map<int, ll> mp;
int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        ll A;
        cin >> A;
        sum += A;
        sum %= M;
        mp[sum]++;
    }
    
    ll ans = 0;
    for(auto& u : mp){
        if(u.first == 0) ans += u.second;
        ans += u.second * (u.second - (ll)1) / (ll)2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[810];
int main()
{
	int n;
	int sum = 0;
	cin >> n;
	rep(i, n) { cin >> a[i]; sum += a[i]; }
	if (sum % 10 != 0) { cout << sum << endl; }
	else {
		sort(a, a + n);
		rep(i, n) { if (a[i] % 10 != 0) { cout << sum - a[i] << endl; return 0; }
		}
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256