akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


string S[110];

int main() {

    int N;
    cin >> N;

    rep(i, N)cin >> S[i];

    rep(i, N) {
        rep(j, N) {
            if (i == j)continue;
            if (S[i] == S[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    rep(i, N-1) {
        if (S[i][S[i].size()-1] != S[i + 1][0]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

}

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

int main() {
    ll h, w;
    cin >> h >> w;

    ll a, b;

    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    if (h%2) {
        a = h/2 + 1;
        b = h/2;
    }
    else {
        a = h/2;
        b = h/2;
    }

    if (w%2) {
        if (w == 1) {
            cout << a << endl;
        }
        else {
            cout << (a+b) * (w/2) + a << endl;
        }
    }
    else {
        cout << (a+b) * (w/2)<< endl;
    }
            
    return 0;
}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int N = 101;

int main(void){
    for(int T, res; cin >> T, T;){
        vi t(T);
        rep(i, T) cin >> t[i];

        int n; cin >> n;
        vi m(N, 23);
        rep(i, n){
            int D, M; cin >> D >> M;
            D--;
            m[D] = min(m[D], M);
        }

        vvi dp(N, vi(T, inf));
        dp[0][0] = 0;
        range(i, 1, N){
            rep(j, T){
                if(dp[i - 1][j] == inf) continue;

                dp[i][0] = min(dp[i][0], dp[i - 1][j] + 1);

                int nextT = (j + 1) % T;
                if(0 <= m[i] - t[nextT]){
                    dp[i][nextT] = min(dp[i][nextT], dp[i - 1][j]);
                }
            }
        }

        cout << *min_element(all(dp[N - 1])) << endl;
    }

	return 0;
}

Measured memory_bytes: 1228
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=200005;
struct node
{
	int x,y,z;
}e[N*2];
int n,q,i,j,k,w[N],cnt,p[N];
long long ans;
bool cmp(node a,node b)
{
	return a.z<b.z;
}
int find(int x)
{
	return p[x]==-1?x:p[x]=find(p[x]);
}
int main()
{
	scanf("%d%d",&n,&q);
	for(i=0;i<n;++i)
		p[i]=-1;
	for(i=0;i<n;++i)
		w[i]=1<<30;
	for(i=1;i<=q;++i)
	{
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].z);
		w[e[i].x]=min(w[e[i].x],e[i].z+1);
		w[e[i].y]=min(w[e[i].y],e[i].z+2);
	}
	for(i=1;i<n;++i)
		w[i]=min(w[i],w[i-1]+2);
	w[0]=min(w[0],w[n-1]+2);
	for(i=1;i<n;++i)
		w[i]=min(w[i],w[i-1]+2);
	cnt=q;
	for(i=0;i<n-1;++i)
		e[++cnt]=(node){i,i+1,w[i]};
	e[++cnt]=(node){n-1,0,w[n-1]};
	sort(e+1,e+1+cnt,cmp);
	for(i=1;i<=cnt;++i)
		if(find(e[i].x)!=find(e[i].y))
		{
			p[find(e[i].x)]=find(e[i].y);
			ans+=e[i].z;
		}
	printf("%lld",ans);
	return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;

    rep(i, 10){
        if(n <= (i + 1) * 1000){
            cout << (i + 1) * 1000 - n << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3632
/**
*    author:  Dooloper
*    created: 29.06.2020 05:40:09
**/

#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;

ll f(ll n){ return n*(n+1)/2;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  ll ans = 0;
  for(int i = 1; i <= n; i++){
    ll r = n/i;
    int mx = i;
    int my = n;
    int midxy;
    while(my - mx > 1){
      midxy = (my + mx)/2;
      if(n/midxy < r) my = midxy;
      else mx = midxy;
    }
    ans += (ll)(mx - i + 1) * (ll)(mx + i) * f(r) / 2;
    i = mx;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int len;
    string s, t;
    cin >> len >> s >> t;

    string ans = "~";
    for(int i=0; i<2; ++i){
        int n = s.size();
        int m = t.size();
        int x = len / n * n;
        while((len - x) % m != 0)
            x -= n;

        string a;
        while(a.size() < x)
            a += s;
        while(a.size() < len)
            a += t;
        ans = min(ans, a);

        swap(s, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1212
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
   
    int N,Y;
    cin>>N>>Y;
    
    int x,y,z;
    
    for(x=0;x<=N;x++){
        for(y=0;y<=N-x;y++){
            z=N-x-y;
        
        
        if(Y==10000*x+5000*y+1000*z){
            
            cout<<x<<" "<<y<<" "<<z<<endl;
            return 0;
        }
        }
        }
    
    
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
   
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>

int main()
{

    int n, k;
    scanf("%d %d", &n, &k);
    long high[100001];
    int legg[100001];
    //道がkこ

        for (int i = 0; i < n; i++)
    {
        scanf("%ld", &high[i]);
        legg[i] = 1;
    }//高さ


  
    int a;
    int b;
    for (int i = 0; i < k; i++){
        scanf("%d %d", &a, &b);
    if(high[a-1]>high[b-1])
    legg[b - 1] = 0;
    else if (high[a - 1] < high[b - 1])
        legg[a - 1] = 0;
    else{
        legg[b - 1] = 0;
        legg[a - 1] = 0;
    }

    }
    int count=0;

    for (int i = 0; i < n; i++)
    {
        if(legg[i]>0)
            count++;
    } //高さ

    printf("%d", count);
    printf("\n");
}

Measured memory_bytes: 3320
#include<stdio.h>
int main(){
    
    int N, K;
    int sum = 1;
    scanf("%d%d", &N, &K);
   
   for(int i=0;i<N;i++){
		if(sum*2 < sum+K){
			sum *= 2;		
		} else {
			sum += K;
		}
   }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 1724
#include<cstdio>
#include<algorithm>
#include<map>
#define ll long long
#define MP make_pair
#define Pi pair<int,int>
#define Pl pair<ll,ll>
#define PP pair<Pi,Pl >
using namespace std;
#define N 20
#define inf 100000000000000ll
int n;
ll num[N];
map<PP,ll>p;
ll work(int l,int r,ll x,ll y)
{
	if(r-l<=1) return 0;
	PP u=MP(MP(l,r),MP(x,y));
	if(p.count(u)) return p[u];
	ll res=inf;
	for(int i=l+1;i<=r-1;i++)
	res=min(res,work(l,i,x,x+y)+work(i,r,x+y,y)+num[i]*(x+y));
	return p[u]=res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&num[i]);
	printf("%lld\n",num[1]+num[n]+work(1,n,1,1));
}

Measured memory_bytes: 20736
#include<iostream>
using namespace std;
#include<map>
#include<cmath>
#include<algorithm>
#define int long long int
#define mod 1000000007
int power(int a,int b)
{
	if(b==0)
	  return 1;
	else
	{
		int r=power(a,b/2);
		if(b%2==0)
		{
			return (r*r)%mod;
		}
		else
		{
			int x=(r*r)%mod;
			return (a*x)%mod;
		}
	}
}
int function(int n,int val)
{
	if(n==0)
	   return 1;
	else
	{
		int p=-1;
		int j;
		for(j=0;j<val;j++)
		{
			int x=power(3,j);
			if(x<=n)
			{
				p=j;
			}
			else
			  break;
		}
		if(p==-1)
		  return 1;
		int here=power(2,p);
		if(power(3,p)==n)
		  return 1+here;
		here+=function(n-power(3,p),p);
		return here;
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int arr[n+1],j;
	for(j=0;j<n;j++)
	  cin>>arr[j+1];
	int prefix[n+1]={0};
	int suffix[n+2]={0};
	for(j=1;j<=n;j++)
	{
		prefix[j]=__gcd(arr[j],prefix[j-1]);
	}
	for(j=n;j>=1;j--)
	{
		suffix[j]=__gcd(arr[j],suffix[j+1]);
	}
	int answer=0;
	for(j=1;j<=n;j++)
	{
		int val=__gcd(prefix[j-1],suffix[j+1]);
		answer=max(answer,val);
	}
	cout<<answer<<endl;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int solve(int i,int l,int r,const vi& xs,const vi& as,const vi& bs,const vi& cs,vector<vvi>& memo)
{
	if(memo[i][l][r]!=-1) return memo[i][l][r];
	if(r-l==1)
		return memo[i][l][r]=(as[i]==xs[l]);
	repi(p,l+1,r)
		if(solve(bs[i],l,p,xs,as,bs,cs,memo) && solve(cs[i],p,r,xs,as,bs,cs,memo))
			return memo[i][l][r]=true;
	return memo[i][l][r]=false;
}

int main()
{
	for(int n;cin>>n && n;){
		vi xs(n);
		rep(i,n) cin>>xs[i];
		int m; cin>>m;
		vi as(m),bs(m),cs(m);
		rep(i,m) cin>>as[i]>>bs[i]>>cs[i],bs[i]--,cs[i]--;
		vector<vvi> memo(m,vvi(n+1,vi(n+1,-1)));
		cout<<(solve(0,0,n,xs,as,bs,cs,memo)?"Yes":"No")<<endl;
	}
}

Measured memory_bytes: 1524
#include <cstdio>
int main(void){
    while(1){
    int H,W;
    scanf("%d %d", &H, &W);
        if(H == 0 && W == 0)break;
        else{
            for(int j=0; j<H; j++){
                if(j==0 || j==H-1){
                    for(int i=0; i<W; i++){
                        printf("#");
                    }
                    printf("\n");
                }
                else{
                    printf("#");
                    for(int i=0; i<W-2; i++){
                        printf(".");
                    }
                    printf("#\n");
                    }
                }
                printf("\n");
        }
    }
}

Measured memory_bytes: 2516
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *a,int n,char middle=' '){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?middle:'\n'));
}
void array_show(LL *a,int n,char middle=' '){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?middle:'\n'));
}

deque<P> q1;
int dis[100005];

int main(){
	int n;
	int a,b,c;
	memset(dis,-1,sizeof(dis));
	cin>>n;
	q1.push_back(make_pair(1,1));
	while(!q1.empty()){
		a=q1.front().first,b=q1.front().second,q1.pop_front();
		if(dis[b]!=-1)continue;
		dis[b]=a;
		if(b==0)break;
		c=(b*10)%n;
		q1.push_front(make_pair(a,c));
		c=(b+1)%n;
		q1.push_back(make_pair(a+1,c));
	}
	cout<<dis[0]<<endl;
	return 0;
}


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

using namespace std;

const int N = 100100;

vector<int> g[N];

int main() {
   ios_base::sync_with_stdio(false);
   int n, m;
   cin >> n >> m;
   for (int i = 1; i <= m; ++i) {
      int u, v;
      cin >> u >> v;
      g[u].emplace_back(v);
      g[v].emplace_back(u);
   }
   for (int i = 1; i <= n; ++i) {
      if (g[i].size() & 1) {
         cout << "No\n";
         return 0;
      }
   }
   for (int i = 1; i <= n; ++i) {
      if (g[i].size() >= 6) {
         cout << "Yes\n";
         return 0;
      }
   }
   vector<int> verts;
   for (int i = 1; i <= n; ++i) {
      if (g[i].size() == 4) {
         verts.push_back(i);
      }
   }
   if (verts.size() >= 3) {
      cout << "Yes\n";
      return 0;
   } else if (verts.size() <= 1) {
      cout << "No\n";
      return 0;
   } else {
      int v = verts[0];
      int u = verts[1];
      int cnt = 0;
      for (int w : g[v]) {
         int cur = w;
         int prv = v;
         while (cur != v && cur != u) {
            prv = g[cur][0] ^ g[cur][1] ^ prv;
            swap(cur, prv);
         }
         cnt += cur == u;
      }
      if (cnt == 2) {
         cout << "Yes\n";
         return 0;
      } else {
         cout << "No\n";
         return 0;
      }
   }
}


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

int main() {
	int N;
	cin >> N;
	map<int, int> Nums;
	for (int i = 0; i < N-1; i++) {
		int a;
		cin >> a;
		Nums[a-1]++;
	}
	for (int i = 0; i < N; i++) cout << Nums[i] << endl;
}


Measured memory_bytes: 13008
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    string* s;
    int* t;
    s=new string[n];
    t=new int[n];
    
    for(int i=0;i<n;i++){
        cin>>s[i]>>t[i];
    }
    string sx;
    cin>>sx;
    
    bool a=false;
    int sum=0;
    
    for(int i=0;i<n;i++){
        if(a){
            sum+=t[i];
        }else{
            if(s[i]==sx){
                a=true;
            }
        }
    }
    cout<<sum;
    delete[]s;
    delete[]t;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  ll a; cin >> a;
  double b; cin >> b;
  b *= 100;
  ll ans = a*(int)(b+0.5);
  ans /= 100;
  cout << ans << endl;
}


Measured memory_bytes: 3720
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);

}
int main()
{
	Mohammed_Atef_Hassan
		ll q, h, s, d;
	cin >> q >> h >> s >> d;
	ll n;
	cin >> n;
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, 2 * s);
	cout << (n / 2)*d + (n % 2 ? 1 : 0)*s << finl;
}

Measured memory_bytes: 384
n,k = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
def isOk(x):
	cost = 0
	for a, f in zip(A,F):
		eatable = x//f
		if eatable >= a:
			continue
		cost += a - eatable
	if cost <= k:
		return True
	return False
left = -1
right = A[-1] * F[0]
while left+1 < right:
	# mid = int(left + (right-left)//2)
	mid = (left+right)//2
	if isOk(mid):
		right = mid
	else:
		left = mid
print(right)


Measured memory_bytes: 33940
import java.util.Scanner;

public class Main {



	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		 
		int L = 0;
		int R = 0;

		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();

		L = A + B;
		R = C + D;

		if(L > R) {

			System.out.println("Left");
		
		}else if(L == R) {


			System.out.println("Balanced");
		
		}else if(R > L) {

			System.out.println("Right");
		
		}
	}
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define reps(i,j,k) for(int i=(j);i<=(k);++i)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define sz size()


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const double EPS=1e-8,INF=1e12;
typedef complex<double> P;
typedef P point;
namespace std{
  bool operator<(const P &a,const P &b){
    return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);}
}
double cross(const P &a,const P &b){
  return imag(conj(a)*b);
}
double dot(const P &a,const P &b){
  return real(conj(a)*b);
}

struct L :public vector<P>{
  L(const P &a,const P &b){
    pb(a); pb(b);
  }
};

typedef pair<point,point> ppp;

int ccw(P a,P b,P c){
  b-=a; c-=a;
  if(cross(b,c)>EPS) return 1;
  if(cross(b,c)<-EPS) return -1;
  if(dot(b,c)<-EPS) return +2;
  if(norm(b)+EPS<norm(c)) return -2;
  return 0;
}

ppp c_c_inter(const point &c1,const double &r1,
	      const point &c2,const double &r2){
  point A=conj(c2-c1), B=(r2*r2-r1*r1-(c2-c1)*conj(c2-c1)),C=r1*r1*(c2-c1);
  point D=B*B-4.*A*C;
  point z1=(-B+sqrt(D))/(2.0*A)+c1, z2=(-B-sqrt(D))/(2.0*A)+c1;
  return ppp(z1,z2);
}

bool interLS(const L &l,const L s){
  return cross(l[1]-l[0], s[0]-l[0])*
    cross(l[1]-l[0],s[1]-l[0])<EPS;
}

double len(const L &l){
  return abs(l[0]-l[1]);
}
double d[212][212];

int main(){
  cout<<fixed<<setprecision(10);
  int n;
  while(cin>>n,n){
    vector<P> c(n);
    vector<double> r(n);
    double x,y;
    rep(i,n){
      cin>>x>>y>>r[i];
      c[i]=P(x,y);
    }
    vector<ppp> ps(n-1);
    rep(i,n-1)
      ps[i]=c_c_inter(c[i],r[i],c[i+1],r[i+1]);

    fill(d[0],d[0]+212*212,INF);
    rep(i,n-1){
      L lx(c[0],ps[i].X),ly(c[0],ps[i].Y);
      int fx=1,fy=1;
      rep(j,i){
	fx&=interLS(lx,L(ps[j].X,ps[j].Y));
	fy&=interLS(ly,L(ps[j].X,ps[j].Y));
      }
      if(fx)d[2*n-2][2*i]=d[2*i][2*n-2]=len(lx);
      if(fy)d[2*n-2][2*i+1]=d[2*i+1][2*n-2]=len(ly);
    }
    rep(i,n-1){
      L lx(c[n-1],ps[i].X),ly(c[n-1],ps[i].Y);
      int fx=1,fy=1;
      for(int j=i;j<n-1;++j){
	fx&=interLS(lx,L(ps[j].X,ps[j].Y));
	fy&=interLS(ly,L(ps[j].X,ps[j].Y));
      }
      if(fx)d[2*n-1][2*i]=d[2*i][2*n-1]=len(lx);
      if(fy)d[2*n-1][2*i+1]=d[2*i+1][2*n-1]=len(ly);
    }
    L l(c[0],c[n-1]);
    int f=1;
    rep(i,n-1)
      f&=interLS(l,L(ps[i].X,ps[i].Y));
    if(f) d[2*n-1][2*n-2]=d[2*n-2][2*n-1]=len(l);
    rep(i,n-1)rep(j,i)rep(a,2)rep(b,2){
      L l(a?ps[i].Y:ps[i].X,b?ps[j].Y:ps[j].X);
      int f=1;
      for(int k=j+1;k<i;++k)
	f&=interLS(l,L(ps[k].X,ps[k].Y));
      if(f)
	d[2*i+a][2*j+b]=d[2*j+b][2*i+a]=len(l);
    }
    rep(k,2*n)rep(i,2*n)rep(j,2*n)
      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    cout<<d[2*n-1][2*n-2]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1692
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int mon[10];
	int n1, n2;
	for(int i = 0;i <10; i++){
		cin >> mon[i];
	}
	
	int first = 0;
	for(int i = 0; i < 10; i++){
		if(first < mon[i]){
			first = mon[i];
			n1 = i;
		}
	}
	
	int second = 0;
	for(int i = 0; i < 10; i++){
		if(second < mon[i] && i != n1){
			second = mon[i];
			n2 = i;
		}
	}
	
	int third = 0;
	for(int i = 0; i < 10; i++){
		if(third < mon[i] && i != n1 && i != n2) third = mon[i];
	}
	
	printf("%d\n%d\n%d\n", first, second, third);
	
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int main(){
  ll x,y;
  cin >> x >> y;
  cout << ((8>=max(x,y))?"Yay!":":(") << endl;
}


Measured memory_bytes: 256
var
  a, b, h, m, distance, angle: Double;

begin
  read(a);
  read(b);
  read(h);
  read(m);

  angle := abs(((30 * h) - (5.5 * m)));

  distance := sqrt((sqr(a) + sqr(b)) - (2 * (a) * (b) * Cos(angle * pi / 180)));

  writeln(distance);

end.


Measured memory_bytes: 1380
import sys
def input(): return sys.stdin.readline().rstrip()
 
def main():
    n,t=map(int, input().split())
    dp=[0]*t
    food=[]
    for _ in range(n):
        a,b=map(int, input().split())
        food.append([a,b])
    food.sort(key=lambda x:x[0]*-1)
    for j in range(n):
        a,b=food[j][0],food[j][1]
        dptmp=[0]*t
        for i in range(t):
            if i < a: 
                dptmp[i]=max(b,dp[i])
            else:
                dptmp[i]=max(dp[i-a]+b,dp[i])
        dp=dptmp
    print(dp[t-1])
 
if __name__=='__main__':
    main()

Measured memory_bytes: 74240
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  int H,N;
  cin >> H >> N;
  int dam=0;
  rep(i, N){
  int a;
    cin >> a;
    dam+=a;
  }
  if(dam<H)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Pos = pair<int, int>;

bool reachable(int t, const Pos& start, const Pos& end) {
  int distance = abs(end.first - start.first) + abs(end.second - start.second);
  if(t < distance) {
    return false;
  }
  return (t - distance) % 2 == 0;
}

int main() {
  int N;
  cin >> N;
  vector<int> ts(N);
  vector<Pos> ps(N);
  for(int i = 0; i < N; ++i) {
    cin >> ts[i] >> ps[i].first >> ps[i].second;
  }
  int ct = 0;
  Pos cp = {0, 0};
  for(int i = 0; i < N; ++i) {
    if(reachable(ts[i] - ct, cp, ps[i])) {
      ct = ts[i];
      cp = ps[i];
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n,c[1111],u[1111],v[1111],p[1111];
vector<int> g[1111];
vector<int> s[1111];

int solve(int a,int par)
{
  int res = 0;
  for( int i = 0; i < int(g[a].size()); i++ ) {
    int t = g[a][i];
    if( par == t ) continue;
    if( c[t] ) {
      res += s[a][i];
    } else {
      res += min(solve(t,a),s[a][i]);
    }
  }
  return res;
}

int main(void)
{
  scanf("%d",&n);
  for( int i = 0; i < n-1; i++ ) scanf("%d",c+i+1);
  for( int i = 0; i < n-1; i++ ) {
    scanf("%d%d%d",u+i,v+i,p+i);
    g[u[i]].push_back(v[i]);
    s[u[i]].push_back(p[i]);
    g[v[i]].push_back(u[i]);
    s[v[i]].push_back(p[i]);
  }
  printf("%d\n",solve(0,-1));
  return 0;
}

Measured memory_bytes: 1184
M = 998244353
N, S = map(int, input().split())

ans = 0
prev = [0]*S
for i, a in enumerate(map(int, input().split()), 1):
  if a > S:
    continue
  prev[0] = i
  ans = (ans + prev[S-a]*(N-i+1)) % M
  for j, s in enumerate(prev[:S-a], a):
    prev[j] += s
print(ans)



Measured memory_bytes: 3808
#include <iostream>
using namespace std;
int n;
int main(){
	while(cin>>n){
		if(n==0) break;
		int s=0,a=0,num=0;
		while(s<n){
			a++;
			s=s+a;
		}
		for(int i=2;i<=a;i++){
			for(int j=1;j<((n/i)+1);j++){
				int t=0;
				for(int k=j;k<j+i;k++){
					t=t+k;
				}
				if(t==n) num++;
			}
		}
		cout<<num<<endl;
	}
    return 0;
}

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

long long int gcd(long long int a, long long int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

long long int lcm(long long int a, long long int b)
{
    return a / gcd(a, b) * b;
}

int main() {
	// your code goes here
	long long int a, b;
	cin >> a >> b;
	//cout << "GCD : " << gcd(a, b) << '\n';

    cout << lcm(a, b) << '\n';
	return 0;
}


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

int main(void) {
	// input
	std::string w;
	std::cin >> w;

	int len_w = w.size();
	std::vector<int> n_char(26, 0);
	for(int i = 0; i < len_w; ++i) {
		n_char[w[i] - 'a'] += 1;
	}
	
	bool is_beautiful = true;
	for(int j = 0; j < 26; ++j) {
		if(n_char[j] % 2 == 1) is_beautiful = false;
	}

	std::cout << (is_beautiful ? "Yes" : "No") << std::endl;

	return 0;
}


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

namespace ABC128_B
{
    class Program
    {
        public class param
        {
            public int id { get; set; }
            public string name { get; set; }
            public int point { get; set; }

            public override string ToString()
            {
                return string.Format("id:{0},name:{1},point{2}", id, name, point);
            }
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var re = new List<string[]>();
            for(var i=0;i<n;i++)
            {
                var nm = Console.ReadLine().Split(' ');
                re.Add(nm);
            }
            var mm = re.OrderBy(x => x[0]).ThenByDescending(x=>int.Parse(x[1])).ToList();
            foreach(var ch in mm)
            {
                var ind = re.IndexOf(ch)+1;
                Console.WriteLine(ind);
            }
        }
       
    }
    
}


Measured memory_bytes: 13788
# include <algorithm>
# include <iostream>
# include <cmath>
# include <string>
# include <vector>

using namespace std;

int main() {
    int n,h, max=0, cnt=0;
    cin >> n;
    vector<int> height, maxs;
    for (int i=0; i<n; i++){
        cin >> h;
        if (h > max) {
            max = h;
        }
        if (h >= max) {
            cnt ++;
        }
    }
    cout << cnt << endl;

    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
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; }
//template end



int main(){
    int a,b; scanf("%d%d",&a,&b);
    printf("%d\n",a^b);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W[] = new int[N];

		int sum = 0;
		for (int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
			sum += W[i];
		}
		sc.close();

		int ans = 9999999;
		int sum2 = 0;
		for (int i = 0; i < N; i++) {
			sum2 += W[i];
			int sum3 = sum - sum2;
			if (ans > Math.abs(sum3 - sum2)) {
				ans = Math.abs(sum3 - sum2);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
def solve():
    N, A, B, C, D = map(int, input().split())
    S = input()
    for i in range(A - 1, C - 1):
        if S[i] == '#' and S[i + 1] == '#':
            return "No"
    for i in range(B - 1, D - 1):
        if S[i] == '#' and S[i + 1] == '#':
            return "No"
    if C < D:
        return "Yes"
    for i in range(B - 2, D - 1):
        if S[i] == '.' and S[i + 1] == '.' and S[i + 2] == '.':
            return "Yes"
    return "No"
print(solve())

Measured memory_bytes: 40432
#include <stdio.h>
#include<string.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


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

  int ans = N % 10;
  switch(ans){
    case 0:
      printf("pon\n");
      break;
    case 1:
      printf("pon\n");
      break;
    case 2:
      printf("hon\n");
      break;
    case 3:
      printf("bon\n");
      break;
    case 4:
      printf("hon\n");
      break;
    case 5:
      printf("hon\n");
      break;
    case 6:
      printf("pon\n");
      break;
    case 7:
      printf("hon\n");
      break;
    case 8:
      printf("pon\n");
      break;
    case 9:
      printf("hon\n");
      break;
  }
 
return 0;
}


Measured memory_bytes: 1616
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    B=[max(a,0) for a in A] # 正の部分だけ取れる
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]

    T=[0]*(n+1)
    for i in range(n):
        T[i+1]=T[i]+B[i]

    # A[:i] までは任意、A[i:i+k]は塗るか塗らないかの2択、A[i+k:]からは任意
    ans=0
    for i in range(n-k+1):
        score=T[i]+max(0,S[i+k]-S[i])+(T[n]-T[i+k])
        ans=max(ans,score)

    print(ans)
resolve()

Measured memory_bytes: 66144
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m,x;
  cin>>n>>m>>x;
  vll c(n);
  vvll a(n,vll(m));
  rep(i,n){
    cin>>c[i];
    rep(j,m){
      cin>>a[i][j];
    }
  }
  ll ans=INF;
  for(int bit=0;bit<(1<<n);bit++){
    vll ch(m);
    ll cu=0;
    rep(i,n){
      if(bit&(1<<i)){
        cu+=c[i];
        rep(j,m){
          ch[j]+=a[i][j];
        }
      }
    }
    bool ok=true;
    rep(i,m){
      if(ch[i]<x) ok=false;
    }
    if(ok){
      ans=min(ans,cu);
    }
  }
  if(ans==INF) ans=-1;
  COUT(ans);
}

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

int main(){
  int n,m; cin>>n>>m;
  vector<int> num(n+1,0);
  for(int i=0;i<m;i++){
    int x,y; cin>>x>>y;
    num[x]++; num[y]++;
    if(num[x]==2) num[x]-=2;
    if(num[y]==2) num[y]-=2;
  }
  sort(num.begin(),num.end());
  auto itr=lower_bound(num.begin(),num.end(),1);
  if(itr==num.end()){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int, int>
#define int              long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

const int inf = 1e6;
const int cont = 1e18;
const int mod = 1e9+7;
using namespace std;

void solve(){
    int n;
    string s = "ACL";
    cin>>n;
    for(int i=0; i<n; i++)cout<<s;
}

int32_t main() {
    Fast;
    solve();
    return Okay;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main (){
  int N;
  vector <int> vec(200);
  cin >> N;
  for (int i = 0;i < N;i++){
  cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  cout << vec.at(199)-vec.at(200-N);
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
m=int(input())
B=list(map(int,input().split()))

def ES(x,y):
  if x==n: S[y]=1
  else:
    ES(x+1,y)
    if y+A[x]<=2000:
      ES(x+1,y+A[x])
     
S=[0 for i in range(2001)]
ES(0,0)
for i in range(m):
  if S[B[i]]==1: print("yes")
  else: print("no")
    


Measured memory_bytes: 5640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
int main(){
    string s; cin >> s;
    ll n = s.size();
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    ll l=0,r=n-1;
    while(true){
        if(s[l]!='x'&&s[r]=='x'){
            s.insert(s.begin()+l,'x');
            l++;
        }
        else if(s[l]=='x'&&s[r]!='x'){
            s.insert(s.begin()+r+1,'x');
            l++;
        }
        else if(s[l]==s[r]){
            l++;
            if(r!=l) r--;
        }
        else if(s[l]!=s[r]){
            cout << -1 <<  endl;
            return 0;
        }
        if(l==r) break;
    }
    cout << s.size()-n << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	char s[n + 1];
	char abc[] = "ABC";
	scanf("%s", s);
	int result = 0;
	REP(i, n) {
		REP(j, 4) {
			if(j == 3) {
				result++;
				break;
			}
			if(i + j >= n) {
				break;
			}
			if(s[i + j] != abc[j]) {
				break;
			}
		}
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inv(n) qpow(n, M-2)
using namespace std;

const long long M = 1000003;
typedef long long ll;

int fact[M];

int qpow(long long a, int n) {
	return (n?(qpow(a*a%M, n/2)*(n%2?a:1)):1)%M;
}

int main() {
	fact[0] = 1;
	for (int i = 1; i < M; ++i)
		fact[i] = (ll)fact[i-1]*i%M;

	int q, x, d, n;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d", &x, &d, &n);
		if (d == 0) printf("%d\n", qpow(x, n));
		else {
			int l = (ll)x*inv(d)%M, r = l+(n-1);
			if (r >= M) puts("0\n");
			else printf("%lld\n", (ll)fact[r]*inv(fact[l-1])%M*qpow(d, n)%M);
		}
	}
}


Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String arr[] = 
			{"SUN","MON","TUE","WED","THU","FRI","SAT" };
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int a = 0;
		for(int i = 0 ; i < arr.length ; ++i) {
			if(arr[i].equals(S)) {
				a = i;
			}
		}
		a = 7 - a;
		System.out.println(a);
		
	}
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)


typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

//////////////////////////////////////////


void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; 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;
   }
}

long long N, M, a[100009][3], maxn = -(1LL << 60);
void Input() {

    cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
}



void Solve() {




    for(int i = 0; i < 8; i++) {

        vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}

        sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());

        long long ans = 0;
        for(int j = 0; j < M; j++) {

            ans += vec[j];

        }

        maxn = max(maxn, ans);



    }

    cout << maxn << endl;

}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



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

signed main(){

    
    string str , ans;
    cin >> str;
    
    if(str == "Cloudy"){
        ans  = "Rainy";
    }else if (str == "Rainy"){
        ans = "Sunny";
    }else if(str == "Sunny"){
        ans = "Cloudy";
    }
    cout << ans <<endl;
  	cerr << "hello" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstring>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <map>
#include <unordered_map>
#include <vector> 
#include <bitset>
#include <cctype>
#include <set>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#include <random>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN = 2005;
const int MAXM = 50005;
const double EPS = 1e-8;
const ll MOD = 1e9+7;

#define MP make_pair
#define INF 0x3f3f3f3f
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mst(X,Y) memset(X,Y,sizeof(X)) 
#define rep(i, a, n) for (int i=(a); i<=(n); i++)
#define per(i, a, n) for (int i=(a); i>=(n); i--)
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template <typename T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H);    debug_out(T...);}
template <typename T, typename T1> inline T qpower(T x, T p, T1 mod) { T re = 1; x %= mod; while (p) { if (p & 1)re = (re * x) % mod; x = (x * x) % mod; p >>= 1; }return re; }

ll dp[MAXN][MAXN];
void solve()
{
    int n;
    cin >> n;
    int len1 = n / 3; 
    rep (i,3,n)
        dp[1][i] = 1;
    rep (i,2,len1)
    {
        rep (j,(i-1)*3,n-3)
        {
            rep (k,j+3,n)
            {
                dp[i][k] += dp[i-1][j];
                dp[i][k] %= MOD;
            }
        }
    }
    ll ans = 0;
    //debug(dp[2][7]);
    rep (i,1,len1)
    {
        ans = (ans + dp[i][n])%MOD;
    }
    cout << ans << endl;
}


int main()
{closeSync;
#ifdef DEBUG
	//freopen("C:/Users/86159/Desktop/a2.in.txt", "r", stdin);
	//freopen("C:/Users/86159/Desktop/output.txt", "w", stdout);
#endif
	//clock_t c1 = clock();

    // int T;
    // cin >> T;
    // while (T--)
        solve();

    //cerr << "Time:" << clock() - c1 << "ms" <<endl;
    return 0;
}

Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	vi x(n);
	REP(i, n) cin >> x[i];
	sort(ALL(x));
	vector<vi> v(m);
	for(auto i : x)
	{
		v[i % m].push_back(i);
	}
	vi p(m);
	REP(i, m)
	{
		REP(j, v[i].size() - 1)
		{
			if (v[i][j] == v[i][j + 1])
			{
				p[i]++;
				j++;
			}
		}
	}
	int ans = 0;
	ans += v[0].size() / 2;
	if (m % 2 == 0) ans += v[m / 2].size() / 2;
	FOR(i, 1, (m+1) / 2)
	{
		int j = m - i;
		int a = v[i].size(), b = v[j].size();
		if (a >= b)
		{
			ans += b;
			int np = a - 2 * p[i];
			if (np >= b) ans += p[i];
			else ans += (a - b) / 2;
		}
		else
		{
			ans += a;
			int np = b - 2 * p[j];
			if (np >= a) ans += p[j];
			else ans += (b - a) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    string s;
    cin >> s;
    auto i = 0;
    auto bi = s.size()-1;
    auto ans = 0;
    while(i < bi) {
        if(s[i] == s[bi]) {
            i++;
            bi--;
            continue;
        }
        if(s[i] != 'x' && s[bi] != 'x' && s[i] != s[bi]) {
            cout << -1 << endl;
            return;
        }
        if((s[i] == 'x' || s[bi] == 'x') && s[i] != s[bi]) {
            if(s[i] == 'x') i++;
            if(s[bi] == 'x') bi--;
            ans++;
            continue;
        }
    }
    cout << ans << endl;

}

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

Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int main(void){
    int A, B, C;
    cin >> A >> B;
    if(A<B){
        cout << B+(B-1) << endl;
    }else if(A>B){
        cout << A+(A-1) << endl;
    }else  {
        cout << A+B << endl;
    }
}

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

int n;
long long s[200010],ans,a[100010],b[100010],c[200010];
int main()
{
 scanf("%d",&n);
 long long ji1=0,ji2=0;
 for(int i=1;i<=n;++i)
 {
  scanf("%lld%lld",&a[i],&b[i]);
  c[i]=a[i];
  c[i+n]=b[i];
  ji1+=a[i];
  ji2+=b[i];
 }
 ans=min(ji1,ji2);
 sort(c+1,c+2*n+1);
 for(int i=1;i<=n;++i)
 s[i]=s[i-1]+c[i];
 for(int i=1;i<=n;++i)
 {
  long long x=a[i],y=b[i];
  if(x>y)
  swap(x,y);
  if(lower_bound(c+1,c+2*n+1,x)-c<=n-2)
  {
   if(lower_bound(c+1,c+2*n+1,y)-c<=n-1)
   ans=min(ans,s[n]);
   else
   ans=min(ans,y+s[n-1]);
  }
  else
  ans=min(ans,x+y+s[n-2]);
 }
 printf("%lld\n",ans);
 return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1e18;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n, W, V = 0;
    cin >> n >> W;
    
    int w[n], v[n];
    forn(i, 0, n) {
        cin >> w[i] >> v[i];
        V += v[i];
    }
    
    ll dp[n+1][V+1] = {};
    forn(j, 1, V+1) {
        dp[0][j] = INF;
    }
    forn(i, 0, n) {
        forn(j, 1, V+1) {
            ll a = dp[i][j];
            ll b = (j-v[i] >= 0) ? dp[i][ j-v[i] ] + w[i] : INF;
            dp[i+1][j] = min(a, b);
        }
    }
    
    for (int j = V; j >= 0; --j) {
        if (dp[n][j] <= W) {
            cout << j << endl;
            break;
        }
    }
}


Measured memory_bytes: 82404