akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
//#include <stdio.h>
//#include <assert.h>

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int K, S;
int count{0};

void dfs(int depth, array<int, 2> xy) {
  if (depth == 2) {
    int remain = S - xy[0] - xy[1];
    if (0 <= remain && remain <= K) {
      ++::count;
    }
    return;
  }

  for (int i{0}; i <= MIN(K, S); ++i) {
    xy[depth] = i;
    dfs(depth + 1, xy);
  }
}

int main() {
  scanf("%d%d", &K, &S);
  array<int, 2> xy;

  dfs(0, xy);
  printf("%d\n", ::count);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
static const int INF = 2147483647;
static const int MAX_N = 1 << 18;

int n, dat[2 * MAX_N - 1];

void init(int n_){
	n = 1;
	while(n < n_) n *= 2;

	for(int i = 0; i < 2 * n - 1; i++) dat[i] = 0;
}

void update(int k, int a){
	k += n - 1;
	dat[k] += a;
	while(k > 0){
		k = (k - 1) / 2;
		dat[k] += a;
	}
}

int query(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return 0;

	if(a <= l && r <= b) return dat[k];
	else{
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return vl + vr;
	}
}

int main(){
	int n_, q;
	scanf("%d %d", &n_, &q);
	init(n_);
	for(int i = 0; i < q; i++){
		int com, x, y;
		scanf("%d %d %d", &com, &x, &y);
		if(com == 0) update(x - 1, y);
		if(com == 1) printf("%d\n", query(x - 1, y, 0, 0, n));
		//for(int i = 0; i < 2 * n - 1; i++){
		//	printf("%d", dat[i]);
		//	if(i == 2 * n - 2) printf("\n");
		//	else printf(" ");
		//}
	}
	return 0;
}

Measured memory_bytes: 3716
#include <iostream>

using namespace std;
int gcd(int x,int y){
	if(x<=y){int temp=x;x=y;y=temp;}
	if(y>0)return gcd(y,x%y);
	else return x;
}
int main(){
	int sum=0;
	int K;
	cin >> K;
	for(int i=1;i<=K;i++){
		for(int j=1;j<=K;j++){
			for(int k=1;k<=K;k++){
				sum+=gcd(gcd(i,j),k);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

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

// cout 2-dimentional vector
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]; }
  return s;
}

int mod = 1e9+7;

int main() {
  string s;
  cin >> s;
  int l = s.length();

  vvll dp(l+1, vll(4, 0));
  dp[l][3] = 1;
  for (int i = l-1; i >= 0; --i) {
    if (s[i] == '?') {
      dp[i][3] = dp[i+1][3] * 3 % mod;
      for (int j = 2; j >= 0; --j) {
        dp[i][j] = (dp[i+1][j] * 3 % mod + dp[i+1][j+1]) % mod;
      }
    } else {
      rep (j, 4) {
        dp[i][j] = dp[i+1][j];
      }
      if (s[i] == 'A') {
        dp[i][0] = (dp[i][0] + dp[i+1][1]) % mod;
      } else if (s[i] == 'B') {
        dp[i][1] = (dp[i][1] + dp[i+1][2]) % mod;
      } else if (s[i] == 'C') {
        dp[i][2] = (dp[i][2] + dp[i+1][3]) % mod;
      }
    }
  }
  printf("%lld\n", dp[0][0]);

  return 0;
}


Measured memory_bytes: 7360
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n;
  cin >> n;
  map<string,int> m;
  rep(i,n){
    string s;
    cin >> s;
    m[s]++;
  }
  int u=0;
  vector<string> ans;
  for (auto it=m.begin();it!=m.end();++it){
    u=max(u,it->second);
  }
  for (auto it=m.begin();it!=m.end();++it){
    if (u==it->second) ans.push_back(it->first);
  }
  sort(all(ans));
  rep(i,ans.size()) cout << ans[i] << endl;

}


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

int N, W;

int main() {
    cin >> N >> W;
    vector<pair<int, int>> item(N); //firstがweight, secondがvalue
    for (int i = 0; i < N; i++) {
        cin >> item[i].first >> item[i].second;
    }
    
    int maxValue = 1e5 + 1, maxWeight = 1e9 + 1;
    vector<vector<long long>> weight(N, vector<long long>(maxValue + 1, maxWeight));    //各value以上にするための最小のweight
    
    for (int i = 0; i <= item[0].second; i++) {
        weight[0][i] = item[0].first;
    }
    for (int i = 1; i < N; i++) {
        int value = item[i].second;
        for (int j = 0; j <= value; j++) {
            weight[i][j] = min(weight[i - 1][j], 1ll * item[i].first);
        }
        for (int j = value + 1; j <= maxValue; j++) {
            weight[i][j] = min(weight[i - 1][j], weight[i - 1][j - value] + item[i].first);
        }
    }
    
    for (int i = 0; i < maxValue; i++) {
        if (weight[N - 1][maxValue - i] <= W) {
            cout << maxValue - i << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

struct UnionFind
{
    int n, num;
    vector<int> r, p;
    UnionFind() {}
    UnionFind(int sz) : n(sz), num(sz), r(sz, 1), p(sz, 0) { iota(p.begin(), p.end(), 0); }
    int find(int x)
    {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (r[x] < r[y])
            swap(x, y);
        r[x] += r[y];
        p[y] = x;
        num--;
    }
    int size(int x)
    {
        return r[find(x)];
    }
    int count() const
    {
        return num;
    }
};

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

    int n;
    cin >> n;
    typedef pair<P, int> PP;
    vector<PP> v(n), w(n);
    rep(i, n)
    {
        int x, y;
        cin >> x >> y;
        v[i] = PP(P(x, y), i);
        w[i] = PP(P(y, x), i);
    }
    sort(all(v)), sort(all(w));
    typedef pair<int, P> pp;
    priority_queue<pp, vector<pp>, greater<pp>> que;
    rep(i, n - 1)
    {
        PP p = v[i + 1], q = v[i];
        int a = p.second, b = q.second;
        int dx = p.first.first - q.first.first;
        int dy = p.first.second - q.first.second;
        if (dy < 0)
            dy *= -1;
        que.push(pp(min(dx, dy), P(a, b)));
    }
    rep(i, n - 1)
    {
        PP p = w[i + 1], q = w[i];
        int a = p.second, b = q.second;
        int dy = p.first.first - q.first.first;
        int dx = p.first.second - q.first.second;
        if (dx < 0)
            dx *= -1;
        que.push(pp(min(dx, dy), P(a, b)));
    }
    int ans = 0;
    UnionFind uf(n);
    while (!que.empty())
    {
        pp p = que.top();
        que.pop();
        int a = p.first, b = p.second.first, c = p.second.second;
        if (uf.same(b, c))
            continue;
        uf.unite(b, c);
        ans += a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13296
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int nn=scan.nextInt();
int mm=scan.nextInt();
  
  if(nn==mm){
    System.out.println("Yes");
  }else{
    System.out.println("No");
  }
}
}

Measured memory_bytes: 21204
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from collections import Counter
N = int(input())
c = Counter([])
ans = 1
for i in range(1,N+1):
    c = c + Counter(prime_factorize(i))
for x in c.values():
    ans = (ans*(x+1)) % 1000000007
print(ans)

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

int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};

int main(){
  int H,W;
  cin >> H >> W;

  vector<string> m(H);
  int cnt = 0;
  for (int i = 0; i < H; i++)
  {
    cin >> m[i];
    for (int j = 0; j < W; j++)
    {
      if(m[i][j]=='.') cnt++;
    }
  }

  vector<vector<int>> dist(H,vector<int>(W,-1));
  dist[0][0] = 0;
  queue<pair<int,int>> q;
  q.emplace(0,0);
  while(!q.empty()){
    pair<int,int> now = q.front();
    int nowh = now.first;
    int noww = now.second;
    q.pop();
    for (int i = 0; i < 4; i++)
    {
      int nexth = nowh + dh[i];
      int nextw = noww + dw[i];
      if(nexth >= H || nexth < 0 || nextw >= W || nextw < 0) continue;
      if(m[nexth][nextw]=='#') continue;
      if(dist[nexth][nextw]!=-1) continue;
      dist[nexth][nextw] = dist[nowh][noww] + 1;
      q.emplace(nexth,nextw);
    }
  }
  if(dist[H-1][W-1]==-1) cout << -1 << endl;
  else cout << cnt-dist[H-1][W-1]-1 << endl;  
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    int n = Integer.parseInt(line);
    
    line = sc.nextLine();
    String HeiSt[] = new String[n];
    HeiSt = line.split(" ", 0);
    int hei0 = Integer.parseInt(HeiSt[0]);
    int hei1;
    long step = 0;
    
    for(int i = 1; i < n; i++){
      hei1 = Integer.parseInt(HeiSt[i]);
      if(hei0 > hei1){
        step += hei0 - hei1;
      }else if(hei0 < hei1){
        hei0 = hei1;
      }
    }
    
    System.out.println(step);
  }
}

Measured memory_bytes: 82120
n,m,k1=map(int,input().split())
mat=[[10**9 for j in range(n)]for i in range(n)]
r=[int(i)-1 for i in input().split()]
for i in range(m):
    a,b,c=map(int,input().split())
    mat[a-1][b-1]=c 
    mat[b-1][a-1]=c
for i in range(n):
    mat[i][i]=0 
dp=[[10**9 for j in range(n)]for i in range(n)]
for i in range(n):
    dp[i][i]=0 
for k in range(n):
    for i in range(n):
        for j in range(n):
            if mat[k][j]==10**9:
                continue 
            mat[i][j]=min(mat[i][j], mat[i][k]+mat[k][j])
            mat[j][i]=mat[i][j]
#print(dp)\
dp=mat 
mini=10**100 
#print(dp[2][3]+dp[3][1])
from itertools import permutations
for i in permutations(r) : 
    ans=0 
   # print(i)
    for j in range(1,k1): 
        ans+=dp[i[j-1]][i[j]]
    #print(i,ans)
    mini=min(mini,ans)
print(mini)

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  int min = vec.at(0);
  int count = 1;
  
  for (int i = 1; i < n; i++) {
    if (vec.at(i) <= min) {
      count++;
      min = vec.at(i);
    }
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define inf 1e18

ll sum(vector<ll>&a,ll l ,ll r)
{
  ll s=0;
  for(ll i=l;i<=r;i++)
    s+=a[i];
  return s;
}


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

  vector<ll>a(n);
  for(auto &it:a)
      cin>>it;
  ll dp[n+5][n+5];
  for(ll i=0;i<n;i++)
    for(ll j=0;j<n;j++)
      dp[i][j]=inf;

  for(ll l=n-1;l>=0;l--)
  {
    for(ll r=l;r<n;r++)
    {
      if(l==r)
        dp[l][r]=0;
      else
      {
        ll s=sum(a,l,r);
       // dp[l][r]=inf;
        for(ll i=l;i<r;i++)
        {
          dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s);
        }
      }
    }
  }

  cout<<dp[0][n-1]<<endl;



}



