akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main(){
    int n;
    ll k, q;
    cin >> n >> k >> q;
    vector<ll> x(n, k-q);
    vector<int> a(q);
    rep(i,q){
        int a;
        cin >> a;
        --a;
        x[a]++;
    }
    rep(i,n) {
        if(x[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <math.h>

using namespace std;

int main()
{
	int p1 = 0, p2 = 0;
	string s, s2;
	cin >> s;
	int s_len = s.length();
	for (int t = 0; t < s_len; t++) {
		s2 = s[t];
		if (t % 2 == 0) {
			p1 += abs(0 - atoi(s2.c_str()));
			p2 += abs(1 - atoi(s2.c_str()));
		}
		else {
			p1 += abs(1 - atoi(s2.c_str()));
			p2 += abs(0 - atoi(s2.c_str()));

		}
	}
	if (p1 < p2) cout << p1 << endl;
	else cout << p2 << endl;
}

Measured memory_bytes: 512
object Main extends App {
	val Array(n, k) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val s = scala.io.StdIn.readLine.toList.toArray
	s(k-1) = (s(k-1).toInt + 32).toChar
	println(s.mkString)
}

Measured memory_bytes: 25544
I = [int(_) for _ in open(0).read().split()]
n, u, v = I[:3]
A, B = I[3::2], I[4::2]
S = [set() for _ in range(n+1)]
for a, b in zip(A, B):
    S[a].add(b)
    S[b].add(a)
def cal(x):
  dist=[None]*(n+1)
  dist[x]=0
  st=set([x])
  while st:
    x=st.pop()
    for i in S[x]:
      if dist[i]==None:
        dist[i]=dist[x]+1
        st.add(i)
  return dist

T=cal(u)
A=cal(v)
ans=0
for t,a in zip(T[1:],A[1:]):
  if t<a:
    ans=max(ans,a-1)
print(ans)

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

const W INF = 1LL << 50;
struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph& G, vector<W>& d, vector<int>& prev) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	fill(prev.begin(), prev.end(), -1);

	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				prev[e.to] = v;
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

bool exist[100][100];
bool use[100][100];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	Graph G(N);
	for(int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		exist[a][b] = exist[b][a] = 1;
		G[a].push_back({ b, c });
		G[b].push_back({ a, c });
	}

	vector<W> d(N);
	vector<int> prev(N);
	for(int i = 0; i < N; i++) {
		dijkstra(i, G, d, prev);
		for(int j = 0; j < N; j++) {
			if(i == j) continue;
			int v = j;
			while(v != i) {
				use[v][prev[v]] = use[prev[v]][v] = 1;
				v = prev[v];
			}
		}
	}

	int ans = M;
	for(int i = 0; i < N; i++) {
		for(int j = i + 1; j < N; j++) {
			if(!exist[i][j]) continue;
			if(use[i][j]) ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";


int main(){
    int N,max_count,max; cin >> N;
    vint A(N),A_x(N); REP(i,N) cin >> A.at(i);
    A_x = A;
    max = *max_element(ALL(A)); 
    max_count = count(ALL(A),max);

  if(max_count >=2){
        REP(i,N) cout << max <<"\n";
    }
  else{
    REP(i,N){
        if(A[i] == max){
            A_x.erase(A_x.begin()+i);
            cout << *max_element(ALL(A_x)) << "\n";
        }

        else cout << max << "\n";


        // A.erase(A.begin());
        // max = *max_element(ALL(A));
        // if(x > max) cout << x << "\n";
        // else cout << max << "\n";


    }
    
  }

}

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

int main()
{
    ll N;
    cin >> N;
    string S[N];
    for(ll i=0;i<N;i++)
        cin >> S[i];
    sort(S,S+N);
    ll j=0;
    for(ll i=0;i<=N-1;i++){
        if(S[i]!=S[i+1]){
            j++;
        }
    }
    cout << j << endl;

}

Measured memory_bytes: 9852
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int S[1000] = { 0 };


int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	vector<int>ans;
	for (int bit = 0; bit < (1 << N); ++bit) {
		int a=0;
		rep(i, N) {
			if (bit&(1 << i)) {
				a += A[i];
			}
		}
		ans.push_back(a);
	}
	int Q;
	cin >> Q;
	vector<int>M(Q);
	rep(i, Q)cin >> M[i];

	rep(i,Q) {
		bool flg = false;
		rep(j,ans.size()) {
			if (M[i] == ans[j]) {
				flg = true;
				break;
			}
		}
		if (flg) {
			cout << "yes" << endl;
		}
		else{
			cout << "no" << endl;
		}
	}

	return 0;
}





Measured memory_bytes: 7052
a, b = map(int, input().split())

if a > 0 and b > 0:
    print("Positive")
elif (a > 0 and b < 0) or (a < 0 and b > 0):
    print("Zero")
elif (a < 0 and b < 0):
    if (abs(a-b)+1) % 2 == 0:
        print("Positive")
    else :
        print("Negative")


Measured memory_bytes: 3060
d = [int(input()) for _ in range(5)]

ans = 0
r =[]
for i in range(5):
  if d[i]%10!=0:
    r.append(d[i]%10)
    ans += d[i]-(d[i]%10)+10
  else:
    ans += d[i]

if len(r) == 0:
  print(ans)
  exit()
else:
  ans -= 10-min(r)
  print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
typedef unsigned long long ll;
using namespace std;
int main(){
    double a,b;
    int ans;
    scanf("%lf %lf",&a,&b);
    ans=b/0.1;
    while(ans<a/0.08){
        ans+=1;
    }
    int x1=ans*0.08,x2=ans*0.1;
    if(a==x1&&b==x2) printf("%d\n",ans);
    else printf("-1\n");
}


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

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N, M;
const int MAX_M = 100000;
int a[MAX_M];

int main(){
  cin >> N >> M;
  REP(i, M) cin >> a[i];

  REP(i, M - 1) {
    if(a[i + 1] == a[i] + 1) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll dp[N + 1];
  dp[0] = 1;
  dp[1] = 1;
  REP(i, N - 1) {
    dp[i + 2] = (dp[i + 1] + dp[i]) % MOD;
  }

  if(M == 0) {
    cout << dp[N] << endl;
    return 0;
  }

  ll ans = dp[a[0] - 1];
  REP(i, M - 1) {
    ans = ans * dp[a[i + 1] - a[i] - 2] % MOD;
  }

  ans = ans * dp[N - 1 - a[M - 1]] % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
#define M 1000001
#define mod 10007
int main(void){
    int K,N,A[400000];
    scanf("%d %d",&K,&N);
    for (int i=0; i<N; i++) {
        scanf("%d",&A[i]);
        A[i+N]=A[i]+K;
    }
    int max=0,sum=0;
    for (int i=0; i<N; i++) {
        if(A[i+1]-A[i]>max){
            max=A[i+1]-A[i];
        }
    }
    
    printf("%d\n",K-max);
    return 0;
}

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

using namespace std;

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

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define rep(i,n) for(int i =0;i<n;++i)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define FOR(it,a ) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
typedef pair<int,int> PI;

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


int h,w,s;
int u[100][100];

int sum[100][100];

PI memo[50][50][50][50];//group, yobi
bool vis[50][50][50][50];//group, yobi

PI rec(int x1,int y1,int x2,int y2){
  auto&  ans =memo[x1][y1][x2][y2];
  if(ans.F>=0)  return ans;
  ans=mp(0,10000000000000);
  assert(vis[x1][y1][x2][y2]==0);
  vis[x1][y1][x2][y2]=1;
  //ans = mp(-1,0);
  int su =sum[x2][y2]-sum[x2][y1]-sum[x1][y2]+sum[x1][y1];
  int all = sum[h][w];
  int saiju = all - su;
  if(saiju <= s)
    ans=mp(1,s-saiju);
  
  
  for(int x=x1+1;x<x2;++x){
    auto p = rec(x1,y1,x,y2);
    auto p2 = rec(x,y1,x2,y2);
    ans=max(ans,mp(p.F+p2.F,min(p.S,p2.S)));
  }
  
  for(int y=y1+1;y<y2;++y){
    auto p = rec(x1,y1,x2,y);
    auto p2 = rec(x1,y,x2,y2);
    ans=max(ans,mp(p.F+p2.F,min(p.S,p2.S)));
  }
  
  //cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << ans.F << " " << ans.S << endl;
  return ans;
}

void solve(){
  rep(i,h)rep(j,w) cin >> u[i][j];
  rep(i,h)rep(j,w)
    sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] + u[i][j] - sum[i][j];
  //cout << sum[h][w] << endl;
  memset(memo,-1,sizeof(memo));
  memset(vis,0,sizeof(vis));
  auto ans = rec(0,0,h,w);
  cout << ans.F << " " << ans.S << endl;
  //cout << rec(0,0,h,w) << endl;
}


int main(){
  while(cin >>h  >> w>>s,h) solve();  
}

Measured memory_bytes: 56140
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int x,n;
    cin >> x >> n;
    set<int> s;
    rep(i,0,n-1){
        int p;
        cin >> p;
        s.insert(p);
    }
    int i = 0;
    int now;
    // for(auto i=s.begin();i!=s.end();i++)cout << *i << endl;//1 3 5
    while(1){
        now = x - i;
        auto itr = s.find(now);
        if(itr == s.end()){
            cout << now << endl;
            return 0;
        }
        now = x + i;
        itr = s.find(now);
        if(itr == s.end()){
            cout << now << endl;
            return 0;
        }
        i++;
    }


    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int arr[105]={};
    string str;
    cin>>str;
    int s=str.size();
    for(int i=0;i<s;i++)
    {
        arr[str[i]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        if(arr[i]%2!=0)
        {
            cout<<"No";return 0;
        }
    }
    cout<<"Yes";
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> s2t(26, -1);
  vector<int> t2s(26, -1);
  for (int i = 0; i < s.size(); i++) {
    int a = s[i] - 'a';
    int b = t[i] - 'a';

    if (s2t[a] != -1 || t2s[b] != -1) {
      if (s2t[a] != b || t2s[b] != a) {
        cout << "No\n";
        return 0;
      }
    }
    s2t[a] = b;
    t2s[b] = a;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  int n, m;
  cin>>n>>m;
  int aa = (n - m)*100 + m*1900;
  int ans = aa * (1<<m);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n+1;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
#define stringc(s) string s; cin >> s;
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  vector<int> q(n);
  set<int> s;
  r1(i,k) {
    int d;
    cin >> d;
    r1(j,d) {
      int f;
      cin >> f;
      s.insert(f);
    }
  }
  cout << q.size()-s.size() << endl;
}

Measured memory_bytes: 3608
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,p]=i2()
s=input()

  
if p==2 or p==5:
   x1=0
   for i in range(n):
     if int(s[i])%p==0:
        x1+=i+1  
   print(x1)
else:
  t=0
  x2=0
  d={0:1}
  a=1
  for i in range(n)[::-1]:
     t+=int(s[i])*a
     t%=p
     a*=10
     a%=p
     if t in d:
        x2+=d[t]
        d[t]+=1
     else:
        d[t]=1
  print(x2)

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	LL n, a, b;
	cin>>n>>a>>b;

	if (a > b || (n == 1 && a != b))
	{
		cout<<0<<endl;
		return 0;
	}


	LL mn = (n-1) * a + b;
	LL mx = (n-1) * b + a;
	LL res = mx - mn + 1;
	cout<<res<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[200100],ed[200100],t[200100];
vector<int> v[26];

char s[200100];

int lowbit(int x){
	return x&(-x);
}

int query(int x){
	int ret=0;
	while(x){
		ret+=t[x];
		x-=lowbit(x);
	}
	return ret;
}
int N;
void add(int x){
	while(x<=N){
		t[x]+=1;
		x+=lowbit(x);
	}
}

int main(){
	while(~scanf("%s",s)){
		int l=strlen(s);
		for(int i=0;i<26;i++)
			v[i].clear();
		for(int i=0;i<l;i++){
			s[i]-='a';
			v[s[i]].push_back(i);
		}
		int flag=0;
		for(int i=0;i<26;i++){
			ed[i]=v[i].size()-1;
			flag+=v[i].size()%2;
		}
		N=l+10;
		memset(a,0,sizeof(a));
		if(flag<=1){
			int p=1,q=l,i=0;
			int x=l/2;
			if(flag==1){
				int hh=1;
				for(int i=0;i<26;i++){
					if(v[i].size()%2==1){
						a[v[i][ed[i]/2]]=x+1;
					}
				}
			}
			while(p<=x){
				while(i<l&&a[i]!=0) i++;
				a[i]=p++;
				if(p<=q){
					a[v[s[i]][ed[s[i]]]]=q--;
					ed[s[i]]--;
				}
				i++;
			}

			memset(t,0,sizeof(t));
			long long ans=0;
			for(int i=0;i<l;i++){
				ans+=i-query(a[i]);
				add(a[i]);
			}
			printf("%lld\n",ans);
		}
		else puts("-1");
	}
}


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

using ll = long long;

void solve(long long N, long long M, std::vector<std::vector<long long>> A){
    vector<queue<int>> sport(N);
    for(int i = 0;i < N;i++)
        for(int j = 0;j < M;j++)
            sport[i].push(A[i][j]);
    
    auto check = [&](int k){
        vector<queue<int>> q = sport;
        set<int> ng;
        while(1){
            map<int, int> mp;
            for(int i = 0;i < N;i++){
                while(ng.find(q[i].front()) != ng.end()){
                    q[i].pop();
                    if(q[i].empty())return false;
                }
                mp[q[i].front()]++;
            }
            bool f = false;
            for(auto a : mp){
                if(a.second > k){
                    f = true;
                    ng.insert(a.first);
                }
            }
            if(!f){
                return true;
            }
        }
    };
    ll ok = 1e9;
    ll ng = 0;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout<<ok<<endl;
}

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


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

int n,a[500],b[500],k,sum,ans;

int main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i],sum+=a[i];
    for(int i=1;i<=sqrt(sum);i++){
        if(sum%i)continue;
        int x=0;
        rep(j,n){
            b[j]=a[j]%i;
            x+=b[j];
        }
        sort(b,b+n);
        x/=i;
        int sum2=0;
        rep(j,n-x)sum2+=b[j];
        if(sum2<=k)ans=max(ans,i);

        int I=sum/i;
        x=0;
        rep(j,n){
            b[j]=a[j]%I;
            x+=b[j];
        }
        sort(b,b+n);
        x/=I;
        sum2=0;
        rep(j,n-x)sum2+=b[j];
        if(sum2<=k)ans=max(ans,I);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int x = nextInt();
        int n = nextInt();

        if(n==0){
            print(x);
            System.exit(0);
        }

        boolean flag;
        flag = true;
        int[] arr = new int[n];

        int min,min_i,tmp;
        min = 1000;
        min_i = 1000;
        for(int i=0;i<n;i++){
            arr[i] = nextInt();
        }
        for(int a:arr){
            if(x==a){
                flag = false;
            }
        }
        if(flag){
            print(x);
            System.exit(0);
        }

        for(int i=1;i<101;i++){
            flag = true;
            tmp = x-i;
            for(int a:arr){
                if(a!=tmp){
                    flag=true;
                    min = tmp;
                }
                else{
                    flag = false;
                    break;
                }
            }
            if(flag){
                print(min);
                System.exit(0);
            }

            flag = true;
            tmp = x+i;
            for(int a:arr){
                if(a!=tmp){
                    flag=true;
                    min = tmp;
                }
                else{
                    flag = false;
                    break;
                }
            }
            if(flag){
                print(min);
                System.exit(0);
            }

        }
    }

    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }

    //print
    public static void print(Object a){
        System.out.println(a);
    }


    //gcd
    public static int gcd (int a, int b){
        int tmp;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return b;
    }


    //lcm
    public static int lcm(int a,int b){
        int tmp;
        long c = a;
        c *= b;
        while((tmp = a%b) != 0){
            a = b;
            b = tmp;
        }
        return (int)(c/b);
    }
}

Measured memory_bytes: 35892
N=int(input())
h=[0 for i in range(N+1)]
h=list(map(int,input().split()))
dp=[0 for i in range(N+1)]
for i in range(1,N):
  if(i==1):
    dp[i]=dp[i]+abs(h[i]-h[i-1])
  else:
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[N-1])

Measured memory_bytes: 15032
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const ll INF=1LL<<60;

int main(){
    int n;
    ll h[100010];
    ll dp[100010];

    cin>>n;
    rep(i,n)cin>>h[i];
    rep(i,100010)dp[i]=INF;

    dp[0]=0;
    for(int i=1;i<n;++i){
        chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1)chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 5192
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	if(a + b + c <= 21){
			System.out.println("win");
        }else{
			System.out.println("bust");
        }
     }
}

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

