akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = list(map(int, input().split()))

### それぞれの数字が2の素因数をいくつ持つかを返す
def num_factor2(num):
    result = 0
    while num % 2 == 0:
        result += 1
        num /= 2
    return result

a_factor2 = map(num_factor2, a)

num_factor2_zero = 0
num_factor2_one = 0
num_factor2_twoormore = 0

for a_ in a_factor2:
    if a_ == 0:
        num_factor2_zero += 1
    elif a_ == 1:
        num_factor2_one += 1
    elif a_ >= 2:
        num_factor2_twoormore += 1

if num_factor2_zero <= num_factor2_twoormore or (num_factor2_zero <= num_factor2_twoormore + 1 and num_factor2_one == 0):
    print("Yes")
else:
    print("No")
 

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    int cnt=0;
    vii v(n);
    for(int i = 0; i < n; i++){
        int x, y;
        cin>>x>>y;
        v[i]={x, y};
    }   
    int mx = 0;
    for(int i = 1; i < n; i++){
        if(v[i-1].f==v[i-1].s&&v[i].s==v[i].f){
            cnt++;
            mx=max(mx, cnt);
        }
        else cnt=0;
    }
    cout<<(mx>=2?"Yes":"No");
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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

int KETASUM(int x) {
    int ans = 0;
    while (x) {
        ans += x%10;
        x /= 10;
    }
    return ans;
}