Measured memory_bytes: 4912
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e5 * 3 + 10;



int main() {
    fastInp;

    ll m, k;
    cin >> m >> k;
    ll nms = (1ll << m), x = 0;
    if (k == 0) {
        for (int i = 0; i < nms; i++) {
            cout << i << " " << i << " ";
        }
        return 0;
    }
    for (int i = 0; i < nms; i++) {
        if (k != i) {
            x ^= i;
        }
    }

    if (x != k) {
        cout << "-1";
        return 0;
    }

    for (int i = 0; i < nms; i++) {
        if (k != i) cout << i << " ";
    }

    cout << k << " ";

    for (int i = nms - 1; i >= 0; i--) {
        if (k != i) cout << i << " ";
    }

    cout << k << " ";
    return 0;
}



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

int main(){
    int array[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << array[k-1] << endl;
}

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

#define int long long

#define REP(i, a) for(int i = 0; i < (a); i++)

using namespace std;

signed main()
{
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vector<int> a(n); REP(i, n) cin >> a[i];
    for(int i = n-1; i >= 0; i--)
    {
        cout << a[i];
        if(i != 0) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int n,a,b,c,d,i;
char s[200200];
bool check(int x, int y) {
  for (int i=x+1; i<=y; i++) if (s[i]=='#' && s[i-1]=='#') return false;
  return true;
}
int main() {
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  a--; b--; c--; d--;
  scanf("%s",s);
  if (!check(a,c) || !check(b,d)) { puts("No"); return 0; }
  if (c<d) { puts("Yes"); return 0; }
  for (i=b; i<=d; i++) if (s[i]=='.' && s[i-1]=='.' && s[i+1]=='.') {
    puts("Yes"); return 0;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
  	long long N,res = 0;
  	cin >> N;
  	vector<long long> A(N+1);
  	vector<long long> B(N);
  	for(int i = 0; i < N+1; i++){
    	cin >> A[i];
    }
  
  	for(int i = 0; i < N; i++){
    	cin >> B[i];
    }
  
  	for(int i = 0; i < N; i++){
    	if(B[i] >= A[i]){
        	res += A[i];
          	B[i] -= A[i];
          	A[i] = 0;
          	if(B[i] >= A[i+1]){
            	res += A[i+1];
              	B[i] -= A[i+1];
              	A[i+1] = 0;
            }else{
            	res += B[i];
              	A[i+1] -= B[i];
            }
        }else{
        	res += B[i];
          	A[i] -= B[i];
        }
    } 
  	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1792
def yymm_or_mmyy(s):
    yymm = 'YYMM'
    mmyy = 'MMYY'
    abmg = 'AMBIGUOUS'
    na = 'NA'

    top = s[0] + s[1]
    bot = s[2] + s[3]

    if is_mm(top):
        out = abmg if is_mm(bot) else mmyy
    else:
        out = yymm if is_mm(bot) else na

    return out

def is_mm(s):
    mm = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
    return s in mm

s = str(input())
out = yymm_or_mmyy(s)
print(out)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)

{

  int a,b,c,x,y,z;

  scanf("%d %d %d",&a,&b,&c);

  if(a>b)


  {


    x=a;


    a=b;


    b=x;


  }


  if(b>c)


  {


    y=b;


    b=c;


    c=y;


  }


  if(a>b)


  {


    z=a;


    a=b;


    b=z;


  }


  printf("%d %d %d\n",a,b,c);


  return 0;


}

Measured memory_bytes: 596
package main

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

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

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

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

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	stones := make([]bool, N)
	s := next()
	for i := 0; i < N; i++ {
		if s[i] == 'R' {
			stones[i] = true
		}
	}

	c := 0
	i := 0
	j := N - 1
	for i < j {
		for stones[i] == true && i < j {
			i++
		}
		for stones[j] == false && i < j {
			j--
		}
		if i < j {
			c++
			i++
			j--
		}
	}

	fmt.Fprintf(out, "%d\n", c)
}


Measured memory_bytes: 2408
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     
	int a,b,c,d;
	cin>>a>>b>>c>>d;
    
	while(a>0&&c>0)
	{
	
		  c=c-b;
		  a=a-d;
		  
		  
		  if(c<=0)
		  {
		 
		  	cout<<"Yes"<<endl;
		  	break;
		  	
		  }
		  
		  
		  else if(a<=0)
		  {
		  
		  	cout<<"No"<<endl;
		    break;
		  	
		  	
		  }
		  
	
	}	
	
	


     return 0;
     
     
}

Measured memory_bytes: 3584
#include<iostream>

using namespace std;
#define rep(i,a) for (int i = 0; i < (a); ++i)
#define repr(i,n) for (int i = (n); i >= 0; --i)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int a[4],tmp;cin>>tmp;
  repr(i,3){
    a[i]=tmp%10;
    tmp/=10;
  }
  int res;
  char op[3];
  for(int i=0;i<( 1 << 4 );i++){
    res=a[0];
    for(int j=1;j<4;j++){
      if( i & ( 1 << j ) ){
        res+=a[j];
        op[j-1]='+';
      }else{
        res-=a[j];
        op[j-1]='-';
      }
    }
    if(res==7){
      rep(i,3)cout<<a[i]<<op[i];
      cout<<a[3]<<"=7"<<'\n';
      return 0;
    }
  }
}

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

int main()
{
    long long n;
    cin>>n;
    if(n%2==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    int k=0;
    for(int i=1;i<=1e7;i++)
    {
       k*=10;
       k+=7;
       k=k%n;
       if(k==0)
       {
           cout<<i<<endl;
           return 0;
       }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 3644
h, w = map(int, input().split())
sy, sx = map(lambda x:int(x) + 1, input().split()) 
gy, gx = map(lambda x:int(x) + 1, input().split()) 
grid = [['#'] * (w + 4) for _ in range(2)]
for _ in range(h):
    grid.append(['#', '#'] + list(input()) + ['#', '#'])
grid.append(['#'] * (w + 4))
grid.append(['#'] * (w + 4))

stack = [(sy, sx)]

move = [(-1, 0), (1, 0), (0, 1), (0, -1)]

visited = set()
ans = 0
while stack:
    edge = set()
    while stack:
        y, x = stack.pop()
        visited.add((y, x))
        if gy == y and gx == x:
            print(ans)
            quit()
        for my, mx in move:
            if (y+my, x+mx) in visited:
                continue
            if grid[y+my][x+mx] == '.':
                stack.append((y+my, x+mx))
            else:
                edge.add((y, x))
    ans += 1
    next_points = set()
    for y, x in edge:
        for dy in range(-2, 3):
            yy = y + dy
            for dx in range(-2, 3):
                xx = x + dx
                if grid[yy][xx] == '.' and not (yy, xx) in visited and not (yy, xx) in next_points:
                    next_points.add((yy, xx))
    stack = list(next_points)
print(-1)

Measured memory_bytes: 193824
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

vector<ll> r, b, g;
int n;
string s;

void getPrefs() {
	r = vector<ll>(n, 0);
	b = vector<ll>(n, 0);
	g = vector<ll>(n, 0);
	for(int i = 0; i < n; i++){
		r[i] = (i == 0)? 0 : r[i - 1];
		b[i] = (i == 0)? 0 : b[i - 1];
		g[i] = (i == 0)? 0 : g[i - 1];
		if(s[i] == 'R'){
			r[i] ++;
		}else if(s[i] == 'B'){
			b[i] ++;
		}else{
			g[i] ++;
		}
	}
}

ll getSum(int a, int bb, char rbg){
	if(a >= n or bb >= n) { return 0; }
	if(rbg == 'R'){
		return r[bb] - (a == 0? 0 : r[a - 1]);
	}else if(rbg == 'B'){
		return b[bb] - (a == 0? 0 : b[a - 1]);
	}else if(rbg == 'G'){
		return g[bb] - (a == 0? 0 : g[a - 1]);
	}
	return 0;
}

char getLastChar(char m, char n){
	if(m != 'G' and n != 'G'){
		return 'G';
	} else if(m != 'B' and n != 'B'){
		return 'B';
	} else {
		return 'R';
	}
}

int main(){
	cin >> n;
	cin >> s;
	ll sum = 0;
	getPrefs();
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 1; j < n - 1; j++){
			if(s[i] != s[j]){
				sum += getSum(j + 1, n - 1, getLastChar(s[i], s[j]));
				sum -= getSum(j + (j - i), j + (j - i), getLastChar(s[i], s[j]));
			}
		}
	}
	cout << sum;
	return 0;
}

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

int main(){
    string s;
    cin >>s;
    if(s=="ABC"){
        cout << "ARC" <<endl;
    }else{
        cout << "ABC" <<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int d;
    cin >> d;
    assert(d == 365);
    vector<int> c(26);
    for(int i = 0; i < 26; i++){
        cin >> c[i];
    }
    vector<vector<int> > s(d, vector<int> (26));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(d), satisfaction(d), last(26);
    for(int i = 0; i < d; i++){
        vector<int> fin = last;
        fin[0] = i + 1;
        int curr = 0, ans = INT_MIN, choose = 1;
        for(int x = 1; x <= 26; x++){
            vector<int> temp = last;
            temp[x - 1] = i + 1;
            curr += s[i][x - 1];
            for(int j = 0; j < 26; j++){
                curr -= (i + 1 - temp[j]) * c[j];
            }
            if(curr > ans){
                ans = curr;
                choose = x;
                fin = temp;
            }
        }
        t[i] = choose;
        last = fin;
        satisfaction[i] = ans;
    }
    // int sat = 0;
    // for(int i = 0; i < d; i++){
    //     last[t[i] - 1] = i + 1;
    //     sat += s[i][t[i] - 1];
    //     for(int j = 0; j < 26; j++){
    //         sat -= (i + 1 - last[j]) * c[j];
    //     }
    //     satisfaction[i] = sat;
    // }
    // for(int i = 0; i < d; i++){
    //     cout << satisfaction[i] << "\n";
    // }
    // for(int i = 0; i < d; i++){
    //     cout << t[i] << "\n";
    // }
    int res = max(1000000 + satisfaction[d - 1], 0);
    for(int i = 0; i < d; i++){
        cout << t[i] << "\n";
    }
    // cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			string rec = Console.ReadLine();
			string[] cir = rec.Split(' ');

			int W = int.Parse(cir[0]);
			int H = int.Parse(cir[1]);
			int x = int.Parse(cir[2]);
			int y = int.Parse(cir[3]);
			int r = int.Parse(cir[4]);

			if (W < x + r || 0 > x - r || H < y + r || 0 > y - r)
			{
				Console.WriteLine("No");
			}
			/*else if (H < y + r || 0 > y - r)
			{
				Console.WriteLine("No");
			}*/
			else
				Console.WriteLine("Yes");
		}
	}
}



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

long A, B, C;

int main(){
    cin >> A >> B >> C;
    bool flag = true;
    long count = 0;
    long tmp_A, tmp_B, tmp_C;
    if (A % 2 == 1 or B % 2 == 1 or C % 2 == 1){
        flag = false;
    }

    else if(A == B and B == C){
        count = -1;
        flag = false;
    }

    while(flag){
        tmp_A = A;
        tmp_B = B;
        tmp_C = C;
        if (A % 2 == 0 and B % 2 == 0 and C % 2 == 0){
            A = tmp_B / 2 + tmp_C / 2;
            B = tmp_A / 2 + tmp_C / 2;
            C = tmp_A / 2 + tmp_B / 2;
            count++;
            if(count > 10000000){
                count = -1;
                flag = false;
            }
        }
        else
        {
            flag = false;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
char a[505],b[505];
int main(){
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)cin>>a[i];
	for(ll i=1;i<=n;i++)cin>>b[i];
	for(ll i=1;i<=n;i++) cout<<a[i]<<b[i];
	return 0;
} 

Measured memory_bytes: 256
import math
ind = 0
list = [[0 for i in range(3)] for j in range(3)]
for i in input().split():
  list[0][ind] = i
  ind+=1

ind = 0
for k in input().split():
  list[1][ind] = k
  ind+=1

ind = 0
for l in input().split():
  list[2][ind] = l
  ind+=1

ind = 0
kosu = int(input())
for kosu2 in range(kosu):
  p = int(input())
  for x in range(3):
    for y in range(3):
      if int(list[x][y]) == p:
        list[x][y] = -1

if list[0][0] == -1 and list[0][1] == -1 and list[0][2] == -1:
  print("Yes")
elif list[1][0] == -1 and list[1][1] == -1 and list[1][2] == -1:
  print("Yes")
elif list[2][0] == -1 and list[2][1] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][0] == -1 and list[1][0] == -1 and list[2][0] == -1:
  print("Yes")
elif list[0][1] == -1 and list[1][1] == -1 and list[2][1] == -1:
  print("Yes")
elif list[0][2] == -1 and list[1][2] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][0] == -1 and list[1][1] == -1 and list[2][2] == -1:
  print("Yes")
elif list[0][2] == -1 and list[1][1] == -1 and list[2][0] == -1:
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3192
//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<iterator>
#include<algorithm>
#include<bitset>

#define Filein(N) freopen("N", "r", stdin);
#define Fileout(N) freopen("N", "w", stdout);
#define sci(x) scanf("%d", &x)
#define sci2(x,y) scanf("%d%d", &x,&y)
#define scll2(x,y) scanf("%lld%lld",&x,&y)
#define scll(x) scanf("%lld",&x)
#define scd(x) scanf("%lf", &x)
#define scstr(x) scanf("%s", x)
#define pfi(x) printf("%d", x)
#define pfll(x) printf("%lld", x)
#define pfd(x) printf("%f", x)
#define pfstr(x) printf("%s", x)
#define ps printf(" ")
#define pn printf("\n")
#define pfdt printf("..")

#define For(i,a,n) for(int i=a; i<=n;i++)
#define rFor(i,n,a) for(int i=n; i>=a; i--)
#define TestCase int testcase, cs=1; cin>>testcase;while(testcase--)

#define mkp make_pair
#define pb push_back
#define ff first
#define ss second

#define px(x) cout<<"X -> "<<x<<endl;
#define py(x) cout<<"Y = "<<x<<endl;
#define pz(x) cout<<"Z >> "<<x<<endl;
#define pstr(x) printf("%s\n",x);

using namespace std;
using ll = long long;
using vi = vector <int>;
using mpii = map<int,int>;
using si = set<int>;
using sll = set<ll>;
using vll= vector<ll>;

#define INF 1000000000
#define LINF 4000000000000000000
#define pi  (2*acos(0))
#define Mod 1000000007

 int main(){
 int n,m;

 sci2(n,m);

 For(i,1,n){
  int j = n-i;
   if(i*2+j*4==m||i*4+j*2==m) {
    printf("Yes\n");
    return 0;
   }

 }


 printf("No\n");





    return 0;
}







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

const int INF = 1e9 + 5;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n , k;
	scanf("%d", &n);
	scanf("%d", &k);
	vector<int>h(n);
	for (int &x : h)
		scanf("%d", &x);
	vector <int>dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i)		//FOR EVERY NEXT STONE
		for (int j = i + 1; j <= i + k; ++j)		//JUMPS ALLOWED TO i+k STONES
			if (j < n)		//SINCE WE ARE ONLY CONSIDERING STONES IN THE RANGE UPTO N
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
	printf("%d", dp[n - 1]);
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    ll ans = 0;
    if (m / 2 <= n) 
      ans += m / 2, n -= m / 2;
    else {
      ans += n;
      m -= n * 2;
      ans += m / 4; 
    }
    cout << ans << endl;
    return 0;
} 



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"a == b"<<"\n";
  }else if(a<b){
    cout<<"a < b"<<"\n";
  }else if(a>b){
    cout<<"a > b"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 1124
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    long X=gl();
	    long yen=100;
	    long y=0;
	    while (yen<X) {
	    	long a=Math.floorDiv(yen, 100);
	    	yen+=a;
	    	y++;
	    }
        System.out.print(y);

//        if (2*X<=Y&& Y<=4*X && Y%2==0) {
//        	System.out.println("Yes");
//        }else{
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35488
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int main(){
    int N, M;
    int last = 0;
    int ans = 0;
    P war[100000];
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        war[i] = P(b, a);
    }
    sort(war, war+M);
    for(int i = 0; i < M; i++){
        if(last <= war[i].second){
            last = war[i].first;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> dp(100010);
  dp[0] = 0;

  for (int i = 1; i <= 100000; ++i)
  {
    dp[i] = 100000;
    
    int p = 1;
    while (p <= i)
    {
      dp[i] = min(dp[i], dp[i - p] + 1);
      p *= 6;
    }

    int q = 1;
    while (q <= i)
    {
      dp[i] = min(dp[i], dp[i - q] + 1);
      q *= 9;
    }

    if (i == N) break;
  }

  cout << dp[N] << endl;
}

Measured memory_bytes: 640
/*
分析 f[x] = ans
f1 = f2 = 0
f3 = 1
f4 = 1
f5 = 1
f6 = 2
f7 = 3
f8 = 4
f9 = 6
f10 = f9 + f7 = 9;
*/
/*
*/
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1e9 + 7;
int s, f[2005];
int main()
{
	scanf("%d", &s);
	f[3] = 1;
	for(int i = 4; i <= s; i ++)
		f[i] = ( f[i - 3] + f[i - 1] ) % N;
	printf("%d", f[s]);
}

Measured memory_bytes: 3780
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }
    val map = mutableMapOf<Int, Int>()
    for(a in A){
        map[a] = (map[a] ?: 0) + 1
    }
    var f = false
    if((map[0] ?: 0) == N){
        f = true
    }else if(N % 3 == 0){
        val keys = map.keys.toList()
        if(keys.size == 2 && keys.contains(0)){
            f = keys.map { k ->
                if(k == 0){
                    map[k]!! == N / 3
                }else{
                    map[k]!! == 2 * N / 3
                }
            }.all { it }
        }else if(map.keys.size == 3){
            f = keys[0].xor(keys[1].xor(keys[2])) == 0
                    && map[keys[0]]!! == map[keys[1]]!!
                    && map[keys[1]]!! == map[keys[2]]!!
        }
    }
    if(f){
        println("Yes")
    }else{
        println("No")
    }
}

