akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int N;
int used[11];
vector<int> perm;

int dfs(int level) {
    if (level == N) {
        for (int i = 0; i < N; i++) {
            cout << (char)('a' + perm[i]);
        }
        cout << endl;
        return 0;
    }

    int flag = 0;
    for (int i = 0; i <= level; i++) {
        if (i != 0 && used[i-1] == 0) continue;
        perm[level] = i;
        used[i]++;
        dfs(level+1);
        used[i]--;
    }
    return 0;
}

int main(void) {
    cin >> N;
    perm = vector<int> (N);
    dfs(0);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N ;
    vector<int> P(N);
    for (int i = 0; i < N ; i++) {
        cin >> P.at(i);
    }
    int min = P[0];
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (P[i]<=min)
        {
            min = P[i];
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		if (x >= a && x <= a + b) {
			pr.println("YES");
		} else {
			pr.println("NO");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(test) printf(test ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

#include <stdio.h>
#include <algorithm>
//#include <vector>

using namespace std;


int main() {

	int n;
	scanf("%d", &n);
	printf("%d\n", (n + 1) * n / 2);

	return 0;
}

Measured memory_bytes: 128
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))

m = a1 + a2 + a3

n = int(input())
b = []
for i in range(n):
  b.append(int(input()))

if ((m[0] in b and m[1] in b and m[2] in b) or
    (m[3] in b and m[4] in b and m[5] in b) or
    (m[6] in b and m[7] in b and m[8] in b) or
    (m[0] in b and m[3] in b and m[6] in b) or
    (m[1] in b and m[4] in b and m[7] in b) or
    (m[2] in b and m[5] in b and m[8] in b) or
    (m[0] in b and m[4] in b and m[8] in b) or
    (m[2] in b and m[4] in b and m[6] in b)):
  print('Yes')
  
else:
  print('No')
    
    

Measured memory_bytes: 3064
// =====================================================================================
//
//       Filename:  atcoder.cpp
//
//    Description:  
//
//        Version:  1.0
//        Created:  26/04/20 03:38:51 AM IST
//       Revision:  none
//       Compiler:  g++
//
//         Author:  Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com
//   Organization:  
//
// =====================================================================================

#include<bits/stdc++.h>


using namespace std;

#define int long long 
#define pb push_back
//#define _SHOW_TIME
int countSame(int *a,int*b){
    int c = 0 ; 
    for(int i=0;i<26;i++){
        if(a[i]>0 && b[i]>0 ) c++;
    }
    return c; 
}
void solve(){
  int n ;cin>>n;
  string s;cin>>s;
  int a[26]={0},b[26]={0};
  for(int i=0;i<n;i++) b[s[i]-'a']++;

  int mx = 0; 
  for(int i =0;i<n;i++){
        a[s[i]-'a']++;
        b[s[i]-'a']--;
        mx = max(mx,countSame(a,b));
  }
  cout<<mx<<endl;
}
int32_t main(){
 /////////////////////////////////////
    #ifdef _SHOW_TIME
	int tt = (int) clock();
    #endif
    /////////////////////////////////////
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /////////////////////////////////////
    solve();
    /////////////////////////////////////
    #ifdef _SHOW_TIME
        cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl;
    #endif
    /////////////////////////////////////
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
string str;
bool n = false, e = false, w = false, s = false;
int main()
{
    cin >> str;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == 'N')
            n = true;
        if (str[i] == 'W')
            w = true;
        if (str[i] == 'S')
            s = true;
        if (str[i] == 'E')
            e = true;
    }
    if (n & !s)
    {
        cout << "No" << endl;
        return 0;
    }
    if (s & !n)
    {
        cout << "No" << endl;
        return 0;
    }
    if (e & !w)
    {
        cout << "No" << endl;
        return 0;
    }
    if (w & !e)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3544
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		String[] strAry;
		int[][] table;
		int n;
		StringBuffer sb = new StringBuffer();
		while(!(str = br.readLine()).equals("0")){
			n = Integer.parseInt(str);
			table = new int[n+1][n+1];
			strAry = new String[n];
			for(int i = 0 ; i < n ; i++){
				strAry = br.readLine().split(" ");
				int num;
				for(int y = 0 ; y < n ; y++ ){
					num = Integer.parseInt(strAry[y]);
					table[i][y] = num;
					table[i][n] += num;
					table[n][y] += num;
					table[n][n] += num;
				}
			}

			for(int i = 0 ; i < n + 1 ; i++){
				for(int y = 0 ; y < n + 1 ; y++){
					sb.append(String.format("%5s",String.valueOf(table[i][y])));
				}
				sb.append("\n");
			}
		}
		sb.delete(sb.length() - 1, sb.length());
		System.out.println(sb.toString());
	}
}

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