int main() {
    int a, n, m;
    scanf("%d %d %d", &a, &n, &m);
    int ans=0, c=(-1), i=1+a;
    c = 1;
    rep(j,n) c *= i;
    while (c<=m && i<=m) {
        if (i-a == KETASUM(c)) ans++;
        i++;
        c = 1;
        rep(j,n) c *= i;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3200
#include <stdio.h>

int main() {
    int n, x; //n:?????§?????° x:????¨??????°
    int sumCount[10000] = {0};
    int dataSetCount;
    int i, j, k;
    dataSetCount = 0;
    
    scanf("%d %d", &n, &x);

    while (!(n == 0 && x == 0)) {

         for (i = 1; i <= n; i++) {
            for (j = i + 1; j <= n; j++) {
                for (k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        sumCount[dataSetCount]++;
                    }
                }
            }    
        }

    dataSetCount++;
    scanf("%d %d", &n, &x);

    }
    
    for (i = 0; i < dataSetCount; i++) {
        printf("%d\n", sumCount[i]);
    }
    return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#define NILL -1
using namespace std;

typedef struct
{
    int parent;
    int r; //sibling
    int l; //child
} TREE;

vector<TREE> t(100000);
int d[100000];

void depth(int node,int p)
{
    d[node] = p;
    if(t[node].r != NILL) depth(t[node].r,p);
    if(t[node].l != NILL) depth(t[node].l,p+1);
}

int main()
{
    int v,k;
    int vi;
int child,sibl;
int n;

    cin >> n;
    for(int i=0;i < n;i++){
        t[i].l = NILL;
        t[i].r = NILL;
        t[i].parent = NILL;
    }

    for(int i=0;i < n;i++){
        cin >> v >> k;
        for(int j=0;j < k;j++){
            cin >> vi;
            if(j == 0) t[v].l = vi;
            else t[child].r = vi;

            child = vi;
            t[vi].parent = v;
        }
    }

    //根を調べる
    for(int i=0;i < n;i++){
        if(t[i].parent == NILL) sibl = i;
    }
    depth(sibl,0);

    for(int i=0;i < n;i++){
        printf("node %d: parent = %d, depth = %d, ",i,t[i].parent,d[i]);
        if(t[i].parent == NILL) printf("root,");
        else if(t[i].l == NILL) printf("leaf,");
        else cout << "internal node,";

        int vv=t[i].l;
        cout << " [";
for(int j=0;vv != NILL; vv=t[vv].r,j++){
            if(j) cout << ", ";
            printf("%d",vv);
        }
        cout << "]" << endl;
    }
    return 0;
}



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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int L, R, d;
	cin >> L >> R >> d;

	int ans = 0;
	for(int i=L; i<=R; i++){
		if((i % d) == 0){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3716
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    A = LI()
    d = [0] * (max(A)+1)

    for x in A:
        for i in range(2,int(math.sqrt(x))+1):
            cnt = 0
            while x % i == 0:
                cnt += 1
                x //= i
            d[i] = max(d[i],cnt)
            if x == 1: break
        else:
            d[x] = max(1,d[x])
    m = 1
    for i in range(2,len(d)):
        m = (m * i ** d[i]) % MOD
    ans = 0
    for x in A:
        ans += (m * pow(x,MOD-2,MOD)) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 50796
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			Set<Integer> set = new HashSet<>();

			set.add(1);
			for (int i = 1; i < 10; i++) {
				int m = (int)Math.pow(6, i);
				if (m <= 100000) {
					set.add(m);
				} else {
					break;
				}
			}

			for (int i = 1; i < 10; i++) {
				int m = (int)Math.pow(9, i);
				if (m <= 100000) {
					set.add(m);
				} else {
					break;
				}
			}

			Integer[] c = new Integer[set.size()];
			set.toArray(c);
			Arrays.sort(c);

			int[] dp = new int[100010];
			Arrays.fill(dp, INF);
			for (int i : c) {
				dp[i] = 1;
			}

			for (int j = 1; j < 100010; j++) {
				for (int i = 0; i < c.length; i++) {
					if (j - c[i] < 0) continue;
					dp[j] = min(dp[j], min(dp[j-c[i]]+1, dp[j-1]+1));
				}
			}

			out.println(dp[n]);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int count = 0; //回文数の数をカウント
  std::string str;
  
  cin >> A >> B;
  
  for (int kaibun = A ; kaibun < B + 1 ; kaibun++) {
    if(kaibun < 10000 || kaibun > 99999) continue; //飛ばす
    
    str = std::to_string(kaibun); //intをstringに変換
    
    if(str[0] == str[4] && str[1] == str[3]) count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
n, k = [int(e) for e in input().split()]
a = list(map(str, input().split()))
elem_dict = {}
ans = 0
for i in a:
    if i not in elem_dict:
        elem_dict[i] = 1
    else:
        elem_dict[i] += 1
elem_sorted = sorted(elem_dict.items(), key=lambda x:x[1])
for i in range(len(elem_sorted)-k):
    ans = ans + elem_sorted[i][1]
print(ans)

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

int main() {
  int n;
  cin >> n;
  map<string,ll> m;
  ll ans = 0;
  rep(i,0,n) {
    string s;
    cin >> s;
    vector<string> t(10);
    rep(j,0,10) t[j] = s.substr(j,1);
    sort(t.begin(), t.end());
    s = "";
    rep(j,0,10) s += t[j];
    ans += m[s];
    m[s]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11356
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define __FastIO                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define D cout << "ok" << endl;
#define _(x) cout << #x << "->" << x;
#define _n cout<<endl;
#define __ cout<<" ";
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define LOG2(x)                                                           \
  (sizeof(unsigned long) * 8 - 1 - __builtin_clzl((unsigned long)(x)))
#define LOG2_UP(x)                                                        \
  (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define FIN freopen("in", "r", stdin);
#define FOUT freopen("out", "w", stdout);
#define zero(b) memset(b,0,sizeof b);
#define mone(b) memset(b,-1,sizeof b);
#define gcd(a,b) __gcd(a,b)
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
//template <typename T> using ordered_set = tree<T, null_type, less<T>,
//rb_tree_tag, tree_order_statistics_node_update>;
 
int main()
{
	__FastIO;
	int n,k;
	cin>>n>>k;
	if(k==1) 
	{
		cout<<0<<endl;
		return 0;
	}

	cout<<(n-k)<<endl;
}

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

const int J = 1;
const int O = 2;
const int I = 4;

int n;
string res;
int memo[8][1000];

int to_joi(char c) {
  switch (c) {
  case 'J':
    return J;
  case 'O':
    return O;
  case 'I':
    return I;
  default:
    cout << "error:to_joi" << endl;
    return -1;
  }
}

//joiはjoinの略 駄洒落じゃないよ
int DFS(int joi, int day) {
  //n日目で終了
  if (day == n) {;
    return 1;
  }
  if (memo[joi][day] == 0) {
    int tod = to_joi(res[day]);
    for (int j=0; j<8; j++) {
      if (j&joi && j&tod) {
	memo[joi][day] += DFS(j, day+1);
      }
    }
    memo[joi][day] %= 10007;
  }
  return memo[joi][day];
}

int main(void) {
  for (int i=0; i<8; i++) {
    for (int j=0; j<5; j++) {
      memo[i][j] = 0;
    }
  }
  cin >> n >> res;
  cout << DFS(J, 0) << endl;
  return 0;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,d,i,j,k,l,m,n,ans,tmp,hoge,fuga,piyo;
ll x[10010],y[10010];
string s,str;
int main(){
  cin>>a>>b>>c>>d;
  while(a>0&&c>0){
    c-=b;
    if(c<=0){
      cout<<"Yes";
      return 0;
    }
    a-=d;
    if(a<=0){
      cout<<"No";
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        long[] n = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
        if(n[0] == 1 || n[1] == 1)
        {
            Console.WriteLine($"{1}");
            return;
        }
        long result = 0;
        if((n[0] * n[1]) % 2 == 1)
        {
            result++;
        }
        result += (n[0] * n[1]) >> 1;
        Console.WriteLine($"{result}");
    }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			int[] a = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int[] ans = new int[N + 1];
			int cnt = 0;
			StringBuilder sb = new StringBuilder();
			for (int i = N; i > 0; i--) {
				int sum = 0;
				int j = 1;
				while (i * j <= N) {
					sum += ans[i * j];
					j++;
				}
				if (sum % 2 != a[i - 1]) {
					ans[i] = 1;
					cnt++;
					sb.Append($"{i} ");
				}
			}

			Console.WriteLine($"{cnt}");
			Console.WriteLine(sb.ToString().Trim());
		}
	}
}

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

int main(){
    int x,y;
    while(cin >> x >> y,!(x==0&&y==0)){
        if(x > y){
            int tmp = y;
            y = x;
            x = tmp;
        }
        cout << x << " " << y << endl;
    }
}


Measured memory_bytes: 3076
using System;
using System.Linq;
public class Hello
{
    public static int n;
    public static int[] A;
    public static int[,] dp; //trueならば1,falseならば-1
    public static void Main()
    {
        //入力受け取り
        n = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int q = int.Parse(Console.ReadLine());
        int[] m = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        
        //メモ用の二重配列
        dp = new int[21, 4000];

        for(int j = 0; j < q; j++)
        {
            if(solve(0,m[j]) == 1) Console.WriteLine("yes");
            else if(solve(0,m[j]) == -1) Console.WriteLine("no");
        }
    }
    
    public static int solve(int i, int m)
    {
        //まずメモリを参照
        if(dp[i, m + 2000] != 0)
        {
            return dp[i, m + 2000];
        }
        //再帰の終了条件
        else if(m == 0) dp[i, m + 2000] = 1;
        else if(i >= n) dp[i, m + 2000] = -1;

        //部分問題に分割
        else if(solve(i + 1, m) == 1) dp[i, m + 2000] = 1;
        else if(solve(i + 1, m - A[i]) == 1) dp[i, m + 2000] = 1;
        else dp[i, m + 2000] = -1;
        
        return dp[i, m + 2000];
    }


}


Measured memory_bytes: 8512
#!/usr/bin/python3

import sys

def solve(input: str):
    count = {}
    for char in list(input):
        if char not in count:
            count[char] = 0
        count[char] += 1
    if len(count) != 2:
        return False
    for _, v in count.items():
        if v != 2:
            return False
    return True

def main():
    inputs = sys.stdin.read().rstrip()
    if solve(inputs):
        print("Yes")
    else:
        print("No")

main()

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

#define LIMIT_SEC 5.5

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N;
    cin >> N;
    bool flag = false;
    rep(i, N) {
        char ch;
        cin >> ch;
        if (ch == 'Y') flag = true;
    }
    cout << (flag ? "Four" : "Three") << endl;
    return 0;
}


Measured memory_bytes: 256
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  ll n;
	cin >> n;
  ll a[n];
  ll num=0;
  map<ll, ll> mi, pl;
  FOR(i, 0, n-1){
    ll at;
    cin >> at;
    a[i] = at;
    mi[i-a[i]]++;
    pl[i+a[i]]++;
  }
  for (const auto& [key, value] : mi){
    num += pl[key]*mi[key];
  }
	cout << num << "\n";
}


Measured memory_bytes: 37328
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
  
int mgcd(int a, int b){
   int ta = max(a, b);
   int tb = min(a, b);
   int t = INF;
   while(t != 0){
     t = ta % tb;
     ta = tb;
     if(t != 0) tb = t;
   }
   return tb;
}

int mlcm(int a, int b){
  return a * b / mgcd(a, b);
}
  
signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);
  
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  
  int b = 1;
  int c = 0;
  int l = a[0];
  FOR(i, 1, n){
    l = mlcm(a[i], l);
  }
  
  b *= l;
  REP(i, n) c += l / a[i];

  cout << (D)b / c << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var s = ReadLine();
        for(var k = 0; k < 2; k++)
        {
            for(var i = 0; i < s.Length - k - 1; i++)
            {
                if (k == 0 && s[i] == s[i + 1])
                {
                    WriteLine($"{i + 1} {i + 2}");
                    return;
                }
                if (k == 1 && s[i] == s[i + 2])
                {
                    WriteLine($"{i + 1} {i + 3}");
                    return;
                }
            }
        }
        WriteLine("-1 -1");
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13280
import sys
readline = sys.stdin.readline

N = int(readline())

if N == 2:
    print(1)
    exit(0)

n1 = N - 1

n1_count = 1

i = 2
while i * i <= n1:
    if n1 % i == 0:
        if n1 // i != i:
            n1_count += 2
        else:
            n1_count += 1
    
    i += 1

n_count = 1
i = 2
while i * i <= N:
    if N % i == 0:
        a = i
        n = N
        while n % a == 0:
            n = n // a
        if (n - 1) % a == 0:
            n_count += 1
        
        if N // i != i:
            a = N // i
            n = N
            while n % a == 0:
                n = n // a
            if (n - 1) % a == 0:
                n_count += 1

    i += 1

print(n1_count + n_count)

Measured memory_bytes: 40044
/*{{{*/
#include <bits/stdc++.h>
#ifdef _GLIBCXX_DEBUG
int c_;
#define cout (c_?cerr:cout)
#define dbg(...) {if(!c_)cerr<<"\033[96;1m";++c_;\
__VA_ARGS__;--c_;if(!c_)cerr<<"\033[0m";}
#else
#define dbg(...)
#endif
#define st first
#define nd second
#define flg() __LINE__, __PRETTY_FUNCTION__
#define dprt(...) dbg(prt(__VA_ARGS__))
#define drprt(...) dbg(rprt(__VA_ARGS__))
#define dmp(...) dprt(#__VA_ARGS__,'=',__VA_ARGS__)
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
#define rdmp(...) dbg(cerr<<#__VA_ARGS__<<": ";rprt(__VA_ARGS__))
using namespace std; using ll = long long;template< typename t > using V = vector< t >;
template< typename t > void prt(const t& a){cout<<a<<'\n';}template
< typename t, typename... v >void prt(const t& a, v&&... b){cout<<a<<' ';prt(b...);}
template< typename t > void rprt(t a, const t& b){while(a!=b)cout<<(*a++)<<' ';cout << '\n';}
/*}}}*/

int n;
int tb[100];

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

    cin >> n;

    for (int i = 0; i < n; ++i)
        cin >> tb[i];

    int res = 0;
    int pt = 101;
    for (int i = 1; i < n; ++i)
        if (tb[i] == tb[i - 1])
            ++res, tb[i] = pt++;

    prt(res);

}

Measured memory_bytes: 892
import sys


def main() -> None:
    x, y = [int(next_str()) for _ in range(2)]

    cnt = 0
    if abs(x) < abs(y):
        cnt += x < 0
        cnt += y < 0
    elif abs(x) > abs(y):
        cnt += x > 0
        cnt += y > 0
    else:
        cnt += x != y

    print(abs(abs(x) - abs(y)) + cnt)


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#選択ソート
n=int(input())
a=[int(i) for i in input().split()]
k=0
for i in range(n):
    l=0
    min=i
    for j in range(n-i-1):
        if a[i+j+1]<a[min]:
            min=i+j+1
            l=1
    a[i],a[min]=a[min],a[i]
    if l==1:
        k+=1

print(" ".join(list(map(str,a))))
print(k)



Measured memory_bytes: 5608
#include <cstdio>
#include <algorithm>
using std::sort;
int main(void)
{
    int i,N,ptr,currCount,lastNum,res=0;
    int *a;
    scanf("%d",&N);
    a=new int [N];
    for(i=0;i<N;i++)
        scanf("%d",a+i);
    sort(a,a+N);
    ptr=0;
    while(ptr<N)
    {
        lastNum=a[ptr];
        currCount=0;
        while(ptr<N && a[ptr]==lastNum)
        {
            currCount++;
            ptr++;
        }
        res+= currCount%2;
    }
    printf("%d\n",res);
    delete [] a;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

ll a[maxn];

void solve() {
	ll n,x,mi=INF,id=INF; cin >> x >> n;
	set<ll> s;
	rep(i,0,n) {
		cin >> a[i];
		s.insert(a[i]);
	}
	if (n==0) {cout << x; return;}
	per(i,300,-1) {
		if (s.count(i)) continue;
		if (abs(x-i) <= mi) mi = abs(x-i), id = min(id,(ll)i);
	}
	cout << id;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	//int t; cin >> t; while(t--)
	solve();

	return 0;
}

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int n = sc.nextInt();
			int w = sc.nextInt();
			if(n == 0 && w == 0)break;
			else calc(n, w);
			
		}
	}
	public void calc(int n, int w){
		int[] vs = new int[100 / w + 1];
		double maxW = 0;
		double maxH = 0;
		for(int i = 0; i < n; i++){
			int v = sc.nextInt();
			vs[v / w] += 1;
			if(maxW < v / w) maxW = v/w;
			if(vs[v / w] > maxH) maxH = vs[v / w];
		}
		double sum = 0;
		for(int i = 0; i < maxW + 1; i++){
			sum += ((maxW - i) / maxW) * (vs[i] / maxH);
		}
		System.out.println(sum + 0.01);
	}

	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23600
d, g = map(int, input().split())
s_list = [[0 for _ in range(2)] for __ in range(d)]
for i in range(d):
    s_list[i][0], s_list[i][1] = map(int, input().split())
ans = 100000
for i in range(1 << d):
    ansi = 0
    m_res = 0
    total_score = 0
    for j in range(d):
        if(i & (1 << j)):
            ansi += s_list[j][0]
            total_score += s_list[j][0]*(j+1)*100 + s_list[j][1]
        else:
            m_res = j
    if(total_score < g):
        q_s = 100*(m_res+1)
        di = g - total_score
        num = (di + q_s - 1) // q_s
        if(num > s_list[m_res][0]):
            continue
        ansi += num
    ans = min(ansi, ans)
print(ans)


Measured memory_bytes: 3444
object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val borders = List.tabulate(m){_ ⇒ readInt - 1}
  val goal = borders.foldLeft((1 until n).reduce{(a, b) ⇒ a * 10 + b}){(a, b) ⇒ a.swapToNext(b)}
  val piles = Array.tabulate(m){_ ⇒ Array.tabulate(n){_ ⇒ false}}

  println(
    borders.permutations.map(countHeights).min
  )

  def countHeights(border: List[Int]): Int = {
    def sub(border: List[Int], depth: Int, result: Int): Int = {
      border match {
        case Nil if result == goal ⇒
          depth + 1
        case Nil ⇒ m
        case h :: _ if piles(depth)(h) || piles(depth)(h + 1) || (h > 0 && piles(depth)(h - 1)) ⇒ sub(border, depth + 1, result)
        case h :: t ⇒
          piles(depth)(h) = true
          val res = sub(t, depth, result.swapToNext(h))
          piles(depth)(h) = false
          res
      }
    }
    sub(border, 0, (1 until n).reduce{(a, b) ⇒ a * 10 + b})
  }
  object WrappedInt{
    private val digit = Array(1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000)
  }
  implicit class WrappedInt(val value: Int) extends AnyVal {
    import WrappedInt._
    def swapToNext(position: Int): Int = (takeNth(position) - takeNth(position + 1)) * digit(position) * 9 + value
    private[this] def takeNth(position: Int): Int = value / digit(position) % 10
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 48356
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 210 };
const int oo { 2000000010 };

int state[MAX][MAX][MAX];

int dp(int A, int B, int C)
{
    if (A == B and B == C)
        return 0;

    if (A >= MAX or B >= MAX or C >= MAX)
        return oo;

    if (state[A][B][C] != -1)
        return state[A][B][C];

    int res = dp(A + 1, B + 1, C) + 1;
    res = min(res, dp(A, B + 1, C + 1) + 1);
    res = min(res, dp(A + 1, B, C + 1) + 1);
    res = min(res, dp(A + 2, B, C) + 1);
    res = min(res, dp(A, B + 2, C) + 1);
    res = min(res, dp(A, B, C + 2) + 1);

    state[A][B][C] = res;

    return res;
}

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

    int A, B, C;
    cin >> A >> B >> C;

    int M = min( {A, B, C} );

    A -= M;
    B -= M;
    C -= M;

    memset(state, -1, sizeof state);

    cout << dp(A, B, C) << '\n';

    return 0;
}


Measured memory_bytes: 36480
n=int(input())
a=[]
b=[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
m=0
for i in range(n-1,-1,-1):
  a[i]+=m
  if a[i]%b[i]:m+=b[i]-a[i]%b[i]
print(m)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    string S;
    cin >> S;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string A;
        int b, c;
        cin >> A >> b >> c;
        if (A == "replace") {
            string R;
            cin >> R;
            S = S.substr(0, b) + R + S.substr(c + 1, S.length() - c);
        } else if (A == "reverse") {
            reverse(S.begin() + b, S.begin() + c + 1);
        } else cout << S.substr(b, c - b + 1) << endl;
        // cout << S << endl;
    }
}



