akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string s;
	cin >> s;
	string res;
	REP(i, s.length()) {
		if (s[i] == 'B') res = res.substr(0, res.length() - 1);
		else res = res + s[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;

  int cnt=0;
  int l=1;
  int r=N;
  vector<bool> used(N,false);
  while(cnt!=M){
    int a=r-l-1;
    int b=(l-1)+(N-r);
    if(a==b)  r--;
    if(used.at(a))  r--;
    used.at(a)=true;
    used.at(b)=true;
    cout << l << " " << r << endl;
    cnt++;
    l++;
    r--;
  }

  return 0;
}

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

int main(){

    int n; cin >> n;
    int m = -1;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        m = max(m, a[i]);
    }

    int d = m / 2;      //11    5       6    3
    //cout << d << endl;
    int ans = a[0];
    int sa = 1000*1000*1000;
    if(m % 2 == 0){
        //dに近いやつ
        for(int i = 0; i < n; i++){
            if(a[i] == m) continue;
            int temp = abs(d - a[i]);
            if(temp < sa){
                sa = temp;
                ans = a[i];
            }
        }
    }else{
        
        for(int i = 0; i < n; i++){
            if(a[i] == m) continue;

            if(a[i] <= d){
               int temp = abs(d - a[i]);
               //cout << temp << endl;
                if(temp < sa){
                    sa = temp;
                    ans = a[i];
                } 
            }else{
                int temp = abs(a[i] - d - 1);
                //cout << temp << endl;
                if(temp < sa){
                    sa = temp;
                    ans = a[i];
                }
            }
        }
    }

    cout << m << " " << ans << endl;
    return 0;
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int memo[10];

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    memo[a] = 1;
    memo[b] = 1;
    memo[c] = 1;
    memo[d] = 1;
    if(memo[1] == 1 && memo[4] == 1 && memo[7] == 1 && memo[9] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

int main(){
  int K;
  int N;
  std::cin >> K >> N;
  std::vector<int> A(N, 0);

  for(int i = 0; i < N; ++i){
    std::cin >> A[i];
  }

  std::vector<int> B(N,0);
  for(int i = 0; i < N-1; ++i){
    B[i] = (A[i+1] - A[i]);
  }
  B[N-1] = K + A[0] - A[N-1];

  for(int i = 0; i < N; ++i){
    if(2 * B[i] > K){
      B[i] = K - B[i];
    }
  }

  std::sort(B.begin(), B.end());
  int min = 0;
  for(int i = 0; i < N-1; ++i){
    min += B[i];
  }

  std::cout << min << std::endl;
  return 0;
}

Measured memory_bytes: 1792
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

isRectangle [a,b,c]
  | a * a + b * b == c * c = "YES"
  | b * b + c * c == a * a = "YES"
  | a * a + c * c == b * b = "YES"
  | otherwise = "NO"

main :: IO ()
main = do
    _ <- getLine
    ns <- fmap (fmap (read :: String -> Integer) . words) . lines <$> getContents
    -- ns <- fmap (fmap (read :: String -> Integer) . words) . lines <$> (return "4 3 5\n4 3 6\n8 8 8")
    forM_ [0..length ns-1] $ \i -> do
      putStrLn $ isRectangle (ns!!i)

Measured memory_bytes: 4468
#include <iostream>
#include <queue>
#include <vector>
#define INF 1000000001
using namespace std;
struct E{
  int rel,cost;
};
vector <E> grh[100000];
int v,e,r;

void dijkstra(){
  priority_queue < pair <int,int> > Q;
  int sum = 0;
  int d[100000];
  for(int i=0;i<v;i++) d[i] = INF;
  d[r] = 0;
  Q.push(make_pair(0,r));
  
  int s,f;
  while(!Q.empty()) {
    f = Q.top().first;
    s = Q.top().second;
    Q.pop();
    
    
    for(int i=0;i<grh[s].size();i++) {
      E e = grh[s][i];
      if(d[e.rel] > e.cost - f) {
	d[e.rel] = e.cost - f;
	Q.push(make_pair(-d[e.rel],e.rel));
      }
    }
  }

  for(int i=0;i<v;i++) {
    if(d[i] == INF ) cout << "INF"<<endl;
    else  cout << d[i] << endl;
  }
}

int main() {

  cin >> v >> e >> r; 
  int a,b,c;
  for(int i=0;i<e;i++) {
    cin >> a >> b>> c;
    grh[a].push_back((E){b,c});
  }
  
  dijkstra();

  return 0;

}	   

Measured memory_bytes: 11304
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

int main()
{
    ll x;
    cin >> x;
    ll p=x/500;
    x-=p*500;
    ll q=x/5;
    cout << 1000*p+5*q << endl;
    return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    cout << (x >= 30 ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 3580
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  int x, A = 0, B = 0, AB = 0, O = 0;
  char b[8];
  while (scanf("%d,%s", &x, b) == 2) {
    if (b[0] == 'A' && b[1] == 'B')
      AB++;
    else if (b[0] == 'A')
      A++;
    else if (b[0] == 'B')
      B++;
    else
      O++;
  }
  printf("%d\n%d\n%d\n%d\n", A, B, AB, O);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	int i,j,k,g,f,n,px,py,sx[11],sy[11],d[11][3][3];
	int dx[12]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2},dy[12]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};
	while(cin >> sx[0] >> sy[0]) {
		if (sx[0]+sy[0]==0) break;
		memset(d,0,sizeof(d));
		cin >> n;
		for (i=1;i<=n;i++) cin >> sx[i] >> sy[i];
        d[0][1][1]=1;
		for (i=0;i<n;i++) {
			f=0;
			for (k=-1;k<2;k++) for (g=-1;g<2;g++) {
                if (d[i][1+k][1+g]==0) continue;
			    for (j=0;j<12;j++) {
				    px=g+sx[i]+dx[j]; py=k+sy[i]+dy[j];
				    if (px<0 || px>9 || py<0 || py>9) continue;
				    if ((sx[i+1]-px)*(sx[i+1]-px)<2 && (sy[i+1]-py)*(sy[i+1]-py)<2) { f=1; d[i+1][py-sy[i+1]+1][px-sx[i+1]+1]=1;}
           		}
			}
            if (f==0) break;
		}
        if (f==1) cout << "OK" << endl; else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 20001;

int G[101][101];
int color[101], d[101], f[101];
int t = 0;

void dfs(int u, int n)
{
	color[u] = 1;
	d[u] = ++t;
	for (int v = 1; v <= n; v++) {
		if (G[u][v] && color[v] == 0)
			dfs(v, n);
	}
	color[u] = 1;
	f[u] = ++t;
}

int main(void)
{
	int n, k, v, u;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int i = 0; i < k; i++) {
			cin >> v;
			G[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (color[i] == 0)
			dfs(i, n);
	}
	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3124
L=[]
while True:
    a=str(input())
    
    if a=="END OF INPUT":
        break
    
    a=a.split(" ")
    L.append(a)
    b=len(a)
    c=L[0]
    
    for i in range(b):
        d=c[i]
        print(len(d),end="")
    L=[]

    print()
    
    



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

namespace AGC008Repainting
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, K;
            string[] vals = Console.ReadLine().Split(' ');
            N = int.Parse(vals[0]);
            K = int.Parse(vals[1]);
            int[] a = new int[N];
            vals = Console.ReadLine().Split(' ');
            for(int i=0; i < N; i++)
            {
                a[i] = int.Parse(vals[i]);
            }

            long[] cuma = new long[N + 1];
            for(int i=1; i <= N; i++)
            {
                cuma[i] = cuma[i - 1] + a[i - 1];
            }

            long[] cumb = new long[N + 1];
            for(int i=1; i <= N; i++)
            {
                cumb[i] = cumb[i - 1];
                if (a[i - 1] > 0)
                    cumb[i] += a[i - 1];
            }

            long maxScore = long.MinValue;
            long s;
            for(int i=0; i <= N - K; i++)
            {
                s = cuma[i + K] - cuma[i];
                if (s < 0)
                    s = 0;
                s += cumb[i] + (cumb[N] - cumb[i + K]);
                if (maxScore < s)
                    maxScore = s;
            }
            Console.WriteLine(maxScore);
        }
    }
}

Measured memory_bytes: 32220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 5e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, m;
	cin >> n >> m;
	int dp[n][m] = {};
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == '#') continue;
			if (i) dp[i][j] += dp[i-1][j];
			if (j) dp[i][j] += dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[n-1][m-1];
	return 0;
}


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

