akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s;
int n;
vector<string> vs;
map<string,vi> M;

int main(){
	while(cin>>s>>n){
		M[s].push_back(n);
		vs.push_back(s);
	}
	sort(vs.begin(),vs.end());
	vs.erase(unique(vs.begin(),vs.end()),vs.end());
	for(vector<string>::iterator i=vs.begin();i!=vs.end();i++){
		cout<<*i<<endl;
		sort(M[*i].begin(),M[*i].end());
		int S=M[*i].size()-1;
		for(int j=0;j<S;j++) cout<<M[*i][j]<<' ';
		cout<<M[*i][S]<<endl;
	}
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
const int N=18,mod=1000000007;
int bin[N],jc[1<<N],inv[1<<N],a[N],f[N][1<<N],n,m,cnt[1<<N];
int qp(int k,int x)
{
	int res=1;
	while(k)
	{
		if(k&1)res=1ll*res*x%mod;	
		x=1ll*x*x%mod;
		k>>=1;
	}
	return res;
}
void init()
{
	jc[0]=bin[0]=inv[0]=cnt[0]=1;
	for(int i=1;i<=n;i++)bin[i]=bin[i-1]<<1;
	for(int i=1;i<=bin[n];i++)jc[i]=1ll*jc[i-1]*i%mod;
	inv[bin[n]]=qp(mod-2,jc[bin[n]]);
	for(int i=bin[n]-1;i;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
	for(int i=1;i<=bin[n];i++)
		cnt[i]=(i&1)?mod-cnt[i>>1]:cnt[i>>1];
}
int C(int a,int b)
{
	if(a<b)return 0;
	return 1ll*jc[a]*inv[b]%mod*inv[a-b]%mod;
}
int ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+m+1); init();
	f[m+1][0]=1;
	for(int i=m;i;i--)
		for(int t=0;t<bin[n];t++)
			if(f[i+1][t])
			{
				(f[i][t]+=f[i+1][t])%=mod;
				int p=bin[n]-1-t;
				for(int j=0;j<n;j++)
					if(!(t&(1<<j)))
						(f[i][t|(1<<j)]+=1ll*C(p-a[i]+1,(1<<j)-1)*f[i+1][t]%mod*jc[1<<j]%mod)%=mod;
			}
	for(int i=0;i<bin[n];i++)
		(ans+=1ll*f[1][i]*jc[bin[n]-1-i]%mod*cnt[i]%mod)%=mod;
	printf("%d",1ll*ans*bin[n]%mod);
	return 0;
}

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

void testCase(){
    int s, w;
    cin>>s>>w;
    if(w >= s) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}

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



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int sz=1e5 + 5;

int n;
string s;

void add_self(int& a,int b){
	a+=b;
	if(a>=mod){
		a-=mod;
	}
	if(a<0){
		a+=mod;
	}
}

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n>>s;
    
    vector<int> dp(n+2);
    dp[1]=1;
    for(int i=0;i<n-1;i++){
    	vector<int> new_dp(n+2);
    	int len=i+2;
    	int L=1,R=len+1;
    	for(int last=1;last<len;last++){
    		if(s[i]=='>'){
    			L=1;
    			R=last;
			}
			else{
				L=last+1;
				R=len;
			}
			add_self(new_dp[L],dp[last]);
			add_self(new_dp[R+1],-dp[last]);
		}
		int x=0;
		for(int i=1;i<=len;i++){
			add_self(x,new_dp[i]);
			dp[i]=x;
		}
	}
	
	int ans=0;
	for(int i=1;i<=n;i++){
		add_self(ans,dp[i]);
	}
	
	cout<<ans<<"\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int main() {
	ll N; cin >> N;
	ll p[100001] = {};

	rep(i, 0, N) {
		ll a; cin >> a;

		if (a > 0) {
			p[a - 1]++;
		}
		p[a]++;
		p[a + 1]++;
	}
	ll maxV = 0;
	repe(i, 0, 100001) {
		maxV = max(maxV, p[i]);
	}
	cout << maxV << endl;

	return 0;
}

Measured memory_bytes: 1024
n=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(n):
    a=A[i]
    b=B[i]
    c=C[i]
    if a==b and b==c:
        pass
    elif a==b or a==c or b==c:
        ans+=1
    else:
        ans+=2
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}


Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