Measured memory_bytes: 3196
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
// forループ関係
#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--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
const int MOD = 1000000007;
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
#define P pair<ll, ll>
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
void add(long long &a, long long b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}
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;
}

int main() {

    ll n, k;
    cin >> n >> k;

    if (n > k) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}



Measured memory_bytes: 3100
#include<stdio.h>
int a[200000]={0};
int main()
{
	int n,i,m=1,s=0,sum=0,k=0,flag=0,p=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	{
		if(a[i-1]==m)
		{
			s=i-s;
			m++;
			sum=sum+s-1;
			s=i;
			k++;
			flag=0;
			p=1;
		}
		else if(p==1)
			flag=i;
	}
	if(flag!=0)
		sum=sum+flag-s;
	if(sum!=0)
		printf("%d",sum);
	else if(k==n)
		printf("0");
	else 
		printf("-1");
}

Measured memory_bytes: 896
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            for (int i = 0; i <= n; i += 4) {
                for (int j = 0; j <= n; j += 7) {
                    if (i + j == n) {
                        out.println("Yes");
                        return;
                    }
                }
            }
            out.println("No");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



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

bool solve(){
  pair<int, int> D[6];
  for ( int i = 0; i < 6; i++ ) {
    cin >> D[i].first >> D[i].second;
    if ( D[i].first > D[i].second) swap(D[i].first, D[i].second);
  }
  sort(D, D+6);
  pair<int, int> F[3];
  for ( int i = 0; i < 6; i+=2){
    if ( D[i] == D[i+1] ) D[i/2] = D[i];
    else return false;
  }

  return D[0].first == D[1].first && D[0].second == D[2].first && D[1].second == D[2].second;
}

