akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter

fun main(args: Array<String>) {
    val (n, k, c) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!

    fun f(s: String): IntArray {
        val list = mutableListOf<Int>()
        var i = 0
        while (i < n && list.size < k) {
            if (s[i] == 'o') {
                list.add(i)
                i += c + 1
            } else {
                i++
            }
        }
        return list.toIntArray()
    }

    val l = f(s)
    val r = f(s.reversed())
    for (i in r.indices) r[i] = n - r[i] - 1

    val lastL = IntArray(n + 1) { -1 }
    for (i in 0 until k) lastL[l[i] + 1] = i
    for (i in 0 until n) if (lastL[i + 1] == -1) lastL[i + 1] = lastL[i]

    val lastR = IntArray(n + 1) { -1 }
    for (i in 0 until k) lastR[r[i]] = i
    for (i in n - 1 downTo 0) if (lastR[i] == -1) lastR[i] = lastR[i + 1]

    val pw = PrintWriter(System.out)

    for (i in 0 until n) {
        if (s[i] == 'x') continue

        val li = lastL[i]
        val ri = lastR[i + 1]

        var cnt = 0
        cnt += li + 1
        cnt += ri + 1
        if (li != -1 && ri != -1 && r[ri] - l[li] <= c) cnt--

        if (cnt == k - 1) pw.println(i + 1)
    }

    pw.flush()
}


Measured memory_bytes: 55516
n = gets.to_i
c = Array.new(n - 1).map{Array.new(3, 0)}
0.upto(n-2) do |i|
  c[i][0], c[i][1], c[i][2] = gets.split.map(&:to_i)
end
0.upto(n - 2) do |i|
  a = 0
  i.upto(n - 2) do |j|
    if a <= c[j][1]
      a = c[j][1]
    else
      b = a - c[j][1]
      if b % c[j][2] > 0
        a -= b
        a += (b / c[j][2]) * c[j][2]
        a += c[j][2]
      end
    end
    a += c[j][0]
  end
  puts a
end
puts 0

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

using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  unordered_map<char, int> counts_left, counts_right;
  for (char c : S) {
    counts_right[c]++;
  }

  int count = 0;
  int answer = 0;
  for (char c : S) {
    counts_left[c]++;
    counts_right[c]--;
    if (counts_right[c] == 0) {
      if (counts_left[c] > 1) {
	count--;
      }
    } else {
      if (counts_left[c] == 1) {
	count++;
      }
    }
    answer = max(answer, count);
  }
  cout << answer;

  return 0;
}


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

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int N, K;
  cin >> N >> K;
  vector<mint> wa(N+1, 0);
  wa.at(1) = 1;
  vector<P> p(K);
  int x, y;
  
  rep(i, K){
    cin >> x >> y;
    p.at(i) = make_pair(x, y);
  }
  
  for(int i=1; i<N; i++){
    mint sum = 0;
    rep(j, K){
      int r = max( i - (p.at(j).first) + 1, 0);
      int l = max( i - (p.at(j).second) , 0);
      
      sum += wa.at(r)- wa.at(l);        
    }
    wa.at(i+1) = wa.at(i) + sum ;
  }

  cout << wa.at(N) - wa.at(N-1) << endl;
  return 0;
}

