akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == -1)
            return 0;

        double x = 1.0;
        double y = 0.0;
        while(--n > 0){
            double len = sqrt(x*x + y*y);
            double dx = -y / len;
            double dy = x / len;
            x += dx;
            y += dy;
        }

        printf("%.10f\n%.10f\n", x, y);
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  long long cnt = 0;
  for(i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(i=0;i<n;i++){
    if(a[i]>100000){                                                                      cnt++;
      a[i]=0;
    }
  }
  vector<int> b(100001,0);
  for(i=0;i<n;i++) b[a[i]]++;
  for(i=1;i<=100000;i++){
    if(b[i]>i) cnt += b[i]-i;
    else if(b[i]<i) cnt += b[i];
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 4020
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    t = [[]]
    for _ in range(n):
        ret = []
        for _ in range(gete(int)):
            ret.append(tuple(geta(int)))
        t.append(ret)

    ans = 0
    for c in range(2**n):
        l = [0] * (n + 1)

        cur = 1
        tmp = c
        while tmp > 0:
            if tmp & 1 == 1:
                l[cur] = 1
            cur += 1
            tmp = tmp >> 1

        ok = True
        for i, h in enumerate(l):
            if h == 1:
                for tj in t[i]:
                    if tj[1] != l[tj[0]]:
                        ok = False
                        break
            if not ok:
                break

        if ok:
            ans = max(ans, sum(l))

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 42348
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    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);
}
void  solve(){
  int h,w;
  cin>>h>>w;
  char x[h][w];
  rep(i,0,h){
    rep(j,0,w){
      cin>>x[i][j];
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      int flag=0;
      if(x[i][j]=='#'){
        if(i>0) flag+= x[i-1][j]==x[i][j]?1:0;
        if(i<h-1) flag+= x[i+1][j]==x[i][j]?1:0;
        if(j>0) flag+= x[i][j-1]==x[i][j]?1:0;
        if(j<w-1) flag+= x[i][j+1]==x[i][j]?1:0;
        if(flag==0){
          cout<<"No\n";
          return;
        }
      }

    }
  }
  cout<<"Yes\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3620
//This solution is not worked out by myself.
#include<cstdio>
long long str[205][2];
long long n,noww=100;
void solve(long long num)
{
	if(num<=1) return ;
	if(num%2) str[++str[0][0]][0]=noww--,solve(num-1);
	else str[++str[0][1]][1]=noww--,solve(num/2);
}
int main ()
{
	scanf("%lld",&n); solve(n+1);
	printf("%lld\n",2*(str[0][0]+str[0][1])); noww=100-str[0][0]-str[0][1]+1;
	for(int i=1;i<=str[0][0];i++) printf("%lld ",str[i][0]);
	for(int i=str[0][1];i;i--) printf("%lld ",str[i][1]);
	for(int i=noww;i<=100;i++) printf("%lld ",1ll*i);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	cin>>T;
	int a,b;
	cin>>a>>b;

	if(a%T==0)
	{
		if(((b/T) - (a/T) + 1) !=0)
		{
			cout<<"OK\n";
		}
		else
		{
			cout<<"NG\n";
		}
	}
	else
	{
		if(((b/T) - (a/T)) !=0)
		{
			cout<<"OK\n";
		}
		else
		{
			cout<<"NG\n";
		}
	}

	return 0;
}


Measured memory_bytes: 3608
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
ans=0
for i in range(h):
    ans+=input().count("#")
if ans==h+w-1:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 77372
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N), sum(N+1);
  rep(i, N) cin >> A[i];
  sort(all(A));
  int t = 0;
  rep(i, N) {
    sum[i+1] = sum[i] + A[i];
    if(i < N-1 && 2*sum[i+1] < A[i+1]) t = i+1;
  }
  cout << N-t << "\n";
  return 0;
}


