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

vector<int> edges[100000];

int dfs(int i, int prev){
    int ret = 0;
    for(auto j : edges[i]){
        if(j != prev) ret ^= dfs(j, i) + 1;
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N-1; i++){
        int x, y;
        cin >> x >> y;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }

    int gr = dfs(0, -1);
    cout << (gr!=0 ? "Alice" : "Bob") << endl;
    return 0;
}

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

int main(){
    int n,a,mx=0,mn=1000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        mx=max(mx,a);
        mn=min(mn,a);
    }
    cout<<mx-mn<<endl;
    return 0;
}

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

void print_vec(std::vector<int> v)
{
  std::vector<int>::iterator itr;
  for(itr=v.begin(); itr!=v.end(); itr++)
  {
    cout << *itr << " ";
  }
  cout << endl;
}

int main()
{
  int n,q;
  cin >> n >> q;
  std::vector<int> v;
  int tmp = 0;
  bool flag = 0;
  string S;
  cin >> S;
  for(int i=0; i<n; i++)
  {
    if(S[i] == 'A'){
      flag = 1;
    } else if(S[i] == 'C'){
      tmp += flag;
      flag = 0;
    } else {
      flag = 0;
    }
    v.push_back(tmp);
  }
  int l,r;
  for(int i=0; i<q; i++)
  {
    cin >> l >> r;
    cout << v[r-1]-v[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1528
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&01
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N;
    cin>>N;
    vector<ll> orig(N);
    vector<ll> pu,mi;
    for(auto&& t:orig){
        cin>>t;
        if (t>=0) pu.push_back(t);
        else mi.push_back(t);
    }
    auto aaa_func = [&](){
        auto pu2=pu;
        auto mi2=mi;
        ll ans=0;
        for(int i=1;i<pu.size();++i){
            mi[0] -= pu[i];            
        }
        for(int i=1;i<mi.size();++i){
            pu[0] -= mi[i];
        }
        cout<<pu[0]-mi[0]<<endl;

        for(int i=1;i<pu2.size();++i){
            cout<<mi2[0]<<" "<<pu2[i]<<endl;            
            mi2[0] -= pu2[i];            
        }
        for(int i=1;i<mi2.size();++i){
            cout<<pu2[0]<<" "<<mi2[i]<<endl;
            pu2[0] -= mi2[i];
        }
        cout<<pu2[0]<<" "<<mi2[0]<<endl;
    };
    if (pu.size()!=0 && mi.size()!=0){
        aaa_func();
        return 0;
    }


    sort(orig.begin(),orig.end());
    auto tbl=orig;
    auto tbl2=tbl;

    while(tbl.size()>2){
        tbl[0] -= tbl.back();
        tbl.pop_back();
    }
    ll ans=tbl[1]>tbl[0]?tbl[1]-tbl[0]:tbl[0]-tbl[1];
    //cout<<ans<<endl;

    reverse(tbl2.begin(),tbl2.end());
    while(tbl2.size()>2){
        tbl2[0] -= tbl2.back();
        tbl2.pop_back();
    }
    ll ans2=tbl2[1]>tbl2[0]?tbl2[1]-tbl2[0]:tbl2[0]-tbl2[1];
    //cout<<ans2<<endl;

    if(ans>=ans2){
        cout<<ans<<endl;
    } else {
        cout<<ans2<<endl;
        reverse(orig.begin(),orig.end());
    }
    while(orig.size()>2){
        cout<<orig[0]<<" "<<orig.back()<<endl;
        orig[0] -= orig.back();
        orig.pop_back();
    }
    if(orig[1]>orig[0]){
        cout<<orig[1]<<" "<<orig[0]<<endl;
    } else {
        cout<<orig[0]<<" "<<orig[1]<<endl;
    }
#if 0
    ll N;
    cin>>N;
    vector<ll> pl;
    vector<ll> mi;
    for(int i=0;i<N;++i){
        ll a;
        cin>>a;
        if(a>=0) pl.push_back(a);
        else mi.push_back(a);
    }
    sort(pl.begin(),pl.end());
    sort(mi.begin(),mi.end());
    ll ans=0;
    if(pl.size()==0){
    } else if(mi.size()==0){
    }
#endif
    return 0;
}

Measured memory_bytes: 5108
// https://atcoder.jp/contests/arc069/tasks/arc069_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    bitset<100005> a, s;
    REP(i, n) {
        char c;
        cin >> c;
        if (c == 'x')
            s.set(i);
    }
    s[n] = s[0], s[n + 1] = s[1];
    REP(i, 4) {
        a[0] = i & 1, a[1] = (i >> 1) & 1;
        FOR(j, 2, n + 2) a[j] = s[j - 1] ^ a[j - 1] ^ a[j - 2];
        if (a[0] == a[n] && a[1] == a[n + 1]) {
            REP(j, n) cout << (a[j] ? "W" : "S");
            cout << "\n";
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(26,0));
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        for(int j = 0; j < s.length(); j++){
            int c = (int)(s[j] - 'a');
            a[i][c]++;
        }
    }

    for(int i = 0; i < 26; i++){
        int minC = 100;
        for(int j = 0; j < n; j++){
            minC = min(minC, a[j][i]);
        }
        for(int k = 0; k < minC; k++){
            cout << (char)('a' + i);
        }
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));

$flag = 1;
$count = 0;
while ($flag) {
    $flag = 0;
    for ($i = count($a) - 1; $i > 0; $i--) {
        if ($a[$i] < $a[$i - 1]) {
            $t = $a[$i];
            $a[$i] = $a[$i - 1];
            $a[$i - 1] = $t;
            $flag = 1;
            $count++;
        }
    }
}

echo implode(' ', $a) . PHP_EOL;
echo $count . PHP_EOL;


Measured memory_bytes: 9256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] abc = br.readLine().split(" ");
		br.close();

		int ab = Integer.parseInt(abc[0]);
		int bc = Integer.parseInt(abc[1]);
		System.out.println(ab * bc / 2);
	}
}


Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],c[200010],B[200010],A[200010],b[200010],fa[200010],s[200010];
int ans;
int w,Sum,x,y,tot;
inline int read(){
    char ch;
    bool f=false;
    int res=0;
    while (((ch=getchar())<'0'||ch>'9')&&ch!='-');
    if (ch=='-')
        f=true;
    else 
        res=ch-'0';
    while ((ch=getchar())>='0'&&ch<='9')
        res=(res<<3)+(res<<1)+ch-'0';
    return f?~res+1:res;
}
int find(int x){
    if (fa[x]==x)
        return x;
    int y=find(fa[x]);
    fa[x]=y;
    return fa[x];
}
int main(){
    //freopen("duliu.in","r",stdin);
	//freopen("duliu.out","w",stdout);
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        x^=a[i];
        A[i]=a[i];
    }
    a[n+1]=x;
    A[n+1]=x;
    for (int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        y^=b[i];
        B[i]=b[i];
    }
    b[n+1]=y;
    B[n+1]=y;
    n++;
    sort(B+1,B+1+n);
    sort(A+1,A+1+n);    
    for (int i=1;i<=n;i++)
        if (A[i]!=B[i]){
            printf("-1\n");
            return 0;
        }
    for (int i=1;i<=n;i++)
        if (a[i]!=b[i]||i==n){
            c[++tot]=a[i];
            c[++tot]=b[i];
            if (i<n){
                ans++;
            }
        }
    if (ans==0){
        printf("0\n");
        return 0;
    }
    sort(c+1,c+tot+1);
    tot=unique(c+1,c+tot+1)-c-1;
    
    for (int i=1;i<=tot;i++)
        fa[i]=i;
    for (int i=1;i<=n;i++)
        if (a[i]!=b[i]){
            a[i]=lower_bound(c+1,c+tot+1,a[i])-c;
            b[i]=lower_bound(c+1,c+tot+1,b[i])-c;
            if (!s[a[i]])
                s[a[i]]=1;
            if (!s[b[i]])
                s[b[i]]=1;
            fa[find(a[i])]=find(b[i]);
        }
    for (int i=1;i<=tot;i++)
        if (fa[i]==i)
            Sum++;
    printf("%d\n",ans+Sum-1);
    fclose(stdin);
    fclose(stdout);
    return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S;
    cin>>S;
    int aid=S.size(),zid=0;
    
    rep(i,S.size()){
        if(S.at(i)=='A'){
            aid=min(i,aid);
        }
        if(S.at(i)=='Z'){
            zid=i;
        }
    }
    cout << zid-aid+1 << endl;
    return 0;
}

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

