akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)


int h, w, d;
string s = "RYGB";
int main() {
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int x = (i + j) / d % 2;
			int y = (h - 1 - (i - j))/ d % 2;
			cout << s[x * 2 + y];
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  using BS = bitset<64>;
  int n;
  cin>>n;
  vector<BS> ms(n);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int x;
      cin>>x;
      ms[i].set(x);
    }
  }
  
  BS b(0);

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int t,x;
    cin>>t>>x;
    if(t==0) cout<<b[x]<<endl;
    if(t==1) b|= ms[x];
    if(t==2) b&=~ms[x];
    if(t==3) b^= ms[x];
    if(t==4) cout<<((b&ms[x])==ms[x])<<endl;
    if(t==5) cout<<(b&ms[x]).any()<<endl;
    if(t==6) cout<<(b&ms[x]).none()<<endl;
    if(t==7) cout<<(b&ms[x]).count()<<endl;
    if(t==8) cout<<(b&ms[x]).to_ullong()<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3100
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

ma = max(m)
dp = [[0] * (ma+1) for _ in range(n+1)]
for i in range(n):
    dp[i][0] = 1

for i in range(ma+1):
    for j in range(n):
        if i - a[j] < 0:
            dp[j+1][i] = dp[j][i]
            continue
        else:
            dp[j+1][i] = max( dp[j][i] , dp[j][i - a[j]] )
            
for i in m:
    if dp[n][i] == 1:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5944
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

#define MAX 256

int main(void){
	int h[MAX], w[MAX];
	int i = 0, t = 1;
	while (t == 1){
		scanf("%d %d", &h[i], &w[i]);
		if (h[i] == 0 && w[i] == 0)t = 0;
		i++;
	}

	for (int j = 0; j < i - 1; j++){
		for (int k = 0; k < h[j]; k++){;
			for (int l = 0; l < w[j]; l++){
				if ((l + k) % 2 == 0)printf("#");
				if ((l + k) % 2 == 1)printf(".");
			}
			printf("\n");
		}
		if (j != i - 1)printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3124
import itertools
N, M, X = map(int, input().split())
a = [list(map(int,input().split())) for i in range (N)]
nums = [0,1]
c = float('inf')
for balls in itertools.product(nums, repeat=N):
  g = 1
  for j in range(M):
    if X>sum([balls[i]*a[i][j+1] for i in range(N)]):
      g = 0
  if g == 1:
    c = min(c, sum([balls[i]*a[i][0] for i in range(N)]))
if c != float('inf'):
  print(c)
else:
  print(-1)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int f(int x){
  if(x==0)return 0;
  return f(x%__builtin_popcount(x))+1;
}
int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  vector<int>x(N);
  for(int i=0;i<N;i++){
    x[i]=S[i]-'0';
  }
  int pop=0;
  for(int i=0;i<N;i++){
    pop+=x[i];
  }
  vector<int>table(N);
  for(int b=0;b<2;b++){
    int rev=pop;
    if(b==0){rev++;}
    else{rev--;}
    if(rev<=0){continue;}
    int start=0;
    for(int i=0;i<N;i++){
      start*=2;
      start+=x[i];
      start%=rev;
    }
    int popi=1;
    for(int i=N-1;i>=0;i--){
      if(x[i]==b){
        int endi=start;
        if(b==0){endi+=popi;endi%=rev;}
        else{endi-=popi;
             endi+=rev;//?
             endi%=rev;}
        table[i]=f(endi)+1;
      }
      popi*=2;
      popi%=rev;
    }
  }
  for(int i=0;i<N;i++){
    cout<<table[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

int main()
{
	int n;
	std::vector<int> a;

	std::cin >> n;

	for (int i = 0; i < n;i++) {
		int temp;
		std::cin >> temp;
		a.push_back(temp);
	}

	std::vector<int> dif;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			dif.push_back(std::abs(a[i]-a[j]));
		}
	}

	auto itr=std::max_element(dif.begin(), dif.end());

	std::cout << *itr << std::endl;

	std::cin >> n;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define LL long long
LL sum;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
	int n,a,b,c,d;
	scanf("%d",&n);
	for(a=1;a<=n;a++)
		for(b=1;b<=n;b++)
			for(c=1;c<=n;c++)
				d=gcd(a,b),d=gcd(c,d),sum+=d;
	printf("%lld\n",sum);
	return 0;

}


Measured memory_bytes: 1732
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	double dp[1501] = {};
	dp[0] = 1.0;
	int M = N / 2;

	rep(i, N) {
		double P;
		cin >> P;
		for (int j = min(M, i); j >= max(0, i - M); j--) {
			dp[j + 1] += dp[j] * P;
			dp[j] *= 1 - P;
		}
	}

	cout << setprecision(15) << dp[M + 1] << endl;

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int H, W; cin >> H >> W;
	char C[100][100];
	rep(i, 0, H) {
		rep(j, 0, W) {
			cin >> C[i][j];
		}
	}

	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << C[i][j];
		}
		cout << endl;
		rep(j, 0, W) {
			cout << C[i][j];
		}
		cout << endl;
	}

	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

