akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok cerr << "ok\n";
#define whatis(x) cerr << #x << " = " << x << endl;

const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;

int ans[N];
int n, a, b;
bool used[N];

void printans() {
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
  exit(0);
}

void no() {
  puts("-1");
  exit(0);
}

main() {
  scanf("%d %d %d", &n, &a, &b);
  if (a + b - 1 > n) {
    no();
  }
  int in = n;
  if (a + b - 1 == n) {
    for (int i = a; i >= 1; i--) {
      ans[i] = in--;
    }
    for (int i = a + 1; i <= n; i++) {
      ans[i] = in--;
    }
    printans();
  }
  for (int i = n - b + 1; i <= n; i++) {
    ans[i] = in--;
  }
  int ost = n - b;
  a--;
  if (a > ost || a <= 0) {
    no();
  }
  int st = 1;
  int sub;
  int ind = 1;
  for (int i = n - b + 1 - a; i >= 1; i -= a) {
    for (int j = i; j <= i + a - 1; j++) {
      if (ind > ost) no();
      ans[j] = ind++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i]) break;
    ans[i] = ind++;
  }
  a++;
  vector < int > d(n + 1, inf);
  d[0] = -inf;
  for (int i = 1; i <= n; i++) {
    int pos = lower_bound(d.begin(), d.end(), ans[i]) - d.begin();
    d[pos] = ans[i];
  }
  in = n;
  while (d[in] == inf) in--;
  if (in != a) no();
  for (int i = 0; i < d.size(); i++) {
    d[i] = inf;
  }
  d[0] = -inf;
  for (int i = n; i >= 1; i--) {
    int pos = lower_bound(d.begin(), d.end(), ans[i]) - d.begin();
    d[pos] = ans[i];
  }
  in = n;
  while (d[in] == inf) in--;
  if (in != b) no();
  for (int i = 1; i <= n; i++) {
    if (ans[i] <= 0 || ans[i] > n || used[ans[i]]) {
      no();
    }
    used[ans[i]] = 1;
  }
  printans();
}


Measured memory_bytes: 4736
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
_A = [[0, 0, 0] for _ in range(3)]
for i in range(N):
    num = int(input())
    for j in range(3):
        if num in A[j]:
            idx = A[j].index(num)
            _A[j][idx] = 1
if sum(_A[0]) == 3 or sum(_A[1]) == 3 or sum(_A[2]) == 3:
    print('Yes')
elif sum([a[0] for a in _A]) == 3 or sum([a[1] for a in _A]) == 3 or sum([a[2] for a in _A]) == 3:
    print('Yes')
elif _A[0][0] + _A[1][1] + _A[2][2] == 3 or _A[0][2] + _A[1][1] + _A[2][0] == 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=5e7+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r;
    string s,p;
    cin>>n>>s;
    p=s;
    sort(p.B,p.E);
    l=0;
    for(i=0;i<n;i++)
    {
        if(s[i]!=p[i])
        {
            l++;
        }
    }
    cout<<(l/2)<<"\n";
    return 0;
}



Measured memory_bytes: 3852
# coding:utf-8

import sys
from collections import defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
graph = defaultdict(list)
for _ in range(m):
    a, b = LI_()
    graph[a].append(b)
    graph[b].append(a)


def DFS(v: int, visited: list) -> int:
    # print(visited, id(visited))
    ans = 0
    visited[v] = 1
    if all(visited):
        return 1

    for next in graph[v]:
        if visited[next]:
            continue

        ans += DFS(next, visited[:])

    return ans


print(DFS(0, [0] * n))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#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;
int main()
{
  string s;cin >> s;
  bool a,b;
  if(s[0]=='0'&&s[1]!='0') a = true;
  else if(s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2')) a = true;
  else a = false;

  if(s[2]=='0'&&s[3]!='0') b = true;
  else if(s[2]=='1'&&(s[3]=='0'||s[3]=='1'||s[3]=='2')) b = true;
  else b = false;

  if(a&&b) cout << "AMBIGUOUS" << "\n";
  else if(a&&(!b)) cout << "MMYY" << "\n";
  else if((!a)&&b) cout << "YYMM" << "\n";  
  else cout << "NA" << "\n";
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int check = 0;
		
		for (int i = a; i <= b; i++) {
			if (c % i == 0) check++;
		}
		System.out.println(check);
	}
}


