akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;


int main() {
	long long e = 1000000007;
	int n;
	cin >> n;
	long long num[101], a[101], b[101];
	num[1] = 4;
	num[2] = 16;
	num[3] = 61;
	num[4] = 230;
	a[1] = 1;
	a[2] = 4;
	b[1] = 0;
	b[2] = 1;
	for (int i = 5; i <= n; i++) {
		num[i] = 4 * num[i - 1] - 3 * num[i - 4] - 3 * num[i - 3] + (a[i - 3] + b[i - 3]);
		a[i - 2] = num[i - 3] - b[i - 3];
		b[i - 2] = num[i - 4] - a[i - 4];

		if (num[i] >= e) {
			long long m = num[i] % e;
			num[i] = m;
		}
		if (a[i-2] >= e) {
			long long m = a[i-2] % e;
			a[i-2] = m;
		}
		if (b[i-2] >= e) {
			long long m = b[i-2] % e;
			b[i-2] = m;
		}
		while (num[i] <0) {
			num[i] += e;
		}
		if (a[i - 2] <0) {
			a[i - 2] += e;
		}
		if (b[i - 2] <0) {
			b[i - 2] += e;
		}
	}
	cout << num[n] << endl;
	return 0;

}

Measured memory_bytes: 256
array = [[0, 0, 0]]

N = $stdin.gets.chomp.to_i
N.times do |_|
    array.push($stdin.gets.chomp.split(' ').map(&:to_i))
end

(array.length - 1).times do |i|
    p_prev = array[i]
    p_next = array[i + 1]
    duration = p_next[0] - p_prev[0]
    distance = (p_next[1] - p_prev[1]).abs + (p_next[2] - p_prev[2]).abs
    remain = duration - distance
    if remain < 0 || remain % 2 == 1
        print 'No'
        exit
    end
end

print 'Yes'


Measured memory_bytes: 9468
#include <cstdio>
#include <cassert>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int main() {
    lli a, b;
    int c = 0;
    scanf("%lld%lld", &a, &b);
    for (; a <= b; a <<= 1) {
        ++c;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N,K;
		String S;
		Scanner sc=new Scanner(System.in);	
		N=sc.nextInt();
		S=sc.next();
		K=sc.nextInt();
		
		String temp=S.substring(K-1,K);
		for(int i=0;i<N;i++) {
			if(!S.substring(i,i+1).equals(temp)) {
				S=S.replace(S.substring(i,i+1), "*");
			}
		}
			
		System.out.println(S);
	}
}


Measured memory_bytes: 21076
#include<iostream>

using namespace std;

