akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 50
#define M 1e16+1000
using namespace std;
typedef long long ll;
bool valid(vector<ll> a) {
  for (ll n : a) {
    if (n < 0 || n > M) {
      return false;
    }
  }
  return true;
}
int main() {
  ll K;
  cin >> K;
  for (int i = 2; i <= N; i++) {
    vector<ll> a(i,i-1+K/i);
    for (int j = 0; j < K%i; j++) {
      a[j] += i-K%i+1;
    }
    for (int j = K%i; j < i; j++) {
      a[j] -= K%i;
    }
    if (valid(a)) {
      cout << i << endl;
      for (ll n : a) {
        cout << n << ' ';
      }
      return 0;
    }
  }
}

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

#include "bits/stdc++.h"

using namespace std;

#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = 1e18;
const int mod = 1e9+7;

inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x;}
inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x;}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod;}
inline int power(int a, int b) {
    int x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a) { return power(a, mod - 2);}

const int N = 2e5+5;

int h[N],a[N],tree[4*N],dp[N],n;

void update(int node,int start,int end,int l,int r,int val){
    if(start>r or start>end or end<l) return;
    if(l<=start and r>=end){
        tree[node] = val;
        return;
    }
    int mid = (start+end)/2;
    update(2*node,start,mid,l,r,val);
    update(2*node+1,mid+1,end,l,r,val);
    tree[node] = max(tree[2*node],tree[2*node+1]);
}

int query(int node,int start,int end,int l,int r){
    if(start>end or start>r or end<l) return -inf;
    if(l<=start and r>=end) return tree[node];
    int mid = (start+end)/2;
    int ret1 = query(2*node,start,mid,l,r);
    int ret2 = query(2*node+1,mid+1,end,l,r);
    return max(ret1,ret2);
}


class QFlowers {
public:
    void solve(std::istream& cin, std::ostream& cout){
        cin >> n;
        for(int i=1;i<=n;i++) cin >> h[i];
        for(int i=1;i<=n;i++) cin >> a[i];

        int ans = 0;
        fill(dp,dp+N,0);
        fill(tree,tree+4*N,0);
        for(int i=1;i<=n;i++){
            int val = query(1,1,n,0,h[i]);
            dp[h[i]] = val + a[i];
            ans = max(ans,dp[h[i]]);
            update(1,1,n,h[i],h[i],dp[h[i]]);
        }

        cout << ans << endl;
    }
};


int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    QFlowers solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class union_find{
	int n;
	vector<int> a;
public:
	union_find(int N):a(N,-1),n(N){}
	int find(int x){
		if(a[x]<0) return x;
		return a[x]=find(a[x]);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x!=y){ a[x]+=a[y]; a[y]=x; n--; }
	}
	int size(){ return n; }
	int size(int x){ return -a[find(x)]; }
};

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> p(n);
	rep(i,n) scanf("%d",&p[i]);

	union_find U(n-k+1);
	set<int> S(p.begin(),p.begin()+k);
	rep(i,n-k){
		if(*S.begin()==p[i] && *S.rbegin()<p[k+i]) U.unite(i,i+1);
		S.erase(p[i]);
		S.emplace(p[k+i]);
	}

	vector<int> flag(n-1);
	rep(i,n-1) flag[i]=(p[i]<p[i+1]);
	vector<int> sorted;
	int cnt=0;
	rep(i,n-1){
		if(flag[i]) cnt++;
		else        cnt=0;
		if(cnt>=k-1) sorted.emplace_back(i-k+2);
	}
	for(int i=1;i<sorted.size();i++) U.unite(sorted[0],sorted[i]);

	printf("%d\n",U.size());

	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;


int main() {
  string s;
  cin >> s;
  vi d(256);
  for (char c : s) d[c] = 1;
  string ans = "Yes";
  if (d['N']+d['S'] == 1) ans = "No";
  if (d['W']+d['E'] == 1) ans = "No";
  cout<<ans<<endl;
  return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define int long long int
#define rep(i,a,b) for(int i=a;i<b;i++)
#define reprev(i,a,b) for(int i=b-1;i>=a;i--)
#define all(c) c.begin(),c.end()
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vin(a,n) vi a(n); rep(i,0,n) cin>>a[i];
#define vout(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
#define mapp map<int,int>
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define inf LLONG_MAX
#define pi 3.1415926535897932384626
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)

bool comps(const pair<int,int> &a, const pair<int,int> &b) {return (a.second<b.second);} 

int power(int x, unsigned int y)
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

int powerp(int x, unsigned int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

signed main()
{
    
    IOS
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        cout<<a*b; 
    }
    return 0;
}

