akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

LL a[200005];
bool x[200005][20];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (int j = 0; j < 20; j++) {
            x[i][j] = (a[i] & (1 << j)) > 0;
        }
    }

    bool cur[20];
    memset(cur, 0, sizeof(cur));

    LL ans = 0;
    int l = 0, r = 0;
    while (l < n) {
        bool ok = r < n;
        for (int j = 0; j < 20; j++) {
            if (cur[j] && x[r][j]) {
                ok = false; break;
            }
        }
        if (ok) {
            for (int j = 0; j < 20; j++) {
                if (x[r][j]) {
                    cur[j] = true;
                }
            }
            r++;
        } else {
            for (int j = 0; j < 20; j++) {
                if (cur[j] && x[l][j]) {
                    cur[j] = false;
                }
            }
            // printf("l = %d, r = %d\n", l, r);
            ans += (r - l);
            l++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int a[n+1];
  int b[n];
  ll sum0 = 0;
  for(int i = 0; i < n+1; i++){
    cin>>a[i];
    sum0+=a[i];
  }
  for(int i = 0; i < n; i++){
    cin>>b[i];
  }
  for(int i = 0; i < n; i++){
    if(a[i]>b[i]){
      a[i]-=b[i];
    }
    else{
      int tmp = a[i];
      a[i]=0;
      a[i+1]=max(a[i+1]-(b[i]-tmp),0);
    }
  }
  ll sum1 = 0;
  for(int i = 0; i < n+1; i++){
    sum1+=a[i];
  }
  cout<<sum0-sum1<<endl;
  return 0;
}

  



Measured memory_bytes: 1024
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, a, n) for (long long i = a; i <= n; i++)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#pragma endregion
int main() {
    IO;
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1) mp[n]++;
    ll ans = 0;
    for (auto it : mp) {
        ll i;
        for (i = 1; i * (i + 1) / 2 <= it.second; ++i)
            ;
        ans += i - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
H, W = map(int, input().split())
sh, sw = map(lambda x:int(x)-1, input().split())
eh, ew = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(H)]

INF = 10**9
dst = [[INF]*W for _ in range(H)]
dst[sh][sw] = 0

from collections import deque
dq = deque([(sh, sw)])
while dq:
    h, w = dq.popleft()
    for dh in range(-2, 3):
        for dw in range(-2, 3): # [dh,dw]:[-2,-2]~[2,2]
            nh = h + dh; nw = w + dw
            if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.':
                f = dh*dh + dw*dw # 上下左右か否か
                if f == 1 and dst[nh][nw] > dst[h][w]:
                    dst[nh][nw] = dst[h][w]
                    dq.appendleft((nh, nw))
                elif f > 1 and dst[nh][nw] > dst[h][w] + 1:
                    dst[nh][nw] = dst[h][w] + 1
                    dq.append((nh, nw))

print(-1 if dst[eh][ew]==INF else dst[eh][ew])


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

x, y = map(int, input().split())

exist_flag = False

for i in range(x + 1):
  total = 2 * i + 4 * (x - i)
  if total == y:
    exist_flag = True
    break

if exist_flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).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;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int field[12][12];

void dfs(int x, int y) {
  if(x < 0 || 11 < x || y < 0 || 11 < y || field[x][y] == 0) return;
  
  field[x][y] = 0;
  REP(i, 4) {
    int tx = x+dx[i], ty = y+dy[i];
    dfs(tx, ty);
  }
}

int main() {
  int n = 12;
  string s;

  while(getline(cin, s)) {
    REP(i, n) field[0][i] = s[i] - '0';
    FOR(i, 1, n) {
      getline(cin, s);
      REP(j, n) {
	field[i][j] = s[j] - '0';
      }
    }
    
    int ans = 0;
    REP(i, n) {
      REP(j, n) {
	if(field[i][j] == 1) {
	  ans++;
	  dfs(i, j);
	}
      }
    }
    cout << ans << endl;

    getline(cin, s);
  }
}

Measured memory_bytes: 1172
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize;n],
        q: usize,
        bc: [(usize,usize);q],
    }

    let mut map = BTreeMap::new();
    let mut s = 0;
    for e in a {
        *map.entry(e).or_insert(0usize) += 1;
        s += e;
    }

    for (b, c) in bc {
        let mut tmp = 0;
        if let Some(count) = map.get(&b) {
            tmp = *count;
        }
        map.remove(&b);
        *map.entry(c).or_insert(0) += tmp;
        s = s - b * tmp + c * tmp;
        println!("{}", s);
    }
}


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


