akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    int[] nums = new int[N];
    int sum = 0;
    for(int i = 0; i < N; i++){
      nums[i] = Integer.parseInt(S[i]);
      sum += nums[i];
    }
    
    int ans = 0;
    double d = (double)sum/N;
    int ave = (int)Math.round(d);
    for(int i = 0; i < N; i++){
      ans += (int)Math.pow(nums[i]-ave, 2);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
N = int(input())
tasks = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    tasks.append([B, A])
tasks.sort()

ok = True
S = 0
for i in range(N):
    B, A = tasks[i][0], tasks[i][1]
    S += A
    if S > B:
        ok = False
        break

if ok == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38212
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-B: Merge Sort

#include <climits>
#include <cstdio>
#include <cstring>

static void print_ints(const int as[], const unsigned int n, const char* sep = " ") {
  const char* out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = sep;
  }
  std::printf("\n");
}

static void print_int(const unsigned int n) {
  std::printf("%d\n", n);
}

static unsigned int comparison_count = 0u;

static void merge(int* const begin, int* const middle, int* const end) {
  auto size = middle - begin;
  int tmp[size+1]; // size+1(sentinel)
  std::memcpy(tmp, begin, sizeof(tmp[0])*size);
  tmp[size] = INT_MAX; // > 10**9
  auto ss0 = begin, ss1 = tmp, ss2 = middle;
  const auto end1 = ss1+size, end2 = end;
  while (ss2 < end2) {
    while (*ss1 <= *ss2) {
      *ss0++ = *ss1++;
      ++comparison_count;
    }
    *ss0++ = *ss2++;
    ++comparison_count;
  }
  while (ss1 < end1) {
    *ss0++ = *ss1++;
    ++comparison_count;
  }
}

void merge_sort(int* const begin, int* const end) {
  auto size = end - begin;
  if (size > 1) {
    auto middle = begin + size/2;
    merge_sort(begin, middle);
    merge_sort(middle, end);
    merge(begin, middle, end);
  }
}

int main(void) {
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, ss+n);

  print_ints(ss, n);
  print_int(comparison_count);

  return 0;
}

// eof

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
char A[1005][1005];
int H,W;
bool IsIn(int x, int y){
    return 0<=x&&x<H&&0<=y&&y<W;
}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int dist[1005][1005];
int main() {
    cin>>H>>W;
    queue<pair<int,int>> Q;
    rep(i,H)rep(j,W){
        cin>>A[i][j];
        if(A[i][j]=='#'){
            Q.push({i,j});
            dist[i][j] = 0;
        }
        else{
            dist[i][j] = -1;
        }
    }
    //BFS
    while(!Q.empty()){
        auto p = Q.front();
        Q.pop();
        int x = p.first;int y = p.second;
        rep(i,4)rep(j,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!(IsIn(nx,ny))||dist[nx][ny]!=-1){
                continue;
            }
            dist[nx][ny] = dist[x][y]+1;
            Q.push({nx,ny});
        }
    }
    int ans = 0;
    rep(i,H)rep(j,W){
        ans = max(ans, dist[i][j]);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 13328
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    dp[i] = min([dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, min(i, k) + 1)])
print(dp[n - 1])


Measured memory_bytes: 52448
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;


int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    vector<int> counter(N+1,0);
    vector<int> ans;
    for(int i = N-1; i >= 0; i--){
        int count = 0;
        int now = i+1;
        while (now <= N){
            count += counter[now];
            now += i+1;
        }
       
        if (count%2 != a[i]){
            counter[i+1]++;
            ans.push_back(i+1);
        }
    }
/*
    rep(i,counter.size()){
        cout << i << " " << counter[i] << endl;
    }
*/
    int size = ans.size();
    cout << size << endl;
    if (size > 0){
        rep(i,size){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 5316
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void ){
    int a[200],b;
    int i = 0;
    while( scanf( "%d %d",&a[i],&b ) != EOF ){
         a[i] = a[i] + b;
         i++;
    }
    for( int j = 0;j < i;j++ ){
        int n = 1;
        int nCount = 0;
        while( a[j] / n >= 1 ){
            n *= 10;
            nCount++;
        }
        printf( "%d\n",nCount );
    }
    return 0;
}

Measured memory_bytes: 1028
import itertools
import numpy as np

N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]