void y() {
    cout << "Yes" << endl;
    exit(0);
}

void n() {
    cout << "No" << endl;
    exit(0);
}

void Y() {
    cout << "YES" << endl;
    exit(0);
}

void N() {
    cout << "NO" << endl;
    exit(0);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

/*   kokomade  */

int cnt = 0;
bool is_prime[ 50000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main() {
    IOS;
    int n,ans=0;
    string a,b,c;

    cin>>n>>a>>b>>c;
    for (int i = 0; i < n; ++i) {
        if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i])ans+=2;
        else if((a[i]==b[i]&&b[i]!=c[i]&&c[i]!=a[i])||(a[i]!=b[i]&&b[i]==c[i]&&c[i]!=a[i])||(a[i]!=b[i]&&b[i]!=c[i]&&c[i]==a[i]))ans++;


    }

    cout<<ans;

    cout<<endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


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

#define int long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  最右のi=a[i]を消去
}*/

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

  vi a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }

  vi ans;
  while(1){
    bool flag = false;
    for(int i = a.size()-1; i >= 0; i--){
      if(i == a[i]){
        ans.pb(i+1);
        a.erase(a.begin()+i);
        flag = true;
        break;
      }
    }
    if(!flag) break;
  }

  if(ans.size() != n){
    cout << -1 << endl;
  }else{
    reverse(all(ans));
    rep(i, n) cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 764
/*  Sourav Verma IPG_2013  ABV_IIITMG 
        Task @ Codeforces & Atcoder  */

#include<bits/stdc++.h>

#define ll                    long long int
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define rloop(i,a,b)          for(int i=(int)a;i<=(int)b;++i)
#define loopr(i,a,b)          for(int i=(int)a;i>=(int)b;--i)
#define count_1(n)            __builtin_popcountll(n)
#define pb                    push_back
#define mset(a,b,c)           loop(i,0,b) a[i]=c
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define MAX                   1e9
#define MIN                   -1e9
#define itoc(c)               ((char)(((int)'0')+c))
#define vi                    vector<int>
#define vvi                   vector<vi>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define mini                  INT_MIN
#define sv()                  int t; scanf("%d",&t); while(t--)
using namespace std;
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll lcm(int x, int y) { return x * 1ll * y / (int)__gcd(x, y); }
ll hcf(ll a, ll b) {if(b>a) return (hcf(b, a)); if(a%b==0) return b; return (hcf(b, a%b));} 
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

void solve(std::istream &in, std::ostream &out){
    int a,b,h; in>>a>>b>>h;
    out<<((a+b)*h)/2;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    #ifdef debug
        freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
	#endif
    
    solve(std::cin, std::cout);
    
    #ifdef debug
        fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
    #endif
    
    return 0;
}

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

int main()
{
    int s;
    cin>>s;
    int a[1000001] = {0};
    int i = 1;
    a[s]++;
    while(true){
        i++;
        if(s%2==0) s /= 2;
        else s = 3*s+1;
        if(a[s] != 0) break;
        else a[s]++;
    }
    cout << i << endl;
    return 0;
}

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, k;
ll a[100005];
ll sum[100005], plusSum[100005];
int main()
{
	std::cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
		sum[i + 1] = sum[i] + a[i];
		plusSum[i + 1] = plusSum[i] + std::max(0LL, a[i]);
	}

	ll ans = -inf;
	for (int i = 0, end = n - k + 1; i < end; ++i) {
		auto a1 = plusSum[i] + sum[i + k] - sum[i] + plusSum[n] - plusSum[i + k];
		auto a2 = plusSum[n] - plusSum[i + k] + plusSum[i];
		ans = std::max({ ans,a1,a2 });
	}

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


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnevenNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int counter = 0;

            for (int i = 1; i <= N; i++)
            {
                if (1 <= i && i <= 9)
                    counter++;
                if (100 <= i && i <= 999)
                    counter++;
                if (10000 <= i && i <= 99999)
                    counter++;
            }

            Console.WriteLine(counter);
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
int main(void){
  char a[11];
  char b[11];
  int len;
  scanf("%s",a);
  scanf("%s",b);
  len = strlen(a);
  b[len]='\0';
  if(strcmp(a,b)==0)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 1724
class Edge:
  def __init__(self, starting_point, arrival_point, cost):
    self.starting_point = starting_point
    self.arrival_point = arrival_point
    self.cost = cost

def solve():
  N, M, P = map(int, input().split())
  edges = []
  INF = float('inf')
  dist = [INF for _ in range(N + 10)]
  dist[1] = 0
  for i in range(M):
    a, b, c = map(int, input().split())
    e = Edge(a, b, -c + P)
    edges.append(e)
  for i in range(2 * N):
    for e in edges:
      if dist[e.arrival_point] > e.cost + dist[e.starting_point]:
        dist[e.arrival_point] = e.cost + dist[e.starting_point]
        if i == N - 1:
          dist[e.arrival_point] = -INF
  if dist[N] != -INF:
    return max(-dist[N], 0)
  else:
    return -1
print(solve())

Measured memory_bytes: 49628
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
    return 0;
  }else if(s=="MON"){
    cout<<6<<endl;
    return 0;
  }else if(s=="TUE"){
    cout<<5<<endl;
    return 0;
  }else if(s=="WED"){
    cout<<4<<endl;
    return 0;
  }else if(s=="THU"){
    cout<<3<<endl;
    return 0;
  }else if(s=="FRI"){
    cout<<2<<endl;
    return 0;
  }else if(s=="SAT"){
    cout<<1<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
	stack<double> s;
	double a, b;
	char c[80], bf;
	while (1)
	{
		cin >> c;
		if (c[0] == '+')
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a+b);
		}
		else if (c[0] == '-' && c[1] == '\0')
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a-b);
		}
		else if (c[0] == '*')
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a*b);
		}
		else if (c[0] == '/')
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			s.push(a/b);
		}
		else
		{
			s.push(atof(c));
		}
		bf = getchar();
		if (bf == '\n')
			printf("%.6f\n", s.top());
		if (bf == EOF)
			return 0;
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    N = int(input())
    L = list(map(int, input().split()))

    for i in range(1, N):
        print(*L)
        tmp = L[i]
        j = i
        while j > 0 and L[j-1] > tmp:
            L[j] = L[j-1]
            j -= 1
        L[j] = tmp

    print(*L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5980
n = int(input())
s = input()

S = len(s)
mod = 10 ** 9 + 7

tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)

