akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int N;
string s, t;

bool solve() {
  repp(i, 2, N - 1) {
    if ((t[i - 1] == 'S' && s[i - 1] == 'o') ||
        (t[i - 1] == 'W' && s[i - 1] == 'x')) {
      t[i] = t[i - 2];
    } else {
      if (t[i - 2] == 'S')
        t[i] = 'W';
      else
        t[i] = 'S';
    }
  }

  bool ok = true;
  if ((t[0] == 'S' && s[0] == 'o') || (t[0] == 'W' && s[0] == 'x')) {
    if (t[1] != t[N - 1])
      ok = false;
  } else {
    if (t[1] == t[N - 1])
      ok = false;
  }

  if ((t[N - 1] == 'S' && s[N - 1] == 'o') ||
      (t[N - 1] == 'W' && s[N - 1] == 'x')) {
    if (t[0] != t[N - 2])
      ok = false;
  } else {
    if (t[0] == t[N - 2])
      ok = false;
  }
  return ok;
}

int main() {
  cin >> N;
  cin >> s;

  t = s;

  t[0] = 'S';
  t[1] = 'S';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'S';
  t[1] = 'W';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'W';
  t[1] = 'S';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'W';
  t[1] = 'W';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  cout << -1 << endl;
}

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

int main() {
	int n;
	cin>>n;
	int a[n],i,j;
	for(i=0;i<=n;i++)
	{
	    cin>>a[i];
	}
	int b[n]={0},count=0;
	for(i=0;i<n;i++)
	{

	    
	    if(a[i-1]>=a[i])
	    {
	        count++;
	        b[i]=count;
	    }
	    else
	    count=0;
	}
	sort(b,b+n);
	    cout<<b[n-1];
	return 0;
}

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


int main(){
    string s,ans;
    int k;
    cin >> k;
  	cin >> s;
    int ss = s.size();
    if(ss <= k){
      cout << s << endl;
      return 0;
    }else if(ss > k){
      for (int i=0 ;i < k;i++){
        ans += s[i];
      }
    }
    cout << ans << "..." << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;




public class Main{
	static class MyScanner {
	    BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    } 

	    int nextInt() { return Integer.parseInt(next());}

	    long nextLong() {return Long.parseLong(next());}

	    double nextDouble() {return Double.parseDouble(next());}

	    String nextLine(){
	        String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	    }
	}
		
	
		 public static void main(String[] args) throws IOException {
			 	PrintWriter out = new PrintWriter(System.out);
			    MyScanner sc = new MyScanner();
			 	Main solver = new Main();
				solver.solve(out, sc);
				out.flush();
				out.close();
			
		 }
	
		
		 
		 
		
 		void solve(PrintWriter out, MyScanner sc) throws IOException{	
 		
 			int a = sc.nextInt();
 			int b = sc.nextInt();
 			int c = sc.nextInt();
 			
 			if(a == 7 && b == 5 && c == 5 || a == 5 && b == 7 && c == 5 || a == 5 && b == 5 && c == 7) out.print("YES");
 			else out.println("NO");
 			
 			
 		

 			
 			
 			
 		
 		}
 		
 		

 	
		
	
			
		
		
		
		
		
		
		
		
	
	
}



Measured memory_bytes: 21076
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int a, b, c, d;cin>>a>>b>>c>>d;
  while(true){
    c-=b;
    if(c<=0){cout<<"Yes";return 0;}
    a-=d;
    if(a<=0){cout<<"No";return 0;}
  }
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3576
import io.StdIn.readLine
object Main extends App {
  val mod = 1000000007
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val xs = readLine.split(" ").toSeq.map(_.toLong)
  val ys = readLine.split(" ").toSeq.map(_.toLong)
  val lx = (for (i <- 0 until n) yield xs(i) * (2 * i - n + 1)).reduce((a, b) => (a + b) % mod)
  val ly = (for (j <- 0 until m) yield ys(j) * (2 * j - m + 1)).reduce((a, b) => (a + b) % mod)
  println(lx * ly % mod)
}


Measured memory_bytes: 80576
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int main(){
	int h,w;
	string s[50];
	cin>>h>>w;
	for(int i=0;i<h;i++)
		cin>>s[i];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='.')
				continue;
			bool ok=false;
			for(int k=0;k<4;k++){
				int nx=i+dx[k],ny=j+dy[k];
				if(0<=nx&&nx<h&&0<=ny&&ny<=w&&s[nx][ny]=='#')
					ok=true;
			}
			if(!ok){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
}


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

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

