akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>

#include <cassert>
#include <climits>

#include <string.h>

#include <vector>
#include <map>
#include <stack>
#include <deque>

enum Color
{
    kWhite,
    kGray,
    kBlack,
};

int n;
int start_vertex = 0;
std::vector< std::vector<int> > matrix;
std::vector<Color> c;
std::vector<int> d;

void breadthFirstSearch()
{
    for (int i = 0; i < n;++i)
    {
        c.push_back(kWhite);
        d.push_back(-1);
    }

    std::deque<int> tmp_queue;
    tmp_queue.push_back(start_vertex);
    c[start_vertex] = kGray;
    d[start_vertex] = 0;

    while (! tmp_queue.empty())
    {
        int current = tmp_queue.front();
        tmp_queue.pop_front();
        c[start_vertex] = kBlack;

        std::vector<int> line = matrix[current];
        for (int i = 0; i < line.size(); ++i)
        {
            if (line[i] > 0 && c[i] == kWhite)
            {
                tmp_queue.push_back(i);
                c[i] = kGray;
                d[i] = d[current] + 1;
            }
        }
    }
}

int main()
{
    std::cin >> n;
    for (int i = 0; i < n; ++i)
    {
        std::vector<int> line;
        for (int j = 0; j < n; ++j)
        {
            line.push_back(0);
        }
        matrix.push_back(line);
    }

    for (int i = 0; i < n; ++i)
    {
        int u;
        int k;

        std::cin >> u;
        std::cin >> k;

        for (int j = 0; j < k; ++j)
        {
            int tmp;
            std::cin >> tmp;
            matrix[u - 1][tmp - 1] = 1;
        }
    }

    breadthFirstSearch();

    for (int i = 0; i < n; ++i)
    {
        std::cout << (i + 1) << " " << d[i] << std::endl;
    }

    return 0;
}






