akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) { cin >> A[i]; }
  deque<ll> d;
  REP(i, N) {
    ll p = lower_bound(ALL(d), A[i]) - d.begin();
    if (p == 0) {
      d.push_front(A[i]);
    } else {
      d[p - 1] = A[i];
    }
  }
  cout << d.size();
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;

const int MAXN = 1000;

char lab[MAXN][MAXN];
bool v[MAXN][MAXN];
int matrix[MAXN][MAXN];

int h, w;

int recursion(int x, int y){
    if(x>=h || y>=w) return 0;
    if(lab[x][y]=='#') return 0;
    if(x==h-1 && y==w-1) return matrix[x][y]=1;
    if(v[x][y]) return matrix[x][y];
    v[x][y]=1;
    return matrix[x][y] = (recursion(x+1,y) + recursion(x,y+1)) % (1000000007);
}

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

    cin >> h >> w;

    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++)
            cin >> lab[i][j];

    cout << recursion(0,0) << '\n';

    return 0;
}



Measured memory_bytes: 6272
#include <iostream>
using namespace std;
int main(){
  int K,S;
   cin >> K;
  cin >>S;
  int ans = 0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      if(S-i-j<=K && (S-i-j>=0))
	   ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int a, b, k, i, n;
    std::cin >> a >> b >> k;
    for (i = a; i <= b; i++) {
        if (i < a+k || i > b-k) {
            std::cout << i <<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in(),k=in();
    string s=stin();
    rep(i,n){
        if(i!=k-1)cout<<s.at(i);
        else{
            char c='a'-'A';
            char x=c+s.at(i);
            cout<<x;
        }
    }
    cout<<endl;
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
class segtree {
 private:
  int n;
  vector<T> data, lazy;

 public:
  segtree(int n_) {
    n = pow(2, ceil(log2(n_)));
    data.resize(n);
    lazy.resize(n);
    auto __x = data[0];
    repi(n) {
      data[i] = __vmin(__x);
      lazy[i] = 0;
    }
  }
};

ll a[100100];
ll re[100100];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> a[i];
  repi(n) re[0] += i % 2 ? -a[i] : a[i];
  repr(i, 1, n) re[i] = 2 * a[i - 1] - re[i - 1];
  cout << re[0];
  repr(i, 1, n) cout << " " << re[i];
  cout << endl;
}


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

#define M 3000
#define ll long long

ll N,v[M],dp[M][M],sum;

inline ll sol (int i, int j, long long sum)
{
	if(i==j) return dp[i][j]=v[i];
	if(dp[i][j]!=-1) return dp[i][j];
	
	return dp[i][j]=max(sum-sol(i+1,j,sum-v[i]),sum-sol(i,j-1,sum-v[j]));
}


int main ()
{
	cin >> N;
	for(int i=0; i<N; i++) { cin >> v[i]; sum+=v[i]; }
	for(int i=0; i<M; i++) for(int j=0; j<M; j++) dp[i][j]=-1;
	cout << sol(0,N-1,sum) - (sum - dp[0][N-1]);
}

Measured memory_bytes: 70784
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();
        s = s.replaceAll("ABC", "");
        int ans = (n - s.length()) / 3;

        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}
		scan.close();
	}

}


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

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
int pre[2][100005] ;
int main(int argc,char* argv[]) { 
    io() ;
    #ifndef ONLINE_JUDGE
      //  freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    string s,t ;
    cin >> s >> t ;
    int n = s.length() ;
    int m = t.length() ;
    s = " " + s ;
    t = " " + t ;
    int q ;
    cin >> q ;
    int a,b,c,d ;
    for(int i = 1 ; i <= n ; i++){
    	pre[0][i] = pre[0][i-1] + ((s[i] == 'A')?1:2) ;
    	pre[0][i] %= 3 ;
    }
    for(int i = 1 ; i <= m ; i++){
    	pre[1][i] = pre[1][i-1] + ((t[i] == 'A')?1:2) ;
    	pre[1][i] %= 3 ;
    }
    while(q--){
    	cin >> a >> b >> c >> d ;
    	int v1 = (pre[0][b] - pre[0][a-1] + 3)%3 ;
    	int v2 = (pre[1][d] - pre[1][c-1] + 3)%3 ;
    	if(v1 == v2){
    		cout << "YES\n" ;
    	}
    	else{
    		cout << "NO\n" ;
    	}
    }
    return 0 ; 
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b;
    cin >> a >> b;
    if(abs(a+b)%2==0){
        cout << abs(a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

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

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

void solve(void){
	int N;
	cin >> N;
	vector <int> as(N), bs(N);
	rep(N, i) {
		cin >> as[i];
		bs[i] = as[i];
	}
	sort(all(bs));
	map <int, int> mp;
	rep(N, i) mp[bs[i]] = i;
	int ans = 0;
	rep(N, i) {
		if (i & 1) continue;
		ans += mp[as[i]] & 1;
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 5760
N,M = map(int,input().split())
L1 = list(map(int,input().split()))
Mcount = 0
for i in range(N):
    if L1[i]>=sum(L1)/(4*M):
        Mcount +=1
if Mcount >=M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b) {
			System.out.println("a < b");
		} else if(a > b) {
			System.out.println("a > b");
		} else if(a == b) {
			System.out.println("a == b");
		}

	}
}


Measured memory_bytes: 26228
#include<bits/stdc++.h>
#define int long long
#define FI first
#define SE second
#define PB push_back
#define MT make_tuple
using namespace std;
typedef tuple<int,int> TI1;
typedef tuple<int,int,int> TI2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N;
vector<TI1> V;

bool isHousing(int x){
    if(x==0)return true;
    int sum=0;
    priority_queue<int> que;
    for(int i=0;i<x-1;++i){
        int a,b;
        tie(b,a)=V[i];
        sum+=a;
        que.push(a);
    }
    for(int i=x-1;i<N;++i){
        int a,b;
        tie(b,a)=V[i];
        if(sum+a<=b*x)return true;
        sum+=a;
        que.push(a);
        sum-=que.top();
        que.pop();
    }
    return false;
}

signed main(){
    cin>>N;
    for(int i=0;i<N;++i){
        int a,b;
        cin>>a>>b;
        V.PB(MT(b,a));
    }
    sort(V.begin(),V.end(),greater<TI1>());
    int R=N,L=0;
    for(int i=0;i<20;++i){
        int mid=(L+R)/2;
        if(isHousing(mid)){
            L=mid;
        }
        else R=mid;
    }
    if(isHousing(R))cout<<R<<endl;
    else cout<<L<<endl;
}

Measured memory_bytes: 13740
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  x = x - x%5;
  int gohyaku,goen;
  gohyaku = x/500;
  goen = (x%500)/5;
  cout << gohyaku * 1000 + goen * 5 << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
A_list = [input() for i in range(N)]
B_list = [input() for j in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            if B_list[k] != A_list[i + k][j:j + M]:
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Measured memory_bytes: 3064
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=200000+19;

int S[N],A[N],l[N],r[N];
int n,top;
ll res;

int main(){
	n=IN();
	For(i,1,n+1) A[i]=IN();
	S[top=1]=0;
	for (int i=1;i<=n;i++){
		while (A[i]<A[S[top]]) top--;
		l[i]=S[top];
		S[++top]=i;
	}
	S[top=1]=n+1;
	for (int i=n;i>=1;i--){
		while (A[i]<A[S[top]]) top--;
		r[i]=S[top];
		S[++top]=i;
	}
	For(i,1,n+1){
		res+=1ll*A[i]*(i-l[i])*(r[i]-i);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=998244353.;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
        
        int main()
        {
            FAST;
           ll h,w;
           cin>>h>>w;
           if(h==1 || w==1)
           {
               cout<<1<<"\n";
               return 0;
           }
           ll x=h*w;
           cout<<setprecision(25)<<ceil(x/2.0*1.0);
            return 0;
        }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int S,h,m,s;

  cin >> S;

  h = S / 3600;
  m = S % 3600 / 60;
  s = S % 3600 % 60;
  
  cout << h <<":"<< m << ":"<< s << endl;

  return 0;

}


Measured memory_bytes: 3088
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, a: "List[int]"):
    if all([aa == 0 for aa in a]):
        print(YES)
    elif len(set(a)) == 2 and len([aa for aa in a if aa == 0]) == N // 3:
        print(YES)
    elif len(set(a)) == 3:
        l = list(set(a))
        if l[0] ^ l[1] ^ l[2] == 0 and a.count(l[0]) == N // 3 and a.count(l[1]) == N // 3:
            print(YES)
        else:
            print(NO)
    else:
        print(NO)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15868
fun main(args : Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!!

    // Generate compressed s
    val compressedList = mutableListOf<Int>()
    var before = 'X'
    var contineousNumber = 0
    if (S.first() == '0') {
        compressedList.add(0)
    }
    S.forEach {
        if (it == before) {
            contineousNumber++
        } else {
            if (before != 'X') {
                if (before == '1') {
                    compressedList.add(contineousNumber)
                } else {
                    compressedList.add(contineousNumber)
                }
            }
            contineousNumber = 1
        }
        before = it
    }
    compressedList.add(contineousNumber)
    if (S.last() == '0') {
        compressedList.add(0)
    }

    val cumilativeList = createCumilativeList(compressedList)
    var max = 0
    (0..(cumilativeList.size -1)).step(2 ).forEach{
        val from = it
        var to = from + (2 * K)

        val diff = if (from - 1 < 0) 0 else cumilativeList[from-1]
        if (to >= cumilativeList.size) {
            to = cumilativeList.size - 1
        }
        max = Math.max(max, cumilativeList[to] - diff)
    }
    println(max)
}

fun createCumilativeList(list: List<Int>) : List<Int> {
    val cumilativeList = mutableListOf<Int>()

    list.forEachIndexed { index, value ->
        if (index == 0) {
            cumilativeList.add(value)
        } else {
            cumilativeList.add(
                    cumilativeList.last() + value
            )
        }
    }

    return cumilativeList
}

Measured memory_bytes: 41200
#include<bits/stdc++.h>
#include<queue>
using namespace std;
priority_queue<int> q;

int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		while(n--)
		{
			int in;
			cin>>in;
			q.push(in);
		}
		while(m--)
		{
			q.push(q.top()/2);
			q.pop(); 
		}
		long long ans=0;
		while(!q.empty())
		{
			ans+=q.top();
			q.pop();
		}
		cout<<ans<<endl;
	}
} 

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int ans = 0;
  if (a%2==0 && b%2==0 && c%2==0) {
    if (a == b && b == c) ans = -1;
    else {
      ans = 1;
      int A = a, B = b, C = c;
      while(true) {
        A = (b + c) / 2;
        B = (a + c) / 2;
        C = (a + b) / 2;
        if (A%2==1 || B%2==1 || C%2==1) break;
        else ans ++, a = A, B = b, c = C;
      }
    }
  } else ans = 0;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int dp[100005];
int solve(int i , int n)
{
	if (i == n) return 0;
	if (dp[i] != -1) return dp[i];
	int cost  =  abs(a[i] - a[i + 1] ) + solve(i + 1, n);
	if (i + 2 <= n) cost =  min(cost, abs(a[i] - a[i + 2]) + solve(i + 2, n));
	return dp[i] = cost;
}
int32_t main()
{
	
	int n; cin >> n;
	memset(dp, -1, sizeof dp);
	for (int i = 1; i <= n; i++) cin >> a[i];
	cout << solve(1, n);
	return 0;
}






Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int n;cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    a[n+1] = 0;
    int sum = 0;
    for(int i=1;i<n+2;i++){
        sum+=abs(a[i]-a[i-1]);
    }
    //debug(sum);
    for(int i=1;i<=n;i++){
        cout << sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << newl;
    }
}
// 0 3 5 -1 0
//3+2+6+1



