akhauriyash/Code-Regression huggingface dataset:
// e
fn main() {
    input! {
     n: usize,
     x: usize,
     m: usize,
    }
    let mut nexts = vec![0; m];
    for i in 1..m {
        let next = i * i % m;
        nexts[i] = next;
    }

    let mut visited = vec![false; m];
    let mut res = 0;
    res += x;
    visited[x] = true;
    for i in 2..n + 1 {
        x *= x;
        x %= m;
        res += x;
        if visited[x] {
            // 閉路に入った
            let start = x;
            let mut cum: Vec<usize> = Vec::new();
            cum.push(0);
            let mut length = 0;
            let mut current = start;
            while true {
                current = nexts[current];
                length += 1;
                cum.push(cum.last().unwrap() + current);
                if current == start {
                    break;
                }
            }
            // 残り何周できるか
            let j = (n - i) / length;
            res += cum[length] * j;
            // 1周未満で何回移動できるか
            let k = (n - i) - j * length;
            res += cum[k];
            break;
        } else {
            visited[x] = true;
        }
    }

    println!("{}", res);
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


Measured memory_bytes: 3332
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
class Simple
{
    int N;
    int[] a;
    void Solve() {
        //input
        N = io.Int;
        a = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = io.Int;
        }
        //cal
        var dic = new Dictionary<int, int>();
        Action<int> add = (num) => {
            if (!dic.ContainsKey(num)) dic[num] = 0;
            dic[num]++;
        };
        for (int i = 0; i < N; ++i) {
            add(a[i] - 1);
            add(a[i]);
            add(a[i] + 1);
        }
        var ans = dic.Values.Max();
        //ret
        WriteLine(ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
        AutoFlush = false
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if (_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == "")
            st = ReadLine();
        if (st != null)
            _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else
            st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 22112
#include"bits/stdc++.h"
using namespace std;
int a[22][22];
int f[22][1<<21];
int n;
int lowbit(int x)
{
	return x&(-x);
}
int count1(int num)
{
	int ret=0;
	while(num)
	{
		num-=lowbit(num);
		ret++;
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<1<<n;j++)
		{
			if(count1(j)!=i)
				continue;
			for(int l=0;l<n;l++)
				if((j&(1<<l))&&a[i][n-l])
					f[i][j]=(f[i][j]+f[i-1][j^(1<<l)])%1000000007;
		}
	}
	printf("%d",f[n][(1<<n)-1]);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d.at(i);
  }
  std::sort(d.begin(), d.end());
  int aida = d.at((N / 2)) - d.at((N / 2) - 1);
  
  cout << aida << endl;
}

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

int main(){
	string s,t="2018";
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i<4)cout<<t[i];
		else cout<<s[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
using namespace std;
void divisor();
int a[205];
int main(int argc, char *argv[])
{
	int n;
	divisor();
	cin>>n;
	if(n<105)
	{
		printf("0\n");
		return 0;
	}
	else
	{
		int ans=0;
		for(int i=105;i<=n;i++)
			if(a[i]>=8)
				ans++;
		printf("%d\n",ans);
	}
	return 0;
}
void divisor()
{
	for(int i=105;i<=200;i+=2)
	{
		int l=1,r=i;
		while(l<r)
		{
			if(i%l==0)
			{a[i]+=2;r=i/l;}
			l++;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
vector<int> adj[N];
int dfs(int u){
    vector<int> below;
    for(int v : adj[u])
        below.push_back(dfs(v));
    sort(below.rbegin(),below.rend());
    int ans = 0;
    for(int i = 0; i < below.size(); ++i)
        ans = max(ans,below[i]+i+1);
//    cout << u << ' ' << ans << '\n';
    return ans;
}
int main(){
    int n;
    cin >> n;
    for(int i = 2; i <= n; ++i){
        int a;
        scanf("%d",&a);
        adj[a].push_back(i);
    }
    cout << dfs(1) << '\n';
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int,int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first 
#define s second 
using namespace std;
const int N=5e6+10;
const int mod=1e9+7;
int arr[N],iarr[N];
int logi(int n){int p=0;while(n/2){n=n/2;p++;}return p;}
int poww(int x,int y){int pro=1;while(y){if(y&1)pro=((pro%mod)*(x%mod)%mod);y=y>>1;x=((x%mod)*(x%mod)%mod);}return pro;}
int poww2(int x,int y){int pro=1;while(y){if(y&1)pro=pro*x;y=y>>1;x=x*x;}return pro;}
double poww1(double x,int y){double pro=1.000000000;while(y){if(y&1)pro=((pro)*(x));y=y>>1;x=((x)*(x));}return pro;}
map<int,int> mp1,mp2;
set<int> st;
int arr1[1000001],arr2[1000001];
/*

*/
void solve()
{
	int k;
	cin>>k;
	int curr=7,i,flag=0;
	for(i=0;i<=k;i++)
	{
		if(curr%k==0) 
		{
			flag=1;
			break;
		}
		curr = (curr*10+7)%k;
	}
	if(flag) cout<<i+1;
	else cout<<-1;
}

int32_t main()																																	
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
N, K = map(int,input().split())
a = list(map(int,input().split()))

white_start, black_start = 0, 0
white_sum, black_sum = 0, 0#K区間を白、黒にしたときの"損失"
for i in range(K):
  white_sum += max(-a[i],0)
  black_sum += max(a[i],0)
curr_white = white_sum
curr_black = black_sum

for i in range(N-K):
  curr_white += max(-a[i+K],0) - max(-a[i],0)
  curr_black += max(+a[i+K],0) - max(+a[i],0)
  if curr_white < white_sum :
    white_sum = curr_white
    white_start = i+1
  if curr_black < black_sum :
    black_sum = curr_black
    black_start = i+1
ans = 0
if white_sum < black_sum:#白塗りのほうがいい
  for i in range(N):
    if i < white_start or i >= white_start+K:
      ans += max(a[i],0)
    else: ans+=a[i]
  print(ans)
else:
  for i in range(N):
    if i < black_start or i >= black_start+K:
      ans += max(a[i],0)
  print(ans)

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

#define int long long

signed main(){
    int n, k;
    cin >> n >> k;
    int t = n/k;
    t = t*t*t;
    int a = 0;
    if(k % 2 == 0){
        a = (n + k/2) / k;
    	a = a*a*a;
    }
    cout << t + a;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
using ll = long long;
using namespace std;
 
int main(){
	string S;
	cin >> S;
	int N = stoi(S);
	int sum = 0;
	for( char s : S ){
		sum += s-'0';
	}
	cout << ( N%sum == 0 ? "Yes" : "No" ) << endl;
	return 0;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1275

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main()
{
	int N,K,M;

	while(cin >> N >> K >> M && N)
	{
		vector<int> stones;
		REP(i,1,N+1){
			stones.push_back(i);
		}

		int pos=M-1;
		while(stones.size() != 1)
		{
			stones.erase(stones.begin()+pos);
			pos = (pos - 1 + K) % stones.size();
		}
		cout << stones[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    for (int i = K;i < N;++i) {
        if (A[i] > A[i - K]) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 4764
import java.util.*;


public class Main {

	static void log(long i) {
		System.out.println(i);
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		long pos = sc.nextLong();
		long numBlue = sc.nextLong();
		long numRed = sc.nextLong();
		
		long cntLoop = pos / (numBlue+numRed);
		long base = (numBlue+numRed)*cntLoop;
		long dif = pos - base;
		long cntLast;

		if (dif < numBlue)
			cntLast = dif;
		else
			cntLast = numBlue;
		dif = cntLoop*numBlue+cntLast;
		
		sc.close();
		log(dif);
	}

	// test 2 B - String Palindrome
//	public static void main(String args[]) {
//		Scanner sc = new Scanner(System.in);
//		
//		long amount = sc.nextlong();
//
//		// 500
//		long c500=0;
//		c500 = amount/500;
//		
//		// 5
//		long c5 = (amount - (c500 * 500)) / 5;
//
//		// calc 螫峨＠縺?
//		log( c500 * 1000 + c5 * 5 );
//		
//		sc.close();
//	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main() {
  int n;
  	cin>>n;
  vector<long long int>vec(n);
  
  for(int i=0;i<n;i++){
	long long int a;
    	cin>>a;
    vec[i]=a;
  }
  
  sort(vec.begin(), vec.end());
  
  vector<long long int>A(n);
  vector<long long int>B(n);
  
  A[0]=vec[0];
  B[n-1]=vec[n-1];  
  
    for(int j=1;j<n;j++){
	A[j]=__gcd(A[j-1],vec[j]);
     }
  
  for(int j=n-2;j>=0;j--){
    B[j]=__gcd(B[j+1],vec[j]);
  }
  vector<long long int>C(n);
  C[0]=B[1];
  C[n-1]=A[n-2];
  for(int i=1;i<n-1;i++){
    C[i]=__gcd(B[i+1],A[i-1]);
}
  sort(C.begin(), C.end());
  cout<<C[n-1]<<endl;
}


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

int main() {
  int n,k,count,ans;
  count = 0; ans = 0;
  string s;
  cin >> n >> k >> s;
  rep(i,n-1) {
    if(s[i] == 'R' && s[i+1] == 'L') count++;
  }
  if(s[0] == 'R' && s[n-1] == 'L') {
    ans = count*2;
    rep(i,k) {
      if(ans == 2) {
        ans--;
        break;
      }
      ans -= 2;
    }
  }else if(s[0] == 'R' || s[n-1] == 'L'){
    ans = count*2 + 1;
    rep(i,k) {
      if(ans == 1) {
        break;
      }
      ans -= 2;
    }
  }else {
    ans = count*2 + 2;
    rep(i,k) {
      if(ans == 2) {
        ans--;
        break;
      }
      ans -= 2;
    }
  }
  cout << (n - ans) << endl;
  return 0;
}

Measured memory_bytes: 512
import           System.IO hiding (char8)
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Tuple
import           Data.Int
import           Data.Char
import           Data.Maybe
import qualified Data.ByteString.Char8 as BS
import           Debug.Trace

-- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + --

main :: IO ()
main = do  
  (k, s) <- readInt2 <$> BS.getLine
  print $ f (k, s)

f :: (Int, Int) -> Int
f (k, s) = length r
  where
    r = [(x, y) | x <- [0..k], y <- [0..k], s - (x + y) <= k, s - (x + y) >= 0]
 
-- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + --

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt 
 
readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readIntN
 
readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words
 
toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

Measured memory_bytes: 764
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B;
    string S;
    cin >> A >> B >> S;

    if(S[A] != '-'){
        cout << "No" << endl;
        return 0;                
    }

    for(ll i = 0; i < A + B + 1; i++){
        if(i != A){
            if(!(S[i] >= '0' && S[i] <= '9')){
                cout << "No" << endl;
                return 0;     
            }
        }
    }

    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main(){

  int x,y;

  cin >> x >> y;

  if( (y < 2 * x) || ((y - 2 * x) % 2 != 0) || (4 * x < y) || ((4 * x - y) % 2 != 0)){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  
  
  return 0;
  

  
}


Measured memory_bytes: 3596
import sys
def main():
    input = sys.stdin.readline
    S = input().rstrip()
    Q = int(input())
    prefix = []
    suffix = []
    reverse = False
    for _ in range(Q):
        q = input().rstrip().split()
        if q[0] == '1': reverse = not reverse
        else:
            is_pre = (q[1] == '1' and reverse == False) or (q[1] == '2' and reverse)
            if is_pre:
                prefix.append(q[2])
            else:
                suffix.append(q[2])

    if reverse:
        S = S[::-1]
        prefix, suffix = suffix, prefix
    prefix.reverse()
    print(''.join(prefix) + S + ''.join(suffix))

if __name__ == '__main__':
    main()

Measured memory_bytes: 59216
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}


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

class Main {

    public static void main( String[] args ) {
        try {
	      	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
			int n = Integer.parseInt( kb.readLine( ) );        
			ArrayDeque<Integer> dq = new ArrayDeque<Integer>( );
            String[] str;
            for( int i=0; i<n; i++ ) {
                str = kb.readLine().split( " " );
                if( "insert".equals( str[0] ) ) {
                    dq.addFirst( Integer.parseInt( str[1] ) );
                } else if( "deleteFirst".equals( str[0] ) ) {
                    dq.removeFirst( );
                } else if( "deleteLast".equals( str[0] ) ) {
                    dq.removeLast(  );
                } else {
                    dq.removeFirstOccurrence( Integer.parseInt( str[1] ) );
                }
            }
        	
			StringBuilder output = new  StringBuilder( );
            for( Iterator itr = dq.iterator( ); itr.hasNext( ); ) {
                output.append( itr.next( ) ).append( " " );
            }
            output.deleteCharAt( output.lastIndexOf( " " ) );
            System.out.println( output );
            
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 561144
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //string[] s =Console.ReadLine().Split(',');

            //int w = int.Parse(s[0]);
            //List<string> stringList1 = new List<string>();
            //List<string> stringList2 = new List<string>();

            for (int i = 0; ; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0]);
                int b = int.Parse(s[1]);


                if ((a == 0) && (b == 0)) break;

                if (a < b)
                {
                    Console.WriteLine(a + " " + b);
                }
                else
                {
                    Console.WriteLine(b + " " + a);
                }
            }

            //int n =int.Parse(s);
        }
    }
}

Measured memory_bytes: 5772
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		x: isize,
	}

	if x >= 30 {
		println!("Yes");
	}
	else {
		println!("No");
	}
}



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

#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define foreach(i, k, n) for (int i = (k); (i) < (n); ++(i))
#define check(x) cout << #x "=" << x << endl;
#define checkpair(x, y) cout << #x "=" << x << ", " #y "=" << y << endl;

const int INF = 1001001001;

int main()
{
    int n;
    cin >> n;
    bool ok = false;
    foreach(i, 1, 10)
    foreach(j, 1, 10){
        if (n == i*j){
            ok = true;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


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

int main(void)
{
    int x, y, z, tmp;
    cin >> x >> y >> z;

    swap(x, y);
    swap(x, z);

    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <set>
#include <map>
#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>

using namespace std;

int m,f,r;//中間試験の点数、期末テストの点数、再試験の点数、試験を受けてない場合は-1

int main()
{
  while(scanf("%d %d %d",&m,&f,&r)){
    if(m == -1&& f == -1 && r== -1){
      break;
    }
    if(m == -1||f== -1){
      cout <<"F"<<endl;
    }
    else if(m+f >=80)
      cout <<"A"<<endl;
    else  if(m+f>=65 &&m+f<80)
      cout <<"B"<<endl;
    else if(m+f >=50&&m+f<65)
      cout <<"C"<<endl;
    else if(m+f >=30&&m+f<50){
      if(r>=50){
	cout <<"C"<<endl;
      }else
	cout <<"D"<<endl;
    }
    else if(m +f <30){
      cout <<"F"<<endl;
    }
  }
  return 0;
}

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

int a[111][111];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, k; cin >> n >> k;
  vector<int> cnt(n + 1, 0);
  for (int i = 0; i < k; ++i){
    int x, y; cin >> x;
    for (int j = 0; j < x; ++j) cin >> y, cnt[y]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i){
    ans += cnt[i] == 0;
  }
  cout << ans;
}



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

int main() {
  int a, b;
  cin >> a;
  int KYR, WAYO, YUNI, MRS;
  double YABAI;
  KYR = 0;
  int ZUN;
  ZUN = 0;
  YUNI = 0;
  int EKSA = 0;
  int RIM;
  int d;
  d = 2;
  RIM = 0;
  KYR = a + 1;
  
  vector<double> OOTJNY(200);
  for(int PKRN = 0; PKRN < 200;){
    for(int TOMIO = 0; TOMIO < a; TOMIO++){
    cin >> OOTJNY.at(TOMIO);
     }
     OOTJNY.at(ZUN) /= 2;
     WAYO = OOTJNY.at(ZUN);
      if(OOTJNY.at(ZUN) != WAYO){
       cout << YUNI << endl;
       EKSA = 1;
       break;
       }
        else if(OOTJNY.at(ZUN) == 0){
         MRS ++;
        }
      
      if(OOTJNY.at(ZUN) == WAYO){
      RIM ++;
      ZUN ++;
       if(ZUN == a){
         ZUN = 0;
       }
       if(RIM == a){
       RIM = 0;
       d *= 2;
       PKRN ++;
       YUNI ++;
       }
      }
    else if(MRS == a){
      cout << YUNI << endl;
      EKSA = 1;
      break;
    }
    }
  
  if(EKSA == 0){
    cout << YUNI << endl;
  }
}


Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin >> str;
	int size = str.size();
	vector<int> X(4,0);
	for(int i=0;i<size;++i){
		switch( str[i] ){
		case 'N':X[0]++;break;
		case 'W':X[1]++;break;
		case 'S':X[2]++;break;
		case 'E':X[3]++;break;
		}
	}
	bool flagX = false;
	bool flagY = false;
	if( (X[0] && X[2]) || (X[0]==0 && X[2]==0)){
		flagX = true;
	}
	if( (X[1] && X[3]) || (X[1]==0 && X[3]==0)){
		flagY = true;
	}
	if( flagX && flagY ){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

count = sum(B)

for i in range(N-1):
    if A[i + 1] - A[i] == 1:
        count += C[A[i] - 1]

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

ll euclidean_gcd(ll a, ll b) {
    if (a < b) return euclidean_gcd(b, a);
    ll r;
    while(r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a / euclidean_gcd(a, b) *  b;
}

int main()
{
    int N;
    cin >> N;
    ll ans = 1LL;
    rep(i, 0, N) {
        ll T;
        cin >> T;
        ans = lcm(ans, T);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n;
  cin >> n;
  vector<ll> x(n), l(n);
  repr(i, n, 0) cin >> x[i] >> l[i];
  using pl = pair<ll, ll>;
  vector<pl> rng;
  rng.reserve(n);
  for (int i = 0; i < n; ++i) {
    pl p {x[i] + l[i], x[i] - l[i]};
    rng.push_back(p);
  }
  sorti(rng);
  ll cnt = 0;
  pl now = rng.front();
  for (int i = 1; i < n; ++i) {
    pl next = rng[i];
    if (next.second >= now.first) {
      now = next;
    } else {
      cnt ++;
    }
  }

  cout << n - cnt << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
int n,k;
char s[252521];
 
int main(){
  scanf("%d%d",&n,&k);
  scanf("%s",s);
bitset<200000> yo;
  REP(i,n)if(s[i]=='B')yo.set(i);
 
  int head = 0;
  bool flip = false;
  while(k--){
    if(yo.test(head)^flip){
      // head is b
      flip ^= true;
      if(++head==n)head=0;
    }else{
      yo.flip(head);
    }
  }
  REP(i,n)putchar(yo[(head+i)%n]^flip?'B':'A');
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
 
long main(){
  long n,m,x;
  scanf("%ld %ld",&n,&m);
  x = m-2*n;
  if(x>=0){
    printf("%ld\n",n+(x/4));
  }else{
    printf("%ld\n",m/2);
  }
  return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int>h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        if(h[i] >= K) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
struct edge {int from, to, cost; };

int main() {
  int n, m;
  cin>>n>>m;

  edge es[m];
  for (int i=0; i<m; i++) {
    int a, b, c;
    cin>>a>>b>>c;
    --a;
    --b;
    edge e = {a, b, -c};
    es[i] = e;
  }
  long long d[n];
  long long INF = (long long)1e12;
  for (int i=0; i<n; i++) d[i] = INF;

  d[0] = 0;
  long long ans = 0;
  for (int i=0; i<2 * n; i++) {
    for (auto e: es) {
      if (d[e.from] == INF) {
        continue;
      }
      if (d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
      }
    }
    if (i == n - 1) ans = d[n-1];
    if (i == 2 * n - 1) {
      if (ans > d[n-1]) {
        cout<<"inf"<<endl;
        return 0;
      }
    }
  }
  cout<<-ans<<endl;

}

Measured memory_bytes: 256
from collections import defaultdict
N,K=map(int,input().split())

dtlist=[]
tset_all=set()
for i in range(N):
  t,d=map(int,input().split())
  dtlist.append((d,t))
  tset_all.add(t)
dtlist.sort()
#print(heapq)

dtlist_Krev=[]
dsum=0
tdic=defaultdict(int)
for i in range(K):
  d,t=dtlist.pop()
  dtlist_Krev.append((d,t))
  dsum+=d
  tdic[t]+=1
dtlist_Krev.sort(reverse=True)

t0=len(tdic)
max_answer=dsum+(t0**2)
#print(t0,max_answer)

for i in range(t0+1,min(K,len(tset_all))+1):
  loop_flg=True
  while(loop_flg):    
    d,t=dtlist_Krev.pop()
    if tdic[t]>1:
      tdic[t]-=1
      dsum-=d
      
      while(True):        
        d2,t2=dtlist.pop()
        if tdic[t2]==0:
          tdic[t2]=1
          dsum+=d2
          loop_flg=False
          break
          
  answer_i=dsum+(i**2)
  #print(i,answer_i)
  max_answer=max(max_answer,answer_i)
  
print(max_answer)

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


int main(){


    long long int t;
    double a;

    cin>>t>>a;

    int ans=0;

    while(t--){
        long long b,c;
        cin>>b>>c;

        b=b*b;
        c=c*c;

        c=c+b;

        double z=sqrt(c);

        if(z<=a)
            ans++;
    }

    cout<<ans<<endl;






    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<string> data(n);
    for(int i=0; i<data.size(); i++) cin >> data.at(i);

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    for(int i=0; i<data.size(); i++){
        if(data.at(i) == "AC") ac++;
        else if(data.at(i) == "WA") wa++;
        else if(data.at(i) == "TLE") tle++;
        else re++;
    }

    cout << "AC" << " " << "x" << " "  << ac << endl;
    cout << "WA" << " " << "x" << " "  << wa << endl;
    cout << "TLE" << " " << "x" << " "  << tle << endl;
    cout << "RE" << " " << "x" << " "  << re << endl;
}

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

int main() {
  int k,s,z;
  cin >> k >> s;
  int ans = 0;
  rep(x, k+1){
    rep(y, k+1){
      z = s-x-y;
      if(0<=z && z<=k) ans++;
    }
  } 
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int shuffle(int card[201], int n){
	int a[101], b[101], aa = 0, bb = 0;
	for(int i = 0;i < n;i++)a[i] = card[i];
	for(int i = 0;i < n;i++)b[i] = card[i+n];
	for(int i = 0;i < 2*n;i++){
		card[i] = a[aa++];i++;
		card[i] = b[bb++];
	}
	return 0;
}

int cut(int card[201], int k, int n){
	int a[200], b[200];
	for(int i = 0;i < k;i++)a[i] = card[i];
	for(int i = k;i < 2*n;i++)b[i-k] = card[i];
	for(int i = 0;i < 2*n-k;i++)card[i] = b[i];
	for(int i = 0;i < k;i++)card[(2*n-k)+i] = a[i];
	return 0;
}

int main(){
	int n, m, k, card[201];
	scanf("%d %d", &n, &m);
	for(int i = 0;i < 2*n;i++)card[i] = i+1;
	for(int i = 0;i < m;i++){
		scanf("%d", &k);
		if(k)cut(card, k, n);
		else shuffle(card, n);
	}
	for(int i = 0;i < n*2;i++)printf("%d\n", card[i]);
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<vector<ll>> prod(vector<vector<ll>>& a, vector<vector<ll>>& b, ll mod) {
    vector<vector<ll>> ret(a.size(),vector<ll>(b[0].size(),0));
    for (int i = 0;i < a.size();++i) for (int j = 0;j < b[0].size();++j) for (int k = 0;k < a[0].size();++k) {
        ret[i][j] += a[i][k]*b[k][j];
        ret[i][j] %= mod;
    }
    return ret;
}

int main() {
    ll l,a,b,m;
    cin >> l >> a >> b >> m;
    // m = 1e18;
    l--;
    vector<ll> c(20,0);
    for (int i = 0;i < 19;++i) {
        ll d = 1;
        for (int j = 0;j < i;++j) d *= 10;
        c[i] = max(0LL,(d-a-1)/b);
    }
    c[19] = 2e18;
    vector<vector<ll>> x(3,vector<ll>(1,0)),y(3,vector<ll>(3,0));
    x[0][0] = x[1][0] = a%m;
    x[2][0] = b%m;
    for (int i = 1;i < 20;++i) {
        ll d = 1;
        for (int j = 0;j < i;++j) (d *= 10) %= m;
        y[0][1] = y[0][2] = y[1][1] = y[1][2] = y[2][2] = 1;
        y[0][0] = d;
        // for (int j = 0;j < 3;++j) p_ary(y[j],0,3,k);
        // for (int j = 0;j < 3;++j) p_ary(x[j],0,1,k);
        ll z = min(l,c[i])-c[i-1];
        // cout << z << endl;
        while (z > 0) {
            if (z&1) x = prod(y,x,m);
            y = prod(y,y,m);
            z >>= 1;
        }
        // for (int j = 0;j < 3;++j) p_ary(y[j],0,3,k);
        // for (int j = 0;j < 3;++j) p_ary(x[j],0,1,k);
        if (l <= c[i]) break;
    }
    cout << x[0][0] << endl;
    // for (int i = 0;i < 20;++i) cout << a+b*c[i] << " " << a+b*(c[i]+1) << endl;
    // p_ary(c,0,20,i);
}

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

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int N = 1e6 + 7;
const ll mod = 1e9 + 7;

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

int n;
ll s[N];
pair < ll , int > d[N];
ll dd[N];
ll p[N];
vector < int > v[N];
map < ll , int > m;

void dfs( int x , int p )
{
    s[x] = 1;
    for( auto y : v[x] ){
        if( y == p )continue;
        dfs( y , x );
        s[x] += s[y];
    }
}

void foo( int x , int p , int val )
{
    dd[1] += val;
    for( auto y : v[x] ){
        if( y == p )continue;
        foo( y , x , val + 1 );
    }
}

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

    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> d[i].fi;
        d[i].se = i;
        m[d[i].fi] = i;
    }
    sort( d + 1 , d + n + 1 );
    reverse( d + 1 , d + n + 1 );
    for( int i = 1; i < n; i++ ){
        int x = d[i].se;
        ll sum = d[i].fi + 2 * s[x] + 2 - n;
        if( m.find(sum) == m.end() || sum > d[i].fi ){
            cout << "-1\n";
            return 0;
        }
        int y = m[sum];
        v[x].push_back(y);
        v[y].push_back(x);
        s[y] += s[x] + 1;
    }
    dfs( 1 , 1 );
    foo( 1 , 1 , 0 );
    queue < int > g;
    g.push(1);
    vector < int > used(n + 1,  0);
    used[1] = 1;
    while( !g.empty() ){
        int x = g.front();
        g.pop();
        for( auto y : v[x] ){
            if( used[y] ){
                if( p[x] == y )continue;
                if( dd[y] != dd[x] - s[y] + (n - s[y]) ){
                    cout << "-1\n";
                    return 0;
                }
            }else{
                p[y] = x;
                used[y] = true;
                g.push(y);
                dd[y] = dd[x] - s[y] + n - s[y];
            }
        }
    }
    sort( d + 1 , d + n + 1 , [&](pair < ll , int > a, pair < ll , int > b ){
        return a.se < b.se;
    });
    for( int i = 1; i <= n; i++ ){
        if( d[i].fi != dd[i] ){
            cout << "-1\n";
            return 0;
        }
        used[i] = 0;
    }
    for( int i = 1; i <= n; i++ ){
        used[i] = 1;
        for( auto x : v[i] ){
            if( used[x] )continue;
            cout << i << " " << x << "\n";
        }
    }
}


Measured memory_bytes: 48044
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            bool1 = i > 0 and s[i - 1][j] == "#"
            bool2 = i < H-1 and s[i+1][j] == "#"
            bool3 = j > 0 and s[i][j - 1] == "#"
            bool4 = j < W-1 and s[i][j + 1] == "#"
            if bool1 or bool2 or bool3 or bool4:
                continue
            else:
                print("No")
                exit()

print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// 型エイリアス
using pii = pair<int, int>;
using tisb = tuple<int, string, bool>;
using vi = vector<int>;
using vii = vector<vi>;

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

  int minv=R[0], maxv=-pow(10, 9);
  
  // i=0から始めるとmaxvを出しようがなくておかしくなる
  for(int i=1; i<N; ++i){
    maxv = max(maxv, R[i]-minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
if 2*n>=m:
    print(m//2)
else:
    x=(m-2*n)//4
    ans=min(n+x,(m-2*x)//2)
    x+=1
    anser=min(n+x,(m-2*x)//2)
    print(max(ans,anser))



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

#define N 100

int x[100];

int main()
{
	int n, k;

	cin >> n >> k;
	for( int i = 0; i < n; i++ ) {
		cin >> x[i];
	}

	int ans = 0;
	for( int i = 0; i < n; i++ ) {
		ans += min( x[i] * 2, abs(x[i] - k) * 2 );
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	vector<int> A(h*w, 0);
	vector<int> Ar(h*w + 1, 0);
	for (int i = 0; i < h*w; ++i) {
		cin >> A[i];
		Ar[A[i]] = i;
	}
	int q, l, r;
	cin >> q;
	vector<int> dp(h*w+1, 0);
	for (int i = 1; i <= d; ++i) {
		dp[i] = 0;
		int j = i;
		while (j+d <= h*w) {
			int src = Ar[j];
			int dst = Ar[j+d];
			int inc = abs((src%w) - (dst%w))
				+ abs(src / w - dst / w);
			dp[j + d] = dp[j] + inc;
			j += d;
		}
	}
	for (int i = 0; i < q; ++i) {
		cin >> l >> r;
		int cost = dp[r] - dp[l];
		cout << cost << endl;
	}
}

Measured memory_bytes: 2176
from copy import copy
s = list(input())

a = int((len(s) - 1)/2)
b = int((len(s) + 3)/2)
sa = s[:a]
sb = s[b-1:]

judge1 = s[::-1] == s
judge2 = sa[::-1] == sa
judge3 = sb[::-1] == sb

if judge1 and judge2 and judge3:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3444
def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  if N == 0 and A[0] != 1:
    print(-1)
    return True
  min_maxs = [0] * len(A)
  min_maxs[len(A)-1] = [A[-1], A[-1]]

  for index in reversed(range(len(A)-1)):
    min_maxs[index] = [min_maxs[index+1][0] // 2 + A[index], min_maxs[index+1][1] + A[index]]

  result = 1
  recent = 1
  for index in range(1, len(A)):
    num_of_node = (recent - A[index-1]) * 2
    if num_of_node < min_maxs[index][0]:
      print(-1)
      return True
    
    result += min(num_of_node, min_maxs[index][1])
    recent = min(num_of_node, min_maxs[index][1])

  print(result)

if __name__ == "__main__":
    resolve()

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0);

    ll d, n;
    cin >> d >> n;

    ll x = 1;
    while (d--) x *= 100;

    ll i;
    for (i = 1; n; ++i)
    	if (i % x == 0 && i/x%100 != 0)
    		--n;

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

    return 0;
}


Measured memory_bytes: 256
H, W = map(int,input().split())
s = []
black = 0
for i in range(H):
    tmp = list(input())
    s.append(tmp)
    for j in range(W):
        if tmp[j] == "#":
            black += 1
white = H*W - black
 
 
q = [(0,0,0)]
s[0][0] = "#"
while q:
    i, j, cnt = q.pop(0)
    for di, dj in [(1,0),(0,1),(-1,0),(0,-1)]:
        ni, nj = i+di, j+dj
        if ni == H-1 and nj == W-1:
            print(white-cnt-2)
            exit(0)
        elif 0 <= ni < H and 0 <= nj < W and s[ni][nj] == ".":
            s[ni][nj] = "#"
            q.append((ni,nj,cnt+1))
print(-1)

Measured memory_bytes: 3064
void main()
{
    long k = rdElem;
    string s = rdStr;

    if (s.length <= k) s.writeln;
    else writeln(s[0..k], "...");
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 2720
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

s, = read_line(str)

s = [int(c) for c in s]

c = 0

ss = 0

for i in range(0, len(s)):
    if s[i] == 1:
        if ss < 0:
            c += 2
        ss += 1
    else:
        if ss > 0:
            c += 2
        ss -= 1
print(c)


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

int main()
{
	int n, m;
  	cin >> n >> m;
  
  	vector<int> a(2*m);
  	vector<int> cnt(n);
  	for (int i=0; i<2*m; i++) {
    	cin >> a.at(i);
		cnt.at(a.at(i) - 1)++;
    }
  
  	for (int i=0; i<n; i++)
      cout << cnt.at(i) << endl;
}
        
  

Measured memory_bytes: 256
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

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

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var a, b, t int
	fmt.Fscan(read, &a, &b, &t)

	ans := 0
	for time := a; time <= t; time = time + a {
		ans = ans + b
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//#define mod 1000000007
#define inf 1e18
ll mod(ll x)
{
	if(x<0)
	return -x;
	else
	return x;
}
int main()
{
  ll n;
  cin>>n;
  ll k;
  cin>>k;
  ll h[n]={0};
  for(ll i=0;i<n;i++)
  {
  	cin>>h[i];
  }
  ll dp[n]={0};
  dp[0]=0;
  for(ll i=2;i<n;i++)
  {
  	dp[i]=inf;
  }
  dp[1]=mod(h[1]-h[0]);
  for(ll i=2;i<n;i++)
  {
  	for(ll j=i-k;j<i;j++)
  	{
  		    if(j>=0)
		  dp[i]=min(dp[j]+mod(h[i]-h[j]),dp[i]);
	}
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
value = input().split()
value_1 = [int(n) for n in value]

sea = value_1[0]
mou = value_1[1]

while sea != mou:
    if sea<mou:
        sea = sea+value_1[0]
    else:
        mou = mou+value_1[1]

print(sea)


Measured memory_bytes: 2940
n=gets.to_i
a=gets.split.map(&:to_i)
b=[1000000]*n
(n-1).times do |i|
    b[i] = a[i]   if a[i]<b[i]
    b[i+1] = a[i] if a[i]<b[i+1]
end
p b.inject(:+)


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

N = int(readline())
A = [None] + list(map(int, readline().split()))

ans = 1000
dp = [0]*(N+1)
dp[0] = 1000
for i in range(1, 1+N):
    a = A[i]
    res = 1000
    for j in range(1, i):
        res = max(res, dp[j], dp[j] % A[j] + (dp[j]//A[j])*A[i])
    dp[i] = res

print(dp[N])

Measured memory_bytes: 66500
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int n, m, k, ans(0);
char a[10][10];
bool f[20];
vector<pair<int, int>> v;

void dfs(int x) {
    if (x > n + m) {
        int tot = 0;
        for (auto i : v)
            if (!f[i.first] && !f[i.second + n])
                tot++;
        ans += (tot == k);
        return;
    }
    f[x] = 0;
    dfs(x + 1);
    f[x] = 1;
    dfs(x + 1);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i][j] == '#')
                v.push_back({i, j});
    dfs(1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int n,m,c,s,g;
LL dp[25][101][101];
LL d[101][101];
LL x[100001];
LL y[100001];
LL dis[100001];
LL cam[100001];
LL p[101];
LL q[101][101];
LL r[101][101];

LL calc(int cc,LL val){
	LL now=r[cc][0];
	LL t=0;
	LL ans=0;
	REP(i,val){
		if(t==p[cc]-1){
			ans+=now;
			continue;
		}
		if(i>=q[cc][t]){
			now=r[cc][t+1];
			t++;
		}
		ans+=now;
	}
	//cout<<cc<<" cam"<<val<<" "<<ans<<endl;
	return ans;
}

int main(){
	while(cin>>n>>m>>c>>s>>g){
		if(n==0&&m==0&&c==0&&s==0&&g==0){
			break;
		}
		
		s--;
		g--;
		REP(i,25){
			REP(j,101){
				REP(k,101){
					dp[i][j][k]=1e17;
				}
			}
			REP(j,101){
				dp[i][j][j]=0;
			}
		}
		
		REP(i,101){
			REP(j,101){
				d[i][j]=1e17;
			}
			d[i][i]=0;
		}
		REP(i,m){
			cin>>x[i]>>y[i]>>dis[i]>>cam[i];
			x[i]--;
			y[i]--;
			dp[cam[i]][x[i]][y[i]]=min(dp[cam[i]][x[i]][y[i]],dis[i]);
			dp[cam[i]][y[i]][x[i]]=min(dp[cam[i]][y[i]][x[i]],dis[i]);
		}
		REP(i,c){
			cin>>p[i];
		}
		REP(i,c){
			REP(j,p[i]-1){
				cin>>q[i][j];
			}
			REP(j,p[i]){
				cin>>r[i][j];
			}
		}
		REP(l,25){
			REP(k,101){
				REP(i,101){
					REP(j,101){
						dp[l][i][j]=min(dp[l][i][j],dp[l][i][k]+dp[l][k][j]);
					}
				}
			}
		}
		/*
		REP(i,5){
			REP(j,5){
				REP(k,5){
					cout<<dp[i][j][k]<<" ";
				}
				cout<<endl;
			}
			cout<<endl;
		}*/
		
		
		REP(l,25){
			REP(i,101){
				REP(j,101){
					if(dp[l][i][j]==0)continue;
					if(dp[l][i][j]<1e16){
						d[i][j]=min(d[i][j],calc(l-1,dp[l][i][j]));
					}
				}
			}
		}
		/*
		cout<<endl;
		cout<<" dice "<<endl;
		REP(i,5){
			REP(j,5){
				cout<<d[i][j]<<" ";
			}
			cout<<endl;
		}*/
		
		
		REP(k,101){
			REP(i,101){
				REP(j,101){
					d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		if(d[s][g]<1e16){
			cout<<d[s][g]<<endl;
		}else{
			cout<<-1<<endl;
		}
	}
}


Measured memory_bytes: 5524