akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D, T, S;
  cin >> D >> T >> S;
  
  if ( D%S == 0) {
  	if ( D/S <= T ) {
    	cout << "Yes" << endl;
	  }
  
  	else {
    	cout << "No" << endl;
 	 }
  }
  
  else if ( D%S != 0 ) {
    if ( D/S+1 <= T ) {
      cout << "Yes" << endl;
    }
    
    else {
      cout << "No" << endl;
    }
  }
    
}

Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(), a.rend());
    a.push_back(0);
    rep(i,n){
        //a[i],a[i+1]
        if(a[i]<=i+1 or a[i+1]<=i+1){
//            (i,i)
            int x = i, y = i;
            int X = 0;
            while(i < a[x+X])X++;
            int Y = a[i] -i;
            if(X%2==0 or Y%2==0){
                cout << "First" << endl;
            }else{
                cout << "Second" << endl;
            }
            return 0;
        }
    }
}


Measured memory_bytes: 1024
#import<ios>
int D,d,c,a,X=448;char s[9];
int main()
{
for(;c+21&&scanf("%s",s);a+=D/64)
c=*s-69,
d=511-D,
D=
c==9 ?D* 8&X|d/ 8&56|D   &7:
c==14?d* 8&X|D/ 8&56|D   &7:
!c   ?d*64&X|D   &56|D/64&7:
c==18?D*64&X|D   &56|d/64&7:
c==13?D   &X|D* 8&56|d/ 8&7:
c==7 ?D   &X|d* 8&56|D/ 8&7:
(a&&printf("%d\n",a),a=0,83);
}

Measured memory_bytes: 0
X,N = map(int,input().split())
P = list(map(int,input().split()))


P_n = [i for i in range(110) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Measured memory_bytes: 9044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int N = s.size();
	int cnt = 0;
	for(int i = 0; i < N; ++i)
	{
		if(i % 2 == 0 && s[i] == 'p')
			--cnt;
		else if(i % 2 == 1 && s[i] == 'g')
			++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int d;
    cin >> d;
    vector<ll> decrease(26);
    for(int i = 0; i < 26; i++) cin >> decrease[i];
    vector<vector<ll>> increase(d, vector<ll>(26));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++){
            cin >> increase[i][j];
        }
    }
    for(int i = 0; i < d; i++){
        int mx = 0;
        int contest = -1;
        for(int j = 0; j < 26; j++){
            if(increase[i][j] >= mx) {mx = increase[i][j]; contest = j + 1;}
        }
        cout << contest << "\n";
    }
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, j, k, ans;
	string s;
	cin >> s >> k;
	vector<vector<vector<int>>> dp(s.size() + 1, vector<vector<int>>(k + 1, vector<int>(2, 0)));
	dp[0][0][0] = 1;
	rep(i, s.size()) {
		if (s[i] == '0') {
			rep(j, k + 1) {
				dp[i + 1][j][0] = dp[i][j][0];
				dp[i + 1][j][1] = dp[i][j][1];
			}
			rep(j, k) {
				dp[i + 1][j + 1][1] += 9 * dp[i][j][1];
			}
		}
		else {
			rep(j, k + 1) {
				dp[i + 1][j][1] = dp[i][j][0] + dp[i][j][1];
			}
			rep(j, k) {
				dp[i + 1][j + 1][0] = dp[i][j][0];
				dp[i + 1][j + 1][1] += (s[i] - '1') * dp[i][j][0] + 9 * dp[i][j][1];
			}
		}
	}
	ans = dp[s.size()][k][0] + dp[s.size()][k][1];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (A, B, C, D) = next().map { it - '0' }
    fun sign(a: Int) = if (a < 0) '-' else '+'
    for (bit in 0 until (1 shl 3)) {
        val b = if (((bit shr 0) and 1) == 1) -B else B
        val c = if (((bit shr 1) and 1) == 1) -C else C
        val d = if (((bit shr 2) and 1) == 1) -D else D
//System.err.println("$bit:  $A${sign(b)}$B${sign(c)}$C${sign(d)}$D=${A+b+c+d}")
        if (A + b + c + d == 7) {
            return println("$A${sign(b)}$B${sign(c)}$C${sign(d)}$D=7")
        }
    }
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 33820
s = input()

