akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N;
int dat[300][300];
ll dp[300][300];

int main() {
	cin >> N;
	REP(i, N) REP(j, N) scanf("%d", &dat[i][j]);
	
	REP(i, N) dp[i][i] = 0;
	REP(i, N) REP(j, N) dp[i][j] = dat[i][j];
	
	REP(k, N) REP(i, N) REP(j, N) chmin(dp[i][j], dp[i][k] + dp[k][j]);
	
	bool ng = false;
	REP(i, N) REP(j, N) if (dat[i][j] != dp[i][j]) ng = true;
	
	if (ng) puts("-1");
	else {
		ll ans = 0;
		
		REP(i, N) FOR(j, i + 1, N) {
			bool f = true;
			REP(k, N) if (k != i && k != j && dp[i][j] == dp[i][k] + dp[k][j]) f = false;
			if (f) ans += dp[i][j];
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int count=0;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]!=t[i])
      count++;
    
  }
  cout<<count<<endl;
  
  
  
}

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

int main(){
  long long n, W;
  cin>>n>>W;
  vector<long long> dp(W+1, 0);
  while(n--){
    long long w, v;
    cin>>w>>v;
    for(long long i=W-w; i>=0; i--){
      dp[i+w] = max(dp[i+w], dp[i]+v);
    }
  }
  long long ans = 0;
  for(long long i=0; i<W+1; i++) ans = max(ans, dp[i]);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
list1=[]
listn=[]
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        list1.append(b)
    elif b==1:
        list1.append(a)
    elif a==n:
        listn.append(b)
    elif b==n:
        listn.append(a)
list1=set(list1)
listn=set(listn)
ans=0
if len(listn)!=0:
    for i in range(len(list1)):
        num=list1.pop()
        if num in listn:
            ans=1
            break
if ans==1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 26868
import sys
sys.setrecursionlimit(pow(10, 6))

n = int(input())
alist = list(sorted(map(int, input().split())))

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

l1 = [gcd(0, alist[0])]
l2 = [gcd(alist[-1], 0)]
if n == 2:
  print(max(alist))
else:
  for a in alist[1:]:
    l1.append(gcd(a, l1[-1]))
  for a in alist[::-1][1:]:
    if l2[-1] > a:
      l2.append(gcd(l2[-1], a))
    else:
      l2.append(gcd(a, l2[-1]))
  l2 = l2[::-1]
  maxl = l2[1]
  for i in range(n - 2):
    gcda = gcd(max(l1[i], l2[i+2]), min(l1[i], l2[i+2]))
    if gcda > maxl:
      maxl = gcda
  print(max(maxl, l1[-2]))


Measured memory_bytes: 14080
def resolve():
    N,M = map(int,input().split())
    import collections
    n_dict = collections.defaultdict(list)
    for _ in range(M):
        a,b = map(int,input().split())
        n_dict[a].append(b)
        n_dict[b].append(a)

    color = [-1 for _ in range(N)]
    flag = False
    d = collections.deque()
    d.append((1,0))
    while d:
        n,c = d.pop()
        color[n-1] = c^1
        for a in n_dict[n]:
            if color[a-1] == -1:
                d.append((a,c^1))
            elif color[a-1] == c^1:
                flag = True

    cumsum = [0,0]
    for i in range(N):
        cumsum[color[i]] += 1
    ans = 0
    if flag:
        ans = cumsum[0] + cumsum[1]
        print(ans * (ans-1)//2 - M)
    else:
        print(cumsum[0] * cumsum[1] - M)    
resolve()

Measured memory_bytes: 73816
#include<bits/stdc++.h>
using namespace std;
int n,ans;
struct lsg{int x,y;}a[1000000];
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')k=-1;else kk=c-'0';c=getchar();
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}
bool pd(lsg x,lsg y){return x.y<y.x||x.x==y.x&&x.y>y.y;}
int main(){
	n=read();for (int i=1;i<=n;i++)a[i].x=read(),a[i].y=read();
	sort(a+1,a+1+n,pd);ans=a[1].y-a[1].x+1;
	for (int i=2;i<=n;i++){
			if (a[i].y<a[i-1].y){a[i].y=a[i-1].y;continue;}
			a[i].x=max(a[i-1].y+1,a[i].x);ans+=a[i].y-a[i].x+1;
		}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// 6/13
// 3-2-3. 反転
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, pair<ll, ll>>;
const ll INF = 1e9;

struct Edge {
    ll to;
    ll fee;
    ll time;
    Edge(ll to, ll f, ll ti) : to(to), fee(f), time(ti) { }
};
using Graph = vector<vector<Edge>>;

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

    Graph G(N);
    rep(i, M) {
        ll u, v, fee, time;
        cin >> u >> v >> fee >> time;
        u--; v--;
        G[u].push_back(Edge(v, fee, time));
        G[v].push_back(Edge(u, fee, time));
    }

    vector<int> C(N), D(N);
    rep(i, N) cin >> C[i] >> D[i];

    ll MAX_MONEY = 50 * 49;
    if (S >= MAX_MONEY) S = MAX_MONEY;

    vector<vector<ll>> dist(MAX_MONEY + 1, vector<ll>(N, LLONG_MAX));
    dist[S][0] = 0;

    // 最短候補のqueue。
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, {S, 0}));
    // queueに入れるもの。
    // 最短距離0／{所持金、街}}。

    while (!que.empty()) {
        auto p = que.top();
        que.pop();

        ll s = p.second.first;  // 所持金
        ll v = p.second.second;  // フォーカスの当たっている点

        if (dist[s][v] < p.first) continue;

        // if (dist[])
        // printf("v, s = %d, %d\n", v, s);

        // 両替をする場合
        {
            ll ns = min(s + C[v], MAX_MONEY);
            if (dist[ns][v] > dist[s][v] + D[v]) {
                dist[ns][v] = dist[s][v] + D[v];
                que.push(P(dist[ns][v], {ns, v}));
            }
        }

        // 次のへんへ行く場合
        for (auto ne : G[v]) {
            ll ns = s - ne.fee;
            // ll at = 0;  // additional time
            // if (ns < 0) {
            //     ll num = ((-ns) + C[v] - 1) / C[v];
            //     ns += (C[v] * num);
            //     at += (D[v] * num);
            //     ns = min(ns, MAX_MONEY);
            // }
            // bool end = false;
            // while (true) {
            //     if (ns >= MAX_MONEY) {
            //         cout << "here?" << endl;
            //         ns = MAX_MONEY;
            //         end = true;
            //     }
            //     if (dist[ns][ne.to] > dist[s][v] + ne.time + at) {
            //         cout << "here?2" << endl;
            //         dist[ns][ne.to] = dist[s][v] + ne.time + at;
            //         que.push(P(dist[ns][ne.to], {ns, ne.to}));
            //     }
            //     ns += C[v];
            //     at += D[v];
            //     if (end) break;
            // }

            if (ns < 0) continue;

            if (dist[ns][ne.to] > dist[s][v] + ne.time) {
                // cout << "here?2" << endl;
                dist[ns][ne.to] = dist[s][v] + ne.time;
                que.push(P(dist[ns][ne.to], {ns, ne.to}));
            }
        }
    }

    rep(i, N) {
        if (i == 0) continue;

        ll res = LLONG_MAX;
        rep(j, MAX_MONEY) {
            res = min(res, dist[j][i]);
        }
        cout << res << endl;
    }

}