Measured memory_bytes: 26292
#include <stdio.h>
int main(){
  int x[4];
  for(int i = 0; i < 4; i++) scanf("%d", &x[i]);
  int x3, y3, x4, y4;
  x3 = x[2] + (x[3] - x[1])* -1;
  y3 = x[3] + x[2] - x[0];
  x4 = x3 + (y3 - x[3])*-1;
  y4 = y3 + x3 - x[2];
  printf("%d %d %d %d\n", x3, y3, x4, y4);
}

Measured memory_bytes: 128
#include <iostream>

int main() {
    int n, k, x, y;

    std::cin >> n >> k >> x >> y;

    int total = 0;
    if(n > k) {
        total += (k * x) + ((n - k) * y);
    } else {
        total += n * x;
    }

    std::cout << total << std::endl;
}


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


int main(){
    ll N, ans = 0;
    bool flag = true;
    cin >> N;
    vector<ll> vec(N + 1,1e9);
    for(int i = 0; i < N ; i++){
        cin >> vec[i];
    }


    for(int i = 0; i < N ; i++){
        if(vec[i] <= vec[i + 1]){
            continue;
        }else if((vec[i] == vec[i + 1] + 1)) vec[i + 1]++;
        else flag = false;
    }

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


}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size(), ans = INT_MAX;
    for (int i = 0; i < n - m + 1; ++i) {
        int cnt = 0;
        for (int j = 0; j < m; ++j) {
            if (t[j] != s[i + j]) ++cnt;
        }
        // cout << cnt << " ";
        ans = min(ans, cnt);
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int flag=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3==0||a[i]%5==0)
                flag=1;
            else
            {

                flag=0;
                break;
            }

        }
    }
    if(flag==1)
        cout<<"APPROVED";
    else cout<<"DENIED";

    return 0;
}


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

using namespace std;