ans = tmp_ans

for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod

ans %= mod

print(ans)


Measured memory_bytes: 10984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define has(c, i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i >= a; i--)

int main() {
  cout << fixed << setprecision(8);

  ll n, W;
  cin >> n >> W;

  vl weights(n);
  vl values(n);
  FOR(i,0,n) {
    cin >> weights[i] >> values[i];
  }

  unordered_map<ll, ll> m;
  ll res = 0;

  FOR(i,0,n) {
    FORD(j,0,W) {
      ll nw = j + weights[i];
      if(nw <= W) {
	ll val = m[j] + values[i];
	m[nw] = max(m[nw], val);
	res = max(res, val);
      }
    }
  }
  
  cout << res << endl;
}


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

using namespace std;

int main(){
	string str;
	cin>>str;
	string rpta="";
	for (int i=0 ; i<str.size() ; i++){
		if(str[i]=='1' || str[i]=='0'){
			rpta+=str[i];
		}else{
			if(rpta.size()>0){
				rpta.erase(rpta.size()-1);	
			}
			
		}
	}
	cout<<rpta;
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define B 1
#define W 2

short d[] = {0,1,-1};
int n,m,p;
short G[7*7*7+1][8][8];

int check(int x,int y,int z)
{
  short i,j,k,dx,dy,dz,c,cnt,nx,ny,nz;
  for(i=0;i<3;i++)
    {
      for(j=0;j<3;j++)
	{
	  for(k=0;k<3;k++)
	    {
	      if(i+j+k == 0)
		continue;

	      dx = d[k],dy = d[j],dz = d[i];
	      c = G[z][y][x];
	      cnt = 0;
	      nx = ny = nz = 0;
	      
	      while((0 <= x+nx && x+nx < n) && (0 <= y+ny && y+ny < n) && (0 <= z+nz && z+nz < n) && G[z+nz][y+ny][x+nx] == c)
		nz-=dz,ny-=dy,nx-=dx;
	      nz+=dz,ny+=dy,nx+=dx;
	      
	      while((0 <= x+nx && x+nx < n) && (0 <= y+ny && y+ny < n) && (0 <= z+nz && z+nz < n) && G[z+nz][y+ny][x+nx] == c)
		cnt++,nz+=dz,ny+=dy,nx+=dx;
	      
	      if(cnt >= m)
		return 1;
	    }
	}
    }
  return 0;
}

int main()
{
  while(1)
    {
      scanf("%d %d %d",&n,&m,&p);
      if(n+m+p == 0)
	break;
      int i,j,k,x,y,z,found;
      for(i=0;i<p+1;i++)
	for(j=0;j<n+1;j++)
	  for(k=0;k<n+1;k++)
            G[i][j][k] = 0;
      found = -1;
      for(i=0;i<p;i++)
	{
	  z = 0;
	  scanf("%d %d",&x,&y);
	  x--,y--;
	  while(G[z][y][x]!=0)
	    z++;
	  G[z][y][x] = i%2?W:B;
	  if(found == -1 && m/2 <= i)
	    if(check(x,y,z))
	      found = i;    
	}
      if(found == -1)
	printf("Draw\n");
      else 
	found%2?printf("White %d\n",found+1):printf("Black %d\n",found+1); 


    }
  return 0;
}

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

int main() {
  string a, b;
  cin >> a >> b;
  int c = stoi(a + b);
  for(int i=1; i <= 1000; i++) if(i*i == c){ cout << "Yes" << endl; return 0;}
  cout << "No" << endl;
}


Measured memory_bytes: 256
def bubble(n, A):
    flag = True
    i = 0
    while (flag):
        flag = False
        for j in reversed(range(i+1, n)):
            if (A[j-1][1] > A[j][1]):
                A[j-1], A[j] = A[j], A[j-1]
                flag = True
        i += 1
    return A

def selection(n, A):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if (A[minj][1] > A[j][1]):
                minj = j
        A[minj], A[i] = A[i], A[minj]
    return A

def judge(A, B):
    for i in range(n):
        if (bubble(n, A)[i] != selection(n, B)[i]):
            return "Not stable"
    return "Stable"

n = int(input())
A = input().split(" ")
B = A.copy()
print (" ".join(bubble(n, A)))
print ("Stable")
print (" ".join(selection(n, B)))
print (judge(bubble(n, A), selection(n, B)))


Measured memory_bytes: 5608
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Candy Distribution
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int asums[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    asums[i + 1] = (asums[i] + ai) % m;
  }
  sort(asums, asums + n + 1);
  //for (int i = 0; i <= n; i++) printf("%d ", asums[i]); putchar('\n');

  ll cnt = 0;
  for (int i = 0; i <= n;) {
    int j = i + 1;
    while (j <= n && asums[j] == asums[i]) j++;
    int d = j - i;
    cnt += (ll)d * (d - 1) / 2;
    i = j;
  }

  printf("%lld\n", cnt);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool end;
};

