akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
//#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;



int main(void){
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size() <= k) cout<<s<<endl;
    else{
        rep(i,k) cout<<s[i];
        cout<<"..."<<endl;
    }
}

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

typedef long long int ll;

ll m = 1000000007;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;

    ll sum = 0;

    vector<ll>v(n);
    for(ll &x:v)cin>>x,sum+=x;

    ll ans = 0;

    for(int i = 0; i < n; i++){
        sum = sum - v[i];

        ans = (ans%m + (sum%m * v[i]%m)%m)%m;

    }

    cout<<ans;

    return 0;

}



Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  if(n==1){
    if(k&1) cout<<as[0];
    cout<<endl;
    return 0;
  }

  const Int MAX = 2e5+100;
  vector<Int> nxt(MAX);
  for(Int i=n-1;i>=0;i--) nxt[as[i]]=i;

  vector<Int> bs(n);
  for(Int i=n-1;i>=0;i--){
    bs[i]=nxt[as[i]];
    nxt[as[i]]=i;
  }

  vector<Int> cs(n,-1),ds(n,0);
  for(Int i=0;i<n;i++){
    MFP([&](auto dfs,Int v)->Int{
          if(~cs[v]) return cs[v];
          if(bs[v]+1==n){
            ds[v]=(v==n-1);
            return cs[v]=0;
          }
          if(bs[v]<=v){
            ds[v]=0;
            return cs[v]=(bs[v]+1)%n;
          }
          cs[v]=dfs(bs[v]+1);
          ds[v]=ds[bs[v]+1];
          return cs[v];
        })(i);
    //cout<<i<<":"<<cs[i]<<endl;
  }
  //cout<<"UKU"<<endl;
  {
    Int pos=0;
    for(Int i=0;i+1<k;i++){
      Int pre=pos;
      pos=cs[pos];
      if(pos==0){
        k%=(i+1+ds[pre]);
        //cout<<(i+1+(pre==n-1))<<endl;
        break;
      }
    }
  }

  if(k==0){
    cout<<endl;
    return 0;
  }

  Int pos=0;
  for(Int i=0;i+1<k;i++) pos=cs[pos];
  //assert(pos!=0);

  vector<Int> cnt(MAX,0);
  vector<Int> vs;
  for(Int i=pos;i<n;i++){
    if(cnt[as[i]]){
      while(cnt[as[i]]){
        cnt[vs.back()]--;
        vs.pop_back();
      }
    }else{
      vs.emplace_back(as[i]);
      cnt[vs.back()]++;
    }
  }

  for(Int i=0;i<(Int)vs.size();i++){
    if(i) cout<<" ";
    cout<<vs[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 16640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	n := oneInt()
	as := scanNums(n)

	ans := calc(as)

	fmt.Println(ans)
}

func calc(as []int) int {
	minAbs := abs(as[0])
	cntMinus := 0
	sum := 0
	for i := 0; i < len(as); i++ {
		if as[i] < 0 {
			cntMinus++
		}
		sum += abs(as[i])

		minAbs = min(minAbs, abs(as[i]))
	}

	if cntMinus%2 != 0 {
		return sum - 2*minAbs
	} else {
		return sum
	}
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}

func nextWord(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanNums(n int) (nums []int) {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		s := nextWord(sc)
		num, _ := strconv.Atoi(s)
		nums = append(nums, num)
	}
	return nums
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int ans = 0;
  int x = 0;
  int N; cin >> N;
  string s; cin >> s;
  REP(i, s.size()) {
    if (s[i] == 'I') x++;
    if (s[i] == 'D') x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

q = int(input())
for _ in range(q):
    query = list(map(int, input().split()))
    flag = query[0]
    start = query[1]
    end = query[2]
    if flag == 0:
        print(min(num[start:end]))
    elif flag == 1:
        print(max(num[start:end]))



Measured memory_bytes: 5624
MOD = 10**9 + 7
#puts MOD
count = gets.to_i
numbers = gets.chomp.split.map {|n| n.to_i % MOD}

result = 0
prev_sum = numbers.sum
count.times do
  current = numbers.shift
  current_sum = prev_sum = prev_sum - current
  # sum = 0 
  # numbers.each do |n|
    # result += current * n
  # end
  sum = current_sum * current
  result += sum
end
  
puts result % MOD


Measured memory_bytes: 35736
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
int mass[100];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<2*n;i++)
        scanf("%d",mass+i);
    sort(mass,mass+2*n);
    int ans=0;
    for(int i=0;i<2*n;i+=2)
        ans+=mass[i];
    printf("%d",ans);
}

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

using namespace std;

using ll = long long;

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

    int h, w, d;
    cin >> h >> w >> d;

    vector<vector<int>> a(h, vector<int>(w));
    vector<int> x(h * w + 1), y(h * w + 1);
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            y[a[i][j]] = i;
            x[a[i][j]] = j;
        }

    vector<int> sum(h * w + 1);
    for (int i = 1; i + d <= h * w; ++i)
        sum[i + d] += sum[i] + abs(x[i] - x[i + d]) + abs(y[i] - y[i + d]);

    int q, l, r;
    cin >> q;
    while (q--) {
        cin >> l >> r;
        cout << sum[r] - sum[l] << '\n';
    }

    return 0;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var HW = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var H = HW[0];
        var W = HW[1];
        var hw = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var h = hw[0];
        var w = hw[1];
        Console.WriteLine(H * W - H * w - h * W + h * w);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main(){
  int N;
  cin>>N;
  vector<int> p(N);
  for (int i=0;i<N;i++) cin>>p[i];
  int sum=0;
  sort(p.begin(),p.end(),greater<int>());
  for (int i=0;i<N;i++){
    if (i==0) sum+=p[i]/2;
    else sum+=p[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n, k;
	cin >> n >> k;
	vi h(n);
	int ans = 0;
	rep(i, n) {
		cin >> h[i];
		if (h[i] >= k) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(){

	int res=0, tmp=0;
	string str;
	
	while(cin>>str, !cin.eof()){
		
		tmp = 0;

		for(int i=0; i<str.size(); ++i){
			
			if('0'<=str[i]&&str[i]<='9'){
				tmp = tmp*10 + (int)(str[i]-'0');
			}
			else{
				res += tmp;
				tmp = 0;
			}
		}

		res += tmp;
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
int n,m,a[maxn],b[maxn],c[maxn],fa[maxn];
inline int find(int n){return fa[n]==n?n:fa[n]=find(fa[n]);}
int main(){
	read(n);
	rep(i,1,n)fa[i]=i;
	rep(i,1,n)read(a[i]),a[0]^=a[i];
	rep(i,1,n)read(b[i]),b[0]^=b[i];
	rep(i,1,n)if(a[i]!=b[i])a[++m]=a[i],b[m]=b[i];
	n=m;
	rep(i,0,n){
		c[i]=a[i],c[i+n+1]=b[i];
	}sort(c,c+1+n);sort(c+1+n,c+n+n+2);
	rep(i,0,n)if(c[i]!=c[n+1+i]){
		puts("-1");
		return 0;
	}m=unique(c,c+n+1)-c-1;
	rep(i,0,n){
		a[i]=lower_bound(c,c+m+1,a[i])-c;
		b[i]=lower_bound(c,c+m+1,b[i])-c;
		fa[find(a[i])]=find(b[i]);
	}
	int ans=n;
	// printf("dasdsadsa%d\n",ans);
	rep(i,0,m)ans+=find(i)==i;
	cout<<ans-1;
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){ 
 ll sum = 0LL;
 ll N,K; cin >> N >> K; vector<ll> A(N);
 for(ll i = 0LL; i < N; i++){ cin >> A[i]; sum += A[i];}
  set<ll> s;
 for(ll i = 1LL; i*i <= sum; i++){ 
   if(sum % i == 0LL){ s.insert(i); s.insert(sum/i);}}
  ll ans = 1LL;
  for(auto ne : s){
    
    vector<ll> rem(N);
    for(ll i = 0LL; i < N; i++){ rem[i] = A[i]%ne;}
    
    sort(rem.begin(),rem.end());
    
    ll lsum = 0LL; ll rsum = 0LL;
    for(ll i = 0; i < N; i++){ rsum += ne-rem[i];}
    ll cnt = 1LL << 60;
    for(ll i = 0LL; i < N; i++){
      lsum += rem[i]; rsum -= ne-rem[i];
      if(lsum != rsum){ continue;}
      cnt = min(cnt , lsum);
    }
    
    if(cnt <= K){ ans = max(ans, ne);}
  }
  
  cout << ans << endl; return 0;}
    
    
                                           
           
           

  
  

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

#define MOD (1000 * 1000 * 1000 + 7)
typedef long long ll;
typedef long double ld;

int main() {
    ll n, k, x, y;
    cin >> n >> k >> x >> y;

    ll sum = 0;
    if(n > k) {
        ll b = n - k;
        sum = k * x + b * y;
    } else {
        sum = n * x;
    }
   
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
N = input()
K = int(input())

l = len(N)

dp = [[[0]*(K+1) for _ in range(2)] for _ in range(l)]
dp[0][0][1] = 1
dp[0][1][1] = int(N[0]) - 1
dp[0][1][0] = 1
#print(dp[0])

for i in range(1,l):
  for j in range(K+1):
    if int(N[i]) == 0:
      if j > 0:
        dp[i][0][j] = dp[i-1][0][j]
        dp[i][1][j] += 9*dp[i-1][1][j-1]
    else:
      if j > 0:
        dp[i][0][j] = dp[i-1][0][j-1]
        dp[i][1][j] += dp[i-1][0][j-1]*(int(N[i])-1) + 9*dp[i-1][1][j-1]
      dp[i][1][j] += dp[i-1][0][j]
    dp[i][1][j] += dp[i-1][1][j]

  #print(dp[i])
print(dp[l-1][0][K]+dp[l-1][1][K])

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

int main() {
  int H, W;
  cin >> H >> W;
  
  char P[H+2][W+2];
  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++) {
      if (i == 0 || j == 0 || i == H+1 || j == W+1) {
        P[i][j] = '#';
      } else {
        cin >> P[i][j];
      }
    }
  }
  
  for (int i=0; i<H+2; i++) {
    for (int j=0; j<W+2; j++) {
      cout << P[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define lli long long int 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> a;
    vector<int> b;
    vector<int> c;
    int n;
    cin>>n;
    a.resize(n);
    b.resize(n);
    c.resize(n-1);
    int i,j;
    int ans = 0;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        cin>>b[i];
    for(i=0;i<(n-1);i++)
        cin>>c[i];
    for(i=0;i<n;i++)
    {
        ans = ans + b[a[i]-1];
        if(i>0)
        {
            if(a[i]==(a[i-1]+1))
                ans = ans + c[a[i]-2];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
value = input()
count = len(value)
hitachi = ['hi', 'hihi', 'hihihi', 'hihihihi', 'hihihihihi']

if count % 2 != 0:
  print('No')
else:
  if value in hitachi:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3060
def leap(y)
  if y % 400 == 0
    1
  elsif y % 100 == 0
    0
  elsif y % 4 == 0
    1
  else
    0
  end
end

$month = [0, 31, [28, 29], 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def add_day(y, m, y1, m1, d1, y2, m2, d2)
  if y1 == y2 && m1 == m2
    d2 - d1
  elsif m == m1 && y == y1
    if m == 2
      $month[2][leap(y)] - d1 + 1
    else
      $month[m] - d1 + 1
    end
  elsif m == m2 && y == y2
    d2 - 1
  else
    if m == 2
      $month[2][leap(y)]
    else
      $month[m]
    end
  end
end

loop do
  data = gets.chomp.split.map(&:to_i)
  break if data.all?{ |x| x == -1 }

  y1, m1, d1, y2, m2, d2 = data
  count = 0
  
  y1.upto(y2) do |y|
    if y1 == y2
      m1.upto(m2) { |m| count += add_day(y, m, *data) }
    elsif y1 == y
      m1.upto(12) { |m| count += add_day(y, m, *data) }
    elsif y2 == y
      1.upto(m2) { |m| count += add_day(y, m, *data) }
    else
      1.upto(12) { |m| count += add_day(y, m, *data) }
    end
  end
  puts count
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<vector<int>> t(n,vector<int>(n,-1));
    rep(i,n){
        int a;cin>>a;
        rep(j,a){
            int x,y;cin>>x>>y;x--;
            t[i][x]=y;
        }
    }
    int res=0;
    for(int i=0;i<(1<<n);i++){
        bool jud=true;
        rep(j,n){
            if((i&(1<<j))==0)continue;
            rep(k,n){
                if(t[j][k]==0&&(i&(1<<k))!=0){
                    jud=false;
                    break;
                }else if(t[j][k]==1&&(i&(1<<k))==0){
                    jud=false;
                    break;
                }
            }
        }
        int buf=0;
        rep(j,n)if(i&(1<<j))buf++;
        if(jud){
            //cout<<i<<endl;
            chmax(res,buf);
        }
    }
    cout<<res<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    vector<vi> ans(h+2,vi(w+2,0));
    rep(i,h)rep(j,w){
        ans[i+1][j+1]=-1;
    }
    int idx=0;
    int x=1,y=1;
    int dx[] = {1,0,-1,0};
    int dy[] = {0,1,0,-1};
    int cnt=0;
    while(idx<n){
        ans[y][x]=idx+1;
        a[idx]--;
        if (a[idx]==0) idx++;
        y+=dy[cnt]; x+=dx[cnt];
        if (ans[y][x]!=-1){
            y-=dy[cnt]; x-=dx[cnt];
            cnt = (cnt+1)%4;
            y+=dy[cnt]; x+=dx[cnt];
        }
    }
    rep(i,h){
        rep(j,w){
            if (j>0) cout<<" ";
            cout<<ans[i+1][j+1];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

int main(){
	int x1,y1,x2,y2,n,xf=1,yf=1,x,y;
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	if(x1>x2)swap(x1,x2),xf=-1;
	if(y1>y2)swap(y1,y2),yf=-1;
	vector<pair<int,int>>v;
	for(int i=0;i<n;i++){
		scanf("%d%d",&x,&y);
		if(x1<=x&&x<=x2 && y1<=y&&y<=y2)v.emplace_back(x*xf,y*yf);
	}
	sort(v.begin(),v.end());
	vector<int>d(v.size(),1<<30);
	for(auto &e:v)n=e.second,*lower_bound(d.begin(),d.end(),n)=n;
	n=lower_bound(d.begin(),d.end(),1<<30)-d.begin();
	printf("%.9f\n",100.0*(x2-x1+y2-y1)-20*n+5*(n+(n>=min(x2-x1,y2-y1)+1))*3.14159265358979323846);
}

Measured memory_bytes: 2544
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	while(cin>>a>>b)
	{
		if(a==0&&b==0) break;
		for(;a;a--)
		{
			for(int i=b;i;i--) cout<<"#";
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3124
package main

import (
	"fmt"
	"sort"
)

type Robot struct {
	Place  int
	Length int
	Min int
	Max int
}

type RobotSort []Robot

func (p RobotSort) Len() int {
	return len(p)
}

func (p RobotSort) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p RobotSort) Less(i, j int) bool {
	return p[i].Max < p[j].Max
}

func main() {
	var iCount int
	fmt.Scanf("%d", &iCount)

	var robots RobotSort

	for i := 0; i < iCount; i++ {
		var robot, length int
		fmt.Scanf("%d %d", &robot, &length)

		robots = append(robots, Robot{
			Place: robot,
			Length: length,
			Min: robot - length,
			Max: robot + length,
		})
	}

	sort.Sort(robots)

	ret := 0
	cur := -1000000000
	for _, v := range robots {
		if  cur <= v.Min {
			ret++
			cur = v.Max

		}
	}
	fmt.Printf("%d\n", ret)
}


Measured memory_bytes: 12928
#include <stdio.h>
#include <complex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;

P ps[1024];

int main() {
    ps[0] = P(1, 0);
    rep (i, 1024) if (i) {
        ps[i] = ps[i-1] + P(0, -1) * -ps[i-1] / abs(ps[i-1]);
    }
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == -1) return 0;
        n--;
        printf("%.2f\n", ps[n].real());
        printf("%.2f\n", ps[n].imag());
    }
}

Measured memory_bytes: 0
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    dic = {}
    for i in range(n):
        s = "".join(sorted(input()))
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    ans = 0
    for k,v in dic.items():
        ans += v * (v-1) //2 # vC2
    print(ans)
if __name__ == '__main__':
  main()


Measured memory_bytes: 17852
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A=[]
for i in range (N):
	A.append(list(map(int,input().split())))
tmp=0
ans=0


for i in range (N):
	tmp=0
	for j in range (M):
		tmp+=A[i][j]*B[j]
	tmp+=C
	if tmp>0:
		ans+=1
print(ans)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc152/tasks/abc152_a

#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;

    if(a == b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
int MOD=1e9+7;
using namespace std;
vector<vector<int>> vec;
vector<vector<int>> dp;
int h,w;
void rec(int y,int x){
    if(vec[y][x]=='#'){
        return;
    }
    if(y+1<h){
        if(vec[y+1][x]=='.'){
            dp[y+1][x] += dp[y][x];
            dp[y+1][x] %= MOD;
        }
    }
    if(x+1<w){
        if(vec[y][x+1]=='.'){
            dp[y][x+1] += dp[y][x];
            dp[y][x+1] %=MOD;
        }
    }
}
int main(){
    cin >> h >> w;
    vec.resize(h,vector<int>(w));
    dp.resize(h,vector<int>(w));
    for(int i=0;i<h;i++){
        string s;
        cin >> s;
        for(int j=0;j<w;j++){
            vec[i][j]=s[j];
        }
    }
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            rec(i,j);
        }
    }
    cout<<dp[h-1][w-1]%MOD<<endl;
    
}

Measured memory_bytes: 8192
N,M = map(int,input().split())
a_g=[];b_g=[]
for i in range(N):
  a_g.append(list(input()))
for i in range(M):
  b_g.append(list(input()))

for i in range(N-M+1):
  for j in range(N-M+1):
    flag=1
    for k in range(M):
      for l in range(M):
        if a_g[k+i][l+j] != b_g[k][l]:
          flag=0
          break
    if flag:
      print("Yes");exit()
print("No")

Measured memory_bytes: 42352
//Link : https://atcoder.jp/contests/agc013/tasks/agc013_b
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define N 1000005

bool vis[N];
int ret[N];
void solve() {
  int m,k;scanf("%d %d ", &m,&k);
  int r = (1<<m)-1;


  if(k<=r) {
    if(k==0) {
      for(int i=0;i<=r;++i) {
        printf("%d %d ", i,i);
      }
      putchar('\n');
      return;
    } if(m==1) {
      printf("-1\n");
      return;
    } else {
      int check = k&(k-1);
      vector<int> go;
      vis[k] = true;
      if(check==0) {
        //2^x
        go.push_back(r);
        vis[r] = true;
        for(int i=0;i<m;++i) {
          if( (k&(1<<i)) ==0) {
            go.push_back(1<<i);
            vis[1<<i] = true;
          }
        }
      } else {
        for(int i=0;i<m;++i) {
          if( (k&(1<<i)) ) {
            go.push_back(1<<i);
            vis[1<<i] = true;
          }
        }
      }
      int pos = 0;

      for(int i=0;i<go.size();++i) {
        ret[pos++] = go[i];
      }
      for(int i=0;i<=r;++i) {
        if(!vis[i]) {
          ret[pos++] = i;
        }
      }
      ret[pos++] = k;
      for(int i=r;i>=0;--i) {
        if(!vis[i]) {
          ret[pos++] = i;
        }
      }
      for(int i=go.size()-1;i>=0;--i) {
        ret[pos++] = go[i];
      }

      ret[pos++] = k;
      for(int i=0;i<pos;++i) {
        printf("%d ", ret[i]);
      }
      putchar('\n');
    }
  } else {
    printf("-1\n");
  }
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>

int main()
{
	long long a;
	long long b;
	long long c;
	
	scanf("%lld%lld%lld", &a, &b, &c);
	if (c - a - b < 0)
		printf("No\n");
	else if (4*a*b < (c - a - b)*(c - a - b))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int K, S;
  cin >> K >> S;

  int ans = 0;
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
      if(S -x - y >= 0 && S - x - y <= K){
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  val NIL = -1

  class Node(var parent:Int = NIL,var left:Int = NIL,var right:Int = NIL) { }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = (0 until n).map(_=>new Node).toArray
    val depth = new Array[Int](n)

    for(i<-0 until n) {
      val s = readLine.split(" ").map(_.toInt)
      val id = s(0)
      val k = s(1)
      var prev = 0
      for(j<-2 until k+2) {
        if(j==2) tree(id).left = s(j)
        else tree(prev).right = s(j)
        prev = s(j)
        tree(s(j)).parent = id
      }
    }

    def getDepth(node:Int,d:Int):Unit = {
      depth(node) = d
      if( tree(node).right != NIL ) getDepth(tree(node).right, d)
      if( tree(node).left != NIL ) getDepth(tree(node).left, d+1)
    }

    val root = tree.indexWhere(_.parent == NIL)
    getDepth(root, 0)

    for(i<-0 until n) {
      print("node " + i + ": ")
      print("parent = " + tree(i).parent + ", ")
      print("depth = " + depth(i) + ", ")
      if( tree(i).parent == NIL ) print("root, ")
      else if( tree(i).left == NIL ) print("leaf, ")
      else print("internal node, ")

      print("[")

      var node = tree(i).left
      val a = new ArrayBuffer[Int]
      while(node!=NIL) {
        a.append(node)
        node = tree(node).right
      }
      print(a.mkString(", "))
      println("]")
    }
  }
}

Measured memory_bytes: 283432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<deque>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<cassert>
#define F first
#define S second
#define INF (1<<28)

using namespace std;
typedef pair<int,int> P;
typedef pair<string,int> SI;
int n,m,k,d;

class Pox
{
public:
  int p,cost,bit;
  Pox(){}
  Pox(int p,int cost,int bit):p(p),cost(cost),bit(bit){}
};

int toIndex(string s)
{
  if(s[0] == 'H')
    return 0;
  if(s[0] == 'D')
    return 1;
  if(s[0] == 'C')
    return 1+(s[1]-'0');//2,3,4,5,6,7
  if(s[0] == 'L')
    return 7+(atoi)(s.substr(1,s.length()-1).c_str());
  assert(false);
}

int main()
{
  
  while(cin >> m >> n >> k >> d,(n|m|k|d))
    {

      vector<int> calorie;
      calorie.resize(m);
      for(int i=0;i<m;i++)
	cin >> calorie[i];
      vector<vector<P> > G;
      G.resize(2+6+100+1);
      for(int i=0;i<d;i++)
	{
	  string from,to;
	  int cost;
	  cin >> from >> to >> cost;
	  int f,t;
	  f = toIndex(from);
	  t = toIndex(to);
 
	  G[f].push_back(P(t,cost));
	  G[t].push_back(P(f,cost));
	}
      
      int mincost[127][127][127];//mincost[bit][from][to]
     for(int i=0;i<127;i++)
       for(int j=0;j<127;j++)
	 for(int k=0;k<127;k++)
	   mincost[i][j][k] = INF;

     mincost[0][0][0] = 0;
     deque<Pox> deq;
     deq.push_back(Pox(0,0,0));

     int ans = INF;

     while(!deq.empty())
       {
	 Pox pox = deq.front(); deq.pop_front();
	 int bit = pox.bit;
	 int cost = pox.cost;
	 int p = pox.p;


	 if(p == 1)
	   ans = min(ans,cost);

	 for(int i=0;i<G[p].size();i++)
	   {      
	     P pes = G[p][i];
	     int to = pes.F;
	     int d = pes.S;	     

	     if(2 <= to && to <= 7)
	       {
		 to -= 2;
		 if((bit >> to) & 1)
		   continue;

		 if(mincost[bit|(1<<to)][p][to+2] > cost + d*k - calorie[to])
		   {
		     mincost[bit|(1<<to)][p][to+2] = cost + d*k - calorie[to];
		     deq.push_back(Pox(to+2,cost+d*k-calorie[to],bit|(1<<to)));
		   }
		 continue;
	       }

	     if(mincost[bit][p][to] > cost + d*k)
	       {
		 mincost[bit][p][to] = cost + d*k;
		 deq.push_back(Pox(to,cost+d*k,bit));
	       }
	   }
       }

     cout << ans << endl;

    }
  return 0;
}

Measured memory_bytes: 9840
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
ans = 0
for i in range(N):
    A = np.array(list(map(int, input().split())))
    if np.sum(A*B) + C > 0:
        ans += 1
print(ans)

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

int main() {
  int l;

  cin >> l;

  double hen;

  hen = double(l/3);

  double hen2 = hen*hen*hen;

  cout << fixed << setprecision(10) << (double)(l*l*l)/27;

}

Measured memory_bytes: 3824
//  LINK ZADATKA: http://agc006.contest.atcoder.jp/tasks/agc006_b

#include <queue>
#include <vector>
#include <list>
#include <map>
#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 <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9

int n, x, sol[200200];
list<int>brojke;
int main(){
	sd(n); sd(x);

	if(x == 1 || x == (2*n-1)){
		printf("No\n");
		return 0;
	}
	 
	sol[n] = x;
	sol[n-1] = x-1;
	sol[n+1] = x+1;
	int broj;
	//FOR(i, 1, 2*n-1) printf("%d\n", sol[i]);
	FOR(i, 1, 2*n-1){
		 if(i < x-1 || i > x+1) brojke.PB(i);
	}

	FOR(i, 1, n-2){
		sol[i] = *brojke.begin();
		brojke.pop_front();
	}	
	
	FOR(i, n+2, (2*n-1)){
		sol[i] = *brojke.begin();	
		brojke.pop_front();
	}
	printf("Yes\n");
	FOR(i, 1, 2*n-1) printf("%d\n", sol[i]);
	return 0;
}


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

int main() {
  int n;
  while(cin >> n, n) {
    int cnt = 0;
    while(n != 1) {
      cnt++;
      if(n%2) n = 3*n + 1;
      else n /= 2;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1156
using System;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadInt;
            Console.Write("Christmas");
            while (n<25)
            {
                n++;
                Console.Write(" Eve");
            }
            Console.Write("\n");
            return;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}



Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long ll;
typedef pair<int,int> P;
const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL<<60;
int dx[2]={0,1};
int dy[2]={1,0};
int main(){
  int h,w;
  cin>>h>>w;
  char f[h][w];
  rep(i,h){
    rep(j,w) cin>>f[i][j];
  }
  int dp[h][w];
  rep(i,h) rep(j,w) dp[i][j]=inf;
  if(f[0][0]=='#') dp[0][0]=1;
  else dp[0][0]=0;
  rep(i,h){
     rep(j,w){
       rep(k,2){
          int ny=i+dy[k];
          int nx = j+dx[k];
          if(ny<h&&nx<w){
            int add=0;
            if(f[ny][nx]=='#'&&f[i][j]=='.') add++;
            dp[ny][nx]=min(dp[ny][nx],dp[i][j]+add);
          }
       }
     }
  }
  cout<<dp[h-1][w-1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, V;
  cin >> A >> V;
  ll B, W;
  cin >> B >> W;
  ll T;
  cin >> T;
  if(T*W + abs(A-B) <= T*V) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	int score[4], ans = 0;
	
	REP(i, 4) cin >> score[i];
	sort(score, score + 4, greater<int>());
	REP(i, 3) ans += score[i];
	
	REP(i, 2) cin >> score[i];
	ans += max(score[0], score[1]);
	
	cout << ans << endl;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double a,b;
    int x=0;
    cin>>a;
    for(int i=0;i<=a;i++)
    {
        if(i%2==1)
        {
            x++;
        }
    }
    b=x/a;
    cout<<b;


  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];
  bool flag = true;
  int cnt = 0;
  while (flag){
    for (int i = 0; i < N; i++){
      if (a[i] & 1) {
        flag = false;
        continue;
      }
      a[i] /= 2;
    }
    if (flag) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(long long A, long long B, long long C, long long K){

    lli sum = 0;

    sum += min(A,K);
    K-=A;
    K-=B;
    sum -= max(0LL,K);

    cout<<sum<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    func(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int s[100100];
int sa[100100];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		char t;
		cin>>t;
		if(t=='o'){
			s[i]=1;
		}else{
			s[i]=-1;
		}
	}
	
	for(int i=-1;i<2;i+=2){
		for(int j=-1;j<2;j+=2){
			sa[0]=i;
			sa[1]=j;
			for(int k=2;k<n;k++){
				sa[k]=sa[k-2]*sa[k-1]*s[k-1];
				
			}
		
		
		//cout<<s[0]*sa[1]*sa[n-1]*sa[0]<<" "<<sa[n-1]*s[n-1]*sa[0]*sa[n-2]<<endl;
		if(s[0]*sa[1]*sa[n-1]*sa[0]==1&&sa[n-1]*s[n-1]*sa[0]*sa[n-2]==1){
			for(int i=0;i<n;i++){
				if(sa[i]==1){
					cout<<'S';
				}else{
					cout<<'W';
				}
			}
			cout<<endl;
			return 0;
		}
		}
	}
	cout<<-1<<endl;
	return 0;
}
					

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int dan = 1;//何段か
  for (int i = 0;i + 1 < N;i++) {
    if (vec.at(i) > vec.at(i + 1)) {
      dan++;
    }
  }
  
  cout << dan << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
double minkov(std::vector<int>&x ,std::vector<int>&y,int size ,int n)
{
	if(n == 0){
		double max = 0;
		for(int i = 0 ; i < size ; i ++){
			if(max <= std::abs(x[i]-y[i])){
				max = std::abs(x[i]-y[i]);
			}
		}
		return max;
	}else{
		double dist= 0;
		for(int i= 0 ; i < size ; i ++){
			dist += std::pow(std::abs(x[i] - y[i]),n);
		}
		return std::pow(dist,(double)1/n);
	}
}


int main(int argc, char const *argv[])
{
	int n,temp;
	std::vector<int> x ;
	std::vector<int> y ;
	std::cin >> n;
	for(int i = 0 ; i < n ; i ++){
		std::cin >> temp;
		x.push_back(temp);
	}
	for(int i = 0 ; i < n ; i ++){
		std::cin >> temp;
		y.push_back(temp);
	}
	printf("%lf\n%lf\n%lf\n%lf\n",minkov(x,y,n,1),minkov(x,y,n,2),minkov(x,y,n,3),minkov(x,y,n,0));
	return 0;
}

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

typedef struct {
  char mark;
  int number;
} card;

int N;
card c1[40], c2[40];

void bubbleSort(card* c);
void selectionSort(card* c);
void trace(card* c);
bool compare();

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    char ch; int num;
    cin >> ch >> num;
    c1[i].mark = ch;
    c2[i].mark = ch;
    c1[i].number = num;
    c2[i].number = num;
  }
  
  bubbleSort(c1);
  selectionSort(c2);
  
  bool s = compare();
  
  trace(c1);
  cout << "Stable\n";
  trace(c2);
  if (s) { cout << "Stable\n"; }
  else { cout << "Not stable\n"; }
  
  return 0;
}

// stable sort
void bubbleSort(card* c) {
  for (int i = 0; i < N; ++i) {
    for (int j = N - 1; j >= i + 1; --j) {
      if (c[j].number < c[j - 1].number) {
        swap(c[j], c[j - 1]);
      }
    }
  }
}

// not stable sort
void selectionSort(card* c) {
  for (int i = 0; i < N; ++i) {
    int minv = i;
    for (int j = i + 1; j < N; ++j) {
      if (c[j].number < c[minv].number) { minv = j; }
    }
    if (minv != i) { swap(c[minv], c[i]); }
  }
}

// print
void trace(card* c) {
  for (int i = 0; i < N; ++i) {
  if (i) { cout << " "; }
    cout << c[i].mark << c[i].number;
  }
  cout << "\n";
}

// check
bool compare() {
  for (int i = 0; i < N; ++i) {
    if (c1[i].mark != c2[i].mark) { return false; }
  }
  return true;
}

Measured memory_bytes: 1164
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, W = map(int, input().split())
    goods = [list(map(int, input().split())) for _ in range(n)]
    
    max_value = 1
    for i in range(n):
        max_value += goods[i][1]

    dp = [[f_inf for _ in range(max_value)] for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 0

    for j in range(1, max_value):
        for i in range(1, n + 1):
            w, v = goods[i - 1]
            if j - v >= 0:
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w)
            else:
                dp[i][j] = dp[i - 1][j]

    res = 0
    for k in range(max_value):
        if dp[-1][k] <= W:
            res = k

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 387128
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var N = ReadInt();
            var T = ReadLines(N);
            
            if (N == 1)
            {
                Println(T[0]);
                return;
            }

            var lcm = Lcm(T[0], T[1]);
            for (int i = 2; i < N; i++)
            {
                lcm = Lcm(lcm, T[i]);
            }
            Println(lcm);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 11220
n, k = gets.chomp.split(" ").map(&:to_i)

a = gets.chomp.split(" ").map(&:to_i)

g = 1
amin = a.min
amax = a.max
amin.downto(1) do |i|
  if amin % i == 0
    if a.all?{|x| x % i == 0}
      g = i
      break
    end
  end
end

if k <= amax && k % g == 0
  puts "POSSIBLE"
else
  puts "IMPOSSIBLE"
end

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define mod 1000000007
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
int main()
{
   ll n;cin>>n;ll a[n][3];
   f(i,0,n)
   {
       f(j,0,3)cin>>a[i][j];
   }
ll dp[n][3]={0};dp[0][0]=a[0][0];dp[0][1]=a[0][1];dp[0][2]=a[0][2];
   f(i,1,n)
   {
       f(j,0,3)
       {
           f(k,0,3)
           {
               if(k==j)continue;
               dp[i][j]=max(dp[i][j],a[i][j]+dp[i-1][k]);
           }
       }
   }
 // f(i,0,n){f(j,0,n)cout<<dp[i][j]<<" ";cout<<"\n";}
   cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);


    return 0;

}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
typedef int Int;
#define int long long
#define SUM(i,j) (k[j]-k[i-1])
using namespace std;
Int main(){
	int n;
	cin>>n;
	int num[n+1];
	int k[n+1];
	k[0]=0;
	num[0]=0;
	for(int i=1;i<=n;i++){
		cin>>num[i];
		k[i]=k[i-1]+num[i];
	}
	int minv=0x7FFFFFFF,l1=1,l2=3;
	int ans[4]={0,0,0,0};
	for(int i=2;i<=n-2;i++){
		while(l1<i && abs(SUM(1,l1)-SUM(l1+1,i))>=abs(SUM(1,l1+1)-SUM(l1+2,i)))
			l1++;
		while(l2<n && abs(SUM(i+1,l2)-SUM(l2+1,n))>=abs(SUM(i+1,l2+1)-SUM(l2+2,n)))
			l2++;
		ans[0]=SUM(1,l1);
		ans[1]=SUM(l1+1,i);
		ans[2]=SUM(i+1,l2);
		ans[3]=SUM(l2+1,n);
		sort(ans,ans+4);
		minv=min(minv,ans[3]-ans[0]);
	}
	cout<<minv;
	return 0;
}

Measured memory_bytes: 3456