int main(void){

    int n;
    vector<int> odd;
    vector<int> even;
    
    cin >> n;
    for(int i=0; i<n; i++) {
        int temp;
        cin >> temp;
        if(temp%2==0) even.push_back(temp);
        else odd.push_back(temp);
    }
    
    int odd_size = odd.size();
    int even_size = even.size();
    
    if(odd_size%2==0) {
        even_size += odd_size/2;
        odd_size = 0;
    }
    else {
        even_size += odd_size/2;
        odd_size = 1;
    }

    if(odd_size == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
    
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>


int main(void){
	int a,b,c;
	int i,j,k;
	int m,n;

	scanf("%d %d %d",&a,&b,&c);
	if(a<=c&&c<=b){
		printf("Yes\n");
	}else if(b<=c&&c<=a){
		printf("Yes\n");
	}else{
		printf("No\n");
	}


	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

bool dp[1000][1000];
bool c[1000][1000];

bool solve(long x, long y){
  // if(c[x][y]) return dp[x][y];
  // c[x][y] = true;
  if(x+y<=1) return dp[x][y] = false;
  if( (x==2 && y==0) || (x==0 && y==2) ) return dp[x][y] = true;
  if(x==1 && y==1) return dp[x][y] = false;

  if(abs(x-y)<=1) return false;
  else return true;
  //
  // bool can = false;
  // for(int dx = 1; 2*dx <=x; dx++){
  //   if(!solve(x-2*dx, y+dx)) return dp[x][y] = true;
  // }
  // for(int dy = 1; 2*dy <=y; dy++){
  //   if(!solve(x+dy, y-2*dy)) return dp[x][y] = true;
  // }
  // return dp[x][y] = false;
}

int main(){
  long x,y;
  cin>>x>>y;
  //
  // fill(c[0],c[100],false);
  // rep(i,100){
  //   rep(j,100) cout << solve(i,j);
  //   cout << endl;
  // }


  if(solve(x,y)) cout << "Alice" << endl;
  else cout << "Brown" << endl;

  return 0;
}


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

constexpr double eps = 1e-12;

int main() {
    int n;
    while(cin >> n, n) {
        double cur = 1e20;
        int id = 1e9;
        for(int i = 0; i < n; ++i) {
            int p; double h, w; cin >> p >> h >> w;
            h /= 100;
            const double bmi = w / h / h;
            if(abs(cur - bmi) < eps) {
                id = min(id, p);
            } else if(abs(22 - cur) > abs(22 - bmi)) {
                cur = bmi;
                id = p;
            }
        }
        cout << id << endl;
    }
}



Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> H;
    for(int i = 0; i < n; i++){
        int h; cin >> h;
        H.push_back(h);
    }

    int cnt = 0;
    int min_h = 0;
    for(int i = 0; i < n - 1; i++){
        if(H[i] > H[i+1])cnt += (H[i] - H[i+1]);
    }
    cout << cnt + H[n-1]<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll div_ceil(ll, ll);

const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  ll N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << (COM(N-K+1, i) * COM(K-1, i-1)) % MOD << '\n';
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int a, b, c;
  cin>>a>>b>>c;
  if(a<=c && c<=b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;
  int count[3] = {};
  for (char c: S) {
    ++count[c % 3];
  }
  long long ans = (long long) count[0] * count[1] * count[2];
  for (int i: range(0, N)) {
    for (int j: range(0, N + 1)) {
      if (i - j >= 0 && i + j < N) {
        if (S[i - j] != S[i] && S[i] != S[i + j] && S[i - j] != S[i + j]) {
          --ans;
        }
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 20000

int main(void){
	unsigned short *A, *B;
	
	int C[VMAX+1];
	int n, i, j;
	scanf("%d", &n);
	
	A = malloc(sizeof(short) * n + 1);
	B = malloc(sizeof(short) * n + 1);
	
	for(i = 0; i <= VMAX; i++) C[i] = 0;
	
	for(i = 0; i < n; i++){
		scanf("%hu", &A[i + 1]);
		C[A[i + 1]]++;
	}
	
	for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i - 1];
	
	for(j = 1; j <= n; j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i = 1; i <= n; i++){
		if(i > 1) printf(" ");
		printf("%d", B[i]);
	}
	printf("\n");
	
	return 0;
}




Measured memory_bytes: 9684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		int scoreh = 0;
		int scorek = 0;

		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str1;
		str1=br.readLine();
		String[] sp1 = str1.split(" ");

		int h1 = Integer.parseInt(sp1[0]);
		int h2 = Integer.parseInt(sp1[1]);

		String str2;
		str2=br.readLine();
		String[] sp2 = str2.split(" ");

		int k1 = Integer.parseInt(sp2[0]);
		int k2 = Integer.parseInt(sp2[1]);

		String str3;
		str3=br.readLine();
		String[] sp3 = str3.split(" ");

		int a = Integer.parseInt(sp3[0]);
		int b = Integer.parseInt(sp3[1]);
		int c = Integer.parseInt(sp3[2]);
		int d = Integer.parseInt(sp3[3]);

		scoreh = h1 * a + h2 * b + (h1 / 10) * c + (h2 / 20) * d;
		scorek = k1 * a + k2 * b + (k1 / 10) * c + (k2 / 20) * d;

		if(scoreh > scorek){
			System.out.println("hiroshi");
		} else if(scoreh < scorek){
			System.out.println("kenjiro");
		} else{
			System.out.println("even");
		}
	}
}

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

struct ttt
{
    int x;
    int len;
}a[100000];

bool sp(ttt x,ttt y)
{
    return x.x<y.x;
}

int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        for(i=0;i<n;i++)
            scanf("%d %d",&a[i].x,&a[i].len);
        sort(a,a+n,sp);
        int tap=0;
        int num=1;
        for(i=1;i<n;i++)
        {
            if(a[tap].x-a[tap].len<a[i].x-a[i].len&&a[tap].x+a[tap].len>a[i].x+a[i].len)
            {
                tap=i;
            }
            else if((a[i].x-a[tap].x)>=a[i].len+a[tap].len)
            {
                num++;
                tap=i;
            }
            else
            {
                tap=tap;
            }
        }
        cout<<num<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h+2,vector<char>(w+2,'#'));

    FOR(i,1,h+1){
        FOR(j,1,w+1){
            cin >> a[i][j];
        }
    }

    queue<pair<int,int>> s;

    FOR(i,1,h+1){
        FOR(j,1,w+1){
            if(a[i][j] == '#'){
                s.push(pair<int,int>(i,j));
            }
        }
    }

    int gsize = s.size();
    int ngsize = 0;
    int cnt = 0;
    while(!s.empty()){
        pair<int,int> v = s.front();
        s.pop();
        gsize--;
        int cy = v.first;
        int cx = v.second;
        if(a[cy][cx+1] == '.'){
            a[cy][cx+1] = '#';
            s.push(pair<int,int>(cy,cx+1));
            ngsize++;
        }
        if(a[cy][cx-1] == '.'){
            a[cy][cx-1] = '#';
            s.push(pair<int,int>(cy,cx-1));
            ngsize++;
        }
        if(a[cy+1][cx] == '.'){
            a[cy+1][cx] = '#';
            s.push(pair<int,int>(cy+1,cx));
            ngsize++;
        }
        if(a[cy-1][cx] == '.'){
            a[cy-1][cx] = '#';
            s.push(pair<int,int>(cy-1,cx));
            ngsize++;
        }
        if(gsize == 0){
            gsize = ngsize;
            if(ngsize != 0){
                cnt++;
            }
            ngsize = 0;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 H, W;
  cin >> H >> W;
  vector<string> s_(H), s(W, string(H, '.'));
  REP(i, H) {
    cin >> s_[i];
    REP(j, W) {
      s[j][i] = s_[i][j];
    }
  }
  int64 res = 0;
  REP(l, W-1) {
    string &s1 = s[l], &s2 = s[l+1];
    auto dp = make_v<int64>(H+1, H+1), cost = make_v<int64>(H+1, H+1);
    REP(i, H) {
      REP(j, H) {
        cost[i+1][j+1] = cost[i][j] + (s1[i] == s2[j]);
      }
    }
    fill_v<int64>(dp, INF);
    dp[0][0] = 0;
    REP(i, H+1) {
      REP(j, H+1) {
        if (i+1 <= H) {
          chmin(dp[i+1][j], dp[i][j] + cost[i+1][j]);
        }
        if (j+1 <= H) {
          chmin(dp[i][j+1], dp[i][j] + cost[i][j+1]);
        }
      }
    }
    res += dp[H][H];
  }
  cout << res << endl;
}


Measured memory_bytes: 1964
i=0
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)
    else:
        break
    i+=1


Measured memory_bytes: 5592
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf 1e9 + 1
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define MAX 3000

int dp[MAX+1][MAX+1];
string getLCS(string& s, string& t, int len)
{
        string LCS;
        int i = 0, j = 0;
        while(len > 0)
        {
            if(s[i] == t[j])
            {
                LCS.push_back(s[i]);
                i++;
                j++;
                len--;
            }
            else
            {
                if(dp[i][j+1] > dp[i+1][j])
                    j++;
                else i++;
            }
        }
        return LCS;
}

int lenLCS(string& s, string& t, int i, int j)
{
        if(i >= s.length() || j >= t.length())
            return 0;
        
        if(dp[i][j] != -1)
            return dp[i][j];

        if(s[i] == t[j])
            return dp[i][j] = 1 + lenLCS(s,t,i+1,j+1);
        else 
        {
            return dp[i][j] = max(lenLCS(s,t,i,j+1), lenLCS(s,t,i+1,j));
        }
}

string solve(string s, string t)
{
        memset(dp, -1, sizeof dp);
        int len = lenLCS(s,t,0,0);
        return getLCS(s,t,len);
}
 
int main() {
    string s, t;
    cin >> s >> t;
    cout << solve(s, t);
}


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


int main(){

int N,ac=0,wa=0,re=0,tle=0;
  cin >> N ;
  
string s;
  
  rep(i,N){
    cin >> s;
    if(s=="AC")
      ac++;
    else if(s=="WA")
      wa++;
    else if(s=="RE")
      re++;
    else if(s=="TLE")
      tle++;
      
  }
    
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
  
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
#define LL long long
using namespace std;
const int maxn = 1e5+10;
int cnt[maxn<<2];
int n,a[maxn],m;
LL sum;
void ins(int t){while (t<=m) {cnt[t]++; t += lowbit(t);}}
int getsum(int t){
    int ans = 0;
    while (t) {ans += cnt[t]; t -= lowbit(t);}
    return ans;
}
bool check(int t){
    memset(cnt,0,sizeof(cnt));
    int now = 0;
    LL ans = 0;
    ins(now + n);
    for (int i=0;i<n;i++) {
        if(a[i] >= t){
            ans += getsum(now+1+n);
            now++;
            ins(now+n);
        }else{
            ans += getsum(now-1+n);
            now--;
            ins(now+n);
        }
    }
    return ans >= sum - ans;
}

void work(){
    m = (n << 1) + 1;
    int l = 1e9+10, r = 0;
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (a[i] < l) l = a[i];
        if (a[i] > r) r = a[i];
    }
    sum = 1LL * n * (n - 1) / 2 + n;
    int ans = -1,mid;
    while (l<=r){
        mid = (l+r)>>1;
        if (check(mid)) {
            ans = mid, l = mid + 1;
        }else {
            r = mid - 1;
        }
    }
    printf("%d\n",ans);
}
int main(){
    while (~scanf("%d",&n)) work();
    return 0;
}




Measured memory_bytes: 2176
#include <stdio.h>
int main(void){
int n[3];
for(int i = 0; i < 3; i++)
scanf("%1d",&n[i]);
if (n[0] == 7)printf("Yes");
else if (n[1] == 7)printf("Yes");
else if (n[2] == 7)printf("Yes");
else printf("No");
return 0;
}


Measured memory_bytes: 1724
<?php
//??\?????°??¨?±±??????????????\???????????????
$count=0;
$mountList=array();
//?±±??????????????\?????????
while($count<10){
    $stdin=trim(fgets(STDIN));
    //??\??????????????????????????????????????????????????\???
    if(0<=$stdin&&$stdin<=10000){
        $mountList[]=$stdin;
        $count++;
    }
}
//??\??????????????°????????????????????????
rsort($mountList);

//????????????
for($i=0;$i<3;$i++){
    //????????????
    echo $mountList[$i]."\n";
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> l(n); rep(i,n) cin >> l[i];

  sort(l.begin(),l.end());
  int ans = 0;

  rep(i,n){
    for(int j = i+1;j<n;j++){
      for(int k = j+1;k<n;k++){
	if(l[i]!=l[j] && l[j]!=l[k])
	  //if(l[i]+l[j]>l[k] || l[j]+l[k]>l[i] || l[k]+l[i]>l[j]){
	  if(l[i]+l[j]>l[k]){
	    //printf("%d %d %d\n",l[i],l[j],l[k]);
	  ans++;
	}
      }
    }
  }

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


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		DSU dsu = new DSU(n);
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			int t = Integer.parseInt(sa[0]);
			int u = Integer.parseInt(sa[1]);
			int v = Integer.parseInt(sa[2]);
			if (t == 0) {
				dsu.merge(u, v);
			} else {
				pw.println(dsu.same(u, v) ? 1 : 0);
			}
		}
		pw.flush();
		br.close();
	}
}

/**
 * Disjoint Set Union（Union Find）
 */
class DSU {
	private int n;
	private int[] parentOrSize;
	private int num;

	/**
	 * n頂点0辺の無向グラフを作る。<br>
	 * O(n)
	 * 
	 * @param n 頂点数
	 */
	public DSU(int n) {
		this.n = n;
		this.parentOrSize = new int[n];
		Arrays.fill(parentOrSize, -1);
		num = n;
	}

	/**
	 * 辺(a, b)を足す。<br>
	 * ならしO(α(n))
	 * 
	 * @param a 頂点番号（0≦a＜n）
	 * @param b 頂点番号（0≦b＜n）
	 * @return 代表元
	 */
	int merge(int a, int b) {
		assert 0 <= a && a < n;
		assert 0 <= b && b < n;

		int x = leader(a);
		int y = leader(b);
		if (x == y) {
			return x;
		}
		if (-parentOrSize[x] < -parentOrSize[y]) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		parentOrSize[x] += parentOrSize[y];
		parentOrSize[y] = x;
		num--;
		return x;
	}

	/**
	 * 頂点a, bが連結かどうか。<br>
	 * ならしO(α(n))
	 * 
	 * @param a 頂点番号（0≦a＜n）
	 * @param b 頂点番号（0≦b＜n）
	 * @return true：連結　false：非連結
	 */
	boolean same(int a, int b) {
		assert 0 <= a && a < n;
		assert 0 <= b && b < n;

		return leader(a) == leader(b);
	}

	/**
	 * 頂点aの属する連結成分の代表元を返す。<br>
	 * ならしO(α(n))
	 * 
	 * @param a 頂点番号（0≦a＜n）
	 * @return 代表元
	 */
	int leader(int a) {
		assert 0 <= a && a < n;

		if (parentOrSize[a] < 0) {
			return a;
		} else {
			return parentOrSize[a] = leader(parentOrSize[a]);
		}
	}

	/**
	 * 頂点aの属する連結成分の要素数を返す。<br>
	 * ならしO(α(n))
	 * 
	 * @param a 頂点番号（0≦a＜n）
	 * @return 要素数
	 */
	int size(int a) {
		assert 0 <= a && a < n;

		return -parentOrSize[leader(a)];
	}

	/**
	 * 連結成分の数を返す。<br>
	 * O(1)
	 * 
	 * @return 連結成分数
	 */
	int num() {
		return num;
	}

	/**
	 * グラフを連結成分に分けた情報を返す。<br>
	 * O(n)
	 * 
	 * @return 「1つの連結成分の頂点番号のリスト」のリスト
	 */
	List<List<Integer>> groups() {
		int[] leaderBuf = new int[n];
		int[] groupSize = new int[n];
		for (int i = 0; i < n; i++) {
			leaderBuf[i] = leader(i);
			groupSize[leaderBuf[i]]++;
		}
		List<List<Integer>> result = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			result.add(new ArrayList<>(groupSize[i]));
		}
		for (int i = 0; i < n; i++) {
			result.get(leaderBuf[i]).add(i);
		}
		result.removeIf(List::isEmpty);
		return result;
	}
}


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

