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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N,M;
vpint G[111111];

const int INF=1001001001001001001;
int dist[111111];
signed main(){
	cin>>N>>M;
	rep(i,N-1)G[i+1].eb(i,0);
	rep(i,M){
		int l,r,c;
		cin>>l>>r>>c;
		l--;r--;
		G[l].eb(r,c);
	}

	fill_n(dist,N,INF);
	priority_queue<pint,vector<pint>,greater<pint>>que;
	que.emplace(0,0);
	dist[0]=0;
	while(que.size()){
		int d,v;
		tie(d,v)=que.top();
		que.pop();
		for(auto &e:G[v]){
			if(dist[e.fi]<=d+e.se)continue;
			dist[e.fi]=d+e.se;
			que.emplace(dist[e.fi],e.fi);
		}
	}
	if(dist[N-1]==INF)cout<<-1<<endl;
	else cout<<dist[N-1]<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N,ans=0;
    cin>>N;
    if(N%1000==0){
        cout<<0<<endl;
    }else{
        cout<<(N/1000)*1000+1000-N<<endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int c[10][10];
int mins[10];
bool used[10] = {};

int rec(int x) {
  if (x == 1) return 0;

  int ret = INF;
  rep(nx, 10) if (nx != x and used[nx] == false) {
    used[nx] = true;
    ret = min(ret, c[x][nx] + rec(nx));
    used[nx] = false;
  }
  return ret;
}

int main() {
  int h, w; cin>>h>>w;
  rep(i, 10) rep(j, 10) cin>>c[i][j];
  rep(i, 10) {
    used[i] = true;
    mins[i] = rec(i);
    used[i] = false;
  }
  int ans = 0;
  rep(i, h) rep(j, w) {
    int t; cin>>t;
    if (t != -1) ans += mins[t];
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int main(){
    int n, m, t;
    while(cin >> n >> m >> t && n){
        int a[110];
        a[0] = 0;
        rep(i, n) cin >> a[i+1];
        a[n+1] = t;
        int ans = 0;
        rep(i, n+1) ans += max(0, a[i+1] - a[i] - ((i==0 || i==n) ? m : 2*m));
        cout << ans << endl;
    }
}

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

typedef int64_t i64;
typedef uint64_t ui64;
#include <bits/stdc++.h>

class graph{
private:
    struct vrtx{
        int to;
        int64_t cost;
    };
    struct adj{
        int start;
        int to;
        int64_t cost;
    };
    int nd;
    int edg;
public:
    std::vector<vrtx> *node;
    std::vector<adj> edge;
    graph(int n,int m){
        nd=n;
        edg=m;
        node=new std::vector<vrtx>[nd];
    }
    void add_dir(int s,int t,int64_t c){
        node[s].push_back({t,c});
        edge.push_back({s,t,c});
    }
    void add_undir(int s,int t,int64_t c){
        node[s].push_back({t,c});
        node[t].push_back({s,c});
        edge.push_back({s,t,c});
    }
    void dlt_dir(int s,int t){
        for(int i=0;i<node[s].size();i++){
            if(node[s][i].to==t){
                node[s].erase(node[s].begin()+i);
                break;
            }
        }
    }
    void dlt_undir(int s,int t){
        for(int i=0;i<node[s].size();i++){
            if(node[s][i].to==t){
                node[s].erase(node[s].begin()+i);
                break;
            }
        }
        for(int i=0;i<node[t].size();i++){
            if(node[t][i].to==s){
                node[t].erase(node[t].begin()+i);
                break;
            }
        }
    }
    void refr(void){
        for(int i=0;i<nd;i++) std::vector<vrtx>().swap(node[i]);
        delete[] node;
        std::vector<adj>().swap(edge);
    }
    void dfs(int r,bool **vst);
    void bellford(int s,int64_t **d);
    void dijkstra(int s,int64_t **d);  // 負の閉路なし
    void bfs(int s,int64_t **d);  // 辺に重み無し or 木
    void cumulsum(int s,int64_t **d);  // 木
    void cumulprd(int s,int64_t **d);  // 木
};

void graph::dijkstra(int s,int64_t **d){
    for(int i=0;i<nd;i++) (*d)[i]=INT64_MAX/2;
    std::priority_queue<std::pair<int64_t,int>,std::vector<std::pair<int64_t,int>>,std::greater<std::pair<int64_t,int>>> que;
    (*d)[s]=0;
    que.push({0,s});
    while(!que.empty()){
        std::pair<int64_t,int> p=que.top();
        que.pop();
        if((*d)[p.second]<p.first) continue;
        for(vrtx i:node[p.second]){
            if((*d)[i.to]>(*d)[p.second]+i.cost){
                (*d)[i.to]=(*d)[p.second]+i.cost;
                que.push({(*d)[i.to],i.to});
            }
        }
    }
}

int main(void){
    int v,e;
    scanf("%i%i",&v,&e);
    graph g(v,e);
    int r;
    scanf("%i",&r);
    int s,t;
    i64 d;
    for(int i=0;i<e;i++){
        scanf("%i%i%lli",&s,&t,&d);
        g.add_dir(s,t,d);
    }
    i64 *dist=new i64[v];
    g.dijkstra(r,&dist);
    for(int i=0;i<v;i++){
        if(dist[i]==INT64_MAX/2) printf("INF\n");
        else printf("%lli\n",dist[i]);
    }
    return 0;
}



Measured memory_bytes: 28088
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

int n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[1002],y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[1002];
int dp[1002];
int mem[1002];
bool vi[1002];
int judge=1;

//-------------------------↓↓↓↓↓↓------------------------

void dfs(ll now){
    if(mem[now]==0||vi[now]||judge==0)return;
    vi[now]=true;
    rep(i,Size(g[now])){
        dfs(g[now][i]);
    }
    int tem_dp[1002][x[now]+5];
    rep(i,1002){
        rep(j,x[now]+5){
            tem_dp[i][j]=INF;
        }
    }
    rep(j,x[now]+5)tem_dp[0][j]=0;
    rrep(i,1,Size(g[now])+1){
        ll chi=g[now][i-1];
        rrrep(j,x[now],0){
            if(j>=x[chi])tem_dp[i][j]=min({tem_dp[i-1][j-x[chi]]+dp[chi],tem_dp[i][j]});
            if(j>=dp[chi])tem_dp[i][j]=min({tem_dp[i-1][j-dp[chi]]+x[chi],tem_dp[i][j]});
        }
    }
    int ret=INF;
    rep(i,x[now]+1){
        ret=min(ret,tem_dp[Size(g[now])][i]);
    }
    if(ret==INF)judge=0;
    dp[now]=ret;
    return;
}

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

    cin>>n;
    rep(i,n-1){
        cin>>a;
        mem[a-1]=1;
        //g[i+1].push_back(a-1);
        g[a-1].push_back(i+1);
    }
    rep(i,n)cin>>x[i];
    dfs(0);
    if(judge==1)Cout("POSSIBLE");
    else Cout("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 19968
using System;
//using System.Text;
using System.Linq;
class Program
{
    static void Main()
    {
        int n;
        n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            var a = Console.ReadLine().Split().Select(int.Parse).ToList();
            a.Sort();
            Console.WriteLine(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]? "YES":"NO");
        }
    }
}

Measured memory_bytes: 9512
a,b=map(int,input().split())
import math
c= math.gcd(a,b)
c2=c
l=[]
i=2
while i<=c:
  if c % i==0:
    c=c//i
   
    l.append(i)
  else:
    i+=1
  if i*i-1>c:
    l.append(c)
    break
  
print(len(set(l))+1)


Measured memory_bytes: 9160
package main

import (
  "fmt"
)

func main() {
  var n int
  fmt.Scan(&n)
  a := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a[i])
  }
  if len(a)!=len(removeDuplicate1(a)) {
    fmt.Println("NO")
  } else {
    fmt.Println("YES")
  }
}

func removeDuplicate1(args []int) []int {
    results := make([]int, 0, len(args))
    encountered := map[int]bool{}
    for i := 0; i < len(args); i++ {
        if !encountered[args[i]] {
            encountered[args[i]] = true
            results = append(results, args[i])
        }
    }
    return results
}


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

int n, q;

struct segtree {
  int l, r, x;
  segtree *sl, *sr;

  segtree(int l, int r) : l(l), r(r), x(2147483647) {
    if (l != r) {
      int m = l + r >> 1;
      sl = new segtree(l, m);
      sr = new segtree(m + 1, r);
    }
  }

  void update(int k, int v) {
    if (l == k && r == k) {
      x = v;
      return;
    }

    int m = l + r >> 1;
    if (k <= m)
      sl->update(k, v);
    else
      sr->update(k, v);
    x = min(sl->x, sr->x);
  }

  int query(int ql, int qr) {
    if (ql == l && qr == r) return x;
    int m = l + r >> 1;
    if (qr <= m)
      return sl->query(ql, qr);
    else if (ql > m)
      return sr->query(ql, qr);
    else
      return min(sl->query(ql, m), sr->query(m + 1, qr));
  }
};

segtree *s;

int main() {
  cin >> n >> q;
  s = new segtree(0, n - 1);
  for (int i = 0; i < q; i++) {
    int c, x, y; cin >> c >> x >> y;
    if (c == 0) {
      s->update(x, y);
    } else {
      cout << s->query(x, y) << endl;
    }
  }
}



Measured memory_bytes: 12496
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    vector<int> dp(1e4+1);

    for (int i=1; i<101; i++) {
        for (int j=1; j<101; j++) {
            for (int k=1; k<101; k++) {
                int duh = i*i + j*j + k*k + i*j + j*k + k*i;
                if (duh < 1e4+1) {
                    dp[duh]++;
                }
            }
        }
    }
    int n;
    cin >> n;
    for (int i=1; i<n+1; i++) cout << dp[i] << " ";
    cout << "\n";
}


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