int main() {
	long long int Aoki{}, Takahashi{}, count{};
	cin >> Takahashi >> Aoki >> count;

	if (count >= Takahashi) {
		count -= Takahashi;
		Takahashi = 0;
	}
	else {
		Takahashi -= count;
		count = 0;
	}

	if (count > 0)
	{
		if (count >= Aoki) {
			count -= Aoki;
			Aoki = 0;
		}
		else {
			Aoki -= count;
			count = 0;
		}
	}
	cout << Takahashi << " " << Aoki;
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

int main(){
  int n, k;
  int a[300000];
  
  scanf("%d %d", &n, &k);
  rep(i, n){
    scanf("%d", &a[i]);
  }
  
  rep(i, n-k){
    if(a[i]<a[i+k])printf("Yes\n");
    else printf("No\n");
  }
  
  return 0;
}


Measured memory_bytes: 4548
from collections import defaultdict

k = int(input())

ms = defaultdict(int)

ans = 1
i = 7
while True:
    if i % k == 0:
        print(ans)
        exit()
    i = (i * 10 + 7) % k
    if ms[i] > 0:
        print(-1)
        exit()
    ms[i] += 1
    ans += 1


Measured memory_bytes: 170156
#include<iostream>
#include<cmath>
using namespace std;
int dfs(int n,int mx,int use){
	int rt=(int)sqrt(n),r=0;
	for(int i=mx;i>0;i--){
		if(n==i*i)r++;
		if(n>i*i&&use<3)r+=dfs(n-i*i,i,use+1);
	}
	return r;
}
int main(){
	int n;
	while(cin>>n,n)cout<<dfs(n,n,0)<<endl;
	return 0;
}

Measured memory_bytes: 868
#include <iostream>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <vector>
#include <climits>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <iomanip>
using namespace std; 
#define Endl '\n'
int main()
{
    long long int n=100;
    long long int k;
    cin>>k;
    int w=0;
    while(k>n)
    {
        w++;
        n=n+(n/100);
    }
    cout<<w;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  char c1[1000] = {0};
   
  scanf("%s",&c1);

  for(char c:c1){ 
    if(!c) continue;
    else if(c == 'A') printf("X");
    else if(c == 'B') printf("Y");
    else if(c == 'C') printf("Z");
    else printf("%c",c - 3);
  }
  printf("\n");
}    

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

#define nl cout<<"\n"
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007

//write your function here
void fun()
{

}


int32_t main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    //start code from here
    ll n;
    ll temp=1000;
    cin>>n;
    string s;
    ll a,b,c,d=0;
    a=b=c=0;
    for (ll i = 0; i < n; i++)
    {
        cin>>s;
        if(s=="AC")
        a++;
        else if(s=="WA")
        b++;
        else if(s=="TLE")
        c++;
        else
        d++;

    }
    
    cout<<"AC "<<"x "<<a;
    nl;
    cout<<"WA "<<"x "<<b;
    nl;
    cout<<"TLE "<<"x "<<c;
    nl;
    cout<<"RE "<<"x "<<d;

} 