void sort(int array[3])
{
    for (int i = 1; i < 3; ++i)
        for (int j = i; j > 0 && array[j] < array[j-1]; --j)
            std::swap(array[j], array[j-1]);
}

int main()
{
    int array[3];
    for ( int i=0; i<3; ++i) cin >> array[i];
    sort(array);
    
    
    for (int i = 0; i < 3; ++i)
    {
	    std::cout << array[i];
        if (i==2) cout << endl;
        else cout << " ";
	}
	return 0;    
}

Measured memory_bytes: 3080
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        boolean state = true;
        for(int i = 0; i < N; i++){
            if(sc.next().equals("Y")) state = false;
        }
        System.out.println(state ? "Three" : "Four");
    }
}


Measured memory_bytes: 21972
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define INF 100000000000000
using namespace std;

typedef struct _STUDENT_TEST{
    long long middle_test;
    long long last_test;
    long long again_test;
}STUDENT_TEST;

int main() {
    vector<STUDENT_TEST> manager;
    STUDENT_TEST student_test;
    long long m, f, r;
    while(1){
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        student_test.middle_test = m;
        student_test.last_test = f;
        student_test.again_test = r;
        manager.push_back(student_test);
    }
    for(int i=0; i<manager.size(); i++){
        m = manager.at(i).middle_test;
        f = manager.at(i).last_test;
        r = manager.at(i).again_test;
        if(m==-1 || f==-1){
            cout << "F" << endl;
        }else if((m+f)>=80){
            cout << "A" << endl;
        }else if((m+f)>=65 && (m+f)<80){
            cout << "B" << endl;
        }else if((m+f)>=50 && (m+f)<65){
            cout << "C" << endl;
        }else if((m+f)>=30 && (m+f)<50){
            if(r>=50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        }else{
            cout << "F" << endl;
        }
    }
}


Measured memory_bytes: 3168
#define s(X,Y,Z)(t=X,X=Y,Y=t,p=Z?&X:&Y,*p^=7,a)
m,a,b,c,t,r,*p;main(n){while(r=scanf("%d",&n),n){for(a=1,b=2,c=3;n--;scanf(" %c%*s",&t),m=t-76,r+=m%6==0?s(c,b,m):1<m&m<8?s(b,a,m^7):s(c,a,m>0));printf("%d\n",r);}}

Measured memory_bytes: 0
/*
 *       ~ AtCoder  Botay ~
 *        code by kazalika
 */

#include <bits/stdc++.h>

//#pragma GCC optimize("O3")

using namespace std;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int k;
  cin >> k;
  string s;
  cin >> s;
  if (k >= (int) s.size())
    cout << s;
  else
    cout << s.substr(0, k) << "...";

}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i =0; i<N; i+=1) {
    cin>>a[i];
  }
  int A=0;
  for(int i =0; i<N-1; i+=1) {
    for(int j =i+1; j<N; j+=1) {
      A+=a[i]*a[j];
    }
  }
  cout<<A<<endl;
}

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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif
}