Measured memory_bytes: 61248
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 400005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m,tot;
int a[maxn],pos[maxn];
pair<int,int>ans[maxn];
pair<int,int>sum[maxn];
int ma[2][maxn][22],lg[maxn];
inline int query(int fl,int l,int r)
{
    int len=lg[r-l+1];
    return min(ma[fl][l][len],ma[fl][r-(1<<len)+1][len]);
}
vector<int>G[maxn];
inline void dfs(int k,int l,int r)
{
    if(r==l+1)
    {ans[k]=make_pair(-a[l],-a[r]);return ;}
    reg int x,y,len=(r-l+1)>>1;
    x=query(r&1,(l>>1)+(l&1),(l>>1)+(l&1)+len-1);
    y=query(l&1,((pos[x]+1)>>1)+((pos[x]+1)&1),r/2+(r&1));
    ans[k]=make_pair(-x,-y);
    if(l<pos[x]-1)
    {
        G[k].push_back(++tot);
        dfs(tot,l,pos[x]-1);
    }
    if(pos[x]+1<pos[y]-1)
    {
        G[k].push_back(++tot);
        dfs(tot,pos[x]+1,pos[y]-1);
    }
    if(pos[y]+1<r)
    {
        G[k].push_back(++tot);
        dfs(tot,pos[y]+1,r);
    }
}
priority_queue< pair<pair<int,int>,int> >q;
int main()
{
    n=read();m=n>>1;reg int i,j,x;lg[0]=-1;
    for(i=1;i<=n;++i)a[i]=read(),pos[a[i]]=i;
    for(i=1;i<=m;i++)ma[0][i][0]=a[i*2-1];
    for(i=1;i<=m;i++)ma[1][i][0]=a[i*2];
    for(i=1;i<=n;++i)lg[i]=lg[i>>1]+1;
    for(j=1;j<=lg[m];++j)for(i=1;i+(1<<j)-1<=m;++i)
        ma[0][i][j]=min(ma[0][i][j-1],ma[0][i+(1<<(j-1))][j-1]),
            ma[1][i][j]=min(ma[1][i][j-1],ma[1][i+(1<<(j-1))][j-1]);
    dfs(tot=1,1,n);reg int sz;
    q.push(make_pair(ans[1],1));pair<int,int>t;
    while(!q.empty())
    {
        t=q.top().first;
        printf("%d %d ",-t.first,-t.second);
        x=q.top().second;q.pop();sz=G[x].size();
        for(i=0;i<sz;++i)q.push(make_pair(ans[G[x][i]],G[x][i]));
    }
	return 0;
}