Measured memory_bytes: 7428
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 1111
int main()
{
	while(true){
		int N;
		int A[MAX_N];
		scanf("%d",&N);
		if(N==0){break;}
		for(int i=0;i<N;i++){scanf("%d",&A[i]);}
		sort(A,A+N);
		int ans=1000001;
		for(int i=0;i<N-1;i++){
			ans=min(ans,A[i+1]-A[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}



Measured memory_bytes: 3236
// Example program
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
const ll MAXN = 1e5 + 1;

ll a[MAXN];
int b[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] == i + 1)
            b[i] = 1;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (b[i] == 1)
        {
            cnt++;
            if (i + 1 < n)
            {
                if (b[i + 1] == 1)
                    i++;
            }
        }
    }
    cout << cnt;
}



Measured memory_bytes: 1408
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);
//    #endif
}
int main()
{
    vok();
    int a,b,c;
    IN a>>b>>c;
    set<int> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size()==2)
    {
        OUT "Yes"<<endl
    }
    else
    {
        OUT "No"<<endl
    }
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int num[100010] = {};
    rep(i, n) {
        int a;
        cin >> a;
        num[a]++, num[a + 1]++, num[a + 2]++;
    }
    int maxi = 0;
    rep(i, 100010) maxch(maxi, num[i]);
    cout << maxi << endl;
    return 0;
}

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