#define debug(x)    cerr << #x << ": <" << (x) << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

using ll = long long;
using vi = vector<int>;

int main() {
  ioThings();

  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  int mn = 1e9;
  for (int i = 1; i < 101; i++) {
    int s = 0;
    for (auto& j : a)
      s += (j - i) * (j - i);
    mn = min(mn, s);
  }

  cout << mn;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N;
	cin >> N;
	vector<int> Ai(N+1, 0);
	rep(i, N) cin >> Ai.at(i+1);

	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		if (i % 2 == 1 && Ai[i] % 2 == 1) ans += 1;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(100000)

s=int(input())
seen=set()
a=s
seen.add(a)
idx=1

while True:
    if a%2==0:
        a//=2
    else:
        a=3*a+1
    idx+=1
    if a in seen:
        print(idx)
        exit()
    seen.add(a)

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

int gcd(int x,int y);

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

int gcd(int x,int y){
  if(x < y){
    swap(x,y);
  }
  while(y>0){
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}


Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long a = scan.nextLong();
        long b = scan.nextLong();
        long mod = 1000000007;
        long ans = pow(2, N, mod);
        ans = (ans + mod - 1) % mod;
        long x = COM(N, a, mod);
        long y = COM(N, b, mod);
        ans = (ans + mod - x) % mod;
        ans = (ans + mod - y) % mod;
        System.out.println(ans);
    }

    private long COM(long N, long a, long mod) {
        long Y = 1;
        long X = 1;
        for (long i = N - a + 1; i <= N; i++) {
            X *= i;
            X %= mod;
            Y *= (N - i + 1);
            Y %= mod;
        }
        long Y_1 = pow(Y, mod-2, mod);
        long com = X * Y_1;
        com %= mod;
        return com;
    }

    private long pow(long base, long y, long mod) {
        if (y == 0) {
            return 1;
        }
        if (y % 2 == 1) {
            long z = base * pow(base, y - 1, mod);
            z %= mod;
            return z;
        }
        long z = pow(base,  y / 2, mod);
        z = z * z;
        z %= mod;
        return z;
    }

}


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

#define ll long long
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define MAX 1000000

vector<bool>prime(MAX, true);
vector<ll>fact(MAX);
vector<ll>factinv(MAX);

ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a=(a * a) % MOD;
	}
	return res;
}

void getprime()
{
	for(ll i = 2;i < MAX; i++)
	{
		if(prime[i-1])
		{
			for(ll j = i*i; j < MAX; j += i)
				prime[j-1] = false;
		}
	}
}

void getfact()
{
	fact[0] = 1;
	factinv[0] = 1;
	
	for(ll i = 1; i < MAX; i++)
		fact[i] = (fact[i-1] * i)%MOD;
	
	for(ll i = 1; i < MAX; i++)
		factinv[i] = (factinv[i-1] * fastpower(i, MOD -2) )%MOD;

}