// vector<vector<int>> adj;
// vector<bool> visited;
// void dfs(int v) 
// {
//     visited[v] = true;
//     for (int u : adj[v]) 
//     {
//         if (!visited[u])
//         {
//             dist[u].ff=dist[v].ff+1;
//             dist[u].ss=u;
//             dfs(u);
//         }
//     }
// }
// int binarySearch(int l, int r) 
// { 
//     while (l <= r) { 
//         int m = l + (r - l) / 2; 
  
//         //ignore left half 
//         if (!check(m)) 
//             l = m + 1; 
  
//         //ignore right half 
//         else
//             r = m - 1; 
//     }   
//     return l;
// }

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int a = 0;
		
		for (int i = 0; i < N; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a += (r + 1) - l;
		}
		
		System.out.println(a);

		sc.close();
	}
}


Measured memory_bytes: 25324
#include<iostream>
using namespace std;
#define MAX 10005
#define KAZU -1

struct Node{int parent, left, right;};

Node T[MAX];
int n,D[MAX],H[MAX];

void getDepth(int u,int d){
  if(u == KAZU) return;
  D[u] = d;
  getDepth(T[u].left,d+1);
  getDepth(T[u].right,d+1);
}
int getHeight(int u){
  int h1=0,h2=0;
  if(T[u].left != KAZU){
    h1 = getHeight(T[u].left)+1;
  }
  if(T[u].right != KAZU){
    h2 = getHeight(T[u].right)+1;
  }
  H[u] = (h1 > h2 ? h1 : h2);
  return H[u];
}

int getSibling(int u){
  if(T[u].parent == KAZU) return KAZU;
  if(T[T[u].parent].left != u && T[T[u].parent].left != KAZU){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right != u && T[T[u].parent].right != KAZU){
    return T[T[u].parent].right;
  }
  return KAZU;
}

void print(int u){
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "sibling = " << getSibling(u) << ", ";
  int deg = 0;
  if(T[u].left != KAZU) deg++;
  if(T[u].right != KAZU) deg++;
  cout << "degree = " << deg << ", ";
  cout << "depth = " << D[u] << ", ";
  cout << "height = " << H[u] << ", ";
  if(T[u].parent == KAZU){
    cout << "root" << endl;
  }
  else if(T[u].left == KAZU && T[u].right == KAZU){
    cout << "leaf"<< endl;
  }
  else{
    cout << "internal node" << endl;
  }
}

int main(){
  int i,j,v,l,r,root=0;
  
  cin >> n;
  for(i=0;i<n;i++) T[i].parent = KAZU;
  
  for(i=0;i<n;i++){
    cin >> v >> l >> r;
    T[v].left  = l;
    T[v].right = r;
    if( l != KAZU ) T[l].parent = v;
    if( r != KAZU ) T[r].parent = v;
  }

  for(i = 0;i < n;i++){
    if(T[i].parent == KAZU) root = i;
  }

  getDepth(root,0);
  getHeight(root);

  for(i=0;i<n;i++)print(i);
  
  return 0;
}



Measured memory_bytes: 3120
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn f(a: usize, b: usize) -> usize {
    if b % a == 0 {
        return 2 * a * (b / a) - a;
    }

    if a > b {
        return f(b, a);
    }

    2 * a * (b / a) + f(b % a, a)
}

fn main() {
    let (n, x): (usize, usize) = util::get2();
    println!("{}", n + f(x, n - x));
}


Measured memory_bytes: 4352
// Half and Half

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

using namespace std;

int main() {
    int A, B, C, X, Y, i, j;
    cin >> A >> B >> C >> X >> Y;

    // 買い方
    // X > Y の場合
    //     1. AピザをX枚、BピザをY枚買う
    //     2. ABピザを 2 * X枚買う
    //     3. ABピザを 2 * Y枚買い、Aピザを(X - Y)枚買う

    int result1, result2, result3;
    if (X > Y) {
        result1 = A * X + B * Y;
        result2 = C * 2 * X;
        result3 = C * 2 * Y + A * (X - Y);
    } else {
        result1 = A * X + B * Y;
        result2 = C * 2 * Y;
        result3 = C * 2 * X + B * (Y - X);
    }

    vector <int> results = {result1, result2, result3};
    int result = *min_element(results.begin(), results.end());

    // for debug
    // cout << "result1: " << result1 << endl;
    // cout << "result2: " << result2 << endl;
    // cout << "result3: " << result3 << endl;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h,w,k;
    cin>>h>>w>>k;
    int ats=0;
    vector<string> A(h);
    for (int i=0;i<h;i++) {cin>>A[i];}
    for (int i=0;i<pow(2,h);i++) {
		for (int j=0;j<pow(2,w);j++) {
			int d=0;
			for (int eil=0;eil<h;eil++) {
				for (int st=0;st<w;st++) {
					if (((1<<eil)&i)>0 && ((1<<st)&j)>0 && A[eil][st]=='#') {d++;}
					}
				}
				if (d==k) {ats++;}
			}
		}
	cout<<ats<<endl;
    return 0;
}