Measured memory_bytes: 3172
/**
*    author:  souzai32
*    created: 01.08.2020 20:58:19
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n,m;
    cin >> n >> m;
    cout << (1900*m+100*(n-m))*pow(2,m) << endl;

    return 0;
}

Measured memory_bytes: 4256
import scala.io.StdIn._

object Main extends App with StdInHelper {
  val Array(n, t) = readLongs
  val ts = readLongs

  var next = 0L
  var ans = 0L
  for (ti <- ts) {
    if (next <= ti) ans += t
    else ans += t - (next - ti)
    next = ti + t
  }

  println(ans)
}

trait StdInHelper {
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
}


Measured memory_bytes: 52716
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn color(a: usize) -> usize {
    match a {
        1..=399 => 1,
        400..=799 => 2,
        800..=1199 => 3,
        1200..=1599 => 4,
        1600..=1999 => 5,
        2000..=2399 => 6,
        2400..=2799 => 7,
        2800..=3199 => 8,
        _ => 9
    }
}

fn main() {
    input!{
        n: usize,
        a_vec: [usize; n],
    }

    let mut color_kinds: HashMap<usize, usize> = HashMap::new();
    for &a in a_vec.iter() {
        let kind = color(a);
        *color_kinds.entry(kind).or_insert(0) += 1;
    }

    let max_ans = color_kinds.get(&9).unwrap_or(&0) + color_kinds.keys().filter(|&x| *x != 9).count();


    let min_ans = if color_kinds.keys().filter(|&x| *x == 9).count() == 0 {
        color_kinds.keys().count()
    } else {
        if color_kinds.keys().filter(|&x| *x != 9).count() == 0 {
            1
        } else {
            color_kinds.keys().filter(|&x| *x != 9).count()
        }
    };

    println!("{} {}", min_ans, max_ans)
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);

int main(){
    ll x; cin >> x;
    ll ans=0;

    while(x>=500){
        x -= 500;
        ans+=1000;
    }
    while(x>=5){
        x -= 5;
        ans+=5;
    }
    cout << ans << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
	int N, M;
	scanf("%d %d", &N, &M);
	
	int R;
	
	if(N==1){
		R = M*(M-1)/2;
	}
	
	else if (M==1){
		R = N*(N-1)/2;
	}
	
	else R = N*(N-1)/2 + M*(M-1)/2;
	
	printf("%d",R);
	return 0;
}


Measured memory_bytes: 128
struct B{int w,s,v;}A[1111];
comp(a,b)struct B*a,*b;{return a->w+a->s-b->w-b->s;}
n,i,j;
long dp[22222],ans;
main(){
	scanf("%d",&n);
	for(;~scanf("%d%d%d",&A[i].w,&A[i].s,&A[i].v);i++);
	qsort(A,n,sizeof(struct B),comp);
	for(i=0;i<n;i++)
	{
		for(j=A[i].s;j>=0;j--)ans=fmax(ans,dp[j+A[i].w]=fmax(dp[j+A[i].w],dp[j]+A[i].v));
	}
	printf("%ld",ans);
}


Measured memory_bytes: 380
//
//  main.cpp
//  ABC 065 C
//
//  Created by Shuangyi Zhang on 2017/6/24.
//  Copyright © 2017年 Shuangyi Zhang. All rights reserved.
//

#include <iostream>
using namespace std;
const long long INF=1000000007;
int main() {
    int n,m,t;
    cin>>n>>m;
    if (n<m){
        t=n;
        n=m;
        m=t;
    }
   // cout<<n<<m;
    if ((n-m)>1){
        cout<<0<<endl;
        return 0;
    }

    long long ans=1;
    for (long long i=1;i<=m;i++){
        ans=(ans*i)%INF;
       // cout<<ans;
    }
   // cout<<ans;
    if ((n-m)==1){
        ans=(((ans*ans)%INF)*n)%INF;
    }else{
        ans=(2*ans*ans)%INF;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding = SJIS

k, s = map(int, input().split())
ans = 0

if s < k:
    ans = (s + 1) * (s + 2) / 2
elif s <= 2 * k:
    t = 2 * k - s
    a = (k + 1) * (k + 2) / 2
    b = t * (t + 1) / 2
    c = t * (2 * k - (t - 1)) / 2
    ans = a - b + c
elif s <= 3 * k:
    t = 3 * k - s + 1
    ans = t * (t + 1) / 2
print(int(ans))

Measured memory_bytes: 8976
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int arr[] = new int[n];
        long sum=0;
        for(int i=0;i<n;i++){
            arr[i]=s.nextInt();
            sum+=arr[i];
        }
        int q = s.nextInt();
        while(q--!=0){
            int x = s.nextInt(),price = s.nextInt();
            System.out.println(sum-arr[x-1]+price);
        }

    }


}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back()
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;

int dp[100000];
int solve(int n,int a[],int k)
{
	dp[0]=0;
	fff(i,1,n-1)
	{
		//racunamo dp[i]
		int min=abs(a[i]-a[i-1])+dp[i-1];
		fff(j,2,k)
		{
			if(i-j>=0)
			{
				int cost=dp[i-j]+abs(a[i]-a[i-j]);
				if(cost<min) min=cost;
			}
			else break;
		}
		dp[i]=min;
	}
	return dp[n-1];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	int a[n];
	fff(i,0,n-1) cin>>a[i];
	cout<<solve(n,a,k);
	
 	return 0;
}

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

int main()
{
	int N;
	while (cin >> N, N) {
		vector<string> L(N);
		vector<int> a(N), b(N);
		for (int i = 0; i < N; i++) {
			int P, A, B, C, D, E, F, S, M;
			cin >> L[i] >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			a[i] = F * S * M - P;
			b[i] = A + B + C + (D + E) * M;
		}
		vector<int> idx(N);
		iota(idx.begin(), idx.end(), 0);
		sort(idx.begin(), idx.end(), [&](int l, int r) {
			return a[l] * b[r] != a[r] * b[l] ? a[l] * b[r] > a[r] * b[l] : L[l] < L[r];
		});
		for (int i = 0; i < N; i++) {
			cout << L[idx[i]] << endl;
		}
		cout << '#' << endl;
	}
	return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
struct Node
{
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k)
{
  Node *y = NIL;  // parent node of x
  Node *x = root; // root node of the tree
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

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

void inorder(Node *u)
{
  if (u == NIL)
    return;
  inorder(u->left);
  cout << ' ' << u->key;
  inorder(u->right);
}

void preorder(Node *u)
{
  if (u == NIL)
    return;
  cout << ' ' << u->key;
  preorder(u->left);
  preorder(u->right);
}

int main()
{
  int N, x;
  string com;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> com;
    if (com == "insert")
    {
      cin >> x;
      insert(x);
    }
    else if (com == "print")
    {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
}



Measured memory_bytes: 26604
from collections import deque
import itertools, math
d,g = list(map(int,input().split()))
pc = [list(map(int,input().split())) for _ in range(d)]
g /= 100

#ans = sum([pc[x][0] for x in range(d)])
ans = float('inf')
for bit in range(1<<d):
  cnt = 0
  point = 0
  pat = set(range(1,d+1))
  
  for i in range(d):
    if bit & (1<<i):
      point += pc[i][0]*(i+1) + pc[i][1]//100
      cnt += pc[i][0]
      pat.discard(i+1)
  
  if point < g:
      next = max(pat)
      n = min(pc[next-1][0], math.ceil((g - point)/(next)))
      cnt += n
      point += n*(next)
    
  if point >= g:
      #print(ans,cnt)
      ans = min(ans,cnt)


print(ans)


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

using namespace std;
#define fre freopen("in.txt","r",stdin)
#define IO ios::sync_with_stdio(false)
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=3.1415926;
const int MOD=1e9+7;
const int N=1e3+5;
int main()
{
    int n;
    scanf("%d",&n);
    ll m,a,r,c,h;
    m=a=r=c=h=0;
    while(n--)
    {
        char s[15];
        scanf("%s",s);
        if(s[0]=='M') m++;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='C') c++;
        if(s[0]=='H') h++;
    }
    ll ans=m*a*c+m*a*r+m*a*h+a*r*c+a*r*h+r*c*h+a*c*h+m*r*c+m*r*h+m*c*h;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 764
n, a, b = map(int, input().split())

mod = 10**9 + 7

def nck(k):
    y, z = 1, 1
    for i in range(1, k+1):
        y = (y * (n+1-i)) % mod
        z = (z * pow(i, mod-2, mod)) % mod
    return (y*z) % mod

ans = (pow(2, n, mod) - 1 - nck(a) - nck(b)) % mod
print(ans)

Measured memory_bytes: 8988
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(long long int i = 0; i < (n); i++)



int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


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


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}




/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  /*文字列を種類ごと区切って配列にする*/
  string s;
  cin>>s;
  vector<string> v;
  long long int cnt=0,start;
  bool flag=true;
  for(long long int i=0;i<s.size();i++){
    if(flag){
      start=i;
      flag=false;
    }
    if(s[i]==s[i+1]){
      cnt++;
    }else{
      v.push_back(s.substr(start,cnt+1));
      cnt=0;
      flag=true;
    }
  }
 
  
  
  
    
    typedef pair<char, long long int> pair;
    vector<pair> p;
    
    for ( long long int i = 0; i < v.size(); ++i )
        p.push_back( pair( v[i][0], v[i].size() ) );
  
  long long int ans=0;
  
  if(p.size()==1){//例外
    ans+=p[0].second*(p[0].second+1)/2;
    cout<<ans<<endl;
    return 0;
  }
  
  
  if(p[0].first=='>' && p[p.size()-1].first=='>'){
    ans+=p[0].second;
    for(long long int i=0;i<(v.size()-1)/2;i++){
      ans+=max(p[(2*i)+1].second,p[(2*i)+2].second);
    }
  }else if(p[0].first=='>' && p[p.size()-1].first=='<'){
    ans+=p[0].second;
    ans+=p[p.size()-1].second;
    for(long long int i=0;i<p.size()/2-1;i++){
      ans+=max(p[(2*i)+1].second,p[(2*i)+2].second);
    }
  }else if(p[0].first=='<' && p[p.size()-1].first=='>'){
    
    for(long long int i=0;i<p.size()/2;i++){
      ans+=max(p[(2*i)].second,p[(2*i)+1].second);
    }
  }else if(p[0].first=='<' && p[p.size()-1].first=='<'){
    ans+=p[p.size()-1].second;
    for(long long int i=0;i<(p.size()-1)/2;i++){
      ans+=max(p[(2*i)].second,p[(2*i)+1].second);
    }
  }

  for(long long int i=0;i<v.size();i++){
    ans+=p[i].second*(p[i].second-1)/2;
  }
  
  cout<<ans<<endl;
  
  
  
  
}

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    vector<int> v(k);
    for(int i=0;i<k;i++) cin >> v[i];
    int ans = 0;
    for(int i=1;i<k;i++) ans = max(ans, v[i]-v[i-1]);
    ans = max(ans, v[0] + n - v[k-1]);
    cout << n - ans << "\n";
    return 0;
}