int main () {
    int N,M,X;
    cin >> N >> M >> X;
    vector<vector<int >> c(N,vector<int>(M + 1));
    for(int i = 0; i<N; i++) {
        for(int j = 0; j<M + 1; j++) {
            cin >> c[i][j];
        }
    }

    int chk = 0;
    int res = INT_MAX;
    for(int i = 0; i<(1<<N); i++) {
        int cnt = 0;
        vector<int> sum(M + 1);
        for(int j = 0; j<N; j++) {
            if(i & (1<<j)) {
                cnt += c[j][0];
                for(int h = 1; h<=M; h++) {
                    sum[h] += c[j][h];                
                }
            }
        }
        chk = 0;
        for(int j = 1; j<=M; j++) {
            if(X > sum[j]) {
                chk = 1;
            }
        }
        if(chk == 0) { 
            res = min(res, cnt);
        }
    }
    if(res < INT_MAX) cout << res << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3620
def main():
    a = input()
    b = int(input())
    n = len(a)

    dp = [[[0 for _ in range(2)] for _ in range(b+1)] for _ in range(n+1)]
    dp[0][0][0] = 1

    for i in range(n):
        nd = int(a[i])
        for j in range(b+1):
            for k in range(2):
                for d in range(10):
                    ni = i+1
                    nj = j
                    nk = k
                    if d != 0:
                        nj += 1
                    if nj > b:
                        continue
                    if k == 0:
                        if d > nd:
                            continue
                        if d < nd:
                            nk = 1
                    dp[ni][nj][nk] += dp[i][j][k]

    ans = dp[n][b][0] + dp[n][b][1]
    print(ans)


main()


Measured memory_bytes: 40304
#include<cstdio>

int main() {
    int x,y;
    for(int i = 1; i <= 3000; i++){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0){
            break;
        }
        if(x >= y){
            printf("%d %d\n",y,x);
        }
        else{
            printf("%d %d\n",x,y);
        }
    }
return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a;
  cin>>a;
  if(a>=30){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;

  int num = 0;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    if(tmp %2 == 1) num++;
  }

  cout << (num % 2 == 0 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#define Max 107000
typedef struct {
  char name[10];
  int time;
} process;

int main(){
  process dat1[Max];
  int i,j,tmp,a,b,head=0,tail,tim=0;

  scanf("%d%d",&a,&b);
  tail = a-1;
  for (i = 0;i < a;i++){
    scanf("%s%d",dat1[i].name,&dat1[i].time);
  }

  for (i = 0;;i++){
    if(i ==Max)
      i =head;
    dat1[i].time -= b;
    if(dat1[i].time > 0){
      tail++; 
if(tail==Max)
  tail =0;
      dat1[tail] = dat1[head]; 
      tim += b;
    
    }
    else if(dat1[i].time <= 0){
      tim += b + dat1[i].time;
  printf("%s %d\n",dat1[i].name,tim);
    if(head == tail)break;
    }

  

 head++; 
if(head==Max)
  head =0;
  }


return 0;
}


	 
	 
    

    
  

Measured memory_bytes: 2268
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin>>s;
	s.replace(3,1,"8");
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll a, b;
  	cin >> a >> b;
  	ll cal = 0;
  	if(a <= 0 && b >= 0 || a >= 0 && b <= 0){
      cout << "Zero" << endl;
      return 0;
    }
  	else if(a > 0 && b > 0){
      cout << "Positive" << endl;
      return 0;
    }
  	else{
      if(-1 * a > -1 * b) cal = -1 * a - (-1 * b) + 1;
      else cal = -1 * b - (-1 * a) + 1;
      if(cal % 2 == 0) cout << "Positive" << endl;
      else cout << "Negative" << endl;
    }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    int n, a, b, q = 0;
    cin >> n;
    bool ans = false;
    rep(i, n) {
        cin >> a >> b;
        if (a == b) {
            ++q;
            if (q >= 3) {
                ans = true;
            }
        }
        else {
            q = 0;
        }
    }
    if (ans) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}



Measured memory_bytes: 3616
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int main() {
    int a;
    cin >> a;

    cout << a+a*a+a*a*a << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	int ret = 0;
	for (int i=0; i<n; i++) {
		int a; cin >> a;
		if (i%2==0 && a%2==1) ret++;
	}
	cout << ret << endl;
	return 0;
}

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

ll dp[3003][3003][4];

void solve(){
    long int r,c;
    cin>>r>>c;
    ll k;
    cin>>k;
    ll a[r+1][c+1];
    memset(a,0,sizeof(a));
    while(k--){
    	ll x,y;
    	cin>>x>>y;
    	cin>>a[x][y];
    }

    // for(long int i=1;i<=r;i++){
    // 	for(long int j=1;j<=c;j++)
    // 		cout<<a[i][j]<<" ";
    // 	cout<<endl;
    // }
    for(long int i=1;i<=r;i++){
    	for(long int j=1;j<=c;j++){

    		dp[i][j][1]=max(dp[i][j-1][1],a[i][j]+max({dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]}));
    		dp[i][j][2]=max(dp[i][j-1][2],a[i][j]+dp[i][j-1][1]);
    		dp[i][j][3]=max(dp[i][j-1][3],a[i][j]+dp[i][j-1][2]);

    		// debug(dp[i][j][1]); debug(dp[i][j][2]); debug(dp[i][j][3]); cout<<endl;


    	}
    }

    cout<<max({dp[r][c][1],dp[r][c][2],dp[r][c][3]})<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
  
using namespace std;                           

string s;
int n;

int main(){
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s == "SUN"){
			cout << 7;
			return 0;
		}
		if(s == "MON"){
			cout << 6;
			return 0;
		}
		if(s == "TUE"){
			cout << 5;
			return 0;
		}
		if(s == "WED"){
			cout << 4;
			return 0;
		}
		if(s == "THU"){
			cout << 3;
			return 0;
		}
		if(s == "FRI"){
			cout << 2;
			return 0;
		}
		if(s == "SAT"){
			cout << 1;
			return 0;
		}
	}
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,a,b;
  
  if(scanf("%d",&n)==1 && scanf("%d",&a)==1 && scanf("%d",&b)==1){}
  
  if(n*a > b){
    printf("%d",b);
  }else{
    printf("%d",n*a);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
using namespace std;
const int N=2005;
int n,x,y,ans;
int f[N],g[N],mx[N];
vector<int>e[N];
char s[N];
void dfs(int x,int no){
	g[x]=s[x]=='1';
	f[x]=0;
	for(int i:e[x])if(i!=no){
		dfs(i,x);
		g[x]+=g[i];
		f[i]+=g[i];
		f[x]+=f[i];
	}
	int ma=0,sum=0;
	for(int i:e[x])if(i!=no)
		ma=max(ma,f[i]),sum+=f[i];
	if(ma*2>sum){
		int d=0;
		for(int i:e[x])if(i!=no&&ma==f[i])
			d=mx[i];
		if(ma-d<=sum-ma)mx[x]=sum-(sum&1);else{
			mx[x]=(sum-ma)*2+d;
		}
	}else mx[x]=sum-(sum&1);
}
int main(){
	scanf("%d\n%s",&n,s+1);
	fo(i,2,n)cin>>x>>y,e[x].push_back(y),e[y].push_back(x);
	ans=2e9;
	fo(i,1,n){
		dfs(i,0);
		if(f[i]%2==0&&mx[i]==f[i])ans=min(ans,f[i]/2);
	}
	printf("%d",ans==2e9?-1:ans);
}

Measured memory_bytes: 512
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [a,b,k] = nextIntArray()
    if( k >= a + b){
        console.log(0, 0)
        return
    } else if (k <= a){
        console.log(a-k, b)
        return
    } else {
        console.log(0, b - (k-a))
    }

}
Main()


