akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
#include <vector>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <list>
using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    //START
  	cout << "A";
  	string A;
  	cin >> A >> A;
	cout << A[0] << "C" << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
/*FUNC*/
//各桁の和
int EDSum(ll number){
    int ans=0;
    while(1){
        ans += number % 10;
        number /= 10;
        if(number == 0) break;
    }
    return ans;
}

//エラトステネスのふるい(素数発見アルゴリズム)
vector<int> SOE(int min, int max)
{
    //0,1は含まれない
    if (min < 2) min = 2;
    //探索リスト作成
    vector<int> int_array;
    for (int i = min; i <= max; i++) int_array.push_back(i);
    //素数リスト
    vector<int> sosu;
    //√max
    double stop = sqrt(max);
    //計算
    while (true)
    {
        //素数リストに追加
        sosu.push_back(int_array.front());
        int_array.erase(int_array.begin());
        //停止
        if (stop < (double)(sosu.back())) break;
        //ふるい
        for (int i = 0; i < (int)int_array.size(); i++)
        {
            if (int_array[i] % sosu.back() == 0)
                int_array.erase(int_array.begin() + i);
        }
    }
    sosu.insert(sosu.end(), int_array.begin(), int_array.end());
    return sosu;
}

//最小公倍数
int MinCM(int a, int b)
{
    int c = a * b;
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return c / b;
}

//最大公約数
int MaxCD(int a, int b)
{
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
//iget cin int 2 vector
vector<int> igets(int N){
    vector<int> A;
    int temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        A.push_back(temp);
    }
    return A;
}

ll nPr(ll n,ll r) {
    ll ans=1;
    r=n-r;
    while(n!=r) {
        ans*=n;
        --n;
    }
    return ans;
}

ll nE(ll n) {
    return nPr(n,n);
}