// Description: ????????????
// Verifyed: various problem 
const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P p;R c;};

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

// vertical parallel
// verified: AOJ CGL_2_A
bool vertical(L a,L b) {return sdot(O,a.t-a.s,b.t-b.s)==0;}
bool parallel(L a,L b) {return sdet(O,a.t-a.s,b.t-b.s)==0;}
bool eql(L a,L b){ return parallel(a,b) and sdet(a.s,a.t,b.s)==0;}

// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
	int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
	int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
	return max(sa,sb)<0;
}

// crossing point 
// verified: AOJ CGL_2_C
P cross(L a,L b){
	R u=det(a.s,b.s,b.t)/det(O,a.t-a.s,b.t-b.s);
	return u*a.s+(1-u)*a.t;
}
	
// distance 
// verified: AOJ CGL_2_D
R dsp(L l,P p){
	P h=proj(l,p);
	if(sdot(l.s,l.t,p)<=0) h=l.s;
	if(sdot(l.t,l.s,p)<=0) h=l.t;
	return abs(p-h);
}

R dss(L a,L b){return iss(a,b)?0:min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}

istream& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

int main(void){
	int n;
	cin >> n;
	rep(i,n){
		P a,b,c,d;
		cin >> a >> b >> c >> d;
		L s1={a,b},s2={c,d};
		cout << (sgn(dss(s1,s2))==0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0;i<=(n);i++)
using namespace std;
typedef long long ll;
int main(){
  ll n,y;
  cin >> n >>y;
  int z=0;
  rep(i,n){
    rep(j,n){
      if(((9000*i) + (4000*j) - y + (1000*n)==0) && ((n-i-j)>=0)){
        z=n-i-j;
        cout << i << " " << j << " " << z << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

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

#define rep(i, N) for(int i = 0;i < N;i++)
typedef long long ll;
const int mod = 1e9 + 7;

using namespace std;

int main(void) {
	unsigned long long A;
	long double B;
	cin >> A >> B;

	printf("%lld\n", (unsigned long long)floor(A * B));

	return 0;
}

Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;
int Array[100005] , dp[100005];

int main(){
    int N , i;
    scanf( "%d" , &N );

    for( i = 1 ; i <= N ; ++i )
        scanf( "%d" , Array + i );
    
    dp[1] = 0;
    dp[2] = abs( Array[2] - Array[1] );

    for( i = 3 ; i <= N ; ++i )
        dp[i] = min( dp[i - 1] + abs( Array[i] - Array[i - 1] ) , dp[i - 2] + abs( Array[i] - Array[i - 2] ) );

    printf( "%d\n" , dp[N] );
    return 0;
}

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

int main(void){
   
   int N;
   char s;
   map<char,int> mp{};
   cin >> N;
   
   for(int i=0;i<N;i++){
       cin >> s;
       mp[s] = 1;
   }
   
   if(mp.size() == 4){
       cout << "Four" << endl;
   }
   else if(mp.size() == 3){
       cout << "Three" << endl;
   }
}

Measured memory_bytes: 3612
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

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

    bitset<24> B(0);
    long long sum = 0;
    long long ans = 0;

    int right = 0;
    for (int left = 0; left < N; left++) {
        if (right <= left) right = left;
        while (right < N && (sum + A[right]) == (B ^ (bitset<24>(A[right]))).to_ullong()) {
            sum += A[right];
            B ^= bitset<24>(A[right]);
            right++;
        }
        ans += (right - left);
        sum -= A[left];
        B ^= A[left];
    }

    cout << ans << endl;

    return 0;
}














































Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n,i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
}

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

int main(){
  string str;
  
  //空白も含めて1行まるごとを文字列として受け取るためにはgetline関数を使う
  getline(cin,str);

  for(int i=0;i<(int)str.size();i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]=str[i]-'a'+'A';
    }else if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]-'A'+'a';
    }
  }
  cout<<str<<endl;
  return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N,K;cin>>N>>K;
    int z=N/K;
    int ans=z*z*z;
    if(K%2==0&&N*2>=K){
        int count=0;
        int d=(N-K/2)/K+1;
        ans+=d*d*d;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n,k,c = list(map(int,input().split()));s = [True if i == "o" else False for i in input()]
front = [0] * n;back = [0] * n;count = 0

day = 0
while day < n:
  if s[day]:
    front[day] = 1
    day += c+1
    count += 1
  else:
    day += 1
    
day = n-1
while day >= 0:
  if s[day]:
    back[day] = 1
    day -= c+1
  else:
    day -= 1
    
if count == k:
  for i in range(n):
    if front[i] == 1 and back[i] == 1:
      print(i+1)

Measured memory_bytes: 9380
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <queue>
#include <math.h>
using namespace std;
#define lol long long

int main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	int ans = d[N/2] - d[(N/2) - 1];
	cout << ans << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

void div(ll n, queue<ll> &que){
  for(ll i = 1; i*i <= n; i++){
    if(n%i == 0){
      que.push(i);
      if(n != i*i){
        que.push(n/i);
      }
    }
  }
  return;
}

int main(){
  ll n;
  cin >> n;
  
  ll cnt = 0;
  
  queue<ll> que;
  div(n-1, que);
  while(que.size() > 0){
    if(n%que.front() == 1)
      cnt++;
    que.pop();
  }
  
  div(n, que);
  while(que.size() > 0){
    ll num = n;
    ll k = que.front();
    if(k == 1){
      que.pop();
      continue;
    }
    while(num%k == 0 && num >= k){
      num /= k;
    }
    if(num%k == 1){
      cnt ++;
    }
    que.pop();
  }
  
  cout << cnt << endl;
  
  return 0;
  
}

Measured memory_bytes: 3560
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn find_first(s: &String, chr: char) -> usize {
    for (i, c) in s.chars().enumerate() {
        if c == chr {return i}
    }
    0
}

fn find_last(s: &String, chr: char) -> usize {
    let mut last: usize = 0;
    for (i, c) in s.chars().enumerate() {
        if c == chr { last = i}
    }
    last
}

fn main() {
    let s = get!(String);
    println!("{}", find_last(&s, 'Z') - find_first(&s, 'A')+1);
}


Measured memory_bytes: 4352
// たて a cm よこ b cm の長方形の面積と周の長さを求めるプログラムを作成して下さい。
// 【入力】
// a と b が１つの空白で区切られて与えられます。
// 【出力】
// 面積と周の長さを１つの空白で区切って１行に出力して下さい。
// 【制約】
// ・1 ≤ a, b ≤ 100
// 【例】
// ・入力：3 5、出力：15 16
#include <iostream>
using namespace std;

int main( void) {
  int a, b;	// 長方形の縦と横の長さ（cm）
  int area;	// 長方形の面積
  int length;	// 長方形の周の長さ

  cin >> a >> b;

  area = a * b;
  length = 2*a + 2*b;

  cout << area << ' ' << length << endl;

  return 0;
}



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

int main() {

    int N;

    cin >> N;

    int a[N];

    int a_sum = 0;
    int b_sum = 0;

    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }

    sort(a, a + N); 
    reverse(a, a + N); 

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

        //cout << a[i] << endl;

        if (i % 2 == 0){
            a_sum = a_sum + a[i];
        }
        else {
            b_sum = b_sum + a[i];
        }

    }
    cout << a_sum - b_sum << endl;

    return 0;
}

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

