akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, elems):
        self.parent = dict()
        self.children = dict()
        for e in elems:
            self.parent[e] = e
            self.children[e] = 1

    def root(self, e):
        if self.parent[e] == e:
            return e

        return self.root(self.parent[e])

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        if self.same(x, y):
            return

        rx, ry = self.root(x), self.root(y)
        # ry <- rx
        if self.members(ry) < self.members(rx):
            rx, ry = ry, rx

        self.children[ry] += self.children[rx]
        self.parent[rx] = ry

    def members(self, x):
        return self.children[self.root(x)]


n, m = map(int, input().split())

uf = UnionFind(range(1, n+1))
c = 0
for _ in range(m):
    x, y, z = map(int, input().split())
    if uf.same(x, y):
        continue
    else:
        c += 1
        uf.unite(x, y)

print(n - c)

Measured memory_bytes: 21988
import sys

r, c = map(int, raw_input().split())

c_sum = 0
sum_vector = [0 for i in xrange(c+1)]

for i in xrange(r):
	temp = map(int, raw_input().split())
	temp.append(sum(temp))
	for j in xrange(c):
		sum_vector[j] += temp[j]
		sys.stdout.write(str(temp[j])+" ")
	else:
		sum_vector[c] += temp[c]
		print temp[c]

for i in xrange(c):
	sys.stdout.write(str(sum_vector[i])+" ")
print sum_vector[c]

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;

    cin>>n;

    if(n==2)
    {
        cout<<1;
        return 0;
    }


    li ans=0;

    for(li i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            li tp=n;

            while(tp%i==0)
            {
                tp/=i;
            }

            if(tp%i==1)
            {
                ans++;
            }
        }
    }   

    n--;

    for(li i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(n/i==i)
            {
                ans++;
            }
            else
            {
                ans+=2;
            }
        }
    }

    ans+=2;

    cout<<ans;

    return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int x, y;
    cin >> x >> y;
    int a[7] = {1, 3, 5, 7, 8, 10, 12};
    int b[4] = {4,6,9,11};
    int c = 2;
    rep(i, 7)
    {
        if (x == a[i])
            x = 'a';
    }
    rep(i, 4)
    {
        if (x == b[i])
            x = 'b';
    }
    if(x!='a'&&x!='b') x='c';
    rep(i, 7)
    {
        if (y == a[i])
            y = 'a';
    }
    rep(i, 4)
    {
        if (y == b[i])
            y = 'b';
    }
    if(y!='a'&&y!='b') y='c';
    if (x == y)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000;
const long long maxh=1000000000;
long long H[maxn+1],h[maxn+1];
int n;
long long mH,A,B;
bool check(int k){
	for(int i=1;i<=n;++i)h[i]-=B*k;
	int t=0;
	for(int i=1;i<=n;++i)
	if(h[i]>0){
		t+=(h[i]-1)/(A-B)+1;
		if(t>k)return false;
	}
	return true;
}
	