ll nCr(ll n,ll r) {
    if(r==0)return -1;
    else{
        if(0!=n-r&&n-r<r)r=n-r;
        return nPr(n,r)/nE(r);
    }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if (S[2] == S[3] && S[4] == S[5]) cout << YES << '\n';
    else cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 2E+05;

int N;

int H[MAX_N + 1];

ll dp[MAX_N + 1], A[MAX_N + 1];

ll getmax(int i);
void setmax(int i, ll x);

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> H[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    for (int i = 1; i <= N; i++) {
        setmax(H[i], getmax(H[i] - 1) + A[i]);
    }

    cout << getmax(N) << "\n";

    return 0;
}

ll getmax(int i)
{
    ll s = 0;
    while (i > 0) {
        s = max(s, dp[i]);
        i -= i & -i;
    }
    return s;
}

void setmax(int i, ll x)
{
    while (i <= N) {
        dp[i] = max(dp[i], x);
        i += i & -i;
    }
}

Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  int ary[26];
  for(int i=0; i<26; ++i){
    ary[i]=0;
  }
  for(int i=0; i<s.size(); ++i){
    char a=s[i];
    int b=a-'a';
    ary[b]+=1;
  }
  int f=0;
  for(int i=0; i<26; ++i){
    int c=ary[i];
    if(c>0){
      if(c%2==1){
        f=1;
        break;
      }
    }
  }
  if(f==0){
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
int sy, sx;
char maze[1010][1010];
P nums[10];
ll bfs(ll goal) {
	queue<P> que;
	rep(i,h){
		rep(j, w) {
			dis[i][j] = -1;
		}
	}
	que.push(P(sy, sx));
	dis[sy][sx] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == nums[goal].first && p.second == nums[goal].second) break;
		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (0 <= ny && ny < h && 0 <= nx && nx < w && maze[ny][nx] != 'X' && dis[ny][nx] == -1) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	sy = nums[goal].first;
	sx = nums[goal].second;
	return dis[nums[goal].first][nums[goal].second];
}

int main() {
	cin >> s;
	for (ll i = 1; i < s.size(); i++) {
		if (s[i] != '9') {
			cout << s[0] - '0' - 1 + 9 * (s.size() - 1) << endl;
			return 0;
		}
	}
	cout << s[0] - '0' + 9 * (s.size() - 1) << endl;
	return 0;
}



Measured memory_bytes: 256
s = input()
lis = []
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                tmp = ""
                if(i == 0):
                    tmp += "A"
                tmp += "KIH"
                if(j == 0):
                    tmp += "A"
                tmp += "B"
                if(k == 0):
                    tmp += "A"
                tmp += "R"
                if(l == 0):
                    tmp += "A"
                lis.append(tmp)
if(s in lis):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    int n,b;
    ll ans=0;
    cin >> n;
    vector<ll> v(n);
    for(int i=0;i < n;i++)
    {
        int x;
        cin >> x;
        v.at(i)=x-i-1;
    }
    sort(v.begin(),v.end());

    b=v.at(n/2);

    for(int i=0;i < n;i++)
    {
        ans += abs(v.at(i)-b);
    }
    cout << ans << endl;
}
 


Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Set {
  int64_t amount, num;
  Set(int64_t b, int64_t c) {
    amount = b;
    num    = c;
  }
  bool operator<(const Set& another) const {
    return num < another.num;
  }
  bool operator>(const Set& another) const {
    return num > another.num;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  std::vector<Set> set;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    set.push_back(Set(1, a));
  }
  
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    set.push_back(Set(b, c));
  }

  std::sort(set.begin(), set.end(),std::greater<Set>());

  int64_t card=0;
  int64_t result=0;
  int itr=0;
  while(card<n){
    if(card+set[itr].amount<=n){
      card+=set[itr].amount;
      result+=set[itr].num*set[itr].amount;
    }else{
      int64_t remain=n-card;
      card+=remain;
      result+=set[itr].num*remain;
    }
    itr++;

  }
  cout<<result<<endl;

  return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m, num[3], c[3][2];
	
	num[0] = num[1] = num[2] = -1;

	cin >> n >> m;

	bool v = true;

	for(int k = 0; k < m; ++k) {

		cin >> c[k][0] >> c[k][1];

		if(num[c[k][0] - 1] != -1 && num[c[k][0] - 1] != c[k][1])
			v = false;

		num[c[k][0] - 1] = c[k][1];
	}

	if(num[0] == 0 && n > 1)
		v = false;

	if(v) {

		if(n > 1 && num[0] == -1) 
			num[0] = 1;

		for(int k = 0; k < n; ++k) {

			if(num[k] == -1) 
				num[k] = 0;

			cout << num[k];
		}

		cout << '\n';
	}

	else
		cout << "-1\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool ok(string a,string b)
{
	for(int i=0;i<a.length();i++)
		if(a[i]!='?'&&a[i]!=b[i])
			return false;
	return true;
}
void print(string S,string T,int pos)
{
	for(int i=0;i<pos;i++)
		if(S[i]!='?')
			cout<<S[i];
		else	cout<<"a";
	cout<<T;
	for(int i=pos+T.length();i<S.length();i++)
		if(S[i]!='?')
			cout<<S[i];
		else	cout<<"a";
	exit(0);
}
int main()
{
	string S,T;
	cin>>S>>T;
	for(int i=S.length()-T.length();i>=0;i--)
		if(ok(S.substr(i,T.length()),T))
			print(S,T,i);
	cout<<"UNRESTORABLE";
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

//#[fastout]
fn main() {
    input! {
        n:usize,
        a:[usize;n]
    }

    let mut m = 1000_usize;
    let mut k = 0;

    let mut i = 0;
    while i + 1 < n {
        for j in i..n - 1 {
            if a[j] > a[j + 1] {
                k += m / a[i];
                m %= a[i];
                m += k * a[j];
                k = 0;
                i = j + 1;
                break;
            } else if j + 1 == n - 1 {
                k += m / a[i];
                m %= a[i];
                m += k * a[n - 1];
                k = 0;
                i = n;
            }
        }
    }
    println!("{}", m + k * a.last().unwrap());
}


Measured memory_bytes: 2144
h1,m1,h2,m2,k =(int(x) for x in input().split())  
 
hrtom= (h2-h1)
 
if (m2-m1 < 0) and (h2-h1 >=0) : 
    min = (h2-h1)*60 + (m2-m1) - k
    print(min)
    
elif (m2-m1 >= 0) and (h2-h1 >=0 ):
    min = (h2-h1)*60 + (m2-m1) - k 
    print(min)

    

else:
    print('0')

Measured memory_bytes: 9196
#include<stdio.h>
#include<math.h>

int main(){
  int a, b, c, y;
  scanf("%d %d", &a, &b);
  if(b == 100){
    c = 1000*a + b;
  } else if(b/10 == 0){
    c = 10*a + b;
  } else {
    c = 100*a + b;
  }
  y = sqrt(c);
  if(y*y == c){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int a[300][300] , b[300][300] , h , c;
int main() {
	cin >> h >> c;
	for (int i = 1 ; i <= h ; i++)
	{
		for (int e = 1 ; e <= c ; e++)
		{
			char x;
			cin >> x;
			if (x == '#')
			{
				b[i][e] = 1;
			}
			//cout <<b[i][e];
			a[0][i] = a[0][e] = a[h+1][e] = a[i][c+1] = a[i][0] = a[e][0] = 1000000;
			
		}
	}
	for (int i = 1 ; i <= h ; i++)
	{
		for (int e = 1 ; e <= c ; e++)
		{
			if (i == 1 && e == 1)
			{
				if (b[i][e] == 1)
				{
					a[i][e] = 1;
				}
				continue;
			}
			if (b[i][e] == 1)
			{
				if (b[i-1][e] == 0)
				{
					a[i][e] = a[i-1][e] + 1;
				}
				else
				{
					a[i][e] = a[i-1][e];
				}
				
				if (b[i][e-1] == 0)
				{
					a[i][e] = min(a[i][e] , a[i][e-1] + 1);
				}
				else
				{
					a[i][e] = min(a[i][e] , a[i][e-1]);
				}
			}
			else
			{
				a[i][e] = min(a[i][e-1] , a[i-1][e]);
			}
			//cout <<a[i][e];
		}
	//	cout <<'\n';
	}
	cout << a[h][c];
}

Measured memory_bytes: 512
def fun(h):
    cost = [0]*len(h)
    for i in range(1, len(h)):
        if i == 1:
            cost[i] = abs(h[i]-h[i-1])
        else:
            cost[i] = min((cost[i-2]+abs(h[i]-h[i-2]),
                           cost[i-1]+abs(h[i]-h[i-1])))
    return cost[-1]


n = int(input())
h = [int(x) for x in input().strip().split(" ")]
print(fun(h))


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int p[100005];
int main()
{
  string s,t;
  cin >> s;
  cin >> t;
  t.pop_back();


if(s == t)
		cout << "Yes";
else
		cout << "No";
  
  

}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  List<Deque<Integer>> a;
  int ans;
  int turn = 0;
  boolean win = false;
  static final int A = 0;
  static final int B = 1;
  static final int C = 2;
  static final int N = 3;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = new ArrayList<Deque<Integer>>();
      a.add(read(sc));
      a.add(read(sc));
      a.add(read(sc));
    } finally {
      sc.close();
    }
  }

  private static Deque<Integer> read(Scanner sc) {
    Deque<Integer> ans = new ArrayDeque<Integer>();
    String s = sc.next();
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) == 'a' ) ans.addLast(A);
      if (s.charAt(i) == 'b' ) ans.addLast(B);
      if (s.charAt(i) == 'c' ) ans.addLast(C);
    }
    return ans;
  }
  
  void solve() {
    while (!win) play();
  }

  void play() {
    if (a.get(turn).size() == 0) {
      win = true;
      ans = turn;
      return;
    }
    turn = a.get(turn).pollFirst();
  }

  void show() {
    if (ans == A) System.out.println("A");
    if (ans == B) System.out.println("B");
    if (ans == C) System.out.println("C");
  }
}