int main() 
{
	int n[5];

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

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

Measured memory_bytes: 3616
N = int(input())
*A, = map(int, input().split())

def partition(A, p, r):
    x = A[r]
    i = p
    
    for j in range(p, r):
        if A[j] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[i], A[r] = A[r], A[i]
    
    return i

j = partition(A, 0, N - 1)
print(*(str(x) if i != j else "[%d]" % x for i, x in enumerate(A)))


Measured memory_bytes: 16388
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1],br[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	ll ff=1;
	for(i=1;i<=n;i++){
		if(ar[i]!=i){
			ff=0;break;
		}
	}
	if(ff){
		cout<<"YES";return 0;
	}
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			for(k=1;k<=n;k++){
				br[k]=ar[k];
			}
			swap(br[i],br[j]);
			ll flg=1;
			for(k=1;k<=n;k++){
				
				if(br[k]!=k){
					flg=0;
					break;
				}
			}
			if(flg){
				cout<<"YES";return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.question", "r", stdin );
	int n, m;

	while ( (cin >> n >> m) && n && m ){
		vector <vector <int> > t (n, vector <int> (m, 0 ) );
 		int i,j;

		for (i = 0; i < n; ++i){
			for (j = 0; j < m; ++j){
				cin >> t[i][j];
			} // end for
		} // end for

		multimap<int, int, greater<int> > rank;

		for (j = 0; j < m; ++j ){
			int sum = 0;
			for (i = 0; i < n; ++i){
				sum += t[i][j];
			} // end for
			rank.insert (make_pair (sum, j ) );
		} // end for

		multimap<int, int, greater<int> >::iterator it = rank.begin();
		for (j = 0; j < m && it != rank.end(); ++j, ++it){
			cout << ((*it).second + 1);
			if (j != m - 1){
				cout << ' ';
			} // end if
		} // end for
		cout << endl;
	} // end loop
		
	return 0;
}

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

#include <atcoder/all>
typedef long long lint;
using namespace std;
using namespace atcoder;

int n, d;
vector<int> x, y;

int main() {
    cin >> n >> d;
    x.resize(n);
    y.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    // ts[i]:true<=>x[i]を使う
    two_sat ts(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (abs(x[i] - x[j]) < d) {
                ts.add_clause(i, false, j, false);
            }
            if (abs(x[i] - y[j]) < d) {
                ts.add_clause(i, false, j, true);
            }
            if (abs(y[i] - x[j]) < d) {
                ts.add_clause(i, true, j, false);
            }
            if (abs(y[i] - y[j]) < d) {
                ts.add_clause(i, true, j, true);
            }
        }
    }
    if (ts.satisfiable()) {
        cout << "Yes" << endl;
        auto res = ts.answer();
        for (int i = 0; i < n; i++) {
            int ans = res[i] ? x[i] : y[i];
            cout << ans << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3696
#include<stdio.h>
int main(){
	int a,b,c[101],d[101]={0},z[101][101]={0},e,f,g[101];
	scanf("%d %d",&a,&b);
	for(e=0;e<b;e++){
		scanf("%d",&c[e]);
	}
	for(e=0;e<b;e++){
		for(f=0;f<a;f++){
			scanf("%d",&g[f]);
		if(g[f]==c[e]){
			z[e][f]=1;
		d[f]+=1;
		}
		}
		for(f=0;f<a;f++){
			if(z[e][f]!=1){
				d[c[e]-1]++;
			}
			}
	}
	for(e=0;e<a;e++){
		printf("%d\n",d[e]);
	}
	return 0;	
		
	}

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

int main(void){

    int N,K,D;
    cin>>N;

    K=N/4;
    D=N/7;

    for(int i=0;i<=K;i++){
        for(int j=0;j<=D;j++){
            if(N==4*i+7*j){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        
    }

    
    cout<<"No"<<endl;

    return 0;
}

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

int main(){
    int n ; cin >> n ;
    int ans = 0 ;
    for(int i=1;i*i<=n;i++){
        int b = i ;
        for(int j=0;j<20;j++){
            b *= i ;
            if(b>n) break ;
            if(b>ans) ans = b ;
        }
    }
    cout << ans << endl ;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000

int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a >= 6 && a <= 12) cout << b / 2 << endl;
	else if (a <= 5) cout << 0 << endl;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int n;
  	cin >> n;
    int m = n;
    int sum = 0;
    while(m!=0){
        sum += m%10;
        m = (m - m%10)/10;
    }
    if (n%sum) cout << "No" << endl;
    else cout << "Yes" << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
s = input()
if len(s)%2 != 0:
  print('No')
else:
  for i in range(len(s)):
    if i % 2 == 0 and s[i] != 'h':
      print('No')
      break
    elif i % 2 == 1 and s[i] != 'i':
      print('No')
      break
  else:
    print('Yes')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,d,x,y;
  int count=0;
  cin>>n>>d;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    if(x<0) x=x*-1;
    if(y<0) y=y*-1;
    if(d*d>=x*x+y*y) count++;
  }
  cout<<count<<endl;
  
}


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

using namespace std;

using ll = long long;

ll Solve() {
    ll n, k;
    cin >> n >> k;

    int len = log2(k) + 1;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] != 0) len = max(len, (int)log2(a[i]) + 1);
    }

    vector<ll> max_f(len + 1);
    vector<vector<ll>> f(len + 1, vector<ll>(2));
    for (ll i = 0; i < len; ++i) {
        ll value = 1ll << i;
        for (ll j = 0; j < n; ++j)
            f[i][!(a[j] >> i & 1)] += value;
        max_f[i] = max(f[i][0], f[i][1]);
    }

    for (int i = 1; i < len; ++i) max_f[i] += max_f[i - 1];

    ll res = 0, k_sum = 0;
    for (ll i = len - 1; 0 <= i; --i) {
        if (k >> i & 1) { // k の i ビット目が 1
            // 0 を選んで i + 1 ビット目以降は最適な方法を選ぶ
            ll score = k_sum + f[i][0];
            if (0 < i) score += max_f[i - 1];
            res = max(res, score);

            k_sum += f[i][1];
        }
        else { // k の i ビット目が 0
            k_sum += f[i][0];
        }
    }

    return max(res, k_sum);
}

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

    cout << Solve() << endl;

    return 0;
}


Measured memory_bytes: 1024
W,H,x,y,r=input().split()
W=int(W)
H=int(H)
x=int(x)
y=int(y)
r=int(r)
if H>=y+r and W>=x+r and 0<=y-r and 0<=x-r:
        print("Yes")
else:
        print("No");



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