int n;
string a[10005];


bool largr(string x, string y)
{
    string t = x + y;
    string r = y + x;
    if (t < r) return true;
    return false;
}

int m;
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a,a+n,largr);
    for (int i = 0; i < n; i++) cout << a[i];
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll H, N;
    cin >> H >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 0;
    rep(i, N) sum += A[i];
    if(H <= sum) output("Yes");
    else output("No");
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    string A(n, '-');
    for(auto& e : A) cin >> e;

    vector<vector<vll>> dp(n + 1, vector<vll>(n + 1, vll(n + 1)));
    dp[0][0][0] = 1;

    rep(i, n){
        rep(j, n){ // null rank
            rep(k, n){ // person stock
                int cur = dp[i][j][k];
                if(cur == 0) continue;

                auto& nvec = dp[i + 1];
                if(A[i] == 'U'){
                    nvec[j + 1][k + 1] = ADD(nvec[j + 1][k + 1], cur, mod);
                    if(k > 0){
                        nvec[j][k] = ADD(nvec[j][k], MUL(cur, k, mod), mod);
                    }
                }
                else if(A[i] == 'D'){
                    if(j > 0){
                        nvec[j][k] = ADD(nvec[j][k], MUL(cur, j, mod), mod);
                        if(k > 0){
                            nvec[j - 1][k - 1] = ADD(nvec[j - 1][k - 1], MUL(cur, j * k, mod), mod);
                        }
                    }
                }
                else { // A[i] == '-'
                    nvec[j][k] = ADD(nvec[j][k], cur, mod);
                }
            }
        }
    }

    cout << dp[n][0][0] << endl;

    return 0;
}

Measured memory_bytes: 67816
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
const Int MAX = 2002;
using BS = bitset<MAX*2>;
void det(vector<BS> &v){
  int n=v.size();
  for(Int i=0;i<n;i++){
    for(Int k=i;k<n;k++){
      if(v[k][i]){
	swap(v[i],v[k]);
	break;
      }
    }
    for(Int k=0;k<n;k++)
      if(i!=k&&v[k][i]) v[k]^=v[i];
  }
}
//END CUT HERE
signed CFR382_D(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  vector<BS> v(n,BS(0));
  for(Int i=0;i<n;i++) v[i][n+i]=1;
  vector<Int> a(m),b(m);
  for(Int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    v[a[i]][b[i]]=1;
  }
  det(v);
  for(Int i=0;i<m;i++)
    cout<<(v[b[i]][a[i]+n]?"NO":"YES")<<endl;
  return 0;
}
/*
verified on 2018/01/09
http://codeforces.com/contest/736/problem/D
*/

signed ARC054_D(){
  int n;
  cin>>n;
  vector<BS> v(n,BS(0));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      char c;
      cin>>c;
      v[i][j]=c-'0';
    }
  }
  det(v);
  int ans=1;
  for(int i=0;i<n;i++) ans&=v[i][i];
  cout<<(ans?"Odd":"Even")<<endl;
  return 0;
}
/*
verified on 2018/01/09
https://beta.atcoder.jp/contests/arc054/tasks/arc054_c
*/

signed AOJ_1308(){
  int m,n,d;
  while(cin>>m>>n>>d,m){
    vector<vector<int> > s(n,vector<int>(m));
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
	cin>>s[i][j];

    vector<BS> v(n*m,BS(0));
    auto idx=[&](int y,int x){return y*m+x;};
    auto in=[&](int y,int x){return 0<=y&&y<n&&0<=x&&x<m;};
    auto bfs=[&](int y,int x){
      int z=idx(y,x);
      v[z][z]=1;
      v[z][n*m]=s[y][x];
      
      vector<vector<int> > dp(n,vector<int>(m,-1));
      using P = pair<int, int>;
      queue<P> q;
      dp[y][x]=0;
      q.emplace(y,x);
      int dy[]={0,0,1,-1};
      int dx[]={1,-1,0,0};
      while(!q.empty()){
	tie(y,x)=q.front();q.pop();
	if(dp[y][x]==d) v[z][idx(y,x)]=1;
	for(int k=0;k<4;k++){
	  int ny=y+dy[k],nx=x+dx[k];
	  if(!in(ny,nx)||~dp[ny][nx]) continue;
	  dp[ny][nx]=dp[y][x]+1;
	  q.emplace(ny,nx);
	}
      }
    };
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
	bfs(i,j);
    
    auto u=v;
    det(v);
    int ans=1;
    for(int i=0;i<n*m;i++){
      int tmp=s[i/m][i%m];
      for(int j=0;j<n*m;j++) tmp+=u[i][j]&v[j][n*m];
      ans&=!(tmp&1);
    }
    cout<<ans<<endl;
  }
  return 0;
}
/*
verified on 2018/01/09
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1308
*/