Measured memory_bytes: 1792
/*
 * C言語のサンプルプログラム - Webkaru
 * - 入力した文字がアルファベットの小文字か大文字かを判定 -
 */
#include<stdio.h>
 
int main(void){
 
  /* 文字 */
  char moji;
 
  /* 文字を入力 */
  scanf("%c", &moji);
 
  /* アルファベットの小文字か大文字かを判定 */
  if((moji>= 'a') && (moji<='z')){
    printf("a\n");
  }
  else if((moji>= 'A') && (moji<='Z')){
    printf("A\n");
  }
 
  return 0;
}


Measured memory_bytes: 1580
import sys
S = input()
ans = 0
ans += int(S)
pow2 = [1,2,4,8,16,32,64,128,256,512]
for i in range(1,pow2[len(S)-1]):
    v = []
    for j in range(9):
        if i&pow2[j]:
            v.append(j)
    v.append(10)
    j = -1
    for x in v:
        sys.stderr.write(str(j+1)+' '+str(x+1)+' '+ S[j+1:x+1] + '\n')
        ans += int(S[j+1:x+1])
        j = x
print(ans)


Measured memory_bytes: 3188
H, W = map(int, input().split())
A = []
answer = []
for _ in range(H):
    a = list(input())
    if("#" in a): A.append(a)


for a in list(zip(*A)):
    if("#" in a): answer.append(a)

for result in list(zip(*answer)): print("".join(result))

Measured memory_bytes: 3316
N = int(input())
B = list(map(int, input().split()))

base_lis = []
ans_lis = []  

for i in B:
    base_lis.append(i)
    base_lis.append(i)