Measured memory_bytes: 4740
#include <iostream>
using namespace std;
int main( void )
{
  int a,b,c,n=0,m=0;
  char s,t;
  while( 1 ){
    cin>>a>>s>>b>>t>>c;
    if( cin.eof() ) break;
    if( a*a+b*b == c*c ) n++;
    if( a == b ) m++;
  }
  cout << n << endl;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;


ll dp[4020][4020];
int main(){
	string s;
	cin>>s;
	int n=s.size();
	vector<int>red,blue;
	rep(i,n){
		if(s[i]=='0'){
			red.push_back(i);
			red.push_back(i);
		}
		if(s[i]=='1'){
			red.push_back(i);
			blue.push_back(i);
		}
		if(s[i]=='2'){
			blue.push_back(i);
			blue.push_back(i);
		}
	}
	dp[0][0]=1;
	int r=red.size(),b=blue.size();
	rep(i,r+1)rep(j,b+1){
		dp[i][j]%=mod;
		int m=i+j;
		if(j<b&&blue[j]<=m)dp[i][j+1]+=dp[i][j];
		if(i<r&&red[i]<=m)dp[i+1][j]+=dp[i][j];
	}
	cout<<dp[r][b]%mod<<endl;
	return 0;
}

Measured memory_bytes: 123520
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A[3];
	rep(i,3) scan(A[i]);
	int ans=0;
	while(ans<100000){
		if(A[0]%2||A[1]%2||A[2]%2){
			prin(ans);
			return 0;
		}
		else{
			int Atmp[3];
			rep(k,3){
				Atmp[k]=A[(k+1)%3]/2+A[(k+2)%3]/2;
			}
			rep(k,3) A[k]=Atmp[k];
		}
		ans++;
	}
	prin(-1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int i,j,k,m,n,ans,tot,mx,t;
struct point{
	int nam,pla,sum;
}p[N];
int ver[N],nxt[N],head[N],edge[N],v[N],d[N],s[N],x[N],y[N];
bool vis[N],used[N];
void add(int x,int y)
{
	ver[++tot]=y,nxt[tot]=head[x],head[x]=tot;
}
bool cmp(int a,int b){return a>b;}
void dfs(int x)
{
	vis[x]=1;
	s[x]=v[t];
	for(int i=head[x];i;i=nxt[i])
	{
		if(!vis[ver[i]]) t++,dfs(ver[i]);
	}
}
int main()
{
	scanf("%d",&n);
	tot=1;
	for(int i=1;i<=n;i++) p[i].nam=i;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		add(x[i],y[i]);
		add(y[i],x[i]);
		d[x[i]]++,d[y[i]]++;
	}
	mx=0;
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	for(int i=1;i<=n;i++) if(d[i]>mx) mx=d[i],j=i;
	sort(v+1,v+n+1,cmp);
	t=1;
	dfs(j);
	for(int i=1;i<n;i++)
	{
		ans+=min(s[x[i]],s[y[i]]);
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)
	{
		printf("%d ",s[i]);
	}
}

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

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	if(A+B == C+D){
  		cout << "Balanced" << endl;
    }else if( A+B < C+D){
      cout << "Right" << endl;
	}else{
      cout << "Left" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
 
int main(){
  int N, M;
  cin >> N >> M;
 
  vi penalty(100010, 0);
  vector<bool> ac(100010, false);
 
  int p; string S;
  for(int i=0; i<M; i++){
    cin >> p >> S;
    if(!ac[p-1]){
      if(S == "WA") penalty[p-1]++;
      if(S == "AC") ac[p-1] = true;
    }
  }
 
  int right = 0, pen = 0;
  for(int i=0; i<N; i++){
    if(ac[i]) pen += penalty[i];
    if(ac[i]) right++;
  }
 
  cout << right << " " << pen << endl; 
}

Measured memory_bytes: 640
#include <stdio.h>

int N;
char S[200000];

int main(void) {
	int i;
	int tomori_nao = 0;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%199999s", S) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (i > 0 && S[i - 1] == 'x' && S[i] == 'x') break;
		tomori_nao++;
	}
	printf("%d\n", tomori_nao);
	return 0;
}



Measured memory_bytes: 2140
#include <cstdlib>
#include <cstdio>

int main(void) {
  int N, a, b;
  scanf("%d%d%d", &N, &a, &b);
  if (abs(b - a) % 2 == 0)
    printf("Alice\n");
  else
    printf("Borys\n");
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

ll rui[101000]={};

int main(){
   int n,k; scanf("%d%d",&n,&k);
   vector<ll> a(n); rep(i,0,n)scanf("%lld",&a[i]);
   rep(i,0,n)rui[i+1]=rui[i]+a[i];
   vector<ll> lb(n+1,0LL),rb(n+1,0LL);
   rep(i,0,n)lb[i+1]=lb[i]+max(0LL,a[i]);
   rrep(i,n,0)rb[i-1]=rb[i]+max(0LL,a[i-1]);
   ll res=0;
   rep(i,0,n-k+1){
      ll sub=max(0LL,rui[i+k]-rui[i])+lb[i]+rb[i+k];
      chmax(res,sub);
   } printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


int n, m;
char s[10005];
int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%s", s);
  n = strlen(s);
  bool flag = true;

  int m = n / 2;
  for(int i = 0; i < m; i++) {
    if(s[i] != s[n - i - 1]) {
      flag = false;
    }
  }
  for(int i = 0; i < m / 2; i++) {
    if(s[i] != s[m - i - 1]) {
      flag = false;
    }
  }

  if(flag) puts("Yes");
  else puts("No");
  
  return 0;
}


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

dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
  a, b, c = map(int, input().split())
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
  dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c
  
print(max(dp[N]))

Measured memory_bytes: 22772
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> L(N);
    range(i, 0, N) cin >> L.at(i);
    sort(L.begin(), L.end());
    lint ans = 0;
    range(i, 0, N - 1) range(j, i + 1, N) {
        lint ub = distance(L.begin(), lower_bound(L.begin(), L.end(), L.at(i) + L.at(j))) - 1;
        ans += ub - j;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    s1 = input()
    s2 = input()
    if s1[0] == s2[0]:
        ans = 3
        pre = 0
        i = 1
    else:
        ans = 6
        pre = 1
        i = 2
    while i < n:
        if s1[i] == s2[i]:
            if pre == 0:
                ans *= 2
            pre = 0
            i += 1
        else:
            if pre == 0:
                ans *= 2
            else:
                ans *= 3
            pre = 1
            i += 2
        ans %= md
    print(ans)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digisum(int n){int s=0;while(n!=0){s+=n%10;n/=10;}return s;}  //  桁和
int stpow(int n){if(n==0)return 1;int a=1;rep(i,1,n+1)a=a*i%MOD;return a;}
Vi stpowV(){Vi a(100001);a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
vector<int> divisor(int n){  //  約数列挙 O(√n)
Vi r;for(int i=1;i*i<=n;i++){if(n%i==0){r.pb(i);if(i*i!=n)r.pb(n/i);}}sort(ALL(r));
return r;}
vector<pair<int,int>> fac(int n) {  //  素因数分解
vector<Pii>r;for(int i=2;i*i<=n;++i){if(n%i)continue;r.emplace_back(i,0);while(n%i==0){
n/=i;r.back().second++;}}if(n!=1)r.emplace_back(n,1);return r;}
bool prime(int n){  //  素数判定
if(n<2)return false;else if(n==2)return true;else if(n%2==0)return false;
double s=sqrt(n);for(int i=3;i<=s;i+=2){if(n%i==0){return false;}}return true;}
Vi primevec(){  //  素数配列
int N=1000000;int l[N];Vi a(0);for(int i=0;i<N;i++){l[i]=1;}for(int i=2;i<sqrt(N);i++){
if(l[i]){for(int j=0;i*(j+2)<N;j++){l[i*(j+2)]=0;}}}for(int i=2;i<N;i++){if(l[i]){
a.pb(i);}}return a;}
int comb(int n, int r){  //  nCr (MOD環境下)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  Vi a(n);
  Vin(a);
  
  int ans = 0;
  
  rep(i,0,n){
    rep(j,1+i,n){
      ans += a[i]*a[j];
    }
  }
  cout<<ans<<endl;
  
  return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    if(n % 2) {
        cout << 0 << endl;
    } else {
        ll ans = 0;
        n /= 2;
        while(n != 0) {
            n /= 5;
            ans += n;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n, m, X, Y = gets.chomp.split.map(&:to_i)
x = gets.chomp.split.map(&:to_i)
y = gets.chomp.split.map(&:to_i)

x << X
y << Y


if x.max < y.min
  puts 'No War'
else
  puts 'War'
end

Measured memory_bytes: 1916
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>

using namespace std;
#define rep(i, n) for(i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x)*(x)
typedef long long ll;

void solve() {
    int r;
    cin >> r;
    cout << r*2*3.14;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), B(n);
  rep(i, n) cin >> A[i] >> B[i];
  sort(all(A));
  sort(all(B));
  auto median = [&](vector<ll>& v) {
    if(n%2) return v[(n-1)/2];
    else    return v[n/2-1]+v[n/2];
  };
  cout << median(B)-median(A)+1 << "\n";
  return 0;
}


Measured memory_bytes: 6364
//https://atcoder.jp/contests/abc134/tasks/abc134_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll r;
	cin>>r;
	ll area;
	area=3*r*r;
	cout<<area<<"\n";
	
	return 0;
}

Measured memory_bytes: 3664
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>
#include<stack>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

llong eval(char *s){
    llong total;
    total = strtol(s, &s, 10);
    while(*s){
        if(*s=='+'){
            s++;
            total = total + strtol(s, &s, 10);
            continue;
        }
        if(*s=='-'){
            s++;
            total = total - strtol(s, &s, 10);
            continue;
        }
    }
    return total;
}

int main(){
    string S;
    cin >> S;
    llong N=S.size()-1;    
    llong total = 0;
    string s;
    for(int i=0; i<pow(2, N); i++){
        string temp;
        for(int j=0; j<N; j++){
            if((i>>j)&1){
                temp.push_back('+');
                continue;
            }
            temp.push_back('-');
        }
        s = "";
        for(int i=0; i<N; i++){
            s = s + S[i] + temp[i];
        }
        s = s + S[S.size()-1];
        if(eval((char*)s.c_str())==7){
            cout << s << "=7" << endl;
            exit(0);
        };
    }
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

// iと (xi + yi)の偶数奇数が合っている
// i <= (xi + yi)である

int main() {
    int N;
    cin >> N;
    int t[N], x[N], y[N];
    t[0]=x[0]=y[0]=0;
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool flag = true;
    for (int i = 1; i <= N; ++i) {
        int step = t[i] - t[i-1];
        int prog = abs((x[i] + y[i]) - (x[i-1] + y[i-1]));

        if(step < prog) {
            flag = false;
            break;
        }
        else {
            if(step%2 == prog%2) {}
            else {
                flag = false;
                break;                
            }
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int diff = 0;
  for(int i = 0; i < N; i++) {
    cin >> p[i];
    if(p[i] != i + 1) diff++;
  }
  if(diff <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main()
{
  vector<vector<int>> C(3, vector<int>(3));
  vector<vector<int>> S(3, vector<int>(2)), T(3, vector<int>(2));
  bool B=0;
  rep(i, 3){
    rep(j, 3){
      cin >> C[i][j];
      if(j>0) S[i][j-1]=C[i][j]-C[i][j-1];
      if(i>0) T[i-1][j]=C[i][j]-C[i-1][j];
    }
  }
  rep(i, 2){
    rep(j, 2){
      if(S[i][j]!=S[i+1][j]){
        B=1;
        break;
      }
      if(T[i][j]!=T[i][j+1]){
        B=1;
        break;
      }
    }
    if(B==1) break;
  }
  if(B==1) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N, K; cin >> N >> K;
    double ans = 0;
    for(int i=1; i<=N; i++){
        ll x = i;
        int cnt = 0;
        while(x<K){
            x *= 2;
            cnt++;
        }
        
        ans += pow(0.5, cnt);
    }
    
    cout << fixed << setprecision(20) << ans / N << endl;
    
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    string S;
    cin >> S;
    vector<bool> a(26, true);
    rep(i, S.size()) {
        a[S[i] - 'a'] = false;
    }
    rep(i, 26) {
        if (a[i]) {
            cout << (char) (i + 'a') << "\n";
            return 0;
        }
    }
    cout << "None\n";
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int value = 100000;
        int n = new Scanner(System.in).nextInt();
        for(int i = 0;i < n;i++){
            value *= 1.05;
            if(value % 1000 != 0) value = value / 1000 * 1000 + 1000;
        }
        System.out.println(value);
    }
}

Measured memory_bytes: 25912
#include <bits/stdc++.h>
using namespace std;
int a,b,t1,t2,t3;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b;
    t1=a-b;
    t2=a+b;
    t3=a*b;
    t1=max(t1,t2);
    t1=max(t1,t3);
    cout<<t1;
    return 0;
}


Measured memory_bytes: 256
using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] sentence = new string[3];
            sentence = Console.ReadLine().Split(' ');

            int fiveSentence = 0;
            int sevenSentence = 0;

            int a = int.Parse(sentence[0]);
            int b = int.Parse(sentence[1]);
            int c = int.Parse(sentence[2]);

            if(a == 5)
            {
                fiveSentence++;
            }
            else if(a == 7)
            {
                sevenSentence++;
            }

            if (b == 5)
            {
                fiveSentence++;
            }
            else if (b == 7)
            {
                sevenSentence++;
            }

            if (c == 5)
            {
                fiveSentence++;
            }
            else if (c == 7)
            {
                sevenSentence++;
            }

            if(fiveSentence == 2 && sevenSentence == 1)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }

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

/*
index=0を白として、そこからDFSしていき距離が偶数なら同じ色、距離が奇数なら違う色を割り当てていく。
dfsにはtreeとどの色を割り当てたかを記録していく必要がある。
あと、どこを訪れたか、これは割り当てた色を使えば大丈夫そう。未：-1, 白: 0, 黒: 1 みたいに
*/
void dfs(vector<vector<pair<int, int>>> &tree, vector<int> &colors, int index) {
    for (auto node : tree[index]) {
        if (colors[node.first] != -1) continue;
        int weight = node.second;
        colors[node.first] = (weight % 2 == 0) ? colors[index] : colors[index] ^ 1;
        dfs(tree, colors, node.first);
    }
}

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

    vector<vector<pair<int, int>>> tree(n);
    for(int i = 0; i < n - 1; i++) {
        int v1, v2, w;
        cin >> v1 >> v2 >> w;
        v1--; v2--;
        tree[v1].emplace_back(v2, w);
        tree[v2].emplace_back(v1, w);
    }

    vector<int> colors(n, -1);
    colors[0] = 0;
    dfs(tree, colors, 0);

    for(int i = 0; i < n; i++) {
        cout << colors[i] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

int main(){
    string s;
    cin>>s;
    ll cnt=0,ans=0,l=s.length();
    rep(i,l-1){
        while(s[i]=='B'&&s[i+1]=='C'){
            ans+=cnt;
            i+=2;
        }
        if(s[i]=='B'&&s[i+1]=='C')i--;
        if(s[i]=='A')cnt++;
        else cnt=0;
    }
    //cout<<s<<endl;
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3748
n, a, b, c, d = map(int,input().split())

y = 0
for i in range(n):
    j = n-1-i
    if i*d-j*c >= a-b >= i*c-j*d:
        y = 1
if y == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 40560
n, k = map(int, input().split())
x = list(map(int, input().split()))

cand = []

# 全探索
for i in range(n - k + 1):
    cand.append(min(abs(x[i]), abs(x[i + k - 1])) + abs(x[i + k - 1] - x[i]))

print(min(cand))

Measured memory_bytes: 14224
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<limits>
using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//grobal変数


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a % 2 != 0 && b % 2 != 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	if (n<1200){
		cout<<"ABC";
	}
	else if (n<2800){
		cout<<"ARC";
	}
	else {
		cout<<"AGC";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long
#define maxx 405
#define inf 1e15+7
ll sum(ll a[],ll i,ll j)
{
    ll s=0;
    for(ll k=i;k<=j;k++)
        s+=a[k];
    return s;
}
ll f(ll a[],ll n,ll dp[][maxx],ll i,ll j)
{
    if(i>=j)
        return 0;
    if(dp[i][j]!=0)
        return dp[i][j];
    dp[i][j]=inf;
    for(ll k=i;k<=j;k++)
    {
        dp[i][j]=min(dp[i][j],f(a,n,dp,i,k)+f(a,n,dp,k+1,j)+sum(a,i,k)+sum(a,k+1,j));
    }
    return dp[i][j];
}
int main()
{
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll dp[maxx][maxx]={0};
    cout<<f(a,n,dp,0,n-1);
}


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

signed main(void)
{
	int n, k;
	cin >> n >> k;
	int a[n];
	int lo, hi, mid, cnt;
	hi = 0;
	rep(i, n) 
	{
		cin >> a[i];
		hi = max(hi, a[i]);
	}
	lo = 0;
	hi += 1;
	while (hi - lo > 1)
	{
		mid = (hi + lo) / 2;
		cnt = 0;
		rep(i, n)
			cnt += (a[i] + mid - 1) / mid - 1;
		if (cnt > k)
			lo = mid;
		else
			hi = mid;
	}
	cout << hi << endl;
	return 0;
}


Measured memory_bytes: 4328
li = []
for i in range(102):
    li.append(i)
lis = set(li)
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
lia = list(map(int,input().split()))
lias = set(lia)
seta = lis - lias
li = list(seta)
li.reverse()
a = 1000
for i in range(102-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

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

int main(){
	int n,m;
	cin >> n >> m;
  	pair<long long,long long> d[n];
	long long cnt = 0;
	long long sum = 0;
	for(int i=0; i<n;++i){
		cin >> d[i].first;
		cin >> d[i].second;
	}
	sort(d,d+n);
	int i = 0;
	while(cnt != m){
		if(d[i].second > 0){
			sum += d[i].first;
			d[i].second --;
			cnt ++;
		}else{
			i++;
		}
	}

	cout << sum << endl;
 
}

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

int main()
{
    int a, b, x;

	cin >> a >> b >> x;

	if (a <= x && x <= (a + b))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N):
    mod = 10 ** 9 + 7
    memo = [{} for _ in range(N + 1)]

    def check(last4):
        for i in range(4):
            x = list(last4)
            if i > 0:
                x[i], x[i - 1] = x[i - 1], x[i]
            if ''.join(x).count('AGC') >= 1:
                return False
        return True

    def dfs(memo, digit, last3):
        # last3文字 + digit文字 で条件を満たす個数を再帰取得する
        if last3 in memo[digit]:
            return memo[digit][last3]  # 計算済みの場合はそれを使用
        if digit == 0:
            return 1  # +0文字なのであればパターンは1のみ
        re = 0
        for c in 'AGCT':
            if check(last3 + c):
                re = (re + dfs(memo, digit - 1, last3[1:] + c)) % mod
        memo[digit][last3] = re
        return re

    print(dfs(memo, N, 'TTT'))  # 最初の3文字は入れ替えてAGCになりうる4文字に干渉しないものにする


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


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

int main(){
	string s,t;
	cin >> s >> t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end());
	reverse(t.begin(),t.end());
	if(s<t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,k,i,j,a[100001],x,max;
	while(scanf("%d %d",&n,&k),n!=0 && k!=0){
		max=0;
		for(i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=0;i<=n-k;i++){
			x=0;
			for(j=i;j<i+k;j++)x+=a[j];
			if(max<x)max=x;
		}
		printf("%d\n",max);
	}
	return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
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; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        if ((i+1) % 2 == 1 && a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
import java.util.*;
    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();
        int d = sc.nextInt();

        while(true){
            c = c - b;
            if(c<=0){
                System.out.println("Yes");
                return;
            }
            a = a - d;
            if(a<=0){
                System.out.println("No");
                return;
            }
        }
    }
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> odd(n/2),even(n/2);
    for(int i=0; i<n/2; i++){
        cin >> odd[i];
        cin >> even[i];
    }
    int ans=0,count=1;
    sort(odd.begin(),odd.end());
    sort(even.begin(),even.end());
    int oddflag=0,evenflag=0;
    int oddmax=0,oddsec=0,evenmax=0,evensec=0;
    int oddmaxnum=0,evenmaxnum=0;
    oddmaxnum=odd[0],evenmaxnum=even[0];
    for(int i=1; i<n/2; i++){
        if(odd[i]==odd[i-1])count++;
        else {
            if(count>oddmax){
               oddsec=oddmax;
               oddmax=count;
              oddmaxnum=odd[i-1];
            }
            else if(count>oddsec)oddsec=count;
            oddflag=1,count=1;
        }
    }if(count>oddmax){
            oddsec=oddmax;
            oddmax=count;
            oddmaxnum=odd[n/2-1];
        }
        else if(count>oddsec)oddsec=count;
    if(!oddflag)oddmax=n/2;
    count=1;
    for(int i=1; i<n/2; i++){
        if(even[i]==even[i-1])count++;
        else {
        if(count>evenmax){
            evensec=evenmax;
            evenmax=count;
            evenmaxnum=even[i-1];
        }
        else if(count>evensec)evensec=count;
        evenflag=1,count=1;
        }
    }if(count>evenmax){
            evensec=evenmax;
            evenmax=count;
            evenmaxnum=even[n/2-1];
        }
        else if(count>evensec)evensec=count;
    if(!evenflag)evenmax=n/2;
    if(oddmaxnum!=evenmaxnum)ans=n-(oddmax+evenmax);
    else ans=n-max(oddmax+evensec,oddsec+evenmax);
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int n;
  int x;
  int t;
  cin >> n >> x >> t;
  int ans = 0;
  if (n <= x)
    ans = t;
  else if (n % x == 0)
    ans = (n / x) * t;
  else
    ans = (n / x + 1) * t;

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


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll n,sum1=0,sum2=0;
    cin>>n;
    vector<ll>a(n),b(n);
    for(ll i=0;i<n;i++)cin>>a[i],sum1+=a[i];
    for(ll i=0;i<n;i++)cin>>b[i],sum2+=b[i];
    if(sum1<sum2)cout<<-1<<endl;
    else{
        ll rest=sum1-sum2;
        ll ans=0;
        vector<ll>div;
        for(ll i=0;i<n;i++){
            if(a[i]==b[i]){
                ans++;
                continue;
            }
            if(a[i]<b[i])continue;
            ll d=a[i]-b[i];
            div.push_back(d);
        }
        sort(div.begin(),div.end());
        for(ll i=0;i<(ll)div.size();i++){
            if(rest>=div[i]){
                rest-=div[i];
                ans++;
            }
        }
        cout<<n-ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 2428
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<complex>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<cstring>
#include<cassert>
using namespace std;
  
#define REP(i,x,n) for(int i = x ; i < (int)(n) ; i++)
#define rep(i,n) REP(i, 0, n)
#define f first
#define s second
#define mp make_pair
#define pb push_back
  
typedef pair<int,int> P;
typedef long long ll;
typedef complex<double> Point;
  
static const int INF = (1<<29);
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
  
struct Circle{
  Point p;
  int r,color;
  Circle(){}
  Circle(Point p, int r, int c):p(p),r(r),color(c){}
};
  
int n;
int ans;
bool del[24];
Circle circle[24];
bool visit[(1 << 24)];
 
bool check(int i, int j){
  return abs(circle[i].p - circle[j].p) < (double)(circle[i].r + circle[j].r);
}
  
void dfs(int count, int select){
  if(visit[select]) return;
  visit[select] = true;
  ans = max(ans,count);
  bool overlap;
    
  for(int i = 0 ; i < n ; i++){
    if(del[i]) continue;
    for(int j = i + 1 ; j < n ; j++){
      if(del[j]) continue;
        
      if(circle[i].color != circle[j].color) continue;
  
      overlap = false;
      for(int k = i - 1 ; k >= 0 ; k--){
        if(del[k]) continue;
        if(check(i,k)){
          overlap = true;
          break;
        }
      }
      if(overlap) continue;
  
      overlap = false;
      for(int k = j - 1 ; k >= 0 ; k--){
        if(del[k]) continue;
        if(check(j,k)){
          overlap = true;
          break;
        }
      }
      if(overlap) continue;
        
      del[i] = del[j] = true;
      int tmp = select;
      tmp |= (1 << i);
      tmp |= (1 << j);
      dfs(count + 2, tmp);
      del[i] = del[j] = false;
    }
  }
}
  
int main(){
  while(cin >> n && n){
    rep(i,n){
      int x,y,r,c;
      cin >> x >> y >> r >> c;
      circle[i] = Circle(Point(x,y),r,c);
    }
    ans = 0;
    memset(visit,false,sizeof(visit));
    memset(del,false,sizeof(del));
    dfs(0,0);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 19540
#include <stdio.h>

int main(void)
{
    int timeCount, count, minPrice, difference, priceOnTime;
    int benefit = -999999999;
    char tempString[12];
    fgets(tempString,sizeof(tempString),stdin);
    sscanf(tempString,"%d",&timeCount);

    fgets(tempString,sizeof(tempString),stdin);
    sscanf(tempString,"%d",&priceOnTime);
    minPrice = priceOnTime;

    for (count = 0; count < timeCount - 1; count++) {
      fgets(tempString,sizeof(tempString),stdin);
      sscanf(tempString,"%d",&priceOnTime);
      difference = priceOnTime - minPrice;
      if (benefit < difference) {
          benefit = difference;
      }

      if(priceOnTime < minPrice) {
          minPrice = priceOnTime;
      }
    }

    printf("%d\n",benefit);

    return 0;
}


Measured memory_bytes: 2140
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		int [] v = new int[n]; //宝石の価値
		int [] c = new int[n]; //宝石のコスト
		
		for(int i = 0; i < n; i++) {
			v[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n; i++) {			
			c[i] = stdIn.nextInt();
		}

		int max = Integer.MIN_VALUE;
		
		for(int bit = 0; bit < (1 << n); bit++) {
			int sum = 0;
			
			for(int i = 0; i < n; i++) {
				if(((bit >> i) & 1) ==1) {
					sum+= v[i]-c[i];
				}
			}
			
			max = Math.max(sum, max);
			
		}
		
		System.out.println(max);
		
	}

}


Measured memory_bytes: 23892
import heapq as hp
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

q = []
for a in A:
    hp.heappush(q, -a)

for i in range(M):
    #print(q)
    b = hp.heappop(q)

    c = b//2
    if b % 2 != 0:
        c += 1
    hp.heappush(q, c)

ans = 0
for a in q:
    ans += -a
print(ans)

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int A, B;
    cin >> A >> B;

    int ans = 0;
    REV(i, 40, 1) {
        int a = A % (1LL << i);
        int b = B % (1LL << i);

        int half = 1LL << (i - 1LL);

        int num = 0;
        if (A / (1LL << i) != B / (1LL << i)) {
            if (b >= half) num += b - half + 1;
            num += (1LL << i) - max(a, half);
        } else {
            if (b >= half) {
                num = b - max(a, half) + 1;
            }
        }
        if (i == 1) {
            int a2 = A / 2;
            int b2 = B / 2;
            if (b2 > a2) {
                num += b2 - a2 - 1;
            }
        }
        if (num % 2 == 1) ans += 1LL << (i - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256