akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		double a = in.nextDouble();
		double area = a*a*Math.PI;
		double circumference = 2*a*Math.PI;
		String x = String.format("%.6f", area);
		String y = String.format("%.6f", circumference);
		System.out.println(x+" "+y); 
	}
}

Measured memory_bytes: 28096
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);

        int n = stdin.nextInt();
        int[] a = new int[n];
        int count = 0;
        boolean exsitOdd = false;

        for (int i = 0; i < n; i++)
            a[i] = stdin.nextInt();

        while (!exsitOdd) {
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 == 1) {
                    exsitOdd = true;
                    break;
                }
                a[i] /= 2;
            }
            count++;
        }
        System.out.println(count - 1);
    }
}

Measured memory_bytes: 22996
hoge=[]
for i in range(5):
  hoge.append(int(input()))
  
ans=0
yobun=[]
for i in range(5):
  if(hoge[i]%10==0):
    yobun.append(10)
    ans+=hoge[i]
  else:
    yobun.append(hoge[i]%10)
    ans+=+10+hoge[i]-hoge[i]%10
    
hiku=min(yobun)
if(min(yobun)==10):
  print(sum(hoge))
else:
  print(ans+hiku -10)

Measured memory_bytes: 3064
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    string S;
    cin>>S;
    if(S[2]==S[3]&&S[4]==S[5])cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
}


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

int main(){
  vector<bool> flag(100001,false);
  vector<int> num(100001,0);
  flag[2]=true;
  for(int i=3;i<100001;i+=2){
    bool f=true;
    for(int j=3;j*j<=i;j++){
      if(i%j==0){
        f=false;
        break;
      }
    }if(f) flag[i]=true;
  }for(int i=3;i<100001;i++){
    if(flag[i] && flag[(i+1)/2]) num[i]++;
    num[i]+=num[i-1];
  }int q; cin>>q;
  for(int i=0;i<q;i++){
    int l,r; cin>>l>>r;
    cout<<num[r]-num[l-1]<<endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

struct UF{
  vector<int> data;
  UF(int n) { data.assign(n,-1); }
  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)  return;
    if (data[y] < data[x]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
  }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};


int main(){
  int n, m; cin >> n >> m;
  UF data(n);
  int ans = 0;
  rep(i,m){
    int a, b; cin >> a >> b; a--; b--;
    data.merge(a,b);
  }
  rep(i,n) chmax(ans,data.size(i));
  cout << ans<< endl;
  return 0;
}



Measured memory_bytes: 4024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for(int i=0; i<N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> dist(N, -1);
  queue<int> que_b;
  queue<int> que_w;
  dist[0] = 0;
  dist[N-1] = 0;
  que_b.push(0);
  que_w.push(N-1);
  int count_b=0;
  int count_w=0;
  int i=0,j=0;
  while(1){
    while(!que_b.empty()){
      int v = que_b.front();
      if(dist[v] > i){
        i++;
        break;
      }
      que_b.pop();
      for(int nv: G[v]){
        if(dist[nv] != -1){
          continue;
        }
        count_b++;
        dist[nv] = dist[v] + 1;
        que_b.push(nv);
      }
    }
    while(!que_w.empty()){
      int v = que_w.front();
      if(dist[v] > j){
        j++;
        break;
      }
      que_w.pop();
      for(int nv: G[v]){
        if(dist[nv] != -1){
          continue;
        }
        count_w++;
        dist[nv] = dist[v] + 1;
        que_w.push(nv);
      }
    }
    if(que_b.empty() && que_w.empty()){
      break;
    }
  }
  if(count_b <= count_w){
    cout << "Snuke" << endl;
  }else{
    cout << "Fennec" << endl;
  }
  return 0;
}


Measured memory_bytes: 6144
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	sl := strings.Split(s, "")
	tl := strings.Split(t, "")
	sort.Strings(sl)
	sort.Sort(sort.Reverse(sort.StringSlice(tl)))
	s = strings.Join(sl, "")
	t = strings.Join(tl, "")
	if s < t {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int X = Integer.parseInt(br.readLine());
		long ans = 0;
		for(int x=1; x<32; x++) {
			for(int b=2; b<=10; b++) {
				int B = (int)Math.pow(x, b);
				if(B<=X) {
					if(B>ans) {
						ans=B;
					}
				}else{
					break;
				}
			}
		}
		
		System.out.println(ans);	
	}
}

Measured memory_bytes: 32516
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
all = 0
for i in range(n):
	all += abs(a[i+1] - a[i])

for i in range(1,n+1):
	if i != n:
		print(all - (abs(a[i+1]-a[i]) + abs(a[i] - a[i-1])) + abs(a[i+1]-a[i-1]) + abs(a[n]))
	else:
		print(all - abs(a[i]-a[i-1]) + abs(a[n-1]))