int main(){
	/*input*/
	int n, T;	cin >> n >> T;
	int* c = new int[n];
	int* t = new int[n];
	for(int i = 0; i< n; i++){
		cin >> c[i] >> t[i];
	}
	/*calcultion*/
	int min_c = 1001;
	for(int i = 0; i < n; i++){
		if(t[i] <= T){
			if(min_c > c[i])min_c = c[i];
		}
	}
	/*output*/
	if(min_c > 1000){
		cout << "TLE" << endl;
	}else{
		cout << min_c << endl;
	}
	delete[] c;
	delete[] t;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {

  int x; cin >> x;
  int ans = 1;
  for(int i=2; i<=x; i++){
    int p = 2;
    int tmp = i*i;
    while( tmp <= x ){
      ans = max(ans, tmp);
      tmp *= i;
    }
  }
  cout << ans << endl;

  return 0;
}

//


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector<int> we(n), v(n);
    for (int i = 0; i < n; ++i) cin >> we[i] >> v[i];
    vector<long long> dp(w + 1, 0);
    for (int i = 0; i < n; ++i)
        for (int weight = w - we[i]; weight >= 0; --weight)
            dp[weight + we[i]] = max(dp[weight + we[i]], dp[weight] + v[i]);
    cout << *max_element(dp.begin(), dp.end()) << '\n';
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int 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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif
struct UnionFind {
	vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}

	int find(int k) {
		if(data[k] < 0) return(k);
		return data[k] = find(data[k]);
	}

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

	int size(int k)	{
		return -data[find(k)];
	}
};