Measured memory_bytes: 4084
# -*- coding: utf-8 -*-
# B - FizzBuzz Sum
# 標準入力の取得
N = int(input())

# 求解処理
# 1～Nまで3または5で割り切れないものをどんどん足していく
result = 0
for n in range(1, N+1):
    if (n % 3 == 0) or (n % 5 == 0):
        continue
    result += n

# 結果出力
print(result)

Measured memory_bytes: 9168
#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> pp;
const int INF = 1e9;
const int MOD = 1000000007;

 
int main() {
  int n,t;
  cin >> n >> t;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  ll ans = 0;
  rep(i,n){
    if(i== n-1) ans += t;
    else{
      ans += min(a.at(i+1) - a.at(i),t);
    }
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
require 'pp'

# n件読み込んだ結果を数値の配列で返却する
def gets_n_iarray
  n = gets.chomp.to_i
  array = []
  n.times do
    array.push(gets.chomp.to_i)
  end
  return n, array
end


N, a_list = gets_n_iarray

# 配列に出現する数値をカウント
# {1=>3, 2=>1, 3=>2}
count_hash = a_list.group_by(&:itself).map{|k,v| [k, v.count] }.to_h
puts count_hash.values.count{|v| v.odd? }

# paper = []
#
# a_list.each do |i|
#   paper.include?(i) ? paper.delete(i) : paper.push(i)
# end
#
# puts paper.size


Measured memory_bytes: 27828
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#pragma endregion

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> x(m);
    rep(i, m) cin >> x.at(i);

    if(m == 1) {
        cout << 0 << endl;
        return 0;
    }
    sort(all(x));

    vector<ll> v(m - 1);
    rep(i, m - 1) v[i] = abs(x[i] - x[i + 1]);

    sort(all(v));

    ll sum = 0;
    rep(i, m - n) sum += v[i];
    cout << sum << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s,t; cin >> s >> t;

    sort(all(s));
    sort(all(t));
    reverse(all(t));

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
	int64_t n, m, k;
	cin >> n >> m >> k;
	vector<int64_t> as(n), bs(m);
	for (auto &&a : as)
	{
		cin >> a;
	}
	for (auto &&b : bs)
	{
		cin >> b;
	}

	vector<int64_t> dp_a(n + 1, 0), dp_b(m + 1, 0);
	for (int64_t i = 0; i < n; i++)
	{
		dp_a[i + 1] = dp_a[i] + as[i];
	}
	for (int64_t i = 0; i < m; i++)
	{
		dp_b[i + 1] = dp_b[i] + bs[i];
	}

	int64_t ans = 0;

	for (int64_t i = 0; i <= n; i++)
	{
		if (k < dp_a[i])
		{
			break;
		}

		int64_t t = k - dp_a[i];

		ans = max<int64_t>(ans, i + distance(dp_b.begin(), upper_bound(dp_b.begin(), dp_b.end(), t)) - 1);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9592
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
int main()
{
  int h,w,k;cin >> h >> w >> k;
  vector<vector<char>> a(h, vector<char>(w));
  int sx, sy;
  rep(i,h) rep(j,w) {
    cin >> a[i][j];
    if(a[i][j] == 'S') {
      sx = i; sy = j;
    }
  }

  vector<int> dx = {1, 0, -1, 0};
  vector<int> dy = {0, 1, 0, -1};

  const int inf = 1e+9;
  vector<vector<int>> d(h, vector<int>(w, inf));
  d[sx][sy] = 0;
  using pi = pair<int,int>;
  queue<pi> q;
  q.push({sx, sy});
  while( !q.empty() ) {
    pi p = q.front(); q.pop();
    int x = p.first, y = p.second;
    rep(i,4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(0 <= nx && nx < h && 0 <= ny && ny < w) {
	if(a[nx][ny] == '#' || d[nx][ny] != inf) continue;
	d[nx][ny] = d[x][y] + 1;
	q.push({nx, ny});
      }
    }
  }
  int res = 1e+9;

  auto Ceil = [](int a, int b)-> int{
		if(a%b == 0) return a/b;
		else return (a+b-a%b)/b;
	      };
  
  rep(i,h) rep(j,w) {
    if(d[i][j] <= k) {
      int dis = min({i, h-i-1, j, w-j-1});
      chmin(res, Ceil(dis,k) + 1);
    }
  }
  cout << res << "\n";
  
  return 0;
}


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

//解説1
int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N-1));
    rep(i, N) {
            rep(j, N-1) {
            cin >> A[i][j];
            A[i][j]--;
        }
        //次に試合をする選手が常に末尾に来るようにする（計算が速い）
        reverse(A[i].begin(), A[i].end());
    }

    vector<P> q;
    //選手iの次の試合が行える状態かを判定し、行えるならキューに追加する関数（ラムダ式）
    //[&]→デフォルトで環境にある変数を参照して、ラムダ式の中で使用する
    auto check = [&](int i) {
        if(A[i].size() == 0) return;
        int j = A[i].back();
        if(A[j].size() == 0) return;
        if(A[j].back() == i) {
            P p(i, j);
            //重複を避けるための前処理
            if(p.second < p.first) swap(p.first, p.second);
            q.push_back(p);
        }
    };

    //初日にできる試合をチェックする
    rep(i, N) {
        check(i);
    }


    int day = 0;
    while (q.size() > 0) {
        day++;
        
        //重複している試合を消去(uniqueの使いかた→覚える)
        sort(q.begin(), q.end());
        q.erase(unique(q.begin(), q.end()), q.end());

        //現在のキューを別のキューに読み込み、元のキューを空にする
        vector<P> prevQ;
        swap(prevQ, q);

        //現在できる試合を行う
        for(P p : prevQ) {
            int i = p.first, j = p.second;
            A[i].pop_back();
            A[j].pop_back();
        }
        //次の日にできる試合を元のキューに書き込む
        for(P p : prevQ) {
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }       
    }

    //終了時に消化されていない試合が存在したら-1を出力
    rep(i, N) {
        if(A[i].size() != 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << day << endl;

    return 0;
}

Measured memory_bytes: 4224
h1,m1,h2,m2,k=map(int,input().split())
j=0
if h2>=h1 and m2>=m1:
    j=60*(h2-h1)+m2-m1
elif h2>=h1 and m1>m2:
    j=60*(h2-h1-1)+(60-(m1-m2))
elif h2<h1 and m2>=m1:
    j=60*(24-(h1-h2))+m2-m1
else:
    j=60*(24-(h1-h2)-1)+(60-(m1-m2))
print(j-k)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
//
// using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<ll>> v(n, vector<ll>(n, INT_MAX));
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    from--; to--;
    v[from][to] = cost;
    v[to][from] = cost;
  }
  rep(i, n){
    rep(j, n){
      rep(k, n){
        v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
      }
    }
  }
  rep(i, n){
    rep(j, n){
      if(v[i][j] <= l) v[i][j] = 1;
      else v[i][j] = INT_MAX;
    }
  }

  rep(i, n){
    rep(j, n){
      rep(k, n){
        v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
      }
    }
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int from, to;
    cin >> from >> to;
    from--; to--;
    if(v[from][to] >= INT_MAX) cout << -1 << endl;
    else cout << v[from][to] - 1 << endl;
  }
}


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

