akhauriyash/Code-Regression huggingface dataset:
import sys

n = int(input())
a = list(map(int,input().split()))
m = 0
b = [0]*n
ans = []

for i in reversed(range(n)):
	sum_a = 0
	for j in range(i,n,i+1):
		sum_a += b[j]
	if sum_a % 2 == a[i]:
		b[i] = 0
	else:
		b[i] = 1

for i in range(n):
	if b[i] == 1:
		m += 1
		ans.append(i+1)

if not ans:
	print("0")
else:
	print(m)
	for i,x in enumerate(ans):
		if i == 0:
			sys.stdout.write(str(x))
		else:
			sys.stdout.write(" ")
			sys.stdout.write(str(x))

Measured memory_bytes: 67304
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define MAX_Q 55

int N, M, Q;
vector<int> a(MAX_Q), b(MAX_Q), c(MAX_Q), d(MAX_Q);
int ans;

void dfs(int cur, int num, vector<int> &A) {
  if (cur >= N) {
    int sum = 0;
    FOR(i, Q) {
      if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    ans = max(ans, sum);
    return;
  }
  A[cur] = num;
  for (int i = 0; num + i <= M; i++) {
    dfs(cur + 1, num + i, A);
  }

  return;
}

int main() {
  cin >> N >> M >> Q;
  FOR(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }

  vector<int> A(N + 1, 0);

  for (int i = 1; i <= N; i++) dfs(0, i, A);

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

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

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  ll a=0;
  ll goukei=0;
  rep(i,n){
    cin >> v[i];
    goukei+=v[i];
    if(i%2==1){
      a+=v[i];
    }
  }
  vector<ll> ans(n);
  ans[0]=goukei-(a*2);
  cout << ans[0] << " ";
  for(int i=1;i<n;i++){
    ans[i]=2*v[i-1]-ans[i-1];
    cout << ans[i] << " ";
  }
}


Measured memory_bytes: 2816
#include <cstdio>
#include <cmath>

int main(void){
  long long a, b, c;
  scanf("%ld %ld %ld", &a, &b, &c);
  
  if(sqrtl(4*a*b) < c-a-b){
    printf("Yes");
  }else{
    printf("No");
  }
  
  
  return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int x, y;
  cin >> x >> y;
  if (x % 500 <= y) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#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=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(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;

//自作関数 a^n mod MODを求める
int m_pow(int a, int n){
  if(n == 0) return 1;
  if(n % 2 == 0){
    int t = m_pow(a, n / 2);
    return t * t % MOD;
  }
  return a * m_pow(a, n - 1) % MOD;
}

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

  int n,a,b;
 
  cin >> n >> a >> b;
 
  cout << (n % (a + b) > a ? a : n % (a + b)) + (n / (a + b)) * a;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int ans[10000010];
bool isPrime[10000010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //set_prime();
    int N; cin >> N;
    rep(i, N + 1) ans[i] = 1;
    REP(i, 2, N) {
        //if(!isPrime[i]) continue;
        int j = 1;
        while(i * j <= N) {
            ans[i * j] += 1;
            j++;
        }
    }
    int sum = 0;
    REP(i, 1, N) sum += i * ans[i];
    cout << sum << endl;

    return 0;
}


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

int main() {
  while (true) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;

    if (m == 0) {
      break;
    }
    
    vector<int> P(m);
    for (int i = 0; i < m; i++) {
      cin >> P[i];
    }

    sort(P.begin(), P.end());

    int maxgap = 0;
    int maxidx = 0;
    for (int i = m - nmax; i <= m - nmin; i++) {
      int gap = P[i] - P[i - 1];
      if (gap > maxgap) {
	maxgap = gap;
	maxidx = i;
      }
    }

    cout << m - maxidx << endl;
  }
}

Measured memory_bytes: 3072
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(long[]);
    sort!"a > b"(as);
    long r;
    foreach (i; 0..N*2) if (i%2 == 1) r += as[i];
    writeln(r);
}

Measured memory_bytes: 15076
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
X = list(map(int, input().split()))
d = defaultdict(list)

for i in range(N):
    d[X[i]%M].append(i)

ans = len(d[0])//2