main(){
  if ( solve() ) cout << "yes" << endl;
  else cout << "no" << endl;
}



Measured memory_bytes: 3112
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<int> cnt(N);
  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    cnt[a[i]]++, cnt[b[i]]++;
  }
  bool ok = true;
  rep(i, N) {
    if (cnt[i] % 2)
      ok = false;
  }

  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}

Measured memory_bytes: 2560
const main = (): void => {
  const n = getParams();
  console.log(solve(n));
};

const getParams = (): number =>
  Number(getStdin());

const getStdin = (): string =>
  require('fs').readFileSync('/dev/stdin', 'utf8').trim();

const solve = (n: number): number =>
  Math.ceil(n / 111) * 111;

main();


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int t, x; cin >> t >> x;
    cout << 1.0*t/x;
}



Measured memory_bytes: 256
s = input()
t = input()
s = sorted(s)
t = sorted(t, reverse=True)
u = min(len(s), len(t))
if s == t:
    print("No")
    exit()
if len(s) < len(t) and s == t[:len(s)]:
    print("Yes")
    exit()
else:
    for i in range(u):
        if s[i] > t[i]:
            print("No")
            exit()
        elif s[i] == t[i]:
            pass
        else:
            print("Yes")
            exit()
    print("No")

Measured memory_bytes: 38256
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int m=Integer.parseInt(scan.next());
		int[] x=new int [m];
		for (int i=0;i<m;++i) {
			x[i]=Integer.parseInt(scan.next());
		}
		Arrays.parallelSort(x);
		int[] diff=new int[m-1];
		for (int i=0;i<m-1;++i) {
			diff[i]=x[i+1]-x[i];
		}
		Arrays.parallelSort(diff);
		int sum=0;
		for (int i=0;i<m-n;++i) {
			sum+=diff[i];
		}
		System.out.print(sum);
				
	}
}
//end