Measured memory_bytes: 59904
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	int x;
	// nyuryoku
	cin >> x;
	// keisan
	int first = 600,kyu = 8;
	while(first <= x){
		first += 200;
		kyu--;
	}
	// syutsuryoku
	cout << kyu << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

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

  string s;
  cin >> s;
  int n = 0;
  for (char c : s) {
    if (c == '+')
      ++n;
    else if (c == '-')
      --n;
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/dp/tasks/dp_a

class Main {
    // Frog 1
    public static int forg1(int[] stones) {
        int[] dp = new int[stones.length];
        dp[0] = 0;
        dp[1] = Math.abs(stones[1] - stones[0]);

        for (int i = 2; i < stones.length; i++) {
            dp[i] = Math.min(dp[i-1]+Math.abs(stones[i-1]-stones[i]),
            dp[i-2]+Math.abs(stones[i-2]-stones[i]));
        }
        return dp[stones.length-1];
    }

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

        int[] arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = in.nextInt();
        }
        in.close();

        // call function hear
        int ret = forg1(arr);
        System.out.println(ret);
    }
}

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

int main(){
	
	int N,K,x[1000];
	cin >> N;
	cin >> K;
	for(int i = 0;i < N ; i++){
		cin >> x[i];
}
 int sum = 0;
for(int i = 0;i < N; i++){
	if((K - x[i]) >= x[i]){
		sum += 2*x[i];
	}
	else{
		sum += 2*(K - x[i]);
	}
}

cout << sum << endl;

}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
edge,inside,cnt,ix = 0,0,0,0
if s[0]=='R' or s[-1]=='R':
  edge += 1