int main()
{
	int n, l;
	while (cin >> n >> l, n | l) {
		vector<char> d(n);
		vector<int> p(n);
		for (int i = 0; i < n; i++) {
			cin >> d[i] >> p[i];
		}
		for (int t = 1; ; t++) {
			bool end = true;
			int L = -1, R = -1;
			vector<int> pos(l), num(l);
			for (int i = 0; i < n; i++) {
				if (p[i] == -1) continue;
				if (d[i] == 'L') {
					p[i]--;
				}
				else {
					p[i]++;
				}
				if (p[i] == 0) {
					L = i + 1;
					p[i] = -1;
				}
				else if (p[i] == l) {
					R = i + 1;
					p[i] = -1;
				}
				else {
					end = false;
					if (pos[p[i]]) swap(d[num[p[i]]], d[i]);
					pos[p[i]]++;
					num[p[i]] = i;
				}
			}
			if (end) {
				cout << t << ' ' << (L != -1 ? L : R) << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    int a_sum=0, b_sum=0;

    for(int i=0; i<n; i++) {
        if(i % 2 == 0) a_sum += v[i];
        else b_sum += v[i];
    }

    cout << a_sum - b_sum << endl;
}

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

//cin.tie(0);
//ios::sync_with_stdio(false);

int main() {
  int N, L;
  int val;
  cin >> N >> L;
  if (L > 0) {
    val = (N-1)*(2*L+N) / 2;
  } else {
    if (L+N-1 >= 0) {
      val = N*(2*L+N-1) / 2;
    } else {
      val = (N-1)*(2*L+N-2) / 2;
    }
  }
  cout << val << endl;
}

Measured memory_bytes: 256
import copy

class Dice(object):
	def __init__(self,List):
		self.face=List
		
	def n_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp
		return List
		
 	def s_spin(self,a_list):
 		List=copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[4]
 		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp
		return List
		
	def e_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp
		return List
		
 	def w_spin(self,a_list):
 		List = copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[2]
 		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp
		return List

dice=Dice(map(int,raw_input().split()))
emer=copy.copy(dice.face)
face_storage=[]
face_storage.append(emer)
q=input()
for a in range(q):
	question=map(int,raw_input().split())
	for a in range(24):
		face_storage.append(dice.n_spin(face_storage[a]))
		face_storage.append(dice.s_spin(face_storage[a]))
		face_storage.append(dice.e_spin(face_storage[a]))
		face_storage.append(dice.w_spin(face_storage[a]))
	for c in face_storage:
		if c[0]==question[0] and c[1]==question[1]:
			print(c[2])
			break

Measured memory_bytes: 6728
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
#define pb push_back
#define po pop_back
#define skip continue
//scanf("%lld",&a);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<long long>v,u;
    pair<long long, long long>n;
    set<string>y;
    long long a,b,c,d=0,e=0,i,f=0,g=0,j,k=0,l=0,r=0,z,m,h,p;
    string t,s,x,q;
    double w;
    cin>>a;
    if(a%1000==0){
        cout<<0;
    }
    else{
        cout<<1000-(a%1000);
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#define MAX 200000 //数列の長さn
#define AI 1000000001

long long cnt;

int merge (int A[], int left, int mid, int right){
  int n1, n2, i, j, k;
  int L[MAX / 2 + 2], R[MAX / 2 + 2];
  n1 = mid - left;
  n2 = right - mid;
  // L=n1+1;
  // R=n2+1;
  for(i = 0; i <= n1 - 1; i++){
    L[i] = A[left + i];
  }
  for(j = 0; j <= n2 - 1; j++){
    R[j] = A[mid + j];
  }
  L[n1] = AI;
  R[n2] = AI;
  i = 0;
  j = 0;
  for(k = left; k <= right - 1; k++){
   if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
      cnt += (n1 - i);
    }
  }
  return 0;
}


int mergeSort (int A[], int left, int right){
  int i, mid;
  if (left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
  return 0;
}

int main (void){
  int A[MAX], n, i;
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  cnt = 0;
  mergeSort(A, 0, n);
  // for(i=0;i<n;i++){
  //     printf("%lld",A[i]);
  //     if(i<n-1)printf(" ");
  //   }
    // printf("\n");
  printf("%lld\n", cnt);
    return 0;
}



Measured memory_bytes: 3340
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int n, m, s, g1, g2;
		cin >> n >> m >> s >> g1 >> g2;
		if (n == 0) break;
		s--; g1--; g2--;
		vector< vector<int> > d(n, vector<int>(n, INT_MAX / 10));
		for (int i = 0; i < n; i++) d[i][i] = 0;
		while (m--) {
			int b1, b2, c; cin >> b1 >> b2 >> c;
			b1--; b2--;
			d[b1][b2] = c;
		}
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		int mini = INT_MAX / 10;
		for (int i = 0; i < n; i++)
			mini = min(mini, d[s][i] + d[i][g1] + d[i][g2]);
		cout << mini << endl;
	}
}

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

namespace B {
	class Program {
		static bool[] haved = new bool[26];
		static void Main(string[] args) {
			string uinps = Console.ReadLine();
			foreach (var item in uinps) {
				if (haved[item - 'a']) {
					Console.WriteLine("no");
					return;
				}
				haved[item - 'a'] = true;
			}
			Console.WriteLine("yes");
			return;
		}
	}
}


Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define aint(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int h, w, k;
  int x1, y1, x2, y2;
  cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> c[i][j];
    }
  }
  vector<vector<int>> d(h, vector<int>(w, inf));
  queue<pair<int, int>> Queue;
  d[x1 - 1][y1 - 1] = 0;
  Queue.emplace(x1 - 1, y1 - 1);
  int u, v;
  pair<int, int> uv;
  while (!Queue.empty()) {
    uv = Queue.front();
    Queue.pop();
    u = uv.first;
    v = uv.second;
    int p, q;
    for (int l = 1; l <= k; l++) {
      p = u + l; q = v;
      //cout << p << q << endl;
      //cout << h << endl;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      //cout << (0 <= p < h) << endl;
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.emplace(p, q);
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u - l; q = v;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.emplace(p, q);
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u; q = v + l;
      //cout << k << endl;
      //cout << l << endl;
      //cout << u << v << p << q << endl;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.emplace(p, q);
      }
      d[p][q] = d[u][v] + 1;
    }
    for (int l = 1; l <= k; l++) {
      p = u; q = v - l;
      if (!(0 <= p && p < h && 0 <= q && q < w)) {
        break;
      } 
      if (c[p][q] == '@') {
        break;
      }
      if (d[u][v] + 1 > d[p][q]) {
        break;
      }
      if (d[p][q] == inf) {
        Queue.emplace(p, q);
      }
      d[p][q] = d[u][v] + 1;
    }
  
  }
  if (d[x2 - 1][y2 - 1] == inf) {
    cout << -1 << endl;
  }
  else {
    cout << d[x2 - 1][y2 - 1] << endl;
  }
}