int main(){
    string S;
    cin>>S;
    
    ll p=0;
    REP(i,S.length()){
        string t=(S.substr(p,5));
        //sl(p,t)
        if(t=="erase"){
            p+=5;
            if(S[p]=='r'){
                p++;
            }
        }else if(t=="dream"){
            p+=5;
            string t=(S.substr(p,5));
            if(t!="erase"&&S[p]=='e'&&S[p+1]=='r'){
                p+=2;
            }
        }else{
            if(p>=S.length()-1){
                break;
            }else{
                cout<<"NO";return 0;
            }
        }
    }
    cout<<"YES";
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

#define ll              long long
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             (int)(1e18)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define rep(i,j,n)      for(int i=j;i<n;i++)
#define all(p)          p.begin(),p.end()
#define ub(a,b)         upper_bound(all(a),b)
#define lb(a,b)         lower_bound(all(a),b)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

void run()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
	run();
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(3, 0));
	rep(i, 0, n)
	{
		rep(j, 0, 3)cin >> a[i][j];
	}
	vector<vector<int>> dp(n, vector<int>(3, 0));
	rep(i, 0, 3)dp[0][i] = a[0][i];
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				if (k == j)
				{
					continue;
				}
				dp[i][j] = max(a[i][j] + dp[i - 1][k], dp[i][j]);
			}
		}
	}
	int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int a,b,c;
  int count=0;
  int ac,bc,cc;

  cin >> a >> b >> c;

  ac=a;
  bc=b;
  cc=c;

  bool flag=true;
  while (ac%2==0 && bc%2==0 && cc%2==0)
  {
    int a2=ac/2;
    int b2=bc/2;
    int c2=cc/2;

    ac=b2+c2;
    bc=c2+a2;
    cc=a2+b2;
    count++;

    if (ac==a && bc==b && cc==c)
    {
      flag=false;
      break;
    }
    
  }
  

  if (flag)
  {
    cout << count << endl;
  }else
  {
    cout << -1 << endl;
  }  

  return 0;
}

