akhauriyash/Code-Regression huggingface dataset:
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

H, W, D = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
L, R = zip(*[list(map(int, input().split())) for _ in range(Q)])

# h_pos[a]: a がある位置の h
# w_pos[a]: a がある位置の w
h_pos = np.zeros(H * W + 1)
w_pos = np.zeros(H * W + 1)
for h in range(H):
    for w in range(W):
        h_pos[A[h][w]] = h
        w_pos[A[h][w]] = w

dp = np.zeros(H * W + 1, dtype=int)
for i in range(1, H * W + 1):
    if i - D >= 0:
        dp[i] = dp[i - D] + abs(h_pos[i - D] - h_pos[i]) + abs(w_pos[i - D] - w_pos[i])

for l, r in zip(L, R):
    print(dp[r] - dp[l])


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


int req (vector<int> A,int N) {
  int wrongB = 0;
  int wrongC = 0;
  vector<int> B(N),C(N);
  B[0] = A[0];
  C[1] = A[1];
  for (int i=1; i<N; i++) {
    B[i] = A[i] % A[0];
    if (B[i] == 0) {
      B[i] = A[0];
      continue;
    }
    wrongB++;
  }
  for (int i=0; i<N; i++) {
    if (i == 1) {
      continue;
    }
    C[i] = A[i] % A[1];
    if (C[i] == 0) {
      C[i] = A[1];
      continue;
    }
    wrongC++;
  }
  if (wrongC < 2) {
    return A[1];
  }
  if (wrongB < 2) {
    return A[0];
  }
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  return max(req(B,N),req(C,N));
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  
  cout << req(A,N) << endl;
  
}

Measured memory_bytes: 4928
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
//-------------------------------------------------------------------------------

intl n,h;
intl a[100000];
intl b[100000];
void input_var(){
    cin >> n >> h;
    rep(i,n){
        cin >> a[i] >> b[i];
    }
}
//-------------------------------------------------------------------------------