ans_lis.append(base_lis[0])
base_lis.pop(0)
ans_lis.append(base_lis[-1])
base_lis.pop(-1)

for i in range(0,len(base_lis),2):
    ans_lis.append(min(base_lis[i],base_lis[i+1]))

print(sum(ans_lis))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
int n,k,q,a[2005],b[2005],ans=INF,c[2005],d[2005],t;
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<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int check(int x){
	for(int i=1;i<=n;++i) c[i]=a[i];
	int l=0; t=0;
	for(int r=1;r<=n;++r){
		if(c[r]>=x) continue;
		if(r-l-k>0){
			sort(c+l+1,c+r);
			for(int i=l+1;i<=r-k;++i) d[++t]=c[i];
		}
		l=r;
	}
	sort(c+l+1,c+n+1);
	if(n-l-k+1>0) for(int i=l+1;i<=n-k+1;++i) d[++t]=c[i];
	if(t>=q){
		sort(d+1,d+t+1);
		return d[q]-x;
	}
	else return INF;
}
int main(){
	n=read(),k=read(),q=read();
	for(int i=1;i<=n;++i) b[i]=a[i]=read();
	sort(b+1,b+n+1);
	for(int i=1;i<=n;++i) ans=min(check(b[i]),ans);
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a;
  cin>>n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
  }
  for(int i=0; i<n; i++){
    if(i==0){
      a=vec.at(i);
    } else{
      a=vec.at(a-1);
    }
    if(a==2){
      cout<<i+1<<endl; break;
    }
  }
  if(a!=2){cout<<-1<<endl;}
}

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

int main(){
  int w, a, b;
  cin >> w >> a >> b;
  if(a > b) swap(a, b);
  if(a + w >= b) cout << 0 << endl;
  else cout << abs(a + w - b) << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)
	if S[0:1] != "A" {
		fmt.Println("WA")
		return
	}
	cnt := 0
	wi := 2
	for i, v := range S[2 : len(S)-1] {
		if v == 'C' {
			cnt++
			wi += i
		}
	}
	if cnt != 1 {
		fmt.Println("WA")
		return
	}
	for i := 1; i < len(S); i++ {
		if i == wi {
			continue
		}
		w := S[i : i+1]
		if w != strings.ToLower(w) {
			fmt.Println("WA")
			return
		}
	}
	fmt.Println("AC")

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int 
int main() {
	// your code goes here
	lli t,d,l=0;
	cin>>t>>d;
	while(t--)
	{
		lli a,b;
		cin>>a>>b;
		if((a*a+b*b)<=d*d)
		l++;
		
	}
	cout<<l;
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void) {
	int N;
	int K;
	int min;
	int count = 0;
	scanf("%d %d", &N, &K);
	int A[N];
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
		if(A[i] == 1){
			min = i;
		}
	}
	count = (N - K) / (K-1)+1;
	if((N - K) % (K-1) != 0){
		count++;
	}

	printf("%d\n", count);

	return 0;
}

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

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

using namespace std;

int main() {
  int N; cin >> N;
  int a[111];
  rep(i, N) { cin >> a[i]; }
  int mi = 1<<28;
  REP(x, -100, 101) {
    int sum = 0;
    rep(i, N) {
      sum += (a[i] - x) * (a[i] - x);
    }
    if (mi > sum) {
      mi = sum;
    }
  }
  cout << mi << "\n";
}


Measured memory_bytes: 256
N,K = map(int,input().split())
points1 = []
points2 = []
for i in range(N):
	x,y = tuple((map(int,input().split())))
	points1.append((x,y))
	points2.append(y)
points1.sort()
points2.sort()

xDict = {}
index = 0
for x,y in points1:
	if index in xDict:
		if xDict[index] != x:
			index += 1
			xDict[index] = x
	else:
		xDict[index] = x

yDict = {}
index = 0
for y in points2:
	if index in yDict:
		if yDict[index] != y:
			index += 1 
			yDict[index] = y
	else:
		yDict[index] = y

nPoints = [[0 for j in range(len(yDict))] for i in range(len(xDict))]

for kx,vx in xDict.items():
	for ky,vy in yDict.items():
		exists = 1 if (vx,vy) in points1 else 0
		if kx == 0 and ky == 0:
			nPoints[kx][ky] += exists
		elif kx == 0 and ky > 0:
			nPoints[kx][ky] += nPoints[kx][ky-1] + exists
		elif kx > 0 and ky == 0:
			nPoints[kx][ky] += nPoints[kx-1][ky] + exists
		else:
			nPoints[kx][ky] += nPoints[kx-1][ky] + nPoints[kx][ky-1] - nPoints[kx-1][ky-1] + exists

