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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++) cin >> W.at(i);
  int sum = accumulate(W.begin(), W.end(), 0);
  int ans = 1e9;
  int sum2 = 0;
  for (int i = 0; i < N; i++) {
    sum2 += W.at(i);
    ans = min(ans, abs(sum2 - (sum - sum2)));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n.zero?

  a = []
  n.times do |i|
    a << gets.to_i
  end

  max = -100_000
  n.times do |i|
    sum = 0
    a[i..-1].each do |_a|
      sum += _a
      max = sum if sum > max
    end
  end

  puts max
end

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

int main() {
	int n, d, a;
	cin >> n >> d >> a;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	sort(p.begin(), p.end());
	d = d * 2;
	ll ans = 0;
	ll tot = 0;
	queue<pair<ll, ll>> que;
	rep(i, n) {
		ll x = p[i].first;
		ll h = p[i].second;
		while (que.size() && que.front().second < x) {
			tot -= que.front().first;
			que.pop();
		}
		h -= tot;
		if (h > 0) {
			ll num = (h + a - 1) / a;
			ans += num;
			ll damage = num * a;
			tot += damage;
			que.emplace(damage, x + d);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//try {
            //PrintWriter pw = new PrintWriter("test.txt");
            int n = scan.nextInt();scan.nextLine();
            String[] F = new String[n];
            Arrays.fill(F, "");
            int[] f = new int[n];
            int[][] p = new int[n][11];

            for (int i = 0; i < n; i++) {
            	F[i] = F[i]+scan.nextLine();
            	F[i] = F[i].replaceAll(" ", "");
            	f[i] = Integer.parseInt(F[i], 2);
            }

            for (int i = 0; i < n; i++) {
            	for (int j = 0; j < 11; j++) {
            		p[i][j] = scan.nextInt();
            	}
            }

            int ans = Integer.MIN_VALUE;

            for (int bit = 0; bit < (1 << 10); bit++) {
            	if (Integer.bitCount(bit) == 0) continue;
            	int pro = 0;
            	for (int i = 0; i < n; i++) {
            		int cnt = 0;
            		//pw.println("bit : "+Integer.toBinaryString(bit));
            		//pw.println("f["+i+"] : "+Integer.toBinaryString(f[i]));
            		cnt = Integer.bitCount(bit&f[i]);
            		//pw.println("cnt : " + cnt);
            		pro += p[i][cnt];
            	}
            	//pw.println("pro : "+pro);
            	ans = Math.max(ans, pro);
            }

            //pw.println(ans);
            System.out.println(ans);
            /*pw.close();
		*} catch (IOException ex) {
			*ex.printStackTrace();
		}
		*/
	}
}


Measured memory_bytes: 28148
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<(n*a>=b ? b : n*a);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <cassert>

using namespace std;

const int mod = 1000000007;

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

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++){
            int num = i * m + j * n - 2 * i * j;
            if (num == k){
                cout << "Yes";
                return 0;
            }
        }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#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 a=1;

    for (int i=1; i<N; i++){
    if (vec.at(i-1)>vec.at(i))
    a++;
}

  cout<<a<<endl;
  
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int memo[2010][20][30];

void solve(int y, int m, int d, int s) {
    memo[y][m][d] = s;
    if(y == 1 && m == 1 && d == 1) return;
    
    if(d == 1) {
        if(m == 1 && (y-1) % 3 == 0) {
            solve(y-1, 10, 20, s+1);
        }
        else if(m == 1 && (y-1) % 3 != 0) {
            solve(y-1, 10, 19, s+1);
        }
        else if(y % 3 == 0 || (m-1) % 2 == 1) {
            solve(y, m-1, 20, s+1);
        }
        else {
            solve(y, m-1, 19, s+1);
        }
    }
    else {
        solve(y, m, d-1, s+1);
    }
}

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

    int y, m, d;

    memset(memo, -1, sizeof(memo));
    solve(1000, 1, 1, 0);

    rep(i,0,n) {
        cin >> y >> m >> d;
        cout << memo[y][m][d] << endl;
    }
    return 0;
}