int main() {
    int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y, _; cin >> x >> y >> _;
        x--; y--;
        uf.unite(x, y);
    }
    set<int> st;
    rep(i, n) {
        st.insert(uf.find(i));
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 5376
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)
    val A = Array(N) { readLine()!!.split(" ").map(String::toInt).let { Pair<Int, Int>(it[0], it[1]) } }
    val C = Array(M) { readLine()!!.split(" ").map(String::toInt).let { Pair<Int, Int>(it[0], it[1]) } }

    for (a in A) {
        var min = Integer.MAX_VALUE
        var index = 0
        for ((i, c) in C.withIndex()) {
            val man = Math.abs(a.first - c.first) + Math.abs(a.second - c.second)
            if (man < min) {
                min = man
                index = i
            }
        }
        println(index + 1)
    }
}



Measured memory_bytes: 36076
arr = gets.split(" ").map { |v|
	v.to_i
}

cnt = 0
if arr[0] == arr[1] and arr[1] == arr[2] and arr[2] % 2 == 0 then
	puts "-1"
	exit
end

while true do
	if arr[0] % 2 == 1 or arr[1] % 2 == 1 or arr[2] % 2 == 1 then
		puts cnt
		exit
	else
		cnt += 1
		arr = [(arr[1]+arr[2]) / 2 , (arr[0]+arr[2]) / 2 , (arr[1]+arr[0]) / 2 ]
	end