Measured memory_bytes: 1664
X, Y = map(int, input().split())

mod = 10**9+7
N = 1333334
fac = [1]*(N+1)
rev = [1]*(N+1)
 
for i in range(1,N+1):
  fac[i] = i*fac[i-1]%mod
  rev[i] = pow(fac[i], mod-2, mod)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod

a, b = (2*X-Y)//3, (2*Y-X)//3
if a<0 or b<0 or (2*X-Y)%3 or (2*Y-X)%3:
    print(0)
else:
    print(comb(a+b, a))


Measured memory_bytes: 61552
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()
#define P pair<ll,ll>

using Graph = vector<vector<int>>;

const int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
ll INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Min = INFL, Max = -1;
ll a, b, c, n, sum, A[500010], B[500000], rui[500000], dp[5000];
str S, T; bool check = true;	vector<ll> v;



int main() {
	//Code Line
	cin >> S >> T;

	cout << T;
	cout << S << endl;
	return 0;
}


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

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

int main() {

  	// 入力
	string S, ans = "No", i;
	int count1 = 0, count2 = 0;
	int tmp;

	cin >> S;

	REP(i, S.length()){
		if(S[0] == S[i]){
			count1++;
			tmp = i;
		}
	}
	if(count1 == 2) {
		if(tmp == 1){
			if(S[2] == S[3]){
				ans = "Yes";
			} 
		} else if(tmp == 2) {
			if(S[1] == S[3]){
				ans = "Yes";
			} 			
		} else {
			if(S[1] == S[2]){
				ans = "Yes";
			} 			
		}

	}
  	cout << ans  << endl;
}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
        if (m == -1 && f == -1 && r == -1){
            break;
        }else{
            if(m == -1 || f == -1){
                System.out.printf("F\n");
            }else if(m + f >= 80){
                System.out.printf("A\n");
            }else if(m + f >= 65) {
                System.out.printf("B\n");
            }else if(m + f >= 50) {
                System.out.printf("C\n");
            }else if(m + f >= 30){
                if(r >= 50) {
                    System.out.printf("C\n");
                }else{
                    System.out.printf("D\n");
                }
            }else{
                System.out.printf("F\n");
            }
        }
        }
    }
}



