akhauriyash/Code-Regression huggingface dataset:
import sys
import itertools

input = sys.stdin.readline


def main():
    H, W, D = [int(x) for x in input().split()]
    A = [[int(x) for x in input().split()] for _ in range(H)]
    Q = int(input())
    LR = [[int(x) for x in input().split()] for _ in range(Q)]

    d = {}
    for j in range(H):
        for i in range(W):
            d[A[j][i]] = (i, j)

    A = [[0] for j in range(D)]

    for i in range(D):
        accumu = 0
        for j in range(i, H * W + 1, D):
            if j <= D:
                continue
            accumu += abs(d[j][0] - d[j - D][0]) + abs(d[j][1] - d[j - D][1])
            A[i].append(accumu)


    for l, r in LR:
        if l % D == 0:
            print(A[l % D][r // D - 1] - A[l % D][l // D - 1])
        else:
            print(A[l % D][r // D] - A[l % D][l // D])


if __name__ == '__main__':
    main()


Measured memory_bytes: 84828
n,m = map(int, raw_input().split())
r = 0
cakes = [map(int, raw_input().split()) for _ in range(n)]

for b in range(8):
	cakes.sort(key = lambda x: sum([x[i] * (-1 if ((b >> i) & 1) else 1) for i in range(3) ]))
	
	s = 0
	for i in range(n-1, n - 1 - m, -1):
		s += sum([cakes[i][j] * (-1 if ((b >> j) & 1) else +1) for j in range(3)])
	r = max(r, s)
print r

Measured memory_bytes: 99124
#include<stdio.h>

int main(void){
 int a ,b ,c;
 int max ,mid ,min;
 scanf("%d %d %d",&a ,&b ,&c);
 max=a;
  if(max<b){
   max=b;
   min=a;
  }
  else{
   max=a;
   min=b;
  }
  if(max<c){
   mid=max;
   max=c;
  }
  else if(min>c){
   mid=min;
   min=c;
  }
  else{
   mid=c;
  }

 printf("%d %d %d\n",min ,mid ,max);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

typedef vector<int> Node;
typedef vector<Node> Graph;

using ull = unsigned long long;
inline int trail(ull s) {
  return (s ? __builtin_ctzll(s) : 64);
}
// O(3^(n/3)) ?
// reference:https://sites.google.com/site/indy256/algo/bron_kerbosh
template <typename T>
T BronKerbosch(const vector<ull>& g, ull cur, ull allowed,
               ull forbidden, const vector<T>& w) {
  if(allowed == 0 && forbidden == 0) {
    T res = 0;
    for(int u = trail(cur); u < g.size();
        u += trail(cur >> (u + 1)) + 1)
      res += w[u];
    return res;
  }
  if(allowed == 0) return -1;
  T res = -1;
  int piv = trail(allowed | forbidden);
  ull z = allowed & ~g[piv];
  for(int u = trail(z); u < g.size();
      u += trail(z >> (u + 1)) + 1) {
    res = max(res, BronKerbosch(g, cur | (1ULL << u),
                                allowed & g[u],
                                forbidden & g[u], w));
    allowed ^= 1ULL << u;
    forbidden |= 1ULL << u;
  }
  return res;
}

template <typename T>
T maxmum_clique(const vector<vector<int>> G,
                const vector<T>& w) {
  int n = G.size();
  assert(n < 64);
  vector<ull> g(n, 0);
  for(int i = 0; i < n; ++i)
    for(int j : G[i]) g[i] ^= 1ULL << j;
  return BronKerbosch(g, 0, (1ULL << n) - 1, 0, w);
}

template <typename T>
T maximal_independent_set(const vector<vector<int>>& G,
                          const vector<T>& w) {
  int n = G.size();
  assert(n < 64);
  vector<ull> g(n, (1ULL << n) - 1);
  for(int i = 0; i < n; ++i) {
    g[i] ^= 1ULL << i;
    for(int j : G[i]) g[i] ^= 1ULL << j;
  }
  return BronKerbosch(g, 0, (1ULL << n) - 1, 0, w);
}

struct country {
  string name;
  int n;
  long long s;
  vector<string> v;
};

int n, mid;
map<string, int> mp;
vector<country> v;
vector<int> w;
vector<vector<int>> edge;

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    mp.clear();
    v.clear();
    v.resize(n);
    w.resize(n);
    edge.clear();
    edge.resize(n - 1);
    for(int i = 0; i < n; ++i) {
      cin >> v[i].name >> w[i] >> v[i].n;
      for(int j = 0; j < v[i].n; ++j) {
        string x;
        cin >> x;
        v[i].v.push_back(x);
      }
      mp[v[i].name] = i;
    }
    for(int i = 1; i < n; ++i)
      for(auto s : v[i].v)
        if(mp[s] > 0) edge[i - 1].push_back(mp[s] - 1);
    vector<int> nw(n - 1, 0);
    for(int i = 1; i < n; ++i) nw[i - 1] = w[i];
    for(auto s : v[0].v) nw[mp[s] - 1] = 0;
    cout << maximal_independent_set<int>(edge, nw) + w[0]
         << endl;
  }
  return 0;
}



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


def solve(A: int, B: int, C: int, X: int, Y: int):
    ret = 0
    if C * 2 <= A + B:
        ret += min(X, Y) * 2 * C
        if X > Y:
            if C * 2 <= A:
                ret += C * 2 * (X - Y)
            else:
                ret += A * (X - Y)
        else:
            if C * 2 <= B:
                ret += C * 2 * (Y - X)
            else:
                ret += B * (Y - X)

    else:
        ret += A * X + B * Y
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(A, B, C, X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

char a[11][11];

int used[11][11];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), m = readInt();
    for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];		
		}    
    }
    int x = 1, y = 1;
    while(1) {
    	used[x][y] = 1;
    	if (x == n && y == m) {
    		break;
    	}
    	if (x + 1 <= n) {
			if (a[x + 1][y] == '#') {
				x++;
				continue;
			}
    	}
    	if (y + 1 <= m) {
    		if (a[x][y + 1] == '#') {
				y++;
				continue;    			
    		}
    	}
    	cout << "Impossible";
    	return 0;
    }
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (a[i][j] == '#' && !used[i][j]) {
    			cout << "Impossible";
    			return 0;
    		}
    	}
    }
    cout << "Possible";
    return 0;
}

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

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

  bool ok = true;
  auto X = 0, Y = 0, T = 0;
  for(auto i = 0; i < N; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    auto d = abs(X-x) + abs(Y-y);
    if(t < T+d) ok = false;
    if((t&1) != ((T+d)&1)) ok = false;
    T = t;
    X = x;
    Y = y;
  }

  if(ok) cout << "Yes" << endl;
  else   cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