Measured memory_bytes: 35520
#include <stdio.h>
#define E (N/A+(N%A!=0))*B
#define F (N/C+(N%C!=0))*D
int main(void){int  N,A,B,C,D;scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);printf("%d\n",((E<F)*E+(E>=F)*F));return 0;}



Measured memory_bytes: 2140
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

map<pair<int, int>, int> m;

void press_f(int x){
    int b=x%10;
    int a;
    while(x){
        a=x%10;
        x/=10;
    }
    m[{a,b}]++;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        press_f(i);
    }
    int ans=0;
    for(int i=0; i<=9; i++){
        for(int j=0; j<=9; j++){
            ans+=m[{i,j}]*m[{j,i}];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1)
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX             100005

typedef long long ll;


int main()
{
    FastRead

    long double r,ans;

    cin>>r;

    ans = 2.0*pi*r;

    cout<<fixed<<setprecision(15)<<ans;
}


Measured memory_bytes: 3764
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
const LL MOD = 1000000007;
static const size_t MAX_N = 2000005;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		LL r1 = -1, c1 = -1, r2 = -1, c2 = -1;
		cin >> r1 >> c1 >> r2 >> c2;
		if (r1 < 0) return 0;
		modll ans = 0;

		for (LL r = r1; r <= r2; ++r) {
			modll a = combination(c2 + r + 1, c2);
			ans += a;
			if (c1 > 0) {
				a = combination(c1 + r, c1 - 1);
				ans -= a;
			}
//			cout << (c2 + r) << "," << (c2 - 1) << "," << a << endl;
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  vector<pair<ll, ll>> ab(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    ab[i] = make_pair(b[i], a[i]);
  }
  sort(ab.begin(), ab.end());
  ll close = 0;
  ll sum   = 0;
  for (int i = 0; i < n; i++) {
    if (close != ab[i].first) close = ab[i].first;
    sum += ab[i].second;
    if (sum > close) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6540
a,b,c,d = (int(i) for i in input())
 
if a+b+c+d == 7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
  
elif a-b+c+d == 7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
const int mod=1e9+7;
int a[maxn];
int main(){
	int n,m,x;scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) scanf("%d",&x),n-=x;
	if(n<0) printf("-1\n");else printf("%d\n",n);
}

Measured memory_bytes: 3724
#include<stdio.h>
int main()
 {int s=0,a[6],i,j=0;
  for(i=0;i<=5;i++)
   {  scanf("%d",&a[i]);
		if(i<5)
        {
		if(a[i]>j)
		j=a[i];
		}
   }
   for(i=0;i<5;i++)
   {
   if(j<=(a[5]+a[i]))
		s++;
	 else 
	 break;
	}
  
if(s==5)
	printf("Yay!\n");
	else
	printf(":(\n");
 return 0;
 }

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

int main()
{

  int a[3];
  rep(i,3){
    cin >> a[i];
  }
  sort(a, a+3);
  cout << (a[0] + a[1] == a[2] ? "Yes" : "No") << endl; 
  return 0;
}


Measured memory_bytes: 3616
//Author:Nirmit Shah
//201701044
//Daiict,Gandhinagar
 
#include<bits/stdc++.h>
using namespace std;
 
//Macros
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define error std::cerr
#define INF LONG_LONG_MAX
//#define MINF=LONG_LONG_MIN
#define MOD 1000000007
#define pii pair<int,int>
#define forn(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define ull unsigned long long
 
//Debugging
#define deb1(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 all(c) c.begin(),c.end()
 
ll min(ll x,ll y)
{
    if(x>y)
        return y;
    return x;
}
 
ll max(ll x,ll y)
{
    if(x>y)
        return x;
    return y;
}
 
ll gcd(ll x,ll y)
{
    if(!x)
        return y;
    return gcd(y%x,x);
}
 
ll calcpower(ll x, ll y)
{
    ll ans = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            ans = (ans*x) % MOD;
 
            y = y>>1;
            x = (x*x) % MOD;
    }
    return ans;
}
 
/*bool prime[1000005];
void Sieve(ll n)
{
    for(int i=0; i<1000005; i++)
        prime[i] = true;
    prime[1] = false;
    prime[0] = false;
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p])
        {
            for (ll i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
}*/
 
int main()
{
    Fast;
    string s,t;
    cin>>s>>t;
    
    int m1[256]={0},m2[256]={0};
        
        for(int i=0;i<s.length();i++)
        {
            if(m1[s[i]]!=m2[t[i]])
            {
                cout<<"No\n";
                return 0;
            }
            m1[s[i]]=i+1;
            m2[t[i]]=i+1;
        }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 916
a,b,c,d = map(int,input().split())

s=[]

s.append(a*c)
s.append(a*d)
s.append(b*c)
s.append(b*d)
if (a<=0 and b>=0) or (c<=0 and d>=0):
  s.append(0)
s.sort()

print(s[-1])

Measured memory_bytes: 9184
# D
import numpy as np
N, W = map(int, input().split())
v_list_0 = []
v_list_1 = []
v_list_2 = []
v_list_3 = []

w0, v0 = map(int, input().split())
v_list_0.append(v0)

for i in range(1, N):
    w, v = map(int, input().split())
    if w == w0:
        v_list_0.append(v)
    elif w == w0+1:
        v_list_1.append(v)
    elif w == w0+2:
        v_list_2.append(v)
    else:
        v_list_3.append(v)

# best weight
vn0 = np.cumsum([0] + sorted(v_list_0, reverse=True))
vn1 = np.cumsum([0] + sorted(v_list_1, reverse=True))
vn2 = np.cumsum([0] + sorted(v_list_2, reverse=True))
vn3 = np.cumsum([0] + sorted(v_list_3, reverse=True))

# find best n0, n1, n2, n3
vmax = 0
n3_max = min(len(v_list_3), W//(w0+3))
for n3 in range(n3_max+1):
    n2_max = min(len(v_list_2), (W - (n3*(w0+3)))//(w0+2))
    for n2 in range(n2_max+1):
        n1_max = min(len(v_list_1), (W - (n3*(w0+3) + n2*(w0+2)))//(w0+1))
        for n1 in range(n1_max+1):
            n0_max = min(len(v_list_0), (W - (n3*(w0+3) + n2*(w0+2) + n1*(w0+1)))//(w0))
            vnow = vn3[n3] + vn2[n2] + vn1[n1] + vn0[n0_max]
            if vnow > vmax:
                vmax = vnow
print(vmax)

Measured memory_bytes: 21676
N, W = map(int, input().split())
w = [0] * N
v = [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for i in range(N + 1)]

for j in range(N):
    for i in range(1, W + 1):
        if w[j] > i:
            dp[j + 1][i] = dp[j][i]
        else:
            dp[j + 1][i] = max(dp[j][i], dp[j][i - w[j]] + v[j])

print(dp[N][W])

Measured memory_bytes: 120044
N = int(input())
S = list(input())
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
X = []
Y = S
max=[]
for i in range(N):
    X.append(Y[0])
    del Y[0]
    count = 0
    for j in range(26):
        if X.count(alp[j]) > 0 and Y.count(alp[j]):
            count += 1
        max.append(count)
max.sort(reverse = True)
print(max[0])


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <array>
#include <string>

int main()
{
    long N;
    std::cin >> N;
    std::array<long, 5> s{};
    for (auto i = 0; i < N; ++i) {
        std::string name;
        std::cin >> name;
        switch (name[0]) {
        case 'M':
            s[0]++;
            break;
        case 'A':
            s[1]++;
            break;
        case 'R':
            s[2]++;
            break;
        case 'C':
            s[3]++;
            break;
        case 'H':
            s[4]++;
            break;
        default:
            break;
        }
    }

    std::cout << s[0] * s[1] * s[2]
                     + s[0] * s[1] * s[3]
                     + s[0] * s[1] * s[4]
                     + s[0] * s[2] * s[3]
                     + s[0] * s[2] * s[4]
                     + s[0] * s[3] * s[4]
                     + s[1] * s[2] * s[3]
                     + s[1] * s[2] * s[4]
                     + s[1] * s[3] * s[4]
                     + s[2] * s[3] * s[4]
              << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var split = input.Split(' ');
        int[] spliti = new int [10];
        for (int i = 0; i < 3; i++)
        {
            spliti[i] = int.Parse(split[i]);
        }
        //var input = int.Parse(Console.ReadLine());

        if (spliti[0] < spliti[1] && spliti[1] < spliti[2])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8892
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] abc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int A = abc[0];
        int B = abc[1];
        int C = abc[2];
        if (A == B && B == C)
        {
            Console.WriteLine("No");
            return;
        }
        if (A != B && B != C && C != A)
        {
            Console.WriteLine("No");
            return;
        }
        Console.WriteLine("Yes");
    }
}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int res = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                int total = 500 * a + 100 * b + 50 * c;  // 合計金額
                if (total == X) ++res;                   // 合計金額が X に一致したら答えをインクリメント
            }
        }
    }
    cout << res << endl;
}


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