string s, t;
vvi dp;

string dfs(int i, int j) {
    if(!i) {
        return "";
    } else if(dp[i-1][j] == dp[i][j]) {
        return dfs(i-1, j);
    } else if(dp[i][j-1] == dp[i][j]) {
        return dfs(i, j-1);
    }
    return dfs(i-1, j-1) + s[i-1];
}


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


    dp.assign(s.size()+1, vi(t.size()+1));
    rep(i, s.size()) {
        rep(j, t.size()) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            dp[i][j+1] = max(dp[i][j+1], dp[i][j]);
            if(s[i] == t[j]) {
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
            }
        }
    }
    rep(i, s.size()) {
        dp[i+1][t.size()] = max(dp[i+1][t.size()], dp[i][t.size()]);
    }
    rep(i, t.size()) {
        dp[s.size()][i+1] = max(dp[s.size()][i+1], dp[s.size()][i]);
    }
    /*rep(i, s.size()) {
        rep(j, t.size()) {
            cout << dp[i+1][j+1];
        }
        cout << '\n';
    }*/

    cout << dfs(s.size(), t.size()) << endl;
}

Measured memory_bytes: 35968
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int a, b;
    cin >> a >> b;

    int x = a + b, y = a - b, z = a * b;
    
    print(max(x, max(y, z)));
    
}


Measured memory_bytes: 3636
#include<stdio.h>
#define INF (1<<30)
void Merge(int,int,int);
void MergeSort(int,int);
int n;
int S[500001];
int count=0;
int main(){
  int i;
  
  scanf("%d",&n);
 for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  
  MergeSort(0,n);
   
   
   for(i=0;i<n-1;i++){
   printf("%d ",S[i]);
}
 
   printf("%d\n%d\n",S[i],count);
 return 0;
}
int L[500001],R[500001];
void Merge(int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0;i<n1;i++){
    L[i] = S[left + i];
  }
  
  for(i=0;i<n2;i++){
    
    R[i] = S[mid+i];
    
  }

  L[n1]=INF;
  R[n2]=INF;
  i=0;
  j=0;
  
  for(k=left;k<right;k++){
    count++;  
    if (L[i] <= R[j]){
      S[k] = L[i];
      i = i+1;
    }
    else {
      S[k] = R[j];
      j = j+1;
    }
  }

}
 
 

void MergeSort(int left,int right){
 
  int mid;
  if (left+1 < right){
   
    mid = (left + right)/2;
    MergeSort(left, mid);
    MergeSort(mid, right);
    Merge(left, mid, right);



  }





}

Measured memory_bytes: 5484
import numpy as np

def main():
    N = int(input())
    As = list(map(int, input().split()))

    leap_seq = [0]
    for n in range(N):
        if leap_seq[-1]+1 == As[n]:
            leap_seq.append(As[n])

    del leap_seq[0]
    if len(leap_seq) == 0:
        print(-1)
    else:      
      print(int(N-len(leap_seq)))

if __name__ == "__main__":
    main()


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

int main(){
    vector<int> ps;
    int x, n, temp, absmin = INT_MAX, its;
    cin >> x >> n;
    for(int i=0;i<n;i++){
        cin >> temp;
        ps.push_back(temp);
    }
    for(int i=0;i<100;i++){
        bool checku = true;
        bool checka = true;
        for(int j=0;j<ps.size();j++){
            if(ps.at(j) == x-i)checku = false;
            if(ps.at(j) == x+i)checka = false;
        }
        if(checku){
            cout << x-i << endl;
            return 0;
        }
        if(checka){
            cout << x+i << endl;
            return 0;
        } 
        
    }


    
}

Measured memory_bytes: 3628
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

a,b = farr()
a,b = int(a),int(b*100+ .5)
ans = (a*b) //100
print(ans)


Measured memory_bytes: 37804
#include <bits/stdc++.h>
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;}
using Int = long long;
const char newl = '\n';


template<typename V>
V compress(V vs){
  sort(vs.begin(),vs.end());
  vs.erase(unique(vs.begin(),vs.end()),vs.end());
  return vs;
}
template<typename T>
map<T, int> dict(const vector<T> &vs){
  map<T, int> res;
  for(int i=0;i<(int)vs.size();i++)
    res[vs[i]]=i;
  return res;
}
map<char, int> dict(const string &s){
  return dict(vector<char>(s.begin(),s.end()));
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  vector<string> ss(n);
  for(int i=0;i<n;i++) cin>>ss[i];

  cout<<compress(ss).size()<<newl;
  return 0;
}


