akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8

n = input()
k = input()

x = map(int, raw_input().split())
t = 0

for d in x:
    d_z = abs(d)
    d_k = abs(k-d)
    if d_z > d_k:
        t += d_k * 2
    else:
        t += d_z * 2

print t


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

//選択ソート(0オリジン)　
int selectionSort(int A[], int N) {
    int i, j, t, sw = 0, minj;
    for (i=0; i<N-1; i++) {
        minj = i;
        for (j=i; j<N; j++) {
            if (A[j] < A[minj]) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if (i != minj) sw++;//操作を行ったら
    } 
    return sw;
}
int main() {
    int A[100], N, i, sw;

    cin >> N;
    for (i=0; i<N; i++) cin >> A[i];

    sw = selectionSort(A, N);

    for (i=0; i<N; i++) {
        if (i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}



Measured memory_bytes: 3088
def actual(n):
    return len([i for i in range(1, n + 1) if len(str(i)) % 2 == 1])

    # nums = [i for i in range(1, n+1)]
    # return len([n for n in nums if len(str(n)) % 2 == 1])

n = int(input())
print(actual(n))

Measured memory_bytes: 6720
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int x = 0; x <= K; ++x){
        for(int y = 0; y <= K; ++y){
            int z = S - x - y;
            if(0 <= z and z <= K){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int r,D,x;
    long long temp;
    cin>>r>>D>>x;

    for(int i=0;i<10;i++){
        temp=r*x-D;
        cout <<temp<<endl;
        x=temp;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        S=list(input().rstrip())
        n=3
        for i in range(2**n):
            sum=int(S[0])
            for j in range(n):
                if((i>>j)&1):
                    sum+=int(S[j+1])
                else:
                    sum-=int(S[j+1])
            if(sum==7):
                ans=(S[0]+str((i>>0)&1).replace("1","+").replace("0","-")+S[1]
                +str((i>>1)&1).replace("1","+").replace("0","-")+S[2]+str((i>>2)&1).replace("1","+").replace("0","-")+S[3]
                +"="+str(sum))
                print(ans)
                return
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1222"""
        output = """1+2+2+2=7"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """0290"""
        output = """0-2+9+0=7"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3242"""
        output = """3+2+4-2=7"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 5640
#include <stdio.h>

int main(void) {
    int a;
    int b;
    int c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    if(a < b){
        if(b < c){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
        
    }
	return 0;
}



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

#define ll  long long


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string  s;
    int q;
    cin>>s;
    cin>>q;
    
    bool st=0;
    vector<char> v[2];
    for(int i=0;i<q;i++){
        int t;
        cin>>t;
        if(t==1){
            //reverse(ans.begin(),ans.end());
            st=!st;
        }else if(t==2){
            int f;
            char c;

            cin>>f>>c;
            --f;
            v[f^st].push_back(c);
        }
    }
    string ans;
    for(int i=(int)v[0].size()-1;~i;--i)
        ans+=v[0][i];
    ans+=s;

    for(char c: v[1])
        ans+=c;
    if(st)
        reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1448
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> dp(n);
	dp[0] = max(0LL, a[0]); dp[1] = max(0LL, a[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = dp[i - 2] + max(0LL, a[i]);
	}
	vector<int> use;
	vector<bool> us(n);
	int s = n - 2;
	if (dp[n - 2] < dp[n - 1]) s = n - 1;
	for (int i = s % 2; i < n; i += 2) {
		if (a[i] > 0) {
			use.pb(i);
			us[i] = true;
		}
	}
	vector<int> ans;
	int u = use.size();
	if (u == 0) {
		int val = -INF;
		int idx = 0;
		rep(i, n) {
			if (chmax(val, a[i])) idx = i;
		}
		cout << val << endl;
		cout << n - 1 << endl;
		for (int i = n; i >= idx + 2; i--) cout << i << endl;
		rep(i, idx) cout << 1 << endl;
		return 0;
	}
	for (int i = n - 1; i >= 0; i--) {
		if (!us[i]) {
			ans.pb(i + 1);
		}
		else {
			break;
		}
	}
	for (int i = u - 1; i >= 1; i--) {
		for (int j = (use[i] + use[i - 1]) / 2; j > use[i - 1]; j--) {
			ans.pb(j + 1);
		}
	}
	for (int i = 0; i < use[0]; i++) ans.pb(1);
	cout << max(dp[n - 2], dp[n - 1]) << endl;
	cout << ans.size() << endl;
	for (int i : ans) cout << i << endl;
} 

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

int main() {
    int n,m;
    while (cin >> n >> m)
    {
        if(n==0) break;
        vector<int> a(n);
        int ans=0;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a.begin(), a.end());

        for (int i = 0; i < n-1; i++)
        {
            for (int j = i+1; j < n; j++)
            {
                if (a[i]+a[j]>m) break;
                ans=max(ans,a[i]+a[j]);
            }
        }
        if(ans==0){
            cout << "NONE" << endl;
        }else{
            cout << ans << endl;
        }
    }
}
//g++ -o a.exe a.cpp


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999999
#define MOD 1000000007 

void func()
{
    ll x,n;
    cin>>x>>n;
    set<ll> s;
    loop(i,0,n){
        ll t;
        cin>>t;
        s.insert(t);
    }
    ll ans=x,m=10000;
    loop(i,-10,111){
        if(s.count(i)==0){
            if(abs(i-x)<m){
                m=abs(i-x);
                ans=i;
            }
        }
    }
    cout<<ans<<"\n";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

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

int main(){
  string s,t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  
  if(s<t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    set<string> all_substr;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            all_substr.insert(s.substr(i, j));
        }
    }
    auto itr = all_substr.begin();
    for (int i = 1; i < k; i++) {
        itr++;
    }
    cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define sort stable_sort 
using namespace std;

int _;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const long long INF=1e9+50;

int n;
long long ans;
pair<long long,long long> lu,ru,ld,rd;

inline long long Manhattan(long long a,long long b)
{
	long long ax=a/INF,ay=a%INF,bx=b/INF,by=b%INF;
	return abs(ax-bx)+abs(ay-by);
}

int main()
{	
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	lu.first=2e10;
	ru.first=2e10;
	ld.first=2e10;
	rd.first=2e10;
	for(int i=0;i<n;i++)
	{
		long long x,y;
		scanf("%d%d",&x,&y);
		if(x+y<lu.first)
		{
			lu.first=x+y;
			lu.second=x*INF+y;
		}
		if(x+(long long)1e9-y<ru.first)
		{
			ru.first=x+(long long)1e9-y;
			ru.second=x*INF+y;
		}
		if((long long)1e9-x+y<ld.first)
		{
			ld.first=(long long)1e9-x+y;
			ld.second=x*INF+y;
		}
		if((long long)1e9-x+(long long)1e9-y<rd.first)
		{
			rd.first=(long long)1e9-x+(long long)1e9-y;
			rd.second=x*INF+y;
		}
	}
	long long a[4]={lu.second,ru.second,ld.second,rd.second};
	for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
		{
			if(i == j)
				continue;
			ans=max(Manhattan(a[i],a[j]),ans);
		} 
	printf("%lld",ans);
	return 0;
}   	         

Measured memory_bytes: 3824
class Vector:


    def __init__(self):
        self.a = []

    def pushBack(self, x):
        self.a.append(x)

    def randomAccess(self, p):
        print(self.a[p])

    def popBack(self):
        self.a = self.a[:-1]


v = Vector()

n = int(input())
for i in range(n):
    q_str =  input().split()
    q = int(q_str[0])
    if q == 0:
        v.pushBack(int(q_str[1]))
    elif q  == 1:
        v.randomAccess(int(q_str[1]))
    else:
        v.popBack()



Measured memory_bytes: 13368
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int N;
    long long MOD = 1000000007;

    cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    for(int i=0;i<N;i++){
        cin >> A.at(i);
        sum += A.at(i);
        sum %= MOD;
    }

    long long res = 0;
    for(int i=0;i<N;i++){
        sum -= A.at(i);
        if(sum<0) sum += MOD;
        res += A.at(i) * sum;
        res %= MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 4832
using static System.Math;
using static System.Console;
class 予選CのD問題
{
	const int 無限 = 1000000007;
	const int 種類 = 26;
	static void Main() => WriteLine(分割(ReadLine()));
	static int 分割(string 文字列)
	{
		var 長さ = 文字列.Length;
		var 状態 = new int[長さ + 1];
		for (var あ = 0; あ < 長さ; あ++) 状態[あ + 1] = 状態[あ] ^ (1 << (文字列[あ] - 'a'));
		var 和 = 0;
		for (var 種 = 0; 種 < 種類; 種++) if ((状態[長さ] & (1 << 種)) != 0) 和++;
		if (和 <= 1) return 1;
		var 分割数 = new int[長さ + 1];
		var 一覧 = new int[1 << 種類];
		for (var あ = 1; あ <= 長さ; あ++) 分割数[あ] = 無限;
		for (var 状 = 1; 状 < (1 << 種類); 状++) 一覧[状] = 無限;
		for (var あ = 1; あ <= 長さ; あ++)
		{
			for (var 種 = 0; 種 < 種類; 種++) 分割数[あ] = Min(分割数[あ], 一覧[状態[あ] ^ (1 << 種)] + 1);
			一覧[状態[あ]] = Min(一覧[状態[あ]], 分割数[あ]);
		}
		return 分割数[長さ];
	}
}


Measured memory_bytes: 275424
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}

template<typename T>
class CumulativeSum{
public:
  Int n;
  vector<T> sum;
  vector<T> A;
  Int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(Int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(Int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(Int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(Int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(Int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  void add(Int l, Int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(Int l,Int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n;
  cin>>n;
  string s;
  cin>>s;

  CumulativeSum <Int> M(n);
  CumulativeSum <Int> C(n);
  CumulativeSum <Int> MC(n);
  Int sum = 0;
  for(Int i=0;i<n;i++){
    if(s[i] == 'M') sum++, M.add(i, i+1, 1);
    if(s[i] == 'C') MC.add(i, i+1, sum), C.add(i, i+1, 1);
  }
  
  Int Q;
  cin>>Q;

  for(Int i=0;i<Q;i++){
    Int k;
    cin>>k;
    Int ans = 0;
    for(Int j=0;j<n;j++){
      if(s[j] != 'D') continue;
      Int a = MC.get(j, min(n, j+k));
      Int b = M.get(0, j) * C.get(j, min(n, j+k));
      ans += a - b;
    }
    cout<<ans<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 48412
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;
using namespace __gnu_pbds;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "  ";
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll n;
    cin>>n;
    if(n==1){
        cout<<0;
        return 0;
    }
    ll ans = 0;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll k = n/i;
            if((n/k)==(n%k)){
                ans += k;
            }
            k++;
            if((n/k)==(n%k)){
                ans += k;
            }
            k-=2;
            if((n/k)==(n%k)){
                ans += k;
            }
        }
    }
    cout<<ans;
    return 0;
}






Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def dfs(cur):
  if dp[cur]!=-1:
    return dp[cur]
  res=0
  for nx in G[cur]:
    res=max(res,dfs(nx)+1)
  dp[cur]=res
  return res

n,m=map(int,input().split())
G=[[] for i in range(n)]
for i in range(m):
  x,y=map(int,input().split())
  G[x-1].append(y-1)

dp=[-1]*n
for i in range(n):
  dp[i]=max(dp[i],dfs(i))
print(max(dp))


Measured memory_bytes: 134732
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
S = list(input())

tmp = S.count("#")
tmp2 = len(S) - tmp
num = [0]*N
num_sharp = 0
num_peri = 0
for i in range(len(S)):
	if S[i] == "#":
		num_sharp += 1
	else:
		num_peri += 1
	num[i] = num_sharp + tmp2-num_peri

print(min(tmp2, min(num)))

Measured memory_bytes: 14732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int ara[3][3];
    bool is[101];
    memset(is,false,sizeof(is));
    for(int i =0; i < 3;i++)
    {
        for(int j = 0; j < 3;j++)
        {
            cin >> ara[i][j];
        }
    }
    int n,x;
    cin >> n;
    for(int i =0; i < n;i++)
    {
        cin >> x;
        is[x] = true;
    }
    for(int i =0; i < 3;i++)
    {
        for(int j = 0; j < 3;j++)
        {
            if(is[ara[i][j]])
            {
                ara[i][j] = 0;
            }
        }
    }
    int f = 1;
    for(int i =0; i < 3;i++)
    {
        f = 1;
        for(int j =0; j <3;j++)
        {
            if(ara[i][j] != 0)
            {
                f = 0;
                break;
            }
        }
        if(f == 1)
        {
            break;
        }
    }
    if(f == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        for(int i =0; i < 3;i++)
        {
            f = 1;
            for(int j =0; j <3;j++)
            {
                if(ara[j][i] != 0)
                {
                    f = 0;
                    break;
                }
            }
            if(f == 1)
            {
                break;
            }
        }
        if(f == 1)
        {
            cout << "Yes" << endl;
        }
        else
        {
            if((!ara[0][0] && !ara[1][1] && !ara[2][2]) || (!ara[0][2] && !ara[1][1] && !ara[2][0]))
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }

        }
    }


}






Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int M=1e7+5,N=8e4+5;

typedef long long LL;

typedef double db;

int n,h[N],e[M],nxt[M],tot,Top,st[N],low[N],dfn[N],a[N][2],Id[N][2],pd[N],p[N],l,r,mid,m,sum,rt,L[N],R[N],b[N],cou;

bool vis[N],bz[N];

struct Data
{
	int Id,x;
}A[N];

bool operator < (Data a,Data b)
{
	return a.x<b.x;
}

char c;

int read()
{
	int x=0,sig=1;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}

void Init(int l,int r,int &x)
{
	x=++m;
	if (l==r) return;
	int mid=l+r>>1;
	Init(l,mid,L[x]); Init(mid+1,r,R[x]);
}

void Add(int x,int y)
{
	e[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
}

void link1(int l,int r,int Id,int p,int q,int x)
{
	if (l==p && r==q)
	{
		Add(Id,x); return;
	}
	int mid=l+r>>1;
	if (q<=mid) link1(l,mid,Id,p,q,L[x]);
	else if (p>mid) link1(mid+1,r,Id,p,q,R[x]);else
	{
		link1(l,mid,Id,p,mid,L[x]); link1(mid+1,r,Id,mid+1,q,R[x]);
	}
}

void link2(int l,int r,int v,int x)
{
	if (l==r)
	{
		Add(x,v); return;
	}
	int mid=l+r>>1;
	if (v<=mid) link2(l,mid,v,L[x]);else link2(mid+1,r,v,R[x]);
}

void link3(int l,int r,int x)
{
	if (l==r) return;
	int mid=l+r>>1;
	Add(x,L[x]); Add(x,R[x]);
	link3(l,mid,L[x]); link3(mid+1,r,R[x]);
}

void dfs(int x)
{
	vis[x]=bz[x]=1; st[++Top]=x;
	dfn[x]=low[x]=++tot;
	for (int i=h[x];i;i=nxt[i])
	{
		if (!vis[e[i]])
		{
			dfs(e[i]); low[x]=min(low[x],low[e[i]]);
		}else if (bz[e[i]]) low[x]=min(low[x],low[e[i]]);
	}
	if (dfn[x]==low[x])
	{
		for (sum++;st[Top+1]!=x;p[st[Top--]]=sum) bz[st[Top]]=0;
	}
}

bool check(int len)
{
	memset(h,0,sizeof(h));
	tot=0;
	for (int i=1;i<=n;i++)
	{
		Add(Id[i][0],Id[i][1]+2*n); Add(Id[i][1],Id[i][0]+2*n);
		Add(Id[i][0]+2*n,Id[i][1]); Add(Id[i][1]+2*n,Id[i][0]);
		for (int j=0;j<2;j++)
		{
			int l,r,mid;
			for (l=1,r=Id[i][j],mid=l+r>>1;l<r;mid=l+r>>1)
				if (A[mid].x>a[i][j]-len) r=mid;else l=mid+1;
			if (l<Id[i][j]) link1(1,2*n,Id[i][j]+2*n,l,Id[i][j]-1,rt);
			for (l=Id[i][j],r=2*n,mid=l+r>>1;l<r;mid=l+r>>1)
				if (A[mid].x<a[i][j]+len) l=mid+1;else r=mid;
			if (A[r].x>=a[i][j]+len) r--;
			if (Id[i][j]<r) link1(1,2*n,Id[i][j]+2*n,Id[i][j]+1,r,rt);
			link2(1,2*n,Id[i][j],rt);
		}
	}
	link3(1,2*n,rt);
	tot=Top=sum=0;
	memset(vis,0,sizeof(vis));
	for (int i=1;i<=m;i++) if (!vis[i]) dfs(i);
	for (int i=1;i<=2*n;i++) if (p[i]==p[i+2*n]) return 0;
	return 1;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		a[i][0]=read(); a[i][1]=read();
		A[++m].Id=i*2; A[m].x=a[i][0]; A[++m].Id=i*2+1; A[m].x=a[i][1];
	}
	sort(A+1,A+m+1);
	for (int i=1;i<=m;i++) Id[A[i].Id>>1][A[i].Id&1]=i;
	m*=2;
	Init(1,2*n,rt);
	r=1e9;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++) if (i!=j)
		{
			r=min(r,max(max(abs(a[i][0]-a[j][0]),abs(a[i][0]-a[j][1])),max(abs(a[i][1]-a[j][0]),abs(a[i][1]-a[j][1]))));
		}
	}
	for (l=1,mid=r>>1;l<r;mid=l+r>>1)
	{
		if (check(mid)) l=mid+1;else r=mid;
	}
	if (!check(l)) l--;
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 11392
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 105;

int n;
int arr[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>n;
    int a = 0, b = 0;
    REP(i,1,n){
        cin>>arr[i];
        b += arr[i];
    }
    int ans = b-a;
    REP(i,1,n){
        a += arr[i];
        b -= arr[i];
        ans = min(ans, abs(a - b));
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    vector<int> e(3, 0);
    for(auto& val: e)
        cin >> val;
    sort(e.begin(), e.end() );
    cout << (e[0] * e[1] / 2) << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int ans = 1, a[10], n, sum = 0, ma = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ma *= 3;
		if (a[i] % 2 == 0) {
			ans *= 2;
		}
	}
	cout << ma - ans << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
/*input
5
2 3 2 1 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int n;
int mid;
int a[maxn];

vector<pii> v;

void add(int u){
	if(SZ(v)&&v.back().F==u){
		v.back().S++;

		if(v.back().S==mid){
			pii meow=v.back();
			v.pop_back();
			if(u>-2) add(u-1);
		}

	}
	else if(mid==1){
		v.pb(MP(-1,1));
	}
	else{
		v.pb(MP(u,1));
	}
}

bool check(){
	//cout<<"===\n";
	v.clear();
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) continue;

		while(SZ(v)&&v.back().F>=a[i]) v.pop_back();

		add(a[i]-1);

		//for(auto i:v) cout<<i<<' ';
		//	cout<<'\n';
	}
	//cout<<"===\n";
	if(SZ(v)&&v[0].F<0) return 0;
	return 1;
}


int main()
{
	IOS;
	cin>>n;
	REP(i,n) cin>>a[i];
	


	int l=0,r=maxn;
	while(l!=r-1){
		mid=l+r>>1;
		if(check()) r=mid;
		else l=mid;
	}
	cout<<r<<'\n';
	return 0;
}


Measured memory_bytes: 3188
counter = 0

n = input()
n = n.lower()

while True:
    m = input()
    if m == "END_OF_TEXT":
        break
    else:
        m = list(m.split())
        for i in m:
            i = i.lower()
            if n == i:
                
                counter += 1
            else:
                pass

print(counter)


Measured memory_bytes: 5556
r, c = map(int, input().split())
table = []
for i in range(r):
    table.append(list(map(int, input().split())))
    table[i].append(sum(table[i]))
    print(*table[i])
print(*[sum([table[i][j] for i in range(r)]) for j in range(c + 1)])


Measured memory_bytes: 5720
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
	int N;
	string s;
	cin>>N>>s;
	ll ans = INF;
	ll preans[300000]={};

	for(int i=0;i<N;i++){
		if(s[i] == '.') preans[0]++;
	}
	ans = min(preans[0],ans);
	for(int i=1;i<=N;i++){
		if(s[i-1] == '.') preans[i] = preans[i-1] - 1;
		else preans[i] = preans[i-1] + 1;
		ans = min(preans[i],ans);
			}
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2948
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int h,w,n,x,y;
	cin>>h>>w>>n;cin>>x>>y;
	string s,t;
	cin>>s;cin>>t;
	reverse(All(s));reverse(All(t));
	int lx=1,hx=h,ly=1,hy=w;
	rep(i,n){
		if(i>0){
			if(t[i]=='U') hx=min(h,hx+1);
			if(t[i]=='D') lx=max(1,lx-1);
			if(t[i]=='L') hy=min(w,hy+1);
			if(t[i]=='R') ly=max(1,ly-1);
		}
		//cout<<lx<<hx<<ly<<hy<<endl;
		if(s[i]=='D') hx--;
		if(s[i]=='U') lx++;
		if(s[i]=='R') hy--;
		if(s[i]=='L') ly++;
		//cout<<lx<<hx<<ly<<hy<<endl;
		if(hx<lx || hy<ly){
			cout<<"NO"<<endl;return 0;
		}
	}
	if(lx<=x && x<=hx && ly<=y && y<=hy){
		cout<<"YES"<<endl;
	}
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 776
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const tmp = readln.split.to!(int[]);
    const N = tmp[0], M = tmp[1];
    auto res = new int[M];
    foreach (i; 0..N) {
        auto input = readln.split.to!(int[]);
        input[1..$].each!(a => res[a-1]++);
    }
    res.count!(r => r == N).writeln;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
    int A;
    int B;

    scanf("%d", &A);
    scanf("%d", &B);

    if(1 > B || B > 16 || 1 > A || A > 16 || (A + B) > 16) {
        exit(0);
    }

    if(A <= 8 && B <= 8) {
        printf("Yay!\n");
    } else {
        printf(":(\n");
    }
    return 0;
}

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

int cnth[1500010], cntw[1500010];

int main()
{
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;

        vector<int> cnth(n * 1000 + 10, 0);
        vector<int> cntw(m * 1000 + 10, 0);
        vector<int> sumh(n + 1, 0);
        vector<int> sumw(m + 1, 0);
        for (int i = 1; i <= n; ++i) {
            int a;
            cin >> a;
            sumh[i] = sumh[i - 1] + a;
            for (int j = 0; j < i; ++j)
                ++cnth[sumh[i] - sumh[j]];
        }
        for (int i = 1; i <= m; ++i) {
            int a;
            cin >> a;
            sumw[i] = sumw[i - 1] + a;
            for (int j = 0; j < i; ++j)
                ++cntw[sumw[i] - sumw[j]];
        }
        int lim = min(n, m) * 1000 + 10;
        long long ans = 0;
        for (int i = 1; i < lim; ++i) {
            ans += cnth[i] * cntw[i];
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 14688
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    f = [True]*n
    cnt = 0
    ans = -1
    x = 0
    while f[x]:
        f[x] = False
        cnt += 1
        x = a[x] - 1
        if cnt == k:
            ans = x+1
            break
    if ans != -1:
        print(ans)
    else:
        k -= cnt
        y = a[x] - 1
        tmp = [x]
        while y != x:
            tmp.append(y)
            y = a[y] - 1
        print(tmp[k%(len(tmp))] + 1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 32364
/** author: __nishad__ **/

#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int a, b, c, k, sum=0, temp=0;
    vll v;

    cin>>a>>b>>c>>k;
    v.pb(a);
    v.pb(b);
    v.pb(c);

    int mx = maxv(v);

    for(int i=0; i<v.size(); i++){
        if(v[i] == mx){
            for(int j=0; j<k; j++){
                mx=mx*2;
            }
            sum = sum + mx;
        }
        else
            sum = sum + v[i];
    }

    cout<<sum;


}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> P(n);
    for(int i=0;i<n;i++) cin >> P[i];
    vector<double> cum(n);
    cum[0]=((double)P[0]+1)/2;
    for(int i=1;i<n;i++){
        cum[i]=cum[i-1]+((double)P[i]+1)/2;
    }
    double ans=cum[k-1];
    for(int i=k;i<n;i++){
        double tmp=cum[i]-cum[i-k];
        ans=max(ans,tmp);
    }
    printf("%.12f\n",ans);
}

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

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

    vector<long long> S(N + 1, 0);
    for(int i=0; i<N; ++i) {
        cin >> S[i + 1];
        S[i + 1] += S[i];
    }

    long long res = 0;
    map<long long, int> cnt;
    cnt[0] = 1;
    for(int i=1; i<=N; ++i) {
        if(i >= K) cnt[(S[i - K] - (i - K)) % K] -= 1;
        res += cnt[(S[i] - i) % K];
        cnt[(S[i] - i) % K] += 1;
    }
    cout << res << endl;
}

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

long long gcd(long long a, long long b)
{
    if (a%b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a%b));
    }
}

int main() {
    int N;cin >> N;
    vector<ll> A(N);
    for (int i = 0;i < N;i++){
        cin >> A[i];
    }
    vector<int> X(N);vector<int> Y(N);
    X[0] = A[0];Y[N - 1] = A[N - 1];
    for (int i = 1;i < N;i++){
        X[i] = gcd(X[i - 1],A[i]);Y[N - 1 - i] = gcd(Y[N - i],A[N - 1 - i]);
    }
    ll res = max(X[N - 2],Y[1]);
    for (int i = 1;i < N - 1;i++){
        ll l = X[i - 1];
        ll r = Y[i + 1];
        res = max(res,gcd(l,r));
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
function Main(input) {
	  var inputs = input.split(' ');
	  var K = Number(inputs[0]);
	  var S = Number(inputs[1]);
	  var count = 0;
	  for(var X = 0; X <= K; X++) {
	    for(var Y = 0; Y <= K; Y++) {
	      var Z = (S - X - Y);
	      if(0 <= Z && Z <= K) {
	        count++;
	      }
	    }
	  }
	  console.log(count);
	}

	Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	like := make([]int, m)
	for i := 0; i < n; i++ {
		k := nextInt()
		for i := 0; i < k; i++ {
			like[nextInt()-1]++
		}
	}
	ans := 0
	for i := range like {
		if like[i] == n {
			ans++
		}
	}
	puts(ans)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let mut s = vec![a, b].into_iter().collect::<HashSet<_>>();
    for i in 1..4 {
        if !s.contains(&i) {
            println!("{}", i);
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int n ,m;
int s[100005];
int q[50005];
bool search(int x)
{
	int t = lower_bound(s,s+n,x) - s;
	if(s[t] == x) return true;
	else return false;
}
int main()
{
	int sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i ++)
		scanf("%d",&s[i]);
	scanf("%d",&m);
	for(int i = 0; i < m; i ++)
	{
		scanf("%d",&q[i]);
		if( search(q[i]) ) sum ++;
	}
	printf("%d\n",sum);
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

int32 N, M, C;
vector<int32> num;
int main(void){
	cin >> N >> M >> C;
	num.resize(C);
	REP(i, C) cin >> num[i];
	vector<PLL> luz;
	REP(i, N){
		int64 c, w;
		cin >> c >> w;
		luz.push_back(PLL(w, c-1));
	}
	sort(all(luz), greater<PLL>());
	int64 res = 0;
	REP(i, luz.size()){
		if(M > 0 && num[luz[i].sc] > 0){
			M--;
			num[luz[i].sc]--;
			res += luz[i].fs;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 5584
n,m = map(int,input().split())
if m == n-1:
  print(0)
  exit()
if 2*(n-m-1) > n:
    print("Impossible")
    exit()

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]

u = Unionfind(n)
a = list(map(int,input().split()))
for i in range(m):
    x,y = map(int,input().split())
    u.union(x,y)
count = 2*(n-m-1)
l = [[] for i in range(n)]
for i in range(n):
    x = u.find(i)
    if x < 0:
        l[i].append(a[i])
    else:
        l[x].append(a[i])

ans = 0
h = []
for i in range(n):
    if l[i]:
        l[i].sort()
        ans += l[i][0]
        count -= 1
        for j in l[i][1:]:
            h.append(j)
h.sort()
ans += sum(h[:count])
print(ans)


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

using namespace std;

int main()
{
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a<=k){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }
      return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n;
    cin >> n;
    ll res = 1;
    for (int i = 1; i <= n; ++i) {
        res = (res * i) % mod;
    }
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a, b, c, d, e, k;
  
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
  if(e - a <= k)  printf("Yay!\n");
  else printf(":(\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    if(N % 2 == 0) {
        string T1 = S.substr(0, N / 2);
        if(S.compare(T1 + T1) == 0) {
            cout << "Yes\n";
        } else cout << "No\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>

using namespace std;


int main() {

  int n;
  string buf;

  string word[300];
  string n_word[300];

  char* tp;
  int idx;
  bool flag;

  cin >> n;

  getline(cin,buf);

  for(int i=0;i<n;i++) {

    getline(cin,buf);

    idx=0;

    tp=strtok((char*)buf.c_str()," ");

    for(int j=0;tp!=NULL;j++) {

      word[j]=tp;

      idx++;
      //cout << word[j] << " ";
      tp=strtok(NULL," ");

    }

    //cout << word[2][1] << " " << word[0].size();

    flag=false;

    for(int i=0;i<26;i++) {

      if(i%2==0 || i==13) continue;

      else {

	for(int j=0;j<26;j++) {

	  for(int k=0;k<idx;k++) n_word[k]="";

	  for(int k=0;k<idx;k++) {

	    for(int l=0;l<word[k].size();l++) {

	      n_word[k]+=(i*(word[k][l]-'a')+j)%26+'a';

	    }

	    if(n_word[k]=="this" || n_word[k]=="that") {

	      flag=true;

	    }

	  }

	  if(flag==true) goto Next;

	}

      }

    }

  Next:
    for(int i=0;i<idx;i++) {

      if(i==0) cout << n_word[i];
      
      else cout << " " << n_word[i];

    }

    cout << endl;

  }      

  return 0;

}
    

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

using ll = long long;
#define DEBUG(x) cerr << #x << ": " << x << endl;

ll getDigit(ll x) {
    ll digit = 0;
    while (x > 0) {
        x /= 10;
        digit++;
    }
    return digit;
}

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

    ll Min = 1e13;
    for (ll i = 1; i*i <= N; i++) {
        if (N % i != 0) continue;
        ll tmp = max(getDigit(i), getDigit(N / i));
        Min = min(tmp, Min);
    }

    cout << Min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n , m;
	cin >> n >> m;
	if(n * 2 <= m){
		long long int ans = n;
		m -= n * 2;
		ans += m / 4;
		cout << ans << endl;
	}
	else
		cout << m / 2  << endl;
}

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

double toRad(int deg)
{
	return ((deg / 180.0) * M_PI);
}

int main(void)
{
	int dir = 90;
	int rotate, dist;
	double x, y;
	
	x = y = 0;
	while (scanf("%d,%d", &dist, &rotate), !(dist == 0 && rotate == 0)){
		x += dist * cos(toRad(dir));
		y += dist * sin(toRad(dir));
		dir = (dir - rotate + 360) % 360;
	}
	
	printf("%d\n%d\n", (int)x, (int)y);
	
	return (0);
}

Measured memory_bytes: 604