Measured memory_bytes: 3656
#include <iostream>
#include <string>

using namespace std;

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

	long long dp[10][10] = {};

	for (int i = 1; i <= N; ++i) {
		auto s = to_string(i);
		dp[s.front() - '0'][s.back() - '0'] += 1;
	}

	long long ans = 0;
	for (int A = 1; A <= N; ++A) {
		auto s = to_string(A);
		ans += dp[s.back() - '0'][s.front() - '0'];
	}

	cout << ans << endl;
}


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

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

using namespace std;

bool check(string s){
  rep(i,s.size()) if( s[i] == '&' ) s[i] = ' ';
  stringstream ss;
  ss << s;
  vector<string> vec;
  while( !( ss >> s ).fail() ) vec.push_back(s);
  set<char> S;
  rep(i,vec.size()) REP(j,i+1,vec.size()){
    char a = ( (vec[i].size() == 2 ) ? vec[i][1] : vec[i][0] );
    char b = ( (vec[j].size() == 2 ) ? vec[j][1] : vec[j][0] );
    if( a == b ) {
      if( min(vec[i].size(),vec[j].size()) == 1 && max(vec[i].size(),vec[j].size()) == 2 ) return false;
    }
  }
  return true;
}

bool compute(string s){
  rep(i,s.size()) if( s[i] == '|' || s[i] == '(' || s[i] == ')' ) s[i] = ' ';
  stringstream ss;
  ss << s;
  vector<string> vec;
  while( !( ss >> s ).fail() ) vec.push_back(s);
  rep(i,vec.size()) if( check(vec[i]) ) return true;
  return false;
}

