akhauriyash/Code-Regression huggingface dataset:
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for _ in range(n)]

sum = 0
for i in range(n):
    sum += ca[i][0]
ans = sum + 1

for i in range(2**n) :
    cnt = 0
    a = [0]*m
    for j in range(n) :
        if ((i>>j)&1) :
            for k in range(m) :
                a[k] += ca[j][k+1]
            cnt += ca[j][0]
    if cnt > 0 and min(a) >= x :
        ans = min(cnt,ans)

if ans == sum + 1 :
    print(-1)
else :
    print(ans)


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

using namespace std;

/* Template file for Online Algorithmic Competitions */
/* Typedefs */
    /* Basic types */
    typedef long long           ll;
    typedef unsigned long long ull;
    /* STL containers */
    typedef vector <int>    vi;
    typedef vector <ll>     vll;
    typedef pair <int, int> pii;
    typedef pair <ll, ll>   pll;
    typedef vector < pii >  vpii;
    typedef vector < pll >  vpll;
    typedef vector <string> vs;
    typedef vector < vi >   vvi;
/* Macros */
    /* Loops */
    #define fl(i, a, b)     for(int i(a); i<(b); i++)
    #define rep(i, n)       fl(i, 0, n)
    #define rep1(i, n)      fl(i, 1, n)
    #define rfl(i, a, b)    for(int i(a);i>=(b);i--)
    /* Algorithmic functions */
    #define srt(v)          sort((v).begin(),(v).end())
    /* STL container methods */
    #define pb              push_back
    #define mp              make_pair
    /* String methods */
    #define slen(s)         s.length()
    /* Shorthand notations */
    #define F               first
    #define S               second
    #define MOD             1000000007
    #define MAX             100010
    #define re              return 
    #define sz(x)           ((int) (x).size())
    #define all(x)          (x).begin(), (x).end()
    #define sqr(x)          ((x) * (x))
    #define fill(x, y)      memset(x, y, sizeof(x))
/* Templates */
template<class T> T abs(T x) { re x > 0 ? x : -x; }

int main(){

    int a, b;

    cin >> a >> b;

    if(a + b == 15){
        cout << "+";
    }
    else if(a * b == 15){
        cout << "*";
    }
    else{
        cout << "x";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
inline unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}
 
inline void shell_sort(unsigned a[], unsigned n){
  const unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913,1050113};
  // generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)
 
  unsigned gap_num = 0, count = 0;
  while(gaps[gap_num+1] < n) gap_num++;
 
  for(int i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);
 
  std::cout << (gap_num+1) << '\n';
 
  for(int i = gap_num; i; i--) std::cout << gaps[i] << ' ';
  std::cout << gaps[0] << '\n';
 
  std::cout << count << '\n';
}
 
int main(){
  std::ios::sync_with_stdio(false);
  unsigned n;
  unsigned a[1000000];
  std::cin >> n;
  for(unsigned i = 0; i < n; i++) std::cin >> a[i];
  shell_sort(a,n);
  for(unsigned i = 0; i < n; i++) std::cout << a[i] << '\n';
}

Measured memory_bytes: 7056
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
int32_t main(){
    fast;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int w=0;
    for(int i=0;i<n;i++)
        if(s[i]=='W')
            w++;
    for(int i=n-w;i<n;i++)
        if(s[i]=='W')
            w--;
    cout<<w;
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[101], b[101], c, d;
//
struct edge{int to, cap, rev;};
#define INF 1000
#define MAX_V 208

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size()-1});
}

int dfs(int at, int goal, int flow){
	if(at == goal){return flow;}
	used[at] = true;
	for(int i = 0; i < G[at].size(); i++){
		edge &e = G[at][i];
		if(!used[e.to] && e.cap > 0){
			int dif = dfs(e.to, goal, min(e.cap, flow));
			if(dif > 0){
				e.cap -= dif;
				G[e.to][e.rev].cap += dif;
				return dif;
			}
		}
	}
	return 0;
}