int main() {
	ll N; cin >> N;
	ll a[100000] = {};

	ll x = 0, y = 0, z = 0;
	rep(i, 0, N) {
		ll p; cin >> p;
		if (p % 4 == 0)x++;
		else if (p % 2 == 0)y++;
		else z++;
	}
	if (y >= 1)y = 1;

	cout << ((x >= y + z - 1) ? "Yes" : "No") << endl;

	return 0;
}

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


int main(){
  int N;
  cin >> N;
  int div[9][9];
  for(int i=0; i<9; i++){
    for(int j=0; j<9; j++) div[i][j]=0;
  }
  for(int i=1; i<=N; i++){
    int bottom=i%10;
    if(bottom==0) continue;
    int top=i;
    while(top>9){
      top/=10;
    }
    div[top-1][bottom-1]++;
  }
  int ans=0;
  for(int i=0; i<9; i++){
    for(int j=0; j<9; j++){
      ans+=div[i][j]*div[j][i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  string S;
  cin>>S;
  rep(i,(S.size()+1)/2){
    if(S.at(i)!=S.at(S.size()-i-1)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  rep(i,((S.size()-1)/2-1)/2){
    if(S.at(i)!=S.at((S.size()-1)/2-1-i)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  int j=0;
  for(int i=(S.size()+3)/2-1;i<S.size()-1;i++,j++){
    if(S.at(i)!=S.at(S.size()-1-j)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3604
N, K = map(int,input().split())
p = list(map(int,input().split()))

li = [0] * N
for i in range(N): li[i] = sum(range(1, p[i]+1)) / p[i]

ans, total = sum(li[:K]), sum(li[:K])
if N != K:
  for i in range(1, N - K + 1):
    total = total - li[i-1] + li[i-1+K]
    ans = max(ans, total)
  print(ans)
else: print(ans)

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

class UnionFind{
    vector<int> par;
    vector<long long> wei;
    int groupCount;

public:
    UnionFind(int n = 0){
        init(n);
    }

    void init(int n = 0){
        par.resize(n);
        fill(par.begin(), par.end(), -1);

        wei.resize(n);
        fill(wei.begin(), wei.end(), 0LL);

        groupCount = n;

        return;
    }

    int root(int x){
        if(par[x] < 0){
            return x;
        }
        int r = root(par[x]);
        wei[x] += wei[par[x]];
        return par[x] = r;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return -par[root(x)];
    }

    long long weight(int x){
        root(x);
        return wei[x];
    }

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

    bool unite(int x, int y, long long w = 0){
        w += weight(x) - weight(y);

        x = root(x);
        y = root(y);

        if(x == y){
            return false;
        }

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

        par[x] += par[y];
        par[y] = x;
        wei[y] = w;
        --groupCount;

        return true;
    }

    int size(void){
        return groupCount;
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    for(int i = 0 ; i < m ; ++i){
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    UnionFind uf(n);
    vector<long long> ans(m);
    long long now = (long long)n * (n - 1LL) / 2LL;
    for(int i = m - 1 ; i >= 0 ; --i){
        ans[i] = now;
        long long as = uf.size(a[i]), bs = uf.size(b[i]);
        if(uf.unite(a[i], b[i])){
            now -= as * bs;
        }
    }

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

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int mod = 1000000007;



int main()
{
  string s,t;
  cin>>s>>t;
  vector<vector<ll>> a(30);
  ll n=s.size();
  rep(i,n){
    char c_now=s[i];
    a[c_now-'a'].push_back(i);
  //  a[c_now-'a'].push_back(i+s.size());

  }
  rep(i,n){
    char c_now=s[i];
//    a[c_now-'a'].push_back(i);
    a[c_now-'a'].push_back(i+s.size());

  }
  //cout<<a['o'-'a'][0]<<endl;
  //cout<<a['t'-'a'][0]<<endl;
  ll ans=0;
  ll now=0;
  rep(i,t.size()){
    int c=t[i]-'a';
  //  cout<<a[c][0]<<endl;

    if (a[c].size()==0){
      ans=-1;break;
    }

    else{

      int idx=*lower_bound(a[c].begin(),a[c].end(),now)+1;
    //  cout<<idx<<endl;
      now=idx;
      if (idx>=s.size()) {
        now-=s.size();ans+=s.size();
    }
    else{
      now=idx;
    //  cout<<now<<endl;
    }

  }
//  cout<<now<<endl;



}
if (ans==-1)cout<<ans;
else{
  ans+=now;
  cout<<ans;
}
}


Measured memory_bytes: 2800
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

#define INF INT_MAX / 2 - 1
#define PI 2*acos(0.0)
#define ll long long

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

int main() {
	int x = 0;
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	REP (i, n) {
		if (s[i] == 'I') {
			x++;
		}
		else if (s[i] == 'D') {
			x--;
		}
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

#define ll long long
const int maxN = 100005;
const ll INF = 1000000000000000000LL;

class TaskA {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		ll d, limit;
		cin >> d >> limit;
		ll v;
		cin >> v;
		// d = v * t
		cout << ( d  <= limit * v ? "Yes":"No") << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskA solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3648
S=list(input())
b1=int(S[0]+S[1])
b2=int(S[2]+S[3])
if 0<b1<13 and 0<b2<13:
    print('AMBIGUOUS')
    #==========
elif (b1==0 or b1>12) and 13>b2>0:
    print('YYMM')
elif 0<b1<13 and (b2==0 or b2>12):
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38256
#include <cstdio>

using namespace std;

struct point
{
    int x, y, value;
};

int absolute (int a)
{
    if(a<0)
        return -1 * a;
    return a;
}

int maximum (int a, int b)
{
    if(a>=b)
        return a;
    else
        return b;
}

int line, column;

int distance (point a)
{
    return absolute(a.x - line) + absolute(a.y - column);
}

point hints[105];

int main()
{
    bool isOk;
    int n, height, index;

    scanf("%d", &n);
    for(int i=1; i<=n; i++)
        scanf("%d %d %d\n", &hints[i].x, &hints[i].y, &hints[i].value);

    for(line=0; line<=100; line++)
    {
        for(column=0; column<=100; column++)
        {
            isOk = true;

            for(index=1; index<=n; index++)
            {
                if(hints[index].value !=0)
                {
                    height = hints[index].value + distance(hints[index]);
                    break;
                }
            }

            for(index=1; index<=n; index++)
                if(maximum(height - distance(hints[index]), 0) != hints[index].value)
                    isOk = false;

            if(isOk == true)
                break;
        }

        if(isOk == true)
            break;
    }

    printf("%d %d %d\n", line, column, height);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 55;
const int dr[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dc[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int H, W;
char M[SIZE][SIZE];
int count(int x, int y){
	int sum = 0, r, c;
	for(int i = 0; i < 8; i ++){
		r = x + dr[i];
		c = y + dc[i];
		if(r >= 0 && r < H && c >= 0 && c < W && M[r][c] == '#')sum ++;
	}
	return sum;	
}
int main(){
	cin>>H>>W;
	for(int i = 0; i < H; i ++)cin>>M[i];
	for(int i = 0; i < H; i ++)
		for(int j = 0; j < W; j ++)
			if(M[i][j] == '.')M[i][j] = '0' + count(i, j);
	for(int i = 0; i < H; i ++)cout<<M[i]<<endl;
	return 0;
} 

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    int val = Integer.parseInt(sc.next());
    char[][] map = new char[h][w];
    for(int i=0;i<h;i++){
      map[i] = sc.next().toCharArray();
    }
    int res = 0;
    for(int i=0;i<(1<<h);i++){
      for(int j=0;j<(1<<w);j++){
        int count = 0;
        for(int k=0;k<h;k++){
          for(int l=0;l<w;l++){
            if(((i>>k) & 1)==0 && ((j>>l) & 1)==0 && map[k][l]=='#'){
              count++;
            }
          }
        }
        if(count==val){
          res++;
        }
      }
    }
    System.out.println(res);
  }
}

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

vector<int> v;
int a[10001];

int main()
{	
	for (int i = 0; i <= 1000; i++){
		for (int j = 0; j <= 1000; j++){
			a[i + j]++;
		}
	}
	
	int n;
	while (~scanf("%d", &n)){
		int res = 0;
		for (int i = 0; i <= n; i++){
			res += a[i] * a[n - i];
		}
		printf("%d\n", res);
	}
}

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

using namespace std;

using ll = long long;

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

    ll n, min_cap;
    cin >> n >> min_cap;
    for (ll i = 0, x; i < 4; ++i) {
        cin >> x;
        min_cap = min(x, min_cap);
    }

    cout << 5 + (n + min_cap - 1) / min_cap - 1 << endl;

    return 0;
}
 

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

using namespace std;

using mask_t = int;

int solve(const std::vector<int>& ls, int a, int b, int c) {
  int const n = ls.size();
  mask_t const endMask = 1 << n;
  std::pair<int, int> valueAndMpTbl[256];
  for (mask_t mask = 1; mask < endMask; ++mask) {
    int value = 0;
    int mp = 0;
    std::bitset<8> bits{static_cast<unsigned long long>(mask)};
    for (int i = 0; i < 8; ++i) {
      if (!bits.test(i)) {
        continue;
      }
      if (value != 0) {
        mp += 10;
      }
      value += ls[i];
    }
    valueAndMpTbl[mask] = std::make_pair(value, mp);
  }
  int ret = INT_MAX;
  for (mask_t aMask = 1; aMask < endMask; ++aMask) {
    auto const aValueAndMp = valueAndMpTbl[aMask];
    int aCandidate = aValueAndMp.second + abs(a - aValueAndMp.first);
    if (aCandidate >= ret) {
      continue;
    }
    for (mask_t bMask = 1; bMask < endMask; ++bMask) {
      if ((aMask & bMask) != 0) {
        continue;
      }
      auto const bValueAndMp = valueAndMpTbl[bMask];
      int bCandidate =
          aCandidate + bValueAndMp.second + abs(b - bValueAndMp.first);
      if (bCandidate >= ret) {
        continue;
      }
      for (mask_t cMask = 1; cMask < endMask; ++cMask) {
        if ((aMask & cMask) != 0) {
          continue;
        }
        if ((bMask & cMask) != 0) {
          continue;
        }
        auto const cValueAndMp = valueAndMpTbl[cMask];
        int cCandidate =
            bCandidate + cValueAndMp.second + abs(c - cValueAndMp.first);
        if (cCandidate >= ret) {
          continue;
        }
        ret = std::min(cCandidate, ret);
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, a, b, c;
  std::cin >> n >> a >> b >> c;
  std::vector<int> ls(n);
  bool aExists = false;
  bool bExists = false;
  bool cExists = false;
  for (auto& l : ls) {
    std::cin >> l;
    if (!aExists && l == a) {
      aExists = true;
    } else if (!bExists && l == b) {
      bExists = true;
    } else if (!cExists && l == c) {
      cExists = true;
    }
  }

  if (aExists && bExists && cExists) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::vector<int> needs;
  std::cout << solve(ls, a, b, c) << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int w=fs.nextInt(), h=fs.nextInt();
		h=w=(int)1e6;
		int n=fs.nextInt();
		int[] xs=new int[n];
		int[] ys=new int[n];
		HashSet<Long> points=new HashSet<>();
		int[] onX=new int[w+1], onY=new int[h+1];
		for (int i=0; i<n; i++) {
			xs[i]=fs.nextInt();
			ys[i]=fs.nextInt();
			points.add(hash(xs[i], ys[i]));
			onX[xs[i]]++;
			onY[ys[i]]++;
		}
		int maxX=0, maxY=0;
		for (int x=0; x<=w; x++) maxX=Math.max(maxX, onX[x]);
		for (int y=0; y<=h; y++) maxY=Math.max(maxY, onY[y]);
		ArrayList<Integer> candidateXs=new ArrayList<>();
		ArrayList<Integer> candidateYs=new ArrayList<>();
		for (int x=0; x<w; x++)
			if (onX[x]==maxX) candidateXs.add(x);
		for (int y=0; y<h; y++)
			if (onY[y]==maxY) candidateYs.add(y);
		int ans=maxX+maxY-1;
		outer: for (int x:candidateXs) {
			for (int y:candidateYs) {
				if (!points.contains(hash(x, y))) {
					ans++;
					break outer;
				}
			}
		}
		
		System.out.println(ans);
	}

	static long hash(int x, int y) {
		return x*1_000_000_000l+y;
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 90116
#include<stdio.h>
int main(void)
{
	int H,R;
	scanf ("%d%d",&H,&R);
	if (H+R==0)
	printf ("0\n");
	else if (H+R>0)
	printf ("1\n");
	else
	printf ("-1\n");
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
	// int dx[4]    = {1, 0, -1, 0};
	// int dy[4]    = {0, 1, 0, -1};
	// ll pas[5001][5002];

#include <vector>

struct UnionFind {
  private:
	std::vector<int> rank, par, col;
	int n_;

  public:
	UnionFind(int n) : n_(n) {
		rank.resize(n, 1);
		par.resize(n);
		for (int i = 0; i < n; ++i) { par[i] = i; }
		col.resize(n, 1);
	}
	int root(int i) {
		while (par[i] != i) { i = par[i]; }
		return i;
	}
	bool isSame(int x, int y) { return root(x) == root(y); }
	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (isSame(x, y)) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			col[y] += col[x];
		} else {
			if (rank[x] == rank[y]) rank[x]++;
			par[y] = x;
			col[x] += col[y];
		}
	}
	int cnt(int x) {
		x = root(x);
		return col[x];
	}
};

bool used[114514] = {};
int cnt			  = 0;

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	UnionFind uf(m + 1);
	int k, a, b;
	for (int i = 0; i < n; ++i) {
		cin >> k;
		cin >> a;
		if (!used[a]) cnt++;
		used[a] = true;
		for (int i = 1; i < k; ++i) {
			cin >> b;
			if (!used[b]) cnt++;
			used[b] = true;
			uf.unite(a, b);
		}
	}

	dump(uf.cnt(a) == cnt ? "YES" : "NO");
	return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    for(int i = 0; i < K; i++)
        cin >> D.at(i);
    int num = 0;
    while(1){
        int v = N + num;
        bool j = true;
        while(v > 0){
            int k = v % 10;
            v /= 10;
            for(int i = 0; i < K; i++){
                if(k == D.at(i)) j = false;
            }
        }
        if(j == true) break;
        num++;
    }
    cout << N + num;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;
int main (){
    
    int N;
    cin >> N ;
    string S,T;
    cin >> S >> T;

    for (int i=0;i<N;i++){
        cout << S[i] << T[i];
    }


}

Measured memory_bytes: 256
N = int(input())
l = list(map(int,input().split()))
l.sort()
s = 0
for i in range(int(len(l)/2)):
  if l[2*i] * l[2*i+1]>0:
  	s += abs(l[2*i] + l[2*i+1])
  else:
    l1 = l[2*i] + l[2*i+1]
    l2 = - l1
    s += l1 if l1>l2 else l2
if(len(l)%2==1):
  s += l[-1]
  
print(s)

Measured memory_bytes: 64752
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	i64 n, m; cin >> n >> m;
	std::string s, t; cin >> s >> t;
	
	i64 l = n * m / std::__gcd(n, m);
	
	std::map<i64, char> d;
	for(i64 i = 0, j = 0; i < l and j < n; i += l / n, j++) d[i] = s[j];
	for(i64 i = 0, j = 0; i < l and j < m; i += l / m, j++) {
		if(!d.count(i)) continue;
		if(d[i] != t[j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << l << endl; 
	return 0;
}


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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<set<int> > ichi(30);
    for (int i = 0; i < N; i++) ichi[S[i]-'a'].insert(i);
    int Q; cin >> Q;
    for (int _ = 0; _ < Q; _++) {
        int o; cin >> o;
        if (o == 1) {
            int i; char c; cin >> i >> c;
            i--;
            if (S[i] != c) {
                ichi[S[i]-'a'].erase(i);
                S[i] = c;
                ichi[S[i]-'a'].insert(i);
            }
        } else {
            int l, r; cin >> l >> r;
            l--; r--;
            int ans = 0;
            for (int i = 0; i < 26; i++) {
                if (ichi[i].size() > 0 && ichi[i].lower_bound(l) != ichi[i].end()) {
                    int hoge = *(ichi[i].lower_bound(l));
                    if (l <= hoge && hoge <= r) ans++;
                }
            }
            cout << ans << endl;
        }
    }
}


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

using namespace std;

int main() {
    
    long long int n, a[200001], i, k, exist[200001]={}, x, big, end, t, imsi;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    cin>>a[i];
    x=1;
    t=1;
    exist[1]=1;
    while(1)
    {
        x=a[x];
        t++;
        exist[x]+=1;
        if(exist[x]>1)
        {
            end=t;
            imsi=x;
            break;
        }
        
    }
    x=1;
    t=1;
    while(x!=imsi)
    {
        t++;
        x=a[x];
        
    }
    big=t;
    if(k>=end)
    k=big+(k-big)%(end-big);
    x=1;
    for(i=1;i<=k;i++)
    x=a[x];
    cout<<x;
    return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N, L;
    cin >> N >> L;
    vector<int> a(N);
    for (int i = 0; i < N; i++)cin >> a[i];

    for (int i = 0; i < N - 1; i++) {
        if (a[i] + a[i + 1] >= L) {
            cout << "Possible" << endl;
            int left = 0, right = N - 1;
            for (int j = 0; j < N - 1; j++) {
                if (left < i) {
                    cout << ++left << endl;
                } else {
                    cout << right-- << endl;
                }
            }
            return 0;
        }
    }
    cout << "Impossible" << endl;

    return 0;
}

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

void dfs(const int N, vector<int> now, set<vector<int>>& res) {
    if (now.size() == N) {
        res.insert(now);
        return;
    }
    int lim = (now.empty() ? 0 : *max_element(now.begin(), now.end()) + 1);
    rep(next, lim + 1) {
        now.push_back(next);
        dfs(N, now, res);
        now.pop_back();
    }
}

set<vector<int>> make_cands(int N) {
    set<vector<int>> cands;
    dfs(N, vector<int>(), cands);
    return cands;
}

int main()
{
    int N;
    cin >> N;
    auto cands = make_cands(N);
    for (auto cand : cands) {
        string s;
        for (auto diff : cand)s += 'a' + diff;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(){
	int a,b;
	int v[4];
	while(cin>>a>>b,a||b){
		int ans=INF;
		for(int i=1;i*i<=a;i++){
			if(a%i)continue;
			for(int j=1;j*j<=b;j++){
				if(b%j)continue;
				v[0]=i;
				v[1]=a/i;
				v[2]=j;
				v[3]=b/j;
				sort(v,v+4);
				int s=0;
				rep(i,3){
					s += (v[i]-v[i+1])*(v[i]-v[i+1]);
				}
				ans = min(ans,s);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
using namespace std;
int main(){
    int i,n,maxi=-1,pos,tt=0;
    cin >> n;
    int p[n];
    for(i=0;i<n;i++){
        cin >>p[i];
        if(p[i]>maxi){
            maxi = p[i];
            pos = i;
        }
    }
    for(i=0;i<n;i++){
        if(i!=pos){
            tt = tt+p[i];
        }
    }
    cout << tt+p[pos]/2;


}

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

int n,k,a[105],dp[100005];

int main() {
	scanf("%d%d",&n,&k);
	for (int i=0; i<n; i++) {
		scanf("%d",&a[i]);
	}
	memset(dp,0,sizeof(dp));
	for (int i=1; i<=k; i++) {
		int win = 0;
		for (int j=0; j<n; j++) {
			if (i-a[j] >= 0 && dp[i-a[j]] == 0) {
				win = 1;
				break;
			}
		}
		dp[i] = win;
	}
	if (dp[k] == 1) printf("First\n");
	else printf("Second\n");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - a + b);

}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(), (VECTOR).end()

int main(){

	int N;
	cin >> N;
	vector<pint> RED, BLUE;
	vector<bool> RFlag(N, false), BFlag(N, false);
	int x, y;
	for(int i = 0; i < N; i ++){
		cin >> x >> y;
		RED.pm(y, x);
	}
	for(int i = 0; i < N; i ++){
		cin >> x >> y;
		BLUE.pm(x, y);
	}
	sort(all(RED));
	sort(all(BLUE));

	//青点をx座標の小さいほうから調べる
	for(int i = 0; i < N; i ++){
		//赤点をy座標が大きいほうから調べる
		for(int j = N - 1; j >= 0; j --){
			if(!RFlag[j] && RED[j].first < BLUE[i].second && RED[j].second < BLUE[i].first){
				RFlag[j] = true;
				BFlag[i] = true;
				break;
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < N; i ++){
		if(RFlag[i])cnt ++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int a,b,c,d;
  char s[10]; 
  scanf("%s",s);
  if(s[2]==s[3]&&s[4]==s[5]){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 1636
#include<iostream>
#include<string>
#include<vector>
#include <cstdlib>
#include<cctype>
#include <algorithm>    
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define VCOUT(num) for(auto& num:vec)
#define GET_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define LLINF 1000000000000000000//10^18
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000
#define MAX 100
#define MX 10

//int main(int argc, char const* argv[]){

int main(){ 
    vector<int>vec;
     vector<char>cvec;
      vector<string>svec;
    
   int a,b,x,y,z,count=0;
 
   cin>>x;
   a=x/3600;
   b=(x-a*3600)/60;
   y=x-a*3600-b*60;
   
   
    
 
  cout<<a<<":"<<b<<":"<<y<<endl;
    return 0;
}




Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

ll b[200001] = {};
int main() {
	string s; cin >> s;
	ll b_cnt = 0;
	ll total = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'B') {
			b_cnt++;
			continue;
		}
		else {
			total += b_cnt;
		}
	}
	cout << total << endl;
	return 0;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
	int a,b ;
	cin >> a >> b;
	cout<<a*b-(a+b)+1<<endl;
}



Measured memory_bytes: 256
n = gets.to_i

if n <= 9
  res = n
elsif 10 <= n && n <= 99
  res = 9
elsif 100 <= n && n <= 999
  res = (n - 99) + 9
elsif 1000 <= n && n <= 9999
  res = 9 + 900
elsif 10000 <= n && n <= 99999
  res = 9 + 900 + (n - 9999)
else
  res = 9 + 900 + 90000
end

puts res


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

int x,n;
set<int> p;

signed main() {
  cin >> x >> n;
  rep(i,n) {
    int a; cin >> a; 
    p.insert(a);
  }
  int ans = -1;
  for(int i=0; i<=101; i++) {
    if(p.count(i))continue;
    if(abs(x-ans) > abs(x-i)) ans = i;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3680
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
T = IL()
s = sum(T)
M = I()
D = ILL(M)
for m,t in D:
  P(s-T[m-1]+t)


Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

int n,s;
int dp[10][1<<10][333];

int f(int now, int used, int sum){
    if(sum < 0)return 0;
    if(now == n)return sum == 0;
    if(dp[now][used][sum] != -1) return dp[now][used][sum];
    int ret = 0;
    rep(i,10)if(used & (1<<i)){
        ret += f(now+1, used&~(1<<i), sum-i*(now+1));
    }
    dp[now][used][sum] = ret;
    return ret;
}

signed main(void) {
    while(cin >> n >> s){
        rep(i,10)rep(j,1<<10)rep(k,333)dp[i][j][k] = -1;
        if(s <= 330)cout << f(0, (1<<10)-1, s) << endl;
        else cout << 0 << endl;
    }
}



Measured memory_bytes: 29628
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
s = list(map(int, [input() for i in range(n)]))
l = [
  [0, 0, 0]
  , [0, 0, 0]
  , [0, 0, 0]
]
for i in range(0, 3):
  for j in range(0, n):
    if a1[i] == s[j]:
      l[0][i] = i+1
for i in range(0, 3):
  for j in range(0, n):
    if a2[i] == s[j]:
      l[1][i] = i+1
for i in range(0, 3):
  for j in range(0, n):
    if a3[i] == s[j]:
      l[2][i] = i+1
n = []
for i in l:
  for j in i:
    if j != 0:
      n.append(j)
count = 0
for i in range(0, 3):
  if l[i][0] and l[i][1] and l[i][2]:
    count += 1
if (l[0][0] and l[1][1] and l[2][2]) or (l[2][0] and l[1][1] and l[0][2]):
  count += 1
else:
  for i in range(1, 4):
    if n.count(i) == 3:
      count += 1
print('Yes' if count >= 1 else 'No')

Measured memory_bytes: 3064
#16　AtCoder Beginner Contest 150 C - Count Order
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
ans = 0
j = 0
for i in itertools.permutations(range(1, n+1)):
    j += 1
    if p == i: ans += j
    if q == i: ans -= j
print(abs(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool cmp(const P &a, const P &b) {
    return a.first > b.first;
}
int main() {
    int n, m; cin >> n >> m;
    vector<P> a;
    rep(i, n) {
        ll x; cin >> x;
        a.push_back({x,1});
    }
    rep(i, m) {
        ll b, c; cin >> b >> c;
        a.push_back({c,b});
    }
    sort(a.begin(),a.end(),cmp);
    ll cnt = 0;
    ll ans = 0;
    for(int i=0;i<n&&cnt<n;i++) {
        ll tmp = a[i].first;
        ll c = a[i].second;
        if(cnt+c<=n){
            cnt += c;
            ans += tmp*c;
        }else{
            ans += tmp*(n-cnt);
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 6512
def tree_diameter(T, w):
    N = len(T)
    v = 0
    def dfs(r):
        depth = [-1] * N # the depth of each vertex
        stack = [(r, -1, 0)] # (vertex, parent, status)
        d = 0 # current depth
        while stack:
            v, p, st = stack.pop()
            if st == 0: # visited v for the first time
                d += (0 if p == -1 else w[p][v])
                depth[v] = d
                n_children = 0
                for u in T[v]:
                    if depth[u] >= 0:
                        continue
                    if n_children == 0:
                        stack += [(v, p, 2), (u, v, 0)]
                        n_children += 1
                    else:
                        stack += [(v, p, 1), (u, v, 0)]
                        n_children += 1
                if n_children == 0: # v is a leaf
                    d -= (0 if p == -1 else w[p][v])
            elif st == 1: # now searching
                continue
            else: # search finished
                d -= (0 if p == -1 else w[p][v])
        return depth
    
    dist = dfs(v)
    u, _ = max(enumerate(dist), key=lambda x: x[1])
    dist = dfs(u)
    v, d = max(enumerate(dist), key=lambda x: x[1])
    return (u, v), d

INF = float('inf')
N = int(input())
E = [[] for _ in range(N)]
weight = [{} for _ in range(N)]
for _ in range(N-1):
    s, t, w = map(int, input().split())
    E[s].append(t); E[t].append(s)
    weight[s].setdefault(t, w); weight[t].setdefault(s, w)
_, d = tree_diameter(E, weight)
print(d)


Measured memory_bytes: 65032
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using Graph = vector<vector<int>>;
int N, M, K;
int id;
vector<int> cc_id;   
vector<int> cc_num;  
void dfs(const Graph &G, int v, int &cnt) {
    cc_id[v] = id;
    cnt++;
    for (auto i : G[v]) {
        if (cc_id[i] != -1) continue;
        dfs(G, i, cnt);
    }
}
int main() {
    cin >> N >> M >> K;
    Graph G(N);  
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A.at(i) >> B.at(i);
        A[i]--, B[i]--;
        G[A[i]].push_back({B[i]});
        G[B[i]].push_back({A[i]});
    }
    vector<int> C(K), D(K);
    REP(i, K) {
        cin >> C.at(i) >> D.at(i);
        C[i]--, D[i]--;
    }
    cc_id.assign(N, -1);  
    id = 0;
    REP(i, N) {
        if (cc_id[i] == -1) {
            int cnt = 0;
            dfs(G, i, cnt);
            cc_num.push_back(cnt);
            id++;
        }
    }
    vector<int> ans(N);
    REP(i, N) ans[i] = cc_num[cc_id[i]] - 1 - (int)G[i].size();
    REP(i, K) {  
        if (cc_id[C[i]] == cc_id[D[i]]) {
            ans[C[i]]--;
            ans[D[i]]--;
        }
    }
    REP(i, (int)ans.size()) {
        cout << ans[i];
        if (i != (int)ans.size() - 1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 12084
import java.util.*;

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

        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int[] k = new int[n - 1];

        for(int i = 1; i <= n - 1; i++){
            for(int j = i + 1; j <= n; j++){
                int min = Math.min(j - i, Math.abs(x - i) + 1 + Math.abs(j - y));
                //System.out.println(i+" "+j+" "+min);
                k[min - 1]++;
            }
        }

        for(int i : k){
            System.out.println(i);
        }
    }
}


Measured memory_bytes: 22356
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
#define MOD 1000000007
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    cin>>N;
    ll count=1;
    rep1(i, N){
        count*=i;
        count%=MOD;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A = int(input())
	B = int(input())
	D = defaultdict(int)
	D[A] += 1
	D[B] += 1
	if D[1] == 0:
		print(1)
	elif D[2] == 0:
		print(2)
	else:
		print(3)
	


if __name__ == '__main__':
	main()

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

using namespace std;

#define N 200005

int n, a[N], f[N], len = 0, head[N], nxt[N << 1], to[N << 1], cnt = 0;

void add(int x, int y)
{
	cnt++;
	to[cnt] = y, nxt[cnt] = head[x], head[x] = cnt;
}

int ans[N];

void dfs(int x, int fa)
{
	// cout << x << ' ' << len << ' ' << f[len] << endl;
	bool add = 0;
	int pos = 0, pre = 0;
	if(a[x] > f[len]) f[++len] = a[x], add = 1;
	else 
	{
		int p = lower_bound(f + 1, f + len + 1, a[x]) - f;
		pre = f[p], f[p] = a[x], pos = p;
	}
	ans[x] = len;
	for(int p = head[x]; p; p = nxt[p])
	{
		int v = to[p];
		if(v == fa) continue;
		dfs(v, x);
	}
	if(add) f[len--] = 0;
	else f[pos] = pre;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i <= n - 1; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	dfs(1, 0);
	for(int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 23592