Measured memory_bytes: 256
// 2020-08-30 16:57:15
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
const int V = 100010, inf = 1e9;
vector<int> G[V];
void answer() {
  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> df(n, inf), ds(n, inf);
  df[0] = 0;
  ds[n - 1] = 0;
  {
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int v : G[u])
        if (v != n - 1 && df[u] < df[v]) {
          df[v] = df[u] + 1;
          q.push(v);
        }
    }
  }
  {
    queue<int> q;
    q.push(n - 1);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int v : G[u])
        if (v != 0 && ds[u] < ds[v]) {
          ds[v] = ds[u] + 1;
          q.push(v);
        }
    }
  }
  int ans = 0;
  rep(i, n) {
    if (df[i] <= ds[i])
      ans++;
    else
      ans--;
  }
  if (ans > 0)
    cout << "Fennec" << '\n';
  else
    cout << "Snuke" << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    vector<int> arr(len);
    for(int i = 0; i < len; i++)
        cin >> arr[i];
    int index = 1;
    while(arr[0] == arr[index])
        index++;
    bool up = false;
    if(arr[index] > arr[0])
        up = true;
    int ans = 1;
    for(int i = index + 1; i < len; i++) {
        if((up && arr[i] < arr[i - 1]) || (!up && arr[i] > arr[i - 1])) {
            ans++;
            index = i + 1;
            while(arr[i] == arr[index])
                index++;
            up = false;
            if(arr[index] > arr[i])
                up = true;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c,d,x;
	cin >> a >> b;
	x = ( a + b ) / 2;
	c = ( a + b ) % 2;
 	d = ( c + 9 ) / 10;
	cout << x + d << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,A,B,C,D;
  cin >> N >> A >> B >> C >> D;
  A--;
  B--;
  C--;
  D--;
  string s;
  cin >> s;
  int sl = sz(s);

  
  if(C < D) {
    bool flag = true;
    srep(i,B+1,D-1) {
      if(s[i] == '#' && s[i+1] == '#') {
        flag = false;
      }
    }
    srep(i,A+1,C-1) {
      if(s[i] == '#' && s[i+1] == '#') {
        flag = false;
      }
    }
    if(flag) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
  }
  bool flag = true;
  srep(i,A+1,C-1) {
    if(s[i] == '#' && s[i+1] == '#') {
        flag = false;
    }
  }
  srep(i,B+1,D-1) {
    if(s[i] == '#' && s[i+1] == '#') {
      flag = false;
    }
  }

  bool f = true;
  for(int i = B-1;i + 2 <= D+1;i++){
    if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') {
      f = false;
    }
  }
  if(f) flag = false;

  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main()
{
    vector<bool> b(26, false);
    string s;
    cin >> s;
    for (int i = 0; i < int(s.size()); i++) {
        int idx = s[i] - 'a';
        if (b[idx]) {
            cout << "no" << endl;
            return 0;
        }
        b[idx] = true;
    }
    cout << "yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 1
using namespace std;

int main()
{
    int i,j;
    int M1,D1,M2,D2;

    scanf("%d %d", &M1, &D1);
    scanf("%d %d", &M2, &D2);

    if( M1 != M2)
        printf("1\n");
    else
        printf("0\n");

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 500000 + 1000;

int n;
int d[MAXN], s[MAXN], f[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> s[0];
	for(int i = 1; i <= n; i++)
		cin >> d[i];
	for(int i = 1; i <= n; i++)
		s[i] = min(s[i - 1], abs(s[i - 1] - d[i]));
	f[n + 1] = 1;
	for(int i = n; i >= 1; i--)
		f[i] = (f[i + 1] <= d[i] / 2 ? f[i + 1] : f[i + 1] + d[i]);
	// for(int i = 1; i <= n; i++)
	// 	cout << i << ' ' << s[i] << ' ' << f[i] << endl;
	int T;
	cin >> T;
	while(T--)
	{
		int q;
		cin >> q;
		cout << (f[q + 1] <= s[q - 1] ? "YES" : "NO") << endl;
	}


	return 0;
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    rep(i, n){
        int p;
        cin >> p;
        if(p <= a){
            ++cnt1;
        }else if(p <= b){
            ++cnt2;
        }else{
            ++cnt3;
        }
    }
    int ans = min({cnt1, cnt2, cnt3});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=1001001001;
int dp[100010];
int N;

int main(){
    cin>>N;
    fill_n(dp,N+2,INF);

    for(int i=0;i<N;i++){
        int A;cin>>A;
        *lower_bound(dp,dp+N+2,A)=A;
    }
    cout<<lower_bound(dp,dp+N+2,INF)-dp<<endl;
    return 0;
}

Measured memory_bytes: 1548
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    set<int> st;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(st.count(x) == 0) st.insert(x);
        else st.erase(x);
    }
    cout << st.size() << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

A=[int(input()) for i in range(N)]
A.sort()
ans=N

flag=False

for i in range(N-1):
	if flag==True:
		flag=False
		continue
	elif A[i]==A[i+1]:
		ans-=2
		flag=True
#print(A)
print(ans)

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
            ll N,a; cin>>N;
            double b,c;
            if(N%2==0){
                       cout<<0.5<<endl;
                       }
            if(N%2==1){
                       a=(N-1)/2+1;    
                       b=N;c=a;
                       cout<<fixed<<setprecision(6)<<c/b<<endl;
                      
                       }
    }



Measured memory_bytes: 256
N,x = map(int,input().split())
if N <= 2:
  if N != x:
    print('No')
  else:
    print('Yes')
    for i in range(1,2*x):
      print(i)
      
else:
  if x == 1 or x == 2*N-1:
    print('No')
  else:
    print('Yes')
    if N == x:
      for i in range(1,2*x):
        print(i)
    elif N > x:
      for i in range(N-x):
        print(2*N-1-i) 
      for i in range(1,N+x):
        print(i)     
    else:
      for i in range(1,3*N-x):
        print(i+x-N) 
      for i in range(1,x-N+1):
        print(i) 

Measured memory_bytes: 4560
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll A, B;
    cin >> A >> B;
    if(B % A == 0) {
        cout << -1 << endl;
        return 0;
    }

    const ll inf = 5e15;
    ll ans = inf;
    for(ll b = 1; b <= A; b++) {
        ll orig = B * b;
        if(B * b % A == 0) continue;
        ll a = B * b / A + 1;
        ll mod = B * b % A;
        ll one = A - mod;
        orig += one;
        ll cnt_0 = b + one;
        ll cnt_1 = a;
        if(cnt_1 < cnt_0) chmin(ans, orig);
    }

    cout << (ans == inf ? -1 : ans) << endl;
    return 0;
}



Measured memory_bytes: 3236
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as Maybe
import qualified Debug.Trace as Trace

solve :: Int -> Int
solve n = solveImpl (-1) 1 n

solveImpl :: Int -> Int -> Int -> Int
solveImpl tmpAns i n
    | i * i > n = tmpAns
    | otherwise =
        if (mod n i == 0)
            then if (tmp < tmpAns || tmpAns < 0)
                then solveImpl tmp (i + 1) n
                else solveImpl tmpAns (i + 1) n
            else solveImpl tmpAns (i + 1) n
    where tmp = (i + (div n i)) - 2

main = do
    n <- (fst . Maybe.fromJust . BS.readInt) <$> BS.getLine
    let ans = solve n
    print ans

Measured memory_bytes: 3772
#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<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
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(){
	ll N,M,A[100001],Asum[100001]={};
	scan(N>>M);
	rep(i,N){
		scan(A[i]);
	}
	sort(A,A+N);
	rep(i,N) Asum[i+1]=Asum[i]+A[i];
	ll summin=0,summax=200001;
	ll num;
	while(summin+1<summax){
		ll summid=(summin+summax)/2+(summin+summax)%2;
		ll ijonum=0;
		rep(i,N){
			int itr=lower_bound(A,A+N,summid-A[i])-A;
			ijonum+=N-itr;
		}
		//printf("sum:%lld num:%lld\n",summid,num);
		if(ijonum<M){
			summax=summid;
		}
		else{
			summin=summid;
			num=ijonum;
		}
	}
	ll ans=0;
	ll wasaisyo=INF;
	rep(i,N){
		int itr=lower_bound(A,A+N,summin-A[i])-A;
		ans+=Asum[N]-Asum[itr]+(N-itr)*A[i];
		if(itr<N) wasaisyo=min(wasaisyo,A[i]+A[itr]);
	}
	//prin(num);
	//prin(summin);
	prin(ans-(num-M)*wasaisyo);

	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int N = s.nextInt();
			final int V[] = new int[N];
			for(int i = 0; i < N; i++) {
				V[i] = s.nextInt();
			}
			final int C[] = new int[N];
			for(int i = 0; i < N; i++) {
				C[i] = s.nextInt();
			}

			int ret = 0;
			for (int i = 0; i < N; i++) {
				if (V[i] > C[i]) {
					ret += V[i] - C[i];
				}
			}
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 23252
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	LL L;
	cin >> N >> L;
	vector<LL> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	////
	for(int i=0;i<N-1;++i){
		LL res = A[i] + A[i+1];
		if( res >= L ){
			cout << "Possible" << endl;
			for(int j=0;j<i;++j){
				cout << j+1 << endl;
			}
			for(int j=N-2;j>i;--j){
				cout << j+1 << endl;
			}
			cout << i+1 << endl;
			return;
		}
	}
	cout << "Impossible" << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static final int TASKS = 3;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		int[][] H = new int[N][TASKS];
		
		for(int i = 0; i < N ; i++) {
			String[] S = br.readLine().split(" ");
			H[i][0] = Integer.parseInt(S[0]);
			H[i][1] = Integer.parseInt(S[1]);
			H[i][2] = Integer.parseInt(S[2]);
		}
		
		int[] preCache = new int[TASKS];
		int[] currCache = new int[TASKS];
		
		for(int i = 0; i < TASKS; i++) {
			preCache[i] = H[0][i];
		}
		System.out.println(minCostJump(N, H, preCache, currCache));
	}
	
	public static int minCostJump(int N, int[][] H, int[] preCache, int[] currCache) {
		
		for(int i = 1; i < N ; i++) {
			for(int j = 0; j < TASKS; j++) {
				for(int k = 0; k < TASKS; k++) {
					if(j == k) continue;
					currCache[j] = Math.max(currCache[j], H[i][j]+ preCache[k]);
				}
			}
			preCache = currCache;
			currCache = new int[TASKS];
		}
		
	
		return Math.max(preCache[0], Math.max(preCache[1], preCache[2]));
	}
}