Measured memory_bytes: 12024
N = int(input())
S = input()

word1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
word2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''

for i in range(len(S)):
    for j in range(len(word1)):
        if S[i]==word1[j]:
            ans = ans + word2[j+N]
            
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {

	int n; cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	int ans = 0;
	int maxCnt = 0;
	for (int i = 1; i <= n; i++) {
		int x = i;
		int cnt = 0;
		while (true) {
			if (x % 2 == 1) break;
			if (x / 2 == 0) {
				break;
			}
			else {
				x /= 2;
			}
			cnt++;
		}
		if (chmax(maxCnt, cnt)) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  vector<ll>a(n); ll p[60],t=1,ans=0;
  for(int i=0; i<n; i++) cin >>a[i];
  for(int i=0; i<60; i++){
    p[i]=t;
    t=(t*2)%MOD;
  }
  for(int i=0; i<60; i++){
    ll odd=0,even=0;
    for(int j=0; j<n; j++){
      if(a[j]%2) odd++;
      else even++;
      a[j]/=2;
    }
    ll cnt=(odd*even)%MOD;
    ans+=cnt*p[i]; ans%=MOD;
  }
  cout <<ans;
}

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

Measured memory_bytes: 5528
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  set<string> memo;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    memo.insert(s);
  }
  cout<<memo.size()<<endl;
  return 0;
}


Measured memory_bytes: 19240
import sys
import queue
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	# = int(input())
	n, m, k = tin()
	#s = input()
	friend_l = [[] for _ in range(n)]
	for _ in range(m):
		a, b = tin()
		a, b = a-1, b-1
		friend_l[a].append(b)
		friend_l[b].append(a)
	
	friend_group=[-1]*n
	gid=1
	st=0
	while st < n:
		if friend_group[st] > 0:
			st += 1
			continue
		friend_group[st] = gid
		qq=queue.Queue()
		qq.put(st)
		while not qq.empty():
			f = qq.get()
			for t in friend_l[f]:
				if friend_group[t] == -1:
					friend_group[t] = gid
					qq.put(t)
		gid += 1
				
	num_mem = collections.Counter(friend_group)
	
	#about block
	bl=[[] for _ in range(n)]
	bln = [0]*n
	for _ in range(k):
		a,b = tin()
		a,b = a-1, b-1
		if friend_group[a] == friend_group[b]:
			bln[a]+=1
			bln[b]+=1
			
	ret=[]
		
	for i in range(n):
		full = num_mem[friend_group[i]]
		fn = len(friend_l[i])
		p=(full-fn-bln[i] -1)
		ret.append(p)
	print(*ret)
	
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 115148
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
string adversity ="dream",thinking="dreamer",disadvantage="erase",behavior="eraser";
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL_of(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(string, you);

  // just a joke
  // --------------------------------------
  reverse(ALL_of(adversity));
  reverse(ALL_of(thinking));
  reverse(ALL_of(disadvantage));
  reverse(ALL_of(behavior));
  reverse(ALL_of(you));
  // --------------------------------------

  #define _dream (adversity)
  #define _dreamer (thinking)
  #define _erase (disadvantage)
  #define _eraser (behavior)
  #define _s (you)
  
  while (_s.size() > 0) {
    if (_s.substr(0, 5) == _dream || _s.substr(0, 5) == _erase) _s.erase(0, 5);
    else if (_s.substr(0, 6) == _eraser) _s.erase(0, 6);
    else if (_s.substr(0, 7) == _dreamer) _s.erase(0, 7);
    else break;
  }

  if (_s.empty()) OUT("YES")
  else OUT("NO")
  BR;
  
  return 0;
}