end


Measured memory_bytes: 1788
#include<iostream>
#include<string>
main(){int f,i,m;std::string s;for(std::cin>>f;std::cin>>s;f?puts(f-2?"A":"B"):puts("NA")){f=0;for(i=1;s[0]+s[1]==101&(m=s.find(35))!=-1&s[m-i]==s[m+i];)m-++i-1|m+i-s.size()+1|s[m+i]-'~'||(f=1);for(i=2;s[0]+s[1]==156&s[i]==81&s[i+1]==61;)++++i-s.size()+2|s[i]+s[i+1]-252||(f=2);}}

Measured memory_bytes: 0
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
from collections import defaultdict


def main():
    N = int(input())
    dct = defaultdict(int)

    for i in range(N):
        s = input()
        sorted_s = "".join(sorted(s))
        dct[sorted_s] += 1

    ans = 0
    for k, v in dct.items():
        ans += v * (v - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18144
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	fmt.Println((N - 1 + K - 2) / (K - 1))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
   int n;
   vector<double> x(10);
   string u[10];
   cin >> n;
   double sum=0;
   rep(i,n){
       cin >> x[i] >> u[i];
   }
   rep(i,n){
       if(u[i]=="JPY"){
            sum += x[i];
       }
       else {
           sum += x[i]*380000.0;
       }
   }
       cout << sum << endl;
    return 0;
}


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