int main(){
    ll a,b,q;
    cin >> a >> b >> q;
    ll s[a];
    for(ll i=0;i<a;i++) cin >> s[i];
    ll t[b];
    for(ll i=0;i<b;i++) cin >> t[i];
    for(ll i=0;i<q;i++){
        ll x;
        cin >> x;
        ll res=1e12;
        ll memos;
        memos=lower_bound(s,s+a,x)-s;
        ll memot;
        memot=lower_bound(t,t+b,x)-t;
        for(ll j=0;j<2;j++){
            for(ll k=0;k<2;k++){
                res=min(res,abs(s[memos-j]-t[memot-k])+min(abs(s[memos-j]-x),abs(t[memot-k]-x)));
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 5188
#include <stdio.h>
int main()
{
  float v,y,n;
  int i;
  while((scanf("%f",&v)) != EOF){
    y=4.9*(v/9.8)*(v/9.8);
    for(i=1; i<10000; i++){
      if(i*5-5>=y)break;
    }
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main() {
    int n;cin>>n;
    int m=n-n/2;
    cout<<fixed<<setprecision(10);
    cout<<(double)m/n<<endl;
}

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

const int N = 1e3 +50;

int n, cnt[N];
char s[N];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; ++i)
		cnt[s[i]]++;
	if(cnt['W'] && !cnt['E'])
		return 0 * printf("No\n");
	if(cnt['E'] && !cnt['W'])
		return 0 * printf("No\n");
	if(cnt['N'] && !cnt['S'])
		return 0 * printf("No\n");
	if(cnt['S'] && !cnt['N'])
		return 0 * printf("No\n");
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

'''
4
10 30 40 20
'''

N = int(input())
h = list(map(int, input().split()))

dp = [None] * N

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-2] + abs(h[i]-h[i-2]) + abs(h[i]-h[i-1])),
                dp[i-1] + abs(h[i]-h[i-1]))

print(dp[N-1])

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

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

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

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	
	VI ck0(n), ck1(n);
	rep(i, n){
		int a, x, y;
		cin >>a;
		rep(j, a){
			cin >>x >>y;
			if(y==1) ck1[i] |= 1<<(x-1);
			else ck0[i] |= 1<<(x-1);
		}
	}
	int ans = 0;
	rep(i, 1<<n){
		bool ok = 1;
		rep(j, n) if(i>>j &1){
			if((ck1[j] &  i) != ck1[j]) ok =0;
			if((ck0[j] & ~i) != ck0[j]) ok =0;
		}
		if(ok) ans = max(ans, __builtin_popcount(i));
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
import math

n,d=map(int,input().split())
x={}
for a in range(0,n):
    x[a]=list(map(int,input().split()))
cou=0
for i in range(0,n):
    for j in range(i+1,n):
        s=0
        for b in range(0,d):
            s=s+(x[i][b]-x[j][b])**2
        if math.sqrt(s).is_integer()==True:
           cou=cou+1
print(cou)


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
int n,i;
  double money=0;
  scanf("%d",&n);
   double x[n];
  double sum=0;
  char u[n][3];
  for(i=0;i<n;i++){
  scanf("%lf",&x[i]);
    scanf("%s",u[i]);
  }
  for(i=0;i<n;i++){
  if(u[i][0]=='J'){
  sum=sum+x[i];
  }else{
  money=x[i]*380000.0;
    sum=sum+money;
  }
  }
  printf("%f",sum);
  return 0;
}

Measured memory_bytes: 128
w="bcdefghijklmnopqrstuvwxyza"
d={}
for i in xrange(len(w)):
    d[w[i]]=25-i
ss=raw_input()
s=[]
for i in xrange(len(ss)):
    s.append(ss[i])
K=int(raw_input())
for i in xrange(len(s)):
    if d[s[i]]<=K:
        K -= d[s[i]]
        s[i]="a"
K%=26
s[len(s)-1]=w[(25-d[s[len(s)-1]]+K)%26]
print "".join(s)

Measured memory_bytes: 3692
def main():
    N = int(input())
    MOD = 10**9 + 7
    memo = [{} for i in range(N+1)]

    def is_ok(last4):
        for i in range(4):
            t = list(last4)
            if i >= 1:
                t[i-1], t[i] = t[i], t[i-1]
            if "".join(t).count("AGC") >= 1:
                return False
        return True

    def dfs(cur, last3):
        if last3 in memo[cur]:
            return memo[cur][last3]
        if cur == N:
            return 1
        ret = 0
        for c in "AGCT":
            if is_ok(last3 + c):
                ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
        memo[cur][last3] = ret
        return ret

    print(dfs(0, "TTT"))


if __name__ == '__main__':
    main()


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

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

int32_t main(){
  DESYNC;
  int n,m;
  cin >> n >> m;
  vector<int> s[n];
  for(int i=0; i<m; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      int x;
      cin >> x;
      x--;
      s[x].pb(i);
    }
  }
  int p[m];
  for(int i=0; i<m; i++){
    cin >> p[i];
  }
  int ans = 0;
  for(int msk = 0; msk < (1<<n); msk++){
    vector<bool> on(m);
    for(int i=0; i<m; i++) on[i] = false;
    for(int i=0; i<n; i++){
      if(msk & (1<<i)){
        for(int x : s[i]) on[x] = !on[x];
      }
    }
    int cnt = 0;
    for(int i=0; i<m; i++) cnt += (on[i] == p[i]);
    if(cnt == m) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#define MOD 1000000007
using namespace std;
const int MAXN = 205;
typedef long long ll;
struct Edge{
  int to,next;
}e[MAXN<<1];
int head[MAXN],n,cnt=1,m,c,cut_cnt;
inline void insert(int u,int v)
{
  e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
  e[++cnt].to=u,e[cnt].next=head[v],head[v]=cnt;
}
set<int>block[MAXN];
int dfn[MAXN],low[MAXN],block_cnt,dfs_clock,stk[MAXN],top,cut[MAXN];
void tarjan(int x,int fa,int from)
{
  low[x]=dfn[x]=++dfs_clock,stk[++top]=x;
  for(int i=head[x];i;i=e[i].next){
    int v=e[i].to;
    if(v==fa)continue;
    if(!dfn[v]){
      tarjan(v,x,i);
      if(low[v]>=dfn[x]){
	int u;
	cut[i]=cut[i^1]=true;
	++cut_cnt;
		
	++block_cnt;
	while(true){
	  u=stk[top--];
	  block[block_cnt].insert(u);
	  if(u==v)break;
	}
	block[block_cnt].insert(x);
      }
      low[x]=min(low[x],low[v]);
    }
    else low[x]=min(low[x],dfn[v]);
  }	
}
inline ll gcd(ll a,ll b)
{
  return b==0?a:gcd(b,a%b);
}
inline ll ksm(ll x,ll k)
{
  ll ret=1;
  while(k){
    if(k&1)ret=ret*x%MOD;
    x=x*x%MOD;
    k>>=1;
  }
  return ret;
}
ll fac[MAXN*10],inv[MAXN*10];
inline ll C(int n,int m)
{
  return fac[m]*inv[n]%MOD*inv[m-n]%MOD;
}
inline void init()
{
  fac[0]=1;
  for(int i=1;i<=2000;++i)fac[i]=fac[i-1]*i%MOD;
  inv[2000]=ksm(fac[2000],MOD-2);
  for(int i=1999;i>=0;--i)inv[i]=inv[i+1]*(i+1)%MOD;
}
int main()
{
  init();
  scanf("%d%d%d",&n,&m,&c);
  for(int i=1;i<=m;++i){
    int u,v;
    scanf("%d%d",&u,&v);
    insert(u,v);
  }
  for(int i=1;i<=n;++i){
    if(!dfn[i])tarjan(i,0,0);
  }
  ll ans=1;
  for(int i=1;i<=block_cnt;++i){
    int n_cnt=block[i].size(),m_cnt=0;
    for(set<int>::iterator j=block[i].begin();j!=block[i].end();++j){
      for(int k=head[*j];k;k=e[k].next){
	if(block[i].count(e[k].to))++m_cnt;
      }
    }
    m_cnt>>=1;
    if(m_cnt>n_cnt){
      ans=ans*C(c-1,m_cnt+c-1)%MOD;
    }else if(m_cnt==n_cnt){
      ll t=0;
      for(int i=0;i<n_cnt;++i){
	t=(t+ksm(c,gcd(i,n_cnt)))%MOD;
      }
      ans=ans*t%MOD*ksm(n_cnt,MOD-2)%MOD;
    }else{
      ans=ans*c%MOD;
    }
  }
  cout<<ans%MOD<<endl;
  return 0;
}


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

def cycle_search(i):
    next_search_ind=i
    ret=[]
    while 1:
        now_ind=next_search_ind
        next_search_ind=sorted_A.index(A[now_ind])
        ret.append(A[now_ind])
        cycle_searched[now_ind]=True
        if cycle_searched[next_search_ind]:
            break
    return ret


sorted_A=sorted(A)

cycles=[]
cycle_searched=[False]*n

for i in range(n):
    if cycle_searched[i] == False:
        cycles.append(cycle_search(i))

ans=0
min_A=sorted_A[0]
for cycle in cycles:
    cycle_len=len(cycle)
    if cycle_len == 1:
        continue
    else:
        ans1 = sum(cycle)+(cycle_len-2)*min(cycle)
        min_cycle=min(cycle)
        ans2 = sum(cycle)-min_cycle+min_A+(cycle_len-2)*min_A+2*(min_A+min_cycle)
        ans += min(ans1,ans2)

print(ans)


Measured memory_bytes: 5724
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1e9+7
#define INF 1e9
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;


int main(void){
    int N,cnt=0;
    cin>>N;
    VI a(N,0),b(N,0),c(N,0);
    int k;cin>>k;
    REP(i,k){int j;cin>>j;a[j-1]=1;}
    cin>>k;
    REP(i,k){int j;cin>>j;b[j-1]=1;}
    cin>>k;
    REP(i,k){int j;cin>>j;c[j-1]=1;}

    REP(i,N){
        if((a[i]==0||b[i]==1)&&c[i]==1){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    
}





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

int main(){
  int n;
  vector<queue<char>> vec_input(1);
  string str_input;

  cin >> n;
  cin >> str_input;

  rep(i, str_input.size()) {
    vec_input[0].push(str_input[i]);
  }

  int x = 0, max = 0;
  while(true) {
    if (vec_input[0].empty()) break;
    char order = vec_input[0].front();
    vec_input[0].pop();
    if (order == 'I') x += 1;
    else if (order == 'D') x -= 1;

    if (x > max) max = x;
  }

  cout << max << endl;
}


Measured memory_bytes: 256
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define pb	push_back
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	100005
#define P	1000000007

int		N, Ans= 1, A[n];

int		main(int argc, char* argv[]){
		N= IN();
		
		int	now= 1, cnt= 0;
		For(i, 1, N)	{
			int x= IN();
			
			if	(now <= x)	now+= 2, cnt++;
				else	Ans= 1ll*Ans*(cnt+1)%P;
		}
		
		For(i, 1, cnt)	Ans= 1ll*Ans*i%P;
		
		printf("%d\n", Ans);
		
		return	0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
#define INF 1000000000
#define PI 3.14159265359

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

    ll X;
    cin >> X;
    ll ans = 0;
    ll m = 100;


    while(true){
        ans += 1;
        m = m*1.01;
        if (m >= X){
            cout << ans << endl;
            break;
        }
        

    }

}

Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
    if(x-r>=0&&x+r<=W){
        if(y-r>=0&&y+r<=H){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    else{
        printf("No\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x=0;
	cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  while(1){
    for(int i=0;i<n;i++){
      if(a[i]%2!=0){
        cout << x <<endl;
        return 0;
      }
      a[i]/=2;
    }
    x++;
  }
  return 0;
}




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

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

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using DoP = pair<double, double>;
using edge = struct { int to; double cost;}; // edge x = {to, cost}

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1<<29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;

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

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main(){
  int n, k;
  cin >> n >> k;
  vector<vector<int>> a(k);
  vector<int> snu(n+1, 0);
  rep(i, k) {
    int d; cin >> d;
    rep(j, d) {
      int x; cin >> x;
      ++snu[x];
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i) if(snu[i] == 0) ++ans;
  cout <<ans << endl;
}

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

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

    int ans = 0;
    for(int i = 0;i < n;i++){
        ans += l+i;
    }

    int tmp = INT_MAX;
    int ans2 = 0;
    int aaa;
    for(int i = 0;i < n;i++){
        ans2 = 0;
        for(int j = 0;j < n;j++){
            if(i != j){
                ans2 += l+j;
            }
        }
        if(abs(ans-ans2) < tmp){
            tmp = abs(ans-ans2);
            aaa = ans2;
        }
    }

    cout << aaa << endl;

    return 0;
}


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

int main(void){
	int n, i, k=0, p;

	scanf("%d", &n);
	
	for(i = 0 ; i < n ; i++){
		scanf("%d",&p);
		if(p != i + 1){
			k++;
		}
	}

	if(k > 2){
		printf("NO\n");
	}else{
		printf("YES\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;

  int N = a.size();
  int M = b.size();

  if(N > M){
    cout << "GREATER" << endl;
    return 0;
  }
  if(N < M){
    cout << "LESS" << endl;
    return 0;
  }

  for(int i=0;i<N;i++){
    if(a[i] > b[i]){
      cout << "GREATER" << endl;
      return 0;
    }
    if(a[i] < b[i]){
      cout << "LESS" << endl;
      return 0;
    }
  }

  cout << "EQUAL" << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

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

	map<char,ll> cnts;
	for (char c : s) cnts[c]++;
    
    ll ret = cnts['R'] * cnts['G'] * cnts['B'];
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j += 2){
            if (s[i] != s[j] &&
				s[i] != s[(i + j) / 2] && 
				s[j] != s[(i + j) / 2]
			) {
				ret--;
			}
        }
    }
    
    cout << ret << endl;
}


Measured memory_bytes: 3616
n,m=map(int,(input().split()))

import numpy as np
p = [0] * m
s = [''] * m
mat=[]

for i in range(m):
    p[i],s[i]=input().split()
    mat.append([p[i],s[i]])

#print(n,m)
#print(p)
#print(s)
#print(mat)

kariwa=[0]*n
wa=[0]*n
anstrue=[False]*n

for i in range(m):
    if mat[i][1] == "WA" and anstrue[int(mat[i][0])-1]==False:
        kariwa[int(mat[i][0])-1]+=1
    elif mat[i][1] == "AC" and anstrue[int(mat[i][0])-1]==False:
        anstrue[int(mat[i][0])-1]=True
        wa[int(mat[i][0])-1]=kariwa[int(mat[i][0])-1]

print(sum(anstrue),sum(wa))

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            Console.WriteLine(int.Parse(str[0])-int.Parse(str[1])+1);
            
        }
    }
}


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

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    string S;
    int Q;
    cin>>S>>Q;

    bool Re=false;

    rep(i,Q){
        int T;
        cin>>T;
        if(T==1){
            Re=!Re;
        }else{
            int F;
            char C;
            cin>>F>>C;
            if(F==1){
                if(Re)
                    S.pb(C);
                else
                    S.insert(0,1,C);
            }else{
                if(Re)
                    S.insert(0,1,C);
                else
                    S.pb(C);
            }
        }
    }
    if(Re)reverse(ALL(S));

    cout<<S<<endl;

    return 0;
}

//a=97,z=122

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

void fnInput(int &riElmCnt, vector<int> &rviElm, int &riTrgCnt , vector<int> &rviTrg )
{
  cin >> riElmCnt;

  rviElm.resize(riElmCnt);
  for (int i = 0; i < riElmCnt; i++)
    cin >> rviElm[i];

  cin >> riTrgCnt;

  rviTrg.resize(riTrgCnt);
  for (int i = 0; i < riTrgCnt; i++)
    cin >> rviTrg[i];
}

int fnRcsSch(int iPos, int iTrg, const vector<int> &cnrviElm, vector<vector<int>> &rvviOK)
{
  if (!iTrg)                    return 1;
  if (iTrg < 0)                 return 0;
  if (iPos == cnrviElm.size())  return 0;
  if (rvviOK[iPos][iTrg] != -1) return rvviOK[iPos][iTrg];

  int iRtn, iSmallTarget;

  iRtn = fnRcsSch(iPos + 1, iTrg, cnrviElm, rvviOK);
  rvviOK[iPos + 1][iTrg] = iRtn;
  if (iRtn)  return iRtn;

  iRtn = fnRcsSch(iPos + 1, iTrg - cnrviElm[iPos], cnrviElm, rvviOK);
  if (iTrg - cnrviElm[iPos] >= 0)
    rvviOK[iPos + 1][iTrg - cnrviElm[iPos]] = iRtn;
  return iRtn;
}

void fnExhSch(const vector<int> &cnrviElm, const vector<int> &cnrviTrg)
{
  vector<vector<int>> vviOK(21, vector<int>(2001, -1));
  
  for (int i = 0; i < cnrviTrg.size(); i++)
  {
    int iTrg = cnrviTrg[i];
    int iRtn;

    if (iRtn = fnRcsSch(0, iTrg, cnrviElm, vviOK))
      cout << "yes" << endl;
    else
      cout << "no" << endl;

    vviOK[0][iTrg] = iRtn;
  }
}

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

  int iElmCnt, iTrgCnt;
  vector<int> viElm, viTrg;

  fnInput(iElmCnt, viElm, iTrgCnt, viTrg);
  fnExhSch(viElm, viTrg);

  return 0;
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi x(n);
    rep(i, n) cin >> x[i];
    ll ans = 0LL;
    ll l = 0, r = 1, s = x[0];
    while(r < n) {
        if((s+x[r]) == (s|x[r])) {
            s += x[r++];
        }
        else {
            ll d = r - l;
            ans += d;
            s -= x[l++];
            if(l == r) {
                s = x[l];
                r++;
            }
        }
    }
    {
        ll d = r - l;
        ans += d*(d+1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
S = input()

ans = S[1:].count('E')
tmp = ans
for i in range(1, N):
  if S[i] == 'E':
    tmp -= 1
  if S[i-1] == 'W':
    tmp += 1
  if tmp<ans:
    ans=tmp
print(ans)


Measured memory_bytes: 3676
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

X = d_in()

if X in [3, 5, 7]:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MOD=1e9+7;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int Mult(int x,int y){long z=x*y-(long)((long double)x/MOD*y+1e-8)*MOD;return z;}
static inline void Radix(int A[],const int N)
{
  int temp[200001];
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,N)u[A[i]>>8*k&255]++;
    rep(i,255)u[i+1]+=u[i];
    rep(i,N){temp[--u[A[N-1-i]>>8*k&255]]=A[N-1-i];}k++;
    rep(i,N)v[temp[i]>>8*k&255]++;
    rep(i,255)v[i+1]+=v[i];
    rep(i,N)A[--v[temp[N-1-i]>>8*k&255]]=temp[N-1-i];
  }
}
int main()
{
  int N=IN(),K=IN(),m=0,p=0,z=0,accum=1,A[200000];long one=0,another=0;
  rep(i,N){A[i]=IN();if(A[i]>0)p++;else if(A[i]<0)m++;else z++;}
  Radix(A,N);
  if(K==N){if(z){return puts("0"),0;}else{rep(i,K){accum=Mult(accum,A[i]);}K=0;}}
  if(m+p<K)return puts("0"),0;
  if(!p&&K&1){if(z){return puts("0"),0;}else rep(i,K){accum=Mult(accum,A[N-1-i]);}K=0;}
  p+=z,m=p;
  if(K&1){K--;accum=Mult(accum,A[--p]);}
  while(K)
  {
    K-=2;one=1l*A[p-1]*A[p-2],another=1l*A[m]*A[m+1];
    if(p>=2&&m<=N-2&&one>another){accum=Mult(accum,one%MOD),p-=2,one=1l*A[p-1]*A[p-2];continue;}
    if(p>=2&&m<=N-2&&one<another){accum=Mult(accum,another%MOD),m+=2,another=1l*A[m]*A[m+1];continue;}
    if(p>=2){accum=Mult(accum,one%MOD),p-=2,one=1l*A[p-1]*A[p-2];continue;}
    if(m<=N-2){accum=Mult(accum,another%MOD),m+=2,another=1l*A[m]*A[m+1];continue;}
  }
  return printf("%d\n",accum<0?accum+MOD:accum),0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <math.h>

int main(){
	
	int x, y, z;
	
 	std::cin >> x >> y >> z;

	if(x<y && y<z){
		std::cout  << "Yes" << std::endl;
	}else{
		std::cout  << "No" << std::endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    string s,t;
    cin >> s >> t ;
    cout << t + s << endl;

    return 0;
}

Measured memory_bytes: 256