#define LEN(x) ll(x.length()) //lengthをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll tmp = x / d;
    if(tmp >= k) cout << x - k * d;
    else{
        ll rem = k - tmp;
        if(rem % 2 == 0) cout << x - tmp * d;
        else  cout << d - (x - tmp * d);
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    string str;
    cin>>str;
    ll ct=0;
    ll ans=0;
    ll n=SZ(str);
    fr(i,0,n)
    {
        if(str[i]=='A')
        {
            ct++;
        }
        else if(str[i]=='B'&&i+1<SZ(str))
        {
            if(str[i+1]=='C')
            {
                ans+=ct;
                i++;
            }
            else
            {
                ct=0;
            }
        }
        else if(str[i]=='C')
        {
            ct=0;
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3680
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    // n = x * 1.08 => x = n / 1.08

    if (100*n % 108 == 0) {
        cout << n / 1.08 << endl;
    }
    else {
        int x = (n/1.08)+0.5;
        int d = x*1.08;
        int e = (x+1)*1.08;
        if (d == n) cout << x << endl;
        else if (e == n) cout << x+1 << endl;
        else cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int cmp( const void *p, const void *q ) {
    if( *(double*)p > *(double*)q ) return 1;
    if( *(double*)p < *(double*)q ) return -1;
    return 0;
}
int main(){
  double n,d[100001];
  scanf("%lf",&n);
  for(int i=0;i<n;i++)scanf("%lf",&d[i]);
  qsort(d,n,sizeof(double),cmp);
  printf("%d",(int)(d[(int)n/2]-d[(int)n/2-1]));
  return 0;
}

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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

vector<ll> tt, pat;

ll dfs(ll lv, ll remain) {
  if (remain == 0) return 0;

  ll ret = 0;

  remain--; // B

  // lv-1
  if (tt[lv-1] <= remain) remain -= tt[lv-1], ret += pat[lv-1];
  else ret += dfs(lv-1, remain), remain = 0;

  if (remain > 0) remain--, ret++; // P

  // lv-1
  if (tt[lv-1] <= remain) remain -= tt[lv-1], ret += pat[lv-1];
  else ret += dfs(lv-1, remain), remain = 0;

  remain--; // B

  return ret;
}

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

  ll n, x; std::cin >> n >> x;
  tt.resize(n+1), pat.resize(n+1);
  tt[0] = 1;
  rrep(i, n) tt[i] = tt[i-1] + 3 + tt[i-1];
  pat[0] = 1;
  rrep(i, n) pat[i] = pat[i-1] + 1 + pat[i-1];
  std::cout << dfs(n, x) << "\n";
}


Measured memory_bytes: 256
#include <cstdio>

int main(int argc, const char * argv[]) {
   
    
    int n,k;
    
    scanf("%d %d",&n,&k);
    
    long long ans = 0;
    
    if(k==0){
        ans = (long long)n*n;
        printf("%lld\n",ans);
        return 0;
    }
    
    ans = (long long)(n-k)*(n-k+1)/2;
    
    
    for(int i=k+1;i<n;i++){
        
        int cnt = n-i;//가로전체개수
        
        int mul = cnt/i;
        int mod = cnt%i;
        
        ans += (long long)mul * (i-k);
        if(mod >= k)
            ans += mod - k+1;
        
    }
    
    printf("%lld\n",ans);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//500円の枚数入力
		int a = sc.nextInt();
		//100円の枚数入力
		int b = sc.nextInt();
		//50円の枚数入力
		int c = sc.nextInt();
		// 合計金額の入力
		int x = sc.nextInt();
		//出力用
		int count = 0;
		int sum = 0;
		for(int i = 0; i <= a; i++){
			for(int t = 0; t <= b; t++){
				for(int s = 0; s <= c; s++){
					sum = 500*i + 100*t + 50*s;
					if(sum == x){
						count++;
					}
				}
			}
		}
		// 出力
		System.out.println(count);
	}
}


Measured memory_bytes: 23764
S = input()

if S =="SAT":
    print(1)

elif S =="FRI":
    print(2)

elif S =="THU":
    print(3)

elif S =="WED":
    print(4)

elif S =="TUE":
    print(5)

elif S =="MON":
    print(6)

elif S =="SUN":
    print(7)

Measured memory_bytes: 9044
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int x[3];
	REP(i, 3)cin >> x[i];
	int ret = 3;
	sort(x, x + 3);
	REP(i, 2)if (x[i] == x[i + 1])ret--;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for ai in a:
    d[ai] += 1


n1 = n2 = 0
for k, v in d.items():
    if v >= 3:
        if v % 2 == 0:
            d[k] = 2
        else:
            d[k] = 1

    if d[k] == 1:
        n1 += 1
    else:
        n2 += 1

# print(d)
# print(n1, n2)
n1 += n2 - n2 % 2
n2 = n2 % 2

ans = n1

print(n1)


Measured memory_bytes: 18656
#include<bits/stdc++.h>
using namespace std;
const int N = 1000000;
void eratosthenes(bool prime[N]){
    for(int i = 0;i < N;i++) prime[i] = 1;
    prime[0] = prime[1] = 0;
    for(int i = 0;i < N;i++) {
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long x;
    cin >> x;
    bool prime[N];
    eratosthenes(prime);
    for(int i = x;i < 1000000;i++) {
        if(prime[i]==1) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1280
#include <cstdio>
#include <limits>
#include <cmath>
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;


int main() {
	long long X,Y;
	cin >> X >> Y;
	long long A;
	int i=1;
	int maxlen = 0;

	
	A = X;
	while (A <= Y) {
		A *= 2;
		i++;
	}
	maxlen = i - 1;
	
	cout << maxlen << endl;
	
	return 0;
}

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

using namespace std;

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

	set<string> S;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		S.insert(s);
	}

	cout << S.size() << endl;
	
}






Measured memory_bytes: 19176
/*input
7
zenkoku
touitsu
program
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb                push_back
#define pp                pop_back
#define nl                cout << "\n"
#define MIN(con)          (*min_element(ALL(con)))
#define MAX(con)          (*max_element(ALL(con)))
#define NX(cont)          next_permutation(ALL(cont))
#define PX(cont)          prev_permutation(ALL(cont))
#define prec(n)           cout << fixed << setprecision(n)
#define PI                3.14159265358979323846264338327951
#define all(c)            c.begin(),c.end()
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define sp                cout << " "
#define mod               1000000007    //9
#define ifalse            ios_base::sync_with_stdio(false),cin.tie(NULL)

using ll = long long;
using ld = long double;
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > string toString(T a)       { return to_string(a); }  // Convert int to string
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}  // Convert string to int

ll add(ll x, ll y) { x += y; if(x >= mod) x -= mod; return x; }
ll sub(ll x, ll y) { x -= y; if(x < 0) x += mod; return x; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }

ll powr(ll a, ll b) {
    ll x = 1LL;
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}

ll inv(ll a) { return powr(a, mod - 2); }
const int inv2 = (mod + 1) >> 1;
const ll INF =  1e18;
const int inf = 1e9;

bool check(ll n)
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;
    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

/*********************************************START**************************************************************/

int main()
{
    ifalse;
    int n;
    cin >> n;
    string a, b, c;
    int cnt = 0;
    cin >> a >> b >> c;
    for(int i = 0; i < n; i ++) {
    	if(a[i] == b[i] and b[i] == c[i]) {
    		continue;
    	}
    	else if(a[i] == b[i]) {
    		cnt ++;
    	}
    	else if(a[i] == c[i]) {
    		cnt ++;
    	}
    	else if(c[i] == b[i]) {
    		cnt ++;
    	}
    	else {
    		cnt += 2;
    	}
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, a[3005], ans, sol, fen[3005], l, k;
void update(long long poz){
	while (poz<=3000){
		fen[poz]++;
		poz+=poz&-poz;
	}return; }
	
long long query(long long poz){
	long long sum=0;
	while (poz>=1){
		sum+=fen[poz];
		poz-=poz&-poz;
	}return sum; }
	
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i]; 
	sort(a, a+n); for (int i=n; i>=1; i--) a[i]=a[i-1];
	for (long long i=1; i<=n; i++) update(a[i]);
	for (int i=1; i<=n; i++){
		for (int j=i+1; j<=n; j++){
			l=query(a[i]+a[j]-1); k=query(a[j]-a[i]); 
			l=min(l, (long long)(j-1)); k=max(k, (long long)(i)); 
			sol=l-k; ans+=max(sol, (long long) 0);
		}
	}
	cout << ans;
return 0;
}

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#include <iostream> 
using namespace __gnu_pbds; 
using namespace std; 
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
typedef tree<int, null_type, less<int>, 
rb_tree_tag, tree_order_statistics_node_update> pbset; 
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    int vis[N]={0};

    int k; cin>>k;
    int ans = -1;
    int cur(0);
    for (int i=1; ;i++)
    {
        cur*=10LL;
        cur+=7LL;
        cur%=k;

        if (!cur)
        {
            ans = i;
            break;
        }

        if (vis[cur])
            break;

        vis[cur] = 1;
    }        

    cout<< ans <<endl;
              
}

Measured memory_bytes: 11464
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<pair<int, int> > VPII;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N, A, B;
	cin >> N >> A >> B;
	string S;
	cin >> S;

	LL a_plus_b = 0, b_only = 0;
	FOR(i, 0, S.length()) {
		if (S[i] == 'a') {
			if (a_plus_b < A + B) {
				O("Yes");
				a_plus_b++;
			}
			else {
				O("No");
			}
		}
		else if (S[i] == 'b') {
			if (a_plus_b < A + B && b_only < B) {
				O("Yes");
				a_plus_b++;
				b_only++;
			}
			else {
				O("No");
			}
		}
		else {
			O("No");
		}
	}

	return 0;
}


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

typedef struct Node{
  int key;
  struct Node *prev,*next;
}Node;

Node *nil;

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->prev=nil;
}