if M%2==0:
    ans += len(d[M//2])//2

for m in range(1, (M+1)//2):
    if len(d[m])>len(d[M-m]):
        S, T = d[m], d[M-m]
    else:
        S, T = d[M-m], d[m]
    
    cnt = Counter([X[i] for i in S])
    ans += min(sum(v//2 for v in cnt.values()), (len(S)-len(T))//2)+len(T)

print(ans)

Measured memory_bytes: 87260
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int n;

void solve(){
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  int x = a[n - 1];
  int j = -1;
  for(int i = 0; i < n - 1; i++){
    if(a[i] <= x){
      j++;
      int t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  j++;
  int t = a[j];
  a[j] = x;
  a[n - 1] = t;

  for(int i = 0; i < n - 1; i++){
    if(i == j) cout << "[" << a[i] << "] ";
    else cout << a[i] << " ";
  }
  if(j == n - 1) cout << "[" << a[n - 1] << "]\n";
  else cout << a[n - 1] << endl;

  return;
}

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



Measured memory_bytes: 3392
import java.io.*;

/**
 * Created by Ayushi on 19 Apr 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long n = Integer.parseInt(br.readLine());
        br.close();
        double ans = n*2;
        ans = ans * Math.PI;
        System.out.println(ans);
    }
}


Measured memory_bytes: 33264
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i,j,k;


int main(){
    ll N;
    cin>>N;
    cout<<2*N*M_PI<<endl;
}


Measured memory_bytes: 3744
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
  if(b==0) return a;
  else  gcd(b,a%b);
}
int main()
{
  long long int a,b;
  cin>>a>>b;
 long long s=a*b;
  int l;
  if(a<b) l=gcd(b,a);
  else l=gcd(a,b);
  s=s/l;
  cout<<s;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;

int main()
{
    cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i % 3 == 0 || i % 5 == 0)
        {
            continue;
        }
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
//11
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(long long h,w,l;cin>>h>>w>>l,h|w|l;){
    bool s[102][102]={};
    int x,y,d;
    string ds="NESW";
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	char c;
	cin>>c;
	s[i][j]=c!='#';
	if(c!='#'&&c!='.'){
	  x=j;
	  y=i;
	  d=ds.find(c);
	}
      }
    }
    long long p[102][102][4];
    fill(p[0][0],p[102][0],-1);
    while(l){
      int dx[]={0,1,0,-1};
      int dy[]={-1,0,1,0};
      for(;;){
	if(p[y][x][d]!=-1){
	  long long m=p[y][x][d]-l;
	  if(l>m){
	    l=l%m+m;
	  }
	}
	p[y][x][d]=l;
	if(s[y+dy[d]][x+dx[d]])break;
	d=(d+1)%4;
      }
      y+=dy[d];
      x+=dx[d];
      l--;
    }
  end:
    cout<<y<<' '<<x<<' '<<ds[d]<<endl;
  }
  return 0;
}

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

public class Main implements Runnable {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        int n = in.nextInt();
        int[] p = new int[n];
        int[] pos = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt() - 1;
            pos[p[i]] = i;
        }
        boolean[] adj = new boolean[n];
        for (int i = 0; i < n - 1; i++) {
            adj[i] = pos[i] < pos[i + 1];
        }
        int max = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (adj[i]) cnt++;
            else cnt = 0;
            max = Math.max(max, cnt + 1);
        }
        System.out.println(n - max);
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException {super(System.out);}
}
class ContestScanner implements Closeable {
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 43616
import sys
sys.setrecursionlimit(200000)
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])

Measured memory_bytes: 141092
import statistics
N = int(input())
AB = [[a,b] for a,b in (map(int,input().split()) for _ in range(N))]

A,B = zip(*AB)
A = list(A)
B = list(B)
A.sort()
B.sort()
medianA = statistics.median(A)
medianB = statistics.median(B)
if N%2 == 0:
    ans = (medianB-medianA)/0.5+1
else:
    ans = medianB-medianA+1
print(int(ans))

Measured memory_bytes: 138136
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int x[6];
  int ans;
  REP1(i, 5) {
	cin >> x[i];
	if (x[i] == 0) {
		ans = i;
	  }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_C
#include <iostream>

using namespace std;

int main(){
  int one[3][10] = {0};
  int two[3][10] = {0};
  int three[3][10] = {0};
  int four[3][10] = {0};
  int n;
  //cout << one[2][5] << endl;

  cin >> n;
  for(int i = 0; i < n; i++){
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    if(b == 1) one[f - 1][r - 1] += v;
    if(b == 2) two[f - 1][r - 1] += v;
    if(b == 3) three[f - 1][r - 1] += v;
    if(b == 4) four[f - 1][r - 1] += v;
  }


  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 10; j++){
      cout << " " << one[i][j];
    }
    cout << endl;
  }
  //cout << " " << endl;
  cout << "####################" << endl;

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 10; j++){
      cout << " " << two[i][j];
    }
    cout << endl;
  }
  //cout << " " << endl;
  cout << "####################" << endl;

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 10; j++){
      cout << " " << three[i][j];
    }
    cout << endl;
  }
  //cout << " " << endl;
  cout << "####################" << endl;

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 10; j++){
      cout << " " << four[i][j];
    }
    cout << endl;
  }
  //cout << " " << endl;
  //cout << "####################" << endl;

}



Measured memory_bytes: 3120
#include<cstdio>
int n,m,cnt[101000];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){int a,b;scanf("%d%d",&a,&b);cnt[a]++;cnt[b]++;}
	for(int i=1;i<=n;i++)if(cnt[i]%2!=0)return 0*puts("NO");
	puts("YES");return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 200100
using namespace std;
int n,m,len;
int cnt[N];
int ys[N];
int to[N<<1],nex[N<<1],beg[N<<1];
inline void Add(int a,int b){
	nex[++len]=beg[a],beg[a]=len,to[len]=b;
	nex[++len]=beg[b],beg[b]=len,to[len]=a;
}
void dfs(int p,int fa,int w){
	ys[p]=w;cnt[w]++;
	for(int i=beg[p];i;i=nex[i]){
		if(to[i]==fa) continue;
		if(!ys[to[i]]) dfs(to[i],p,w^1);
		else if(ys[to[i]]==ys[p]){
			printf("%lld\n",1LL*n*(n-1)/2-m);
			exit(0);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		Add(a,b);
	}
	dfs(1,0,2);
	printf("%lld\n",1LL*cnt[2]*cnt[3]-m);
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int n, k, mark, sz;
	long long int tmp=0, ans=200000000001, cal;
	vector<long long int> v;

	cin>> n >> k;
	v.resize(n);

	for(int i=0;i<n;i++){
		cin>> v[i];
			
		if(0<i) tmp=v[i]*v[i-1];
		if(tmp<0) mark=i;
	}

	if(0<=v[0]){
		cout<< v[k-1] << endl;
		return 0;
	}
	if(v[n-1]<=0){
		cout<< abs(v[n-k]) << endl;
		return 0;
	}
long long int ze=0;
	for(long long int i=max(ze, mark-k);i<=mark;i++){
		if(i+k>n) break;
		//cout<< abs(v[i]) << " " << abs(v[i+k-1]) << endl;
		cal=abs(v[i]*2)+abs(v[i+k-1]);
		ans=min(ans, cal);
		cal=abs(v[i])+abs(v[i+k-1]*2);
		ans=min(ans, cal);
		if(v[i]<0 && v[i+k-1]<0) cal=abs(v[i]);
		ans=min(ans, cal);
		if(v[i]>0 && v[i+k-1]>0) cal=v[i+k-1];
		ans=min(ans, cal);
	}

	cout<< ans << endl;

}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

#define ff first
#define ss second

const int maxn = 2e5;
const int MOD = 998244353;

class Modint {
public:
	long long val;

	Modint (long long _val = 0)
		: val((_val + MOD) % MOD) {}

	Modint operator+ (Modint other) {
		return Modint(val + other.val);
	}

	void operator+= (Modint other) {
		val += other.val;
		val %= MOD;
	}

	Modint operator- () {
		return Modint(MOD - val);
	}

	Modint operator- (Modint other) {
		return Modint(val + MOD - other.val);
	}

	void operator-= (Modint other) {
		val += MOD - other.val;
		val %= MOD;
	}

	Modint operator* (Modint other) {
		return Modint(val * other.val);
	}

	void operator*= (Modint other) {
		val *= other.val;
		val %= MOD;
	}

	bool operator== (Modint other) {
		return val == other.val;
	}

	bool operator!= (Modint other) {
		return val != other.val;
	}
};

Modint exp (Modint a, int k) {
	if (k == 0) {
		return Modint(1);
	} else if (k % 2 == 0) {
		Modint half = exp(a, k / 2);
		return half * half;
	} else {
		return a * exp(a, k - 1);
	}
}

Modint inv (Modint a) {
	return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
	out << p.val;
	return out;
}

vector<Modint> BIT(maxn + 1, 0), dp(maxn + 1, 0);

void update(int ind, Modint inc) {
	while (ind <= maxn) {
		BIT[ind] += inc;
		ind += (ind & (-ind));
	}
}

Modint query(int ind) {
	Modint res = 0;
	while (ind) {
		res += BIT[ind];
		ind -= (ind & (-ind));
	}

	return res;
}

int main() {

	int n, k; cin >> n >> k;
	vector<pair<int, int>> seg(k);
	for (int i = 0; i <= k - 1; i++) cin >> seg[i].ff >> seg[i].ss;

	dp[1] = 1;
	update(1, 1);

	for (int i = 2; i <= n; i++) {
		for (auto p : seg) dp[i] += (query(max(0, i - p.ff)) - query(max(0, i - p.ss - 1)));
		update(i, dp[i]);
	}

	cout << dp[n];

	return 0;
}

Measured memory_bytes: 6292
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    cout << n / 100 + (n / 10) % 10 + n % 10 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int INF=(1<<29);
  queue<int> q1,q2;
  int i,j,x,y,w,h,b[100][100],a[100][100];
  while(1){
    scanf("%d %d\n",&w,&h);
    if(w==0 && h==0){
      break;
    }
    for(i=0;i<=h*2;i++){
      for(j=0;j<=w*2;j++){
        a[i][j]=1,b[i][j]=INF;
      }
    }
    for(i=1;i<=h*2-1;i++){
      if(i%2==1){
        for(j=2;j<=w*2-1;j=j+2){
          scanf("%d",&a[i][j]);
        }
      }
      else{
        for(j=1;j<=w*2-1;j=j+2){
          scanf("%d",&a[i][j]);
        }
      }
      scanf("\n");
    }
    b[1][1]=1;
    q1.push(1),q2.push(1);
    while(!q1.empty()){
      x=q1.front(),y=q2.front();
      q1.pop(),q2.pop();
      if(a[x+1][y]==0 && b[x+2][y]>b[x][y]+1){
        b[x+2][y]=b[x][y]+1;
        q1.push(x+2),q2.push(y);
      }
      if(a[x-1][y]==0 && b[x-2][y]>b[x][y]+1){
        b[x-2][y]=b[x][y]+1;
        q1.push(x-2),q2.push(y);
      }
      if(a[x][y+1]==0 && b[x][y+2]>b[x][y]+1){
        b[x][y+2]=b[x][y]+1;
        q1.push(x),q2.push(y+2);
      }
      if(a[x][y-1]==0 && b[x][y-2]>b[x][y]+1){
        b[x][y-2]=b[x][y]+1;
        q1.push(x),q2.push(y-2);
      }
    }
    if(b[h*2-1][w*2-1]==INF){
      printf("0\n");
      continue;
    }
    printf("%d\n",b[h*2-1][w*2-1]);
  }
  return 0;
}


Measured memory_bytes: 3320
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			int count = 0;
			
			
			for(int i = 1;i<=N;i=i+2) {
				ArrayList<Integer> yaku = enum_div(i);
				if(yaku.size()==8) {
					count++;
				}
					
				}
			
			
			System.out.println(count);
			}
			
			
			
		}
		
		
	
	
	
	
	private static ArrayList<Integer> enum_div(int n){//数字１〜ｎまでの約数を全部Allaylistに詰め込むメソッド
		ArrayList<Integer> ret = new ArrayList<Integer>();
	
		for(int i = 1;i*i<=n;i++) {
			if(n%i==0) {
				ret.add(i);
				if(i*i!=n){
					ret.add(n/i);
				}
			}
		}
		
		//ただここまでだと格納した約数はソートされてない
		
		Collections.sort(ret);//int型、Sting型くらいの格納した奴ならコレクションクラスのソートが使える。
		//ソートしてからcollections.reverseつかえば降順にもできる
	
		return ret;
		
		
		
	}
		

}


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


int main(){
  int n;
  cin >> n;
  vector<int> x(n),y(n),h(n);
  int vi=1;
  for(int i=0;i<n;++i){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]>0) vi=i;
  }

  long long cx,cy,ch;
  cx=-1;
  cy=-1;
  ch=-1;
  for(int i=0;i<=100;++i){
    for(int j=0;j<=100;++j){
      long long nh=h[vi]+abs(i-x[vi])+abs(j-y[vi]);
      bool ok=true;
      for(int k=0;k<n;++k){
        if(h[k]>0 && nh-h[k]!=abs(i-x[k])+abs(j-y[k])) ok=false;
        if(h[k]==0 && nh>abs(i-x[k])+abs(j-y[k])) ok=false;
      }
      if(ok){
        cx=i;
        cy=j;
        ch=nh;
      }
    }
  }
  cout << cx << " " << cy << " " << ch << endl;
  return 0;
}


Measured memory_bytes: 3640
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
//#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
     
using namespace std;
      
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<ll> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvi;
typedef vector<char> vc;
      
const ll INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
//static const int maxn = 2e5 + 228;;
const ld eps = 1e-7;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);
     
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef DEBUG
//      freopen("haybales.in", "r", stdin);
//      freopen("haybales.out", "w", stdout);
    #endif
}

void solve(){
	int n;
	cin >> n;
	map<pii, int> cnt;
       	for(int i=1; i<=n; i++){
		string s = to_string(i);
		cnt[make_pair(s[0], s.back())]++;
	}	
	int ans = 0;
	for(char c='1'; c<='9'; c++){
		for(char c2='1'; c2<='9'; c2++){
			ans += cnt[make_pair(c, c2)] * cnt[make_pair(c2, c)];	
		}
	}
	cout << ans << endl;
}

signed main(){
        fast_io();
	srand(time(NULL));
//	cout << fixed << setprecision(12);
	int q = 1;
//	cin >> q;
	while(q--)
		solve();
     
}





Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;cin>>s;
  rep(i,26) {
    char c = 'a'+i;bool f=false;
    rep(j,s.size()) {
      if (s[j]==c) {f=true;break;}
    }
    if (f) continue;
    else {
      cout<<c;return 0;
    }
  }
  cout << "None";
}

Measured memory_bytes: 512
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    k, q = map(int, input().split())
    D = list(map(int, input().split()))

    for _ in range(q):
        n, x, m = map(int, input().split())
        b = x
        for i in range(k):
            s = (n - 2 - i) // k + 1
            t = D[i] % m
            if t == 0:
                t = m
            b += s * t
        print(n - 1 - (b // m - x // m))
resolve()

Measured memory_bytes: 74952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  bool b=true;;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==1) b=false;
  }
  if(b) cout<<"second"<<endl;
  else cout<<"first"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin >> n;
    ll l = 0,r=n;
    while(l+1!=r){
        ll m = (l+r)/2;
        if(6*(m/2+m%2)+5*(m/2)>=n)r=m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;

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

int main() {
    ll N,M;
    string s,t;
    cin>>N>>M>>s>>t;

    ll L=(ll)(N*M/gcd(N,M));
    ll spans=L/N,spant=L/M;
    for(ll i=0;i<N;i++){
        if(spans*i%spant==0){
            if(s[i]!=t[spans*i/spant]){
                cout<<-1<<endl;
                //cout<<i<<endl;
                return 0;
            }
        }
    }
    cout<<L<<endl;
    return 0;
}



Measured memory_bytes: 512
m_count = 0
a_count = 0
r_count = 0
c_count = 0
h_count = 0

n = input()

for i in range(n):
    name = raw_input()
    if name[0] == 'M':
        m_count += 1
    elif name[0] == 'A':
        a_count += 1
    elif name[0] == 'R':
        r_count += 1
    elif name[0] == 'C':
        c_count += 1
    elif name[0] == 'H':
        h_count += 1

count = 0
count += m_count * a_count * r_count
count += m_count * r_count * c_count
count += m_count * c_count * h_count
count += a_count * r_count * c_count
count += a_count * c_count * h_count
count += r_count * c_count * h_count
count += m_count * a_count * c_count
count += m_count * a_count * h_count
count += m_count * r_count * h_count
count += a_count * r_count * h_count

print count


Measured memory_bytes: 5764
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(1, n + 1):
        h = n // i
        ans += i * ((h * (h + 1)) // 2)
    print(ans)
    return




n = RN()
solve()


Measured memory_bytes: 85536
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);
ll bur(ll N, ll X);
bool IsPrime(int num);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll L = 0;
	ll P = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	//ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S[50],T[50],U[52];
	ll count = 0;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 1;
	ll dist1 = 0;
	ll dist2 = 0;
	ll now = 0;
	int tmax = 0;
	int tmax2 = 0;
	//int flag = 0;
	char temp,head;
	//int is = 0;
	bool flag = false;
	
	//char p;

	ll all = 0;
	ll niku = 0;
	ll state = 2;
	bool down = true;
	

	//cin >> S;
	
	
	
	
	//cin >>N;
	vector<int> tr(3);
	
	rep(i, 0, 3) {
		cin >> tr[i];
	}

	sort(tr.begin(), tr.end());

	if(tr[0] + tr[1] == tr[2])
	cout << "Yes" << endl;
	else
		cout << "No" << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll bur(ll N,ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

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

int main() {
	int h,i,j,k,s;
	cin >> k >> s;
	for(h=0;h<=k;h++){
		for(i=0;i<=k-h;i++){
			for(j=0;j<=k-h-i;j++){
				if(h*10000+i*5000+j*1000==s&&h+i+j==k){
					cout << h << " " << i << " " << j << "\n";
				return 0;
				}
			}
		}
	}

		cout << "-1 -1 -1" << "\n";

}


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

string join_vector(std::vector<int> data)
{
  ostringstream buf;
  auto delimiter = " ";
  for (auto i = data.begin(); i != data.end(); i++)
  {
    buf << *i;
    if (std::distance(i, data.end()) > 1)
    {
      buf << delimiter;
    }
  }

  return buf.str();
}

void print_vector(std::vector<int> data)
{
  cout << join_vector(data) << endl;
}

tuple<vector<int>, int> selection_sort(vector<int> a, int n)
{
  auto count = 0;
  for (auto i = 0; i < n; i++)
  {
    auto minj = i;
    for (auto j = i; j < n; j++)
    {
      if (a.at(minj) > a.at(j))
      {
        minj = j;
      }
    }

    if (minj != i)
    {
      swap(a[i], a[minj]);
      count++;
    }
  }

  return make_tuple(a, count);
}

int main()
{
  int n;
  auto a = std::vector<int>{};

  cin >> n;
  for (auto i = 0; i < n; i++)
  {
    int number;
    cin >> number;
    a.push_back(number);
  }

  auto result = selection_sort(a, n);
  print_vector(std::get<0>(result));
  cout << std::get<1>(result) << endl;

  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int n, m, q;
vector<int> g[100010];
int a[100010];
int md[100010] = {};
void f(int s, int d, int c) {
  if (!a[s]) a[s] = c;
  if (d <= md[s]) return;
  md[s] = d;
  for (int y : g[s]) f(y, d - 1, c);
}

int u[100010], d[100010], c[100010];
int main() {
  scanf("%d%d", &n, &m);
  REP(i, m) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].PB(v);
    g[v].PB(u);
  }
  scanf("%d", &q);
  REP(i, q) {
    scanf("%d%d%d", &u[i], &d[i], &c[i]);
  }
  for (int i = q - 1; i >= 0; --i)
    f(u[i], d[i], c[i]);
  REPE(i, 1, n) printf("%d\n", a[i]);
  return 0;
}



Measured memory_bytes: 8440
#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 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];
    
    vector<int> e(n);
    REP(i, n) e[i] = 0;
    REP(i, m) {
        e[a[i]-1]++;
        e[b[i]-1]++;
    }
    REP(i, n) cout << e[i] << endl;

    return 0;
}


Measured memory_bytes: 256
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec dudu = function
    | Nil -> exit 1
    | Node (x, Nil, _) -> x
    | Node (_, l, _) -> dudu l
  and wa = function
    | Nil -> exit 1
    | Node (_, Nil, r) -> r
    | Node (x, l, r) -> Node (x, wa l, r)
  and doit = function
    | Nil -> exit 1
    | Node (y, l, r) when x = y ->
      if l = Nil then r
      else if r = Nil then l
      else Node (dudu r, l, wa r)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then
      match split_on_char ' ' (read_line ()) with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | ["find"; n] -> print_endline (if find (int_of_string n) t then "yes" else "no"); read (i + 1) t
      | ["delete"; n] -> read (i + 1) (delete (int_of_string n) t)
      | _ -> print t; read (i + 1) t in
  read 0 (create ())

Measured memory_bytes: 27184
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
  input! {
    k: usize,
    s: String
  };

  if k >= s.len() {
    println!("{}", s);
  } else {
    println!("{}{}", &s[0..k], "...");
  }
}


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

#define MAX_N 4001

int main(){
  int n;
  unsigned long long ID, price, figure, man[MAX_N], id[MAX_N];

  while(cin >> n, n){
    memset(man, 0, sizeof(man));
    memset(id, 0, sizeof(id));

    for(int i = 1 ; i <= n ; i++){
      cin >> ID >> price >> figure;
      man[ID] += price * figure;
      id[i] = ID;
    }

    bool flag[MAX_N], f = false;
    memset(flag, false, sizeof(flag));
    
    for(int i = 1 ; i <= n ; i++){
      if(man[id[i]] >= 1000000 && flag[id[i]] == false){
	cout << id[i] << endl;
	flag[id[i]] = true;
	f = true;
      }
    }
    if(f == false) cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
  int a,b;
  int i;
  bool flg=true;
  string s;
  cin >> a>>b;
  cin>>s;
  i=0;
  for(char& c:s){
    if(i<a){
      if(c<'0'||c>'9'){
        flg=false;
        break;
      }
    }else if(i>a){
      if(c<'0'||c>'9'){
        flg=false;
        break;
      }
    }else{
      if(c!='-'){
        flg=false;
        break;
      }
    }
    i++;
  }
  if(flg)cout << "Yes" <<endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807


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

rep(i, n)
{
  ll a,b,ans=0;
	cin >> a>>b;
	if(a*b==1){cout << 0 << endl;continue;}
	if(a<=b)swap(a,b);
	ans+=(ll)sqrt(a*b);
	if((ll)sqrt(a*b)*(ll)sqrt(a*b)==a*b){ans--;}
	//cout << ans<<" ";

	ll an=((a*b)/ans);
	if(an*ans==a*b)an--;

	if(an==b)an--;
	if((an-1)*(ans+1)>=a*b)an--;

	an--;
	if(an>=b)an--;
	ans+=an;

	//cout << an <<" ";
	cout << ans << endl;
}


return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
int main(){
	const int max_number = 20;
	const int min_number = 0;
	int N;
	
	while(std::cin >> N){
		//JOI[N][max_number + 1]
		std::vector<std::vector<unsigned long long> > JOI(N, std::vector<unsigned long long>(max_number + 1, 0));
		std::vector<int> num(N);
		
		for(int i = 0 ; i < N ; ++i){
			std::cin >> num[i];
		}
		JOI[0][num[0]] = 1;
		for(int i = 1 ; i < N - 1 ; ++i){
			for(int j = 0 ; j <= max_number ; ++j){
				if(JOI[i - 1][j] > 0){
					if(j + num[i] <= max_number){
						JOI[i][j + num[i]] += JOI[i - 1][j];
					}
					if(j - num[i] >= min_number){
						JOI[i][j - num[i]] += JOI[i - 1][j];
					}
				}
			}
		}
		std::cout << JOI[N - 2][num[N - 1]] << std::endl;
	}
	
    return 0;
}

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

typedef pair<int, int> beet;

vector<beet> latte;

int main()
{
	int cnt = 0;

	int po;
	cin >> po;

	for (int i = 0; i < po; ++i) {
		for (int j = i + 1; j < po; ++j) {
			
			cout << "? ";

			for (int k = 0; k < po; ++k) {
				if (k == i || k == j) {
					cout << 1;
				}
				else {
					cout << 0;
				}
			}

			cout << endl;

			int d;
			cin >> d;

			if (d) {
				latte.push_back(beet(i, j));
			}
		}
	}

	cout << "!";
	for (int i = 0; i < latte.size(); ++i) {
		printf(" (%d,%d)", latte[i].first, latte[i].second);
	}
	cout << endl;
}


Measured memory_bytes: 852
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
    int k;
    string str;
    cin >> k >> str;

    size_t len = str.length();

    if(len > k){
        string base = str.substr(0, k);
        cout << base << "...\n";
    } else {
        cout << str << "\n";
    }
    return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String W = sc.next();
        String T;
        int cnt = 0;
        while (!((T = sc.next()).equals("END_OF_TEXT"))) {
            if (T.equalsIgnoreCase(W)) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26124
#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 ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

const long long INF = (long long) 1e11+1;
const long long mod = (long long) 100000000 ;
const long long hell = (long long) 1000000007;


ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x%mod*res%mod)%mod;
    x=(x%mod*x%mod)%mod;    
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,mod-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;
   
   while(test--)
   solve();
}



void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3] and s[4]==s[5])
    cout<<"Yes";
    else
    cout<<"No";
}    


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

/*
  For freq or prime factors

for(auto pri:prime){
  while(k%pri==0){
    pcnt[pri]++;
    k/=pri;
  }
}*/
// gcd of strings
/*
string getgcd(string s1,string s2){
    
    while(true){
        if(s1.length()<s2.length()){
            swap(s1,s2);
            continue;
        }
        if(s2.empty())
        return s1;
        
        if(s1.substr(0,s2.length())!=s2)
        return "";
        
        s1=s1.substr(s2.length());
    }
}
*/
/*
// for user defined DS hashmap and set
 
struct hash_pair{
      size_t operator()(const pair<int,pair<int,int>>& p) const{
          auto hash1=hash<int>()(p.F) ;
          auto hash2=hash<int>()(p.S.F) ;
          auto hash3=hash<int>()(p.S.S) ;
          return (hash1^hash2)^hash3;
      }  
};
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
*/



Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

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

    vector<ll> A(N + 1);
    vector<ll> B(N + 1);
    vector<ll> C(N);

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

    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        cin >> B[i];
        ans += B[i];
    }
    for (ll i = 0; i < N - 1; i++)
    {
        cin >> C[i];
    }

    for (ll i = 0; i < N; i++)
    {
        if (i == 0)
        {
            continue;
        }
        if (A[i - 1] + 1 == A[i])
        {
            ans += C[A[i - 1] - 1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
'use strict'

const divisors = n => {
  let dest = []
  for (let i = 1; i < Math.floor(Math.pow(n, 0.5) + 1); i++) {
    if (n % i === 0) {
      dest.push(i)
      if (Math.floor(n / i) !== i) {
        dest.push(Math.floor(n / i))
      }
    }
  }
  return dest.sort((a, b) => a - b)
}

function main(inp) {
  inp = Number(inp.trim())
  while (1) {
    let temp = divisors(inp)
    if (temp.length === 2) break
    inp++
  }
  console.log(inp)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7724
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#define MN 4000
#define mod 998244353
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,ans,pw[MN+5];
char s[MN+5],t[8][MN+5];
bitset<MN+5> b[8],g,a;
bitset<MN+5> gcd(const bitset<MN+5>&a,const bitset<MN+5>&b,int d,int D)
{
	while(d&&!a[d-1]) --d;while(D&&!b[D-1]) --D;
	if(!d) return b;if(!D) return a;	
	if(d<=D) return gcd(a,(a<<D-d)^b,d,D);
	else return gcd(b,(b<<d-D)^a,D,d);
}
int main()
{
	n=read();scanf("%s",s+1); 
	for(int i=1;i<=n;++i) scanf("%s",t[i]+1);
	for(int i=1;i<=n;++i)
	{
		int d=strlen(t[i]+1);
		for(int j=0;j<d;++j) b[i][j]=t[i][d-j]-'0';	
	}
	g=b[1];for(int i=2;i<=n;++i) g=gcd(g,b[i],MN,MN);
	int deg=MN,len=strlen(s+1);while(!g[deg-1]) --deg;pw[0]=1;
	for(int i=1;i<=len;++i) pw[i]=2*pw[i-1]%mod;
	for(int i=1;i<=len;++i)
	{
		bitset<MN+5> nx;int flag=0; 
		if(!(s[i]=='0'&&a[len-i]))
		{
			if(a[len-i]<s[i]-'0') (ans+=pw[max(0,len-deg+1-i)])%=mod;
			else nx=a,flag=1;
		}
		if(i+deg-1<=len&&!(s[i]=='0'&&!a[len-i]))
		{
			if((a[len-i]^1)<s[i]-'0') (ans+=pw[max(0,len-deg+1-i)])%=mod;
			else nx=(a^(g<<(len-deg+1-i))),flag=1;
		}
		if(!flag) {--ans;break;} else a=nx;
	}
	cout<<(ans+1)%mod;
	return 0;
}



Measured memory_bytes: 4608