akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int n;
int maxn;
int next;
int a[100010];
int b[100010];
int c[100010];
int f[100010][4];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	for(int i=1;i<=n;i++)
	{
		f[i][1]=max(f[i-1][2],f[i-1][3])+a[i];
		f[i][2]=max(f[i-1][1],f[i-1][3])+b[i];
		f[i][3]=max(f[i-1][1],f[i-1][2])+c[i];
	}
	printf("%d",max(f[n][1],max(f[n][2],f[n][3])));
	return 0;
}





Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int a,b;
	char ope;
	while (cin >> a, cin >> ope, cin >> b, ope != '?') {
		if (ope == '+') {
			cout << a+b << endl;
		}
		else if (ope == '-') {
			cout << a-b << endl;
		}
		else if (ope == '*') {
			cout << a*b << endl;
		}
		else {
			cout << a/b << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3104
#include<iostream>

using namespace std;

int main()
{
    int c1 =0 ; int c2 =0 ; int c3=0 ; int c4=0 ;
  //string AC= , WA=0 , TLE=0 ,RE=0 ;
  int n ;
  cin>> n ;

  string arr[n] ;
  for (int i=0 ; i<n ; i++) {
    cin >> arr[i] ;
    if ( arr[i]== "AC" ) c1 =c1+1 ;
    if (arr[i]=="WA") c2=c2+1 ;
    if (arr[i]=="TLE") c3 = c3+1 ;
    if (arr[i]=="RE") c4 = c4+1 ;
  }

  cout << "AC x "<<c1 <<endl ;
  cout << "WA x "<<c2 <<endl ;
  cout << "TLE x "<<c3 <<endl ;
  cout << "RE x "<<c4 <<endl ;


    return 0;
}



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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = long.Parse(Console.ReadLine());
        long[] a =  Console.ReadLine().Split().Select(long.Parse).ToArray();

        var dic = new Dictionary<long, long>() { };
        for (int i = 0; i < n; i++)
        {
            if (!dic.ContainsKey(a[i]))
            {
                dic.Add(a[i], 1);
            }
            else
            {
                dic[a[i]]++;
            }

            if (!dic.ContainsKey(a[i] + 1))
            {
                dic.Add(a[i] + 1, 1);
            }
            else
            {
                dic[a[i] + 1]++;
            }

            if (!dic.ContainsKey(a[i] - 1))
            {
                dic.Add(a[i] - 1, 1);
            }
            else
            {
                dic[a[i] - 1]++;
            }
        }

        long ans = 0;
        ans = dic.Values.Max();
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 29536
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;
int N;

signed main(){
	cin>>N;
	cin>>S;
	int m;
	if(N%2==1){
		cout<<"No"<<endl;
	}
	else{
		int m=N/2-1;
		string s,t;
		for(int i=0;i<=m;i++){
			s+=S[i];
		}
		for(int i=m+1;i<S.size();i++){
			t+=S[i];
		}
		if(s==t){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#d
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n

d_sum = sum(a[1:-1:2])

ans[0] = sum(a)-(2*d_sum)

for i in range(1,len(a)):
    ans[i] = 2*a[i-1] -ans[i-1]

ans=[str(a) for a in ans]
ans=" ".join(ans)
print(ans)

Measured memory_bytes: 18072
import Data.List
import Data.Char
import Data.Functor
import Text.Printf
import System.IO
import qualified Data.ByteString.Char8 as B

getInts :: IO[Integer]
getInts = unfoldr (B.readInteger . B.dropWhile isSpace) <$> B.getLine

main = do
  end <- isEOF
  if end then return ()
  else do
    (a:b:_) <- getInts
    putStrLn $ printf "%ld %ld" (gcd a b) (lcm a b)
    main

Measured memory_bytes: 3844
#include <iostream>
#include <vector>

using namespace std;

int main() {

	long long int n, a, b;
	cin >> n >> a >> b;

	vector<long long int> h(n);

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

	long long int l, r;
	l = 0LL;
	r = 1000000010LL;

	while (r - l > 1) {
		long long int m = (l + r) / 2;

		vector<long long int> h2 = h;

		long long int acount = 0;

		for (long long int i = 0; i < n; i++) {
			h2[i] -= b * m;
			if (h2[i] > 0) {
				long long int ac = h2[i] / (a - b);
				if (h2[i] % (a - b) != 0) {
					ac++;
				}
				acount += ac;
			}
		}

		if (acount <= m) {
			r = m;
		}
		else {
			l = m;
		}
	}

	cout << r << endl;

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i<N; i++){
    cin >> vec.at(i);
  }

 sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
 
 int count = 0;
  for (int i = 0; i<N; i++){
    if(i == N-1){
      count++;
      break;
    }
    if(vec.at(i) == vec.at(i+1)){
    }
    else if(vec.at(i) > vec.at(i+1)){
      count++;
    }
    else{
      break;
    }
  }
  cout << count << endl; 
}
      

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}


using i64 = int_fast64_t;


int main(){
    i64 l,r;
    cin >> l >> r;
    const i64 m = 2019;
    const i64 max = i64(2*1e9);
    const i64 min_ = min({r,l+2019,max});
    i64 ans = 2020;
    for(i64 i=l;i<min_;i++){
        for(i64 j=l+1;j<=min_;j++){
            ans=min(ans,(i*j)%m);
        }
    }
    cout << ans << endl;
}

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

#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);                                                        
#define endl "\n"


vector<int> fac(int n)
{
	vector<int> v;
 	for(int i = 2; i*i <= n; i++)
 	{
 	  	if(n%i == 0)
 	  	{
 	  	    v.push_back(i);
 	  	    v.push_back(n/i);
 	  	}	
 	  	if(i*i == n)
 	  		v.pop_back();
 	}
 	v.push_back(1);
 	v.push_back(n);
 	sort(v.begin(),v.end());
 	return v;	
}



int32_t main()
{
	IOS;
	#ifdef LOCAL
	freopen("input.txt","rt",stdin);
	#endif

	int n;
	cin >> n;
	auto v = fac(n);                         
	int l = 0, r = (int)v.size()-1,minGap = 1e13;
	while(l <= r)
	{
	 	minGap = min(minGap, v[r]+v[l]-2);
	 	l++;r--;
	}
	cout << minGap <<endl;
 
	#ifdef LOCAL
	cerr << "Time elapsed : " << 1.0*clock()/CLOCKS_PER_SEC << " s.\n";
	#endif
    return 0;
}   

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> l = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            l.add(sc.nextInt());
        }
        ArrayList<Integer> ans = new ArrayList<>();

        while (true) {
            boolean cont = false;
            for (int i = l.size() - 1; i >= 0; i--) {
                if (l.get(i) == i + 1) {
                    l.remove(i);
                    ans.add(i + 1);
                    cont = true;
                    break;
                }
            }
            if (!cont)
                break;
        }
        
        if (l.size() != 0)
            System.out.println("-1");
        else 
            for(int i = ans.size() - 1; i >= 0; i--) 
                System.out.println(ans.get(i));

        



    }
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    cout << min(N%K, abs(K - N%K)) << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    vector<int> v(250000000,0);
    int X;
    cin >> X;
    if (X >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

using namespace std;
typedef long long ll;
#define mp make_pair

vector<vector<int> > graph;
const int N = 1e5 + 10;
bool used[N];

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	int n;
	cin >> n;
	graph.resize(n);
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	deque<int> res;
	for (int i = 0; i < n; i++) {
		if (graph[i].size() > 0) {
			res.push_front(i);
			used[i] = true;
			break;
		}
	}
	while (true) {
		int v = res.front();
		bool ind = true;
		for (auto u : graph[v]) {
			if (!used[u]) {
				res.push_front(u);
				used[u] = true;
				ind = false;
				break;
			}
		}
		if (ind)
			break;
	}
	while (true) {
		int v = res.back();
		bool ind = true;
		for (auto u : graph[v]) {
			if (!used[u]) {
				res.push_back(u);
				used[u] = true;
				ind = false;
				break;
			}
		}
		if (ind)
			break;
	}
	cout << res.size() << endl;
	for (int v : res) {
		cout << v + 1 << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

const int MAX = 1e5;
const int INF = 1e9;
int N;
vector<vector<int> > edge(MAX);
int d1[MAX]; // マス1から各マスへの最短距離
int dN[MAX]; // マスNから各マスへの最短距離

// n:どのマスにいるか、d:始点からの距離
void dfs(int n, int d, bool flag) {
  for (int i = 0; i < edge[n].size(); i++) {
    if (flag) {
      if (d1[edge[n][i]] < INF) continue;
      d1[edge[n][i]] = d;
      dfs(edge[n][i], d + 1, true);
    } else {
      if (dN[edge[n][i]] < INF) continue;
      dN[edge[n][i]] = d;
      dfs(edge[n][i], d + 1, false);
    }
  }
}

int main() {
  cin >> N;
  int a, b;
  for (int i = 0; i < N - 1; i++) {
    scanf("%d %d", &a, &b);
    a--; b--;
    if (b != 0 && b != N - 1) edge[a].push_back(b);
    if (a != 0 && a != N - 1) edge[b].push_back(a);
  }

  // 深さ優先探索で1のマスからの各マスへの距離と、Nのマスから各マスへの距離を計算する
  fill(d1, d1 + N, INF);
  fill(dN, dN + N, INF);
  dfs(0, 1, true);
  dfs(N - 1, 1, false);

  // 各マスにおいて、d1 <= dNならば黒、そうでないなら白に塗られる
  // 全マスで計算して、多い方の勝ち。同じ場合は後手が勝つ
  int black, white;
  black = white = 1;
  for (int i = 1; i < N - 1; i++) {
    if (d1[i] <= dN[i]) black++;
    else white++;
  }

  // 解答
  cout << (black > white ? "Fennec" : "Snuke") << endl;

  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> pq[1010];
int main()
{
	int n, m;
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int x;
		scanf("%d",&x);
		if(x == 0)
		{
			int y, z;
			scanf("%d%d",&y,&z);
			pq[y].push(z);
		}
		else if(x == 1)
		{
			int y;
			scanf("%d",&y);
			if(!pq[y].empty()) printf("%d\n",pq[y].top());
		}
		else if(x == 2)
		{
			int y;
			scanf("%d",&y);
			if(!pq[y].empty()) pq[y].pop();
		}
	}
	return 0;
}


Measured memory_bytes: 4084
import java.io.*
import java.util.*

fun solve(N:Int, M:Int, A: List<IntArray>){
    val record = IntArray(M)
    for (i in 0 until N){
        A[i].forEach{ record[it-1]+=1 }
    }
    println(record.filter{ it == N }.size)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val A = mutableListOf<IntArray>()
    repeat(N){
        val k  = sc.next().toInt()
        val a = IntArray(k){ sc.next().toInt() }
        A.add(a)
    }
    solve(N, M, A)
}



Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - n % 1000 << endl;
}

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

using ll =long long;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b == 0){
       return(b);
   }else{
       return(gcd(b, a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);
  
ll N,X;
  cin>>N>>X;
  vector<ll> vec(N);
    vector<ll> sub(N);
  ll G=0;
  ll mul=1;
  for(int i=0;i<N;i++){
    cin>>vec[i];
    sub[i]=abs(vec[i]-X);
 //  cout<<sub[i]<<endl;
   // mul*=sub[i];
  }
  
  
  ll M=999999999999999999999999999999999999999;
  int H;
for(int i=0;i<N;i++){
  G=gcd(G,sub[i]);
  
}
  cout<<G<<endl;



}


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

using namespace std;

#define MOD 1000000007
#define N 3003
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

ll dp[N][N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, i, j, x, y;
    cin>>n;
    string s; cin>>s;
    s = ".." + s;
    dp[1][1] = 1;
    for(i=1; i<=n; i++){
        if(s[i] == '<'){
            for(j=1; j<=i; j++){
                dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
            }
        }
        else if(s[i] == '>'){
            for(j=1; j<=i; j++){
                dp[i][j] = (dp[i][j] + dp[i-1][i] - dp[i-1][j-1] + MOD) % MOD;
            }
        }
        for(j=1; j<=n; j++){
            dp[i][j] = (dp[i][j] + dp[i][j-1] + MOD) % MOD;
        }
    }
    cout<<dp[n][n];
    return 0;
}

Measured memory_bytes: 70656
a, b, k = map(int, input().split())
x = list()
for i in range(k):
    if a+i<= b:
        print(a+i)
        x.append(a+i)
for j in range(k):
    f = b-k+j+1
    if a <= f and f <= b and f not in x:
        print(f)

Measured memory_bytes: 9184
import math
a,b,h,m = map(int, input().split())
s = 30 * h + m * 0.5
l = m*6
x = abs(s-l)
if x >= 180: x = 360-x
c = math.cos(math.radians(x))
print((a**2+b**2-2*a*b*c)**0.5)

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

using i64 = int64_t;

vector<i64> divisor(i64 n) {
    vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    i64 n, m;
    cin >> n >> m;
    auto d = divisor(m);
    sort(d.rbegin(), d.rend());
    for(auto e: d){
        i64 q = m / e;
        if(q >= n){
            cout << e << endl;
            return 0;
        }
    }

    return 0;
}


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

int N,M;
vector<vector<bool>> e(55,vector<bool>(55,false));
queue<pair<int,int>> Q;
vector<bool> seen(55,0);

void dfs(int u) {
  seen[u] = true;
  for(int i = 1;i <= N;i++) {
    if(e.at(u).at(i)) {
      if(!seen[i]) dfs(i);
    }
  }
}

int main() {

  cin >> N >> M;
  for(int i = 0;i < M;i++) {
    int a,b;
    cin >> a >> b;
    e[a][b] = true;
    e[b][a] = true;
    Q.push(make_pair(a,b));
  }

  int ans = 0;

  while(!Q.empty()) {
    pair<int,int> p = Q.front();
    int a = p.first,b = p.second;
    e[a][b] = false;
    e[b][a] = false;

    for(int i = 1;i <= N;i++) {
      seen[i] = false;
    }
    dfs(1);

    e[a][b] = true;
    e[b][a] = true;

    for(int i = 1;i <= N;i++) {
      if(!seen[i]) {
        ans++;
        break;
      }
    }
    Q.pop();
  }

  cout << ans << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    REP (i, N + 1) cin >> A[i];
    REP (i, N) cin >> B[i];
    int ans = 0;
    REP (i, N) {
        if (A[i] >= B[i]) {
            ans += B[i];
        } else {
            int rem = min(A[i + 1], B[i] - A[i]);
            ans += A[i] + rem;
            A[i + 1] -= rem;
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main() {
  int T;
  cin >> T;
  while(T--) {
    string s;
    cin >> s;
    if(s[0]!='>'||s.size()<=3) cout << "NA" << endl;
    else if(s[1]=='\'') {
      if(s[s.size()-1]!='~'||s.size()%2) {
        cout << "NA" << endl;
        goto next;
      }
      s=s.substr(2,s.size()-3);
      for(int i=0; i<s.size()/2; i++) {
        if(s[i]!='='||s[i+s.size()/2+1]!='=') {
          cout << "NA" << endl;
          goto next;
        }
      }
      if(s.size()<3||s[s.size()/2]!='#') cout << "NA" << endl;
      else cout << "A" << endl;
    } else {
      if(s[s.size()-2]!='~'||s[s.size()-1]!='~'||s.size()%2) {
        cout << "NA" << endl;
        goto next;
      }
      s=s.substr(2,s.size()-4);
      for(int i=0; i<s.size(); i+=2) {
        if(s[i]!='Q'||s[i+1]!='=') {
          cout << "NA" << endl;
          goto next;
        }
      }
      if(s.size()>=2) cout << "B" << endl;
      else cout << "NA" << endl;
    }
  next:;
  }
  return 0;
}


Measured memory_bytes: 3160
def examA():
    A, B, C = LI()
    S = A+B+C
    cur = 0
    for i in range(32):
        if A%2==1 or B%2==1 or C%2==1:
            break
        A = (S-A)//2
        B = (S-B)//2
        C = (S-C)//2
        cur +=1
    if cur==32:
        ans = -1
    else:
        ans = cur
    print(ans)
    return

def examB():
    N, M = LI()
    cur = [0]*N
    for i in range(M):
        a, b = LI()
        cur[a-1] +=1
        cur[b-1] +=1
    ans = "YES"
    for j in cur:
        if j%2==1:
            ans = "NO"
            break
    print(ans)
    return


def clear_maze(h,w,s,maze):
#    debug_print(maze)
    distance = [[inf]*w for _ in range(h)]
    def bfs():
        queue = deque()
        queue.append(s)
        distance[s[0]][s[1]] = 0
        while len(queue):
            y, x = queue.popleft()
            for i in range(4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0<= nx <w and 0<= ny <h and maze[ny][nx] != '#'):
                    if distance[ny][nx]<=distance[y][x]+1:
                        continue
                    queue.append((ny, nx))
                    distance[ny][nx] = distance[y][x] + 1
        return distance
    return bfs()
def examC():
    H, W, K = LI()
    A = [SI() for _ in range(H)]
    sx = W-1; sy = H-1
    for i in range(H):
        for j in range(W):
            if A[i][j]=="S":
                sy = i; sx = j
                break
        if sy!=H-1 or sx!=W-1:
            break
    D = clear_maze(H,W,[sy,sx],A)
#    for v in D:
#        print(v)
    ans = inf
    for i in range(H):
        for j in range(W):
            if D[i][j]>K:
                continue
            cur = min((i+K-1)//K,(j+K-1)//K,(H+K-i-2)//K,(W+K-j-2)//K)
            ans = min(ans,cur+1)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examC()


Measured memory_bytes: 58716
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int k,a,b;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i = a;i<=b;i++){
        if(i%k == 0 )ok = 1;
    }
    if(ok)cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3672
using System.Linq;
using static System.Math;
using System;

public class Hello
{
    public static int n, m, x;
    public static int[] c;
    public static int[,] a;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(line[0]);
        m = int.Parse(line[1]);
        x = int.Parse(line[2]);
        c = new int[n];
        a = new int[n, m];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            c[i] = int.Parse(line[0]);
            for (int j = 0; j < m; j++)
                a[i, j] = int.Parse(line[j + 1]);
        }
        getAns();
    }
    static void getAns()
    {
        var ans = int.MaxValue;
        var imax = 1 << n;
        for (int i = 0; i < imax; i++)
        {
            var w = check(i);
            if (w != -1) ans = Min(ans, w);
        }
        Console.WriteLine(ans == int.MaxValue ? -1 : ans);
    }
    static int check(int t)
    {
        var ans = 0;
        var s = new int[m];
        for (int i = 0; i < n; i++)
        {
            if (((t >> i) & 1) == 1)
            {
                ans += c[i];
                for (int j = 0; j < m; j++)
                    s[j] += a[i, j];
            }
        }
        return s.All(y => y >= x) ? ans : -1;
    }
}



Measured memory_bytes: 28032
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
H = list(map(int, input().split()))

# 今の高さ
cur = [0] * N

count = 0

left = 0
while left < N:
    while cur[left] < H[left]:
        right = left
        for i in range(left+1, N):
            if cur[i] == H[i]:
                break
            right = i

#        print(left, right, cur)
        for i in range(left, right+1):
            cur[i] += 1

        count += 1


    # 次のleftを探す
    left += 1

print(count)


Measured memory_bytes: 3064
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]

count = 0
is_check = True
second_check = False
for i in a:
    if i[0] == i[1]:
        is_check = True
        count+=1
    else:
        count = 0
        is_check = False

    if count == 3 and is_check == True:
        second_check = True

if second_check:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
# Problem A: koukyoukoukokukikou

def get_hand(char)
  left_chars = %w(q w e r t a s d f g z x c v b)

  if left_chars.include?(char)
    'l'
  else
    'r'
  end
end

while true
  line = gets
  break unless line

  str = line.chomp
  break if str == '#'

  current = nil
  prev = nil
  count = -1

  str.each_char do |c|
    current = get_hand(c)

    if current != prev
      count += 1
    end

    prev = current
  end

  puts count
end

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

#define ll long long int
#define pii pair<int,int>

ll len;

ll fun1(string str,ll prime)
{
    ll ans=0;

    for(ll i=0;i<len;i++){
        if((str[i]- '0')%prime==0) ans+=(i+1);
    }

    return ans;
}

ll bigmod(ll a,ll pr,ll mod)
{
    if(pr==0) return 1ll;
    else if(pr==1) return a%mod;
    ll x=bigmod(a,pr/2ll,mod);
    x=(x*x)%mod;
    if(pr & 1ll) x=(x * a)%mod;
    return x;
}

ll fun2(string str,ll prime)
{
     ll temp[prime+1];
     memset(temp,0,sizeof temp);

     ll ans=0, last=0;
     ll len=str.length();

     for(ll i=0;i<len;i++){
         ll p=last*10ll + (str[i]-'0');
         p=(p%prime)*bigmod(10ll,len-i-1,prime);
         ++temp[(p%prime)];
         last=(last*10ll +(str[i]-'0'))%prime;
     }

     for(ll i=0;i<prime;i++){
         ll x;
         if(temp[i]==0) continue;
         if(i==0) x=((temp[i]*(temp[i]+1))/2ll);
         else x=((temp[i]*(temp[i]-1))/2ll);
         ans+=max(0ll, x);
     }

     return ans;
}

int main()
{
    ll a,b,c,d,p,q;


    string str;
    cin>>len>>p;
    cin>>str;
    ll ans;
    if(p==5 || p==2) ans=fun1(str,p);
    else ans=fun2(str,p);


    cout<<ans<<'\n';
}


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

int main(){
    
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;

    float noudo = 0;
    int water = 0;
    int salt = 0;
    for(int i = 0; i <= f/(100*a); i++){
       for(int j = 0; j <= (f-100*a*i)/(100*b); j++){
                   
          int sup = min(f - 100*a*i - 100*b*j, (a*i+b*j)*e );          
          int max = 0;
          for(int k = 0; k <= sup/c; k++){

              int l = (sup-k*c)/d;
              int currsol = k*c+l*d;
              if( max < currsol )
                  max = currsol;
              if( sup == currsol)
                break;  
             
          }

          if( noudo <= (float)max/(float)(100*a*i+100*b*j+max) ){
            noudo = (float)max/(float)(100*a*i+100*b*j+max);
            water = 100*(a*i+b*j);
            salt = max;
          }

       }
    }

    cout << water + salt << ' ' << salt << endl;

}


Measured memory_bytes: 256
N = int(input())
T,A = map(int , input().split())
H = [int(k) for k in input().split()]

l = []
for i in range(N):
  tem = abs(T - H[i] * 0.006 - A)
  l.append(tem)

ans = l.index(min(l)) + 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    set<int> S;
    rep(i, K){
        int d;
        scanf("%d", &d);
        S.insert(d);
    }

    For(i, n, mod){
        int t = i;
        bool flag = true;
        while(t){
            if(S.find(t%10) != S.end()){
                flag = false;
                break;
            }
            t /= 10;
        }
        if(flag){
            printf("%d\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

// stl;
const int MAX = 1999999;
vector<bool> count()
{
	vector<bool> res(MAX + 1, false);
	
	for(int i = 2; i <= MAX; i++)
	{
		res[i] = true;
		for(int j = 2; j * j <= i; j++)
		{
			if(i % j == 0)
			{
				res[i] = false;
				break;
			}
		}
	}
	
	return res;
}

int main()
{
	vector<bool> table(count());
	
	int n;
	while(cin >> n)
	{
		cout << count(table.begin(), table.begin() + n + 1, true) << endl;
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
ll mod = 1e9+7;

signed main() {

    long double n,sum=0;
    cin>>n;
    vl a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    debug(sum)
    double ok=round(sum/n);
    debug(ok)
    ll ans=0;
    rep(i,n){
        debug((a[i]-ok)*(a[i]-ok))
        ans+=(a[i]-ok)*(a[i]-ok);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fa[100000],n,m,a,b,ch,dp[100000];
queue<ll>que;
vector<ll>v[100000];
int main(void){
    cin>>n>>m;
    for(int i=0;i<m+n-1;i++){
        cin>>a>>b;
        a--,b--;
        fa[b]++;
        v[a].push_back(b);
    }
    for(int i=0;i<n;i++){
        if(fa[i]==0)que.push(i);
    }
    while(que.size()){
        ll p=que.front();
        que.pop();
        for(auto x:v[p]){
            fa[x]--;
            if(!fa[x]){
                dp[x]=p+1;
                que.push(x);
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<dp[i]<<endl;
    }
}


Measured memory_bytes: 7808
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
S = input()

ans = 1
for i in range(N-1):
    if S[i] != S[i+1]:
        ans += 1
print(ans)


Measured memory_bytes: 4328
pi = 3.1415926

############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n = inp()
print(2*n*pi)
#print('No')
#print()



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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int main() {
  string s;
  cin >> s;
  reverse(begin(s), end(s));

  string a[] = {"dream", "dreamer", "erase", "eraser"};
  for(int i = 0; i < 4; i++) {
    reverse(begin(a[i]), end(a[i]));
  }
  int i = 0;
  bool update = true;
  while(update) {
    update = false;
    for(int j = 0; j < 4; j++) {
      bool match = true;
      for(int k = 0; k < a[j].size(); k++) {
        if(a[j][k] != s[i + k]) {
          match = false;
          break;
        }
      }
      if(match) {
        i += a[j].size();
        update = true;
      }
    }
  }
  if(i == s.size()) puts("YES");
  else puts("NO");
}




Measured memory_bytes: 512
def Fib(num):
    """num番目のフィボナッチ数を返す
    """
    a, b = 1, 0
    for _ in range(num):
        a, b = a + b, a
    return b

n, m = map(int, input().split())
a_i = []
for i in range(m):
    a_i.append(int(input()))

before = 0
total = 1
flag = False
for a in a_i:
    if a == before:
        flag = True
        break
    x = a - 1 - before
    fib = Fib(x+1)
    total = total*fib
    before = a + 1
if flag:
    print("0")
else:
    x = n - before
    total = total*Fib(x+1)
    print(total%1000000007)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;

  bool a[h + 1][w + 1];
  memset(a, 0, sizeof(a));

  for (auto i = 1; i <= h; ++i) {
    for (auto j = 1; j <= w; ++j) {
      char x;
      cin >> x;

      if (x == '#') {
        a[i][j] = true;
      }
    }
  }

  ll dp[h + 1][w + 1];
  memset(dp, 0, sizeof(dp));

  dp[1][1] = 1;

  for (auto i = 1; i <= h; i++) {
    for (auto j = 1; j <= w; ++j) {
      if (i == 1 && j == 1) {
        continue;
      }

      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;

      if (a[i][j]) {
        dp[i][j] = 0;
      }
    }
  }

  cout << (dp[h][w]) << endl;
}

Measured memory_bytes: 9088
N,M,X = [int(i) for i in input().split()]
gates = [int(i) for i in input().split()]

fare = 0

# 減少方向
for i in range(X) :
    if (i in gates) :
        fare += 1

min_fare = fare
fare = 0
for i in range(X,N+1) :
    if (i in gates) :
        fare += 1

if (min_fare > fare) :
    min_fare = fare

print(min_fare)

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

signed main()
{
   string s; cin>>s;
   int N=s.size();

   int ans=0;
   for(int i=0;i<N;i++){
      if(i%2==0){
         if(s[i]=='g') ans+=0;
         else ans-=1;
      }else{
         if(s[i]=='g') ans++;
         else ans+=0;
      }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a%=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}


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

  ll n;
  cin >> n;
  ll c[n];
  rep(i,n) cin >> c[i];
  sort(c,c+n);

  ll sum[n+1];
  sum[0] = 0;
  rep1(i,n) sum[i] = ad(sum[i-1],c[i-1]);
  ll ans =0;
  rep(i,n){
    ans = ad(mu(mu(pw(4,n-1),c[i]),2),ans);
  }
  //  cout << ans << endl;
  rep1(i,n-1){
    ans = ad(mu(pw(4,n-1),sum[i]),ans);    
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if(n == 1) {
		cout << a[0] << endl;
	} else {
		for(int i = n - 1; 0 <= i; i -= 2) {
			cout << a[i] << " ";
		}
		if(n % 2 == 0) {
			for(int i = 0; i < n; i += 2) {
				cout << a[i];
				if(i == n - 2) {
					cout << endl;
				} else {
					cout << " ";
				}
			}
		} else {
			for(int i = 1; i < n; i += 2) {
				cout << a[i];
				if(i == n - 1) {
					cout << endl;
				} else {
					cout << " ";
				}
			}
		}
	}

	return 0;
}

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

const int N = 55;

int n;
int a[N], b[N];
bool used[N], vis[N];

bool f() {
  for (int i = 0; i < n; ++i) {
    memset(vis, false, sizeof vis);
    vis[a[i]] = true;
    for (int j = a[i]; j > 0; --j)
      if (vis[j])
        for (int k = 1; k <= j; ++k)
          if (used[k])
            vis[j % k] = true;
    if (!vis[b[i]])
      return false;
  }
  return true;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i)
    scanf("%d", &b[i]);
  fill(used, used + N, true);
  if (!f())
    return 0 * puts("-1");
  for (int i = N - 1; i > 0; --i) {
    used[i] = false;
    if (!f())
      used[i] = true;
  }
  long long ans = 0;
  for (int i = 1; i < N; ++i)
    if (used[i])// printf(">>>>> %d\n", i);
      ans += (1LL << i);
  printf("%lld\n", ans);
  return 0;
}

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

string A[50];
string B[50];


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

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for(int i = 0; i < M; i++) {
		cin >> B[i];
	}

	bool ans = false;
	for(int i = 0; i <= N - M; i++) {
		for(int j = 0; j <= N - M; j++) {
			bool ok = true;
			for(int k = 0; k < M; k++) {
				if(A[i + k].substr(j, M) != B[k]) {
					ok = false;
					break;
				}
			}
			if(ok) ans = true;
		}
	}

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define OUT(x) cout<<(x)<<"\n"
#define SZ(x) (int)(x).size()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


int main() {
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for(auto&& i : t) cin >> i;

    ll sum = 0;
    FOR(i, 1, N) {
        int d = t[i] - t[i - 1];
        sum += min(d, T);
    }

    sum += T;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>

using namespace std;
int main()
{
    int K,S;
    cin >> K >> S;

    int tmpX, tmpY, tmpZ;
    int SminusZ;
    int count = 0;

    for (int i = 0; i < K+1; i++)
    {
        tmpZ = i;
        SminusZ = S - tmpZ;
        for (int j = 0; j < K+1; j++)
        {
            tmpY = j;
            tmpX =SminusZ - tmpY;
            if (tmpX < K+1 && tmpX >= 0)
            {
                count++;
            }
        }
    }

    cout << count;
    return 0;
}

Measured memory_bytes: 256
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$K) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

for($i=0;$i<(int)$N;$i++) {
  list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
  $a[$i][0]=(int)$A;
  $a[$i][1]=(int)$B;
  $a[$i][2]=(int)$C;
}
$dp[0]=0;
for($i=0;$i<(int)$N;++$i) {
  for($j=0;$j<3;++$j) {
    for($k=0;$k<3;++$k) {
      if ($j == $k) continue;
      $dp[$i+1][$k] = max($dp[$i+1][$k],$dp[$i][$j]+$a[$i][$k]);
    }
  }
}
printf("%d\n",max($dp[$N]));


Measured memory_bytes: 86512
#include <queue>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

int n, m;
vector<int> graph[100010];
int main() {
    cin >> n >> m;
    rep(i, 0, m){
        int a, b; cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queue<int> que;
    vector<int> obj(n, -1);
    que.push(0);

    while (que.size()) {
        int now = que.front(); que.pop();
        for(auto x : graph[now]){
            if(obj[x] != -1) continue;
            obj[x] = now;
            que.push(x);
        }
    }

    cout << "Yes" << endl;
    rep(i, 1, n){
        cout << obj[i]+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 9724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BFrog2 {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }

            int[] dp = new int[n];
            //dp[0] = 0;
            dp[1] = Math.abs(arr[1] - arr[0]);
            for (int i = 1; i < n; i++) {
                dp[i] = dp[i - 1] + Math.abs(arr[i] - arr[i - 1]);
                for (int j = Math.max(0, i - k); j < i; j++) {
                    dp[i] = Math.min(dp[i], dp[j] + Math.abs(arr[i] - arr[j]));
                }
                //dp[i] = Math.min(dp[i - 2] + value2, dp[i - 1] + value1);
            }

            out.print(dp[n - 1]);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}



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

void bfs(vector<string > &vec,vector< vector<ll> > &visited,ll a,ll b,ll count,ll h,ll w){
	queue<pair<ll,ll> >  q;
	q.push({a,b});
	visited[a][b]=1;
	while(!q.empty()){
		pair<ll,ll> pp=q.front();
		ll a=pp.first,b=pp.second;
		q.pop();
		if(a-1>=0&&b>=0&&a-1<h&&b<w&&visited[a-1][b]==0&&vec[a-1][b]=='.'){
			q.push({a-1,b});
			visited[a-1][b]=visited[a][b]+1;
		}
		if(a+1>=0&&b>=0&&a+1<h&&b<w&&visited[a+1][b]==0&&vec[a+1][b]=='.'){
			q.push({a+1,b});
			visited[a+1][b]=visited[a][b]+1;
		}
		if(a>=0&&b-1>=0&&a<h&&b-1<w&&visited[a][b-1]==0&&vec[a][b-1]=='.'){
			q.push({a,b-1});
			visited[a][b-1]=visited[a][b]+1;
		}
		if(a>=0&&b+1>=0&&a<h&&b+1<w&&visited[a][b+1]==0&&vec[a][b+1]=='.'){
			q.push({a,b+1});
			visited[a][b+1]=visited[a][b]+1;
		}
	}
	
}

int main()
{
	ll h,w;
	cin>>h>>w;
	vector<string > vec;
	for(ll i=1;i<=h;i++){
		string s;
		cin>>s;
		vec.push_back(s);
	}
	ll ans=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(vec[i][j]=='.'){
				vector< vector<ll> > visited(h,vector<ll> (w,0));
				ll count=1;
				bfs(vec,visited,i,j,count,h,w);
				for(ll k=0;k<h;k++){
					for(ll l=0;l<w;l++){
						count=max(count,visited[k][l]-1);
					}
				}
				ans=max(ans,count);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256