int main(){
	int ret = 0;
	int n, m;
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; i++){
		int t = 0;
		for(int j=0; j<m; j++){
			int x;
			scanf("%d",&x);
			t += x;
		}
		ret = max(ret,  t);
	}
	printf("%d\n",ret);
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	if (A[0] != 0) {
		cout << -1 << endl;
	}
	else {
		bool ok = true;
		long long ans = 0;
		for (int i = 1; i < N; ++i) {
			if (A[i] - A[i - 1] >= 2) {
				ok = false;
			}
			if (A[i - 1] >= A[i]) {
				ans += A[i - 1];
			}
		}
		ans += A[N - 1];
		cout << (ok ? ans : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S;
  cin>>S;
  int N=S.size();
  string T=S;
  reverse(T.begin(),T.end());
  if(S!=T){
    cout<<"No"<<endl;
    return 0;
  }

  for(int i=0;i<N/2;i++){
    if(S[i]!=S[N/2-1-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int i=0;i<N/2;i++){
    if(S[N/2+1+i]!=S[N-1-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
F = n.times.map{gets.gsub(/\s+/,"").to_i(2)}
P = n.times.map{gets.split.map(&:to_i)}

pmax = -Float::INFINITY

1.upto((1<<10)-1) do |b|
  p = 0
  n.times do |i|
    p += P[i][(F[i] & b).to_s(2).count("1")]
  end
  pmax = [pmax, p].max
end

p pmax


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

typedef pair<int, int> P;

// 素集合データ構造
struct UnionFind {
  vector<int> par, sizes; // par:あるデータの親, sizes:あるデータが属する木のサイズ

  // コンストラクタ
  // データ一つ一つを木とし、親は自分自身に初期化する
  UnionFind(int n) : par(n), sizes(n, 1) {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  // データxが属する木の根ノードを取得
  // 再帰的に根を調べる際に、調べた辺を根に直接繋ぎ直すことで効率化している（経路圧縮）
  int find(int x) {
    return (x == par[x] ? x : par[x] = find(par[x]));
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // それぞれのデータの根ノードを取得
    x = find(x);
    y = find(y);

    // x, yが同じ木に属するならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるようにマージする
    par[y] = x;
    sizes[x] += sizes[y];
  }

  // 2つのデータx, yが同じ木に属するかどうか
  bool same(int x, int y) {
    return (find(x) == find(y));
  }

  // データxの属する木のサイズを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

// 頂点a, bを繋ぐコストcostの無向辺
struct Edge {
  int a, b, cost;

  // Edgeの比較はcostで行うことを定義している？
  bool operator<(const Edge &o) const {
    return cost < o.cost;
  }
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph {
  int n; // 頂点数
  vector<Edge> es; // 辺集合

  // クラスカル法で無向最小全域木を求め、コストの和を返す
  int kruskal() {
    // costの小さい辺から繫いでいくので、昇順にソートしておく
    sort(es.begin(), es.end());

    UnionFind uf(n);
    int min_cost = 0;
    for (int i = 0; i < es.size(); i++) {
      Edge e = es[i];
      // 辺を追加しても閉路ができないなら、辺を繋ぐ
      if (!uf.same(e.a, e.b)) {
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }

    return min_cost;
  }
};

int main() {
  int N;
  cin >> N;
  P x[N], y[N];
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &x[i].first, &y[i].first);
    x[i].second = y[i].second = i;
  }

  // 最小全域木を求めるのに辺が多すぎるので、ソートして隣り合う頂点の辺のみを残す
  sort(x, x + N), sort(y, y + N);
  Graph g;
  g.n = N;
  Edge e;
  for (int i = 0; i < N - 1; i++) {
    e.a = x[i].second, e.b = x[i+1].second, e.cost = x[i+1].first - x[i].first;
    g.es.push_back(e);
    e.a = y[i].second, e.b = y[i+1].second, e.cost = y[i+1].first - y[i].first;
    g.es.push_back(e);
  }

  // クラスカル法
  cout << g.kruskal() << endl;
  return 0;
}


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll K,N; cin>>K>>N;
  vector<ll> A(N,0);
  for(int i=0; i<N; i++){
    ll a; cin>>a; A[i]=a;
  }
  ll ans=0;
  ll b=K-A[N-1]+A[0];
  ans=max(ans,b);
  for(int i=0; i<N-1; i++)
    ans=max(ans, A[i+1]-A[i]);
  ans=K-ans;
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;

    LL ans = 0;
    rep(red, n + 1) {
        rep(green, n + 1) {
            int blue = n - red * r - green * g;
            if (blue >= 0 and blue % b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  string s;
  while(cin>>s){
    int joi=0;
    int ioi=0;
    for(int i=0;i<s.size()-2;i++){
      if(s[i+1]=='O'&&s[i+2]=='I'){
	if(s[i]=='J'){
	  joi++;
	}
	else if(s[i]=='I'){
	  ioi++;
	}
      }
    }
    cout<<joi<<endl<<ioi<<endl;
  }
}

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

int main()
{
    string S;
    int KK;

    cin >> KK;
    cin >> S;

    if(S.length() > KK)
    {
        for(int i=0; i<KK; i++)
        {
            cout << S[i];
        }
        cout << "...";
    }
    else
    {
        cout << S;
    }

    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin >> k;--k;
  cout << a[k] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
 
#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)
 
#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)
 
typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)
 
#define S_RTN(S)  s_cout(S);return 0
 
 
#define _itoa(A,N) sprintf(A, "%d", N);
 
int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);
 
int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);
 
 
int s_asorts(const void* a, const void* b);
 
//昇順
int s_asorts(const void* a, const void* b) {
    return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
    return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
    return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
    int i;
    rept(i, 0, n) {
        l_cin2(*(a + i), *(b + i));
    }
    return 0;
}
int i_cins(int n, int* a) {
    int i;
    for (i = 0; i < n; i++) {
        i_cin(*(a + i));
    }
 
    return 0;
}
int _gcd(int a, int b) {
    int r, tmp;
    if (a < b) { tmp = a; a = b; b = tmp; }
    r = a % b;
    while (r) {
        if (!r) break;
        a = b; b = r;
        r = a % b;
    }
    return(b);
}
 
long _max(long a, long b) {
    return a > b ? a : b;
}
long _min(long a, long b) {
    return a < b ? a : b;
}
int _swp(int* a, int* b)
{
    int tmp;
    tmp = *b; *b = *a; *a = tmp;
    return 0;
}

//大きい順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

//変換(文字から整数)
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}


int main(void){
    char s[101];
    int k;
    i_cin(k);
    scanf("%s",s);
    
    int i=0,cnt=0;
    while(s[i]!=0){
        cnt++;
        i++;
    }
    if(cnt<=k){
        printf("%s",s);
        return 0;
    }else{
        rept(i,0,k){
            printf("%c",s[i]);
        }
        printf("...");
    }
    
}

    




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

def dfs(s):
  if int(s) > N:
    return 0
  if(all(s.count(c) for c in '753')):
    ret = 1
  else: 
  	ret = 0
  for c in '753':
    ret += dfs(s + c)
  return ret

print(dfs('0'))






Measured memory_bytes: 2940
N=int(input())
a = list(sorted(map(int,input().split())))

result = []
# all +
if a[0] > 0:
    if len(a) == 2:
        print(a[1]-a[0])
        print(a[1], a[0])
        exit()
    result.append((a[0], a[1]))
    t = a[0]-a[1]
    a.pop(0)
    a[0] = t
# all -
elif a[-1] < 0:
    if len(a) == 2:
        print(a[0]-a[1])
        print(a[0], a[1])
        exit()
    result.append((a[-1], a[-2]))
    t = a[-1]-a[-2]
    a.pop(-1)
    a[-1] = t

# print(a)
b = []
for i in range(len(a)-1):
    if a[i] > 0:
        result.append((b[0], a[i]))
        t = b[0]-a[i]
        b[0] = t
    else:
        b.append(a[i])
b.append(a[-1])
# print(b)
while len(b) != 1:
    result.append((b[-1], b[0]))
    b.append(b[-1]-b[0])
    b.pop(0)
    b.pop(-2)
# print(b)

print(b[0])
for r in result:
    print(r[0],r[1])

Measured memory_bytes: 20604
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,m;
vector<map<int,int> > v;
vector<pint> vp;

signed main(){
    io();

    in(n,m);
    resz(n,v);
    resz(m,vp);
    rep(i,m){
        int a,b;
        in(a,b);
        a--;
        v[a][b]=i;
    }
    rep(i,n){
        int j=1;
        for(auto e:v[i]){
            //printf("%06lld%06lld\n",i+1,j);
            vp[e.sc].fs=i+1;
            vp[e.sc].sc=j;
            //show(e.fs,e.sc);
            j++;
        }
    }
    for(auto e:vp){
        printf("%06lld%06lld\n",e.fs,e.sc);
    }

    return 0;
}


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

int main()
{
  char s[28];
  int res=0;
  cin >> s;

  int N = strlen(s);
  sort(s,s+N);

  char prev='X';
  rep(i,N){
    if(prev==s[i]) {
      cout << "no" << endl;
      return 0;
    }
    prev = s[i];
  }

  cout << "yes" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
INF = float("inf")
import sys
input = sys.stdin.readline
from collections import*

def bfs():
    q = deque([(sx, sy)])
    dist = [[INF] * W for _ in range(H)]
    dist[sx][sy] = 0
    
    while q:
        x, y = q.popleft()
        b = dist[x][y]
        if (x, y) == (gx, gy):
            return b
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            nx, ny = x + dx, y + dy
            if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > b and c[nx][ny] == ".":
                dist[nx][ny] = b
                q.appendleft((nx, ny))
        b += 1
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > b and c[nx][ny] == ".":
                    dist[nx][ny] = b
                    q.append((nx, ny)) 
    return -1

H, W = map(int, input().split())
cx, cy = map(int, input().split())
dx, dy = map(int, input().split())
sx, sy, gx, gy = cx - 1, cy - 1, dx - 1, dy - 1
c = [input()[:-1] for _ in range(H)]
ans = bfs()
print(ans if ans != INF else -1)

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

int main() {
  int n;
  int num = 0;
  cin >> n;
  vector<int> p(n);
  vector<int> a;
  rep(i, n){
    cin >> p[i];
    p[i]--;
  }
  rep(i, n-1) {
    if(p[i] != i) {
      num++;
      a.push_back(i);
    }
  }
  if(num > 2){
    cout << "NO" << endl;
  }else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        ArrayList<Integer> p = new ArrayList<>();
        ArrayList<Double> expect = new ArrayList<>();
        for(int i=0; i<N; i++){
            int val = scanner.nextInt();
            p.add(val);
            expect.add( (val + 1)/2.0 );
        }
        double maxexpect = 0;
        for(int i=0; i<K; i++){
            maxexpect += expect.get(i);
        }
        double sumexpect = maxexpect;
        for(int i=1; i<N-K+1; i++){
            sumexpect = sumexpect - expect.get(i-1) + expect.get(i+K-1);
            if(sumexpect > maxexpect){
                maxexpect = sumexpect;
            }
        }
        System.out.println(maxexpect);
    }
}

Measured memory_bytes: 98220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc137_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int A, B;
  cin >> A >> B;

  cout << max(A + B, max(A - B, A * B)) << endl;
}

Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	int n;

 	scanf("%d",&n);
 	std::vector<int> a(n);
 	for(auto &x:a)scanf("%d",&x);
 	int ans = 1e9;
 	for(int i=1;i<=100;i++){
 		int curr = 0;
 		for(int j=0;j<n;j++){
 			curr += (i-a[j])*(i-a[j]);
 		}
 		ans = min(ans,curr);
 	}
 	printf("%d\n",ans );
}		


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define tc int t; cin >> t; while(t--)
using namespace std;
void fastio()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    fastio();
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i = 0; i<n; i++)cin>>a[i];
    int dp[n];
    memset(dp,INT_MAX,sizeof(dp));
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i = 2; i<n; i++)
    {
        int b = INT_MAX;
        for(int j = 1;j<=k&&i-j>=0;j++)
        {
            b = min(b,dp[i-j]+abs(a[i]-a[i-j]));
        }
        dp[i] = b;
    }
    cout<<dp[n-1];
}


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

int main() {
  int N,T,A;
  cin>>N>>T>>A;
  vector<int> H(N);
  rep(i,N) cin>>H[i];
  double x = abs(T-H[0]*0.006-A);
  int ans;
  rep(i,N){
    x = min(x,abs(T-H[i]*0.006-A));
    if(x==abs(T-H[i]*0.006-A)) ans=i+1;
  }
  cout << ans << endl;
  return 0;  
    

}


Measured memory_bytes: 256