int max_flow(int start, int goal){
	int flow = 0;
	while(1){
		memset(used, 0, sizeof(used));
		int f = dfs(start, goal, INF);
		if(f == 0) return flow;
		flow += f;
	}
}
//
int main() {
	cin >> n;
	for(int i = 1; i <= n; i++){cin >> a[i] >> b[i];}
	
	for(int j = 1; j <= n; j++){
		cin >> c >> d;
		for(int i = 1; i <= n; i++){
			if(a[i] < c && b[i] < d){
				add_edge(i, n+j, 1);
			}
		}
	}
	
	for(int i = 1; i <= n; i++){add_edge(0, i, 1);}
	for(int j = 1; j <= n; j++){add_edge(n+j, 2*n+1, 1);}
	
	cout << max_flow(0, 2*n+1) << endl;
	
	return 0;
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O2")
//#pragma GCC optimization ("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif


int main()
{
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n , x , t;
    cin >> n >> x >> t;
    int ans = 0;
    int got = 0;
    while(got < n){
        got += x;
        ans += t;
    }
    cout << ans << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 3628
//
//  main.cpp
//  A
//
//  Created by Yoshinao Itakura on 2020/07/25.
//  Copyright © 2020 Yoshinao Itakura. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int A,B,C;
    cin >> A >> B >>C;
    int K;
    cin >> K;
    int count=0;
    for (int i=0; i<=K; ++i){
        for(int j=0; j<=i; ++j){
            if(A<pow(2,i)*B && pow(2,i)*B < pow(2,K-i)*C){
                ++count;
            }
        }
    }
    if(count>0){
        cout <<"Yes"<<endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 4080
/* ALDS1_6_C: Quick Sort */

#include <iostream>
#include <queue>
#include <map>
using std::map;
using std::queue;

struct Card { char suit; int number; };

int partition(Card cards[], int p, int r) {
    int pivot_num = cards[r].number;
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (cards[j].number <= pivot_num) {
            i++;
            std::swap(cards[i], cards[j]);
        }
    }
    std::swap(cards[i + 1], cards[r]);
    return i + 1;
}

void quick_sort(Card cards[], int p, int r) {
    if (r <= p) return;
    int q = partition(cards, p, r);
    quick_sort(cards, p, q - 1);
    quick_sort(cards, q + 1, r);
}

bool is_stable(int n_cards, Card cards[], map< int, queue<int> >& orders) {
    for (int i = 0; i < n_cards; i++) {
        int number = cards[i].number;
        char c = orders[number].front();
        if (c != cards[i].suit)
            return false;
        orders[number].pop();
    }
    return true;
}

int main() {
    std::ios::sync_with_stdio(false);

    int n_cards;
    std::cin >> n_cards;

    map< int, queue<int> > orders;
    int number;
    char suit;
    Card cards[n_cards];
    for (int i = 0; i < n_cards; i++) {
        std::cin >> cards[i].suit >> cards[i].number;
        orders[ cards[i].number ].push( cards[i].suit );
    }

    quick_sort(cards, 0, n_cards - 1);
    bool stable = is_stable(n_cards, cards, orders);

    std::cout << (stable ? "Stable" : "Not stable") << "\n";
    for (int i = 0; i < n_cards; i++) {
        std::cout << cards[i].suit << " " << cards[i].number << "\n";
    }
    return 0;
}

Measured memory_bytes: 19968
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define N 100
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int m, ans, flag[N], x[N], y[N], ct, c[N], con[N];
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (ch<'0' || ch>'9')
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (ch>='0' && ch<='9') p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int check(){
	int p=0;
	for (int i=1;i<=ct;i++)
		for (int j=i+1;j<=ct;j++){
			int u1=x[c[i]]-x[con[c[i]]], v1=y[c[i]]-y[con[c[i]]];
			int u2=x[c[j]]-x[con[c[j]]], v2=y[c[j]]-y[con[c[j]]];
			if (!u1 && !u2) {p++; continue;}
			if (!u1 || !u2) continue;
			if (v1*u2==u1*v2) {p++; continue;}			
		}
	return p;
}
void dfs(int t){
	if (t>m){
		//cout<<"lyk"<<' '<<ct<<' '<<check()<<endl;
		ans=max(ans,check());
		return;
	}
	if (flag[t]) { dfs(t+1);return;}
	flag[t]=1;
	c[++ct]=t;
	for (int i=t+1;i<=m;i++)
		if (!flag[i]){
			flag[i]=1;
			con[t]=i;
			dfs(t+1);
			flag[i]=0;
		}
	flag[t]=0;
	ct--;
}
int main(){
	m=read();
	for (int i=1;i<=m;i++) x[i]=read(), y[i]=read();
	dfs(1);
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int f = sc.nextInt();
        List<Integer> x = new ArrayList<Integer>();
        List<Integer> y = new ArrayList<Integer>();
        for (int i = 0; 100 * a * i <= f; i++) {
            for (int j = 0; ; j++) {
                int sum = 100 * a * i + 100 * b * j;
                if (sum > f) {
                    break;
                } else {
                    x.add(sum);
                }
            }
        }
        for (int i = 0; c * i <= f; i++) {
            for (int j = 0; ; j++) {
                int sum = c * i + d * j;
                if (sum > f) {
                    break;
                } else {
                    y.add(sum);
                }
            }
        }
        x.removeIf(h->{return h == 0;});
        int sw = 0;
        int su = 0;
        double no = 0;
        for (int i = 0; i < x.size(); i++) {
            for (int j = 0; j < y.size(); j++) {
                if (x.get(i) + y.get(j) <= f && y.get(j) * 100 / (double)x.get(i) >= no && y.get(j) * 100 / (double)x.get(i) <= e) {
                    no = y.get(j) * 100 / (double)x.get(i);
                    sw = x.get(i) + y.get(j);
                    su = y.get(j);
                }
            }
        }
        System.out.println(sw + " " + su);
    }
}


Measured memory_bytes: 34544
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n, k;
string s;

int main(){
    cin >> n >> k;
    cin >> s;
    int cnt = 0;
    REP(i, n - 1){
        if(s[i] != s[i + 1])cnt++;
    }
    cnt -= 2 * k;
    if(cnt < 0)cnt = 0;
    cout << n - cnt - 1 << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<"\n"
#define kaigyo cout<<"\n"

#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;typedef pair<int,int> pint;typedef vector<int> vint;
typedef vector<ll> vll;typedef vector<pint> vpint;typedef vector<pll> vpll;
ll INFl=1e+18+1;int INF=1e+9+1;


int main(){
  ll h,w,n,s;
  scan(h>>w>>n);
  s=max(h,w);
    if(n%s==0){
      prin(n/s);
    }
   else{
     prin(n/s+1);
  }
 
  return 0;
}


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

int s;

int rec(int n,int sum ,int a){
  if(sum==s && n==0) return 1;
  if(sum>s || n==0 || a>=9) return 0;
  
  int cnt=0;
  for(int i=a+1;i<10;i++){
    cnt += rec(n-1,sum+i,i);
  }
  
  return cnt;
}

int main(){

  while(1){
    int n;
    scanf("%d %d",&n,&s);
    if(n==0 && s==0) break;

    printf("%d\n",rec(n,0,-1));
  }

  return 0;

}

Measured memory_bytes: 1188
#include <stdio.h>

int main(void){
  int r, c, i, j, sumR, sumC, sumRC = 0;

  scanf("%d %d", &r, &c);
  int table[100 + 1][100 + 1] = {0};

  // Scan and c+1 calculation
  for(i = 0; i < r; i++){
    sumC = 0;
    for(j = 0; j < c; j++){
      scanf("%d", &table[i][j]);
      sumC += table[i][j];
    }
    table[i][j] = sumC;
  }

  // r+1 calculation
  for(j = 0; j < c; j++){
    sumR = 0;
    for(i = 0; i < r; i++){
      sumR += table[i][j];
    }
    table[i][j] = sumR;
  }

  // (r+1,c+1) calculation
  for(i = 0; i < r; i++)
    sumRC += table[i][c];
  table[i][c] = sumRC;
    
  // output
  for(i = 0; i < r + 1; i++){
    for(j = 0; j < c + 1; j++){
      if(j)
	printf(" ");
      printf("%d", table[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

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

  // ここにプログラムを追記
  if (b == '+') {
    cout << a + c << endl;
  } else {
    cout << a - c << endl;
  }
}


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

int wa(int n){
  if (n<10){
    return n;
  }
  return wa(n/10)+n%10;
}

int main(){
  int N;
  cin >> N;
  string ans;
  ans=N%wa(N)==0?"Yes":"No";
  cout << ans << endl;
}


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

int main() {
    int H, N;
    cin >> H >> N;
    int sum = 0;
    for(int i = 0; i < N; ++i) {
        int a; cin >> a;
        sum += a;
    }
    cout << (H <= sum ? "Yes" : "No") << '\n';
    return 0;
}

// overflow
// corner cases


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

int		main(void)
{
	int		num = 0;
	int		n, m;
	cin >> n >> m;
	int		s[m];
	int		c[m];
	int		flag;
	int		i = 0;
	int		j;
	while (i < m)
	{
		cin >> s[i] >> c[i];
		i++;
	}
	i = 1;
	while (i <= n)
	{
		flag = 0;
		j = 0;
		num *= 10;
		while (j < m)
		{
			if (s[j] == i && !(flag))
			{
				flag = 1;
				num += c[j];
			}
			else if (s[j] == i && flag)
			{
				if (num % 10 != c[j])
					flag = -1;
			}
			j++;
		}
		if (i == 1)
		{
			if (flag && !(num) && n != 1)
				flag = -1;
			else if (!(flag) && n != 1)
				num = 1;
		}
		if (flag < 0)
			break ;
		i++;
	}
	if (flag < 0)
		cout <<  "-1";
	else
		cout << num;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,q,ac=0,wa=0;
    string s;
    cin>>n>>m;
    int WA[n+1];
    bool AC[n+1];
    for(int i=1;i<=n;i++){
        WA[i]=0;
        AC[i]=false;
    }
    for(int i=0;i<m;i++){
        cin>>q>>s;
        if(AC[q]){continue;}
        else if(!AC[q]&&s=="WA"){WA[q]++;}
        else if(!AC[q]&&s=="AC"){ac++;AC[q]=true;}
    }
    for(int i=1;i<=n;i++){
        if(AC[i]){wa+=WA[i];}
    }
    cout<<ac<<' '<<wa<<endl;
}

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

using namespace std;

typedef long long ll;

int n, m; ll k;
ll arr[100100];
ll perm[100100];
ll ans[100100];

int main() {
    int i, j;

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%lld",&arr[i]);
    for (i=0;i<n;i++) perm[i] = i;
    scanf("%d%lld",&m,&k);
    for (i=0;i<m;i++) {
        int a;
        scanf("%d",&a);
        swap(perm[a-2],perm[a-1]);
    }
    for (i=0;i<n-1;i++) {
        if (perm[i]<0) continue;
        vector<ll> vec;
        int p = i;
        do {
            vec.push_back(p);
            p = perm[p];
        } while(p!=i);
        for (j=0;j<vec.size();j++) {
            ans[vec[j]] = vec[(j+k)%vec.size()];
            perm[vec[j]] = -1;
        }
    }
    printf("%lld\n",arr[0]);
    ll s = arr[0];
    for (i=0;i<n-1;i++) {
        s += arr[ans[i]+1]-arr[ans[i]];
        printf("%lld\n",s);
    }

    return 0;
}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 200000000000000;
constexpr auto MOD = 1000000007;


int main() {
	int n, m;
	cin >> n >> m;
	vi s(m), c(m);
	rep(i, m)cin >> s[i] >> c[i];

	int a, b;

	if (n == 1) {
		a = 0;
		b = 9;
	}
	else if (n == 2) {
		a = 10;
		b = 99;
	}
	else{
		a = 100;
		b = 999;
	}

	int ans = -1;
	for (;a <= b;a++) {
		bool k = true;
		rep(i, m) {
			if ((a / (int)pow(10, n - s[i])) % 10 != c[i])k = false;
		}
		if (k) {
			ans = a;
			break;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl


int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector< vector<int> > table;

		REP( i, 0, n )
		{
			table.PB( vector<int>() );
			int sum = 0;

			REP( j, 0, n )
			{
				int in;
				cin >> in;
				table[i].PB( in );
				sum += in;
			}

			table[i].PB( sum );
		}

		table.PB( vector<int>() );

		REP( i, 0, n + 1 )
		{
			int sum = 0;

			REP( j, 0, n )
			{
				sum += table[j][i];
			}

			table[n].PB( sum );
		}

		REP( i, 0, table.size() )
		{
			REP( j, 0, table[i].size() )
			{
				printf("%5d", table[i][j] );
			}
			cout << endl;
		}
	}

	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int a,b;cin>>a>>b;
	if(a<=9&&b<=9) cout << a*b;
	else cout << -1;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque, Counter, defaultdict
import heapq

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    N = int(input())
    N %= 10
    if N in set({2, 4, 5, 7, 9}):
        print("hon")
    elif N in set({0, 1, 6, 8}):
        print("pon")
    else:
        print("bon")

if __name__ == '__main__':
    main()

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   ll a; string b; cin>>a>>b;
   b.erase(b.begin()+1);
   int c=stoi(b);
   a*=c; cout<<a/100<<endl;
   return 0;
}


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

using namespace std;

string s;

long long i,j,k,l,n,m;

set<char>c;

int main()
{
    cin>>s;
    if(s.length()!=3){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<3;i++){
        if(s[i]!='a' && s[i]!='b' && s[i]!='c'){
            cout<<"No"<<endl;
            return 0;
        }
        c.insert(s[i]);
    }
    if(c.size()==3){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで標準include
//以下プログラム

using namespace std;

int main(){
	string S;
	cin >> S;
	int c = 0;
	int I = 0;
	if (S.at(0) == 'A') {
		for (int i = 2; i < S.size()-1; i++) {
			if (S.at(i) == 'C') {
				c++;
			}
		}
		if (c == 1) {
			for (int i = 0; i < S.size(); i++) {
				if (65 <= (int)S.at(i) && (int)S.at(i) <= 90) {
					I++;
				}
			}
			if (I == 2) {
				cout << "AC" << endl;
			}
			else {
				cout << "WA" << endl;
			}
		}
		else {
			cout << "WA" << endl;
		}
	}
	else {
		cout << "WA" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static int count(int k){
        int ans = 0;
        for(int i=1;i*i<=k;i++){
        	if(k%i==0){
        	    if(i*i==k) ans+=1;
        	    else ans+=2;
        	}
        }
        return ans;
    }
    public static int solve(int N){
        int ans = 0;
        for(int i=1;i<=N;i++){
        	if(i%2!=0 && count(i)==8)ans++;
        }
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(solve(N));
    }
}


Measured memory_bytes: 23764
#include<stdio.h>
#define X 1
#define Y 1000000000

int main()
{
  int x,y,num,div=0;

  while(1)
    {
      scanf("%d %d",&x,&y);
      if((x >= X && x <= Y) && (y >= X && y <= Y)) break;
    }

  if(x<y)
    {
      num = x;
      x = y;
      y = num;
    }
 
  while(1)
    {
      div = x % y;
      if(div == 0) break;
      x = y;
      y = div;
     }

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



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

using namespace std;

typedef long long  ll;

const int MAX_WH = 1500 * 1000 + 5;
const int MAX_N = 1501;
int size_w[MAX_WH], size_h[MAX_WH];
int h[MAX_N], w[MAX_N];

int main()
{
    int n, m;

    while (true) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0)
            break;

        memset(size_h, 0, sizeof(size_h));
        memset(size_w, 0, sizeof(size_w));

        h[0] = w[0] = 0;
        for (int i = 0; i < n; ++i)
            scanf("%d", &h[i + 1]);
        for (int i = 0; i < m; ++i)
            scanf("%d", &w[i + 1]);

        ++n, ++m;
        for (int i = 1; i < n; ++i)
            h[i] += h[i - 1];
        for (int i = 1; i < m; ++i)
            w[i] += w[i - 1];

        for (int l = 0; l < n - 1; ++l)
            for (int r = l + 1; r < n; ++r)
                ++size_h[h[r] - h[l]];
        for (int l = 0; l < m - 1; ++l)
            for (int r = l + 1; r < m; ++r)
                ++size_w[w[r] - w[l]];

        int lim = min(h[n - 1], w[m - 1]);
        int ans = 0;
        for (int d = 1; d <= lim; ++d)
            ans += size_h[d] * size_w[d];

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

    return 0;
}

Measured memory_bytes: 12908
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

//#define MAX 100
int n;
char c;
int vote[26];
bool isEnd;

int difsec() {
	int top = 0;
	int sec = 0;
	for (int i = 0; i < 26; i++) {
		if (top < vote[i]) {
			sec = top;
			top = vote[i];
		}
		else if (sec < vote[i]) {
			sec = vote[i];
		}

	}
	return top - sec;
}

char top() {
	int top = 0, topc;
	for (int i = 0; i < 26; i++) {
		if (top < vote[i]) {
			top = vote[i];
			topc = i;
		}

	}
	return (char)(topc+'A');
}

int main() {
	cin >> n;
	while (n) {
		for (int i = 0; i < 26; i++) vote[i] = 0;
		isEnd = false;
		for (int i = 1; i <= n; i++) {
			cin >> c;
			if (isEnd) continue;
			++vote[c - 'A'];
			int tmp = difsec();

			if (i == n && tmp == 0) {
				cout << "TIE" << endl;
			}
			else if (tmp > n - i) {
				cout << top() << " " << i << endl;
				isEnd = true;
			}
		}
		cin >> n;
	}

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int red = 1, green = 2, blue = 4;

ll sum[10][4010];

int main(){
	int n; cin >> n;
	string s; cin >> s;
	vector<int> seq;
	for( char c : s ){
		if( c == 'R' ) seq.push_back(red);
		if( c == 'G' ) seq.push_back(green);
		if( c == 'B' ) seq.push_back(blue);
	}
	for( int i = 0; i < n; ++i ){
		for( int color = red; color <= blue; color *= 2 ){
			sum[color][i+1] = sum[color][i];
		}
		sum[seq[i]][i+1] += 1;
	}
	ll ans = 0;
	for( int left = 0; left < n-2; ++left ){
		for( int right = left+2; right < n; ++right ){
			if( seq[left] == seq[right] ) continue;
			int needed_c = 7 - seq[left] - seq[right];
			ans += ( sum[needed_c][right] - sum[needed_c][left+1] );
			if( (right-left)%2 == 0 and seq[(left+right)/2] == needed_c ) ans -= 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3752
W = input()


if W[1] == "S":
    if W[0] == "R" or W[2] == "R":
        print("1")
    else:
        print("0")
else:
    if W[0] == "R" and W[2] == "R":
        print("3")
    elif W[0] == "R" or W[2] == "R":
        print("2")
    else:
        print("1")


Measured memory_bytes: 61636
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    yes((N % 2 == 1) ? false : S.substr(0, N / 2) == S.substr(N / 2, N));
    return 0;
}

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

int main(){
	int a,b;
	cin >> a >> b;
	if(a<b){
		cout << "a < b" << endl;
	}else if(a>b){
		cout << "a > b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;
}

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

long long INF = 10000000;
long long dp[1<<15][15];
long long dist[15][15];

long long rec(long long p, long long s, long long t, long long V){
    if(dp[p][t] >= 0){
        return dp[p][t];
    }
    if(p == (1<<t)){
        return dp[p][t] = dist[s][t];
    }
    long long i, val = INF;
    for(i = 0; i < V; i++){
        if(!((p^(1<<t)) & (1<<i))){
            continue;
        }
        val = min(val,rec(p^(1<<t),s,i,V)+dist[i][t]);
    }
    return dp[p][t] = val;
}

int main(){
    //input
    long long i,j,k;
    for(i = 0; i < 15; i++){
        for(j = 0; j < 15; j++){
            dist[i][j] = INF;
        }
    }
    long long V, E;
    cin >> V >> E;
    long long s,t,d;
    for(i = 0; i < E; i++){
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    //calc
    long long ans = INF;
    for(i = 0; i < V; i++){
        for(j = 0; j < (1<<15); j++){
            for(k = 0; k < 15; k++){
                dp[j][k] = -1;
            }
        }
        ans = min(ans,rec((1<<V)-1,i,i,V));
    }

    //answer
    if(ans < INF){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6960
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	ll n,x,i;
	cin>>n>>x;
	ll arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	int cnt = 0;
	for(i=0;i<n-1;i++)
	{
		if((x-arr[i]) >= 0)
		{
			x-=arr[i];
			cnt++;
		}
	}
	if(arr[i] == x)
		cnt++;
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x, y;
    cin >> x >> y;
    cout << x + y / 2;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz                size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define fin               freopen( "input.txt", "r", stdin );
#define fout              freopen( "output.txt", "w", stdout );
#define deb(x) cout << #x << " " << x << endl
#define inf INT_MAX
const ll N = 200010;
const ll MOD = 1000 * 1000 * 1000 + 7;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}

ll** lcs;

ll LCS(string s, string r, ll n, ll m){

    lcs = new ll*[n+1];
    for(ll i=0;i<=n;i++){
        lcs[i] = new ll[m+1];
    }

    for(ll i=0;i<=n;i++){
        lcs[i][0] = 0;
    }

    for(ll i=0;i<=m;i++){
        lcs[0][i] = 0;
    }

    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            if(s[i-1] == r[j-1]){
                lcs[i][j] = 1+lcs[i-1][j-1];
            }
            else{
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
            }
        }
    }

    return lcs[n][m];
}


void PrintLCS(string s, string r, ll n, ll m, ll len){

    char ans[len+1];
    ans[len] = '\0';
    len--;

    ll i = n, j = m;

    while(i > 0 && j > 0){
        if(s[i-1] == r[j-1]){
            ans[len] = s[i-1];
            i--, j--, len--;
        }
        else{
            if(lcs[i-1][j] > lcs[i][j-1])
                i--;
            else j--;
        }
    }

    printf("%s", ans);
}


void solve(){
    string s, r;
    cin >> s >> r;
    ll ans;
    ans = LCS(s, r, s.sz, r.sz);
    PrintLCS(s, r, s.sz, r.sz, ans);
}

int main(){
    //fin fout
    fast
    ll T = 1; //cin >> T;
    loop(i, 0, T) solve();
    /*#ifdef LOCAL
    clock_t tStart = clock();
    cerr<<fixed<<setprecision(10)<<"\nTime Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
    #endif*/
}


/*339 341 1
342 343 2
342 342 2*/



Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,t[100],sum = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	for(int i = 0;i < m;i++){
		int p,x;
		cin >> p >> x; p--;
		cout << sum - t[p] + x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	let total = parseInt(input);
	let i;
	for(i=0; i*1000<total;i++){}
  
  	console.log('%d',i*1000-total);
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29636
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
#define MAXN 100005
int p[MAXN];
int main () {
    int n, m;
    cin >> n >> m;
    UnionFind tree(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        tree.merge(p[x], p[y]);
    }
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (tree.issame(i, p[i])){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 5036
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        String line;
        
        ArrayList<Integer> n = new ArrayList<Integer>();
        
        for(int i = 0; cin.hasNext(); i++){
	        line = cin.nextLine();
	        
	        if(i == 0) {
	            String[] _n = line.split(" ", 0);
	            
	            for(int j = 0; j < 4; j++) {
	                n.add(Integer.parseInt(_n[j]));
	            
	            }
	            
	        } else {
	            
	        }
	        
        }
        
        Collections.sort(n);
        
        String res = "NO";
        
        if(n.get(0) == 1 && n.get(1) == 4 && n.get(2) == 7 && n.get(3) == 9) {
            res = "YES";
            
        }
        
        System.out.println(res);
        
    }
    
}


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

int main(){
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<>());

	if(s < t){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
//65 - A 90 - Z 97 - a 122 - z
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x - a) > abs(x - b))
        puts("B");
    else puts("A");
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 20:59:27 2019

@author: doppe
"""
H, W = map(int, input().split())
h, w = map(int, input().split())

num = H * W
num = num - H * w
num = num - (W - w) * h

print(num)

Measured memory_bytes: 3060
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
using namespace std;

string a,b;
int lena,lenb, dp[3005][3005];

int LCS(){
    string ans;
    for(int i=1;i<=lena;i++){
        for(int j=1;j<=lenb;j++){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            if(a[i]==b[j]){
                dp[i][j] =max(dp[i][j],dp[i-1][j-1]+1);
            }
        }
    }
    int i=lena, j=lenb;
    while(i && j){
        if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else{
            ans+=a[i];
            i--;
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return dp[lena][lenb];
}

int main(){
    IOS
    //freopen("output.txt","w",stdout);
    cin>>a>>b;
    lena=a.length();
    lenb=b.length();
    a=" "+a;
    b=" "+b;
    int lcs= LCS();
    //cout<<endl<<lcs;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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 io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

bool isPrime(int x){
    int i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(void){

    // // string s,t;
    // // cin>>s>>t;
    // // cout<<t<<s<<endl;
    // ll a,b,k;
    // cin>>a>>b>>k;
    // a-=k;
    // k=max(-a,0LL);
    // a=max(a,0LL);
    // b=max(0LL,b-k);
    // cout<<a<<" "<<b<<endl;
    int x;
    cin>>x;
    for(int i=x;;i++){
        if(isPrime(i)){
            cout<<i<<endl;
            return 0;
        }
    }
}


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

const int MOD = 2019;
int main(){
    ll L, R; cin >> L >> R;
    if(R - L >= MOD){
        cout << 0 << endl;
        return 0;
    }
    L %= MOD;
    R %= MOD;
    if(R < L) cout << 0 << endl;
    else{
        int ans = MOD;
        for(int i = L; i < R; i++){
            for(int j = i + 1; j <= R; j++){
                ans = min(ans, i * j % MOD);
            }
        }
        cout << ans << endl;
    }
    

}


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

int main(){
    char s[1];

    scanf("%s", s);
    
    if(strcmp(s, "A") == 0){
        printf("T\n");
    }else if(strcmp(s, "T") == 0){
        printf("A\n");
    }else if(strcmp(s, "G") == 0){
        printf("C\n");
    }else if(strcmp(s, "C") == 0){
        printf("G\n");
    }
    return 0;
}

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

int main()
{
    int d;
    cin >> d;
    int c[26];
    for(int i = 0; i < 26; i++) cin >> c[i];
    int s[400][26];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++) cin >> s[i][j];
    }
    int last[26];
    for(int i = 0; i < 26; i++) last[i] = -1;
    for(int i = 0; i < d; i++){
        int l = 0;
        for(int j = 0; j < 26; j++){
            if(s[i][j] + (i - last[j]) * c[j] > s[i][l] + (i - last[l]) * c[l]) l = j;
        }
        last[l] = i;
        cout << l + 1 << endl;
    }
}


Measured memory_bytes: 3676
var cnt:Int=0

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list: List<Int> = readLine()!!.split(" ").map { it.toInt() }
    selectionSort(list.toIntArray(),n)
}
fun selectionSort(A:IntArray, N:Int) {
    var tmp:Int
    for (i in (0..(N - 1))) {
        var minj :Int= i
        for (j in (i .. (N - 1)))
        {
            if (A[j] < A[minj])
            {
                minj = j
            }
        }
        if (A[minj] != A[i])
        {
            tmp = A[minj]
            A[minj] = A[i]
            A[i] =tmp
            cnt++
        }
    }
    println(A.joinToString(" "))
    println(cnt)
}


Measured memory_bytes: 31964