Measured memory_bytes: 15888
#include <stdio.h>

const int station[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int main(void)
{
    int n;

    scanf("%d", &n);
    while (n-- > 0){
        int begin, end;
        int i, j;
        int f = 0, b = 0;

        scanf("%d %d", &begin, &end);
        for (i = begin; station[i] != end; i = (i + 1) % 15, f++);
        for (j = begin + 1; station[j] != begin; j = (j + 1) % 15);
        for (; station[j] != end; j = (j + 1) % 15, b++);
        if (f < b){
            for (i = begin; station[i] != end; i = (i + 1) % 15){
                printf("%d ", station[i]);
            }
        }
        else {
            for (j = begin + 1; station[j] != begin; j = (j + 1) % 15);
            for (; station[j] != end; j = (j + 1) % 15){
                printf("%d ", station[j]);
            }
        }
        printf("%d\n", end);
    }

    return 0;
}

Measured memory_bytes: 600
def check(P):
	global k, T, n

	i = 0
	for j in range(k):
		s = 0
		while s + T[i] <= P:
			s += T[i]
			i += 1
			if (i == n):
				return n
	
	return i

def solve():
	left = 0
	right = 100000 * 10000

	while right - left > 1:
		mid = (left + right) // 2
		v = check(mid)
		if (v >= n):
			right = mid
		else:
			left = mid

	return right

if __name__ == '__main__':
	n, k = map(int, input().split())
	T = [int(input()) for i in range(n)]

	ans = solve()
	print(ans)


Measured memory_bytes: 9560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,sum=0;
  cin>>N;
  vi A(N);
  rep(i,0,N){
    cin>>A[i];
    sum+=A[i];
  }
  sort(ALL(A));
  string ans="No";
  if(A[N-1]<(sum-A[N-1]))
    ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int x, n, t = 0;
	int p[100];

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

	int x_1 = x;
	int x_2 = x;
	int y_1 = 0;
	int y_2 = 0;
	int b = 0;
	int count = 0;

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < n; i++) {
			b = x_1 - p[i];
			if (b == 0) {
				count = count + 1;
			}
		}
		if (count == 0) break;

		count = 0;
		x_1 = x_1 - 1;
	}

	for (int j = 0; j < n; j++) {
		for (int i = 0; i < n; i++) {
			b = x_2 - p[i];
			if (b == 0) {
				count = count + 1;
			}
		}
		if (count == 0) break;

		count = 0;
		x_2 = x_2 + 1;
	}

	int p_1 = 0, p_2 = 0;
	p_1 = x - x_1;
	p_2 = x_2 - x;

	if (p_1 <= p_2) {
		cout << x_1;
	}
	else {
		cout << x_2;
	}
}

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

typedef pair<int, int> P;

struct edge {
	int to, cap, cost, rev;
	edge(int to_, int cap_, int cost_, int rev_):to(to_), cap(cap_), cost(cost_), rev(rev_) {}
};

constexpr int INF = (1 << 29);

int V;
vector<vector<edge>> G;
vector<int> h;
vector<int> dist;
vector<int> prevv, preve;

void add_edge(int from, int to, int cap, int cost) {
	if(from == to) return;
	G[from].emplace_back(to, cap, cost, G[to].size());
	G[to].emplace_back(from, 0, -cost, G[from].size() - 1);
}

