akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <memory.h>

using namespace std;

typedef long long ll;

const int VMAX = 1e5;

ll N, M;
vector<int> graph[VMAX + 1];
int color[VMAX + 1];

// coloring -1 or 1
bool dfs(int v, int c){
  color[v] = c;
  for(int i=0;i<graph[v].size();i++){
    int u = graph[v][i];
    if(color[u] == c) return false;
    if(color[u] == 0 && !dfs(u, -c)) return false;
  }
  return true;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  // check if the graph is Bipartite graph
  if(dfs(1, 1)){
    ll cntA = 0, cntB = 0;
    for(int i=1;i<=N;i++){
      color[i] == 1 ? cntA++ : cntB++;
    }
    cout << cntA * cntB - M << endl;
  }else{
    cout << N * (N - 1) / 2 - M << endl;
  }
}

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
 
using namespace std;
int main() {
    long long n;
    cin >> n;
    
    long long a[200010];
    long long ans[200010]={0};
    
    for(int i=2;i<=n;i++){
        cin >> a[i];
    }
    for(int i=2;i<=n;i++){
        ans[a[i]]++;
    }
    
    for(int i=1;i<=n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6720
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    ll ans = 0;
    repf(i,1,n) {
        ans += max((n+i-1)/i-1, 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N;
  int xy[3][3];
  rep(i, 3) rep(j, 3) cin >> xy[i][j];

  rep(i, 101){ // a1
    rep(j, 101){ // a2
      rep(k, 101){ // a3
        if(xy[0][0] - i ==  xy[1][0] - j && xy[0][0] - i ==  xy[2][0] - k){
          if(xy[0][1] - i ==  xy[1][1] - j && xy[0][1] - i ==  xy[2][1] - k){
            if(xy[0][2] - i ==  xy[1][2] - j && xy[0][2] - i ==  xy[2][2] - k){
              // printf("%d %d %d\n", i, j, k);
              print("Yes");
              return 0;
            }
          }
        }
      }
    }
  }
  print("No");
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        char[] c = scanner.next().toCharArray();
        Arrays.sort(c);
        System.out.println(c[0] == c[1] && c[2] == c[3] && c[1] != c[3] ? "Yes" : "No");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

typedef long long ll;
const ll INF = 10e9+7;

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end(),greater<ll>());
    vector<ll> ans;
    REP(i,n-1) {
        if(a[i]==a[i+1]) {
            ans.push_back(a[i]);
            i++;
        }
    }
    REP(i,2) ans.push_back(0);
    cout << ans[0] * ans[1] << endl;
    return 0;
}

Measured memory_bytes: 1660
program sumo
 implicit none
 character(15) :: s
 integer n, m, i, k, win
 m=0
 read*, s
 k=len_trim(s)
 do i=1,k
  n=index(s(i:i),"o")
   if(n.ne.0) m=m+1
 end do
 win=m+(15-k)
 if(win.ge.8) then
  write(*,*) "YES"
 else if (win.lt.8) then
  write(*,*) "NO"
 end if
end program

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int ans = 2*n;
    rep(i, n) {
        bool flag = false;
        for (int j = 0; i+j < n; ++j) {
            if (s[i+j] != t[j]) break;
            if (i+j == n-1) {
                ans = i + n;
                flag = true;
                break;
            }
        }
        if (flag) break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
N,C=map(int,input().split())
from collections import defaultdict
cannel={i:[] for i in range(1,1+C)}
check=[tuple(map(int,input().split())) for i in range(N)]
check.sort(key=lambda x:x[0])
for x in check:
    s,t,c=x
    if cannel[c]==[]:
        cannel[c].append((max(0,s-1),t))
    elif s-cannel[c][-1][1]<=1:
        cannel[c][-1]=(cannel[c][-1][0],t)
    else:
        cannel[c].append((max(0,s-1),t))
start=defaultdict(int)
end=defaultdict(int)
for c in range(1,1+C):
    for x in cannel[c]:
        start[x[0]]+=1
        end[x[1]]+=1
ans=0
now=0
for i in range(10**5+1):
    now+=start[i]-end[i]
    ans=max(ans,now)
print(ans)

Measured memory_bytes: 47536
n = int(input())
lst = []
for i in range(n):
    lst1 = list(map(int,input().split()))
    lst.append(lst1)
vec = []
for i in range(n):
    if lst[i][0]==0:
        vec.append(lst[i][1])
    elif lst[i][0]==2:
        vec.pop()
    else:
        print(vec[lst[i][1]])


Measured memory_bytes: 35636
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  ll T, A;
  cin >> T >> A;
  auto H = mvec<ll>(N);
  for(auto&& i : H){
    cin >> i;
  }
  ll ans{};
  ld dif{MOD};
  ll point{};
  for(auto&& i : H){
    point++;
    if(dif > abs(T - i * 0.006 - A)){
      ans = point;
      dif = abs(T - i * 0.006 - A);
    }
  }
  cout << ans << rt;
}

Measured memory_bytes: 256
S = input()

ans = 1
for right in range(2, len(S)):
    T = S[: right]
    if T == S:
        break
    if len(T) % 2 == 0 and T[: len(T) // 2] == T[len(T) // 2:]:
        ans = max(ans, len(T))

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l;
    int temp;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        l.push_back(temp);
    }
    sort(l.begin(), l.end(), greater<int>());
    int sum = 0;
    for (int i = 0; i < k; ++i) sum += l[i];
    cout << sum << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    x, n = map(int, readline().split())
    P = [int(i) for i in readline().split()]
    notP = [i for i in range(-100, 200) if i not in P]
    abcxP = [abs(x-i) for i in notP]
    mi = 10000000
    idx = 0
    for i in range(len(abcxP)):
        if abcxP[i] < mi:
            mi = abcxP[i]
            idx = i
    print(notP[idx])
if __name__ == '__main__':
    main()


Measured memory_bytes: 9264
#include<bits/stdc++.h>
using namespace std;
//#define ull unsigned  long  long
#define int long long int
//#define lld long double
#define endl "\n"
#define S second
#define F first
#define pir      pair<int,int>
#define vtr      vector<int>
#define mpp      map<int,int>
#define pb       push_back
#define popb     pop_back()
#define mk       make_pair
#define stc      set<char>
#define st       set<int>
#define stk      stack<int>
#define ctn      continue
#define MOD      1000000007
#define fr(i,a,b)   for(int i=a;i<b;i++)
#define rfr(i,a,b)  for(int i=a-1;i>=b;i--)
#define must        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int lcm(int a, int b)
 {
    return (a*b)/gcd(a, b);
 }

int myfun(int x,int y)
{
    return x*y;
}
void primeFactors(int n)
{
    while (n%2 == 0)
    {
        cout<<2<<endl;
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            cout<<i<<endl;
            n = n/i;
        }
    }
    if (n > 2)
        cout<<n<<endl;
}

void fillPrefixSum(int arr[], int N, int prefixSum[])
{
    prefixSum[0] = arr[0];

    for (int i = 1; i < N; i++)
        prefixSum[i] = prefixSum[i-1] + arr[i];
}

int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

int power(int x,  int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;
    }
    return res;
}




