akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    map<int, int> T;
    int N, M; cin >> N >> M;
    for(int i=0; i<N; i++){
        int K; cin >> K;
        for(int j=0; j<K; j++){
            int A; cin >> A;
            T[A]++;
        }
    }
    
    int ret = 0;
    for(auto m:T){
        if(m.second==N) ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[n];
        int ans=0;
        for(int i=0;i<n;i++)nums[i]=sc.nextInt();
        for(int i=0;i<n-1;i++)if(nums[i]<nums[i+1])ans++;
        System.out.println(ans);
    }
    
}


Measured memory_bytes: 68960
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define trace(x)  cerr << #x << ": " << x << endl;
typedef long long ll;
typedef long double ld;const ll N=1e5+5;
int main()
{
    ll n;cin>>n;
    cout<<ceil((double)n/1000)*1000-n;
}

Measured memory_bytes: 3784
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    int n;
    scanf("%d", &n);
    int i = n % 10;
    switch (i)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        printf("hon\n");
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        printf("pon\n");
        break;
    case 3:
        printf("bon\n");
        break;
    }

    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
long long ans, a;
string s;
bool b = true;
int main(){
    cin >> s;
    for(int i = 0; i < s.size()-1; i++){
        if(s[i] == 'A') a++;
        else if(a && s[i] == 'B' && s[i+1] == 'C'){
            ans += a;
            i++;
        }else a = 0;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;
long long mod(const long long &a)
{
  if (a >= 0)
    return a % 1000000007;
  return 1000000007 - (-a) % 1000000007;
}
int mod(const int &a)
{
  if (a >= 0)
    return a % 1000000007;
  return 1000000007 - (-a) % 1000000007;
}

ll mae[100010]; //1*2*...*i
ll usi[100010]; //i*(i+1)*...*(n-1);
void func()
{
  mae[0] = 1;
  usi[n] = 1;
  for (int i = 0; i < n; i++)
  {
    mae[i + 1] = mod(mae[i] * (i + 1));
  }
  for (int i = 0; i < n; i++)
  {
    usi[n - i - 1] = mod(usi[n - i] * (n - i - 1));
  }
}

int main()
{
  cin >> n;
  VLL ls(n);
  rep(i, n) cin >> ls[i];
  VLL ri(n - 1);
  rep(i, n - 1)
  {
    ri[i] = ls[n - 1] - ls[i];
  }
  func();
  ll ans = 0;
  for (int i = 0; i < n - 1; i++)
  {
    ans += mod(mod(mae[i] * ri[i]) * usi[i + 2]);
  }
  cout << mod(ans) << endl;
}


Measured memory_bytes: 3328
N, K = map(int, input().split())
teleps = list(map(int, input().split()))
teleps.insert(0, 0)
current = 1
routes = []
memory = set([])
roop_count = 0
for _ in range(K):
    # ループ検知する
    if current not in memory:
        memory.add(current)
    else:
        # ループ発見
        index = routes.index(current)
        roop_count = len(routes) - index
        di = (K - index) % roop_count
        current = routes[index+di]
        break
    routes.append(current)
    current = teleps[current]
print(current)

Measured memory_bytes: 32376
s = input()
n = len(s)
i = 0
j = n - 1
res = 0
while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
    else:
        if s[i] == 'x':
            res += 1
            i += 1
        elif s[j] == 'x':
            res += 1
            j -= 1
        else:
            res = -1
            break
print(res)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}

int h, w;
string board[22];


int bfs (pii from) {
    vector<vector<int> > visited(h, vector<int>(w, -1));
    queue<pair <pii, int> > q;
    int res = 0;
    q.push(mpr(from,0));
    while (!q.empty()) {
     pii now = q.front().first;
        int now_cost = q.front().second;
        q.pop();
        if (visited[now.first][now.second] != -1) continue;
        visited[now.first][now.second] = now_cost;
        res = max(res, now_cost);
        rep(k, 4) {
         pii next = mpr(now.first + dy[k], now.second + dx[k]);
            if (min(next.first, next.second) < 0 || next.first >= h || next.second >= w) {
                continue;
            }
            if (board[next.first][next.second] != '#') {
                q.push(mpr(next, now_cost+1));
            }
        }
    }
 
    return res;
}



void test_case() {

    cin >> h >> w;
    rep(i, h) {
        cin >> board[i];
    }
 
    int res = 0;
    rep(i, h) {
        rep(j, w) {
            if (board[i][j] != '#') {
                res = max(res, bfs(mpr(i, j)));
            }
        }
    }
    cout << res << endl;
    
    


}
 
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
	int n,da[100],db[100],i,j,f=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&da[i]);
		scanf("%d",&db[i]);
	}
	
	for(i=0;i<n;i++){
		if(da[i]==db[i]){
			f++;
		}else{
			f=0;
		}
		if(f==3){
			break;
		}
	}
	if(f==3){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

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

namespace AOJ.Codes
{
    //問題の名称... Dynamic Programming - Fibonacci Number
    //問題文のURL... http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
    //所要時間... AAA
    //学んだこと... AAA
    //教室内の大まかな着席位置... {左，中央，右} x {前，中央，奥}

    class Fibonacci
    {
        static void Main(string[] args)
        {
            //読み込み
            var N = int.Parse(Console.ReadLine());

            //計算
            var memo = new int[N];
            for (int i = 0; i < N; i++)
                memo[i] = -1;

            var ans = GetFibonacci(N, ref memo);

            //出力
            Console.WriteLine(ans);

            //Enterを押して終了
            Console.ReadLine();
        }

        public static int GetFibonacci(int i, ref int[] memo)
        {
            if (i == 0 || i == 1)
                return 1;

            if (memo[i - 1] != -1)
                return memo[i - 1];
            else
            {
                memo[i - 1] = GetFibonacci(i - 1, ref memo) + GetFibonacci(i - 2, ref memo);
                return memo[i - 1];
            }

        }
    }
}



Measured memory_bytes: 17972
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;



int main(){FIN

    ll n;cin>>n;
    ll ans=0;
    vll v(n);
    vll c(n);
    REP(i,n) cin>>v[i];
    REP(i,n) cin>>c[i];
    REP(i,n){
        ans += ((v[i]>c[i]) ? v[i]-c[i]:0);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import atan2, pi

def solve(a, b, x):
    if a * a * b <= 2 * x:
        return 90 - atan2(a / 2, b - x / a / a) / pi * 180
    else:
        return 90 - atan2(2 * x / a / b, b) / pi * 180

_a, _b, _x = map(int, input().split())
print(solve(_a, _b, _x))


Measured memory_bytes: 3060
#include <stdio.h>


int main(void)
{
	int m, d;

	//1  2  3  4  5  6  7  8  9  10 11 12 
	//31 29 31 30 31 30 31 31 30 31 30 31
	//int set[]={31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int set[]={0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};

	while( scanf("%d %d", &m, &d) != EOF ){
		if(m == 0){ break; }
		switch( (set[m] + d) % 7 ){
		case 1:
			puts("Thursday");
			break;
		case 2:
			puts("Friday");
			break;
		case 3:
			puts("Saturday");
			break;
		case 4:
			puts("Sunday");
			break;
		case 5:
			puts("Monday");
			break;
		case 6:
			puts("Tuesday");
			break;
		case 0:
			puts("Wednesday");
			break;
		}
	}
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
void fast()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
}

int main(void)
{
	fast();
	int a,b;
	cin>>a>>b;
	if(a%b==0)
	{
	    cout<<a/b<<endl;
	}
	else
	{
	  int c;
	  //double a,b;
	  c=((a/b)+1);
	  cout<<c<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

int h,w,N;
cin>>h>>w>>N;

int sr,sc;
cin>>sr>>sc;
sr--,sc--;//0~w,0~hの範囲に合わせる
string s,t;
cin>>s;
cin>>t;

bool yes=true;
{
int l=0,r=w;
    for(int i=N-1;i>-1;i--){
    
    if(t[i]=='L')r=min(w,r+1);
    if(t[i]=='R')l=max(0,l-1);
    if(s[i]=='L')l++;
    if(s[i]=='R')r--;

    if(l==r)yes=false;
    }

    yes&=(l<=sc && sc<r);//wは盤の外なので含めない

}
{
int l=0,r=h;
    for(int i=N-1;i>-1;i--){
    
    if(t[i]=='U')r=min(h,r+1);
    if(t[i]=='D')l=max(0,l-1);
    if(s[i]=='U')l++;
    if(s[i]=='D')r--;

    if(l==r)yes=false;
    }

    yes&=(l<=sr && sr<r);

}
cout<<(yes ? "YES":"NO")<<endl;

 return 0;
}
/*

2 3 3
2 2
RRL
LUD

YES


4 3 5
2 2
UDRRR
LLDUD

NO

5 6 11
2 1
RLDRRUDDLRL
URRDRLLDLRD

NO
*/


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];

    //昇順でソート
    sort(all(l));
    int restsum=0;
    for(int i=0; i<n-1; i++){
        restsum += l[i];
    }
    if(l[n-1]<restsum){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
/* *
 *
 * Author: OakenSh1eld
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int a[10];
	for(int i=0; i<3; ++i) {
		cin>>a[i];
		a[3+i] = a[i];
	}
	int ans = 10000000;
	for(int i=0; i<3; ++i){
		int cur = a[i] + a[i+1];
		ans = min(ans, cur);
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

int main(){
  long long s,m=1000000000,x,ux,y;
  cin>>s;
  if(s<=m){
    cout<<"0 0 1 0 0 "<<s<<endl;
    return 0;
  }


  x=s/m;
  ux=x+1;
  if(x==m) ux--;
  y=s%m;
  cout<<x<<" 0 0 "<<y<<" "<<ux<<" "<<m<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int gcd(int a, int b){
  if (a%b == 0){
  return(b);
  } else {
  return(gcd(b, a%b));
  }
}
int main(){
  int K; cin >> K;
  long long ans = 0;
  for (int i = 1; i <= K; i++){
    ans += i;
  }
  for (int i = 1; i <= K-1; i++){
    for (int j= i+1; j <= K; j++){
      ans += 6 * gcd(j, i);
    }
  }
  for (int i = 1; i <= K-2; i++){
    for (int j = i+1; j <= K-1; j++){
      for (int k = j+1; k <= K; k++){
        ans += 6 * gcd(k, gcd(j, i));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vs = vector<string>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  ll K, X;
  cin >> K >> X;
  
  if (500 * K >= X) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

struct RURM {
	using t1 = int;
	using t2 = int;
	static t1 id1() { return INT_MAX; }
	static t2 id2() { return -1; }
	static t1 op1(const t1& l, const t1& r) { return min(l, r); }
	static t1 op2(const t1& l, const t2& r) { return r != id2() ? r : l; }
	static t2 op3(const t2& l, const t2& r) { return r != id2() ? r : l; }
};

template <typename M>
class LazySegmentTree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int h, n;
	vector<T1> data;
	vector<T2> lazy;
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
	void update(int node) {
		data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]), M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
public:
	LazySegmentTree(int n_)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	LazySegmentTree(int n_, T1 v1, T2 v2)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, v1), lazy(n * 2, v2) {}
	LazySegmentTree(const vector<T1>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {
		init(data_);
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void init(const vector<T1>& data_) {
		for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
		init();
	}
	void update(int l, int r, T2 val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		int tl = l, tr = r;
		r++;
		while (l < r) {
			if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
			if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
			l /= 2; r /= 2;
		}
		while (tl > 1) {
			tl >>= 1, tr >>= 1;
			if (lazy[tl] == M::id2()) update(tl);
			if (lazy[tr] == M::id2()) update(tr);
		}
	}
	T1 find(int l, int r) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		T1 res1 = M::id1(), res2 = M::id1();
		while (l < r) {
			if (l & 1) res1 = M::op1(res1, M::op2(data[l], lazy[l])), l++;
			if (r & 1) r--, res2 = M::op1(M::op2(data[r], lazy[r]), res2);
			l /= 2; r /= 2;
		}
		return M::op1(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y, val;
	cin >> n >> q;
	LazySegmentTree<RURM> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			cin >> val;
			st.update(x, y, val);
		}
	}
	return 0;
}

Measured memory_bytes: 5136
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res


N=II()
AS=LI()
SM=sum(AS)
B=1
res=0
M = 1
m = 1

for a in AS:
    B = M-a
    if B < 0:
        print(-1)
        exit(0)
    res += a
    res += B
    SM -= a
    M = min(B*2, SM)
    m = B
print(res)


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

int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; ++i) if (str[s[i]] != (char)(c[i] + '0')) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        stringstream iss; iss << i;
        string str = iss.str();
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> N >> M;
    s.resize(M); c.resize(M);
    for (int i = 0; i < M; ++i) cin >> s[i] >> c[i], --s[i];
    cout << solve() << endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
long long n,ans;
int main()
{
	ans=1e14;
	scanf("%lld",&n);
	for(long long i=1;i<=sqrt(n)+1;i++)
	    if(n%i==0)
	        ans=min(ans,i+(n/i)-2);
	printf("%lld",ans);
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //C
  string s;
  cin >> s;
  int ans = 0;
  stack<char> st;
  for (int i = 0; i < (int) s.length(); i++) {
    if (st.empty()) {
      st.push(s[i]);
      continue;
    }
    if (st.top() != s[i]) {
      st.pop();
      ans++;
    } else {
      st.push(s[i]);
    }
  }
  cout << (int) s.length() - (int) st.size() << endl;
  return 0;	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

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

  double ans = 0;
  for(int i = 1; i <= n; i++){
    int now = i;
    double p = 1.0 / n;
    while(now < k){
      now *= 2;
      p /= 2;
    }
    ans += p;
  }
  printf("%.15f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#define MAX 101
using namespace std;
int n,tim=0;
int A[MAX][MAX]={0};
int color[MAX]={0},d[MAX]={0},f[MAX]={0};
stack<int> Number_of_vertices;
int input(void){
    int start;
    cin >> n;
    for(int i=0;i<n;i++){
        int id,adj;
        cin >> id >> adj;
        if(i==0){
            start = id-1;
            Number_of_vertices.push(id-1);   
        }
        for(int j=0;j<adj;j++){
            int k;
            cin >> k;
            A[id-1][k-1] = 1;
        }
    }
    return start;
}
void depth_first_search(int id){
    tim++;
    if(color[id]!=1){
        color[id] = 1;
        d[id] = tim;
    }
    for(int i=0;i<n;i++){
        if(A[id][i]==1 && color[i]!=1){
            Number_of_vertices.push(i);
            depth_first_search(i); 
        }
    }
    tim++;
    f[Number_of_vertices.top()] = tim;
    Number_of_vertices.pop();
}
void check(void){
    for(int i=0;i<n;i++){
        if(color[i]==0){
            int start = i;
            Number_of_vertices.push(start);
            depth_first_search(start);
        }
    }
}
void print(void){
    for(int i=0;i<n;i++){
        cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
    }
}
int main(void){
    int start;
    start = input();
    depth_first_search(start);
    check();
    print();
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;

long long f[100100], fact[100100];

long long power(long long x, long long y)
{
  if (!y)
    return 1;
  long long res = power(x, y >> 1);
  res = res * res % BASE;
  if (y & 1)
    res = res * x % BASE;
  return res;
}

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

  int n, x[100100];
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> x[i];

  fact[0] = 1;
  for (int i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * i % BASE;
  f[1] = 1;
  for (int i = 2; i <= n; i++)
    f[i] = (f[i - 1] * i + fact[i - 1]) % BASE;

  long long ans = 0;
  for (int i = 1; i < n; i++)
  {
    long long ways = f[i] * fact[n - 1] % BASE * power(fact[i], BASE - 2) % BASE;
    ans = (ans + ways * (x[i + 1] - x[i])) % BASE;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main(){
    int n,k;
    int ans=inf;
    cin >> n >>k;
    vector<int>h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    for(int i=0;i+k-1<n;i++){
        int x=h[i+k-1]-h[i];
        ans=min(ans,x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
k, n = list(map(int, input().split()))

a_list = list(map(int, input().split()))
sa_list = []
for i in range(n-1):
    sa_list.append(a_list[i+1]-a_list[i]) 

sa_list.append(k-a_list[-1]+a_list[0])



print(k - max(sa_list))

Measured memory_bytes: 26420
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

const int N = 100100;

int val[N];


int main(){
	int n;
	long long l;
	scanf("%d%lld",&n,&l);
	long long size = 0;
	for(int i = 0; i < n; i++){
		scanf("%d",&val[i]);
	}
	vector<int> ans;
	for(int i = 0; i < n-1; i++){
		if(val[i]+val[i+1]>=l){
			for(int j = 0; j < i; j++){
				ans.push_back(j+1);
			}
			for(int j = n-2; j >= i+1; j--){
				ans.push_back(j+1);
			}	
			ans.push_back(i+1);	
			break;
		}
	}	
	if(ans.size()>0){
		puts("Possible");
		for(auto a : ans)printf("%d ",a);
	}
	else{
		puts("Impossible");
	}


}

Measured memory_bytes: 1656
#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>




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 int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;

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

void solve() {
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    ll d = 0;
    for (int i = n; i >= 0; --i) {
        cin >> a[i];
        d = gcd(d, abs(a[i]));
    }
    ll N = 10010;
    vector<int> p(N, 1);
    vector<ll> primes;
    for (int i = 2; i < N; ++i) {
        if (p[i]) {
            primes.push_back(i);
            for (int j = i + i; j < N; j += i) {
                p[j] = 0;
            }
        }
    }
    for (int i = 0; i < primes.size(); ++i) {
        ll pp = primes[i];
        while (d % pp == 0) {
            d /= pp;
        }
    }
    for (int i = 0; i < primes.size(); ++i) {
        ll pp = primes[i];
        if (abs(a[0]) % pp != 0)
            continue;
        vector<ll> b(pp, 0);
        for (int j = 0; j <= min(n, pp - 1); ++j) {
            b[j] = ((a[j] % pp) + pp) % pp;
        }
        for (int j = pp; j <= n; ++j) {
            int id = j % (pp - 1);
            if (id == 0)
                id = pp - 1;
            b[id] = (b[id] + pp + a[j]) % pp;
        }
        int ok = 1;
        for (int j = 0; j < pp; ++j) {
            if (b[j] != 0) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            cout << pp << "\n";
        }
    }
    for (ll i = N; i * i <= d; ++i) {
        if (d % i == 0) {
            cout << i << "\n";
            while (d % i == 0) {
                d /= i;
            }
        }
    }
    if (d > 1) 
        cout << d << 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: 512
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 2341
int n,m,k;
bool white[tam][tam];
int actot[20],tot[20];
int go(int mask)
{
    memset(tot,0,sizeof tot);
    //cout<<"begin this "<<mask<<endl;
    int cuts=0;
    forr(y,0,n)
    {
        if (mask&(1<<y)){
            //cout<<"cut at "<<y<<endl;
            cuts++;
        }
    }
    bool reset=0;
    forr(x,0,m)
    {
        int totnow=0;
        forr(y,0,n)
        {
            totnow+=white[y][x];

            if (mask&(1<<y)|| y==n-1)
            {
                //cout<<totnow<<endl;
                actot[y]=totnow;
                if (tot[y]==0 && totnow>k)
                    return 1e9;
                tot[y]+=totnow;
                if (tot[y]>k)
                    reset=1;
                totnow=0;
            }
        }
        if (reset)
        {
            //cout<<"cut at x "<<x<<'\n';
            cuts++;
            forr(y,0,n)
            {
                if (mask&(1<<y)|| y==n-1)
                {
                    if (actot[y]>k)
                        return 1e9;
                    tot[y]=actot[y];
                }
            }
            reset=0;
        }   
        //return 0;
        //cout<<endl;
    }
    //<<endl;
    //cout<<"finish good "<<cuts<<endl;
    return cuts;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>m>>k;
    forr(i,0,n)
    {
        string txt;
        cin>>txt;
        forr(j,0,m)
        {
            white[i][j]=(txt[j]=='1');
        }
    }
    
    //cout<<go(2)<<endl;
    //return 0;
    int resp=go(0);
    forr(mask,0,(1<<(n-1)))
    {
        resp=min(resp,go(mask));
    }
    cout<<resp<<endl;

}
// PLUS ULTRA!


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 1e9+7;

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

	ll a, b, k; cin >> a >> b >> k;

	if(a && k){
		ll d = min(a, k);
		a -= d;
		k -= d;
	}

	if(b && k){
		ll d = min(b, k);
		b-=d;
		k-=d;
	}

	cout << a << ' ' << b << '\n';

	return 0;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int N;
    cin >> N;
    set<ll> A;
    vector<ll> v;
    ll inp;
    REP(i,N){
        cin >> inp;
        if(A.find(inp) == A.end())
            A.insert(inp);
        else{
            v.push_back(inp);
            A.erase(inp);
        }
    }
    if(v.size() < 2){
        cout << 0 << endl;
    }
    else{
        sort(v.begin(), v.end(), greater<ll>());
        cout << v[0]*v[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
table=[]
n=int(input())
for i in range(n):
    tmp=list(input().split())
    tmp[1]=int(tmp[1])*(-1)
    tmp_table=[tmp,i+1]
    table.append(tmp_table)
table.sort(key=lambda x:x[0])
for i in range(n):
    print(table[i][1])


Measured memory_bytes: 38384
input_n = input()
n = str(input_n)

listN = n.split(' ')

N = int(listN[0])
X = int(listN[1])
T = int(listN[2])

result = 0

if N % X == 0:
    result = N / X
else:
    result = N / X + 1

result = int(result) * T

print(str(result))


Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    ll ans = 0;
    for(int i = 0; i < k; i++)
    {
        if(t[i] == 'r') ans += p;
        else if(t[i] == 's') ans += r;
        else ans += s;
        int pos = i+k;
        while(pos < n)
        {
            if(t[pos] != t[pos-k])
            {
                if(t[pos] == 'r') ans += p;
                else if(t[pos] == 's') ans += r;
                else ans += s;
            }
            else
            {
                pos += k;
                if(pos < n)
                {
                    if(t[pos] == 'r') ans += p;
                    else if(t[pos] == 's') ans += r;
                    else ans += s;
                }
            }
            pos += k;
        }
    }
    cout << ans << endl;
}
    



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long memo[1001][100001];
long long knapsack(long long value[],long long weight[],int index,int n,long long w)
{
  if(index>=n || w<=0)
    return 0;
  if( weight[index]>w )
  {
    if(memo[index][w]!=-1)
      return memo[index][w];
   
     return memo[index][w]=knapsack(value,weight,index+1,n,w);
  }
  if(memo[index][w]!=-1)
    return memo[index][w];
  long long temp1;
  long long temp2;
  temp1=value[index]+knapsack(value,weight,index+1,n,w-weight[index]);
  temp2=knapsack(value,weight,index+1,n,w);
  memo[index][w]=max(temp1,temp2);
  return memo[index][w];
   //return memo[index][w]=max(value[index]+knapsack(value,weight,index+1,n,w-weight[index]),knapsack(value,weight,index+1,n,w));
}
  
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long w;
  cin >> w;
  long long weight[n],value[n];
  for(int i=0;i<n;i++)
    cin >> weight[i] >> value[i];
  for(long long i=0;i<=n;i++)
  {
    for(long long j=0;j<=w;j++)
      memo[i][j]=-1;
  }
  cout << knapsack(value,weight,0,n,w) << endl;
  return 0;
}

Measured memory_bytes: 82480
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
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)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

// 最大公約数
ll GreatestCommonDivisor(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

// 最小公倍数
ll LeastCommonMultiple(ll a, ll b) {
	ll gcd = GreatestCommonDivisor(a, b);

	ll tmp = a / gcd;
	return tmp * b;
}

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

	// long long?
	ll N;
	cin >> N;

	vector<ll> vA(N-1, 0);
	vector<ll> vB(N-1, 0);
	vector<ll> vC(N-1, 0);
	vector<vector<pair<ll, ll> > > vCon(N);
	rep(i, N - 1) {
		cin >> vA[i] >> vB[i] >> vC[i];
		vA[i]--;
		vB[i]--;
		vCon[vA[i]].push_back(make_pair(vB[i], vC[i]));
		vCon[vB[i]].push_back(make_pair(vA[i], vC[i]));
	}
	ll Q, K;
	cin >> Q >> K;

	vector<ll> visited(N, 0);
	deque<ll> deq;
	vector<ll> vLen(N, 0);
	deq.push_back(K - 1);
	visited[K - 1] = 1;
	while (1) {
		if (deq.empty()) {
			break;
		}
		ll next = deq.front();
		deq.pop_front();
		vector<pair<ll, ll> > vtmp = vCon[next];
		for (int i = 0; i != vtmp.size(); ++i) {
			if (visited[vtmp[i].first] == 0) {
				vLen[vtmp[i].first] = vLen[next] + vtmp[i].second;
				visited[vtmp[i].first] = 1;
				deq.push_back(vtmp[i].first);
			}
		}
	}

	vector<ll> vx(Q, 0);
	vector<ll> vy(Q, 0);

	rep(i, Q) {
		cin >> vx[i] >> vy[i];
		vx[i]--;
		vy[i]--;
	}

	rep(i, Q) {
		cout << vLen[vx[i]] + vLen[vy[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 15188
// Vol02_0297
// The_Last_One_is_the_Best

#include <cstdio>

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		int k, p;
		scanf("%d %d", &k, &p);
		if (k % p)
			printf("%d\n", k % p);
		else
			printf("%d\n", p);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		List<String> list = new ArrayList<>(); 
		for(int i = 0; i < a; i++) {
			list.add(sc.next());
		}
		Collections.sort(list);
		StringBuilder val = new StringBuilder();
		for(int j = 0; j < list.size(); j++) {
			val.append(list.get(j));
		}
		System.out.println(val);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int n, k;
string s;
int sa[400005];

int kk, nn;
int Rank[200005];
int tmp[200005];

bool compare_sa(int i, int j)
{
	if(Rank[i] != Rank[j]) return Rank[i] < Rank[j];
	int ri, rj;
	if(i+kk <= nn) ri = Rank[i+kk]; else ri = -1;
	if(j+kk <= nn) rj = Rank[j+kk]; else rj = -1;
	return ri < rj;
}

void makeSA(string s, int sa[]){
	nn = s.size();
	for(int i = 0; i <= nn; i++) sa[i] = i;
	for(int i = 0; i < nn; i++) Rank[i] = s[i];
	s += " ";
	s[nn] = -1;

	for(kk = 1; kk <= nn; kk*=2){
		sort(sa, sa+nn+1, compare_sa);
		int val = 0;
		tmp[sa[0]] = 0;
		for(int i = 1; i <= nn; i++){
			if(compare_sa(sa[i-1], sa[i])) val++;
			tmp[sa[i]] = val;
		}
		for(int i = 0; i <= nn; i++) Rank[i] = tmp[i];
	}
}

int main(void)
{
	cin >> n >> k;
	cin >> s;
	
	if(k >= 15){
		char c = '~';
		for(int i = 0; i < s.size(); i++) c = min(c, s[i]);
		for(int i = 0; i < n; i++) cout << c;
		cout << endl;
		return 0;
	}
	
	string t = s;
	reverse(t.begin(), t.end());
	t = s + t;
	
	makeSA(t, sa);
	
	int p;
	for(int i = 0; i < t.size(); i++){
		if(sa[i] < s.size()){
			p = sa[i];
			break;
		}
	}
	
	s = t.substr(p, n);
	if(k == 0){
		cout << s << endl;
		return 0;
	}
	
	k--;
	int cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[0] == s[i]) cnt++;
		else break;
	}
	int len = cnt;
	for(int i = 0; i < k; i++) len = min(n, len*2);
	
	t = "";
	for(int i = 0; i < len-cnt; i++) t += s[0];
	t += s;
	
	cout << t.substr(0, n) << endl;
	
	return 0;
}

Measured memory_bytes: 384
from bisect import bisect_left
N,Q=map(int,input().split())
A=[int(i) for i in input().split()]
P=[]
m=N//2
for k in range(N-m-1):
  P.append((A[k+m]+A[2*(k+m)-N+1])/2)
S,S_o,S_e=[0],[0],[0]
for i in range(N):
  S.append(S[-1]+A[i])
  if i%2==0:
    S_o.append(S_o[-1]+A[i])
    S_e.append(S_e[-1])
  if i%2==1:
    S_o.append(S_o[-1])
    S_e.append(S_e[-1]+A[i])
for q in range(Q):
  a=int(input())
  l=bisect_left(P,a)
  if N%2:
    ans=S[N]-S[N-m+l-1]+S_o[max(N-2*(m-l+1),0)]
  else:
    ans=S[N]-S[N-m+l]+S_e[max(N-2*(m-l),0)]
  print(ans)


Measured memory_bytes: 80364
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int K = Integer.parseInt(sc.next());
        final int R = Integer.parseInt(sc.next());
        final int S = Integer.parseInt(sc.next());
        final int P = Integer.parseInt(sc.next());
        final char T[] = sc.next().toCharArray();
        sc.close();

        List<Character> C = new ArrayList<>();
        for (char t : T) {
            if (t=='r') {
                C.add('p');
            } else if (t=='s') {
                C.add('r');
            } else {
                C.add('s');
            }
        }
        for (int i=0; i<N-K; i++) {
            if (C.get(i)==C.get(i+K)) {
                C.set(i+K,'x');
            }
        }
        long sum = 0;
        for (int i=0; i<N; i++) {
            if (C.get(i)=='p') {
                sum += P;
            } else if (C.get(i)=='r') {
                sum += R;
            } else if (C.get(i)=='s') {
                sum += S;
            }
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 28072
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if(S.at(i) == 'o') count++;
  }
  cout << 700 + count * 100 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
long long F[210][11];
long long P[210][15];



int main() {
    while (cin >> N) {
        for (int i = 0; i < N; ++i) for (int j = 0; j < 10; ++j) cin >> F[i][j];
        for (int i = 0; i < N; ++i) for (int j = 0; j < 11; ++j) cin >> P[i][j];

        long long res = -(1LL<<60);
        for (int bit = 1; bit < (1<<10); ++bit) {
            long long tmp = 0;
            for (int i = 0; i < N; ++i) {
                int num = 0;
                for (int j = 0; j < 10; ++j) {
                    if ( (bit & (1<<j)) && (F[i][j]) ) ++num;
                }
                tmp += P[i][num];
            }
            chmax(res, tmp);
        }
        cout << res << endl;
    }
}










Measured memory_bytes: 256
"use strict"
function main(arg) {
    arg = arg.trim().split("\n")[1].split(' ').map(Number)
    const n = arg.length
    let ans = 0
    for (let i = 1; i < n - 1; i++) {
        let iP = arg[i - 1]
        let iC = arg[i]
        let iN = arg[i + 1]

        if (iP < iC && iC < iN) {
            ans++
        } else if (iN < iC && iC < iP) {
            ans++
        }
    }
    console.log(ans) 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
template<class T>inline int cmp(vector<T>&v,T &a){
	return lower_bound(all(v),a)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

signed main(){
	int N;
	cin>>N;
	int pay=(N+999)/1000*1000;
	cout<<pay-N<<endl;
}

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


int main() {
    int N; 
    cin >> N;
    vector<long long> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }

	long long res = 0;
	sort(L.begin(),L.end());
    for (int i = 0; i < N; ++i){
        for (int j = i+1; j < N; ++j){
			int l_b = lower_bound(L.begin(),L.end(),L[i]+L[j])
						- L.begin();
			res += max(l_b-(j+1),0);
        }
    }

	cout << res << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;




int main(){
    string s;
    cin>>s;
    ll ans=s.size();
    ll n=s.size();
    for(ll i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]){
            ans=min(ans,max(i+1,n-i-1));
        }
        
        
    }
    cout<<ans<<endl;
    
    
    
    
return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w)), b(h, vector<int>(w));
  for (auto& v : a) {
    for (auto& e : v) cin >> e;
  }
  for (auto& v : b) {
    for (auto& e : v) cin >> e;
  }

  int m = 80 * 80 + 1;
  vector<vector<vector<bool>>> s(h + 1, vector<vector<bool>>(w + 1, vector<bool>(m)));
  s[0][0][0] = true;
  s[0][1][0] = true;
  s[1][0][0] = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int d = abs(a[i][j] - b[i][j]);
      for (int k = 0; k < m; k++) {
        if (!s[i + 1][j][k]) continue;
        if (abs(k + d) < m) s[i + 1][j + 1][abs(k + d)] = true;
        if (abs(k - d) < m) s[i + 1][j + 1][abs(k - d)] = true;
      }
      for (int k = 0; k < s[i][j + 1].size(); k++) {
        if (!s[i][j + 1][k]) continue;
        if (abs(k + d) < m) s[i + 1][j + 1][abs(k + d)] = true;
        if (abs(k - d) < m) s[i + 1][j + 1][abs(k - d)] = true;
      }
    }
  }
  cout << find(s[h][w].begin(), s[h][w].end(), true) - s[h][w].begin() << endl;
}


Measured memory_bytes: 5888
#include<stdio.h>
int main()
{
    int a[5],k,i;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    if((a[4]-a[0])<=k)
    {
        printf("Yay!");
    }
    else
    {
        printf(":(");
    }
}


Measured memory_bytes: 1728
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var n int
	fmt.Scan(&n)
	abc := make([][3]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&abc[i][0], &abc[i][1], &abc[i][2])
	}

	dp := make([][3]int, n+1)

	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 1; k < 3; k++ {
				index := (j + k) % 3
				happy := abs(dp[i][j] + abc[i][index])
				if happy > dp[i+1][index] {
					dp[i+1][index] = happy
				}
			}
		}
	}
	fmt.Println(max(dp[n][0], dp[n][1], dp[n][2]))
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll a, p;
int main() {
	cin >> a >> p;
	a *= 3;
	p += a;
	cout << p / 2 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAX=2147483647;
int n,q;
int d[600000];
void init(){
  int n_=1;
  while(n_<n) n_*=2;
  n=n_;
  for(int i=0;i<2*n-1;i++)d[i]=MAX;
}
void update(int k,int x){
  k+=n-1;
  d[k]=x;
  while(k>0){
    k=(k-1)/2;
    d[k]=min(d[k*2+1],d[k*2+2]);
  }
}
int find(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return MAX;

  if(a<=l && r<=b)return d[k];
  else{
    int vl=find(a,b,k*2+1,l,(l+r)/2);
    int vr=find(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}
int main(){
  scanf("%d %d",&n,&q);
  init();
  for(int i=0;i<q;i++){
    int c,x,y;
    scanf("%d %d %d",&c,&x,&y);
    if(c==0)update(x,y);
    else printf("%d\n",find(x,y+1,0,0,n));
    // for(int j=0;j<2*n-1;j++)printf("%d ",d[j]);
    //printf("\n");
  }
  return 0;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

int n;
string s;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    // ac, wa, tle, re
    cin>>n;
    int ans[4]={};
    for(int i=0; i<n; i++){
        cin>>s;
        if(s=="AC") ans[0]++;
        else if(s=="WA") ans[1]++;
        else if(s=="TLE") ans[2]++;
        else ans[3]++;
    }
    cout<<"AC"<<" x "<<ans[0]<<"\n";
    cout<<"WA"<<" x "<<ans[1]<<"\n";
    cout<<"TLE"<<" x "<<ans[2]<<"\n";
    cout<<"RE"<<" x "<<ans[3]<<"\n";
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int S = Integer.parseInt(line);

		int h = S / 3600;
		int m = (S - h * 3600) / 60;
		int s = S - h * 3600 - m * 60;

		System.out.println(h + ":" + m + ":" + s);
	}

}

Measured memory_bytes: 26160