typedef long long ll;

using Graph = vector<vector<int>>;

int main() {
    int N;
    cin >> N;
    map<int, int>mp;
    mp[0] = 0;
    for (int i = 1; i <= N-1; i++) {
        int A;
        cin >> A;
        A--;
        mp[A] += mp[i] + 1; 
    }
    for (int i = 0; i < N; i++) {
        cout << mp[i] << endl;
    }
}


Measured memory_bytes: 12980
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e5 + 9, M = 3e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

ll mem[109][109][109], arr[N];
int n, m;

ll solve(int l, int r, int steps) {
  if(steps < 0)
    return -inf;
  if(steps == 0 || l > r)
    return 0;
  ll& ret = mem[l][r][steps];
  if(~ret)
    return ret;
  ret = -inf;
  ll c1 = solve(l + 1, r, steps - 1) + arr[l];
  ll c2 = solve(l, r - 1, steps - 1) + arr[r];
  ll c3 = solve(l + 1, r, steps - 2);
  ll c4 = solve(l, r - 1, steps - 2);
  ret = max(max(c1, c2), max(c3, c4));
  return ret;
}

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  memset(mem, -1, sizeof mem);
  ll best = -inf;
  for (int i = 0; i <= m; ++i) {
    best = max(best, solve(0, n - 1, i));
  }
  cout << best;
  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