int solve(int s, int t, int k) {
	fill(begin(h), end(h), 0);

	int cost = 0;
	int ans = 0;
	while(true) {
		priority_queue<P, vector<P>, greater<P>> que;
		fill(begin(dist), end(dist), INF);
		dist[s] = 0;
		que.emplace(0, s);

		while(!que.empty()) {
			const P p = que.top();
			que.pop();

			const int v = p.second;
			if(dist[v] < p.first) continue;

			for(int i = 0; i < G[v].size(); ++i) {
				edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.emplace(dist[e.to], e.to);
				}
			}
		}

		if(dist[t] == INF) break;

		for(int v = 0; v < V; ++v) {
			h[v] += dist[v];
		}

		const int d = 1;
		cost += d * h[t];
		if(cost > k) break;

		for(int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
		++ans;
	}
	return ans;
}

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

	vector<vector<int>> mat(a, vector<int>(b, 0));

	for(int i = 0; i < a; ++i) {
		string s;
		cin >> s;
		for(int j = 0; j < b; ++j) {
			if(s[j] == '1') {
				++mat[i][j];
			}
		}
	}

	for(int j = 0; j < b; ++j) {
		string s;
		cin >> s;
		for(int i = 0; i < a; ++i) {
			if(s[i] == '1') {
				++mat[i][j];
			}
		}
	}

	const int S = a + b;
	const int T = S + 1;
	V = a + b + 2;
	G.resize(V);
	h.resize(V);
	dist.resize(V);
	prevv.resize(V);
	preve.resize(V);

	for(int i = 0; i < a; ++i) {
		const int v = i;
		add_edge(S, v, 1, 0);

		for(int j = 0; j < b; ++j) {
			const int u = j + a;
			add_edge(v, u, 1, mat[i][j]);
		}
	}

	for(int j = 0; j < b; ++j) {
		const int v = j + a;
		add_edge(v, T, 1, 0);
	}

	cout << solve(S, T, k) << endl;

	return 0;
}

Measured memory_bytes: 4864
import heapq 