Measured memory_bytes: 26256
n,m=map(int,input().split())
a=[0]*m
for i in range(m):
  a[i]=int(input())
a.append(0)
temp=[0]*(n+1)
temp[0]=1
if 1 in a:
  temp[1]=0
  j=1
else:
  temp[1]=1
  j=0
for i in range(2,n+1):
  if a[j]==i:
    temp[i]=0
    j=j+1
  else:
    temp[i]=temp[i-2]+temp[i-1]
    temp[i]=temp[i]%(10**9+7)
print(temp[n])

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    string n;
    int kk;
    cin >> n >> kk;

    // dp[i][j]: ある桁まで確定したとき 0でない数字がちょうどj個あるものの個数 iは数がN以下なのが確定したかのフラグ
    vector<vector<int>> dp(2, vector<int>(kk + 1, 0));
    dp[false][0] = 1;

    for (int i = 0; i < n.size(); i++)
    {
        vector<vector<int>> ndp(2, vector<int>(kk + 1, 0));

        // N以下が確定していないとき
        const int lim = n[i] - '0';
        for (int k = 0; k <= kk; k++)
        {
            for (int l = 0; l <= lim; l++)
            {
                if (k + (l != 0) <= kk)
                    ndp[l != lim][k + (l != 0)] += dp[false][k];
            }
        }

        // N以下が確定しているとき
        for (int k = 0; k <= kk; k++)
        {
            for (int l = 0; l <= 9; l++)
            {
                if (k + (l != 0) <= kk)
                    ndp[true][k + (l != 0)] += dp[true][k];
            }
        }
        dp = ndp;
    }

    int ans = dp[false][kk] + dp[true][kk];
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[5], k;
  for(int i = 0;i < 5;++i)cin >> a[i];
  cin >> k;
  bool flg = false;
  for(int i = 0;i < 5;++i)
    for(int j = 0;j < 5;++j)
      if(a[i] - a[j] > k)
        flg = true;
  cout << ((flg) ? ":(" : "Yay!");
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

