akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<< #x <<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

int main(){
    int n ;
    cin >> n;
    vi a(n);
    REP(i,n){
        cin >> a[i];
    }
    int mini = 1;
    ll ans = 0;
    REP(i,n){
        int na = a[i]-1;
        int ad = na/mini;
        if(ad){
            ans += na / mini;
            a[i] = 1;
        }
        // printf("a[%d]: %d,mini: %d,sold: %d\n",i,a[i],mini,na/mini);
        // mini = max(2+(na%mini),mini);
        if(mini == a[i]) mini++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

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

	string S;
	cin >> S;

	S.at(K-1) = tolower(S.at(K-1));

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>

using namespace std;

class BShiftOnly {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        int A[N];
        for (int i = 0; i < N; ++i) {
            in >> A[i];
        }

        int cnt = 0;
        bool flg = true;
        while (flg) {
            for (int i = 0; i < N; ++i) {
                if (A[i] % 2 != 0) {
                    flg = false;
                    break;
                }
                A[i] /= 2;
            }
            if (flg) {
                ++cnt;
            }
        }

        out << cnt << endl;
    }
};


int main() {
	BShiftOnly solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int q = sc.nextInt();
        String order;
        for(int i = 0; i < q; i++){
            order = sc.next();
            if(order.equals("print")) print(str, sc.nextInt(), sc.nextInt());
            else if(order.equals("reverse")) str = reverse(str, sc.nextInt(), sc.nextInt());
            else if(order.equals("replace")) str = replace(str, sc.nextInt(), sc.nextInt(), sc.next());
        }
    }

    public static void print(String str, int a, int b){
        System.out.println(str.substring(a, b + 1));
    }

    public static String reverse(String str, int a, int b){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a; i++){
            sb.append(str.charAt(i));
        }
        for(int i = b; i >= a; i--){
            sb.append(str.charAt(i));
        }
        for(int i = b + 1; i < str.length(); i++) {
            sb.append(str.charAt(i));
        }
        return sb.toString();
    }

    public static String replace(String str, int a, int b, String p){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a; i++){
            sb.append(str.charAt(i));
        }
        sb.append(p);
        for(int i = b + 1; i < str.length(); i++){
            sb.append(str.charAt(i));
        }
        return sb.toString();
    }
}



Measured memory_bytes: 30036
#include <iostream>

using namespace std;

int b, w, n;
const int MOD = 1e9 + 7;

long long fact[500000];
long long ufact[500000];

long long inq(long long x, long long y)
{
    if (y == 0) return 1;
    long long l = inq(x, y / 2);
    if (y % 2) return l * l % MOD * x % MOD;
    return l * l % MOD;
}

long long cnk(long long n, long long k)
{
    if (k < 0 || k > n) return 0;
    return fact[n] * ufact[k] % MOD * ufact[n - k] % MOD;
}

long long ways[2][500000];
long long pref[2][500000];
long long weig[2][500000];
long long allways[500000];

int main()
{
    cin >> b >> w;
    n = b + w;
    allways[0] = 1;
    fact[0] = 1;
    ufact[0] = 1;
    cout << (int)(5e8 + 4) << "\n";
    for (int i = 1; i < n; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        ufact[i] = inq(fact[i], MOD - 2);
        ways[0][i] = cnk(i - 1, w - 1);
        ways[1][i] = cnk(i - 1, b - 1);
        pref[0][i] = (pref[0][i - 1] + ways[0][i]) % MOD;
        pref[1][i] = (pref[1][i - 1] + ways[1][i]) % MOD;
        weig[0][i] = (2 * weig[0][i - 1] + ways[0][i]) % MOD;
        weig[1][i] = (2 * weig[1][i - 1] + ways[1][i]) % MOD;
        allways[i] = (2 * allways[i - 1] + MOD + MOD - cnk(i - 1, w) - cnk(i - 1, b)) % MOD;
        //cout << allways[i] << "\n";
        long long ways_with_selection = (allways[i] - pref[0][i] - pref[1][i] + MOD + MOD) % MOD;
        cout << (ways_with_selection + 2 * weig[0][i]) * inq(inq(2, i + 1), MOD - 2) % MOD << endl;
    }
}


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