Measured memory_bytes: 12528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = 1; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 5000000000000000000;

int main() {
    ll N;
    cin >> N;
    
    set<ll> ans;
    for (ll i = 1; i * i <= N; ++i) {
        if ((N - 1) % i == 0) {
            if (i != 1) ans.insert(i);
            if ((N - 1) / i != 1) ans.insert((N - 1) / i);
        }
    }
    vector<ll> S;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            S.push_back(i);
            S.push_back(N / i);
        }
    }
    for (ll x : S) {
        if (x == 1) continue;
        ll n = N;
        while (n % x == 0) n /= x;
        if ((n - 1) % x == 0) ans.insert(x);
    }
    cout << SZ(ans) << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int t[1000000];
int main(void)
{
	int n, i, j, count;	
	
	for (i = 2; i * i <= 1000000; i++){
		if (t[i] == 0){
			for (j = 2 * i; j <= 1000000; j++){
				if (j % i == 0){
					t[j] = 1;
				}
			}
		}
	}
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		
		for (i = 2; i <= n; i++){
			if (t[i] == 0){
				count++;
			}
		}
		printf("%d\n", count);
	}
	
	return 0;
}

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

int main(){
    int N;  cin >> N;
    string S1, S2;  cin >> S1 >> S2;

    long long ans = 1;
    long long mod = 1e9+7;
    bool yoko = true;
    for(int i=0; i<N; i++){
        if(S1[i]==S2[i]){
            if(i==0) ans = 3;
            else if(yoko) ans*=1;
            else ans = (ans*2)%mod;
            yoko = false;
        }else{
            if(i==0) ans = 6;
            else if(yoko) ans = (ans*3)%mod;
            else ans = (ans*2)%mod;
            i++;
            yoko = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define llu unsigned long long int
#define all(v) v.begin(),v.end()
#define sd size()
#define pi pair<ll,ll>
#define lb(a,b) lower_bound(all(a),b) - a.begin()
#define ub(a,b) upper_bound(all(a),b) - a.begin()
#define sp( a, b)   cout<<setprecision(b)<<a<<" ";
#define mod 1000000007
#define d2 vector<vector<ll>>
#define d1 vector<ll>
#define d1pi vector<pi>
#define d1b vector<bool>
#define p(x) cout<<x;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll N = 2e5+100;
d1 g[N];
vector<bool> vis(N,0);
void un_add_edge(ll a,ll b)
{
        g[a].pb(b);
        g[b].pb(a);
}
void add_edge(ll a,ll b)
{
        g[a].pb(b);
      
}
ll lcm(ll a,ll b)
{
        return (a*b)/__gcd(a,b);
}
int main()
{
        fast;
        ll n,k;
        cin>>n>>k;
        d1 v(n,0),dp(n,1e18);    
        for(ll i=0;i<n;i++)
        {
                cin>>v[i];
        }
        dp[0]=0;
        for(ll i=0;i<n;i++)
        {   
                
                for(ll j=1;j<=k;j++)
                {
                    if(i-j>=0)
                    {
                        if(dp[i]>dp[i-j]+abs(v[i]-v[i-j]))
                        {
                                dp[i]=dp[i-j]+abs(v[i]-v[i-j]);
                                
                        }
                    }
                    else
                    break;
                }
                
                
                    
        }
      
        cout<<dp[n-1]<<" ";
        
}



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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    if( N / 100 == N % 10 ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    else:
        for i in range(h):
            if i == 0:
                print("#"*w)
            elif i == h-1:
                print("#"*w)
            else:
                print("#" + "."*(w-2) + "#")
        print()

Measured memory_bytes: 7660
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @h,@w,@k = gets.to_s.split.map{ |v| v.to_i }
    @c = Array.new(h){ gets.chomp }
  end

  def solve
    ans = 0
    (1<<h).times do |mask_y|
      (1<<w).times do |mask_x|
        cnt = 0
        h.times do |y|
          w.times do |x|
            next if c[y][x] == "."
            next if (mask_y >> y) & 1 == 1
            next if (mask_x >> x) & 1 == 1
            cnt += 1
          end
        end
        ans += 1 if cnt == k
      end
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14320
line = input()
line = line.rstrip().split(' ')

total = int(line[0])
total_leg = int(line[1])

kame = (total_leg - total * 2) / 2
tsuru = total - kame

if total_leg % 2 == 1:
    print('No')
elif (0 <= kame and kame <= total) and (0 <= tsuru and tsuru <= total):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9188
N = int(input())
xyh = []
si = 0
for i in range(N):
    x, y, h = map(int, input().split())
    xyh.append([x,y,h])
    if h > 0:
        si = i

for cx in range(101):
    for cy in range(101):
        H = xyh[si][2] + abs(cx - xyh[si][0]) + abs(cy - xyh[si][1])
        ok = True
        for x,y,h in xyh:
            if h > 0 and H - h != abs(cx - x) + abs(cy - y):
                ok = False
            if h == 0 and H > abs(cx - x) + abs(cy - y):
                ok = False
        if ok:
            print(cx, cy, H)
            exit()

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

int main() {
  string S;
  cin >> S;
  set<char> s;
  rep(i,S.size()){
    s.insert(S[i]);
  }
  if(s.size() == S.size()){
    cout << "yes";
  }
  else{
    cout << "no";
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int sum, hon[9], a, no, i;

  while(1){
    a = 0;
    scanf("%d",&sum);
    if(sum == 0) break;
    for(i = 0 ; i < 9 ; i++){
      scanf("%d",&hon[i]);
      a += hon[i];
    }
    no = sum - a;
    printf("%d\n",no);
  }

  return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,N) repi(i,0,(N))
#define repi(i,a,b) for (int i = (a); i < (b); ++ i)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)

#define all(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define t
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;
constexpr long long MOD = 1e9 + 7;
constexpr long long INF = 1LL << 60;
// UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1},
          dy[] = {1, 0, -1, 0};
template<class T = int> bool chmin(T& a, T b) { bool f = a > b; a = f ? b : a; return f;}
template<class T = int> bool chmax(T& a, T b) { bool f = a < b; a = f ? b : a; return f;}

template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){
  return s << "(" << p.first << ", " << p.second << ")";
}


signed main() { 
    ios(); 
    int N;
    cin >> N;
    string s;
    cin >> s;
    // ????????????? 0???i????E??????????N???i??????????e??????????????????
    // ??????????????, i - ????+ ?????????????.
    // l(i) -> [0,i) r(i) -> [i, N)
    vi l(N + 1), r(N + 1);
    l[0] = 0;
    r[N] = 0;
    rep(i, N) {
        l[i + 1] = l[i] + (s[i] == 'W' ? 1 : 0);
    }
    rrep(i, N) {
        r[i] = r[i + 1] + (s[i] == 'E' ? 1 : 0);
    }
    int min = INF;
    rep(i, N) {
        int tmp = l[i] + r[i + 1];
        chmin(min, tmp);
    }
    cout << min << endl;
}


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int inp[100010];
int dp[100010];

int main(){


    int n;
    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>inp[i];
    }

    dp[0] = 0;

    for(int i = 1; i < n; i++) {
        dp[i] = dp[i-1] + abs(inp[i] - inp[i-1]);
        if(i!=1) {
            dp[i] = min(dp[i], dp[i-2] + abs(inp[i] - inp[i-2]));
        }
    }

    cout<<dp[n-1]<<endl;
    


}


Measured memory_bytes: 1024
#include <stdio.h>

int P, Q, A, N;
int count = 0;
void solve(int n, int i, int j, int before)
{
    if (P * j < Q * i)
        return;
    else if (P / Q > i / j + (N - n))
        return;
    if (P * j == Q * i)
        count++;
    if (n < N)
    {
        for (int k = before; k <= A / j; k++)
        {
            solve(n + 1, i * k + j, j * k, k);
        }
    }
}

int main(void)
{
    while (1)
    {
        scanf("%d %d %d %d", &P, &Q, &A, &N);
        if ((P | Q | A | N) == 0)
            break;
        count = 0;
        solve(0, 0, 1, 1);
        printf("%d\n", count);
    }
}


Measured memory_bytes: 2116
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int a[Q],b[Q],c[Q],d[Q];
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--,b[i]--;
    }
    int ans=0;
    for(int i0=1;i0<=M;i0++) for(int i1=i0;i1<=M;i1++) for(int i2=i1;i2<=M;i2++) for(int i3=i2;i3<=M;i3++) for(int i4=i3;i4<=M;i4++) for(int i5=i4;i5<=M;i5++) for(int i6=i5;i6<=M;i6++) for(int i7=i6;i7<=M;i7++) for(int i8=i7;i8<=M;i8++) for(int i9=i8;i9<=M;i9++) {
        int A[10];
        int cnt=0;
        A[0]=i0,A[1]=i1,A[2]=i2,A[3]=i3,A[4]=i4,A[5]=i5,A[6]=i6,A[7]=i7,A[8]=i8,A[9]=i9;
        rep(k,Q){
            if(A[b[k]]-A[a[k]]==c[k]) cnt+=d[k];
        }
        ans=max(cnt,ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

template <typename T>
T gcd(T a, T b) {
    if (a <= 0 || b <= 0) {
        // どちらかが 0 以下であれば -1 を返す
        return -1;
    } else if (a == 1 || b == 1) {
        // どちらかが 1 であれば，最小公約数は 1
        return 1;
    } else {
        if (a < b) swap(a, b);
        if (a%b == 0) return b;
        return gcd(b, a%b);
    }
}

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

    // input
    int N, M;
    cin >> N >> M;
    
    // calculation
    cout << gcd(N, M) << "\n";
    
    return 0;
}



Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(){
	string s;
	cin>>s;
	int ans1=0,ans2=0;
	for(int i=0;i<s.length();i++){
		if(i%2==0){
			if(s[i]!='0') ans1++;
			if(s[i]!='1') ans2++;
		}else{
			if(s[i]!='1') ans1++;
			if(s[i]!='0') ans2++;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 512
/*
    ##############################
    #  Author: Pratyush Gaurav   #
    #  College: NIT ROURKELA     #
    ##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

void solve() {
    lli n;
    ld t, a;
    cin >> n;
    cin >> t >> a;
    vector<ld> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    ld ans = INF;
    lli idx = -1;
    for (int i = 0; i < n; ++i) {
        ld temp = t - (h[i] * 0.006);
        if (abs (temp - a) < ans) {
            ans = abs(temp - a);
            idx = i;
        }
    }
    cout << idx + 1 << endl;
}

int main()
{
    opt;
    lli t = 1;
    //cin >> t;

    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

char* substring(char *destination, const char *source, int beg, int n)
{
    // extracts n characters from source string starting from beg index
    // and copy them into the destination string
    while (n > 0)
    {
        *destination = *(source + beg);

        destination++;
        source++;
        n--;
    }

    // null terminate destination string
    *destination = '\0';

    // return the destination string
    return destination;
}


int palind(char a[100]){
char cpy[100]={'\0'};
int count =0;
for (int i=strlen(a)-1;i>=0;i--){
      strncat(cpy,&a[i],1);
      count++;
}
int res = strcmp(cpy,a);
if (res==0)return 1;
else return -1;
}



int main(void) {
  char S[100]={'\0'};
  scanf("%s",&S);
  char Copy1[100]={'\0'};
  char Copy2[100]={'\0'};
  int count=0;
  substring(Copy1,S,0,((strlen(S)-1)/2));
  substring(Copy2,S,((strlen(S)+3)/2)-1,strlen(S)-1);
  if (palind(S)==1)count++;
  if (palind(Copy1)==1)count++;
  if (palind(Copy2)==1) count++;

 if (count==3) printf("Yes");
 else printf("No");

 return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	vector<bool> isnum(300007, false);

	for(int i = 0; i < 300000; i+=7) {
		isnum[i+1] = true;
		isnum[i+6] = true;
	}
	isnum[1] = false;

	vi allp;

	for(int i = 0; i < 300000; i+=7) {
		if(isnum[i+1]) {
			allp.push_back(i+1);
			for(int j = 2*(i+1); j < 300000; j += (i+1)) {
				isnum[j] = false;
			}
		}
		if(isnum[i+6]) {
			allp.push_back(i+6);
			for(int j = 2*(i+6); j < 300000; j += (i+6)) {
				isnum[j] = false;
			}
		}
	}

	int m;
	while(cin >> m, m!=1) {
		cout << m << ":";
		
		FOR(i, 0, allp.size()) {
			if(m%allp[i] == 0) {
				cout << " " << allp[i];
			}
		}

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int[] w, d;
    String[] name;
    int i, j, tmp;
    String st;

    n = sc.nextInt();
    for(;;){
      w = new int[n];
      d = new int[n];
      name = new String[n];

      for(i = 0;i < n;i++){
        name[i] = sc.next();
        w[i] = sc.nextInt();
        d[i] = sc.nextInt();
        d[i] = sc.nextInt();
        d[i] += 3 * w[i];
      }

      for(i = 0;i < n - 1;i++){
        for(j = 0;j < n - 1 - i;j++){
          if(d[j] < d[j + 1]){
            st = name[j]; name[j] = name[j + 1]; name[j + 1] = st;
            tmp = d[j]; d[j] = d[j + 1]; d[j + 1] = tmp;
          }
        }
      }

      for(i = 0;i < n;i++)System.out.println(name[i] + "," + d[i]);

      n = sc.nextInt();
      if(n == 0)break;
      else System.out.println();
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20620
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    int K;
    map <int, int> food;

    for (int i = 0; i < N; i++){
        cin >> K;
        for(int j = 0; j < K; j++){
            int Aij;
            cin >> Aij;
            food[Aij - 1] += 1;
        }
    }

    int count = 0;
    for(int i = 0; i < M ; i++){
        if(food[i] == N){
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;

}



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

int main() {
  
  int N=0;
  int K=0;
  int count = 0;
	cin >> N >> K;
	vector<int> h(N);

 
for (int i = 0; i < N; i++) {
		cin >> h.at(i);
	}
  
  for(int i=0; i<N ; i++){
  	if(h.at(i) >= K) {
      count += 1;
 	}
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,p;
    int x,y;
    cin>>a>>b>>c>>d>>p;
    x=a*p;
    y=b;

    if(p>c){
       y+=(p-c)*d;
    }
    
    if(x<y) cout<<x<<endl;
    else cout<<y<<endl;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    cin >> s;
    int ans = s.size();
    while(1){
        s.erase(s.size()-1);
        s.erase(s.size()-1);
        ans-=2;
        if(s.substr(0,s.size()/2)==s.substr(s.size()/2)){
            cout<< ans << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
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)
        {
            int N = cin.ReadInt;
            var AB = new int[N][];
            for(int i=0;i<N;i++){
                AB[i] = cin.ReadIntArray(2);
            }
            var ABs = AB.OrderBy(x => x[1]);
            long curtime = 0;
            string ans = "Yes";
            foreach(int[] L in ABs){
                curtime += L[0];
                if(curtime > L[1]){
                    ans = "No";
                    break;
                }
            }
            WriteLine(ans);
        }
    }

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


Measured memory_bytes: 31780
N, K = map(str, input().split())
D = map(str, input().split())

D = set(D)	# 集合に変換
number = {'0','1','2','3','4','5','6','7','8','9'}	# 集合
out = D^number
#print(out)


out = sorted(list(out))
res_list = []
flag = 0
for i in range(len(N)):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
        flag = 2
  elif flag == 1:
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
      flag = 2
  elif flag == 2:
    res_list.append(out[0])
        
if flag == 1:
  res_list.append(out[0])  
res = ''
for i in range(len(res_list)):
  res += res_list[i]
print(res)        
    
          
"""
flag = 0
for i in range(len(N)-1, -1, -1):
  if flag == 0:
    if len(set(N[i])&set(out)) == 1:
      res_list.append(N[i])
    else:
      tmp = -1
      for j in range(len(out)):
        if N[i] < out[j]:
          tmp = out[j]
          break
      if tmp == -1:
        res_list.append(out[0])
        flag = 1
      else:
        res_list.append(tmp)
  elif flag == 1:
    flag = 0
    tmp = -1
    for j in range(len(out)):
      if N[i] < out[j]:
        tmp = out[j]
        break
    if tmp == -1:
      res_list.append(out[0])
      flag = 1
    else:
      res_list.append(tmp)
if flag == 1:
  res_list.append(out[0])
  
res = ''
for i in range(len(res_list)-1, -1, -1):
  res += res_list[i]
print(res)
"""

Measured memory_bytes: 3064
import math
N,K = map(int,input().split())
cnt2 = 0
for n in range(1,N+1):
    if K/n <= 1:
        x = 0
    elif abs((math.log(K)-math.log(n))//math.log(2)-(math.log(K)-math.log(n))/math.log(2))<=0.00001:
        x = (math.log(K)-math.log(n))//math.log(2)
    else:
        x = (math.log(K)-math.log(n))//math.log(2)+1
    cnt2 += (0.5)**x
  

print(cnt2/N)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<queue>
#define ll long long
typedef unsigned long long ULL;
const int N=110;
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a+(b/2))<<endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np 
from numba import jit
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a,dtype="int64")

@jit
def imo(a):
    imos=np.zeros(n+1,dtype="int64")
    for i in range(n):
        imos[max(0,i-a[i])]+=1
        imos[min(n,i+a[i]+1)]-=1
    
    immo=np.zeros(n+1,dtype="int64")
    immo=np.cumsum(imos)
    return immo[:n]


for _ in range(min(k,41)):
    a=imo(a)
    
print(*a)


Measured memory_bytes: 123712
n = int(input())
A = tuple(map(int, input().split()))
c = 0
s = 0
r = 0
for l in range(n):
    while r < n and A[r] ^ s == A[r] + s:
        s = A[r] + s
        r += 1

    c += r- l
    if l == r:
        r += 1
    s -= A[l]

print(c)

Measured memory_bytes: 23816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<pair<int,int>> G[101010];

int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back({b,i});
        G[b].push_back({a,i});
    }

    int ans=0;
    rep(i,n) ans=max(ans,(int)G[i].size());
    cout<<ans<<endl;

    queue<pair<int,int>> q;
    vector<bool> seen(n,false);
    q.push({0,-1});
    seen[0]=true;
    vector<int> res(n-1,-1);
    while(!q.empty()){
        auto p=q.front();
        q.pop();
        int v=p.first,c=p.second;
        int color=1;
        if(color==c) color++;
        for(auto e : G[v]){
            if(seen[e.first]) continue;
            seen[e.first]=true;
            q.push({e.first,color});
            res[e.second]=color;
            color++;
            if(color==c) color++;
        }
    }

    rep(i,n-1) cout<<res[i]<<endl;
}



Measured memory_bytes: 9676
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<string>

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


int main() {
  int n;
  cin >> n;
  
  ll sum=0;
  int n1;
  for(ll i=1;i<=n;++i){
    n1 = n/i;
    sum += i*n1*(n1+1)/2;
    //cout<<i<<endl;
  }
  cout<<sum<<endl;



}

Measured memory_bytes: 3532
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

int main(void){

	char *S;
	S = (char*)calloc(100,sizeof(char));
	if (S == NULL){
		return 1;
	}

	scanf("%s",S);

	int len = strlen(S);
	int cnt = 0;

	for (int i = 0; i < len/2; ++i){
		if (S[i] != S[len - i - 1]) cnt++;
	}

	printf("%d\n",cnt);
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  ll c=a+b;
  string s; cin>>s;
  ll sum=0, bsum=0;
  
  rep(i,n){
    if(s[i]!='c'){
      if(s[i]=='a'){
        if(sum<c){
          cout<<"Yes"<<endl;
          sum++;
        }
        else cout<<"No"<<endl;
      }else{
        if(sum<c && bsum<b){
          cout<<"Yes"<<endl;
          sum++; bsum++;
        }
        else cout<<"No"<<endl;
      }
    }else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 848
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N;
   cin >> N;
   map<int,int> M;
   vector<int> A(N);
   for (int i = 0; i < N; i++)
   {
      cin >> A[i];
      M[A[i]]++;
   }
   sort(A.begin(),A.end());
   A.erase(unique(A.begin(),A.end()),A.end());
   int size = A.size();
   int ind = size-1;
   long long ans=0;
   for(long long offset = (1LL<<31); offset > 1; offset /=2){
      while(ind>=0&&A[ind]*2>=offset){
         int cur = A[ind];
         int partner = offset-A[ind];
         if(cur == partner){
            int pair= M[cur]/2;
            ans += pair;
            M[cur]-= pair*2;
         }
         else{
            int pair= min(M[cur],M[partner]);
            ans += pair;
            M[cur]-=pair;
            M[partner]-=pair;
         }
         ind--;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 22696
#include <stdio.h>
#include <string.h>

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

long int lcm(long int a, long int b) {
  return a*b/ gcd(a, b);
}



int main(){
  long int N,M;
  scanf("%ld%ld",&N,&M);
  char S[100000];
  char T[100000];
  scanf("%s",S);
  scanf("%s",T);
  int i;
  int flag=0;
  long int ans=-1;
  for(i=0;i<N;i++){
    if((i*M)%N==0 && S[i]!=T[i*M/N]){
	flag=1;
    }
  }
  if(flag==0){
    ans=lcm(N,M);
  }
  printf("%ld",ans);
  return 0;
}

    


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#ifndef JHELPER_EXAMPLE_PROJECT_DEFINITION_HPP
#define JHELPER_EXAMPLE_PROJECT_DEFINITION_HPP

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

#endif //JHELPER_EXAMPLE_PROJECT_DEFINITION_HPP



#ifndef JHELPER_EXAMPLE_PROJECT_UNIONFIND_HPP
#define JHELPER_EXAMPLE_PROJECT_UNIONFIND_HPP

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}

    ll root(ll x) {
        if (data[x] < 0)
            return x;
        else
            return data[x] = root(data[x]);
    }

    ll size(ll x) { return -data[root(x)]; }

    bool isConnect(ll x, ll y) { return root(x) == root(y); }

    bool connect(ll x, ll y) {
        x = root(x);
        y = root(y);

        if (x == y)
            return false;

        if (data[x] > data[y]) {
            x ^= y;
            y ^= x;
            x ^= y;
        }

        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};


#endif //JHELPER_EXAMPLE_PROJECT_UNIONFIND_HPP


class ALucky7 {
public:
	void solve(std::istream& in, std::ostream& out) {
	    UnionFind U(5);
	    string N; in >> N;
	    string ans = "No";
	    REP(i, N.size()) {
	        if (N[i] == '7') ans = "Yes";
	    }
	    out << ans << '\n';
	}
};


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

	ALucky7 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3652
n = int(input())
ls = list(map(int,input().split()))
lss = sorted(ls)
count=0
for i in range(n):
  if ls[i]!=lss[i]:
    count+=1
  else:
    continue
if count == 2 or count == 0:
  print("YES")
else:
  print("NO")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, d, x;
	cin>>n>>d;
	vector<int> e(d, 0);
	vector<vector<int> > vec(n, e);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < d; ++j){
			cin>>x;
			vec[i][j] = x;
		}
	}
	int res = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j < n; ++j){
			int t = 0;
			for(int k = 0; k < d; ++k){
				int xp  = vec[i][k] - vec[j][k];
				int y = xp * xp;
				t += y;
			}
			double d = sqrt(t);
			int dx = (int)d;
			double tr = d - dx;
			if(tr == 0)res++;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

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

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

/** Problem0065 : Trading **/
int main()
{
	string str;
	pair<map<int, int>, map<int, int> > list;
	while (getline(cin, str), str!="") {
		stringstream ss(str);
		int n; ss>>n;
		list.first[n]++;
	}
	while (getline(cin, str)) {
		stringstream ss(str);
		int n; ss>>n;
		list.second[n]++;
	}
	
	map<int, int>::iterator it = list.first.begin();
	for (;it!=list.first.end(); it++) {
		if (it->second>0 && list.second[it->first]>0) {
			cout << it->first << " " << it->second+list.second[it->first] << endl;
		}
	}
}

Measured memory_bytes: 1224
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    S = [input().rstrip() for i in range(N)]
    R = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
    for i in S:
        R[i] += 1
    print('AC x {}'.format(R['AC']))
    print('WA x {}'.format(R['WA']))
    print('TLE x {}'.format(R['TLE']))
    print('RE x {}'.format(R['RE']))

if __name__ == '__main__':
    main()

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, ans, a[300001], first_sum, second_sum;
multiset <ll> first_half, buffer, second_half;
vector <ll> ranking;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	ans=-INF;
	cin >> n;
	for(int i = 0; i < 3*n; i++){
		cin >> a[i];
		if(i < n){
			first_sum+=a[i];
			first_half.insert(a[i]);
		}
		else{
			ranking.pb(a[i]);
		}
	}
	sort(ranking.begin(), ranking.end());
	for(int i = 0; i < 2*n; i++){
		if(i < n){
			second_half.insert(ranking[i]);
			second_sum+=ranking[i];
		}
		else{
			buffer.insert(ranking[i]);
		}
	}
	ans = max(ans, first_sum-second_sum);
	for(int i = n; i < 2*n; i++){
		if(a[i] > *first_half.begin()){
			first_sum+=a[i];
			first_sum-=*first_half.begin();
			first_half.erase(first_half.begin());
			first_half.insert(a[i]);
		}
		if(!buffer.empty()){
		if(buffer.count(a[i])){
			buffer.erase(buffer.find(a[i]));
		}
		else{
			second_sum-=a[i];
			second_sum+=*buffer.begin();
			second_half.erase(second_half.find(a[i]));
			second_half.insert(*buffer.begin());
			buffer.erase(buffer.begin());
		}
		}
		ans=max(ans,first_sum-second_sum);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

long long modpow(long long a, long long n, long long m) {
  long long 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);

  ll N,K,ans = 0;
  cin >> N >> K;
  COMinit();
  // N個の箱のうち、K個の箱が空の状態を指す。
  for (ll i = 0; i < K; ++i) {
    ll md = modpow(K-i, N, mod);
    // 包除原理
    if (i % 2 == 0) {
      ans += COM(K, i) * md;
    } else {
      ans += (mod - (COM(K, i) * md) % mod) % mod;
    } 

    ans %= mod;
  }

  cout << ans << endl;
}



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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

int main(){
    ll N;
    cin >> N;

    ll k;
    cin >> k;
    ull ma = 0;
    FOR(i, 0, k){
        ll b; cin >> b;
        ma |= (1<<b);
    }
    
    FOR(mask, 0, 1LL<<N){
        if((mask&ma) != ma) continue;
        cout << mask << ":";
        FOR(i, 0, 18){
            if(mask>>i&1){
                cout << ' ' << i;
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3108