/*
void dfs(vector<intl> &v) {
    if (v.size() == 数列の長さ) {
        return;
    }
    for (int i = 0; i < 各項の値; i++) {
        v.push_back(i);
        dfs(v);
        v.pop_back();
    }
}*/

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    sort(a, a + n,greater<>());
    intl ma = a[0];
    sort(b,b + n,greater<>());
    intl cnt = 0;
    intl idx = 0;
    while(true){
        if(b[idx] > ma){
            h -= b[idx];
            idx++;
            cnt++;
            if(h <= 0)break;
        }
        else {
            cnt += ((h + ma - 1)/ ma);
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  map<string,int> U;
  int n,m=0;
  cin >>n;
  while(n--){
    string s;
    cin >>s;
    U[s] = 1;
  }
  cin >>n;
  while(n--){
    string s;
    cin >>s;
    if(U[s] == 1){
      if(m == 0) cout <<"Opened by "<<s<<endl;
      else cout <<"Closed by "<<s<<endl;
      m = 1-m;
    }
    else cout <<"Unknown "<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std; 
#define rep(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1<<29;
const int MOD=1073741824;
#define pp pair<ll,ll>
#define ppi pair<int,int>
typedef long long int ll;
bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
////////////////////////////////////////////////////////////////////

int main(){
    int tc=1;
    // cin>>tc;
    while(tc--){
        int n;cin>>n;
        int a[n];
        vector<ppi> b,c;
        ll mx=0;
        rep(i,n){
            cin>>a[i];
        }
        ll ans=1000,st=0,res=0;
        bool f=0;
        for(int i=0;i<n-1;i++){
            res=max(ans,res);
            if(a[i]<a[i+1]){
                st+=ans/a[i];
                ans%=a[i];
            }
            else{
                ans+=st*a[i];
                st=0;
            }
            // cout<<ans<<endl;
        }
        if(st){
            ans+=st*a[n-1];
        }
        res=max(ans,res);
        cout<<res;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD=1e9+7;
using namespace std;

int main(){
  ll r,g,b,N;
  cin >> r >> g >> b >> N;
  ll cnt = 0;
  for(ll i=0;i*r<=N;i++){
    for(ll j=0;j*g<=N-i*r;j++){
      ll tmp = N-i*r-j*g;
      if(tmp%b==0) {
        cnt++;
      }

    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll ans = INF;
    ll x = 0;
    ll y = accumulate(ALL(a), 0ll);
    rep(i, n-1){
        x += a[i];
        y -= a[i];
        chmin(ans, abs(x-y));
    }
    cout << ans << endl;
    return 0;
}

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


void maxim(vector<int> da,int &a,int &b){
	int A = 0, B = 0;
	for (int i = 1;i < da.size();i++) {
		if (da[i] > A) {
			B = A;
			b = a;
			A = da[i];
			a = i;
		}
		else if (da[i] <= A && da[i] > B) {
			B = da[i];
			b = i;
		}
	}
}

int main() {
	int n,eve1,eve2,odd1,odd2;
	cin >> n;
	vector<int> da(n);
	for (int i = 0;i < n;i++) {
		cin >> da[i];
	}
	int ans = 0;
	odd1 = 0;
	eve1 = 0;
	odd2 = 0;
	eve2 = 0;
	vector<int> ev(100001, 0), od(100001, 0);
	n /= 2;
	for (int i = 0;i < n;i++) {
		ev[da[i * 2]]++;
		od[da[i * 2 + 1]]++;
	}
	maxim(ev, eve1, eve2);
	maxim(od, odd1, odd2);
	if (eve1 == odd1) {
		ans = max(ev[eve1] + od[odd2], ev[eve2] + od[odd1]);
	}
	else
		ans = ev[eve1] + od[odd1];
	cout << n*2 - ans << endl;
	//cout << eve2 << " " << odd2 << endl;
	//cout << ev[2] << " " << od[2] << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin =new Scanner(System.in);
		int n=stdin.nextInt();
		int a[]=new int [n];
		int i;
		for(i=0;i<n;i++){
			a[i]=stdin.nextInt();
		}
		int max=-300,min=300;
		for(i=0;i<n;i++){
			if(max<a[i])
				max=a[i];
			if(min>a[i])
				min=a[i];
		}
		int min2=Integer.MAX_VALUE;
		int p=0;
		for(i=min;i<=max;i++){
			p=0;
			for(int j=0;j<n;j++)
				p+=(a[j]-i)*(a[j]-i);

			if(p<min2)
				min2=p;
		}

		System.out.println(min2);
	}
}


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


 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
  
  string s,t;
  cin >> s >> t;
  int count=0;
  for(int i=0;i<3;i++){
  	if(s[i]==t[i]){
    	count++;
    }
  }
  
  cout << count << "\n";

}


Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		long b = scan.nextLong();
		long n = scan.nextLong();
		
		if(n<b) {
			double x = Math.floor(a*n/b)-5* Math.floor(n/b);
			System.out.println((int)x);
			
		}else {
			long y = b-1;
			double x = Math.floor(a*y/b)-5* Math.floor(y/b);
			System.out.println((int)x);
		}
		
	}	
	
	
	//最小公約数
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
}

Measured memory_bytes: 35776
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
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;}
const int INF = 1e9;

int N,M;
int k[10];
int s[10][10];
int p[10];


/*
p[i]が点灯のための偶奇

サンプル少ないので全列挙で試せばよい
*/
int popcount(int x) {  
 int ret = 0;  
 while (x) {  
     x &= x-1;  
     ++ret;  
 }  
 return ret;  
}  

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
        }
    }
    for (int i =0; i < M; i++) cin >> p[i];
    
    int count = 0;
    for (int state = 0; state < (1 << N); state++) {
        bool flag = true;
        for (int i = 0; i < M; i++) {
            int sw = 0;
            for (int j = 0; j < k[i]; j++) {
                sw |= 1 << (s[i][j] - 1);
            }
            if (popcount(sw & state) % 2 != p[i]) flag = false; 
        }
        if (flag) count++;
    }
    cout << count << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String result = "" , str = sc.nextLine();
			for(int i=0; i<str.length(); i++){
				if ( str.charAt(i) == '@' ) {
					for(int j=0; j<Integer.parseInt(""+str.charAt(i+1)); j++)
						result += Character.toString(str.charAt(i+2));
					i+=2;
				} else
					result += str.charAt(i);
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp15
{
    class Class202
    {
        static void Main()
        {
            var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = xy[0], y = xy[1];
            int ans = 0;
            if (y >= x)
            {
                ans = Min(y - x, Abs(y + x) + 1);
            }
            else
            {
                ans = Min(x - y + 2, Abs(x + y) + 1);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }




void solve(){
    ll n;
    cin>>n;
    string s=to_string(n);
    ll k=s.size();
    ll ans=0;
    ll b[20];
    b[0]=1;
    rep(i,7) b[i+1]=b[i]*10;
    rep2(i,1,n+1){
        string t=to_string(i);
        ll m=t.size();
        if(t[m-1]=='0'||t[0]=='0') continue;
        if(t[m-1]==t[0]) ans++;
        ll num=i;
        if(m==1){
            t=to_string(i*10+i);
            num=i*10+i;
        }
        else if(i>99){
            t=to_string(i/b[m-1]*10+i%10);
            num=i/b[m-1]*10+i%10;
        }
        m=2;
        // cout<<"t:"<<t<<"//";

        rep(j,k-2){
            ans+=b[j];
        }

        if(t[m-1]<s[0]){
            // cout<<"paturn a ";
            ans+=b[k-2];

        }
        else if(t[m-1]==s[0]){
            // cout<<"paturn b"<<i<<" ";
            ll a=(num%10)*b[k-1]+num/10;
            // cout<<"a:"<<a<<" ";
            if(a<=n){
                ans++;
                ans+=abs((n-a)/10);
            }
        }
        else{
            // cout<<"paturn c"<<i<<" ";
        }
        // cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
     

    solve(); 


    return 0;
}


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

typedef long long LL;

const int MAXN = 100000;
const LL MOD = (LL)1e9+7;

int N, K;
LL dp[MAXN+5], ans;

LL power(LL a,LL b){
    return b ? power(a*a%MOD,b/2)*(b%2?a:1)%MOD : 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> K;
    for (LL i = K; i >= 1; --i){
        dp[i] = power(K/i, N);
        for (LL j = 2 * i; j <= K; j += i) {
            dp[i] -= dp[j];
        }
        ans=(ans+i*dp[i]%MOD)%MOD;
    }
    cout << (ans + MOD) %MOD << '\n';
    return 0;
}

Measured memory_bytes: 4392
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;


long long int life(long long int x){
  long long int l;
  if(x>1){
    l = 1+2*life(x/2);
  }else{
    l = 1;
  }
  return l;
}

int main(int argc, char *argv[]){
  long long int h;
  cin >> h;
  cout << life(h) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

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

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    int K, X; 
    cin >> K >> X;
    if (K * 500 >= X) cout << "Yes";
    else cout << "No";
    
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
package main

import "fmt"

func f(a int, b int) int {
	largeValue := 0
	if a > b {
		largeValue = a
	} else {
		largeValue = b
	}
	result := 0
	for {
		largeValue = int(largeValue / 10)
		result = result + 1
		if largeValue < 1 {
			break
		}
	}
	return result
}

func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	result := f(n, n)
	for i := 1; i <= (n / i); i++ {
		if n%i == 0 {
			tmp := f(i, n/i)
			result = min(result, tmp)
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 1768
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100+20;
int n,m;
char sz[N][N];
void init()
{
    for(int i=0;i<100;i++)
        for(int j=0;j<100;j++)
            sz[i][j]='.';
}
void ts(int x,int y)
{
    sz[x+1][y]='#';
    sz[x][y+1]='#';
    sz[x+1][y+1]='#';
}
int main()
{
    //freopen("out.txt","w",stdout);
    while(~scanf("%d%d",&n,&m))
    {
        init();
        n--;
        int x=0,y=0;
        if(n) m--;
        while(n)
        {
            n--;
            ts(x,y);
            y+=2;
            x+=((y/100)*2);
            y%=100;
        }
        while(m)
        {
            sz[x+1][y+1]='#';
            y+=2;
            x+=((y/100)*2);
            y%=100;
            m--;

        }
        printf("100 100\n");
        for(int i=0;i<100;i++)
        {
            for(int j=0;j<100;j++)
                printf("%c",sz[i][j]);
            printf("\n");
        }
    }


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
N, K = map(int, input().split())

if K == 1 :
  print (0)
else :
  print (N-(K-1)-1)


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

int main()
{
    int n, ans[100001];
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        ans[a] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << ' ';
    }
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int N=2e5;
vector<int>B(N+1);
void insert(int I,int val){
	while( I<=N ){
		B[I]=max(B[I],val);
		I+=I&-I;
	}
}
int query(int I){
	int mx=0;
	while( I > 0){
		mx=max(mx,B[I]);
		I-=I&-I;
	}
	return mx;
}

int32_t main()
{
   IOS
   int n;cin>>n;
   vector<int>h(n+1);
   vector<int>b(n+1);
   int ans=0;
   for(int i=1;i<=n;i++)
   cin>>h[i];
   for(int i=1;i<=n;i++)
   cin>>b[i];
   for(int i=1;i<=n;i++){
	   int mx=query(h[i]);
	   insert(h[i],mx+b[i]);
	   ans=max(ans,mx+b[i]);
   }
   cout<< ans << endl;
   
  
  
  
}


Measured memory_bytes: 4992
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(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 all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

int n, m;
bool ok(int x, int y){
  return x >= 0 and y >= 0 and x < n and y < m;
}

void solve(){
  cin >> n >> m;
  vector<string> s(n);
  forn(i,n) cin >> s[i];
  forn(i,n){
    forn(j,n){
      if (s[i][j] == '#'){
        int c = 0;
        int x[4] = {-1, 1, 0, 0};
        int y[4] = {0, 0, 1, -1};

        forn(k,4){
            if (ok(i+x[k],j+y[k]) and s[i+x[k]][j+y[k]] == '#'){
              c++;
            }
          }
        
        if (!c){
          cout << "No";
          return;
        }
      }
      
    }
  }
  cout << "Yes";
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

2 6 3
4 6 5
6 6 7
7 7 7

*/

Measured memory_bytes: 3608
#include<stdio.h>
int main(void){
int sum,i;
char k[1000];
while(1){
scanf("%s",k);
if(k[0]=='0')break;
for(sum=0,i=0;k[i]!='\0';i++){
sum+=(k[i]-'0');
}
printf("%d\n",sum);
}
return 0;
}

Measured memory_bytes: 536
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	String c;

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		c = in.readLine();
	}

	void calc() {
		int rNum = 0;

		for (int i = 0; i < N; ++i) {
			if (c.charAt(i) == 'R') {
				++rNum;
			}
		}
		int wChangeNum = 0;
		for (int i = 0; i < rNum; ++i) {
			if (c.charAt(i) == 'W') {
				++wChangeNum;
			}
		}
		System.out.println(wChangeNum);
	}

	void showResult() {
	}
}


Measured memory_bytes: 29512
# -*- coding: utf-8 -*-

#お店にあるベルは 3 種類で、それぞれ a円、 b円、 c円です。
#この 3 つのうち、異なる 2 つのベルを選んで買うときの、値段の合計の最小値を求めて下さい。

x = input().split()
#x = [700, 600, 780]

y =[int(x[0]), int(x[1]), int(x[2])]

z = sorted(y)

ans = z[0] + z[1]

print(ans)




Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll n,mx=0;
	unordered_map<string, ll>mp;
	cin >> n;
	string st;
	list<string>ls;
	for (int i = 0; i < n; i++) {
		cin >> st;
		mp[st]++;
		mx = max(mx, mp[st]);
	}
	for (auto it : mp) {
		if (it.second == mx) {
			ls.push_back(it.first);
		}
	}
	ls.sort();
	for (auto& i : ls) {
		cout << i << endl;
	}
	return 0;
}

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

class Program
{
    static void Main()
    {
        var AB = ReadLine().Split().Select(int.Parse).ToArray();
        var N = AB[0];
        var X = AB[1];
        var L = ReadLine().Split().Select(int.Parse).ToArray();
        var S = new int[N+1];
        for (int i = 0; i < N; i++)
        {
            S[i + 1] = S[i] + L[i];
        }
        WriteLine(S.Count(x => x <= X));
    }
}

Measured memory_bytes: 13396
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	A := nextInt()
	B := nextInt()
	s := A + B
	d := A - B
	m := A * B
	if s >= d && s >= m {
		fmt.Fprintln(out, s)
	} else if d >= s && d >= m {
		fmt.Fprintln(out, d)
	} else {
		fmt.Fprintln(out, m)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

#define int ll
void solve() {
    int k;
    cin >> k;
    int a[32] = { 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 << a[k - 1] << endl;
}

#undef int
int main() {
    init();
    solve();
}

Measured memory_bytes: 256
// 最大公約数
// a,bの最小公倍数(LCM)はa*b/GCD
/*
 * C言語のサンプルプログラム - Webkaru
 * - 入力した2つの自然数の最大公約数を求める -
 */
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


ll gcd(ll a, ll b)
{

    ll r, tmp;
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return b;
}

int main(){
    int a,b;
    cin>>a>>b;
    ll lcm=(ll)a*b/gcd(a,b);
    cout<<lcm<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k, x, ans = 0;
	cin >> n;
	for (i = 1; i <= n; i++) {
		cin >> x;
		if ((i % 2 == 1) && (x % 2 == 1)) ans++;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}


const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

int digsum(int n) {
    int res = 0;
    while(n > 0) {
        res ++;
        n /= 10;
    }
    return res;
}


signed main() {
    make(int, N);

    int ans = 0;
    FORE(i, 1, N) {
        if (digsum(i) % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    long long int sum=0;
    scanf("%d",&N);
    for(long long int i=1;i<=N;i++)
    {
        if(i%3!=0 && i%5!=0 && (i%3!=0 && i%5!=0))
        {
            sum = sum + i;
        }
    }
    printf("%lld\n",sum);
    return 0;
}


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

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

    int Sum = 0;

    for(int i = 0; i < N.size(); i++){
        Sum += N.at(i) - '0';
    }

    if(Sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3744
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int n,m;
	while(cin>>n,n){
		int cnt=0;
		while(n!=1){
			if(n&1) n = n*3+1;
			else n /= 2;
			cnt++;
		}
		cout << cnt<< endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d%d%d",&a,&b,&c);
    if(a<=b){
        x=b/a;
    if(x>c)
        printf("%d",c);
        else
            printf("%d",x);
    }
    else
        printf("0");

    return 0;

}

Measured memory_bytes: 128
import scala.io.StdIn.readInt

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(50000)
    var n = 0
    while( { n = readInt; n} != 0 ) {
      var cnt = 0
      if(p(n-2) == 1) cnt = 1
      else if(n%2==0) {
        for(i<- 3 to n/2 by 2)
          if(p(i) ==1 && p(n-i) ==1)
            cnt += 1
      }
      println(cnt)
    }
  }
}

Measured memory_bytes: 50968
package main

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

func gcd(x, y int) {
	if x == 0 || y == 0 {
		fmt.Println(0)
		return
	} else if x == 1 || y == 1 {
		fmt.Println(1)
		return
	} else if x%y == 0 {
		fmt.Println(y)
		return
	} else if y%x == 0 {
		fmt.Println(x)
		return
	} else {
		if x > y {
			gcd(y, x%y)
		} else {
			gcd(x, y%x)
		}
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n1, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	sc.Scan()
	n2, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	gcd(n1, n2)
}



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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n,m; cin >> n >> m;
  vector<lint> p(m), y(m); for(lint i=0;i<m;i++) { cin >> p[i] >> y[i]; }
  
  vector<lint> ymat[n];
  for(lint i=0;i<m;i++) { ymat[p[i]-1].push_back(y[i]); }
  for(lint i=0;i<n;i++) { sort(ymat[i].begin(),ymat[i].end()); } // sort for each prefucture

  vector< pair<lint,lint> > vp(m);
  for(lint i=0;i<m;i++) {
    vp[i].first = p[i];
    vp[i].second = (lint)(lower_bound(ymat[p[i]-1].begin(),ymat[p[i]-1].end(),y[i])-ymat[p[i]-1].begin()+1);
  }

  for(lint i=0;i<m;i++) { printf("%06lld%06lld\n",vp[i].first,vp[i].second); }
  return 0;
}

Measured memory_bytes: 11948
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int n;
vector<int> a;

void mainmain(){
    cin >> n;
    for (int i = 0;i < n; i++){
        int m;
        cin >> m;
        m -= 1;
        a.push_back(m);
    }
    int count = 0;
    for(int i = 0 ;i < n; i++){
        int j = a[i];
        if(j < i) continue;
        if(a[j] == i) count++;
    }
    cout << count << endl;
}

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

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
char a[1010][1010];
int ans[1010][1010];
vector<pair<int,int> > v;
int n,m;
int cnt=0;
void solve(){
	for(int i=0;i<v.size();i++){
		int x=v[i].first;
		int y=v[i].second;
		for(int i=0;i<4;i++){
			int ax=x+dx[i];
			int ay=y+dy[i];
			if(ax>=0&&ax<n&&ay>=0&&ay<m&&a[ax][ay]=='.'){
				a[ax][ay]='#';
				v.push_back(make_pair(ax,ay));
				ans[ax][ay]=ans[x][y]+1;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cnt=max(cnt,ans[i][j]);
		}
	}
	return ;
}
int main(){
	memset(ans,0,sizeof(ans));
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='#')v.push_back(make_pair(i,j));
		}
	}
	solve();
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 15212
#include<stdio.h>
#define N 8
#define FREE -1
#define NOTFREE 1
void printer(void);
void Queen(int);
int line[N],row[N],srashr[2*N-1],srashl[2*N-1];
int X[N][N];
int main(){
  int i,j,a,x,y;
  for(i=0;i<N;i++){
    row[i]=FREE;
    line[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    srashr[i]=FREE;
    srashl[i]=FREE;
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[N][N]=0;
    }
  }
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d %d",&x,&y);
    X[x][y]=1;
  }
  Queen(0);
  return 0; 
}

void printer(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]==1){
	if(row[i]!=j)
	  return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)
	printf("Q");
      else
	printf(".");
    }
    printf("\n");
  }
}

void Queen(int x){
  int i;
  if(x==N){
    printer();
    return;
  }
  for(i=0;i<N;i++){
    if(NOTFREE==line[i] || NOTFREE==srashr[x+i] || NOTFREE==srashl[x-i+N-1])
      continue;
  row[x]=i;
  line[i]=srashr[x+i]=srashl[x-i+N-1]=NOTFREE;
  Queen(x+1);
  row[x]=line[i]=srashr[x+i]=srashl[x-i+N-1]=FREE;
    }
}




Measured memory_bytes: 2112
#pragma comment(linker, "/STACK:512000000")
#define _CRT_SECURE_NO_WARNINGS
//#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
typedef long long li;
typedef long double ld;
void solve();
void precalc();
clock_t start;
//int timer = 1;

int testNumber = 1;

bool todo = true;

int main() {
#ifdef AIM
    freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    start = clock();
    int t = 1;
    cout.sync_with_stdio(0);
    cin.tie(0);
    precalc();
    cout.precision(10);
    cout << fixed;
    //cin >> t;
    int testNum = 1;
    while (t--) {
        //cerr << testNum << endl;
        //cout << "Case #" << testNum++ << ": ";
        solve();
        ++testNumber;
        //++timer;
    }

#ifdef AIM
    cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif

    return 0;
}

//BE CAREFUL: IS INT REALLY INT?

template<typename T>
T binpow(T q, T w, T mod) {
    if (!w)
        return 1 % mod;
    if (w & 1)
        return q * 1LL * binpow(q, w - 1, mod) % mod;
    return binpow(q * 1LL * q % mod, w / 2, mod);
}

template<typename T>
T gcd(T q, T w) {
    while (w) {
        q %= w;
        swap(q, w);
    }
    return q;
}
template<typename T>
T lcm(T q, T w) {
    return q / gcd(q, w) * w;
}

void precalc() {

}

//#define int li

//const int mod = 1000000007;


void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            string s;
            cin >> s;
            if (s == "snuke") {
                cout << char('A' + j) << i + 1 << "\n";
                return;
            }
        }
    }
}


















































Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	vvi is(n+1);
	REP(i,m){
		int a,b;
		cin>>a>>b;
		
		is[a].push_back(b);
	}
	
	REP(i,is[1].size()){
		REP(j,is[is[1][i]].size()){
			if(is[is[1][i]][j]==n){
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 8576
#include <stdio.h>
#include <stdlib.h>
 
#define MAX 2000001
#define VMAX 10000
 
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: 9612
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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;}

const int INF=1001001001001001001ll;

int N,M,C,start,goal;
int D[20][100][100];
int cost[20][20000];

int W[100][100];

void solve(){
    start--;goal--;
    fill_n(**D,20*100*100,INF);
    rep(i,C)rep(j,N)D[i][j][j]=0;
    rep(i,M){
        int x,y,d,c;
        cin>>x>>y>>d>>c;x--;y--;c--;
        chmin(D[c][x][y],d);
        chmin(D[c][y][x],d);
    }


    rep(l,C)rep(k,N)rep(i,N)rep(j,N)
        chmin(D[l][i][j],D[l][i][k]+D[l][k][j]);

    int p[20];rep(i,C)cin>>p[i];
    rep(i,C){
        int q[55];
        q[0]=0;q[p[i]]=20000-1;
        rep(j,p[i]-1)cin>>q[j+1];
        rep(j,p[i]){
            int r;cin>>r;
            for(int k=q[j]+1;k<=q[j+1];k++)cost[i][k]=cost[i][k-1]+r;
        }
    }

    fill_n(*W,100*100,INF);rep(i,N)W[i][i]=0;
    rep(i,C)rep(j,N)rep(k,N){
        if(D[i][j][k]==INF)continue;
        chmin(W[j][k],cost[i][D[i][j][k]]);
    }

    rep(k,N)rep(i,N)rep(j,N)chmin(W[i][j],W[i][k]+W[k][j]);
    if(W[start][goal]==INF)cout<<-1<<endl;
    else cout<<W[start][goal]<<endl;
}

signed main(){
    while(cin>>N>>M>>C>>start>>goal,N||M||C)solve();
}

Measured memory_bytes: 7812
#!/usr/bin/env python3
import sys

def solve_even(N: int, K: int):
    return pow((N - (K//2)) // K + 1, 3) + pow((N - K) // K + 1, 3)

def solve(N: int, K: int):
    return pow(N // K, 3) if K % 2 else solve_even(N, K)

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    K = int(next(tokens))
    print(solve(N, K))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,a[400001];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],a[0]^=a[i];
	for(int i=1;i<=n;i++)cout<<(a[0]^a[i])<<' ';
}

Measured memory_bytes: 4392
h,w = map(int, input().split())
ar = []
for _ in range(h):
  row = list(input())
  if row == ['.']*w:
    continue
  ar.append(row)

c = 0
while c < len(ar[0]):
  count = 0
  for r in range(len(ar)):
    if ar[r][c] == '#':
      count += 1
  if count == 0:
    for row in ar:
      row.pop(c)
  else:
    c += 1

for row in ar:
  print("".join(row))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int ch=0,ans=0;
    for(int i=0;i<n;++i){
      string s; cin>>s;
      if(s=="lu" || s=="ru"){
        if(ch==1){
          ans++;
          ch=0;
        }else ch=1;
      }else if(s=="ld" || s=="rd"){
        if(ch==-1){
          ans++;
          ch=0;
        }else ch=-1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3044