int main()
{
  ll n;
  cin>>n;
  string s;
  cin>>s;
  vector<ll>r(n,0),g(n,0),b(n,0);
  if(s[0]=='R')
    r[0]=1;
  if(s[0]=='G')
    g[0]=1;
  if(s[0]=='B')
    b[0]=1;
  
  for(ll i=1;i<n;i++)
  {
    if(s[i]=='R')
      r[i]=r[i-1]+1;
    else
      r[i]=r[i-1];
    if(s[i]=='G')
      g[i]=g[i-1]+1;
    else
      g[i]=g[i-1];
    if(s[i]=='B')
      b[i]=b[i-1]+1;
    else
      b[i]=b[i-1];
  }
  ll res=0;
  for(ll i=1;i<n;i++)
  {
    if(s[i]=='R')
    {  res += (g[i-1]*(b[n-1]-b[i]));
       res += (b[i-1]*(g[n-1]-g[i]));
    }
    if(s[i]=='G')
    {  res += (r[i-1]*(b[n-1]-b[i]));
       res += (b[i-1]*(r[n-1]-r[i]));
    }
    if(s[i]=='B')
    {  res += (g[i-1]*(r[n-1]-r[i]));
       res += (r[i-1]*(g[n-1]-g[i]));
    }
    
  }
  for(ll i=1;i<n;i++)
  {
    for(ll j=i-1;j>=0;j--)
    {
      if(i+(i-j)<n)
      {
        if(s[i]=='R')
        {
          if((s[j]=='G' && s[i+(i-j)] == 'B') || (s[j]=='B' && s[i+(i-j)] == 'G'))
            res--;
        }
        if(s[i]=='G')
        {
          if((s[j]=='R' && s[i+(i-j)] == 'B') || (s[j]=='B' && s[i+(i-j)] == 'R'))
            res--;
        }
        if(s[i]=='B')
        {
          if((s[j]=='G' && s[i+(i-j)] == 'R') || (s[j]=='R' && s[i+(i-j)] == 'G'))
            res--;
        }
      }
    }
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 18880
#include<iostream>
using namespace std;
int main()
{
  int a,b,x,y;
  cin>>x>>y;
  if(y%2!=0)
    cout<<"No";
  else
  {
  b=((y-2*x)/2);
  a=x-b;
    if(a<0||b<0)
      cout<<"No";
    else
    {
    if(2*a+4*b==y)
      cout<<"Yes";
    else
      cout<<"No";
    }
  }
}
  


Measured memory_bytes: 3132
#!/usr/bin/env python3
A, B = map(int, input().split())
s = {*range(25 * A, 25 * A + 25)} & {*range(20 * B, 20 * B + 20)}
s = {i // 2 for i in s if i % 2 < 1}
print(-1 * (len(s) < 1) or min(s))


Measured memory_bytes: 61968
#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)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> lig(m, vector<int>(n));
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      cin >> lig[i][j];
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;
  vector<int> swi(n+2);
  rep(i, pow(2,n)) {
    rep(j, m) {
      int sig = 0;
      for (int k: lig[j]) {
        sig ^= swi[k];
      }
      if (sig != p[j]) break;
      if (sig == p[j] && j == m-1) ans++;
    }
    swi[1]++;
    rep(j, n+1) {
      if (swi[j] == 2) {
        swi[j] = 0;
        swi[j+1]++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>

#define Pa pair<int,int>

using namespace std;


string bfs(int a[101][101], int sx, int sy, int gx, int gy, int w, int h)
{
	int s, t, m = a[sy][sx];
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
	bool vis[101][101];
	string str = "NG";
	queue<Pa> que;
	Pa pa;
	fill(&vis[1][1], &vis[h][w], true);
	
	que.push(Pa(sy, sx));
	vis[sy][sx] = false;
	
	while(!que.empty()){
		pa = que.front();
		que.pop();
		if(pa.first == gy && pa.second == gx){
			str = "OK";
			break;
		}
		
		for(int i = 0; i < 4; i++){
			s = pa.first + dy[i];
			t = pa.second + dx[i];
			if(1 <= s && s <= h && 1 <= t && t <= w){
				if(vis[s][t] && m == a[s][t]){
					que.push(Pa(s, t));
					vis[s][t] = false;
				}
			}
		}
	}
	
	return str;
}

int main()
{
	int a[101][101], w, h, sx, sy, gx, gy, s, t, u, v, n;
	
	while(1){
		cin >> w >> h;
		if(w == 0 && h == 0){
			break;
		}
		fill(&a[1][1], &a[h][w], 0);
		cin >> sx >> sy;
		cin >> gx >> gy;
		cin >> n;
		
		while(n--){
			cin >> s >> t >> u >> v;
			if(t == 0){
				for(int i = v; i <= v+1; i++){
					for(int j = u; j <= u+3; j++){
						a[i][j] = s;
					}
				}
			} else {
				for(int i = v; i <= v+3; i++){
					for(int j = u; j <= u+1; j++){
						a[i][j] = s;
					}
				}
			}
		}
		
		cout << bfs(a, sx, sy, gx, gy, w, h) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct BIT{
private:
   int sz;
   vector<ll> node;
public:
   BIT(int n):sz(n),node(n+1){};
   void add(int k,ll x){
       k++;
       while(k<=sz){
           node[k]+=x;
           k+=k&-k;
       }
   }
   ll sum(int k){
       k++;
       ll ret=0;
       while(k>0){
           ret+=node[k];
           k-=k&-k;
       }
       return ret;
   }
   ll sum(int l,int r){
       return sum(r-1)-sum(l-1);
   }
   ll get(int k){
       return sum(k,k+1);
   }
};

int main(){
    cout<<fixed<<setprecision(10);
    int n;
    cin>>n;
    double a[n],b[n],c[n];
    rep(i,n)cin>>a[i]>>b[i]>>c[i];
    int ord[n];
    rep(i,n)ord[i]=i;
    sort(ord,ord+n,[&](int x,int y){return -a[y]/b[y]>-a[x]/b[x];});
    int inv[n];
    rep(i,n)inv[ord[i]]=i;
    int ord2[n];
    rep(i,n)ord2[i]=i;
    double d[n];
    rep(j,2){
    double left=-3e8,right=3e8,mid=0;
    rep(k,100){
        mid=(left+right)/2;
        BIT bit(n);
        rep(i,n)d[i]=(-a[i]*mid-c[i])/b[i];
        sort(ord2,ord2+n,[&](int x,int y){return d[x]<d[y];});
        int cnt=0;
        rep(i,n){
            int idx=inv[ord2[i]];
            cnt+=bit.sum(idx);
            bit.add(idx,1);
        }
        if(cnt<=n*(n-1)/4)left=mid;
        else right=mid;
    }
    cout<<-mid<<" ";
    rep(i,n)swap(a[i],b[i]);
    sort(ord,ord+n,[&](int x,int y){return -a[y]/b[y]>-a[x]/b[x];});
    rep(i,n)inv[ord[i]]=i;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2304
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int n;
vector<ll>f; 
ll solve(){
   ll res=0;
   int len=f.size();
   if(len==1)return 0;
   if(len==2)return f[0];
   if(len%2==1){
        int d=(len-1)/2;
        rep(i,d){
           res+=f[i];
           res+=f[i+1];
        };
   }else{
        int d=len/2;
        rep(i,d-1){
          res += f[i];
          res += f[i+1];
        }
       res += f[d-1];
       
   }

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

    cin >> n;
    f.resize(n);
    rep(i,n) { 
        cin>>f[i];
    }
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    cout<< solve() <<endl;
    return 0;
}

Measured memory_bytes: 4776
inputs = input().split()
A = int(inputs[0])
B = int(inputs[1])
M = int(inputs[2])
a = []
b = []
x = []
y = []
c = []
inputs = input().split()
for i in range(A):
    a.append(int(inputs[i]))
inputs = input().split()
for j in range(B):
    b.append(int(inputs[j]))

for i in range(M):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    c.append(int(inputs[2]))
price = min(a) + min(b)
for i in range(M):
    if(a[x[i]-1] + b[y[i]-1] - c[i] < price):
        price = a[x[i]-1] + b[y[i]-1] -  c[i]
print(price)

Measured memory_bytes: 24916
#include <iostream>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll arr[100001];
ll n;
ll dp[100001];
ll solve(int start){
    
    if(start==n) return 0;
    
    if(dp[start]!=-1) return dp[start];
    ll ans = 0;
    
    if(start+1<n) ans = abs(arr[start+1]-arr[start]) + solve(start+1);
    
    if(start+2<n) ans=  min(ans,abs(arr[start+2]-arr[start])+ solve(start+2));
    
    return dp[start] = ans;

}



int main() {

	cin>>n;
	memset(dp,-1,sizeof dp);
	for(ll i=0;i<n;i++) cin>>arr[i];
	ll ans = solve(0);
	cout<<ans;
	return 0;
}

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

int main() {
	int n;cin>>n;
  int sum=0,mx=0,p[n];
  rep(i,n){
    cin>>p[i];
    mx=max(mx,p[i]);
    sum += p[i];
  }
  cout<<sum-mx/2;

}

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

using namespace std;

typedef long long ll;

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

    for (int a = 0; a <= y/10000; a++) {
        for (int b = 0; b <= (y-a*10000)/5000; b++) {
            int z = a*10000 + b*5000 + (n-a-b)*1000;
            if (z == y) {
                cout << a << " " << b << " " << n-a-b << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9+7

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

    int n,a;

    cin >> n;

    int mx = INT_MIN,mn = INT_MAX;

    for(int i = 0;i < n;i++)
    {
        cin >> a;
        mn = min(mn,a);
        mx = max(mx,a);
    }
    cout << mx-mn;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
typedef pair <int,int> pii;
pii arr[300005];
vector <pii> operationsCards;
int psa[300005];
int maxCards[300005];

int binarySearch(int idx){
    int l = 1, r = N+1, m;
    while (r-l > 1){
        m = (l+r)/2;
        if (maxCards[m] >= idx) l = m;
        else r = m;
    }
    if (maxCards[l] < idx) return l-1;
    return l;
}

int main() {
    scanf("%d", &N);
    for (int i=1; i<=N; i++) arr[i].second = i;
    for (int i=1; i<=N; i++){
        int a;
        scanf("%d", &a);
        arr[a].first++;
    }
    sort(arr+1, arr+1+N);
    for (int i=1; i<=N; i++){
        operationsCards.push_back({arr[i].first, arr[i].second});
    }
    for (int i=1; i<=N; i++){
        psa[i] = psa[i-1]+operationsCards[i-1].first;
    }
    for (int operation = 1; operation <= N; operation++){
        int k = lower_bound(operationsCards.begin(), operationsCards.end(), make_pair(operation, 0)) - operationsCards.begin();
        maxCards[operation] = N-k;
        if (k != 0) maxCards[operation] += psa[k]/operation;
    }
    for (int i=1; i<=N; i++){
        printf("%d\n", binarySearch(i));
    }
    return 0;
}

Measured memory_bytes: 9708
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
 
int main () {
	int n;
	cin >> n;
	vector <string> s(n);
	rep(i,n) {cin >> s[i];}
	map <string,int> p;
	int ma =0;
	rep(i,n) {
		p[s[i]]++;
		ma = max(ma, p[s[i]]);
	};
	vector <string> b;
	rep(i,n) {
		if(p[s[i]] == ma) {
			b.push_back(s[i]);
			p[s[i]] =0;
		}
	}
	sort(b.begin(), b.end());
	for (int i =0;i<b.size();i++) {
		cout << b[i] << endl;
	}

}


Measured memory_bytes: 28528
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int s[300010];
char op[300010];
int id[300010];
int n,m;
long long t;
bool cmp1(int a,int b)
{
	int pa,pb;
	if(op[a]=='2')
		pa=((s[a]-t)%m+m)%m;
	else pa=(s[a]+t)%m;
	if(op[b]=='2')
		pb=((s[b]-t)%m+m)%m;
	else pb=(s[b]+t)%m;
	if(pa!=pb)return pa<pb;
	return op[a]=='2';
}
int id2[300010];
bool cmp2(int a,int b)
{
	if(s[a]!=s[b])
		return s[a]<s[b];
	return op[a]=='2';
}
int ans[300010];
int main()
{
	cin>>n>>m>>t;
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>op[i];
		s[i]--;id[i]=id2[i]=i;
	}
	sort(id,id+n,cmp1);
	sort(id2,id2+n,cmp2);
	int pos=0;
	if(op[0]=='2')
	{
		long long x=s[0]-t;
		for(int i=0;i<n;i++)
			if(op[i]=='1')
			{
				long long y=s[i]+t;
				if(s[i]>s[0])y-=m;
				if(y<x)continue;
				pos=(pos+(y-x)/m+1)%n;
			}
		pos=(n-pos)%n;
	}
	else{
		long long x=s[0]+t;
		for(int i=0;i<n;i++)
			if(op[i]=='2')
			{
				long long y=s[i]-t;
				if(s[i]<s[0])y+=m;
				if(y>x)continue;
				pos=(pos+(x-y)/m+1)%n;
			}
	}
	int p=0;
	for(int i=0;i<n;i++)
		if(id2[i]==0)p=i;
	p=(p+pos)%n;
	int q=0;
	for(int i=0;i<n;i++)
		if(id[i]==0)q=i;
	for(int i=0;i<n;i++)
	{
		int j=id[(q+i)%n];
		int x=(q+i)%n,y;
		if(op[j]=='2')
			y=((s[j]-t)%m+m)%m;
		else y=(s[j]+t)%m;
		int z=id2[(p+i)%n];
		ans[z]=y+1;
	}
	for(int i=0;i<n;i++)
	{
		if(ans[i]==m)
		{
			ans[i]=0;
		}
	}
	for(int i=0;i<n;i++)
		printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

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


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

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}
int no = 1, n1;
int recu(int n, int k, int val) {


	if (n == n1) {
		return min(val * 2, val + k);
	}
	return min( recu(n + 1, k, 2 * val), recu(n + 1, k, val + k)              );


}
int digit(int n) {

	int temp = 0;
	while (n) {
		// temp += n % 10;
		n = n / 10;
		temp++;
	}



	return temp;
}

bool check(int a[], int n) {
	for (int i = 0; i < n; ++i)
	{
		/* code */
		if (a[i] % 2)
			return false;
	}
	return true;
}
bool ispalin(int n){


	string  str =to_string(n);
	// cout<<str<<endl;


	for (int i = 0; i < str.size()/2; ++i)
	{
		/* code */
		// watch2(str[i],str[str.size()-i-1]);
		if(str[i]!=str[str.size()-i-1]){
			return false;
		}
	}


	return true;


}

int main() {
	int i,  n, m,k, c = 0, sum = 0;
	c_p_c();
	cin>>n>>k;
	int a[n];
	fo(i,n) cin>>a[i] , k-=a[i],sum++;;
	sort(a,a+n);

	sum+=k/a[0];
	cout<<sum<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	while( cin >> n , n ){
		// pair<int,P> Í (¿,-¯,-üÍ³ê½Ô)
		// char Í`[¼(At@xbg1¶)
		char c[12] = {0};
		vector<pair<int,P> > v;
		
		for(int i=0 ; i < n ; i++ ){
			char t;
			int win=0, lose=0;
			cin >> t;
			c[i] = t;
			for(int j=0 ; j < n-1 ; j++ ){
				int r;
				cin >> r;
				if( r == 0 ){
					win++;
				}else if( r == 1 ){
					lose++;
				}
			}
			// pair<int,P> Í (¿,-¯,-üÍ³ê½Ô)
			P p( -lose , -i );
			pair<int,P> p_(win,p);
			v.push_back( p_ );
		}
		sort( v.rbegin() , v.rend() );
		for(int i=0 ; i < v.size() ; i++ ){
			cout << c[ -v[i].second.second ] << endl;
		}
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>

void swap(int &a, int &b){
    int tmp = a;
    a = b;
    b = tmp;
}

void partition(int *a, int p, int r){
    int x = a[r];
    int i = p - 1;
    for(int j = p; j < r; ++j){
        if(a[j] <= x){
            ++i;
            swap(a[i], a[j]);
        }
    }
    int m = i+1;
    swap(a[m], a[r]);
    for(int j = p; j <= r; ++j){
        if(j != p){
            std::printf(" ");
        }
        if(j == m){
            std::printf("[");
        }
        std::printf("%d", a[j]);
        if(j == m){
            std::printf("]");
        }
    }
    std::printf("\n");
}

int main(){
    int n;
    std::scanf("%d", &n);
    std::vector<int> array(n, 0);

    for(int i = 0; i < n; ++i){
        std::scanf("%d", &array[i]);
    }
    partition(&array[0], 0, n-1);
}


Measured memory_bytes: 2724
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        final int M = Integer.parseInt(sc.next());
        int[] ar = new int[M];
        int ans = 0;
        
        for (int i = 0; i < N; i++) {
            int k = Integer.parseInt(sc.next());
            for (int j = 0; j < k; j++) {
                int index = Integer.parseInt(sc.next());
                ar[index - 1]++;
            }
        }
        for (int i = 0; i < M; i++) {
            if (ar[i] == N) ans++;
        }
        
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M, C;
  cin >> N >> M >> C;

  int B[M];
  int A[N][M];
  for (int i = 0; i < M;i++){
    cin >> B[i];
  }
  for (int i = 0; i < N;i++){
    for (int j = 0; j < M;j++){
      cin >> A[i][j];
    }
  }
    int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    int sum = 0;
    for (int j = 0; j < M; j++)
    {
      sum += B[j] * A[i][j];
    }
    sum += C;
    if(sum>0){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    string s;
    cin >> s;
    if (s == "SUN")
        cout << 7 << endl;
    else if (s == "MON")
        cout << 6 << endl;
    else if (s == "TUE")
        cout << 5 << endl;
    else if (s == "WED")
        cout << 4 << endl;
    else if (s == "THU")
        cout << 3 << endl;
    else if (s == "FRI")
        cout << 2 << endl;
    else if (s == "SAT")
        cout << 1 << endl;
}

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

using namespace std;

typedef long long ll;


int main(){
	char s[400];
	cin >> s;
	if(s[0] == 'S'){
		cout << "Cloudy" << endl;
	}else if(s[0] == 'C'){
		cout <<  "Rainy" << endl;
	}else{
		cout << "Sunny" << endl;
	}
	return 0;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    using ll = long long;
    ll x; cin >> x;

    ll c = 100;
    int year = 0;
    for (year = 0; c < x; year++) {
        c = c + c / 100;
    }

    cout << year << endl;

    return 0;
%>

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

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



int main(){
   int n,m; scanf("%d%d",&n,&m);
   vector<int> a(m); int cnt=0;
   rep(i,0,m){
       scanf("%d",&a[i]);
       if(a[i]&1)cnt++;
   }
   if(m==1){
       printf("%d\n",a[0]);
       if(a[0]==1)printf("1\n1\n");
       else printf("2\n%d 1\n",a[0]-1);
       return 0;
   }
   if(cnt>2){printf("Impossible\n"); return 0;}
   int idx[2],cnt2=cnt;
   rep(i,0,m){
       if(a[i]&1){
           cnt--;
           if(cnt==0)idx[0]=i;
           if(cnt==1)idx[1]=i;
       }
   }
   if(cnt2>=1)swap(a[0],a[idx[0]]);
   if(cnt2==2)swap(a[m-1],a[idx[1]]);
   rep(i,0,m)printf("%d ",a[i]); puts("");
   a[0]--; a[m-1]++; vector<int> b;
   rep(i,0,m)if(a[i]>0)b.push_back(a[i]);
   printf("%d\n",b.size());
   rep(i,0,b.size())printf("%d\n",b[i]);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  for (int c=0; c<=n; c+=4) {
    for (int d=0; d<=n; d+=7) {
      if (c+d==n) {
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;

int main()
{
	lld x = 0,sum = 0;

	cin >> x;

	for(int i = 1; i < INF; i++)
	{
		sum += i;
		if (sum >= x)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}
	

Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split()))

sorted_A = sorted(A, reverse=True)

if N % 2 == 0:
    print(sorted_A[0] + 2*sum(sorted_A[1:N//2]))
elif N == 3:
    print(sorted_A[0] + sorted_A[N // 2])
else:
    print(sorted_A[0] + 2*sum(sorted_A[1:N//2]) + sorted_A[N//2])

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

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

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  string S;
  cin >> S;

  S.replace(0, 4, "2018");

  cout << S << endl;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd


def find_lcm(a, b):
    return a * b // gcd(a, b)


def main():
    number = int(input())
    mods = list(map(int, input().split(" ")))
    be_divided = reduce(find_lcm, mods) - 1
    answer = 0
    for mod in mods:
        answer += be_divided % mod
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5384
#include <iostream>
#include <vector>
#include <iterator>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0; i< (n); i++)
typedef long long ll;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
    }
    int ans = 0;
    int curMin = 1e9;
    rep(i,n){
        curMin = min(curMin, p[i]);
        if(curMin == p[i]) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 1024
import sys

s = ""
for line in sys.stdin:
  s += line
  
char = "abcdefghijklmnopqrstuvwxyz"

for c in char:
  n1 = s.count(c)
  n2 = s.count(c.upper())
  print(c + " : " + str(n1 + n2))


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

int main(){
	int N, sum, count=0;
	int a[210];
	cin >> N;
	for(int i=0; i<N; i++)cin >> a[i];
	while(true){
		sum = 0;
		for(int i=0; i<N; i++)sum += a[i]%2;
		if(sum != 0)break;
		for(int i=0; i<N; i++)a[i] /= 2;
		count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var ans int
	nums := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&nums[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
	ans = ((nums[0] * 10) + nums[1]) + nums[2]
	fmt.Println(ans)
}

Measured memory_bytes: 512
N, M, C = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

cnt = 0
for i in range(N):
    ans = 0
    for j in range(M):
        ans += A[i][j]*B[j]
    ans += C
    if ans > 0:
        cnt += 1
        
print(cnt)

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

using namespace std;

int main()
{
    int N, L, Sum = 0;
    cin >> N;
    vector<int> v;

    for (int i = 0; i < N; i++)
    {
        cin >> L;
        v.push_back(L);
    }

    sort(v.begin(), v.end(), greater<>());

    for (int i = 1; i < v.size(); i++)
    {
        Sum += v[i];
    }

    if (v[0] < Sum)
    {
        cout << "Yes";
    }

    if (v[0] >= Sum)
    {
        cout << "No";
    }
}

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

typedef long long ll;
ll n, ans;
int x, m, dist[100005], p[100005];
ll memo[100005];

ll dp(ll _x, ll prev, ll _n){
    if (_n == 0) return 0;
    if (dist[_x] != -1){
        int cycle_size = dist[prev] - dist[_x] + 1;
        ll cycle_weight = memo[prev] - memo[p[_x]];
        ll tmp = _n / cycle_size * cycle_weight;
        _n %= cycle_size;
        while (_n != 0){
            tmp += _x;
            _x = (_x * _x) % m;
            --_n;
        }
        return tmp;
    }
    else{
        dist[_x] = dist[prev] + 1;
        memo[_x] = memo[prev] + _x;
        p[_x] = prev;
        ll nx = (_x * _x) % m;
        ll tmp = _x + dp(nx, _x, --_n);
        //printf("%lld %lld %lld\n", tmp, memo[_x], _x);
        return tmp;
    }
}

int main(){
    scanf("%lld", &n);
    scanf("%d%d", &x, &m);
    memset(memo, -1, sizeof memo);
    memset(dist, -1, sizeof dist);
    memset(p, -1, sizeof p);
    memo[m] = 0;
    p[x] = m;
    ll ans = dp(x, m, n);
    cout<<ans;
}



Measured memory_bytes: 5288