void solve()
{
    string s;
    cin>>s;
    vtr v;
    int n=s.length();
    int cnt=0;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') cnt++;
        else mx=max(mx,cnt),cnt=0;
    }
    //v.pb(cnt);
    mx=max(mx,cnt);
    //sort(v.begin(),v.end(),greater<int>());
    cout<<mx<<endl;

}



signed main()
{
	must;
    int tt=1;
    //cin >> tt;
	while(tt--)solve();
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++ i) {
        cin >> a[i];
    }
    int ans = n - accumulate(a.begin(), a.end(), 0);
    cout << (ans >= 0 ? ans : -1) << endl;
}


Measured memory_bytes: 3636
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		int a = Integer.parseInt(s.next());
		int b = Integer.parseInt(s.next());
		int c = Integer.parseInt(s.next());
		int count=0;
		for(int i = a ; i <= b ; i++){
			if(c%i==0)count++;
		}
		System.out.println(count);
	}
}
			
			

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

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

  string l = "", r = "";
  int cnt = 0;
  rep(i, N) {
    if (S[i] == '(')
      ++cnt;
    else
      --cnt;
    if (cnt < 0)
      l.push_back('('), ++cnt;
  }
  r = string(cnt, ')');

  cout << l + S + r << endl;
}

Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
ans_ac = 0
ans_wa = 0

ac = Array.new(10**5, false)
wa = Array.new(10**5, 0)

m.times do |i|
  item = gets.chomp.split
  number = item[0].to_i
  next if ac[number]
  if item[1] == 'WA'
    wa[number] += 1
  else
    ans_ac += 1
    ac[number] = true
  end
end
  
ac.each_with_index {|v, i|
  if v
    ans_wa += wa[i]
  end
}

puts "#{ans_ac} #{ans_wa}"