temp = ''
#print(ix)
s += 'L'
for i in range(n+1):
  if i!=n:
    if temp=='R' and s[i]=='L':
      inside += 1
    elif temp==s[i]:
      cnt += 1
  temp = s[i]
#print(inside,cnt,edge)
if inside>=k:
  print(min(k*2+cnt,n-1))
else:
  print(min(inside*2+edge+cnt,n-1))

Measured memory_bytes: 9228
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin >> c;
    printf("%c\n", (c + 1));
    return 0;
}

Measured memory_bytes: 256
X = int(input())

def makePrimeChecker(n):
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if isPrime[i]:
            for j in range(i * i, n + 1, i):
                isPrime[j] = False
    return isPrime

isPrime = makePrimeChecker(10**6)

while not isPrime[X]:
    X += 1

print(X)

Measured memory_bytes: 46320
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func calcScore(day int, score, c, last []int) int {
	loss := make([]int, 26)
	for i := 0; i < 26; i++ {
		loss[i] = c[i] * (day - last[i])
	}

	ret := 0
	for j := 0; j < 26; j++ {
		score[j] -= loss[j]
		ret += score[j]
	}

	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	D := getInt()
	c := getInts(26)
	s := make([][]int, D)
	for i := 0; i < D; i++ {
		s[i] = getInts(26)
	}

	last := make([]int, 26)
	score := make([]int, 26)

	for i := 0; i < D; i++ {
		t := getInt() - 1
		score[t] += s[i][t]
		last[t] = i + 1
		ans := calcScore(i+1, score, c, last)
		out(ans)
		// out(score)
	}

	// for i := 0; i < D; i++ {
	// 	maxS := 0
	// 	idxS := 0
	// 	for j := 0; j < 26; j++ {
	// 		if maxS < s[i][j] {
	// 			maxS = s[i][j]
	// 			idxS = j
	// 		}
	// 	}
	// 	out(idxS + 1)
	// }
}


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