Measured memory_bytes: 512
/* author   : mpily :-()
title : Competing.cpp
time :Sat Jan 11 11:10:48 2020

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

int main(){
	int N,M;
	cin>>N>>M;
	vector<long long>arr(N);
	long long ans = 1;
	for(int i = 0; i < N; i++){
		cin>>arr[i];
		arr[i]/=2;
		long long temp = __gcd(ans,arr[i]);
		ans = ans * arr[i];
		ans/=temp;
	}
	bool can = 1;	
	for(auto a : arr){
		long long tocheck = ans/a;
		if(tocheck%2 == 0){
			can = 0;
			break;
		}
	}
	if(can){
		long long temp = M/ans;
		long long toout = temp/2;
		if(temp%2)toout+=1;
		cout<<toout<<"\n"; 
	}
	else{
		cout<<0<<"\n";
	}
	return 0;
}


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

class Main {
	public static void main (String[] args) throws IOException {
	    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    String s = in.readLine();
	    
	    String res = "";
	    
	    for (int i = 0; i < s.length(); i++) {
	        char c = s.charAt(i);
	        if (c == '0') {
	            res += "0";
	        }
	        if (c == '1') {
	            res += "1";
	        }
	        if (c == 'B' && res.length() > 0) {
	            res = res.substring(0, res.length() - 1);
	        }
	    }
	    System.out.println(res);
	    
	    in.close();
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  int n=s.size();
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]=='o') ans++;
  }

  if((15-n)+ans>=8) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl

//ここから編集する


int main() {
    int N;
    cin >> N;
    vector<ll> A(N),B(N);
    ll sum_A = 0LL;
    ll T = 1LL * N * (N + 1) / 2;

    rep(i,0,N){
        cin >> A[i];
        sum_A += 1LL * A[i];
    }

    if(sum_A % T != 0){
        cout << "NO" << endl;
        return 0;
    }

    ll K = sum_A / T;

    for(int i = 0; i < N-1;i++){
        B[i] = A[i+1] - A[i];
    }
    B[N-1] = A[0] - A[N-1];

    rep(i,0,N){
        B[i] -= K;
    }

    rep(i,0,N){
        if(B[i] % N != 0 || B[i] > 0){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int a, b, x;

	scanf("%d %d %d", &x, &a, &b);

	if (abs(x - a) < abs(x - b)) {
		printf("A\n");
	}
	else {
		printf("B\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 1e5 + 7;
LL a, b, n;

int main() {
	cin >> a >> b >> n;
	//保证a * floor(x / b)尽可能小 => floor(x / b)=0 => x / b < 1
	//保证floor(a * x / b)尽可能大 => x / b < 1且尽可能接近1
	//若x / b >= 1 => a * floor(x / b) >= a 和第一项差距拉不开
	LL x = min(n, b - 1LL);
	LL res = floor(a * x / b) - a * floor(x / b);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3584
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
group = UnionFind(N)

for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    group.union(A, B)

print(len(group.roots()) - 1)

Measured memory_bytes: 12944
#include <iostream>

using namespace std;

int main()
{
    int n[101]={0};
    int buf;
    while(cin>>buf)
    {
        n[buf]++;
    }
    int b=0;
    for(int i=0;i<101;++i){
        if(n[i]>b)b=n[i];
    }
    for(int i=0;i<101;++i){
        if(n[i]==b)cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {

		Scanner scaner = new Scanner( System.in );

		int width 	= Integer.parseInt( scaner.next() );
		int height 	= Integer.parseInt( scaner.next() );
		int x		= Integer.parseInt( scaner.next() );
		int y		= Integer.parseInt( scaner.next() );
		int r		= Integer.parseInt( scaner.next() );

		String resultMessage = "No";

		if ( ( x - r >= 0 ) && ( x + r <= width ) && ( y + r ) <= height && ( y - r) >= 0 ) {
			resultMessage = "Yes";
		}

		System.out.println( resultMessage );

		scaner.close();
	}
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

long long int to_int(string S){
    int n = S.size();
    long long int ans = 0;
    vector<int> B(n);
    for(int i =0;i < n;i++){
      bool frag = 1;
        for(int j = 0;j < 10;j++){
            char a = '0' + j;
            if(S[i] == a){
                B[i] = j;
                frag = 0;
                break;
            }
        }
        if(frag) return -1;
    }
    for(int i = 0;i < n;i++){
        ans += B[i]*pow(10,(n-i-1));
    }
    return ans;
}

int CA[12]{31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(A + B <= K){
    cout << 0 << ' ' << 0 << endl;
  }else if(A >= K){
    cout << A-K << ' ' << B << endl;
  }else{
    cout << 0 << ' ' << (A+B) - K << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main (int argc, char const *argv[])
{
    int64_t R, G, B, N;
    int64_t ans = 0;

    scanf("%"PRId64"%"PRId64"%"PRId64"%"PRId64, &R, &G, &B, &N);

    for (int r = 0; r <= (N / R); r++) {
        for (int g = 0; g <= ((N - R * r) / G); g++) {
            if (((N - R * r - G * g) % B) != 0) continue;
            ans++;
        }
    }

    printf("%"PRId64"\n", ans);
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int N, K, X, Y;
  scanf("%d %d %d %d", &N, &K, &X, &Y);
  if(N <= K) printf("%d\n", N*X);
  else printf("%d\n", K*X + (N-K)*Y);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	long long x = c - (a + b);
	long long y2 = 4LL * a * b;
	if (x > 0 && x * x > y2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
num = 100
for i in range(n):
    s1 = sum(w[0:i])
    s2 = sum(w[i:])
    if abs(s1 - s2) < num:
        num = abs(s1 - s2)
print(num)
    

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

int main()
{
	int n;
   string s;

   cin >> n >> s;

   if(n%2 == 1){
      cout << "No" << endl;
   }
   else if(s.substr(0, n/2) == s.substr(n/2, n/2)){
      cout << "Yes" << endl;

   }
   else{
      cout << "No" << endl;
   }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define K 971
using namespace std;
typedef unsigned long long ull;

string s, t;
unordered_map<ull,int> cnt;
ull d[300005], H[300005];

signed main(){
  
  cin>>s>>t;

  ull h=0, x=1;
  
  for(int i=0;i<t.size()-1;i++) x=x*K;
  
  for(int i=0;i<s.size();i++){
    h=h*K+s[i];
    if(i>=t.size()-1){
      cnt[h]++;
      h=h-s[i-(t.size()-1)]*x;
    }
  }

  d[0]=1;
  
  for(int i=1;i<=t.size();i++) d[i]=d[i-1]*K;
  
  h=0;
  
  for(int i=0;i<t.size();i++){
    h=h*K+t[i];
    H[i]=h;
  }
  
  int ans=0;

  for(int i=0;i<t.size();i++){
    for(int j='A';j<='z';j++){
      if((char)j==t[i]) continue;
      ull hash=j;
      if(i!=0) hash=H[i-1]*d[1]+hash;
      if(i!=t.size()-1)
	hash=hash*d[t.size()-i-1]+H[t.size()-1]-H[i]*d[t.size()-i-1];

      if(cnt.count(hash)) ans+=cnt[hash];
    }
  }
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 17164
from collections import deque
import numpy as np
def main():
    hw = list(map(int, input().split()))
    s = np.zeros((hw[0],hw[1]), dtype=int)
    validpoints = []
    for i in range(hw[0]):
        tmp = input()
        tm = [None]*hw[1]
        for j in range(hw[1]):
            if tmp[j] == '.':
                tm[j] = 0
                validpoints.append((i,j))
            elif tmp[j] == '#':
                tm[j] = 1
        s[i] = np.array(tm)

    ma = 0
    # for i in validpoints:
    #     for j in validpoints:
    #         vis = np.array(s)
    #         cost = breadth(s,i,j,vis)
    #         if cost > ma:
    #             ma = cost
    for i in validpoints:
        cost = breadth(s,i)
        if cost > ma:
            ma = cost
    print(ma)

    # print(breadth(s,(2,0),(0,4)))
    # print(breadth(s,(0,0),(1,0)))

def breadth(ss, start):
    q = deque()
    visited = np.array(ss)
    visited[start] = 1
    q.append({start})
    c = 0

    while not len(q) == 0:
        c += 1
        v = q.pop()
        tmpl = []
        for i in v:
            visited[i] = 1
            child = get_child_quad(ss, visited, i)
            tmpl.extend(child)
        tmps = set(tmpl)
        if len(tmps) > 0:
            for i in tmps:
                visited[i] = 1
            q.append(set(tmpl))

    return c-1

def get_child_quad(ss, visited, p):
    down = (p[0]+1,p[1])
    up = (p[0]-1,p[1])
    right = (p[0],p[1]+1)
    left = (p[0],p[1]-1)
    child = [down,up,right,left]
    return list(filter(lambda pp: 0 <= pp[0] < len(ss) and 0 <= pp[1] < len(ss[0]) and visited[pp[0],pp[1]] == 0, child))

# def breadth(ss, start, goal, visited):
#     newvis = np.array(visited)
#     newvis[start] = 1
#     if start == goal:
#         return 0
#     down = (start[0]+1,start[1])
#     up = (start[0]-1,start[1])
#     right = (start[0],start[1]+1)
#     left = (start[0],start[1]-1)
#     child = [down,up,right,left]
#     child = list(filter(lambda i: 0 <= i[0] < len(ss) and 0 <= i[1] < len(ss[0]) and visited[i[0],i[1]] == 0, child))
#     if len(child) > 0:
#         mi = 99999
#         for i in child:
#             co = breadth(ss,i,goal,newvis)
#             if mi > co:
#                 mi = co
#         return 1+mi
#     else:
#         return 1
    

# def breadth(ss, start, goal):
#     q = deque()
#     visited = np.array(ss)
#     visited[start] = 1
#     q.append(start)
#     c = 0
#     while not len(q) == 0:
#         v = q.pop()
#         if v == goal:
#             break
#         down = (v[0]+1,v[1])
#         up = (v[0]-1,v[1])
#         right = (v[0],v[1]+1)
#         left = (v[0],v[1]-1)
#         child = [down,up,right,left]
#         child = list(filter(lambda i: 0 <= i[0] < len(ss) and 0 <= i[1] < len(ss[0]) and visited[i[0],i[1]] == 0, child))

#         if len(child) > 0:
#             for i in child:
#                 visited[i] = 1
#                 q.append(i)
#             c += 1
        
#     return c

if __name__ == '__main__':
    main()

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
全部の数の約数とりたい


各桁毎の素数の数一覧
範囲	0の数	素数の個数
10まで	10^1	1	4
100まで	10^2	2	25
1000まで	10^3	3	168
1万まで	10^4	4	1229
10万まで	10^5	5	9592
100万まで	10^6	6	78498
1000*10^6まで
*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N; cin>>N;
  vector<ll> A(N,0), B(1000010, 0);
  ll ans = 2;
  rep(k,N){
    ll a;
    cin >> a;
    for(ll i=2; i*i<=a; i++){
      if (a%i == 0){
        if (B[i]>0)
          ans = 1;
        B[i]++;
        while (a%i == 0)
          a /= i;
      }
    }
    if (a>1){
      if (B[a] > 0)
        ans = 1;
      B[a]++;
    }
  }
  if (ans == 2){
    cout << "pairwise coprime" <<endl;
    return 0;
  }
  for(ll i=2; i<=1000000; i++){
    if (B[i] == N){
      cout << "not coprime" <<endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}


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

int main(){

    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
        sort(s.at(i).begin(),s.at(i).end());
    }
    
    sort(s.begin(),s.end());

    long long int count=0;
    long long int num=0;
    for(int i=1; i<n; i++){
        if(s.at(i-1)==s.at(i)){
            num++;
            count+=num;
        }
        else num=0;
    }

    cout << count << endl;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace QiFeng233{
	ll n,sn,ans;
	bool chk(ll x){
		ll tmp=n;
		while(tmp>1){
			if(tmp%x==0)tmp/=x;
			else{
				if((tmp-1)%x==0)return 1;
				else return 0;
			}
		}
		if(tmp==1)return true;
		else return false;
	}
	void solve(){
		scanf("%lld",&n);
		sn=(ll)sqrt((double)n);
		for(ll i=2;i<=sn;++i){
			if(chk(i))++ans;
		}
		for(ll i=1;i<=sn;++i)if((n-1)%i==0)++ans;
		if(n-1==sn*sn)--ans;
		printf("%lld",ans+1);
	}
}
signed main(){
	QiFeng233::solve();
	return 0;
}

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

maxi = 0

for i in range(1, n):
    x = a[i] - a[i-1]

    maxi = max(maxi, x)

x = a[-1] - a[0]

if k - x < x:
    x = k - x

maxi = max(maxi, x)

print(k - maxi)

Measured memory_bytes: 77388
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	string S;
	cin >> S;
	cout << (S[0]==S[1] || S[1]==S[2] || S[2]==S[3] ? "Bad" : "Good") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[3000];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}

Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>

using namespace std;

#define M 987654321

class Prim
{
public:
	void mst (vector <vector <int> >, vector<int> &, vector <bool> &, vector <int> &);
private:

};
void Prim::mst (vector <vector <int> > t, vector <int>& pi, vector <bool>& v, vector <int>& cost)
{
	int size = v.size();
	int i;

	do{
		int mincost = M;
		int u;

		// costªÅ¬ÆÈém[huðIð·é
		for (i = 0; i < size; ++i){
			if (!v[i] && cost[i] < mincost){
				mincost = cost[i];
				u = i;
			} // end if
		} // end for

		v[u] = true;
	
		for (i = 0; i < size; ++i){
			// Ü¾ÜÜêÄ¢È¢m[hÌRXgÌXV
			if (!v[i] && t[u][i] < cost[i] ){
				cost[i] = t[u][i];
				pi[i] = u;
			} // end if
		} // end for		 
		
	} while ((int)count (v.begin(), v.end(), true ) != size );// end while
}

int main()
{
	Prim prim;

//	cut here before submit 
//	freopen("testcase.cdl", "r", stdin);

	string str = "";
	int n,m;	// n: jÕÌÓ m: jÕðÔ¹Ì

	while (getline (cin, str ) ) {
		stringstream ssn(str);
		ssn >> n;
		if (n == 0){
			break;
		} // end if
		getline (cin, str );
		stringstream ssm(str);
		ssm >> m;

		int i;
		vector <vector <int> > table (n, vector <int> (n, M ) );
		for (i = 0; i < m; ++i){
			int from, to, dist;
			getline (cin, str );
				while (str.find(',') != string::npos ){
				str = str.replace(str.find(','), 1, " ");
			} // end while
			stringstream ss(str);
			ss >> from >> to >> dist;
			table[from][to] = dist;
			table[to][from] = dist;
		} // end for

		vector <bool> visit (n, false );
		vector <int> len (n, M );
		vector <int> path (n, -1);
		len[0] = 0;
		path[0] = -1;

		prim.mst (table, path, visit, len );

		int res = accumulate (len.begin(), len.end(), 0);
		
		map <int, int> edge;
		for (i = 0; i < n; ++i){
			int curr = i;
			while (path[curr] != -1 ){
				edge[curr] = path[curr];
				curr = path[curr];
			} // end while

		} // end for

		cout << (res/100 - edge.size() ) << endl;

	} // end while

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{	
	long long a,b,c;
	while(scanf("%lld%lld",&a,&b)!=EOF)
	{
		long long s[3];
		s[0]=a-b;
		s[1]=a+b;
		s[2]=a*b;
		c=*max_element(s,s+3);
		printf("%lld\n",c);
	}
	
	return 0;
}

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

using namespace std;

const int mod=1000000007;
int n,cnt[30];
char s[1<<20];

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;++i) ++cnt[s[i]-'a'];
	long long ans=1;
	for (int i=0;i<26;++i) ans=ans*(cnt[i]+1)%mod;
	ans=(ans+mod-1)%mod;
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 384
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
D=0
a=0
b=0
c=0
mp=10**5
#4^8=2^16=10^16*0.3010=10^5?
for i in range(4**N):
  a=0
  b=0
  c=0
  x=0
  y=0
  z=0
  for j in range(N):
    if(i&1<<2*j and i&1<<(2*j+1)):
      #A-=[l[j]
      a+=l[j]
      x+=1
    elif(i&1<<2*j and ~(i&1<<(2*j+1))):
      b+=l[j]
      y+=1
    elif(~(i&1<<2*j) and (i&1<<(2*j+1))):
      c+=l[j]
      z+=1
  if(a==0 or b==0 or c==0):
    continue

  mp=min(mp,abs(A-a)+abs(B-b)+abs(C-c)+(x+y+z-3)*10)
  if(mp==110):
    print("a={}".format(a)+"b={}".format(b)+"c={}".format(c))
print(mp)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>

int cum[10][30001];

int main()
{
  int n;
  char s[30001];
  scanf("%d%s", &n, s);

  int first[10];
  int last[10];
  
  std::fill(first, first + 10, -1);
  std::fill(last, last + 10, -1);

  for (int i = 0; i < n; ++i)
  {
    const int d = s[i] - '0';
    if (first[d] < 0)
    {
      first[d] = i;
    }
    if (last[d] < i)
    {
      last[d] = i;
    }
    for (int j = 0; j < 10; ++j)
    {
      cum[j][i + 1] = cum[j][i];
    }
    cum[d][i + 1] += 1;
  }
  long long ans = 0;
  for (int i = 0; i < 10; ++i)
  {
    for (int j = 0; j < 10; ++j)
    {
      for (int k = 0; k < 10; ++k)
      {
        if (first[i] < 0 || last[k] < 0 || last[k] - first[i] <= 1) continue;
        if (cum[j][last[k]] - cum[j][first[i] + 1] > 0)
        {
          ++ans;
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main()
{
    char S[6];
    cin>>S;

    if(S[0]=='S')cout<<"Cloudy"<<endl;
    else if(S[0]=='C')cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
    return 0;
}



Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());
    int X = Integer.parseInt(sc.next());
    int Y = Integer.parseInt(sc.next());

    int cost = 0;

    if (2 * C < A && 2 * C < B) {
      cost += 2 * C * Math.max(X, Y);
    } else if (2 * C < A) {
      cost += 2 * C * X;
      if (X < Y) {
        cost += B * (Y - X);
      }
    } else if (2 * C < B) {
      cost += 2 * C * Y;
      if (Y < X) {
        cost += A * (X - Y);
      }
    } else if (2 * C < A + B) {
      if (X > Y) {
        cost += 2 * C * Y + A * (X - Y);
      } else {
        cost += 2 * C * X + B * (Y - X);
      }
    } else {
      cost += A * X + B * Y;
    }

    System.out.println(cost);
  }

}

Measured memory_bytes: 22868