ans, cnta = 0, 0
for i in range(len(s)):
    if s[i] == 'A':
        cnta += 1
    elif s[i:i + 2] == 'BC':
        ans += cnta
    elif s[i - 1:i + 1] != 'BC':
        cnta = 0
print(ans)


Measured memory_bytes: 68100
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N; cin >> N;
    vi P(N); REP(i, N) {
        cin >> P[i];
        P[i]--;
    }

    vb a(N+1, false);
    REP(i,N){
        if (P[i] == i) a[i] = true;
    }

    map<int, int> mp;
    int i = 0;
    while(i<N) {
        int j = i;
        while (a[j]) j++;

        if (i<j) {
            mp[j - i]++;
            i = j;
        }
        else {
            i++;
        }
    }

    int ans = 0;
    for(auto p : mp) {
        ans += (p.first + 1) / 2 * p.second;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	int ret=0;
	for(int i=0;i<a;i++){
			int p;scanf("%d",&p);
			if(p<b||p>=c)ret++;
	}printf("%d\n",ret);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    vector<int>p(n+2);
    int temp;
    rep(i,n){
        cin >> temp;
        p[temp] = i+1;
    }
    rep(i,n){
        cout << 30000*(i+1) << " ";
    }
    cout << endl;
    rep(i,n){
        cout << 30000*(n-i)+p[i+1] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 640
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

n=I()
d=LI()
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=d[i]*d[j]
print(ans)


Measured memory_bytes: 38768
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
int main(void){
    
    string S;
    cin >> S;
    
    int A_posi = 0;
    int Z_posi = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'A'){
            A_posi = i;
            break;
        }
    }
    for(int i = S.size() - 1; i >= 0; i--){
        if(S[i] == 'Z'){
            Z_posi = i;
            break;
        }
    }
    
    int ans = Z_posi - A_posi + 1;
    cout << ans << endl;
    

}


Measured memory_bytes: 3376
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
    int n,a;
    cin >> n >> a;
    Yes(n%500 <= a);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        cin>>s;n=s.length();
        for(i=0;i<n;i++)
            cnt+=(int)(s[i]-'0');
        if(cnt%9==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3704
from sys import stdin, exit
import itertools
#stdin = open("input.txt")

if __name__ == "__main__":
    s = stdin.readline().rstrip()
    t = stdin.readline().rstrip()
    
    s = sorted(s)
    t = sorted(t, reverse=True)
    
    print("Yes" if s < t else "No")
        

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

int main(){
    int n, p;
    int bowl, pebbles[50];
    int winner;
    cin >> n >> p;
    while(n || p){
        for(int i=0;i<n;++i){
            pebbles[i] = 0;
        }
        bowl = p;
        winner = 1000;
        while(true){
            for(int i=0;i<n;++i){
                if(bowl){
                    ++pebbles[i];
                    --bowl;
                }else{
                    bowl = pebbles[i];
                    pebbles[i] = 0;
                }
                if(pebbles[i] == p){
                    winner = i;
                    break;
                }
            }
            if(winner < 50) break;
        }
        cout << winner << endl;
        cin >> n >> p;
    }
}

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

#define ris   return *this
#define tmplt template<class T
#define dbgo  debug& operator<<
tmplt > struct rge { T b, e; };
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
~debug(){cerr<<endl;}
tmplt > dbgo(T x){cerr<<boolalpha<<x;ris;}
tmplt, class C > dbgo(pair<T, C> x){ris<<"("<<x.first<<", "<<x.second<<")";}
tmplt > dbgo(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}ris<<"]";}
tmplt > dbgo(vector<T> x){ris<<range(x.begin(),x.end());}
#else
tmplt > dbgo(const T&){ris;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}

