akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int k = Integer.parseInt(str[1]);
    System.out.println(n%k==0?0:1);
  }
}

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

vector<vector<int>> bv;
vector<vector<int>> bh;

long long f1( int i, int j, long long res )
{
	if( j >= bh.size() ) return res;
	int x = bh[i][j];
	res += bh.size();
	auto it = find( bv[x].begin() + j, bv[x].end(), x );
	if( it != bv[x].end() ) res += bv.size();
	long long ret = f1( i, j + 1, res );
	res = max( res, ret );
	return res;
}
long long f( int i, int j, long long res )
{
	if( i >= bv.size() ) return res;
	int y = bv[j][i];
	res += bv.size();
	auto it = find( bh[y].begin() + j, bh[y].end(), y );
	if( it != bh[y].end() ) {
		long long ret = f1( i, it - bh[y].begin(), res );
		res = max( res, ret );
	}
	long long ret = f(i + 1, 0, res );
	res = max( res, ret );
	return res;
}

int main()
{
	int H, W, M;
	cin >> H >> W >> M;
	typedef pair<int, int> P;
	set<P> st;
	for( int i = 0; i < M; i++ ) {
		int h, w;
		cin >> h >> w;
		h--;
		w--;
		st.insert( P( h, w ) );
	}

	map<int, int> hma;
	int mah = 0;
	map<int, int> wma;
	int maw = 0;
	for( auto it = st.begin(); it != st.end(); it++ ) {
		int h = it->first;
		int w = it->second;
		hma[h]++;
		wma[w]++;
		if( hma[h] > mah ) mah = hma[h];
		if( wma[w] > maw ) maw = wma[w];
	}
	int ans = mah + maw - 1;
	vector<int> ch;
	vector<int> cw;
	for( auto it = hma.begin(); it != hma.end(); it++ ) {
		if( it->second == mah ) ch.push_back( it->first );
	}
	for( auto it = wma.begin(); it != wma.end(); it++ ) {
		if( it->second == maw ) cw.push_back( it->first );
	}
	for( int h : ch ) {
		for( int v : cw ) {
			if( st.count( P( h, v ) ) == 0 ) {
				cout << ans + 1 << endl;
				return 0;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 49580
#include<stdio.h>
int main()
{
    int N;scanf("%d",&N);
    int a[10000],i,j,sum=0,max,t;
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    max=a[0];
    for(j=1;j<N;j++)
    {
      if(max<a[j])
      {
          max=a[j];
      }
    }
    for(i=0;i<N;i++)
    {
      sum+=a[i];
    }
    sum+=(max/2)-max;
    printf("%d",sum);
    return 0;
}


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

int solve(int h,vector<vector<int>> &f){
  int res=0;
  bool update=false;
  for(int i=0;i<h;i++){
    int cnt=1;
    for(int j=1;j<=5;j++){
      if(j<5 && f[i][j-1]==f[i][j] && f[i][j-1]!=0){
	cnt++;
      }
      else{
	if(cnt>=3){
	  update=true;
	  int num=f[i][j-1];
	  for(int k=j-cnt;k<j;k++){
	    res+=num;
	    f[i][k]=0;
	  }
	}
	cnt=1;
      }
    }
  }

  for(int i=0;i<h*2;i++){
    for(int j=h-1;j>0;j--){
      for(int k=0;k<5;k++){
	if(f[j][k]==0 && f[j-1][k]!=0){
	  swap(f[j][k],f[j-1][k]);
	}
      }
    }
  }

  if(update){
    return res+solve(h,f);
  }
  else{
    return res;
  }
}
int main(){
  int h;
  while(cin>>h,h){
    vector<vector<int>> f(h,vector<int>(5,0));
    for(int i=0;i<h;i++){
      for(int j=0;j<5;j++){
	cin>>f[i][j];
      }
    }

    cout<<solve(h,f)<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int factorial(int n){
  int x=1;
  for(int i=1; i<=n; ++i) x*=i;
  return x;
}

int main(){
  int N;
  char mx='a';
  cin>>N;
  deque<string> L;
  L.push_back("a");
  
  if(N==1){
    cout<<"a"<<endl;
    return 0;
  }
  
  while(L.size()!=factorial(N)){
    mx='a';
    string S=L.front();
    L.pop_front();
    
    for(int i=0; i<S.size(); ++i){
      if(mx<S.at(i)) mx=S.at(i);
    }
    
    for(int i=0; i<=mx-'a'+1; ++i){
      char A='a'+i;
      if(S.size()==N-1) cout<<S+A<<endl;
      L.push_back(S+A);
      if(S+A=="ab" && N==2) return 0;
      if(S+A=="abc" && N==3) return 0;
      if(S+A=="abcd" && N==4) return 0;
      if(S+A=="abcde" && N==5) return 0;
      
      if(S+A=="abcdef" && N==6) return 0;
      if(S+A=="abcdefg" && N==7) return 0;
      if(S+A=="abcdefgh" && N==8) return 0;
      if(S+A=="abcdefghi" && N==9) return 0;
      if(S+A=="abcdefghij" && N==10) return 0;
    }
  }
  
}

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


int main(void){
    int a,b;cin >> a >> b;
    int digit = log10(b)+1;

    int x = a*pow(10,digit)+b;
    //printf("x: %d\n",x);
    //double y =pow(x, 0.5);
    //printf("y: %lf",y);
    if(pow(x, 0.5) - floor(pow(x, 0.5)) ==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    

}

Measured memory_bytes: 3892
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <set>

using namespace std;

inline int getInt() { int s; scanf("%d", &s); return s; }

// bad knowhow
#define ALL(c) (c).begin(), (c).end()
#define REP(i,n) for(long long i=0;i<(long long)n;++i)
#define MAX_SIZE 100

set<int> g_p[MAX_SIZE];
set<int> g_leak;

int main() {

	while (true) {
		REP(i, MAX_SIZE) g_p[i].clear();
		g_leak.clear();

		const int n = getInt();
		if (n==0) break;
		
		REP(i, n) {
			const int m = getInt();
			REP(j, m) g_p[i].insert(getInt()-1);
		}

		int k = getInt();
		REP(i, k) g_leak.insert(getInt()-1);

		vector<int> suspect;
		REP(i,n) {
			vector<int> is;
			set_intersection(
				ALL(g_leak), ALL(g_p[i]),
				std::inserter(is, is.end())
			);
			if (is.size()!=g_leak.size()) continue;
			suspect.push_back(i);
		}

		cout << ((suspect.size()==1) ? suspect[0] + 1 : -1) << endl;
	}
}

Measured memory_bytes: 1608
#include<cstdio>
const long long mod = 1e9+7;
int arr[100005];
int main(){
    int n, x;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        arr[x] ++ ;
    }
    bool flag = true;
    if(n&1){
        if(arr[0]!=1)
            flag = false;
        for(int i=2;i<n;i+=2){
            if(arr[i]!=2){
                flag = false;
                break;
            }
        }
    }else {
        for(int i=1;i<n;i+=2){
            if(arr[i]!=2){
                flag = false;
                break;
            }
        }
    }
    if(flag){
        long long ans = 1ll;
        int t = n/2;
        while(t--){
            ans = (ans <<1)%mod;
        }
        printf("%lld\n",ans);
    }else
        puts("0");
    return 0;
}


Measured memory_bytes: 512
///******* In the name of Allah *******///

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

void Ok()
{
    long int a[113],b,c,d,e,f,g,t,i,j,k,l,m,n,r,sum,ans_1,ans_2,ans_3,cnt,Max = 0,Min = 999;
    double aa,bb,cc,dd,ee;
    char aaa[1013],bbb[1013],ccc[1013];

    cin>>n>>k;
    for(i=1;i<=k;i++)
    {
        a[i] = 1;
    }

    ans_1 = (n - k);
    a[1] += ans_1;

    for(i=1;i<=k;i++)
    {
        Max = max(Max,a[i]);
        Min = min(Min,a[i]);
    }
    ans_2 = Max - Min;
    cout<<ans_2<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char s[] = sc.next().toCharArray();
		int cnt = 0;
		for (int i = 0; i < s.length; i = i + 2) {
			if (s[i] == 'p') {
				cnt--;
			}
		}
		for (int i = 1; i < s.length; i = i + 2) {
			if (s[i] == 'g') {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  char a, b;
  cin >> a >> b;
  
  if (a == b) 
    cout << 'H' << endl;
  else
    cout << 'D' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//けんちょんの競プロ精進記録 SPOJ DQUERY - D-queryより
template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

using namespace std;

// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


#define debug(x) cout << #x << "==" << x << endl;

const int inf = 1e+8;

typedef long long ll;



string common_subsq(string s, string t) {
  string com = "";
  int i = 0, j = 0;
  while( i < (int)s.size() and j < (int)t.size()) {
    if( s[i] == t[j] ) {
      com += s[i];
      i++; j++;
    } else if ( s[i] < t[j] ) {
      i++;
    } else {
      j++;
    }
  }
  return com;
}

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<string> S(N);
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[i] = s;
  }

  string com = S[0];
  for(int i = 1; i < N; i++) {
    com = common_subsq( com, S[i] );
  }

  cout << com << "\n";

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    public static void main(String[] args) {
        int N = nint();
        int M = nint();
        List<Integer> ds = new ArrayList<>();
        for (int i = 1; i <= Math.sqrt(M); i++) {
            if (M % i == 0) {
                ds.add(i);
                ds.add(M/i);
            }
        }
        ds.sort((i1, i2) -> i1 - i2);
        
        for (int d: ds) {
            if (d >= N) {
                so.println(M / d);
                return;
            }
        }
        throw new RuntimeException();
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }
    
    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }
    
    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }
    
    private static char[][] nchars2D(int h, int w) {
        return nchars2D(h, w, 0);
    }
    
    private static char[][] nchars2D(int h, int w, int pad) {
        char[][] a2 = new char[h+pad*2][w+pad*2];
        for(int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad+i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 29012
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    H = readInts()
    ma_ = H[0]
    for i in range(1,n):
        if ma_ < H[i]:
            H[i] -=1
        if ma_ <= H[i]:
            #もし1段下げた場合に、その時の最大よりも大きい
            #（または等しい)ければよい
            ma_ = H[i]
        else:
            print('No')
            exit()
    print('Yes')



if __name__ == '__main__':
  main()


Measured memory_bytes: 14396
# https://atcoder.jp/contests/abc113/tasks/abc113_c

import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, m = input_int_list()
    cnt = defaultdict(int)
    cities = []
    ids = [None] * m
    for i in range(0, m):
        p, y = input_int_list()
        cities.append((i, p, y))

    cities = sorted(cities, key=lambda x: x[2])

    for i, p, y in cities:
        num = cnt[p] + 1
        cnt[p] += 1
        _id = "{:0=6}{:0=6}".format(p, num)
        ids[i] = _id

    for _id in ids:
        print(_id)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 105644
s = input()
t = input()

s = ''.join(s)
t = ''.join(t)


count = 0
maxcount = 0
slen = len(s)
tlen = len(t)
j = 0

while j <= slen-tlen:
    k = j
    for i in range(tlen):
        if t[i] == s[k]:
            count += 1
        k+= 1
    j += 1
    if count > maxcount :
        maxcount = count
    count = 0
print(len(t)-maxcount)

Measured memory_bytes: 9072
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

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


int main(void) {

	int n;
	int a[101];
	int pos = 101;
	int count = 0;
	bool flag = 0;

	cin >> n;
	FOR(i, 1, n) {
		cin >> a[i];
	}

	flag = true;
	while (flag) {
		flag = false;
		FOR(i, 1, n - 1) {
			if (a[i] == a[i + 1]) {
				a[i + 1] = pos;
				pos++;
				count++;
				flag = true;
			}
		}
	}
	cout << count << endl;

	return 0;
}

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

long long gcd(long long a, long long b){
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    
    //ユークリッド互除法
    long long p = min(c, d);
    long long q = max(c, d);
    long long r = q % p;
    
    while(r != 0) {
        r = q % p;
        q = p;
        p = r;
    }
//    long long lcm_cd = c * d / q; //cとdの最小公倍数
    long long lcm_cd = c * d / gcd(c, d); //cとdの最小公倍数

    long long num_m_c = b / c - (a - 1) / c;    //cの倍数の数
    long long num_m_d = b / d - (a - 1) / d;    //dの倍数の数
    long long num_m_cd = b / lcm_cd - (a - 1) / lcm_cd;   //c,dの最小公倍数の数
    
    long long ans = b - (a - 1) - (num_m_c + num_m_d - num_m_cd);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort(all(v))
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
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;};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


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

	int n, m;
  cin >> n >> m;
  UnionFind uf(n + 1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if(a == 1 || b == n) {
      uf.unite(a, b);
    }
  }
  if(uf.same(1, n)) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Node;

Node root;
int maxh;

Node treeSearch(Node u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;
  if(y == NIL){
    root = z;
  }else{
    if(z->key < y->key){
      y->left = z;
    }else{
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);
  maxh = 0;
  for(i=0; i<n; i++){
    scanf("%s",com);
    if(com[0] == 'f'){
	    scanf("%d",&x);
	    Node t = treeSearch(root,x);
	    if(t != NIL){printf("yes\n");
	    }else printf("no\n");
	  }else if(com[0] == 'i'){
	  scanf("%d",&x);
	  insert(x);
	  }else if(com[0] == 'p'){
	    inorder(root);
	    printf("\n");
	    preorder(root);
	    printf("\n");
	  }
  }

  return 0;
}



Measured memory_bytes: 20440
def main():
    n = int(input())
    X = [int(x) for x in input().split()]
    ave_x = int(sum(X) / len(X))
    error_1 = 0
    error_2 = 0
    for x in X:
        error_1 += (x-ave_x) ** 2
        error_2 += (x-(ave_x+1)) ** 2
        min_e = min(error_1, error_2)
    print(min_e)
    
if __name__ == '__main__':
    main()

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

long long mod = 1e9+7;
long long fact[200005];

long long mod_pow(long long x, long long y){
    long long res = 1;
    while (y > 0){
	    if (y & 1){
		res = res*x%mod;
	    }
	    x = x*x%mod;
	    y >>= 1;
    }
    return res;
}

long long inv(long long a){
    return mod_pow(a, mod-2);
}


long long factorial(int a){
    if (a == 0) return fact[a] = 1;
    if (fact[a] != -1) return fact[a];
    return fact[a] = factorial(a-1) * a % mod;
}
 
long long comb(int n, int r){
    if (n <= 200000) return factorial(n)* inv(factorial(n-r)) % mod * inv(factorial(r)) % mod;
    long long ans = 1;
    for (int i = n; i > n-r; i--){
        ans = (ans * i) % mod;
    }
    for (int i=1; i <= r; i++){
        ans = (ans * inv(i)) % mod;
    }
    return ans;
}
 
int main(){
    long long  n, a, b;
    cin >> n >> a >> b;
    memset(fact, -1, sizeof(fact));
    factorial(min(n, 200000LL));
    
    long long ans;
    ans = mod_pow(2, n)-comb(n, a)-comb(n, b)-1;
    while (ans<0)
	ans += mod;
    cout << ans << endl;  
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e5+3;
int main(){
	int n;
	cin >> n;
	vector<int> num(MAX);
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		num[a]++;
		num[a+1]++;
		num[a+2]++;
	}
	cout << *max_element(num.begin(), num.end()) << endl;
	return 0;
}

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

int main() {
	int N,i;
	cin >> N >> i;
	cout << N + 1 - i << "\n";

	Would you please return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        int m=sc.nextInt();
        int h[]=sc.nextIntArray(n);
        int d[]=new int[n];
        for (int i = 0,a,b; i < m; i++) {
			a=sc.nextInt()-1;
			b=sc.nextInt()-1;
			if(h[a]<=h[b])d[a]--;
			if(h[a]>=h[b])d[b]--;
		}
        int r=0;
        for (int i = 0; i < d.length; i++) {
			if(d[i]==0)r++;
		}
   
        out.println(r);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//class P {
//	int x,c;long s;
//	P(int  x, int c, long s) {
//	  this.x=x;
//	  this.c=c;
//	  this.s=s;
//	}
//}


class P implements Comparable<P>{
	int x,c;long s;
	P(int  x, int c, long s) {
	  this.x=x;
	  this.c=c;
	  this.s=s;
	}

    public int compareTo(P p){
        return Long.signum(s-p.s);
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 54376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}


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

    int N; cin >> N;
    vc<pair<int,pi>> v;
    rep(i,N){
        int a,b; cin >> a >> b;
        v.eb(a+b,pi(a,b));
    }
    sort(all(v));
    reverse(all(v));
    int A=0,B=0;
    rep(i,N){
        if(i%2==0) A+=v[i].se.fi;
        else B+=v[i].se.se;
    }
    cout << A-B << endl;
}

Measured memory_bytes: 4596
class UnionFind:
    def __init__(self, n: int) -> None:
        self.forest = [-1] * n

    def union(self, x: int, y: int) -> None:
        x = self.findRoot(x)
        y = self.findRoot(y)
        if x == y:
            return
        if self.forest[x] > self.forest[y]:
            x,y = y,x
        self.forest[x] += self.forest[y]
        self.forest[y] = x
        return

    def findRoot(self, x: int) -> int:
        if self.forest[x] < 0:
            return x
        else:
            self.forest[x] = self.findRoot(self.forest[x])
            return self.forest[x]

    def issame(self, x: int, y: int) -> bool:
        return self.findRoot(x) == self.findRoot(y)

    def size(self,x: int) -> int:
        return -self.forest[self.findRoot(x)]


n,m = map(int,input().split())
ab = [tuple(map(int,input().split())) for i in range(m)]
uf = UnionFind(n)
for ai,bi in ab:
    uf.union(ai-1,bi-1)
ans = 0
for i in range(n):
    ans = max(ans,uf.size(i))
print(ans)


Measured memory_bytes: 40812
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  n <- readInt
  let b = permutations n
   in put $ minimum $ map f b

f :: [Int] -> Int
f [a, b, c] = abs (b - a) + abs (c - b)


Measured memory_bytes: 380
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int n,tmp,c,m;
    cin>>n;
    m=c=0;
    rep(i,n){
      cin>>tmp;
      c+=tmp;
      m=max(m,tmp);
    }
    cout<<(int)(c-m/2)<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
H, W, M = map(int, input().split())
h_cnt = [0] * H
w_cnt = [0] * W
s = set()
for i in range(M):
    h, w = map(int, input().split())
    h -= 1
    w -= 1
    h_cnt[h] += 1
    w_cnt[w] += 1
    s.add((h, w))

cand1 = max(h_cnt) + max(w_cnt)
cand2 = cand1 - 1

x = Counter(h_cnt)
y = Counter(w_cnt)

def check(k):
    cnt = False
    for i in range(k + 1):
        cnt += x[i] * y[k - i]
    for h, w in s:
        if h_cnt[h] + w_cnt[w] == k:
            cnt -= 1
        if h_cnt[h] + w_cnt[w] == k + 1:
            cnt += 1
    return cnt > 0

if check(cand1):
    print(cand1)
else:
    print(cand2)

Measured memory_bytes: 130104
n=int(input())
def factorize(n):
    fct0 =fct1 =fct2 =fct3 =fct4 = 0  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if 2<=e<4:
            fct0+=1
        elif 4<=e<14:
            fct1+=1
        elif 14<=e<24:
            fct2+=1
        elif 24<=e<74:
            fct3+=1
        elif 74<=e:
            fct4+=1
        b, e = b + 1, 0
    return [fct0,fct1,fct2,fct3,fct4]
from math import factorial
l=factorize(factorial(n))
ans=l[4]
ans+=(l[3]+l[4])*max(sum(l)-1,0)
ans+=(l[2]+l[3]+l[4])*max(sum(l)-l[0]-1,0)
ans+=(sum(l)-l[0])*max(sum(l)-l[0]-1,0)*max(sum(l)-2,0)//2
print(int(ans))

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<string> Only;
    map<string, int> str;

    // for (int i = 0; i < N; i++) {
    //     cin >> S[i];
    //     bool only = true;
    //     int size = Only.size();
    //     if (i != 0) {
    //         for (auto x : Only) {
    //             if (S[i] == x) only = false;
    //         }    
    //     }
    //     if (only) Only.push_back(S[i]);
    // }

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

    for (int i = 0; i < N; i++) {
        Only.push_back(S[i]);
    }

    sort(Only.begin(), Only.end());
    Only.erase(unique(Only.begin(), Only.end()), Only.end());

    int size = Only.size();

    for (int i = 0; i < size; i++) {
        str[Only[i]] = 0;
    }

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

    vector<string> ans;
    int MAX = 0;
    for (int i = 0; i < size; i++) {
        MAX = max(MAX, str[Only[i]]);
    }

    for (int i = 0; i < size; i++) {
        if (str[Only[i]] == MAX) ans.push_back(Only[i]);
    }
    
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 30068
N, K = map(int, input().split())

N_list = []
for i in range(1, N+1):
    N_list.append(i)
for i in range(K):
    L = int(input())
    P_list = [int(x) for x in input().split()]
    for P in P_list:
        if P in N_list:
            N_list.remove(P)

print(len(N_list))

Measured memory_bytes: 9192
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

unsigned long long int a = 0, b = 0, c =1, d = 0, e = 9999, n = 0, maxy = 0, mini = 9999, counter = 0, sur = 0,kuso=0,kuso2=0,ans=0;
std::vector<unsigned long long int> vec{};
std::vector<std::string>str{};
std::vector<std::string>str2{};

int arraykun[2300] = {}, nyan[1001] = {}, koji[50][50];
std::string output, output2, input,nyahhoi;
int kakunou[50][50] = { 53 };

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {
	
		c = i % j;
		i = j;
		if (c != 0) {
		
			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a>>b>>c;

	
	cout << (a-b+1)*(a-c+1) << endl;

}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		while(true){
			String line=sc.nextLine();
			
			if(line.equals("0")){
				break;
			}
			
			int n=Integer.parseInt(line);
			int counter=0;//?????°
			
			if(n==1){
				System.out.println(1);
			}else{
				
				for(int i=n+1; i<=2*n; i++){
					
					for(int h=2; h<=Math.sqrt(i); h++){
						
						if(i%h==0){
							counter++;
							break;
						}
						
					}
					
				}
				
				System.out.println(n-counter);
			}
			
			
			
		}
	}
}

Measured memory_bytes: 27832
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>


using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef int status;
typedef long long ll;
typedef unsigned long long ull;
const ull base = 343;
const int INF = int(1e9);
const ll INF1 = ll(1e18);
const int MAX = 1000002;

int N;
int a[MAX];
int flag = 0;

int main()
{
    cin>>N;
    for(int i = 1;i <= N;i++){
        cin>>a[i];
        if(a[1]!=0||a[i]-a[i-1]>1)flag = 1;
    }
    if(flag == 1){
        cout<<-1<<endl;
        return 0;
    }
    ll sum = 0;
    for(int i = N;i > 1;i--){
        if(a[i]>a[i-1]){
            sum += a[i]-a[i-1];
        }else {
            sum += a[i];
        }
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> R(A), G(B), T(C);
  rep(i,A) cin >> R.at(i);
  rep(i,B) cin >> G.at(i);
  rep(i,C) cin >> T.at(i);
  sort(R.begin(), R.end(), greater<ll>());
  sort(G.begin(), G.end(), greater<ll>());
  rep(i,X) T.push_back(R[i]);
  rep(i,Y) T.push_back(G[i]);
  sort(T.begin(), T.end(), greater<ll>());

  ll sum = 0;
  rep(i, X+Y) {
    sum += T[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 7844
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
int I,J,x,y,mas[110][110]={{0}};
int dy[6]={-1,-1, 0, 0, 1, 1};
int dx_k[6]={ 0, 1,-1, 1, 0, 1};
int dx_g[6]={-1, 0,-1, 1,-1, 0};
int d[110][110];
int wall=0;
long long int wall_len=0;
typedef pair<int,int>P;
int bfs();
int wall_reck(int,int);
int main(){
  cin >> x >> y;
  for(int i=1;i<y+1;i++){
    for(int j=1;j<x+1;j++){
      cin >> mas[i][j];
    }
  }
 
  for(int i=0;i<y+2;i++){
    for(int j=0;j<x+2;j++){
      if(mas[i][j]==0){
    if(i==0 || j==0 || i==y+1 || j==x+1){
      wall_reck(i,j);
    }
    else{
      I=i;
      J=j;
      bfs();
      //帰ってきた値が1（つまり、抜けられた）、または範囲外（必ず１）なら、周り(六方)の壁の数を計算。
      if(wall == 1){
        wall=0;
        wall_reck(i,j);
      }
    }
      }
    }
  }
  cout << wall_len << endl;
}
 
int bfs(){
  queue<P>que;
  memset(d,-1,sizeof(d));
  que.push(P(I,J));
  d[I][J] = 0;
  while(!que.empty()){
    P p = que.front();
    que.pop();
    //外につながったか。
    if(p.first==0 || p.second==0 || p.first==y+1 || p.second==x+1){
      wall=1;
      break;
    }
    for(int i=0;i<6;i++){
      int ny,nx;
    ny=p.first+dy[i];
      if(!(p.first&1)){
    nx=p.second+dx_g[i];
      }
      else{
    nx=p.second+dx_k[i];
      }
      if(mas[ny][nx]==0 && d[ny][nx]==-1){
    que.push(P(ny,nx));
    d[ny][nx]=d[p.first][p.second]+1;
      }
    }
 
  }
}
 
int wall_reck(int i,int j){
  for(int k=0;k<6;k++){
    if(!(i&1)){
      if(mas[i+dy[k]][j+dx_g[k]]==1){
    wall_len++;
      }
    }
    else{
      if(mas[i+dy[k]][j+dx_k[k]]==1){
    wall_len++;
      }
    }
 
  }
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;



void solve()
{
  int n;
  cin >> n;

  const ll INF = 1LL << 60;
  ll dp[100010];  
  fill(dp, dp + 100010, INF);
  dp[0] = 0;

  vector<int> yen { 1 };

  int num = 1;
  while(num < n)
  {
    num *= 6;
    yen.emplace_back(num);
  }

  num = 1;
  while(num < n)
  {
    num *= 9;
    yen.emplace_back(num);
  }

  sort(yen.rbegin(), yen.rend());

  for(int i = 0; i <= n; ++i)
  {
    for(const auto& y : yen)
    {
      if (i + y > n) continue;
      dp[i + y] = min(dp[i + y], dp[i] + 1);
    }
  }

  cout << dp[n];
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4388
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long ans = 0;
    for (int i = 1; i <= N; i++) {
      if (i % 3 == 0 || i % 5 == 0) continue;
      ans += i;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int H,W,D;
  cin>>H>>W>>D;
  VVI A(H,VI(W));
  vector<pair<int,P> > PP;
  rep(i,H) rep(j,W){
    cin>>A[i][j];
    PP.push_back(make_pair(A[i][j],make_pair(i,j)));
  }
  sort(all(PP));
  int Q;
  cin>>Q;
  VI L(Q),R(Q);
  rep(i,Q) cin>>L[i]>>R[i];
  vector<ll> X(H*W);
  rep(i,H*W){
    if(i>=D){
      X[i]=X[i-D]+abs(PP[i].second.first-PP[i-D].second.first)+abs(PP[i].second.second-PP[i-D].second.second);
    }
  }
  rep(i,Q){
    cout<<X[R[i]-1]-X[L[i]-1]<<endl;
  }
}

Measured memory_bytes: 4084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        double A = Double.parseDouble(st.nextToken());
        double B = Double.parseDouble(st.nextToken());
        double H = Double.parseDouble(st.nextToken());
        double M = Double.parseDouble(st.nextToken());
        
        double angle_H = (60 * H + M) / 720 * 360;
        double angle_M = M /60 * 360;

        double A_x = A * Math.cos(Math.toRadians(angle_H));
        double A_y = A * Math.sin(Math.toRadians(angle_H));

        double B_x = B * Math.cos(Math.toRadians(angle_M));
        double B_y = B * Math.sin(Math.toRadians(angle_M));

        double ans = Math.sqrt(Math.pow((A_x - B_x),2) + Math.pow((A_y - B_y),2));
       
        pw.println(ans);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 33292
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    string s;
    cin>>s;
    bool now=(s[0]=='B');
    ll cnt=0;
    rep(i,s.size()){
        if(now!=(s[i]=='B')){
            cnt++;
            now=!now;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 512
n=int(input())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    G[a-1].append((b-1,c))
    G[b-1].append((a-1,c))
q,k=map(int,input().split())
k=k-1
stack=[k]
dis=[-1]*n
dis[k]=0
from collections import deque
stack=deque(stack)
while len(stack)>0:
    now=stack.pop()
    d=dis[now]
    for i in G[now]:
        if dis[i[0]]==-1:
            dis[i[0]]=d+i[1]
            stack.append(i[0])
for i in range(q):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    print(dis[x]+dis[y])



Measured memory_bytes: 82528
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld                long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
//Bitwise 
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          (1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=1e5+5;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}

int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	int k;
	cin>>k;
	ll ans=0;
	rep(i,1,k+1){
		rep(ii,1,k+1){
			rep(iii,1,k+1){
				int temp=__gcd(iii,ii);
				temp=__gcd(temp,i);
				ans+=temp;
			}
			
		}
		
	}
	cout<<ans<<endl;
	return 0;
}

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

#define ll long long
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int reverse(int x){
    int ret = 0;
    while(x){
    ret = ret*10 + x%10;
    x /= 10;
    }
    return ret;
}


int main() {
    int A,B;
    cin >> A >> B;
    int cnt = 0;
    
    for(int i=A;i<=B;i++){
        if ( reverse(i) == i ){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256