int main(){
    int N; cin >> N;
    int K; cin >> K;
    for (int i = 0;i < N; i++) cin >> h[i];
    for (int i = 0;i < N; i++) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0;i < N;i++) {
        for (int j = 1;j < K+1;j++) {
                chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String [] str = new String[N];

        for(int i = 0; i < N; i++) {
            str[i] = sc.next();
        }

        Arrays.sort(str);

        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < N; i++) {
            sb.append(str[i]);
        }

        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 37284
/*

n以下の素数がいくつあるか数えて出力せよ。
複数のデータセットが与えられる。

やり方：
	・n[]を入力。
	・データセットごとに、「n以下の素数の数を表示する関数」"sosuu01"を使って終わり。

結果：Time limit exceeded

--------------------------------------------------------------------------------

3:41 2013/01/16

データセットに配列を使わないことにした。10027の例に倣い。
それでもTime limit。どうしろと。
sosuu01が、力技で全ての整数を見てるから、そこを改良したい。

--------------------------------------------------------------------------------

だめだ。

--------------------------------------------------------------------------------

17:23 2013/02/02

春休み勉強会の講義資料に、素数判定の関数のもっと良い方法があった。
「nがaで割り切れる（n/a=b）なら、nはbでも割り切れるため、ループで増やしていくiの上限は、nの平方根(i*i<=nまで)で良い」	らしい。

--------------------------------------------------------------------------------

17:47 2013/02/02

retを消して直接、if(scanf()==EOF){}とかにしてみたり、素数判定の際に偶数はスキップするように変えてみたが、やっぱり駄目だった。
現状、01.83秒。
以前までは10秒以上かかっていたので、大きな進歩だ。やったね。
あと0.83秒。	どうやって短縮したものか。
main()関数も随分短くなったものだ。11行しかない。

--------------------------------------------------------------------------------

*/

#include <stdio.h>

int max = 1000000;
int prime[1000000];

void sosuu01(int n);		//n以下の素数の数を表示する関数。
void make_prime()
{
	int i,k;
	for(i=0; i<=max; i++){
		prime[i]=1;
	}
	prime[0]=0;
	prime[1]=0;
	for(i=2; i<=max; i++){
		if(prime[i]){
			for(k=i+i; k<=max; k+=i){
				prime[k]=0;
			}
		}
	}
}

int main()
{
	int n;
	make_prime();
	while(1){
		if(scanf("%d",&n)==EOF){
			break;
		}
		sosuu01(n);
	}
	return 0;
}

void sosuu01(int n)
{
	int i;
	int count=0;
	for(i=2; i<=n; i++){
		if(prime[i]){
			count++;
		}
		if(i%2!=0){
			i++;
		}
	}
	printf("%d\n",count);
	return;
}

Measured memory_bytes: 4500
#include <iostream>
#include <cstdio>
#include <vector>
#define N 405
using namespace std;

typedef long long ll;
ll n, m, num, cnt[160005], s[160005], z[N][N];
ll dr[4] = {-1, 0, 0, 1}, dc[4] = {0, -1, 1, 0};
bool v[N][N];
char a[N][N];
//vector<ll> x, y;
void f(ll p, ll q) {
	ll i, j, x, y;
	if (p < 1 || p > n || q < 1 || q > m || v[p][q] || a[p][q] != '#') return;
	v[p][q] = 1;
	s[num]++;
	for (i = 0; i < 4; i++) {
		x = p + dr[i];
		y = q + dc[i];
		if (a[x][y] != '.') continue;
		if (z[x][y] != num) {
			cnt[num]++;
			z[x][y] = num;
			for (j = 0; j < 4; j++) {
				f(x + dr[j], y + dc[j]);
			}
		}
	}
}
int main()
{
	ll i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		scanf ("%s", &a[i][1]);
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (v[i][j] || a[i][j] != '#') continue;
			num++;
			f(i, j);
		}
	}
	ll ans = 0;
	for (i = 1; i <= num; i++) {
		ans += s[i] * cnt[i];
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

struct P{
    int h,w;
};

int main(){
    int h,w,d, q;
    int sa;
    P a[300*300+1];
    int aa[300*300+1] = {};
    int l[100000], r[100000];
    
    cin >> h >> w >> d;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            scanf("%d", &sa);
            a[sa].h = i+1;
            a[sa].w = j+1;
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        scanf("%d %d", &l[i], &r[i]);
    }
    int mem = 0;
    for(int i = 1; i <= d; i++){
        mem = 0;
       for(int j = i; j <= h*w-d; j+=d){
           mem += abs(a[j].h - a[j+d].h) + abs(a[j].w - a[j+d].w);
           aa[j+d] = mem;
       }
    }
    int ans;
    for(int i = 0; i < q; i++){
        ans = aa[r[i]] - aa[l[i]];
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  ll x;
  cin >> n >> x;
  vll a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    ll sum = a[i-1] + a[i];
    if (sum <= x) continue;
    if (sum - a[i] < x) {
      ans += sum - x;
      a[i] -= sum - x;
    }
    else {
      ll rem = sum - a[i];
      ans += a[i];
      a[i] = 0;
      ans += rem - x;
      a[i-1] -= rem - x;
    }
  }

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

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


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

/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/
 
int main() {
  
  ll N, K, C, count=0, ans=0;
  string D, E;
  cin >> N >> K;
  
  if(N>K){
  	C = N%K;
  	ans = min(C,K-C);
  }
  else if ( N==K ){
  	ans = 0;
  }
  else {
    C=min(N,K-N);
    ans = C;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repeat(i, n) for(ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main() {
	int N = 0, result = 0, max_R = 0;
	cin >> N;

	vector<int> d(N, 0);

	repeat(i, N) {
		cin >> d[i];
	}

	sort(d.begin(), d.end(), greater<int>());
	max_R = d[0];
	result++;

	repeat(i, N) {
		if (max_R > d[i]) {
			result++;
			max_R = d[i];
		}
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	s='#'+s;
	lvi bps,rbps;
	for (int i = 1; i <=n; ++i)
	{
		if(s[i]=='o')
		{
			bps.pb(i);
			i+=c;
		}
	}
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='o')
		{
			rbps.pb(i);
			i-=c;
		}
	}
	reverse(all(rbps));
	if(bps.size()>k) return 0;
	for(int i=0;i<bps.size()-1;i++)
	{
		bool flag=false;
		for(int j=bps[i]+1;j<bps[i+1];j++)
		{
			if(s[j]=='o')
			{
				ll dif=rbps[i+1]-j-1;
				if(dif<c)
				{
					cout<<bps[i]<<endl;
				}
				flag=true;
				break;
			}
		}
		if(flag) continue;
		cout<<bps[i]<<endl;
	}
	if(rbps[bps.size()-1]==bps[bps.size()-1])
	{
		cout<<rbps[bps.size()-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5064
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = [next(it) for i in range(N)]

    if N == 1:
        print(1)
        return

    ax = max(A)+1
    dp = [0]*ax
    for ai in A:
        da = dp[ai]
        if da > 1:
            continue
        dp[ai] += 1
        if da == 0:
            for aj in range(2*ai, ax, ai):
                dp[aj] = 2
    ans = 0
    for ai in A:
        if dp[ai] == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 105604