const int mxN = 700;
const int inf = 1e9+5;
int g[mxN][mxN], color[mxN], n, m, white, black;


bool dfs(int u, int c) {
    color[u] = c;
    if(c == 0) {
        white++;
    }
    else {
        black++;
    }
    forn(v, n) if(g[u][v]) {
        if(color[v] == -1) {
            if(!dfs(v, c^1)) {
                return false;
            }
        } else if(color[v] == color[u]) {
            return false;
        }
    }
    
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(color, -1, sizeof color);
    cin >> n >> m;
    
    forn(i, m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u][v] = g[v][u] = 1;
    }
    forn(i, n) forn(j, n) if(i != j) g[i][j] ^= 1;
    vector<pair<int,int>> a;
    forn(i, n) {
        if(color[i] == -1) {
            white = black = 0;
            if(!dfs(i, 0)) {
                cout << "-1\n";
                exit(0);
            }
            a.emplace_back(white, black);
        }
    }
    int k = a.size();
    vector<vector<int>> dp(k+1, vector<int>(n+1, -inf));
    dp[0][0] = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= n; j++) {
            int& me = dp[i][j];
            int x = a[i-1].first, y = a[i-1].second;
            if(x <= j) {
                max_self(me, dp[i-1][j-x] + x);
            }
            if(y <= j) {
                max_self(me, dp[i-1][j-y] + y);
            }
        }
    }
    ll ans = inf;
    forn(i, n+1) {
        ll v1 = dp[k][i];
        ll v2 = n - v1;
        min_self(ans, v1 * (v1-1) / 2 + v2 * (v2-1) / 2);
    }
    
    cout << ans << endl;
}













// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 4096
def main():

    N, K, Q = map(int, input().split())
    d = dict()
    for _ in range(Q):
        a = int(input())
        d[a] = d.get(a, 0) + 1
    for i in range(1, N+1):
        if i in d:
            v = K-(Q-d[i])
        else:
            v = K - Q
        if v > 0:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 1001001001;

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    int ans = 0;

    while(N > 0){
        if(N <= K){
            ans++;
            N -= K;
        }
        else{
            ans++;
            N = N-(K-1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
class PriorityQueue
  def initialize(array=[])
    @heap = array.sort_by(&:first)
  end
  def push(val, pri = nil)
    @heap.push([pri || val, val])
    adjust_up
  end
  def pop
    swap(0, @heap.size-1)
    val = @heap.pop[1]
    adjust_down
    val
  end
  def sort
    Array.new(@heap.size){ pop }
  end
  def size
    @heap.size
  end
  def empty?
    size == 0
  end
  private
  def adjust_down
    index = 0
    size = @heap.size
    while has_child?(index)
      left = index * 2 + 1
      right = left + 1
      min = left
      min = right if right < size && @heap[left][0] > @heap[right][0]
      if @heap[index][0] > @heap[min][0]
        swap(index, min)
        index = min
      else
        break
      end
    end
  end
  def adjust_up
    index = @heap.size - 1
    while index > 0
      parent = parent_index(index)
      if @heap[index][0] < @heap[parent][0]
        swap(index, parent)
      else
        break
      end
      index = parent
    end
  end
  def has_child?(idx)
    idx*2+1 < size
  end
  def parent_index(index)
    ((1+index) / 2) -1
  end
  def swap(x,y)
    @heap[x],@heap[y] = @heap[y],@heap[x]
  end
end


N,M = gets.split.map(&:to_i)
prices = gets.split.map(&:to_i)
pq = PriorityQueue.new
prices.each{|v| pq.push(v,-v) }
M.times do
  price = pq.pop / 2
  pq.push(price, -price)
end
 
puts Array.new(N){ pq.pop }.sum

Measured memory_bytes: 24656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(),x.end()
#define SZ(x) (ll) x.size()
#define f first
#define s second
#define MAXN 100100

ll A[MAXN];
ll a,N;

ll gcd(ll a, ll b){
	if (a<b)swap(a,b);
	if (b == 0)return a;
	return gcd(b, a%b);
}

ll query(){
	// for (ll i=1;i<=N;++i)cout<<A[i]<<' ';cout<<'\n';
	a = 0;
	for (ll i=1;i<=N;++i)a += A[i]-1;
	if (a%2 == 1){
		return 1;
	}
	// Other case is if everything except 1 thing is even
	ll ind = -1;
	for (ll i=1;i<=N;++i){
		if (A[i] == 1)return 2;
		if (A[i]%2 == 1){
			if (ind == -1)ind = i;
			else {
				return 2;
			}
		}
	}
	if (ind == -1){return 2;}
	--A[ind];
	ll l = A[1];
	for (ll i=2;i<=N;++i)l = gcd(l, A[i]);
	assert(l != 1);
	
	for (ll i=1;i<=N;++i)A[i] /= l;
	return 3 - query();
}

int main(){
	cin>>N;
	for (ll i=1;i<=N;++i)cin>>A[i];
	if (query() == 1)cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long h,w,x,y;
    cin>>w>>h>>x>>y;
    cout<<h*w/2;
    if(h*w%2)
    {
        cout<<".5 ";
    }else
    {
        cout<<" ";
    }
    if(x * 2 == w && y * 2 == h)
    {
        cout<<1<<endl;
    }else
    {
        cout<<0<<endl;
    }
}

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

using namespace std;

int N;
const int maxSize = 101;
string arr[maxSize];
int main()
{
cin >> N;
for(int i=0; i<N; i++)
cin >> arr[i];

bool satisfies = true;
for(int i=0; i<N-1; i++)
{
for(int j=i+1; j<N; j++)
{
if(arr[j]==arr[i])
satisfies = false;
}
}

for(int i=1; i<N; i++)
{
int ln = arr[i-1].length()-1;
if(arr[i][0]!=arr[i-1][ln])
satisfies = false;
}

if(satisfies)
cout << "Yes";
else
cout << "No";
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    cin >> a >> b;

    for(int i = 1; i < 1000000; i++){
        int price = i*0.08;
        int price2 = i*0.1;

        if((a==price) && (b==price2)){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
A=input()
B=input()
C=input()
t=[0,0,0]
flag="a"
while True:
  if flag=="a":
    if len(A)==t[0]:
      print("A")
      break
    else:
      flag=A[t[0]]
      t[0]+=1
  elif flag=="b":
    if len(B)==t[1]:
      print("B")
      break
    else:
      flag=B[t[1]]
      t[1]+=1
  elif flag=="c":
    if len(C)==t[2]:
      print("C")
      break
    else:
      flag=C[t[2]]
      t[2]+=1

Measured memory_bytes: 3064
#!/usr/bin/env python3
from itertools import permutations
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
q = list(map(lambda x: x-1, q))
p = list(map(lambda x: x-1, p))
a = [list(i) for i in permutations(range(n))]
print(abs(a.index(p)-a.index(q)))


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

bool cmp(const tuple<int, string, int>& x, const tuple<int, string, int>& y){
  if (get<1>(x) == get<1>(y)){
    return get<2>(x) > get<2>(y);
  } else{
    if (get<1>(x).compare(get<1>(y)) < 0){
      return true;
    } else{
      return false;
    }
  }
}

int main(){
  int N;
  cin >> N;
  vector<tuple<int, string, int>> vec;

  for (int i=0; i<N; i++){
    string s;
    int p;
    cin >> s >> p;
    vec.emplace_back(i+1, s, p);
  }

  sort(
    vec.begin(),
    vec.end(),
    cmp
  );

  for (int i=0; i<N; i++){
    cout << get<0>(vec[i]) << endl;
  }
  return 0;
}


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

typedef struct _COORD {
	double x;
	double y;
} COORD;

#define RAD(a)  ((a) * M_PI / 180.0)

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
double div3left(double a, double b)
{
	return (2*a+b)/3;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
double div3right(double a, double b)
{
	return (a+2*b)/3;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
COORD Triangle(COORD p1, COORD p2)
{
	COORD ret;
	double th = M_PI * 60.0 / 180.0; // ?????????????????¢?????????????????????

	double a = p2.x - p1.x;
	double b = p2.y - p1.y;
	double Cos60;
	double Sin60;

	Cos60 = cos( th );
	Sin60 = sin( th );
	ret.x = a * Cos60 - b * Sin60 + p1.x;
	ret.y = a * Sin60 + b * Cos60 + p1.y;
	return ret;
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
void kock(int n, COORD p1, COORD p2)
{
	COORD s, u, t;

	if (n == 0) {
		return;
	}

	// p1, p2 ?????? s, t, u ????¨????
	s.x = div3left(p1.x, p2.x);
	s.y = div3left(p1.y, p2.y);
	t.x = div3right(p1.x, p2.x);
	t.y = div3right(p1.y, p2.y);
	u = Triangle(s, t);

	kock(n-1, p1, s);
	printf("%.8f %.8f\n", s.x, s.y);
	kock(n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	kock(n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	kock(n-1, t, p2);
}

/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int n;
	COORD p1 = { 0., 0.};
	COORD p2 = { 100., 0.};
//
	scanf("%d", &n);

	printf("%.8f %.8f\n", p1.x, p1.y);
	kock(n, p1, p2);
	printf("%.8f %.8f\n", p2.x, p2.y);

	return 0;
}

Measured memory_bytes: 640
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N, M = NMI()
	querys = [NLI() for _ in range(M)]
	querys.sort(key=lambda x: x[1])
	ans = 0
	last = 0
	for a, b in querys:
		if a <= last < b:
			continue
		last = b-1
		ans += 1
	print(ans)


if __name__ == "__main__":
	main()

Measured memory_bytes: 29488
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>

using namespace std;

long fun(long x){
    long i = 1;
    while(i<x){
        i *= 2;
    }
    if(i==x){
        return 1;
    }
    else{
        return 0;
    }
}

int main(int argc, const char * argv[]) {
    // insert code here...
    long b;
    while(scanf("%ld",&b)==1){
        if(b==0){
            break;
        }
        else{
            if(fun(b)==1){
                printf("%ld %d\n",b,1);
            }
            else{
                long a = 0;
                long max = 0;
                for(long n=1;n<=sqrt((float)b)*2;n++){
                    if(b-(n*(n-1)/2)>0&&(b-n*(n-1)/2)%n==0 &&((b-n*(n-1)/2)/n)>0 ){
                    a = (b-n*(n-1)/2)/n;
                    max = n;
                    }
                   
                }
                printf("%ld %ld\n",a,max);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N,K;

int ans[100010];
vector<int> g[100010];
bool used[100010];
int dist[100010];

vector<int> rg[100010];

void dfs(int now,int len){
    used[now]=true;
    dist[now]=len;
    for(int i=0;i<g[now].size();i++){
        int next=g[now][i];
        if(used[next]) continue;

        dfs(next,len+1);
    }
    return;
}

int rdfs(int now,int len){
    used[now]=true;
    if(len==K-1) return now;
    for(int i=0;i<rg[now].size();i++){
        int next=rg[now][i];
        if(used[next]) continue;

        return rdfs(next,len+1);
    }
    return -1;
}

void visit(int now){
    used[now]=true;
    for(int i=0;i<g[now].size();i++){
        int next=g[now][i];
        if(used[next]) continue;

        if(dist[next]>dist[now]) visit(next);
    }
    return;
}

int main(){
  cin>>N>>K;
  int a[N+1]={};
  for(int i=0;i<N;i++){
      cin>>a[i];
      a[i]--;
      ans[i]=a[i];
      if(i>0){
          g[a[i]].push_back(i);
          rg[i].push_back(a[i]);
      }
  }
  ans[0]=0;

  dfs(0,0);

  priority_queue<pair<int,int>> PQ;
  for(int i=0;i<N;i++){
      used[i]=false;
      PQ.push(make_pair(dist[i],i));
  }
  while(!PQ.empty()){
      pair<int,int> tp=PQ.top();
      PQ.pop();
      int now=tp.second;
      if(used[now]) continue;

      int x=rdfs(now,0);
      if(x!=-1){
          ans[x]=0;
          visit(x);
      }
  }

  int res=0;
  for(int i=0;i<N;i++){
      if(ans[i]!=a[i]) res++;
  }
  cout<<res<<endl;


  return 0;
}


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

int main(void) {

    int cnt = 0;
    int K, S; cin >> K >> S;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (0 <= z && z <= K) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int main(){
  int x;
  cin>>x;
  if(x==2){ cout<<2<<endl; return 0;}
  if(x%2==0) x++;
  while(1){
    bool fl=true;
    for(int i=3;i<sqrt(x);i+=2){
      if(x%i==0) {fl=false; break;}
    }
    if(fl) {cout<<x<<endl; return 0;}
    x+=2;
  }
}
    

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

using ll = int64_t;

#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 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 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; cin >> n;
  bool ok = true;
  rep(i, n) {
    int a; std::cin >> a;
    if (a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0))
      ok = false;
  }
  std::cout << (ok ? "APPROVED" : "DENIED") << "\n";
}


Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();
    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    let xs = line.trim().split_whitespace();
    let mut result = Vec::new();

    for x in xs {
        let ans = x.parse::<T>().map_err(|_| format!("{}", "parse error"))?;
        result.push(ans);
    }
    Ok(result)
}

fn main() {
    // let (a, b) = read_parameters::<usize>().map(|xs| (xs[0], xs[1])).unwrap();
    let r = read_parameters::<f64>().unwrap();
    let r = r[0];

    println!(
        "{:.6} {:.6}",
        std::f64::consts::PI * r * r,
        2.0 * std::f64::consts::PI * r
    );
}



Measured memory_bytes: 5072
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20


struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
for (int i = 0;i < graph[pos].size();i++) {
	int to = graph[pos][i].to;
	int cost = graph[pos][i].cost;
	if (d[pos] + cost < d[to]) {
		d[to] = d[pos] + cost;
		q.push(Node(to, d[to]));
	}

}
	}
	cout << d[TO] << endl;
}
int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[], int n, int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >= 0) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n, int* v, int* ww) {
	int W[101][10001];
	for (int j = 0;j <= w;j++) {
		W[0][j] = 0;
	}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++) {
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n + 1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n + 1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x > 2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int gnc(int a, int b) {
	while (b%a != 0) {
		if (a > b) swap(a, b);
		else {
			b = b%a;
		}
	}
	return a;
}
int calc(int a, long long int b, long long int m) {
	if (b == 0) return 1;
	else if (b % 2 == 0) {
		long long int d = calc(a, b / 2, m);
		return (d*d) % m;
	}
	else {
		long long int d = calc(a, b -1, m);
		return (d*a) % m;
	}
}


int main() {
	long long int x;
	cin >> x;
	long long int num;
	long long int num2;
	int num1;
	num2 = x / 11;
	num1 = x % 11;
	if (num1 == 0) {
		num = 2 * num2;
	}
	else if (num1 > 0 && num1 <= 6) {
		num = 2*num2 + 1;
	}
	else num = 2*num2+ 2;
	cout << num << endl;
	return 0;
	}




Measured memory_bytes: 256
import std.stdio;

void main() {
    int n;
    readf(" %s", &n);

    if (n < 105) {
        writeln(0);
        return;
    }
    if (n == 105) {
        writeln(1);
        return;
    }

    auto ans = 1;
    for (auto i = 107; i <= n; i++ ) {
        if (i % 2 == 0)
            continue;
        auto cnt = 1;
        for (auto j = 3; j <= n; j++ )
            if (i % j == 0)
                cnt++;
        if (cnt == 8)
            ans++;
    }
    ans.writeln;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
typedef long long ll;
ll n;
ll ans=0;
int main(){
	cin>>n;
	if (n%2==1){
		cout<<"0"<<endl;
		return 0;
	}
	ll res=n/2;
	ll base=5;
	for (ll i=1;i,base<=res;i++){
		ans+=res/base;
		if (base>=2e17) break;
		base=base*5;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    ll s=0;
    for(int i=0;i<n;i++)
        cin>>a[i],s+=a[i];
       ll ps=0,mn=s;
    for(int i=0;i<n;i++)
    {
        ps+=a[i];
        mn=min(mn,abs(ps-(s-ps)));

    }
    cout<<mn<<endl;






}













































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

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<int> a(100000, 0);
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
        if (tmp > 0) {
            a[tmp - 1]++;
        }
        if (tmp < 100000 - 1) {
            a[tmp + 1]++;
        }
    }

    int mx = 0;
    for (int i = 0; i < 100000; i++) {
        mx = max(mx, a[i]);
    }

    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
      public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            if(a==b&&b==c&&c==a){
                         System.out.println(1);
            }else if(a==b||b==c||c==a){
                         System.out.println(2);
            }else if(a!=b&&b!=c&&c!=a){
                         System.out.println(3);
            }
      }
}

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

typedef long long ll;

int main(){
    ll S;
    cin >> S;
    ll M = sqrt(S);
    if (S == M*M){
        cout << 0 << " " << 0 << " " << M << " " << 0 << " " << 0 << " " << M << endl;
    }else{
        ll T = (M+1)*(M+1)-S;
        ll N = sqrt(T);
        ll a = 1;
        for(ll i = N;i>=0;i--){
            if (T%i == 0){
                a = i;
                break;
            }
        }
        cout << 0 << " " << 0 << " " << M+1 << " " << a << " " << T/a << " " << M+1 << endl;
    }
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i = 0; i < n; i++)
const int MAX = 3e5+3;
const int INF = 1e9;

int a[MAX];

int main(){

  int n,x; cin >> n >> x;
  REP(i,n) cin >> a[i];
  ll cnt = 0;
  REP(i,n-1){
    ll res = a[i] + a[i+1];
    if(res > x){
      cnt += res - x;
      a[i+1] -= res - x;
      if(a[i+1] < 0) a[i+1] = 0;
    }
    //cout << res << " ";
  }
  cout << cnt << endl;

  return 0;
}


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

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

int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    rep(i, N) {
        int a; cin >> a;
        A[i] = make_pair(a, i);
    }
    sort(A.rbegin(), A.rend());
    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(N + 1));
    auto f = [&](auto &&f, int l, int r) {
        if(dp[l][r]) return dp[l][r];
        auto[a, x] = A[l + r - 1];
        auto cost = [&](int y) { return (int64_t)a * abs(x - y); };
        if(l) chmax(dp[l][r], f(f, l - 1, r) + cost(l - 1));
        if(r) chmax(dp[l][r], f(f, l, r - 1) + cost(N - r));
        return dp[l][r];
    };
    int64_t ans = 0;
    rep(l, N + 1) chmax(ans, f(f, l, N - l));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 34864
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

int main() {
  int h, w; cin >> h >> w;
  char s[h][w];
  rep(i, h)
    rep(j, w) cin >> s[i][j];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i, h) {
    vector<int> done(w);
    rep(j, w) {
      if(s[i][j] == '#') continue;
      if(done[j]) continue;
      int l = 0;
      while(j+l < w) {
        if(s[i][j+l] == '#') break;
        l++;
      }
      rep(k, l) {
        cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }
  rep(j, w) {
    vector<int> done(h);
    rep(i, h) {
      if(s[i][j] == '#') continue;
      if(done[i]) continue;
      int l = 0;
      while(i+l < h) {
        if(s[i+l][j] == '#') break;
        l++;
      }
      rep(k, l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) ans = max(ans, cnt[i][j] -1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long int ll;

int main() {
    int N, T, A;
    double ans; 
    int ans_id = 1;
    int H;
    cin >> N >> T >> A;
    for (int i = 1; i <= N; ++i) {
        cin >> H;
        if (i == 1) ans = abs(A - (T - H * 0.006));
        if (ans > abs(A - (T - H * 0.006))) {
            ans_id = i;
            ans = abs(A - (T - H * 0.006));
        }
    }
    cout << ans_id << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
x0 = sum([e * ((-1) ** i) for i, e in enumerate(a)]) // 2
x = [x0]
for i in range(1, n):
	x.append(a[i - 1] - x[-1])
xx = [str(2 * e) for e in x]
print(' '.join(xx))

Measured memory_bytes: 21316
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
n=0
for i in range(N):
    A=[]
    A=list(map(int,input().split()))
    R=0
    for j in range(M):
        R += B[j]*A[j]
    if R+C>0:
        n += 1
print(n)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		char C = sc.next().charAt(0);
		boolean ans = false;
		char A = a.charAt(a.length()-1);
		char B1 = b.charAt(0);
		char B2 = b.charAt(b.length()-1);

		if(A == B1 && B2 == C) {
			ans = true;
		}
		System.out.println(ans ? "YES" : "NO");
	}
}


Measured memory_bytes: 35504
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

string s;

matrix dp;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>s;
    dp.resize(13,Vi(s.size()+1));
    dp[0][0] = 1;
    rep(i,s.size()){
        rep(j,13){
            ll tmp = dp[j][i];
            ll tp = j*10;
            if(s[i]=='?'){
                rep(k,10){
                    tp = j*10+k;
                    tp %= 13;
                    dp[tp][i+1] += tmp;
                    dp[tp][i+1] %= Mod;
                }
            }else{
                tp += s[i]-'0';
                tp %= 13;
                dp[tp][i+1] += tmp;
                dp[tp][i+1] %= Mod;
            }
        }
    }
    ll ans = 0;
    ans = dp[5][s.size()];
    ans %= Mod;
    print(ans);
    return 0;
}

Measured memory_bytes: 11472
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> map = new HashMap<>();
		for(; n > 0; n--) {
			map.put(sc.next(), 1);
		}
		System.out.println(map.size());
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 72192
#include <stdio.h>

int main(void)
{
	int a[31];
	int i, j;
	int n;
	int ans[2];

	for (i = 1; i < 31; i++){
		a[i] = 0;
	}

	for (i = 0; i < 28; i++){
		scanf("%d", &n);
		a[n] = 1;
	}

	j = 0;

	for (i = 1; i < 31; i++){
		if (a[i] == 0){
			ans[j] = i;
			j++;
		}
	}

	printf("%d\n", ans[0]);
	printf("%d\n", ans[1]);

	return (0);
}

Measured memory_bytes: 596
a,b,c = gets.split(" ")
r = [["No", "No"],["No", "Yes"]]

ab = (a.to_i - b.to_i + 1).to_s[0].to_i
bc = (b.to_i - c.to_i + 1).to_s[0].to_i
puts r[(ab + 1) ** (-(ab + 1))][(bc + 1) ** (- ( ab + 1))]

Measured memory_bytes: 6116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int a, b, c; ll k;

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>a>>b>>c>>k;
    if(k%2==0) cout<<a-b;
    else cout<<b-a;
    return 0;
}

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

int main(){
    ll a,b;
    cin >> a >> b;
    ll temp=0;

    if(a!=0){
        if(a%2==0){
            if((a/2)%2==0) temp=0;
            else temp=1;
        }
        else{
            if(((a-1)/2)%2==0) temp=0;
            else temp=1;
            temp=temp^(a-1);
        }
    }

    ll temp2=0;
    if(b!=0){
        if(b%2==0){
            if((b/2)%2==0) temp2=0;
            else temp2=1;
            temp2=temp2^b;
        }
        else{
            if(((b+1)/2)%2==0) temp2=0;
            else temp2=1;
        }
    }
    ll ans=temp^temp2;
    cout << ans << endl;
}

Measured memory_bytes: 256