ans = -1
for x1 in range(len(xDict)):
	for x2 in range(x1+1,-1,-1):
		for y1 in range(len(yDict)):
			for y2 in range(y1+1,-1,-1):
				point = nPoints[x1][y1]
				if x2 > 0:
					point -= nPoints[x2-1][y1]
				if y2 > 0:
					point -= nPoints[x1][y2-1]
				if x2 > 0 and y2 > 0:
					point += nPoints[x2-1][y2-1]
				if point >= K:
					area = (xDict[x1]-xDict[x2]) * (yDict[y1]-yDict[y2])
					if ans < 0:
						ans = area
					else:
						ans = min(ans, area)
					break
print(ans)

Measured memory_bytes: 3192
from fractions import gcd
import math


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    a = [int(input()) for i in range(n)]
    m = max(a)
    mi = a.index(m)
    m2 = max(a[:mi] + a[mi+1:])
    for i in range(n):
        if a[i] == m:
            print(m2)
        else:
            print(m)
main()


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n;
    cin >> n;
    cout << n/30 << " " << n%30*2 << endl;
    return 0;
}



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

int main() {
  int a,b;
  cin>>a>>b;
  
  if(a>=13){
    cout<<b<<endl;
  }
  if(a<=12&&a>=6){
    cout<<b/2<<endl;
  }
  if(a<=5){
    cout<<"0"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC088D()
{
	int H, W;
	cin >> H >> W;

	vector<vector<int> > grid(H, vector<int>(W));
	int nB = 0;
	for (int i = 0; i < H; ++i)
	{
		string str;
		cin >> str;
		for (int j = 0; j < W; ++j)
		{
			if (str[j] == '.')
			{
				grid[i][j] = 1000000;
			}
			else
			{
				++nB;
				grid[i][j] = -1;
			}
		}
	}

	if (grid[0][0] < 0 || grid[H - 1][W - 1] < 0)
	{
		cout << -1 << endl;
		return;
	}
	priority_queue<pair<int, pair<int, int> > > qu;
	qu.push({ 0,{0,0} });
	grid[0][0] = 0;
	vector < pair<int, int> > d = { {0,1},{0,-1},{1,0},{-1,0} };
	while (!qu.empty())
	{
		auto x = qu.top();
		int x0 = x.second.first;
		int y0 = x.second.second;
		int dist = x.first;
		qu.pop();
		for (auto& dx : d)
		{
			int x1 = x0 + dx.first;
			int y1 = y0 + dx.second;
			if (x1 == x0 && y1 == y0)
				continue;
			if (x1 < 0 || x1 >= H || y1 < 0 || y1 >= W)
				continue;
			int newDist = dist + 1;
			if (grid[x1][y1] <= newDist)
				continue;
			grid[x1][y1] = newDist;
			qu.push({ newDist,{x1,y1} });
		}
	}
	if (grid[H - 1][W - 1] == 1000000)
	{
		cout << -1 << endl;
		return;
	}
	int x = grid[H - 1][W - 1] + 1;
	int y = H * W - x - nB;
	cout << y << endl;
}
int main()
{
	ABC088D();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int ma = 0, mi = INF;
    rep(i, N) {
        ma = max(A[i], ma);
        mi = min(A[i], mi);
    }
    if(ma - mi > 1) {
        cout << "No" << endl;
    } else if(ma - mi == 0) {
        if(ma + 1 == N || (N / ma > 1)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        int m = 0;
        rep(i, N) {
            if(A[i] == mi)
                m++;
        }
        ma -= m;
        N -= m;
        if(ma > 0 && N / ma > 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3708
#include "omp.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <random>
#include <bitset>
#include <unordered_set>
#include <cassert>
#include <list>


using namespace std;

typedef long long ll;
typedef long double ld;


const int sze = 1e5 + 10;
const ll MOD1 = 1e9 + 7;

ll fact[sze];


inline ll MOD(ll v)
{
	return v % MOD1;
}


ll bin_pow(ll v, int pow)
{
	ll res = 1;

	while (pow)
	{
		if (pow & 1)
			res = MOD(res * v);

		pow >>= 1;

		v = MOD(v * v);
	}

	return res;
}


ll A(ll n, ll k)
{
	return MOD(fact[n] * bin_pow(fact[n - k], MOD1 - 2));
}


ll C(ll n, ll k)
{
	return MOD(fact[n] * bin_pow(MOD(fact[n - k] * fact[k]), MOD1 - 2));
}


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

	int n;
	cin >> n;

	vector<ll> values(n), next(n);
	for (int i = 0; i < n; ++i)
		cin >> values[i];

	int ind = n;
	for (int i = n - 1; i >= 0; --i)
	{
		next[i] = ind;

		if (values[i] != 0)
			ind = i;
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ll sum = 0, my_xor = 0;
		int j = i;
		while (j < n)
		{
			sum += values[j];
			my_xor ^= values[j];

			if (sum == my_xor)
			{
				ans += next[j] - j;
				j = next[j];
			}
			else
				break;
		}
	}

	cout << ans;

	return 0;
}

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

bool prime(ll n){
  bool x = true;
  for(ll k=2;k*k<=n;k++)
    if(n%k==0) x = false;
  if(n==1) x = false;
  return x;
}

int main(){
  ll N,i,ans;
  ans = 0;
  cin >> N;
  for(i=2;i*i<=N;i++)
    if(N%i==0 && prime(i)){
      ll count = 0;
      ll a = 0;
      while(N%i==0){
        N /= i;
        count++;
      }
      for(ll j = 1;j<=100;j++){
        a += j;
        if(a > count) break;
        ans++;
      }
    }
  if(prime(N)) ans++;
  cout << ans << endl;
}



Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;

public class Main {
	static FastScanner sc = new FastScanner();

	public static void main(String[] args) throws Exception {
		PrintWriter writer = new PrintWriter(System.out);
		while (true) {
			int R = sc.nextInt();
			if (R == 0) break;
			int C = sc.nextInt();
			int Q = sc.nextInt();
			int[][] G = new int[R][C];
			int[][] tr = new int[C][R];
			for (int i = 0; i < R; ++i) {
				for (int j = 0; j < C; ++j) {
					tr[j][i] = G[i][j] = sc.nextInt();
				}
			}
			int ru = 1;
			while (ru < C * 2) {
				ru *= 2;
			}
			int[][] row = new int[R][ru];
			for (int i = 0; i < R; ++i) {
				build(G[i], row[i]);
			}
			int cu = 1;
			while (cu < R * 2) {
				cu *= 2;
			}
			int[][] col = new int[C][cu];
			for (int i = 0; i < C; ++i) {
				build(tr[i], col[i]);
			}
			for (int i = 0; i < Q; ++i) {
				int R1 = sc.nextInt();
				int C1 = sc.nextInt();
				int R2 = sc.nextInt();
				int C2 = sc.nextInt();
				int ans = Integer.MAX_VALUE;
				if (R2 - R1 < C2 - C1) {
					for (int j = R1; j <= R2; ++j) {
						ans = Math.min(ans, get(row[j], 0, C1, C2 + 1, 0, ru / 2));
					}
				} else {
					for (int j = C1; j <= C2; ++j) {
						ans = Math.min(ans, get(col[j], 0, R1, R2 + 1, 0, cu / 2));
					}
				}
				writer.println(ans);
			}
		}
		writer.flush();
	}

	static void build(int[] in, int[] out) {
		for (int i = 0; i < in.length; ++i) {
			out[out.length / 2 - 1 + i] = in[i];
		}
		for (int i = in.length; i < out.length / 2; ++i) {
			out[out.length / 2 - 1 + i] = Integer.MAX_VALUE;
		}
		for (int i = out.length / 2 - 2; i >= 0; --i) {
			out[i] = Math.min(out[i * 2 + 1], out[i * 2 + 2]);
		}
	}

	static int get(int[] tree, int cur, int f, int e, int left, int right) {
		if (right <= f || e <= left) return Integer.MAX_VALUE;
		if (f <= left && right <= e) return tree[cur];
		int mid = (left + right + 1) / 2;
		return Math.min(get(tree, cur * 2 + 1, f, e, left, mid), get(tree, cur * 2 + 2, f, e, mid, right));
	}

	static class FastScanner {
		Reader input;

		FastScanner() {
			this(System.in);
		}

		FastScanner(InputStream stream) {
			this.input = new BufferedReader(new InputStreamReader(stream));
		}

		int nextInt() throws IOException {
			int sign = 1;
			int b = input.read();
			while ((b < '0' || '9' < b) && b != '-' && b != '+') {
				b = input.read();
			}
			if (b == '-') {
				sign = -1;
				b = input.read();
			} else if (b == '+') {
				b = input.read();
			}
			int ret = b - '0';
			while (true) {
				b = input.read();
				if (b < '0' || '9' < b) return ret * sign;
				ret *= 10;
				ret += b - '0';
			}
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  int s = 10,sum=0;
  rep(i,3){
    if (n%s == 1){
      sum++;
    }
    n=n/10;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int X;
    cin >> X;
    ll tmp = 130;
    rep(i, X) {
        FOR(j, -tmp, tmp + 1) {
            if (pow(i, 5) - pow(j, 5) == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4060
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   char b;
   cin >> b;

   if(b=='A') cout << 'T' << endl;
   else if(b=='C') cout << 'G' << endl;
   else if(b=='G') cout << 'C' << endl;
   else if(b=='T') cout << 'A' << endl;





   return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())

if H%3==0 or W%3==0:
  ans=0
else:
  ans=min(W,H)
  
for h in range(1,H):
  nans=max(abs(h*W-(H-h)*(W//2)),abs(h*W-(H-h)*(W-W//2)),abs((H-h)*(W//2)-(H-h)*(W-W//2)))
  ans=min(ans,nans)
for w in range(1,W):
  nans=max(abs(w*H-(W-w)*(H//2)),abs(w*H-(W-w)*(H-H//2)),abs((W-w)*(H//2)-(W-w)*(H-H//2)))
  ans=min(ans,nans)
print(ans)

Measured memory_bytes: 3064
A,B,C,D,E,F=map(int,input().split())

from itertools import product
w=[]
for i,j in product(range(F//(100*A)+1),range(F//(100*B)+1)):
    if 0<100*A*i+100*B*j<=F:
        w.append(100*A*i+100*B*j)
s=[]
for i,j in product(range(E*F//(100*C)+1),range(E*F//(100*C)+1)):
    if C*i+D*j<=E*(F//100):
        s.append(C*i+D*j)

w.sort()
s.sort()
ans=[]
for a in w:
    for b in s:
        if (a//100)*E>=b and a+b<=F:
            ans.append([a+b,b])
        else:
            break
ans.sort(key=lambda x:x[1]/(x[0]+x[1]),reverse=True)
print(ans[0][0],ans[0][1])


Measured memory_bytes: 128480
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	fast;
	int arr[3][3];
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j ++ )
		{
			cin >> arr[i][j];
		}
	}
	int n;
	cin >> n;
	int b[n];
	for(int i = 0 ; i < n ; i ++ )
	{
		cin >> b[i];
		for(int j = 0 ; j < 3 ; j ++ ){
			for(int k = 0 ; k < 3 ; k++ ){
				if(arr[j][k]==b[i]){
					arr[j][k]=-1;
				}
			}
		}
	}
	for(int i = 0 ; i < 3 ; i ++ ){
		int sum = 0;
		for(int j = 0 ; j < 3 ; j ++ ){
			if(arr[i][j]==-1)
			sum++;
		}
		if(sum==3){
			cout<<"Yes";return 0;
		}
	}
	for(int i = 0 ; i < 3 ; i ++ ){
		int sum = 0;
		for(int j = 0 ; j < 3 ; j ++ ){
			if(arr[j][i]==-1)
			sum++;
		}
		if(sum==3){
			cout<<"Yes";return 0;
		}
	}
	int sum = 0;
	for(int i = 0 ; i < 3 ; i ++ ){
		if(arr[i][i]==-1)
		sum++;
	}
	if(sum==3){
		cout<<"Yes";return 0;
	}
	if(arr[0][2]=-1 && arr[1][1]==-1 && arr[2][0]==-1){
		cout<<"Yes";return 0;
	}
	cout<<"No";
	
}





Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

char s[100005];

int main(){

	scanf("%s",s);

	int len=strlen(s);

	if(len%2==0){
		if(s[0]==s[len-1]){
			printf("First\n");
		}
		else{
			printf("Second\n");
		}
	}
	else{
		if(s[0]==s[len-1]){
			printf("Second\n");
		}
		else{
			printf("First\n");
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    ll tcurr=0, acurr=0;
    long i;
    for(i=0; i<n; i++) {
        ll t, a;
        scanf("%lld%lld", &t, &a );
        if(i==0) {
            tcurr=t;
            acurr=a;
        }
        else {
            if(t*acurr==a*tcurr) {
                continue;
            }
            long tmp = MAX((acurr-1)/a+1, (tcurr-1)/t+1);

            acurr= tmp*a;
            tcurr= tmp*t;
        }
    }
    printf("%lld\n", acurr+tcurr);


    return 0;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  int vec[n];
  for(int i=0;i<n;i++){
    vec[i]=0;
  }
  int x,y;
  for(int i=0;i<k;i++){
    cin>>x;
    for(int j=0;j<x;j++){
      cin>>y;
      vec[y-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(vec[i]==0){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3640
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
lst=[[0]*w for i in range(h)]
# yoko=[0,w-1]
# tate=[0,h-1]
now=[0,0]
muki=0
# print(lst)
def chech(x,y):
    if 0<=x<w and 0<=y<h:
        if lst[y][x]==0:
            return 1
        else:
            return 0
    else:
        return 0

while a:
    lst[now[1]][now[0]]=len(a)
    a[-1]-=1
    if a[-1]==0:
        a.pop()
    # print(a)
    # print(lst)
    # print(now)
    if muki==0:
        if chech(now[0]+1,now[1]):
            now[0]+=1
        else:
            if chech(now[0],now[1]+1):
                now[1]+=1
                muki=1
            else:
                break
    elif muki==1:
        if chech(now[0],now[1]+1):
            now[1]+=1
        else:
            if chech(now[0]-1,now[1]):
                now[0]-=1
                muki=2
            else:
                break
    elif muki==2:
        if chech(now[0]-1,now[1]):
            now[0]-=1
        else:
            if chech(now[0],now[1]-1):
                now[1]-=1
                muki=3
            else:
                break
    elif muki==3:
        if chech(now[0],now[1]-1):
            now[1]-=1
        else:
            if chech(now[0]+1,now[1]):
                now[0]+=1
                muki=0
            else:
                break
for i in range(h):
    print(*lst[i])

Measured memory_bytes: 69740
#include <stdio.h>
#include <string.h>

#define MAX 100001

int main(void){
  int i,j;

  char str[MAX];
  scanf(" %s",str);

  long ans[MAX];
  for(i=0;i<MAX;i++){
    ans[MAX]=0;
  }

  long r_num=0,l_num=0,repeat_place;
  for(i=0;i<strlen(str);i++){
    if(str[i]=='R'){
      if(l_num==0){
        r_num++;
      }else{
        if(l_num%2==0){
          ans[repeat_place]+=l_num/2;
          ans[repeat_place+1]+=l_num/2;
        }else{
          ans[repeat_place]+=l_num/2;
          ans[repeat_place+1]+=l_num/2+1;
        }
        l_num=0;
        r_num++;
      }
    }else{
      if(r_num==0){
        l_num++;
      }else{
        repeat_place=i-1;
        if(r_num%2==0){
          ans[repeat_place]+=r_num/2;
          ans[repeat_place+1]+=r_num/2;
        }else{
          ans[repeat_place]+=r_num/2+1;
          ans[repeat_place+1]+=r_num/2;
        }
        r_num=0;
        l_num++;
      }
    }
  }

  if(l_num%2==0){
    ans[repeat_place]+=l_num/2;
    ans[repeat_place+1]+=l_num/2;
  }else{
    ans[repeat_place]+=l_num/2;
    ans[repeat_place+1]+=l_num/2+1;
  }

  for(i=0;i<strlen(str);i++){
    printf("%ld ",ans[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 1280
from sys import stdin
import fractions

#最小公倍数
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

n,m = [int(x) for x in stdin.readline().rstrip().split()]
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
koubai = lcm(n,m)

if s[::koubai//m] == t[::koubai//n]:
    print(koubai)
else:
    print(-1)

Measured memory_bytes: 5344
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
typedef long long ll;
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=1e5+10,mod=1e9+7;
char s[maxn];
int tot[26];
int main(){
	int n=read();
	scanf("%s",s+1);
	ll sum=1;
	REP(i,1,n) tot[s[i]-'a']++;
	REP(i,0,25) sum=sum*(tot[i]+1)%mod;
	sum=(sum+mod-1)%mod;
	printf("%lld\n",sum);
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> dp(N + 1, INF);
    dp[0] = 0;
    rep(i, N) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (ll j = 6; i + j <= N; j *= 6) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
        for (ll j = 9; i + j <= N; j *= 9) {
            dp[i + j] = min(dp[i + j], dp[i] + 1);
        }
    }
    cout << dp[N] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
from collections import deque
H, W = map(int, input().split())
cy, cx = map(int, input().split())
dy, dx = map(int, input().split())
cy -= 1
cx -= 1
dy -= 1
dx -= 1
d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
S = [input() for _ in range(H)]

worps = [[float('inf')]*W for _ in range(H)]
q = deque([[cy, cx]])

worps[cy][cx] = 0
while q:
    y, x = q.popleft()
    worp = worps[y][x]

    for h, w in d:
        ny, nx = y+h, x+w
        if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == "." and worp < worps[ny][nx]:
            worps[ny][nx] = worp
            q.appendleft([ny, nx])

    worp += 1
    for h in range(-2+y, 3+y):
        for w in range(-2+x, 3+x):
            if 0 <= h < H and 0 <= w < W and S[h][w] == "." and worp < worps[h][w]:
                worps[h][w] = worp
                q.append([h, w])

ans = worps[dy][dx]
if ans != float('inf'):
    print(ans)
else:
    print(-1)


Measured memory_bytes: 114760
#include <stdio.h>
#include <string.h>


int min(int a,int b){
    if(a>=b)return b;
    else return a;
}
int powori(int a, int b){
    int ret=a;
    for(int i=0;i<b;i++){
        ret =ret *a;
    }
    if(b==0)ret =1;
    return ret;
}
int main(){
    int n,len;
    len = 0;
    char x[6];
    scanf("%d", &n);
    for(int i= 1;i<n+1;i++){
        snprintf(x,6,"%d",i);
        if(strlen(x) % 2 == 1)len++;
    }
    if(n==100000)
    len--;
    printf("%d",len);
    return 0;
}

Measured memory_bytes: 128
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())

    ans = 0
    for i in range(1, n+1):

        if i % 3 == 0:
            continue

        if i % 5 == 0:
            continue

        ans += i

    print(str(ans))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """15"""
        output = """60"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1000000"""
        output = """266666333332"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 72248
#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*res);
    x=(x*x);    
    y=y/2;
  }
  return res;
}

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

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


void solve(){
    int n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=k;i<=n+1;i++){
        ll f=i-1;
        ll mn=(f*(f+1))/2;
        f=n-i+1;
        ll mx=(f-1)*i;
        f=i;
        mx=mx+(f*(f+1))/2;
        //cout<<mx-mn+1<<" ";
        ans=(ans+(mx-mn+1))%hell;
    }
    cout<<ans%hell;
}


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

///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: 3648