N,M=map(int,input().split())
A=[-a for a in list(map(int,input().split()))]
heapq.heapify(A)
for _ in [0]*M:
    a=heapq.heappop(A)
    heapq.heappush(A,-((-a)//2))
    
res=0
for i in range(N):
    a=heapq.heappop(A)
    res+=-a
print(res)

Measured memory_bytes: 91584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  for(int i=1; i<10000000;i++){
    if((A*i)%B==C){cout << "YES" << endl; return 0;}
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
//#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};


template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

int main(){
    int arr[12] = {1,6,36,216,1296,7776,46656,9,81,729,6561,59049};
    int n; cin >> n;
    int cnt[n+10];
    fill(cnt,cnt+n+5,MM);
    cnt[0] = 0;
    cnt[1] = 1;
    for(int i = 0; i < 12; i++){
        for(int num = 0; num <= n+1; num++){
            if (cnt[num-arr[i]] != MM && num >= arr[i]){
                cnt[num] = min(cnt[num],cnt[num-arr[i]]+1);
            }
        }
    }
    cout << cnt[n] << endl;
}

Measured memory_bytes: 1016
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
	int a, b;
	double da, db;
	cin >> a >> b;
	int d = a / b;
	int r = a % b;
	da = (double)a;
	db = (double)b;
	double f = da / db;
	printf("%d %d %.8lf\n", d, r, f);
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          998244353
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}

vector<vector<char> >vmt;
vector<vii> dp;
void solve()
{
  
  int h,w;
  cin >> h >> w;
  
  vmt.assign(h,vector<char>(w,'a'));
  dp.assign(h,vii(w,0));

  forf(i,0,h)
  {
    forf(j,0,w) cin >> vmt[i][j];
  }
  
  if(vmt[h-1][w-1]=='.') dp[h-1][w-1]=0;
  else dp[h-1][w-1]=1;

  for(int i=1;i < h+w ;i++)
  {
    for(int j=0;j<h;j++)
    {
      for(int k=0;k<w;k++)
      {
         if(abs(h-1-j)+abs(w-1-k) == i)
         {
          int vl = big;
           if(k+1<w)
           {
            if(vmt[j][k]=='.' || vmt[j][k+1]=='#') vl = min(vl,dp[j][k+1]);
            else vl = min(vl,dp[j][k+1]+1);
           }
           if(j+1<h)
           {
            if(vmt[j][k]=='.' || vmt[j+1][k]=='#') vl = min(vl,dp[j+1][k]);
            else vl = min(vl,dp[j+1][k]+1);
           }
           dp[j][k] = vl;
         }
      }
    }
  }



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

}

int32_t main()
{
  //pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

void selectSort(int A[], int N){
    int sw = 0;
    for(int i=0; i<N; i++){
        int minj = i;
        for(int j=i+1; j<N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if(i != minj) sw++;
    }
    rep(i,N){
        cout << A[i];
        if(i != N-1) cout << " ";
    }cout << endl;
    cout << sw << endl;
}

int main()
{
    int N; cin >> N;
    int A[N];
    rep(i,N){
        int Ai; cin >> Ai;
        A[i] = Ai;
    }
    selectSort(A, N);
}


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

ll N, K;
string S;

void solve() {
  if (S[K - 1] == 'A') {
    S[K - 1] = 'a';
  }
  if (S[K - 1] == 'B') {
    S[K - 1] = 'b';
  }
  if (S[K - 1] == 'C') {
    S[K - 1] = 'c';
  }
  cout << S << '\n';
}

int main() {
  cin >> N >> K >> S;

  solve();
  return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;


class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        int head = 0;
        int tail = s.Length - 1;
        int res = 0;
        while (true)
        {
            if (head >= tail) break;
            if (s[head] == s[tail])
            {
                head++;
                tail--;
                continue;
            }
            if (s[head] == 'x')
            {
                head++;
                res++;
                continue;
            }
            if(s[tail] == 'x')
            {
                tail--;
                res++;
                continue;
            }
            Console.WriteLine(-1);
            return;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13280
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
/*
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  int n,ans=0;
  cin>>n;
  vi B(n-1);
  rep(i,n-1) cin>>B[i];
  rep(i,n){
    if(i==0) ans+=B[0];
    else if(i==n-1) ans+=B[i-1];
    else ans+=min(B[i-1],B[i]);
  }
  out(ans);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


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

int main(){
	long long n,a[100005];
	cin>>n;
	for(long long i=0;i<n;i++){
		cin>>a[i];
	}
	long long sum=0,m=0;
	for(long long i=0;i<n-1;i++){
		if(a[i]<a[i+1] || i==n-2){
			if(a[i]>=a[i+1])
			    sum++;
			if(m<sum){
				m=sum;
			}
			sum=0;
		}
		else{
			sum++;
		}
	}
	cout<<m<<endl;
}


Measured memory_bytes: 1024
// Aizu Vol-5 0555: Ring
// 2017.8.31 bal4u@uu

#include <stdio.h>
#include <string.h>

char p[30], s[30];

int match(char *s, char *p)
{
	char *tp, *pp;
	char c = *p++;

    while (*s) {
        if (*s++ == c) {
            tp = s, pp = p;
            do if (!*pp) return 1;
            while (*tp++ == *pp++);
        }
    }
	return 0;
}

int main()
{
	int n, k, ans;

	scanf("%s%d", p, &n);
	ans = 0;
	while (n--) {
		scanf("%s", s);
		k = strlen(s);
		memcpy(s+k, s, k), s[k+k] = 0;
		if (match(s, p)) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int m,f,r,ans1;
	for(;;){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1)
			break;
		ans1=m+f;
		if(m==-1||f==-1){
			cout<<"F"<<endl;
		}else if(ans1>=80){
			cout<<"A"<<endl;
		}else if(ans1>=65){
			cout<<"B"<<endl;
		}else if(ans1>=50||r>=50){
			cout<<"C"<<endl;
		}else if(ans1>=30){
			cout<<"D"<<endl;
		}else if(ans1<30){
			cout<<"F"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;

int main() {
  int n, Q;
  scanf("%d%d", &n, &Q);
  vl q(1, n);
  for (int i = 0; i < Q; ++i) {
    ll x;
    scanf("%lld", &x);
    while (!q.empty() && q.back() >= x) q.pop_back();
    q.push_back(x);
  }
//  vii v(q.back(), 1);
  map<ll, ll> v; v[q.back()] = 1;
  vii add;
  for (int i = q.size() - 2; i >= 0; --i) {
//    for (const auto & p : v) cerr << p.first << ' ' << p.second << endl;
    add.clear();
    ll m = q[i];
//    int it = lower_bound(v.begin(), v.end(), pii(m + 1, 0)) - v.begin();
    ll sm = 0;
    auto it = v.end(); --it;
    while (true) {
      if (it->first <= m) {
        ++it;
        v.erase(it, v.end());
        break;
      }
      sm += it->first / m * it->second;
      ll r = it->first % m;
      if (r) add.emplace_back(r, it->second);
      if (it == v.begin()) {
        v.clear(); break;
      }
      --it;
    }
    v[m] += sm;
    if (add.empty()) continue;
    sort(add.begin(), add.end());
    pii td(0, 0);
    for (const auto& p : add) {
      if (p.first == td.first) td.second += p.second;
      else {
        if (td.second) v[td.first] += td.second;
        td = p;
      }
    }
    v[td.first] += td.second;
  }
  vl d(n);
//  for (const auto & p : v) cerr << p.first << ' ' << p.second << endl;
  for (const auto & p : v) {
    d[p.first - 1] += p.second;
  }
  vl res(n);
  ll s = 0;
  for (int i = n-1; i >= 0; --i) {
    s += d[i];
    res[i] = s;
  }
  for (int i = 0; i < n; ++i) {
    printf("%lld\n", res[i]);
  }
  return 0;
}

Measured memory_bytes: 11376
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end());
    cout<<abs(deq[n-1]-deq[0])<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

//線形捜索
int search(int *A, int n , int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key ) i++;
  return i != n;
}

int main(){
  int i, n, A[10000+1], q, key, sum= 0;

  scanf("%d", &n);//要素数を入力
  for (i = 0; i<n; i ++){
    scanf("%d", &A[i]);
    }
  scanf("%d", &q);// 比較する要素数を入力
  for (i=0;i<q; i++){
    scanf("%d", &key);
    if(search(A,n,key) ) sum++;
  }
printf("%d\n", sum);

return 0;
}


Measured memory_bytes: 2100
//	-*- mode: C++ -*-
//	Finding a Word
//
//		Write a program which reads a word W and a text T, and prints the number of word W which appears in text T
//
//		T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensitive.
//
//	Constraints
//		The length of W ≤ 10
//		W consists of lower case letters
//		The length of T in a line ≤ 1000
//	Input
//		In the first line, the word W is given. In the following lines, the text T is given separated by space characters and newlines.
//
//		"END_OF_TEXT" indicates the end of the text.
//
//	Output
//		Print the number of W in the text.
//
//	Sample Input
//		computer
//		Nurtures computer scientists and highly-skilled computer engineers
//		who will create and exploit "knowledge" for the new era.
//		Provides an outstanding computer environment.
//		END_OF_TEXT
//	Sample Output
//		3

#include <iostream>
#include <string>
#include <cctype>

int	main(int	argc,
		 char*	argv[])
{
	const std::string	end	= "END_OF_TEXT";

	std::string	W	{};
	std::string T	{};

	std::cin >> W;
	for(unsigned int i = 0; i < W.length(); i++){
		if(isupper(W[i])){
			W[i] = tolower(W[i]);
		}
	}

	unsigned int	count	{0};

	while(1){
		std::cin >> T;
		if(T == end){
			break;
		}

		for(unsigned int i = 0; i < T.length(); i++){
			if(isupper(T[i])){
				T[i] = tolower(T[i]);
			}
		}

		if(T == W){
			++count;
		}
	}

	std::cout << count << '\n';

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
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; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	ll n,a,b;
	cin >> n >> a >> b;
	ll x = n/(a+b)*a;
	ll y = n%(a+b);
	if(y<=a) x+=y;
	else x+=a;
	cout << x << endl;

  return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
int M = 998244353;
// enum : int { M = (int)1e9 + 7 };
// enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

ll modPow(ll base, ll ex, ll m) {
	ll ret = 1;
	while(ex){
		if(ex & 1){
			ret = ret * base % m;
		}
		ex >>= 1;
		base = base * base % m;
	}
	return ret;
}
vector<ll> mFacts, mInvFacts;
ll modFact(int n){ return mFacts[n]; }
ll modInvFact(int n){ return mInvFacts[n]; }
ll modInv(int n, ll m){ return modPow(n, m - 2, m); }
ll modC(int n, int k, ll m){ return modFact(n) * modInvFact(k) % m * modInvFact(n - k) % m; }
void init(int n, ll m){
    mFacts.resize(n + 1);
    mInvFacts.resize(n + 1);
    mFacts[0] = 1;
    for(int i = 1; i <= n; i++){
        mFacts[i] = mFacts[i - 1] * i % m;
    }
    mInvFacts[n] = modInv(mFacts[n], m);
    for(int i = n - 1; i >= 0; i--){
        mInvFacts[i] = mInvFacts[i + 1] * (i + 1) % m;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    init(1e6, M);
    string s; cin >> s;
    int n = s.size();
    // blue
    vector<vector<ll>> dp(n + 1, vector<ll>(2 * n + 10));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        char c = s[i - 1];
        auto blue = [&](int i, int j){ return j; };
        auto red =  [&](int i, int j){ return j != i * 2; };
        for(int j = 0; j < i; j++){
            printde(i, j, c, (blue(i - 1, j) && c == '0'), (red(i - 1, j) && c == '2'));
            if(c == '1' || (blue(i - 1, j) && c == '0') || (red(i - 1, j) && c == '2')){
                dp[i][j - 1 + (c - '0')] += dp[i - 1][j];
                dp[i][j - 1 + (c - '0')] %= M;
                dp[i][j + (c - '0')] += dp[i - 1][j];
                dp[i][j + (c - '0')] %= M;
            }else if(c == '0'){
                dp[i][j + (c - '0')] += dp[i - 1][j];
                dp[i][j + (c - '0')] %= M;
            }else{
                dp[i][j - 1 + (c - '0')] += dp[i - 1][j];
                dp[i][j - 1 + (c - '0')] %= M;
            }
        }
    }
    printde(dp);
    ll ans = 0;
    for(int i = 0; i <= n; i++){
        ans += dp[n][i] * modC(n, i, M);
        ans %= M;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 78720
#include <cstdio>

using namespace std;

const int mod = 1000000007;
int c[200000];
int right[200000];
int dp[200001];

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        
        c[i]--;
    }
    
    for (i = 0; i < 200000; i++) right[i] = -1;
    
    dp[n] = 1;
    for (i = n - 1; i >= 0; i--) {
        dp[i] = dp[i + 1];
        if (right[c[i]] != -1 && right[c[i]] != i + 1) {
            dp[i] += dp[right[c[i]]];
            if (dp[i] >= mod) dp[i] -= mod;
        }
        
        right[c[i]] = i;
    }
    
    printf("%d\n", dp[0]);
    
    return 0;
}


Measured memory_bytes: 2560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = Integer.parseInt(in.next());
            Map<Integer, Integer> a = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int tmp = Integer.parseInt(in.next());
                if (a.containsKey(tmp) == false) a.put(tmp, 1);
                else a.remove(tmp);
            }
            int ans = 0;

            for (Map.Entry<Integer, Integer> entry : a.entrySet()) {
                if (entry.getValue() == 1) ans++;
            }
            out.println(ans);

        }

    }
}



Measured memory_bytes: 46040
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////


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

	vll a(N), b(M);
	rep(i, N)cin >> a[i];
	rep(i, M)cin >> b[i];

	vll c = convolution(a, b);

	rep(i, N + M - 1)cout << c[i] << " ";
	cout << endl;
}


Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int bj = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == '7')
        {
            bj = 1;
        }
    }
    if(bj == 1)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int max(int a, int b){
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int min(int a, int b ){
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main(void){
  int d,w;
  int stage[10][10];
  int counter;
  int frmin;
  int depsum,depmax;
  int depsummax;
  //int allsum[10][10];
  scanf("%d%d",&d,&w );
  while (d != 0) {
    for (int i = 0; i < d; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d",&stage[i][j]);
        //allsum[i][j] = 0
      }
    }

    depsummax = 0;
    /*
    for (int i = 1; i < d+1; i++) {
      for (int j = 1; j < w+1; j++) {
        allsum[i][j] = allsum[i][j-1] + stage[i-1][j-1];
      }
    }
    for (int i = 1; i < w+1; i++) {
      for (int j = 1; j < d+1; j++) {
        allsum[j][i] = allsum[j-1][i] + stage[j-1][i-1];
      }
    }
    */
    for (int i = 0; i < d-2; i++) {
      for (int j = 0; j < w-2; j++) { //始点
        for (int k = i+2; k < d; k++) {
          for (int l = j+2; l < w; l++) { // 終点
            depmax = 0;
            depsum = 0;
            frmin = 1000;
            counter = 0; //initialize
            for (int m = i; m <= k; m++) {
              for (int n = j; n <= l; n++) {
                if (i<m&&m<k && j<n&&n<l) {
                  depsum += stage[m][n];
                  counter++;
                  depmax = max(depmax,stage[m][n]);
                } else {
                  frmin = min(frmin,stage[m][n]);
                }
              }
            }
            if (depmax < frmin) {
              depsum = frmin * counter - depsum;
              depsummax = max(depsummax,depsum);
            }
          }
        }
      }
    }
    
    printf("%d\n",depsummax );
    scanf("%d%d", &d,&w);
  }
  return 0;
}



Measured memory_bytes: 2680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		if (k % 2 == 0) {
			long k2 = k / 2;
			long v1 = n / k;
			long v2 = n / k2 - v1;
			System.out.println(v1 * v1 * v1 + v2 * v2 * v2);
		} else {
			long v1 = n / k;
			System.out.println(v1 * v1 * v1);
		}
	}
}


Measured memory_bytes: 23380