akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    //for(int i = S.length() - 1; i >= 0; i--) {
      //inverse += String.valueOf(S.charAt(i));
    //}
    String s1 = "dream";
    String s2 = "dreamer";
    String s3 = "erase";
    String s4 = "eraser";
    String ans = "YES";
    int pos = S.length();
    while(pos > 0 ) {
      String str5 = "";
      String str6 = "";
      String str7 = "";
      if(pos - 5 >= 0) {
        str5 = S.substring(pos - 5,pos);
      }
      if(pos - 6 >= 0) {
        str6 = S.substring(pos - 6,pos);
      }
      if(pos - 7 >= 0) {
        str7 = S.substring(pos - 7,pos);
      }
      if((pos - 5 >= 0) && (s1.equals(str5))) {
        pos -= 5;
      } else if((pos - 7 >=0) && (s2.equals(str7))) {
        pos -= 7;
      } else if((pos - 5 >=0) && (s3.equals(str5))) {
        pos -= 5;
      } else if((pos - 6 >=0) && (s4.equals(str6))) {
        pos -= 6;
      } else {
        ans = "NO";
        break;
      }     
    }
    System.out.println(ans);
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,k;cin >>n>>k;
    ll r,s,p;cin >>r>>s>>p;
    string t;cin >>t;
    ll ans=0;
    vector<ll>pre(n,0);
    for (int i = 0; i < n; ++i) {
        if(t[i]=='r') {
            if (i < k) {
                ans+=p;
                pre[i]=1;
            }
            else {
                if(t[i]==t[i-k]) {
                    if (!pre[i - k]) {
                        ans += p;
                        pre[i]=1;
                    }
                }
                else {
                    ans+=p;
                    pre[i]=1;
                }
            }
        }
        if(t[i]=='s') {
            if (i < k) {
                ans+=r;
                pre[i]=1;
            }
            else {
                if(t[i-k]==t[i]){
                    if(!pre[i-k]) {
                        ans += r;
                        pre[i]=1;
                    }
                }
                else {
                    ans+=r;
                    pre[i]=1;
                }
            }
        }
        if(t[i]=='p') {
            if (i < k) {
                ans+=s;
                pre[i]=1;
            }
            else {
                if(t[i]==t[i-k]){
                    if(!pre[i-k]) {
                        ans += s;
                        pre[i]=1;
                    }
                }
                else {
                    ans+=s;
                    pre[i]=1;
                }
            }
        }
//        cout <<ans <<endl;
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(void) {
	int a,b;
	char op;
	for(;;){
		scanf("%d %c %d",&a,&op,&b);
		if(a>=0&&a<=20000&&b>=0&&b<=20000){
			if(op=='+') printf("%d\n",a+b);
			else if(op=='-') printf("%d\n",a-b);
			else if(op=='*') printf("%d\n",a*b);
			else if(op=='/'&&b!=0) printf("%d\n",a/b);
			else if(op=='?') break;
	         }
        }
	return 0;
}


Measured memory_bytes: 2072
#include <iostream>
 
using namespace std;
 
 
int main()
{
	long long a;
	cin >> a;
    
    
    
    long long b = 100, step = 0;
	
	while(b < a){
		b += b /100;
		step++;
	}
	
	
	
	
	
	 cout << step;
     return 0;
}

Measured memory_bytes: 3612
/* Made by Takauov Yerzhan - 31/01/2020 */
#include <bits/stdc++.h>
#define enter endl
#define LL long long
#define LD long double
#define UL unsigned long long
#define Okoshka ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define F first
#define S second

using namespace std;

const LL MXN = 3e5 + 7;
const LL MOD = 1e9 + 7;
const LL INF = 1e18 + 7;

int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, -1, +1};

LL n, cnt = 1, ans;

int main()
{
    ///Okoshka;
    cin >> n;
    while(n > 0){
        n /= 2;
        ans += cnt;
        cnt *= 2;
    }
    cout << ans;
}


Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL a;

