akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll D;
    cin>>D;
    V<ll> c(26);
    
    cinf(26,c);
    V<P> p(26);
    V<ll> t(D);
    set<P> st;
    ll sum=0;
    /*rep(i,26){
        p[i]=make_pair(c[i],i);
    }
    sort(all(p));*/
    ll s[D][26];
    rep(i,D){
        rep(j,26)cin>>s[i][j];
    }
    rep(i,D){
        cin>>t[i];
        t[i]--;
    }
    V<ll> ans(D);
    
    ll M;
    cin>>M;
    while(M--){
        ll d,q;
        cin>>d>>q;
        d--;q--;
        t[d]=q;
        ll now=0;
        V<ll> lst(26,1);
        rep(i,D){
        
        ll cnt=0;
        rep(j,26){
            if(j!=t[i]){
                cnt+=c[j]*lst[j];
            }
        }
        now+=s[i][t[i]]-cnt;
        
        //cout<<now<<endl;
        lst[t[i]]=1;
        rep(j,26){
            if(j!=t[i]) lst[j]++;
        }
    }
    cout<<now<<'\n';
    }
    
    //cout<<ans[i]<<endl;
    /*rep(i,D) cout<<ans[i]+1<<endl;*/
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=1,n=11,m=0,o=0;
  std::cin >> x;
std::vector<char> v;
while(x>=1){
    y=(x-1)%26;
    z=(x-1)/26;
    v.pb((char)y+97) ;
    x=z;
  }
rep(i,v.size())std::cout << v[v.size()-1-i];
std::cout << '\n';
}


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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int, int>;

signed main() {
  int n, k;
  cin >> n >> k;

  vi p(n);
  rep(i, 0, n) cin >> p[i];

  vi q(n);
  rep(i, 0, n) q[i] = p[i]+1;

  int sum = 0;
  rep(i, 0, k) sum += q[i];

  int ans = sum;
  rep(i, k, n){
    sum -= q[i-k];
    sum += q[i];
    chmax(ans, sum);
  }

  printf("%.9f\n", (double)ans/2);

  return 0;
}


Measured memory_bytes: 3328
S = input()
N = len(S) + 1
result = [ -1 for i in range(N) ]

def countContinueChar(index):
    startChar = S[index]
    count = 0
    for i in range(index, N-1):
        if S[i] != startChar:
            break
        count += 1
    return count

def getValueOfIndex(index, current, prev = '', preprev = ''):
    if S[index] == '<':
        if prev == '>':
            return 0
        else:
            return current + 1
    else:
        if prev == '<':
            v = countContinueChar(index)
            if v < current + 1:
                return current + 1
            else:
                return v
        else:
            if preprev == '<' and prev == '>':
                return countContinueChar(index)
            else:
                if prev != '>':
                    return countContinueChar(index)
                else:
                    return current - 1

current = -1
prev = ''
preprev = ''
sum = 0
for i in range(N):
    if i == N-1:
        if S[-1] == '<':
            result[i] = current + 1
            sum += current + 1
        #else:
            #result[i] = 0
        break
    if i > 0:
        prev = S[i - 1]
    if i > 1:
        preprev = S[i - 2]
    current = getValueOfIndex(i, current, prev, preprev)
    #result[i] = current
    sum += current

#print(result)
print(sum)

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

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

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

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

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

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

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

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

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

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

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

int a,b,c;

signed main(){
    in(a,b,c);
    if(a>b&&a>c){
        out("A");
    }else if(b>a&&b>c){
        out("B");
    }else{
        out("C");
    }

    return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define IOS                      \
   ios_base::sync_with_stdio(0); \
   cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define Maxn 1000000 + 10
using namespace std;
int n;
int h;
int result = 0;
map<ll,ll> mp;
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);  //递归求最大公约数
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;    //递归求最小公倍数
} 
int main()
{
    IOS;
    ll a,b;
    cin>>a>>b;
    ll g=gcd(a,b);
    for(ll i=2;i*i<g;i++)
    {
        while(g%i==0)
        {
            mp[i]++;
            g/=i;
        }
    }
    if(g!=1)
    {
        mp[g]=1;
    }
    cout<<mp.size()+1<<endl;
}


