akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_146
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            string s = Read();
            bool[] cans = new bool[n + 1];
            for (int i = 0; i <= n; i++) cans[i] = s[i] == '0';
            Array.Reverse(cans);
            List<int> res = new List<int>();
            int now = 0;
            while (now < n)
            {
                bool can = false;
                for (int i = Min(m, n - now); i >= 1; i--)
                {
                    if (cans[now + i])
                    {
                        can = true;
                        now += i;
                        res.Add(i);
                        break;
                    }
                }
                if (!can)
                {
                    WriteLine(-1);
                    return;
                }
            }
            res.Reverse();
            res.ForEach((item) => { Write(item+" "); });
            WriteLine();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, l; std::cin >> n >> l;
  int sum = 0;
  vi v(n);
  rrep(i, n) {
    sum += l + i - 1;
    v[i-1] = l+i-1;
  }
  int ans = 0, diff = inf;
  rep(i, n) {
    int tmp = abs(sum-(sum-v[i]));
    if (diff > tmp) ans = sum-v[i], diff = tmp;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
 
int main(){
   int x, y;
   cin >> x >> y;

   int ans;

   if(x > y ){
      if(y == 0){
         ans = abs(y-x)+1;
      }
      else if(y < 0 && x >= 0){
         ans = abs(abs(x) - abs(y))+1;
      }
      else{
         ans = abs(y-x) +2;
      }
   }
   else{
      if(x >= 0 || y <= 0){
         ans = abs(y-x);
      }
      else{
         ans = abs(abs(x)-abs(y))+1;
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
/*
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331961#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331969#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2331970#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2332101#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2333449#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2335101#2
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2335527#2
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int main() {
	ll n, a, b;	cin >> n >> a >> b;
	ll sml = b + (n - 1)*a;
	ll big = a + (n - 1)*b;
	cout << max(0LL, big - sml + 1) << endl;
	return 0;
}

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

int main() {

  ll N,D;
  cin >> N >> D;
  ll pos[N][2];

  for(ll i = 0; i < N; i++){
    cin >> pos[i][0] >> pos[i][1];
  }

  ll ans = 0;

  for(ll i = 0; i < N; i++){
    if(D*D >= pos[i][0]*pos[i][0] + pos[i][1]*pos[i][1]){
      ans += 1;
    }

  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6688
#include <cstdio>
int main(){
    int in;
    int h,m,s;
    scanf("%d",&in);

    h = in / 3600;
    in %= 3600;

    m = in / 60;
    in %= 60;

    s = in;

    printf("%d:%d:%d\n",h,m,s);
}

Measured memory_bytes: 2728
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (h, w, d) = readIntegerList()
    val pMap = mutableMapOf<Int, Pair<Int, Int>>()
    for (i in 1..h) {
        val aList = readIntegerList()
        for (j in 1..w) {
            pMap[aList[j - 1]] = Pair(i, j)
        }
    }

    // Dごとに累積和をとる
    val sum = LongArray(h * w + d + 1)
    for (i in 1..(h * w - d)) {
        sum[i + d] =
            sum[i] + Math.abs(pMap[i + d]!!.first - pMap[i]!!.first) + Math.abs(pMap[i + d]!!.second - pMap[i]!!.second)
    }

    val q = readInteger()
    repeat(q) {
        val (l, r) = readIntegerList()
        println(sum[r] - sum[l])
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 80948
using System;

class E
{
	static void Main()
	{
		var M = 1000000007;
		var l = Console.ReadLine();
		var n = l.Length;

		var dp = new long[n + 1, 2];
		dp[0, 0] = 1;
		for (var i = 0; i < n; i++)
		{
			var f = l[i] == '1';
			dp[i + 1, 0] = (f ? 2 : 1) * dp[i, 0] % M;
			dp[i + 1, 1] = ((f ? dp[i, 0] : 0) + 3 * dp[i, 1]) % M;
		}
		Console.WriteLine((dp[n, 0] + dp[n, 1]) % M);
	}
}


Measured memory_bytes: 13224
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  h,w,i,j,count,x,y,sw,m,n,b,c,soeji:Integer;
  a:array of Integer;
  s123,s1,s2,s3:string;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);
    SetLength(a,n+1);
    for i := 1 to n do
      Readln(a[i]);

    soeji:=1;
    for i := 1 to n do begin
      if a[soeji]=2 then begin
        Writeln(i);
        Readln;
        exit;
      end;
      soeji:=a[soeji];
    end;

    Writeln('-1');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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




int main(){

int n;
cin>>n;
int d[n][2];
for(int i=0;i<n;i++){
    cin>>d[i][0]>>d[i][1];
}
int flag=0;
for(int i=0;i<n-2;i++){
    if(d[i][1]==d[i][0] &&d[i+1][1]==d[i+1][0] &&d[i+2][1]==d[i+2][0] ){
        flag=1;
        break;
    }
}
if(flag){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}

}


Measured memory_bytes: 3628
# python3.4.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = input()

a_count = S.count("a")
b_count = S.count("b")
c_count = S.count("c")

if abs(a_count - b_count) <= 1 and abs(b_count-c_count) <= 1 and abs(c_count-a_count) <= 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 5428
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int, int> pll;
bool visited[100005];
const int max_N = 1e5 + 10;

int A;
int B;
int C;
int N;
char S[100005];
int l[100005];
int r[100005];

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

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (S[i]=='R'){
			count++;
		}
		else {
			count=count-1;
		}
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,x,a[SZ];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;++i)
		scanf("%d",a+i);
	sort(a+1,a+1+n);
	int cn=0;
	for(int i=1;i<=n;++i)
	{
		x-=a[i];
		if(x<0) break;
		++cn;
	}
	if(x>0) --cn;
	cout<<cn<<"\n";
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

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

	int N=in();
	vector<vector<int>> A(2,vector<int>(N,0)),DP(2,vector<int>(N,0));

	REP(i,2){
		REP(j,N){
			A[i][j]=in();
		}
	}
	DP[0][0]=A[0][0];
	DP[1][0]=A[0][0]+A[1][0];
	REP(i,N-1){
		REP(j,2){
			chmax(DP[j][i+1],DP[j][i]+A[j][i+1]);
			if(j<1){
				chmax(DP[j+1][i],DP[j][i]+A[j+1][i]);
			}
		}
	}
	
	out(DP[1][N-1]);
	return 0;
}


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

int main(void){

    int N,ac=0,wa=0,tle=0,re=0,i;
    char S[4];

    scanf("%d",&N);
    for(i=0;i<N;i++){
        S[0]="\0";
        scanf("%s",S);
        if(!strcmp(S,"AC")) ac++;
        else if(!strcmp(S,"WA")) wa++;
        else if(!strcmp(S,"TLE")) tle++;
        else if(!strcmp(S,"RE")) re++;
    }

    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);   

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define MAXN 100000
#define MOD 1000000007

using namespace std;

int fact[MAXN + 1];

int main() {
  //  ifstream cin("A.in");
  //  ofstream cout("A.out");
    int i,n,m;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    fact[0] = 1;
    for(i = 1; i <= MAXN ;i ++)
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    if(std::abs(n - m) >= 2)
        cout << 0 << endl;
    else {
        if(n > m)
            std::swap(n, m);
        if(n == m)
            cout << (1LL * fact[n] * fact[m] * 2) % MOD << endl;
        else
            cout << (1LL * fact[n] * fact[m]) % MOD << endl;
    }
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();
		String[] array = s.split(" ");

		int a = Integer.parseInt(array[0]);
		int b = Integer.parseInt(array[1]);
		int c = Integer.parseInt(array[2]);

		int ab = a + b;
		int bc = b + c;
		int ac = a + c;

		if (ab <= bc && ab <= ac) {
			System.out.println(ab);
		} else if (bc <= ab && bc <= ac) {
			System.out.println(bc);
		} else if (ac <= bc && ac <= ab) {
			System.out.println(ac);
		}
	}
}


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

//Containers
typedef long long int lng;
#define vint vector<int>
#define vtwod vector<vector<int>>
#define vlng vector<long long int>
#define vstr vector<string>
#define vpint vector<pair<int,int>>
#define pint pair<int,int>
#define lint list<int>
#define qint queue<int>
#define dqint deque<int>
#define pq priority_queue<int>
#define rpq priority_queue<int,vector<int>,greater<int>>
#define fl forward_list<int>
#define st stack<int>
#define sint set<int>
#define msint multiset<int>


//Methods of containers:-
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define binsear binary_search
#define popf pop_front
#define popb pop_back
#define empb emplace_back
#define empf emplace_front
#define emp emplace
#define emt empty
#define ins insert
#define insaft insert_after
#define emplaft emplace_after
#define ersaft erase_after
#define swp swap
#define splicaft splice_after


//FUNCTIONS
bool isprime(int n)
{
    if(n<=1)
    {
        return false;
    }
    for(size_t i=2;i<n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }
    return true;
}

int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}

int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}

void gcd(int a,int b)
{
    cout<<__gcd(a,b)<<endl;
}

/*******************************************************CODE**************************************************************/
void doit()
{
    int k=0,n=0,num=0,sum=0;
    cin>>n>>k;
    rpq v;
    for(size_t i=0;i<n;i++)
    {
        cin>>num;
        v.push(num);
    }
    for(size_t i=0;i<k;i++)
    {
        sum+=v.top();
        v.pop();
    }
    cout<<sum<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(NULL);
    doit();
    return 0;
}



Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {

    string s;
    vector<char> v(10);
    cin >> s;
    int n = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            v[n] = '0';
            n++;
        }else if(s[i] == '1'){
            v[n] = '1';
            n++;
        }else{
            if(n > 0) n--;
        }
    }

    for(int i = 0; i < n; i++){
        cout << v[i];
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int binarySearch(int [],int,int);

int main()
{
  int S[100000],key,n,q,i,c=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      if(binarySearch(S,n,key)!=0)c++;
    }
  printf("%d\n",c);

  return 0;
}

int binarySearch(int S[],int n,int key)
{
  int left=0,right=n,mid;
  while(left<right)
    {
      mid=(left+right)/2;
      if(S[mid]==key)return mid;
      else if(key<S[mid])right=mid;
      else left=mid+1;
    }
  return 0;
}

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

int main(){
  int S;
  cin >> S;
  int a=S/100;
  int b=S%100;
  if(1<=a&&a<=12){
    if(1<=b&&b<=12){
      cout << "AMBIGUOUS" << endl;
    }else{
      cout << "MMYY" << endl;
    }
  }else{
    if(1<=b&&b<=12){
      cout << "YYMM" << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int H,W;
int fields[200][200];
bool dp[200][200];
int recoursion(int y,int x){
        if(dp[y][x])
                return false;
        dp[y][x]=true;
        if(fields[y][x]==0){
                H=y;W=x;
                return true;
        }
        else if(fields[y][x]==1)
                return recoursion(y-1,x);
        else if(fields[y][x]==2)
                return recoursion(y+1,x);
        else if(fields[y][x]==3)
                return recoursion(y,x-1);
        else if(fields[y][x]==4)
                return recoursion(y,x+1);
        else
                return false;
}
int main(){
        while(true){
                cin >> H >> W;
                if(H+W==0)
                        break;
                string str;
                for(int i=0 ; i<H ; i++ ){
                        cin >> str;
                        for(int l=0 ; l<W ; l++ ){
                                dp[i][l]=false;
                                if(str[l]=='.')
                                        fields[i][l]=0;
                                else if(str[l]=='^')
                                        fields[i][l]=1;
                                else if(str[l]=='v')
                                        fields[i][l]=2;
                                else if(str[l]=='<')
                                        fields[i][l]=3;
                                else if(str[l]=='>')
                                        fields[i][l]=4;
                        }
                }
                if(recoursion(0,0))
                        cout<<W<<" "<<H<<endl;
                else
                        cout<<"LOOP"<<endl;
        }
        return 0;
}

Measured memory_bytes: 3264
import java.util.Scanner;

/**
 * ABC043A
 */
public class Main {

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

        int N = sc.nextInt();

        int candies = 0;
        for (int i = 1; i <= N; i++) {
            candies += i;
        }

        System.out.println(candies);
        sc.close();
    }
}

Measured memory_bytes: 22740
A = int(input())
B = int(input())

if A == 1:
    if B == 2:
        print(3)
    else:
        print(2)
elif A == 2:
    if B == 1:
        print(3)
    else:
        print(1)
elif A == 3:
    if B == 1:
        print(2)
    else:
        print(1)

Measured memory_bytes: 38384
#include<stdio.h>
#define MAX 100000
int A[MAX],n;
int parti( int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;

}
int main()
{
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q=parti(0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");
  return 0;

}
  

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = b * (n - 1) + a - (a * (n - 1) + b) + 1;

    cout << max(0ll, ans) << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

int n;
vector <int> app[30];
char val[maxn];

int idx(char x)
{
	return x-'a'+1;
}

void solve()
{
	scanf("%s",val+1);
	int len=strlen(val+1);
	repp(i,1,len)
	{
		app[idx(val[i])].push_back(i);
	}
	int flag=0;
	int x=0,y=0;
	repp(i,1,26)
	{
		int sz=app[i].size();
		if(sz<=1)
		{
			continue;
		}
		for(int j=1;j<sz;j++)
		{
			if(app[i][j]-app[i][j-1]<3)
			{
				flag=1;
				x=app[i][j-1];
				y=app[i][j];
				break;
			}
		}
		if(flag)
		{
			break;
		}
	}
	if(!flag)
	{
		puts("-1 -1");
	}
	else
	{
		printf("%d %d",x,y);
	}
}

int main()
{

    solve();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(init, i, n) for (int i = init; i < (n); i++)
#define ll long long
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end())
#define PI 3.14159265358979323846264338327950
//コード自動整形 Shift + Option + F @vscode
using namespace std;

/////main/////
int main()
{
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double rad = 2 * PI * ((H * 30) + (M * 0.5) - 6 * M) / 360;

    long double output = sqrt(A * A + B * B - 2.0 * A * B * cos(rad));

    cout << fixed << setprecision(10)<< output << endl;
}
/////main/////

/////function/////

Measured memory_bytes: 4140
package main

import (
	"fmt"
)

func main() {
	var w, h, x, y, r int

	fmt.Scan(&w, &h, &x, &y, &r)

	if x < r {
		fmt.Println("No")
	} else if y < r {
		fmt.Println("No")
	} else if x+r > w {
		fmt.Println("No")
	} else if y+r > h {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}



Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int N;
    cin>>N;
    vector<int> H(N);
    rep(i,N) cin>>H.at(i);
    vector<int> sa(N);
    sa.at(0)=0;
    rep(i,N-1){
        if(H.at(i+1)<=H.at(i)){
            sa.at(i+1)=sa.at(i)+1;
        }else{
            sa.at(i+1)=0;
        }
    }
    int max=0;
    rep(i,N){
        if(sa.at(i)>=max) max=sa.at(i);
    }
    cout<<max<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
 
int main(){
int a,b,c,n;
cin>>a>>b>>c;
 
if(a>b){
n=a;
a=b;
b=n;
}
if(b>c){
n=b;
b=c;
c=n;
if(a>b){
n=a;
a=b;
b=n;
}
}
cout<<a<<" "<<b<<" "<<c<<endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    int x;
    cin >> x;
    a[x-1]++;
  }
  sort(a.begin(), a.end());
  vector<int> s(n+1);
  rep(i,n) s[i+1] = s[i] + a[i];
  for (int k = 1; k <= n; ++k) {
    int l = 0, r = n/k+1;
    while(r-l > 1) {
      int c = (l+r)/2;
      bool ok = [&](int c) {
          int i = lower_bound(a.begin(), a.end(), c) - a.begin();
          int sum = c * (n-i) + s[i];
          return (sum >= c*k);
      }(c);
      if (ok) l = c; else r = c;
    }
    printf("%d\n", l);
  }
  return 0;
}

Measured memory_bytes: 5492
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h> 
#include<math.h>


using namespace std;
typedef long long ll;


int main(){
	int n,m=0;
	cin>>n;
	char a[n];
	for(int i=0;i<n;i++) 
		cin>>a[i];
	for(int i=0;i<n;i++) 
	{if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')  m+=1;
	}
	cout<<m;
	
	

	 

	
	return 0;
}





Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int A[20];
int x[20][20];
int y[20][20];

int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
		REP(j,A[i]){
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
			y[i][j];
		}
	}
	int ans=0;
	REP(i,1<<N){
		bool check=true;
		REP(j,N){
			if((i>>j)&1){
				REP(k,A[j]){
					int b=(i>>x[j][k])&1;
					//cout<<(i>>x[j][k])<<" "<<y[j][k]<<" "<<i<<" "<<j<<" "<<k<<" "<<b<<endl;
					if(b!=y[j][k]){
						check=false;
					}
				}
			}
		}
		int aa=0;
		if(check==true){
			//cout<<i<<" 答え"<<endl;
			REP(j,N){
				if((i>>j)&1){
					aa++;
				}
			}
		}
		ans=max(ans,aa);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[222222];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,ans;
priority_queue<int>q;
signed main(){
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		q.push(a);
	}
	while(q.top()>=n){
		int p=q.top();
		q.pop();
		//p→n-1
		int memo=p-(n-1);
		int cnt=(memo-1)/n+1;
		int a[55];
		rep(i,n-1){
			a[i]=q.top();
			q.pop();
		}
		q.push(p-(cnt*n));
		rep(i,n-1){
			a[i]+=cnt;
			q.push(a[i]);
		}
		ans+=cnt;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def prime(N):
    p = 2
    koko = int(N**0.5)
    while N != 1:
        if N % p == 0:
            yaku[p] += 1
            N //= p
        elif p > koko:
            p = N
        else:
            p += 1
    return


N = int(input())

ans = 0
mod = 10**9 + 7
yaku = [0 for i in range(10**3)]
for i in range(1, N + 1):
    prime(i)

ans = 1
for a in yaku:
    ans *= a + 1
print(ans % mod)


Measured memory_bytes: 3064
/*
 * ----------------------------------------------------------------------------
 *  (: Bismillahir Rahmanir Rahim :) 
 * File: /home/grim/Programming/Atcoder/Today/B_Substring.cpp
 * Project: /home/grim/Programming/Atcoder/Today
 * Created Date: Saturday, August 29th 2020, 6:09:52 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Aug 29 2020
 * Modified By: Grim Firefly :)
 * -----
 *   ________        .__           ___________.__                  _____ .__          
 *  /  _____/_______ |__|  _____   \_   _____/|__|_______   ____ _/ ____\|  |  ___.__.
 * /   \  ___\_  __ \|  | /     \   |    __)  |  |\_  __ \_/ __ \\   __\ |  | <   |  |
 * \    \_\  \|  | \/|  ||  Y Y  \  |     \   |  | |  | \/\  ___/ |  |   |  |__\___  |
 *  \______  /|__|   |__||__|_|  /  \___  /   |__| |__|    \___  >|__|   |____// ____|
 *         \/                  \/       \/                     \/              \/     
 * 
 *           |\_|\
 *           | a_a\
 *           | | "]
 *       ____| '-\___
 *      /.----.___.-'\
 *     //        _    \
 *    //   .-. (GF)  /|
 *   |'|  /\:  .--  / \
 *  // |-/  \_/____/\/~|
 * |/  \ |  []_|_|_] \ |
 * | \  | \ |___   _\ ]_}
 * | |  '-' /   '.'  |
 * | |     /    /|:  | 
 * | |     |   / |:  /\
 * | |     /  /  |  /  \
 * | |    |  /  /  |    \
 * \ |    |/\/  |/|/\    \
 *  \|\ |\|  |  | / /\/\__\
 *   \ \| | /   | |__
 *        / |   |____)
 *        |_/
 * ----------------------------------------------------------------------------
 */

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

//constant
#define PI acos(-1.0)
#define SZ 10000
#define mod 1000000007
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef unsigned un;
typedef pair<int, int> pii;
typedef vector<int> vi;

//Debug Setting up
#define watch(x) cout << (#x) << "=" << x << endl
#define watch2(x, y) cout << (#x) << "=" << x << " & " << (#y) << "=" << y << endl;
#define watchara(wow)     \
    for (auto x : wow)    \
    {                     \
        cout << x << " "; \
    }                     \
    cout << "\n"

//defining fast_io
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

//defining something
#define F first
#define S second

//Main Function Start From Here
void solve()
{
    string mn, sub;
    cin >> mn;
    cin >> sub;
    int mill = 0;
    for (int i = 0; i <= mn.size() - sub.size(); i++)
    {
        int cnt = 0;
        for (int j = 0; j < sub.size(); j++)
        {
            if (mn[i + j] == sub[j])
            {
                cnt++;
            }
        }

        mill = max(cnt, mill);
    }
    cout << sub.size() - mill << endl;
}

int main()
{
    fast_io;

    solve();

    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
#include <math.h>
using namespace std;
void solve(){
    string s;
    cin >> s;
    bool check = false;
    bool br = false;
    int i;
    for (i = (s.size() - 1) / 2; i > 0; i--){//iは文字数を表す(1 - sのサイズの半分)
        for(int j = 0; j < s.size() - 2 * i + 1; j++){//jは標準刺激のスタート地点、0からsのサイズ*2を引いたところの次まで
        br = false;
            if(j == 0){//jが0のとき、最後の文字を削らねばならない
                for(int k = 0; k < i; k++){
                    if(s.at(j + k) != s.at(j + i + k))
                    break;  //違うのが見つかったのでj==0の時のkについてのfor文を抜ける
                    if(k == i - 1){
                        check = true;
                    }
            }    
            }
                if(check)
                break;//もしj==0で成立すればjについてのfor文を抜ける
            else{
                for(int k = 0; k < i; k++){
                    if(s.at(j + k) != s.at(k + i + k)){
                        break;//違ったらbreak
                    }
                    if(k == i - 1){
                        check = true;
                    }
                }
            }
            if(check)
            break;
        }
        if(check)
        break;
    }
    cout << i * 2 << endl;
}
int main(){
    solve();
    return 0;
}

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

int main()
{
    ll a,b,n,ans,val;
    cin>>a>>b>>n;
    if(b==1)
    {
        ans=0;
    }

    else
    {
        val=min(b-1,n);
        ans=((a*val)/b)-a*(val/b);
    }

    cout<<ans;
}


Measured memory_bytes: 3592
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
 
	crap;

	int n, w;
	cin >> n >> w;

	vector<int> wt(n), val(n);

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

	for (int i = 0; i < n; ++i) {
		cerr << val[i] << " ";
	}

	int dp[n + 1][w + 1];
	for (int i = 0; i < n + 1; ++i) {
		for (int j = 0; j < w + 1; ++j) {
			if (i == 0 or j == 0)
				dp[i][j] = 0;
			else if (wt[i - 1] <= j)
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}

	cout << dp[n][w] << endl;

	return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
int ksm(int x,int k)
{
	if(k==1) return x;
	ll ans=ksm(x,k/2);
	ans=ans*ans%mod;
	if(k%2) ans=ans*x%mod;
	return ans;
}
int cc(int x,int y)
{
	ll ans=1,div=1;
	int i;
	for(i=x;i>=x-y+1;i--) ans=ans*i%mod;
	
	for(i=y;i>=1;i--) div=div*i%mod;
	
	ans=ans*ksm(div,mod-2)%mod;
	return ans;
}
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	int t=x+y;
	if(t%3){
		printf("0\n");
		return 0;
	}
	t/=3;
	if(t>x||t>y){
		printf("0\n");
		return 0;
	}
	printf("%d\n",cc(t,t*2-x));
	return 0;
}

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

int gcd(int a, int b){
	if(b==0) return gcd(b,a);
	if(a%b==0) return b;
	return gcd(b,a%b);
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	vector<int> l(n),r(n);
	for(int i=1; i<n; i++){
		l[i] = gcd(l[i-1], a[i-1]);
	}
	for(int i=n-2; i>=0; i--){
		r[i] = gcd(r[i+1], a[i+1]);
	}
	int ans = 1;
	for(int i=0; i<n; i++){
		ans = max(ans, gcd(l[i],r[i]));
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    if(s.length()!=t.length()){
    	cout << "No\n"; return 0;
    }
    if(s==t){
    	return cout << "Yes\n", 0;
    }
    for(int i=1; i<s.length(); i++){
    	s=s.substr(1)+s[0];
    	if(s==t){
    		return cout << "Yes\n", 0;
    	}
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
X = [a,b,c,d,e]
t = 0

m = 10
for x in X:
    if x%10==0:
        t += x
    else:
        t += (x//10+1) * 10
        m = min(m, x%10)
t = t - 10 + m
print(t)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <queue>
#define MAXN 500
#define FL(i,j,k) for(ll i=j;i<k;++i)
using namespace std;
typedef long long int ll;
ll a,b,c,d,e,f,g;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>a>>b;
    char ab;
    int bc;
    FL(i, 0, a)FL(j, 0, b){
        string s;cin>>s;
        if(s=="snuke"){
            ab=(char)(j+'A'),bc=i+1;
        }
    }
    cout<<ab<<bc;
}


Measured memory_bytes: 384
alpha = list("abcdefghijklmnopqrstuvwxyz")

s = list(str(input()))
t = list(str(input()))

info = [[0] * len(s) for _ in range(26)]

ss = s[:] * 2

for i in range(26):
    last = -1
    for j in range(len(ss)-1,-1,-1):
        info[i][j%(len(s))] = last
        if ss[j] ==  alpha[i]:
            last = j % (len(s))
#print(info)

count = 0
num = 0
place = -1

while num < len(t):
    x = info[alpha.index(t[num])][place]
    if x > place:
        count += x - place
    else:
        count += x - place + len(s)
    place = x
    num += 1

s_ = [0] * 26
t_ = [0] * 26
for lets in s:
    s_[alpha.index(lets)] = 1
for lett in t:
    t_[alpha.index(lett)] = 1
for i in range(26):
    if s_[i] < t_[i]:
        count = -1
        break

print(count)

Measured memory_bytes: 83056
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

static const double eps = 10e-9;

int main(){
	int n;

	while(~scanf("%d",&n)){
		if(n==0) break;

		vector<int> input;
		for(int i=1;i<=n-1;i++){
			input.push_back((i*i)%n);
		}

		int* table = new int[(n-1)/2+1]();

		sort(input.begin(),input.end());

		vector<int>::iterator end_it = unique(input.begin(),input.end());
		input.erase(end_it,input.end());

		for(int i=0;i<input.size();i++){
			for(int j=0;j<input.size();j++){
				if(i==j) continue;
				int calc = input[i]-input[j] ;
				if(calc < 0) calc+=n;
				if(calc > (n-1)/2) calc = n - calc;

				table[calc]++;
			}
		}

		for(int i=1;i<(n-1)/2+1;i++){
			printf("%d\n",table[i]);
		}

		delete[] table;
	}
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

int n;
int a = 0;
int main() {
    scanf("%d",&n);
    int m = n;
    rep(i,0,8){
        a += n%10;
        n /= 10;
    }
    if(m%a == 0) puts("Yes");
    else puts("No");
    return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }
template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}
// -------------------------------------------------------------------

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

    int l;
    cin >> l;
    vec a(l + 1);
    rep (i, l)
        cin >> a[i + 1];

    mat dp(5, vec(l + 1));

    For(i, 1, l) {
        rep (j, 5) {
            int pre = INF;
            For(k, 0, j) pre = min(pre, dp[k][i - 1]);
            int now;
            if (j == 0 or j == 4)
                now = a[i];
            else if (j == 1 or j == 3) {
                if (a[i] == 0)
                    now = 2;
                else
                    now = a[i] % 2;
            } else
                now = !(a[i] % 2);

            dp[j][i] = pre + now;
        }
    }
    int ans = INF;
    rep (i, 5)
        ans = min(ans, dp[i][l]);

    print(ans);

    return 0;
}


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

int main() {
    int s;
    cin >> s;
    set<int> st;
    st.insert(s);
    for(int i=2;i<=1000000;i++){
        if(s%2==0){
            s = s/2;
        }else{
            s = 3*s+1;
        }
        if(st.find(s) != st.end()){
            cout << i << endl;
            return 0;
        }
        st.insert(s);
    }
    return 0;
}

Measured memory_bytes: 256
def swap(a, i, j)
  tmp = a[j]
  a[j] = a[i]
  a[i] = tmp
  a
end

def bubble_sort(a, n)
  (0..n - 1).each do |i|
    (n - 1).downto(i + 1) do |j|
      a = swap(a, j, j - 1) if a[j][1] < a[j - 1][1]
    end
  end
  puts a.join(' ')
end

def selection_sort(a, n)
  (0..n - 1).each do |i|
    minj = i
    (i..n - 1).each do |j|
      minj = j if a[j][1] < a[minj][1]
    end
    a = swap(a, i, minj)
  end
  puts a.join(' ')
end

def is_stable(a, b, n)
  (0..n - 1).each do |i|
    (i + 1..n - 1).each do |j|
      (0..n - 1).each do |l|
        (l + 1..n - 1).each do |m|
          return false if a[i][1] == a[j][1] && a[i] == b[m] && a[j] == b[l]
        end
      end
    end
  end
  true
end
n = gets.to_i
a = gets.split
b_a = a.dup
s_a = a.dup
bubble_sort(b_a, n)
puts is_stable(a, b_a, n) ? 'Stable' : 'Not stable'
selection_sort(s_a, n)
puts is_stable(a, s_a, n) ? 'Stable' : 'Not stable'



Measured memory_bytes: 6884
scores = readlines
  scores.each do |score|

    texam,kexam,sexam = score.split.map(&:to_i)

    break if (texam == -1) && (kexam == -1) && (sexam == -1)
      exam = texam + kexam

      if (texam == -1) || (kexam == -1)
        puts "F"

      elsif exam >= 80
        puts "A"

      elsif exam >= 65 && exam < 80
        puts "B"

      elsif exam >= 50 && exam < 65
        puts "C"
        
      elsif exam >= 30 && exam < 50

        if sexam >= 50
          puts "C"
        else
          puts "D"
        end

      elsif texam + kexam <= 29
        puts "F"
      end

  end



Measured memory_bytes: 6876
T = [0]

def curserch(N,k,T,P,n):
    T[0] = T[0]+1
    P[k]["d"] = T[0]
    for i in range(1,n+1):
        if N[k][i]==1 and P[i]["d"]==0:
            curserch(N,i,T,P,n)
            T[0] = T[0]+1
            P[i]["f"]=T[0]


n = int(input())
A = [[0 for j in range(n+1)] for i in range(n+1)]


for i in range(n):
    vec = input().split()
    u = int(vec[0])
    k = int(vec[1])
    nodes = vec[2:]
    for i in range(int(k)):
        v = int(nodes[i])
        A[u][v] = 1

P=[{"d":0} for i in range(n+1)]
for i in range(1,n+1):
    if P[i]["d"]==0:
        curserch(A,i,T,P,n)
        T[0] = T[0]+1
        P[i]["f"]=T[0]
for i in range(1,n+1):
    print(i,P[i]["d"],P[i]["f"])

Measured memory_bytes: 7872