int main(){
  string s;
  while( cin >> s, s != "#" ){
    puts(compute(s)?"yes":"no");
  }
  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz(a) (int)(a).size()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

int main() {

    //ifstream cin("defend.in");
    //freopen("defend.out", "w", stdout);
    //ifstream cin("input.txt");

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

    int n, m;
    cin >> n >> m;

    vector<int> cnt(26);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char c;
            cin >> c;
            ++cnt[c - 'a'];
        }
    }

    int odd = 0;
    for (int i = 0; i < 26; ++i) {
        if (cnt[i] & 1) {
            ++odd;
        }
    }

    if (odd > 1) {
        cout << "No\n";
        return 0;
    }

    vector<int> d(5);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (n - i - 1 < i) {
                continue;
            }
            if (m - j - 1 < j) {
                continue;
            }
            int s = 1;
            if (n - i - 1 != i) {
                ++s;
            }
            if (m - 1 - j != j) {
                ++s;
            }
            if (n - i - 1 != i && m - 1 - j != j) {
                ++s;
            }
            ++d[s];
        }
    }

    int d2 = 0, d4 = 0;
    for (int i = 0; i < 26; ++i) {
        d4 += cnt[i] / 4;
        cnt[i] %= 4;
        d2 += cnt[i] / 2;
    }

    //cout << d2 << " " << d4 << " " << d[2] << " " << d[4] << "\n";

    if (d4 >= d[4] && d2 + 2 * (d4 - d[4]) >= d[2]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

}


Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                System.out.println(Math.max(sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt() , sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt()  ));
        }
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int pref[200009],suf[200009];