d_list = []
sum_d = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1]-A[a-1] == c:
      d_list.append(d)
  if sum_d <= sum(d_list):
    sum_d = sum(d_list)
  d_list.clear()
print(sum_d)

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

int main()
{
    int N; cin >> N;
    vector<int> T(N+1);
    int sum = 0;
    for(int i = 1; i <= N; i++)
    {
        cin >> T[i];
        sum += T[i];
    }
    int M; cin >> M;
    vector<int> r(M+1);
    for(int i = 1; i <= M; i++)
    {
        int P, X;
        cin >> P >> X;
        r[i] = sum - (T[P] - X);
    }
    for(int i = 1; i <= M; i++)
    {
        cout << r[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();

		if (n % 500 <= a) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}
	}
}

Measured memory_bytes: 20820
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main()
{
	int N;
	cin >> N;
	while(N--){
		int num[8];
		int numchar;
		int max=0;
		int min=0;
		cin >> numchar;
		REP(i,8){
			num[i] = numchar%10;
			numchar /= 10;
		}
		sort(num , num+8);
		REP(i,8){
			max += num[i]*pow(10,(double)i);
		}
		REP(i,8){
			min += num[7-i] * pow(10,(double)i);
		}
		cout << max - min << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <vector>
#include <stack>



int main()
{
    int a, b, c;
    std::priority_queue<int, std::vector<int>, std::greater<int>> pq;
    int height, third;
    for (int i = 0; i < 10; i++) {
        //scanf("%d", &height);
        std::cin >> height;
        if (i < 3) {
            pq.push(height);
        } else {
            third = pq.top(); pq.pop();
            if (third < height) pq.push(height);
            else pq.push(third);
        }
    }

    c = pq.top(); pq.pop();
    b = pq.top(); pq.pop();
    a = pq.top(); pq.pop();

    std::cout << a << std::endl;
    std::cout << b << std::endl;
    std::cout << c << std::endl;

    return 0;
}


Measured memory_bytes: 3132
#define _DEBUG
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//デバッグ
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug1(x1) cout<<#x1<<": "<<x1<<endl
#define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug5,debug4,debug3,debug2,debug1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    string s;
    cin>>s;
    int N = s.size();
    if(s[N-1]=='s'){
        cout<<s<<"es"<<endl;
    }else{
        cout<<s<<"s"<<endl;
    }
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,a;
  cin >> n;
  rep(i,n){
    cin >> a;
    if(a%2!=0)continue;
    if(a%3!=0&&a%5!=0){
      pri("DENIED");
      return 0;
    }
  }
  pri("APPROVED");
  return 0;
}


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

using namespace std;

int N, A, B, C;
vector<int> l;

int calc_mp(int cur, int a, int b, int c) {
    if(cur==N) {
        if(min(min(a, b), c)!=0) {
            return abs(a-A) + abs(b-B) + abs(c-C) - 30;
        } else {
            return 1000000;
        }
    }
    
    int retn = calc_mp(cur+1, a, b, c);
    int reta = calc_mp(cur+1, a+l[cur], b, c) + 10;
    int retb = calc_mp(cur+1, a, b+l[cur], c) + 10;
    int retc = calc_mp(cur+1, a, b, c+l[cur]) + 10;
    return min(min(retn, reta), min(retb, retc));
}

int main() {
    cin >> N >> A >> B >> C;
    
    l.resize(N);
    for(int i=0; i<N; i++) {
        cin >> l[i];
    }
    
    cout << calc_mp(0, 0, 0, 0) << endl;


    return 0;
    
}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = sorted(list(map(int, input().split())) + [0])
ans = 10**9 + 10

for i in range(n-k+1):
    left = i
    right = i+k
    to_right = abs(x[left]) + abs(x[right]-x[left])
    to_left = abs(x[right]) + abs(x[right]-x[left])
    if min(to_right, to_left) < ans:
        ans = min(to_right, to_left)

print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a;
  bool chk = true;
  int i;
  for(i=0;i<n;i++){
    cin >> a;
    if(a%2==0){
      if(a%3!=0 && a%5 != 0)chk=false;
    }
  }
  if(chk)cout<<"APPROVED"<<endl;
  else cout << "DENIED"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int count = 0;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = 0,h = 0;
		String str = "";
		int firstX = 0,firstY = 0;

		while(sc.hasNext()){
			
			count = 0;
			w = sc.nextInt();
			h = sc.nextInt();
			
			if(w == 0 && h == 0) break;
			
			char[][] tiles = new char[h][w];
			
			// テ」ツつソテ」ツつ、テ」ツδォテ、ツスツ愿ヲツ按?
			for(int i = 0;i<h;i++){
				str = sc.next();
				for(int j = 0;j<w;j++){
					tiles[i][j] = str.charAt(j);
					if(tiles[i][j]=='@'){
						firstX = j; 
						firstY = i;
					}
				}
			}
			
			// テ・ツ?催・ツクツーテゥツ鳴凝・ツァツ?
			walkTiles(firstY,firstX,tiles);
			
			System.out.println(count);
			
		}
	}
	
	static void walkTiles(int y,int x,char[][] tiles){
		if(y>tiles.length-1 || x<0 || y<0 || x>tiles[y].length-1) return;
		if(tiles[y][x] == '#') return;
		
		count++;
		tiles[y][x] = '#';
		
		// テ・ツ?催・ツクツーテゥツδィテ・ツ按?
		walkTiles(y-1,x,tiles);
		walkTiles(y,x+1,tiles); 
		walkTiles(y+1,x,tiles);
		walkTiles(y,x-1,tiles);
	}

}

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


