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

using namespace std;

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

const int N = int(1e5 + 10);
pii p[N];
multiset< int > st;

int main(){
	int n;

	scanf("%d", &n);

	for(int i = 1 ; i <= n ; i++){
		scanf("%d", &p[i].first);
		p[i].second = i;
	}

	sort(p + 1, p + 1 + n, greater< pii >());

	st.insert(-1);
	st.insert(n + 1);
	st.insert(0);
	st.insert(n + 2);

	st.insert(p[1].second);

	ll sum = 0LL;

	for(int i = 2 ; i <= n ; i++){
		int idx = p[i].second;
		// printf("%d\n", p[i].first);

		st.insert(idx);

		auto e = st.find(idx);
		auto pv = prev(e);
		auto pvv = prev(pv);

		auto nxt = next(e);
		auto nnxt = next(nxt);

		ll r_ = ll(idx - *pvv);
		ll l_ = ll(idx - *pv);
		ll r = ll(*nnxt - idx);
		ll l = ll(*nxt - idx);

		// printf("%lld %lld | %lld %lld\n", l_, r_, l, r);
		ll add = 0LL;

		if(*nxt != n + 1){
			// printf("++\n");
			add += ((*nnxt - *nxt) * (l_));
		}

		if(*pv != 0){
			add += ((*pv - *pvv) * (l));
		}
		// printf("adding %lld\n", add);

		sum += ll(p[i].first) * add;
	}

	printf("%lld\n", sum);

	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int rinsetu[10];
int x[10];
int y[10];
int n;

double f(int xi, int yi) {
    double x2 = (x[xi] - x[yi]) * (x[xi] - x[yi]);
    double y2 = (y[xi] - y[yi]) * (y[xi] - y[yi]);
    return sqrt(x2 + y2);
}

double length(double len, int town) {
    int i = 0;
    double ans = 0;
    for (i=0; i<n; i++) {
        if (rinsetu[i] == 0) {
            rinsetu[i] = 1;
            ans += length(len + f(town, i), i);
            rinsetu[i] = 0;
        };
    }
    return ans==0 ? len : ans;
}

int nn(int a) {
    int res = 1;
    for (int i=a; i>=1; i--) {
        res *= i;
    }
    return res;
}

int main() {
    cin >> n;
    REP(i, n) {
        cin >> x[i] >> y[i];
    }
    double l[n];
    for (int i=0; i<n; i++) {
        rinsetu[i] = 1;
        l[i] = length(0, i);
        rinsetu[i] = 0;
    }
    double ans = 0;
    double n2 = nn(n);
    for (int i=0; i<n; i++) {
        ans += l[i]/n2;
    }
    printf("%.16lf\n", ans);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main()
{
  int x,y;
  int crane, turtle;

  cin >> x >> y;
  // crane+turtle==x, crane*2+turtle*4=y
  // y - x*2 == 3*turtle
  turtle = (y-x*2)/2;
  crane = x - turtle;
//printf("turtle = %d crane = %d\n", turtle, crane);
  if (crane+turtle == x && crane*2+turtle*4 == y && turtle >= 0 && crane >=0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 3468
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	
	int ans=0;
	for(int i=1;i<n;i++){
		int cnt=0;
		
		for(char c='a';c<='z';c++){
			bool left=false,right=false;
			
			for(int j=0;j<i;j++)
				if(s[j]==c)
					left=true;
			
			for(int j=i;j<n;j++)
				if(s[j]==c)
					right=true;
			
			if(left&&right)
				cnt++;
		}
		
		if(ans<cnt)
			ans=cnt;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a;
    for(int i = 1; i * i <= n; i++){
        a.push_back(i);
        if(i * i != n)a.push_back(n / i);
    }
    sort(a.begin(), a.end());
    int m = a.size();
    vector<int> w(m);
    rep(i, m){
        if(i == 0)w[i] = 1;
        else w[i] = a[i] - a[i-1];
    }

    vector<vector<ll>> dp(k, vector<ll>(m, 0));
    ll mod = 1000000007;
    rep(i, m)dp[0][i] = w[i];
    for(int i = 1; i < m; i++)(dp[0][i] += dp[0][i-1]) %= mod;;
    for(int i = 1; i < k; i++){
        rep(j, m){
            dp[i][j] = dp[i-1][m-j-1];
        }
        rep(j, m)(dp[i][j] *= w[j]) %= mod;
        for(int j = 1; j < m; j++)(dp[i][j] += dp[i][j-1]) %= mod;
    }
    cout << dp[k-1][m-1] << endl;
}

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


int main(){
  int n,m;

  int ans = 0;
  cin >> n >> m;

  vector<int> p(n,0);

  int max_l = 0 , min_r = 10000000;

  int l,r;
  for(int i = 0; i < m; ++i){
    cin >> l >> r;
    if(r < min_r)min_r = r;
    if(l > max_l)max_l = l;
  }
  if((min_r - max_l) < 0) cout << 0 << endl;
  else cout << 1 + min_r - max_l << endl;
}







Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp0[100005]={0};
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
const ll g2=pow(2,mod-2);
struct segtree{
private:
  vector<ll> node,lazy;
  ll siz;
public:
  segtree(int n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2,0);
    lazy.resize(siz*2,0);
  }
  void eval(ll pos){
    node[pos]+=lazy[pos];
    node[pos]%=mod;
    if(pos<siz-1) {
      lazy[pos*2+1]+=lazy[pos]/2;
      lazy[pos*2+2]+=lazy[pos]/2;
    //  lazy[pos*2+1]%=mod;
    //  lazy[pos*2+2]%=mod;
    }
    lazy[pos]=0;
  }
  void add_q(ll a,ll b,ll x,ll l,ll r,ll pos){
    eval(pos);
    if(b<=l||r<=a) return;
    if(a<=l&&r<=b){
      lazy[pos]+=(x*(r-l));
      eval(pos);
      return;
    }
    ll mid=(l+r)/2;
    add_q(a,b,x,l,mid,pos*2+1);
    add_q(a,b,x,mid,r,pos*2+2);
    node[pos]=(node[pos*2+1]+node[pos*2+2])%mod;
  }
  ll sum_q(ll a,ll b,ll l,ll r,ll pos){
    if(b<=l||r<=a) return 0;
    eval(pos);
    if(a<=l&&r<=b){
      return node[pos]%mod;
    }
    ll mid=(l+r)/2;
    return (sum_q(a,b,l,mid,pos*2+1)+sum_q(a,b,mid,r,pos*2+2))%mod;
  }
  void add(ll a,ll b,ll x){
    add_q(max((ll)0,a),min(b,siz),x,0,siz,0);
  }
  ll sum(ll a,ll b){
    return sum_q(max((ll)0,a),min(b,siz),0,siz,0);
  }
  void debug(){
    cout<<"Node:"<<endl;
    ll t=2;
    for(int i=2;i<=siz*2;i++) {
      cout<<node[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
    cout<<"Lazy:"<<endl;
    t=2;
    for(int i=2;i<=siz*2;i++){
      cout<<lazy[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
  }
};
int main(){
  ll n,m;
  cin>>n>>m;
  segtree dp1=segtree(n+3);
  dp0[0]=1;
  for(int i=0;i<n;i++){
    dp1.add(i+1,min(n+1,i+m),dp0[i]);
    dp0[i+1]=dp0[i]+dp1.sum(i,i+1);
    dp0[i+1]%=mod;
  }
/*  for(int i=0;i<=n;i++) cout<<dp0[i]<<" ";
  cout<<endl;
  for(int i=0;i<=n;i++) cout<<dp1.sum(i,i+1)<<" ";
  cout<<endl;*/
  ll ans=pow(2,n);
  //cout<<ans<<endl;
  ans-=(dp0[n]+dp1.sum(n,n+1));
  if(ans<0){
    ll t=(0-ans)/mod;
    ans+=(t+1)*mod;
  }
  cout<<ans%mod<<endl;
}



Measured memory_bytes: 7860
using System;
using System.Linq;
using System.Collections.Generic;

public class BinarySearch{
public static void Main()
{
	int.Parse(Console.ReadLine());
	var sList = Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	int.Parse(Console.ReadLine());
	var tList = Console.ReadLine().Split().Select (c => int.Parse(c)).ToList();
	
	int count = 0;
	
	tList.ForEach(t =>
	{
		if(sList.BinarySearch(t) > -1) count++;
	});
	
	Console.WriteLine(count);
}
}

Measured memory_bytes: 18392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

lf cal(ll x){
    ll t = x;
    ll cnt = 0;
    while (x) {
        cnt += x%10;
        x /= 10;
    }
    return (lf)t/(lf)cnt;
}
int main(){
    IOS();
    ll k;
    cin >> k;
    ll cur = 0, tmp = 1;
    REP (i,k) {
        ll ta = cur + tmp;
        ll tb = cur + 10*tmp;
        if (cal(ta)<=cal(tb)) cur = ta;
        else {
            cur = tb;
            tmp *= 10;
        }
        cout << cur << endl;
    }
}


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

int main()
{
        ll N; cin >> N;
        vector<ll> a(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> a[i];
        }
        ll pos = 0;
        ll ans = 0;
        for (int i = 0; i < N; ++i) {

                if (a[pos] == 2) {
                        cout << i+1 << endl;
                        exit(0);
                }

                pos = a[pos] - 1;



        }
        cout << -1 << endl;


}


Measured memory_bytes: 1024
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
typedef long long LL;
using namespace std;
const int SIZE=1001;
int r[2*SIZE],w[2*SIZE];
bool DP[2*SIZE][2*SIZE];
int N;
int leastSpace(int n,int maximN){
	DP[0][0]=true;
	if(maximN) DP[0][w[0]]=true;
	int maxim=0;
	FOR(i,1,N){
		FOR(j,0,n+1){
			if(maximN!=i && j>=w[i])
				DP[i][j]=DP[i-1][j]|DP[i-1][j-w[i]];
			else DP[i][j]=DP[i-1][j];
			if(DP[i][j]) maxim=max(maxim,j);
		}
	}
	return n-maxim;
}
int main() {
	
	
	while(cin >> N && N){
		REP(i,SIZE*2){
			r[i]=w[i]=0;
		}
		REP(i,SIZE)
			REP(j,SIZE)
				DP[i][j]=0;
		int sum=0,maxim=0,sumW=0,maximN=0;
		REP(i,N){
			cin >> r[i] >> w[i];
			sum+=r[i];
			maxim=max(maxim,r[i]);
			if(r[i]==maxim) maximN=i;
			sumW+=w[i];
		}
		if(maxim*2<=sum){
			cout << sum+sumW << endl;
			continue;
		}
		int space=maxim*2-sum;
		cout << sum+sumW+leastSpace(space,maximN) << endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3136
s = input()
n = len(s)
p = []
flag = False
for i in range(n-1):
    if flag:
        flag = False
        continue 
    if s[i] == "B" and s[i+1] == "C":
        flag = True
        p.append("#")
    elif s[i] == "A":
        p.append(s[i])
    else:
        p.append("!")

nowa = 0
ans = 0
for i in range(len(p)):
    if p[i] == "A":
        nowa += 1
    elif p[i] == "#":
        ans += nowa
    elif p[i] == "!":
        nowa = 0
print(ans)

Measured memory_bytes: 5096
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[]$) {
        Scanner sc = new Scanner(in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextLong();
        long ans=2*b;
        if(c-b>a){
            ans+=a+1;
        }else if(c-b==a){
            ans+=a;
        }else{
            ans+=c-b;
        }
        out.println(ans);
    }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans*x)%mod;
            }
            x=(x*x)%mod;
            n>>=1;
        }
        return ans;
    }
    //最大公約数
    static int gcd (int a,int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
    //※最小公倍数はa*b/gcd(a,b)である
    static class UF{
        static int size=51;
        static int[] par=new int[size];
        //初期化
        static void init(){
            for (int i = 1; i <size ; i++) {
                par[i]=i;
            }
        }
        //根をたどる
        static int root(int x){
            if(par[x]==x){
                return x;
            }else{
                return par[x]=root(par[x]);
            }
        }
        //同じ根をもつか(同じ集合に属するか)判定
        static boolean same(int x,int y){
            return root(x)==root(y);
        }
        //合体
        static void unite(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y)return;
            par[x]=y;
        }
    }
}

Measured memory_bytes: 23764
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
l = x[-1] - x[0]
y = []
for i in range(m-1):
  y.append(x[i+1]-x[i])
y.sort(reverse=True)
print(l-sum(y[:(n-1)]))

Measured memory_bytes: 13968
import math
width, height, xPosition, yPosition, radius = list(map(int, input().split(" ")))
horizontalMargin = radius * math.cos(math.radians(0))
verticalMargin = radius * math.sin(math.radians(90))
ANSWER_NO = "No"
ANSWER_YES = "Yes"
condition = False
if xPosition >= horizontalMargin and xPosition <= (width - horizontalMargin):
    if yPosition >= verticalMargin and yPosition <= (height - verticalMargin):
        condition = True

print(ANSWER_YES) if condition else print(ANSWER_NO)

Measured memory_bytes: 7872
#include <stdio.h>
 
 int main(){

  int val;
  int h,i,key,N;
  int count = 0;
  int A[100];

  scanf("%d",&val);
 
  for(i = 0;i < val;i++){
  scanf("%d",&A[i]);
  }

  for(h = 0;h < val;h++){
  for(i = val - 1 ;i > h;i--){
	  if(A[i] < A[i - 1]){
		  key = A[i - 1];
		  A[i - 1] = A[i];
		  A[i] = key;
        count++;
	  }
   }
  }
	 for(i = 0;i < val-1;i++)
   printf("%d ",A[i]);
   printf("%d\n",A[i]);
      printf("%d\n",count);
	 return 0;
  }
 

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod 998244353
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 1000005
 
 
// Driver code to test above functions
int32_t main()
{
  
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n, ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin >> x;
 
        ans += mp[i-x];
 
        mp[i+x]++;
    }
 
    cout << ans;
 
    return 0;
 
} 

Measured memory_bytes: 26308
def gcd(a,b):
	while b:
		a, b = b, a % b
	return a
n = input()
t = input()
list = []
for i in range(0,n-1):
	list.append(input())
list.sort()
for i in range(0,n-1):
	t = list[i] * t // gcd(list[i], t)
print t

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

using namespace std ;

const int MAX = 1e5 + 10 ;

int prime[MAX] , ans[MAX];

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	for(int i = 0 ; i < MAX ; ++i)
		prime[i] = 1 ; 
	prime[0] = prime[1] = 0 ;
	for(int i = 2 ; i <= MAX ; ++i)
	{
		if(prime[i])
			for(int j = i+i ; j <= MAX ; j += i)
				prime[j] = 0 ;
	}
	for(int i = 3 ; i < MAX ; ++i)
	{
		ans[i] = ans[i-1] + (bool)(prime[i] && prime[(i+1)/2]);
	}
	int q ;
	cin>>q ;
	while(q--)
	{
		int l , r ;
		cin>>l>>r ;
		cout<<ans[r] - ans[l-1]<<"\n";
	}
	return 0 ;
}

Measured memory_bytes: 1408
#include<iostream>
#include<set>
#include<queue>
using namespace std;

bool check(string a){
    char pivot = a[0];
    for(int i = 1; i < a.length(); i++) if(a[i] != pivot)   return false;
    return true;
}

char rgb[3] = {'r', 'g', 'b'};

int main(){
    string x;
    while(cin >> x){
        if(x == "0")    break;

        queue<pair<string,int>> q;
        set<string> s;

        q.push({x,0});

        int ans = -1;
        while(!q.empty()){
            pair<string,int> t = q.front(); q.pop();
            if(check(t.first)){
                ans = t.second;
                break;
            }
            
            if(s.find(t.first) != s.end())  continue;

            s.insert(t.first);
            for(int i = 0; i < t.first.length()-1; i++){
                if(t.first[i] == t.first[i+1])  continue;

                for(int j = 0; j < 3; j++){
                    if(t.first[i] != rgb[j] && t.first[i+1] != rgb[j]){
                        string copy = t.first;
                        copy.replace(i, 2, 2, rgb[j]);
                        if(s.find(copy) == s.end()) q.push({copy, t.second+1});
                    }
                }
            }
        }

        if(ans == -1)   cout << "NA" << endl;
        else            cout << ans << endl;
    }
    return 0;
}


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

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

typedef long long ll;

int main() {
    set<ll> a;
    
    vector<ll> b;
    b.push_back(3);
    b.push_back(5);
    b.push_back(7);
    
    int c[3];
    c[0]=3,c[1]=5,c[2]=7;
    
    ll tmp=0;
    ll m = b.size();
    
    while(tmp<999999999){
        m = b.size();
        rep(i,m){
            rep(j,3){
                tmp = b[i]*10 + c[j];
                b.push_back(tmp);
            }
        }
    }
    
    sort(b.begin(),b.end());
    ll n;cin>>n;
    
    m = b.size();
    
    int d[3];
    vector<ll> e;

    b.push_back(0);
    rep(i,m){
        rep(j,3) d[j]=0;
        if(b[i]!=b[i+1]){
        
        tmp = b[i];
        while(tmp>0){
          ll res = tmp%10;
            if(res == 3)++d[0];
            if(res == 5)++d[1];
            if(res == 7)++d[2];
          tmp/=10;
          if(tmp==0)break;
        }
//    cout<<b[i]<<" "<<d[0]<<" "<<d[1]<<" "<<d[2]<<endl;
        ll res2 = d[0]*d[1]*d[2];
        if(res2 != 0)e.push_back(b[i]);
        }
    }

   ll ans = 0;
    m = e.size();
    rep(i,m){
        if(e[i]<=n && e[i]!=e[i+1])++ans;
        if(e[i]>n)break;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10476
x, y = list(map(int, input().split()))
if y == 0:
    print(abs(x) + (x > 0))
elif x < y < 0:
    print(y - x)
elif 0 < y < x:
    print(x - y + 2)
else:
    print(abs(abs(y) - abs(x)) + (x < 0) + (y < 0))


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

n,k = map(int,input().split())
a = list(map(int,input().split()))

res = 1
cnt = k

if n <= cnt:
    print(res)
else:
    if (n-k)%(k-1) == 0:
        print(1 + (n-k)//(k-1))
    else:
        print(1 + (n-k)//(k-1)+1)

Measured memory_bytes: 14388
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            String s = sc.next(), ret = "";
            Set<Integer> set = new HashSet<>();
            
            for(int i=0; i<s.length(); i++){
            	set.add((int)(s.charAt(i)));
            }
            
            for(int i=97; i<=122; i++){
            	if(!set.contains(i)){
            		System.out.println(s + String.valueOf((char)i));
            		sc.close();
            		return;
            	}
            }
            
            for(int i=25; i>=0; i--){
            	set.remove((int)(s.charAt(i)));
            	for(int j=s.charAt(i)+1; j<=122; j++){
            		if(!set.contains(j)){
            			System.out.println(s.substring(0, i) + String.valueOf((char)j));
            			sc.close();
                        return;
            		}
            	}
            }
            
            //出力
            System.out.println(-1);
            sc.close();
        }
    }
	

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

template <typename T = int>
void primeFactors(T a, map<T, int> &facs) {
    double sqrtA = sqrt(a);
    for (int i = 2; i <= sqrtA + 1e-10; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
    return;
}

struct Combination {
    vector<ll> fac, finv, inv;

    Combination(ll maxN) {
        maxN += 100; // for safety
        fac.resize(maxN + 1);
        finv.resize(maxN + 1);
        inv.resize(maxN + 1);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (ll i = 2; i <= maxN; ++i) {
            fac[i]  = fac[i - 1] * i % MOD;
            inv[i]  = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    ll operator()(ll n, ll k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> facs;
    primeFactors(m, facs);
    Combination nCk(200000);
    ll ret = 1;
    for (auto &p : facs) {
        ret = (ret * nCk(n - 1 + p.second, p.second)) % MOD;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
 
#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)
 
 
 
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back
 
 
 
 
 
#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>
 
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>
 
#define pss pair<string,string>
#define pcc pair<char,char>
 
#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>
 
 
 
#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>
 
 
 
#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9
 
 
 
///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;
 
 
int power(int a,int b){
    int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}
 
 
int arr[g_size];
 
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
 
	int n,m,T,res;
 
	int maxi=-mx,mini=mx,count=0;
 
	int i,j,k;
 
	bool flag;
 
	string s1,s2;
 
	char s[100000];
 
	int ara[n_size],ara2[n_size];
 
	cin>>k;
 
	vi v;
 
	rf(i,32,1){
        int l=1;
        int r=10;
        while(r-l>1){
            int mid=(l+r)/2;
            int x=power(i,mid);
            if(x>k) r=mid;
            else{
                v.pb(x);
                l=mid;
            }
        }
	}
 
	auto z=max_element(v.bb,v.ee);
 
	cout<<*z<<endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define mod 1000000007

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

    VVI dp(n,VI(2));
    dp[0][0] = 1;
    dp[0][1] = n-1;

    ll s = n-1;
    REP(i,n-1){
        dp[i+1][0] = (dp[i][0] + dp[i][1]) % mod;
        dp[i+1][1] = s;
        if (i >= 1){
            s = (s + dp[i-1][0] + dp[i-1][1] - 1 + mod) % mod;
        } 
    }

    // REP(j,2){
    //     REP(i,n) cout << dp[i][j] << " ";
    //     cout << endl;
    // }

    ll ans = (dp[n-1][0] + dp[n-1][1]) % mod;
    FOR(i,1,n-2){
        ans = (ans + (n-1) * dp[i][1]) % mod;
    }
    ans = (ans + (n-1)*(n-1)) % mod;
    cout << ans << endl;

    return 0;
}

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

using namespace std;
int mod(int a)
{
    if(a>0)
    {
        return(a);
    }
    return(-1*a);
}
int min(int a , int b)
{
    if(a>b)
    {
    	//cout<<b<<"\t" ;
        return(b);
    }
    //cout<<a<<"\t" ;
    return(a);
}
int main()
{
    int a,b,c,i,j,n,m ;
    cin>>n ;
    vector<int>v,cost;
    for(i=0 ; i<n ;i=i+1)
    {
        cin>>a;
        v.push_back(a);
    }
    int arr[n] ;
    arr[1] = mod(v[1]-v[0]) ;
    arr[0] = 0 ;
    for(i=2 ; i<n ; i=i+1)
    {
    	b = arr[i-1]+ mod(v[i-1]-v[i]) ;
    	c = arr[i-2] + mod(v[i-2]-v[i]) ;
    	arr[i] = min(b,c) ;
	}
	cout<<arr[n-1] ;
}

Measured memory_bytes: 1144
#include <stdio.h>

int main(void)
{
    int n;
    int i,j,k,l;
    int ij,ijk;
    int C[50];
    int count;

    
    while(scanf("%d", &n) != EOF){
        count = 0;
        for (i = 0; i <= 9; i++){
            for (j = 0; j <= 9; j++){
                ij = i + j;
                for (k = 0; k <= 9; k++){
                    ijk = ij + k;
                    for (l = 0; l <= 9; l++){
                        if (ijk + l == n){
                            count++;
                        }
                    }
                    
                }
            }
        }
        printf("%d\n", count);      
    }

    return (0);
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a , b;
      cin >> a >> b;
     
      if (a % 2 == 0 || b % 2 == 0) {
        cout << "Even" << endl;
      }
      else {
        cout << "Odd" << endl;
      }
    }

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

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

    int ans = 0;
    vector<int> vec(N);

    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    ans = vec.at(N/2) - vec.at(N/2-1);
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
long long int t;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli x,k,i;
   cin>>x;
   k=360;
   lli n=x;
   while(n%2==0)
   {
       n=n/2;
       if(k%2==0)
       {
           k=k/2;
       }
   }
   for (i = 3;i<=n+1;i=i+2)
    {  while (n % i == 0)
        {   n = n/i;
            if(k%i==0)
            {
                k=k/i;
            }
        }
    }
   cout<<k<<"\n";
   return 0;
}//main


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

int isPrime(int x){
    int i;
    if (x<2)return false;
    else if(x ==2)return true;
    if (x %2 ==0)return false;
    for(i = 3; i*i<=x; i+=2){
        if(x%i == 0)return false;
    }
    return true;
}

int main(){
    int n, a, count;
    count = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(isPrime(a)) count++;
        
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3012
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  
int n;
int m;
int l;
int ans[m-n+1];
vector<int> v;
  
cin >> n >> m >> l;
  int tempn = n;
  
  int tempm = m;
 
for(int i = 0;i<l;i++){
  
  if(n > m){
    
    break;
  }
  
    v.push_back(n);
  //  ans[i] = n; 
    n=n+1;
 
}

for(int j = 0;j<l;j++){
  
  if(n > m){
    
    break;
  }
  
     v.push_back(m);
  
 //    ans[j+l] = m; 
     m = m-1;
    

}
  
int tmp = 0;

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

v.erase(std::unique(v.begin(), v.end()), v.end());
  
for(int k = 0;k<v.size();k++){
  
   // cout << ans[k] << endl;
     cout << v[k] << endl;
  
}
   //cout << n << endl;
   //cout << m << endl;
   //cout << l << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

const int MaxN = 300 + 5;

int N;
int A[MaxN], Cnt[4];
double f[MaxN][MaxN], g[MaxN][MaxN];
bool vis[MaxN][MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for (int i = 1; i <= N; ++i) Cnt[A[i]]++;
}

double dfs(int k, int i, int j) {
  if (vis[i][j] == true) return f[i][j];
  vis[i][j] = true;
  if (i == 0 && j == 0 && k == 0) return f[i][j] = 0;

  if (k != 0) f[i][j] += g[i][j + 1] * k / N;
  if (i != 0) f[i][j] += dfs(k, i - 1, j) * i / N;
  if (j != 0) f[i][j] += dfs(k, i + 1, j - 1) * j / N;
  f[i][j]++;
  f[i][j] /= 1.0 * (i + j + k) / N;
  return f[i][j];
}

void solve() {
  for (int k = 0; k <= Cnt[3]; ++k) {
    memset(vis, false, sizeof vis);
    memcpy(g, f, sizeof f);
    memset(f, 0, sizeof f);

    for (int i = 0; i <= N; ++i)
      for (int j = 0; j <= N; ++j)
        if (i + j + k <= N) dfs(k, i, j);
  }
  printf("%.10lf\n", f[Cnt[1]][Cnt[2]]);
}

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

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

long long int x,k,d,ans;


int main(){
    cin >> x >> k >> d;
    if(x <0){
        x = -x;
    }

    if(x >= 0 ){
        if(x/d > k){
            ans = x-k*d;
        }
        else{
            // cout << k-(x+d)/d << " "  << endl;
            if((k-(x+d)/d) % 2){
                // cout << x-(x+d)/d*d+d << " ooooo" << endl;
                ans = x-(x+d)/d*d+d;
            }
            else{
                // cout << x-(x+d)/d*d <<  "1111" << endl;
                ans = -1*(x-(x+d)/d*d);
            }
        }
    }
    // else{
    //     if(x+k*d < 0){
    //         ans = x+k*d;
    //     }
    //     else{

    //         if((k-(x-d)/d) % 2){
    //             ans = abs(x-(x+d)/d*d-d);
    //         }
    //         else{
    //             ans = abs(x-(x+d)/d*d);
    //         }
    //     }
    // }
    cout << ans << endl;

return 0;
}

Measured memory_bytes: 3644
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

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

const int INF32 = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);                
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int x; n--;) {
        cin >> x;
        ans += x >= k;
    }
    cout << ans;
    return false;                                                       
}

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

int Get_sum(int n){
	int sum = 0;
	while(n > 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main(){
	int N,A,B;
	int sum = 0;
	scanf("%d %d %d",&N,&A,&B);
	for(int i=1; i<=N; i++){
		if(Get_sum(i) >= A && Get_sum(i) <= B){
			sum += i;
		}
	}
	printf("%d\n",sum);

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
    char search[21], word[21];
    int count=0;
    int i;
    
    scanf("%s", search);
    while(1){
        scanf(" %s", word);
        if(strcmp(word, "END_OF_TEXT")==0)break;
        for(i=0;word[i]!='\0';i++){
            word[i]=tolower(word[i]);
        }
        if(strcmp(word, search)==0){
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}

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

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

using namespace std;

int main() {
  string N;
  cin >> N;
  for (int i = 0; i < N.size(); ++i) {
    if (N[i] == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println(n*n);
        sc.close();
    }
}

Measured memory_bytes: 23636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		call(n);
	}

	private static void call(long n) {
		StringBuilder sb = new StringBuilder();
		for(long i = 1;i <= n;i++){
			if(i % 3 == 0 || String.valueOf(i).indexOf("3") != -1){
				sb.append(String.format(" %d", i));
			}
		}
		System.out.println(sb.toString());
	}

}

Measured memory_bytes: 32756
from sys import stdin
di = {}
a = stdin.readline().strip()
l = len(a)
di = {}
for i in a:
    di[i] = di.get(i,0) + 1
i
total = (l * (l+1))/2
valid = 0

for i in xrange(l/2):
    if a[i]!=a[l-1-i]:
        valid = 1
        break

rem = 0

for kk in di:
    key = di[kk]
    rem += (key * (key+1))/2

print total - rem + 1

Measured memory_bytes: 3072
using System;

namespace _153232
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split();
            int a = int.Parse(AB[0]);
            int b = int.Parse(AB[1]);
            int[] ss = new int[] { a + b, a - b, a * b };
            int s;
            Array.Sort(ss);
            s = ss[2];
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 11220
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
MOD = 10**9 + 7

dp = [-1]*(2**N)
dp[0] = 1

# stateを二進数で表したときに、1である桁番号の女性がマッチングに参加
# 男性側は前から固定で女性と同じ人数だけ参加
def solve(state, c):
  global dp
  if dp[state] >= 0:
    return dp[state]
  else:
    dp[state] = 0 # 一旦、値を0に戻しておく
    for i in range(N):
      if state & (1<<i) and A[c-1][i]: 
        # i番目の女性がマッチングに参加しており、なおかつ
        # 最後の男性との相性が良い場合は、その2人でペアを作った場合の組合せを足し合わせる
        dp[state] += solve(state ^ (1<<i), c-1)
        dp[state] %= MOD
    
    return dp[state]

print(solve(2**N-1, N))

Measured memory_bytes: 62300
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,i;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      n=Integer.parseInt(token[0]);

      out.println((n-1)/2);

      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 23380
n = int(input())
cost = [0] * (n+1)
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
maxAns = 0
for i in range(n+1):
    cost[i] = abs(a[i+1] - a[i])
    maxAns += cost[i]

for i in range(1, n+1):
    ans = maxAns
    if (min(a[i-1], a[i], a[i+1]) == a[i] or max(a[i-1], a[i], a[i+1]) == a[i]):
        ans -= cost[i-1] + cost[i] - abs(cost[i-1] - cost[i])
    print(ans)



Measured memory_bytes: 14940
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    int res = 0;
    rep(i, N) {
        if(A[i] == B[i] && B[i] == C[i])
            continue;
        else if(A[i] != B[i] && B[i] != C[i] && A[i] != C[i]) {
            res += 2;
        } else {
            res += 1;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> cnt(m);
    REP(i, n){
        ll k;
        cin >> k;
        REP(j, k){
            ll a;
            cin >> a;
            cnt[a - 1]++;
        }
    }
    ll ans = 0;
    REP(i, m){
        if(cnt[i] == n) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int d1=a[2]-a[0];
    int d2=a[2]-a[1];
    if(d1%2==0&&d2%2==0)
    {
        cout<<(d1/2)+(d2/2)<<endl;
        return 0;
    }
    if(d1%2!=0&&d2%2!=0)
    {
        cout<<(d1/2)+(d2/2)+1<<endl;
        return 0;
    }
    if(d1%2==0)
    {
        d2++;
        cout<<(d1/2)+(d2/2)+1<<endl;
        return 0;
    }
    if(d2%2==0)
    {
        d1++;
        cout<<(d1/2)+(d2/2)+1<<endl;
    }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M, K;
	cin >> N >> M;
	vector<int64> cnt(M);
	REP(i, N) {
		cin >> K;
		REP(j, K){
			int32 A;
			cin >> A;
			cnt[A-1]++;
		}
	}
	int64 res = 0;
	REP(i, M){
		if (cnt[i] == N) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 256
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;
        long ans=0;

        String s[]=br.readLine().trim().split(" ");
        int H=Integer.parseInt(s[0]);
        int W=Integer.parseInt(s[1]);
        int K=Integer.parseInt(s[2]);

        char str[][]=new char[H][W];
        for(i=0;i<H;i++) str[i]=br.readLine().trim().toCharArray();

        N=1<<(H+W);

        int row[]=new int[H];
        int col[]=new int[W];

        for(i=0;i<N;i++)
        {
            Arrays.fill(row,0);
            Arrays.fill(col,0);

            int count=0,tmp=i;
            while (tmp>0&&count<H)
            {
                row[count++]=tmp&1;
                tmp>>=1;
            }

            count=0;
            while (tmp>0&&count<W)
            {
                col[count++]=tmp&1;
                tmp>>=1;
            }

            tmp=0;
            for(int x=0;x<H;x++)
            {
                for(int y=0;y<W;y++)
                {
                    if(row[x]==1||col[y]==1) continue;
                    if(str[x][y]=='#') tmp++;
                }
            }
            if(tmp==K) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 34152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int circle = sc.nextInt();
        int num = sc.nextInt();
        int[] house = new int[num];
        for (int i = 0; i < house.length; i++){
            house[i] = sc.nextInt();
        }
        int sabun = 0;
        for (int j = 0; j < house.length - 1; j++){
            int sabunCheck = Math.abs( house[j] - house[j + 1]);
            if (sabun < sabunCheck){
                sabun = sabunCheck;
            }
        }
        int sabuncheck2 = 0;
            sabuncheck2 = Math.abs(circle - house[house.length - 1] + house[0]);
        if (sabuncheck2 > sabun){
            System.out.println(circle - sabuncheck2);
        }else {
            System.out.println(circle - sabun);
        }

    }
}


Measured memory_bytes: 67060
<?php
list($n, $y) = ints();
for ($i = 0; $i <= $n; $i++) {
    if ($i * 10000 > $y) break;
    for ($j = 0; $j <= $n - $i; $j++) {
        if ($i * 10000 + $j * 5000 > $y) break;
        $k = $n - $i - $j;
        if ($k * 1000 === $y - ($i * 10000 + $j * 5000)) {
            echo "{$i} {$j} {$k}";
            exit;
        }
    }
}
echo '-1 -1 -1';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4728
#include<iostream>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;
void subBin(string str, int n)
{
    if (n == 0){
        bit.push_back(str);
    }
    if (n > 0) {
        subBin(str + "0", n - 1);
        subBin(str + "1", n - 1);
    }
}

int counting(int n){
    if(n == 1)return 1;
    else if(n == 0)return 0;

    return n%2 + counting(n/2);
}
int main(){
    int n;
    cin >> n;

    int f[n][10];
    int bf[n];

    rep(i, n){
        bf[i] = 0;
        rep(j, 10){
            cin >> f[i][j];
            bf[i] += pow(2, 9-j)*f[i][j];
        }
    }


    long long p[n][11];
    long long maxans = -1000000000000;
    rep(i, n){    
        rep(j, 11)cin >> p[i][j];
    }
    
    rep(i, 1024){
        long long  ans = 0;
        bool work = false;
        rep(j, n){
            int tmp = i&bf[j];
            int no = counting(tmp);
            if(no != 0)work = true;
            ans += p[j][no];
        }
        if(ans > maxans && work)maxans = ans;
    }

    cout << maxans << endl; 

}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }


const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

int main(){
    
    ll n;
    cin >> n;
    mint ans = 0;
    mint a[n] = {};

    mint memo[n] = {};
    rep(i,0,n){
        cin >> a[i];
        if(i == 0) memo[i] = a[i];
        else memo[i] = memo[i-1] + a[i];
    }

    rep(i,0,n){
        ans += (memo[n-1]-memo[i])*a[i];
    }
    
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 6760