void solve()
{
	int n,i;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<n;i++)
	pref[i+1]=pref[i]+(s[i]=='W');
	for(i=n-1;i>=0;i--)
	suf[i+1]=suf[i+2]+(s[i]=='R');
	
	int ans=n;
	for(i=0;i<=n;i++)
	ans=min(ans,pref[i]+suf[i+1]-min(pref[i],suf[i+1]));
	
	cout<<ans<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 5296
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define double long double
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define fo(i, n) for(int i = 0; i < n; i ++)
#define foe(i, n) for(int i = 0; i <= n; i ++)
#define fo1(i, n) for(int i = 1; i < n; i ++)
#define fo1e(i, n) for(int i = 1; i <= n; i ++)
using namespace std;


int32_t main(){
  fastio
  string s, t;
  cin >> s >> t;
  int ans = 0;
  fo(i, 3)
    if(s[i] == t[i])
      ans ++;
  cout << ans;
}


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))

int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int>> color_count(3, vector<int>(C, 0));
    int D[C][C];
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            cin >> D[i][j];
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            int c;
            cin >> c;
            color_count[(i + j) % 3][c - 1]++;
        }
    }
    int ans = 1e9;
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            for(int k = 0; k < C; k++){
                if(i != j && i != k && j != k){
                    int this_ans = 0;
                    for(int l = 0; l < C; l++){
                        this_ans += D[l][i] * color_count[0][l];
                        this_ans += D[l][j] * color_count[1][l];
                        this_ans += D[l][k] * color_count[2][l];
                    }
                    ans = min(ans, this_ans);
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
ikeru = [[] for _ in range(n)]
hashi = []
for i in range(m):
	a, b = map(int, input().split())
	ikeru[a-1].append(b-1)
	ikeru[b-1].append(a-1)
	hashi.append((a-1, b-1))

ans = 0
for num in hashi:
	settansaku = set([])
	setmada = {0}
	kouho = 1
	
	while kouho != 0:
		for i in list(setmada):
			settansaku.add(i)
			setmada.remove(i)
			kouho -= 1
			for k in ikeru[i]:
				if not k in setmada:
					if not k in settansaku:
						if (k, i) != num and (i, k) != num:
							setmada.add(k)
							kouho += 1
	
	if len(settansaku) != n:
		ans += 1

print(ans)

Measured memory_bytes: 9120
n = int(input())
p = [int(i) for i in input().split()]
ans =0
check = 0
for n,i in enumerate(p):
    if n+1 == i and check == 0:
        ans += 1
        check =1
    elif n+1 == i and check == 1:
        check = 0
    else:
        check=0
print(ans)


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

const int INF=1e8;

int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	const int con=401;
	vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(con,vector<int>(con,INF)));
	dp[0][0][0]=0;
	for(int k=0;k<n;k++){
		int a,b,c;
		cin>>a>>b>>c;
		for(int i=0;i<con;i++){
			for(int j=0;j<con;j++){
				int rhs=INF;
				if(i>=a && j>=b) rhs=dp[k][i-a][j-b]+c;
				dp[k+1][i][j]=min(dp[k][i][j],rhs);
			}
		}

	}
	int res=INF;
	for(int i=1;i<con;i++){
		for(int j=1;j<con;j++){
			if(ma*j==mb*i){
				res=min(res,dp[n][i][j]);
			}
		}
	}
	if(res>=INF) res=-1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll X[1005][2];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, D;
    cin >> N >> D;
    for(int i = 0; i < N; i++) {
        cin >> X[i][0] >> X[i][1];
    }
    atcoder::two_sat g(N);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < i; j++) {
            for(int k = 0; k < 2; k++) {
                for(int l = 0; l < 2; l++) {
                    if(abs(X[i][k] - X[j][l]) < D) {
                        g.add_clause(i, (1 - k) == 1 , j, (1 - l) == 1);
                    }
                }
            }
        }
    }
    if(!g.satisfiable()) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        auto v = g.answer();
        for(int i = 0; i < N; i++) {
            if(v[i]) cout << X[i][1] << endl;
            else cout << X[i][0] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3692
import scala.io.StdIn


object Main extends App {
  val Array(n, l)  = StdIn.readLine.toString.split(" ").map(_.toInt)

  def solve(n: Int, l: Int) : Int  = {

    val ls = (1 to n).map(l + _ -1)
    var m = Int.MaxValue

    ls.foreach {i =>
      if (Math.abs(m) > Math.abs(i))
        m = i
    }
    ls.sum - m
  }
  println(solve(n, l))

}
  



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

vector< vector<int> > s(505, vector<int>(505));

int main() {
  int N, M, Q, l, r, p, q;
  cin >> N >> M >> Q;
  for (int i=0; i<M; i++) {
    scanf("%d %d", &l, &r);
    s[l][r]++;
  }
  for (int i=1; i<=N; i++) {
    for (int j=1; j<=N; j++) {
      s[i][j] += s[i][j-1] + s[i-1][j] - s[i-1][j-1];
    }
  }
  for(int i=0; i<Q; i++) {
    scanf("%d %d", &p, &q);
    cout << s[q][q] - s[q][p-1] - s[p-1][q] + s[p-1][p-1] << endl;
  }
  return 0;
}


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

int main() {
  int n, m = 10000000;
  scanf("%d", &n);
  vector<int> x(n);
  for(int i = 0; i < n; i++) scanf("%d", &x[i]);
  for(int p = 1; p <= 100; p++) {
    int t = 0;
    for(auto a : x) t += (a - p) * (a - p);
    m = min(m, t);
  }
  printf("%d\n", m);
}

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

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;
const ll INF = 1e18;

int main() {
    //code
    ll n,w;
    cin>>n>>w;
    ll weights[n],value[n];
    ll size = 0;
    for(int i = 0 ; i < n ; i++){
        cin>>weights[i]>>value[i];
        size += value[i];
    }
    vector<ll> dp(size+1,INF);
    dp[0] = 0;
    for(int i = 0 ; i < n; i ++){
        for(int j = (size - value[i]); j>=0; j--){
            dp[j+value[i]] = min(dp[j+value[i]],dp[j] + weights[i]);
        }
    }

    ll ans = 0;
    for(int i = 0; i<=size ; i++){
        if(dp[i]<=w){
            ans = i;
        }
    }

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


Measured memory_bytes: 4036
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		int c = Integer.parseInt(tmpArray[2]);
		int x = Integer.parseInt(tmpArray[3]);
		int y = Integer.parseInt(tmpArray[4]);
		
		int AB = (a + b)/2;
		
		long result = 0;
		if(AB >= c){
			int tmp = Math.min(x, y);
			
			x -= tmp;
			y -= tmp;
			
			result += tmp*2*c;
			
//			System.out.println(result);
		}
		
		if(a > 2*c){
			a = 2*c;
		}
		
		if(b > 2*c){
			b = 2*c;
		}
		
		result += x*a;
		result += y*b;
		
		System.out.println(result);
	}

}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m;int a[214514],b[214514],cnt[224514];
signed main(){
	cin>>n>>m;
	rep(i,m)cin>>a[i]>>b[i];
	rep(i,m){
		if(a[i]==1)cnt[b[i]]++;
		if(b[i]==n)cnt[a[i]]++;
	}
	for(int i=0;i<224514;i++){
		if(cnt[i]==2){
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
}
		
		


Measured memory_bytes: 4992
n = int(input())
ac = wa = tle = re = 0
for i in range(n):
  m = input()
  if m == 'AC': ac += 1
  elif m == 'WA': wa += 1
  elif m == 'TLE': tle += 1
  else: re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod=1000000007;
//head

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

    int r, c;
    cin >> r >> c;

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

    vector<vector<int>> dp(r,vi(c,1 << 30));
    
    dp[0][0] = (g[0][0] == '#');

    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(i > 0) dp[i][j] = min(dp[i][j], dp[i-1][j] + (g[i-1][j] == '.' && g[i][j] == '#'));
            if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1] + (g[i][j-1] == '.' && g[i][j] == '#'));
        }
    }
    if(dp[r-1][c-1] == 1 << 30) {
        cout << 0 << endl;
    } else {
        cout << dp[r-1][c-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n,m,ly,s[N],b[N],vis[N],sum,tar,flag,a1[N];long long Ans;
int to[N*2],fst[N],nxt[N*2],hz[N*2],l=1;
void biu()
{
	puts("-1");
	exit(0);
}
void link(int x,int y)
{
	to[++l]=y;nxt[l]=fst[x];fst[x]=l;
	to[++l]=x;nxt[l]=fst[y];fst[y]=l;
}
struct T
{
	int x,y;
}a[N];
T operator+(T a,T b)
{
	return (T){a.x+b.x,a.y+b.y};
}
void Dfs(int x,int y,int f)
{
	a[x].y=y;b[x]=y^1;
	vis[x]=1;sum+=y;tar+=y^1;
	for (int i=fst[x];i;i=nxt[i])
		if (to[i]!=f)
		{
			if (!vis[to[i]])
				Dfs(to[i],y^1,x);
			else flag=i;
		}
}
void Get(int x,int y,int f)
{
	a[x].y=y+a1[x];b[x]=y^1;
	sum+=a[x].y;tar+=b[x];
	for (int i=fst[x];i;i=nxt[i])
		if (to[i]!=f&&!hz[i])
		{
			Get(to[i],y^1,x);
			a[x]=a[x]+a[to[i]];
			b[x]=b[x]+b[to[i]];
		}
}
int main()
{
	scanf("%d%d",&n,&m);
	if (n&1) biu();
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		link(x,y);
	}
	Dfs(1,1,0);
	if (flag)
	{
		int u=to[flag],v=to[flag^1];
	//	cout<<u<<'-'<<v<<endl;
	//	cout<<tar<<' '<<sum<<endl;
		if (a[u].y==a[v].y)
		{
			//puts("1%");
			if ((tar-sum)%2) biu();
			if (a[u].y) a1[u]+=(tar-sum)/2,a1[v]+=(tar-sum)/2;
			else a1[u]+=(tar-sum)/2,a1[v]+=(tar-sum)/2;
			Ans+=abs((tar-sum)/2);
		//	cout<<Ans<<endl;
		}
		else
		{
			//Ans=Get+x
			if (sum!=tar) biu();
			a[u].x++;a[v].x--;
			s[++ly]=0;
		}
		hz[flag]=hz[flag^1]=1;
	}
	else if (sum!=tar) biu();
	sum=tar=0;
	Get(1,1,0);
	//cout<<sum<<' '<<tar<<endl;
	for (int i=2;i<=n;i++)
	{
		//cout<<a[i].x<<' '<<a[i].y<<endl;
		a[i].y-=b[i];
		if (a[i].x) s[++ly]=a[i].x==1?a[i].y:-a[i].y;
		else Ans+=abs(a[i].y);
	}
	sort(s+1,s+ly+1);
	for (int i=1;i<=ly;i++)
		Ans+=abs(s[i]-s[(ly+1)/2]);
	printf("%lld\n",Ans);
}

Measured memory_bytes: 14208
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int m, f, r;
    while (cin >> m >> f >> r)
    {
        if (m == -1 && f == -1 && r == -1)
            break;
        string res;
        if (m == -1 || f == -1)
            res = "F";
        else if (m + f >= 80)
            res = "A";
        else if (m + f >= 65)
            res = "B";
        else if (m + f >= 50)
            res = "C";
        else if (m + f >= 30)
        {
            if (r >= 50)
                res = "C";
            else
                res = "D";
        }
        else
            res = "F";
        cout << res << endl;
    }
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;
    vector<i64> sm(M, 0);
    REP(i, N) {
        i64 K; cin >> K;
        i64 a;
        REP(j, K) {
            cin >> a;
            a--;
            sm[a] += 1;
        }
    }

    i64 cnt = 0;
    REP(i, M) {
        if (sm[i] == N) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && b==c){
		cout<<a+b<<endl;
	}
	else if(a>b && b>c){
		cout<<b+c<<endl;
	}
	else if(a>c && c>b){
		cout<<b+c<<endl;
	}
	else if(b>a && a>c){
		cout<<a+c<<endl;
	}
	else if(b>c && c>a){
		cout<<a+c<<endl;
	}
	else if(c>a && a>b){
		cout<<a+b<<endl;
	}
	else if(c>b && b>a){
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}

int main() {
	int n,k,ans=0,i;
	cin >> n>> k;
	int l[50];
	for(i=0;i<n;i++){
		cin >> l[i];
	}
	qsort(l,n,sizeof(l[0]),ascSort);
	for(i=0;i<k;i++){
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int maxn=5e4+5;
string s;

int main()
{
	cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if((s[i]=='A' && s[i+1]=='B') || (s[i]=='B' && s[i+1]=='A')){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256