int main(){
  int a,b;
  int flag=1;
  char op;
  while(flag){
    scanf("%d %c %d",&a, &op, &b);
    if(op=='+'){
      cout<<a+b<<endl;
    }else if(op=='-'){
      cout<<a-b<<endl;
    }else if(op=='*'){
      cout<<a*b<<endl;
    }else if(op=='/'){
      cout<<a/b<<endl;
    }else if(op=='?'){
      flag=0;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>

using namespace std;

int a[3100];
long dp[3100][3100];

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

	for(int len=1; len<=N; len++) {
		for(int i=0; i+len <= N; ++i) {
			int j = i + len;
			if((N - len) % 2 == 0) dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
			else dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
		}
	}

	cout << dp[0][N];
}

Measured memory_bytes: 73984
#include <stdio.h>

int main(void){
    int N,i,j,min;
    int result = 0;
    
    scanf( "%d" , &N );
    int num[N + 1];
    
    for( i = 0 ; i < N ; i++ ){
        scanf( "%d" , &num[i] );
    }
    
    result = num[1] - num[0];
    if( num[1] < num[0] ){
        min = num[1];
    }else{
        min = num[0];
    }
    //printf( "%d\n" , result );
    
    for( i = 2 ; i < N ; i++ ){
      if( num[i] < min ){
          min = num[i];
          //printf( "min%d\n" , min );
      }else if( result < ( num[i] - min ) ){
          //printf( "%d r%d - %d\n" , result,num[i] ,  min );
          result = num[i] - min;
          
      }
    }
    
    printf( "%d\n" , result );
}



Measured memory_bytes: 2640
#include<iostream>
using namespace std;
long long sum=0,a[300001],beki[61];
int A[300001][60]={0},B[300001][60]={0};
int main(){
	int N;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>a[i];
		for(int j=0;j<60;j++){
			A[i][j]=A[i-1][j]+((a[i]>>j)&1);
			B[i][j]=B[i-1][j]+1-((a[i]>>j)&1);
		}
	}
	beki[0]=1;
	for(int i=1;i<=60;i++){
		beki[i]=beki[i-1]*2;
		beki[i]%=1000000007;
	}
	for(int i=1;i<=N-1;i++){
		for(int j=0;j<60;j++){
			if(((a[i]>>j)&1)==0)sum+=((A[N][j]-A[i][j])*beki[j])%1000000007;
			else if(((a[i]>>j)&1)>0)sum+=((B[N][j]-B[i][j])*beki[j])%1000000007;
			sum%=1000000007;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 143232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
string S;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
while(N){
    ll m=N%26;
    char add;
    if(m==0) add='z';
    else add='a'+m-1;
    S=S+add;
    N/=26;
    if(m==0) N--;
}
reverse(S.begin(),S.end());
cout<<S<<endl;

}
    


Measured memory_bytes: 3660
import math

N = int(input())
cnt = 0
maxI = int(math.floor(math.sqrt(N)))

for i in range(1,maxI+1, 1):
  cnt += int(math.floor((N-1)/i)) - i

cnt *= 2

if N == maxI * maxI:
  cnt += maxI + 1
else:
  cnt += maxI

print(cnt)

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

template <ll mod>
struct ModCombination{
    ll N;
    vector<ll> fact,inv,finv;

    ModCombination(ll n):N(n){
        fact.assign(n+1, 1);
        inv.assign(n+1, 1);
        finv.assign(n+1,1);
        for(int i=1;i<n;i++){
            fact[i+1] = fact[i]*(i+1)%mod;
            inv[i+1] = inv[mod%(i+1)]*(mod-mod/(i+1))%mod;
            finv[i+1] = finv[i]*inv[i+1]%mod;
        }
    }

    ll Comb(ll n,ll k){
        if(k<0||n<k)return 0;
        return (fact[n]*finv[k]%mod)*finv[n-k]%mod;
    }
};

ll dp[3010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,W,H;cin>>H>>W>>N;
  ModCombination<MOD> C(H+W);
  vector<tuple<ll,ll> > rc(N+1);
  for(ll i=0;i<N;i++){
    ll r,c;cin>>r>>c;r--;c--;
    rc[i]=make_tuple(r,c);
  }
  rc[N]=make_tuple(H-1,W-1);
  sort(rc.begin(),rc.end());
  for(ll i=0;i<=N;i++){
    ll r,c;tie(r,c)=rc[i];
    dp[i] = C.Comb(r+c,r);
    for(ll j=0;j<i;j++){
      ll pr,pc;tie(pr,pc)=rc[j];
      dp[i] = (dp[i]-dp[j]*C.Comb(r-pr+c-pc,r-pr)%MOD+MOD)%MOD;
    }
  }
  //debugArray(dp,N+1);
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define MODD 1000000007
#define ll long long
using namespace std;


string S;




int Solve(int p1,int p2,int K) {
    
    if (p1 == p2) {
        return 1;
    }
    
    if (p1 > p2) {
        
        return 0;
        
    }
    
    //printf("%d %d\n",p1,p2);
    
    int ans = max(Solve(p1+1,p2,K),
                  Solve(p1,p2-1,K));
    
    
    if (S[p1]==S[p2] || K > 0)
        ans = max(ans,2+Solve(p1+1,p2-1,K-(S[p1]!=S[p2])));
    
    return ans;
    
}

int dp[333][333][333];

int Solve(int Kmax) {
    
    
    for(int L=0;L<=S.size();L++) {
        
        for(int p1=0;p1+L-1<=S.size()-1;p1++) {
            int p2 = p1+L-1;
            
            
            
            for(int K=0;K<=Kmax;K++) {
                
                if (p1 == p2) {
                    dp[p1][p2][K]=1;
                    continue;
                }
                
                if (p1 > p2) {
                    dp[p1][p2][K]=0;
                    continue;
                }
                
                int ans = max(dp[p1+1][p2][K],dp[p1][p2-1][K]);
                
                if (S[p1]==S[p2] || K > 0)
                    ans = max(ans,2+dp[p1+1][p2-1][K-(S[p1]!=S[p2])]);
                
                
                dp[p1][p2][K]=ans;

            }
            
            
        }
        
    }
    
    return dp[0][S.size()-1][Kmax];
    
}


int main() {
    int K;
    cin>>S>>K;
    
    cout << Solve(K) << endl;
    
    //cout << Solve(0, S.size()-1,K) << endl;
    
    
}

Measured memory_bytes: 131200
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    int ret = 1000;
    for(size_t i = 0; i < S.size()-2; i++)
    {
        int temp = stoi(S.substr(i,3));
        if (ret > abs(753 - temp))
            ret = abs(753 - temp);
    }
    cout << ret << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>> n;
    long H[n];
    for(int i = 0; i < n; i++)
        cin>> H[i];
    int ans = 0, lar = 0;
    for(int i = 0; i < n; i++)
    {
        if(H[i+1] <= H[i] && i < n-1)
            lar++;
        else
        {
            if(ans <= lar)
                ans = lar;
            lar = 0;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int n,q;
vi graph[200002];
int vis[200002];
int cnt=0;
void dfs(int t)
{
    vis[t]=1;
    ++cnt;
    for(auto x:graph[t])
    {
        if(vis[x]==0)
        {
            dfs(x);
        }
    }
}
void solve()
{
   cin>>n>>q;
   memset(vis,0,sizeof(vis));
   rep(i,0,q)
   {
    int x,y;
    cin>>x>>y;
    graph[x].pb(y);
    graph[y].pb(x);
   }
   if(q==0)
   {
    cout<<1;return;
   }
   int mx=0;
   rep(i,1,n+1)
   {
    cnt=0;
    if(vis[i]==0)
    {
        dfs(i);
    }
     mx=max(mx,cnt);
   }
   cout<<mx;




}

signed main()
{
        FIO
       
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 22472
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main(){
    IOS;
    in n,m;
    while(cin >> n >> m and (n+m)){
        in ans = 0;
        vector<in> a,comb;
        a.pb(0);
        rep(i,0,n){
            in x;
            cin >> x;
            a.pb(x);
        }
        rep(i,0,sz(a)){
            rep(j,i,sz(a)){
                comb.pb(a[i]+a[j]);
            }
        }
        sort(all(comb));
        rep(i,0,sz(comb)){
            auto it = upper_bound(all(comb),m-comb[i]);
            if(it != comb.begin()){
                it--;
                ans = max(ans,*it+comb[i]);
            }
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 10812
#include <iostream>

long long gcd(long long a, long long b) // 最大公約数
{
    if (a < b) {return gcd(b, a);}

    long long r = a % b;
    while (r != 0)  {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

long long lcm(long long a, long long b)
{
    long long val = a * b;
    val /= gcd(a, b);

    return val;
}

int main(int argc, char *argv[])
{
    long long a, b, c, d;
    long long ans;

    std::cin >> a >> b >> c >> d;
    a--;

    ans  = b - a;
    ans -= ((b / c) + (b / d) - (b / lcm(c, d))) 
         - ((a / c) + (a / d) - (a / lcm(c, d)));

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
void swap(int *,int *);

int main(){
  int i,j,n,A[100],c=0,mini;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n-1;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(A[j] < A[mini]){
	mini=j; 
      }
    }
    if(A[mini]<A[i])c++;
    swap(&A[i],&A[mini]);
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}

void swap(int *a,int *b){
  int t;
  t=*a;
  *a=*b;
  *b=t;
}

Measured memory_bytes: 604
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def solve():
    N = int(readline())
    if N == 0:
        return False
    mi = su = 0
    ans = -10**9
    for i in range(N):
        a = int(readline())
        su += a
        ans = max(ans, su - mi)
        mi = min(su, mi)
    print(ans)
    return True
while solve():
    ...



Measured memory_bytes: 5612
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int k = scan.nextInt();
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = 0;
    for(int i = a; i <= b; i++){
      if(i % k == 0){
        System.out.println("OK");
        break;
      }
      c = i;
    }
    if(c == b)
      System.out.println("NG");
  }
}
    
    


Measured memory_bytes: 35708
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    LL X, K, D;
    cin >> X >> K >> D;

    LL ans = abs(X);
    if(abs(X)/D > K){
        FOR(i,0,K){
            ans -= D;
        }
        cout << ans << endl;
        return 0;
    }

    LL count_to_zero = abs(X)/D;
    FOR(i,0,count_to_zero){
        ans -= D;
    }

    LL left_count = K - count_to_zero;
    if(left_count%2==0){
        cout << ans << endl;
    }else{
        cout << abs(ans - D) << endl;
    }
    return 0;

}

Measured memory_bytes: 3632
module mod_t_list
  implicit none
  type :: t_list
    integer :: vol
    integer, pointer :: arr(:)
  end type t_list
  private
  public :: t_list, init_list, release_list, push_back
  public :: pop_back, poll_back, get_at, size_of_list
contains
  subroutine init_list(list)
    implicit none
    type(t_list), intent(inout) :: list
    list%vol = 0
    nullify(list%arr)
    allocate(list%arr(1))
    return
  end subroutine init_list
  subroutine release_list(list)
    implicit none
    type(t_list), intent(inout) :: list
    if (associated(list%arr)) deallocate(list%arr)
    return
  end subroutine release_list
  subroutine push_back(list,n)
    implicit none
    type(t_list), intent(inout) :: list
    integer, intent(in) :: n
    integer, allocatable :: tmp(:)
    if (size(list%arr).eq.list%vol) then
      allocate(tmp(list%vol))
      tmp = list%arr
      deallocate(list%arr)
      allocate(list%arr(2*list%vol))
      list%arr(1:list%vol) = tmp
      deallocate(tmp)
    end if
    list%vol = list%vol+1
    list%arr(list%vol) = n
    return
  end subroutine push_back
  function pop_back(list) result(n)
    implicit none
    type(t_list), intent(inout) :: list
    integer :: n
    n = list%arr(list%vol)
    list%vol = list%vol-1
    return
  end function pop_back
  subroutine poll_back(list)
    implicit none
    type(t_list), intent(inout) :: list
    list%vol = list%vol-1
    return
  end subroutine poll_back
  function get_at(list,i) result(n)
    implicit none
    type(t_list), intent(in) :: list
    integer, intent(in) :: i
    integer :: n
    n = list%arr(i)
    return
  end function get_at
  function size_of_list(list) result(s)
    implicit none
    type(t_list), intent(in) :: list
    integer :: s
    s = list%vol
    return
  end function size_of_list
end module mod_t_list
program crossing
  use mod_t_list
  implicit none
  type(t_list) :: ilist(0:450), jlist(0:450)
  integer :: n, m, i, j, s
  s = 0
  read(*,*) n
  m = (nint(sqrt(8.d0*real(n,8)+1.d0))-1)/2
  if (n.ne.m*(m+1)/2) then
    write(*,'(a)') "No"
    stop
  end if
  do i = 0, 450
    call init_list(ilist(i))
    call init_list(jlist(i))
  end do
  write(*,'(a)') "Yes"
  write(*,'(i0)') m+1
  s = 0
  write(*,'(i0)',advance='no') m
  do i = 1, m
    do j = 1, i
      call push_back(ilist(i),s+j)
      if (j.ne.i) call push_back(jlist(j),s+j)
    end do
    s = s+i
    write(*,'(x,i0)',advance='no') s
  end do
  write(*,*)
  do i = 1, m
    write(*,'(i0)',advance='no') m
    do j = 1, size_of_list(ilist(i))
      write(*,'(x,i0)',advance='no') get_at(ilist(i),j)
    end do
    do j = 1, size_of_list(jlist(i))
      write(*,'(x,i0)',advance='no') get_at(jlist(i),j)
    end do
    write(*,*)
  end do
  do i = 0, 450
    call release_list(ilist(i))
    call release_list(jlist(i))
  end do
  stop
end program crossing

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  ll N;
  cin >> N;
  int ans = 11;
  rep2(i,1,(int)sqrt(N)+1){
    if (N%i ==0) {
      ll B = N / i ;
      int f;
      if(B >= 1e9){
        f = 10;
      }else if(B >= 1e8){
        f = 9;
      }else   if(B >= 1e7){
        f = 8;
      }else if(B >= 1e6){
        f = 7;
      }else if(B >= 1e5){
        f = 6;
      }else if(B >= 1e4){
        f = 5;
      }else if(B >= 1e3){
        f = 4;
      }else if(B >= 1e2){
        f = 3;
      }else if(B >=10){
        f = 2;
      }else{
        f =1;
      }
      ans = min(ans,f);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range, std.algorithm;

void main() {
  auto N = readln.chomp.to!int;
  auto K = readln.chomp.to!int;
  auto X = readln.chomp.to!int;
  auto Y = readln.chomp.to!int;

  if (N < K) {
    writeln(N * X);
  } else {
    writeln(K * X + (N - K) * Y);
  }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;
const ull BASE = 1e9 + 7;

int n, k;
int d[10];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    rep(i, k) cin >> d[i];
    int ans = 0;
    rep2(i, n, n + 1000000) {
        string si = to_string(i);
        bool ok = true;
        rep(j, si.length()) {
            rep(l, k) {
                if (si[j] - '0' == d[l]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import cmath
a, b, h, m = map(int, input().split())

t = h * 60 + m
th_a = ((0.5 * t) / 360.0) * 2 * cmath.pi
th_b = ((6.0 * t) / 360.0) * 2 * cmath.pi

za = cmath.rect(a, th_a)
zb = cmath.rect(b, th_b)

c = abs(za - zb)
print(c)


Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
int N;
int M;
int L[100000];
int R[100000];
int main(){
  int res;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<M;Lj4PdHRW++){
      rd(L[Lj4PdHRW]);
      rd(R[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(M==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = R[0];
      for(KL2GvlyY=1;KL2GvlyY<M;KL2GvlyY++){
        Q5VJL1cS = min_L(Q5VJL1cS, R[KL2GvlyY]);
      }
    }
    {
      int cTE1_r3A, e98WHCEY;
      if(M==0){
        cTE1_r3A = 0;
      }
      else{
        cTE1_r3A = L[0];
        for(e98WHCEY=1;e98WHCEY<M;e98WHCEY++){
          cTE1_r3A = max_L(cTE1_r3A, L[e98WHCEY]);
        }
      }
      res =Q5VJL1cS-cTE1_r3A+ 1;
    }
  }
  if(res < 0){
    res = 0;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// int N, M, L[1d5], R[1d5];
// {
//   int res;
//   rd(N,M,(L,R)(M));
//   res = min(R(M)) - max(L(M)) + 1;
//   if(res < 0) res = 0;
//   wt(res);
// }


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

#define N 100005
#define lgN 18
#define LL long long int
const int MOD = 1e9 + 7;

vector<int> g[5];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int a, b, i;
	for (i=0;i<3;i++) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (i=1;i<=4;i++) if ((int)g[i].size() > 2) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	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];
    }
    
    for(int i = 0;i < N;i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for(int k = 0;k < N;k++){
            cout << A[k];
            if(k == N - 1){
                cout << endl;
                break;
            }
            cout << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3076
'''
Introduction to Heuristics Contest
A - AtCoder Contest Scheduling
'''

def main():
    # 本番テストケースは365
    D = int(input())

    # コンテストタイプごとの満足度の下がりやすさ
    C = list(map(int, input().split()))

    # 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
    S = []
    for _ in range(D):
        sday = list(map(int, input().split()))
        S.append(sday)

    ''' てきとう '''
    import random
    for i in range(D):
        tmp = random.randint(1, 26)
        print(tmp)

main()

Measured memory_bytes: 10012
#include<stdio.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];
    rep(i, n) scanf("%d", a+i);
    ll x = 1000;
    rep(i, n-1){
        int s = a[i];
        int t = a[i+1];
        if(s<t){
            ll k = x/s; // number of stock
            x %=s;
            x += k*t;
        }
    }
    printf("%lld\n", x);
    return 0;
}

Measured memory_bytes: 1700
from collections import deque
N,*L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
  a,b = L[2*i],L[2*i+1]
  dic[a].append(b)
  dic[b].append(a)
q = deque([1])
dist = [-1]*(N+1)
dist[1] = 0
while q:
  p = q.popleft()
  for v in dic[p]:
    if dist[v]==-1:
      q.append(v)
      dist[v] = dist[p]+1
u = max(range(1,N+1),key=lambda x:dist[x])
q = deque([u])
dist = [-1]*(N+1)
dist[u] = 0
while q:
  p = q.popleft()
  for v in dic[p]:
    if dist[v]==-1:
      q.append(v)
      dist[v] = dist[p]+1
M = max(dist)
if M%3==1:
  print('Second')
else:
  print('First')

Measured memory_bytes: 52228
#include<bits/stdc++.h>
#define LL long long
const int MOD=1e9+7;
using namespace std;
string str1,str2;
int main() {
    int n;
    scanf("%d",&n);
    cin>>str1>>str2;
 
    LL res=1;
    int i=0;
    int sta;
    if(str1[i]==str2[i]){
        res*=3;
        i++;
        sta=1;
    }
    else{
        res*=6;
        i+=2;
        sta=2;
    }
 
    while(i<n){
        if(str1[i]==str2[i]){
            if(sta==1)
                res=res*2%MOD;
            i++;
            sta=1;
        }
        else{
            if(sta==1)
                res=res*2%MOD;
            else
                res=res*3%MOD;
            i+=2;
            sta=2;
        }
    }
 
    printf("%lld\n",res);
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll m;
	cin >>n >>m;
	VL a(n), sm(n+1);
	rep(i, n) cin >>a[i];
	sort(all(a));
	rep(i, n) sm[i+1] = sm[i] + a[i];
	
	auto f=[&](ll md){
		ll ct = 0, wt = 0;
		repr(i, n-1, 0){
			int ps = lower_bound(all(a), md - a[i]) - a.begin();
			ct += n - ps;
			wt += (sm[n] - sm[ps]) + a[i] * (n-ps);
		}
		return make_pair(ct, wt);
	};
	
	ll lf = 0, rg=1e7;
	while(rg - lf >1){
		ll md = (rg + lf) >> 1;
		auto cr = f(md);
		//dbg(md, cr.first);
		( cr.first >= m? lf: rg ) = md; 
	}
	ll ct, ans; tie(ct, ans) = f(lf);
	if(ct > m) ans -= lf * (ct - m);
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K,S;
  cin >> K >> S;
  long long count = 0;
  for (int i = 0; i <= K; i++) {
    if (S-i >= K){
      count += max(2*K + i + 1 - S,0);
    }
    else {
      count += max(S - i + 1,0);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3620
n,k = map(int,input().split(" "))
r,s,p = map(int,input().split(" "))
ar = list(input())
count = 0
for i in range(n):
    if i - k >= 0 and ar[i] == ar[i-k]:
        ar[i] = "."
    else:
        if ar[i] == 'r':
            count += p
        elif ar[i] == 's':
            count += r
        elif ar[i] == 'p':
            count += s
print(count)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[20],t[20];
	cin>>s>>t;
	int x=strlen(s),f=0;
	for(int i=0;i<x;i++)
	{
		if(s[i]!=t[i])
		f=1;
	}
	if(f==1)
	printf("No");
	else
	printf("Yes");
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <stdlib.h>
#include <time.h> 
#include <assert.h>

#define nmax 500010
#define eps 1e-8
#define MOD 1000000007

#define P1 25671
#define P2 191
#define MOD1 666013
#define MOD2 1000000007
#define B_SIZE 315

#define SZ(x) ((int)(x.size()))

#define fst first
#define snd second
#define pb push_back
#define mp make_pair

using namespace std;

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

typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int n;
double dp[3010][3010]; // dp[i][j] -> probability of having i tails in first j positions
double p[3010];

int main()
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) scanf("%lf", &p[i]); // p[i] -> head probability

	int max_tails = n / 2;

	dp[0][1] = p[1];
	dp[1][1] = 1 - p[1];

	for (int i = 2; i <= n; i++) {

		// put head
		for (int j = 0; j <= max_tails; j++) dp[j][i] = dp[j][i] + dp[j][i - 1] * p[i];

		// put tails
		for (int j = 1; j <= max_tails; j++) dp[j][i] = dp[j][i] + dp[j - 1][i - 1] * (1 - p[i]);
	}

	double sum = 0;

	for (int i = 0; i <= max_tails; i++) sum += dp[i][n];

	printf("%.10lf", sum);

	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    int n, w;
    cin >> n >> w;

    V<int> v(n), o(n);
    rep(i, n) cin >> v[i] >> o[i];

    V<int> dp(w + 1, 0);
    rep(i, n) {
        for (int j = w - o[i]; j >= 0; j--) {
            dp[j + o[i]] = max(dp[j + o[i]], dp[j] + v[i]);
        }
    }
    int ans = 0;
    rep(i, w + 1) { ans = max(dp[i], ans); }
    cout << ans << endl;
}



Measured memory_bytes: 3260
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  long long a,sum,b[65000],ans;
  while(cin >> n,n!=0){
    sum = 0;
    for(int i=0;i<n;i++){
      cin >> a;
      sum += a;
    }
    for(int i=0;i<n-1;i++) cin >> b[i];
    sort(b,b+n);
    reverse(b,b+n);
    ans = sum*n;
    for(int i=1;i<n;i++){
      sum += b[i-1];
      ans = max(ans,sum*(n-i));
    }
    cout << ans << endl;
  }
  return(0);
}



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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <string> s;
    for (int i = 0; i < n; i++) {
        string t;
        cin >> t;
        s.push_back(t);
    }
    vector <int> rem(n, 0);
    for (int i = 0; i < n; i++) {
        int x = count(s[i].begin(), s[i].end(), '.');
        if (x == m) {
            rem[i] = true;
        }
    }
    vector <string> a;
    for (int i = 0; i < n; i++) {
        if (!rem[i]) {
            a.push_back(s[i]);
        }
    }
    vector <int> musor(m, 0);
    for (int i = 0; i < m; i++) {
        int x = 0;
        for (int j = 0; j < n; j++) {
            x += (s[j][i] == '.');
        }
        if (x == n) {
            musor[i] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        bool any = false;
        for (int j = 0; j < m; j++) {
            if (rem[i] || musor[j]) {
                continue;
            }
            any = 1;
            cout << s[i][j];
        }
        if (any) {
            cout << '\n';   
        }
    }
    return 0;
}

Measured memory_bytes: 256