Measured memory_bytes: 4844
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    vector<ll>yakusu(n+1);
    for(ll i=1;i<=n;++i){
        for(ll j=i;j<=n;j+=i){
            ++yakusu[j];
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;++i)ans+=i*yakusu[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 81392
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;
char s[300010];
int ans1[300010],ans2[300010];
int main()
{
    int N;
    scanf("%d",&N);
    scanf("%s",s);
    memset(ans1,0,sizeof(ans1));
    memset(ans2,0,sizeof(ans2));
    //ans1[0]=1;
    for(int i=0;i<N;i++){
        if(s[i]=='E'){
            ans1[i]++;
        }
        ans1[i+1]=ans1[i];
    }
    //ans2[N-1]=1;
    for(int i=N-1;i>=0;i--){
        if(s[i]=='W'){
            ans2[i]++;
        }
        ans2[i-1]=ans2[i];
    }
    int maxx=0,t;
    for(int j=0;j<N;j++){
        t=ans1[j]+ans2[j];
        maxx=max(t,maxx);
    }
    printf("%d\n",N-maxx);
    return 0;
}


Measured memory_bytes: 2944
a, b, c= map(int, input().split())
kawaiso = 0 
if a==b and a!=c:
    kawaiso = 1
 
elif  b==c and b!=a:
    kawaiso = 1
 
elif c==a and c!=b:
    kawaiso = 1
    
else:
    kawaiso = 0
  
 
if kawaiso == 1:
    print ("Yes")
    
else:
    print("No")

Measured memory_bytes: 3060
def main(N, K, A):
  cp = 0
  cn = 0
  cz = 0
  An = []
  Anp = []
  Ap = []
  for a in A:
    cp += a > 0
    cn += a < 0
    cz += a == 0
    if a > 0:
      Ap.append(a)
    if a < 0:
      An.append(a)
      Anp.append(-a)
  Anp = sorted(Anp)
	
  if K <= cn * cp:
    # negative 
    #print(K)
    
    ok = -10**20  # There are <= K pairs <= ok
    ng = 0
    # x, count

    while ok + 1 < ng:
      x = (ok + ng) //2
      count = 0
      i_an = -1
      for i, a in enumerate(Ap): # a: increasing -> x // a increasing
        while i_an + 1 < len(An) and An[i_an + 1]* a <= x:
          i_an += 1

        count += i_an + 1
        #print(x, a, count)
      #print(x, count)
      if count < K:
        ok = x
      else:
        ng = x
    return ng
  elif K <= cn * cp + cz * (cp + cn) + (cz - 1 )* cz //2:
    
    return 0
  else:
    # positive
    #print(K)
    K -=  cn * cp + cz * (cp + cn) + (cz - 1 )* cz //2
    #print(K)
    ok = 0
    ng = 10**20  # There are <= K pairs <= ok
    # x, count

    while ok + 1 < ng:
      x = (ok + ng) //2
      count = 0
      for Aa in [Ap, Anp]:
        i_ap = -1
        for i, a in zip(range(len(Aa)-1, -1, -1), Aa[::-1]):
          # a: decreasing -> x // a increasing
          while i_ap+1 < len(Aa) and Aa[i_ap+1] * a <= x:
            i_ap += 1
          count += i_ap + 1
          count -= i <= i_ap
          #print(x, a, count, i, i_ap, Aa)
      count //= 2
      #print(x, count)
      if count < K:
        ok = x
      else:
        ng = x
    return ng

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
print(main(N,K,A))
#pairs = []
#for i in range(len(A)):
#  for j in range(i + 1, len(A)):
#    pairs.append(A[i]*A[j])
#pairs.sort()
#for K, p in zip(range(1, N*(N+1)//2+1), pairs):
#  
#  result = main(N, K, A)
#  if result != p:
#    print(K, p, result)
#print('done')





Measured memory_bytes: 184628
n = gets.to_i
s = gets.chomp
sar = s.split("")
answer = ""
sar.each do |i|
  if ((i.ord-64)+n)%26 == 0
    j = "Z"
  else
    j = ((((i.ord-64)+n)%26)+64).chr
  end
  answer += j
end
puts answer

Measured memory_bytes: 19708
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
from collections import Counter
c = Counter(a)

for i in range(0+(n%2^1),n,2):
    if i == 0 and c.get(0,0) != 1:
        print(0)
        exit()
    elif i > 0 and c.get(i,0) != 2:
        print(0)
        exit()
print(2**(n//2) % mod)

Measured memory_bytes: 14692
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,c,x,y;
long long ans=0;
struct Apple{
	int col,val;
	bool operator <(const Apple x) const {
		return x.val<val;
	}
}p[300005];
int main(){
	cin>>x>>y>>a>>b>>c;
	for(int i=1,x;i<=a;i++)cin>>x,p[i]={1,x};
	for(int i=1,x;i<=b;i++)cin>>x,p[i+a]={2,x};
	for(int i=1,x;i<=c;i++)cin>>x,p[i+a+b]={0,x};
	sort(p+1,p+a+b+c+1);
	int s=x+y;
	for(int i=1;s;i++){
		if(p[i].col==1&&x){
			x--,s--,ans+=p[i].val;
		}
		else if(p[i].col==2&&y){
			y--,s--,ans+=p[i].val;
		}
		else if(p[i].col==0){
			s--,ans+=p[i].val;
		}
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,s;
const int N=3009;
ll a[N],dp[N][N],cur_index;
const ll MOD=998244353;

ll func(int index,int required){
	if(required==0)	return n-(index-1);
	if(required<0 || index==n)	return 0;

	
	if(dp[index][required]!=-1)	return dp[index][required];

	ll ans=0;
	ans+=func(index+1,required);ans%=MOD;
	ans+=func(index+1,required-a[index]);ans%=MOD;

	return dp[index][required]=ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>s;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)	cin>>a[i];
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=func(i,s);
		ans%=MOD;
		// cout<<func(i,s)<<"\n";
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 71168
a=int(input())
b=int(input())

if a==1 and b==2:print(3)
elif a==1 and b==3:print(2)
elif a==2 and b==1:print(3)
elif a==2 and b==3:print(1)
elif a==3 and b==1:print(2)
elif a==3 and b==2:print(1)

Measured memory_bytes: 80004
#include<bits/stdc++.h>
using namespace std;
long long ans,a,b,n,i,weizhi[100005];
int main(){
    cin>>n>>a>>b;
    for(i=1;i<=n;i++){
    	cin>>weizhi[i];
	}
    for(i=2;i<=n;i++){
    	ans+=min((weizhi[i]-weizhi[i-1])*a,b);
	}
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

ll a,b,c;

int main(void) {
	cin >> a >> b >> c;
	if (a - b == b - c)ct("YES");
	else ct("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int res = 0;
  for (int i = 0; i < N; i++){
    if (i % 2 == 0) res += a[i];
    if (i % 2 == 1) res -= a[i];
  }
  cout << res;
}

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

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

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<string> mp(h);

    for(auto &l: mp)
        cin >> l;

    priority_queue<pair<int,int>> q;
    q.push(pair<int,int>(-0, 0*w+0));

    vector<int> dis(w*h, 1e9);

    while(!q.empty()) {
        int c = -q.top().first;
        int i = q.top().second / w;
        int j = q.top().second % w;
        q.pop();
        if(c >= dis[i*w + j]) continue;
        dis[i*w + j] = c;

        for(int k=0; k<4; k++) {
            int ni = i + dy[k];
            int nj = j + dx[k];
            if(!(0 <= ni && ni < h)) continue;
            if(!(0 <= nj && nj < w)) continue;
            if(mp[ni][nj] != '.') continue;
            if(c+1 >= dis[ni*w + nj]) continue;
            q.push(pair<int,int>(-(c+1), ni*w + nj));
        }
    }

    if(dis[w*h-1] == 1e9) {
        cout << -1 << endl;
        return 0;
    }

    long wcnt = 0;
    for(auto &l: mp)
        for(auto &c: l)
            if(c == '.') wcnt++;

    cout << wcnt - dis[w*h-1] - 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 1000005;

char S[MAX_N], T[MAX_N];
int N, pos[MAX_N], R[MAX_N], f[MAX_N];

int main() {
  scanf("%d%s%s", &N, S + 1, T + 1);
  int l = 0, r = N, res = 0;
  
  for (int i = N, l = N; i; --i) {
    if (l > i) l = i;
    while (l > 0 && S[l] != T[i]) l--;
    pos[i] = l;
  }

  for (int i = 1; i <= N; ++i)
    R[pos[i]] = i;
  
  if (R[0]) {
    puts("-1");
    return 0;
  }

  // for (int i = N; i; --i) 
  //   if (R[i] > i) {
  //     for (int j = i; j < N; ++j) f[j] = f[j + 1];
  //     for (int j = i; j <= R[i]; ++j) f[j]++;
  //   }
  // for (int i = 1; i <= N; ++i) res = max(res, f[i]);
  static int q[MAX_N];
  int add = 0, temp;
  l = 1, r = 0;
  for (int i = N; i; --i) 
    if (R[i] > i) {
      while (l <= r && q[l] - add >= R[i]) l++;
      q[++r] = i + add, add++;
      res = max(res, r - l + 1);
    }

  printf("%d\n", res);
  return 0;
}


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

#include <atcoder/all>
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; --i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repc2(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;

using mint = modint998244353;
struct S {
    mint a;
    int size;
};
struct F {
    mint b, c;
};

S op(S a, S b) {
    return S{a.a + b.a, a.size + b.size};
}

S e() {
    return S{mint(0), 0};
}

S mapping(F f, S s) {
    return S{f.b * s.a + s.size * f.c, s.size};
}

F composition(F f, F g) {
    return F{f.b * g.b, g.c * f.b + f.c};
}

F id() {
    return F{1, 0};
}
int n, q;

int main() {
    cin >> n >> q;
    vector<S> v(n);
    rep(i, n) {
        ll a;
        cin >> a;
        v[i] = S{mint(a), 1};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> st(v);
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 0) {
            int l, r, b, c;
            cin >> l >> r >> b >> c;
            st.apply(l, r, F{mint(b), mint(c)});
        } else {
            int l, r;
            cin >> l >> r;
            cout << st.prod(l, r).a.val() << endl;
        }
    }
    return 0;
}

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

namespace atcoder_b_085
{
    class _03
    {
        static void Main()
        {
            int N;     //お札の枚数
            int Y;     //合計金額
            long[] bill = new long[]{ 10000, 5000, 1000 };

            //値取得
            string[] str = Console.ReadLine().Split(' ');
            N = int.Parse(str[0]);
            Y = int.Parse(str[1]);

            for (long i = 0; i <= N; i++) {

                for (long j = 0; j <= N - i; j++)
                {
                    long k = N - i - j;
                    if (i + j + k == N && bill[0] * i + bill[1] * j + bill[2] * k == Y)
                    {
                        Console.WriteLine(i.ToString() + " " + j.ToString() + " " + k.ToString());
                        return;
                    }

                }
                
            }

            Console.WriteLine("-1 -1 -1");

        }
    }

}

Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

const int maxn=1e6;
int x,vis[maxn+5],sum[maxn+5],totle;

int main()
{
	for(int i=2;i<=maxn;++i)
		if(!vis[i])
		{
			sum[++totle]=i;
			for(int j=i*2;j<=maxn;j+=i)
				vis[j]=1;
		}
	x=read();
	printf("%d",sum[lower_bound(sum+1,sum+1+totle,x)-sum]);
	return 0;
}

Measured memory_bytes: 6272
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if (s == u) print2(a - 1, b); else print2(a, b - 1);

    return 0;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long t[n], a[n];
  for (int i = 0; i < n; i++) cin >> t[i] >> a[i];
  for (int i = 1; i < n; i++) {
    long long mt = (t[i - 1] - 1) / t[i] + 1;
    long long ma = (a[i - 1] - 1) / a[i] + 1;
    t[i] *= max(mt, ma);
    a[i] *= max(mt, ma);
  }
  cout << t[n - 1] + a[n - 1] << "\n";
  return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
mod = 2019

d = [0] * (n+1)

k = 1
for i in range(n):
    d[i+1] = d[i] + k * int(s[n-1-i])
    d[i+1] %= mod
    k *= 10
    k %= mod

count = [0] * mod
for i in range(n+1):
    count[d[i]] += 1

ans = 0
for i in range(mod):
    c = count[i]
    ans += c * (c-1) // 2

print(ans)

Measured memory_bytes: 16244
import sys
def g(i):
  print i
  sys.stdout.flush()
  s = raw_input()
  if s=="Vacant":
    sys.exit(0)
  return 0 if s=="Male" else 1

N = int(raw_input())
S = [0]*N
l = 0
S[l] = g(l)
r = N-1
S[r] = g(r)
while True:
  c=(r+l)//2
  S[c]=g(c)
  if (c-l)%2==(S[c]+S[l])%2:
    l=c
  else:
    r=c

Measured memory_bytes: 4056
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){

	int a,b,c;
	int sw = 0;
	scanf("%d %d %d",&a,&b,&c);
	FOR(i,1,b+1) if(a*i%b == c) sw = 1;

	if(sw == 1) printf("YES\n");
	else printf("NO\n");
}

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

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<vector<int>>v;
vector<bool>check;
queue<int>q;

int main() {
	int n, m;
	cin >> n >> m;
	v.assign(n, vector<int>(0, 0));
	check.assign(n, false);
	rep(i, 0, m) {
		int a, b, c;
		cin >> a >> b >> c;
		v[a - 1].push_back(b - 1);
		v[b - 1].push_back(a - 1);
	}
	int ans = 0;
	rep(i, 0, n) {
		if (check[i] == false) {
			q.push(i);
			ans++;
			check[i] = true;
			while (!q.empty()) {
				int hoge = q.front();
				q.pop();
				rep(j, 0, v[hoge].size()) {
					if (check[v[hoge][j]] == false) {
						q.push(v[hoge][j]);
						check[v[hoge][j]] = true;
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6520
x,k,d = list(map(int,input().split()))
p = abs(x)

if p//d >= k:
    print(abs(x)-k*d)
else:
    a = p%d
    b = abs((p%d)-d)
    if ((p//d)-k)%2 == 0:
        print(a)
    else:
        print(b)

Measured memory_bytes: 9108
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main(){
	int s, m, h;

	scanf("%d", &s);

	m = s / 60;
	s = s % 60;
	h = m / 60;
	m = m % 60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}


Measured memory_bytes: 2048
//disco2019_a.cpp
//Sat Nov 23 20:40:25 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int x,y;
	cin >> x >> y;

	int ans = 0;
	if (x==3){
		ans += 100000;
	}else if (x==2){
		ans += 200000;
	}else if (x==1){
		ans += 300000;
	}
	if (y==3){
		ans += 100000;
	}else if (y==2){
		ans += 200000;
	}else if (y==1){
		ans += 300000;
	}
	if (x==1 && y==1){
		ans += 400000;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ll long long
using namespace std;

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

void solve() {
    int k;
    cin >> k;
    ll sum = 0;
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= k; ++j) {
            for (int a = 1; a <= k; ++a) {
                sum += gcd(a, gcd(i, j));
            }
        }
    }
    cout << sum << endl;
    return;
}

int main() {
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3192
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    a,b = max(A), min(A)
    ap,bp = A.index(a),A.index(b)
    ans = []
    if a >= -b:
        for i in range(N):
            if A[i] < 0:
                A[i] += a
                ans.append([ap+1,i+1])
        for i in range(N-1):
            A[i+1] += A[i]
            ans.append([i+1,i+2])
    else:
        for i in range(N):
            if A[i] > 0:
                A[i] += b
                ans.append([bp+1,i+1])
        for i in range(N-1):
            A[-i-2] += A[-i-1]
            ans.append([N-i,N-i-1])
            
    L = len(ans)
    print(L)
    for i in range(L):
        print(*ans[i])
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = list(input())
win_point = {"r":P,"p":S,"s":R}
score = 0
for i in range(K):
    score += win_point[T[i]]
for i in range(K,N):
    if T[i] == T[i-K]:
        T[i] = "."
        continue
    score += win_point[T[i]]
print(score)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll N, M;
	ll size;
	ll ans = 0;

	cin >> N >> M;

	multiset<ll> A;
	ll tmp;
	rep(i, N) {
		cin >> tmp;
		A.insert(tmp);
	}

	multiset<P> S;
	ll B, C;
	rep(i, M) {
		cin >> B >> C;
		S.emplace(-C, B);
	}

	auto itrA = A.begin();
	auto itrS = S.begin();
	size = S.size();
	ll count = itrS->second;
	rep(i, N) {
		if (*itrA < -itrS->first) {
			auto itrTA = itrA;
			itrA++;
			A.erase(itrTA);
			A.insert(-itrS->first);
			count--;
			if (count == 0) {
				size--;
				if (size > 0) {
					itrS++;
					count = itrS->second;
				}
				else {
					break;
				}
			}
		}
		else {
			itrA++;
		}
	}

	ans = 0;
	auto n = A.begin();
	rep(i, N) {
		ans += *(n++);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 11264
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int n, m;
    cin >> n >> m;
    vector <pi> p(n + m);
    loop(i, n) {
        cin >> p[i].F;
        p[i].S = 1;
    }
    loop(i, m)
        cin >> p[i + n].S >> p[i + n].F;
    sort(all(p), greater<pi>());
    int ans = 0, cur = n;
    for (int i = 0; cur; ++i) {
        if (p[i].S > cur) {
            ans += cur * p[i].F; 
            cur = 0;
        }
        else {
            ans += p[i].S * p[i].F;
            cur -= p[i].S;
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 6296
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	g := make([][]int, n)
	inds := make([][]int, n)
	var a, b int
	for i := 0; i < n-1+m; i++ {
		fmt.Scan(&a, &b)
		a--
		b--
		g[a] = append(g[a], b)
		inds[b] = append(inds[b], a)
	}

	gs := topologicalSort(g)
	im := make(map[int]int)
	for i, v := range gs {
		im[v] = i
	}

	for i := 0; i < n; i++ {
		mx := -1
		u := 0
		for _, v := range inds[i] {
			if mx < im[v] {
				mx = im[v]
				u = v + 1
			}
		}
		fmt.Println(u)
	}
}

func topologicalSort(g [][]int) []int {
	n := len(g)
	inds := make([]int, n)
	for i := 0; i < n; i++ {
		for _, e := range g[i] {
			inds[e]++
		}
	}

	q := make([]int, 0)
	for i := 0; i < n; i++ {
		if inds[i] == 0 {
			q = append(q, i)
		}
	}

	ans := make([]int, 0)
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		ans = append(ans, u)
		for _, v := range g[u] {
			inds[v]--
			if inds[v] == 0 {
				q = append(q, v)
			}
		}
	}
	return ans
}


Measured memory_bytes: 24040
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#define int long long
using namespace std;
signed main(){
    int n,m;
    cin>>n>>m;
    int ml=0,mr=114514;
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        ml=max(ml,l);
        mr=min(mr,r);
    }
    if(mr-ml+1<=0)cout<<0<<endl;
    else cout<<mr-ml+1<<endl;
    return 0;
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
#define INF 1e9 + 7
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
typedef long long ll;

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

Measured memory_bytes: 256
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]

ans = [0]*m
food = 0
for i in range(n):
    k = l[i][0]
    for j in range(k):
        food = l[i][j+1]-1
        ans[food] += 1
#print(ans)
print(ans.count(n))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;cin >> n;
  vector<char> s(n);
  rep_i(i, n){
    cin >> s[i];
  }

  vector<int> L(n);
  int w_c = 0;
  rep_i(i, n){
    if(i == 0){
      L[i] = 0;
    }else{
      L[i] = w_c;
    }
    if(s[i] == 'W'){
      ++w_c;
    }
  }
  
  vector<int> R(n);
  int e_c = 0;
  for (int i = n - 1; i >= 0; i--){
    if(i == n - 1){
      R[i] = 0;
    }else{
      R[i] = e_c;
    }
    if(s[i] == 'E'){
      ++e_c;
    }
  }
  int min = 1e9;
  rep_i(i, n){
    if(L[i] + R[i] < min){
      // say(i);
      min = L[i] + R[i];
    }
  }
  say(min);
}

Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main() {
	int a, b, c;	cin >> a >> b >> c;
	int ab = a + b;
	int bc = b + c;
	int ca = c + a;
	int answer = 0;

	if (ab <= bc&&ab <= ca) {
		answer += ab;
	}
	else if (bc <= ab && bc <= ca) {
		answer += bc;
	}
	else {
		answer += ca;
	}
	cout << answer << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    string d[7] = {"SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for (int i = 0; i < 7;i++)
    {
        if(d[i] == s)
        {
            cout << 7 - i;
            return 0;
        }
    }
}

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

int main(){
	ll n; cin >> n;
	ll b[n+1] = {0};
	ll z, i, j;
	rep(i, n){
		cin >> z;
		b[z] += 1;
	}

	
	ll d[n+1] = {0};
	rep(i,n){
		d[b[i]] += 1;
	}

	ll dRuiseki[n+1] = {0}, dkRuiseki[n+1] = {0};
	rep(i, n) {
		dkRuiseki[i] += (dkRuiseki[i-1] + i*d[i]);
		dRuiseki[i] += dRuiseki[i-1] + d[i];
	}
	ll f[n+1];
	rep(i,n){
		f[i] =  (dkRuiseki[i] + i*(dRuiseki[n] - dRuiseki[i]))/i ;
	}

	ll ans[n+1] = {0};
	ll count = 1;
	rep(i, n){
		while(n+1-i <= f[count] && count < n+1){
			count++;
		}
		ans[n+1-i] = count-1;
	}

	rep(i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x, i, j) cerr << #x << "------------" << "\n";cerr << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cerr << x[k] << " ";cerr << "\n"; cerr.flush();
#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;
 
const ll mod = 1e9 + 7;
const ll inf = 1e11 + 5;
const int MaxN = 2e5 + 5;

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

	int n;
	cin >> n;
	map<string, int> stringCnt;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		stringCnt[s]++;
	}
	ll ans = 0;
	for(auto &it: stringCnt){
		ll cnt = it.second;
		ans += (cnt * (cnt - 1)) / 2;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 11264
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;

char str[200005];
int main()
{
	for (int i = 0; i < 200005; i++)
	{
		str[i] = '+';
	}
	cin >> str;
	/*int left, right;
	left = 0;
	right = 1;
	while (str[right] != '+')
	{
		if (str[left] == 'S' && str[right] == 'T')
		{
			str[left] = '+';
			str[right] = '+';
			bool findout=
			if (left == 0)
			{
				left = right + 1;
				right = right + 2;
			}
			else
			{

			}
		}
		else if()

	}
	*/
	int i = 0;
	for (; i < 200005; i++)
	{
		if (str[i] == '\0')
			break;
	}
	int counts, countt;
	counts = 0, countt = 0;
	for (int j = i-1; j >=0; j--)
	{
		if (str[j] == 'T')
		{
			countt++;
		}
		if (str[j] == 'S' && countt > 0)
		{	
			counts++;
			countt--;
	    }
		
	}
	cout << i-(counts*2);
	

	
}

Measured memory_bytes: 384
n = int(input())
p_list = list(map(int, input().split()))

sorted_p_list = sorted(p_list)

count = 0
flag = True

if sorted_p_list == p_list:
    print("YES")
else:
    for i in range(n):
        if sorted_p_list[i] != p_list[i]:
            count += 1
            if count > 2:
                print("NO")
                flag = False
                break

    if flag: print("YES")

Measured memory_bytes: 38384
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

  vector<vector<int>> a(2, vector<int>(n, 0));
  vector<vector<int>> dp(2, vector<int>(n, 0));
  for (int y = 0; y < 2; y++) {
    for (int x = 0; x < n; x++) {
      cin >> a[y][x];
      dp[y][x] = a[y][x];
    }
  }

  for (int y = 0; y < 2; y++) {
    for (int x = 0; x < n; x++) {
      dp[y][x] = a[y][x];
      if (y > 0) {
        dp[y][x] = max(dp[y][x], dp[y - 1][x] + a[y][x]);
      }
      if (x > 0) {
        dp[y][x] = max(dp[y][x], dp[y][x - 1] + a[y][x]);
      }
    }
  }
  cout << dp[1][n-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[100010],f[100010];
int main()
{
	memset(f,0x3f,sizeof(f));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	f[1]=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i-j>0)
			{
				f[i]=min(f[i],abs(a[i]-a[i-j])+f[i-j]);
			}
		}
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,W;
vector<int >w(100,0);
vector<int >v(100,0);
vector<vector<long long > >memo(100,vector<long long >(100001,-1));
long long calc(int item,int rem){
	if(item==n)return 0;
	if(memo[item][rem]!=-1)return memo[item][rem];
  	else{
    	long long  maxi=0;
      //don't include
      maxi = max(maxi,calc(item+1,rem));
      if(w[item]<=rem)
        maxi = max(maxi,calc(item+1,rem-w[item])+v[item]);
      memo[item][rem]=maxi;
      return maxi;
    }
}
int main(){
	cin>>n>>W;
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  cout<<calc(0,W);
}

Measured memory_bytes: 82264
use std::io::*;
use std::str::*;

// const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let x: String = read().unwrap();
    let y: String = read().unwrap();

    let mut chars_x: Vec<_> = x.chars().collect();
    chars_x.sort();
    let mut chars_y: Vec<_> = y.chars().collect();
    chars_y.sort();
    chars_y.reverse();
    let xx: String = chars_x.into_iter().collect();
    let yy: String = chars_y.into_iter().collect();

    //    println!("{} {}", xx, yy);

    if xx < yy {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for(int i = 0; i < N; i++){
    int temp;
    cin >> temp;
    A.at(i) = make_pair(temp, i+1);
  }
  sort(A.begin(), A.end());
  for(int i = 0; i < N-1; i++){
    cout << A.at(i).second << " ";
  }
  cout << A.at(N-1).second << endl;
  
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a > c){
    cout << "NO" << endl;
  }else{
    if(a+b<c){
      cout << "NO" << endl;
    }else{
      cout << "YES" << endl;
    }
  }
}

Measured memory_bytes: 256
using System;

namespace V0001
{
    class Program
    {
        static int Main(string[] args)
        {
            for(var i = 1; i < 10; i++)
            {
                for(var j = 1; j < 10; j++)
                {
                    var x = i * j;
                    Console.WriteLine(String.Format("{0}x{1}={2}", i,j,x));
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 8976
// 配列のほかにmaxとmaxの次に大きい要素を変数に記録し場合分け.
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[200050];
  int b[200050];
  int semimax,max;
  int n; cin >> n;
  for(int i=0;i<n;++i){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a,a+n);
  max = a[n-1];
  semimax = a[n-2];
  for(int i=0;i<n;++i){
    if(b[i]!=max) cout << max << endl; // max以外を取り除くならば
      else cout << semimax << endl; // maxを取り除くならば
  }
  
  return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, A[111];

ll i, j, k;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        if(A[i]%2==0&&A[i]%3!=0&&A[i]%5!=0){
            break;
        }
    }
    if(i==N){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){
  int a, b;
  cin>>a>>b;
  cout<<a*b<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main()
{
  long long int n, i, fact = 1;
  scanf("%lld", &n);
  if(n==0)
  {
      printf("1\n");
  }
  else if (n<21)
  {for (i=1;i<=n;i++)
    fact=fact*i;

  printf("%lld\n",fact);
  }
  else
  {

  }

  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
    int main(void){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      if(a < c && c < b){
        printf("Yes");
      }else if(b < c && c < a){
        printf("Yes");
      }else{
        printf("No");
      }
      return 0;
    } 

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

bool binarysearch(int t, int start, int end, int a[]);

int main()
{
    int n, m;
    int a[100000];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    cin >> m;
    int t;
    int cnt = 0;
    for(int i = 0; i < m; i++){
        cin >> t;
        if(binarysearch(t, 0, n, a)) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

bool binarysearch(int t, int start, int end, int a[])
{
    if(start >= end && a[start] != t) return false;
   int key = (end + start) / 2;
   if(a[key] == t) return true;
   else if(a[key] > t) return binarysearch(t, start, key, a);
   else if(a[key] < t) return binarysearch(t, key + 1, end, a);
}

Measured memory_bytes: 1564
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0

for i in range(q):
    q_temp = T[i]
    S.append(q_temp)
    j = 0
    while S[j] != q_temp:
        j += 1
    if j < n:
        ans += 1

print(ans)



Measured memory_bytes: 6544
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<int>a(N);
	double sum = 0;
	rep(i, N) {
		cin >> a[i];
		sum += a[i];
	}
	P mn = make_pair(INF, INF);
	rep(i, N) {
		P p = make_pair(abs(N * a[i] - sum), i);
		mn = min(mn, p);
	}
	cout << mn.second;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int n=0, m=0, a=0, b=0, c=0, d=0,ans=0,ans2=0;
string s;
signed main() {
    cin >> n >>m>>c;
    vector<vector<int>> A(n,vector<int>(m));
    vector<int> B(m);
    REP(i, m)
        cin >> B[i];
        REP(i,n){
            REP(j,m){
                cin >> A[i][j];
               ans+=A[i][j]*B[j];
            }
            if(ans+c>0){
        
                ans2++;
            }
            ans = 0;
        }
        cout << ans2;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (k <= a)
		cout << 1 * k << endl;
	else {
		ans += a;
		k -= a;
		if (k <= b)
			cout << ans << endl;
		else {
			k -= b;
			cout << ans + (-1 * k) << endl;
		}
	}
}

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

	solve();
}


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

typedef long long ll;
#define DEBUG

void solve(long long A, long long B, long long K){
    ll resA = 0;
    ll resB = 0;
    if(A >= K){
        // 高橋くんで完結
        resA = (A-K);
        resB = B;
    }else{
        // 両方たべる。高橋くんはたべつくす
        resA = 0;
        if(A+B >= K){
            resB = B - (K - A);
        }else{
            //たりない
            resB = 0;
        }
    }
    cout << resA << " " << resB << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define n 500000
#define SENTINEL 2000000000
int count=0,A[n];


void marge(int left,int mid, int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  int L[n1],R[n2];
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  
  L[n1] =SENTINEL;
  R[n2] =SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i=i+1;
      count++;
    }
    else {
      A[k]=R[j];
      j = j+1;
      count++;
    }
  }
}

void margesort(int left,int right){
  int mid;
  
  if(left+1<right){
    mid = (left + right)/2;
    margesort(left,mid);
    margesort(mid,right);
    marge(left,mid,right);
  }
}



int main(){
  int i,a,b,c,d;
  
  scanf("%d",&b);
  
  for(i=0;i<b;i++){
    scanf("%d",&A[i]);
  }
  
  margesort(0,b);
  
  for(i=0;i<b-1;i++){
    printf("%d",A[i]);
    printf(" ");
  }
  printf("%d\n",A[i]);
 
  printf("%d\n",count);
  return 0;
}

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

const int INF = 2e9;



int main(){
    int n; cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);
    for(int i = 0; i < n; i++){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    bool can = true;
    for(int i = 0; i < n; i++){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        
        if(dt < dist){
            can = false;
        }

        if(dist % 2 != dt % 2){
            can = false;
        }
    }

    cout << (can ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4224