template <typename T, typename K> struct P {
	T a;
	K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, K;
	scanf("%d%d", &N, &K );
	int* vec = new int[N];
	ll ans = 0;
	rep( i, 0, K ){
		scanf("%d", vec+i);
		ans += vec[i];
	}
	ll temp = ans;
	rep( i, K, N ){
		scanf("%d", vec+i);
		temp += vec[i]-vec[i-K];
		ans = max( ans, temp);
	}
	printf("%.10lf\n", ( double )(ans + K ) / 2);
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    boolean flag=false;
    while(n!=0)
    {
      int d=n%10;
      if(d==7)
      {flag=true;
        break;}
      n/=10;
    }
   if(flag)
     System.out.println("Yes");
    else
     System.out.println("No"); 
  }
}
   
    


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

using namespace std;


    


int main() {
    int N;
    cin >> N;
    
    vector<long long> L(N+1);
    
    L[0]=2LL;
    L[1]=1LL;
    for(int i=2; i<=N; i++){
        L[i]=L[i-2]+L[i-1];
    }
    
    cout << L[N] << endl;
    
}
        


Measured memory_bytes: 256
import string
import bisect

s = str(input())
t = str(input())
len_s = len(s)
len_t = len(t)

s_alpha_ind = {x:[] for x in string.ascii_lowercase}