Measured memory_bytes: 5372
N = int(input())
a = list(map(int,input().split()))
#xor_a = [bin(x) for x in a]
#print(xor_a)
x = 0
for i in a:
    x ^= i
b = [x^y for y in a]
print(' '.join(map(str, b))) #' 'joinにより空白を間にいれる。mapにより文字列に直す
#atcoderではforを使った普通の縦の並びでもいいらしい

Measured memory_bytes: 41804
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    int x=x2-x1,y=y2-y1;
    cout<<x2-y<<" "<<y2+x<<" "<<x1-y<<" "<<y1+x<<endl;
}

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

using namespace std;
using ll = long long;
ll a[85];
int main() {
#ifdef LOCAL
    freopen("in3.txt", "r", stdin);
    freopen("out3.txt", "w", stdout);
#endif
ll n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
ll m = 1000;
for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]>0 ) m+=m/a[i]*(a[i+1]-a[i]);
}
cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3516
#include <stdio.h>
int main(){
  int n,a,b,i,j,tmp1,tmp2,count=0;
  scanf("%d %d %d",&n,&a,&b);
  
  for(i=1;i<=n;i++){
    tmp1=0;
    tmp2=i;
    for(j=0;j<5;j++){
      tmp1+=(tmp2%10);
      tmp2/=10;
    }
    
    if(a<=tmp1 && tmp1<=b)count+=i;
  }
  printf("%d",count);
}

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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

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

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	ll n;
	cin >> n;
	string s[2];
	cin >> s[0] >> s[1];
	ll cnt = 1;
	if (s[0][0] == s[1][0]) {
		cnt *= 3;
	}
	else {
		cnt *= 6;
	}
	for(int i=1;i<n;i++) {
		if (s[0][i] == s[0][i - 1])continue;
		if (s[0][i] == s[1][i]) {
			if (s[0][i - 1] == s[1][i - 1]) {
				cnt *= 2;
				cnt %= MOD;
			}
		}
		else {
			if (s[0][i - 1] == s[1][i - 1]) {
				cnt *= 2;
				cnt %= MOD;
			}
			else {
				cnt *= 3;
				cnt %= MOD;
			}

		}
	}
	cout << cnt;
	return 0;
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  
  long int ans=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
div = 10**9+7
A = [0 for i in range(N+1)]
A[0] = 1
for i in range(M):
    A[int(input())] = -1
for i in range(N):
    if A[i] == -1:
        continue
    now = A[i]
    if A[i+1] != -1:
        A[i+1] += now * 1
    if i < N-1 and A[i+2] != -1:
        A[i+2] += now * 1
# print(A)
print(A[-1] % div)


Measured memory_bytes: 465304
#include<iostream>
#include<stack>
#include<algorithm>

using namespace std;
typedef long long ll;

int main()
{
    int a,b,c,x,y;
    int min;
    scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
    if(x<y){
        if((a+b)<2*c){
            min+=(a+b)*x;
        }else{
            min+=(2*c)*x;
        }
        if(b<2*c)
            min+=b*(y-x);
        else
            min+=(2*c)*(y-x);
    }else{
        if((a+b)<2*c){
            min+=(a+b)*y;
        }else{
            min+=(2*c)*y;
        }
        if(a<2*c)
            min+=a*(x-y);
        else
            min+=(2*c)*(x-y);
    }
    printf("%d",min);
    return 0;
}



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

using namespace std;

const int Z = 1e9+7;