Measured memory_bytes: 29592
s=input()

ans=[]

count=0
max=0

for i in range(len(s)):
  if s[i]=='A' or s[i]=='G' or s[i]=='C' or s[i]=='T':
    ans.append(s[i])
    count=count+1
    #print(ans,count)
    if count>=max:
      max=count
  else:
    count=0
#print(ans)
print(max)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int a, b;
int main(void) {
    cin >> a >> b;
    cout << 6-(a+b) << endl;
    return 0;
}



Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,k;
	cin >> n >> k;
	cout << (n-k)*(k>1) << endl;
	return 0;
}


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



int main() {
  int N;
  cin>>N;
  vector<long long> mon(N+1);
  for(int i=0;i<=N;i++){
    cin>>mon.at(i);
  }
  vector<long long> yuu(N);
  for(int i=0;i<N;i++){
    cin>>yuu.at(i);
  }
  long long monsum=0;
  for(int i=0;i<=N;i++){
    monsum+=mon.at(i);
  }
  
  reverse(mon.begin(),mon.end());
  reverse(yuu.begin(),yuu.end());
  
  for(int i=0;i<N;i++){
    long long x=mon.at(i);
    mon.at(i)=max(mon.at(i)-yuu.at(i),0ll);
    yuu.at(i)=max(yuu.at(i)-x,0ll);
    mon.at(i+1)=max(mon.at(i+1)-yuu.at(i),0ll);
  }
  long long monsum2=0;
  for(int i=0;i<=N;i++){
    monsum2+=mon.at(i);
  }
  
  cout<<monsum-monsum2<<endl;
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;
int R,G,B,N;
int ans = 0;


int main(){
    int N; cin >> N;
    map<int,int> m{};
    for(int i=0;i<N;i++){
        int n; cin >> n;
        if(m[n]) m[n]--;
        else m[n]++;
    }
    int ans = 0;
    for(auto i =m.begin(); i!=m.end();i++){
        ans+=i->second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef  long long ll;
int main()
{
    ll n,z,w;
    ll a[maxn];
    scanf("%lld%lld%lld",&n,&z,&w);
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    ll ans=0;
    if(n==1)
    {
        ans=abs(w-a[1]);
        cout<<ans<<endl;
    }
    else
    {
     ans=abs(a[n]-w);
     ans=max(ans,abs(a[n-1]-a[n]));
     cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

int n;
map< int, int > p;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    vi a(n);
    REP(i,n){
        cin>>a[i];
        p[a[i]]++;
    }

    if(p[1]>=1){
      if(p[1]==1){
        cout << "1" << endl;
      }else{
        cout << "0" << endl;
      }
      return 0;
    }

    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());

    int sz = a.size();
    int mx = a[sz-1];
    vector<bool> dp(mx+1, true);
    int ans = 0;
    
    REP(i,sz){
      for(int j=a[i]; j<=mx; j+=a[i]){
        if(j==a[i] && p[a[i]]==1) continue;
        dp[j]=false;
      }
    }

    for(auto e:p){
      if(e.second>0 && dp[e.first]){
        ans++;
      }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13576
r, c = map(int, input().split())

matrix = [list(map(int, input().split())) for _ in range(r)]

for i in range(r):
    matrix[i].append(sum(matrix[i]))

matrix.append(list(map(sum, zip(*matrix))))
# matrix.append([sum(i) for i in zip(*matrix)])

for row in matrix:
    print(' '.join(str(e) for e in row))


Measured memory_bytes: 5708
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int n; cin>>n;
  double a[n];
  double ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=1/a[i];
  }
  cout<<1/ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void print(int array[], int n){
  int j;
  for(j = 0; j < n; j++){
    if(j > 0) printf(" ");
    printf("%d", array[j]);
  }
  printf("\n");
}

int main(){
  int array[2000],n = 200,i = 0,j = 0,v,k;
  scanf("%d", &n);
  for(i = 0;i < n; i++)scanf("%d", &array[i]);

  print(array, n);

  for(i = 1; i < n; i++) {
    v = array[i];
    k = i - 1;
    while(k >= 0 && array[k] > v) {
      array[k + 1] = array[k];
      k--;
    }
    array[k + 1] = v;
    print(array, n);
  }
  return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

const int MOD = 1000000007;

int main(int argc, char **argv)
{
  #ifdef LOCAL
    freopen("in.txt", "r", stdin);
  #endif

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

  int n, m; cin >> n >> m;
  vector<vector<int>> adj(n);
  for(int i=0; i<m; i++) {
    int x, y; cin >> x >> y;
    x--; y--;
    adj[x].push_back(y);
  }

  const int INF = 1e9;
  vector<int> dist[3];
  dist[0] = vector<int>(n, INF);
  dist[1] = vector<int>(n, INF);
  dist[2] = vector<int>(n, INF);

  int st, ed; cin >> st >> ed;
  st--; ed--;

  queue<pair<int, int>> q;
  dist[0][st] = 0;
  q.push({0, st});

  while(q.size()) {
    int v = q.front().second;
    int s = q.front().first; q.pop();

    for(int u : adj[v]) {
      if(dist[s][v] + 1 < dist[(s+1)%3][u]) {
        dist[(s+1)%3][u] = dist[s][v] + 1;
        q.push({(s+1)%3, u});
      }
    }
  }

  if(dist[0][ed] == INF) cout << "-1" << endl;
  else cout << dist[0][ed] / 3 << endl;

  return 0;
}

Measured memory_bytes: 6912
#include <cstdio>

int main(){
   int N;
   scanf("%d",&N);
   for(int i=0; i*4 <= N ; i++){
          for(int j=0 ; i *4 + j *7<=N;j++){
                if(i*4+j*7 == N){
                      printf("Yes");
                     return 0;
                  }
           }
     }
     printf("No");
     return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define MAX 2000000

int size=0,A[MAX + 1];

void maxHeapify(int i){
  int l,r,largest,t;

  l = 2 * i;
  r = 2 * i + 1;

  if(l <= size && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  
  if(r <= size && A[r] > A[largest]){
    largest = r;
  }
  
  if(largest != i){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;

  if(size < 1) return 0;

  maxv = A[1];
  A[1] = A[size--];

  maxHeapify(1);
  
  return maxv;
}

void increaseKey(int i,int key){
  int tmp;
    
  if(key < A[i]){
    return;
  }
  A[i] = key;

  while(i > 1 && A[i / 2] < A[i]){
    tmp = A[i];
    A[i] = A[i / 2];
    A[i / 2] = tmp;
    i = i / 2;

  }
}

void insert(int key){
 
  size++;
  A[size] = -1000000001;
  increaseKey(size,key);
}

int main(){
  int key;
  char com[20];

  while(1){
    scanf("%s",com);

    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(com[0] == 'e' && com[1] == 'x'){
      printf("%d\n",extract());
    }
    else{
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 5592
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int mod = 1000000007;
const int tmpMod = 998244353;

int main() {
 
  int64_t N;
  cin>>N;
  //vector<int64_t> A(N);
  //for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int> > A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << N + (N*N) + (N*N*N) << endl;
}


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

int main(int argc, char const *argv[])
{
    int32_t A, B;
    cin >> A >> B;

    int32_t K;
    bool found = false;
    for (K = 0; K <= max(A, B); K++)
    {
        if (abs(A - K) == abs(B - K))
        {
            found = true;
            cout << K << endl;
        }
    }

    if (found == false)
    {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100][100],b[100],c[100],m,n;
  int mn;
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	a[i][j]=200000000;
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p;
      if(p){
	cin>>p>>q>>r;
	p--;
	q--;
	a[p][q]=a[q][p]=min(a[p][q],r);
      }else{
	cin>>p>>q;
	p--;
	q--;
	memset(b,-1,sizeof(b));
	b[p]=1;
	c[p]=0;
	for(j=0;j<n;j++){
	  if(j!=p)
	    c[j]=c[p]+a[p][j];
	}
	for(;;){
	  mn=q;
	  for(j=0;j<n;j++){
	    if(b[j]==-1&&c[mn]>c[j])
	      mn=j;
	  }
	  if(mn==q)
	    break;
	  b[mn]=1;
	  for(j=0;j<n;j++)
	    c[j]=min(c[j],c[mn]+a[mn][j]);
	}
	if(c[q]==200000000)
	  cout<<-1<<endl;
	else
	  cout<<c[q]<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
	int A,B; // A years old. B yen.
	cin >> A >> B;
	if(A >= 13){
		cout << B;
	}else if(A <= 5){
		cout << 0;
	}else{
		cout << B/2;
	}
	return 0;
}

Measured memory_bytes: 888
n = input()
prices = list()
for idx in range(int(n)):
    tmp = input()
    prices.append(int(tmp))

minp = prices[0]
maxv = prices[1] - prices[0]

for price in prices[1:]:
    maxv = max(maxv, price - minp)
    minp = min(minp, price)

print(maxv)




Measured memory_bytes: 15084
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
line = lines.shift().split(' ')
for (i=0; i<N; i++) {
    line[i] = line[i] * 1
}
sum = 0
for (i=0; i<N; i++) {
    for (j=i+1; j<N; j++) {
        sum += line[i] * line[j]
    }
}
console.log(sum)

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

int main()
{
  int N;
  cin >> N;
  int exponent = 32;
  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    if (0 != A%2)
    {
      cout << 0;
      return 0;
    }
    for (int j = 1; j <= exponent; ++j)
    {
      A >>= 1;
      if (0 != A%2)
      {
        exponent = j;
        break;
      }
    }
  }
  cout << exponent;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long N = iArray[0];
            long K = iArray[1];
            List<long> result = new List<long>();
            result.Add(K);
            for(long p =1; p < N; p++)
            {
                result.Add(K+p);
                result.Add(K-p);
            }
            String console = "";
            result.Sort();
            for (int q = 0; q < result.Count; q++)
            {
                console += result[q].ToString()+" ";
            }
            Console.WriteLine(console);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
 
int main()
{   
    
    long long n,m,ans;
    cin>>n>>m;
    if(n==1&&m==1) ans=1;
    else if(n==1) ans=m-2;
    else if(m==1) ans=n-2;
    else ans=(n-2)*(m-2);
    cout<<ans<<endl;
    
   
}

Measured memory_bytes: 256
n = int(input())
A = [int(x) for x in input().split()]

cnt = 0
for i in range(n - 1):
    k = i
    for j in range(i + 1, n):
        if A[j] < A[k]:
            k = j

    if i != k:
        A[i], A[k] = A[k], A[i]
        cnt += 1

print(*A)
print(cnt)



Measured memory_bytes: 5608
N = int(input())
A = list(map(int, input().split()))
R = []

'''プラススタート、マイナススタートの累積和を取る'''
plus_start = []
minus_start = []
'''後ろからの累積和'''
plus_start_rev = []
minus_start_rev = []

tmp = 0
pm = -1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    plus_start.append(tmp)
tmp = 0
pm = -1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    plus_start_rev.append(tmp)

tmp = 0
pm = 1
for i in range(N):
    pm *= -1
    tmp += A[i] * pm
    minus_start.append(tmp)

tmp = 0
pm = 1
for i in range(-1, -N-1, -1):
    pm *= -1
    tmp += A[i] * pm
    minus_start_rev.append(tmp)

'''各山の降水量を計算する'''
for i in range(N):
    if i == 0:
        tmp = plus_start[-1]
        R.append(tmp)
        continue
    if i % 2 == 0:
        tmp = minus_start[i-1] + plus_start_rev[N-i-1]
    else:
        tmp = plus_start[i-1] + minus_start_rev[N-i-1]
    R.append(tmp)

print(*R)


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

int main(){
  int count=1;
  string S;
  cin>>S;
  if(S.at(0)=='R'&&S.at(1)=='R'){
    count++;
  }
  if(S.at(1)=='R'&&S.at(2)=='R'){
    count++;
  }
  if(S.at(0)=='S'&&S.at(1)=='S'&&S.at(2)=='S'){
    count--;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long dp[n+1] = {};
  long long cnt[10][10] = {};
  
  REP(i,n+1){
    if(i == 0)continue;
    dp[i] = dp[i-1];
    REP(t, 10){
      if(t == 0)continue;
      REP(d, 10){
        int di = i % 10;
        int ti;
        int temp = i;
        int num = 0;
        while(temp > 0){
          if(temp < 10){
            ti = temp;
            break;
          }else{
            temp /= 10;
            num++;
          }
        }
        if(ti != t || di != d){
          continue;
        }
        cnt[t][d]++;
        dp[i] += 2*cnt[d][t];
        if(ti == di){
          dp[i]--;
        }
      }
    }
  }
  long long ans = dp[n];
  cout<<ans<<endl; 
  return 0;
}

Measured memory_bytes: 1792
import heapq

N, M = map(int,input().split())
An = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(An)
for m in range(M):
    heapq.heappush(An,-1*((-1*heapq.heappop(An))//2))
 
print(-sum(An))


Measured memory_bytes: 14260
#include "bits/stdc++.h"
#define readInt(x) scanf_s("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmax(x, y) (x > (y) ? x : x = (y))
#define chmin(x, y) (x < (y) ? x : x = (y))
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = INT32_MAX / 2;
const int MAX = 1e5 + 10;

int n;
int a[MAX];

int main()
{
    cin >> n;
    int sump = 0;
    int sumn = 0;
    ll cntp = 0;
    ll cntn = 0;
    rep(i, n) {
        cin >> a[i];
        sump += a[i];
        sumn += a[i];
        if (i % 2) {
            int r = max(sump + 1, 0);
            sump -= r;
            cntp += r;
            r = max(1 - sumn, 0);
            sumn += r;
            cntn += r;
        }
        else {
            int r = max(1 - sump, 0);
            sump += r;
            cntp += r;
            r = max(sumn + 1, 0);
            sumn -= r;
            cntn += r;
        }
    }
    write(min(cntp, cntn));
}

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

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

    vector<int> s(n);
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    /*pairでたたく方******************
    vector<pair<int, int>> k(n);
    for (int i = 0; i < n; i++)
    {
        k[i] = make_pair(s[i],i+1);
    }

    sort(k.begin(), k.end());

    for (int i = 0; i < n; i++)
    {
        cout << k[i].second << " ";
    }cout << 
    *********************************/

    ///*pairを使わない方
    vector<int> stu(n);
    for (int i = 0; i < n; i++)
    {
        stu[s[i] - 1] = i + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cout << stu[i] << " ";
    }
    cout << endl;
    //**************************/
    return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        //String[] a = sc.nextLine().split(" ");

        int x = Integer.parseInt(s1[0]);
        int a = Integer.parseInt(s1[1]);

        int result=0;
        if (x < a) {
        	result=0;
        } else {
        	result=10;
        }

        System.out.println(result);
    }



}

Measured memory_bytes: 22740
#include <vector>
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    int c = 0;
    while (s[c] == 'F') c++;
    x -= c;
    c++;
    bool h = false;
    vector<int> hor, ver;
    while (c < s.size()) {
        int c0 = c;
        while (c < s.size() && s[c] == 'F') c++;
        if (h) hor.push_back(c-c0);
        else ver.push_back(c-c0);
        h = !h;
        c++;
    }
    x += accumulate(hor.begin(), hor.end(), 0);
    y += accumulate(ver.begin(), ver.end(), 0);
    if (x % 2 != 0 || y % 2 != 0) { cout << "No\n"; return 0; }
    x /= 2; y /= 2;
    bool dp[8000] = {};
    dp[0] = true;
    for (int a : hor) {
        for (int i = x; i >= a; i--) dp[i] = dp[i-a];
    }
    if (!dp[x]) { cout << "No\n"; return 0; }
    fill(dp+1, dp+8000, false);
    for (int a : ver) {
        for (int i = y; i >= a; i--) dp[i] = dp[i-a];
    }
    if (!dp[y]) { cout << "No\n"; return 0; }
    cout << "Yes\n";
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	h,w,n=MI()
	sr,sc=MI()
	S=RD()
	T=RD()

	ans="YES"

	#Rの検証
	x=w-sc+1
	for i,j in zip(S,T):
		if i=="R":
			x-=1
			if x==0:
				ans="NO"
		if j=="L":
			if x<w:
				x+=1

	#Lの検証
	x=sc
	for i,j in zip(S,T):
		if i=="L":
			x-=1
			if x==0:
				ans="NO"
		if j=="R":
			if x<w:
				x+=1

	#Dの検証
	x=h-sr+1
	for i,j in zip(S,T):
		if i=="D":
			x-=1
			if x==0:
				ans="NO"
		if j=="U":
			if x<h:
				x+=1

	#Uの検証
	x=sr
	for i,j in zip(S,T):
		if i=="U":
			x-=1
			if x==0:
				ans="NO"
		if j=="D":
			if x<h:
				x+=1

	print(ans)










if __name__ == "__main__":
	main()


Measured memory_bytes: 73868
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

/*int main1(void) {
	ll n, k, ans = 0, mi = 1000000000000;
	cin >> n >> k;
	vector<ll>a(n);
	for (int i = 0;i < n;i++)cin >> a[i];
	for (int l = 0;l <= n - k;l++) {
		int r = l + k - 1;
		ans = abs(a[r]) + abs(a[r] - a[l]);
		mi = min(mi, ans);
		ans = abs(a[l]) + abs(a[r] - a[l]);
		mi = min(mi, ans);
	}
	cout << mi << endl;
	return 0;
}*/
char a[50][50];

int main(void) {
	int h, w;
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (a[i][j] == '#') {
				if (i == 0) {
					if (j == 0) {
						if (a[i][j + 1] == '.'&&a[i + 1][j] == '.') {
							cout << "No" << endl;
							return 0;
						}
					}
					else {
						if (j == w - 1) {
							if (a[i][j-1] == '.'&&a[i + 1][j] == '.') {
								cout << "No" << endl;
								return 0;
							}
						}
						else {
							if (a[i][j - 1] == '.'&&a[i + 1][j] == '.'&&a[i][j+1]=='.') {
								cout << "No" << endl;
								return 0;
							}
						}
					}
				}
				else {
					if (i == w - 1) {
						if (j == 0) {
							if (a[i][j + 1] == '.'&&a[i - 1][j] == '.') {
								cout << "No" << endl;
								return 0;
							}
						}
						else {
							if (j == w - 1) {
								if (a[i][j - 1] == '.'&&a[i - 1][j] == '.') {
									cout << "No" << endl;
									return 0;
								}
							}
							else {
								if (a[i][j - 1] == '.'&&a[i - 1][j] == '.'&&a[i][j + 1] == '.') {
									cout << "No" << endl;
									return 0;
								}
							}
						}
					}
					else {
						if (j == 0) {
							if (a[i][j + 1] == '.'&&a[i - 1][j] == '.'&&a[i+1][j]=='.') {
								cout << "No" << endl;
								return 0;
							}
						}
						else {
							if (j == w - 1) {
								if (a[i][j - 1] == '.'&&a[i - 1][j] == '.'&&a[i + 1][j] == '.') {
									cout << "No" << endl;
									return 0;
								}
							}
							else {
								if (a[i - 1][j] == '.'&&a[i + 1][j] == '.'&&a[i][j - 1] == '.'&&a[i][j + 1] == '.') {
									cout << "No" << endl;
									return 0;
								}
							}
						}
					}
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int k,x;
	cin>>k>>x;
	FOR(i,x-k+1,x+k){
		cout<<i<<" ";
	}

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int dp[44][444][444];
int A[44], B[44], C[44];
const int INF = 1e9;

int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}
	for (int i = 0; i < 44; i++)
		for (int j = 0; j < 444; j++)
			for (int k = 0; k < 444; k++)
				dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int a = 0; a < 444; a++) {
			for (int b = 0; b < 444; b++) {
				dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]], dp[i][a][b] + C[i]);
				dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b]);
			}
		}
	}
	int ans = INF;
	for (int i = 1; i < 444; i++) {
		for (int j = 1; j < 444; j++) {
			int g = __gcd(i, j);
			if (i/g == Ma && j/g == Mb) ans = min(ans, dp[N][i][j]);
		}
	}
	if (ans == INF) ans = -1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 34176