akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

int main () {
  int a, b;
  cin >> a >> b;
  cout << dup(b-1,a-1) << endl; 
  return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;
    string S;

    cin >> N >> S;

    ll ans = 0;
    for(char i = '0'; i <= '9'; i++){
    for(char k = '0'; k <= '9'; k++){
    for(char j = '0'; j <= '9'; j++){
        queue<char> q;
        q.push(i);
        q.push(j);
        q.push(k);

        for(int l = 0 ; l < S.size(); l++){
            if( q.front() == S[l] ){
                q.pop();
            }

            if( q.size() == 0 ){
                ans++;
                break;
            }
        }

    }
    }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
import sys

read = sys.stdin.read


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, M, *A = map(int, read().split())
    G = A.copy()

    while not any(x % 2 for x in G):
        G = [i // 2 for i in G]

    if not all(x % 2 for x in G):
        print(0)
        exit(0)

    total = 1

    for x in A:
        total = lcm(total, x // 2)

    print((M // total + 1) // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14932
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int gcd(int x, int y);

int main()
{
    int a, b, c, N;
    int sum=0;
    
    scanf("%d", &N);

    for(c=1;c<=N;c++){
    	for(b=1;b<=N;b++){
    		for(a=1;a<=N;a++){
    			sum += gcd(gcd(a,b),c);
    		}
    	}
    }
    
    printf("%d", sum);

    return 0;
}


int gcd(int x, int y)
{
    int r;

    
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int count = 0;
  
  for (int i = 0; i < N; i++){
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for (int j = 0; j < N - 1; j++){
    
    if (a.at(j) > a.at(j + 1)){
      count++;
    }
  }
 
  cout << 1 + count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <cstring>
using namespace std;
   
int main() {
  int M, N;
  cin >> N >> M;
  int books[100010];
  memset(books, 0, sizeof books);
  for(int i=0; i<N; i++) {
    cin >> books[i];
  }
       
  int l = 0, r = (int)1e9;
  while(r - l > 1) {
    int m = (l+r)/2;
    int BPS = 0;
    for(int i=0; i<M; i++) {
      long long size = m;
      for(;;) {
        if(BPS == N) break;
        if(size - books[BPS] < 0) break;
        size -= books[BPS++];
      }
      if(BPS == N) break;
    }
    if(BPS == N) {
      r = m;
    } else l = m;
  }
       
  cout << l+1 << endl;
   
     
  return 0;
}

Measured memory_bytes: 1560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();

			for (int i = 1; i <= 9; i++) {
				if (n <= i * 111) {
					System.out.println(i * 111);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF = 1e+9;

int main(){
	int n,m,dist[21][21];
	
	for(int i=0 ; i < 21 ; i++ )
		for(int j=0 ; j < 21 ; j++ )
			dist[i][j] = INF;

	scanf("%d %d", &n, &m);
	for(int i=0 ; i < m ; i++ ){
		int a,b,c,d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		dist[a][b] = c;
		dist[b][a] = d;
	}
	for(int k=1 ; k <= n ; k++ ){
		for(int i=1 ; i <= n ; i++ ){
			for(int j=1 ; j <= n ; j++ ){
				dist[i][j] = min( dist[i][j] , dist[i][k]+dist[k][j] );
			}
		}
	}
	int x1,x2,y1,y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);
	int ans = y1 - (y2 + dist[x1][x2] + dist[x2][x1]);
	printf("%d\n", ans );
}

Measured memory_bytes: 1028
import sys
 
v = []
for line in sys.stdin:
    v.append([i for i in line.split()])
 
m = 0
for a, b in v[1:]:
  a = float(a)
  if b == "JPY":
    m += a
  else:
    m += 380000.0 * a
print(m)

Measured memory_bytes: 2940
N, Y = gets.chomp.split(" ").map(&:to_i)

(0..N).each do |x|
  (0..N).each do |y|
    z = N - (x + y)
    next if z < 0
    if x * 10000 + y * 5000 + z * 1000 == Y then
      puts "#{x} #{y} #{z}"
      exit
    end
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 3836
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int R, G;
	std::cin >> R >> G;
	std::cout << (G*2-R) << "\n";
}


Measured memory_bytes: 384
#include <iostream>

int main() {
  int N;
  std::cin >> N;
  int Hmax = 1;
  int H;
  int Output = N;
  for (int i = 1; i <= N; ++i) {
    std::cin >> H;
    if (H < Hmax) {
      --Output;
    } else {
      Hmax = H;
    }
  }
  std::cout << Output << "\n";
  return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<map>
  using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) begin(v),end(v)

#define MAX_N 1010
class maxFlow
{
public:
  int N;//???????????°
  int G[MAX_N][MAX_N];//G[i][j] :=???i??????j????????§?????????
  bool is_visited[MAX_N];

  maxFlow(int n)
  {
    N=n;
    //?????????????????¨????????°???????????§??????
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	G[i][j]=0;
  }

  //n1->n2???arc?????????
  void add_arc(int n1,int n2,int capacity)
  {
    G[n1][n2]+=capacity;//????????§?????±???
  }

  //??´???????????§???????????¢?´¢
  int dfs(int now,int end,int min_capacity)
  {
    if(now==end)return min_capacity;
    if(!is_visited[now])
      {
	is_visited[now]=true;
	for(int i=0;i<N;i++){
	  if(G[now][i]>0){//now??????i????????§??????????????????????????°????????§??????
	    int ret=dfs(i,end,min(min_capacity,G[now][i]));
	    if(ret>0){//??´???????????????????????????????????§?¢???????????????????????????????????????´??°
	      G[now][i]-=ret;
	      G[i][now]+=ret;
	      return ret;
	    }
	  }
	}
	return -2;//??´????????????????????????????????£???
      }
    else return -1;//?????§????¨???????????????£???
  }
  
  int get_maxFlow(int start,int end)
  {
    int temp,ans=0;
    //??´???????????????????????????????????§????????????????????????????????????????´¢
    while(true){
      for(int i=0;i<N;i++)is_visited[i]=false;
      temp=dfs(start,end,100);
      if(temp>0)ans+=temp;
      else break;
    }
    return ans;
  }
  
};

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

int main()
{
  int n,m;

  while(true){
    cin>>m>>n;
    if(m==0&&n==0)break;
    maxFlow G(m+n+2);
    vector<int> b(m);
    vector<int> r(n);
    rep(i,m){
      cin>>b[i];
      G.add_arc(m+n, i, 1);
    }
    rep(i,n){
      cin>>r[i];
      G.add_arc(m+i, m+n+1 , 1);
    }
    
    rep(i,m){
      rep(j,n){
        if(gcd(b[i],r[j])!=1){
          G.add_arc(i, m+j, 1);
        }
      }
    }

    cout<<G.get_maxFlow(m+n, m+n+1)<<endl;
    
  }

  
  return 0;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    

    printf( "%.9lf ", w * h / 2 );
    if( w / 2 == x && h / 2 == y ) printf( "1\n" );
    else printf( "0\n" );

    return 0;
}



Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in a:
  d[i]+=1
c=0
for i in d.keys():
  if d[i]>i:
    c+=d[i]-i
  elif d[i]<i:
    c+=d[i]
print(c)

Measured memory_bytes: 68776
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cerr << #x << " is " << x << endl;
#define F(i,b) for(int i = 0 ; i < (int)(b) ; i++)
#define RF(j,b) for(int j = (int)(b)-1 ; j >= 0 ; j--)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;
/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
//debug
#define TRACE

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


void solve(){
	cin >> s ;
	int n = sz(s) ;
	vi dp1(n+1) , dp2(n+1) ;
	dp2[0] = 1 ;
	for(int i = 0 ; i < n ; i++){
		if(s[i] == '0'){
			dp1[i+1] = 3LL * dp1[i] ;
			dp2[i+1] = dp2[i] ;
		}
		else{
			dp1[i+1] = 3LL * dp1[i] + dp2[i] ;
			dp2[i+1] = 2LL * dp2[i] ;
		}
		dp1[i+1] %= MOD ;
		dp2[i+1] %= MOD ;
	}
//	trace(dp1,dp2) ;
	cout << (dp1[n] + dp2[n]) % MOD << endl ; 
}

int32_t main(){_
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}

}


Measured memory_bytes: 2000
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
s = list(read())
ans = 0
ans = 1
t = s[0]
for i in range(n):
    if t != s[i]:
        t = s[i]
        ans += 1
print(ans)

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

ll N,X[200000],Y[200000];

int main(void){
    cin >> N;
    rep(i,N){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(Y,Y+N);
    rep(i,N){
        int p = lower_bound(Y,Y+N,X[i])-Y;
        //cout <<"p:" <<  p << endl;
        if(p<N/2)cout << Y[N/2] << endl;
        else cout << Y[(N/2)-1] << endl;
    }
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        x += (d-1)/k+1;
    }
    cout << x << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int A,B,C,K;
signed main(){
	scanf("%lld%lld%lld%lld",&A,&B,&C,&K);
	if (K&1)printf("%lld\n",B-A);
	else printf("%lld\n",A-B);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n;cin>>n;ll ans=1;
    for(ll i=1;i<=n;i++){
        ans=(ans*i)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

int a, b;
int main()
{
  scanf("%d%d",&a,&b);
  if(a>0) 
  {
    puts("Positive");
	return 0;
  }
  if(a<=0 && b>=0) 
  {
    puts("Zero");
    return 0;
  }
  if(b<0)
  {
    int g=b-a+1;
	if(g&1) puts("Negative"); else puts("Positive");
  }
}

Measured memory_bytes: 128
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "m_solutions2020_d.cpp"

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

  int n;
  cin >> n;

  vl a(n);
  cin >> a;

  bool down = a[0] > a[1];
  ll stock = 0;
  ll ans = 1000;
  if (!down) {
    stock += (ans / a[0]);
    ans -= (ans / a[0]) * a[0];
  }

  FOR(i, 1, n - 1) {
    if (!down) {
      if (a[i] > a[i + 1]) {
        ans += stock * a[i];
        stock = 0;
        down = true;
      }
    } else {
      if (a[i] < a[i + 1]) {
        stock += (ans / a[i]);
        ans -= (ans / a[i]) * a[i];
        down = false;
      }
    }
  }

  ans += stock * a[n - 1];
  cout << ans << endl;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
	long x,i,n;
	long R[200000],max,min;

	scanf("%ld",&n);

	max=-1000000000;

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

	min = R[0];

	for(i=1;i<n;i++){
		x = R[i] - min;
		if(max<x)max = x;
		if(min>R[i])min = R[i];
	}

	printf("%ld\n",max);

	return 0;
}

Measured memory_bytes: 3300
from collections import Counter

def update_rank_lis(rank_lis, drop_sport):
    return [
        [sport for sport in ranks if sport != drop_sport]
        for ranks in rank_lis
    ]

def count_first(rank_lis):
    first_cnt = Counter([ranks[0] for ranks in rank_lis])
    return sorted([(cnt, sport) for sport, cnt in first_cnt.items()])[-1]

def solve(N, M, rank_lis):
    min_value = N
    for _ in range(M):
        most_pop_cnt, most_pop_sport = count_first(rank_lis)
        min_value = min(most_pop_cnt, min_value)
        rank_lis = update_rank_lis(rank_lis, most_pop_sport)
    print(min_value)
    
N, M = map(int, input().split())
rank_lis = [list(map(int, input().split())) for _ in range(N)]
solve(N, M, rank_lis)


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

const int maxn = 1e5 + 10;

int a[maxn], b[maxn], c[maxn];
int dp[maxn][3];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d %d", &a[i], &b[i], &c[i]);
    }

    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    for (int i = 2; i <= n; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    printf("%d\n", max(dp[n][2], max(dp[n][0], dp[n][1])));

}

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

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar()) 
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}
const int MAXN = 300000 + 100;

int n, k;
ll arr[MAXN], MX[MAXN << 2], f[MAXN];

void pushup(int o) {
	MX[o] = max(MX[ls], MX[rs]);
}
void update(int pos, ll c, int l, int r, int o) {
	if (l == r) {
		MX[o] = c;
	//	cout << l << " " << MX[l] << endl;
		return ;
	}
	int mid = l + r >> 1;
	if (pos <= mid)
		update(pos, c, lson);
	else
		update(pos, c, rson);
	pushup(o);
}
ll query(int L, int R, int l, int r, int o) {
	if (L <= l && r <= R) {
		return MX[o];
	}
	ll res = 0;
	int mid = l + r >> 1;
	if (L <= mid)
		res = max(res, query(L, R, lson));
	if (mid < R)
		res = max(res, query(L, R, rson));
	return res;
}

int main () {
	read(n);
	read(k);
	rep(i, 1, n + 1) {
		read(arr[i]);
	}
	ll ans = 0;
	rep(i, 1, n + 1) {
		int l = max(-k + arr[i], 0ll);
		int r = min(k + arr[i], 1ll * MAXN);
		ll d = query(l, r, 1, MAXN, 1);
	//	cout << "i: " << d << endl;
		f[i] = query(l, r, 1, 1ll * MAXN, 1) + 1;
		
		update(arr[i], f[i], 1, 1ll * MAXN, 1);
		ans = max(f[i], ans);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 16516
n = int(input())
shop_open = [0] * n
profit_ls = [0] * n
for i in range(n):
    shop_open[i] = list(map(int, input().split()))
for i in range(n):
    profit_ls[i] = list(map(int, input().split()))

num_patterns = 2 ** 10
max_profit = -float('inf')
for pattern_10 in range(1,num_patterns):
    pattern_ls = [0] * 10
    for d in range(10):
        if ((pattern_10 >> d) & 1):
            pattern_ls[d] = 1
    profit = 0
    for shop_ind in range(n):
        the_shop_open = shop_open[shop_ind]
        both_open_times = 0
        for time in range(10):
            if the_shop_open[time] == 1 and pattern_ls[time] == 1:
                both_open_times += 1
        profit += profit_ls[shop_ind][both_open_times]
    max_profit = max(max_profit, profit)
print(max_profit)

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n;
  cin >> n;
  queue<int> que;
  ll sum = 0;
  REP(i,n){
    int x;cin >> x;
    que.push(x);
    sum += x;
  }
  ll pre = 0,res = 100100100100100;
  for(int i = 0;i < n-1;i++){
    pre += que.front();que.pop();
    res = min(res,abs(sum-2*pre));
  }
  cout << res << endl;




  return 0;
}


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

using vi = vector<int>;

int N;
vi h(100010);

vi dp(100010);

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

  dp[0] = 0; dp[1] = abs(h[1]- h[0]);
  for(int i=2; i<N; i++){
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
  }

  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

bool is_prime(
  int n
)
{
  auto max = static_cast<int>(sqrt(n));
  for (int i = 2; i <= max; ++i)
    if (0 == n%i)
      return false;
  return true;
}

int main()
{
  int N;
  cin >> N;
  vector<int> prime;
  for (int i = 2; i <= N; ++i)
    if (is_prime(i))
      prime.push_back(i);
  vector<int> cnt(prime.size());
  for (int i = 0; i < prime.size(); ++i)
    for (int j = prime[i]; j <= N; j *= prime[i])
      cnt[i] += N/j;
  long long total = 1;
  int mod = 1000000007;
  for (int i = 0; i < cnt.size(); ++i)
  {
    total *= ((cnt[i] + 1)%mod);
    total %= mod;
  }
  cout << total;
  return 0;
}


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

int main(){
  vector< vector<int> > a(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      if(a[i][j]+a[i+1][j+1]!=a[i+1][j]+a[i][j+1]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;
typedef long long ll;
const int nax = 100005;

int mod;

int add (int a,int b)
{
    return (a+b) % mod;
}

int mul (int a,int b)
{
    return (ll)a * b % mod;
}

pair <int,int> process(pair<int,int> a)
{
    return {a.first,add(a.first,a.second)};
}

vector <int> edges[nax],children[nax];
pair <int,int> down[nax],up[nax];
vector <pair <int,int> > downs[nax],pref[nax],suf[nax];

pair <int,int> merge(pair <int,int> a,pair <int,int> b)
{
    pair <int,int> p;
    p.first = mul(a.first,b.first);
    p.second = add(mul(a.second,add(b.first,b.second)),mul(a.first,b.second));
    return p;
}
void dfs_one(int a,int parent)
{
    pair <int,int> p{1,0};
    for (int b:edges[a])
    {
        if (b==parent)
            continue;

        children[a].push_back(b);
        dfs_one(b,a);
        p=merge(p,down[b]);
        downs[a].push_back(down[b]);
    }

    down[a]=process(p);
}

void dfs_two (int a,int parent)
{
    for (int i=0;i<children[a].size();i++)
    {
        pair <int,int> p{1,0};
        if (i!=0)
            p=merge(p,pref[a][i-1]);
        if (i!=downs[a].size()-1)
            p=merge(p,suf[a][i+1]);
        if (a!=1)
            p=merge(p,up[a]);

        int b=children[a][i];
        up[b]=process(p);
        dfs_two(b,a);
    }
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n >> mod;

    for (int i = 1;i < n; i++)
    {
        int a,b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    dfs_one(1,-1);

    for (int a=1;a<=n;a++)
    {
        int k=downs[a].size();
        pair <int,int> p(1,0);
        for (int i=0;i<k;i++)
        {
            p=merge(p,downs[a][i]);
            pref[a].push_back(p);
        }

        p = {1,0};
        for (int i=k-1;i>=0;i--)
        {
            p=merge(p,downs[a][i]);
            suf[a].push_back(p);
        }

        reverse(suf[a].begin(),suf[a].end());
    }

    dfs_two(1,-1);

    for (int a=1;a<=n;a++)
    {
        pair <int,int> p{1,0};
        if (a!=1)
            p=merge(p,up[a]);
        if (children[a].size()!=0)
            p=merge(p,pref[a].back());
        p=process(p);
        cout << p.second << endl;
    }
}



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

int main(){
  char s;
  cin >> s;
  if(s == 'a') cout << 'a' << endl;
  else if(s == 'b') cout << 'a' << endl;
  else if(s == 'c') cout << 'a' << endl;
  else if(s == 'd') cout << 'a' << endl;
  else if(s == 'e') cout << 'a' << endl;
  else if(s == 'f') cout << 'a' << endl;
  else if(s == 'g') cout << 'a' << endl;
  else if(s == 'h') cout << 'a' << endl;
  else if(s == 'i') cout << 'a' << endl;
  else if(s == 'j') cout << 'a' << endl;
  else if(s == 'k') cout << 'a' << endl;
  else if(s == 'l') cout << 'a' << endl;
  else if(s == 'm') cout << 'a' << endl;
  else if(s == 'n') cout << 'a' << endl;
  else if(s == 'o') cout << 'a' << endl;
  else if(s == 'p') cout << 'a' << endl;
  else if(s == 'q') cout << 'a' << endl;
  else if(s == 'r') cout << 'a' << endl;
  else if(s == 's') cout << 'a' << endl;
  else if(s == 't') cout << 'a' << endl;
  else if(s == 'u') cout << 'a' << endl;
  else if(s == 'v') cout << 'a' << endl;
  else if(s == 'w') cout << 'a' << endl;
  else if(s == 'x') cout << 'a' << endl;
  else if(s == 'y') cout << 'a' << endl;
  else if(s == 'z') cout << 'a' << endl;
  else cout << 'A' << endl;
  return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<string> str(n);
  
  for(i = 0; i < n; i++)
    cin >> str[i];
  char buf = str[0][str[0].size() - 1];
  bool judge = true;
  for(i = 1; i < n; i++){
    if(str[i][0] != buf){
      judge = false;
      //cout << buf spa str[i][0] spa i << endl;;
    }
    for(j = 0; j < i; j++)
      if(str[i] == str[j])
        judge = false;
    buf = str[i][str[i].size() - 1];
  }
  
  if(judge)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,an,i;
	while(scanf("%d %d",&a,&b)!=EOF){
		an = a+b;
		if(an==0){
			i=1;
		}else{
			for(i=0;an>0;i++){
			an/=10;
			}
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 600
S=input()
s=S[::-1]
s2=list(S)
N1=int((len(S)-1)/2)
N2=int((len(S)+3)/2)-1
a1=[]
a2=[]
for i in range(0,N1):
    a1.append(s2[i])
T=''.join(a1)
t=T[::-1]
for i in range(N2,len(S)):
    a2.append(s2[i])
U=''.join(a2)
u=U[::-1]
if S==s and U==u and T==t:
    print('Yes')
else:
    print('No')

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

int main(void){
	int n, x, m[110];
	int sum = 0, b = 1000;

	cin >> n >> x;
	int ans = n;
	for (int i = 0; i < n; i++){
		cin >> m[i];
		x -= m[i];
		b = min(b, m[i]);
	}
	ans += (x / b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename T> T gcd(T a, T b){a = abs(a); b = abs(b); if(a<b) swap(a,b); while(b>0){a %= b; swap(a,b);} return a;}
template <typename T> T lcm(T a, T b){return (1LL * a * b) / gcd(a,b);}
template <typename T, typename U> P<T,U> operator+(const P<T,U> &a, const P<T,U> &b){return {a.first + b.first, a.second + b.second};}
template <typename T, typename U> P<T,U> operator-(const P<T,U> &a, const P<T,U> &b){return {a.first - b.first, a.second - b.second};}

const int inf = INT_MAX;

template <typename T>
class RMQ{
private:
  int size;
  vector<T> vec;

  
  int aux(int x, int y, int i, int l, int r){
    if(r<=x || y<=l) return inf;
    else if(x<=l && r<=y) return vec[i];
    else return min(aux(x,y,i*2+1,l,(l+r)/2), aux(x,y,i*2+2,(l+r)/2,r));
  };

public:
  RMQ(int n): size((1<<((int)ceil(log(n)/log(2))+1))-1), vec(size, inf){}
  void update(int i, int x){
    int j = i+(size+1)/2-1;
    vec[j] = x;
    --j;
    while(j>=0){
      vec[j/2] = min(vec[(j/2)*2+1], vec[(j/2)*2+2]);
      if(j==0) break;
      (j /= 2) -= 1;
    }    
  }

  int find(int x, int y){
    return aux(x,y,0,0,(size+1)/2);
  }
};

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

  int n,q; cin >> n >> q;
  RMQ<int> rmq(n);

  REP(i,q){
    int com,x,y; cin >> com >> x >> y;
    if(com){
      cout << rmq.find(x,y+1) << endl;
    }else{
      rmq.update(x,y);
    }
  }
  
  return 0;
}



Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t N, K, pattern;
  cin >> N >> K;
  
  rep(i, N){
  	if(i==0) pattern = K;
    else pattern *= K-1;
  }
  
  cout << pattern << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
signed main(){
	int n;
	cin>>n;
	vector<int> c(n);
	for(int i=0;i<n;i++){
		cin>>c[i];
	}
	sort( c.begin(), c.end() );
	int ans = 0;
	for(int i=0;i<n;i++){
		int res = 1;
		int nokori = n-1-i;
		res *= modpow( 2, 2*n-2 );
		res *= nokori + 2;
		res %= inf;
		res *= c[i];
		res %= inf;
		ans += res;
		ans %= inf;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

void swaprange(int b, int t, int e, int a[])
{
    for (int i = 0; i < e - b; i++)
    {
        swap(a[b+i], a[i+t]);
    }
}

int main()
{
    int n, q, b, t, e;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> b >> e >> t;
        swaprange(b, t, e, a);
    }
    printarray(n, a);
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3128
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

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

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

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

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

#pragma endregion

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

int main() {
    i64 a, b;
    cin >> a >> b;
    if(a <= 5) cout << 0 << endl;
    else if(a <= 12) cout << b / 2 << endl;
    else cout << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char* argv[])
{
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            printf("%dx%d=%d\n", i, j, i*j);
        }
    }
    
    return 0;
}

Measured memory_bytes: 924
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int sum = 0;
    int last = 10;
    rep(i,5){
        int x;
        cin >> x;
        if(x%10!=0)last = min(last,x%10);
        if(x%10==0)sum+=x;
        else sum += x-x%10+10;
    }
    cout << sum-10+last << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int x,tmp;
	int ans=1;
	int i,j,k;
	scanf("%d",&x);
	for(i=2;i<x;i++){
		j=2;	
		while( pow(i,j) <= x ){
				j++;
		}
		if(j>2){
			//printf("i=%d j=%d\n",i,j);
			tmp=1;
			for(k=0;k<j-1;k++){
				tmp = tmp *i;
			}
			if ( ans < tmp){
				ans = tmp;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []

mx=0
for i in range(N):
    A.append(int(input()))

M = max(A)
    
if A.count(max(A)) > 1:
    for i in range(N):
        print(M)
else:
    for i in range(N):
        if A[i] != M:
            print(M)
        else:
            print(sorted(A)[-2])

Measured memory_bytes: 14204
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int E[N+1], W[N+1];
  E[0]=0, W[0]=0;
  rep(i,N){
    if(S[i]=='E'){
      E[i+1] = E[i]+1;
      W[i+1] = W[i];
    }
    if(S[i]=='W'){
      E[i+1] = E[i];
      W[i+1] = W[i]+1;
    }
  }
  int ans=INF;
  rep(i,N){
    int num = W[i] + E[N]-E[i+1];
    if(ans>num) ans = num;
  }
  cout << ans << endl;
  return 0;
}
  



Measured memory_bytes: 3076
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n;
	R[] rs;

	void run(){
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			sc.nextLine();
			rs=new R[n];
			for(int j=0; j<n; j++){
				Scanner s=new Scanner(sc.nextLine());
				rs[j]=new R();
				rs[j].id=s.nextInt();
				for(int i=0; s.hasNext(); i++){
					rs[j].pins[i]=s.nextInt();
				}
			}
			solve();
		}
	}

	void solve(){
		for(int i=0; i<n; i++){
			rs[i].score=getScore(rs[i].pins);
		}
		Arrays.sort(rs);
		for(R r : rs){
			println(r.id+" "+r.score);
		}
	}

	int getScore(int[] pin){
		int score=0;
		for(int frame=0, i=0; frame<10; frame++){
			if(frame<9){
				if(pin[i]==10){
					score+=10+pin[i+1]+pin[i+2];
					i++;
				}else if(pin[i]+pin[i+1]==10){
					score+=10+pin[i+2];
					i+=2;
				}else{
					score+=pin[i]+pin[i+1];
					i+=2;
				}
			}else{
				score+=pin[i]+pin[i+1]+pin[i+2];
			}
		}
		return score;
	}

	class R implements Comparable<R>{
		int id, score;
		int[] pins=new int[22];

		@Override
		public int compareTo(R r){
			if(r.score!=score){
				return r.score-score;
			}else{
				return id-r.id;
			}
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <algorithm>
using lint=int64_t;
using namespace std;

#include<map>
template<typename T> 
void factP(map<T,T> &m,T n)
{
	T x=n;
	for(T i=2;i*i<=n;i++)
	{
		while(x%i==0)
		{
			m[i]++;
			x/=i;
		}
	}
	if(x!=1)m[x]++;
	return;
}

int comb(int n)
{
	return (n*(n-1))/2;
}

int main()
{
	int N;

	cin >> N;

	map<int,int> m;
	for(int i=2;i<=N;i++)
		factP<int>(m,i);

	int list[]={2,4,14,24,74};
	int cnt[5]={};
	for(auto&& i:m)
	{
		for(int j=0;j<5;j++)
		{
			if(i.second>=list[j])
				cnt[j]++;
		}
	}

	int ans=0;
	ans+=comb(cnt[1])*max(cnt[0]-2,0);
	ans+=cnt[2]*max(cnt[1]-1,0);
	ans+=cnt[3]*max(cnt[0]-1,0);
	ans+=cnt[4];

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int H, W; cin >> H >> W;
  
  int check[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      check[i][j] = -1;
    }
  }
  
  
  char A[H][W];
  queue <pair<int, int> > que;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
      if (A[i][j] == '#'){
        check[i][j] = 0;
        que.push(make_pair(i, j));
      }
    }
  }

  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  
  while (!que.empty()){
    pair<int, int> P = que.front(); que.pop();

    for (int i = 0; i < 4; i++){
      int nx = P.first + dx[i];
      int ny = P.second + dy[i];

      if (0 <= nx && nx < H && 0 <= ny && ny < W && check[nx][ny] == -1){
        que.push(make_pair(nx, ny));
        check[nx][ny] = check[P.first][P.second] + 1;
        ans = check[nx][ny];
      }
    }
  }
  

  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 13328
#include<iostream>
#define N 123456
using namespace std;

bool isPrime(int x){
  if(x<=1)return false;
  for(int i=2;i*i<=x;i++){    //i*iを使えばsqrtを使う必要はない
    if(x%i == 0)return false; //余りが0 = 割り切れたら素数でない
  }
  return true;
}

int main(){
  int n;
  bool primeTable[N*2+1];
  for(int i=0;i<=N*2;i++){
    primeTable[i] = isPrime(i);
  }

  while(cin >> n,n){
    int p = 0;
    for(int i=n+1;i<=2*n;i++){
      if(primeTable[i])p++;
    }
    cout << p << endl;
  }
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
void solve(){
  int d,t,s;
  cin>>d>>t>>s;
  if (t*s>=d){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
int main(){
  solve();
  return 0;
}

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

int n, dp[1000005][2];
int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  s += "0";
  n = s.length();

  for (int i = 0; i <= n; i++) {
    dp[i][0] = dp[i][1] = 1000000000;
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      int x = s[i] - '0';
      x += j;
      for (int a = 0; a < 10; a++) {
        int ni = i + 1, nj = 0;
        int b = a - x;
        if (b < 0) {
          nj = 1;
          b += 10;
        }
        dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
      }
    }
  }
  cout << min(dp[n][0], dp[n][1] + 1) << endl;
}

Measured memory_bytes: 9220
#include <iostream>
using namespace std;
int main(void){
    int n,m,a[100000],c=0;
    bool b[100000];
    cin>>n>>m;
    
    for(int i=0;i<n;i++){
        a[i]=1;
        b[i]=false;
    }
    
    b[0]=true;
    
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        a[x]--;
        a[y]++;
        if(b[x])b[y]=true;
        if(a[x]==0)b[x]=false;
    }
    for(int i=0;i<n;i++){
        if(b[i])c++;
    }
    
    cout<<c<<endl;
    
}


Measured memory_bytes: 768
n = int(input().strip())
A = list(map(int, input().strip().split()))
A.sort()
B=[0]*n
for i in range(n):
    B[i]=A[n-1-i]
x=0
if n%2==1:
 
    for i in range(int((n-1)//2+1) ):
        x+=2*B[i]
    x-=B[(n-1)//2]
    x-=B[0]
    
    print(x)
else:
    for i in range(int(n/2)):
        x+=2*B[i]
    
    x-=B[0]
    print(x)

Measured memory_bytes: 31496
S = input()
N = len(S)
x = int((N - 1) / 2)
y = int((N + 3) / 2) - 1

word = S[0:x]
head = S[0:x]
tail = S[y:N]
reverse = word[::-1]

if tail == word and tail == reverse:
  print('Yes')
else:
  print('No')

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

int main()
{
  int N,D;
  cin>>N>>D;
 vector<vector<int>> vec(N, vector<int>(D));
 
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < D; j++)
    {
      cin >> vec.at(i).at(j);
    }
  }
 int count=0;
  double sum=0;
  for (int i = 0; i < N-1; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      sum=0;
      for(int k=0;k<D;k++)
      {
      sum=sum+std::pow((vec.at(i).at(k)-vec.at(j).at(k)),2);
      }
      sum=std::pow(sum,0.5);
      if(ceil(sum)==floor(sum))
      {
      count++;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007


int main(){
	ll n,m;
	cin>>n>>m;
	ll ans = min(n,m/2);
	n -= ans;
	m -= ans*2;
	ans += m/4;
	printf("%lld\n",ans);
	return 0;
}
 

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

int main(){

  int h, w;
  string s[999];
  int data[999][999];

  while(true){
    cin >> h >> w;
    if(!h && !w) break;

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

    for(int i=0;i<h;i++){
      int k = 0;
      for(int j=w-1;j>=0;j--){
	data[i][j] = ++k;
	if(s[i][j] == '*') data[i][j] = k = 0;
      }
    }

    int ans = 0;
    for(int j=0;j<w;j++){
      for(int i=0;i<h;i++){
	int p = data[i][j];
	for(int k=i,l=1;k<h;k++,l++){
	  p = min(p, data[k][j]);
	  ans = max(ans, p * l);
	}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 4692