for i in range(len_s):
    s_alpha_ind[s[i]].append(i+1)

ans = 0
now_s_ind = 0
for i in range(len_t):
    now_t = t[i]
    if len(s_alpha_ind[now_t]) == 0:
        ans = -1
        break
    else:
        # print('now s_ind is: '+ str(now_s_ind))
        # print('-'*30)
        # print('now_t is: ' + str(now_t))

        # 二分探索で、now_s_indよりも大きな値を探す
        # なければ最初の値を返す
        Inds = s_alpha_ind[now_t]
        ind = bisect.bisect_right(Inds, now_s_ind)
        # print('Inds is :')
        # print(Inds)
        # print('ind is:' + str(ind))

        if ind == len(Inds):
            ans += (len_s - now_s_ind + Inds[0])
            if i == 0:
                ans -= len_s
            now_s_ind = Inds[0]
        else:
            ans += Inds[ind] - now_s_ind
            now_s_ind = Inds[ind]
        # print('ans is:' +  str(ans))


print(ans)

Measured memory_bytes: 8304
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		int c[] = new int[n];
		for(int i = 0; i < n; i++)
			c[i] = 0;
		
		for(int i = 0; i < m * 2; i++){
			int temp = sc.nextInt();
			for(int j = 0; j < n; j++)
				if(j + 1 == temp){
					c[j]++;
					break;
				}
		}
		
		for(int i = 0; i < n; i++)
			System.out.println(c[i]);
	}
 
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 1000000007

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(N + 1, vector<int>(N + 1, 0)));
    vector<vector<vector<bool>>> flag(N + 1, vector<vector<bool>>(N + 1, vector<bool>(N + 1, true)));
    REP(_, M) {
        int l, r, x;
        cin >> l >> r >> x;
        --l;
        if (x == 1) {
            REP(a, r) FOR(b, a, r) {
                if (!(b <= l)) {
                    flag[a][b][r] = false;
                }
            }
        } else if (x == 2) {
            REP(a, r) FOR(b, a, r) {
                if (!(a <= l && l < b)) {
                    flag[a][b][r] = false;
                }
            }
        } else if (x == 3) {
            REP(a, r) FOR(b, a, r) {
                if (!(l < a)) {
                    flag[a][b][r] = false;
                }
            }
        }
    }

    dp[0][0][0] = 1;
    REP(a, N + 1) FOR(b, a, N + 1) FOR(c, b, N + 1) {
        int A, B, C;
        A = b, B = c, C = c + 1;
        if (flag[A][B][C]) dp[A][B][C] = (dp[A][B][C] + dp[a][b][c]) % MOD;
        A = a, B = c, C = c + 1;
        if (flag[A][B][C]) dp[A][B][C] = (dp[A][B][C] + dp[a][b][c]) % MOD;
        A = a, B = b, C = c + 1;
        if (flag[A][B][C]) dp[A][B][C] = (dp[A][B][C] + dp[a][b][c]) % MOD;
    }

    int result = 0;
    REP(a, N + 1) FOR(b, a, N + 1) result = (result + dp[a][b][N]) % MOD;
    cout << result << endl;

    return 0;
}

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

string s;
int q;

int main() {
    cin >> s >> q;
    bool isReg = true;
    int num_rev = 0;
    string front = "", back = "";
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            isReg = !isReg;
            num_rev++;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (isReg) {
                if (f == 1) {
                    front.push_back(c);
                } else {
                    back.push_back(c);
                }
            } else {
                if (f == 2) {
                    front.push_back(c);
                } else {
                    back.push_back(c);
                }
            }
        }
    }
    if (num_rev % 2 == 0) {
        reverse(front.begin(), front.end());
        cout << front << s << back << endl;
    } else {
        reverse(back.begin(), back.end());
        reverse(s.begin(), s.end());
        cout << back << s << front << endl;
    }
}

Measured memory_bytes: 1088
#include<stdio.h>

int main(void){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if(a==b)
    printf("a == b\n");
    else if(a > b)
    printf("a > b\n");
    else if(a<b)
    printf("a < b\n");

    
    return 0;
}


Measured memory_bytes: 2056