int main(int argc,char *argv[]){
	if(argc>=2){freopen(argv[1],"r",stdin);}
	if(argc>=3){freopen(argv[2],"w",stdout);}
	scanf("%d",&n);
	scanf("%I64d%I64d",&A,&B);
	mH=-1;
	for(int i=1;i<=n;++i){
		scanf("%I64d",&H[i]);
		mH=max(mH,H[i]);
	}
	int l=1,r=mH;
	while(l<r){
		for(int i=1;i<=n;++i)h[i]=H[i];
		int m=(l+r)>>1;
		if(check(m))r=m;else l=m+1;
		//system("pause");
	}
	printf("%d",l);
	fclose(stdin);fclose(stdout);
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;

    for(int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3500
import sys
sys.setrecursionlimit(10**9)
def SCC(G):
  D=[]
  C=[len(G)-1]
  U=[1]*len(G)
  def DFS(x):
    if U[x]:
      U[x]=0
      for i in range(len(G[x])):
        DFS(G[x][i])
      D.append(x)
  
  for i in range(len(G)):
    if U[i]:
      DFS(i)
  GR=[[] for i in range(len(G))]
  for i in range(len(G)):
    for j in range(len(G[i])):
      GR[G[i][j]].append(i)
  R=[]
  U=[1]*len(G)
  def DFSR(x):
    if U[x]:
      R[-1].append(x)
      U[x]=0
      for i in range(len(GR[x])):
        DFSR(GR[x][i])
  
  for i in range(len(G)-1,-1,-1):
    if U[D[i]]:
      R.append([])
      DFSR(D[i])
  return R

N,D=map(int,input().split())
G=[[] for i in range(2*N)]
X=[list(map(int,input().split())) for i in range(N)]
for i in range(N):
  for j in range(i+1,N):
    for k in range(2):
      for l in range(2):
        if abs(X[i][k]-X[j][l])<D:
          G[k*N+i].append((l^1)*N+j)
          G[l*N+j].append((k^1)*N+i)
G=SCC(G)
C=[0]*(2*N)
for i in range(len(G)):
  for j in range(len(G[i])):
    C[G[i][j]]=i
for i in range(N):
  if C[i]==C[i+N]:
    print('No')
    exit()
print('Yes')
for i in range(N):
  if C[i]>C[i+N]:
    print(X[i][0])
  else:
    print(X[i][1])

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

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

  // ここにプログラムを追記
  int sum ;
  M=N;
  for(int i=1; i<=8; i++){
    sum+=M%10;
    M=M/10;
  }
  
  if(N%sum==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
  
      
  
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 110
#define INF 0xffffff
#define NIL 0

typedef enum {
  WHITE,
  BLACK,
} color_t;


int main(){
  int n, i, j, u ,k;
  int w[N][N]= {0}; // 0-origin w[u][v] : the weight of "node u -> node v"
  int adj[N][N];  // adj[u][i] : the adjency nodes of node u
  int v;
  int d[N], pi[N];
  color_t color[N];
  int mincost;
  int sum=0;

  for( i = 0 ; i < N ; i++){
    color[i] = WHITE;
    for( j = 0 ; j < N ; j++){
      w[i][j] = INF;
      adj[i][j] = INF;
    }
  }

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

  // initialize single source
  for( i = 0 ; i < N ; i++){
    d[i] = INF;
    pi[i]= NIL;
  }
  const int s = 0;
  d[s] = 0; // s: source
 
  // dijkstra()
  while(1){
    mincost = INF;
    for(i = 0 ; i < n ; i++){
      if( color[i] != BLACK && d[i] < mincost ){
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INF){
      break;
    }
    
    color[u] = BLACK; 
    for( i=0 ; i < n ; i++){
      v = adj[u][i];
      if( v == INF ){
	break;
      }
      if( color[v] != BLACK && (d[u] + w[u][v]) < d[v] ){
	pi[v] = u;
	d[v]  = d[u] + w[u][v];
      }
    }
    
  }

  // print
  sum = 0;
  for( i = 0 ; i < n ; i++ ){
    if( d[i] != INF ){
      printf("%d %d\n" ,i ,d[i]);
    }
  }

  return 0; // Don't forget return 0
}

Measured memory_bytes: 704
N = input()

l = [int(x) for x in str(N)]

#リストlの末尾を調査して判定
if int(l[-1])==3:
    print('bon')
elif int(l[-1])==0 or int(l[-1])==1 or int(l[-1])==6 or int(l[-1])==8:
    print('pon')
else:
    print('hon')

Measured memory_bytes: 9124
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let k: usize = read_as_vec()[0];
    if k % 2 == 0 {
        println!("-1");
        return;
    }

    let mut m: usize = 0;
    for i in 1..=k {
        m = (m * 10 + 7) % k;
        if m == 0 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 2136
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <string.h>

using namespace std;

int main(){
	string W;
	cin >> W;
	
	int count = 0;
	
	string T;
	while(true){
		cin >> T;
		if(T == "END_OF_TEXT") break;
		for(int i = 0; i < T.size(); i++){
			if(T.at(i) > 64 && T.at(i) < 91) T.at(i) += 32; 
		}
		if(T == W) {
			count++;
		}
	}
	
	cout << count << endl;
	
}





Measured memory_bytes: 3200
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    char a;
    private void solve() {
        a = next().charAt(0);

        if ('a' <= a && a <= 'z') {
            out.println("a");
        } else {
            out.println("A");
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] x = new int[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextInt();
        }
        return x;
    }

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

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

int main()
{
  int n;
  cin >> n;
  vector<vector<int> > mat(n+1,vector<int>(n+1,0));
  for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++){
	  int k;
	  cin >> k;
	  mat[i][j] = k + mat[i-1][j] + mat[i][j-1] - mat[i-1][j-1];
	}
  int ret = 0x80000000;
  for(int x1=0; x1<n; x1++)
	for(int y1=0; y1<n; y1++)
	  for(int x2=x1+1; x2<=n; x2++)
		for(int y2=y1+1; y2<=n; y2++){
		  int t = mat[y2][x2] - mat[y2][x1] - mat[y1][x2] + mat[y1][x1];
		  ret = max(ret, t);
		}
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            TreeSet<Integer> seen = new TreeSet<>();
            int n = in.nextInt();
            seen.add(-1);
            seen.add(n);
            int[] w = new int[n];
            for (int i = 0; i < n; ++i) w[in.nextInt() - 1] = i;
            long res = 0;
            for (int i = 0; i < n; ++i) {
                seen.add(w[i]);
                int prev = seen.headSet(w[i], false).last();
                int next = seen.tailSet(w[i], false).first();
                res += (w[i] - prev) * (long) (next - w[i]) * (i + 1);
            }
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 64044
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int a[105];
int n,m;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	int cnt = 0;
	int sum = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sum += a[i];
	}
	sort(a,a+n,greater<int>());
	for(int i = 0;i < n;i++){
		if(4 * m* a[i] >= sum){
			cnt++;
		}
	}
	if(cnt >= m){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[(int)2e5 + 1];
int main()
{

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n, std::greater<int>());
        long long ans = -a[0];
    for (int i = 0; i < n / 2; i++)
    {
        
        ans += a[i] * 2;
    }
    if (n % 2 == 1)
    {
        ans += a[n / 2];
    }
    cout<<ans;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    string s;cin>>s;
    ll ans=0;
    rep(i,s.size()){
        if(i%2){
            if(s[i]=='g')ans++;
        }
        else if(s[i]=='p')ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n = int(input())
vv = list(map(int, input().split()))
cc = list(map(int, input().split()))
ans = 0
for v, c in zip(vv, cc):
    if v-c > 0:
        ans += v-c
print(ans)


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

#define INF INT_MAX

using namespace std;

int main(void){
	string abc;
	bool flag = true;
	cin >> abc;
	char lastword = abc[abc.size() - 1];
	for(int i = 0;i < 2;i++){
		cin >> abc;
		if(lastword != abc[0]){
			flag = false;
			break;
		}else{
			lastword = abc[abc.size() - 1];
		}
	}
	if(flag){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define S second
#define F first
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using LL = long long;
using LD = long double;
const int mod = 1e9 + 7;
const LL N = 1e5 + 5;

using namespace std ;

LL arr[N];
int main (){
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    arr[0] = 0;
    arr[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; ++i){
        arr[i] = 1e9;
        for(int j = i - 1; j >= max(0, i - k); --j){
            arr[i] = min(arr[i], abs(h[i] - h[j]) + arr[j]);
        }
    }
    cout << arr[n - 1] << endl;
}


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

typedef long long ll;

const int MAXN = 1e5 + 5;

int N;
int a[MAXN];
vector <int> v;
int f[2 * MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", a + i);
}

void update(int x) {
	for (x += MAXN; x < 2 * MAXN; x += x & -x)
		f[x]++;
}

int get(int x) {
	int res = 0;
	for (x += MAXN; x; x -= x & -x)
		res += f[x];
	return res;
}

ll calc(int val) {
	memset(f, 0, sizeof f);
	ll res = 0;
	update(0);
	int pref = 0;
	for (int i = 0; i < N; i++) {
		pref += a[i] > val ? -1 : 1;
		res += get(pref - 1);
		update(pref);
	}
	return res;
}

int solve() {
	for (int i = 0; i < N; i++)
		v.push_back(a[i]);
	
	sort(v.begin(), v.end());
	
	int lo = 0, hi = N;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		if (2 * calc(v[mid]) > (ll)N * (N + 1) / 2)
			hi = mid;
		else
			lo = mid + 1;
	}
	
	return v[lo];
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

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

vector<int> data[3];
int main(){
  int n, m;
  cin >> n >> m;

  int a,b,c;
  while(cin >> a >> b >> c, a != 0){
    data[0].push_back(a);
    data[1].push_back(b);
    data[2].push_back(c);
  }

  int l;
  cin >> l;
  for(int i = 0;i < l;i++){
    int memo[10010] = {};
    int money[10010];

    for(int i = 0;i < m;i++){
      cin >> money[i];
    }

    for(int i = 0;i < data[0].size();i++){
      memo[data[0][i]-1] += money[data[1][i]-1] * data[2][i];
    }

    for(int i = 0;i < n;i++){
      cout << memo[i];
      if(i < n-1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}





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

bool isnum(char c)
{
  if(c>='0'&&c<='9')
    return true;
  return false;
}
int main()
{
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  if(s.length()!=a+b+1)
  {
    cout<<"No\n";
    return 0;
  }
  for(int i=0;i<s.length();i++)
  {
    if(i==a)
    {
      if(s[i]!='-')
      {
        cout<<"No\n";
        return 0;
      }
    }
    else if(!isnum(s[i]))
    {
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";


  return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
v = np.array([int(x) for x in input().split()])
c = np.array([int(x) for x in input().split()])
ans = v - c
s = 0
for i in range(n):
	if ans[i] > 0:
		s += ans[i]
print(s)

Measured memory_bytes: 21652
n=int(input())
a=list(map(int,input().split()))

b=[0]*n
for i in range(n):
    b[i]=a[i]-i-1
b=sorted(b)
mid=b[n//2]
ans=0
for i in range(n):
    ans+=abs(b[i]-mid)
print(ans)

Measured memory_bytes: 26132
#include<bits/stdc++.h>
#define for(i,n) for(int i=0;i<n;i++)
#define ford(i,n) for(int i=n;i>0;i--);
using namespace std;
int main()
{
 	int a,b;
  cin>>a>>b;
  if(a<b){
     for(i,b) cout<<a;
  }
  else for(i,a) cout<<b;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };
static const char Move[] = { 'E', 'W', 'N', 'S' };

int N, A, B, C, X;
VI Y;

int solve( int now_time, int rd, int now ) {
	if ( now == N ) {
		return now_time - 1;
	}
	if ( now_time > 10000 ) {
		return -1;
	}
	if ( Y[ now ] == rd ) {
		return solve( now_time + 1, ( A * rd + B ) % C, now + 1 );
	}
	return solve( now_time + 1, ( A * rd + B ) % C, now );
}

int main() {
	while ( ~scanf( "%d %d %d %d %d", &N, &A, &B, &C, &X ) && N && C ) {
		Y.resize( N );
		for ( int i = 0; i < N; i++ ) {
			scanf( "%d", &Y[ i ] );
		}
		printf( "%d\n", solve( 0, X, 0 ) );
	}
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int N,M,K;
  cin>>N>>M>>K;
  for(int i(0);i<=N;i++){
    for(int j(0);j<=M;j++){
      int k = i*j+(N-i)*(M-j);
      if(k == K){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	char c[55][55];
	int H, W;
	cin >> H >> W;
	
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j)
			cin >> c[i][j];
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (c[i][j] == '#') {
				if (c[i - 1][j] != '#' && c[i + 1][j] != '#' && c[i][j - 1] != '#' && c[i][j + 1] != '#') {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
from math import cos, sqrt, pi
a, b, h, m = [int(i) for i in input().split()]
mdeg = 6 * m
hdeg = 30 * (h + m/60)

deg = abs(hdeg - mdeg)
if deg >= 180:
    deg = 360 - deg

print( sqrt(a ** 2 + b ** 2 - 2*a*b*cos(deg/180 *  pi)))


Measured memory_bytes: 9452
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	double A[100000];
	vector<double> V;
	map<double, int> mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		V.push_back(A[i]);
		mp[A[i]]++;
	}
	sort(V.begin(), V.end());
	for (int i = 0; i < N; i++) {
		double X = A[i];
		int L = -1, R = N, COUNT = 0;
		COUNT += (mp[X] - 1);
		while (R - L > 1) {
			int MID = (L + R) / 2;
			if (V[MID] < X) L = MID;
			else R = MID;
		}
		cout << COUNT + R * 3 << endl;
	}
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int AS,AE,BS,BE;
  bool saki; //Aが先？
  scanf("%d%d%d%d",&AS,&AE,&BS,&BE);
  if(AS<BS){
    saki=true;
    if(AE<BS){
      printf("0\n");
      return 0;
    }
  }else{
    saki=false;
    if(BE<AS){
      printf("0\n");
      return 0;
    }
  }
  //以上入力と例外処理

  if(saki){
    if(AE>BE){
      printf("%d\n",BE-BS);
    }else{
      printf("%d\n",AE-BS);
    }
  }else{
    if(BE>AE){
      printf("%d\n",AE-AS);
    }else{
      printf("%d\n",BE-AS);
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n;
    cin>>n;
    vc<pi> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a.begin(),a.end());
    vi ans(n);
    for(int i=0;i<n;i++)
    {
        if(i<n/2) ans[a[i].second]=a[n/2].first;
        else{
            ans[a[i].second]=a[n/2-1].first;
        }
    }
    for(int i=0;i<n;i++) print(ans[i]);
}

Measured memory_bytes: 4480
from math import floor
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        if floor(dist**0.5)**2 == dist:
            cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

typedef long long ll;
const int MAX = 1e5+1;

int N;

int a[MAX];
ll fenwick[2*MAX];
 
void update(ll x, ll v) {
  x++;
  for(; x <= 2 * N; x += x & (-x))
    fenwick[x] += v;
}
 
ll sum(ll x) {
  ll res = 0;
  x++;
  for(; x; x -= x & (-x)) 
    res += fenwick[x];
  return res;
}

bool ok(int x) {
  memset(fenwick, 0, sizeof(fenwick));
  ll ans = 0, total = 0ll;
  for (int i = 0; i < N; i++) {
    total += (a[i] >= x) ? 1 : -1;
    ans += sum(total+N) + ((total >= 0) ? 1 : 0);
    update(total+N, 1);
  }
  return ans >= ((1ll*N*(N+1))/2)/2 ;
}

int main () {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];

  if (N == 1) {
    cout << a[0] << endl;
    return 0;
  }
  int l = 1, r = 1e9+1;
  while (r-l > 1) {
    int m = (l+r)/2;
    if (ok(m)) l = m;
    else r = m;
  }

  cout << l << endl;
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;
signed main(){
	int a,b,c,x=0,y=0;
	cin>>a>>b;
	f(i,a){
		cin>>c;
		x+=c;
	}
	f(i,b){
		cin>>c;
		y+=c;
	}
	cout<<x*y<<endl;
	return 0;
}



Measured memory_bytes: 3124
N, M, Q, *ABCD = map(int, open(0).read().split())

L = list(zip(*[iter(ABCD)] * 4))

def solve(A):
    if len(A) == N:
        return sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c)

    return max(solve(A + [i]) for i in range(A[-1], M + 1))

print(solve([1]))

Measured memory_bytes: 9212
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        // 解
        int ans = 0;

        // 入力
        int[] inp = ConsoleReader.ReadInt(' ');

        // 処理
        int a = inp[0];
        int b = inp[1];

        if ((b % a) == 0)
        {
            ans = a + b;
        }
        else
        {
            ans = b - a;
        }
        
        //出力
        Console.WriteLine(ans);
    }
}

class ConsoleReader
{
    // 文字列または数値の入力
    public static string ReadString() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Console.ReadLine()); }
    public static string[] ReadString(char sep) { return Console.ReadLine().Split(sep); }
    public static int[] ReadInt(char sep) { return Console.ReadLine().Split(sep).Select(x => int.Parse(x)).ToArray(); }
}



Measured memory_bytes: 13396
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int a, b, c;
  ci(a, b, c);
  co((a + b) * c / 2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long a[200010],b[200010];
int main()
{
    int n,m,i,j,k1,k2;
    long long sum,s1,s2,s;
    scanf("%d",&n);
    b[0]=0;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        b[i]=b[i-1]+a[i];
    }
    s=100000000000000000;
    for(i=1;i<n;i++)
    {
        s1=b[i];
        s2=b[n]-b[i];
        sum=fabs(s1-s2);
        s=min(s,sum);
    }
    printf("%lld\n",s);
    return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 文字列の入力
		String s = sc.next();
      String o;
      if(s.equals("Sunny")){
      	o="Cloudy";
      }else if(s.equals("Cloudy")){
      	o="Rainy";
      }else {
      	o="Sunny";
      }
		// 出力
		System.out.println(o);
	}
}

Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char c;
    cin>>c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        cout<<"vowel"<<endl;
    }
    else{
        cout<<"consonant"<<endl;
    }
}


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

int main() {
    long long n,d;
    cin >> n >> d;
    int count = 0;
    vector<long long> v(2*n);
    
    for(int i=0; i<2*n; i++){
        cin >> v[i];
    }
    
    for(int i=0; i<n; i++){
        if(v[2*i]*v[2*i] + v[2*i+1]*v[2*i+1] <= d*d) count++;
    }

    cout << count << endl;
    
	return 0;
}


Measured memory_bytes: 6416
import re

def find_a_word(w, t):
    list = []
    for e in map(lambda x: re.split(r'\s|,|\.', x.lower()), t):
        list.extend(e)
    return list.count(w.lower())

if __name__ == '__main__':
    w = input()
    t = []
    while True:
        i = input()
        if i == 'END_OF_TEXT':
            break
        else:
            t.append(i)

    print(find_a_word(w, t))



Measured memory_bytes: 6504
#include <iostream>

using namespace std;

int main()	{
  char x, y;
  cin >> x >> y;
  if (x > y)	{
    cout << ">" << endl;
  }
  else if (y > x)	{
    cout << "<" << endl;
  }
  else	{
    cout << "=" << endl;
  }
  return 0;
}

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

void solve() {
  int n;
  cin >> n;
  vector<int> k(n), l(n), r(n);
  for (int i = 0; i < n; i++) {
    cin >> k.at(i) >> l.at(i) >> r.at(i);
  }
  int64_t s = 0;
  vector<pair<int, int>> al, ar;
  for (int i = 0; i < n; i++) {
    s += min(l.at(i), r.at(i));
    if (l.at(i) > r.at(i)) {
      al.emplace_back(k.at(i), max(l.at(i), r.at(i)) - min(l.at(i), r.at(i)));
    } else {
      ar.emplace_back(n - k.at(i), max(l.at(i), r.at(i)) - min(l.at(i), r.at(i)));
    }
  }
  sort(al.rbegin(), al.rend());
  sort(ar.rbegin(), ar.rend());
  priority_queue<int> q;
  int64_t ans = s;
  int j = 0;
  for (int i = 0; i < n; i++) {
    while (j < al.size() and al.at(j).first == n - i) {
      q.push(al.at(j).second);
      j++;
    }
    if (q.empty()) continue;
    ans += q.top();
    q.pop();
  }
  while (!q.empty()) {
    q.pop();
  }
  j = 0;
  for (int i = 0; i < n; i++) {
    while (j < ar.size() and ar.at(j).first == n - i) {
      q.push(ar.at(j).second);
      j++;
    }
    if (q.empty()) continue;
    ans += q.top();
    q.pop();
  }
  cout << ans << "\n";
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve();
  }
}


Measured memory_bytes: 7508
using System;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var n = cin.ReadIntArray(5);
            int mind = 10;
            int min_index = 0;
            for (int i = 0; i < 5; i++)
            {
                if ((n[i] % 10 != 0) && (n[i] % 10 < mind))
                {
                    mind = n[i] % 10;
                    min_index = i;
                }
            }
            int sum = 0;
            for (int i = 0; i < 5; i++)
            {
                if (i == min_index || (n[i] % 10 == 0))
                {
                    sum += n[i];
                }
                else
                {
                    sum += n[i] + (10 - n[i] % 10);
                }
            }
            Console.WriteLine(sum);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}



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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;
    
    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    
    if(y == NIL) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u){
    if(u->left != NIL)inorder(u->left);
    printf(" %d",u->key);
    if(u->right != NIL)inorder(u->right);
}
void preorder(Node u){
    printf(" %d",u->key);
    if(u->left != NIL)preorder(u->left);
    if(u->right != NIL)preorder(u->right);
    
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}

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

int H, W, N, M, p[100], q[100], x, y, dist[109][109][11]; vector<pair<int, int>> X[109][109];
int dy1[6] = { 0,0,-1,-1,1,1 }, dx1[6] = { -1,1,-1,0,-1,0 };
int dy2[6] = { 0,0,-1,-1,1,1 }, dx2[6] = { -1,1,0,1,0,1 };

int solve() {
	for (int i = 1; i <= H; i++) { for (int j = 1; j <= W; j++) { for (int k = 0; k <= N; k++) dist[i][j][k] = (1 << 30); } }
	for (int i = 0; i <= N; i++) {
		queue<pair<int, int>>Q;
		Q.push(make_pair(p[i], q[i])); dist[p[i]][q[i]][i] = 0;
		while (!Q.empty()) {
			int to1 = Q.front().first, to2 = Q.front().second; Q.pop();
			for (int j = 0; j < X[to1][to2].size(); j++) {
				int p1 = X[to1][to2][j].first, p2 = X[to1][to2][j].second;
				if (dist[p1][p2][i] > dist[to1][to2][i] + 1) {
					dist[p1][p2][i] = dist[to1][to2][i] + 1;
					Q.push(make_pair(p1, p2));
				}
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			bool OK = true;
			for (int k = 1; k <= N; k++) {
				if (dist[i][j][0] >= dist[i][j][k]) OK = false;
			}
			if (OK == true) ans++;
		}
	}
	return ans;
}

int main() {
	while (true) {
		cin >> H >> W; if (H == 0) break;
		for (int i = 0; i < 109; i++) { for (int j = 0; j < 109; j++) X[i][j].clear(); }
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				for (int k = 0; k < 6; k++) {
					int fx = i, fy = j;
					if (j % 2 == 1) { fx += dx1[k]; fy += dy1[k]; }
					if (j % 2 == 0) { fx += dx2[k]; fy += dy2[k]; }
					if (fx <= 0 || fy <= 0 || fx > H || fy > W) continue;
					X[i][j].push_back(make_pair(fx, fy));
				}
			}
		}
		cin >> N;
		for (int i = 1; i <= N; i++) { cin >> p[i] >> q[i]; }
		int ret = 0;
		cin >> M;
		for (int i = 1; i <= M; i++) {
			cin >> x >> y;
			p[0] = x; q[0] = y;
			ret = max(ret, solve());
		}
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>


using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A& a, const B& b) { a = max(a, (A)b); };



int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(2+N);
	vector<bitset<5001>> dpl(2 + N), dpr(2 + N);
	REP(i, 1, 1+N) cin >> A[i];
	REP(i, 1, 2 + N) {
		dpl[i] |= dpl[i - 1];
		dpl[i] |= (dpl[i - 1] << A[i]);
		if (A[i] <= 5000) dpl[i][A[i]] = true;

		dpr[N + 1 - i] |= dpr[N + 2 - i];
		dpr[N + 1 - i] |= (dpr[N + 2 - i] << A[N + 1 - i]);
		if (A[N + 1 - i] <= 5000) dpr[N + 1 - i][A[N + 1 - i]] = true;
	}
	vector<vector<int32_t>> tbll(2 + N), tblr(2 + N);
	REP(i, 0, 2 + N) {
		tbll[i].push_back(0);
		REP(j, 0, 1 + K) if (dpl[i][j]) tbll[i].push_back(j);

		tblr[i].push_back(0);
		REP(j, 0, 1 + K) if (dpr[i][j]) tblr[i].push_back(j);
	}
	ll ans = 0;
	REP(i, 1, 1 + N) {
		bool ok = true;
		for (ll l : tbll[i-1]) {
			auto itra = lower_bound(tblr[i+1].begin(), tblr[i+1].end(), K - A[i] - l);
			auto itrb = lower_bound(tblr[i+1].begin(), tblr[i+1].end(), K - l);
			if (distance(itra, itrb) > 0) {
				ok = false;
				break;
			}
		}
		if (ok) ++ans;
	}
	PRI(ans);
	return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n;
int a[N], l[N], r[N], m[N];

int main() {

	FAST;

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	l[0] = 0;
	for (int i = 1; i <= n; i ++) {
		l[i] = __gcd(l[i - 1], a[i - 1]);
	}
	r[n + 1] = 0;
	for (int i = n; i >= 1; i --) {
		r[i] = __gcd(r[i + 1], a[i + 1]);
	}
	for (int i = 1; i <= n; i ++) {
		m[i] = __gcd(l[i], r[i]);
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		ans = max(ans, m[i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
lst = list(map(int,input().split()))
count = 0
for i in range(0,n):
    flag = 0
    minj = i
    for j in range(i,n):
        if lst[j] < lst[minj]:
            minj = j
            flag = 1
    lst[i],lst[minj] = lst[minj],lst[i]
    if flag == 1:
        count = count + 1
tmp_lst = map(str,lst)
print(' '.join(tmp_lst))
print(count)


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

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

    int l = 0;
    int r = 0;
    int ll = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '('){
            l++;
        }else{
            if(l == 0){
                ll++;
            }else{
                l--;
            }
        }
    }

    for(int i = 0; i < ll; i++){
        s = '(' + s;
    }
 
    for(int i = 0; i < l; i++){
        s = s + ')';
    }


    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int x,a,b;
	int ans=0;
	
	cin>>x>>a>>b;
	x-=a;
	x-=b*(x/b);
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while ((r = a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  vector<int> X(N-1), Y(N-1);
  int tmp = A[0];
  for (int i=0; i<N-1; i++){
    tmp = gcd(tmp, A[i]);
    X[i] = tmp;
  }
  tmp = A[N-1];
  for (int i=0; i<N-1; i++){
    tmp = gcd(tmp, A[N-i-1]);
    Y[i] = tmp;
  }
  int ans = max(X[N-2], Y[N-2]);
  for (int i=0; i<N-2; i++){
    tmp = gcd(X[i], Y[N-3-i]);
    ans = max(tmp, ans);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>

#define MAX_N 100001

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */

int N;	// 問題数 １≦N≦10^5
int M;	// 提出数 １≦M≦10^5
int AC[MAX_N] = {0};
int WA[MAX_N] = {0};

int main () {

	char S[3];
	int p, ac = 0, pn=0;

	// 個数と長さの読込み
	scanf("%d %d", &N,&M);
	// 問題の正否
	for(int i = 0; i < M; i++) {
		scanf("%d %s", &p, S);
		if(S[0] == 'A' && AC[p] == 0) ac += (AC[p] = 1);
		if(S[0] == 'W' && AC[p] == 0) WA[p] ++;
	}
	
	for(int i = 1; i <= N; i++) pn += (AC[i] == 1) * WA[i];

	printf("%d %d\n", ac, pn);

	return 0;
}

Measured memory_bytes: 896
INF = 10**10


H, W = map(int, input().split())

def next_field (a):
    ret = []
    if a[0] < H-1 :
        ret.append((a[0] + 1, a[1]))
    
    if a[1] < W-1:
        ret.append((a[0], a[1] + 1))
    
    return ret

field = {}
dist = {}
for h in range(H):
    f = input()
    for w, c in enumerate(f):
        field[(h,w)] = c
        dist[(h,w)] = INF

s = set()

if field[(0,0)] == ".":
    dist[(0,0)] = 0
else:
    dist[(0,0)] = 1

s.add((0,0))

while len(s) > 0:
    cur = s.pop()

    for nxt in next_field(cur):

        if field[cur] == field[nxt] or field[nxt] == ".":
            dist[nxt] = min(dist[nxt], dist[cur])
        else:
            dist[nxt] = min(dist[nxt], 1 + dist[cur])

        s.add(nxt)
    
print(dist[(H-1,W-1)])



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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(
                Enumerable.Range(1, 9)
                          .Select(
                              _ => Enumerable.Range(1, 9).Select(__ => _.ToString() + "x" + __.ToString() + "=" + _ * __))
                          .SelectMany(_ => _).Aggregate((a, b) => a + Environment.NewLine + b));
        }
    }
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pint;
typedef map <int,int> mapii;
typedef map <char,int> mapci;
typedef map <string,int> mapsi;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vc;
typedef set <int> si;
typedef set <ll> sll;
typedef set <char> sc;
#define pb(i) push_back(i) ;
#define ms(arr) memset(arr,0,sizeof(arr))
#define deb(x) cout<< #x <<" "<< x<<endl;
#define loop(i,n) for(int i=0;i<n;i++)
#define Loop(i,k,n) for(ll i=k;i<=n;i++)
#define testcase int t;cin>>t; while(t--)

int main() {
    int n;
    cin >> n;
    ll arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    for (int i = n - 2; i >= 0; i--) {
        if (arr[i] > arr[i + 1]) {
            arr[i]--;
            if (arr[i] > arr[i + 1]) {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import numpy as np

N, A, B = map(int, input().split())
C = A - B

E = np.array([int(input()) for _ in range(N)], dtype=np.int64)
Z = np.zeros(N, dtype=np.int64)

OK = (np.max(E) // B) + 1
NG = 0

while (OK - NG) > 1:
    m = (OK + NG)//2

    if -np.sum((-np.maximum(Z, E-m*B) // C)) <= m:
        OK = m
    else:
        NG = m

print(OK)

Measured memory_bytes: 17060
#include<iostream>
using namespace std;
int A,B,C;
main()
{
  cin>>A>>B>>C;
  cout<<A<<" "<<B<<" "<<3*C-A-B<<"\n"<<4*C-2*A-B<<" "<<C<<" "<<2*A+B-2*C<<"\n"<<A+B-C<<" "<<2*C-B<<" "<<2*C-A<<endl;
}

Measured memory_bytes: 256