int main(){
	priority_queue<int> qu;

	for(int i = 0; i < 10; i ++)
	{
		int t;
		cin>>t;

		qu.push(t);
	}

	for(int i = 0; i < 3; i ++)
	{
		cout<<qu.top()<<endl;
		qu.pop();
	}

    return 0;
}

Measured memory_bytes: 1216
/*
    Author: Mohammad faisal
    Problem: Can you solve this.
    Date: 06/08/2019

*/
// #include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
using namespace std;
int main()
{
  int n,m,c;
  cin >> n >> m >> c;
  int* b = new int[n];
  for(int i=0;i<m;i++)
    cin >> b[i];
  // int* a = new int[n];
  int sum=0,count=0;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
      int x;
      cin >> x;
      sum+=(x*b[j]);
    }
    // cout<<"sum: "<<sum<<endl;
    if((sum+c)>0)
    {
      count++;
      sum=0;
    }
    else
    {
      sum=0;
    }
  }
  cout<<count<<endl;

  return 0;
}
    

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

using namespace std;


int main() {
    int n;
    cin >> n;
    if(n % 2 == 0) {
        cout << n / 2 - 1 << "\n";
    } else {
        cout << (n-1) / 2 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
while(True):
    var=input()
    var=var.split()
    x=int(var[0])
    y=int(var[1])
    if(x==0 and y==0):
        break
    else:
        if(x>y):
            print(str(y)+" "+str(x))
        else:
            print(str(x)+" "+str(y))


Measured memory_bytes: 5616
import java.util.*;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		if (W >= S) 
			System.out.println("unsafe");
		else 
			System.out.println("safe");
	}
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
ll par[100005];
ll size[100005];
void init(ll n)
{
    rep(i,n){
        par[i] = i;
        size[i] = 1;
    }
}
ll root(ll x){
    if (par[x] == x) return x;
    else{
        return par[x] = root(par[x]);
    }
}
bool same(ll x,ll y){
    return root(x) == root(y);
}
void unite(ll x,ll y){
    x = root(x);
    y = root(y);
    if (size[x] < size[y]) swap(x,y);
    size[x] += size[y];
    par[y] = x;
}

ll siz(ll x){
    return size[root(x)];
}
ll n,m;
ll bridge[100005][2];
int main(){
    ll a,b;
    cin >> n >> m;
    rep(i,m){
        cin >> a >> b;
        bridge[m-i-1][0] = a-1;
        bridge[m-i-1][1] = b-1;
    }
    ll ans[100005];
    init(n);
    ans[m] = n*(n-1)/2;
    rep(i,m){
        a = bridge[i][0];
        b = bridge[i][1];
        if (same(a,b)){
            ans[m-i-1] = ans[m-i];
        }
        else{
            ans[m-i-1] = ans[m-i]-siz(a)*siz(b);
            unite(a,b);
        }
    }
    rep(i,m){
        PRINT(ans[i+1]);
    }
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll k, n; cin >> n >> k;
    vector<ll> a(n);
    cin >> a;
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, k) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define weightSum weight + (it -> first)
#define valueSum (it -> second) + value
using namespace std;
map <int, ll> maxValue;

int main() {
    ll n, w, weight, value;

	cin >> n >> w;
	for (int i = 1; i <= n; i++) {
		cin >> weight >> value;

		for (map <int, ll> :: reverse_iterator it = maxValue.rbegin(); it != maxValue.rend(); it++)
			if (weightSum <= w)
				maxValue[weightSum] = max(maxValue[weightSum], valueSum);

		maxValue[weight] = max(maxValue[weight], value);
	}

	ll result = 0;
    for (pair <int, ll> value : maxValue)
    	result = max(result, value.second);
	cout << result;

	return 0;
}


Measured memory_bytes: 9864
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;

#define INF 1e9+7
#define mp make_pair
#define pii pair<int,int>
#define st first
#define nd second
#define pb push_back

typedef long long int lint;
typedef unsigned long long int ulint;


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

    int arr[n+10];
    int dp[n+10];

    for (int i=1; i<n+1; i++)
        cin >> arr[i];

    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);

    for (int i=3; i<n+1; i++)
    {
        dp[i] = INF;

        for (int j=1; j<=k; j++)
        {
            if (i-j > 0)
                dp[i] = min(dp[i],dp[i-j] + abs(arr[i] - arr[i-j]));
        }
    }

    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