void insert(int key){
  Node *x=(Node *)malloc(sizeof(Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

Node* listSearch(int key){
  Node *cur=nil->next;
  while (cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void deleteNode(Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void printList(){
  Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil) break;
    isf++;
    if(isf>1) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

int main(){
  int i;
  int key,n;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
	if(com[6]=='F'){
	  deleteFirst();
	}
	else if(com[6]=='L'){
	  deleteLast();
	}
      }
      else{
	deleteKey(key);
	nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 32984
N, K = map(int, input().split())
X = list(map(int, input().split()))

cur = sum((X[i] + 1) / 2 for i in range(K))
ans = cur
for i in range(K, N):
    cur += (X[i] + 1) / 2 - (X[i - K] + 1) / 2
    ans = max(ans, cur)

print(ans)


Measured memory_bytes: 98660
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll A, B, C;
    cin >> A >> B >> C;

    drop(max(C - (A - B),0LL));

    return 0;
}

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

const double PI = acos(-1);

int main(){	
int n, m ,k;
	cin >> n>> m >> k;
	vector<int> a(n);
	vector<int>b(m);
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];
	ll t=0;
	rep(i,m) t+= b[i];
	int j = m;
	int ans = 0;
	rep(i,n+1){
		while(j>0 && t>k){
			--j;
			t -= b[j];
		}
		if(t > k) break;
		ans = max(ans, i+j);
		if(i == n)break;
		t += a[i];
	}
	cout << ans << endl;
	return 0;

}





Measured memory_bytes: 4836
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a, b, c, k; cin >> a >> b >> c >> k;
    int ans = 0;
    ans = min(a,k);
    k -= ans;
    if (k > 0) {
        // cout << ans << endl;
        k -= min(b,k);
        // cout << k << endl;
        if (k > 0) {
            ans -= k;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef  long long ll;
const double PI = acos(-1.0);

int main(){

    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double x1 = h*30+m*0.5;
    double x2 = 6*m;
    double jd=fabs(x1-x2);
    if(jd>=180) jd = 360-jd;
    double g = jd*1.0/180.0*PI;
    double  ans = sqrt(a*a+b*b-2*a*b*cos(g));
    printf("%.15f\n",ans);
    return 0;
}


Measured memory_bytes: 4140
S = input().rstrip()
N = len(S) - 1
p = "+"

ans = 0
for bit in range(1 << N):
	mae = 0
	for j in range(N):
		if (bit >> j) & 1:
			ans += int(S[mae: j + 1])
			mae = j + 1
	ans += int(S[mae: len(S)])
print(ans)

Measured memory_bytes: 66528
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define FOR0(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)

int abs(int n)
{
    if (n >= 0)
        return n;
    else
        return -n;
}

int main()
{
    const int INF = 1e9;
    int N, K;
    cin >> N >> K;
    int h[N];
    FOR1(i, N)
    {
        cin >> h[i];
    }
    int dp[N];
    FOR1(i, N)
    {
        dp[i] = INF;
    }
    dp[1] = 0;
    FOR(i, 2, N)
    {
        FOR1(j, K)
        {
            if (j <= i - 1)
            {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
#include<iomanip>
#include<cstdio>
using namespace std;
#define ll long long






int main()
{
	ll n,i;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll ans=0;
	ll m=-1;
	for(i=0;i<n;i++)
	{
		if(m<a[i])
		{
			m=a[i];
		}
		else
		{
			ans+=m-a[i];
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 5144
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <list>

using namespace std;
using ll = long long;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i=0; i<N; ++i) {
        int pi;
        cin >> pi;
        p[pi-1] = i;
    }
    int count = 0;
    int max = 0;
    for (int i=0; i<N-1; ++i) {
        if (p[i] < p[i+1]) {
            ++count;
        }
        else {
            if (count > max) max = count;
            count = 0;
        }
    }
    if (count > max) max = count;
    max = N - max - 1;
    cout << max << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
  cin >> s;
  int g=0, p=0;
  int ans = 0;
  rep(i,(int)s.size()){
    if(s[i] == 'g'){
      if(g != p){
        ans++;
        p++;
      }else{
        g++;
      }
    }else{
      if(g != p){
        p++;
      }else{
        ans--;
        g++;
      }
    }
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
loop do
    n, x = gets.split.map(&:to_i)
    break if n == 0 && x == 0
    res = 0
    [*1..n].combination(3).to_a.each_with_index do |z, index|
        res += 1 if x == z.inject(:+)
    end
    puts res
end


Measured memory_bytes: 27032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n; cin>>n;
    vector<string> s;
    rep(i,n){
        string v;
        cin>>v;
        s.push_back(v);
    }
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        if(s[i]=="AC") ac++;
        if(s[i]=="WA") wa++;
        if(s[i]=="TLE") tle++;
        if(s[i]=="RE") re++;
    }
    cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
}


Measured memory_bytes: 7448
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,int> p;

int main(){
  int x,y;
  cin >> x >> y;
  cout << x + (int)y/2 << endl;
  return 0;
}


Measured memory_bytes: 256
func main(input1: String = readLine()!, input2: String = readLine()!) {
    let stones = Array(input2)
    let numberOfR = stones.filter { $0 == "R" }.count
    let numberOfMovingW = stones[..<numberOfR].filter { $0 == "W" }.count
    print(numberOfMovingW)
}

main()

Measured memory_bytes: 14580
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i%2 == 0:
        ans += a[i]
    else:
        ans -= a[i]
ans1 = ans
print(ans, end=' ')
for i in range(1, n):
    ans *= -1
    ans += 2*a[i-1]
    print(ans, end=' ')
    
print()


Measured memory_bytes: 20648
l, r = map(int, input().split())
a = 2019

for i in range(r - l):
    t = 2019
    for j in range(i + 1, r - l + 1):
        tmp = (l + i) * (l + j) % 2019
        if a > tmp:
            a = tmp
        if a == 0:
            print(a)
            exit()
#        if tmp > t:
#            break
#        t = tmp
        

print(a)

Measured memory_bytes: 2940
#include <bits/stdc++.h> 
using namespace std;
//関数
const long INF=1000000000000000;
const long MOD=1000000007;
bool check=false;


int main(void){
    long N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    char p=S.at(0);
    long count=0;
    for(int i=0;i<N;i++){
        count+=(S.at(i)!=p);
        p=S.at(i);
    }
    long ans=N-(count+1);
    //cout<<ans<<endl;
    //cout<<count<<endl;
    while(K>0){
        K--;
        if(count>=2) {
            ans+=2;
            count-=2;
        }
        else if(count==1){
            ans++;
            count--;
        } 
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		String s = sc.next();
		String t = sc.next();
		String ans = "No";

		for (int i = 0; i <= t.length(); i++) {
			if (s.equals(t)) {
				ans = "Yes";
				break;
			}
			s = s.substring(s.length() - 1) + s.substring(0, s.length() - 1);
		}
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b < 24) cout << a+b << endl;
    else cout << a+b-24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>


using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    ll N,M;
    cin >> N >> M;
    UnionFind tree(N+10);
    for(int i=0;i<M;i++){
        int x,y,z;
        cin >> x >> y >> z;
        tree.unite(x,y);
    }
    set<int> se;
    int ans=0;
    for(int i=1;i<=N;i++){
        if(!se.count(tree.root(i))){
            se.insert(tree.root(i));
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 20:25:04 2020

@author: naoki
"""

K, S = map(int, input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z >= 0 and z <= K:
            count += 1
            
print(count)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    for (int i = 0; i < S.length() - 1; i++) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int num=input.nextInt();
        if(num>=100 && num<=999)
        {
          String temp=""+num;
          if((temp.length()%2==0))
          {
            System.out.println("No");
            
          }else
          {
            int counter=0;
            for(int k=0;k<(temp.length()/2);k++)
            {
              int temp2=temp.length()-1-k;
              if(temp.charAt(k)==temp.charAt(temp2))
              {
                counter++;
              }
            }
            if(counter==(temp.length()/2))
            {
              System.out.println("Yes");
            }else
            System.out.println("No");
          }
          
        }
  }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[100][100];
bool L[100][100];
bool R[100][100];

signed main(){
    while(cin>>N,N){
        rep(i,N)rep(j,N)cin>>A[i][j];
        memset(L,0,sizeof(L));memset(R,0,sizeof(R));
        rep(i,N){
            int mi=LLONG_MAX;
            rep(j,N)chmin(mi,A[i][j]);
            rep(j,N)L[i][j]=A[i][j]==mi;
        }
        rep(j,N){
            int ma=LLONG_MIN;
            rep(i,N)chmax(ma,A[i][j]);
            rep(i,N)R[i][j]=A[i][j]==ma;
        }
        int ans=0;
        rep(i,N)rep(j,N)if(L[i][j]&&R[i][j])ans=A[i][j];
        cout<<ans<<endl;
    }
    return 0;
}

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

int pcnt(int x) {
  return __builtin_popcount(x);
}

int f(int x) {
  if(x == 0) return 0;
  return f(x%pcnt(x)) + 1;
}

int main() {
  int n; cin >> n;
  string s; cin >> s;
  vector<int> x(n); for(int i = 0; i < n; i++) x[i] = s[i] - '0';
  int pc = 0; for(int i = 0; i < n; i++) pc += x[i];
  vector<int> ans(n, 0);
  for(int b = 0; b < 2; b++) {
    int npc = pc;
    npc = (b == 0) ? npc + 1 : npc - 1;
    if(npc <= 0) continue;
    int r0 = 0;
    for(int i = 0; i < n; i++) {
      r0 = (r0 * 2) % npc;
      r0 += x[i];
    }

    int k = 1;
    for(int i = n-1; i >= 0; i--) {
      if(x[i] == b) {
        int r = r0;
        if(b == 0) r = (r + k) % npc;
        else r = (r - k + npc) % npc;
        ans[i] = f(r) + 1;
      }
      k = (k * 2) % npc;
    }
  }

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


Measured memory_bytes: 5216
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{

    int N, M;
    cin >> N >> M;

    vector<vector<int>> V(N,vector<int>());
    for (int i = 0; i < N; ++i){
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j){
            int a;
            cin >> a;
            V[i].push_back(a);
        }
    }

    vector<int> item(M+1, 0);
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < V[i].size(); ++j){
            item[V[i][j]] += 1;
        }
    }
    int ans = 0;
    for (int j = 0; j <= M; ++j)
    {
        if(item[j] == N){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
left = [None for i in range(n)]
right = [None for i in range(n)]
root = sum(range(n)) - n - 1

for i in range(n):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)

def Preorder(i):
    if (i == -1):
        return
    print(" {}".format(i), end = "")
    Preorder(left[i])
    Preorder(right[i])
      
def Inorder(i):
    if (i == -1):
        return
    Inorder(left[i])
    print(" {}".format(i), end = "")
    Inorder(right[i])
      
def Postorder(i):
    if (i == -1):
        return
    Postorder(left[i])
    Postorder(right[i])
    print(" {}".format(i), end = "")

print("Preorder")
Preorder(root)
print()
  
print("Inorder")
Inorder(root)
print()
  
print("Postorder")
Postorder(root)
print()

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

#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))

int main(void){
    int N, a[100005], b[5], c[5], i, j, p, t;
    scanf("%d", &N);
    if (0) {
        ;
    }
    else {
        p=1;
        j=0;
        b[1]=-1; b[2]=-1; b[3]=-1;
        for (i=1; i<=N; i++) {
            scanf("%d", &a[i]);
            if (j==0) {
                b[1]=a[i];
                j++;
            }
            if (j==1 && a[i]!=b[1]) {
                b[2]=a[i];
                j++;
            }
            if (j==2 && a[i]!=b[1] && a[i]!=b[2]) {
                b[3]=a[i];
                j++;
            }
            if (j==3 && a[i]!=b[1] && a[i]!=b[2] && a[i]!=b[3]) {
                p=0;
                j++;
                break;
            }
        }
        
        while (!(b[1]<=b[2] && b[2]<=b[3])) {
            if (b[1]>b[2]) {
                t=b[1];
                b[1]=b[2];
                b[2]=t;
            }
            if (b[2]>b[3]) {
                t=b[2];
                b[2]=b[3];
                b[3]=t;
            }
        }
        
        if (j==1 && b[3]!=0) p=0;
        if (j==3 && (b[1]^b[2])!=b[3]) p=0;
        
        c[1]=0; c[2]=0; c[3]=0;
        for (i=1; i<=N; i++) {
            if (p==0) break;
            if (a[i]==b[1]) c[1]++;
            else if (a[i]==b[2]) c[2]++;
            else if (a[i]==b[3]) c[3]++;
        }
        
        if (j==2 && !(c[1]==0 && c[2]==N/3 && c[3]==2*N/3)) p=0;
        if (j==3 && !(c[1]==N/3 && c[2]==N/3 && c[3]==N/3)) p=0;
        /*rintf("%d, %d, %d\n", c[1], c[2], c[3]);
        printf("%d, %d, %d\n", b[1], b[2], b[3]);
        printf("%d\n", j);*/
    }
    if (p==1) printf("Yes");
    else printf("No");
    return 0;
}
/*
b[1]=a[1];
    for (i=2; i<=2; i++) {
        b[2]=a[i];
        printf("%d\n%d\n", b[1], b[2]);
        for (j=3; j<=N; j++) {
            b[j]=b[j-1]^b[j-2];
            printf("%d\n", b[j]);
        }
    }
*/

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  double check = 0;
  rep(i,n){
    ll x = a[i];
    ans *= x;
    check += log10(x);
    //cout << check << endl;
    if(check > 18 || ans > (ll)pow(10,18)){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4056