Measured memory_bytes: 768
-- Ball
-- import Control.Monad
--
-- main :: IO ()
-- main = readLn
--   >>= (\ n -> replicateM n getLine)
--   >>= mapM putStrLn . solve
--
-- kolve :: [String] -> String
-- solve = tellYesNo . dfs 0 0 . map (map read . words)
--
-- dfs :: Int -> Int -> [Int] -> Bool
-- dfs _ _ [] = True
-- dfs l r (x:xs)
--   | l < x && r < x = dfs x r xs || dfs l x xs
--   | l < x     = dfs x r xs
--   | r < x     = dfs l x xs
--   | otherwise = False
--
import Control.Monad

main = readLn
  >>= (\ n -> replicateM n getLine)
  >>= mapM solve . map (map read) . map words

solve :: [Int] -> IO ()
solve = putStrLn . tellYesNo . dfs 0 0

dfs :: Int -> Int -> [Int] -> Bool
dfs _ _ [] = True
dfs l r (x:xs)
  | l < x && r < x = dfs x r xs || dfs l x xs
  | l < x = dfs x r xs
  | r < x = dfs l x xs
  | otherwise = False

tellYesNo :: Bool -> String
tellYesNo b
  | b == True = "YES"
  | otherwise = "NO"

Measured memory_bytes: 4040
/**
 * @author torith
 * @date 2018-10-13
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
        cout << '0' << "\n";
        return 0;
    }

    ll ans = min(min(A*B,A*C),B*C);
    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>

using namespace std;

#define NMAX 20

struct point{
	int x,y;
};

int main(){

	int N,M;
	char dir;
	string dirdata("WSNE");
	int dx[]={-1,0,0,1};
	int dy[]={0,-1,1,0};
	int x,y,dis;
	point robo,juel[NMAX];
	int cnt;

	while(1){

		cin>>N;
		if(N==0) break;

		robo.x=10,robo.y=10;
		cnt=0;

		for(int i=0;i<N;i++){
			cin>>x>>y;
			if(x==10&&y==10) cnt++,x=-1,y=-1;
			juel[i].x=x,juel[i].y=y;
		}

		cin>>M;
		for(int i=0;i<M;i++){
			cin>>dir>>dis;
			for(int i=0;i<dis;i++){
				robo.x+=dx[dirdata.find(dir)];
				robo.y+=dy[dirdata.find(dir)];
				for(int j=0;j<N;j++){
					if(robo.x==juel[j].x&&robo.y==juel[j].y){
						cnt++;
						juel[j].x=-1,juel[j].y=-1;
					}
				}
			}
		}
		if(cnt==N) puts("Yes");
		else puts("No");
	}


	return 0;
}

Measured memory_bytes: 1168
fun main(args: Array<String>) {
    val n = readInt()
    var a = readListLong().sorted().toMutableList()
    val q = readInt()
    var bc = readMatrixInt(q)
    var list = LongArray(100007).toMutableList()
    a.forEach {
        list[it.toInt()]++
    }

    var ans:Long = a.sum().toLong()


    for (i in 0 until q) {

        val b = bc[i][0]
        val c = bc[i][1]
        var sa: Int = c - b
        var count: Long = list[b]

        list[b] -= count
        list[c] += count

        ans += sa * count
        println(ans)
    }
}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 76932
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
    
if(N%2 != 0):    
    print(B[N//2]-A[N//2]+1)
else:
    print(B[N//2]+B[N//2-1] - A[N//2]-A[N//2-1] + 1)

Measured memory_bytes: 25404
def resolve():
    from math import ceil
    h, w = map(int, input().split())
    if h <= 1 or w <= 1:
        print(1)
    elif h * w % 2 == 0:
        print(int(h * w / 2))
    else:
        print(int(ceil(h * w / 2)))


resolve()

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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int V[N];
    int C[N];
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    
    int res = 0;
    for (int i = 0; i < N; i++) {
        int _tmp_money = V[i] - C[i];
        if (_tmp_money > 0) {
            res += _tmp_money;
        }
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N,K,Q=map(int,input().split())
a_list,b_list=[],[]
for i in range(Q):
    a=int(input())
    a_list.append(a)

points=[K-Q]*N
A=list(a_list)
for a in a_list:
    points[a-1]+=1
for p in points:
    if p>0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m =sc.nextInt();
		int k, a;
		int food[][] = new int[n][m + 1];
		for(int i = 0; i < n; ++i) {
			k = sc.nextInt();
			for(int j = 0; j < k; ++j) {
				a = sc.nextInt();
				food[i][a]++;
			}
		}
		sc.close();
		int ans = 0;
		int j = 0;
		for(int i = 1; i <= m; ++i) {
			for(j = 0; j < n; ++j) {
				if(food[j][i] == 0)break;
			}
			if(j == n)++ans;
		}
		System.out.println(ans);
	}

}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    string s;
    cin >> s;

    // 処理
    // 出力
    rep(i, s.size()) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a[(int)1e5],t;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>t;
        a[t]=i;
    }
    for(int i=1; i<=n; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 100 * 1000 + 7;
vector<int> g[MX];

bool fl = false;

int dfs(int v, int p = -1) {
    int sm = 0;
    for (int to : g[v]) {
        if (to != p) {
            sm += dfs(to, v);
        }
    }
    if (sm >= 2) {
        fl = true;
    }
    return sm == 0;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if (dfs(1) == 1) {
        fl = true;
    }
    if (fl) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
    return 0;
}




Measured memory_bytes: 5888
#include "stdio.h"

#define max(a,b) (a) > (b) ? (a) : (b)

int n;
long long int dp[31] = {};//i段目におけるパターン

long long int ans = 0;

int main(){

	while(1){

		scanf("%d",&n);

		if(n==0) break;

		ans = 0;

		for(int i=0;i<=n;i++){
			dp[i] = 0;	
		}

		dp[0] = 1;
		
		for(int i=1;i<=n;i++){
			for(int j=1;j<=3;j++){
				if(i-j>=0){
					dp[i] += dp[i-j];
				}
			}
		}

		printf("%d\n",(int)(dp[n]/3650) + 1);

	}

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 998244353
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
int main(){
	fast_io();
	string s;
	cin >> s;
	for(char a:s){
		cout << (a == '9'?'1':'9');
	}cout << '\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long n,d,a,b,c=0,i;
  cin>>n>>d;
  for(i=0;i<n;i++)
  { cin>>a>>b;
   if((a*a) +(b*b)<=d*d)
     c++;
  }
  cout<<c;
}
  

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

using namespace std;

using lint = long long;

void solve() {
	int A, B, C, D; scanf("%d%d%d%d", &A,&B,&C,&D);
	int ans = 0;
	for(int t = 0; t < 100; t++) {
		if(A <= t && t < B && C <= t && t < D) {
			ans++;
		}
	}
	printf("%d\n", ans);
}


int main(int argc, char *argv[]) {
	int T=1;
	for(int TC = 1; TC <= T; TC++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;

  for(int i=sy+1;i<=ty;i++){
    cout<<'U';
  }
  for(int i=sx+1;i<=tx;i++){
    cout<<'R';
  }
  for(int i=ty-1;i>=sy;i--) cout<<'D';
  for(int i=tx-1;i>=sx;i--) cout<<'L';
  cout<<'L';
  for(int i=sy+1;i<=ty+1;i++) cout<<'U';
  for(int i=sx+1;i<=tx+1;i++) cout<<'R';
  cout<<'D';
  cout<<'R';
  for(int i=ty-1;i>=sy-1;i--) cout<<'D';
  for(int i=tx-1;i>=sx-1;i--) cout<<'L';
  cout<<'U'<<endl;
  return 0;
}


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

using namespace std;

typedef long long LL;

#define MAX_N 100005
#define MAX_M 100005

int N, M;
int K[MAX_N];
vector<int> L[MAX_N];

void input()
{
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    scanf("%d", &K[i]);
    for (int j = 0; j < K[i]; j++) {
      int l;
      scanf("%d", &l);
      L[i].push_back(l);
    }
  }
}

class UnionFind{
public:
  int par[MAX_N];
  int cnt[MAX_N];
  UnionFind()
  {
    init();
  }
  void init()
  {
    memset(par, 0, sizeof(par));
    memset(cnt, 0, sizeof(cnt));
    for (size_t i = 0; i < MAX_N; i++) {
      par[i] = i;
    }
    for (size_t i = 0; i < N; i++) {
      cnt[L[i][0]]++;
    }
  }
  int find(int x)
  {
    if(x == par[x]){
      return x;
    }
    else{
      return par[x] = find(par[x]);
    }
  }
  void unite(int x, int y)
  {
    x = find(x);
    y = find(y);
    if(x == y){
      return;
    }
    par[x] = y;
    cnt[y] += cnt[x];
  }
  bool same(int x, int y)
  {
    return find(x) == find(y);
  }
  int size(int x)
  {
    return cnt[find(x)];
  }
}unionFind;

int main()
{
  input();

  unionFind.init();

  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < K[i]-1; j++) {
      unionFind.unite(L[i][j], L[i][j+1]);
    }
  }

  //cerr << unionFind.size(L[0][0]) << endl;
  if(unionFind.size(L[0][0]) == N){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

  return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1000 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    vector<int> v(3);
    rep(i, 3) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    cout << v[2] * 10 + v[1] + v[0] << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

type p struct{ r, c int }

func main() {
	var H, W, N int
	fmt.Scan(&H, &W, &N)
	M := map[p]int{}
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		for r := a - 3; r < a; r++ {
			if r < 0 || r > H-3 {
				continue
			}
			for c := b - 3; c < b; c++ {
				if c < 0 || c > W-3 {
					continue
				}
				M[p{r, c}]++
			}
		}
	}
	A := make([]int, 10)
	for _, v := range M {
		A[v]++
	}
	A[0] = (H-2)*(W-2) - len(M)
	for _, a := range A {
		fmt.Println(a)
	}
}


Measured memory_bytes: 113792
from collections import deque
import sys
sys.setrecursionlimit(10**9)
n=int(input())
a=[int(x) for x in input().split()]

v=deque()
for x in sorted(a):
    v.append(x)
def A(l):
    if len(l)==1:
        print(l[0])
    else:
        l.appendleft((l.popleft()+l.popleft())/2)
        A(l)

A(v)


Measured memory_bytes: 3316
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by zzt on 17-4-8.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] s = new String[n];
        int[][] charCount = new int[26][n];
        for (int i = 0; i < n; i++) {
            s[i] = scanner.next();
        }
        char[] sc;
        for (int i = 0; i < n; i++) {
            sc = s[i].toCharArray();
            for (char c :
                    sc) {
                charCount[c - 'a'][i]++;
            }
        }
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < 26; i++) {
            Arrays.sort(charCount[i]);
            for (int j = 0; j < charCount[i][0]; j++) {
                buf.append((char) (i + 'a'));
            }
        }
        System.out.println(buf.toString());
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i <= b; ++i) {
        if(a*i%b == c) {
            cout << "YES" << "\n";
            return 0;
        }
    }
    cout << "NO" << "\n";
    return 0;
}


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

using namespace std;
using LLONG = long long;

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

    return 0;
}

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

int main() {
  int N, K, x, sum = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x < K - x) {
      sum += 2 * x;
    } else {
      sum += 2 * (K - x);
    }
  }
  cout << sum << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, k);
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  ll ans = numeric_limits<ll>::max();
  for (int i = k - 1; i < n; ++i) {
    ll l = x[i - (k - 1)], h = x[i];
    ans = min(ans, h - l + min(abs(h), abs(l)));
  }
  out(ans);
}


Measured memory_bytes: 4044
using System;

public class Dijkstra {
    
    const int MAX   = 100;
    const int INFTY = 1000000;
    const int WHITE = 0;
    const int GRAY  = 1;
    const int BLACK = 2;

    public int[,] M; // 2?¬??????????

    Dijkstra(int n) {
	this.M = new int[n, n]; // 2?¬????????????????????????????
    }

    public void dijkstra(int n) {
	int minv = 0;
	int[] d = new int[MAX];
	int[] color = new int[MAX];

	for (int i = 0; i < n; i++) {
	    d[i] = INFTY;
	    color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	while (true) {
	    minv = INFTY;
	    int u = -1;
	    for (int i = 0; i < n; i++) {
		if (minv > d[i] && color[i] != BLACK) {
		    u = i;
		    minv = d[i];
		}
	    }
	    if (u == -1) {
		break;
	    }
	    color[u] = BLACK;
	    for (int v = 0; v < n; v++) {
		if (color[v] != BLACK && M[u, v] != INFTY) {
		    if (d[v] > d[u] + M[u, v]) {
			d[v] = d[u] + M[u, v];
			color[v] = GRAY;
		    }
		}
	    }
	    
	}
	
	for (int i = 0; i < n; i++) {	    
	    Console.WriteLine(i + " " + (d[i] == INFTY ? -1 : d[i]));
	}
    }

    public static void Main() {
	// G???????????°n?????\???
	int n = int.Parse(Console.ReadLine());
	Dijkstra dijkstra = new Dijkstra(n);

	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < n; j++) {
		dijkstra.M[i, j] = INFTY;
	    }
	}

	int u = 0; // ????????????(????????????)
	int k = 0; // u???????¬???°(????????¨???????????£????????????)
	int v = 0; // u??¨??£??\????????????????????????
	int c = 0; // u-v????????????
	
	for (int i = 0; i < n; i++) {
	    string[] input = Console.ReadLine().Split(' ');
	    // ??\????????????1,2????????????u,k(????????????, ????¬???°)
	    u = int.Parse(input[0]);
	    k = int.Parse(input[1]);
	    // 3???????????\??????????¬???°?????????v,c(u?????£??\??????????????????, ??????)

	    int offset = 2;
	    
	    for (int j = 0; j < k; j++) {
		v = int.Parse(input[offset]);
		c = int.Parse(input[offset + 1]);
		dijkstra.M[u, v] = c;
		offset += 2;		    
	    }
	}
	dijkstra.dijkstra(n);
    }
}

Measured memory_bytes: 9232
// problem: "https://atcoder.jp/contests/abc122/tasks/abc122_a"

#include<iostream>

using namespace std;

int main()
{
    char c;
    cin>>c;

    if(c=='A')
        cout<<'T';
    else if(c=='T')
        cout<<'A';
    else if(c=='G')
        cout<<'C';
    else
        cout<<'G';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
 
int a;
int solve(int p,int q,int n,int seki,int l){
  if(p==0) return 1;
  if(n<=0) return 0;
  int ret = 0;
  for(int i=l;seki*i<=a;++i){
    int bunsi = p*i-q;
    int bunbo = q*i;
    if(bunsi<0) continue;
    ret+=solve(bunsi,bunbo,n-1,seki*i,i);
  }
  return ret;
}
 
int main(){
  int p,q,n;
  while(cin>>p>>q>>a>>n,p){
    //memset(memo,0,sizeof(memo));
    cout << solve(p,q,n,1,1) << endl;
  }
  return 0;
}

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

using namespace std;

#define lint long long
#define P pair<int, int>

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

    int tmp = N;

    int X = 0;
    for(int i = 0; i < 8; ++i){
        X += tmp % 10;
        tmp /= 10;
    }
    if(N % X){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
    int a, b;
    scanf("%d%d",&a, &b);
    if(a < 10)
    printf("%d\n", 100 * (10 - a) + b);
    else printf("%d\n",b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<string.h>
#define ll long long
using namespace std;
const ll mod = 1e9;

int main ()
{
	//	freopen("1.out","r",stdin);
	//	freopen("abc.out","w",stdout);
	
	int n,k,s;
	cin>>n>>k>>s;
	for(int i=1;i<=n;i++)
	{
		if(i<=k)
			cout<<s;
		else
		{
			if(s == mod-1 ) cout<<mod;
			else cout<<mod-1;
		}
		cout<<" ";
	}
	cout<<endl;
	return 0;
}

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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1) {
    for(int u : to[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u,v); 
    }   
}

// 典型問題、木を直線化する
int main(){
    int n, q;
    cin >> n >> q;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
Int check(Int a,Int b,Int c){
  if(a==b or b==c or c==a) return 0;
  if(a>=b+c) return 0;
  if(b>=a+c) return 0;
  if(c>=a+b) return 0;
  return 1;
}

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

  Int n;
  cin>>n;

  auto ls=read(n);

  Int ans=0;
  for(Int i=0;i<n;i++)
    for(Int j=i+1;j<n;j++)
      for(Int k=j+1;k<n;k++)
        if(check(ls[i],ls[j],ls[k])) ans++;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n;
    cin >> n;
    double a = (n + 1) / 2;
    cout << a / n << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int n, m, ans = 305, a[305][305], b[305], d[305], vi[305];
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		b[i] = 1;
		d[a[i][1]]++;
	}
	for (int i = 1; i <= m; i++) {
		int mon = 0;
		for (int j = 1; j <= m; j++) {
			if (!vi[j]) {
				if (d[j] > d[mon]) {
					mon = j;
				}
			}
		}
		ans = min(ans, d[mon]);
		vi[mon] = 1;
		for (int j = 1; j <= n; j++) {
			d[a[j][b[j]]]--;
			while (vi[a[j][b[j]]])
			{
				b[j]++;
			}
			d[a[j][b[j]]]++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            long answer = 0;

            for (int i = 1; i <= N; i++)
            {
                if (i % 3 != 0 && i % 5 != 0)
                {
                    answer += i;
                }
            }

            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 27544
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	i := 1
	for {
		sc.Scan()
		in := sc.Text()
		val, _ := strconv.Atoi(in)
		if val == 0 {
			return
		}

		fmt.Printf("Case %v: %v\n", i, val)
		i++
	}

}



Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N, Y;
int main(){
  int i, j, k;
  rd(N);
  rd(Y);
  Y /= 1000;
  for(i=Y%5;i<=N;i+=5){
    for(j=0;j<N+1-i;j++){
      k = N - i - j;
      if(i+5*j+10*k==Y){
        wt_L(k);
        putchar_unlocked(' ');
        wt_L(j);
        putchar_unlocked(' ');
        wt_L(i);
        putchar_unlocked('\n');
        return 0;
      }
    }
  }
  wt_L(-1);
  putchar_unlocked(' ');
  wt_L(-1);
  putchar_unlocked(' ');
  wt_L(-1);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// int N, Y;
// {
//   int i, j, k;
//   
//   rd(N,Y);
//   Y /= 1000;
// 
//   for(i=Y%5;i<=N;i+=5) rep(j,N+1-i){
//     k = N - i - j;
//     if(i+5j+10k==Y){
//       wt(k,j,i);
//       return 0;
//     }
//   }
//   wt(-1,-1,-1);
// }


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

int main(void) {
    int s[5],k;
    cin >> s[0] >> s[1] >> s[2] >> s[3] >> s[4] >> k;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < i; j++) {
            if (s[i] - s[j] > k || s[j] - s[i] > k) {
                cout << ":(\n";
                return 0;
            }
        }
    }
    cout << "Yay!";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<long long> dp(w + 1);
  for (int i = 0; i < n; i++){
    int ww, vv;
    cin >> ww >> vv;
    for (int j = w - ww; j >= 0; j--){
      dp[j + ww] = max(dp[j + ww], dp[j] + vv);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << '\n';
    
  return 0;
}


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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define max_heap priority_queue <int> pq; // max heap 
#define min_heap priority_queue <int, vector<int>, greater<int> > pq;  //min heap
#define make_pairVector vector<pair<long long int,long long int> > pairVector // vector of pairs
#define hashmap unordered_map<long long int, long long int>hashmap;
#define pb push_back


//map<pair<ll,ll>, ll > hash;          // pair,value hashmap where key is a pair
//hash[make_pair(i,j)] = 0;
//if(hash.find(make_pair(i,j)) == hash.end())


//map<ll,ll>::iterator itr;           // iterating a map
//for (itr = hash.begin();itr != hash.end(); itr++)
//{
//   itr->first = key  
//   itr->second = value
//}


// vector<string> v; //to convert vector to a set
// set<string> s(v.begin(), v.end());


// set<string>s;     // to convert set to a vector
// vector<string> v(s.begin(),s.end());


// cin >> x >> y;
// pairVector.pb(mp(x,y));


// string size = str.size()


// stack <int> s; 


// queue <int> gquiz; 


// __gcd(m, n) 

// ll arr[10e5 + 5];


// char arr[10e5 + 5];


// printf ("%.9f\n",x);


bool sortbysec(const pair<long long int,long long int> &a, const pair<long long int,long long int> &b) 
{ 
    return (a.second < b.second); 
}
bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
int check_key(map<long long int, long long int> m, long long int key) 
{ 
    // Key is not present 
    if (m.find(key) == m.end()) 
        return 0; 
  
    return 1; 
} 

void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}

int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x,n;
    cin >> x >> n;
    ll freq[105] = {0};
    ll mindiff = 10000,y,ans = 1;
    for(ll i = 0; i<n; i++)
    {
        cin >> y;
        freq[y] = 1;
    }
    for(ll i = 0; i<=101; i++)
    {
        if(freq[i] == 0)
        {
            if(abs(x-i)< mindiff)
            {
                mindiff = abs(x-i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}   

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

using namespace std;

int main(){
  int N; cin >> N;
  vector<int> A1(N); vector<int> A2(N);
  for(int i = 0; i < N; i++){ cin >> A1[i];}
  for(int i = 0; i < N; i++){ cin >> A2[i];}
  
  int sum = 0;
  
  for(int i = 0; i < N; i++){
    int res = 0;
    for(int k = 0; k <= i; k++){
      res += A1[k];}
    for(int l = i; l < N; l++){
      res += A2[l];}
    sum = max( sum, res);}
  
  cout << sum << endl; return 0;}

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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve() {
    int n, m;
    cin>>n>>m;
    unordered_map<int, int> hs;
    for (int i = 0; i < n; ++i) {
        int k;
        cin>>k;
        for (int j = 0; j < k; ++j) {
            int temp;
            cin>>temp;
            hs[temp] += 1;
        }
    }
    int ans = 0;
    for(auto& e:hs){
        if(e.second == n){
            ans += 1;
        }
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}


Measured memory_bytes: 3664
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-08-29 21:38:12 +0900
# LastModified: 2020-08-29 21:54:27 +0900
#


import os
import sys
sys.setrecursionlimit(900000)
# import numpy as np
# import pandas as pd
from collections import Counter


def dfs(u, color, path, n, d):
    color[u] = d
    for v in path[u]:
        if color[v] == -1:
            dfs(v, color, path, n, d)



def main():
    n, m = map(int, input().split())
    path = [[] for _ in range(n+1)]
    for _ in range(m):
        a, b = map(int, input().split())
        path[a].append(b)
        path[b].append(a)
    color = [-1]*(n+1)
    d = 0
    for i in range(1, n+1):
        if color[i] == -1:
            dfs(i, color, path, n, d)
            d += 1
    color = color[1:]
    color_cnt = Counter(color).values()
    print(max(color_cnt))



if __name__ == "__main__":
    main()


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

int main(){

vector<vector<int>> a(3,vector<int>(3));
vector<vector<int>> A(3,vector<int>(3));


for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){

      cin >> a.at(i).at(j);

  }
}

int N;
cin >> N;
vector<int> b(N);

for (int k = 0; k < N; k++)
{
  cin >> b.at(k);
  for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        if (a.at(i).at(j) == b.at(k)) A.at(i).at(j)=1;
    }
  }
}
bool tf = false;
int sum = 0;

for (int i = 0; i < 3; i++) {
  sum = A.at(i).at(0) + A.at(i).at(1) +A.at(i).at(2);
if (sum == 3)  tf = true;
}

sum = 0;
for (int i = 0; i < 3; i++) {
  sum = A.at(0).at(i) + A.at(1).at(i) +A.at(2).at(i);
if (sum == 3)  tf = true;
}

sum = 0;
for (int i = 0; i < 3; i++) sum += A.at(i).at(i);
if (sum == 3)  tf = true;

sum = 0;
sum = A.at(0).at(2)+A.at(1).at(1)+A.at(2).at(0);
if (sum == 3)  tf = true;

if (tf == true) cout << "Yes" <<endl;
else cout << "No" <<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,number;
    int k=0;
    for(i=1;i<=n;i++)
    {
        cin>>number;
        if(i%2!=0 && number%2!=0)
            k++;
    }
    cout<<k<<endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int now=0;
	while (now<s.size()) {
		if (s[now]=='S'&&now+1<s.size()&&s[now+1]=='T') {
			s.erase(now,2);
			if (now>0) now--;
		}
		else now++;
	}
	printf("%d\n",s.size());
	return 0;
} 

Measured memory_bytes: 640
def run():
  N, W = map(int, input().split())
  wv_li = [[0, 0]]+[list(map(int, input().split())) for n in range(N)]
  dp = [[0]*(N+1) for w in range(W+1)]
  #print(wv_li)
  #print(dp)
  for w in range(1, W+1):
    for n in range(1, N+1):
      wn, vn = wv_li[n]
      if w < wn:
        dp[w][n] = dp[w][n-1]
      else:
        dp[w][n] = max(dp[w][n-1], dp[w-wn][n-1]+vn)
  print(dp[W][N])
      
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 130908
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		int cou = 0;
		for(int i = 0; i < n-1; i++){
			int min = i;
			for(int j = i+1; j < n; j++){
				if(a[j] < a[min]){
					min = j;
				}
			}
			if(min != i){
				cou++;
				int work = a[min];
				a[min] = a[i];
				a[i] = work;
			}
		}
		for(int i = 0; i < n-1; i++){
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n-1]);
		System.out.println(cou);
	}
}



Measured memory_bytes: 26412
def main():
    a, b = list(map(int, input().split()))
    if b - a <= 3:
        ans = a
        for i in range(a + 1, b + 1):
            ans = ans ^ i
        print(ans)
    else:
        if a % 4 == 0:
            ans = 0
        elif a % 4 == 1:
            ans = a ^ (a + 1) ^ (a + 2)
        elif a % 4 == 2:
            ans = a ^ (a + 1)
        else:
            ans = a
        if b % 4 == 0:
            ans = ans ^ b
        elif b % 4 == 1:
            ans = ans ^ (b - 1) ^ b
        elif b % 4 == 2:
            ans = ans ^ (b - 2) ^ (b - 1) ^ b
        else:
            ans = ans ^ (b - 3) ^ (b - 2) ^ (b - 1) ^ b
        print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
    static void Main()
    {
#if DEBUG
        string exampleInput =
        @"50000 700000 40000000000
";
        Console.SetIn(new System.IO.StringReader(exampleInput));
#endif

        var ABN = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        var A = ABN[0];
        var B = ABN[1];
        var N = ABN[2];
        var rmax = A * N / B - A * (N / B);
        if(N >= B)
        {
            var kmax = (N + 1) / B;
            
            for (long k = kmax; k >= Math.Max(1, kmax - 10000); k--)
            {
                var x = k * B - 1;
                var r = A * x / B - A * (x / B);
                rmax = Math.Max(rmax, r);
            }
        }
        Console.WriteLine(rmax);
        Console.Out.Flush();
    }
}

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

int main() {
    int N, count=1, maxNum=0;
    cin >> N;
    vector<string> S(N);
    vector<pair<int, string>> ans;
    pair<int, string> tmp;
    for(int i=0; i<N; i++){
	cin >> S[i];
    }
    sort(S.begin(), S.end());

    for(int i=0; i<N-1; i++){
	if(S[i]==S[i+1])
	    count++;
	else{
	    maxNum = max(count, maxNum);
	    tmp.first=count;
	    tmp.second=S[i];	    
	    ans.push_back(tmp);
	    count=1;
	}
    }

    if(ans.empty()||ans[ans.size()-1].second != S[N-1]){
	maxNum = max(count, maxNum);
	tmp.first=count;
	tmp.second=S[N-1];	    
	ans.push_back(tmp);
    }
    sort(ans.begin(), ans.end());

    for(auto i: ans){
	if(maxNum==i.first)
	    cout << i.second << endl;
    }

}


Measured memory_bytes: 18676
#include<bits/stdc++.h>
using namespace std;
struct Node
{
    int x,y;
}s[100005];
bool cmp(Node a,Node b)
{
   if(a.x==b.x)return a.y<b.y;
   return a.x<b.x;
}
int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>s[i].x>>s[i].y;
    sort(s,s+n,cmp);
    priority_queue<int>que;
    int pos=0;
    int ans=0;
    for(int i=1;i<=k;i++)
    {
        while(pos<n&&s[pos].x<=i)
        {
            que.push(s[pos].y);
            pos++;
        }
        if(!que.empty())
        {
            ans+=que.top();
            que.pop();
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll a, b;
ll f(ll x) {
    return (a*x)/b - a*(x/b);
}
int main() {
    ll n;
    cin >> a >> b >> n;
    cout << f(min(n, b-1));
}


Measured memory_bytes: 3592