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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n - 1) {
    if(a[i] == a[i + 1]) {
      a[i + 1] = 1000000;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

def to_num_list(s):
    seen = {}
    ret = []
    idx = 0
    for ch in s:
        if ch not in seen:
            seen[ch] = idx
            idx += 1
        ret.append(seen[ch])
    return ret

if to_num_list(S) == to_num_list(T):
    print('Yes')
else:
    print('No')


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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;

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

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
signed main(){
	string s;
	cin>>s;
	int n=s.size();
	int cnt=0;
	rep(i,n)if(s[i]=='p')cnt++;
	cout<<n/2-cnt<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string s, t;
string ans;
int LCS[3005][3005];

int main(){
	cin >> s;
	cin >> t;
//	cout << "still\n";
	for(int i = 1; i <= s.size(); i++){
		for(int j = 1; j <= t.size(); j++){
//			cout << i << " " << j << "\n";
			if(s[i-1] == t[j-1]) LCS[i][j] = LCS[i-1][j-1] + 1;
			else LCS[i][j] = max(LCS[i-1][j], LCS[i][j-1]);
		}
	}
	int i = s.size();
	int j = t.size();
	while(i != 0 and j != 0){
		if(LCS[i-1][j] == LCS[i][j]) i--;
		else if(LCS[i][j-1] == LCS[i][j]) j--;
		else{
			ans = ans + s[i-1];
			i--;
			j--;
		}
	}
	for(int k = ans.size() - 1; k >= 0; k--){
		cout << ans[k];
	}
	return 0;
}

Measured memory_bytes: 35456
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int a[] = new int[n];
        double sum=0.0;
        for(int i=0;i<n;i++) a[i] = in.nextInt();
        for(int i=0;i<n;i++){
            sum+=(1/(a[i]+.0));
        }
        sum = 1/sum;
        out.println(sum);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22356
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int v[1111];
int n;
vector<int> ans;
void make_op(int parity, int pos = -1){
	vector<int> mark(n, 0);
	
	if(pos == -1)
		for(int i = parity; i < n; i+=2){
			if(v[i] >= 0)
			mark[i] = 1;
		}
	else mark[pos] = 1;
	//cout << pos << endl;
 
	while(mark.size() > 1){
 
		for(int l = 0; l < mark.size(); l++){
			if(mark[l]) continue;
			if(l == 0 || l == mark.size()-1){
				ans.push_back(l+1);
				mark.erase(mark.begin() + l);
				continue;
			}
			if((mark[l-1] && mark[l+1]) || (!mark[l-1] && !mark[l+1])){
				ans.push_back(l+1);
				if(mark[l-1]) mark[l] = 1;
				mark.erase(mark.begin()+l+1);
				mark.erase(mark.begin()+l-1);
				break;
			}
		}
		
	}
	cout << ans.size() <<"\n";
	for(auto &u : ans){
		cout << u << "\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
 
	cin >> n;
	
	int x;
	long long p = 0;
	int qp = 0;
	long long imp = 0;
	int qi = 0;
	int ma = -1e9;
	int i_ma = 0;
	for(int i = 0; i < n; i++){
		cin >> v[i];
		x = v[i];
		if(x >= 0){
			if(i & 1)
				qi++, imp += x;
			else qp++, p += x;
		}
		if(x > ma){
			ma = x;
			i_ma = i;	
		}
	}
	if(qp && p >= imp){
		cout << p << "\n";
		make_op(0);
	}
	else if(qi && imp > p){
		cout << imp << "\n";
		make_op(1);
	}
	else {
		cout << ma << "\n";
		make_op(0, i_ma);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(){
	int N,ans(0);
  	scanf("%d",&N);
  	int V[N],C[N];
  	for(int i = 0 ; i < N ; i ++){
      	scanf("%d",&V[i]);
    }
  	for(int i = 0 ; i < N ; i ++){
      	scanf("%d",&C[i]);
      	if(V[i] > C[i]) ans += V[i] - C[i];
    }
  	printf("%d",ans);
}

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

using namespace std;

int DP(const vector<vector<int>> &maze) {
  int H = maze.size() - 1;
  int W = maze[0].size() - 1;
  vector<vector<int>> dp(H + 1, vector<int>(W + 1, 100001));
  for (int h = H - 1; h >= 0; --h) {
    for (int w = W - 1; w >= 0; --w) {
      int right = maze[h][w] == 1 ? 1 : 0;
      int down = maze[h][w] == 1 ? 1 : 0;
      if (h != H - 1 || w != W - 1) {
        if (right == 1 && maze[h][w + 1] == 1) right = 0;
        if (down == 1 && maze[h + 1][w] == 1) down = 0;
        right += dp[h][w + 1];
        down += dp[h+1][w];
      }
      dp[h][w] = min(right, down);
    }
  }
  return dp[0][0];
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> maze(H + 1, vector<int>(W + 1, -1));
  for (size_t h = 0; h < H; ++h) {
    string row;
    cin >> row;
    for (size_t w = 0; w < W; ++w) {
      char c = row[w];
      maze[h][w] = c == '.' ? 0 : 1;
    }
  }
  cout << DP(maze) << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e5 + 10;
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
char str[maxn];
signed main()
{
    scanf("%s", str + 1);
    int N = strlen(str + 1), ans = 0;
    for (ri i = 2; i <= N; ++i) {
        if (str[i] != str[i - 1]) {
            ans++;
        }
    }
    writeln(ans);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
	int N;
  	char tmp;
  	bool result = false;
  	cin >> N;
  	for(int i=0;i<N;i++){
    	cin >> tmp;
      	if(tmp == 'Y') result = true;
    }
  	if(result) cout << "Four" << endl;
  	else cout << "Three" << endl;
}

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int n; cin >> n;
  if (n == 1){
    cout << 1 << "\n";
    return 0;
  }
  int sum = 1; 
  for(int i = 0; i <3 ; ++i){
    sum *= n;
  }
  cout << sum << "\n";
  return 0;
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    int h[n];
    bool l[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        l[i] = true;
    }
    int a, b;
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        if (h[a - 1] > h[b - 1])
            l[b - 1] = false;
        else if (h[a - 1] < h[b - 1])
            l[a - 1] = false;
        else
            l[a - 1] = l[b - 1] = false;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        if (l[i])
            ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 4072
h, w = map(int, input().split())
ans_h, ans_w = 0, 0
for i in range(h):
    s = [_ for _ in input().split()]
    for j in enumerate(s):
        if j[1] == 'snuke':
            ans_h, ans_w = i, j[0]
            break

ans = chr(65+ans_w)
ans += str(ans_h+1)
print(ans)

Measured memory_bytes: 3060
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).trim().split('\n');
main();

function main(){
  for(var i = 0, len = input.length; i < len; i++){
    var c = input[i].split(' ');
    if(+c[1] && +c[0]){
      var date = new Date(2004, c[0]-1, +c[1]);
      console.log(['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getDay()]);
    }
  }
  


}

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

int main(){
  int num;
  cin >> num;
  for(int i = 1; i <= num; i++){
    if(i % 3 == 0)cout <<' '<< i;
    else{
      if(i % 3 == 10)cout <<' '<< i;
      else{
        int temp = i;
        while(temp != 0){
          if(temp % 10 == 3){
            cout <<' '<< i;
            break;
          }
          else temp /= 10;
        }
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 3100
N = int(input())
L = list(map(int,input().split()))

dp = [0 for i in range(N)]
dp[1] = abs(L[0] - L[1])
for i in range(2,N) :
    dp[i] = min(dp[i-1] + abs(L[i-1] - L[i]), dp[i-2] + abs(L[i-2] - L[i]))

ans = dp[N-1]

print(ans)


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

class DoublyLinkedList{
    public:
        struct Node{
            int value;
            Node* next;
            Node* prev;
        };

        DoublyLinkedList(){
            nil = new Node();
            nil->next = nil->prev = nil;
        };
     //   ~DoublyLinkedList();

        void insertNode(int key){
            Node *x;
            x = new Node();
            x->value = key;
            x->next = nil->next;
            nil->next->prev = x;
            nil->next = x;
            x->prev = nil;
        }

        void deleteNode(int key){
            Node * ptr = list_search(key);
            if(ptr == nil) return;
            ptr->prev->next = ptr->next;
            ptr->next->prev = ptr->prev;
            delete ptr;
        }

        void deleteFirstNode(){
            Node * ptr = nil->next;
            nil->next = nil->next->next;
            nil->next->prev = nil;
            delete ptr;
        }

        void deleteLastNode(){
            Node * ptr = nil->prev;
            ptr->prev->next = ptr->next;
            ptr->next->prev = ptr->prev;
            delete ptr;
        }

        void print_list(){
            Node * current_node_ptr = nil->next;
            while( current_node_ptr != nil->prev ){
                cout << current_node_ptr->value << " ";
                current_node_ptr = current_node_ptr->next;
            }
            cout << nil->prev->value << "\n";
        }


    private:
        Node *nil;

        Node* list_search(int key){
            Node * current_node_ptr = nil->next;
            while(current_node_ptr != nil && current_node_ptr->value != key){
                current_node_ptr = current_node_ptr->next;
            }
            return current_node_ptr;
        }
};



// main
int main(){
   // 入力
   int n;
   cin >> n;
   string command;
   int key;

   // 初期化
   DoublyLinkedList dlist;

    for (int i=0; i<n; i++) {
         std::cin >> command;
         if (command == "insert") {
             cin >> key;
             dlist.insertNode(key);
         } else if (command == "delete") {
             cin >> key;
             dlist.deleteNode(key);
         } else if (command == "deleteFirst") {
             dlist.deleteFirstNode();
         } else if (command == "deleteLast") {
             dlist.deleteLastNode();
         }
     }

    // print
    dlist.print_list();

    return 0;
}





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

int main(void){
    string s;
    cin >> s;
    int a,b,c,d;
    /*
    a = (int)(s.at(0) - '0');
    b = (int)(s.at(1) - '0');
    c = (int)(s.at(2) - '0');
    d = (int)(s.at(3) - '0');
    //cout << a << b << c << d << endl;
    */

    int sum = (int)(s.at(0) - '0');
    for(int i=0;i<(1<<3);i++){
        bitset<3> b(i); //1を+,0を-
        //cout << b << endl;

        for(int j=0;j<3;j++){
            if(b.test(j)){
                sum += (int)(s.at(j+1) - '0');
            }else{
                sum -= (int)(s.at(j+1)-'0');
            }
            //cout << sum << endl;
        }

        if(sum==7){
            int k=0;
            for(int j=0;j<3;j++){
                if(b.test(j)){
                    s.insert(1+k,"+");
                }else{
                    s.insert(1+k,"-");
                }
                k += 2;                
            }
            s += "=7";
            cout << s << endl;
            break;
        }else{
            sum = (int)(s.at(0) - '0');
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int a;
	sd(a);
	pd(a+(a*a)+(a*a*a));
	return 0;
}

Measured memory_bytes: 3820
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        System.out.println(solve(in));
        
      }
      
      public static String solve(Scanner in) {
       int N = in.nextInt();
       int M = in.nextInt();
       int votes = 0;
       int[] nums = new int[N];

       for (int i = 0; i < N; i++) {
         nums[i] = in.nextInt();
       }


       for (int i = 0; i < N; i++) {
         votes += nums[i];
      }
       
       double minimum = (1.0 / (double) (4*M))* votes;
       int count = 0;
       Arrays.sort(nums);
       for (int i = 0; i < N; i++) {
         if (nums[i] >= minimum) count++;
       }
       if (count >= M) return "Yes";
       return "No";
      }
    
}

Measured memory_bytes: 21844
INF = 10**9
while 1:
    n = input()
    if not n:
        break
    dp = [INF]*5
    dp[0] = 0
    pos = 0; time = 0
    k = -1
    ps = []; ts = []
    for i in xrange(n):
        p, t = map(int, raw_input().split())
        ps.append(p); ts.append(t)
    for i in xrange(n):
        p, t = ps[i], ts[i]
        d = abs(p - pos)
        can = False
        r = INF
        for j in xrange(3, -1 if i==0 else 0, -1):
            dp[j+1] = INF
            if dp[j] == INF:
                continue
            if j<3 and d*(j+1) <= t - time:
                can = True
                dp[j+1] = dp[j] + d
            if pos*(j+1) + p <= t - time:
                r = min(r, dp[j] + pos + p)
                can = True
        dp[1] = r
        if not can:
            k = i+1
            break
        pos, time = p, t
    if k!=-1:
        print "NG", k
    else:
        print "OK", (min(dp[1:]) + p)

Measured memory_bytes: 4296
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
/*----------------------------------------------------------------------*/

const int N = 1e3+5;
ll dp[N][N];
char mat[N][N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    int h,w;
    cin>>h>>w;

    F(i, 0, h) {
    	F(j, 0, w) {
    		cin>>mat[i][j];
    	}
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0]=1;
    F(i, 0, h) {
    	F(j, 0, w) {
    		if((i+j) == 0 || mat[i][j] == '#') continue;
    		if(i) {
    			dp[i][j] += dp[i-1][j];
    			dp[i][j] %= MOD;
    		}
    		if(j) {
    			dp[i][j] += dp[i][j-1];
    			dp[i][j] %= MOD;
    		}
    	}
    }
    cout<<dp[h-1][w-1];

    return 0;
}/*

*/

Measured memory_bytes: 9088
//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<pair<int, int>>> cost(N);   // negative.
  vector<vector<pair<int, int>>> rcost(N);  // negative.
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    cost[a].emplace_back(b, -(c - P));
    rcost[b].emplace_back(a, -(c - P));
  }
  auto reach_s = vector<bool>(N);
  auto dfs1 = [&](auto rec, int cur) -> void {
    reach_s[cur] = true;
    for (auto& edge : cost[cur]) {
      int i = edge.first;
      if (!reach_s[i]) {
        rec(rec, i);
      }
    }
  };
  dfs1(dfs1, 0);

  auto reach_e = vector<bool>(N);
  auto dfs2 = [&](auto rec, int cur) -> void {
    reach_e[cur] = true;
    for (auto& edge : rcost[cur]) {
      int i = edge.first;
      if (!reach_e[i]) {
        rec(rec, i);
      }
    }
  };
  dfs2(dfs2, N - 1);

  bool loop_detected = false;
  i64 INF = 1LL << 40;
  vector<i64> minpath(N, INF);
  minpath[0] = 0;
  for (int k = 0; k <= N + 1; ++k) {
    bool update = false;
    REP(i, N) {
      if (minpath[i] == INF) continue;
      if (!reach_s[i] || !reach_e[i]) continue;
      for (auto& edge : cost[i]) {
        int j = edge.first;
        if (!reach_s[j] || !reach_e[j]) continue;
        int c = edge.second;

        if (minpath[j] > minpath[i] + c) {
          minpath[j] = minpath[i] + c;
          update = true;
        }
        DEBUG(i, j, c, minpath[j], update);
      }
    }
    if (!update) break;
    if (k == N) {
      loop_detected = true;
      break;
    }
  }
  if (minpath[N - 1] == INF || loop_detected) {
    cout << -1 << '\n';
  } else {
    cout << max(-minpath[N - 1], 0LL) << '\n';
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;

void solve()
  {
    int a,b;
    cin>>a>>b;
    int hcf = __gcd(a,b);
    //cerr<<hcf;
    int ans = 1;
    for(int i=2; i*i<=hcf; i++)
       {
        if(hcf%i == 0)
           {
            ans++;
            while(hcf%i == 0)
               hcf/=i;
           }
       }
  if(hcf>1)
     ans++;
  cout<<ans;
  }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
vector<ll> s(500000);

ll pot(ll a, ll b)
{
    if (b == 1)
        return a;
    if (b % 2 == 1)
        return a * pot(a, b - 1) % MOD;
    ll x = pot(a, b / 2);
    return x * x % MOD;
}

ll inv(ll a)
{
    return pot(a, MOD - 2);
}

ll C(ll n, ll k)
{
    return s[n] * inv(s[k] * s[n - k] % MOD) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    s[0] = 1;
    for (int i = 1; i < 500000; ++i)
        s[i] = (s[i - 1] * i) % MOD;
    ll odp = 0;
    for (int j = b + 1; j <= w; ++j)
    {
        int i = h - a;
        odp = (odp + C(i + j - 2, i - 1) * C(a + w - j + 1 - 2, a - 1) % MOD) % MOD;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
int main(void)
{
   int S;
   int h,m,s;
   scanf("%d",&S);
   h=S/3600;
   S%=3600;
   m=S/60;
   S%=60;
   s=S;
   printf("%d:%d:%d\n",h,m,s);
   return 0;
}


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

using i64 = long long int;

int main(){
    int n;
    string s;
    cin >> n >> s;
    string left = s.substr(0, n), right = s.substr(n);

    map<pair<string, string>, i64> mp_left, mp_right;
    for(int i=0;i<(1<<n);++i){
        string left_blue, left_red, right_blue, right_red;
        for(int j=0;j<n;++j){
            if(i&(1<<j)){
                left_red.push_back(left[j]);
                right_red.push_back(right[j]);
            }else{
                left_blue.push_back(left[j]);
                right_blue.push_back(right[j]);
            }
        }
        reverse(left_blue.begin(), left_blue.end());
        reverse(right_blue.begin(), right_blue.end());
        mp_left[make_pair(left_red, left_blue)]++;
        mp_right[make_pair(right_red, right_blue)]++;
    }

    i64 ans = 0;
    for(auto e : mp_left){
        ans += e.second * mp_right[make_pair(e.first.second, e.first.first)];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 103424
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
ll a, b, dif;
ll h[100005];

bool C(ll x) {
	if (h[n-1] <= x * b) return true;
	else if (h[n-1] > x * a) return false;
	ll cnt = 0;
	FOR(i, n) {
		if (h[i] <= x * b) continue;
		cnt += ((h[i] - x * b) + dif - 1) / dif;
		if (cnt > x) return false;
	}
	return true;
}

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> a >> b;
	FOR(i, n) cin >> h[i];
	sort(h, h + n);
	dif = a - b;

	ll left = 0, right = 1000000000;
	while (right - left > 1) {
		ll mid = (left + right) / 2;
		if (C(mid)) right = mid;
		else left = mid;
	}
	cout << right << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std;
int main()
{
    int N;
    long long ans=1;
    cin>>N;
    for(int i=1;i<=N;i++)
   { ans=ans*i;
    ans=ans%1000000007;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

const long long INF = (1LL << 60);

int main(){
    int w;
    cin >> w;

    long long a[100005];
    rep(i,w){
        cin >> a[i];
    }

    long long away[100005] = {0};
    long long cur = 0, ans = 0;
    rep(i,w){
        if(a[i] == 0) cur = INF;
        else if(a[i] < 0){
            cur = min(cur, -a[i]);
        }else{
            long long tmp = min(a[i], cur);
            ans += tmp;
            away[i] += tmp;
        }
        if(cur > 0) cur--;
    }
    cur = 0; 
    for(int i = w - 1; i >= 0; i--){
        if(a[i] == 0) cur = INF;
        else if(a[i] < 0){
            cur = min(cur, -a[i]);
        }
        else{
            long long tmp = min(a[i], cur);
            tmp = max(tmp - away[i], 0LL);
            ans += tmp;
        }
        if(cur > 0) cur--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4656
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, m;
    char a[60][60], b[60][60];
    cin >> n >> m;
    imfor(i, n) {
        imfor(j, n) {
            cin >> a[i][j];
        }
    }
    imfor(i, m) {
        imfor(j, m) {
            cin >> b[i][j];
        }
    }
    int ex = 0;
    imfor(i, n) {
        imfor(j, n) {
            if (i + m - 1 >= n || j + m - 1 >= n) {
                continue;
            }
            int f = 1;
            imfor(k, m) {
                imfor(l, m) {
                    if (a[k + i][l + j] != b[k][l]) {
                        f = 0;
                    }
                }
            }
            if (f == 1) {
                ex = 1;
            }
        }
    }
    if (ex == 1) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
int mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);
vector<vector<ll>> dp;
vector<vector<ll>> vec;

ll dfs(ll parent,ll color,ll vertex){
  if(dp[vertex][color]!=-1) return dp[vertex][color];
  dp[vertex][color]=1;
  for(auto x:vec[vertex]){
    if(x!=parent){
      if(color==0) 
        dp[vertex][0]*=(dfs(vertex,0,x)%mod+dfs(vertex,1,x)%mod)%mod;
      else if(color==1){
        dp[vertex][1]*=dfs(vertex,0,x)%mod;
      }
      dp[vertex][color]=dp[vertex][color]%mod;
    }
  }
  return dp[vertex][color]%mod;
}

int main()
{
  //------------ SEE BELOW ARTICLE---------------
 // https://codeforces.com/blog/entry/64250?#comment-484569
  // input_from_file;
  ll n,u,v;cin>>n;
  dp.resize(n+1,vector<ll> (2,-1));
  vec.resize(n+1);
  for(int i=0;i<n-1;i++){
    cin>>u>>v;
    vec[u].pb(v);vec[v].pb(u);
  }
  // cout<<dfs(vec,parent,color);
  cout<<(dfs(-1,0,1)+dfs(-1,1,1))%mod;
  return 0;
}


Measured memory_bytes: 19584
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)1e9+7 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-5 ;
const int    maxn = (int) 4e5+20 ;
const int    maxm = (int) 1e6+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

LL N,A,B,K;
LL mod = 998244353;

LL C[maxn];

void work()
{
    read(N);

    C[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        C[i] = (((C[i - 1] * fp(i, mod - 2, mod)) % mod) * (N - i + 1)) % mod;
    }

//    for(int i = 0; i <= N; i++)
//        cout <<C[i] <<endl;


    read(A), read(B);
    read(K);

    LL ans = 0;
    for(int i = 0; i <= N; i++)
    {
        LL tmp = K - A * i;
        if(tmp < 0) continue;
        if(tmp % B) continue;
        if(tmp / B > N) continue;
        int j = tmp / B;

        ans += C[i] * C[j];
        ans %= mod;
    }

    cout <<ans <<endl;
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


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

int main() {
    int a,b,m;
    cin>>a>>b>>m;
    vector<int> r(a),d(b);
    for(int i = 0;i < a;++i) {
        cin>>r[i];
    }
    for(int i = 0;i < b;++i) {
        cin>>d[i];
    }
    int ans=10000000;
    for(int i = 0;i < m;++i) {
        int x,y,c;
        cin>>x>>y>>c;
        --x;--y;
        ans=min(ans,r[x]+d[y]-c);
    }
    sort(r.begin(),r.end());
    sort(d.begin(),d.end());
    ans=min(ans,r[0]+d[0]);
    cout<<ans<<endl;
    return 0;
}


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

n,k=[int(i) for i in input().split()]
h=[int(i) for i in input().split()]

dp=[2**30]*n
dp[0] = 0

for i in range(n+1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j]-h[i]))
        else: break

print(dp[n-1])


Measured memory_bytes: 52448
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, l = list(map(int, readline().split()))

    s = [input() for _ in range(n)]

    s.sort()

    print(*s,sep="")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
    using namespace std;
     
    #define       pb(a)             push_back((a))
    #define       mp(a,b)           make_pair((a),(b))
    #define       REP(a,b)          for(ll i=(a);i<(b);i++)
    #define       REP2(a,b)         for(ll j=(a);j<(b);j++)
    #define       REPE(a,b,c,d)     REP(a,b)for(ll j=(c);j<(d);j++)
    #define       REPV(a,b,c)       for(ll (a)=b;(a)<(c);(a)++)
    #define       IREP(a,b)         for(ll i=(a);i>=(b);i--)
    #define       IREP2(a,b)        for(ll j=(a);j>=(b);j--)
    #define       IREPV(a,b,c)      for(ll (a)=b;(a)>=(c);(a)--)
    #define       all(v)            (v).begin(),(v).end()
    #define       Trvs(c)           for (auto it = (c).begin(); it != (c).end(); it++)
    #define       INF               INT_MAX
    #define       sz(x)             x.size()
    #define       flash             ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define       F                 first
    #define       S                 second
    #define       MOD               1000000007
     
    using         ll     = long long;
    using         vi     = vector<int>;
    using         vvi    = vector<vi>;
    using         vll    = vector<ll>;
    using         vvll   = vector<vll>;
    using         vb     = vector<bool>;
    using         vd     = vector<double>;
    using         vs     = vector<string>;
    using         pii    = pair<int, int>;
    using         pll    = pair<ll, ll>;
    using         pdd    = pair<double, double>;
    using         vpii   = vector<pii>;
    using         vvpii  = vector<vpii>;
    using         vpll   = vector<pll>;
    using         vvpll  = vector<vpll>;
    using         vpdd   = vector<pdd>;
    using         vvpdd  = vector<vpdd>;
     
     
    ll gcd(ll a,ll b){
    	if(b==0)return a;
    	return gcd(b,a%b);
    }
    ll lcm(ll a,ll b){
     
    	return a*b/gcd(a,b);
    }
     
    ll ceeel(ll n,ll a){
    	if(n%a==0) return n/a;
    	return n/a +1;
    }
    ll power(ll x, ll y){
    	ll ans=1;
    	REP(0,y){
    		ans*=x;
    	}
    	return ans;
    }
     
    void solve(){
    	ll n,m; cin >> n >> m;
 	
 	if(n<m){
 		REP(0,m)cout<<n;
 	}   	
 	else {
 		REP(0,n)cout<<m;
 	}
 }
     
     
    	
     
     
    int main(){
     
    	flash
    	
    	
    	//ll t;cin>>t;while(t--)
    	solve();
     
     
    	return 0;
    }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int k, x;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> k>>x;
    for(int i=x-k+1;i<=x+k-1;i++){
        cout<<i<<"\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,x,y,z,Sta,ans,f[45][1<<17];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),x=read(),y=read(),z=read(),Sta=(1<<x+y+z-1)|(1<<y+z-1)|(1<<z-1);
	f[0][0]=1;
	Rep(i,1,n){
		Rep(j,0,(1<<x+y+z)-1){
			Rep(k,1,10){
				int l=(j<<k)|(1<<k-1);l&=(1<<x+y+z)-1;
				if((l&Sta)!=Sta)f[i][l]=(f[i][l]+f[i-1][j])%Mod;
			}
		}
	}int ans=1;Rep(i,1,n)ans=1ll*ans*10%Mod;
	Rep(i,0,(1<<x+y+z)-1)ans=(ans-f[n][i]+Mod)%Mod;cout<<ans<<'\n';
	return 0;
}





Measured memory_bytes: 24048
#include<iostream>
using namespace std;
int main(){
int n,x,i,k,a=0,j,h;
	while(cin>>n>>x){
		if(n==0&&x==0){
			break;
		}
		a=0;
		for(k=1;k<n-1;k++){
			for(i=k+1;i<n;i++){
				for(h=i+1;h<n+1;h++){
					
					if(k+i+h==x&&k!=i&&k!=h&&i!=h){
						a++;	
					}
				}
			}
		}
		cout<<a<<endl;
	}
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
class unionfind {
    vector<int> par, rank, size_;
public:
    unionfind(int n) :par(n), rank(n), size_(n, 1) {
        iota(par.begin(),par.end(), 0);
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])swap(x, y);
        par[y] = x;
        size_[x] += size_[y];
        if (rank[x] == rank[y])rank[x]++;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return size_[find(x)];
    }
};

signed main(){
    int N,K,L;
    cin >> N >> K >> L;
    auto t = unionfind(N);
    auto c = unionfind(N);
    for(int i = 0; i < K; ++i){
        int a,b; cin >> a >> b;
        --a,--b;
        t.unite(a,b);
    }
    for(int j = 0; j < L; ++j){
        int a,b; cin >> a >> b;
        --a,--b;
        c.unite(a,b);
    }
    map<pair<int,int>,int>cnt;
    for(int i = 0; i < N; ++i){
        cnt[make_pair(t.find(i), c.find(i))] += 1;
    }
    for(int i = 0; i < N; ++i)
        cout << cnt[make_pair(t.find(i),c.find(i))]<< endl;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct edge{
	int v,next;
	ll w;
}e[maxn<<1];
int head[maxn],tot;
void add(int u,int v,ll w){
	e[++tot].v = v;
	e[tot].w = w;
	e[tot].next = head[u];
	head[u] = tot;
}
ll dep[maxn];
void dfs(int u,int f,ll d){
	dep[u] = d;
	for(int i =head[u];i;i=e[i].next){
		int v = e[i].v;
		if(v == f) continue;
		dfs(v,u,d+e[i].w);
	}
}
int main(){
	int n,u,v;
	ll w;
	scanf("%d",&n);
	for(int i = 1;i<n;i++){
		scanf("%d%d%lld",&u,&v,&w);
		add(u,v,w);
		add(v,u,w);
	}
	int q,k;
	scanf("%d%d",&q,&k);
	dfs(k,0,0);
	while(q--){
		scanf("%d%d",&u,&v);
		printf("%lld\n",dep[u]+dep[v]);
	}
}


Measured memory_bytes: 10752
# region
import sys
import itertools

DEBUG = True if (len(sys.argv) > 1 and sys.argv[1] == "DEBUG") else False


def dp(value):
    if DEBUG:
        print(value)
    return


def input_text(split=" "):
    # 入力
    result = []
    while True:
        try:
            row = list(
                map(lambda x: int(x) if x.isdecimal() else x, input().split(split))
            )
            result.append(row)
        except EOFError:
            break
    return result


# endregion
it = input_text()
k = it[0][0]
s = it[1][0]

if len(s) <= k:
    print(s)
else:
    print(s[:(k)] + "...")


Measured memory_bytes: 62008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int B[] = new int[N];
		int C[] = new int[N-1];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
		}
		for (int i=0;i<N;i++) {
			B[i] = sc.nextInt();
		}
		for (int i=0;i<N-1;i++) {
			C[i] = sc.nextInt();
		}
		int sum =0;
		for (int i=0;i<N;i++) {
			sum +=B[i];
		}
		for (int i=1;i<N;i++) {
			if (A[i-1]+1==A[i]) {
				sum +=C[A[i-1]-1];
			}
		}
		System.out.println(sum);
	}

}


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

#define endl '\n'
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back
#define MAXN 200005

int main(){ios_base::sync_with_stdio(false);

    int n;
    set<string> s;
    string t;
    cin >> n;
    while(n--){
        cin >> t;
        s.insert(t);
    }
    cout << ((int)s.size()) << endl;

    return 0;
}



Measured memory_bytes: 19220
#include <iostream>

auto main() -> int
{
    int64_t a, b, c, d;
    std::cin >> a >> b >> c >> d;

    if(b >= 0 && d >= 0)
    {
        if(b == 0 && d == 0) std::cout << a * c << std::flush;
        else
        {
            auto p1 = b * d, p2 = a * c;
            std::cout << (p1 > p2 ? p1 : p2) << std::flush;
        }
    }
    else if(b >= 0)
    {
        if(a >= 0) std::cout << a * d << std::flush;
        else std::cout << a * c << std::flush;
    }
    else if(d >= 0)
    {
        if(c >= 0) std::cout << b * c << std::flush;
        else std::cout << a * c << std::flush;
    }
    else
    {
        std::cout << a * c << std::flush;
    }

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  bool f = false;
  rep(i,n-1){
    f |= (c * i - d * (n-1-i) <= b-a && b-a <= i * d - c *(n - 1 -i));
  }
  if(f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

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

	if (a > b) {
		t = a; 
		a = b;
		b = t;
	}

	if (b > c) {
		t = b;
		b = c;
		c = t;
	}

	if (a > b) {
		t = a;
		a = b;
		b = t;
	}

	cout << a << " " << b << " " << c << endl;

	return 0;
}


Measured memory_bytes: 3080
#include<iostream>

using namespace std;

int main(void)
{
  char n[5];
  cin>>n;
  int count=1;
  
  for(int i=0;i<4;i++){
    for(int j=i+1;j<4;j++){
      if(n[i]>n[j]){
        int tmp=n[i];
        n[i]=n[j];
        n[j]=tmp;
      }
    }
  }
  
  for(int i=1;i<4;i++){
    if(n[0]==n[i]){count++;}
  }
  
  if(count>=3){puts("Yes");}
  else{puts("No");}
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const int INF = 1e9 +5;
long long int mem[5001] = {INT_MIN};

int main()
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    ll int n,i;
    cin>>n;
    vector<ll int> h(n,0);
    vector<ll int> dp(n,INF);
    for(i=0;i<n;i++)
        cin>>h[i];
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+2 && j<n;j++)
            dp[j]=min(dp[j],dp[i]+abs(h[j]- h[i]));
    }
    cout<<dp[n-1];
    return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

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

    int dp[h + 1];
    dp[0] = 0;
    for (int i = 1; i <= h; i++) dp[i] = inf;
    for (int i = 0; i <= h; i++) {
        for (int j = 0; j < n; j++) {
            int idx = min(h, i + a[j]);
            dp[idx] = min(dp[idx], dp[i] + b[j]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}

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


using namespace std;

int main(){

	int a;
	int b;
	
	cin>>a>>b;
	
	if(a<b){
		
		int temp=a;
		a=b;
		b=temp;
	}
	
	if((a-1)>b)
		cout<<a+a-1<<endl;
	else
		cout<<a+b<<endl;
		
	


	return 0;
}

Measured memory_bytes: 256