using namespace std;

typedef long double dbl;
typedef long long int lli;

const dbl inf = 170705091707.00;

vector<vector<lli>> A;
vector<vector<dbl>> graph;
vector<dbl> D;

dbl dist(lli a, lli b)
{
	dbl res = sqrt((A[a][0]-A[b][0])*(A[a][0]-A[b][0])+(A[a][1]-A[b][1])*(A[a][1]-A[b][1]));
	return max(dbl(0.00), res-A[a][2]-A[b][2]);
}

int main(void)
{
	lli n, xs, ys, xt, yt;
	scanf("%lld%lld%lld%lld%lld", &xs, &ys, &xt, &yt, &n);
	A.clear(); A.resize(n+2, vector<lli>(3));
	graph.clear(); graph.resize(n+3, vector<dbl>(n+3));
	D.clear(); D.resize(n+3, inf);
	A[0][0] = xs; A[0][1] = ys;
	A[n+1][0] = xt; A[n+1][1] = yt;
	A[0][2] = A[n+1][2] = 0;
	for(lli i = 1;i <= n;i++)
	{
		scanf("%lld%lld%lld", &A[i][0], &A[i][1], &A[i][2]);
	}
	
	for(lli i = 0;i < n+2;i++)
	{
		for(lli j = 0;j < n+2;j++)
		{
			if(i != j)
			{
				graph[i][j] = dist(i, j);
				//cout << i << " " << j << " " << graph[i][j] << "\n";
			}
		}
	}

	set<pair<dbl, lli>> Q;
	D[0] = 0.00;
	Q.insert({D[0], 0});

	while(!Q.empty())
	{
		pair<dbl, lli> top = *Q.begin();
		//cout << top.second << "\n";
		Q.erase(Q.begin());

		for(lli i = 0;i < n+2;i++)
		{
			if(D[i] > top.first+graph[top.second][i])
			{
				if(D[i] != inf) Q.erase({D[i], i});
				D[i] = top.first+graph[top.second][i];
				Q.insert({D[i], i});
			}
		}
	}

	printf("%.20Lf\n", D[n+1]);
}