Measured memory_bytes: 46052
#include <iostream>

using namespace std ;

int main()
{

int x,y;
cin>>x>>y;
if(x+y>=x-y && x+y>=x*y)
    cout<<x+y;
else if(x-y>=x+y && x-y>=x*y)
     cout<<x-y;
else cout<<x*y;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int res = 0, l = 0, r = s.length() - 1;
        while (l <= r) {
            if (s.charAt(l) == s.charAt(r))    {
                l++;
                r--;
            } else if (s.charAt(l) != 'x' && s.charAt(r) != 'x')   {
                System.out.println(-1);
                return;
            } else if (s.charAt(l) == 'x')  {
                l++;
                res++;
            } else  {
                r--;
                res++;
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 24324
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct UnionFind {vector<int> par, cnt;
    UnionFind(int NV) { par.clear(); cnt.resize(NV, 1); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, cnt.size()) cnt[i] = 1; rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) {x = operator[](x); y = operator[](y);
        if (x != y) par[x] = y, cnt[y] += cnt[x];}};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




typedef long long ll;
int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    vector<pair<int, int>> va, vb;
    rep(i, 0, N) {
        int x, y; cin >> x >> y;
        va.push_back({ x, i });
        vb.push_back({ y, i });
    }

    vector<tuple<int, int, int>> edges;
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    rep(i, 0, N - 1) {
        edges.push_back(make_tuple( va[i + 1].first - va[i].first, va[i].second, va[i + 1].second ));
        edges.push_back(make_tuple( vb[i + 1].first - vb[i].first, vb[i].second, vb[i + 1].second));
    }
    sort(edges.begin(), edges.end());
    
    UnionFind uf(N);
    ll ans = 0;
    for (auto p : edges) {
        int x, y, c;
        tie(c, x, y) = p;

        //printf("%d - %d : %d\n", x, y, c);

        if (uf[x] != uf[y]) {
            uf(x, y);
            ans += c;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
#define NIL -1

vector<vector<int>> s(100, vector<int>(100));
vector<vector<int>> d(100, vector<int>(100, NIL));

int bfs(int y, int x, int h, int w){
    queue<pair<int, int>> q;
    q.push(make_pair(y, x));
    pair<int, int> u;
    while(!q.empty()){
        u = q.front();
        int old_y = u.first;
        int old_x = u.second;
        q.pop();
        int new_y;
        int new_x;
        for(int i=-1; i<=1; i=i+2){
            new_x=old_x+i;
            new_y=old_y;
            if(new_x>=0 && new_x<w){
                if(d[new_y][new_x]==NIL && s[new_y][new_x]!=1){
                    d[new_y][new_x]=d[old_y][old_x]+1;
                    q.push(make_pair(new_y, new_x));
                    //cout << new_y << " " << new_x << " " << old_y << " " << old_x << endl;
                }
            }
        }
        for(int i=-1; i<=1; i=i+2){
            new_x=old_x;
            new_y=old_y+i;
            if(new_y>=0 && new_y<h){
                if(d[new_y][new_x]==NIL && s[new_y][new_x]!=1){
                    d[new_y][new_x]=d[old_y][old_x]+1;
                    q.push(make_pair(new_y, new_x));
                    //cout << new_y << " " << new_x << " " << old_y << " " << old_x << endl;
                }
            }
        }
    }
}

int main() {
    int h;
    int w;
    string tmp_s;
    cin >> h >> w;

    int num_blk=0;
    for(int i=0; i<h; i++){
        cin >> tmp_s;
        for(int j=0; j<w; j++){
            if(tmp_s[j]=='.'){
                s[i][j]=0;
            }else{
                s[i][j]=1;
                num_blk++;
            }
        }
    }

    if(s[0][0]==1 || s[h-1][w-1]==1){
        cout << -1 << endl;
    }else{
        d[0][0]=1;
        bfs(0, 0, h, w);
        if(d[h-1][w-1]!=NIL){
            LL ans=h*w-num_blk-d[h-1][w-1];
            cout << ans << endl;
            //cout << h*w << " " << num_blk << " " << d[h-1][w-1] << endl;
        }else{
            cout << -1 << endl;
        }
    }

    //for(int i=0; i<h; i++){
    //    for(int j=0; j<w; j++){
    //        cout << d[i][j] << " ";
    //    }
    //    cout << endl;
    //}

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cstdlib>
#include <map>

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

using namespace std;

int main()
{
	int a[13];
	int n;
	while(cin >> n && n)
	{
		memset(a,0,sizeof(a));
		vector<int> res;
		rep(i,n) 
		{
			cin >> a[i];
			res.push_back(a[i]);
		}
		
		int count = 0;
		while(true)
		{
			map<int,int> m;

			rep(i,n)
			{
				m[a[i]]++;
			}

			rep(i,n)
			{
				a[i] = m[a[i]];
			}

			bool flag = true;
			rep(i,n)
			{
				if(res[i] != a[i])
				{
					flag = false;
				}
			}

			if(flag)
			{
				cout << count << endl;
				rep(i,n)
				{
					if(i == n-1) cout << a[i] << endl;
					else cout << a[i] << " ";
				}
				break;
			}
			else
			{
				rep(i,n)
				{
					res[i] = a[i];
				}
				count++;
			}
		}
	}
	return 0;
}

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

int N;
int A[210];

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

    int res = 0;

    while (true)
    {
        bool exist_odd = false;
        for (int i = 0; i < N; ++i)
        {
            if (A[i] % 2 != 0)
                exist_odd = true;
        }

        if (exist_odd)
            break;

        for (int i = 0; i < N; ++i)
        {
            A[i] /= 2;
        }
        ++res;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace abc061_c
{
    class Program
    {
        static void Main()
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] a = new long[100000];
            for (int i = 0; i < x[0]; i++)
            {
                int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[b[0] - 1] += b[1];
            }
            int ret = 0;
            x[1]--;
            while (x[1] > 0)
            {
                x[1] -= a[ret];
                ret++;
            }
            if (x[1] != 0) ret--;
            Console.WriteLine(ret + 1);
            //Console.ReadLine();
        }
    }
}

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

int main()
{
    long long K,X;
    cin >> K >> X;

    rep(i,2*K) {
        if (i==2*K-1) {
            break;
        } else {
            cout << X-K+i+1 << " ";
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.14159265358979323846265
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
int main()
{
	long long L,R,ans=2019;
	cin>>L>>R;
	int xL=L/2019,xR=R/2019;
	if(L%2019==0||xL!=xR)
	{
		cout<<0<<endl;
		return 0;
	}
	for(long long i=L;i<=R;i++)
		for(long long j=L;j<i;j++)
			ans=min(ans,i*j%2019LL);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256