Measured memory_bytes: 14048
while True:
    h,w = map(int,input().split())
    if h==w==0:
        break
    for i in range(h):
      ans=""
      for j in range(w):
        if (i+j)%2 == 0:
          ans += "#"
        else:
          ans += "."
      print(ans)
    print()
            


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


def main():
    N = int(input())
    la = list(map(int, input().split()))
    num_negative = sum(1 for a in la if a < 0)
    if num_negative % 2 == 0:
        print(sum(abs(a) for a in la))
    else:
        print(sum(abs(a) for a in la) - 2 * min(abs(a) for a in la))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14412
/**
 *    author:  Atreus
**/
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
ll w[maxn], v[maxn], dp[120][maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n, W;
	cin >> n >> W;
	for (int i = 1; i <= n; i++)
		cin >> w[i] >> v[i];
	ll answer = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= W; j++){
			dp[i][j] = dp[i - 1][j];
			if (j < w[i])
				continue;
			dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
			answer = max(answer, dp[i][j]);
		}
	}
	cout << answer << endl;
}


Measured memory_bytes: 81408
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, sum = 0;
	cin >> a >> b;
	int arr[9999];
	for(int i=1; i<=a; i++)
	{
		arr[i] = i + b - 1;
		sum += arr[i];
	}
//	printf("%d\n",sum);
	int ans = 1;
	for(int i=2; i<=a; i++)
		if(abs(arr[i]) < abs(arr[ans]))
			ans = i;
	printf("%d\n",sum - arr[ans]);
	return 0;
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h> 
 
using namespace std;
 
 
#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

vector<ll>v;
bool OK(ll N){
    for(ll i=2;i*i<=N;i++){
        if(N%i==0) return 0;
    }
    return 1;
}
int main(){
    ll a,b,c;
    sfl(a),sfl(b);
    c=__gcd(a,b);
    for(ll i=1;i*i<=c;i++){
        if(c%i==0){
            if(c/i==i){
                v.pb(i);
            }
            else{
                v.pb(i);
                v.pb(c/i);
            }
        }
    }
    sort(all(v));
    ll cnt=1;
    for(ll i=1;i<v.size();i++){
        if(OK(v[i])){
            cnt++;
        }
    }

    pfl(cnt);
    return 0;
}

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

using namespace std;