int main() {
  long long counter = 0;
  long long n, a, b;
  cin >> n >> a >> b;

  vector<int> towns(n);

  for (int i = 0; i < n; i++) {
    cin >> towns[i];
  }

  for (int i = 1; i < n; i++) {
    long long distance = (towns[i] - towns[i - 1]) * a;
    counter += min(distance, b);
  }

  cout << counter;
  return 0;
}


Measured memory_bytes: 640
// AtCoder ABC105: B - Cakes and Donuts
// 2019.9.11 bal4u

#include <stdio.h>

int dp[110];

int main()
{
	int i, N;
	
	scanf("%d", &N);
	dp[0] = 1;
	for (i = 0; i <= 100; i++) if (dp[i]) dp[i+4] = 1;
	for (i = 0; i <= 100; i++) if (dp[i]) dp[i+7] = 1;
	puts(dp[N]? "Yes": "No");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
   string str;
   cin >> str;
   for(int i=0; i<str.length(); i++)
   {
       if(i%2==1 && str[i]=='R')
        {cout<<"No";
        return 0;}
       if(i%2==0 && str[i]=='L')
        {cout<<"No";
        return 0;}
    }
      cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
//		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		long K = sc.nextLong();
		int Q = sc.nextInt();
		int A[] = new int[Q];

		getAnswer(N,K,Q) ;
		//System.out.println(ans);
	}

	public void getAnswer(int N, long K, int Q) {
		int point[] = new int[N];

		for(int i = 0 ; i < Q; i ++) {
			int A = sc.nextInt();
			point[A-1] += 1;
		}
		for(int i = 0 ; i < N ; i ++) {
			long ans = point[i] + K - Q ;
			if(ans > 0 ) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}


	}


}