Measured memory_bytes: 52200
from collections import Counter
n = int(input())

L = list(map(int,input().split()))
sum_all = sum(L)
L = Counter(L)
#print(L)
q = int(input())
sum1 = sum_all
for i in range(q):
    
    a,b = map(int,input().split())
    #print(L)
    if a not in L:
        L[a] = 0
    else:
        L[b] +=L[a] 
    #print(L)
    sum1 = sum1 + b*L[a] - a*L[a]
    L[a] =0
    
    #print(L)
    print(sum1)

Measured memory_bytes: 23288
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int s = 3;
    vector<vector<int>> v(s, vector<int>(s));
    rep(i, s){
        rep(j, s) cin >> v[i][j];
    }

    int n;
    cin >> n;
    rep(i, n){
        int b;
        cin >> b;
        rep(h, s){
            rep(w, s){
                if(v[h][w] == b) v[h][w] = -1;
            }
        }
    }

    for(int i=-1; i<=1; i++){
        for(int j=-1; j<=1; j++){
            if(v[1][1] == -1 && v[1+i][1] == -1 && v[1][j+1] == -1){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }


    rep(i, s){
        if(v[i][0] == -1 && v[i][1] == -1 && v[i][2] == -1){
            cout << "Yes" << endl;
            return 0;
        }
        if(v[0][i] == -1 && v[1][i] == -1 && v[2][i] == -1){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256