int main(void){
  int n;
  cin >> n;
  
  rep(i,n) {
      rep(j,n) {
          if (i*4 + j*7 == n) {
              cout << "Yes" << endl;
              return 0;
          }
      }
  }
  
  cout << "No" << endl;
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=min(n*a,b);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)
odd = 0
even = 0

for i in range(0,N,2):
    odd += int(S[i])

for i in range(1,N,2):
    even += int(S[i])

print(min(N-int(N/2) - odd + even,int(N/2) - even + odd))

Measured memory_bytes: 3188
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<=(n);i++)
#define mer(i,m,n) for(int i=(m);i>=(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<long long int> vll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<char> vc;
vector<string> vs;




int main() {
	int x;
	cin >> x;
	if (x >= 30)cout << "Yes" << '\n';
	else cout << "No" << '\n';
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    int count = 0;
    for( int i = n-1; i >= 1; i--){
        int l = 0, r = i-1;
        while( l < r){
            if( a[l] + a[r] > a[i]){
                count += r - l ;
                r--;
            }
            else
                l++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll n; cin >> n;
    string s[n];
    rep(i, n){
        cin >> s[i];
    }

    sort(s, s+n);
    ll cnt[n] = {};

    reps(i, 1, n){
        if(s[i] == s[i - 1]){
            cnt[i] = cnt[i - 1] + 1;
        }
        else{
            cnt[i] = 0;
        }
    }

    // rep(i, n){
    //     cout << cnt[i] << endl;
    // }

    ll cnt_max = *max_element(cnt, cnt+n);


    rep(i, n){
        if(cnt[i] == cnt_max){
            cout << s[i] << endl;
        }
    }    


    return 0;
}

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

using namespace std;

int main() {
    int n, k;
    cin>>n>>k;
    vector<int> costs;
    for (int i=1; i<=n; i++) {
        int temp;
        cin>>temp;
        costs.push_back(temp);
    }
    int dp[n+1];
    dp[1] = 0;
    // dp[2] = dp[1] + abs(costs[1] - costs[0]);
    for (int i=2; i<=n; i++) {
        vector<int> temp;
        if (i>k) {
            for (int j=0; j<k; j++) {
                temp.push_back(dp[i-(j+1)] + abs(costs[i-1] - costs[i-(j+2)]));
            }
            dp[i] = *min_element(temp.begin(), temp.end());
            temp.clear();
        } else {
            for (int j=0; j<i-1; j++) {
                temp.push_back(dp[i-(j+1)] + abs(costs[i-1] - costs[i-(j+2)]));
            }
            dp[i] = *min_element(temp.begin(), temp.end());
            temp.clear();
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1144
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#define INF (1<<21)
using namespace std;

class Point{
public:
  int x,y,c;
  Point(int x = 0,int y = 0,int c = 0):x(x),y(y),c(c){}
};

int main(){
  int i,j,k,l,h,w,sum,ans,gomi[20][20],G[11][11];
  bool f[20][20],f2[20][20];
  string str;
  while(1){
    Point u,v,g;
    cin >> w >> h;
    if(h == 0 && w == 0) break;
    ans = INF;
    sum = 0;

    for(i=0;i<h;i++){
      cin >> str;
      for(j=0;j<w;j++){
	gomi[i][j] = -1;
	f[i][j] = false;
	if(str[j] == 'o') gomi[i][j] = 0;
	else if(str[j] == 'x') f[i][j] = true;
	else if(str[j] == '*') gomi[i][j] = ++sum;
      }
    }
    
    for(i=0;i<sum;i++){
      for(j=i+1;j<=sum;j++){
	for(k=0;k<h;k++){
	  for(l=0;l<w;l++){
	    f2[k][l] = f[k][l];
	    if(gomi[k][l] == i){
	      u.y = k;
	      u.x = l;
	      f2[k][l] = true;
	    }
	    else if(gomi[k][l] == j){
	      g.y = k;
	      g.x = l;
	    }
	  }
	}
	
	queue <Point> Q;
	bool ff = true;
	u.c = 0;
	Q.push(u);
	while(!Q.empty()){
	  u = Q.front();
	  Q.pop();
	  if(g.x == u.x && g.y == u.y){
	    G[i][j] = G[j][i] = u.c;
	    ff = false;
	    break;
	  }
	  u.c++;
	  int dx[4] = {1,0,-1,0};
	  int dy[4] = {0,1,0,-1};
	  for(k=0;k<4;k++){
	    v = u;
	    v.x += dx[k];
	    v.y += dy[k];
	    if(v.x >= 0 && v.x < w && v.y >= 0 && v.y < h && !f2[v.y][v.x]){
		f2[v.y][v.x] = true;
		Q.push(v);
	      }
	   }
	}
	  if(ff){
	    ans = -1;
	    break;
	  }
      }
	if(ans == -1) break;
    }
    
      if(ans != -1){
	int a[11],be,af,A;
	for(i=0;i<=sum;i++) a[i] = i;
	do{
	  if(a[0] == 0){
	    A = 0;
	    be = a[0];
	    for(i=1;i<=sum;i++){
	      af = a[i];
	      A += G[be][af];
	      be = af;
	    }
	    ans = min(ans,A);
	  }
	} while(next_permutation(a,a+sum+1));
      }
      cout << ans << endl;
		
  }
  return 0;
}

Measured memory_bytes: 928
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b;
    cin >> a >> b;
    if (a * b % 2 == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

vector<pair<int, int>> vp;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(6);

    int N, M;
    cin >> N >> M;

    for (int i = 0; i < N; ++i)
    {
        int A, B;
        cin >> A >> B;
        vp.push_back({A, B});
    }

    sort(vp.begin(), vp.end());

    int cnt = 0;
    ll ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (cnt + vp[i].second <= M)
        {
            ans += (ll)vp[i].first * vp[i].second;
            cnt += vp[i].second;
        }
        else
        {
            ans += (ll)(M - cnt) * vp[i].first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
mod=10**9+7
b=[0]*(n+1)
b[0]=1
b[1]=1

for i in a:
    b[i]=-1

for i in range(2,n+1):
    if b[i]==-1:
        continue
    if b[i-1]!=-1:
        b[i]+=b[i-1]
    if b[i-2]!=-1:
        b[i]+=b[i-2]
        
print(b[-1]%mod)


Measured memory_bytes: 462708
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

ll _find(int d,int n){
    return n<100 ? pow(100,d)*n : 101*pow(100,d);
}

void solve(){
    
    ll n,m;
    cin>>n>>m;
    
    
    cout<<_find(n,m)<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;

    const int nmmax=50;
    char A[nmmax][nmmax],B[nmmax][nmmax];


    for(int y=0;y<N;++y){
        for(int x=0;x<N;++x){
            cin >> A[y][x];
        }
    }

    for(int y=0;y<M;++y){
        for(int x=0;x<M;++x){
            cin >> B[y][x];
        }
    }

    bool exist=false;

    for(int ly=0;ly<N;++ly){
        for(int lx=0;lx<N;++lx){
            if(ly+M-1>=N or lx+M-1>=N) continue;

            bool match=true;
            for(int y=0;y<M;++y){
                for(int x=0;x<M;++x){
                    if(A[ly+y][lx+x]!=B[y][x]) match=false;
                }
            }
            if(match) exist=true;
        }
    }

    if(exist) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n; cin >> n;
    vint a(n); vin(a);
    sort(all(a));
    print(a.back() - a[0]);

    return 0;
}


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

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int N;
  int result = 0;

  get_N(&N);

  result = N*N*N;

  printf("%d", result);

  return 0;
}



Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int A, B;
    cin >> A >> B;
    cout << A * B - (A + B - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;
int L[MAX/2+2],R[MAX/2+2];

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


llong inversion(int A[],int left,int right){
    llong cnt1,cnt2,m;
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        cnt1 = inversion(A,left,mid);
        cnt2 = inversion(A,mid,right);
        m = merge(A,left,right,mid);
        return cnt1 + cnt2 + m;
    }else{
        return 0;
    }
}

int main(){
    int n,A[MAX];
    //scanf("%d",&n);
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];
    llong ans = inversion(A,0,n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n, M, K;

int main(){
    ll ans = 0, x = 0;
    cin >> N >>K;
    REP(i,N){
        ll l;
        while(x <= K && ans < N+1){
            cin >> l;
            x +=l;
            ++ans;
        }
    }
    cout << ans;
}

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

const int MAX_V=100;
const int INF=1001001001;
int S,T;
struct edge{
    int to,cap,cost,rev;
    edge(int to,int cap,int cost,int rev)
        :to(to),cap(cap),cost(cost),rev(rev){}
};

vector<edge>G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
    int res=0;
    while(f>0){
        fill_n(dist,MAX_V,INF);
        dist[s]=0;
        bool update=true;
        while(update){
            update=false;
            for(int v=0;v<MAX_V;v++){
                if(dist[v]==INF)continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e=G[v][i];
                    if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
                        dist[e.to]=dist[v]+e.cost;
                        prevv[e.to]=v;
                        preve[e.to]=i;
                        update=true;
                    }
                }
            }
        }

        if(dist[t]==INF)return INF;
        int d=f;
        for(int v=t;v!=s;v=prevv[v]){
            edge &e=G[prevv[v]][preve[v]];
            d=min(d,e.cap);
        }

        f-=d;
        res+=d*dist[t];

        for(int v=t;v!=s;v=prevv[v]){
            edge &e=G[prevv[v]][preve[v]];
            e.cap-=d;
            G[v][e.rev].cap+=d;
        }
    }
    return res;
}


int main(){
    int M,W;
    while(cin>>M>>W,M||W){
        fill_n(G,MAX_V,vector<edge>());

        vector<int>bm(M),bw(W);
        for(int i=0;i<M;i++)cin>>bm[i];
        for(int i=0;i<W;i++)cin>>bw[i];

        S=98;T=99;

        for(int i=0;i<M;i++)add_edge(S,i,1,0);
        for(int i=0;i<W;i++)add_edge(i+M,T,1,0);

        for(int i=0;i<M;i++){
            for(int j=0;j<W;j++){
                int ab=abs(bm[i]-bw[j]);
                int val=ab*(ab-30)*(ab-30);
                add_edge(i,j+M,1,-val);
            }
        }

        cout<<-min_cost_flow(S,T,min(M,W))<<endl;
    }

    return 0;
}

Measured memory_bytes: 1212
import  sys

M,D = (int(i) for i in input().split()) 

if D<=20:
	print(0)
	sys.exit()

ans=0

for i in range(1,M+1):
	for g in range(21,D+1):
		if g%10>=2 and (g//10)*(g%10)==i:
			ans+=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define for0(i, n) for (int i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (ll)(n); ++i)
#define forc(i, l, r) for (int i = (ll)(l); i <= (ll)(r); ++i)
#define forr0(i, n) for (int i = (ll)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (ll)(n); i >= 1; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) ll((a).size())
#define mod 1000000007
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void fast()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool prime[1000001];
void sieve()
{
  memset(prime, true, sizeof(prime));
  prime[1]=false;
  for (int p=2; p*p<=1000000; p++)
  {
    if (prime[p] == true)
    {
        for (int i=p*p; i<=1000000; i += p)
                prime[i] = false;
    }
  }
}
void solve()
{
  ll n;
  cin >> n ;
  for(int i=1;i<=n;i++){
    cout << "ACL" ;

  }
  cout << endl;
}
int main()
{
  fast();
 /** ll t;
  cin >> t;
  ll c=1;
  while(t--){**/
  solve();


return 0;
}


Measured memory_bytes: 3604
<?php
	fscanf( STDIN, "%d", $n );
	$a = explode( ' ', trim( fgets( STDIN ) ) );
	$min = min( $a );
	$max = max( $a );
	$sum = 0;
	for( $i=0; $i<$n; $i++ ) {
		$sum += $a[$i];
	}
	print $min." ".$max." ".$sum;
?>

Measured memory_bytes: 8440
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static List<Integer> getStrings(Scanner sc, int num) {
		List<Integer> stringList = new ArrayList<>();
		while(num>0) {
			int nextInt = sc.nextInt();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> array = getStrings(sc, n-1);

		int[] jyoshi = new int[n];
		Arrays.fill(jyoshi,0);
		for (int i = 0; i < array.size(); i++) {
			jyoshi[array.get(i)-1]+=1;
		}

		for (int i = 0; i < jyoshi.length; i++) {
			System.out.println(jyoshi[i]);
		}
	}

}


Measured memory_bytes: 66804
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int tile[22][22];
int w, h;
int cnt;

void fill(int x, int y) {
	tile[x][y] = 0;
	cnt++;
	if (tile[x - 1][y] == 1) fill(x - 1, y);
	if (tile[x][y - 1] == 1) fill(x, y - 1);
	if (tile[x][y + 1] == 1) fill(x, y + 1);
	if (tile[x + 1][y] == 1) fill(x + 1, y);
}

int main() {
	int x = 0, y = 0;
	while (cin >> w >> h && (w || h)) {
		cnt = 0;
		for (int i = 0; i < 22; ++i) for (int j = 0; j < 22; ++j) tile[i][j] = 0;
		for (int i = 1; i <= h; ++i){
			for (int j = 1; j <= w; ++j) {
				char tmp;
				cin >> tmp;
				if (tmp == '.') tile[i][j] = 1;
				else if (tmp == '#') tile[i][j] = 0;
				else x = i, y = j, tile[i][j] = 1;
			}
		}
		fill(x, y);
		cout << cnt << endl;
	}

	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


i64 A, B;

int main() {
  cin >> A >> B;
  cout << max((i64)0, A - 2 * B) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

//s=1:正, s=-1:負
class A {
public:
  ll v, s, id;
  A(ll v, ll s, ll id): v(v), s(s), id(id) {}
};

int main(void) {
  ll N;
  cin >> N;
  ll i;
  ll sum=0;
  ll pc=0, nc=0;
  ll id=0;
  vector<ll> a(N);
  
  for(i=0; i<N; i++) {
    cin >> a[i];
    sum+=abs(a[i]);
    
    if(a[i]>=0) {
      pc++;
    }else {
      nc++;
    }
  }
  sort(a.begin(), a.end());
  
  if(pc==0) {
    pt(sum-abs(a[N-1])*2);
    
    ll p=a[N-1];
    for(i=0; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
  }else if(nc==0) {
    pt(sum-a[0]*2);
    
    ll p=a[0];
    for(i=1; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
    pt(a[N-1]<<" "<<p);
    
  }else {
    pt(sum);
    
    ll id=0;
    for(i=0; i<N; i++) {
      if(a[i]>=0) {
        id=i;
        break;
      }
    }
    
    ll p=a[0];
    for(i=id; i<N-1; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
    a[0]=p;
    p=a[N-1];
    for(i=0; i<id; i++) {
      pt(p<<" "<<a[i]);
      p-=a[i];
    }
    
  }
  
}












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

int main() {
  long long int n ;
  cin>> n;
 long long  int k=n%15 ;
  long long int s=n/15 ;
  long long int ans =s*s*60 ; 
if(k==0)
cout << ans<<endl ;
if(k==1)
cout<<ans +15*s+1<<endl;
if(k==2 ||k==3)
cout<<ans+30*s+3<<endl ;
if(k==4||k==5||k==6)
cout <<ans+45*s+7 <<endl ;
if(k==7)
cout<< ans+60*s+14 <<endl ;
if(k==8||k==9||k==10)
cout<<ans+75*s+22<<endl;
if(k==11||k==12)
cout<<ans+90*s+33 <<endl;
if(k==13)
cout<<ans+105*s+46<<endl;
if(k==14)
  cout << ans+120*s+60 << endl;
}


Measured memory_bytes: 3584
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int doubles, lengths, dat[8002], tmp[8002], rank_[8002];
bool compare_suffix(int i, int j) {
	if (dat[i] == dat[j]) {
		int ri = (i + doubles <= lengths ? dat[i + doubles] : -1);
		int rj = (j + doubles <= lengths ? dat[j + doubles] : -1);
		return ri < rj;
	}
	return dat[i] < dat[j];
}
vector<int> suffix_array(string S) {
	lengths = S.size();
	vector<int> arrays(lengths + 1);
	for (int i = 0; i <= lengths; i++) {
		arrays[i] = i;
		dat[i] = i < lengths ? S[i] : -1;
	}
	for (doubles = 1; doubles <= lengths; doubles <<= 1) {
		sort(arrays.begin(), arrays.begin() + lengths + 1, compare_suffix);
		tmp[arrays[0]] = 0;
		for (int i = 1; i <= lengths; i++) tmp[arrays[i]] = tmp[arrays[i - 1]] + (compare_suffix(arrays[i - 1], arrays[i]) ? 1 : 0);
		for (int i = 0; i <= lengths; i++) dat[i] = tmp[i];
	}
	return arrays;
}
vector<int> lcp(string s, vector<int> sa) {
	vector<int> ret; ret.resize(lengths + 1);
	for (int i = 0; i <= lengths; i++) rank_[sa[i]] = i;
	int h = 0; ret[0] = 0;
	for (int i = 0; i < lengths; i++) {
		int j = sa[rank_[i] - 1];
		if (h > 0) h--;
		for (; j + h < lengths && i + h < lengths; h++) {
			if (s[j + h] != s[i + h]) break;
		}
		ret[rank_[i] - 1] = h;
	}
	return ret;
}
string s, t; int sl;
int main() {
	while (cin >> s >> t) {
		sl = s.size();
		s += '$' + t;
		vector<int> v1 = suffix_array(s);
		vector<int> v2 = lcp(s, v1);
		int ret = 0;
		for (int i = 0; i < lengths; i++) {
			if ((v1[i] < sl) != (v1[i + 1] < sl)) {
				ret = max(ret, v2[i]);
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3552
A, B, C, D, E, F = list(map(int, input().split()))

max_concentration = 0
max_sugar = 0
max_sugar_water = 0
for a in range(31):
    if a * 100 * A > F:
        continue
    for b in range(31):
        if 100 * A * a + 100 * B * b > F:
            continue
        for c in range(3000 // C + 1):
            if E * (a * A + b * B) < c * C:
                continue
            if 100 * A * a + 100 * B * b + c * C > F:
                continue
            d = (E * (a * A + b * B) - c * C) // D
            if a * 100 * A + b * 100 * B + c * C + d * D == 0:
                continue
            if a * 100 * A + b * 100 * B + c * C + d * D > F:
                d = (F - (a * 100 * A + b * 100 * B + c * C)) // D
            tmp_sugar_water = a * 100 * A + b * 100 * B + c * C + d * D
            tmp_sugar = c * C + d * D
            tmp_concentration = tmp_sugar / tmp_sugar_water
            if max_concentration <= tmp_concentration:
                max_concentration = tmp_concentration
                max_sugar_water = tmp_sugar_water
                max_sugar = tmp_sugar
print(max_sugar_water, max_sugar)


Measured memory_bytes: 3064
n, m = map(int, input().split())
h = list(map(int, input().split()))
a, b = zip(*[list(map(int, input().split())) for i in range(m)])

flag = [1]*n
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        flag[b[i]-1] = 0
    elif h[a[i]-1] == h[b[i]-1]:
        flag[a[i]-1] = 0
        flag[b[i]-1] = 0
    else:
        flag[a[i]-1] = 0

print(sum(flag))

Measured memory_bytes: 102056
#include <bits/stdc++.h>
using namespace std;
int ans = 0x7fffffff;
int main() {
	int a, b, c;
  scanf ("%d%d%d", &a, &b ,&c);
  ans = min(abs(a - b) + abs(b - c), ans);
  ans = min(abs(b - c) + abs(c - a), ans);
  ans = min(abs(a - c) + abs(a - b), ans);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
N,M = map(int,input().split())
T = [[] for i in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    T[a].append(b)
    T[b].append(a)
Q = deque([(1,[1])])
ans = 0
while Q:
    p,V = Q.pop()
    if len(V)==N:
        ans += 1
        continue
    for c in T[p]:
        if not(c in V):
            Q.append((c,V+[c]))
print(ans)

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

using Graph = vector<vector<int>>;

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>num(n);
    rep(i,n){
        ll x;
        cin >>x;
        a[i] = x-1;
        num[x-1]++;
    }
    ll sum =0;
    rep(i, n){
        if(num[i]>0){
            sum+=num[i]*(num[i]-1)/2;
        }
    }
    
    rep(i, n){
        ll ans;
        ans = sum - (num[a[i]]-1);
        cout << ans <<endl;
    }
    
    return 0;
}



Measured memory_bytes: 6340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long k;
    cin >> n >> k;
    k--;
    long long ans = -1e18;
    vector<long long>v(n + 3);
    vector<int>p(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    for(int i = 1; i <= n; i++){
        vector<long long>pref;
        vector<int>vis(n + 3, 0);
        int x = i;
        long long sum = 0;
        while(1 == 1){
            if(vis[p[x]] == 1){
                break;
            }
            vis[p[x]] = 1;
            sum = sum + v[p[x]];
            pref.push_back(sum);
            x = p[x];
        }
        long long r = (long long)pref.size();
        vector<long long>mx(r + 3);
        mx[0] = pref[0];
        for(long long j = 1; j < r; j++){
            mx[j] = max(mx[j - 1], pref[j]);
        }
        long long cur = max(mx[min(k, r - 1)], (k/r) * pref[r - 1] + mx[k % r]);
        ans = max(ans, cur);
    }
    cout << ans;
    return 0;
}


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

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

    if(a!=b && a!=c && b==c) cout << "Yes" << endl;
    else if(b!=a && b!=c && a==c) cout << "Yes" << endl;
    else if(c!=a && c!=b && a==b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N,W = map(int,input().split())
ls = []
sum_v = 0
for i in range(N):
    ls.append(list(map(int,input().split())))
    sum_v += ls[-1][1]


dp = [[10**9+7]*(sum_v+1) for i in range(N+1) ]
# dp[i][j] はi番目までものを（できるだけ）価値j以上になるよう選ぶのときの最小の重さ
dp[0][0] = 0# ０個選んで価値j以上 --> dp[0][0]のみ達成

for i in range(1,N+1):
    w,v = ls[i-1]
    for j in range(0,sum_v+1):##
        if j>=v:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v] + w)
            #??dp[i-1][j]==inf かつ dp[i-1][j-v]==infのとき??
            #dp[i-1][j-v]にwを足したほうがでかい　--> dp[i][j]==infとなる(価値jは達成できない)

        else:# v > jのとき　何にvを足してもjを超えてしまうので（ピッタリ価値jにできないので）前のまま
            dp[i][j] = dp[i-1][j]
mx = 0
for i in range(1,N+1):
    for j in range(0,sum_v+1):
        if dp[i][j] <=W:
            mx = max(mx,j)
print(mx)


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int count = 0;
  for (int i = 0; i < A+1; i++) {
    for (int j = 0; j < B+1; j++) {
      for (int k = 0; k < C+1; k++) {
        if (X == 500 * i + 100 * j + 50 * k){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  //スペース区切り　input[0] が tmp[0], tmp[1],...
	n = input[0].split(" ");
  
  //この時点では全部文字列（数値に変換しないといけない）

	//文字列から10進数に変換するときはparseIntを使います
	var x = n*(100/108);
    var xx = Math.ceil(x);

    if(Math.floor(xx*108/100) == n){
      console.log('%d', xx);
    }else{
      console.log('%s', ':(');
    }

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372