Measured memory_bytes: 16128
#include<stdio.h>
int main(){
	int stu[31] = { 0 };
	int i;
	int fin;
	
	for(i = 1 ; i < 31 ; i++ ){
		stu[i]=i;
	}
	for(i = 1 ; i < 29 ; i++ ){
		scanf("%d",&fin);
		stu[fin]=0;
	}
	for(i = 0 ; i < 31 ; i++ ){
		if(stu[i] != 0){
			printf("%d\n",stu[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N, i;
	cin >> N;
	int d[N+1];
	for(i=0;i<N;i++){
		cin >> d[i];
	}
	d[N+1] = -1;
	sort(d, d+N);
	reverse(d, d+N);
	
	int tmp, count, point;
	int sum = 0;
	
	tmp = d[0];
	point = 0;
	
	for( i=1; i<=N; i++ ){
		if( tmp != d[i] ){
			count = i - point;
			sum++;
			tmp = d[i];
			point = i;
		}
	}
	
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vvi G(n);
    rep(i, n) {
        int id, k;
        cin >> id >> k;
        id--;
        G[id].resize(k);
        rep(j, k) {
            cin >> G[id][j];
            G[id][j]--;
        }
    }

    vi dist(n, -1);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        for(int ne:G[now]) {
            if(dist[ne] != -1) continue;
            dist[ne] = dist[now] + 1;
            q.push(ne);
        }
    }

    rep(i, n) {
        cout << i + 1 << ' ' << dist[i] << endl;
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

int main() {
  int N; 
  cin >> N;
  vector<ll> A(N);
  REP(i,N){
    cin >> A[i];
  }

  if(N==1){
    cout << 1 << endl;
    return 0;
  }

  int cur = 1;
  int ans = 1;
  int state = 0; // -1:down 0:reset 1:up

  while(cur != N){
    if(A[cur] == A[cur - 1]){
      cur++;
      continue;
    }

    if(state == 1 && A[cur] < A[cur-1]
      || state == -1 && A[cur] > A[cur-1]){
        state = 0;
        ans++;
    }else if(state == 0){
      if(A[cur] < A[cur-1]) state = -1;
      else state = 1;
    }
    cur++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	for(int i=1;i<10;++i)for(int j=1;j<10;++j){
		if(i*j==n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    private static final String rightWord = "AKIHABARA";
    private static final String rightWordNoA = "KIHBR";
    private static final String checkWord = "KIH";

    Pattern pattern = Pattern.compile("AA");
    Pattern checkPattern = Pattern.compile("KIH");

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Main main = new Main();
        String s = scanner.nextLine();
        System.out.println(main.checkToken(s)
                && main.checkDuplicateToken(s)
                && main.checkWord(s) ? "YES" : "NO");
    }

    private boolean checkToken(String s) {
        return rightWordNoA.equals(s.replaceAll("A", ""));
    }

    private boolean checkDuplicateToken(String s) {
        Matcher matcher = pattern.matcher(s);
        return !matcher.find();
    }

    private boolean checkWord(String s){
        Matcher matcher = checkPattern.matcher(s);
        return matcher.find();
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
int main () {
    string s , t ;
    cin >> s >> t ;
    size_t n = s.size() ;
    bool flag = true ;
    for(int i = 0 ; i < n ; i++){
        if(s[i] != t[i]){
            flag = false ;
        }
    }
    if(flag == false){
        cout << "No "<< endl;
    }else{
        cout <<"Yes" << endl;
    }
    
    return 0 ;
}

 


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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

int t;

LL n, a, b, c, d;

LL ret = 0;
int cnt = 0;

map<LL, LL> M;

LL val[3] = {2, 3, 5};
LL cost[3];
LL inf;

LL solve2(LL n) {
	if (n == 0) return 0;
	if (n == 1) return d;
	if (M.find(n) == M.end()) {
		double cost2 = n * 1.00 * d * 1.00;
		LL ret;
		
		if (cost2 >= 1e15) {
			ret = inf;
		} else {
			ret = n * d; 	
		}
		
		FOE(i, 0, 2) {
			if (n >= val[i]) {
				LL c1 = (n % val[i]) * d;
				LL tar = (n - n % val[i]) / val[i];
				if (tar < n) {
					LL c2 = solve2(tar) + cost[i];
				
					if (c1 + c2 < ret) ret = c1 + c2;
				}
			}
			
			LL c1 = (val[i] - n % val[i]) * d;
			LL tar = (n + (val[i] - n % val[i])) / val[i];
			
			if (tar < n) {
				LL c2 = solve2(tar) + cost[i];
				
				if (c1 + c2 < ret) ret = c1 + c2;
			}
			
		//	if (n == 11) printf("?? %d %lld\n", val[i], ret, tar);
		}
		
		M[n] = ret;
	}
	
	return M[n];
}

void solve() {
	cin >> n >> a >> b >> c >> d;
	M.clear();
	cost[0] = a;
	cost[1] = b;
	cost[2] = c;
	
	printf("%lld\n", solve2(n));
}

int main() {
	inf = 1;
	FOE(i, 1, 16) inf *= 10;
	scanf("%d", &t);
	
	while (t--) solve();
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n; cin >> n;
    vl lsum(n,0),rsum(n,0);
    rep(i,n){
        ll a; cin >> a;
        if(i==0) lsum[i] = a;
        else lsum[i] = lsum[i-1] + a;
    }
    vl a(n);
    rep(i,n) cin >> a[i];
    rsum[n-1] = a[n-1];
    for(ll i=n-2; i>=0; i--){
        rsum[i] = rsum[i+1] + a[i];
    }
    ll ans = 0;
    rep(i,n){
        ans = max(ans, lsum[i] + rsum[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var a1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a3 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = int.Parse(Console.ReadLine());

        var a = a1.Concat(a2).Concat(a3).ToArray();
        var bingo = new bool[a.Length];

        for (int i = 0; i < n; i++)
        {
            var b = int.Parse(Console.ReadLine());
            for (int j = 0; j < a.Length; j++)
            {
                if (a[j] == b)
                {
                    bingo[j] = true;
                }
            }
        }

        if (bingo[0] && bingo[1] && bingo[2]
            || bingo[3] && bingo[4] && bingo[5]
            || bingo[6] && bingo[7] && bingo[8]
            || bingo[0] && bingo[3] && bingo[6]
            || bingo[1] && bingo[4] && bingo[7]
            || bingo[2] && bingo[5] && bingo[8]
            || bingo[0] && bingo[4] && bingo[8]
            || bingo[2] && bingo[4] && bingo[6])
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13396
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
using namespace std;
string a,b;
map <long long ,long long > mp;

long long gcd(long long  N,long long  M){
	if(M==0){
		return N;
	}else{
		return gcd(M,N%M);
	}
}

int main(){
	long long  N,M;
	scanf("%lld%lld",&N,&M);
	long long l=N*M/gcd(N,M);
	int k1=l/N;
	int k2=l/M;
	cin>>a>>b;
	int flag=1;
	for(int i=0;i<a.size();i++){
		int pos=k1*i+1;
		mp[pos]=a[i];
	}
	for(int i=0;i<b.size();i++){
		int pos=k2*i+1;
		if(mp[pos]!=b[i]&&mp[pos]!=0){
			flag=0;
			break;
		}
	}
	if(flag){
		printf("%lld",l);
	}else{
		printf("-1");
	}
	return 0;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long INF=pow(2,31)-1;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const long P_SIZE=301;
const long MAX_N=100004;
int bit[MAX_N+1];
int N;
int sum(int i){
	int s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

void add(int i,int x){
	while(i<=N){
		bit[i]+=x;
		i+=i&-i;
	}
}

int main(){
	int Q;
	cin>>N>>Q;
	CLR(bit);	
	REP(i,Q){
		long c,x,y;
		cin>>c>>x>>y;
		if(c==0){
			add(x,y);
		}else{
			cout<<sum(y)-sum(x-1)<<endl;
		}
	}
	//REP(i,SZ(res))cout<<res[i]<<endl;
	return 0;
}

Measured memory_bytes: 1560
#include <iostream>
int main(){
  long long N;
  std::cin >> N;
  long long i = 1;
  long long j = N;
  for (long long x = 2; x*x<=N; ++x){
    if (N % x != 0) continue;
    long long y = N / x;
    if (x+y < i+j) { i=x; j=y; }
  }
  std::cout << ((i-1)+(j-1));
  return 0;
}

Measured memory_bytes: 384
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long
const int MAXN = 200010;
using namespace std;

int tail[MAXN], prv[MAXN];
ll len[MAXN];
struct item {
	int h; ll len;
	inline bool operator<(item rhs) const { return len < rhs.len; }
};
priority_queue<item> Q;

int N, L, A[MAXN], Seq[MAXN], SeqLen = 0;
bool vis[MAXN];

int main() {
	scanf("%d%d", &N, &L);

	int i;
	for(i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		tail[i] = i, len[i] = A[i], prv[i] = i - 1;
	}
	for(i = 1; i < N; i++) Q.push((item){i, len[i] + len[i + 1]});

	while(!Q.empty()) {
		item it = Q.top(); Q.pop();
		int nxt = tail[it.h] + 1;
		ll curlen = len[it.h] + len[ nxt ];

		if(vis[ it.h ] || it.len != curlen || nxt > N) continue;
		if(curlen < L) break;

		Seq[++SeqLen] = nxt - 1;

		vis[nxt] = 1;
		len[it.h] += len[nxt];
		tail[it.h] = tail[nxt];
		prv[ tail[it.h] + 1 ] = it.h;

		Q.push( (item){ it.h, len[ it.h ] + len[ tail[ it.h ] + 1 ] } );
		if(prv[ it.h ]) Q.push( (item){ prv[ it.h ], len[ prv[ it.h ] ] + len[ it.h ] } );
	}

	if(SeqLen == N - 1) {
		printf("Possible\n");
		for(i = SeqLen; i >= 1; i--) printf("%d\n", Seq[i]);
	}
	else printf("Impossible");
	return 0;
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf(a) printf("%d\n",a)
#define sc1(a) scanf("%d",&a)
#define sc2(a, b) scanf("%d%d",&a,&b)
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
//#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 1e5 + 5;

int dp[3002][3002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s1;
    string s2;
    cin >> s1;
    cin >> s2;
    int len1=s1.size();
    int len2=s2.size();
    s1=" "+s1;
    s2=" "+s2;

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

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

    for(int i=1;i<=len1;i++)
    {
        for(int j=1;j<=len2;j++)
        {
            if(s1[i]!=s2[j])
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
            else if(s1[i]==s2[j])
            {
                dp[i][j]=1+dp[i-1][j-1];
                //ans=ans+s1[i];
            }
        }
    }


    int ans=dp[len1][len2];
    //printf("%d\n",dp[len1][len2]);
    char lcs[ans];
    lcs[ans]='\0';
    ans--;
     int i=len1; int j=len2;
     while(i>0&&j>0)
     {
         if(s1[i]==s2[j])
         {
             //cout << s1[i] << " " << s2[j] << endl;
             lcs[ans]=s1[i];
             i--;
             j--;
             ans--;
             //cout << s1[i] << endl;
         }
         else if(dp[i][j-1]>dp[i-1][j])
         {
             j--;
         }
         else
             i--;

     }
   cout << lcs << endl;
    return 0;

}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

string s;
const int maxn = 1e5 + 5;
int dp[maxn][13];

int f(int i, int rem){
	if(i == (int) s.size()) return rem == 5;
	if(dp[i][rem] != -1) return dp[i][rem];
	int ret = 0;
	if(s[i] != '?'){
		int nextrem = rem * 10;
		nextrem += (s[i] - '0');
		nextrem %= 13;
		ret = add(ret, f(i + 1, nextrem));
	}
	else{
		for(int j = 0; j <= 9; j++){
			int nextrem = rem * 10;
			nextrem += j;
			nextrem %= 13;
			ret = add(ret, f(i + 1, nextrem));
		}
	}
	return dp[i][rem] = ret;
}

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

	cin >> s;
	memset(dp, -1, sizeof dp);
	cout << f(0, 0);
}

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

int main(){
    int k;
    cin >> k;
    if(k%2==0||k%5==0){
        cout << "-1" << endl;
        return 0;
    }
    int v = 0;
    for(int i=1; ;++i){
        v = (v*10 + 7)%k; // Ai (mod k) = v
        if(v%k==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x,t;
	cin >> n >> x >> t;
	ll r=n/x;
	if(n%x)r++;
	ll ans=r*t;
	cout << ans ;
	return 0;
}

Measured memory_bytes: 3612
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

int main() {
	int n, l;
	cin >> n >> l;
	int minabs = 200;
	int min = 200;
	vi a(n);

	REP(i, n) {
		a[i] = l + i;
		if (abs(a[i]) < minabs) {
			minabs = abs(a[i]);
			min = a[i];
		}
	}

	cout << accumulate(a.begin(), a.end(), 0) - min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<bits/stdc++.h>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,a[2005];
ll ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	forn(i,n)cin>>a[i];
	sort(a,a+n);
	forn(i,n)for(int j=i+1;j<n;j++)
	{
		int y=upper_bound(a,a+n,a[i]+a[j]-1)-a;
		ans+=y-j-1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int main() {
    int n,k,R,P,S;
    cin >> n >> k >> R >> S >> P;
    string s;
    cin >> s;
    for(int i = 0;i<n;i++)
    {
        if(i >= k && s[i]==s[i-k]){
            s[i] = ' ';
            continue;
        }
        if(s[i] == 'r')
            ans += P;
        if(s[i] == 'p')
            ans += S;
        if(s[i] == 's')
            ans += R;
    }
    cout << ans;
}


Measured memory_bytes: 512
import scala.io.{StdIn => in}
import scala.annotation.tailrec

object Main extends App {
  val Array(_, k) = in.readLine.split(" ").map(_.toInt)
  val a = in.readLine.split(" ").map(_.toInt)
  
  @tailrec
  def gcd(a:Int, b:Int):Int = {
    if(b == 0) a
    else gcd(b, a%b)
  }

  val res = a.reduce( gcd )
  val diff = a.withFilter(_ >= k).map(_ - k)

  val ans = diff match {
    case d if(d.isEmpty) => "IMPOSSIBLE"
    case d if(d.exists(_ % res == 0)) => "POSSIBLE"
    case _ => "IMPOSSIBLE"
  }

  println(ans)
}

Measured memory_bytes: 42392
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class UnionFind{
	public:
	vi parent;
	vi dist;
	UnionFind(int x=1){
		parent=vi(x,-1);
		dist=vi(x);
	}
	int find(int x){
		if(parent[x]<0)return x;
		int r=find(parent[x]);
		dist[x]+=dist[parent[x]];
		return parent[x]=r;
	}
	Def depth(int x){
		find(x);
		return dist[x];
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return -parent[find(x)];
	}
	void unite(int x,int y,Def k=0){
		k+=depth(y);
		k-=depth(x);
		k*=-1;
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(size(x)<size(y)){
			swap(x,y);
			k*=-1;
		}
		parent[x]+=parent[y];
		parent[y]=x;
		dist[y]=k;
	}
};
int main(){
	int n,q;
	while(cin>>n>>q,n){
		UnionFind T(n);
		for(int i=0;i<q;i++){
			char type;
			int x,y;
			cin>>type>>x>>y;
			x--;y--;
			if(type=='!'){
				int a;
				cin>>a;
				T.unite(x,y,a);
			}else{
				if(!T.same(x,y))printf("UNKNOWN\n");
				else printf("%lld\n",T.depth(x)-T.depth(y));
			}
		}
	}
	return 0;
}



Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
int n,s;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if((i%2)+(j%2)==1)
            {
                s++;
            }
        }
    }
    cout<<s<<endl;
}

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

template <class T>
class SegTree {
    int n;
    vector<T> data;
    T def;
    function<T(T,T)> operation;
    function<T(T,T)> update;

    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return def;
        if(a <= l && r <= b) return data[k];
        else {
            T c1 = _query(a, b, 2*k+1, l, (l+r)/2);
            T c2 = _query(a, b, 2*k+2, (l+r)/2, r);
            return operation(c1, c2);
        }
    }
  public:
    SegTree(size_t _n, T _def, function<T(T,T)> _operation, function<T(T,T)> _update)
    : def(_def), operation(_operation), update(_update) {
            n = 1;
            while(n < _n) {
                n *= 2;
            }
            data = vector<T>(2*n-1, def);
    }

    void change(int i, T x) {
        i += n-1;
        data[i] = update(data[i], x);
        while(i > 0) {
            i = (i-1)/2;
            data[i] = operation(data[2*i+1], data[2*i+2]);
        }
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T operator[](int i) {
        return data[i+n-1];
    }
};

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

    SegTree<long long> st(N, (1LL << 31) - 1, 
                            [](long long a, long long b) {return min(a,b); },
                            [](long long a, long long b) {return b; });
    for(int q = 0; q < Q; ++q) {
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0) {
            st.change(x, y);
        } else {
            cout << st.query(x, y+1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4920
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll
void solve(){
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return;
		int based[20000] = {};
		int cnt[20000] = {};
		REP(i, m) {
			int a, b;
			cin >> a >> b;
			REP(q, b) {
				int c;
				cin >> c;
				c--;
				if (b == 1) {
					based[c] += a;
				}
				else {
					cnt[c] += a;
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			int now_min = 1e9;
			REP(q, n) {
				if (i == q) continue;
				now_min = min(now_min, based[q]);
				if (now_min == 0) break;
			}
			ans = max(ans, cnt[i] + based[i] - now_min);
		}
		cout << ans + 1LL << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


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

string convertToString(vector<char>a, int size)
{
    int i;
    string s = "";
    for (i = 0; i < size; i++) {
        s = s + a[i];
    }
    return s;
}

int main() {
    string s1,s2;
    
    cin >> s1;
    cin >> s2;
    vector<char> v1(s1.begin(), s1.end());
    if (s1 == s2) {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0;i < s1.size();i++) {
        char r = v1[v1.size() - 1];
        v1.resize(v1.size() - 1);
        v1.insert(v1.begin(), r);
        string s = convertToString(v1, v1.size());
        if (s == s2) {
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
    return 0;
}
    

Measured memory_bytes: 256
n = int(input())
a = tuple(map(int,input().split()))
x = [0] * n
x1 = 0
for i in range(n):
  if i % 2 == 0:
    x1 += a[i]
  else:
    x1 -= a[i]
x[0] = x1
for i in range(1,n):
  x[i] = 2 * a[i-1] - x[i-1]
for i in range(n):
  x[i] = str(x[i])
print(' '.join(x))

Measured memory_bytes: 17308
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lli long long int
#define endl "\n"
int main()
{
string s;
lli k;
cin>>s>>k;
lli n=s.size();
if(n==1)
{cout<<k/2<<endl;return 0;}
char a=s[0];char b=s[n-1];lli x=-1;lli y=n;
for(lli i=0;i<n;i++)
{if(s[i]==a)
x=i;
else break;
}
for(lli i=n-1;i>=0;i--)
{
if(s[i]==a)
y=i;
else break;
}
lli z=x+n-y+1;
if(x>y)
{
lli ans=n*k;
ans/=2;
cout<<ans<<endl;return 0;
}
long long int ans=z;
z=z/2;
ans=(k-1)*z;x++;
z=n-y;
ans+=x/2;ans+=z/2;
//cout<<ans<<endl;
lli ans2=0;
//cout<<x<<" "<<y<<endl;
for(lli i=x;i<=y;i++)
{
if(s[i]==s[i-1])
{ans2++;i++;}
}
//cout<<ans2<<endl;
ans+=k*ans2;
cout<<ans;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T, typename U>
void print1(T Array, U size) {
  for (int i = 0; i < size; i++) {
    cout << Array[i] << " ";
  }
  cout << endl;
}

template<typename T>
void print(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

// ------------------------------------------------------------------------------------------

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

int lcm(int a, int b) {
   return a / gcd(a, b) * b;
}

signed main() {
  int n;
  cin >> n;
  cout << lcm(2, n) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<char,char> pcc;
const ll mod=998244353;
double vv;
double ff(double x,double y)
{
	double z=vv-x-y;
	return x*y*z;
}
double f(double x)
{
	double l=0.00,r=vv-x;
	while(r-l>eps)
	{
		double lmid=l+(r-l)/3.0,rmid=r-(r-l)/3.0;
		if(ff(x,lmid)<ff(x,rmid))
		l=lmid;
		else
		r=rmid;
	}
	return ff(x,r);
}
int main()
{
	
	cin>>vv;
	double l=0.00,r=vv;
	while(r-l>eps)
	{
		double lmid=l+(r-l)/3.0,rmid=r-(r-l)/3.0;
		if(f(lmid)<f(rmid))
		l=lmid;
		else
		r=rmid;
	}
	printf("%.10lf",f(r));
}

Measured memory_bytes: 256
X, N = map(int, input().split())        #asking for input
p = list(map(int, input().split()))     #asking for input
for d in range(X + 1):                  #doing loop
    for s in [-1, +1]:
        a = X + s * d
        if p.count(a) == 0:
             print(a)
             exit(0)


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

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;

    bool rev = false;
    string front, end;
    while (q--)
    {
        int t;
        cin >> t;
        if (t == 1)
            rev = !rev;
        else
        {
            int f;
            char c;
            cin >> f >> c;
            bool rf = bool(f - 1);
            if (rf == rev)
                front += c;
            else
                end += c;
        }
    }
    reverse(front.begin(), front.end());
    s = front + s + end;
    if (rev)
        reverse(s.begin(), s.end());
    cout << s << endl;
}

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

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

  int S_size = S.size();
  for(int i = 0; i < min(S_size,K); ++i){
      cout << S[i];
  }

  if(K < S_size)
    cout << "..." << endl;

  return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>

#define N 100

int main() {

  int m[N][N];
  int i, j, n, u, k, v;

  scanf("%d", &n);

  for( i=0; i<n; i++ ) {
    for( j=0; j<n; j++ ) {
      m[i][j] = 0;
    }
  }

  for( i=0; i<n; i++ ) {
    scanf("%d %d", &u, &k);
    u--;
    for( j=0; j<k; j++ ) {
      scanf("%d", &v);
      v--;
      m[u][v] = 1;
    }
  }

  for( i=0; i<n; i++ ) {
    for ( j=0; j<n; j++ ) {
      if(j) {
	printf(" ");
      }
      printf("%d", m[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> p(M); vector<string> S(M);
  REP(i, M) cin >> p[i] >> S[i];
  vector<vector<int>> tmp(N, vector<int>(2));
  REP(i, N) {
    tmp[i][0] = 0;
    tmp[i][1] = 0;
  }
  REP(i, M) {
    if(tmp[p[i] - 1][1] == 0 && S[i] == "WA") {
      tmp[p[i] - 1][0]++;
    }
    if(S[i] == "AC") {
      tmp[p[i] - 1][1] = 1;
    }
  }
  ll ans = 0;
  ll res = 0;
  REP(i, N) {
    if(tmp[i][1] == 1) {
      ans++;
      res += tmp[i][0];
    }
  }
  cout << ans << " " << res << endl;
}

Measured memory_bytes: 11520
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int a,b;
cin >>a>>b;
int c;
if(1<=b&&b<=9){
c=10*a+b;
}
else if(b<=99){
c=100*a+b;
}
else{
c=1000*a+b;
}
int d=sqrt(c);
d=d*d;
if(d==c)
cout<<"Yes"<<endl;
else
cout <<"No"<<endl;
return 0;

}

Measured memory_bytes: 256