signed main(){
  //CFR382_D();
  //ARC054_D();
  AOJ_1308();
  return 0;
}



Measured memory_bytes: 3580
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
const int N = 1e5;
ll n, k;
ll w[N], d[N];
 
ll count(ll x){
    ll ret = 0;
    REP(i,n){
        if (x >= w[i]) ret += 1 + (x - w[i]) / d[i];
        if (ret > k) return ret;
    }
    return ret;
}
 
int main() {
    cin >> n >> k;
    REP(i,n) scanf("%lld %lld", w+i, d+i);
 
    ll le = 0, ri = 2e18;
    while (ri - le > 1){
        ll mi = le + (ri - le) / 2;
        if (count(mi) >= k) ri = mi;
        else le = mi;
    }
    cout << ri << endl;
 
    return 0;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

struct UnionFind{
    vector<int> data;
    UnionFind(int size){
        data=vector<int>(size,-1);
    }
    bool union_set(int x,int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];
            data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    ll N,K;
    cin>>N>>K;
    ll ans=K;
    FOR(i,N-1)ans*=(K-1);
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


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

int main(){
	int n,num,card[5][14];
	char m;
	for(int M=0;M<4;M++){
		for(int N=1;N<=13;N++){
			card[M][N]=0;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m>>num;
		switch(m){
			case 'S': card[0][num]=1; break;
			case 'H': card[1][num]=1; break;
			case 'C': card[2][num]=1; break;
			case 'D': card[3][num]=1; break;
		}
	}
	for(int M=0;M<4;M++){
		for(int N=1;N<=13;N++){
			if(card[M][N]==1) continue;
			if(M==0) m='S';
			if(M==1) m='H';
			if(M==2) m='C';
			if(M==3) m='D';
			cout<<m<<" "<<N<<endl;
		}
	}
		
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

const ll INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

const int N = 17, MSK = 1 << N;
ll dp[MSK], c[MSK];
int a[N][N], n;
bool vis[MSK];

ll solve(int msk)
{
    if(msk == 0)
        return 0;

    ll& ans = dp[msk];

    if(!vis[msk])
    {
        ans = -INF;

        for(int sub = msk; sub > 0; sub = (sub - 1) & msk)
            ans = max(ans, c[sub] + solve(msk ^ sub));
        
        vis[msk] = true;
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    
    cin >> n;
    
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];

    for(int msk = 0; msk < (1 << n); msk++)
        for(int i = 0; i < n; i++)
            for(int j = i + 1; j < n; j++)
                if((msk & (1 << i)) && (msk & (1 << j))) c[msk] += a[i][j];

    cout << solve((1 << n) - 1) << endl;

    return 0;
}

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    ll N; cin >> N;
    string S; cin >> S;

    ll ans = 0;

    for (int i = 0; i < S.size(); ++i) {

        vector<ll> l(30, 0);
        vector<ll> r(30, 0);

        ll tmp = 0;

        for (int j = 0; j <= i; ++j) {
            ++l[S[j] - 'a'];
        }

        for (int j = i+1; j < S.size(); ++j) {
            ++r[S[j] - 'a'];
        }

        for (int j = 0; j < 30; ++j) {
            if (l[j] > 0 && r[j] > 0) {
                ++tmp;
            }
        }

        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

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

const long long INF = 1LL << 60; // これはなに？

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

int main() {
	int N, K; cin >> N >> K;
	vector<int> h(N); for(int i = 0; i < N; ++i) cin >> h[i];
	vector<long long> dp(100000); for(int i = 0; i < 100000; ++i) dp[i] = 100000000010; // DPテーブル

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

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

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

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

void solve(long long N, std::vector<long long> A)
{
    ll ans = LONG_MAX;

    for (ll i = 0; i < N - 1; i++)
    {
        ll temp = gcd(A.at(i),A.at(i+1));
        ans = min(ans,temp);
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
//AtCoder ABC107 B - Grid Compression
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll H,W; cin>>H>>W;
    vector<string> hw(H);
    for(auto& a:hw){
        cin>>a;
    }
    //
    unordered_set<ll> drow;
    unordered_set<ll> dcol;
    auto check_row=[&](ll y){
        bool rslt=true;
        for(auto&& s:hw[y]){
            if(s!='.') {
                rslt=false;
                break;
            }
        }
        if(rslt) drow.insert(y);
    };
    auto check_col=[&](ll x){
        bool rslt=true;
        for(ll y=0;y<hw.size();++y){
            if(hw[y][x]!='.'){
                rslt=false;
                break;
            }
        }
        if(rslt) dcol.insert(x);
        return false;
    };
    for(ll y=0;y<hw.size();++y){
        check_row(y);
    }
    for(ll x=0;x<hw[0].size();++x){
        check_col(x);
    }
    for(ll y=0;y<hw.size();++y){
        if(drow.count(y)) continue;
        for(ll x=0;x<W;++x){
            if(dcol.count(x)) continue;
            cout<<hw[y][x];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import product
from bisect import bisect_right
def main():
    n = int(input())
    n_753 = []
    for i in range(3, 10):
        for s in product(['3', '5', '7'], repeat = i):
            if len(set(s)) != 3:
                continue
            n_753.append(int(''.join(s)))
    n_753.sort()
    print(bisect_right(n_753, n))
if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
// review
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;

struct Query {
  ll type, i, l, r;
  char c;
};

const int MAXQ = 20010;

ll n;
ll q;
string s;

Query queries[MAXQ];

void solve() {
  set<int> positions[26];
  for (int i=0;i<n;i++) {
    positions[s[i]-'a'].insert(i + 1);
  }
  for (int i=0;i<q;i++) {
    Query& query = queries[i];
    if (query.type == 1) {
      positions[s[query.i - 1] - 'a'].erase(query.i);
      positions[query.c-'a'].insert(query.i);
      s[query.i - 1] = query.c;
    } else {
      int cnt = 0;
      for(int j=0;j<26;j++) {
        auto iter = positions[j].lower_bound(query.l);
        if (iter != positions[j].end() && *iter <= query.r) {
          cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
}

int main() {
  cin >> n >> s >> q;
  for (int i=0;i<q;i++) {
    Query& query = queries[i];
    cin >> query.type;
    if (query.type == 1) {
      cin >> query.i >> query.c;
    } else {
      cin >> query.l >> query.r;
    }
  }
  solve();
}


Measured memory_bytes: 24964
#include<bits/stdc++.h>
using namespace std;
int main(){
char s[200006],t[200006];
cin>>s>>t;
int l,c=0,i;
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]!=t[i])
c++;
}
cout<<c<<endl;
}

Measured memory_bytes: 3992
#[allow(unused_imports)]
use proconio::{input, fastout};
#[allow(unused_imports)]
use proconio::marker::{Chars};

#[fastout]
fn main() {
  input! {
    n:usize,k:usize,
    mut p:[usize;n]
  }
  p.sort();
  p.split_off(k);
  println!("{}",p.iter().sum::<usize>())
}


Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  cout << 2 * M_PI * n << endl;
}


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

int gcd(long a,long b){
	long r,tmp;
	if(a<b){
    	tmp = a;
    	a = b;
    	b = tmp;
  	}
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
	return b;
}
int main(void){
	long N,X;
	long i,j;
	long x[100000];
	scanf("%ld %ld",&N,&X);
	for(i=0;i<N;i++){
		scanf("%ld",&x[i]);
		x[i] = labs(x[i]-X);
	}
	long ans = x[0];
	for(i=0;i<N-1;i++){
		ans = gcd(x[i],x[i+1]);
		x[i+1]=ans;
	}
	printf("%ld",ans);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const int MAX_N=100001;
const ll LINF=100000000000000000;

ll h[MAX_N],N,A,B;

bool calc(ll x){
  ll cnt=0;
  rep(i,N){
    ll rest=h[i]-B*x;
    if(rest>0){
      cnt+=(rest+A-B-1)/(A-B);
    }
  }
  return cnt<=x;
}

int main(){
  cin >> N >> A >> B ;
  rep(i,N){
    scanf("%lld",&h[i]) ;
  }
  ll ng=0;
  ll ok=LINF;
  while(abs(ok-ng)>1){
    int mid=(ok+ng)/2;
    if(calc(mid)) ok=mid;
    else ng=mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int n, a, mn, c[9];
int main() {
	cin>>n;
	while(n--) {
		cin>>a;
		if(a>=3200) c[8]++;
		else if(!c[a/400]) c[a/400]=1, mn++;
	}
	cout<<max(mn,1)<<' '<<mn+c[8];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  vector<string> s(3);
  for(ll i=0;i<3;i++) cin >> s[i];
  ll f=1;
  for(ll i=0;i<2;i++) {
    if (s[i][s[i].size()-1]!=s[i+1][0]) f=0;
  }
  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer :: n,count=0,i
integer,allocatable :: h(:)

read*, n
allocate(h(n))
read*, h(1:n)

do i = 1, n, 1
  if ( h(i) >= maxval(h(1:i)) ) then
    count = count + 1
  end if
end do

print'(i0)', count

END PROGRAM ATCODER


Measured memory_bytes: 640
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	
	static int a,b,c;
	static int[]v=new int[11];
	
	static int f(int d,int m) {
		//System.out.println(d+" "+m);
		if(m<0)
			return 0;
		if(d==b+1)
			return m==0?1:0;
		int sum=0;
		for(v[d]=v[d-1]+1;v[d]<=a;++v[d]) {
			sum+=f(d+1,m-v[d]);
		}
		return sum;
	}
	
	public static void main(String[] $){
		while(true) {
			a=s.nextInt();
			if(a==0)return;
			b=s.nextInt();
			c=s.nextInt();
			
			System.out.println(f(1,c));
		}
	}
}


Measured memory_bytes: 27732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		int begin = 0;
		int end = 0;

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A') {
				begin = i;
				break;
			}
		}

		for (int i = s.length() - 1; i >= 0; i--) {
			if (s.charAt(i) == 'Z') {
				end = i;
				break;
			}
		}

		System.out.println(end - begin + 1);
	}
}

Measured memory_bytes: 26764
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll a=in();
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
void solveA()
{
  long long a,b,tem;
  cin>>a>>b;
  tem=(a+b);
  if(tem%2==0)
  {
    cout<<tem/2<<endl;
  }
  else
  {
    cout<<"IMPOSSIBLE"<<endl;
  }
}
void solveB()
{
  int n,i,j,count;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  j=1;
  count=0;
  for(i=0;i<n;i++)
  {
    if(ar[i]!=j)
    {
      count++;
    }
    if(count>2)
    {
      cout<<"NO"<<endl;
      return;
    }
    j++;
  }
  cout<<"YES"<<endl;
}
void solveC()
{
  int a,b,x,y;
  cin>>a>>b;
  x=max(a,b);
  y=min(a,b);
  if((x-y)>=2)
  {
    cout<<2*x-1<<endl;
  }
  else
  {
    cout<<x+y<<endl;
  }
}
void solveD()
{
  int n,i,j;
  cin>>n;
  int ar[n];
  for(i=0;i<n;i++)
  {
    cin>>ar[i];
  }
  int count=n;
  for(i=n-1;i>=0;i--)
  {
    for(j=i-1;j>=0;j--)
    {
      if(ar[i]<ar[j])
      {
        count--;
        break;
      }
    }
  }
  cout<<count<<endl;
}
void solveE()
{
  int h,w,x,y,H,W;
  cin>>H>>W;
  cin>>h>>w;
  x=h*W;
  y=(H-h)*w;
  cout<<(H*W)-(x+y)<<endl;
}
void solveF()
{
  int n,m,c,i,j;
  cin>>n>>m>>c;
  int b[m];
  int ar[n][m];
  for(i=0;i<m;i++)
  {
    cin>>b[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    {
      cin>>ar[i][j];
    }
  }
  int count=0;
  int sum;
  for(i=0;i<n;i++)
  {
    sum=0;
    for(j=0;j<m;j++)
    {
      sum=sum+ar[i][j]*b[j];
    }
    if((sum+c)>0)
    {
      count++;
    }
  }
  cout<<count<<endl;
}
void solveG()
{
  
}
int main()
{
 // solveA();
  solveB();
 // solveC();
 //solveD();
 //solveE();
// solveF();
  return 0;
}

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

using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
 
template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int h, w, m;
    cin >> h >> w >> m;
    vpii br(h), br2(w);
    for(int i = 0; i < h; ++i)
    {
        br[i].fi = 0;
        br[i].se = i;
    }
    for(int i = 0; i < w; ++i)
    {
        br2[i].fi = 0;
        br2[i].se = i;
    }
    set<pii> s;

    for(int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        ++br[x].fi, ++br2[y].fi;
        s.insert({x, y});
    }
    sort(rall(br));
    sort(rall(br2));

    //cout << "-----------\n";
    //for(int i = 0; i < h; ++i)
        //cout << br[i].fi << " " << br[i].se << "\n";
    //cout << "-----------\n";
    //for(int i = 0; i < w; ++i)
        //cout << br2[i].fi << " " << br2[i].se << "\n";
    //cout << "-----------\n";
    int ans = br[0].fi + br2[0].fi - 1;

    for(int i = 0, j = 0; i < h && j < w; )
    {
        if(!s.count({br[i].se, br2[j].se}))
        {
            cout << ans+1 << "\n";
            exit(0);
        }

        if(i + 1 < h && br[i].fi == br[i+1].fi)
            ++i;
        else if(j + 1 < w && br2[j].fi == br2[j+1].fi)
            ++j;
        else
            break;
    }

    cout << ans << "\n";
}


Measured memory_bytes: 22392
import sys


def solve(inp):
    N = int(inp.readline().strip())

    nums = [[0 for i in range(11)] for i in range(11)]

    for s in range(1, 10):
        for e in range(0, 10):
            n = 0
            # print('--- {} {}'.format(s, e))
            if s == e and s <= N:
                # 1けた
                n += 1
            for d in (10, 100, 1000, 10000, 100000, 1000000):
                start = end = s * d + e
                if start > 200000:
                    continue
                d2 = int(d / 10)
                while d2 >= 10:
                    end += 9 * d2
                    d2 = int(d2 / 10)
                end = min(end, 200000)
                # print('{} {}'.format(start, end))
                if end <= N:
                    n += int(d / 10)
                else:
                    j = start
                    while j <= N:
                        n += 1
                        j += 10
            # print('  --> {}'.format(n))
            # print()
            nums[s][e] = n

    r = 0
    for s in range(1, N + 1):
        if s % 10 != 0:
            r += nums[s % 10][int(str(s)[0])]

    return str(r)


def solve1(inp):
    N = int(inp.readline().strip())

    r = 0
    for i in range(1, N + 1):
        first = int(str(i)[0])
        last = i % 10
        for j in range(1, N + 1):
            if int(str(j)[0]) == last and j % 10 == first:
                r += 1

    return str(r)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


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

int main() {
	int n;
	cin>>n;
	float arr[n];
	for(int i=0;i<n;i++)
	{
	cin>>arr[i];
	}
	sort(arr,arr+n);
	float a=(arr[1]+arr[0])/2;
	for(int i=2;i<n;i++)
	{
	   a=(a+arr[i])/2;
	    
	}
	cout<<a;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll mx = a[0];
  ll ans = 0;
  rep(i,n-1){
    if(mx > a[i+1]) ans += mx - a[i+1];
    else mx = a[i+1];
  }
  cout << ans << endl;
}


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

int main(void){
    int n, k;
    vector <int> x;
    int v;
    int i;
    int ans = 0;
    
    cin >> n >> k;
    for(i = 0; i < n; i++){
        cin >> v;
        x.push_back(v);
    }
    
    for(i = 0; i < n; i++){
        ans += 2 * min(x[i], k - x[i]);
    }
    
    cout << ans << endl;
    
    
    return 0;
}

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> cost;
    cost.push_back(fabs(a - b));
    cost.push_back(fabs(a - c));
    cost.push_back(fabs(b - c));
    
    sort(cost.begin(), cost.end());
    
    cout << cost[0] + cost[1] << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
sn = int(n**.5)
if (sn)*(sn)==n:
    print(len(str(sn)))
    quit()

divisors = []
c = 0
for i in range(int(n**.5)+1, 0, -1):
    if n % i == 0:
        divisors.append(i)
        c += 1
        if i != n // i:
            divisors.append(n//i)
            c += 1
    if c >= 2:
        break

print(len(str(max(divisors))))

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> ws(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> ws.at(i);
    }
    ll s1 = 0;
    ll s2 = accumulate(ws.begin(), ws.end(), 0);
    ll ans = s2;
    for(int i = 0; i < n; ++i){
        s1 += ws.at(i);
        s2 -= ws.at(i);
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from math import sqrt
def inpl(): return list(map(int, input().split()))
R, N = inpl()
while R:
    H = [0] * 41
    r0 = 0
    l0 = 0
    for _ in range(N):
        l, r, h = inpl()
        if l < 0 and r >= 0:
            l0 = max(l0, h)
        if l <= 0 and r > 0:
            r0 = max(r0, h)

        l += (l <= 0)
        r -= (r >= 0)

        for i in range(l, r+1):
            if i != 0:
                H[i+20] = max(H[i+20], h)
    H[20] = min(l0, r0)
    ans = 20
    for x in range(-R+1, R):
        time = R - sqrt(R**2 - x**2) + H[x+20]
        ans = min(ans, time)
    print(ans)
    R, N = inpl()



Measured memory_bytes: 5696
n = int(input())
a = list(map(int, input().split()))
m = 1000
x = []
tnp = [a[0]]
for i in range(1,n):
    if (a[i-1]>a[i]):
        x.append(tnp)
        tnp = [a[i]]
    else:
        tnp.append(a[i])
x.append(tnp)
#print(x)
ans = 1000
for i in range(len(x)):
    if (len(x[i])>1):
        ans = ans%min(x[i]) + ans//min(x[i])*max(x[i])
        
print(ans)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
const ll LINF = 1e18;
const int INF = 1e9;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans;
    rep(i,5){
        int x; cin >> x;
        if(x==0) ans=i;
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 3608
a=["","",""]
for i in range(3):
    a[i]=int(input())
x=int(input())
cnt=0
for i in range(a[0]+1):
    for j in range(a[1]+1):
        for k in range(a[2]+1):
            ans = x-500*i - 100*j - 50*k
            if ans==0:
                cnt+=1
print(cnt)

Measured memory_bytes: 3060
/* Dynamic Programming C++ implementation of LCS problem */
#include <bits/stdc++.h>
using namespace std;

int max(int a, int b);

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs(char *X, char *Y, int m, int n)
{
	int L[m + 1][n + 1];
	int i, j;

	/* Following steps build L[m+1][n+1] in 
	bottom up fashion. Note that L[i][j] 
	contains length of LCS of X[0..i-1] 
	and Y[0..j-1] */
	for (i = 0; i <= m; i++)
	{
		for (j = 0; j <= n; j++)
		{
			if (i == 0 || j == 0)
				L[i][j] = 0;

			else if (X[i - 1] == Y[j - 1])
				L[i][j] = L[i - 1][j - 1] + 1;

			else
				L[i][j] = max(L[i - 1][j], L[i][j - 1]);
		}
	}
	int index = L[m][n];

	// Create a character array to store the lcs string
	char lcs[index + 1];
	lcs[index] = '\0'; // Set the terminating character

	i = m, j = n;
	while (i > 0 && j > 0)
	{
		// If current character in X[] and Y are same, then
		// current character is part of LCS
		if (X[i - 1] == Y[j - 1])
		{
			lcs[index - 1] = X[i - 1]; // Put current character in result
			i--;
			j--;
			index--; // reduce values of i, j and index
		}

		// If not same, then find the larger of two and
		// go in the direction of larger value
		else if (L[i - 1][j] > L[i][j - 1])
			i--;
		else
			j--;
	}

	// Print the lcs
	cout << lcs << "\n";
}

/* Utility function to get max of 2 integers */
int max(int a, int b)
{
	return (a > b) ? a : b;
}

// Driver Code
int main()
{

	char X[3000];
	char Y[3000];
	cin >> X >> Y;

	int m = strlen(X);
	int n = strlen(Y);
	
	lcs(X,Y,m,n);

	return 0;
}

// This code is contributed by rathbhupendra


Measured memory_bytes: 35456
#include <iostream>
#include <algorithm>
#include <vector>

int main(int argc, char *argv[]) {
  std::vector<uint16_t> A(3);

  std::cin >> A[0] >> A[1] >> A[2];

  std::sort(A.begin(), A.end());

  uint16_t count = A[2] - A[1];

  // A[0]とA[1]の差が偶数なら2で割った値をプラスする。
  // 奇数の場合は1足した値を2で割ってその値に1を足す(2個を+1する)
  if ((A[1] - A[0])%2 == 0) {
    count += (A[1] - A[0]) / 2;
  } else {
    count += (A[1] - A[0] + 1) / 2 + 1;
  }

  std::cout << count << std::endl;
  return 0;
}


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

int main(){
  using namespace std;
  using ll = long long;
  ll q; cin >> q;
  while(q--) {
    ll a,b; cin >> a >> b;
    if(a>b) swap(a,b);
    if (a == b || a + 1 == b) {
      cout<< a * 2 - 2 << endl;
    } else {
      ll c = sqrt(a * b);
      if (c * c == a * b) c--;
      cout << c * 2 - (c * (c + 1) >= a * b ? 2 : 1) << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    int a,b,c=0;
    a=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    c=n%10;
    if (a==1){
        a=9;
    }
    else if (a==9){
        a=1;
    }
    if(b==1){
        b=9;
    }
    else if(b==9){
        b=1;
    }
    if(c==1){
        c=9;
    }
    else if(c==9){
        c=1;
    }
    cout<<c*100+b*10+a;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int n;
bool t[200][200];

void init(){
  for(int i=0;i<200;i++){
    for(int j=0;j<200;j++){
      t[i][j]=false;
    }
  }
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    int a,b;
    for(int i=0;i<n;i++){
      cin>>a;
      while(a--){
	cin>>b;
	t[i][b]=true;
      }
    }
    int u[200]={};
    cin>>a;
    while(a--){
      cin>>b;
      u[b]=true;
    }
    vector<int> ans;
    for(int i=0;i<n;i++){
      bool flg=true;
      for(int j=0;j<200;j++){
	if(u[j]&&!t[i][j])flg=false;
      }
      if(flg)ans.push_back(i+1);
    }
    if(ans.size()==1)cout<<ans[0]<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    int n, m;
    cin>>n>>m;
    bool res = 0;
    int c[26] = {0};
    for (int i=0; i<n; i++) {
        string s;
        cin>>s;
        for (auto ch: s) c[ch-'a']++;
    }

    int odd = 0;
    int d4 = 0, d2 = 0;
    for (int i=0; i<26; i++) {
        c[i] %= 4;
        d2 += c[i] / 2;
        if (c[i] % 2) odd++;
    }
    if (n % 2 == 0 && m % 2 == 0 && odd == 0 && d2 == 0) res = 1;
    else if (n % 2 && m % 2 && odd == 1 && (n/2 + m/2 - d2) >= 0 && (n/2 + m/2 - d2) % 2 == 0) res = 1;
    else if (n % 2 && m % 2 == 0 && odd == 0 && (m/2 - d2) >= 0 && (m/2 - d2) % 2 == 0) res = 1;
    else if (n % 2 == 0 && m % 2 && odd == 0 && (n/2 - d2) >= 0 && (n/2 - d2) % 2 == 0) res = 1;
    if (res) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int m[1010];

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

  int n = 0;
  vector<int> x = { 0, 0 };
  for (int i = 0; i != s.size(); ++i) {
    if (s[i] == '-') {
      ++n;
      continue;
    }
    if (n >= 2) break;
    ++x[n];
  }

  if (n == 1 && x[0] == a && x[1] == b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    Int cnt = 0;
    for (Int i = 0; i < (Int)s.size(); i++) {
        if (s[i] == 'x') cnt++;
    }
    dump(cnt >= 8 ? "NO" : "YES");
    return 0;
}

Measured memory_bytes: 256