int main()
{
	int a, b;

	cin >> a >> b;
	
	if (a*b % 2 == 0) {
		cout << "Even" << endl;
	} else {
		cout << "Odd" << endl;
	}

	return 0;

}

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

int n, a, b, minn, maxx;

int main(){
	cin>>n;
	vector<int> a(n, 0), b(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>a[i]>>b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if(n % 2 == 0){
		minn = a[n/2-1]+a[n/2];
		maxx = b[n/2-1]+b[n/2];
	}
	else{
		minn=a[(n+1)/2-1];
		maxx=b[(n+1)/2-1];
	}
	cout<<maxx-minn+1<<endl;
	return 0;

}


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

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadInt();
        var B = sc.ReadInt();
        var ans = Math.Max(0, A - 2 * B);
        Console.WriteLine(ans);
    }
    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class Debug
{
    public static void Dump<T>(T[,] array)
    {
#if !DEBUG
        return;
#endif
        Console.WriteLine();
        var h = array.GetLength(0);
        var w = array.GetLength(1);

        for (int r = 0; r < h; r++)
        {
            for (int c = 0; c < w; c++)
            {
                Console.Write(array[r, c]);
                Console.Write(" ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();
    }
    public static void Dump<T>(T[] array)
    {
#if !DEBUG
        return;
#endif
        Console.WriteLine();
        Console.WriteLine(string.Join(" ", array));
        Console.WriteLine();
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void CodeFes2017qCC();

#if 1
int main()
{
	CodeFes2017qCC();
	fflush(stdout);
	return 0;
}
#endif

static void CodeFes2017qCC()
{
	std::string orgs;
	std::cin >> orgs;

	int top = 0, end = orgs.length() - 1;
	int xCount = 0;
	bool unmatch = false;
	while (top < end) {
		if (orgs[top] == orgs[end]) {
			top++;
			end--;
		}
		else if (orgs[top] == 'x') {
			xCount++;
			top++;
		}
		else if (orgs[end] == 'x') {
			xCount++;
			end--;
		}
		else {
			unmatch = true;
			break;
		}
	}
	if (unmatch) xCount = -1;
	printf("%d\n", xCount);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char a,b,c,d; cin>>a>>b>>c>>d;
  if(a==b){
    if(a!=c&&c==d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else{
    if((a==c&&b==d)||(a==d&&b==c)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    A,B = map(int, input().split())
    result = 0
    for i in range(2):
        if A > B:
            result += A
            A -= 1
        else:
            result += B
            B -= 1
    print(result)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void) {
  int n,W;
  cin >> n >> W;
  vector<int>v(n), w(n);
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }

  vector<int>dp(W*2, -1);
  dp[0] = 0;
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      if(dp[j] >= 0){
         dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
         if(j+w[i]<=W)ans = max(ans, dp[j+w[i]]);
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3176
n = int(input())
ans = []

if n % 2 == 0:
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j != n+1:
                ans.append((i,j))

else:
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            if i + j != n:
                ans.append((i,j))

print(len(ans))
for i,j in ans:
    print(i,j)


Measured memory_bytes: 68780
n=int(input())
l=[]
for _ in range(n):
    a=int(input())
    ll=[]
    for i in range(a):
        x,y=map(int,input().split())
        x-=1
        ll.append((x,y))
    l.append(ll)

ans=0
for k in range(2**n):
    f=1
    for i in range(n):
        if k>>i&1==0:
            continue
        for x,y in l[i]:
            if (k>>x&1)!=y:
                f=0
    if f:
        c=0
        for i in range(n):
            c+=k>>i&1
        ans=max(ans,c)
print(ans)


Measured memory_bytes: 42604
n = gets.to_i
vs = gets.split.map &:to_i

max = vs.max

a = Array.new(max + 1, 0)
b = Array.new(max + 1, 0)

vs.each_with_index{ |v, i|
	if i % 2 == 0 then
		a[v] += 1
	else
		b[v] += 1
	end
}

a_max = a.each_with_index.max
b_max = b.each_with_index.max

result = n - b_max[0] - a_max[0]

b_next_max = nil
a_next_max = nil

if a_max[1] == b_max[1] then
	a[a_max[1]] = 0
	b[b_max[1]] = 0
	b_next_max = b.each_with_index.max
	a_next_max = a.each_with_index.max

	result = n - [b_max[0] + a_next_max[0], a_max[0] + b_next_max[0]].max
end

puts result


Measured memory_bytes: 12708
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] counts = new int[10][10];
        for (int i = 1; i < N+1; i++) {
            int btm = i % 10;
            int top = -1, x = i;
            while(-0 < x){
                top = x % 10;
                x /= 10;
            }
            counts[top][btm]++;
        }

        int ans = 0;
        for (int i = 0; i < 10 ; i++) {
            for (int j = 0; j < 10; j++) {
                ans += counts[i][j] * counts[j][i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		long l = 1l*a*b;
		if(l<=0){
			System.out.println("Zero");
			return;
		}
		if(a>0 && b>0){
			System.out.println("Positive");
			return;
		}
		if((a+b)%2==0){
			System.out.println("Negative");
		}else{
			System.out.println("Positive");
		}
	}
}

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

using namespace std;

int main() {
    int k;
    cin >> k;
    if (k & 1) {
        cout << (k / 2) * (k / 2 + 1);
    }
    else {
        cout << (k / 2) * (k / 2);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{   
    int a;
    int b;
    cin >> a >>b;
    while (a!=0 && b!=0){
        for (int i = 0; i < a; i++){
            for (int j =0; j<b; j++){
                cout << "#" ;
            }cout << endl; 
             
        }cout << endl;
    cin >> a >>b;
    }
  

    return 0;
}



Measured memory_bytes: 3072
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	string o,e;
	cin >> o >> e;
	string ans="";
	int x=0;
	for(int i=0;i<o.size()+e.size();i++){
		if(i%2==0){
			ans+=o[x];
		}else{
			ans+=e[x];
			x++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

template <int N>
struct union_find {
    int par[N];
    union_find() { for (int i = 0; i < N; ++i) par[i] = -1; }

    int find(int v) {
        if (par[v] < 0) return v;
        return par[v] = find(par[v]);
    }

    bool unite(int x, int y) {
        int xx = find(x), yy = find(y);
        if (xx == yy) return false;
        if (par[xx] < par[yy]) {
            par[xx] += par[yy];
            par[yy] = xx;
        } else {
            par[yy] += par[xx];
            par[xx] = yy;
        }
        return true;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

struct edge {
    int u, v, cost;
    char label;
    edge() {}
    edge(int u, int v, int cost, char label): u(u), v(v), cost(cost), label(label) {}

    bool operator < (const edge& o) const {
        return cost == o.cost ? label < o.label : cost < o.cost;
    }
};

int N, M, K;
vector<edge> edges;

pair<int, int> kruskal(vector<edge> es, int add_a) {
    for (edge& e : es)
        if (e.label == 'A') e.cost += add_a;

    union_find<200> uf;

    sort(begin(es), end(es));

    int weight_sum = 0, a_count = 0, b_count = 0;

    for (const edge& e : es) {
        if (uf.same(e.u, e.v)) continue;
        (e.label == 'A' ? a_count : b_count)++;
        uf.unite(e.u, e.v);
        weight_sum += e.cost;
    }

    if (a_count + b_count < N-1) return make_pair(-1, -1);
    return make_pair(weight_sum, a_count);
}

int solve() {

    auto pr = kruskal(edges, 0);

    if (pr.first == -1 && pr.second == -1) return -1;

    int l = -101010, r = 101010;
    while (l+1 < r) {
        int a = (l + r) / 2;

        pair<int, int> pr = kruskal(edges, a);

        ((pr.second < K) ? r : l) = a;
    }

    auto res_l = kruskal(edges, l);
    auto res_r = kruskal(edges, r);

    return (res_r.second <= K && K <= res_l.second) ? res_l.first - l * K : -1;
}


int main(void) {
    while (true) {
        cin >> N >> M >> K;
        edges.clear();
        if (N == 0 && M == 0 && K == 0) break;
        for (int i = 0; i < M; ++i) {
            int u, v, cost; char label;
            cin >> u >> v >> cost >> label; --u; --v;
            edges.emplace_back(u, v, cost, label);
        }

        cout << solve() << endl;
    }
    return 0;
}



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


int main (int argc, char const *argv[])
{
    string N;
    cin>>N;
    
    if (N[0]==N[2]) {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int r,g,b,n;
  cin >> r >> g >> b >> n;
  int cnt = 0;
  int R = n/r,G;
  for(int i=0;i<=R;i++){
    G = (n - i*r)/g;
    for(int j=0;j<=G;j++){
      if((n-i*r-j*g)%b==0){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  vector<int> sums(N + 1);
  sums[0] = 0;
  for (int i = 0; i < N; ++i) {
    cin >> W[i];
    sums[i + 1] = sums[i] + W[i];    
  }

  int ans = 1e9;
  for (int i = 0; i <= N; ++i) {
    int left = sums[i];
    int right = sums[N] - left;
    ans = min(ans, abs(left - right));
  }

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



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

int puz[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void empty(int *,int *);
int dfs(int,int,int,int,const int);
int cal();
void swap(int *,int *);


int main() {
    int i,j,ans,x,y,l;
    
    //puzzle input
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) scanf("%d",&puz[i][j]);
    }
    
    
    empty(&x,&y);
    for(l=0; l<100; l++) {
        //copy
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
        }
        
        //dfs
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1) {
            printf("%d\n",ans);
            break;
        }
        
        //copy
        for(i=0; i<3; i++) {
            for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
        }
        
        //error
        ans = -1;
        if(l==99) printf("%d\n",ans);
    }
    
    //ans output
    //printf("%d\n",ans);
    
    return 0;
}


void empty(int *x,int *y) {
    int i,j;
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            if(!puz[i][j]) {
                *x = j;
                *y = i;
                return;
            }
        }
    }
}


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


int cal() {
    int i,a,sum=0;
    
    for(i=0; i<9; i++) {
        a = puz[i/3][i%3];
        if(a) {
            a--;
            sum += abs(i/3 - a/3) + abs(i%3 - a%3);
        }
    }
    
    return sum;
}


int dfs(int x,int y,int p,int dep,const int lim) {
    int i,h,nx,ny,res;
    
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1;
    
    for(i=0; i<4; i++) {
        nx = x+dx[i];
        ny = y+dy[i];
        
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;
        
        swap(&puz[y][x],&puz[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;
        
        swap(&puz[y][x],&puz[ny][nx]);
    }
    
    return -1;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main()
{
  string s , t;
  cin >> s >> t;
  int a=0;
  for(int i=0;i < s.size();i++)
  {
    if(!(s[i]==t[i]))
    {
      a++;
    }
  }
  cout << a;
  return 0;
}

Measured memory_bytes: 3904
N = int(input())
W = [input() for i in range(N)]

for i in W:
    if W.count(i) > 1:
        print('No')
        exit()

for i in range(1, N):
    if W[i - 1][-1] != W[i][0]:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 9176
#include <stdio.h>

int main(void){
    int r,c,map[101][101],i,o,sum;
    scanf("%d %d",&r,&c);
    for(i=0;sum=0,i<r;i++){
        for(o=0;o<c;o++){
            scanf("%d",&map[i][o]);
            sum+=map[i][o];
        }
        map[i][o]=sum;
    }
    for(i=0;sum=0,i<c+1;i++){
        for(o=0;o<r;o++)
            sum+=map[o][i];
        map[o][i]=sum;
    }
    for(i=0;i<r+1;i++)
        for(o=0;o<c+1;o++)
            printf("%d%s",map[i][o],o==c?"\n":" ");
    return 0;
}

Measured memory_bytes: 640
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x = int(readline())
    for i in range(x, 10 ** 10 + 1):
        is_prime = True
        for j in range(2, int(i ** 0.5 + 1)):
            if i % j == 0:
                is_prime = False
                break
        if is_prime:
            print(i)
            exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int ans=3*pow(n,2);
	cout<<ans<<endl;



	return 0;
}


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

int main(){
    string s;
    cin>>s;
    int a=s[0]-'0';
    int b=s[1]-'0';
    int c=s[2]-'0';
    int d=s[3]-'0';
    if(a+b+c+d==7){cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl; return 0;}
    if(a-b+c+d==7){cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl; return 0;}
    if(a-b-c+d==7){cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl; return 0;}
    if(a-b-c-d==7){cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl; return 0;}
    if(a+b+c-d==7){cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl; return 0;}
    if(a+b-c-d==7){cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl; return 0;}
    if(a-b+c-d==7){cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl; return 0;}
    if(a+b-c+d==7){cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl; return 0;}
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

res = True

for i in range(N - 1):
    if H[i + 1] > H[i]:
        H[i + 1] -= 1
        
    if H[i + 1] < H[i]:
        res = False
        break

if res:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20612
///******* In the name of Allah *******///

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

int main()
{
    int a,b,m,n,i,j,k,l,cnt = 0,div;
    char c[113];
    cin>>c;
    l = strlen(c);
    div = l/2;
    for(i=0,j=l-1;i<div;i++,j--)
    {
        if(c[i]!=c[j])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

int main() {
  std::ios::sync_with_stdio(false);

  int n, sum = 0;
  cin >> n;
  n+=2;
  vector<int> A(n);
  rep(i,n-2) cin >> A[i+1];
  rep(i,n-1) sum += abs(A[i+1] - A[i]);
  rep(i,n-2) cout << sum - (abs(A[i] - A[i+1]) + abs(A[i+1] - A[i+2])) + abs(A[i] - A[i+2]) << endl;

  return 0;
}


Measured memory_bytes: 2296
s = list(input())
s1 = s[0:int((len(s)-1)*0.5)]
s2 = s[int((len(s)+3)*0.5)-1:len(s)]
s_o =s[::-1]
s1_o =s1[::-1]
s2_o =s2[::-1]
# print("so...{}/s1o....{}/s2o...{}/s...{}/s1...{}/s2...{}/".format(s_o, s1_o, s2_o, s, s1, s2))
if s1_o == s1:
    if s2_o == s2:
        if s_o == s:
            yn = "Yes"
        else:
            yn = "No"
    else:
        yn = "No"
else:
    yn = "No"
print(yn)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll N, D;
    cin >> N >> D;
    ll res = 0;
    REP(i, N){
        ll X, Y;
        cin >> X >> Y;
        if(X*X+Y*Y<=D*D) res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N, K;
	cin >> N >> K;
	int ans = 1;
	int M = INT_MAX;
	for (int i = 0; i <= N; i++) {
		rep(j, i) {
			ans *= 2;
		}
		rep(j, N - i) {
			ans += K;
		}
		//cout << ans << ' ';
		M = min(M, ans);
		ans = 1;
	}
	cout << M << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<=(b);++(i))
#define rep(i, n)  FOR(i,0,n-1)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define ll long long
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;


int main() {
	
	int a,b;cin>>a>>b;

	if(a+b==15) cout << '+' << endl;
	else if(a*b==15) cout << '*' << endl;
	else cout << 'x' << endl;
	return 0;
}

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

struct edge{
public:
    int to,cost;
};

vector<edge> G[100001];
int n;
bool passed[100001];
const int mod=10007;

vector<int> p;
void dfs(int s,bool first,int from){
    if(!first)
        passed[s]=true;
    for(int i = 0; i < G[s].size(); i++){
        edge &e=G[s][i];
        if(passed[e.to]||e.to==from)
            continue;
        p.push_back(e.cost);
        dfs(e.to,false,s);
        break;
    }
}

int main(){
    while(cin>>n&&n!=0){
        for(int i = 0; i < n; i++)
            G[i].clear();
        fill(passed,passed+n,false);
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                int to,cost;
                cin>>to>>cost;
                edge e;
                e.to=to;e.cost=cost;
                G[i].push_back(e);
            }
        }
        int mul=1;
        for(int i = 0; i < n; i++){
            if(passed[i])
                continue;
            p.clear();
            dfs(i,true,-1);
            // ツづづ個陛督づーツ催ュツづゥツつゥ
            int maxNum=-1;
            int sum=0;
            int cnt=0;
            for(int j = 0; j < p.size(); j++){
                if(maxNum==-1||maxNum<p[j]){
                    maxNum=p[j];
                    cnt=1;
                }
                else if(maxNum==p[j])
                    cnt++;
            }
            mul*=cnt;
            mul%=mod;
        }
        cout<<mul%mod<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<long long int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  long long int sab = 0;
  while (1) {
        bool plus = find(p.begin(), p.end(), x + sab) != p.end();
    bool minus = find(p.begin(), p.end(), x - sab) != p.end();
    if (x > 0) {
      if (minus == false) {
        cout << x - sab << endl;
        return 0;
      } else if (plus == false) {
        cout << x + sab << endl;
        return 0;
      }
    } else {
      if (plus == false) {
        cout << x - sab << endl;
        return 0;
      } else if (minus == false) {
        cout << x - sab << endl;
        return 0;
      }
    }
    sab++;
  }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char str[20];
	while(~scanf("%s",str))
	{
		for(int i=0;i<5;i++)
		{
			printf("%c",str[i]);
		}
		printf(" ");
		for(int i=6;i<13;i++)
			printf("%c",str[i]);
		printf(" ");
		for(int i=14;i<19;i++)
			printf("%c",str[i]);
		printf("\n");
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;
int main()
{
    int n;
    cin>>n;
   string s;
   cin>>s;
   int sum=0;
   int t=count(s.begin(),s.end(),'R');
   t=t-1;
   for(int i=0;i<=n;i++)
   {
       if(s[i]=='R')
       {
           if(i>t) sum++;
       }
   }
   cout<<sum<<endl;


   return 0;
}


Measured memory_bytes: 3752
#include<stdio.h>
int main(){
	int k;
	scanf("%d",&k);
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	printf("%d",a[k-1]);
} 

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
int n,i,c;
  scanf("%d",&n);
  if(n%2==1) printf("No");
 
  else{
  char b[n];
  scanf("%s",b,n);
    c=0;
    for(i=0;i<n/2;++i)
    {
     if(b[i]==b[i+n/2]) c++;
    }
   if(c==n/2) printf("Yes");
    else printf("No");
  }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t,s1;
    cin>>s>>t;
    int n=s.length();
    if(t==s){
        cout << "Yes"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        s=s[n-1]+s.substr(0,n-1);
        if(t==s){
        cout << "Yes"<<endl;
        return 0;
        }
    }
    cout << "No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<ll> a(N), b(M);
    for(int i = 0; i < N; i++) cin >> a[i];
    for(int i = 0; i < M; i++) cin >> b[i];
    auto c = atcoder::convolution(a, b);
    for(auto tmp : c) {
        cout << tmp << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 27308
X, N = map(int, input().split())
p_list = list(map(int, input().split()))

if N == 0: 
   print(X)
else:
   for i in range(0,100):
       if not X-i in p_list:
           print(X-i)
           break
       elif not X+i in p_list:
           print(X+i)
           break

Measured memory_bytes: 9180
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin
import math

# 標準入力をスペースで区切って、intに変換 listに収納
N = int(stdin.readline())
H = [int(x) for x in stdin.readline().rstrip().split()]


cnt = 0
max_cnt = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt+=1
    else:
        if max_cnt < cnt:
            max_cnt = cnt
        cnt=0
if H[N-1]  <= H[N-2]:
    if max_cnt <= cnt:
        max_cnt = cnt
print(max_cnt)


Measured memory_bytes: 14408
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cstring>

using namespace std;

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

const ll INF = LLONG_MAX;
struct edge{int from; int to; ll cost;};
edge es[MAX_N*MAX_N];
ll d[MAX_N];
bool neg[MAX_N];
int V,E;

void shortest_path(int s){
    for(int i = 0; i < V; i++) d[i] = INF;
    d[s] = 0;
    //while(true){
    for(int i = 0; i < V-1; i++){
        bool update = false;
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
}

bool find_negative_loop(){
    //memset(d, 0, sizeof(d));
    for(int i = 0; i < V; i++){
        for(int j = 0; j < E; j++){
            edge e = es[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                //if(i == V-1) return false;
                neg[e.to] = true;
            }
            if(neg[e.from]) neg[e.to] = true;
        }
    }
    return true;
}

int main(){
    int N,M;
    cin >> N >> M;
    REP(i,M){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        es[i].from = a;
        es[i].to = b;
        es[i].cost = -c;
    }
    V = N;
    E = M;
    shortest_path(0);
    ll ans = -d[N-1];
    bool sec;
    find_negative_loop();
    sec = !neg[N-1];
    if(!sec)
        cout << "inf" << endl;
    else{
        cout << ans << endl;
    }
     
    return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
junretsu = sorted(set(itertools.permutations( P )))

#print(junretsu)
count = 1
a = 0
for x in junretsu:
    if(list(x) == P):
        a = count
    count += 1
#print(a)
count = 1
b = 0
for x in junretsu:
    if(list(x) == Q):
        b= count
    count += 1
#print(b)
print(abs(b-a))

Measured memory_bytes: 9964
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fr first
#define se second 
signed main()
{
	CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;		
	int a,b;
	cin>>a>>b;
	if(a<=9 and b<=9)cout<<a*b<<endl;
	else
		cout<<-1<<endl;
}


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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


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

    while (true) {
        int N;
        cin >> N;
        if (N == 0) { break; }

        VVI day_human(31);
        FOR(i, 0, N) {
            VI v;
            int x;
            cin >> x;
            FOR(j, 0, x) {
                int day;
                cin >> day;
                day_human[day].emplace_back(i);
            }
        }

        vector<LL> dp(N);
        FOR(i, 0, N) {
            dp[i] = (1LL << i);
        }

        int ans = -1;
        FOR(day, 0, day_human.size()) {
            FOE(h1, day_human[day]) {
                FOE(h2, day_human[day]) {
                    dp[h1] |= dp[h2];
                }
                if (dp[h1] == ((1LL << N) - 1)) {
                    ans = day;
                    break;
                }
            }
            if (ans != -1) {
                break;
            }
        }
        print(ans);
    }

    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    reverse(res.begin(),res.end());
    return res;
}

ll a[550];

int main() {
  ll n,k;cin>>n>>k;
  rep(i,n) cin>>a[i];
  ll sum = 0;
  rep(i,n) sum+=a[i];
  vector<ll> vec = enum_divisors(sum);
  P b[550];
  rep(i,vec.size()) {
    rep(j,n) b[j]=P(a[j]%vec[i],vec[i]-(a[j]%vec[i]));
    ll minus=0;
    sort(b,b+n);
    int id=0;
    while(1) {
      if(minus+b[id].first<=k) {
	minus+=b[id].first;
	id++;
      } else {
	minus=0;
	break;
      }
    }
    bool ok=true;
    for(int id2=id;id2<n;id2++) {
      minus+=b[id2].second;
      if(minus>k) {
	ok=false;
	break;
      }
    }
    if(ok) {
      cout<<vec[i]<<endl;
      return 0;
    } else {
      continue;
    }
  }
}


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

signed main() {
    string s;
    cin>>s;
    int c=0;
    int i=0;
    while(i<3)
    {
        int t=0;
        while(s[i]=='R')
        {
            t++;
            i++;
        }
        if(s[i]!='R')
        i++;
        c = max(c,t);
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 3592
require 'complex'
a,b = gets.chomp.split(" ")
str = a+b
str1 = Math.sqrt(str.to_i)
str2 = Math.sqrt(str.to_i)
str2 = str2.floor
if str1 == str2 then
  print("Yes\n")
else
  print("No\n")
end

Measured memory_bytes: 1916
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }
    else if(a==b){
        cout<<"a == b"<<endl;
    }
    else if(a>b){
        cout<<"a > b"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
using namespace std;
void t(int a[],int n)
{
    int i;
    for(int i=0;i<n;i++)
    {
        if(i>0)
            printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
}
void an(int a[],int n)
{
    int i,j,v;
    for(int i=1;i<n;i++)
    {
        v=a[i];
        j=i-1;
        while(j>=0 &&a[j]>v)
        {
            a[j+1]=a[j];
            j--;

        }
        a[j+1]=v;
        t(a,n);
    }
}
int main()
{
    int n,i,j;
    int a[100];
    scanf("%d",&n);
    for(i=0;i<n;i++)

        scanf("%d",&a[i]);
    t(a,n);
    an(a,n);
    return 0;
}

Measured memory_bytes: 2712
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-13;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
vector<int>g[110000];
int dp[110000];
int ret=0;
int dfs(int a,int b){
	int d[30];
	for(int i=0;i<30;i++)d[i]=0;
	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		int tmp=dfs(g[a][i],a);
		for(int j=0;j<30;j++){
			if(tmp&(1<<j))d[j]++;
		}
	}
	int num=0;
	for(int i=29;i>=0;i--){
		if(d[i]>=2)break;
		if(d[i]==0)num=i;
	}
	ret=max(ret,num);
	int to=(1<<num);
	for(int i=num+1;i<30;i++){
		if(d[i])to+=(1<<i);
	}
	return to;
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	dfs(0,-1);
	printf("%d\n",ret);
}

Measured memory_bytes: 18432
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, x;
  cin >> n >> x;
  int coord = 0;
  int ans = 1;
  for(int i = 0, temp; i < n; ++i){
    cin >> temp;
    coord += temp;
    if(coord > x) break;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
	const ll mod = 1000000007;
  int N, M;
	cin >> N >> M;
	vector<int> S(N), T(M);
	rep(i, N) cin >> S[i];
	rep(i, M) cin >> T[i];

	vector<vector<ll>> sum(N+1, vector<ll>(M+1, 0));
	// sum[i][j]: N=i, M=jの時の答え ただし，()は除く

	// 初期条件を満たす形で初期化済み

	for(int i=1; i<N+1; i++) {
		for(int j=1; j<M+1; j++) {
			// sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1] + dp[i][j]
			// dp[i][j] は S[i-1]==T[j-1] の時 = sum[i-1][j-1]+1, else 0
			sum[i][j] = (sum[i-1][j] + sum[i][j-1])%mod;
			sum[i][j] %= mod;
			sum[i][j] -= sum[i-1][j-1];
			sum[i][j] %= mod;
			if(S[i-1]==T[j-1]) {
				sum[i][j] += (sum[i-1][j-1]+1)%mod;
				sum[i][j] %= mod;
			} 
		}
	}

	ll res = (sum[N][M]+1)%mod; // 除外していた()を加えて答え
	if(res<0) res += mod;
	cout << res << endl; 

  return 0;
}

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

typedef long long ll;

ll n;
ll a[70000], b[70000];

int main(){
  while(cin >> n, n){
    ll sumA = 0;
    ll sumB = 0;

    for(int i = 0; i < n; i++){
      cin >> a[i];
      sumA += a[i];
    }
    for(int i = 0; i < n - 1; i++){
      cin >> b[i];
      sumB += b[i];
    }
    sort(b, b + (n - 1));

    ll ans = 0;

    for(int i = 1; i <= n; i++){
      ans = max(ans, i * (sumA + sumB));
      sumB -= b[i - 1];
    }
    cout << ans << endl;
  }
}

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

class Program{
    static void Main(string[] args){
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        string s_ = String.Concat(s.OrderBy(a => a));
        string t_ = String.Concat(t.OrderByDescending(a => a));
        string ans;
        if(String.Compare(s_, t_) < 0){
            ans = "Yes";
        }else{
            ans = "No";
        }
        Console.WriteLine(ans);
    }
}


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  i64 n, a, b;
  cin >> n >> a >> b;

  vector<i64> x(n+5);
  rep(i, n) {
    cin >> x[i];
  }

  i64 sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    i64 diff = x[i+1] - x[i];
    sum += min(a * diff, b);
  }

  cout << sum << "\n";

  return 0;
}

Measured memory_bytes: 1024