Measured memory_bytes: 64936
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <functional>
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin >> n;
    ll d,a;
    cin >> d >> a;
    
    vector<pair<ll,ll>> pos(n);

    for(int i = 0;i < n;i++){
        cin >> pos[i].first >> pos[i].second;
    }

    sort(pos.begin(),pos.end());
    queue<pair<ll,ll>> que;//あとで保証する.
    d *= 2;
    ll tot = 0;
    ll ans = 0;
    for(int i = 0;i < n;i++){
        ll x = pos[i].first;
        ll h = pos[i].second;
        while(que.size() && que.front().first < x){
            tot -= que.front().second;
            que.pop();
        }
        h -= tot;
        if(h > 0){
            ll num = (h+a-1)/a;
            ans += num;
            ll damage = num * a;
            tot += damage;
            que.emplace(x+d,damage);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <functional>
#include <set>
#include <iterator>

using namespace std;
typedef long long ll;
int X;

int main() {
   cin >> X;
   switch(X) {
      case 3:
      case 5:
      case 7:
         cout << "YES" << endl; break;
      default:
         cout << "NO" << endl; break;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,e=0;
    scanf("%d %d",&n,&m);
    int a[m];
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
        e+=a[i];
    }
    if(n-e<0){
        printf("-1");
    }else{
        printf("%d",n-e);
    }
    return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int mod = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int table[3001] = {0};
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    rep(i, n) {
        for (int j = 2000; j >= 0; --j) {
            if (j == 0 || table[j]) table[j + a[i]] = 1;
        }
    }
    cin >> n;
    rep(i, n) {
        int b; cin >> b;
        if (table[b]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



Measured memory_bytes: 3188
def gcd(a, b):
    while b: a, b = b, a % b
    return a

a,b=map(int,input().split())
b//=gcd(a,b)
a,c=2,1
while a*a<=b:
    if b%a==0:
        c*=a
        while b%a==0:b//=a
    a+=1
print([c*b,c][b==1])

Measured memory_bytes: 7640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
string S, T; cin >> S >> T; int m=S.size(), n=T.size();
S=S+T[n-1];
if(S==T){ cout << "Yes\n"; }else{ cout << "No\n"; }
}

Measured memory_bytes: 3628
while True:
    n = int(input())
    if n == 0:
        break
    dp = [0] * (n + 1)
    dp[0] = 1
    if n <= 3:
        print(1)
    else:
        dp[1] = 1
        dp[2] = 2
        for i in range(3, n + 1):
            dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1]
        print(dp[-1] // (365 * 10) + 1)



Measured memory_bytes: 5592
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

signed main() {
int a,b;cin>>a>>b;
for(int i=1;i<=20;i++){if(a*i==b){cout<<b+a<<endl;return 0;}}
cout<<b-a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=100005;
int n;
int a[M];
int C[M*10];
int s[M*10];
int lowbit(int i)
{
    return i & -i;//或者是return i-(i&(i-1));表示求数组下标二进制的非0最低位所表示的值
}
void update(int i,int val)//单点更新
{
    while(i<=2*M){
        C[i]+=val;
        i+=lowbit(i);//由叶子节点向上更新树状数组C，从左往右更新
    }
}
ll sum(int i)//求区间[1,i]内所有元素的和
{
    ll ret=0;
    while(i>0){
        ret+=C[i];//从右往左累加求和
        i-=lowbit(i);
    }
    return ret;
}

bool check(int x)
{
    for(int i=1;i<=2*M;i++) C[i]=0;
    s[0]=0;
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+(a[i]>=x?1:-1);
    ll ans=0;
    for(int i=0;i<=n;i++)
    {
        ans+=sum(s[i]+M);
        update(s[i]+M,1);
    }
    return ans>=(ll)n*(n+1)/4;
}



int main()
{
    int l=0,r=0;
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        r=max(r,a[i]);
    }
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))
            l=mid+1;
        else
            r=mid-1;
    }
    cout<<r<<endl;
}


Measured memory_bytes: 6784
/*
ID: essi
LANG: C++
TASK: .cpp
*/

#include <bits/stdc++.h>
using namespace std;
#define sep ios::sync_with_stdio(0),cin.tie(0)
#define ll unsigned long long int
#define all(n) n.begin(), n.end()
const int MXI = 2e5+14;
vector<int> Tree[MXI];

int main() {
    sep;
    int n, u; cin >> n;
    for (int i = 2; i <= n; ++i) {
    	cin >> u;
    	Tree[u].emplace_back(i);
    }
    for (int i = 1; i <= n; ++i)
    	cout << Tree[i].size()<< "\n";
    return 0;
}	

Measured memory_bytes: 14488
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#define ll long long int
using namespace std;
int main(void) {
  double a, b, c, d, e, f;
  double x=0;
  double a_s=0, a_w=0;
  cin>>a>>b>>c>>d>>e>>f;
  for(int i=0; 100*a*i<=f;i++) {
    double aa=100*a*i;
    for(int j=0; aa+100*b*j<=f; j++) {
      double w=aa+100*b*j;
      for(int k=0; c*k<=e*w/100; k++) {
	double cc=c*k;
	for(int l=0; cc+d*l<=e*w/100;l++) {
	  double s=cc+d*l;
	  if(s<=e*w/100 and w+s<=f) {
	    if(x<=100*s/(w+s)) {
	      x=100*s/(w+s);
	      a_s=s;
	      a_w=w;
	    }
	  }
	}
      }
    }
  }
  cout<<a_w+a_s<<" "<<a_s<<endl;
  return 0;
}



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

int main()
{
    int N, M;
    cin >> N >> M;
    int ans;
    ans = N * (N - 1) / 2 + M * (M - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<int>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	vector<int>cache(n,0);
	cache[0]=0;
	cache[1]=abs(v[1]-v[0]);
	int temp=k;
	int mval=INT_MAX,mi=0;
	for(int i=2;i<n;i++)
	{
		k=temp;
		mval=INT_MAX;
		mi=i-1;
		for(int j=i-1;j>=0&&k>0;j--)
		{
			if(mval>cache[j]+abs(v[j]-v[i]))
			{
				mval=cache[j]+abs(v[j]-v[i]);
			}
			k--;
		}
		cache[i]=mval;
	}
	cout<<cache[n-1]<<endl;
}

Measured memory_bytes: 1024
a,b,c=map(int,input().split())
k=int(input())

if a<b and b<c:
	print("Yes")
elif a<b:
	for i in range(1,10):
			c=c*2
			if c>b:
				n=i
				break;
	if n<=k:
		print("Yes")
	else:
		print("No")
else:
	for i in range(1,10):
		b=b*2
		if b>a:
			m=i
			break;
	#print(m)
	for i in range(1,10-m):
		c=c*2
		if c>b:
			n=i
			break;
	#print(n)
	if n+m<=k:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 9212
#include <iostream>
#include <queue>

using namespace std;

const int N = 100;
int n;
int M[N][N], color[N], d[N];

int main(){
  queue<int> q;
  cin >> n;
  int u, k, v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v;
      M[u-1][v-1] = 1;
    }
  }
  for(int i=0;i<n;i++) d[i] = -1;
  d[0] = 0;
  color[0] = 1;
  q.push(0);
  int x;
  while(q.empty() == false){
    x = q.front();
    q.pop();
    for(int i=0;i<n;i++){
      if(M[x][i] == 0) continue;
      if(color[i] == 0){
        color[i] = 1;
        d[i] = d[x] + 1;
        q.push(i);
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << d[i] << endl;
  }
  return 0;
}



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ; 
  int w ;
  cin >> s >> w  ;
  
  rep(i,s.size()){
    if(i % w == 0 ) cout << s.at(i) ;
  }
  
  cout << endl ;
  


}


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

using namespace std;
int min(int a, int b){
	return a < b ? a : b;
}
int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int inf = 1e9 + 7;
	vector<int>dp(n, inf);
	dp[0] = 0;
	for (int i = 0; i < n; i++){
		if (i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
		if (i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i] - a[i + 2]));
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const ll inf = (ll)1e16;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
ll dp[3][40],n,t,ans;
bool compare(pii a, pii b)
{
	return a.fi*(b.se+1) > b.fi*(a.se+1);
}
int main()	
{
	//freopen(file".inp","r",stdin);
	//freopen(file".out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>t;
	vector<pii> arr;
	vector<ll> zero;
	for(int i=0;i<n;i++)
	{
		pii temp;
		cin>>temp.fi>>temp.se;
		if(temp.fi == 0)
			zero.eb(temp.se);
		else
			arr.eb(temp);
	}
	sort(arr.begin(),arr.end(),compare);
	for(int i=0;i<2;i++)
		for(int j=0;j<33;j++)
			dp[i][j] = inf;
	dp[0][0] = 0;
	for(int i=0;i<arr.size();i++)
	{
		for(int j=0;j<33;j++)
			dp[(i+1)&1][j] = inf;
		auto s = arr[i];
		for(int j=0;j<33;j++)
		{
			if(dp[i&1][j]==inf)
				continue;
			dp[(i+1)&1][j] = min(dp[(i+1)&1][j],dp[i&1][j]);
			ll check = (dp[i&1][j]+1)*(s.fi+1)+s.se;
			if(check<=t and j+1<33)
				dp[(i+1)&1][j+1] = min(dp[(i+1)&1][j+1],check);	
		}	
	}
	sort(zero.begin(),zero.end());
	vector<ll> pref(zero.size()+1);
	pref[0] = 0;
	for(int i=0;i<zero.size();i++)
		pref[i+1] = pref[i]+zero[i]+1;
	for(int j=0;j<33;j++)
	{
		ll res = t-dp[arr.size()&1][j];
		if(res<0)
			continue;
		ans = max(ans,(ll)(upper_bound(pref.begin(),pref.end(),res)-pref.begin()+j-1));
	}
	cout<<ans;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e2 + 2;

set<int> s;

int findGrun() {
	for(int i=0;;i++){
		if(!s.count(i)){return i;}
	}
}

int main(){
	int n,k,i,j;
	scanf("%d %d",&n,&k);
	int a[maxn];
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	// grundy number method

	// int grun[100010];
	// grun[0] = 0;
	// for(i=1;i<=k;i++){
	// 	s.clear();
	// 	for(j=0;j<n;j++){
	// 		if(i-a[j] >= 0){
	// 			s.insert(grun[i-a[j]]);
	// 			// printf("diinsert: %d\n",i-a[j]);
	// 		}
	// 	}
	// 	grun[i] = findGrun();
	// 	// printf("grun[%d]: %d\n\n",i,grun[i]);
	// }
	// if(grun[k] == 0){printf("Second\n");}
	// else{printf("First\n");}

	// dp bottom up approach
	// dp[k] = condition that at k stone, if 1 then player 1 win, 0 otherwise
	// approach from i pick condition from back
	// int dp[100010];
	
	// dp[0] = 0;
	// for(i=1;i<=k;i++){
	// 	dp[i] = 0;
	// 	for(j=0;j<n;j++){
	// 		if(a[j] <= i){
	// 			if(dp[i - a[j]] == 0){
	// 				dp[i] = 1;
	// 				break;
	// 			}
	// 		}
	// 	}
	// }
	// printf("%s\n",(dp[k]? "First": "Second"));

	int dp[100010];
	memset(dp, 0, sizeof dp);
	for(i=0;i<=k;i++){
		if(dp[i] == 0){
			for(j=0;j<n;j++){
				if((a[j] + i) <= k){
					dp[a[j] + i] = 1 - dp[i];
				}
			}	
		}
		
	}
	printf("%s\n",(dp[k]? "First": "Second"));
	return 0;
};

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N;cin>>N;
    vector<int> score(N,0);
    int sum=0;
    REP(i,N){
        cin>>score[i];
        sum+=score[i];
    }
    if(sum%10!=0){
        cout<<sum<<endl;
        return 0;
    } else {
        sort(score.begin(),score.end());
        REP(i,N){
            if(score[i]%10!=0){
                cout<<sum-score[i]<<endl;
                return 0;
            }
        }
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
D = (1..N).map{gets.split.map(&:to_i)}.sort_by{|ar| -ar[1]}

group = {}
taste = 0
pool = []
D[0...K].each do |t, d|
  taste += d 
  if group[t]
    pool << d
  else  
    group[t] = true 
  end
end
kind = group.size
pool.sort!

g2 = Hash.new(0)
D[K..-1].each do |t, d|
  if d > g2[t] && group[t].nil?
    g2[t] = d 
  end
end
other = g2.values.sort!.reverse

ans = taste + kind ** 2
(0...[pool.size, other.size].min).each do |i|
  taste += (other[i] - pool[i])
  kind += 1
  score = taste + kind ** 2
  ans = score if score > ans
end 

puts ans

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> p(m);
	rep(i, m) cin >> p.at(i).first >> p.at(i).second;
	rep(i, 1000){
		string st;
		st = to_string(i);
		if(st.size() != n) continue;
		bool flag = true;
		rep(j, m){
			if(st[p.at(j).first-1]-'0' != p.at(j).second){
				flag = false;
				break;
			}
		}
		if(flag == true){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
void Google(ll tt){
    cout<<"Case #"<<tt<<": ";
}
 
int main()
{
    IO
    clock_t begin = clock();
    ll n;
    cin>>n;
    ll a[n+1];
    ll sum = 0;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    vector <vector<ll>> dp(n+5,vector<ll> (n+5,0));
    for(ll _s=1;_s<=n;_s++)
    {
        for(ll i=1;i<=n;i++)
        {
            if((i+_s-1)>n)
                break;
            ll j=i+_s-1;
            if(_s==1)
                dp[i][j]=a[i];
            else if(_s==2)
                dp[i][j]=max(a[i],a[j]);
            else
                dp[i][j]=max(a[i]+min(dp[i+2][j],dp[i+1][j-1]),a[j]+min(dp[i][j-2],dp[i+1][j-1]));
        }
    }
    cout<<(dp[1][n] - (sum - dp[1][n]))<<endl;
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 73980
#n=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
import math
def combinations_count(n,k):#nCkを返す
    if k==0 or k==n:
        return 1
    elif n<k or k<0:
        return 0
    else:
        return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
print(combinations_count(n,2)+combinations_count(m,2))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong h, w, n;
llong a[100005];
llong b[100005];
map<pair<llong, llong>, llong> mp;
map<pair<llong, llong>, int> used;

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

llong cnt(llong y, llong x) {
    llong res = 0;
    for (int i = 0; i < 9; i++) {
        if (y + dy[i] < 1 || y + dy[i] > h ||
            x + dx[i] < 1 || x + dx[i] > w) return 10;
        res += mp.count({y + dy[i], x + dx[i]});
    }

    return res;
}

int main() {
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        mp[{a[i], b[i]}] = 1;
    }

    llong ans[16] = {};
    ans[0] = (h - 2) * (w - 2);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 9; j++) {
            if (used.count({a[i] + dy[j], b[i] + dx[j]})) continue;
            
            used[{a[i] + dy[j], b[i] + dx[j]}] = 1;
            int idx = cnt(a[i] + dy[j], b[i] + dx[j]);
            if (idx <= 9) {
                ans[idx]++;
                ans[0]--;
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 64256
n, a, b = map(int, input().split())
sum_num = a + b
if a == 0:
  print(0)
else:
  iter_num = int(n/sum_num)
  rest = n - iter_num * sum_num
  if rest >= a:
    print(a * iter_num + a)
  else:
    print(a * iter_num + rest)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

int main() {
  int word_len, word_num;
  cin >> word_num >> word_len;
  string words[word_num];
  for (int i = 0; i < word_num; i++) {
    cin >> words[i];
  }
  for (int i = 0; i < word_num - 1; i++) {
    for (int j = word_num - 1; j > i; j--) {
      if (words[i] > words[j]) {
        string tmp = words[j];
        words[j] = words[i];
        words[i] = tmp;
      }
    }
  }
  for (int i = 0; i < word_num; i++) {
    cout << words[i];
  }
  puts("");
}



Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 2/27
// Problem:ABC 079 LucasNumber b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

ll memo[100];

ll Luca(int i)
{
  if (i == 0) return 2;
  if (i == 1) return 1;
  if (memo[i] != -1) return memo[i];
  return memo[i] = Luca(i - 1) + Luca(i - 2);
}

int main()
{
  int N;
  memset(memo, -1, sizeof(memo));
  cin >> N;
  cout << Luca(N) << endl;
  return 0;
}



Measured memory_bytes: 256
use std::io;

fn main() {
    let mut inputword = String::new();
    io::stdin().read_line(&mut inputword).unwrap();

    let mut splited : Vec<i32> = inputword.split_whitespace().map(|x| x.parse().ok().unwrap()).collect();
    splited.sort();
    println!("{} {} {}", splited[0], splited[1], splited[2]);
}



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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String a = br.readLine();
        System.out.println(problem171a(a));
    }

    private static String problem171a(String a) {
        return (a.equals(a.toLowerCase())) ? "a" : "A";
    }
}

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

long long dp[10][1001];

int main(){
	dp[0][0] = 1;
	for(int i = 0; i <= 100; ++i){
		for(int j = 1000; j >= i; --j){
			for(int k = 9; k > 0; --k){
				dp[k][j] += dp[k-1][j-i];
			}
		}
	}
	
	int n, s;
	while(cin >> n >> s, n){
		cout << dp[n][s] << '\n';
	}
}

Measured memory_bytes: 1228
def main():
    # 下、右、上、左
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "#" == s[y + dy][x + dx]:
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int main(){
    int N, K;
    cin >> N >> K;
    
    int limit = (N - 1) * (N - 2) / 2;
    if(K > limit){
        cout << -1 << endl;
        return 0;
    }
    
    cout <<  N - 1 + limit - K << endl;
    
    for(int i = 1; i < N; ++i){
        cout << i << " " << N << endl;    
    }
    
    if(K == limit)      return 0;
    
    vector<P> candidates;
    int cnt = 0;
    for(int i = 1; i < N; ++i){
        for(int j = i; j < N; ++j){
            if(i == j)      continue;
            
            candidates.push_back(P(i, j));
            cnt++;
            
            if(cnt == limit - K)    break;
        }
        if(cnt == limit - K)        break;
    }
    
    for(int i = 0; i < candidates.size(); ++i){
        P p = candidates[i];
        cout << p.first << " " << p.second << endl;
    }
}

Measured memory_bytes: 384
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let n: usize = read();
    let mut h = Vec::<usize>::new();
    for i in 0..n {
        h.push(read());
    }
    for i in 1..n {
        if h[i - 1] < h[i] {
            h[i] -= 1;
        } else if h[i - 1] > h[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4476
MOD = 10**9 + 7

r1, c1, r2, c2 = map(int, input().split())

def getFact(n, MOD):
    fact = 1
    for i in range(1, n+1):
        fact = (fact * i) % MOD
    return fact
def getFacts(n, MOD):
    facts = [1] * (n+1)
    for x in range(2, n+1):
        facts[x] = (facts[x-1] * x) % MOD
    return facts
def getInvFacts(n, MOD):
    invFacts = [0] * (n+1)
    invFacts[n] = pow(getFact(n, MOD), MOD-2, MOD)
    for x in reversed(range(n)):
        invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
    return invFacts

facts = getFacts(2*10**6+3, MOD)
invFacts = getInvFacts(10**6+3, MOD)

def f(r, c):
    ans = facts[r+c] * invFacts[r] * invFacts[c]
    return ans % MOD

#print(f(r2+1, c2+1), f(r2+1, c1), f(r1, c2+1), f(r1, c1))
ans = f(r2+1, c2+1) - f(r2+1, c1) - f(r1, c2+1) + f(r1, c1)
ans %= MOD

print(ans)


Measured memory_bytes: 121716
from collections import defaultdict, Counter
from itertools import product, groupby, combinations
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right

INF = 10 ** 10


class Combination:
    def __init__(self, n, mod):
        assert 0 < n
        self.mod = mod
        self.fact = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for i in range(1, len(self.fact)):
            self.fact[i] = (i * self.fact[i - 1]) % self.mod
            self.inv[i] = pow(self.fact[i], self.mod - 2, self.mod)

    def nCr(self, n, k):
        assert 0 < n < len(self.fact) and 0 <= k, (n, k)
        a = self.fact[n]
        b = (self.inv[k] * self.inv[n - k]) % self.mod
        return a * b % self.mod


def main():
    MOD = 10 ** 9 + 7
    n = int(input())
    a_list = list(map(int, input().split()))

    dual = Counter(a_list).most_common(1)[0][0]
    pre, post = [i for i, a in enumerate(a_list) if a == dual]
    x = pre + (n - post)

    comb = Combination(10 ** 5 + 1, MOD)
    for i in range(1, n + 2):
        a, b = comb.nCr(n + 1, i), 0
        if i == 1:
            b = 1
        elif 0 < x and i - 1 <= x:
            b = comb.nCr(x, i - 1)
        print((a - b) % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 19928
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll mypow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1) res = res*a;
        a = a*a;
        n >>= 1;
    }
    return res;
}
void solve(){
    ll n, k; cin >> n >> k;
    cout << k*mypow(k-1, n-1) << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
vector<pll> ps;
bool used[114514];
int cnt[2];

int main() {
  scanf("%d", &N);
  reps(i, 1, N+1) {
    LL A, B;
    scanf("%lld%lld", &A, &B);
    ps.eb(pll(A, i*2));
    ps.eb(pll(B, i*2+1));
  }
  sort(all(ps));

  LL cand = 0;
  bool ok = false;
  rep(i, N) {
    LL v = ps[i].X;
    int sidx = ps[i].Y;
    int idx = sidx/2;
    
    cand += v;
    if (used[idx]) {
      ok = true;
    } else {
      cnt[sidx%2]++;
    }
    used[idx] = true;
  }

  if (cnt[0] == 0 || cnt[1] == 0) ok = true;
  
  LL ans = 0x3fffffffffffffLL;
  if (!ok) {
    rep(i, N) {
      LL t = cand;
      t -= ps[i].X;
      if (ps[i].Y/2 == ps[N].Y/2) t += ps[N+1].X;
      else t += ps[N].X;
      MN(ans, t);
    }
  } else ans = cand;

  printf("%lld\n", ans);
}


Measured memory_bytes: 6512
#include<stdio.h>
#include<stdlib.h>
#define MAX 100010

typedef int long long int64;

#define int int64

int main()
{
    int n,isPlus=0;
    int i,j;
    int a[MAX],r[MAX];
    scanf("%d",&n);

    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i+1);
    }
    //A_1を求める
    int x=2*a[1];
    for(i=2;i<n;i++)
    {
        if(isPlus)x+=(2*a[i]);
        else x-=(2*a[i]);

        isPlus=!(isPlus);
        //printf("%d ",x);
    }

    for(j=1;j<=n;j++)
    {
        if(j==1)r[1]=(x+2*a[n])/2;
        else r[j]=2*a[j-1]-r[j-1];

        printf("%d ",r[j]);
    }


}



Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

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 reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    red = []
    for _ in range(N):
        a, b = map(int, input().split())
        red.append([a, b, 0])

    blue = []
    for _ in range(N):
        a, b = map(int, input().split())
        blue.append([a, b, 1])

    rb = red + blue
    rb.sort(key = lambda x: x[0])
    # print(rb)

    used = set()
    count = 0
    for i in range(2*N):
        if rb[i][2] == 1:
            min_j = None
            max_y = -1
            for j in range(i):
                if rb[j][2] == 0 and j not in used:
                    if max_y < rb[j][1] < rb[i][1]:
                        max_y = rb[j][1]
                        min_j = j
            if min_j != None:
                # print(i, min_j)
                used.add(min_j)
                count += 1
    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3316
import sys
#import copy
#import math
#import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
mod = 1000000007

#read = sys.stdin.buffer.read

def main():
    # input
    N, K = map(int, readline().split())

    if K == N+1:
        print(1)
        return

    #ans0 = 0
    #ans1 = 0
    ans = 0
    for k in range(K, N+2):
        maxsum0 = (k * (2 * N - k + 1)) // 2
        #maxsum1 = ((k - 1) * (2 * N - k + 2)) // 2
        #minsum0 = (k * (k + 1)) // 2
        minsum1 = ((k - 1) * k) // 2
        #ans0 += maxsum0 - minsum0 + 1
        #ans1 += maxsum1 - minsum1 + 1
        ans += maxsum0 - minsum1 + 1

    ans = ans % mod
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

bool comp(pair<int,int> p1,pair<int,int> p2)
{
    if(p1.ff!=p2.ff)
        return p1.ff<p2.ff;
    else
        return p1.ss<p2.ss;
}

int32_t main()
{                
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int a,b;
    cin>>a>>b;
    if(a+b==15)
    {
        cout<<"+";
    }
    else
        if(a*b==15)
            cout<<"*";
    else
        cout<<"x";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
#define ll long long 

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string n;
	cin >> n;
	
	ll sum = 0;
	for(char c : n)
		sum += c-'0';
	
	if(sum % 9 == 0)
	cout << "Yes\n";
	else
	cout << "No\n";
}


Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

int a, b, c;




int main() {
	
	cin >> a >> b >> c;
	if (a == b || a == c || b == c) {
		if (a == b && b == c) {
			cout << "No" << endl;
		}
		else cout << "Yes" << endl;
	}
	else cout << "No" << endl;
 



	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

ll n,a,b,l,r,F;

int main()
{
	cin>>n>>a>>b>>l>>r; n--;
	for(ll i=0;i<=n;i++)
	{
		ll L=a-i*r+(n-i)*l;
		ll R=a-i*l+(n-i)*r;
		if(b>=L&&b<=R) F=1;
	}
	if(F) puts("YES"); else puts("NO");
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll pow(ll x,ll y){
	ll ret = 1LL;
	rep(i,y) ret *= x;
	return ret;
}

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

	ll n,m;
	cin >> n >> m;

	cout << (((n-m)*100 + m*1900)*pow(2,m)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a[25];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		int b = 0,c=32;
		while (c > 0) {
			c -= ((c-1) % 5);
			cout << c << endl;
			if (c < a[b]) {
				cout << 0 << endl;
				c = 0;
				break;
			}
			c -= a[b];
			b++;
			if (b >= n) b = 0;
			cout << c<<endl;
		}
	}
}

Measured memory_bytes: 3064
from sys import stdin, stdout

x = list(map(int, stdin.readline().split())) 
y = [x[0]-x[1], x[1]-x[2], x[2]-x[0]]
count = 0
for i in range(3):
  if y[i] == 0:
    count += 1

if count == 1:
  stdout.write("Yes")
else:
  stdout.write("No")

Measured memory_bytes: 3060