int main() {
    string l;
    cin >> l;

    int pow3[l.length()];
    pow3[0] = 1;
    for (int i = 1; i < l.length(); i++) {
        pow3[i] = 1ll * pow3[i-1] * 3 % Z;
    }

    int p2 = 1;
    int ans = 0;
    for (int i = 0; i < l.length(); i++) {
        if (l[i] == '1') {
            ans = (ans + 1ll * p2 * pow3[l.length()-1-i]) % Z;
            p2 = p2 * 2 % Z;
        }
    }
    ans = (ans + p2) % Z;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main(){
  int n;
  int a[200000];
  int max,i,j,min;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  max=a[1]-a[0];
  min=a[0];
  for(i=1; i<n; i++){
    if(min>a[i]) min=a[i];
    else{
      a[i]-=min;
      if(a[i]>max) max=a[i];
    }
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2564
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt(), m = sc.nextInt();
        boolean[] rec = new boolean[10];
        for(int i=0;i<m;i++) {
            int a= sc.nextInt();
            rec[a] = true;
        }
        HashSet<Integer> dic = new HashSet<>();
        for(int i=1;i<10;i++){
            if(rec[i]) dic.add(i);
        }
        if(rec[5]){
            dic.remove(2);
            dic.remove(3);
        }
        if(rec[3]) dic.remove(2);
        if(rec[7]||rec[1]){
            dic.remove(6);
            dic.remove(9);
        }
        if(rec[1]) dic.remove(4);
        if(rec[9]) dic.remove(6);
        int[] cost = new int[]{0,2,5,5,4,5,6,3,7,6};
        int[] val = new int[]{0,0,1,7,4,5,6,8};
        ArrayList<Integer> digit= new ArrayList<>();
        for(int w:dic) digit.add(w);
        Collections.sort(digit);
        int[] len = new int[10000+10];
        Arrays.fill(len,-10);
        HashMap<Integer,Integer>[] pair = new HashMap[10000+10];
        for(int i=0;i<len.length;i++) pair[i] = new HashMap<>();
        for(int w:digit){
            pair[cost[w]].put(w,1);
            len[cost[w]] = 1;
        }
        for(int i=1;i<=n;i++){
            for(int w:digit){
                int from = i-cost[w];
                if(from<0||len[from]+1<len[i]) continue;
                boolean flag = false;
                if(len[from]+1>len[i]){
                    flag = true;
                }
                for(int j=digit.size()-1;j>=0;j--){
                    int cur = digit.get(j);
                    int change = pair[from].getOrDefault(cur,0)+(cur==w?1:0);
                    int now = pair[i].getOrDefault(cur,0);
                    if(change>now){
                        flag = true;
                        break;
                    }
                }
                if(flag){
                    len[i] = len[from]+1;
                    pair[i] = new HashMap<>();
                    for(int e:pair[from].keySet()) pair[i].put(e,pair[from].get(e));
                    pair[i].put(w,pair[i].getOrDefault(w,0)+1);
                }
            }
        }
        ArrayList<Integer> res = new ArrayList<>();
        for(int w:pair[n].keySet()){
            int time = pair[n].get(w);
            for(int i=0;i<time;i++)  res.add(w);
        }
        Collections.sort(res);
        for(int i=res.size()-1;i>=0;i--) System.out.print(res.get(i));
    }
}


Measured memory_bytes: 32848
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	vector<int> num;
	vector<string> word;
	string code;
	vector<string>::iterator place;
	int he;
	while(cin>>code){
		word.push_back(code);
		for(place=word.begin();*place!=word.back();++place);
		if(place==word.end()-1)num.push_back(1);
		else{
			he=place-word.begin();
			word.pop_back();
			++*(num.begin()+he);
		}
	}
	he=*(max_element(num.begin(),num.end()));
	int i;
	for(i=0;num[i]!=he;++i);
	cout<<word[i]<<' ';
	int siz=1;
	for(i=0;word.begin()+i!=word.end();++i){
		if(word[i].size()>siz)siz=word[i].size();
	}
	for(i=0;word[i].size()!=siz;++i);
	cout<<word[i]<<endl;
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>

using namespace std;

int main() {
    int x, y;
    cin >> x;
    cin >> y;

    int flg = false;
    for(int a = 0; a <= x; a++) {
        int b = x - a;
        int legs = 2 * a + 4 * b;
        if(y == legs) {
            flg = true;
            break;
        }
    }
    if(flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
	int k,x;
	std::cin >> k>>x;
	for (int i = max(x-k+1,-1000000); i <= min(x+k-1,1000000)-1; i++) {
		/* code */
		std::cout << i<<' ';
	}
	std::cout << min(x+k-1,1000000) << std::endl;
}

Measured memory_bytes: 256
N = int(input())

def prime_cnt(N):
    # 約数列挙(1,N)も含まれる
    prime, i = set([2]), 1
    while i * i <= N:
        if N % i == 0:
            prime.add(i)
            prime.add(N//i)
        i += 1
    prime.remove(1)
    return prime
import math
ans = 0
ans = prime_cnt(N-1)
p = prime_cnt(N)
for i in p:
    n = N
    while n % i == 0:
        n /= i
    if (n-1) % i == 0:
        ans.add(i)
#print(sorted(list(ans)))
print(len(ans))


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

ll memo[100000000];

ll fib(ll x){

  if(memo[x]>0)return memo[x];
  if(x==0)return 2;
  else if(x==1)return 1;

  return memo[x]=fib(x-1)+fib(x-2);
}

int main(){

  int n;cin>>n;

  out(fib(n));

  return 0;
}


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

int main (){
    long long N, M, K;
    cin >> N >> M >> K;
    int ans = 0;

    vector<long long> A(N+1,0);
    vector<long long> B(M+1,0);

    for (long long i = 1; i <= N; i++)
    {
        cin >> A.at(i);
        A.at(i) += A.at(i - 1);
        //A.at(i) = K - A.at(i);
    }
    for (long long i = 1; i <= M; i++)
    {
        cin >> B.at(i);
        B.at(i) += B.at(i - 1);
        //B.at(i) = K - B.at(i);
    }
    int a = N, b = 0;

    while(true) {

        if(A.at(a) + B.at(b) <= K) {
            ans = max(ans,a + b);
            b++;
        } else {
            a--;
        }
        if(b > M || a < 0) {
            break;
        }
    }

    

    //cout << "###" << endl;
    /*for(int i = N; i >= 0; i--) {
        for(int j = M; j > ans - i && j >= 0; j--) {
            if(A.at(i) + B.at(j) <= K) {
                ans = max(ans,i+j);
                //cout << i << ',' << j << endl;
                break;
            }
        }
    }
    */

    cout << ans << endl;
    return 0;




    //long long a = 0;
    //long long b = 0;
    long long left = K;
    bool aout = 0;
    bool bout = 0;
    for (long long i = 0; 0/*i < N+M*/; i++)
    {
        if (B.at(b) > A.at(a))
        {
          //  cout << 1 << endl;
            left -= A.at(a);
            if (left <0)
            {
                break;
            }
            
            a++;
            if (a == N)
            {
                aout = 1;
                break;
            }
            
        }else
        {
          //  cout << 2 << endl;
            left -= B.at(b);
            if (left < 0)
            {
                break;
                /* code */
            }
            
            b++;
            if (b == N)
            {
                bout = 1;
                break;
            }
            
        }
        
        
    }
    int bb = b;
    int aa = a;
    if (0/*aout*/)
    {
        for (long long i = 0; i < M-bb; i++)
        {
           // cout << 3 << ' ' << B.at(b) << endl;
            left -= B.at(b);
            if (left < 0)
            {
                break; 
            }
          //  cout << 324786278378 << endl;
            b++;
            
            
        }
        
        /* code */
    }
    if (0/*bout*/)
    {
        for (long long i = 0; i < N-aa; i++)
        {
         //   cout << 4  << endl;
            left -= A.at(a);
            if (left < 0)
            {
                break; 
            }
            a++;

            
        }
        
        /* code */
    }
    
    //cout << a + b << endl;
    return 0;
    

    
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

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

  vector<pair<int,int>> dist(N, make_pair(-1,0));
  deque<int> que;

  dist[0].first= 0;
  que.push_back(0);

  while(!que.empty()){
    int v = que.front();
    que.pop_front();

    for(int nv:G[v]){
      if(dist[nv].first!=-1)
        continue;

      dist[nv].first = dist[v].first + 1;
      dist[nv].second = v;
      que.push_back(nv);
    }
  }

  for (int i = 0; i < N;i++){
    if(dist[i].first==-1){
      cout << i << endl;
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << dist[i].second + 1 << endl;
  }

    return 0;
}


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

int main()
{
  int n, m;
  
  while (cin >> n >> m, n || m){
    int maxn = n + m;
    char s = 'A', store = s;
    for (int i = 1; i < 5; i++){
      cin >> n >> m;
      int sum = n + m;
      if (maxn < sum){
        maxn = sum;
        store = s + i;
      }
    }
    cout << store << ' ' << maxn << endl;
  }
 
  return (0);
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>   
#define ll long long int  
#define mkp make_pair 
#define mod 1000000007 
#define maxn 100001 
#define ff first
#define ss second
using namespace std;     
int dp[maxn][6]; 
int arr[maxn]; 

int main(){    
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);    
  string s; 
  cin>>s;  
  int res=0,ans=0;
  for(int i=0;i<s.size();++i){ 
     ans=0; 
     if(s[i]=='R'){++ans;
      while(s[++i]=='R')++ans; }
    res=max(res,ans); 
  } 
    cout<<res<<"\n";
return 0;  
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,x,y,z,fa[N],sum[N];
int Read()
{
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int Get(int x)
{
	if(fa[x]==x) return x;
	int f=fa[x];
	fa[x]=Get(f);
	sum[x]+=sum[f];
	return fa[x];
}
void merge(int a,int b,int c)
{
	int f1=Get(a),f2=Get(b);
	fa[f1]=f2;
	sum[f1]=-sum[a]+sum[b]+c;
}
int main()
{
//	freopen("line.in","r",stdin);
	//freopen("line.out","w",stdout);
	n=Read(),m=Read();
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		x=Read(),y=Read(),z=Read();
		int f1=Get(x),f2=Get(y);
		if(f1==f2)
		{
			if(sum[x]-sum[y]!=z)
			{
				cout<<"No";
				return 0;
			}
		}
		else
		merge(x,y,z);
	}	
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 4400
n=int(raw_input())
g=[[1000000]*n for _ in xrange(n)]
for i in xrange(n):
    g[i][i]=0
for i in xrange(n):
    r=map(int,raw_input().split())
    for j in r[2:]:
        g[r[0]-1][j-1]=1
for k in xrange(n):
    for i in xrange(n):
        for j in xrange(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])
m=int(raw_input())
for i in xrange(m):
    s,d,v=map(int,raw_input().split())
    s-=1
    d-=1
    if g[s][d]<v:
        print(g[s][d]+1)
    else:
        print('NA')

Measured memory_bytes: 6456
import sys
input = sys.stdin.readline

from collections import defaultdict

def prime_factors(d,N): #素因数 1を含まないことに注意
    ret = []
    middle = int( N**(1/2))
    tmp = N
    for i in range(2, middle+1):
        if tmp%i == 0:
            c = 0
            while tmp%i == 0:
                tmp //= i
                c += 1
            if d[i] < c:
                d[i] = c
    if tmp != 1:
        if d[tmp] == 0:
            d[tmp] = 1

Q = 10**9+7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    d = defaultdict( int)
    for a in A:
        prime_factors(d, a)
    s = 1

    for key, value in d.items():
        s *= pow( key, value)
    ans = 0
    for a in A:
        ans += s*pow(a,Q-2,Q)
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

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

void dfs(string name, map<string, set<string>> &mp, set<string> &res,
         map<string, int> &used) {
    if (used[name] != 0) return;
    used[name] = 1;
    int f = 0;
    for (auto e : mp) {
        if (e.first == name) f = 1;
    }
    if (!f) {
        res.insert(name);
        return;
    }
    for (auto e : mp[name]) {
        dfs(e, mp, res, used);
    }
}

int main() {
    int h;
    while (cin >> h, h) {
        string s[h];
        for (int i = 0; i < h; i++) cin >> s[i];
        map<string, set<string>> mp;
        string ans = "";
        vector<string> op;
        for (int i = h - 1; i >= 0; i--) {
            int j = 0;
            string t = "";
            while (s[i][j] != ':') t += s[i][j++];
            if (i == 0) ans = t;
            op.push_back(t);
            j++;
            string name = "";
            while (s[i][j]) {
                if (s[i][j] == ',' || s[i][j] == '.') {
                    mp[t].insert(name);
                    name = "";
                } else {
                    name += s[i][j];
                }
                j++;
            }
        }
        map<string, int> used;
        set<string> res;
        dfs(ans, mp, res, used);
        cout << res.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3368
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define bs binary_search
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ipr pair<ll,ll>
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n],s=0;
	for(i=0;i<n;i++){
		cin>>ar[i];
		s+=ar[i];
	}
	
	k=(n*(n+1))/2;
	if(s%k==0){
		int f=1;
		k=(s/k);
		for(i=1;i<n;i++){
			l=(ar[i]-ar[i-1])-k;
			if(l>0) {
				f=0;
				break;
			}
			if(l<0) l=-l;
			if(l%n!=0){
				//cout<<"@";
				f=0;
				break;
			}
		}
		l=ar[0]-ar[n-1]-k;
		if(l>0) {
			f=0;
		}
		if(l<0) l=-l;
		if(l%n!=0){
			//cout<<"$";
			f=0;
		}
		if(f==1){
			cout<<"YES";
		}
		else {
			cout<<"NO";
		}
	}
	else {
		cout<<"NO";
	}
	return 0;
}


Measured memory_bytes: 1024
N = int(input())
S = input()
_S = S
while '()' in S:
    for i in range(len(S)-1):
        if S[i] =='(' and S[i+1] == ')':
            S = S[:i] + S[i+2:]
            break
c1 = S.count(')')
c2 = S.count('(')
print('(' * c1 + _S + ')' * c2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n, m;
const LL INF = 1000000000000000000LL;
const int N = 500000;
int ai[N];
LL ans = INF;
struct node
{
    LL p, k, b;
} S[N];
LL K, B;
int tot;
int comp(node a, node b)
{
    return a.p < b.p;
}
int main()
{
    cin >> n>> m;
    for (int i = 1; i <= n; ++ i) cin >> ai[i];
    for (int i = 1; i < n; ++ i)
    {
        int a = ai[i], b = ai[i + 1];
        if (a < b)
        {
            B += b - a;
            S[++ tot] = (node){a + 1, -1, 1 + a};
            S[++ tot] = (node){b + 1, 1, -a - 1};
        }
        else
        {
            K --;
            B += b + 1;
            S[++ tot] = (node){b + 1, 1, (m - a + b) - (b + 1)};
            S[++ tot] = (node){a + 1, -1, 1 + a};
        }
    }
    sort(S + 1, S + tot + 1, comp);
    for (int i = 1, j = 1; i <= m; ++ i)
    {
        while (j <= tot && S[j].p <= i)
        {
            K += S[j].k;
            B += S[j].b;
            j ++;
        }
        // cerr << K * i + B << endl;
        ans = min(ans, K * i + B);
    }
    cout << ans;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<char, int> m1;
    vector<int> b;
    for(int i = 1; i < n; i++){
        int num = 0;
        string s1 = s.substr(0, i);
        string s2 = s.substr(i,n-i);
        rep(j,s1.size()){
            m1[s1[j]] = 1;
        }
        rep(j,s2.size()){
            if(m1[s2[j]] == 1){
                num++;
                m1[s2[j]]++;
            }
        }
        b.pb(num);
        m1.clear();
    }
    sort_2(b);
    cout << b[0] << endl;
    return 0;
}

Measured memory_bytes: 256
N = input()
n=int(N)
if n<10:
    print(n)
elif n<100:
    print(9)
elif n<1000:
    print(n-90)
elif n<10000:
    print(909)
elif n<100000:
    print(909+n-9999)
else:
    print(90909)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()

int main()
{
    int N;
    ll Y;
    cin >> N >> Y;
    
    FOR(i, 0, N+1) {
        FOR(j, 0, N+1) {
            int k = N - i - j;
            if (0 <= k && k <= N && 10000*i +5000*j + 1000*(N-i-j) == Y) {
                cout << i <<  " " << j << " " << k;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}

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

int main(){
    ll n, m; cin >> n >> m;
    ll sum = 0;
    vector<ll> x(n); 
    rep(i,n){
        cin >> x[i];
        sum += x[i];
    }

    m -= sum;

    sort(all(x));

    cout << n + m/x[0] << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int best = 0;
  int n, X;
  cin >> n >> X;
  vector<int> x(n + 1, X);
  vector<int> d(n);
  for(int i = 0; i < n; i++)
  {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  for(int i = 0; i < n; i++)
  {
    d[i] = x[i + 1] - x[i];
  }
  for(int i = 1; i < n; i++)
  {
    d[0] = gcd(d[0], d[i]);
  }
  cout << d[0];

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N, M,ans;
	ans = 0;
	cin >> N;
	vstr s(N);
	for (int i = 0; i < N; i++)cin >> s[i];
	cin>>M;
	vstr t(M);
	for (int i = 0; i < M; i++)cin >> t[i];
	map<string, int> mp;
	for (int i = 0; i < N; i++) {
		mp[s[i]] = 0;
		for (int j = 0; j < N; j++) if (s[i] == s[j])mp[s[i]]++;
		for (int j = 0; j < M; j++)if (s[i] == t[j])mp[s[i]]--;
		ans = max(ans, mp[s[i]]);
	}
	cout << ans << endl;
}

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

int main(){
  int N,p[10];
  cin >> N;
  for(int i=0;i<N;i++)
    cin >> p[i];
  int max=p[1],sum=0;
  for(int i=0;i<N;i++){
  if(max<p[i])max=p[i];
  sum+=p[i];
  }
  cout << sum-max/2 << endl;
  return 0;
}

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

int m_dis(int, int, int, int);

int main(void){
    int n, m;
    vector <int> a, b, c, d;
    int i, j;
    int x;
    
    cin >> n >> m;
    
    for(i = 0; i < n; i++){
        cin >> x;
        a.push_back(x);
        cin >> x;
        b.push_back(x);
    }
    
    for(i = 0; i < m; i++){
        cin >> x;
        c.push_back(x);
        cin >> x;
        d.push_back(x);
    }
    
    for(i = 0; i < n; i++){
        int ans = INT_MAX;
        int dis;
        int check_point;
        
        for(j = 0; j < m; j++){
            dis = m_dis(a[i], c[j], b[i], d[j]);
            if(dis < ans){
                ans = min(ans, m_dis(a[i], c[j], b[i], d[j]));
                check_point = j + 1;
            }
        }
        cout << check_point << endl;
    }
    
    return 0;
}

int m_dis(int x1, int x2, int y1, int y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

Measured memory_bytes: 256
#include <iostream>
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;

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

	int charge = 1000 - (N % 1000);
	if (charge == 1000)
		charge = 0;
	std::cout << charge;
	
	return 0;
}

	


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
  while(N>0){
    ll tmp=N%10;
    N/=10;
    if(tmp==7){
      cout<<YES<<endl;
      return;
    }
  }
  cout<<NO<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int MOD = 1000000007;
int main(){
	long long int N,K,A,M,pI,mI,ans=1;
	vector<long long int> p,m;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>A;
		if(A<0)m.push_back(-A);
		else p.push_back(A);
	}
	sort(p.begin(),p.end());
	sort(m.begin(),m.end());
	if(p.size()==0 && K%2){
		for(int i=0;i<K;i++)ans=((-ans*m[i])%MOD+MOD)%MOD;
	}else{
		pI=p.size()-1;
		mI=m.size()-1;
		if(K%2){
			ans=p[pI]%MOD;
			pI--;K--;
		}
		for(int i=0;i<K/2;i++){
			if(mI-1<0 && pI-1<0){M=-p[0]*m[0]%MOD;}
			else if(mI-1<0){M=p[pI]*p[pI-1]%MOD;pI-=2;}
			else if(pI-1<0){M=m[mI]*m[mI-1]%MOD;mI-=2;}
			else if(p[pI]*p[pI-1]>=m[mI]*m[mI-1]){M=p[pI]*p[pI-1]%MOD;pI-=2;}
			else {M=m[mI]*m[mI-1]%MOD;mI-=2;}
			ans=(ans*M%MOD+MOD)%MOD;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int N;
    cin >> N;
    //mapで/と\を数え上げ
    unordered_map<int, int> A, B;
    int key;
    REP(i, N)
    {
        cin >> key;
        if (i % 2 == 0)
            A[key]++;
        else
            B[key]++;
    }

    //valueを"変える個数"に変換
    for (auto it = A.begin(); it != A.end(); ++it)
        it->second = N / 2 + N % 2 - it->second;
    for (auto it = B.begin(); it != B.end(); ++it)
        it->second = N / 2 - it->second;

    //Aについて、変える個数が一番少ないものと二番目に少ないものを調べる
    //secondの初期値は下の感じにしておくと数字が一種類のケースの処理が後で楽になる。
    //もっと簡単にソートできるのでは???
    pii fA, sA;
    fA.second = N / 2 + N % 2;
    sA.second = N / 2 + N % 2;
    int value;
    for (auto it = A.begin(); it != A.end(); it++)
    {
        value = it->second;
        if (value < fA.second)
        {
            sA = fA;
            fA.first = it->first;
            fA.second = value;
        }
        else if (value < sA.second)
        {
            sA.first = it->first;
            sA.second = value;
        }
    }

    //Bについて
    pii fB, sB;
    fB.second = N / 2;
    sB.second = N / 2;
    for (auto it = B.begin(); it != B.end(); it++)
    {
        value = it->second;
        if (value < fB.second)
        {
            sB = fB;
            fB.first = it->first;
            fB.second = value;
        }
        else if (value < sB.second)
        {
            sB.first = it->first;
            sB.second = value;
        }
    }

    //同じ数字じゃなきゃ最小の和、同じなら2組試して小さいほう
    if (fA.first != fB.first)
        cout << fA.second + fB.second << endl;
    else
        cout << min(fA.second + sB.second, sA.second + fB.second);

    //system("pause");
}

Measured memory_bytes: 4376
#include <iostream>
#include <vector>

using namespace std;

bool check(vector<int>& v){
    int n = v[v.size()-1];
    for(int i = 0; i < v.size()-1; i++){
        if(v[i] == n) return true;
    }
    return false;
}

int main(){
    int s;
    cin >> s;
    vector<int> v = {s};
    int i = 0;
    for(; !check(v); i++){
        if(s%2){
            s = s*3+1;
        }else{
            
            s = s/2;
        }
        v.push_back(s);
    }
    //for(int i : v)cout << i << endl;
    cout << i+1 << endl;
}

Measured memory_bytes: 256