int main()
{
	FIO;
	cin >> a;
	cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3648
import numpy as np

if __name__ == "__main__":
  _data_list = []
  tmp_list = list(map(int, input().split()))
  _data_list.append(tmp_list)
  _rows = len(tmp_list)
  for i in range(_rows-1):
    _data_list.append(list(map(int, input().split())))
  _data_list = np.array(_data_list)

  flag_matrix = np.zeros((3,3),dtype=np.bool)
  _n = int(input())
  _b = []
  for i in range(_n):
    _b.append(int(input()))

  for data in _b:
    flag_matrix = np.logical_or(flag_matrix,_data_list == data)

  if np.all(flag_matrix[0]) or np.all(flag_matrix[1]) or np.all(flag_matrix[2]) or np.all(flag_matrix[:,0]) or np.all(flag_matrix[:,1]) or np.all(flag_matrix[:,2]) or (flag_matrix[0,0]*flag_matrix[1,1]*flag_matrix[2,2]) or (flag_matrix[0,2]*flag_matrix[1,1]*flag_matrix[2,0]):
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 12432
// AGC023
// A - Zero-Sum Ranges

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;
const ll INF = 1e18;

int N;
int a[MAX_N];

ll comb2(int n) { return 1LL * n * (n - 1LL) / 2LL; }

ll solve() {
    ll s[MAX_N + 2];

    s[0] = 0;
    for (int i = 0; i < N; i++) {
        s[i + 1] = s[i] + a[i];
    }
    sort(s, s + N + 1);
    s[N + 1] = INF;

    ll ans = 0;
    int prev_i = 0;
    ll prev_s = s[0];
    for (int i = 1; i <= N + 1; i++) {
        if (s[i] != prev_s) {
            ans += comb2(i - prev_i);
            prev_i = i;
            prev_s = s[i];
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


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

int main()
{

    int N, K, Q;
    cin >> N >> K >> Q;
    //cout << N << " " << K << " " << Q << endl;

    vector<int> A(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> A[i];
        //cout << A[i] << endl;
    }

    vector<int> P(N); //参加者の正解数
    for (int i = 0; i < N; i++)
    {
        P[i] = 0;
    }

    for (int i = 0; i < Q; i++)
    {
        P[A[i] - 1]++;
    }

    for (int i = 0; i < N; i++)
    {
        int point = K - (Q - P[i]);
        //cout << P[i] << ":" << point;

        if (point > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;
}

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

int main() {
	int a, b, c, d, e, f, h, m, s;
	while(cin >> a >> b >> c >> d >> e >> f){
		int t0 = a*3600+b*60+c;
		int t1 = d*3600+e*60+f;
		int t2 = t1-t0;
		h = t2/3600;
		m = (t2-h*3600)/60;
		s = t2%60;
		cout << h << ' ' << m << ' ' << s << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
import           Control.Applicative
import           Control.Monad
import           Data.List

main :: IO ()
main = do
  num <- getLine
  cards <- replicateM (read num) (words <$> getLine)
  putStrLn $ unwords $ map show $ foldl check [0, 0] cards
    where
      check [taro, hanako] [card1, card2]
        | card1 > card2 = [taro+3, hanako]
        | card1 < card2 = [taro, hanako+3]
        | otherwise = [taro+1, hanako+1]


Measured memory_bytes: 4464
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    ll n; cin >> n;
    ll c = 0 , ok = 0;
    while(n--)
    {
        ll a, b; cin >> a >> b;
        if(a == b)
            c++;
        if(a != b)
            c = 0;
        if(c == 3)
            ok = 1;
    }
    if(ok)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3648
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int a = sc.nextInt() + sc.nextInt();
                int b = sc.nextInt() + sc.nextInt();
                if(a > b) System.out.println("Left");
                else if(a < b) System.out.println("Right");
                else System.out.println("Balanced");
                sc.close();
        }
}//0=48
 //a=97 a -> +26 = 123
//鶏になれ

Measured memory_bytes: 35736
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N = int(readline())
A = list(map(int, read().split()))

if N == 2:
    print(A[1] - A[0])
    exit()

dp = [10 ** 10] * N
dp[1] = abs(A[1] - A[0])
dp[2] = abs(A[2] - A[0])

for i in range(3, N):
    dp[i] = min(dp[i - 1] + abs(A[i] - A[i - 1]), dp[i - 2] + abs(A[i] - A[i - 2]))

print(dp[-1])

Measured memory_bytes: 13816
/*    FAILING IS AN ART
       AND 
     I HAVE MASTERED IT
*/
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 
    fast;

    ll r,c,a,b;
    cin>>r>>c>>a>>b;
    bool ans[r][c];
    ll i=0;

    for( i=0;i<r-b;i++)
    {
        ll j=0;
        for(j;j<a;j++)
           ans[i][j]=0;
        for(j;j<c;j++)
           ans[i][j]=1;
    }


    for(i;i<r;i++)
    {
        ll j=0;
        for(j;j<a;j++)
            ans[i][j]=1;
        for(j;j<c;j++)
            ans[i][j]=0;
    }

    for(ll i=0;i<r;i++)
    {
        for(ll j=0;j<c;j++)
            cout<<ans[i][j];
        cout<<endl;
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  int res = 0;
  if (k < n) {
    res += k*x + (n-k)*y;
  }
  else res += n*x;
  dump(res);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
ll n,k,a[101],dp[101][100005],prefix[101][100005];
//ll f(ll ed,ll k)
//{
//	if(ed<0 || k<0)
//	return 0;
//	if(dp[ed][k]!=-1)
//	return dp[ed][k];
//	if(k==0)
//	return dp[ed][k]=1;
//	if(ed==0)
//	return dp[ed][k]=a[ed]-k>=0?1:0;
//	ll ans=0;
//	repi(i,0,a[ed])
//	{
//		if(k-i>=0)
//		{
//			ans+=f(ed-1,k-i);
//			ans=ans%mod;
//		}
//	}
//	return dp[ed][k]=ans;
//}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//	cout<<setprecision(12)<<fixed;
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,k,l,m,first,last;
    	cin>>n>>k;
    	repi(i,1,n)
    	cin>>a[i];
    	repi(i,0,n)
    	{
    		dp[i][0]=1;
    		prefix[i][0]=1;
		}
    	repi(j,0,k)
    	prefix[0][j]=1;
    	
    	repi(i,1,n)
    	{
    		repi(j,1,k)
    		{
    			first=(j-a[i]-1>=0)?prefix[i-1][j-a[i]-1]:0;
    			last=prefix[i-1][j];
    			dp[i][j]=(last-first+mod)%mod;
    			prefix[i][j]=(prefix[i][j-1]+dp[i][j])%mod;
			}
		}
    	cout<<dp[n][k];
	}
	return 0;
}

Measured memory_bytes: 158080
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 2e9
#define mod 1000000007
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef long long ll;
void read(ll &x)
{
	scanf("%lld",&x);
}
void read(ll &x, ll &y)
{
	scanf("%lld%lld",&x,&y);
}
void read(ll &x, ll &y, ll &z)
{
	scanf("%lld%lld%lld",&x,&y,&z);
}
void print(ll x)
{
	printf("%lld ",x);
}
void println(ll x)
{
	printf("%lld\n",x);
}
const ll N=1000000;
ll n,a[5][111],b[111],c[111],ans;
int main()
{
	//freopen("c.cpp","r",stdin);
 
	cin>>n;
	for(ll i=1;i<=2;i++)
		for(ll j=1;j<=n;j++)
			read(a[i][j]);
	for(ll i=1;i<=n;i++)
		b[i]=b[i-1]+a[1][i];
	for(ll i=n;i>=1;i--)
		c[i]=c[i+1]+a[2][i];
	for(ll i=1;i<=n;i++)
		ans=max(ans,b[i]+c[i]);
	cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

bool compare(pair<string,pair<int,int>> p1,pair<string,pair<int,int>> p2)
{
	if(p1.first<p2.first)
		return 1;
	else if(p1.first>p2.first)
		return 0;
	else
	{
		return p1.second.first>p2.second.first;
	}
}

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	pair<string,pair<int,int>> p[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>p[i].first>>p[i].second.first;
		p[i].second.second=i;
	}
	sort(p+1,p+n+1,compare);
	for(int i=1;i<=n;i++)
	{
		cout<<p[i].second.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str="";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	Int a, b, c; cin >> a >> b >> c;
	if (c == 0) {
		cout << b;
		return 0;
	}
	if (b >= c) cout << b+c;
	else {
		if (a + b >= c) cout << b + c;
		else cout << (a+b)+b+1;
	}
	


	cout << endl;
	return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::min;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    mut a: [usize; n],
    mut f: [usize; n]
    }
    if a.iter().sum::<usize>() <= k {
        println!("0");
        return
    }
    a.sort();
    f.sort();
    let (mut l, mut r) = (0, std::usize::MAX);
    while l + 1 < r {
        let mid = (l + r) / 2;
        let mut t = 0;
        for i in 0..n {
            t += a[i].checked_sub(mid / f[n - i - 1]).unwrap_or(0);
        }
        if t > k {
            l = mid;
        } else {
            r = mid;
        }
    }
    println!("{}", r);
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

ll N, K;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N >> K;
	vector<ll> P(N); REP(i, N) cin >> P[i], --P[i];
	vector<ll> C(N); REP(i, N) cin >> C[i];

	ll res{-INF};
	REP(init, N)
	{
		ll co = init;
		vector<ll> sum;
		ll t{0};
		while (true)
		{
			co = P[co];
			t += C[co];
			sum.push_back(t);
			if (init == co)
				break;
		}

		ll M = sum.size();

		if (M >= K)
		{
			res = max(res, *max_element(sum.begin(), sum.begin()+K));
		}
		else // M < K
 		{
			ll p = K / M;
			if (sum.back() > 0)
			{
				ll b = sum.back();
				if (p > 1)
					res = max(res, (p-1)*b + *max_element(ALL(sum)));

				if (K%M)
					res = max(res, p*b+*max_element(sum.begin(), sum.begin()+K%M));
				else
					res = max(res, p*b);
			}
			else
			{
				res = max(res, *max_element(ALL(sum)));
			}
		}

	}

	std::cout << res << std::endl;
	
	return 0;
}


Measured memory_bytes: 3816
n = int(input())
d = dict()
for i in range(n):
    s= input()
    d.setdefault(s, 0)
    d[s] += 1
d = sorted([[x, y] for x, y in d.items()], key=lambda x:x[1], reverse=True)
now = 0
ans = set()
for x, y in d:
    if y >= now:
        ans.add(x)
        now = y
    else:
        break
for x in sorted(ans):
    print(x)

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

int main (){
    int r,g,b;
    cin >> r >> g >> b ;
    if((10*g+b)%4==0){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define max 100005
void add(int, int, int, int*);
int getSum(int, int*);

int main()
{
  int n,q,com,x,y,i;
  cin >> n >> q;
  int *A;
  A = new int[max];
  
  for (i=0; i<max; i++)
    A[i] = 0;
  
  for(i=0; i<q; i++)
    {
      cin >> com >> x >> y;
      if(com)
	cout << getSum(y, A) - getSum(x-1, A) << endl;
      else
	add(x, y, n, A);
    }
  return 0;
}

void add(int x,int y, int n, int* A)
{
  for(; x<=n; x = x + (x & -x))
    A[x] += y;
}
 
int getSum(int a, int* A)
{
  int ans = 0;
  for(; a>0; a = a - (a & (-a)))
    ans += A[a];
  return ans;
}


Measured memory_bytes: 3472
#include <stdio.h>

int main(void)
{
	int m, f, r;

	while (1)
	{
		scanf("%d%d%d", &m, &f, &r);
	
		if (m == -1 && f == -1 && r == -1)
			break;

		else if (m == -1 || f == -1)
			puts("F");
		else if (m + f >= 80)
			puts("A");
		else if (m + f >= 65)
			puts("B");
		else if (m + f >= 50)
			puts("C");
		else if (m + f >= 30) 
		{
			if (r >= 50)
			 	puts("C");
			else
				puts("D");
		}
		else
			puts("F");
	}
	return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a==5&&b==7&&c==5)||(b==5&&c==7&&a==5)||(c==5&&a==7&&b==5)){
    printf("YES\n");
  }
  else{
    printf("NO\n");
  }
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    vector<int> P(N);
    for (int& p : P)
        cin >> p;

    int cnt = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (P[i] == i + 1) {
            swap(P[i], P[i + 1]);
            ++cnt;
        }
    }
    if (P[N - 1] == N) {
        swap(P[N - 1], P[N - 2]);
        ++cnt;
    }

    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 640
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
s = input()
for i in range(len(s)):
    if i % 2 == 0:
        print(s[i], end='')


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

using namespace std;

int main () {
  string s;

  cin >> s;
  string ans = "";
  
  for (int i = 0; i < s.length(); i++){
    if (s[i] == '0'){
      ans += "0";
    }else if (s[i] == '1'){
      ans += "1";
    }else{
      if(ans.size() != 0){
        ans.erase(ans.size()-1, 1);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool F[102][102];
int A[102][102]={0},W,H;
int ww[2][6]={{-1,0,-1,1,-1,0},{0,1,-1,1,0,1}},hh[6]={-1,-1,0,0,1,1};

int init(){
	for(int i=0;i<102;i++)for(int j=0;j<102;j++)F[i][j]=false;
	return 1;
}

int color(int w,int h,int k){
	if(w==0||w>W||h==0||h>H)return 1;
	if(k==0)k=init();
	if(F[w][h])return 0;
	int ret=0;
	F[w][h]=true;
	if(A[w][h]==1)return ret;
	for(int i=0;i<6;i++){
		ret+=color(w+ww[h%2][i],h+hh[i],k);
	}
	return ret;
}

int main(){
	int ans=0;
	scanf("%d%d",&W,&H);
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)scanf("%d",&A[j][i]);
	for(int i=1;i<=W;i++)for(int j=1;j<=H;j++){
		if(A[i][j]==0){
			int s=color(i,j,0);
			if(s==0)A[i][j]++;
		}
	}
	for(int i=1;i<=W;i++)for(int j=1;j<=H;j++){
		if(A[i][j]==1){
			for(int k=0;k<6;k++){
				if(A[i+ww[j%2][k]][j+hh[k]]==0){ans++; /*printf("(%d,%d),(%d,%d)\n",i,j,i+ww[j%2][k],j+hh[k]);*/}
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615


int main(){
  int n;cin>>n;
  vector<int> p(n);
  rep(i,n) cin>>p.at(i);
  int ans=0;
  int min=p.at(0);
  for(int i=0;i<n;i++){
	if(p.at(i)<=min){
      ans+=1;
      min=p.at(i);
    }
  }
  cout<<ans;

}

Measured memory_bytes: 3952
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const int INF =100100100;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back 
#define mp make_pair



signed main (){	
	int AA,BB,max=0;
	cin >> AA >> BB ;
	if (AA > BB) {max = AA;}
	if (BB > AA) {max = BB;}
	if(max > 0) {
		cout << 2 * max - 1 << endl;
	}else {
		cout << 2 * AA << endl;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

string name, str;
int length1, length2;

struct list {
	int a;
	int b;
	int c;
	int r;
};

int ok[1010];

int main() {
	while (1) {
		int A, B, C, N;
		cin >> A >> B >> C;
		if (A == 0 && B == 0 && C == 0)break;
		cin >> N;

		for (int i = 0; i < A + B + C; i++)
			ok[i] = 2;

		struct list d[1010];

		for (int i = 0; i < N; i++) {
			cin >> d[i].a >> d[i].b >> d[i].c >> d[i].r;
			if (d[i].r) {
				ok[d[i].a - 1] = 1;
				ok[d[i].b - 1] = 1;
				ok[d[i].c - 1] = 1;
			}
		}
		for (int i = 0; i < N; i++) {
			if (d[i].r != 1) {
				if (ok[d[i].a - 1] == 1 && ok[d[i].b - 1] == 1)
					ok[d[i].c - 1] = 0;
				else if (ok[d[i].b - 1] == 1 && ok[d[i].c - 1] == 1)
					ok[d[i].a - 1] = 0;
				else if (ok[d[i].a - 1] == 1 && ok[d[i].c - 1] == 1)
					ok[d[i].b - 1] = 0;
			}
		}
		for (int i = 0; i < A + B + C; i++)
			cout << ok[i] << endl;
	}
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

ll n;
vll a;

bool isOk(ll mid){
  vll s(n+1);
  rep(i,n){
    s[i+1]=s[i];
    if(a[i]<=mid) s[i+1]++;
    else s[i+1]--;
  }
  
  BIT<ll> bit(2*n+10);
  ll cnt=0;
  rep(i,n+1){
    cnt+=bit.sum(s[i]+n+1-1);
    bit.add(s[i]+n+1);
  }
  return cnt>n*(n+1)/2/2;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  a.resize(n);
  rep(i,n) cin>>a[i];
  
  ll ok=1e9, ng=0;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3456
#include<cstdio>
#include<iostream>
using namespace std;
main(){
  long long n,i,j,t,a[5000],max;
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    else{
      for(i=0;i<n;i++){
	cin >> a[i];
      }
      max=a[0];
      for(i=0;i<n;i++){
	for(j=i,t=0;j<n;j++){
	  t=t+a[j];
	  if(t>max){
	    max=t;
	  }
	}
      }
      cout << max  << endl;
    }
  }
}

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

int main(){
    // input
    int N;
    string S;
    cin >> N >> S;

    // calc
    bool ans = true;
    if( N%2 != 0 ){
        ans = false;
    }else{
        int L = S.length() / 2;
        for( int l = 0; l <L; l++ ){
            if( S[l] != S[l+L] ){
                ans = false;
            }
        }
    }
    
    // output
    printf(ans ? "Yes" : "No");
} 

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>

#define ll long long

#define reps(i, s, n) for (int i = s; i < (n); i++)
#define rep(i, n) reps(i, 0, n)

using namespace std;

void init()
{
}

double getAngle(int num, int max)
{
	return (double)num / max * M_PI * 2;
}

void solve()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	int hcount = h * 60 + m;
	int hmax = 12 * 60;

	double hangle = getAngle(hcount, hmax);
	double mangle = getAngle(m, 60);

	double hx = cos(hangle) * a;
	double hy = sin(hangle) * a;
	double mx = cos(mangle) * b;
	double my = sin(mangle) * b;

	double dist = sqrt(pow(hx - mx, 2) + pow(hy - my, 2));
	printf("%.15lf\n", dist);
}

int main()
{
	init();
	solve();
}


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

using namespace std;

int main(){
	map<string,bool> dict;
	int n;
	char com[10],key[13];
	scanf("%d",&n);
	for(int i = 0; i < n ; i++){
		scanf("%s %s",com,key);
		if(com[0]=='i'){
			dict[string(key)] = true;
		}else if(com[0] == 'f'){
			if(dict[string(key)]){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
}


Measured memory_bytes: 47556
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	int A, B;
	cin >> A >> B;
	if (B == 1) {
		A = 2;
		B = 1;
	}
	
	cout << (B-2)/(A-1)+1<< endl;
}

Measured memory_bytes: 256
l,r = map(int, input().split())

q1 = l//2019
q2 = r//2019

if q1!=q2:
  print(0)
  exit()

r1 = l%2019
r2 = r%2019
ans = 2019
for i in range(r1,r2+1):
  for j in range(i+1,r2+1):
    rr = (i*j)%2019
    ans = min(ans,rr)
    if ans==0:
      print(ans)
      exit()
      
print(ans)

Measured memory_bytes: 3064
N = int(input())
S = str(N)
D = len(S)
M = N%10
SE = N//(10**(D-1))
ans = 0
for i in range(1,N+1):
    x = i
    t = str(x)
    d = len(t)
    m = x%10
    s = x//(10**(d-1))
    if m == 0:
        continue
    for j in range(1,D+1):
        if j == 1:
            if s == m:
                ans += 1
        elif 2 <= j <= D-1:
            ans += 10**(j-2)
        else:
            if SE > m:
                ans += 10**(j-2)
            elif SE == m:
                p = N%(10**(D-1))
                p = p//10
                ans += p+1
                if M < s:
                    ans -= 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,d,x;
  cin>>n>>d>>x;
  vector<int> a(n);
  for(int i = 0;i<n;i++) cin>>a[i];
  int c = 0;
  for(int i = 0;i<n;i++)
  {   int j = 0;
     
      while(j*a[i]+1<=d) j++;
      c+=j;
   
  }
  cout<<c+x<<endl;
}

Measured memory_bytes: 3632
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

max_A = max(A)
max_A_counter = 0
sec_A = max_A
for a in sorted(A, reverse=True):
    if a==max_A:
        max_A_counter+=1
    if a!=max_A:
        sec_A=a
        break

for i in range(N):
    if A[i]==max_A:
        print(max_A if 2<=max_A_counter else sec_A)
    else:
        print(max_A)

Measured memory_bytes: 13340
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
int pos[100000];
int main() {
	string s;
	cin >> s;
	int n = s.size();
	if (s[0] == '0' || s[n - 1] == '1') {
		cout << -1 << endl;
		return 0;
	}

	for (int i = 0; i + 1 < n; i++) {
		if (s[i] != s[n - i - 2]) {
			cout << -1 << endl;
			return 0;
		}
	}
	pos[n - 1] = n - 1;
	for (int i = n - 2; i >= 0; i--) {
		cout << pos[i + 1] + 1 << " " << i + 1 << endl;
		if (s[i] == '1') pos[i] = i;
		else pos[i] = pos[i + 1];
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a + b >= 10)
    {
        cout << "error\n";
    }
    else
    {
        cout << a + b << endl;
    }
    return 0;
}


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

int main(){
    int N;  cin >> N;
    vector<pair<string,int>> R(N);
    for(int i=0; i<N; i++){
        cin >> R[i].first >> R[i].second;
    }

    vector<int> O(N);
    iota(O.begin(), O.end(),0);
    sort(O.begin(), O.end(), [&](const int &a, const int &b){
        if(R[a].first != R[b].first) return R[a].first < R[b].first;
        else return R[a].second > R[b].second;
    });

    for(int i=0; i<N; i++){
        cout << O[i]+1 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 5010
using namespace std;

int n,k,dp[20][N],num[N],ans;

void sol(int l,int r,int now)
{
    if(l==r)
    {
        int i;
        for(i=max(0,k-num[l]); i<k; i++)
        {
            if(dp[now][i]) break;
        }
        if(i<k) ans++;
        return;
    }
    int i,j,mid=((l+r)>>1);
    for(i=0;i<k;i++) dp[now+1][i]=dp[now][i];
    for(j=l; j<=mid; j++)
    {
        for(i=k-1; i>=num[j]; i--)
        {
            dp[now+1][i]|=dp[now+1][i-num[j]];
        }
    }
    sol(mid+1,r,now+1);
    for(i=0;i<k;i++) dp[now+1][i]=dp[now][i];
    for(j=mid+1;j<=r;j++)
    {
        for(i=k-1;i>=num[j];i--)
        {
            dp[now+1][i]|=dp[now+1][i-num[j]];
        }
    }
    sol(l,mid,now+1);
}

int main()
{
    int i,j;
    cin>>n>>k;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&num[i]);
    }
    dp[0][0]=1;
    sol(1,n,0);
    cout<<n-ans;
}

Measured memory_bytes: 512
MAX_SUM = 4000
MAX_I = 1000
K = 4
 
$sn_cache = Array.new(K + 1) {[]}
 
def check_sum(k, n)
  unless $sn_cache[k][n]
    count = 0
    max_i = [MAX_I, n].min
 
    (0..max_i).each do |i|
      count += check_sum(k - 1, n - i)
    end
 
    $sn_cache[k][n] = count
  end
  
  $sn_cache[k][n]
end
 
$sn_cache[1] = Array.new(MAX_I + 1, 1) + Array.new(MAX_SUM - MAX_I, 0)
 
while (line = gets)
  n = line.chomp.to_i
  puts check_sum(K, n)
end


Measured memory_bytes: 7068
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> a (n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    int sum = 0;
    int ans = n + 1;
    for (int l = 0, r = 0; r < n; r++) {
        sum += a[r];
        while (sum - a[l] >= s) {
            sum -= a[l];
            l++;
        }
        if (sum >= s) {
            ans = min(ans, r - l + 1);
        }  
    }
    cout << (ans > n? 0 : ans) << endl;
    
    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){
int n;
cin>>n;
int p[n];
int cnt=0;
for(int i=0;i<n;i++){
  cin>>p[i];
}

for(int i=0;i<n-2;i++){
  if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i+2]<p[i+1]&&p[i+1]<p[i])){
    cnt++;
  }
}

cout<<cnt<<endl;
return 0;
}


Measured memory_bytes: 256
main(){
    int i,n,k,a,b,A,B,dist[101][101];
    scanf("%d%d",&n,&k);
        /*initialize*/
        memset(dist,11,sizeof(dist));
        for(i=1;i<=n;i++)dist[i][i]=0;
        for(;k;k--){
            scanf("%d,%d,%d,%d",&a,&b,&A,&B);
            dist[a][b]=A,dist[b][a]=B;
        }
 
        {/*warshall-floyd*/
            int k,i,j;
            for(k=1;k<=n;k++)
                for(i=1;i<=n;i++)
                    for(j=1;j<=n;j++)
                        if(dist[i][j]>dist[i][k]+dist[k][j])
                            dist[i][j]=dist[i][k]+dist[k][j];
        }
 
        {/*query*/
            scanf("%d,%d,%d,%d",&a,&b,&A,&B);
            printf("%d\n",A-B-dist[a][b]-dist[b][a]);
        }
    exit(0);
}

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

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
// #define int long long

signed main(){
	

	int x,a,b;
	cin>>x>>a>>b;

	if(abs(a-x)>abs(b-x)){
		cout<<"B"<<endl;
	}else{
		cout<<"A"<<endl;
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n, d;
	cin >> n >> d;
	cout << (n - 1) / (2 * d + 1) + 1;
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string word_S = Console.ReadLine();
            string word_T = Console.ReadLine();
            var array_S = word_S.ToCharArray();
            var list_S = array_S.ToList();
            if (word_S == word_T) { 
                Console.WriteLine("Yes");
            }
            else{
                for (int i = 0; i < list_S.Count; i++)
                    {
                    char last_char = list_S[list_S.Count - 1];
                    list_S.RemoveAt(list_S.Count - 1);
                    list_S.Insert(0, last_char);
                    string new_word_S =  new String(list_S.ToArray());
                    if (new_word_S == word_T) { 
                        Console.WriteLine("Yes");
                        break;
                    };
                    if (i == list_S.Count - 1 && new_word_S != word_T)
                    {
                        Console.WriteLine("No");
                    }
                }
            }
        }
    }
}


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

vector<int> b[3];

int ret10(int r)
{
    int ret=1;
    for(int i=0;i<r;i++)ret*=10;
    return ret;
}

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

    int n,m;cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        int s,c;cin>>s>>c;
        b[s-1].push_back(c);
    }

    for(int i=0;i<n;i++)b[i].erase(unique(b[i].begin(),b[i].end()),b[i].end());

    int ans=0;

    if(b[0].size()>1){cout<<-1<<"\n";return 0;}
    else if(b[0].size()==1)
    {
        if(b[0][0]==0&&n>1){cout<<-1<<"\n";return 0;}
        ans+=b[0][0]*ret10(n-1);
    }
    else 
    {
        if(n>1) ans+=ret10(n-1);
    }

    for(int i=1;i<n;i++)
    {
        if(b[i].size()>1){ans=-1;break;}
        if(b[i].size()==1)ans+=b[i][0]*ret10(n-i-1);
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3660
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long MOD = (long)Math.pow(10, 9) + 7;
    long[][][][] dp = new long[100][4][4][4];
    for(int j = 0; j < 4; j++) {
      for(int k = 0; k < 4; k++) {
        for(int l = 0; l < 4; l++) {
          if(!(((j == 0) && (k == 2) && (l == 1)) || ((j == 2) && (k == 0) && (l == 1)) || ((j == 0) && (k == 1) && (l == 2)))) dp[2][j][k][l] = 1;
        }
      }
    }
    for(int i = 3; i < 100; i++) {
      for(int j = 0; j < 4; j++) {
        for(int k = 0; k < 4; k++) {
          for(int l = 0; l < 4; l++) {
            if(!(((j == 0) && (k == 2) && (l == 1)) || ((j == 2) && (k == 0) && (l == 1)) || ((j == 0) && (k == 1) && (l == 2)))) {
              if(l == 1) {
                if(k == 2) {
                  long sum = 0;
                  for(int m = 1; m < 4; m++) {
                    sum = (sum + dp[i - 1][m][j][k]) % MOD;
                  }
                  dp[i][j][k][l] = sum;                 
                } else {
                  if(j == 2) {
                    long sum = 0;
                    for(int m = 1; m < 4; m++) {
                      sum = (sum + dp[i - 1][m][j][k]) % MOD;
                    }
                    dp[i][j][k][l] = sum;                   
                  } else {
                    long sum = 0;
                    for(int m = 0; m < 4; m++) {
                      sum = (sum + dp[i - 1][m][j][k]) % MOD;
                    }
                    dp[i][j][k][l] = sum;                    
                  }
                }
              } else {
                long sum = 0;
                for(int m = 0; m < 4; m++) {
                  sum = (sum + dp[i - 1][m][j][k]) % MOD;
                }
                dp[i][j][k][l] = sum;
              }
            }
          }
        }
      }
    }
    long ans = 0;
    for(int j = 0; j < 4; j++) {
      for(int k = 0; k < 4; k++) {
        for(int l = 0; l < 4; l++) {
          ans = (ans + dp[n - 1][j][k][l]) % MOD;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
($H,$W,$D)=glob<>;
$#x=$W;$#y=$H;
for$h(0..$H-1){
    @l=glob<>;
    for(0..$W-1){
        $x[$l[$_]]=$_;
        $y[$l[$_]]=$h
    }
}
$c[$_]=($_<=$D)?0:$c[$_-$D]+abs($x[$_]-$x[$_-$D])+abs($y[$_]-$y[$_-$D])for(1..$H*$W);
$Q=<>;
print<>!~$",$c[$']-$c[$`],"\n" for(1..$Q)

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

using namespace std;

#define MAX 2000
#define LIMIT 1001000
typedef pair<int,int> pii;

int M,N;
int caves[MAX][MAX];
int dp[MAX][MAX];
map<int,pii> mp;
bool prime[LIMIT];

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,-1,0,1};

void makePrime(){
  fill(prime,prime+LIMIT,true);
  prime[0] = prime[1] = false;
  for(int i = 2 ; i*i < LIMIT ; i++){
    if(prime[i]){
      for(int j = i*2 ; j < LIMIT ; j+=i){
        prime[j] = false;
      }
    }
  }
}

void makeCaves(){
  int x = 1000,y = 1000,dir = 0;
  int num = 1,cnt = 1;
  while(true){
    if(cnt == LIMIT) break;
    for(int i = 0 ; i < 2 ; i++){
      for(int j = 0 ; j < num ; j++){
        mp[cnt] = pii(y,x);
        caves[y][x] = cnt++;
        if(cnt == LIMIT){
          return;
        }
        x += dx[dir];
        y += dy[dir];
      }
      dir = (dir+1)%4;   
    }
    num++;
  }
}

void solve(int sx,int sy){
  dp[sy][sx] = prime[caves[sy][sx]];
  for(int i = 0 ; i < MAX-1 ; i++){
    for(int j = 1 ; j < MAX-1 ; j++){
      if(dp[i][j] >= 0 && caves[i][j] <= M){
        if(caves[i+1][j-1] <= M){
          dp[i+1][j-1] = max(dp[i+1][j-1],dp[i][j]+prime[caves[i+1][j-1]]); 
        }
        if(caves[i+1][j] <= M){
          dp[i+1][j] = max(dp[i+1][j],dp[i][j]+prime[caves[i+1][j]]); 
        }
        if(caves[i+1][j+1] <= M){
          dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+prime[caves[i+1][j+1]]); 
        }
      }
    }
  }
  int res = 0, num = 0;
  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < MAX ; j++){
      if(caves[i][j] <= M && prime[caves[i][j]]){
        if(res < dp[i][j]){
          res = dp[i][j];
          num = caves[i][j];
        }else if(res == dp[i][j]){
          if(num < caves[i][j]){
            num = caves[i][j];
          }
        }
      }
    }
  }
  cout << res << " " << num << endl;
}

int main(){
  makeCaves();
  makePrime();
  while(cin >> M >> N, M){
    pii src = mp[N];
    memset(dp,-1,sizeof(dp));
    solve(src.second,src.first);
  }
  return 0;
}

Measured memory_bytes: 94480
#include<bits/stdc++.h>
#define LL long long
#define R register int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=1e5+9;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
	G;while(*ip<'-')G;
	R x=*ip&15;G;
	while(*ip>'-'){x*=10;x+=*ip&15;G;}
	return x;
}
int k,l[N],r[N];LL f[N];bool b[N];
struct Node{
	int r;mutable int v;
	inline Node(R a,R b=0):r(a),v(b){}
	inline bool operator<(const Node&a)const{return r<a.r;}
};
typedef set<Node>::iterator IT;
set<Node>s;
inline IT Split(R p){
	IT i=s.lower_bound(Node(p));
	return i->r!=p?s.insert(Node(p,i->v)).first:i;
}
inline void Set(R l,R r,R v){
	if(l>r)return;
	IT il=Split(l-1),ir=Split(r);
	ir->v=v;
	s.erase(++il,ir);
}
inline LL Calc(R p){
	R i=s.lower_bound(Node(p))->v;
	return i?f[i]+(p-r[i]+k)%k:0;
}
int main(){
	R n=in();LL k=::k=in(),a=0,a1=0,ans=0;
	s.insert(Node(-1));
	s.insert(Node(k-1));
	for(R i=1;i<=n;++i){
		a1=a;a+=in();
		if(!(b[i]=in()&1))continue;
		if(2*(a-a1)>k)return puts("-1"),0;
		l[i]=(-2*a1%k+k)%k;r[i]=(-2*a%k+k)%k;
		ans=f[i]=Calc(r[i]);
		if(l[i]>r[i])Set(r[i]+1,l[i]-1,i);
		else Set(0,l[i]-1,i),Set(r[i]+1,k-1,i);
	}
	for(R i=1;i<=n;++i)
		if(b[i])ans=min(ans,min(Calc(l[i]),Calc(r[i])));
	cout<<ans+2*a<<endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) s[i] = 'x';
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 256