akhauriyash/Code-Regression huggingface dataset:
S = int(input())
MOD = 10 ** 9 + 7
MAX = 10 ** 4
modinv = lambda a, mod=MOD: pow(a, -1, mod)
fac, inv = [1] * MAX, [1] * MAX
for i in range(1, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = modinv(fac[i])


def comb(n, k, error=0):
    if not 0 <= k <= n:
        return error
    return fac[n] * inv[k] * inv[n - k] % MOD


ans = 0
for i in range(1, S // 3 + 1):
    ans = (ans + comb(S - 3 * i + (i - 1), i - 1)) % MOD
print(ans)


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

n=int(input().rstrip())
c=input().rstrip()
w,r=0,0
for i in c:
    if i=="R":r+=1
    else:w+=1
ans=0
for i in range(r):
    if c[i]=="W":ans+=1
print(ans)

Measured memory_bytes: 9484
from Queue import Queue
d = [0, 1, 0, -1]
h, w = map(int, raw_input().split())
m = list()
m.append(["#" for _ in xrange(w+2)])
for _ in xrange(h):
    m.append(["#"]+list(raw_input())+["#"])
m.append(["#" for _ in xrange(w+2)])
dat = len(filter(lambda x:x==".", [i for j in m for i in j]))

q = Queue()
q.put((1,1,1))

while not q.empty():
    xy = q.get()
    if not m[xy[0]][xy[1]] == ".":
        continue
    m[xy[0]][xy[1]] = xy[2]
    for i in xrange(4):
        e = (xy[0]+d[i], xy[1]+d[i+1&3], xy[2]+1)
        if m[xy[0]+d[i]][xy[1]+d[i+1&3]] == ".":
            q.put(e)

try:
    print dat-m[h][w]
except:
    print -1


Measured memory_bytes: 3052
#include<iostream>
#include<map>
#include<utility>
#include<vector>
#include<set>
using namespace std;

#define lli long long int
int n,m,k,x,y;


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

    map<int,int>r,c;
    map<int,set<int>>v;
    for(int i=0;i<k;i++){
        cin>>x>>y;
        v[x].insert(y);
        if(r.count(x))r[x]++;
        else r[x]=1;

        if(c.count(y))c[y]++;
        else c[y]=1;
    }

    int mr,mc,mrc=0,mcc=0;

    set<int>tr,tc;
    for(auto x:r){
        if(x.second>mrc){
            mrc=x.second;
        }
    }

    for(auto x:r){
        if(mrc==x.second) tr.insert(x.first);
    }

    for(auto x:c){
        if(x.second>mcc){
            mcc=x.second;
        }
    }

    for(auto x:c){
        if(mcc==x.second) tc.insert(x.first);
    }

    int s=mrc+mcc, f=0;
    for(auto x:v){
        if(tr.find(x.first)!=tr.end()){
            set<int>rem;
            for(auto y:x.second){
                if(tc.find(y)!=tc.end()){
                    rem.insert(y);
                }
            }
            if(rem.size()!=tc.size()){
                f=1;
                break;
            }
        }
    }    

    if(f==1) cout<<s<<"\n";
    else cout<<s-1<<"\n";

    return 0;
}

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

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  ll sum = 1e10;
  rep(i,n-k+1){
    sum = min(sum,abs(v.at(i) - v.at(i+k-1)));
  }
  cout << sum << endl;
}

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

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> a(N);
    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        cin >> a[i];
        if (i % 2 == 0 && a[i] % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){

    int n; cin>>n;

    vector<int> sta(n);

    for(int i=0; i<n; i++) cin>>sta[i];

    bool judge = true;

    for(int i=1; i<n; i++){

        //if(sta[i-1] == sta[i])sta[i-1]--;

        if(sta[i] > sta[i-1]) sta[i]--;

        if(sta[i-1] > sta[i]) judge = false; 
    }

    if(judge)cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int p[100'000];
int pInv[100'000];
int parent[100'000];
int depth[100'000];

int findRoot(const int idx)
{
    int curr = idx;
    while (parent[curr] != curr)
    {
        curr = parent[curr];
    }
    return curr;
}

void unionSet(const int rt0, const int rt1)
{
    if (depth[rt0] > depth[rt1])
    {
        parent[rt1] = rt0;
    }
    else if (depth[rt0] < depth[rt1])
    {
        parent[rt0] = rt1;
    }
    else
    {
        parent[rt0] = rt1;
        depth[rt1]++;
    }
}

int main()
{
    int N, M;

    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int v;
        cin >> v;
        v--;

        p[i] = v;
        pInv[v] = i;
        parent[i] = i;
        depth[i] = 0;
    }

    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        unionSet(findRoot(x), findRoot(y));
    }

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (findRoot(i) == findRoot(pInv[i]))
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;

  cout << S.substr(0,3) << endl;
  
  return 0;
}


Measured memory_bytes: 3624
if __name__ == '__main__':
    N = int(input())
    H = list(map(int, input().split()))
    #print(N, H)
    x1 = H.pop()
    for i in range(N-1):
        x2 = H.pop()
        if x1 - x2 <= -2:
            print('No')
            break
        elif x1 > x2:
            x1 = x2
    else:
        print('Yes')

Measured memory_bytes: 14252
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

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

    vector<string> v;

    for(int i = 0; i < n; i++){
      string tmp_;
      cin >> tmp_;
      sort(tmp_.begin(), tmp_.end());
      v.push_back(tmp_);
    }
    sort(v.begin(), v.end());

    unsigned long long count = 1;
    unsigned long long ans = 0;

    for(int j = 1; j < v.size(); j++){
      if(v[j] == v[j-1]){
        count++;
      }else{
        ans += (count*(count-1))/2;
        count = 1;
      }
    }
    ans += (count*(count-1))/2;

    cout << ans << endl;


    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int m; cin >> m;
	vector<int> b(m);
	for (int i = 0; i < m; i++) cin >> b[i];
	int j = 0;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		if (b[j] == a[i]) j++;
	}
	if (j == m) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}


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

int main() {
	long ans=0;
	
	long n;
	cin >> n;
	long S[n];
	for(long i=0; i<n; i++){
		cin >> S[i];
	}
	
	long q;
	cin >> q;
	long T;
	for(long i=0; i<q; i++){
		cin >> T;
		if(binary_search(S,S+n,T)){ans++;}
	}
	
	cout<<ans<<endl;
	return 0;
}

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

int main(){
int N,M;
  cin>>N>>M;
  char A[N][N], B[M][M];
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
   cin>>A[i][j];}}
  for(int i=0; i<M; i++){
    for(int j=0; j<M; j++){
   cin>>B[i][j];}}
  
  bool ans=false;
  for(int ly=0; ly<N; ly++){
   for(int lx=0; lx<N; lx++){
       if(ly+M-1>=N || lx+M-1>=N){continue;}
         // ↑ B[i][j]の可動範囲はly,lx<N-M+1のため、ly,lxがそれを超えた場合continueして、
       bool match=true;               // 以下の処理を飛ばす。
       for(int i=0; i<M; i++){
        for(int j=0; j<M; j++){
          if(A[ly+i][lx+j]!=B[i][j]){match=false;}
        } // ↑ ly,lxを導入する事でB[i][j]が相対的に平行移動している形にできる
       }
       if(match){ans=true;} // Aの中にB[i][j]を全て含むものが見つかった場合はans=true
   }
  }  // ループ全体はここまで
  
  if(ans){cout<<"Yes";}
  else{cout<<"No";}
  
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = getLong(sc);
		int n = getInt(sc);
		int[] a = getIntArray(sc);

		for (int i = 0; i < n; i++) {
			h -= a[i];
		}
		if (h <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	private static boolean isEqual(Integer[] perm, int[] target) {
		for (int i = 0; i < perm.length; i++) {

			if (perm[i].intValue() != target[i]) {

				return false;
			}
		}
		return true;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 48804
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;
const LL mod = 1e9 + 7;

int main()
{
	int n,m;
	int x[105],y[105],d,ans,p;
	while(~scanf("%d%d",&n,&m)){
		for(int i = 1;i <= n;i++) scanf("%d %d",&x[i],&y[i]);
		for(int i = 1;i <= m;i++) scanf("%d %d",&x[i + n],&y[i + n]);
		for(int i = 1;i <= n;i++){
			d = Inf;
			for(int j = 1;j <= m;j++){
				p = abs(x[i] - x[j + n]) + abs(y[i] - y[j + n]);
				if(d > p){
					d = p;
					ans = j;
				}
			}
			printf("%d\n",ans);
		}
	}
    return 0;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();

		int cnt = 0;
		for (char c : s) {
			if (c == '1') {
				cnt++;
			}
		}

		pr.println(cnt);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
using namespace std;
int main(){
    int N,AC,WA,TLE,RE,i;
    cin >> N;
    string S;
    AC = 0;
    WA = 0;
    TLE = 0;
    RE = 0;
    for(i = 0;i < N;i++){
        cin >> S;
        if(S == "AC"){
            AC++;
        }
        else if (S == "WA"){
            WA++;
        }
        else if (S == "TLE"){
            TLE++;
        }
        else if (S == "RE"){
            RE++;
        }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

Measured memory_bytes: 3584
import copy

class StableSort():
    def __init__(self):
        self.N = n
        self.C = copy.copy(c) #こうしないと書き換わってしまう


    def BS(self):
        A = [self.C[i][1] for i in range(self.N)] #数値
        if self.N == 1:
            C = " ".join(self.C)
            return C
        else:
            for i in range(self.N): #比較は常にリストの一番後ろからはじまる
                for j in range(self.N - i - 1):
                    if A[self.N - j - 1] < A[self.N - j - 2]: #常に安定である 
                        A[self.N - j - 1], A[self.N - j - 2] = A[self.N - j - 2], A[self.N - j - 1] 
                        self.C[self.N - j - 1], self.C[self.N - j - 2] = self.C[self.N - j - 2], self.C[self.N - j - 1] 

            C = " ".join(self.C)
            return C


    def SS(self):
        A = [self.C[i][1] for i in range(self.N)] #数値
        if self.N == 1:
            print(self.C[0] + "\n" + "stable")
        else:
            for i in range(self.N - 1):
                A_r = A[i:] #確定してないAの右側の領域
                mini = min(A_r)
                #AとA_rのインデックスは違うので，抜いた左側の分の+iの補正が必要
                mini_index = i + A_r.index(mini) 
                if A[i] > mini:
                    A[i], A[mini_index] = A[mini_index], A[i] 
                    self.C[i], self.C[mini_index] = self.C[mini_index], self.C[i] 

            C = " ".join(self.C) 
            return C

n = int(input())
c = list(input().split()) #トランプ

BS = StableSort().BS()
SS = StableSort().SS()

print(str(BS) + "\n" + "Stable")
if BS != SS:
    print(str(SS) + "\n" + "Not stable")
else:
    print(str(SS) + "\n" + "Stable")



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


int main(){
    int n, m;
    cin >> n >> m;
    map<int, int> r;
    while(m--){
        int x, y;
        cin >> x >> y;
        r[x]++;
        r[y]++;
    }
    for(int i = 1; i <= n; i++)
        cout << r[i] << endl;
}


Measured memory_bytes: 256
n, y = gets.chomp.split.map(&:to_i)

0.upto(n) do |i|
  0.upto(n-i) do |t|
    if i * 10000 + t * 5000 + (n-i-t) * 1000 == y
      puts "#{i} #{t} #{n-i-t}"
      exit
    end
  end
end
puts '-1 -1 -1'


Measured memory_bytes: 1788
from collections import Counter

N, P = map(int, input().split())
S = input()

if P in (2, 5):
    ans = sum(i for i, s in enumerate(S, 1) if not int(s) % P)
else:
    Acc = [0] * (N + 1)
    p10 = 1
    for i, s in enumerate(reversed(S)):
        Acc[N - i - 1] = (Acc[N - i] + p10 * int(s)) % P
        p10 = (p10 * 10) % P
    ans = sum(v * (v - 1) // 2 for v in Counter(Acc).values())
print(ans)


Measured memory_bytes: 17640
#include <bits/stdc++.h>
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define fore(i, a) for(auto &i:a)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
#define MOD 1000000007
#define yes "YES"
#define no "NO"
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;

int main() {
    fastcin;
    vll a;
    ll n, in, ans;
    cin >> n;
    rep(i, 0, n) {
        cin >> in;
        a.push_back(in);
    }
    VSORT(a);
    ans = abs(a.back() - a[0]);
    print(ans);
    return 0;
}

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

int main() {
  int s;
  cin >> s;
  long long m = 1000001;
  vector<int> a(m);
  a[0] = s;
  for (int i=1; i<m; i++){
    if (a[i-1]%2==0) {
      a[i] = a[i-1] /2;
    }
    if (a[i-1]%2==1) {
      a[i] = 3*a[i-1] + 1;
    }
    for (int j=0; j<i; j++) {
      if (a[i] == a[j]){
        cout << i+1 << endl;
        return 0;
      }
    }

  }
}

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

int main() {
    int X, Y, s, count=0;
    cin >> X >> Y;
    vector<int> A(5);
    for (int i=X; i<=Y; i++){
            s = i;
    		for (int k=0; k<5; k++){
              		A[k] = s%10;
                    s = (s-s%10)/10;
            }
            if ((A[0]==A[4])&&(A[1]==A[3])) count++;
    }
    cout << count << endl;
              		
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000000000000LL
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 2000005
template<class T,class V> ostream& operator<<(ostream &s,pair<T,V> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
ii dp[3005][3005];
int a,b,c,d,e,f;
ii solve(int t,int s){
    if(100*s>t*e||t+s>f)return ii(0,0);
//    cout<<t<<' '<<s<<endl;
    if(dp[t][s].fi!=-1)return dp[t][s];
    ii ans=ii(t,s);
    ii tm=solve(t+a,s);
    if(ans.fi==0)ans=tm;
    if(ans.se*tm.fi<ans.fi*tm.se)ans=tm;
    tm=solve(t+b,s);
    if(ans.fi==0)ans=tm;
    if(ans.se*tm.fi<ans.fi*tm.se)ans=tm;
    tm=solve(t,s+c);
    if(ans.fi==0)ans=tm;
    if(ans.se*tm.fi<ans.fi*tm.se)ans=tm;
    tm=solve(t,s+d);
    if(ans.fi==0)ans=tm;
    if(ans.se*tm.fi<ans.fi*tm.se)ans=tm;
    return dp[t][s]=ans;
}
int main()
{
    fastread;
    int T=1;
//    cin>>T;
    for(int qq=1; qq<=T; qq++)
    {
        for(int i=0;i<3005;i++)for(int j=0;j<3005;j++)dp[i][j]=ii(-1,-1);
        cin>>a>>b>>c>>d>>e>>f;
        a*=100;
        b*=100;
        ii x=solve(0,0);
        cout<<x.fi+x.se<<' '<<x.se<<endl;
    }
}


Measured memory_bytes: 144812
def main():
    N = int(input())
    music = []
    m_time = []
    for _ in range(N):
        a, b = input().split()
        music.append(a)
        m_time.append(int(b))
    X = input()
    ans = 0
    for i, a in enumerate(music):
        if a == X:
            for j in range(i+1, N):
                ans += m_time[j]
    print(ans)
main()


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    ll N = S.size();

    ll MOD = 2019;

    // (i, j)が条件を満たすのは a_{j} + 10 * a_{j-1} + .... + 10^{j-i}*a_{i} が2019の倍数の時
    //　左からk+1文字目以降の整数を値とみなしたときの数字をTkとすると，(i, j)が条件を満たすのは 10^{n-j}(T_{i-1} - T_{j})が2019の倍数のとき
    // 10はmod2019で逆元が存在するので，T_{i-1} == T_{j} (mod2019)なら良い

    vector<vector<ll>> modind(MOD);
    modind.at(0).push_back(0);
    ll num = 0;

    vector<ll> x(N);
    x.at(0) = 1;
    rep(i, N-1){x.at(i+1) = x.at(i) * 10 % MOD;}

    rep(i, N){
        num += (S[N-1-i] - '0') * x.at(i) % MOD;
        modind.at(num % 2019).push_back(i + 1);
    }
    ll ans = 0;
    rep(i, MOD){
        ll size = modind.at(i).size();
        if (size >= 2){ans += size * (size - 1) / 2;}
    }
    cout << ans << endl;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7772
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b;

	cin>>a>>b;

	if(a+b<10){
		cout<<a+b<<endl;
	}else{
		cout<<"error"<<endl;
	}

}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int s;
	int c;
}med;

int min(int a, int b){
	if(a > b){
		return b;
	}
	else{
		return a;
	}
}

int minarray(med array[], int num, int M){
	int i, a;
	if(num == 0){
		return M;
	}
	else{
		a = array[0].c;
		for(i = 1; i < num; i++){
			a = min(a, array[i].c);
		}
		return a;
	}
}

int main(){
	int N, Ma, Mb, a, b, c, s, i, j, k = 0, l = 0, m = 0;
	scanf("%d%d%d", &N, &Ma, &Mb);
	med medp[N], medm[N], medz[N];
	for(i = 0; i < N; i++){
		scanf("%d%d%d", &a, &b, &c);
		s = a*Mb - b*Ma;
		if(s > 0){
			medp[k].s = s;
			medp[k].c = c;
			k++;
		}
		else if(s < 0){
			medm[l].s = s;
			medm[l].c = c;
			l++;
		}
		else{
			medz[m].s = s;
			medz[m].c = c;
			m++;
		}
	}
	int M = 100*N, sum = 0;
	int minc[M];
	minc[0] = 0;
	for(i = 1; i < M; i++){
		minc[i] = M;
	}
	for(i = 0; i < k; i++){
		sum += medp[i].s;
		for(j = sum; j >= medp[i].s; j--){
			minc[j] = min(minc[j], minc[j - medp[i].s] + medp[i].c);
		}
	}
	minc[0] = minarray(medz, m, M);
	for(i = 0; i < l; i++){
		for(j = 0; j <= sum; j++){
			minc[j] = min(minc[j], minc[j - medm[i].s] + medm[i].c);
		}
	}
	if(minc[0] >= M){
		printf("-1\n");
	}
	else{
		printf("%d\n", minc[0]);
	}
	return 0;
}

Measured memory_bytes: 128
N=int(input())
a=list(map(int,input().split()))
for i in range(N):
    if a[i]%4==0:
        a[i]=2
    elif a[i]%2==0:
        a[i]=1
    else:
        a[i]=0
zero=a.count(0)
one=a.count(1)
two=a.count(2)

if zero>two+1:
    print("No")
elif zero==two+1:
    if zero+two==N:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")


Measured memory_bytes: 20112
k, n = map(int, input().split())
A = sorted([int(i) for i in input().split()])[::-1]
# print(A)
B = []
for i in range(n-1):
    B.append(A[i] - A[i+1])
B.append(A[n-1]+k-A[0])
print(k-max(B))


Measured memory_bytes: 26444
// 2020-08-11 09:57:03
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
const int mod = 1000000007;
struct mint {
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % mod) {
    if (val < 0) val += mod;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = mod, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += mod;
    u %= mod;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= mod) val -= mod;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += mod;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % mod;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % mod;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};

void answer() {
  string s;
  cin >> s;
  int sz = s.size();
  mint dp[4];
  dp[3] = 1;
  auto matched = [&](int i, int j) {
    if(s[i] == '?') return true;
    else return (s[i] - 'A' == j);
  };
  REPCM(i, sz-1, 0) {
    mint p[4];
    swap(dp, p);
    dp[3] = p[3];
    if(s[i] == '?') dp[3] *= 3;
    rep(j, 3) {
      dp[j] = p[j];
      if(s[i] == '?') dp[j] *= 3;
      if(matched(i, j)) dp[j] += p[j+1];
    }
  }
  cout << dp[0] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3744
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    a,b,c,d,e = inpm()
    print((c-a)*60+(d-b)-e)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10780
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

int calc(int k, int[] ws) {
    bool match(int limit) {
        int n = 0;
        int sum = 0;
        foreach (w; ws) {
            if (sum + w <= limit) {
                sum += w;
            }
            else {
                sum = w;
                n++;
                if (n > k)
                    return false;
            }
        }
        return n + 1 <= k;
    }

    int lo = ws.reduce!max;
    int hi = 10 ^^ 9;
    int ans = hi;
    while (lo <= hi) {
        int m = (lo + hi) / 2;
        if (match(m)) {
            ans = min(ans, m);
            hi = m - 1;
        }
        else {
            lo = m + 1;
        }
    }
    return ans;
}

void main() {
    auto nk = readints();
    int n = nk[0], k = nk[1];

    int[] ws;
    for (int i = 0; i < n; i++) {
        ws ~= readint();
    }
    writeln(calc(k, ws));
}

Measured memory_bytes: 3708
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;


int main(){
    IOS;
    int n;
    int in,dis;
    cin>>n>>dis;
    if(n>=10){
        cout<<dis;
    }
    else
    {
        cout<<100*(10-n)+dis;
    }
    
}

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

int main(){
	string s;
	vector<vector<int> > cd(2, vector<int>(1001, 0));
	int step = 0;
	while(getline(cin, s)){
		if(s == ""){
			step++;
			continue;
		}
		replace(s.begin(), s.end(), ',', ' ');
		stringstream buf(s);
		int c, d;
		buf >> c >> d;
		cd[step][c]++;
	}
	for(int i=0; i<=1000; i++){
		if(cd[0][i]!=0 && cd[1][i]!=0){
			cout << i << " " << cd[0][i]+cd[1][i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3220
// Date: 2020-03-10

#include <algorithm>
#include <bits/stdc++.h>
#include <ios>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

struct node {
    LL a, b;
    bool operator < (const node& r) const {
        return a*(r.b+1) > (b+1)*r.a;
    }
} c[N];
int n, T, nx, ny;
LL d[N], pre[N];
LL dp[N][32];

int main() {
    cin >> n >> T;
    rep(i, 1, n) {
        LL u, v;
        cin >> u >> v;
        if(u) c[++nx] = {u, v};
        else d[++ny] = v+1;
    }
    sort(c+1, c+nx+1);
    sort(d+1, d+ny+1);
    rep(i, 1, ny) d[i] = d[i-1] + d[i];
    mem(dp, -1);
    dp[0][0] = 0;
    int mx = min(31, nx);
    rep(i, 1, nx) rep(j, 0, min(mx, i)) {
        if(j && dp[i-1][j-1] != -1 && dp[i-1][j-1] <= T) {
            if(dp[i][j] == -1) dp[i][j] = dp[i-1][j-1] + 1 + c[i].a*(dp[i-1][j-1]+1) + c[i].b;
            else chkmin(dp[i][j], dp[i-1][j-1] + 1 + c[i].a*(dp[i-1][j-1]+1) + c[i].b);
        }
        if(dp[i-1][j] != -1 && dp[i-1][j] <= T) {
            if(dp[i][j] == -1) dp[i][j] = dp[i-1][j];
            else chkmin(dp[i][j], dp[i-1][j]); 
        }
    }
    int ans = 0;
    rep(j, 0, 31) {
        if(dp[nx][j] != -1 && dp[nx][j] <= T) {
            LL rem = T-dp[nx][j];
            int p = upper_bound(d+1, d+ny+1, rem)-d-1;
            chkmax(ans, j + p);
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 56448
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) begin(V), end(V)
#define ALLR(V) rbegin(V), rend(V)
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

#ifdef DEBUGGING
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

using namespace std;

using namespace std;
const ll inf = 5e15;
const ll mod = 1e9 + 7;

template <ll MOD>
class Combination {
    ll N;
    V<ll> factv, ifactv;

public:
    Combination<MOD>(ll N) : N(N), factv(N + 1, 1), ifactv(N + 1) {
        for (ll i = 1; i <= N; i++) factv[i] = factv[i - 1] * i % MOD;
        ifactv.back() = inv(factv.back());
        for (ll i = N - 1; 0 <= i; i--) ifactv[i] = (i + 1) * ifactv[i + 1] % MOD;
    }

    ll fact(ll n) { return factv[n]; }

    ll ifact(ll n) { return ifactv[n]; }

    ll pow(ll a, ll b) { return b ? (b & 1 ? a : 1) * pow(a * a % MOD, b / 2) % MOD : 1; }

    ll inv(ll a) { return pow(a, MOD - 2); }

    ll comb(ll n, ll k) { return factv[n] * ifactv[n - k] % MOD * ifactv[k] % MOD; }
};

Combination<mod> C(1e6);

ll solve() {
    ll N, K;
    cin >> N >> K;
    ll ans = C.comb(2 * N - 1, N);
    for (ll zero = K + 1; zero < N; zero++) {
        ll p = C.comb(N, zero);
        ll rest = N - zero;
        ll bar = rest - 1;
        ll rest_p = N - (bar + 1);
        ans += mod - p * C.comb(bar + rest_p, rest_p) % mod;
    }
    return ans % mod;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 15872
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  string s;
  cin >> s;
    
  if(s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int idx = 0;
  bool f = false;
  FOR(i, 2, s.size()-1){
    if(s[i] == 'C') {
      f=true;
      idx = i;
      break;
    }
  }

  if(!f) {
    cout << "WA" << endl;
    return 0;
  }

  FOR(i, 1, s.size()){
    if(i != idx && s[i] >= 65 && s[i] <= 90) {
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int a;
    vector<int> list(3);
    cin >> list.at(0) >> list.at(1) >> list.at(2) >> a;
    sort(list.begin(), list.end());
    list.at(2) *= (int)(pow(2.0, a));
    cout << list.at(0) + list.at(1) + list.at(2);
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
template <typename Monoid >
struct SegmentTree{
  using F = function< Monoid(Monoid,Monoid) >;

  int sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M;

  SegmentTree(int n,const F f,const Monoid &M) : f(f),M(M){
    sz = 1;
    while(sz<n) sz<<=1;
    seg.assign(sz*2,M);
  }
  void set(int k,const Monoid &v){
    seg[k+sz] = v;
  }
  void build(){
    for(int k=sz-1;k>0;k--){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  void update(int k,const Monoid &v){
    k += sz;
    seg[k] = v;
    while(k >>= 1){
      seg[k] = f(seg[2*k],seg[2*k+1]);
    }
  }
  Monoid que(int a,int b){
    Monoid L=M,R=M;
    for(a+=sz, b+=sz;a<b;a>>=1,b>>=1){
      if(a&1) L = f(L,seg[a++]);
      if(b&1) R = f(seg[--b],R);
    }
    return f(L,R);
  }
  Monoid operator[](const int &k) const{
    return seg[k+sz];
  }
};
signed main(){
  init_io();
  ll n,k,ans=0;
  cin >> n >> k;
  vector<ll> a(n),sum(n+1,0);
  SegmentTree<ll> seg(n+2,[](ll a,ll b){return a+b;},0);
  priority_queue<P> que;
  multiset<P> st;
  map<ll,ll> mp;
  const ll MAX = 1e18;
  st.insert(P(MAX,n+1));
  for(int i=0;i<n;i++){
    cin >> a[i];
    sum[i+1] = sum[i] + (a[i]-k);
    que.push(P(sum[i+1],i+1));
  }
  que.push(P(0,0));
  for(int i=0;i<=n;i++){
    auto tmp = que.top(); que.pop();
    mp[tmp.second] = i;
    if(tmp.second==0){
      seg.update(i,1);
      st.insert(P(0,i));
    }
  }
  for(int i=0;i<n;i++){
    auto itr =st.lower_bound(P(-sum[i+1],-MAX));
    ll idx = itr->second;
    ans += seg.que(idx,n+1);
    /*
    cout << idx <<" "<<itr->first <<" "<<itr->second<<endl;
    for(int i=0;i<n+2;i++){
      cout << seg[i]<<" ";
    }
    cout << endl;
    */
    st.insert(P(-sum[i+1],mp[i+1]));
    seg.update(mp[i+1],1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 38608
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

struct FactorialIndex {
    v: Vec<Vec<usize>>,
}

impl FactorialIndex {
    fn factorial_index(&mut self, parent: Vec<usize>, source: Vec<usize>) {
        if source.len() == 1 {
            let mut child = parent.clone();
            child.push(source[0]);
            self.v.push(child);
            return;
        }

        for &i in source.iter() {
            let mut child = parent.clone();
            child.push(i);
            let v: Vec<usize> = source.iter().filter(|&j| *j != i).cloned().collect();
            self.factorial_index(child, v);
        }
    }

    fn new(n: usize) -> FactorialIndex {
        let mut f = FactorialIndex { v: Vec::new() };
        f.factorial_index(Vec::new(), (0..n).collect::<Vec<_>>());
        f
    }
}

fn length(p0: (i64, i64), p1: (i64, i64)) -> f64 {
    let sum = (p1.0 - p0.0) * (p1.0 - p0.0) + (p1.1 - p0.1) * (p1.1 - p0.1);
    let f = sum as f64;
    f.sqrt()
}

fn distance(v: Vec<(i64, i64)>) -> f64 {
    v.windows(2).map(|w| length(w[0], w[1])).sum()
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.to();
    let v: Vec<(i64, i64)> = (0..n).map(|_| (iter.to(), iter.to())).collect::<Vec<_>>();
    let f = FactorialIndex::new(n);
    let num = f.v.len();
    let sum: f64 = f.v
        .into_iter()
        .map(|vv| {
            distance(vv.into_iter().map(|i| v[i]).collect::<Vec<_>>())
        })
        .sum();
    println!("{}", sum / (num as f64));
}

Measured memory_bytes: 10492
program main
	implicit none
    integer::a,b,c
    read(*,*)a,b
    if(mod(a,3)==0 .or. mod(b,3)==0 .or. mod(a+b,3)==0)then
    	write(*,*) 'Possible'
    else
    	write(*,*) 'Impossible'
    end if
    stop
end program main


Measured memory_bytes: 2856
#include <bits/stdc++.h>
using namespace std;
long long int s[100009] = {0};
long long int f[100009] = {0};
string z;
long long int n, m, i, x;
int main()
{
    //freopen("test.inp","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    long long int dem1 = 0, dem2 = 0;
    for (i = 1; i <= m; i++)
    {
        cin >> x >> z;
        if (z == "WA")
        {
            if (s[x] == 0) f[x]++;
        }
        else s[x] = 1;
    }
    for (i = 1; i <= n; i++)
    {
        dem1 += s[i];
        if (s[i]==1) dem2 += f[i];
    }
    cout << dem1 << " " << dem2;
}


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

int main(){

    string s;
    cin >> s;
    vector<string> data = {"maerd", "remaerd", "esare", "resare"};

    reverse(s.begin(), s.end());
    
    string curr = "";
    for(int i = 0; i < (int)s.size(); i++){
      
          curr.push_back(s.at(i));

          for(int j = 0; j < 4; j++){
              if( curr == data.at(j) ){
                  curr = "";
                  break;
              } 
          }

          if( curr.size() > 7 ){
              cout << "NO" << endl;
              return 0;
          }

    }

    if( curr == "" )
      cout << "YES" << endl;
    else
      cout << "NO" << endl;

}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

int compare(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int main(void){
  int *buf, *val;
  int n, k, j=-1, count=0, tmp=0, ans=0, *read;

  scanf("%d %d", &n, &k);
  buf = malloc(sizeof(int)*n);
  val = malloc(sizeof(int)*n);
  for(int i=0;i<n;i++){
    scanf("%d", buf+i);
    val[i] = 0;
  }
  qsort(buf, n, sizeof(int), compare);
  for(int i=0;i<n;i++){
    if(buf[i] != tmp){
      tmp = buf[i];
      count++;
      j++;
    }
    val[j] += 1;
  }
  qsort(val, n, sizeof(int), compare);
  read = val;
  while(*read == 0) read++;
  for(int i=0;i<(count-k);i++){
    ans += *read;
    read++;
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
const int INF = 1000010;
int main(){
    int a,b; cin >> a >> b;
    for(int x=1;x<=max(100*a/8,10*b)+1;++x){
        if(floor(x*0.1)==b && floor(x*0.08)==a){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  int64 m;
  scanf("%d%lld", &n, &m);
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &p[i]);
    --p[i];
  }
  vector<bool> visit(n);
  vector<int> Q;
  int t;
  for (t = 0; ; t = p[t]) {
    if (visit[t]) break;
    visit[t] = true;
    Q.push_back(t);
  }
  int i;
  for (i = 0; i < Q.size() && Q[i] != t; ++i);
  if (m < i) {
    printf("%d\n", Q[m] + 1);
  } else {
    m -= i;
    m %= Q.size() - i;
    printf("%d\n", Q[i + m] + 1);
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  long long int A[N];
  for(int i=0; i < N; i++){
    cin >>  A[i];
  }
  int pra =0;
  int mina = 0;
  int flag =0;
  for(int i=0; i < N; i++){
    if (A[i] < 0 )mina +=1;
    if (A[i] == 0 ) flag =1;
  }
  if (mina % 2 == 0) flag =1;
  long long int ans=0;
  if (flag ==1 ){
    for(int i=0; i < N; i++){
      ans += abs(A[i]);
    }
  }
  else{
    long long int B[N];
    for(int i=0; i < N; i++){
      B[i] = abs(A[i]);
    }
    sort(B,B+N);
    ans -= B[0];
    for(int i=1; i < N; i++){
      ans += B[i];
    }
  }
  cout << ans << endl;

}


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


void solve() {
  int N;
  scanf("%d", &N);
  char ch[10010];
  scanf("%s", &ch);
  int len = strlen(ch);
  rep(i, len) {
    int x = ch[i]-'A';
    x = (x+N)%26;
    putchar('A'+x);
  }
  putchar('\n');
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		for (int i = 1; i <= 9; i++)
			if (n % i == 0 && n / i <= 9)
			{
				Console.WriteLine("Yes");
				return;
			}
		Console.WriteLine("No");
	}
}


Measured memory_bytes: 13140
program kadai
implicit none
integer  ::  n,k,q
integer,allocatable  ::  a(:)
integer,allocatable  ::  b(:)
integer  ::  i,j

read(*,*) n,k,q

allocate(a(q))
allocate(b(n))

b=0
do i=1,q
    read(*,*) a(i)
    b(a(i)) = b(a(i)) + 1
end do

do i=1,n
    if (k-q+b(i)>0) then
        write(*,*) "Yes"
    else
        write(*,*) "No"
    end if
end do




stop
contains

end program kadai

Measured memory_bytes: 1536