long long int DP[1001][1001] = {};

int main(){
	
	int n;
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		
		string str1, str2;
		cin >> str1 >> str2;
		
		for(int i = 1; i <= str1.size(); i++){
			for(int j = 1; j <= str2.size(); j++){
				if(str1[i - 1] == str2[j - 1]){
					DP[i][j] = max(max(DP[i - 1][j - 1] + 1, DP[i - 1][j]), DP[i][j - 1]);
				}else{
					DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
				}
			}
		}
		
		cout << DP[str1.size()][str2.size()] << endl;
	}
	return 0;
}


Measured memory_bytes: 10948
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



int main() {


	int n;
	cin >> n;
	vector<int> a(n+10,0);
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	int sum = 0;
	vector<int> ans(n + 10, 0);
	bool flag = false;

	for (int i = n; i > 0; i--)
	{
		int sum = 0;
		for (int j = i; j <= n; j+= i)
		{
			sum += ans[j];
		}

		//cout << "i = " << i << " sum= " << sum << " a[i] = " << a[i] << endl;
		if (sum % 2 != a[i]%2) {
			ans[i] = 1;
			flag = true;
		}
		else
		{
			ans[i] = 0;
		}
		//cout << ans[i] << endl;
	}


	if (flag) {

		vector<int> hoge;
		for (int i = 1; i <= n; i++)
		{
			if (ans[i])hoge.push_back(i);
		}
		cout << hoge.size() << endl;
		for (int i = 0; i < hoge.size(); i++)
		{
			if (i == 0) {
				cout << hoge[i];
			}
			else
			{
				cout << " " << hoge[i];
			}
		}
		cout << endl;
	}
	else
	{
		cout << "0" << endl;
	}


	

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();


    int d ;
    cin >>d ;
    REP(i,d){
        cout << (i+4)%26+1 <<endl;
    }


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



Measured memory_bytes: 3692
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;
struct root{
    int to;
    ll cost;
};

int main() {
    int N;
    cin >> N;
    vector<root> vt[N];

    for(int i=0; i<N-1; i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        vt[a].push_back( root {b, c} );
        vt[b].push_back( root {a, c} );
    }
    queue<int> que;
    int Q,K;
    cin >> Q >> K;
    K--;
    que.push(K);
    ll dist[100000], used[100000];
    memset(used, 0, sizeof(used));
    dist[K]=0;
    used[K]=1;
    while(true){
        int s=que.size();
        for(int i=0; i<s; i++){
            int tmp = que.front(); que.pop();
            for(int next=0; next<vt[tmp].size(); next++){
                if(used[vt[tmp][next].to]==1) continue;
                dist[vt[tmp][next].to]=dist[tmp]+vt[tmp][next].cost;
                que.push(vt[tmp][next].to);
                used[vt[tmp][next].to]=1;
            }
        }
        if(que.size()==0) break;
    }
    ll ans[Q];
    for(int i=0; i<Q; i++){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        ans[i] = dist[x]+dist[y];
    }
    for(int i=0; i<Q; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 11520
N,M,X,Y=gets.chomp.split(" ").map { |e| e.to_i }
x=gets.chomp.split(" ").map { |e| e.to_i }.sort
y = gets.chomp.split(" ").map { |e| e.to_i }.sort

for i in X+1..Y do
  if x[N-1] < i && i <= y[0]
    puts "No War"
    exit
  end
end

puts "War"


Measured memory_bytes: 1788
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n; 
  	cin >> n;
  	vector<int> a(n);
  	rep(i,n) cin >> a[i];
  	sort(a.rbegin(), a.rend());
  	int ans = 0;	
  	rep(i,n){
    	if(i%2==0) ans += a[i];
      	else ans -= a[i];
    }
  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7
// https://atcoder.jp/contests/agc017/tasks/agc017_a

vector<ll> fac;
vector<ll> finv, inv; // いらないときはコメントアウト

// テーブルを作る前処理
void com_init(int maxK){
    fac.resize(maxK + 1);
    finv.resize(maxK + 1);
    inv.resize(maxK + 1);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < maxK + 1; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    com_init(n);

    int even = 0; int odd = 0;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (a % 2 == 0) even++;
        else odd++;
    }

    ll evenNum = pow(2, even);
    ll oddNum0 = 0;
    ll oddNum1 = 0;
    rep(i, 0, odd  + 1) {
        if (i % 2 == 0) oddNum0 += com(odd, i);
        else oddNum1 += com(odd, i);
    }

    ll ans = (p == 0) ? evenNum * oddNum0 : evenNum * oddNum1;
    cout << ans << endl;

}


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

int main(){
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int j=0;j<n;j++){
    scanf("%d",&b[j]);
  }
  vector< pair<int,int> > vect[n];
  for(int i=0;i<n;i++){
    vect[i].push_back(make_pair(a[i],b[i]));
  }
  sort(vect,vect+n);
  int ans=0;
  for(int i=0;i<n;i++){
    if(b[i]>=a[i]) continue;
    ans+=a[i]-b[i];
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for n in range(1 << h):
    for m in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if n>>i & 1: continue
                if m>>j & 1: continue
                if c[i][j] == '#': cnt += 1
        if cnt == k: ans += 1

print(ans)

Measured memory_bytes: 8820
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int x,y;
    cin >> x >> y;
    REP(i,60){
        REP(j,60){
            if(i+j == x and i*4+j*2 == y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define endl "\n"
#define nl cout<<endl
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define txti freopen("input.txt", "r", stdin);
#define txto freopen("output.txt", "w", stdout);
//#define mod 100000007

#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 

bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
 
    return false;
 }
//me
ll const mod = 1e9+7;
ll const inf = 3e3;
bool isdif(ll a, ll b, ll c)
{
    if( a!=b && b!=c && c!=a )
        return 1;
    return 0;
}
bool poss(ll a, ll b, ll c)
{
    if( (a+b>c) && (b+c>a) && (c+a>b) )
        return 1;
    return 0;
}

void solve()
{
    ll x, k ,d ; cin >> x >> k >> d;
    x = abs(x);
    if(x/k >= d)
        cout << x-d*k << endl;
    else{
        ll big_pp = x/d;

        ll rem  = k-big_pp;
    
        ll pp = x%d;


        if(rem%2==0)
            cout << abs(pp) << endl;
        else
            cout <<abs(pp-d) << endl;

    }
}
int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
        ll t;
        /**/t=1;
        /*/cin>>t;/**/
        f(testcases,0,t){
            solve();
        }
 
 
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(void) {
        int n, i, a[200];
        scanf("%d", &n);
        for(i=0;i<n;i++) {
                scanf("%d", &a[i]);
        }
        for(i=n-1;i>=0;i--) {
                if(i==0) {
                        printf("%d", a[i]);
                } else {
                        printf("%d ", a[i]);
                }
        }
        printf("\n");
        return 0;
}

Measured memory_bytes: 600
base_int = ord('A')
N = int(input())
S = input()


s_base = [ord(s) - base_int for s in S]
s_base = [(s + N) % 26 for s in s_base]
s_base = [chr(s + base_int) for s in s_base]

# print(s_base)
print(''.join(s_base))

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int l,r;
    int mina=100000,maxa=0;
    for (int i = 0; i < m; ++i) {
        cin>>l>>r;
        maxa=max(l,maxa);
        mina=min(r,mina);
    }
    if(mina>=maxa)
    {
        cout<<mina-maxa+1;
    }
    else
        cout<<0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 1116
#define mod 1000000007
#define next nxt

int n,m,k,t,x[N],y[N],next[N],p[N],f[N],dfn[N],low[N],h[N],u[N];
long long fac[N],inv[N];
vector<int> q;
long long ans;

int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}

long long power(long long x,long long y){
	long long t=1;
	for (;y;x=x*x%mod,y/=2)
		if (y&1) t=t*x%mod;
	return t;
}

long long polya(int n){
	long long ans=0;
	for (int i=1;i<=n;i++)
		ans=(ans+power(k,gcd(i,n)))%mod;
	return ans*fac[n-1]%mod*inv[n]%mod;
}

long long C(int x,int y){
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

void travel(int x){
	dfn[x]=low[x]=++t;h[x]=1;
	for (int t=p[x];t;t=next[t])
		if (!dfn[y[t]]){
			q.push_back(t);
			f[y[t]]=x;travel(y[t]);
			low[x]=min(low[x],low[y[t]]);
			if (low[y[t]]<dfn[x]) continue;
			
			fill(u+1,u+n+1,0);
			int cnt=1,cmt=0,e=0;u[x]=1;
			do {
				e=q.back();q.pop_back();cmt++;
				if (!u[y[e]]) cnt++,u[y[e]]=1;
				
			} while (e!=t);
			if (cmt==1) ans=ans*k%mod;
			else if (cnt==cmt) ans=ans*polya(cnt)%mod;
				else ans=ans*C(cmt+k-1,k-1)%mod;
			
		}
		else if (h[y[t]]&&y[t]!=f[x]){
				low[x]=min(low[x],dfn[y[t]]);
				q.push_back(t);
			}
	h[x]=0;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();m=read();k=read();
	for (int i=1;i<=m;i++){
		x[2*i-1]=y[2*i]=read();
		y[2*i-1]=x[2*i]=read();
		next[2*i-1]=p[x[2*i-1]];p[x[2*i-1]]=2*i-1;
		next[2*i]=p[x[2*i]];p[x[2*i]]=2*i;
	}
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (int i=2;i<N;i++) fac[i]=fac[i-1]*i%mod;
	for (int i=2;i<N;i++) inv[i]=-(mod/i)*inv[mod%i]%mod;
	for (int i=2;i<N;i++) inv[i]=inv[i-1]*inv[i]%mod;
	ans=1;
	for (int i=1;i<=n;i++)
		if (!dfn[i]) travel(i);
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}

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

using namespace std;

int main() {
	long long int N, A, B;
	cin >> N >> A >> B;
	cout << max( 0LL, ( ( N - 1 )*B + A ) - ( ( N - 1 )*A + B ) + 1 ) << endl;
}

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

struct UnionFind {
	vector<int> par;
	UnionFind(int n) :par(n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
	}
	int root(int x) {
		return par[x] == x ? x : par[x] = root(par[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void merge(int x, int y) {
		int rx = root(x), ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
};

int main() {
	int n; cin >> n;
	vector<long long>x(n), y(n);
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i];
	using P = pair<int, int>; using edge = pair<long long, P>;
	vector<edge>edges;
	vector<int>ids(n);
	for (int i = 0; i < n; i++)ids[i] = i;
	sort(ids.begin(), ids.end(), [&](int i, int j) {return x[i] < x[j]; });
	for (int i = 0; i < n - 1; i++) {
		int u = ids[i], v = ids[i + 1];
		edges.push_back(edge(x[v] - x[u], P(u, v)));
	}
	sort(ids.begin(), ids.end(), [&](int i, int j) {return y[i] < y[j]; });
	for (int i = 0; i < n - 1; i++) {
		int u = ids[i], v = ids[i + 1];
		edges.push_back(edge(y[v] - y[u], P(u, v)));
	}
	sort(edges.begin(), edges.end());
	UnionFind uf(n);
	long long ans = 0;
	for (auto e : edges) {
		int u = e.second.first, v = e.second.second;
		long long cost = e.first;
		if (uf.same(u, v))continue;
		uf.merge(u, v);
		ans += cost;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// graph template
template<typename T>
class Edge{
	public:
		int src, to; T cost;

		Edge(int to, T cost): src(-1), to(to), cost(cost){}
		Edge(int src, int to, T cost): src(src), to(to), cost(cost){}
};
template<typename T>
using Edges = vector<Edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

// kruskal.cpp depend on this.
// kruskal.cpp depend on this.
#ifndef UNION_FIND_TREE
#define UNION_FIND_TREE
template<typename T>
class UnionFindTree{
	private:
		int N;
		vector<int> parent, rank, size;
		vector<T> diff_weight;

		int find(int x){
			if(parent[x] == x){
				return x;
			}else{
				int r = find(parent[x]);
				diff_weight[x] += diff_weight[parent[x]];
				return parent[x] = r;
			}
		}

		T weight(int x){
			find(x);
			return diff_weight[x];
		}

	public:
		void init(int N = -1){
			if(N > this -> N){
				this -> N = N;
				parent.resize(N); rank.resize(N); size.resize(N); diff_weight.resize(N);
			}

			for(int i = 0; i < this -> N; i++){
				parent[i] = i; rank[i] = 0; size[i] = 1; diff_weight[i] = 0;
			}
		}

		UnionFindTree(int N = 0): N(N), parent(N), rank(N), size(N), diff_weight(N){
			init();
		}

		T diff(int x, int y){
			return weight(y) - weight(x);
		}

		// weight(y) = weight(x) + w となるようにmergeする
		bool unite(int x, int y, T w = 0){
			w += weight(x); w -= weight(y);
			x = find(x); y = find(y);
			if(x == y) return weight(y) - weight(x) == w;

			if(rank[x] < rank[y]){
				swap(x, y);
				w = -w;
			}

			parent[y] = x;
			size[x] += size[y];
			if(rank[x] == rank[y]) rank[x]++;
			diff_weight[y] = w;
			return true;
		}

		bool isSame(int x, int y){
			return find(x) == find(y);
		}
		
		int count(int x){
			return size[find(x)];
		}
};
#endif

template<typename T>
T kruskal(Edges<T> &edges, int V){
    sort(edges.begin(), edges.end(), [](const Edge<T> &a, const Edge<T> &b){return a.cost < b.cost;});
    UnionFindTree<T> tree(V);
    
    T ret = 0;
    for(auto &e: edges){
        if(not tree.isSame(e.src, e.to)){
            ret += e.cost;
            tree.unite(e.src, e.to);
        }
    }

    return ret;
}

int main(void){
	int N;
	cin >> N;
	vector<P> x(N), y(N);
	for(int i = 0; i < N; i++){
		int a, b;
		cin >> a >> b;
		x[i] = P(a, i);
		y[i] = P(b, i);
	}

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	Edges<ll> es;
	for(int i = 0; i < N-1; i++){
		es.push_back(Edge<ll>(x[i].second, x[i+1].second, x[i+1].first - x[i].first));
		es.push_back(Edge<ll>(y[i].second, y[i+1].second, y[i+1].first - y[i].first));
	}

	ll res = kruskal(es, N);
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 7792
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    s=input()
    if n%2:
        print("No")
        exit()
    n//=2
    for c0,c1 in zip(s,s[n:]):
        if c0!=c1:
            print("No")
            exit()
    print("Yes")

main()

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt();
		int B = scn.nextInt();
		System.out.println(Math.max(A*B, Math.max(A-B, A+B)));
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <complex>
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++)
const int INF = 1<<28;
#define MAX 1401

int dp[MAX][MAX];

int solve(int H, int W) {
	REP(j,W) {
		int v = 1;
		REP(i, H) {
			if(!dp[i][j])
				v = 0;
			dp[i][j] = v++;
		}
	}

	int ans = 0;
	REP(i, H) {
		pair<int, int> p, p2;
		stack< pair<int, int> > s;
		dp[i][W] = 0;
		REP(j, W+1) {
			p = make_pair(dp[i][j], j);
			if(s.empty())
				s.push(p);
			else {
				if(s.top().first < p.first)
					s.push(p);
				else if(s.top().first > p.first) {
					int pnt = j;
					while(!s.empty() && s.top().first >= p.first) {
						p2 = s.top(); s.pop();
						ans = max(ans, p2.first * (j - p2.second));
						pnt = p2.second;
					}
					p.second = pnt;
					s.push(p);
				}
			}
		}
	}
	return ans;
}

int main() {
	int H, W; cin >> H >> W;
	REP(i, H) REP(j, W) {
		cin >> dp[i][j];
		dp[i][j] = !dp[i][j];
	}
	cout << solve(H, W) << endl;
	return 0;
}

Measured memory_bytes: 8864
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<string> ans;

int n;

void solve(int len, int kind, string s) {
    if (len == n) {
        ans.push_back(s);
        return;
    }

    rep(i, kind + 1) {
        if (i == kind) solve(len + 1, kind + 1, s + char('a' + i));
        else solve(len + 1, kind, s + char('a' + i));
    }
}

int main() {
    cin >> n;
    solve(0, 0, "");
    sort(ans.begin(), ans.end());
    print(ans, "\n");
}

Measured memory_bytes: 7796