typedef long long int lli;

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

    int n, h;
    
    cin >> n >> h;
    int high = h-1;
    for (int i=0; i<n-1; i++) {
        cin >> h;
        if (high > h) {
            cout << "No" << endl;
            return 0;
        }
        else if (high < h) {
            high = h-1;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

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

    int n;
    cin >> n;

    int num_rates[9] = {0};
    rep(i, n){
        int a;
        cin >> a;
        ++num_rates[min(8, a/400)];
    }
    int res = 0;
    rep(i, 8){
        if(num_rates[i]>0)++res;
    }
    if(res) cout << res << " " << res + num_rates[8] << endl;
    else cout << 1 << " " << num_rates[8] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	// 変数定義
	int iChukan;	// 中間試験
	int iKimatsu;	// 期末試験
	int iSaishi;	// 再試験

	while (1)
	{
		// 入力：中間、期末、再試の点数
		scanf("%d %d %d", &iChukan, &iKimatsu, &iSaishi);
		if (iChukan == -1 && iKimatsu == -1 && iSaishi == -1)
		{
			break;
		}

		// 出力：成績
		//// 中間試験、期末試験のいずれかを欠席した場合成績は F
		if (iChukan * iKimatsu < 0)
		{
			printf("F\n");
		}
		////中間試験と期末試験の合計点数が 80 以上ならば成績は A 
		else if (iChukan + iKimatsu >= 80)
		{
			printf("A\n");
		}
		//// 中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B
		else if (65 <= iChukan + iKimatsu && iChukan + iKimatsu < 80)
		{
			printf("B\n");
		}
		//// 中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C
		else if (50 <= iChukan + iKimatsu && iChukan + iKimatsu < 65)
		{
			printf("C\n");
		}
		//// 中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D
		else if (30 <= iChukan + iKimatsu && iChukan + iKimatsu < 50)
		{
			// 再試験の点数が 50 以上ならば成績は C
			if (50 <= iSaishi) {
				printf("C\n");
			}
			else
			{
				printf("D\n");
			}
		}
		///// 中間試験と期末試験の合計点数が 30 未満ならば成績は F
		else
		{
			printf("F\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main(){

long n;cin>>n;
long largest=0;
long temp=0;
long ans=1;
cin>>largest;
for(long i=1; i<n; i++){
  cin>>temp;
  if(temp<=largest){
    ans++;
    largest=temp;
  }else{

  }

}
cout<<ans;

}


Measured memory_bytes: 256
#include <algorithm>
 #include <iostream>
 #include <vector>
 using namespace std;
 typedef long long ll;
 const int INF = 1 << 30;
 const ll INFll = 1ll << 60;
 
 int main() {
   int n,a;
   cin >> n >> a;
   if(a >= n%500){
 	cout << "Yes" << endl;
   }else {
     cout << "No" << endl;
   }
 	return 0;
 }

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

int main(){
  char s[200010] = {};
  int l;
  int i_A, i_Z;

  scanf("%s", s);
  l = strlen(s);

  for(int i = 0; i < l; i++){
    if(s[i] == 'A'){
      i_A = i;
      break;
    }
  }
  for(int i = 0; i < l; i++){
    if(s[i] == 'Z'){
      i_Z = i;
    }
  }
  printf("%d\n", i_Z - i_A + 1);
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k;
	cin >> k;
	cout << 50 << endl;
	REP(i, 50) {
		if (i < k % 50) {
			cout << (49 + k / 50+50-k%50+1);
		}
		else cout << 49 + k / 50-k%50;
		if (i != 49)cout << " ";
		else cout << endl;
	}
}


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

int main(){
  
  string s;
  int k,a=0;
  cin>>s>>k;

  for(int i=0;i<k;i++){
    if(s[i]!='1'){
      cout<<s[i]<<endl;
      break;
    }
    else a++;
  }
  

  if(a==k) cout<<"1"<<endl;

  return 0;
}


Measured memory_bytes: 256
def resolve():
    N, M = map(int, input().split())
    if N%2==1:
        for i in range(1, M+1):
            a, b = i, N-i
            print(a, b)
    else:
        for i in range(1, M+1):
            a, b = i, N - i
            # 円として配置したとき、b-aが半分以上になったら片方だけ進める
            if b-a <= N//2:
                a += 1
            print(a, b)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 69524
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	n-=m;
	if(n<=0){
		cout<<1<<endl;
		return 0;
	}
	//cout<<n<<endl;
	//cout<<((n+m-1-1)/m-1)<<endl;
	cout<<((n+m-1-1)/(m-1))+1<<endl;
	
	return 0;
}

Measured memory_bytes: 3636
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, s: string[][] } => {
  const N = +lines[0]
  const s = lines.slice(1, 1 + N).map(line => line.split(''))
  const obj = { N, s }
  debug(obj)
  return obj
}

const sigma = (num: number) => {
  let total = 0
  for (let i = num; i > 0; i--) {
    total += i
  }
  return total
}

// solver
export const solve = (lines: string[]): string => {
  const { s } = parseLines(lines)
  const dict: { [word: string]: number } = {}
  s.forEach(v => {
    v.sort()
    const word: string = v.join('')
    dict[word] = dict[word] === undefined ? 0 : dict[word] + 1
  })
  const result: number = Object.keys(dict).reduce((prev: number, current: string) => prev + sigma(dict[current]), 0)
  return `${result}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 72708
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;

int n, point[200020], te = 0;
struct e {int to, next; } edge[400040];
void add (int a, int b) {
	te ++;
	edge[te].to = b;
	edge[te].next = point[a];
	point[a] = te;
}

int mx = 0, mx_id = 0;
int dis[200020];

void find_mx (int x) {
	// cerr << x << " " << dis[x] << endl;
	if (dis[x] > mx) {
		mx = dis[x], mx_id = x;
	}
	for (int e = point[x]; e; e = edge[e].next) {
		int to = edge[e].to;
		if (dis[to])
			continue ;
		dis[to] = dis[x] + 1;
		find_mx(to);
	}
}

int main() {
	cin >> n;
	for (int a, b, i = 1; i < n; i ++) {
		cin >> a >> b;
		add (a, b);
		add (b, a);
	}
	mx = 0;
	memset(dis, 0, sizeof dis);
	dis[1] = 1;
	find_mx(1);
	memset(dis, 0, sizeof dis);
	mx = 0;
	dis[mx_id] = 1;
	find_mx(mx_id);
	// cerr << mx << " mx" << endl;
	cout << (mx % 3 == 2 ? "Second" : "First") << endl;
	return 0;
}


Measured memory_bytes: 11136
function main()
  
  (N, K) = map(x -> parse(Int, x), split(readline()))
  
  nums = Tuple[]
  
  for i in 1:N
    (a, b) = map(x -> parse(Int, x), split(readline()))
    push!(nums, (a, b))
  end
  
  sort!(nums, by=x -> x[1])
  
  i = 1
  ans = 0
  
  while K > 0
    ans = nums[i][1]
    K -= nums[i][2]
    i += 1
  end

  println(ans)
  
end

main()

Measured memory_bytes: 172532
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
  string s;
  int ans = 0 ;
  cin >> s;
  if(s.length()==1){
    cout << "0" << endl;
    return 0;
  }

  for(int i=0;i<s.length()-1;i++){
    char niko = s[i];
    char ikko = s[i+1];
    if(niko == ikko){
      s[i+1] = (s[i+1]== '1' ? '0' : '1');
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0)  break;
            boolean judge = false;
            List<Integer> list = new ArrayList<Integer>();
            long[] temp = new long[4001];
            for (int i = 0; i < n; i++) {
                int num = sc.nextInt();
                long a = sc.nextLong();
                long b = sc.nextLong();
                temp[num] += a * b;
                if (!list.contains(num)) {
                    list.add(num);
                }
 
            }
            for (int i : list) {
                if (temp[i] >= 1000000) {
                    judge = true;
                    System.out.println(i);
                }
            }
            if (!judge)System.out.println("NA");
        }
    }
}

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

long long n, k, m = 0;
const long long M = 1e9 + 7;
long long a[100001];

long long power(long long a, long long b) {
    long long c = 1, d = a;

    while (b > 0) {
        if (b & 1)
            c = c * d % M;

        d = d * d % M;
        b >>= 1;
    }

    return c;
}

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

    for (long long i = 1; i <= k; i++)
        a[i] = power(k / i, n);

    for (long long i = k; i > 0; i--)
        for (long long j = 2; i * j <= k; j++)
            a[i] = (a[i] + M - a[i * j]) % M;

    for (long long i = 1; i <= k; i++)
        m = (m + a[i] * i) % M;

    cout << m << endl;
}


Measured memory_bytes: 4296
#include<iostream>
#include<stack>
#include<string>
#include<cstdlib>

using namespace std;

int main(int argc, char const *argv[])
{
    stack<int> numStack;
    string s;

    while( cin >> s) {
        if (s == "+" ) {
            int a = numStack.top();
            numStack.pop();
            int b = numStack.top();
            numStack.pop();
            numStack.push(a + b);
        } else if (s == "-") {
            int a = numStack.top();
            numStack.pop();
            int b = numStack.top();
            numStack.pop();
            numStack.push(b - a);

        } else if ( s == "*" ) {
            int a = numStack.top();
            numStack.pop();
            int b = numStack.top();
            numStack.pop();
            numStack.push(a * b);
        } else {
            numStack.push(atoi(s.c_str()));
        }
    }
    cout<<numStack.top()<<endl;
    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main(){
    int K, N;
    while(cin >> K >> N){
        vector<vector<long long>> pair(K+1, vector<long long>(N+1, 0));
        vector<vector<long long>> solo(K+1, vector<long long>(N+1, 0));
        pair[0][0] = 1;
        solo[0][0] = 1;
        for(int i=1;i<=K;i++){
            long long sum = 0;
            for(int j=0;j<=N;j++){
                pair[i][j] += pair[i-1][j] + 2 * sum;
                pair[i][j] %= MOD;
                sum += pair[i-1][j];
                sum %= MOD;
            }
        }
        for(int i=1;i<=K;i++){
            long long sum = 0;
            for(int j=0;j<=N;j++){
                sum += solo[i-1][j];
                sum %= MOD;
                solo[i][j] = sum;
            }
        }
        vector<int> invalid(2*K+1, 0);
        for(int i=1;i<=K;i++){
            for(int j=i+1;j<=K;j++){
                ++invalid[i+j];
            }
        }
        for(int k=2;k<=2*K;k++){
            long long res = 0;
            int pr = invalid[k];
            if(k%2 == 0){
                for(int i=0;i<=N;i++){
                    res += pair[pr][i] * (solo[K-2*pr-1][N-i] + (i==N ? 0 : solo[K-2*pr-1][N-i-1]));
                    res %= MOD;
                }
            } else {
                for(int i=0;i<=N;i++){
                    res += pair[pr][i] * solo[K-2*pr][N-i];
                    res %= MOD;
                }
            }
            cout << res << endl;
        }
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char const *argv[]) {
	ll N, A, B; cin >> N >> A >> B;
	ll ans = 2 * A - 2 * B + (B - A) * N + 1;
	cout << (ans > 0 ? ans : 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    string ans;
    while (n) {
        int c = (n - 1) % 26;
        ans += 'a' + c;  
        n = (n - 1) / 26;
    }
    // cout << cnt << endl;
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3656
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
-- templete

f p q = let (ls, m) = g (p*10) q [] in case m of 
    Nothing -> [concat $ map show $ reverse ls]
    Just i -> let ll = length ls - i in [concat $ map show $ reverse ls, replicate ll ' ' ++ replicate i '^']

g 0 q ls = (map fst ls, Nothing)
g p q ls = case (findIndex ((==p) . snd) ls) of
    Just i -> (map fst ls, Just (i+1))
    Nothing -> let (x,y) = divMod p q in g (y*10) q ((x, p):ls)

main = map (apply2 f . map readInt . words) . lines <$> getContents >>= mapM_ (mapM_ putStrLn)


Measured memory_bytes: 4192
# input
n , m = map(int, list(input().split()))
s = list(map(int, list(input())))[::-1]

# process
ans = [0]

p = 0
i = -1
while p < n:
    j = m
    while True:
        if p+j < n+1 and s[p+j] == 0:
            ans.append(j)
            p += j
            i += 1
            break
        
        j -= 1        
        if j == 0:
            if ans[i] > 1:
                ans[i] -=1
                p -= 1
            else:
                ans = [-1]
                break

    if ans[0] == -1:
        break

# output
if ans[0] == -1:
    print("-1")
else:
    ans.pop(0)
    print(" ".join(map(str, (ans[::-1]))))



Measured memory_bytes: 11652
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int []po=new int[26];
  String str=sc.next();
  char[]c=str.toCharArray();
  for(int i=0;i<c.length;i++)po[c[i]-'a']++;
  boolean b=true;
  for(int i=0;i<po.length;i++){
  if(po[i]>1)b=false;
  }
  System.out.println(b?"yes":"no");
}
}


Measured memory_bytes: 23124
#include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <set>
    const int N = 2e5 + 5; 
    const int INF = 1e9; 
    using namespace std;
     
    int n, m, p[N], val[N], cnt[N]; 
    char s[N]; 
     
    template < typename T >
    inline T read()
    {
    	T x = 0, w = 1; char c = getchar();
    	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return x * w; 
    }
     
    struct SegTree
    {
    	struct Tree { int mx; } t[N << 2];
    	void build(int p, int l, int r)
    		{
    			if(l == r) { t[p].mx = 1 - INF; return; }
    			int mid = (l + r) >> 1; 
    			build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
    			t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx); 
    		}
    	int query(int p, int l, int r, int ql, int qr)
    		{
    			if(ql <= l && r <= qr) return t[p].mx; 
    			int mid = (l + r) >> 1; int ans = -INF; 
    			if(ql <= mid) ans = query(p << 1, l, mid, ql, qr); 
    			if(mid < qr) ans = max(ans, query(p << 1 | 1, mid + 1, r, ql, qr)); 
    			return ans; 
    		}
    	void modify(int p, int l, int r, int k, int x)
    		{
    			if(l == r) return (void) (t[p].mx = x); 
    			int mid = (l + r) >> 1; 
    			if(k <= mid) modify(p << 1, l, mid, k, x); 
    			else modify(p << 1 | 1, mid + 1, r, k, x); 
    			t[p].mx = max(t[p << 1].mx, t[p << 1 | 1].mx); 
    		}
    } Odd, Even; 
     
    bool check(int mx, int t)
    {
    	if(t < 0) return 0;
    	if(t & 1) return Odd.query(1, 1, n, mx, n) >= t;
    	else return Even.query(1, 1, n, mx, n) >= t; 
    }
     
    int main()
    {
    #ifndef ONLINE_JUDGE
    	freopen("cpp.in", "r", stdin); 
    #endif
    	n = read <int> ();
    	for(int mx = 0, i = 1; i <= n; i++)
    	{
    		p[i] = read <int> (); 
    		if(p[i] > mx) val[i] = 2, mx = p[i];
    		else val[i] = 1; 
    	}
    	Odd.build(1, 1, n); 
    	for(int mx1, mx2, i = n; i >= 1; i--)
    	{
    		mx1 = Odd.query(1, 1, n, p[i], n), mx2 = Even.query(1, 1, n, p[i], n); 
    		if(val[i] & 1) Odd.modify(1, 1, n, p[i], mx2 + val[i]), Even.modify(1, 1, n, p[i], mx1 + val[i]); 
    		else Odd.modify(1, 1, n, p[i], mx1 + val[i]), Even.modify(1, 1, n, p[i], mx2 + val[i]); 
    	}
    	for(int i = n; i >= 1; i--) cnt[i] = cnt[i + 1] + val[i] - 1; 
    	int cntx = 0, cnty = 0, mxx = 0, mxy = 0; 
    	for(int i = 1; i <= n; i++)
    	{
    		Odd.modify(1, 1, n, p[i], 1 - INF), Even.modify(1, 1, n, p[i], 0); 
    		if(check(mxy, cntx + cnt[i + 1] - cnty + (p[i] > mxx))) s[i] = '0', cntx += (p[i] > mxx), mxx = max(mxx, p[i]); 
    		else if(check(max(mxx, p[i]), cnty + cnt[i + 1] - cntx - (p[i] > mxx))) s[i] = '0', cntx += (p[i] > mxx), mxx = max(mxx, p[i]); 
    		else s[i] = '1', cnty += (p[i] > mxy), mxy = max(mxy, p[i]); 
    	}
    	if(cntx != cnty) puts("-1");
    	else printf("%s\n", s + 1); 
    	return 0;
    }

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

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << endl;}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const ll inf = 1e12;
const ll mod = 1e9 + 7;


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

  ll a, b;
  cin >> a >> b;

  cout << a * b / __gcd(a, b) << endl;

}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    rep(i,0,s.size())cout<<(char)('A'+((s[i]-'A')+n)%26);
    cout << ednl;
}

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

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
#include <fstream>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e9 
typedef long long ll;
typedef long double ld;
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=k;
    REP(i,n-1){
        ans*=k-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,summoney,itiman,gosen,sen;
  cin>>n>>summoney;
  
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      if(i*10000+j*5000+(n-i-j)*1000==summoney){
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm> 
#include <cmath>
#include <cstdlib>
using namespace std;
#define ll long long 
#define gc getchar_unlocked
const ll int INF = 1e18;
const int MOD = 1000000007;
const int MAXN = 1e5 + 10;

int vis[MAXN][3],dp[MAXN][3],N,A[3][MAXN];
int solve(int pos,int last)
{
	if(pos == N + 1)
      return 0;
	if(vis[pos][last])
      return dp[pos][last];
	vis[pos][last] = 1;
	int best = 0;
	for(int i = 0;i<3;i++)
    {
		if(i != last) best = max(best, A[i][pos] + solve(pos+1,i) );
	}
	return dp[pos][last] = best;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
	cin>>N;
	for(int i=1;i<=N;i++)
    {
		cin>>A[0][i]>>A[1][i]>>A[2][i];	
	}
  	ll ans = max(solve(1,0),max(solve(1,1),solve(1,2)));
  	cout<<ans<<"\n";
}

Measured memory_bytes: 14896
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,m;
	int F,f;
	
	int big[101][101];
	int sma[4][51][51];
	
	while(cin>>n>>m,m){
		F=1;
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>big[j][i];
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m;j++){
				cin>>sma[0][j][i];
				sma[1][m-i+1][j]=sma[0][j][i];
				sma[2][m-j+1][m-i+1]=sma[0][j][i];
				sma[3][i][m-j+1]=sma[0][j][i];
			}
		}
		for(int i=1;i<=n-m+1 && F;i++){
			for(int j=1;j<=n-m+1 && F;j++){
				
				for(int k=0;k<4 && F;k++){
					f=1;
					for(int y=1;y<=m && F && f;y++){
						for(int x=1;x<=m && F && f;x++){
							if(sma[k][x][y]!=-1 && sma[k][x][y]!=big[x+j-1][y+i-1]){
								f=0;
							}
							
						}
					}
					if(f){
						
						for(int y=1;y<=m && F;y++){
							for(int x=1;x<=m && F;x++){
								if(sma[k][x][y]!=-1){
									cout<<x+j-1<<" "<<y+i-1<<endl;
									F=0;
								}
							}
						}
					}
				}
				
			}
			
		}
		if(F)cout<<"NA"<<endl;
	}
	
	
	
	
	return 0;
}


Measured memory_bytes: 1244
n, k = [int(i) for i in input().split()]

if k > (n - 2) * (n - 1) // 2:
    print(-1)
    exit()

E = []

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if j == n:
            E.append((i, j))
            continue
        if k > 0:
            k -= 1
            continue
        E.append((i, j))

print(len(E))
for e in E:
    print(*e)

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

int main(){
    int k;
    cin >> k;
    vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec[k-1] << endl;

}

Measured memory_bytes: 256
def check(s,t):
    count=[]
    if t in s:
        return 0
    else    :
        for i in range(len(s)-len(t)+1):
            count.append(0)
            for j in range(len(t)):
                if not t[j]==s[i+j]:
                    count[i]+=1
    return min(count)
if __name__ == '__main__':
    s = input().rstrip()
    t= input().rstrip()

    print(check(s,t))


Measured memory_bytes: 9056
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m), ans(n);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < m; i++){
    cin >> c[i] >> d[i];
  }
  for(int i = 0; i < n; i++){
    int mindis = abs(a[i] - c[0]) + abs(b[i] - d[0]), minj = 0;
    for(int j = 1; j < m; j++){
      int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(dis < mindis){
        mindis = dis;
        minj = j;
      }
    }
    ans[i] = minj;
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] + 1 << endl;
  }
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        long[] H = ReadLine().Split(' ').Select(long.Parse).ToArray();
        bool isYes = true;
        long max = 0L;
        for(int i = 0;i < N - 1; i++)
        {
            if(H[i] > H[i + 1] + 1 || H[i + 1] < max - 1)
            {
                WriteLine("No");
                isYes = false;
                return;
            }
            else
            {
                if(max < H[i + 1])
                {
                 	max = H[i + 1]; 
                }
            }
        }
        if (isYes)
        {
            WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 29404
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  REP(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for (auto x : mp) {
    if (x.first == x.second) continue;
    if (x.second < x.first) {
      ans += x.second;
    } else {
      ans += x.second - x.first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6272
#include<iostream>
#include<queue>
#include<cstring>

using namespace std ;

struct ST
{
	int tx ,ty ;
	int kx ,ky ;
	int cnt ;
	ST( int a ,int s ,int d ,int f ,int g ) : tx( a ) ,ty( s ) ,kx( d ) ,ky( f ) ,cnt( g ){}
} ;

int mx[ 4 ] = { 1 ,0 ,0 ,-1 } ;
int my[ 4 ] = { 0 ,1 ,-1 ,0 } ;
int map[ 50 ][ 50 ] ;

int w ,h ;
int tx ,kx ;
int ty ,ky ;

void ans()
{
	queue< ST > que ;
	bool came[ 50 ][ 50 ][ 50 ][ 50 ] = { false } ;
	que.push( ST( tx - 1 ,ty - 1 ,kx - 1 ,ky - 1 ,0 ) ) ;
	came[ tx - 1 ][ ty - 1 ][ kx - 1 ][ ky - 1 ] = true ;
	while( ! que.empty() )
	{
		ST st = que.front() ;
		if( st.tx == st.kx && st.ty == st.ky )
		{
			cout << st.cnt << endl ;
			return ;
		}
		else if( st.cnt >= 100 )
		{
			break ;
		}
		que.pop() ;
		for( int i = 0 ; i < 4 ; i++ )
		{
			int j = 3 - i ;
			tx = st.tx + mx[ i ] ;
			kx = st.kx + mx[ j ] ;
			ty = st.ty + my[ i ] ;
			ky = st.ky + my[ j ] ;
			if( tx < 0 || tx >= w || ty < 0 || ty >= h || map[ ty ][ tx ] == 1 )
			{
				tx = st.tx ;
				ty = st.ty ;
			}
			if( kx < 0 || kx >= w || ky < 0 || ky >= h || map[ ky ][ kx ] == 1 )
			{
				kx = st.kx ;
				ky = st.ky ;
			}
			if( came[ tx ][ ty ][ kx ][ ky ] == false )
			{
				que.push( ST( tx ,ty ,kx ,ky ,st.cnt + 1 ) ) ;
				came[ tx ][ ty ][ kx ][ ky ] = true ;
			}
		}
	}
	cout << "NA" << endl ;
}

int main()
{
	while( cin >> w >> h ,h )
	{
		cin >> tx >> ty ;
		cin >> kx >> ky ;
		for( int i = 0 ; i < h ; i++ )
		{
			for( int j = 0 ; j < w ; j++ )
			{
				cin >> map[ i ][ j ] ;
			}
		}
		ans() ;
	}
}

Measured memory_bytes: 9204
N, Q = [int(x) for x in raw_input().split()]

class Node:

    def __init__(self, x, y):
        self.value = 0
        self.x = x
        self.y = y
        self.l = self.r = None

        if y - x > 1:
            mid = (x + y) / 2
            self.l = Node(x, mid)
            self.r = Node(mid, y)

    def add(self, i, x):
        if self.x <= i < self.y:
            self.value += x
            if self.l:
                self.l.add(i, x)
            if self.r:
                self.r.add(i, x)

    def sum(self, x, y):
        if y <= self.x or self.y <= x:
            return 0
        if x <= self.x and self.y <= y:
            return self.value
        return self.l.sum(x, y) + self.r.sum(x, y)

t = Node(0, N)

for _ in xrange(Q):
    com, x, y = [int(s) for s in raw_input().split()]
    if com == 0:
        t.add(x-1, y)
    if com == 1:
        print t.sum(x-1, y)

Measured memory_bytes: 82300
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end(), greater<long long>());
    return ret;
}
 
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    int sum = 0;
    REP(i, N) {
        cin >> A.at(i);
        sum += A[i];
    }
    auto d = divisor(sum);  // 合計値の約数
 
    vector<int> r(N);
    REP(i, d.size()) {
        REP(j, N) { r[j] = A[j] % d[i]; }
        sort(ALL(r));
        vector<int> L(N + 1), R(N + 1);
        L[0] = 0;
        R[N] = 0;
        REP(j, N) { L[j + 1] += r[j] + L[j]; }
        for (int j = N - 1; j >= 0; j--) {
            R[j] += (d[i] - r[j]) + R[j + 1];
        }
        REP(j, N + 1) {
            if (L[j] == R[j] && L[j] <= K) {
                cout << d[i] << endl;
                return 0;
            }
        }
    }
 
    cout << N << endl;
    return 0;
}
 

Measured memory_bytes: 256
#include<stdio.h>
int array[10000000];
int number;




int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}









void max (int i){
  int l,r,largest;

  l=left(i);
  r=right(i);

  if(l<=number && array[l]>array[i]){largest=l;}

  else{largest=i;}

  if(r<=number && array[r]>array[largest]){largest=r;}

  int tmp;
  if(largest !=i){
    tmp=array[i];
    array[i]=array[largest];
    array[largest]=tmp;

    max(largest);
  }


}


int main(){

  
  scanf("%d",&number);


  
  int i;
  for(i=1;i<=number;i++){
    scanf("%d",&array[i]);
    }

  for(i=number/2;i>=1;i--){max(i);}


   for(i=1;i<=number;i++){
     {printf(" %d",array[i]);}
   
    }

   printf("\n");

  



  void max (int i);
  

  return 0;
}




Measured memory_bytes: 3652
import java.util.HashMap;
import java.util.Map;
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 = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0 ; i < n ; i++) {
			if(!map.containsKey(a[i]) || (map.containsKey(a[i]) && map.get(a[i]) == 0)) {
				map.put(a[i], 1);
			} else {
				map.put(a[i], 0);
			}
		}
		int ans = 0;
		for(int key : map.keySet()) {
			if(map.get(key) == 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

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

if N<4:
    print(0)
else:
    a = [0] * N
    R, G, B = 0, 0, 0
    for i in range(N):
        if S[i] == "R":
            a[i] = 1
            R += 1
        if S[i] == "G":
            a[i] = 2
            G += 1
        if S[i] == "B":
            a[i] = 4
            B += 1

    rgb = R * G * B
    cnt = 0
    for i in range(N-2):
        for d in range(1, (N-i-1) // 2+1):
            if a[i] + a[i+d] + a[i+2*d] == 7:
                cnt += 1

    print(rgb -cnt)


Measured memory_bytes: 68104
#include <cstdio>
#include <queue>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const int N = 2005;
bool G[N][N];
bool used[N];
vector <int> g[N];
int n, a[N], sz;
int in[N];
priority_queue <int> pq;

inline int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

void dfs(int i) {
	used[i] = 1;
	for (int j = 0; j < n; ++ j) if (!used[j] && G[i][j]) { g[i].push_back(j); ++ in[j]; dfs(j); }
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	sort(a, a + n);
	for (int i = 0; i < n; ++ i) for (int j = 0; j < n; ++ j) if (i ^ j) G[i][j] = (gcd(a[i], a[j]) != 1);
	for (int i = 0; i < n; ++ i) if (!used[i]) dfs(i);
	for (int i = 0; i < n; ++ i) if (!in[i]) pq.push(i);
	while (!pq.empty()) {
		int i = pq.top(); pq.pop();
		printf("%d ", a[i]);
		for (int j = 0; j < (int) g[i].size(); ++ j) {
			-- in[g[i][j]];
			if (!in[g[i][j]]) pq.push(g[i][j]);
		}
	}
	puts("");
	return 0;
}


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

int main(void){
    int cockingT[5], array[5], min = 10, signum = 0, sum = 0, count = 0;

    int i;
    for(i = 0; i < 5; i++){
        scanf("%d", &cockingT[i]);
    }

    for(i = 0; i < 5; i++){
        array[i] = cockingT[i] % 10;
    }

    for(i = 0; i < 5; i++){
        if(array[i] != 0){
            if(array[i] < min){
                min = array[i];
                signum = i;
            }
        }else{
            count += 1;
        }
    }
    sum += cockingT[signum];
    
    for(i = signum + 1; i < 5; i++){
        sum += cockingT[i] + 10 - array[i];
    }
    for(i = signum - 1; i >= 0; i--){
        sum += cockingT[i] + 10 - array[i];
    }

    if(count == 5) count--;
    sum -= count * 10;
    printf("%d\n", sum);
    return 0;

}


Measured memory_bytes: 256